aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorBoris Burkov <boris@bur.io>2025-03-05 15:04:03 -0800
committerDavid Sterba <dsterba@suse.com>2025-03-18 20:35:51 +0100
commit7cbce3cb4c5cfffd8b08f148e2136afc1ec1ba94 (patch)
tree28e85d2da7cf2a86b9e3186b9a1e53853d2f54dd
parentbtrfs: make btrfs_discard_workfn() block_group ref explicit (diff)
downloadwireguard-linux-7cbce3cb4c5cfffd8b08f148e2136afc1ec1ba94.tar.xz
wireguard-linux-7cbce3cb4c5cfffd8b08f148e2136afc1ec1ba94.zip
btrfs: explicitly ref count block_group on new_bgs list
All other users of the bg_list list_head increment the refcount when adding to a list and decrement it when deleting from the list. Just for the sake of uniformity and to try to avoid refcounting bugs, do it for this list as well. This does not fix any known ref-counting bug, as the reference belongs to a single task (trans_handle is not shared and this represents trans_handle->new_bgs linkage) and will not lose its original refcount while that thread is running. And BLOCK_GROUP_FLAG_NEW protects against ref-counting errors "moving" the block group to the unused list without taking a ref. With that said, I still believe it is simpler to just hold the extra ref count for this list user as well. Reviewed-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: Boris Burkov <boris@bur.io> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to '')
-rw-r--r--fs/btrfs/block-group.c2
-rw-r--r--fs/btrfs/transaction.c1
2 files changed, 3 insertions, 0 deletions
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index f3a22b660fd3..221df35da49b 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -2801,6 +2801,7 @@ next:
spin_lock(&fs_info->unused_bgs_lock);
list_del_init(&block_group->bg_list);
clear_bit(BLOCK_GROUP_FLAG_NEW, &block_group->runtime_flags);
+ btrfs_put_block_group(block_group);
spin_unlock(&fs_info->unused_bgs_lock);
/*
@@ -2939,6 +2940,7 @@ struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *tran
}
#endif
+ btrfs_get_block_group(cache);
list_add_tail(&cache->bg_list, &trans->new_bgs);
btrfs_inc_delayed_refs_rsv_bg_inserts(fs_info);
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 470dfc3a1a5c..f26a394a9ec5 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -2108,6 +2108,7 @@ static void btrfs_cleanup_pending_block_groups(struct btrfs_trans_handle *trans)
*/
spin_lock(&fs_info->unused_bgs_lock);
list_del_init(&block_group->bg_list);
+ btrfs_put_block_group(block_group);
spin_unlock(&fs_info->unused_bgs_lock);
}
}