mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-05 10:29:37 +00:00
btrfs: balance: factor out convert profile validation
The validation follows the same steps for all three block group types, the existing helper validate_convert_profile can be enhanced and do more of the common things. Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
c67b38925b
commit
5ba366c399
1 changed files with 21 additions and 24 deletions
|
@ -3801,13 +3801,25 @@ static inline int balance_need_close(struct btrfs_fs_info *fs_info)
|
||||||
atomic_read(&fs_info->balance_cancel_req) == 0);
|
atomic_read(&fs_info->balance_cancel_req) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Non-zero return value signifies invalidity */
|
/*
|
||||||
static inline int validate_convert_profile(struct btrfs_balance_args *bctl_arg,
|
* Validate target profile against allowed profiles and return true if it's OK.
|
||||||
u64 allowed)
|
* Otherwise print the error message and return false.
|
||||||
|
*/
|
||||||
|
static inline int validate_convert_profile(struct btrfs_fs_info *fs_info,
|
||||||
|
const struct btrfs_balance_args *bargs,
|
||||||
|
u64 allowed, const char *type)
|
||||||
{
|
{
|
||||||
return ((bctl_arg->flags & BTRFS_BALANCE_ARGS_CONVERT) &&
|
if (!(bargs->flags & BTRFS_BALANCE_ARGS_CONVERT))
|
||||||
(!alloc_profile_is_valid(bctl_arg->target, 1) ||
|
return true;
|
||||||
(bctl_arg->target & ~allowed)));
|
|
||||||
|
/* Profile is valid and does not have bits outside of the allowed set */
|
||||||
|
if (alloc_profile_is_valid(bargs->target, 1) &&
|
||||||
|
(bargs->target & ~allowed) == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
btrfs_err(fs_info, "balance: invalid convert %s profile %s",
|
||||||
|
type, btrfs_bg_type_to_raid_name(bargs->target));
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -4023,24 +4035,9 @@ int btrfs_balance(struct btrfs_fs_info *fs_info,
|
||||||
if (num_devices >= btrfs_raid_array[i].devs_min)
|
if (num_devices >= btrfs_raid_array[i].devs_min)
|
||||||
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(fs_info, &bctl->data, allowed, "data") ||
|
||||||
btrfs_err(fs_info,
|
!validate_convert_profile(fs_info, &bctl->meta, allowed, "metadata") ||
|
||||||
"balance: invalid convert data profile %s",
|
!validate_convert_profile(fs_info, &bctl->sys, allowed, "system")) {
|
||||||
btrfs_bg_type_to_raid_name(bctl->data.target));
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
if (validate_convert_profile(&bctl->meta, allowed)) {
|
|
||||||
btrfs_err(fs_info,
|
|
||||||
"balance: invalid convert metadata profile %s",
|
|
||||||
btrfs_bg_type_to_raid_name(bctl->meta.target));
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
if (validate_convert_profile(&bctl->sys, allowed)) {
|
|
||||||
btrfs_err(fs_info,
|
|
||||||
"balance: invalid convert system profile %s",
|
|
||||||
btrfs_bg_type_to_raid_name(bctl->sys.target));
|
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue