Skip to content

Commit 69dc953

Browse files
Dmitry Monakhovtytso
authored andcommitted
ext4: fix incorect journal credits reservation in ext4_zero_range
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> Cc: stable@vger.kernel.org
1 parent 4631dbf commit 69dc953

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎fs/ext4/extents.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4731,6 +4731,7 @@ static long ext4_zero_range(struct file *file, loff_t offset,
47314731
loff_t new_size = 0;
47324732
int ret = 0;
47334733
int flags;
4734+
int credits;
47344735
int partial;
47354736
loff_t start, end;
47364737
ext4_lblk_t lblk;
@@ -4830,8 +4831,14 @@ static long ext4_zero_range(struct file *file, loff_t offset,
48304831
if (ret)
48314832
goto out_dio;
48324833
}
4833-
4834-
handle = ext4_journal_start(inode, EXT4_HT_MISC, 4);
4834+
/*
4835+
* In worst case we have to writeout two nonadjacent unwritten
4836+
* blocks and update the inode
4837+
*/
4838+
credits = (2 * ext4_ext_index_trans_blocks(inode, 2)) + 1;
4839+
if (ext4_should_journal_data(inode))
4840+
credits += 2;
4841+
handle = ext4_journal_start(inode, EXT4_HT_MISC, credits);
48354842
if (IS_ERR(handle)) {
48364843
ret = PTR_ERR(handle);
48374844
ext4_std_error(inode->i_sb, ret);

0 commit comments

Comments
 (0)