Truncation range tracking (ext4_fc_track_range()) is currently only called in ext4_truncate_down(), which misses three cases where ext4_truncate() frees extents: 1. Same-size ftruncate(fd, oldsize) dropping FALLOC_FL_KEEP_SIZE preallocated blocks beyond EOF jumps straight to ext4_truncate() without calling ext4_fc_track_range(). 2. If a commit occurs between ext4_truncate_down() stopping its handle and ext4_truncate() starting a new handle in transaction T+1, ext4_fc_track_inode() resets i_fc_lblk_len to 0 and freed extents are not tracked. 3. If ext4_ext_remove_space() restarts the journal handle onto a new transaction, earlier tracking belonged to the previous transaction. In all three cases, a subsequent fast commit omits EXT4_FC_TAG_DEL_RANGE and resurrects freed extents after crash recovery. Case 1 reproduces deterministically on -O fast_commit: xfs_io -f -c "pwrite -S 0xaa 0 4k" -c "falloc -k 4k 64k" mnt/foo sync xfs_io -c "truncate 4k" -c "fsync" mnt/foo # crash (dm-flakey drop_writes) and remount: # stat -c %b mnt/foo returns 136 instead of 8 Call ext4_fc_track_range(handle, inode, start_lblk, EXT_MAX_BLOCKS - 1) in ext4_truncate() right after ext4_ext_truncate() releases i_data_sem while the active journal handle is still open. Fixes: aa75f4d3daae ("ext4: main fast-commit commit path") Cc: stable@vger.kernel.org Signed-off-by: Xing Ma --- fs/ext4/inode.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 07a62d8569d31..9edb29ca2e1b7 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5605,6 +5605,14 @@ int ext4_truncate(struct inode *inode) ext4_ind_truncate(handle, inode); up_write(&ei->i_data_sem); + if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) { + ext4_lblk_t start_lblk; + + start_lblk = inode->i_size > 0 ? + (inode->i_size - 1) >> inode->i_blkbits : 0; + ext4_fc_track_range(handle, inode, start_lblk, + EXT_MAX_BLOCKS - 1); + } if (err) goto out_stop; -- 2.39.5