btrfs-progs: add add_block_group_free_space helper

This exists in the kernel free-space-tree.c but not in progs.  We need
it to generate the free space items for new block groups, which is
needed when we start creating the free space tree in make_btrfs().

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Josef Bacik 2021-08-23 16:14:53 -04:00 committed by David Sterba
parent abc2b30443
commit 826e466028
3 changed files with 29 additions and 0 deletions

View File

@ -2816,6 +2816,8 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans,
ret = btrfs_insert_item(trans, extent_root, &key, &bgi, sizeof(bgi));
BUG_ON(ret);
add_block_group_free_space(trans, cache);
return 0;
}

View File

@ -986,6 +986,31 @@ out:
return ret;
}
int add_block_group_free_space(struct btrfs_trans_handle *trans,
struct btrfs_block_group *block_group)
{
struct btrfs_path *path;
int ret;
if (!btrfs_fs_compat_ro(trans->fs_info, FREE_SPACE_TREE))
return 0;
path = btrfs_alloc_path();
if (!path)
return -ENOMEM;
ret = add_new_free_space_info(trans, block_group, path);
if (ret)
goto out;
ret = __add_to_free_space_tree(trans, block_group, path,
block_group->start, block_group->length);
out:
btrfs_free_path(path);
if (ret)
btrfs_abort_transaction(trans, ret);
return ret;
}
int populate_free_space_tree(struct btrfs_trans_handle *trans,
struct btrfs_block_group *block_group)
{

View File

@ -34,5 +34,7 @@ int add_to_free_space_tree(struct btrfs_trans_handle *trans, u64 start,
int remove_from_free_space_tree(struct btrfs_trans_handle *trans, u64 start,
u64 size);
int btrfs_create_free_space_tree(struct btrfs_fs_info *info);
int add_block_group_free_space(struct btrfs_trans_handle *trans,
struct btrfs_block_group *block_group);
#endif