1 ext4: delalloc --estimate need metadata blocks to reserve
3 From: Mingming cao <cmm@us.ibm.com>
5 Calculate the number of metadata blocks needed to allocate blocks
6 Worse case is one block per extent
8 Signed-off-by: Mingming cao <cmm@us.ibm.com>
11 fs/ext4/ext4_extents.h | 1 +
12 fs/ext4/extents.c | 30 ++++++++++++++++++++++++++++++
13 2 files changed, 31 insertions(+)
15 Index: linux-2.6.26-rc5/fs/ext4/ext4_extents.h
16 ===================================================================
17 --- linux-2.6.26-rc5.orig/fs/ext4/ext4_extents.h 2008-06-06 17:03:34.000000000 -0700
18 +++ linux-2.6.26-rc5/fs/ext4/ext4_extents.h 2008-06-06 17:03:58.000000000 -0700
19 @@ -212,6 +212,7 @@ static inline int ext4_ext_get_actual_le
20 (le16_to_cpu(ext->ee_len) - EXT_INIT_MAX_LEN));
23 +extern int ext4_ext_calc_metadata_amount(struct inode *inode, int blocks);
24 extern ext4_fsblk_t idx_pblock(struct ext4_extent_idx *);
25 extern void ext4_ext_store_pblock(struct ext4_extent *, ext4_fsblk_t);
26 extern int ext4_extent_tree_init(handle_t *, struct inode *);
27 Index: linux-2.6.26-rc5/fs/ext4/extents.c
28 ===================================================================
29 --- linux-2.6.26-rc5.orig/fs/ext4/extents.c 2008-06-06 17:03:51.000000000 -0700
30 +++ linux-2.6.26-rc5/fs/ext4/extents.c 2008-06-06 17:03:58.000000000 -0700
31 @@ -246,6 +246,36 @@ static int ext4_ext_space_root_idx(struc
36 + * Calculate the number of metadata blocks needed
37 + * to allocate @blocks
38 + * Worse case is one block per extent
40 +int ext4_ext_calc_metadata_amount(struct inode *inode, int blocks)
42 + int lcap, icap, rcap, leafs, idxs, num;
43 + int newextents = blocks;
45 + rcap = ext4_ext_space_root_idx(inode);
46 + lcap = ext4_ext_space_block(inode);
47 + icap = ext4_ext_space_block_idx(inode);
49 + /* number of new leaf blocks needed */
50 + num = leafs = (newextents + lcap - 1) / lcap;
53 + * Worse case, we need separate index block(s)
54 + * to link all new leaf blocks
56 + idxs = (leafs + icap - 1) / icap;
59 + idxs = (idxs + icap - 1) / icap;
60 + } while (idxs > rcap);
66 ext4_ext_max_entries(struct inode *inode, int depth)