@@ -3940,6 +3940,10 @@ static const char *alloc_name(u64 flags)
};
}
+static int create_priority_trees(struct btrfs_fs_info *fs_info,
+ struct btrfs_space_info *space_info);
+static void remove_priority_trees(struct btrfs_fs_info *fs_info,
+ struct btrfs_space_info *space_info);
static int create_space_info(struct btrfs_fs_info *info, u64 flags)
{
@@ -3958,8 +3962,17 @@ static int create_space_info(struct btrfs_fs_info *info, u64 flags)
return ret;
}
- for (i = 0; i < BTRFS_NR_RAID_TYPES; i++)
+ for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) {
INIT_LIST_HEAD(&space_info->block_groups[i]);
+ space_info->priority_trees[i] = RB_ROOT;
+ }
+
+ ret = create_priority_trees(info, space_info);
+ if (ret) {
+ kfree(space_info);
+ return ret;
+ }
+
init_rwsem(&space_info->groups_sem);
spin_lock_init(&space_info->lock);
space_info->flags = flags & BTRFS_BLOCK_GROUP_TYPE_MASK;
@@ -3974,6 +3987,7 @@ static int create_space_info(struct btrfs_fs_info *info, u64 flags)
alloc_name(space_info->flags));
if (ret) {
percpu_counter_destroy(&space_info->total_bytes_pinned);
+ remove_priority_trees(info, space_info);
kfree(space_info);
return ret;
}
@@ -9928,6 +9942,8 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)
space_info->bytes_may_use > 0))
dump_space_info(info, space_info, 0, 0);
list_del(&space_info->list);
+ remove_priority_trees(info, space_info);
+
for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) {
struct kobject *kobj;
kobj = space_info->block_group_kobjs[i];
@@ -11282,9 +11298,6 @@ static void remove_priority_trees(struct btrfs_fs_info *fs_info,
struct btrfs_priority_tree *pt, *next_pt;
int i;
- if (!is_priority_alloc_enabled(fs_info))
- return;
-
for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) {
root = &space_info->priority_trees[i];
rbtree_postorder_for_each_entry_safe(pt, next_pt, root, node) {
Call create_priority_trees() in create_space_info(). Call remove_priority_trees() before free of space_info. Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com> --- fs/btrfs/extent-tree.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)