Commit 9d4b0a12 authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

btrfs: simplify arguments of btrfs_update_space_info and rename

This function has grown a bunch of new arguments, and it just boils down
to passing in all the block group fields as arguments.  Simplify this by
passing in the block group itself and updating the space_info fields
based on the block group fields directly.
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 2f12741f
...@@ -2101,10 +2101,7 @@ static int read_one_block_group(struct btrfs_fs_info *info, ...@@ -2101,10 +2101,7 @@ static int read_one_block_group(struct btrfs_fs_info *info,
goto error; goto error;
} }
trace_btrfs_add_block_group(info, cache, 0); trace_btrfs_add_block_group(info, cache, 0);
btrfs_update_space_info(info, cache->flags, cache->length, btrfs_add_bg_to_space_info(info, cache, &space_info);
cache->used, cache->bytes_super,
cache->zone_unusable, cache->zone_is_active,
&space_info);
cache->space_info = space_info; cache->space_info = space_info;
...@@ -2173,8 +2170,7 @@ static int fill_dummy_bgs(struct btrfs_fs_info *fs_info) ...@@ -2173,8 +2170,7 @@ static int fill_dummy_bgs(struct btrfs_fs_info *fs_info)
break; break;
} }
btrfs_update_space_info(fs_info, bg->flags, em->len, em->len, btrfs_add_bg_to_space_info(fs_info, bg, &space_info);
0, 0, false, &space_info);
bg->space_info = space_info; bg->space_info = space_info;
link_block_group(bg); link_block_group(bg);
...@@ -2525,14 +2521,6 @@ struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *tran ...@@ -2525,14 +2521,6 @@ struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *tran
btrfs_free_excluded_extents(cache); btrfs_free_excluded_extents(cache);
#ifdef CONFIG_BTRFS_DEBUG
if (btrfs_should_fragment_free_space(cache)) {
u64 new_bytes_used = size - bytes_used;
bytes_used += new_bytes_used >> 1;
fragment_free_space(cache);
}
#endif
/* /*
* Ensure the corresponding space_info object is created and * Ensure the corresponding space_info object is created and
* assigned to our block group. We want our bg to be added to the rbtree * assigned to our block group. We want our bg to be added to the rbtree
...@@ -2553,11 +2541,17 @@ struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *tran ...@@ -2553,11 +2541,17 @@ struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *tran
* the rbtree, update the space info's counters. * the rbtree, update the space info's counters.
*/ */
trace_btrfs_add_block_group(fs_info, cache, 1); trace_btrfs_add_block_group(fs_info, cache, 1);
btrfs_update_space_info(fs_info, cache->flags, size, bytes_used, btrfs_add_bg_to_space_info(fs_info, cache, &cache->space_info);
cache->bytes_super, cache->zone_unusable,
cache->zone_is_active, &cache->space_info);
btrfs_update_global_block_rsv(fs_info); btrfs_update_global_block_rsv(fs_info);
#ifdef CONFIG_BTRFS_DEBUG
if (btrfs_should_fragment_free_space(cache)) {
u64 new_bytes_used = size - bytes_used;
cache->space_info->bytes_used += new_bytes_used >> 1;
fragment_free_space(cache);
}
#endif
link_block_group(cache); link_block_group(cache);
list_add_tail(&cache->bg_list, &trans->new_bgs); list_add_tail(&cache->bg_list, &trans->new_bgs);
......
...@@ -293,28 +293,27 @@ int btrfs_init_space_info(struct btrfs_fs_info *fs_info) ...@@ -293,28 +293,27 @@ int btrfs_init_space_info(struct btrfs_fs_info *fs_info)
return ret; return ret;
} }
void btrfs_update_space_info(struct btrfs_fs_info *info, u64 flags, void btrfs_add_bg_to_space_info(struct btrfs_fs_info *info,
u64 total_bytes, u64 bytes_used, struct btrfs_block_group *block_group,
u64 bytes_readonly, u64 bytes_zone_unusable, struct btrfs_space_info **space_info)
bool active, struct btrfs_space_info **space_info)
{ {
struct btrfs_space_info *found; struct btrfs_space_info *found;
int factor; int factor;
factor = btrfs_bg_type_to_factor(flags); factor = btrfs_bg_type_to_factor(block_group->flags);
found = btrfs_find_space_info(info, flags); found = btrfs_find_space_info(info, block_group->flags);
ASSERT(found); ASSERT(found);
spin_lock(&found->lock); spin_lock(&found->lock);
found->total_bytes += total_bytes; found->total_bytes += block_group->length;
if (active) if (block_group->zone_is_active)
found->active_total_bytes += total_bytes; found->active_total_bytes += block_group->length;
found->disk_total += total_bytes * factor; found->disk_total += block_group->length * factor;
found->bytes_used += bytes_used; found->bytes_used += block_group->used;
found->disk_used += bytes_used * factor; found->disk_used += block_group->used * factor;
found->bytes_readonly += bytes_readonly; found->bytes_readonly += block_group->bytes_super;
found->bytes_zone_unusable += bytes_zone_unusable; found->bytes_zone_unusable += block_group->zone_unusable;
if (total_bytes > 0) if (block_group->length > 0)
found->full = 0; found->full = 0;
btrfs_try_granting_tickets(info, found); btrfs_try_granting_tickets(info, found);
spin_unlock(&found->lock); spin_unlock(&found->lock);
......
...@@ -123,10 +123,9 @@ DECLARE_SPACE_INFO_UPDATE(bytes_may_use, "space_info"); ...@@ -123,10 +123,9 @@ DECLARE_SPACE_INFO_UPDATE(bytes_may_use, "space_info");
DECLARE_SPACE_INFO_UPDATE(bytes_pinned, "pinned"); DECLARE_SPACE_INFO_UPDATE(bytes_pinned, "pinned");
int btrfs_init_space_info(struct btrfs_fs_info *fs_info); int btrfs_init_space_info(struct btrfs_fs_info *fs_info);
void btrfs_update_space_info(struct btrfs_fs_info *info, u64 flags, void btrfs_add_bg_to_space_info(struct btrfs_fs_info *info,
u64 total_bytes, u64 bytes_used, struct btrfs_block_group *block_group,
u64 bytes_readonly, u64 bytes_zone_unusable, struct btrfs_space_info **space_info);
bool active, struct btrfs_space_info **space_info);
void btrfs_update_space_info_chunk_size(struct btrfs_space_info *space_info, void btrfs_update_space_info_chunk_size(struct btrfs_space_info *space_info,
u64 chunk_size); u64 chunk_size);
struct btrfs_space_info *btrfs_find_space_info(struct btrfs_fs_info *info, struct btrfs_space_info *btrfs_find_space_info(struct btrfs_fs_info *info,
......
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