]> git.hungrycats.org Git - linux/commit
btrfs: always remove quota_root from dirty_cowonly_roots
authorQu Wenruo <wqu@suse.com>
Tue, 13 Oct 2026 05:41:17 +0000 (16:11 +1030)
committerDavid Sterba <dsterba@suse.com>
Fri, 16 Oct 2026 16:50:13 +0000 (18:50 +0200)
commit1ea96c80df3396de2024e6cb162bbb372f5fffd8
tree28fe4b18dbf89ac0b8c08367bb8bd168e554ff9f
parent2bffe9d99641bcd1a6adaf771ceb966217016d1c
btrfs: always remove quota_root from dirty_cowonly_roots

[ERROR HANDLING QUIRK]
When btrfs_quota_disable() failed at btrfs_clean_quota_tree() or
btrfs_del_root(), the quota_root->dirty_list is not removed from
fs_info->dirty_cowonly_roots, but the quota_root itself will be freed.

This leaves a dangling pointer in the dirty_cowonly_roots.

This is not a huge problem, as the transaction is aborted thus no one
will read the dirty_cowonly_roots for now.

Furthermore, quota_root should never be logged nor have qgroup swapped
tree blocks, thus it won't cause leaks from extent io tree nor qgroup
swapped blocks.

[ENHANCEMENT]
For the incoming cleanup of dirty_cowonly_roots during
btrfs_free_fs_roots(), any root that is still linked to
dirty_cowonly_roots will be read again, and this existing dangling
pointer is going to cause problem.

To prepare for that cleanup, move the list_del() call into the out
label, so that even if the transaction is aborted, we still unlink
quota_root from dirty_cowonly_roots before freeing it.

Assisted-by: LLM (exposing the bug during review)
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/qgroup.c