btrfs-progs: factor out profile parsing to common utils
There are some duplicate parsers of the profile names, factor out the one from balance to the common code. Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
dd3b931b1c
commit
31df7dc295
|
@ -32,6 +32,7 @@
|
|||
#include "common/open-utils.h"
|
||||
#include "cmds/commands.h"
|
||||
#include "common/utils.h"
|
||||
#include "common/parse-utils.h"
|
||||
#include "common/help.h"
|
||||
|
||||
static const char * const balance_cmd_group_usage[] = {
|
||||
|
@ -42,21 +43,18 @@ static const char * const balance_cmd_group_usage[] = {
|
|||
|
||||
static int parse_one_profile(const char *profile, u64 *flags)
|
||||
{
|
||||
int i;
|
||||
int ret;
|
||||
u64 tmp = 0;
|
||||
|
||||
for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) {
|
||||
if (strcasecmp(btrfs_raid_array[i].raid_name, profile) == 0) {
|
||||
u64 tmp;
|
||||
|
||||
tmp = btrfs_raid_array[i].bg_flag;
|
||||
if (tmp == 0)
|
||||
tmp = BTRFS_AVAIL_ALLOC_BIT_SINGLE;
|
||||
*flags |= tmp;
|
||||
return 0;
|
||||
}
|
||||
ret = parse_bg_profile(profile, &tmp);
|
||||
if (ret) {
|
||||
error("unknown profile: %s", profile);
|
||||
return 1;
|
||||
}
|
||||
error("unknown profile: %s", profile);
|
||||
return 1;
|
||||
if (tmp == 0)
|
||||
tmp = BTRFS_AVAIL_ALLOC_BIT_SINGLE;
|
||||
*flags |= tmp;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int parse_profiles(char *profiles, u64 *flags)
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <ctype.h>
|
||||
#include "common/parse-utils.h"
|
||||
#include "common/messages.h"
|
||||
#include "kernel-shared/volumes.h"
|
||||
|
||||
int parse_u64(const char *str, u64 *result)
|
||||
{
|
||||
|
@ -241,3 +242,21 @@ int fls64(u64 x)
|
|||
return 64 - i;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse string description of block group profile and set that bit in @flags.
|
||||
* Return 1 if the profile is not valid, otherwise 0.
|
||||
*
|
||||
* String matched against btrfs_raid_array, case insensitive.
|
||||
*/
|
||||
int parse_bg_profile(const char *profile, u64 *flags)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) {
|
||||
if (strcasecmp(btrfs_raid_array[i].raid_name, profile) == 0) {
|
||||
*flags |= btrfs_raid_array[i].bg_flag;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ int parse_u64(const char *str, u64 *result);
|
|||
int parse_range_u32(const char *range, u32 *start, u32 *end);
|
||||
int parse_range(const char *range, u64 *start, u64 *end);
|
||||
int parse_range_strict(const char *range, u64 *start, u64 *end);
|
||||
int parse_bg_profile(const char *profile, u64 *flags);
|
||||
int fls64(u64 x);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue