]> git.hungrycats.org Git - linux/commit
btrfs: cleanup qgroup swapped blocks at root release
authorQu Wenruo <wqu@suse.com>
Tue, 13 Oct 2026 05:41:19 +0000 (16:11 +1030)
committerDavid Sterba <dsterba@suse.com>
Fri, 30 Oct 2026 20:36:16 +0000 (21:36 +0100)
commita9517fa5681a10cd8574fd91e9dc99a6b31d933f
treecda05be2d68f3902a63845e2353f0254e2c015d8
parent2c5d4259c25e3b73a105404a712c379f634d6c6c
btrfs: cleanup qgroup swapped blocks at root release

Normally btrfs_qgroup_clean_swapped_blocks() is called when switching
the commit root of a subvolume tree.

However if a transaction is aborted before all dirty subvolumes are
linked to switch_commits, those left-over dirty subvolumes won't get
their qgroup swapped blocks cleaned up.

And since a transaction is already aborted, no new transaction is
allowed to be started, thus no way to cleanup the qgroup swapped blocks
for those subvolume trees.

Fix the problem by calling btrfs_qgroup_clean_swapped_blocks() inside
btrfs_put_root() when the last ref is dropped, so that at unmount time
those left-over qgroup swapped blocks are properly released.

This fix is inspired by the recent Sashiko reports about similar cases
on cowonly roots.

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