btrfs-progs: parse profile name from the raid table

We can use the raid table to match profile names, additionally make the
test case insensitive. The single profile is not represented as a bit
and must be set manually for now.

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2021-09-03 21:36:35 +02:00
parent 7572839a74
commit d15b7b0d58

View File

@ -42,32 +42,23 @@ static const char * const balance_cmd_group_usage[] = {
static int parse_one_profile(const char *profile, u64 *flags) static int parse_one_profile(const char *profile, u64 *flags)
{ {
if (!strcmp(profile, "raid0")) { int i;
*flags |= BTRFS_BLOCK_GROUP_RAID0;
} else if (!strcmp(profile, "raid1")) { for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) {
*flags |= BTRFS_BLOCK_GROUP_RAID1; if (strcasecmp(btrfs_raid_array[i].raid_name, profile) == 0) {
} else if (!strcmp(profile, "raid1c3")) { u64 tmp;
*flags |= BTRFS_BLOCK_GROUP_RAID1C3;
} else if (!strcmp(profile, "raid1c4")) { tmp = btrfs_raid_array[i].bg_flag;
*flags |= BTRFS_BLOCK_GROUP_RAID1C4; if (tmp == 0)
} else if (!strcmp(profile, "raid10")) { tmp = BTRFS_AVAIL_ALLOC_BIT_SINGLE;
*flags |= BTRFS_BLOCK_GROUP_RAID10; *flags |= tmp;
} else if (!strcmp(profile, "raid5")) { return 0;
*flags |= BTRFS_BLOCK_GROUP_RAID5; }
} else if (!strcmp(profile, "raid6")) { }
*flags |= BTRFS_BLOCK_GROUP_RAID6;
} else if (!strcmp(profile, "dup")) {
*flags |= BTRFS_BLOCK_GROUP_DUP;
} else if (!strcmp(profile, "single")) {
*flags |= BTRFS_AVAIL_ALLOC_BIT_SINGLE;
} else {
error("unknown profile: %s", profile); error("unknown profile: %s", profile);
return 1; return 1;
} }
return 0;
}
static int parse_profiles(char *profiles, u64 *flags) static int parse_profiles(char *profiles, u64 *flags)
{ {
char *this_char; char *this_char;