btrfs-progs: fi usage: list multiple profiles type

Update the summary of 'fi usage' where the multiple profiles will be
listed by type, like:

    Multiple profiles:                 yes      (data, metadata)

The string is returned from btrfs_test_for_multiple_profiles so the
callers don't have to assemble it together from the other profile
strings.

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2020-05-04 22:03:09 +02:00
parent da7da3f661
commit 3f92fe88c3
3 changed files with 42 additions and 12 deletions

View File

@ -309,6 +309,7 @@ static int print_filesystem_usage_overall(int fd, struct chunk_info *chunkinfo,
const char *path, unsigned unit_mode) const char *path, unsigned unit_mode)
{ {
struct btrfs_ioctl_space_args *sargs = NULL; struct btrfs_ioctl_space_args *sargs = NULL;
char *tmp;
int i; int i;
int ret = 0; int ret = 0;
int width = 10; /* default 10 for human units */ int width = 10; /* default 10 for human units */
@ -492,11 +493,12 @@ static int print_filesystem_usage_overall(int fd, struct chunk_info *chunkinfo,
printf(" Global reserve:\t\t%*s\t(used: %s)\n", width, printf(" Global reserve:\t\t%*s\t(used: %s)\n", width,
pretty_size_mode(l_global_reserve, unit_mode), pretty_size_mode(l_global_reserve, unit_mode),
pretty_size_mode(l_global_reserve_used, unit_mode)); pretty_size_mode(l_global_reserve_used, unit_mode));
if (btrfs_test_for_multiple_profiles_by_fd(fd) > 0) tmp = btrfs_test_for_multiple_profiles(fd);
printf(" Multiple profiles:\t\t%*s\n", width, "YES"); if (tmp[0])
printf(" Multiple profiles:\t\t%*s\t(%s)\n", width, "yes", tmp);
else else
printf(" Multiple profiles:\t\t%*s\n", width, "no"); printf(" Multiple profiles:\t\t%*s\n", width, "no");
free(tmp);
exit: exit:

View File

@ -1755,7 +1755,8 @@ static char *sprint_profiles(u64 profiles)
} }
static int btrfs_get_string_for_multiple_profiles(int fd, char **data_ret, static int btrfs_get_string_for_multiple_profiles(int fd, char **data_ret,
char **metadata_ret, char **mixed_ret, char **system_ret) char **metadata_ret, char **mixed_ret, char **system_ret,
char **types_ret)
{ {
int ret; int ret;
int i; int i;
@ -1798,22 +1799,49 @@ static int btrfs_get_string_for_multiple_profiles(int fd, char **data_ret,
*mixed_ret = sprint_profiles(mixed_profiles); *mixed_ret = sprint_profiles(mixed_profiles);
*system_ret = sprint_profiles(system_profiles); *system_ret = sprint_profiles(system_profiles);
if (types_ret) {
*types_ret = calloc(1, 64);
if (!*types_ret)
goto out;
if (*data_ret)
strcat(*types_ret, "data");
if (*metadata_ret) {
if ((*types_ret)[0])
strcat(*types_ret, ", ");
strcat(*types_ret, "metadata");
}
if (*mixed_ret) {
if ((*types_ret)[0])
strcat(*types_ret, ", ");
strcat(*types_ret, "data+metadata");
}
if (*system_ret) {
if ((*types_ret)[0])
strcat(*types_ret, ", ");
strcat(*types_ret, "system");
}
}
out:
return *data_ret || *metadata_ret || *mixed_ret || *system_ret; return *data_ret || *metadata_ret || *mixed_ret || *system_ret;
} }
int btrfs_test_for_multiple_profiles_by_fd(int fd) /*
* Return string containing coma separated list of block group types that
* contain multiple profiles. The return value must be freed by the caller.
*/
char *btrfs_test_for_multiple_profiles(int fd)
{ {
char *data, *metadata, *system, *mixed; char *data, *metadata, *system, *mixed, *types;
int ret;
ret = btrfs_get_string_for_multiple_profiles(fd, &data, &metadata, btrfs_get_string_for_multiple_profiles(fd, &data, &metadata, &mixed,
&mixed, &system); &system, &types);
free(data); free(data);
free(metadata); free(metadata);
free(mixed); free(mixed);
free(system); free(system);
return ret; return types;
} }
int btrfs_warn_multiple_profiles(int fd) int btrfs_warn_multiple_profiles(int fd)
@ -1822,7 +1850,7 @@ int btrfs_warn_multiple_profiles(int fd)
char *data_prof, *mixed_prof, *metadata_prof, *system_prof; char *data_prof, *mixed_prof, *metadata_prof, *system_prof;
ret = btrfs_get_string_for_multiple_profiles(fd, &data_prof, ret = btrfs_get_string_for_multiple_profiles(fd, &data_prof,
&metadata_prof, &mixed_prof, &system_prof); &metadata_prof, &mixed_prof, &system_prof, NULL);
if (ret != 1) if (ret != 1)
return ret; return ret;

View File

@ -137,7 +137,7 @@ u64 rand_u64(void);
unsigned int rand_range(unsigned int upper); unsigned int rand_range(unsigned int upper);
void init_rand_seed(u64 seed); void init_rand_seed(u64 seed);
int btrfs_test_for_multiple_profiles_by_fd(int fd); char *btrfs_test_for_multiple_profiles(int fd);
int btrfs_warn_multiple_profiles(int fd); int btrfs_warn_multiple_profiles(int fd);
#endif #endif