ext4_fc_track_range() takes an inclusive end block: __track_range() records end - start + 1 blocks. ext4_punch_hole() passes end_lblk, the first block after the hole, so fast commit tracks one block more than the punch removed, and it is called even when the hole covers no whole block. The extra block also wraps the length: with huge_file, s_maxbytes is 0xffffffff blocks, so a hole from block 0 to s_maxbytes records a length of 0, which ext4_fc_snapshot_inode_data() reads as no change to the file's blocks. Today the hole stops at the block that holds i_size, so only a file that large gets there; the next patch lets the hole run to s_maxbytes on any file. Track [start_lblk, end_lblk - 1], and only when blocks were removed. Keep queueing the inode for every punch, which the call at the end did for a hole within one block, by tracking the inode before the removal. Fixes: aa75f4d3daae ("ext4: main fast-commit commit path") Signed-off-by: Ding Feng --- fs/ext4/inode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 07a62d856..26cf00ff8 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5426,10 +5426,10 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length) start_lblk = EXT4_B_TO_LBLK(inode, offset); end_lblk = end >> inode->i_blkbits; + ext4_fc_track_inode(handle, inode); if (end_lblk > start_lblk) { ext4_lblk_t hole_len = end_lblk - start_lblk; - ext4_fc_track_inode(handle, inode); ext4_check_map_extents_env(inode); down_write(&EXT4_I(inode)->i_data_sem); ext4_discard_preallocations(inode); @@ -5450,8 +5450,8 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length) ext4_es_insert_extent(inode, start_lblk, hole_len, ~0, EXTENT_STATUS_HOLE, 0); up_write(&EXT4_I(inode)->i_data_sem); + ext4_fc_track_range(handle, inode, start_lblk, end_lblk - 1); } - ext4_fc_track_range(handle, inode, start_lblk, end_lblk); ret = ext4_mark_inode_dirty(handle, inode); if (unlikely(ret)) -- 2.39.5