diff options
author | Qu Wenruo <quwenruo@cn.fujitsu.com> | 2015-07-07 16:15:23 +0800 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2015-07-10 14:29:52 +0200 |
commit | 9d25a273b0a6f9c3cbb540c452781e4e2be3824d (patch) | |
tree | 98abce502f789fd728ba611b72e8457b59defeaa | |
parent | de70c9aed8a14b1b477a79bf6c7e2a06a2623988 (diff) |
btrfs-progs: extent-tree: Introduce free_block_group_item function
This function is used to free a block group item. It must be called
with all the space in the block group pinned. Or there is a possibility
that tree blocks be allocated into the range.
The function is used for later block group/chunk free function.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r-- | extent-tree.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/extent-tree.c b/extent-tree.c index c24af6a0..d002a4f8 100644 --- a/extent-tree.c +++ b/extent-tree.c @@ -3448,6 +3448,42 @@ int btrfs_update_block_group(struct btrfs_trans_handle *trans, } /* + * Just remove a block group item in extent tree + * Caller should ensure the block group is empty and all space is pinned. + * Or new tree block/data may be allocated into it. + */ +static int free_block_group_item(struct btrfs_trans_handle *trans, + struct btrfs_fs_info *fs_info, + u64 bytenr, u64 len) +{ + struct btrfs_path *path; + struct btrfs_key key; + struct btrfs_root *root = fs_info->extent_root; + int ret = 0; + + key.objectid = bytenr; + key.offset = len; + key.type = BTRFS_BLOCK_GROUP_ITEM_KEY; + + path = btrfs_alloc_path(); + if (!path) + return -ENOMEM; + + ret = btrfs_search_slot(trans, root, &key, path, -1, 1); + if (ret > 0) { + ret = -ENOENT; + goto out; + } + if (ret < 0) + goto out; + + ret = btrfs_del_item(trans, root, path); +out: + btrfs_free_path(path); + return ret; +} + +/* * Fixup block accounting. The initial block accounting created by * make_block_groups isn't accuracy in this case. */ |