Skip to content

Commit e7d4cb6

Browse files
Tao MaMark Fasheh
authored andcommitted
ocfs2: Abstract ocfs2_extent_tree in b-tree operations.
In the old extent tree operation, we take the hypothesis that we are using the ocfs2_extent_list in ocfs2_dinode as the tree root. As xattr will also use ocfs2_extent_list to store large value for a xattr entry, we refactor the tree operation so that xattr can use it directly. The refactoring includes 4 steps: 1. Abstract set/get of last_eb_blk and update_clusters since they may be stored in different location for dinode and xattr. 2. Add a new structure named ocfs2_extent_tree to indicate the extent tree the operation will work on. 3. Remove all the use of fe_bh and di, use root_bh and root_el in extent tree instead. So now all the fe_bh is replaced with et->root_bh, el with root_el accordingly. 4. Make ocfs2_lock_allocators generic. Now it is limited to be only used in file extend allocation. But the whole function is useful when we want to store large EAs. Note: This patch doesn't touch ocfs2_commit_truncate() since it is not used for anything other than truncate inode data btrees. Signed-off-by: Tao Ma <tao.ma@oracle.com> Signed-off-by: Mark Fasheh <mfasheh@suse.com>
1 parent 811f933 commit e7d4cb6

8 files changed

Lines changed: 456 additions & 288 deletions

File tree

‎fs/ocfs2/alloc.c‎

Lines changed: 327 additions & 181 deletions
Large diffs are not rendered by default.

‎fs/ocfs2/alloc.h‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,37 @@
2626
#ifndef OCFS2_ALLOC_H
2727
#define OCFS2_ALLOC_H
2828

