aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/ext4/extents.c5
-rw-r--r--fs/ext4/inode.c10
2 files changed, 7 insertions, 8 deletions
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index c42472fd4b63e3..ddc3a752996132 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -2409,9 +2409,10 @@ int ext4_ext_index_trans_blocks(struct inode *inode, int extents)
* the time we actually modify the tree. Assume the worst case.
*/
if (extents <= 1)
- index = EXT4_MAX_EXTENT_DEPTH * 2;
+ index = (EXT4_MAX_EXTENT_DEPTH * 2) + extents;
else
- index = EXT4_MAX_EXTENT_DEPTH * 3;
+ index = (EXT4_MAX_EXTENT_DEPTH * 3) +
+ DIV_ROUND_UP(extents, ext4_ext_space_block(inode, 0));
return index;
}
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 3a46f2822cf02f..18651f39a80bb5 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -5844,18 +5844,16 @@ static int ext4_meta_trans_blocks(struct inode *inode, int lblocks,
int ret;
/*
- * How many index blocks need to touch to map @lblocks logical blocks
- * to @pextents physical extents?
+ * How many index and lead blocks need to touch to map @lblocks
+ * logical blocks to @pextents physical extents?
*/
idxblocks = ext4_index_trans_blocks(inode, lblocks, pextents);
- ret = idxblocks;
-
/*
* Now let's see how many group bitmaps and group descriptors need
* to account
*/
- groups = idxblocks + pextents;
+ groups = idxblocks;
gdpblocks = groups;
if (groups > ngroups)
groups = ngroups;
@@ -5863,7 +5861,7 @@ static int ext4_meta_trans_blocks(struct inode *inode, int lblocks,
gdpblocks = EXT4_SB(inode->i_sb)->s_gdb_count;
/* bitmaps and block group descriptor blocks */
- ret += groups + gdpblocks;
+ ret = idxblocks + groups + gdpblocks;
/* Blocks for super block, inode, quota and xattr blocks */
ret += EXT4_META_TRANS_BLOCKS(inode->i_sb);