Skip to content

Commit 723de71

Browse files
josefbacikkdave
authored andcommitted
btrfs: handle space_info setting of bg in btrfs_add_bg_to_space_info
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 <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 9d4b0a1 commit 723de71

File tree

3 files changed

+13
-28
lines changed

3 files changed

+13
-28
lines changed

fs/btrfs/block-group.c

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,16 +1896,6 @@ static int exclude_super_stripes(struct btrfs_block_group *cache)
18961896
return 0;
18971897
}
18981898

1899-
static void link_block_group(struct btrfs_block_group *cache)
1900-
{
1901-
struct btrfs_space_info *space_info = cache->space_info;
1902-
int index = btrfs_bg_flags_to_raid_index(cache->flags);
1903-
1904-
down_write(&space_info->groups_sem);
1905-
list_add_tail(&cache->list, &space_info->block_groups[index]);
1906-
up_write(&space_info->groups_sem);
1907-
}
1908-
19091899
static struct btrfs_block_group *btrfs_create_block_group_cache(
19101900
struct btrfs_fs_info *fs_info, u64 start)
19111901
{
@@ -2008,7 +1998,6 @@ static int read_one_block_group(struct btrfs_fs_info *info,
20081998
int need_clear)
20091999
{
20102000
struct btrfs_block_group *cache;
2011-
struct btrfs_space_info *space_info;
20122001
const bool mixed = btrfs_fs_incompat(info, MIXED_GROUPS);
20132002
int ret;
20142003

@@ -2101,11 +2090,7 @@ static int read_one_block_group(struct btrfs_fs_info *info,
21012090
goto error;
21022091
}
21032092
trace_btrfs_add_block_group(info, cache, 0);
2104-
btrfs_add_bg_to_space_info(info, cache, &space_info);
2105-
2106-
cache->space_info = space_info;
2107-
2108-
link_block_group(cache);
2093+
btrfs_add_bg_to_space_info(info, cache);
21092094

21102095
set_avail_alloc_bits(info, cache->flags);
21112096
if (btrfs_chunk_writeable(info, cache->start)) {
@@ -2129,7 +2114,6 @@ static int read_one_block_group(struct btrfs_fs_info *info,
21292114
static int fill_dummy_bgs(struct btrfs_fs_info *fs_info)
21302115
{
21312116
struct extent_map_tree *em_tree = &fs_info->mapping_tree;
2132-
struct btrfs_space_info *space_info;
21332117
struct rb_node *node;
21342118
int ret = 0;
21352119

@@ -2170,9 +2154,7 @@ static int fill_dummy_bgs(struct btrfs_fs_info *fs_info)
21702154
break;
21712155
}
21722156

2173-
btrfs_add_bg_to_space_info(fs_info, bg, &space_info);
2174-
bg->space_info = space_info;
2175-
link_block_group(bg);
2157+
btrfs_add_bg_to_space_info(fs_info, bg);
21762158

21772159
set_avail_alloc_bits(fs_info, bg->flags);
21782160
}
@@ -2541,7 +2523,7 @@ struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *tran
25412523
* the rbtree, update the space info's counters.
25422524
*/
25432525
trace_btrfs_add_block_group(fs_info, cache, 1);
2544-
btrfs_add_bg_to_space_info(fs_info, cache, &cache->space_info);
2526+
btrfs_add_bg_to_space_info(fs_info, cache);
25452527
btrfs_update_global_block_rsv(fs_info);
25462528

25472529
#ifdef CONFIG_BTRFS_DEBUG
@@ -2552,7 +2534,6 @@ struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *tran
25522534
fragment_free_space(cache);
25532535
}
25542536
#endif
2555-
link_block_group(cache);
25562537

25572538
list_add_tail(&cache->bg_list, &trans->new_bgs);
25582539
trans->delayed_ref_updates++;

fs/btrfs/space-info.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,10 @@ int btrfs_init_space_info(struct btrfs_fs_info *fs_info)
294294
}
295295

296296
void btrfs_add_bg_to_space_info(struct btrfs_fs_info *info,
297-
struct btrfs_block_group *block_group,
298-
struct btrfs_space_info **space_info)
297+
struct btrfs_block_group *block_group)
299298
{
300299
struct btrfs_space_info *found;
301-
int factor;
300+
int factor, index;
302301

303302
factor = btrfs_bg_type_to_factor(block_group->flags);
304303

@@ -317,7 +316,13 @@ void btrfs_add_bg_to_space_info(struct btrfs_fs_info *info,
317316
found->full = 0;
318317
btrfs_try_granting_tickets(info, found);
319318
spin_unlock(&found->lock);
320-
*space_info = found;
319+
320+
block_group->space_info = found;
321+
322+
index = btrfs_bg_flags_to_raid_index(block_group->flags);
323+
down_write(&found->groups_sem);
324+
list_add_tail(&block_group->list, &found->block_groups[index]);
325+
up_write(&found->groups_sem);
321326
}
322327

323328
struct btrfs_space_info *btrfs_find_space_info(struct btrfs_fs_info *info,

fs/btrfs/space-info.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ DECLARE_SPACE_INFO_UPDATE(bytes_pinned, "pinned");
124124

125125
int btrfs_init_space_info(struct btrfs_fs_info *fs_info);
126126
void btrfs_add_bg_to_space_info(struct btrfs_fs_info *info,
127-
struct btrfs_block_group *block_group,
128-
struct btrfs_space_info **space_info);
127+
struct btrfs_block_group *block_group);
129128
void btrfs_update_space_info_chunk_size(struct btrfs_space_info *space_info,
130129
u64 chunk_size);
131130
struct btrfs_space_info *btrfs_find_space_info(struct btrfs_fs_info *info,

0 commit comments

Comments
 (0)