]> git.hungrycats.org Git - linux/commit
btrfs: defrag: prevent inode truncated to zero from not being defragged again
authorFilipe Manana <fdmanana@suse.com>
Tue, 13 Oct 2026 16:04:00 +0000 (17:04 +0100)
committerDavid Sterba <dsterba@suse.com>
Fri, 16 Oct 2026 16:50:27 +0000 (18:50 +0200)
commite3cb5044c579a7c4cff7b9d2db85fa8ea238d3e1
tree4ee0d5d5de3e555dd1298091c448a28fcf89c5f2
parente37fb4ac525bf3e0c9b4e481ac0e9c566b454fb3
btrfs: defrag: prevent inode truncated to zero from not being defragged again

If we add an inode to autodefrag and the inode is truncated to an i_size
of zero before it's picked by autodefrag (run by the cleaner kthread),
we exit btrfs_run_defrag_inode() leaving the BTRFS_INODE_IN_DEFRAG flag
set in the inode, which prevents the inode from being auto defragged in
the future until it's evicted, loaded again and small writes happen to
it again.

Fix this by clearing BTRFS_INODE_IN_DEFRAG before we check if the current
offset is at or beyond the inode's i_size.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/defrag.c