Skip to content

Commit 713e8dd

Browse files
committed
ext4: fix ZERO_RANGE bug hidden by flag aliasing
We accidently aliased EXT4_EX_NOCACHE and EXT4_GET_CONVERT_UNWRITTEN falgs, which apparently was hiding a bug that was unmasked when this flag aliasing issue was addressed (see the subsequent commit). The reproduction case was: fsx -N 10000 -l 500000 -r 4096 -t 4096 -w 4096 -Z -R -W /vdb/junk ... which would cause fsx to report corruption in the data file. The fix we have is a bit of an overkill, but I'd much rather be conservative for now, and we can optimize ZERO_RANGE_FL handling later. The fact that we need to zap the extent_status cache for the inode is unfortunate, but correctness is far more important than performance. Signed-off-by: Theodore Ts'o <tytso@mit.edu> Cc: Namjae Jeon <namjae.jeon@samsung.com>
1 parent 19008f6 commit 713e8dd

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

‎fs/ext4/extents.c‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4802,7 +4802,8 @@ static long ext4_zero_range(struct file *file, loff_t offset,
48024802
max_blocks -= lblk;
48034803

48044804
flags = EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT |
4805-
EXT4_GET_BLOCKS_CONVERT_UNWRITTEN;
4805+
EXT4_GET_BLOCKS_CONVERT_UNWRITTEN |
4806+
EXT4_EX_NOCACHE;
48064807
if (mode & FALLOC_FL_KEEP_SIZE)
48074808
flags |= EXT4_GET_BLOCKS_KEEP_SIZE;
48084809

@@ -4840,15 +4841,21 @@ static long ext4_zero_range(struct file *file, loff_t offset,
48404841
ext4_inode_block_unlocked_dio(inode);
48414842
inode_dio_wait(inode);
48424843

4844+
ret = ext4_alloc_file_blocks(file, lblk, max_blocks, new_size,
4845+
flags, mode);
4846+
if (ret)
4847+
goto out_dio;
48434848
/*
48444849
* Remove entire range from the extent status tree.
4850+
*
4851+
* ext4_es_remove_extent(inode, lblk, max_blocks) is
4852+
* NOT sufficient. I'm not sure why this is the case,
4853+
* but let's be conservative and remove the extent
4854+
* status tree for the entire inode. There should be
4855+
* no outstanding delalloc extents thanks to the
4856+
* filemap_write_and_wait_range() call above.
48454857
*/
4846-
ret = ext4_es_remove_extent(inode, lblk, max_blocks);
4847-
if (ret)
4848-
goto out_dio;
4849-
4850-
ret = ext4_alloc_file_blocks(file, lblk, max_blocks, new_size,
4851-
flags, mode);
4858+
ret = ext4_es_remove_extent(inode, 0, EXT_MAX_BLOCKS);
48524859
if (ret)
48534860
goto out_dio;
48544861
}

0 commit comments

Comments
 (0)