From patchwork Sun Jan 20 21:04:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gene Czarcinski X-Patchwork-Id: 2008621 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id A4E9C3FD86 for ; Sun, 20 Jan 2013 21:04:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752569Ab3ATVEx (ORCPT ); Sun, 20 Jan 2013 16:04:53 -0500 Received: from eastrmfepo203.cox.net ([68.230.241.218]:34577 "EHLO eastrmfepo203.cox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752542Ab3ATVEl (ORCPT ); Sun, 20 Jan 2013 16:04:41 -0500 Received: from eastrmimpo209 ([68.230.241.224]) by eastrmfepo203.cox.net (InterMail vM.8.01.04.00 201-2260-137-20101110) with ESMTP id <20130120210440.TZMF21186.eastrmfepo203.cox.net@eastrmimpo209> for ; Sun, 20 Jan 2013 16:04:40 -0500 Received: from falcon.lcl ([68.100.144.189]) by eastrmimpo209 with cox id qM4W1k00945PsQc01M4ggn; Sun, 20 Jan 2013 16:04:40 -0500 X-CT-Class: Clean X-CT-Score: 0.00 X-CT-RefID: str=0001.0A020209.50FC5BE8.0046,ss=1,re=0.000,fgs=0 X-CT-Spam: 0 X-Authority-Analysis: v=2.0 cv=E5JPVNhl c=1 sm=1 a=xiXiwr23JuvKlkj6ngz4TA==:17 a=a4nn0WfGlNQA:10 a=103jMkqsgCkA:10 a=BIJj-m-0AAAA:8 a=4ga2z3E1CtwA:10 a=omOdbC7AAAAA:8 a=JupNB1XDQl0AC0S3WmoA:9 a=LUue1KWhiSUA:10 a=APg_U0iNW5y7M1bv:21 a=stfIMN4he9_Xnv9_:21 a=xiXiwr23JuvKlkj6ngz4TA==:117 X-CM-Score: 0.00 Authentication-Results: cox.net; auth=pass (CRAM-MD5) smtp.auth=gczarcinski@cox.net From: Gene Czarcinski To: linux-btrfs@vger.kernel.org Cc: Wang Shilong , Miao Xie , Gene Czarcinski Subject: [PATCH 09/13] Btrfs-progs: fix arg parsing for btrfs qgroup limit commands Date: Sun, 20 Jan 2013 16:04:14 -0500 Message-Id: <1358715858-4469-10-git-send-email-gene@czarc.net> X-Mailer: git-send-email 1.8.1 In-Reply-To: <1358715858-4469-1-git-send-email-gene@czarc.net> References: <1358715858-4469-1-git-send-email-gene@czarc.net> 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 Signed-off-by: Gene Czarcinski --- cmds-qgroup.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) 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) {