29+
enum ocfs2_extent_tree_type {
30+
OCFS2_DINODE_EXTENT = 0,
31+
};
32+
2933
struct ocfs2_alloc_context;
3034
int ocfs2_insert_extent(struct ocfs2_super *osb,
3135
handle_t *handle,
3236
struct inode *inode,
33-
struct buffer_head *fe_bh,
37+
struct buffer_head *root_bh,
3438
u32 cpos,
3539
u64 start_blk,
3640
u32 new_clusters,
3741
u8 flags,
38-
struct ocfs2_alloc_context *meta_ac);
42+
struct ocfs2_alloc_context *meta_ac,
43+
enum ocfs2_extent_tree_type et_type);
3944
struct ocfs2_cached_dealloc_ctxt;
40-
int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *di_bh,
45+
int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *root_bh,
4146
handle_t *handle, u32 cpos, u32 len, u32 phys,
4247
struct ocfs2_alloc_context *meta_ac,
43-
struct ocfs2_cached_dealloc_ctxt *dealloc);
44-
int ocfs2_remove_extent(struct inode *inode, struct buffer_head *di_bh,
48+
struct ocfs2_cached_dealloc_ctxt *dealloc,
49+
enum ocfs2_extent_tree_type et_type);
50+
int ocfs2_remove_extent(struct inode *inode, struct buffer_head *root_bh,
4551
u32 cpos, u32 len, handle_t *handle,
4652
struct ocfs2_alloc_context *meta_ac,
47-
struct ocfs2_cached_dealloc_ctxt *dealloc);
53+
struct ocfs2_cached_dealloc_ctxt *dealloc,
54+
enum ocfs2_extent_tree_type et_type);
4855
int ocfs2_num_free_extents(struct ocfs2_super *osb,
4956
struct inode *inode,
50-
struct buffer_head *bh);
57+
struct buffer_head *root_bh,
58+
enum ocfs2_extent_tree_type et_type);
59+
5160
/*
5261
* how many new metadata chunks would an allocation need at maximum?
5362
*

‎fs/ocfs2/aops.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,8 @@ static int ocfs2_write_cluster(struct address_space *mapping,
12781278
} else if (unwritten) {
12791279
ret = ocfs2_mark_extent_written(inode, wc->w_di_bh,
12801280
wc->w_handle, cpos, 1, phys,
1281-
meta_ac, &wc->w_dealloc);
1281+
meta_ac, &wc->w_dealloc,
1282+
OCFS2_DINODE_EXTENT);
12821283
if (ret < 0) {
12831284
mlog_errno(ret);
12841285
goto out;
@@ -1712,7 +1713,13 @@ int ocfs2_write_begin_nolock(struct address_space *mapping,
17121713
* ocfs2_lock_allocators(). It greatly over-estimates
17131714
* the work to be done.
17141715
*/
1715-
ret = ocfs2_lock_allocators(inode, wc->w_di_bh,
1716+
mlog(0, "extend inode %llu, i_size = %lld, di->i_clusters = %u,"
1717+
" clusters_to_add = %u, extents_to_split = %u\n",
1718+
(unsigned long long)OCFS2_I(inode)->ip_blkno,
1719+
(long long)i_size_read(inode), le32_to_cpu(di->i_clusters),
1720+
clusters_to_alloc, extents_to_split);
1721+
1722+
ret = ocfs2_lock_allocators(inode, wc->w_di_bh, &di->id2.i_list,
17161723
clusters_to_alloc, extents_to_split,
17171724
&data_ac, &meta_ac);
17181725
if (ret) {

‎fs/ocfs2/dir.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,7 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh,
13061306
* related blocks have been journaled already.
13071307
*/
13081308
ret = ocfs2_insert_extent(osb, handle, dir, di_bh, 0, blkno, len, 0,
1309-
NULL);
1309+
NULL, OCFS2_DINODE_EXTENT);
13101310
if (ret) {
13111311
mlog_errno(ret);
13121312
goto out_commit;
@@ -1338,7 +1338,7 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh,
13381338
blkno = ocfs2_clusters_to_blocks(dir->i_sb, bit_off);
13391339

13401340
ret = ocfs2_insert_extent(osb, handle, dir, di_bh, 1, blkno,
1341-
len, 0, NULL);
1341+
len, 0, NULL, OCFS2_DINODE_EXTENT);
13421342
if (ret) {
13431343
mlog_errno(ret);
13441344
goto out_commit;
@@ -1481,7 +1481,8 @@ static int ocfs2_extend_dir(struct ocfs2_super *osb,
14811481
if (dir_i_size == ocfs2_clusters_to_bytes(sb, OCFS2_I(dir)->ip_clusters)) {
14821482
spin_unlock(&OCFS2_I(dir)->ip_lock);
14831483
num_free_extents = ocfs2_num_free_extents(osb, dir,
1484-
parent_fe_bh);
1484+
parent_fe_bh,
1485+
OCFS2_DINODE_EXTENT);
14851486
if (num_free_extents < 0) {
14861487
status = num_free_extents;
14871488
mlog_errno(status);

‎fs/ocfs2/file.c‎

Lines changed: 13 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,8 @@ int ocfs2_do_extend_allocation(struct ocfs2_super *osb,
521521
if (mark_unwritten)
522522
flags = OCFS2_EXT_UNWRITTEN;
523523

524-
free_extents = ocfs2_num_free_extents(osb, inode, fe_bh);
524+
free_extents = ocfs2_num_free_extents(osb, inode, fe_bh,
525+
OCFS2_DINODE_EXTENT);
525526
if (free_extents < 0) {
526527
status = free_extents;
527528
mlog_errno(status);
@@ -570,7 +571,7 @@ int ocfs2_do_extend_allocation(struct ocfs2_super *osb,
570571
num_bits, bit_off, (unsigned long long)OCFS2_I(inode)->ip_blkno);
571572
status = ocfs2_insert_extent(osb, handle, inode, fe_bh,
572573
*logical_offset, block, num_bits,
573-
flags, meta_ac);
574+
flags, meta_ac, OCFS2_DINODE_EXTENT);
574575
if (status < 0) {
575576
mlog_errno(status);
576577
goto leave;
@@ -599,92 +600,6 @@ int ocfs2_do_extend_allocation(struct ocfs2_super *osb,
599600
return status;
600601
}
601602

602-
/*
603-
* For a given allocation, determine which allocators will need to be
604-
* accessed, and lock them, reserving the appropriate number of bits.
605-
*
606-
* Sparse file systems call this from ocfs2_write_begin_nolock()
607-
* and ocfs2_allocate_unwritten_extents().
608-
*
609-
* File systems which don't support holes call this from
610-
* ocfs2_extend_allocation().
611-
*/
612-
int ocfs2_lock_allocators(struct inode *inode, struct buffer_head *di_bh,
613-
u32 clusters_to_add, u32 extents_to_split,
614-
struct ocfs2_alloc_context **data_ac,
615-
struct ocfs2_alloc_context **meta_ac)
616-
{
617-
int ret = 0, num_free_extents;
618-
unsigned int max_recs_needed = clusters_to_add + 2 * extents_to_split;
619-
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
620-
struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data;
621-
622-
*meta_ac = NULL;
623-
if (data_ac)
624-
*data_ac = NULL;
625-
626-
BUG_ON(clusters_to_add != 0 && data_ac == NULL);
627-
628-
mlog(0, "extend inode %llu, i_size = %lld, di->i_clusters = %u, "
629-
"clusters_to_add = %u, extents_to_split = %u\n",
630-
(unsigned long long)OCFS2_I(inode)->ip_blkno, (long long)i_size_read(inode),
631-
le32_to_cpu(di->i_clusters), clusters_to_add, extents_to_split);
632-
633-
num_free_extents = ocfs2_num_free_extents(osb, inode, di_bh);
634-
if (num_free_extents < 0) {
635-
ret = num_free_extents;
636-
mlog_errno(ret);
637-
goto out;
638-
}
639-
640-
/*
641-
* Sparse allocation file systems need to be more conservative
642-
* with reserving room for expansion - the actual allocation
643-
* happens while we've got a journal handle open so re-taking
644-
* a cluster lock (because we ran out of room for another
645-
* extent) will violate ordering rules.
646-
*
647-
* Most of the time we'll only be seeing this 1 cluster at a time
648-
* anyway.
649-
*
650-
* Always lock for any unwritten extents - we might want to
651-
* add blocks during a split.
652-
*/
653-
if (!num_free_extents ||
654-
(ocfs2_sparse_alloc(osb) && num_free_extents < max_recs_needed)) {
655-
ret = ocfs2_reserve_new_metadata(osb, &di->id2.i_list, meta_ac);
656-
if (ret < 0) {
657-
if (ret != -ENOSPC)
658-
mlog_errno(ret);
659-
goto out;
660-
}
661-
}
662-
663-
if (clusters_to_add == 0)
664-
goto out;
665-
666-
ret = ocfs2_reserve_clusters(osb, clusters_to_add, data_ac);
667-
if (ret < 0) {
668-
if (ret != -ENOSPC)
669-
mlog_errno(ret);
670-
goto out;
671-
}
672-
673-
out:
674-
if (ret) {
675-
if (*meta_ac) {
676-
ocfs2_free_alloc_context(*meta_ac);
677-
*meta_ac = NULL;
678-
}
679-
680-
/*
681-
* We cannot have an error and a non null *data_ac.
682-
*/
683-
}
684-
685-
return ret;
686-
}
687-
688603
static int __ocfs2_extend_allocation(struct inode *inode, u32 logical_start,
689604
u32 clusters_to_add, int mark_unwritten)
690605
{
@@ -725,7 +640,13 @@ static int __ocfs2_extend_allocation(struct inode *inode, u32 logical_start,
725640
restart_all:
726641
BUG_ON(le32_to_cpu(fe->i_clusters) != OCFS2_I(inode)->ip_clusters);
727642

728-
status = ocfs2_lock_allocators(inode, bh, clusters_to_add, 0, &data_ac,
643+
mlog(0, "extend inode %llu, i_size = %lld, di->i_clusters = %u, "
644+
"clusters_to_add = %u\n",
645+
(unsigned long long)OCFS2_I(inode)->ip_blkno,
646+
(long long)i_size_read(inode), le32_to_cpu(fe->i_clusters),
647+
clusters_to_add);
648+
status = ocfs2_lock_allocators(inode, bh, &fe->id2.i_list,
649+
clusters_to_add, 0, &data_ac,
729650
&meta_ac);
730651
if (status) {
731652
mlog_errno(status);
@@ -1397,7 +1318,8 @@ static int __ocfs2_remove_inode_range(struct inode *inode,
13971318
struct ocfs2_alloc_context *meta_ac = NULL;
13981319
struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data;
13991320

1400-
ret = ocfs2_lock_allocators(inode, di_bh, 0, 1, NULL, &meta_ac);
1321+
ret = ocfs2_lock_allocators(inode, di_bh, &di->id2.i_list,
1322+
0, 1, NULL, &meta_ac);
14011323
if (ret) {
14021324
mlog_errno(ret);
14031325
return ret;
@@ -1428,7 +1350,7 @@ static int __ocfs2_remove_inode_range(struct inode *inode,
14281350
}
14291351

14301352
ret = ocfs2_remove_extent(inode, di_bh, cpos, len, handle, meta_ac,
1431-
dealloc);
1353+
dealloc, OCFS2_DINODE_EXTENT);
14321354
if (ret) {
14331355
mlog_errno(ret);
14341356
goto out_commit;

‎fs/ocfs2/file.h‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ int ocfs2_do_extend_allocation(struct ocfs2_super *osb,
5757
enum ocfs2_alloc_restarted *reason_ret);
5858
int ocfs2_extend_no_holes(struct inode *inode, u64 new_i_size,
5959
u64 zero_to);
60-
int ocfs2_lock_allocators(struct inode *inode, struct buffer_head *fe,
61-
u32 clusters_to_add, u32 extents_to_split,
62-
struct ocfs2_alloc_context **data_ac,
63-
struct ocfs2_alloc_context **meta_ac);
6460
int ocfs2_setattr(struct dentry *dentry, struct iattr *attr);
6561
int ocfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
6662
struct kstat *stat);

‎fs/ocfs2/suballoc.c‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,3 +1894,85 @@ static inline void ocfs2_debug_suballoc_inode(struct ocfs2_dinode *fe)
18941894
(unsigned long long)fe->id2.i_chain.cl_recs[i].c_blkno);
18951895
}
18961896
}
1897+
1898+
/*
1899+
* For a given allocation, determine which allocators will need to be
1900+
* accessed, and lock them, reserving the appropriate number of bits.
1901+
*
1902+
* Sparse file systems call this from ocfs2_write_begin_nolock()
1903+
* and ocfs2_allocate_unwritten_extents().
1904+
*
1905+
* File systems which don't support holes call this from
1906+
* ocfs2_extend_allocation().
1907+
*/
1908+
int ocfs2_lock_allocators(struct inode *inode, struct buffer_head *root_bh,
1909+
struct ocfs2_extent_list *root_el,
1910+
u32 clusters_to_add, u32 extents_to_split,
1911+
struct ocfs2_alloc_context **data_ac,
1912+
struct ocfs2_alloc_context **meta_ac)
1913+
{
1914+
int ret = 0, num_free_extents;
1915+
unsigned int max_recs_needed = clusters_to_add + 2 * extents_to_split;
1916+
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1917+
1918+
*meta_ac = NULL;
1919+
if (data_ac)
1920+
*data_ac = NULL;
1921+
1922+
BUG_ON(clusters_to_add != 0 && data_ac == NULL);
1923+
1924+
num_free_extents = ocfs2_num_free_extents(osb, inode, root_bh,
1925+
OCFS2_DINODE_EXTENT);
1926+
if (num_free_extents < 0) {
1927+
ret = num_free_extents;
1928+
mlog_errno(ret);
1929+
goto out;
1930+
}
1931+
1932+
/*
1933+
* Sparse allocation file systems need to be more conservative
1934+
* with reserving room for expansion - the actual allocation
1935+
* happens while we've got a journal handle open so re-taking
1936+
* a cluster lock (because we ran out of room for another
1937+
* extent) will violate ordering rules.
1938+
*
1939+
* Most of the time we'll only be seeing this 1 cluster at a time
1940+
* anyway.
1941+
*
1942+
* Always lock for any unwritten extents - we might want to
1943+
* add blocks during a split.
1944+
*/
1945+
if (!num_free_extents ||
1946+
(ocfs2_sparse_alloc(osb) && num_free_extents < max_recs_needed)) {
1947+
ret = ocfs2_reserve_new_metadata(osb, root_el, meta_ac);
1948+
if (ret < 0) {
1949+
if (ret != -ENOSPC)
1950+
mlog_errno(ret);
1951+
goto out;
1952+
}
1953+
}
1954+
1955+
if (clusters_to_add == 0)
1956+
goto out;
1957+
1958+
ret = ocfs2_reserve_clusters(osb, clusters_to_add, data_ac);
1959+
if (ret < 0) {
1960+
if (ret != -ENOSPC)
1961+
mlog_errno(ret);
1962+
goto out;
1963+
}
1964+
1965+
out:
1966+
if (ret) {
1967+
if (*meta_ac) {
1968+
ocfs2_free_alloc_context(*meta_ac);
1969+
*meta_ac = NULL;
1970+
}
1971+
1972+
/*
1973+
* We cannot have an error and a non null *data_ac.
1974+
*/
1975+
}
1976+
1977+
return ret;
1978+
}

‎fs/ocfs2/suballoc.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,9 @@ u64 ocfs2_which_cluster_group(struct inode *inode, u32 cluster);
162162
int ocfs2_check_group_descriptor(struct super_block *sb,
163163
struct ocfs2_dinode *di,
164164
struct ocfs2_group_desc *gd);
165+
int ocfs2_lock_allocators(struct inode *inode, struct buffer_head *root_bh,
166+
struct ocfs2_extent_list *root_el,
167+
u32 clusters_to_add, u32 extents_to_split,
168+
struct ocfs2_alloc_context **data_ac,
169+
struct ocfs2_alloc_context **meta_ac);
165170
#endif /* _CHAINALLOC_H_ */

0 commit comments

Comments
 (0)