Skip to content

Commit 801674f

Browse files
jankaratytso
authored andcommitted
ext4: do not zeroout extents beyond i_disksize
We do not want to create initialized extents beyond end of file because for e2fsck it is impossible to distinguish them from a case of corrupted file size / extent tree and so it complains like: Inode 12, i_size is 147456, should be 163840. Fix? no Code in ext4_ext_convert_to_initialized() and ext4_split_convert_extents() try to make sure it does not create initialized extents beyond inode size however they check against inode->i_size which is wrong. They should instead check against EXT4_I(inode)->i_disksize which is the current inode size on disk. That's what e2fsck is going to see in case of crash before all dirty data is written. This bug manifests as generic/456 test failure (with recent enough fstests where fsx got fixed to properly pass FALLOC_KEEP_SIZE_FL flags to the kernel) when run with dioread_lock mount option. CC: [email protected] Fixes: 21ca087 ("ext4: Do not zero out uninitialized extents beyond i_size") Reviewed-by: Lukas Czerner <[email protected]> Signed-off-by: Jan Kara <[email protected]> Signed-off-by: Theodore Ts'o <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 9033783 commit 801674f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

fs/ext4/extents.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3374,8 +3374,8 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,
33743374
(unsigned long long)map->m_lblk, map_len);
33753375

33763376
sbi = EXT4_SB(inode->i_sb);
3377-
eof_block = (inode->i_size + inode->i_sb->s_blocksize - 1) >>
3378-
inode->i_sb->s_blocksize_bits;
3377+
eof_block = (EXT4_I(inode)->i_disksize + inode->i_sb->s_blocksize - 1)
3378+
>> inode->i_sb->s_blocksize_bits;
33793379
if (eof_block < map->m_lblk + map_len)
33803380
eof_block = map->m_lblk + map_len;
33813381

@@ -3627,8 +3627,8 @@ static int ext4_split_convert_extents(handle_t *handle,
36273627
__func__, inode->i_ino,
36283628
(unsigned long long)map->m_lblk, map->m_len);
36293629

3630-
eof_block = (inode->i_size + inode->i_sb->s_blocksize - 1) >>
3631-
inode->i_sb->s_blocksize_bits;
3630+
eof_block = (EXT4_I(inode)->i_disksize + inode->i_sb->s_blocksize - 1)
3631+
>> inode->i_sb->s_blocksize_bits;
36323632
if (eof_block < map->m_lblk + map->m_len)
36333633
eof_block = map->m_lblk + map->m_len;
36343634
/*

0 commit comments

Comments
 (0)