@@ -187,6 +187,21 @@ static int add_block_group(struct btrfs_block_group *block_group)
return 0;
}
+/* This removes block group from fs_info rb tree */
+static void del_block_group(struct btrfs_block_group *block_group)
+{
+ struct btrfs_fs_info *fs_info = block_group->fs_info;
+
+ spin_lock(&fs_info->block_group_cache_lock);
+ rb_erase(&block_group->cache_node,
+ &fs_info->block_group_cache_tree);
+ RB_CLEAR_NODE(&block_group->cache_node);
+
+ if (fs_info->first_logical_byte == block_group->start)
+ fs_info->first_logical_byte = (u64)-1;
+ spin_unlock(&fs_info->block_group_cache_lock);
+}
+
/*
* This will return the block group at or after bytenr if contains is 0, else
* it will return the block group that contains the bytenr
@@ -1008,18 +1023,10 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
btrfs_release_path(path);
}
- spin_lock(&fs_info->block_group_cache_lock);
- rb_erase(&block_group->cache_node,
- &fs_info->block_group_cache_tree);
- RB_CLEAR_NODE(&block_group->cache_node);
-
+ del_block_group(block_group);
/* Once for the block groups rbtree */
btrfs_put_block_group(block_group);
- if (fs_info->first_logical_byte == block_group->start)
- fs_info->first_logical_byte = (u64)-1;
- spin_unlock(&fs_info->block_group_cache_lock);
-
down_write(&block_group->space_info->groups_sem);
/*
* we must use list_del_init so people can check to see if they
Extra the common code into a function, del_block_group(), to delete block group from fs_info rb tree. The function will remove it from rb tree, and update the logical bytenr hint for fs_info. There is only one caller for now, btrfs_remove_block_group(). Signed-off-by: Qu Wenruo <wqu@suse.com> --- fs/btrfs/block-group.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)