btrfs-progs: qgroup show: report unrecognized format of sort string

Let the parsing function distinguish between parsing and other errors
and use that in qgroup show.

Signed-off-by: David Sterba <dsterba@suse.com>
master
David Sterba 2019-03-04 17:00:06 +01:00
parent 88ab0824a2
commit 9a1550bb2d
2 changed files with 13 additions and 2 deletions

View File

@ -346,6 +346,10 @@ static int cmd_qgroup_show(int argc, char **argv)
error("cannot parse sort string: %m");
return 1;
}
if (ret > 0) {
error("unrecognized format of sort string");
return 1;
}
break;
case GETOPT_VAL_SYNC:
sync = 1;

View File

@ -1195,6 +1195,13 @@ int btrfs_show_qgroups(int fd,
return ret;
}
/*
* Parse sort string and allocate new comparator.
*
* Return: 0 no errors while parsing
* 1 parse error
* <0 other errors
*/
int btrfs_qgroup_parse_sort_string(const char *opt_arg,
struct btrfs_qgroup_comparer_set **comps)
{
@ -1232,7 +1239,7 @@ int btrfs_qgroup_parse_sort_string(const char *opt_arg,
}
if (flag == 0) {
ret = -1;
ret = 1;
goto out;
} else {
if (*p == '+') {
@ -1246,7 +1253,7 @@ int btrfs_qgroup_parse_sort_string(const char *opt_arg,
what_to_sort = btrfs_qgroup_get_sort_item(p);
if (what_to_sort < 0) {
ret = -1;
ret = 1;
goto out;
}
btrfs_qgroup_setup_comparer(comps, what_to_sort, order);