Commit 48aaeebe authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

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: default avatarFilipe Manana <fdmanana@suse.com>
Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 60f8667b
...@@ -118,12 +118,12 @@ u64 btrfs_get_alloc_profile(struct btrfs_fs_info *fs_info, u64 orig_flags) ...@@ -118,12 +118,12 @@ u64 btrfs_get_alloc_profile(struct btrfs_fs_info *fs_info, u64 orig_flags)
void btrfs_get_block_group(struct btrfs_block_group *cache) void btrfs_get_block_group(struct btrfs_block_group *cache)
{ {
atomic_inc(&cache->count); refcount_inc(&cache->refs);
} }
void btrfs_put_block_group(struct btrfs_block_group *cache) void btrfs_put_block_group(struct btrfs_block_group *cache)
{ {
if (atomic_dec_and_test(&cache->count)) { if (refcount_dec_and_test(&cache->refs)) {
WARN_ON(cache->pinned > 0); WARN_ON(cache->pinned > 0);
WARN_ON(cache->reserved > 0); WARN_ON(cache->reserved > 0);
...@@ -1805,7 +1805,7 @@ static struct btrfs_block_group *btrfs_create_block_group_cache( ...@@ -1805,7 +1805,7 @@ static struct btrfs_block_group *btrfs_create_block_group_cache(
cache->discard_index = BTRFS_DISCARD_INDEX_UNUSED; cache->discard_index = BTRFS_DISCARD_INDEX_UNUSED;
atomic_set(&cache->count, 1); refcount_set(&cache->refs, 1);
spin_lock_init(&cache->lock); spin_lock_init(&cache->lock);
init_rwsem(&cache->data_rwsem); init_rwsem(&cache->data_rwsem);
INIT_LIST_HEAD(&cache->list); INIT_LIST_HEAD(&cache->list);
...@@ -3380,7 +3380,7 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info) ...@@ -3380,7 +3380,7 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)
ASSERT(list_empty(&block_group->dirty_list)); ASSERT(list_empty(&block_group->dirty_list));
ASSERT(list_empty(&block_group->io_list)); ASSERT(list_empty(&block_group->io_list));
ASSERT(list_empty(&block_group->bg_list)); ASSERT(list_empty(&block_group->bg_list));
ASSERT(atomic_read(&block_group->count) == 1); ASSERT(refcount_read(&block_group->refs) == 1);
btrfs_put_block_group(block_group); btrfs_put_block_group(block_group);
spin_lock(&info->block_group_cache_lock); spin_lock(&info->block_group_cache_lock);
......
...@@ -114,8 +114,7 @@ struct btrfs_block_group { ...@@ -114,8 +114,7 @@ struct btrfs_block_group {
/* For block groups in the same raid type */ /* For block groups in the same raid type */
struct list_head list; struct list_head list;
/* Usage count */ refcount_t refs;
atomic_t count;
/* /*
* List of struct btrfs_free_clusters for this block group. * List of struct btrfs_free_clusters for this block group.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment