Skip to content

Commit 7cbce3c

Browse files
boryaskdave
authored andcommitted
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 <[email protected]> Signed-off-by: Boris Burkov <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 895c672 commit 7cbce3c

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

fs/btrfs/block-group.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2801,6 +2801,7 @@ void btrfs_create_pending_block_groups(struct btrfs_trans_handle *trans)
28012801
spin_lock(&fs_info->unused_bgs_lock);
28022802
list_del_init(&block_group->bg_list);
28032803
clear_bit(BLOCK_GROUP_FLAG_NEW, &block_group->runtime_flags);
2804+
btrfs_put_block_group(block_group);
28042805
spin_unlock(&fs_info->unused_bgs_lock);
28052806

28062807
/*
@@ -2939,6 +2940,7 @@ struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *tran
29392940
}
29402941
#endif
29412942

2943+
btrfs_get_block_group(cache);
29422944
list_add_tail(&cache->bg_list, &trans->new_bgs);
29432945
btrfs_inc_delayed_refs_rsv_bg_inserts(fs_info);
29442946

fs/btrfs/transaction.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,6 +2108,7 @@ static void btrfs_cleanup_pending_block_groups(struct btrfs_trans_handle *trans)
21082108
*/
21092109
spin_lock(&fs_info->unused_bgs_lock);
21102110
list_del_init(&block_group->bg_list);
2111+
btrfs_put_block_group(block_group);
21112112
spin_unlock(&fs_info->unused_bgs_lock);
21122113
}
21132114
}

0 commit comments

Comments
 (0)