]> git.hungrycats.org Git - linux/commitdiff
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)
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

index c45cda4290d5a31350600626294474de1bbca417..71a344b564070ded34d2b740596f5b315875c9c6 100644 (file)
@@ -1847,6 +1847,7 @@ void btrfs_put_root(struct btrfs_root *root)
                if (root->anon_dev)
                        free_anon_bdev(root->anon_dev);
                free_root_extent_buffers(root);
+               btrfs_qgroup_clean_swapped_blocks(root);
 #ifdef CONFIG_BTRFS_DEBUG
                spin_lock(&root->fs_info->fs_roots_radix_lock);
                list_del_init(&root->leak_list);