btrfs-progs: add a btrfs_delete_and_free_root helper
The free space tree code already does this, but we need it for cleaning up per block group roots. Abstract this code out into a helper so that we can use it in multiple places in the future. Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
e33738306c
commit
c4164edeb5
|
@ -2399,6 +2399,31 @@ int btrfs_set_buffer_uptodate(struct extent_buffer *eb)
|
|||
return set_extent_buffer_uptodate(eb);
|
||||
}
|
||||
|
||||
int btrfs_delete_and_free_root(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_root *root)
|
||||
{
|
||||
struct btrfs_fs_info *fs_info = root->fs_info;
|
||||
struct btrfs_root *tree_root = fs_info->tree_root;
|
||||
int ret;
|
||||
|
||||
ret = btrfs_del_root(trans, tree_root, &root->root_key);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
list_del(&root->dirty_list);
|
||||
ret = clean_tree_block(root->node);
|
||||
if (ret)
|
||||
return ret;
|
||||
ret = btrfs_free_tree_block(trans, root, root->node, 0, 1);
|
||||
if (ret)
|
||||
return ret;
|
||||
rb_erase(&root->rb_node, &fs_info->global_roots_tree);
|
||||
free_extent_buffer(root->node);
|
||||
free_extent_buffer(root->commit_root);
|
||||
kfree(root);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_fs_info *fs_info,
|
||||
u64 objectid)
|
||||
|
|
|
@ -221,6 +221,8 @@ int btrfs_fs_roots_compare_roots(struct rb_node *node1, struct rb_node *node2);
|
|||
struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_fs_info *fs_info,
|
||||
u64 objectid);
|
||||
int btrfs_delete_and_free_root(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_root *root);
|
||||
struct btrfs_root *btrfs_csum_root(struct btrfs_fs_info *fs_info, u64 bytenr);
|
||||
struct btrfs_root *btrfs_extent_root(struct btrfs_fs_info *fs_inf, u64 bytenr);
|
||||
struct btrfs_root *btrfs_global_root(struct btrfs_fs_info *fs_info,
|
||||
|
|
|
@ -1257,27 +1257,9 @@ int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info)
|
|||
if (ret)
|
||||
goto abort;
|
||||
|
||||
ret = btrfs_del_root(trans, tree_root, &free_space_root->root_key);
|
||||
if (ret)
|
||||
goto abort;
|
||||
|
||||
list_del(&free_space_root->dirty_list);
|
||||
|
||||
ret = clean_tree_block(free_space_root->node);
|
||||
if (ret)
|
||||
goto abort;
|
||||
ret = btrfs_free_tree_block(trans, free_space_root,
|
||||
free_space_root->node, 0, 1);
|
||||
if (ret)
|
||||
goto abort;
|
||||
|
||||
rb_erase(&free_space_root->rb_node, &fs_info->global_roots_tree);
|
||||
free_extent_buffer(free_space_root->node);
|
||||
free_extent_buffer(free_space_root->commit_root);
|
||||
kfree(free_space_root);
|
||||
|
||||
ret = btrfs_commit_transaction(trans, tree_root);
|
||||
|
||||
ret = btrfs_delete_and_free_root(trans, free_space_root);
|
||||
if (!ret)
|
||||
ret = btrfs_commit_transaction(trans, tree_root);
|
||||
abort:
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue