summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorDmitry Monakhov <dmonakhov@openvz.org>2014-08-27 18:33:49 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-09-05 16:36:38 -0700
commit69fa118cd621a59032a41d2e7ff913bf06ce57b7 (patch)
treeef433c9c172ce3ac43f8539d194dd2f20d876ef1 /fs
parent43fc7fe25e51c6e9c22b872292cf2327a0fd37a6 (diff)
ext4: fix incorect journal credits reservation in ext4_zero_range
commit 69dc9536405213c1d545fcace1fc15c481d00aae upstream. Currently we reserve only 4 blocks but in worst case scenario ext4_zero_partial_blocks() may want to zeroout and convert two non adjacent blocks. Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/ext4/extents.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index b9a7bd3d561e..6f9491affb26 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -4730,6 +4730,7 @@ static long ext4_zero_range(struct file *file, loff_t offset,
loff_t new_size = 0;
int ret = 0;
int flags;
+ int credits;
int partial;
loff_t start, end;
ext4_lblk_t lblk;
@@ -4829,8 +4830,14 @@ static long ext4_zero_range(struct file *file, loff_t offset,
if (ret)
goto out_dio;
}
-
- handle = ext4_journal_start(inode, EXT4_HT_MISC, 4);
+ /*
+ * In worst case we have to writeout two nonadjacent unwritten
+ * blocks and update the inode
+ */
+ credits = (2 * ext4_ext_index_trans_blocks(inode, 2)) + 1;
+ if (ext4_should_journal_data(inode))
+ credits += 2;
+ handle = ext4_journal_start(inode, EXT4_HT_MISC, credits);
if (IS_ERR(handle)) {
ret = PTR_ERR(handle);
ext4_std_error(inode->i_sb, ret);