Commit 158da513 authored by David Sterba's avatar David Sterba

btrfs: refactor helper for bg flags to name conversion

The helper lacks the btrfs_ prefix and the parameter is the raw
blockgroup type, so none of the callers has to do the flags -> index
conversion.
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent e3ecdb3f
...@@ -10146,7 +10146,6 @@ void btrfs_add_raid_kobjects(struct btrfs_fs_info *fs_info) ...@@ -10146,7 +10146,6 @@ void btrfs_add_raid_kobjects(struct btrfs_fs_info *fs_info)
struct btrfs_space_info *space_info; struct btrfs_space_info *space_info;
struct raid_kobject *rkobj; struct raid_kobject *rkobj;
LIST_HEAD(list); LIST_HEAD(list);
int index;
int ret = 0; int ret = 0;
spin_lock(&fs_info->pending_raid_kobjs_lock); spin_lock(&fs_info->pending_raid_kobjs_lock);
...@@ -10155,10 +10154,9 @@ void btrfs_add_raid_kobjects(struct btrfs_fs_info *fs_info) ...@@ -10155,10 +10154,9 @@ void btrfs_add_raid_kobjects(struct btrfs_fs_info *fs_info)
list_for_each_entry(rkobj, &list, list) { list_for_each_entry(rkobj, &list, list) {
space_info = __find_space_info(fs_info, rkobj->flags); space_info = __find_space_info(fs_info, rkobj->flags);
index = btrfs_bg_flags_to_raid_index(rkobj->flags);
ret = kobject_add(&rkobj->kobj, &space_info->kobj, ret = kobject_add(&rkobj->kobj, &space_info->kobj,
"%s", get_raid_name(index)); "%s", btrfs_bg_type_to_raid_name(rkobj->flags));
if (ret) { if (ret) {
kobject_put(&rkobj->kobj); kobject_put(&rkobj->kobj);
break; break;
......
...@@ -123,12 +123,14 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = { ...@@ -123,12 +123,14 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
}, },
}; };
const char *get_raid_name(enum btrfs_raid_types type) const char *btrfs_bg_type_to_raid_name(u64 flags)
{ {
if (type >= BTRFS_NR_RAID_TYPES) const int index = btrfs_bg_flags_to_raid_index(flags);
if (index >= BTRFS_NR_RAID_TYPES)
return NULL; return NULL;
return btrfs_raid_array[type].raid_name; return btrfs_raid_array[index].raid_name;
} }
/* /*
...@@ -3926,11 +3928,9 @@ static void describe_balance_args(struct btrfs_balance_args *bargs, char *buf, ...@@ -3926,11 +3928,9 @@ static void describe_balance_args(struct btrfs_balance_args *bargs, char *buf,
bp += ret; \ bp += ret; \
} while (0) } while (0)
if (flags & BTRFS_BALANCE_ARGS_CONVERT) { if (flags & BTRFS_BALANCE_ARGS_CONVERT)
int index = btrfs_bg_flags_to_raid_index(bargs->target); CHECK_APPEND_1ARG("convert=%s,",
btrfs_bg_type_to_raid_name(bargs->target));
CHECK_APPEND_1ARG("convert=%s,", get_raid_name(index));
}
if (flags & BTRFS_BALANCE_ARGS_SOFT) if (flags & BTRFS_BALANCE_ARGS_SOFT)
CHECK_APPEND_NOARG("soft,"); CHECK_APPEND_NOARG("soft,");
...@@ -4088,29 +4088,23 @@ int btrfs_balance(struct btrfs_fs_info *fs_info, ...@@ -4088,29 +4088,23 @@ int btrfs_balance(struct btrfs_fs_info *fs_info,
allowed |= btrfs_raid_array[i].bg_flag; allowed |= btrfs_raid_array[i].bg_flag;
if (validate_convert_profile(&bctl->data, allowed)) { if (validate_convert_profile(&bctl->data, allowed)) {
int index = btrfs_bg_flags_to_raid_index(bctl->data.target);
btrfs_err(fs_info, btrfs_err(fs_info,
"balance: invalid convert data profile %s", "balance: invalid convert data profile %s",
get_raid_name(index)); btrfs_bg_type_to_raid_name(bctl->data.target));
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
if (validate_convert_profile(&bctl->meta, allowed)) { if (validate_convert_profile(&bctl->meta, allowed)) {
int index = btrfs_bg_flags_to_raid_index(bctl->meta.target);
btrfs_err(fs_info, btrfs_err(fs_info,
"balance: invalid convert metadata profile %s", "balance: invalid convert metadata profile %s",
get_raid_name(index)); btrfs_bg_type_to_raid_name(bctl->meta.target));
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
if (validate_convert_profile(&bctl->sys, allowed)) { if (validate_convert_profile(&bctl->sys, allowed)) {
int index = btrfs_bg_flags_to_raid_index(bctl->sys.target);
btrfs_err(fs_info, btrfs_err(fs_info,
"balance: invalid convert system profile %s", "balance: invalid convert system profile %s",
get_raid_name(index)); btrfs_bg_type_to_raid_name(bctl->sys.target));
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
...@@ -4159,12 +4153,10 @@ int btrfs_balance(struct btrfs_fs_info *fs_info, ...@@ -4159,12 +4153,10 @@ int btrfs_balance(struct btrfs_fs_info *fs_info,
if (btrfs_get_num_tolerated_disk_barrier_failures(meta_target) < if (btrfs_get_num_tolerated_disk_barrier_failures(meta_target) <
btrfs_get_num_tolerated_disk_barrier_failures(data_target)) { btrfs_get_num_tolerated_disk_barrier_failures(data_target)) {
int meta_index = btrfs_bg_flags_to_raid_index(meta_target);
int data_index = btrfs_bg_flags_to_raid_index(data_target);
btrfs_warn(fs_info, btrfs_warn(fs_info,
"balance: metadata profile %s has lower redundancy than data profile %s", "balance: metadata profile %s has lower redundancy than data profile %s",
get_raid_name(meta_index), get_raid_name(data_index)); btrfs_bg_type_to_raid_name(meta_target),
btrfs_bg_type_to_raid_name(data_target));
} }
ret = insert_balance_item(fs_info, bctl); ret = insert_balance_item(fs_info, bctl);
......
...@@ -556,8 +556,6 @@ static inline enum btrfs_raid_types btrfs_bg_flags_to_raid_index(u64 flags) ...@@ -556,8 +556,6 @@ static inline enum btrfs_raid_types btrfs_bg_flags_to_raid_index(u64 flags)
return BTRFS_RAID_SINGLE; /* BTRFS_BLOCK_GROUP_SINGLE */ return BTRFS_RAID_SINGLE; /* BTRFS_BLOCK_GROUP_SINGLE */
} }
const char *get_raid_name(enum btrfs_raid_types type);
void btrfs_commit_device_sizes(struct btrfs_transaction *trans); void btrfs_commit_device_sizes(struct btrfs_transaction *trans);
struct list_head *btrfs_get_fs_uuids(void); struct list_head *btrfs_get_fs_uuids(void);
...@@ -567,6 +565,7 @@ bool btrfs_check_rw_degradable(struct btrfs_fs_info *fs_info, ...@@ -567,6 +565,7 @@ bool btrfs_check_rw_degradable(struct btrfs_fs_info *fs_info,
struct btrfs_device *failing_dev); struct btrfs_device *failing_dev);
int btrfs_bg_type_to_factor(u64 flags); int btrfs_bg_type_to_factor(u64 flags);
const char *btrfs_bg_type_to_raid_name(u64 flags);
int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info); int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info);
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment