From patchwork Fri Jul 1 08:26:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephane Chazelas X-Patchwork-Id: 934812 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p618R7I6029866 for ; Fri, 1 Jul 2011 08:27:08 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755415Ab1GAI1D (ORCPT ); Fri, 1 Jul 2011 04:27:03 -0400 Received: from mail.seebyte.com ([80.193.213.29]:56483 "EHLO mail.seebyte.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754945Ab1GAI1A (ORCPT ); Fri, 1 Jul 2011 04:27:00 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.seebyte.com (Postfix) with ESMTP id 0A6832F00; Fri, 1 Jul 2011 09:26:59 +0100 (BST) X-Virus-Scanned: Debian amavisd-new at mail.seebyte.com Received: from mail.seebyte.com ([127.0.0.1]) by localhost (seebyte2.seebyte.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ISPqAckYoOWP; Fri, 1 Jul 2011 09:26:52 +0100 (BST) Received: from sbl-sc-laptop1.seebyte.com (stephane-chazelas-laptop1.seebyte.com [10.10.10.4]) by mail.seebyte.com (Postfix) with ESMTPSA id C65A22F09; Fri, 1 Jul 2011 09:26:52 +0100 (BST) Received: from stephane by sbl-sc-laptop1.seebyte.com with local (Exim 4.76) (envelope-from ) id 1QcZ3s-0005Rp-IZ; Fri, 01 Jul 2011 09:26:52 +0100 Date: Fri, 1 Jul 2011 09:26:52 +0100 From: Stephane Chazelas To: Andreas Philipp Cc: Hugo Mills , linux-btrfs@vger.kernel.org Subject: [PATCH] Re: [btrfs-progs integration] incorrect argument checking for "btrfs sub snap -r" Message-ID: References: <4E0BC7AA.7000709@cn.fujitsu.com> <4E0C3F72.5040508@gmail.com> <20110630105813.GD11170@carfax.org.uk> <4E0CE2B3.1080600@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <4E0CE2B3.1080600@gmail.com> User-Agent: Mutt/1.5.16 (2007-09-19) Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 01 Jul 2011 08:28:25 +0000 (UTC) 2011-06-30 22:55:15 +0200, Andreas Philipp: > > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On 30.06.2011 14:34, Stephane Chazelas wrote: > > Looks like this was missing in integration-20110626 for the > > readonly snapshot patch: > > > > diff --git a/btrfs.c b/btrfs.c > > index e117172..be6ece5 100644 > > --- a/btrfs.c > > +++ b/btrfs.c > > @@ -49,7 +49,7 @@ static struct Command commands[] = { > > /* > > avoid short commands different for the case only > > */ > > - { do_clone, 2, > > + { do_clone, -1, > > "subvolume snapshot", "[-r] [/]\n" > > "Create a writable/readonly snapshot of the subvolume with\n" > > "the name in the directory.", > > > > Without that, "btrfs sub snap -r x y" would fail as it's not *2* > > arguments. > Unfortunately, this is not correct either. "-1" means that the minimum > number of arguments is 1 and since we need at least and > this is 2. So the correct version should be -2. [...] Sorry, without looking closely at the source, I assumed -1 meant defer the checking to the subcommand handler. do_clone will indeed return an error if the number of arguments is less than expected (so with -2, you'll get a different error message if you do "btrfs sub snap -r foo" or "btrfs sub snap foo") , but will not if it's more than expected by the way. So the patch should probably be: Cheers, Stephane --- 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/btrfs.c b/btrfs.c index e117172..b50c58a 100644 --- a/btrfs.c +++ b/btrfs.c @@ -49,7 +49,7 @@ static struct Command commands[] = { /* avoid short commands different for the case only */ - { do_clone, 2, + { do_clone, -2, "subvolume snapshot", "[-r] [/]\n" "Create a writable/readonly snapshot of the subvolume with\n" "the name in the directory.", diff --git a/btrfs_cmds.c b/btrfs_cmds.c index 1d18c59..3415afc 100644 --- a/btrfs_cmds.c +++ b/btrfs_cmds.c @@ -355,7 +355,7 @@ int do_clone(int argc, char **argv) return 1; } } - if (argc - optind < 2) { + if (argc - optind != 2) { fprintf(stderr, "Invalid arguments for subvolume snapshot\n"); free(argv); return 1;