Skip to content

Commit 48aaeeb

Browse files
josefbacikkdave
authored andcommitted
btrfs: convert block group refcount to refcount_t
We have refcount_t now with the associated library to handle refcounts, which gives us extra debugging around reference count mistakes that may be made. For example it'll warn on any transition from 0->1 or 0->-1, which is handy for noticing cases where we've messed up reference counting. Convert the block group ref counting from an atomic_t to refcount_t and use the appropriate helpers. Reviewed-by: Filipe Manana <[email protected]> Signed-off-by: Josef Bacik <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 60f8667 commit 48aaeeb

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

fs/btrfs/block-group.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ u64 btrfs_get_alloc_profile(struct btrfs_fs_info *fs_info, u64 orig_flags)
118118

119119
void btrfs_get_block_group(struct btrfs_block_group *cache)
120120
{
121-
atomic_inc(&cache->count);
121+
refcount_inc(&cache->refs);
122122
}
123123

124124
void btrfs_put_block_group(struct btrfs_block_group *cache)
125125
{
126-
if (atomic_dec_and_test(&cache->count)) {
126+
if (refcount_dec_and_test(&cache->refs)) {
127127
WARN_ON(cache->pinned > 0);
128128
WARN_ON(cache->reserved > 0);
129129

@@ -1805,7 +1805,7 @@ static struct btrfs_block_group *btrfs_create_block_group_cache(
18051805

18061806
cache->discard_index = BTRFS_DISCARD_INDEX_UNUSED;
18071807

1808-
atomic_set(&cache->count, 1);
1808+
refcount_set(&cache->refs, 1);
18091809
spin_lock_init(&cache->lock);
18101810
init_rwsem(&cache->data_rwsem);
18111811
INIT_LIST_HEAD(&cache->list);
@@ -3380,7 +3380,7 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)
33803380
ASSERT(list_empty(&block_group->dirty_list));
33813381
ASSERT(list_empty(&block_group->io_list));
33823382
ASSERT(list_empty(&block_group->bg_list));
3383-
ASSERT(atomic_read(&block_group->count) == 1);
3383+
ASSERT(refcount_read(&block_group->refs) == 1);
33843384
btrfs_put_block_group(block_group);
33853385

33863386
spin_lock(&info->block_group_cache_lock);

fs/btrfs/block-group.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ struct btrfs_block_group {
114114
/* For block groups in the same raid type */
115115
struct list_head list;
116116

117-
/* Usage count */
118-
atomic_t count;
117+
refcount_t refs;
119118

120119
/*
121120
* List of struct btrfs_free_clusters for this block group.

0 commit comments

Comments
 (0)