diff options
author | Wang Shilong <wangsl-fnst@cn.fujitsu.com> | 2013-01-20 16:04:14 -0500 |
---|---|---|
committer | David Sterba <dsterba@suse.cz> | 2013-01-21 18:28:01 +0100 |
commit | f933e084eafe3f0b441f0ffb99505fc34a66194e (patch) | |
tree | 805363223433f22621c616ffdd6f07d40f041c04 | |
parent | c9597c7f17bd9a8affb51ae4f48a4b8cca042efa (diff) |
Btrfs-progs: fix arg parsing for btrfs qgroup limit commands
We can use this command in two ways.
1. btrfs qgroup limit size qgroupid path
2. btrfs qgroup limit size path
Before applying this patch, we differentiate them by check the parsing result
of the second argument. It is not so good because it may make some mistakes,
For example:
btrfs qgroup limit 1M 123456
^ It is a subvolume name.
In fact, we can differentiate them just by the number of arguments, so fix it
by this way.
Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Gene Czarcinski <gene@czarc.net>
-rw-r--r-- | cmds-qgroup.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/cmds-qgroup.c b/cmds-qgroup.c index 1525c116..129a4f03 100644 --- a/cmds-qgroup.c +++ b/cmds-qgroup.c @@ -383,7 +383,6 @@ static int cmd_qgroup_limit(int argc, char **argv) } memset(&args, 0, sizeof(args)); - args.qgroupid = parse_qgroupid(argv[optind + 1]); if (size) { if (compressed) args.lim.flags |= BTRFS_QGROUP_LIMIT_RFER_CMPR | @@ -397,9 +396,8 @@ static int cmd_qgroup_limit(int argc, char **argv) } } - if (args.qgroupid == 0) { - if (check_argc_exact(argc - optind, 2)) - usage(cmd_qgroup_limit_usage); + if (argc - optind == 2) { + args.qgroupid = 0; path = argv[optind + 1]; ret = test_issubvolume(path); if (ret < 0) { @@ -415,11 +413,11 @@ static int cmd_qgroup_limit(int argc, char **argv) * keep qgroupid at 0, this indicates that the subvolume the * fd refers to is to be limited */ - } else { - if (check_argc_exact(argc - optind, 3)) - usage(cmd_qgroup_limit_usage); + } else if (argc - optind == 3) { + args.qgroupid = parse_qgroupid(argv[optind + 1]); path = argv[optind + 2]; - } + } else + usage(cmd_qgroup_limit_usage); fd = open_file_or_dir(path); if (fd < 0) { |