]> 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, 30 Oct 2026 20:36:16 +0000 (21:36 +0100)
commit5f925e27d6fea0be73e2d7c4eb6a5d11cb78a960
tree875213ceb77aad8623b798edf5d2e8621c872731
parentb29fa9e48d6df933dfd58fa566612c72b71dcb50
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