Skip to content

Commit 85defb9

Browse files
zhangyi089gregkh
authored andcommitted
ext4: fix incorrect punch max_end
[ Upstream commit 29ec9be ] For the extents based inodes, the maxbytes should be sb->s_maxbytes instead of sbi->s_bitmap_maxbytes. Additionally, for the calculation of max_end, the -sb->s_blocksize operation is necessary only for indirect-block based inodes. Correct the maxbytes and max_end value to correct the behavior of punch hole. Fixes: 2da3762 ("ext4: limit length to bitmap_maxbytes - blocksize in punch_hole") Signed-off-by: Zhang Yi <[email protected]> Reviewed-by: Jan Kara <[email protected]> Reviewed-by: Baokun Li <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Theodore Ts'o <[email protected]> Cc: [email protected] Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 35bd33e commit 85defb9

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

fs/ext4/inode.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3992,7 +3992,7 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length)
39923992
struct inode *inode = file_inode(file);
39933993
struct super_block *sb = inode->i_sb;
39943994
ext4_lblk_t start_lblk, end_lblk;
3995-
loff_t max_end = EXT4_SB(sb)->s_bitmap_maxbytes - sb->s_blocksize;
3995+
loff_t max_end = sb->s_maxbytes;
39963996
loff_t end = offset + length;
39973997
handle_t *handle;
39983998
unsigned int credits;
@@ -4001,14 +4001,20 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length)
40014001
trace_ext4_punch_hole(inode, offset, length, 0);
40024002
WARN_ON_ONCE(!inode_is_locked(inode));
40034003

4004+
/*
4005+
* For indirect-block based inodes, make sure that the hole within
4006+
* one block before last range.
4007+
*/
4008+
if (!ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
4009+
max_end = EXT4_SB(sb)->s_bitmap_maxbytes - sb->s_blocksize;
4010+
40044011
/* No need to punch hole beyond i_size */
40054012
if (offset >= inode->i_size)
40064013
return 0;
40074014

40084015
/*
40094016
* If the hole extends beyond i_size, set the hole to end after
4010-
* the page that contains i_size, and also make sure that the hole
4011-
* within one block before last range.
4017+
* the page that contains i_size.
40124018
*/
40134019
if (end > inode->i_size)
40144020
end = round_up(inode->i_size, PAGE_SIZE);

0 commit comments

Comments
 (0)