btrfs-progs: qgroup assign: can't handle options

"qgroup assign" is considered as working without any options
from the following commit.

commit 176aeca9a148 ("btrfs-progs: add getopt stubs where needed")

However, we can pass options to this command.

* actual result

   ==================================================
   # ./btrfs qgroup assign --rescan 0/260 1/261 /btrfs
   btrfs qgroup assign: unrecognized option '--rescan'
   usage: btrfs qgroup assign [options] <src> <dst> <path>

       Assign SRC as the child qgroup of DST

       --rescan       schedule qutoa rescan if needed
       --no-rescan

   ==================================================

* expected result

   ==================================================
   # ./btrfs qgroup assign --rescan 0/260 1/261 /btrfs
   #
   ==================================================

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Satoru Takeuchi 2016-03-18 10:35:15 +09:00 committed by David Sterba
parent f4f4fb2061
commit 208ba29007

View File

@ -32,7 +32,8 @@ static const char * const qgroup_cmd_group_usage[] = {
NULL NULL
}; };
static int _cmd_qgroup_assign(int assign, int argc, char **argv) static int _cmd_qgroup_assign(int assign, int argc, char **argv,
const char * const *usage_str)
{ {
int ret = 0; int ret = 0;
int fd; int fd;
@ -41,28 +42,33 @@ static int _cmd_qgroup_assign(int assign, int argc, char **argv)
struct btrfs_ioctl_qgroup_assign_args args; struct btrfs_ioctl_qgroup_assign_args args;
DIR *dirstream = NULL; DIR *dirstream = NULL;
while (1) { if (assign) {
enum { GETOPT_VAL_RESCAN = 256 }; while (1) {
static const struct option long_options[] = { enum { GETOPT_VAL_RESCAN = 256 };
{ "rescan", no_argument, NULL, GETOPT_VAL_RESCAN }, static const struct option long_options[] = {
{ NULL, 0, NULL, 0 } { "rescan", no_argument, NULL,
}; GETOPT_VAL_RESCAN },
int c = getopt_long(argc, argv, "", long_options, NULL); { NULL, 0, NULL, 0 }
};
int c = getopt_long(argc, argv, "", long_options, NULL);
if (c < 0) if (c < 0)
break; break;
switch (c) { switch (c) {
case GETOPT_VAL_RESCAN: case GETOPT_VAL_RESCAN:
rescan = 1; rescan = 1;
break; break;
default: default:
/* Usage printed by the caller */ /* Usage printed by the caller */
return -1; return -1;
}
} }
} else {
clean_args_no_options(argc, argv, usage_str);
} }
if (check_argc_exact(argc - optind, 3)) if (check_argc_exact(argc - optind, 3))
return -1; usage(usage_str);
memset(&args, 0, sizeof(args)); memset(&args, 0, sizeof(args));
args.assign = assign; args.assign = assign;
@ -208,15 +214,7 @@ static const char * const cmd_qgroup_assign_usage[] = {
static int cmd_qgroup_assign(int argc, char **argv) static int cmd_qgroup_assign(int argc, char **argv)
{ {
int ret; return _cmd_qgroup_assign(1, argc, argv, cmd_qgroup_assign_usage);
clean_args_no_options(argc, argv, cmd_qgroup_assign_usage);
ret = _cmd_qgroup_assign(1, argc, argv);
if (ret < 0)
usage(cmd_qgroup_assign_usage);
return ret;
} }
static const char * const cmd_qgroup_remove_usage[] = { static const char * const cmd_qgroup_remove_usage[] = {
@ -227,15 +225,7 @@ static const char * const cmd_qgroup_remove_usage[] = {
static int cmd_qgroup_remove(int argc, char **argv) static int cmd_qgroup_remove(int argc, char **argv)
{ {
int ret; return _cmd_qgroup_assign(0, argc, argv, cmd_qgroup_remove_usage);
clean_args_no_options(argc, argv, cmd_qgroup_remove_usage);
ret = _cmd_qgroup_assign(0, argc, argv);
if (ret < 0)
usage(cmd_qgroup_remove_usage);
return ret;
} }
static const char * const cmd_qgroup_create_usage[] = { static const char * const cmd_qgroup_create_usage[] = {