mirror of
https://github.com/kdave/btrfs-progs
synced 2025-04-01 22:48:06 +00:00
btrfs-progs: make "btrfs filesystem df" command show upper case profile
[BUG] Since commitdad03fac3b
("btrfs-progs: switch btrfs_group_profile_str to use raid table"), fstests/btrfs/023 and btrfs/151 will always fail. The failure of btrfs/151 explains the reason pretty well: btrfs/151 1s ... - output mismatch --- tests/btrfs/151.out 2019-10-22 15:18:14.068965341 +0800 +++ ~/xfstests-dev/results//btrfs/151.out.bad 2021-11-02 17:13:43.879999994 +0800 @@ -1,2 +1,2 @@ QA output created by 151 -Data, RAID1 +Data, raid1 ... (Run 'diff -u ~/xfstests-dev/tests/btrfs/151.out ~/xfstests-dev/results//btrfs/151.out.bad' to see the entire diff) [CAUSE] Commitdad03fac3b
("btrfs-progs: switch btrfs_group_profile_str to use raid table") will use btrfs_raid_array[index].raid_name, which is all lower case. [FIX] There is no need to bring such output format change. So here we split the btrfs_raid_attr::raid_name[] into upper_name[] and lower_name[], and make upper and lower case helpers for callers to use. Now there are several types of callers referring to lower_name and upper_name: - parse_bg_profile() It uses strcasecmp(), either case would be fine. - btrfs_group_profile_str() Originally it uses upper case for all profiles except "single". Now unified to upper case. - sprint_profiles() It uses lower case. - bg_flags_to_str() It uses upper case. Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
5bee5c99bf
commit
b1c944657c
@ -269,7 +269,7 @@ int parse_bg_profile(const char *profile, u64 *flags)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) {
|
for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) {
|
||||||
if (strcasecmp(btrfs_raid_array[i].raid_name, profile) == 0) {
|
if (strcasecmp(btrfs_raid_array[i].upper_name, profile) == 0) {
|
||||||
*flags |= btrfs_raid_array[i].bg_flag;
|
*flags |= btrfs_raid_array[i].bg_flag;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1032,10 +1032,10 @@ const char* btrfs_group_profile_str(u64 flag)
|
|||||||
|
|
||||||
flag &= ~(BTRFS_BLOCK_GROUP_TYPE_MASK | BTRFS_BLOCK_GROUP_RESERVED);
|
flag &= ~(BTRFS_BLOCK_GROUP_TYPE_MASK | BTRFS_BLOCK_GROUP_RESERVED);
|
||||||
if (flag & ~BTRFS_BLOCK_GROUP_PROFILE_MASK)
|
if (flag & ~BTRFS_BLOCK_GROUP_PROFILE_MASK)
|
||||||
return "unknown";
|
return "UNKNOWN";
|
||||||
|
|
||||||
index = btrfs_bg_flags_to_raid_index(flag);
|
index = btrfs_bg_flags_to_raid_index(flag);
|
||||||
return btrfs_raid_array[index].raid_name;
|
return btrfs_raid_array[index].upper_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 div_factor(u64 num, int factor)
|
u64 div_factor(u64 num, int factor)
|
||||||
@ -1260,14 +1260,14 @@ static char *sprint_profiles(u64 profiles)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
for (i = 0; i < BTRFS_NR_RAID_TYPES; i++)
|
for (i = 0; i < BTRFS_NR_RAID_TYPES; i++)
|
||||||
maxlen += strlen(btrfs_raid_array[i].raid_name) + 2;
|
maxlen += strlen(btrfs_raid_array[i].lower_name) + 2;
|
||||||
|
|
||||||
ptr = calloc(1, maxlen);
|
ptr = calloc(1, maxlen);
|
||||||
if (!ptr)
|
if (!ptr)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (profiles & BTRFS_AVAIL_ALLOC_BIT_SINGLE)
|
if (profiles & BTRFS_AVAIL_ALLOC_BIT_SINGLE)
|
||||||
strcat(ptr, btrfs_raid_array[BTRFS_RAID_SINGLE].raid_name);
|
strcat(ptr, btrfs_raid_array[BTRFS_RAID_SINGLE].lower_name);
|
||||||
|
|
||||||
for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) {
|
for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) {
|
||||||
if (!(btrfs_raid_array[i].bg_flag & profiles))
|
if (!(btrfs_raid_array[i].bg_flag & profiles))
|
||||||
@ -1275,7 +1275,7 @@ static char *sprint_profiles(u64 profiles)
|
|||||||
|
|
||||||
if (ptr[0])
|
if (ptr[0])
|
||||||
strcat(ptr, ", ");
|
strcat(ptr, ", ");
|
||||||
strcat(ptr, btrfs_raid_array[i].raid_name);
|
strcat(ptr, btrfs_raid_array[i].lower_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ptr;
|
return ptr;
|
||||||
|
@ -188,18 +188,13 @@ static void bg_flags_to_str(u64 flags, char *ret)
|
|||||||
snprintf(profile, BG_FLAG_STRING_LEN, "UNKNOWN.0x%llx",
|
snprintf(profile, BG_FLAG_STRING_LEN, "UNKNOWN.0x%llx",
|
||||||
flags & BTRFS_BLOCK_GROUP_PROFILE_MASK);
|
flags & BTRFS_BLOCK_GROUP_PROFILE_MASK);
|
||||||
} else {
|
} else {
|
||||||
int i;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Special handing for SINGLE profile, we don't output "SINGLE"
|
* Special handing for SINGLE profile, we don't output "SINGLE"
|
||||||
* for SINGLE profile, since there is no such bit for it.
|
* for SINGLE profile, since there is no such bit for it.
|
||||||
* Thus here we only fill @profile if it's not single.
|
* Thus here we only fill @profile if it's not single.
|
||||||
*/
|
*/
|
||||||
if (strncmp(name, "single", strlen("single")) != 0)
|
if (strncmp(name, "SINGLE", strlen("SINGLE")) != 0)
|
||||||
strncpy(profile, name, BG_FLAG_STRING_LEN);
|
strncpy(profile, name, BG_FLAG_STRING_LEN);
|
||||||
|
|
||||||
for (i = 0; i < BG_FLAG_STRING_LEN && profile[i]; i++)
|
|
||||||
profile[i] = toupper(profile[i]);
|
|
||||||
}
|
}
|
||||||
if (profile[0]) {
|
if (profile[0]) {
|
||||||
strncat(ret, "|", BG_FLAG_STRING_LEN);
|
strncat(ret, "|", BG_FLAG_STRING_LEN);
|
||||||
|
@ -42,7 +42,8 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
|
|||||||
.devs_increment = 2,
|
.devs_increment = 2,
|
||||||
.ncopies = 2,
|
.ncopies = 2,
|
||||||
.nparity = 0,
|
.nparity = 0,
|
||||||
.raid_name = "raid10",
|
.lower_name = "raid10",
|
||||||
|
.upper_name = "RAID10",
|
||||||
.bg_flag = BTRFS_BLOCK_GROUP_RAID10,
|
.bg_flag = BTRFS_BLOCK_GROUP_RAID10,
|
||||||
.mindev_error = BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET,
|
.mindev_error = BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET,
|
||||||
},
|
},
|
||||||
@ -55,7 +56,8 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
|
|||||||
.devs_increment = 2,
|
.devs_increment = 2,
|
||||||
.ncopies = 2,
|
.ncopies = 2,
|
||||||
.nparity = 0,
|
.nparity = 0,
|
||||||
.raid_name = "raid1",
|
.lower_name = "raid1",
|
||||||
|
.upper_name = "RAID1",
|
||||||
.bg_flag = BTRFS_BLOCK_GROUP_RAID1,
|
.bg_flag = BTRFS_BLOCK_GROUP_RAID1,
|
||||||
.mindev_error = BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET,
|
.mindev_error = BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET,
|
||||||
},
|
},
|
||||||
@ -68,7 +70,8 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
|
|||||||
.devs_increment = 3,
|
.devs_increment = 3,
|
||||||
.ncopies = 3,
|
.ncopies = 3,
|
||||||
.nparity = 0,
|
.nparity = 0,
|
||||||
.raid_name = "raid1c3",
|
.lower_name = "raid1c3",
|
||||||
|
.upper_name = "RAID1C3",
|
||||||
.bg_flag = BTRFS_BLOCK_GROUP_RAID1C3,
|
.bg_flag = BTRFS_BLOCK_GROUP_RAID1C3,
|
||||||
.mindev_error = BTRFS_ERROR_DEV_RAID1C3_MIN_NOT_MET,
|
.mindev_error = BTRFS_ERROR_DEV_RAID1C3_MIN_NOT_MET,
|
||||||
},
|
},
|
||||||
@ -81,7 +84,8 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
|
|||||||
.devs_increment = 4,
|
.devs_increment = 4,
|
||||||
.ncopies = 4,
|
.ncopies = 4,
|
||||||
.nparity = 0,
|
.nparity = 0,
|
||||||
.raid_name = "raid1c4",
|
.lower_name = "raid1c4",
|
||||||
|
.upper_name = "RAID1C4",
|
||||||
.bg_flag = BTRFS_BLOCK_GROUP_RAID1C4,
|
.bg_flag = BTRFS_BLOCK_GROUP_RAID1C4,
|
||||||
.mindev_error = BTRFS_ERROR_DEV_RAID1C4_MIN_NOT_MET,
|
.mindev_error = BTRFS_ERROR_DEV_RAID1C4_MIN_NOT_MET,
|
||||||
},
|
},
|
||||||
@ -94,7 +98,8 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
|
|||||||
.devs_increment = 1,
|
.devs_increment = 1,
|
||||||
.ncopies = 2,
|
.ncopies = 2,
|
||||||
.nparity = 0,
|
.nparity = 0,
|
||||||
.raid_name = "dup",
|
.lower_name = "dup",
|
||||||
|
.upper_name = "DUP",
|
||||||
.bg_flag = BTRFS_BLOCK_GROUP_DUP,
|
.bg_flag = BTRFS_BLOCK_GROUP_DUP,
|
||||||
.mindev_error = 0,
|
.mindev_error = 0,
|
||||||
},
|
},
|
||||||
@ -107,7 +112,8 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
|
|||||||
.devs_increment = 1,
|
.devs_increment = 1,
|
||||||
.ncopies = 1,
|
.ncopies = 1,
|
||||||
.nparity = 0,
|
.nparity = 0,
|
||||||
.raid_name = "raid0",
|
.lower_name = "raid0",
|
||||||
|
.upper_name = "RAID0",
|
||||||
.bg_flag = BTRFS_BLOCK_GROUP_RAID0,
|
.bg_flag = BTRFS_BLOCK_GROUP_RAID0,
|
||||||
.mindev_error = 0,
|
.mindev_error = 0,
|
||||||
},
|
},
|
||||||
@ -120,7 +126,8 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
|
|||||||
.devs_increment = 1,
|
.devs_increment = 1,
|
||||||
.ncopies = 1,
|
.ncopies = 1,
|
||||||
.nparity = 0,
|
.nparity = 0,
|
||||||
.raid_name = "single",
|
.lower_name = "single",
|
||||||
|
.upper_name = "SINGLE",
|
||||||
.bg_flag = 0,
|
.bg_flag = 0,
|
||||||
.mindev_error = 0,
|
.mindev_error = 0,
|
||||||
},
|
},
|
||||||
@ -133,7 +140,8 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
|
|||||||
.devs_increment = 1,
|
.devs_increment = 1,
|
||||||
.ncopies = 1,
|
.ncopies = 1,
|
||||||
.nparity = 1,
|
.nparity = 1,
|
||||||
.raid_name = "raid5",
|
.lower_name = "raid5",
|
||||||
|
.upper_name = "RAID5",
|
||||||
.bg_flag = BTRFS_BLOCK_GROUP_RAID5,
|
.bg_flag = BTRFS_BLOCK_GROUP_RAID5,
|
||||||
.mindev_error = BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET,
|
.mindev_error = BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET,
|
||||||
},
|
},
|
||||||
@ -146,7 +154,8 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
|
|||||||
.devs_increment = 1,
|
.devs_increment = 1,
|
||||||
.ncopies = 1,
|
.ncopies = 1,
|
||||||
.nparity = 2,
|
.nparity = 2,
|
||||||
.raid_name = "raid6",
|
.lower_name = "raid6",
|
||||||
|
.upper_name = "RAID6",
|
||||||
.bg_flag = BTRFS_BLOCK_GROUP_RAID6,
|
.bg_flag = BTRFS_BLOCK_GROUP_RAID6,
|
||||||
.mindev_error = BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET,
|
.mindev_error = BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET,
|
||||||
},
|
},
|
||||||
@ -207,7 +216,7 @@ const char *btrfs_bg_type_to_raid_name(u64 flags)
|
|||||||
if (index >= BTRFS_NR_RAID_TYPES)
|
if (index >= BTRFS_NR_RAID_TYPES)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return btrfs_raid_array[index].raid_name;
|
return btrfs_raid_array[index].upper_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
int btrfs_bg_type_to_tolerated_failures(u64 flags)
|
int btrfs_bg_type_to_tolerated_failures(u64 flags)
|
||||||
|
@ -134,7 +134,8 @@ struct btrfs_raid_attr {
|
|||||||
int nparity; /* number of stripes worth of bytes to store
|
int nparity; /* number of stripes worth of bytes to store
|
||||||
* parity information */
|
* parity information */
|
||||||
int mindev_error; /* error code if min devs requisite is unmet */
|
int mindev_error; /* error code if min devs requisite is unmet */
|
||||||
const char raid_name[8]; /* name of the raid */
|
const char lower_name[8]; /* name of the profile in lower case*/
|
||||||
|
const char upper_name[8]; /* name of the profile in upper case*/
|
||||||
u64 bg_flag; /* block group flag of the raid */
|
u64 bg_flag; /* block group flag of the raid */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user