]> git.baikalelectronics.ru Git - kernel.git/commitdiff
btrfs: handle space_info setting of bg in btrfs_add_bg_to_space_info
authorJosef Bacik <josef@toxicpanda.com>
Fri, 15 Jul 2022 19:45:23 +0000 (15:45 -0400)
committerDavid Sterba <dsterba@suse.com>
Mon, 26 Sep 2022 10:27:54 +0000 (12:27 +0200)
We previously had the pattern of

btrfs_update_space_info(all, the, bg, fields, &space_info);
link_block_group(bg);
bg->space_info = space_info;

Now that we're passing the bg into btrfs_add_bg_to_space_info we can do
the linking in that function, transforming this to simply

btrfs_add_bg_to_space_info(fs_info, bg);

and put the link_block_group() and bg->space_info assignment directly in
btrfs_add_bg_to_space_info.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/block-group.c
fs/btrfs/space-info.c
fs/btrfs/space-info.h

index a6ecf3f87fc3308e181880363c6b541636e933ad..d83c044d3003dfbfbb4e1a1b2fa1a6bbe5e66e14 100644 (file)
@@ -1896,16 +1896,6 @@ static int exclude_super_stripes(struct btrfs_block_group *cache)
        return 0;
 }
 
-static void link_block_group(struct btrfs_block_group *cache)
-{
-       struct btrfs_space_info *space_info = cache->space_info;
-       int index = btrfs_bg_flags_to_raid_index(cache->flags);
-
-       down_write(&space_info->groups_sem);
-       list_add_tail(&cache->list, &space_info->block_groups[index]);
-       up_write(&space_info->groups_sem);
-}
-
 static struct btrfs_block_group *btrfs_create_block_group_cache(
                struct btrfs_fs_info *fs_info, u64 start)
 {
@@ -2008,7 +1998,6 @@ static int read_one_block_group(struct btrfs_fs_info *info,
                                int need_clear)
 {
        struct btrfs_block_group *cache;
-       struct btrfs_space_info *space_info;
        const bool mixed = btrfs_fs_incompat(info, MIXED_GROUPS);
        int ret;
 
@@ -2101,11 +2090,7 @@ static int read_one_block_group(struct btrfs_fs_info *info,
                goto error;
        }
        trace_btrfs_add_block_group(info, cache, 0);
-       btrfs_add_bg_to_space_info(info, cache, &space_info);
-
-       cache->space_info = space_info;
-
-       link_block_group(cache);
+       btrfs_add_bg_to_space_info(info, cache);
 
        set_avail_alloc_bits(info, cache->flags);
        if (btrfs_chunk_writeable(info, cache->start)) {
@@ -2129,7 +2114,6 @@ error:
 static int fill_dummy_bgs(struct btrfs_fs_info *fs_info)
 {
        struct extent_map_tree *em_tree = &fs_info->mapping_tree;
-       struct btrfs_space_info *space_info;
        struct rb_node *node;
        int ret = 0;
 
@@ -2170,9 +2154,7 @@ static int fill_dummy_bgs(struct btrfs_fs_info *fs_info)
                        break;
                }
 
-               btrfs_add_bg_to_space_info(fs_info, bg, &space_info);
-               bg->space_info = space_info;
-               link_block_group(bg);
+               btrfs_add_bg_to_space_info(fs_info, bg);
 
                set_avail_alloc_bits(fs_info, bg->flags);
        }
@@ -2541,7 +2523,7 @@ struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *tran
         * the rbtree, update the space info's counters.
         */
        trace_btrfs_add_block_group(fs_info, cache, 1);
-       btrfs_add_bg_to_space_info(fs_info, cache, &cache->space_info);
+       btrfs_add_bg_to_space_info(fs_info, cache);
        btrfs_update_global_block_rsv(fs_info);
 
 #ifdef CONFIG_BTRFS_DEBUG
@@ -2552,7 +2534,6 @@ struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *tran
                fragment_free_space(cache);
        }
 #endif
-       link_block_group(cache);
 
        list_add_tail(&cache->bg_list, &trans->new_bgs);
        trans->delayed_ref_updates++;
index 6974bbef0feae7a1e549ee719a490267bffcd37c..6260e52d76f4addcc29a55dd5eb56a0216ed277a 100644 (file)
@@ -294,11 +294,10 @@ out:
 }
 
 void btrfs_add_bg_to_space_info(struct btrfs_fs_info *info,
-                               struct btrfs_block_group *block_group,
-                               struct btrfs_space_info **space_info)
+                               struct btrfs_block_group *block_group)
 {
        struct btrfs_space_info *found;
-       int factor;
+       int factor, index;
 
        factor = btrfs_bg_type_to_factor(block_group->flags);
 
@@ -317,7 +316,13 @@ void btrfs_add_bg_to_space_info(struct btrfs_fs_info *info,
                found->full = 0;
        btrfs_try_granting_tickets(info, found);
        spin_unlock(&found->lock);
-       *space_info = found;
+
+       block_group->space_info = found;
+
+       index = btrfs_bg_flags_to_raid_index(block_group->flags);
+       down_write(&found->groups_sem);
+       list_add_tail(&block_group->list, &found->block_groups[index]);
+       up_write(&found->groups_sem);
 }
 
 struct btrfs_space_info *btrfs_find_space_info(struct btrfs_fs_info *info,
index 101e83828ee5fd1763bd139542417b5a2c006d7a..2039096803ed8148670ac3c86b7987022f6b4e56 100644 (file)
@@ -124,8 +124,7 @@ DECLARE_SPACE_INFO_UPDATE(bytes_pinned, "pinned");
 
 int btrfs_init_space_info(struct btrfs_fs_info *fs_info);
 void btrfs_add_bg_to_space_info(struct btrfs_fs_info *info,
-                               struct btrfs_block_group *block_group,
-                               struct btrfs_space_info **space_info);
+                               struct btrfs_block_group *block_group);
 void btrfs_update_space_info_chunk_size(struct btrfs_space_info *space_info,
                                        u64 chunk_size);
 struct btrfs_space_info *btrfs_find_space_info(struct btrfs_fs_info *info,