From patchwork Thu Nov 8 09:52:09 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao Xie X-Patchwork-Id: 1714751 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 1227CDF280 for ; Thu, 8 Nov 2012 09:51:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751698Ab2KHJvy (ORCPT ); Thu, 8 Nov 2012 04:51:54 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:59775 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751114Ab2KHJvx (ORCPT ); Thu, 8 Nov 2012 04:51:53 -0500 X-IronPort-AV: E=Sophos;i="4.80,737,1344182400"; d="scan'208";a="6161421" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 08 Nov 2012 17:50:13 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id qA89po5X003554; Thu, 8 Nov 2012 17:51:50 +0800 Received: from [10.167.225.199] ([10.167.225.199]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2012110817515530-1024188 ; Thu, 8 Nov 2012 17:51:55 +0800 Message-ID: <509B80C9.2070107@cn.fujitsu.com> Date: Thu, 08 Nov 2012 17:52:09 +0800 From: Miao Xie Reply-To: miaox@cn.fujitsu.com User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121016 Thunderbird/16.0.1 MIME-Version: 1.0 To: Linux Btrfs CC: Arne Jansen , wangshilong Subject: [PATCH 1/3] Btrfs-progs: fix arg parsing for btrfs qgroup limit commands References: <509B785A.9010000@cn.fujitsu.com> In-Reply-To: <509B785A.9010000@cn.fujitsu.com> X-Forwarded-Message-Id: <509B785A.9010000@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2012/11/08 17:51:55, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2012/11/08 17:51:55, Serialize complete at 2012/11/08 17:51:55 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Wang Shilong 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 Signed-off-by: Miao Xie --- cmds-qgroup.c | 14 ++++++-------- 1 files changed, 6 insertions(+), 8 deletions(-) -- 1.7.7.6 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/cmds-qgroup.c b/cmds-qgroup.c index 1525c11..129a4f0 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) {