diff mbox

[2/4] btrfs-progs: deal with invalid option combinations for btrfs-image

Message ID 1403142363-29482-2-git-send-email-guihc.fnst@cn.fujitsu.com (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Gui Hecheng June 19, 2014, 1:46 a.m. UTC
For btrfs-image,
	dump 	may not come with option '-o'
	-r	may not come with option '-c', '-s', '-w', dev_cnt != 1
	-m	may not come with dev_cnt < 2
All of the above should be regarded as invalid combinations,
and the usage will show up.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
---
 btrfs-image.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

Comments

David Sterba June 23, 2014, 2:12 p.m. UTC | #1
On Thu, Jun 19, 2014 at 09:46:01AM +0800, Gui Hecheng wrote:
> For btrfs-image,
> 	dump 	may not come with option '-o'
> 	-r	may not come with option '-c', '-s', '-w', dev_cnt != 1
> 	-m	may not come with dev_cnt < 2
> All of the above should be regarded as invalid combinations,
> and the usage will show up.

The generic usage works, but is not very descriptive what really
happened. Would be good to print a message as soon as an error is
detectd. See below:

> @@ -2500,15 +2501,20 @@ int main(int argc, char *argv[])
>  		}
>  	}
>  
> -	if ((old_restore) && create)
> -		print_usage();

In this case the old code makes more sense followed by the message that
create and restore cannot be used at the same time.

> -	if (multi_devices && dev_cnt < 2)
> -		print_usage();

Applies to both modes, eg. "not enoug devices specified for -m option".

> -	if (!multi_devices && dev_cnt != 1)
> +	if (create) {
> +		usage_error = old_restore;
> +	} else {
> +		usage_error = walk_trees || sanitize || compress_level;

Error message here if usage_error is set.

> +		if (multi_devices)
> +			usage_error = usage_error || (dev_cnt < 2);
> +		else
> +			usage_error = usage_error || (dev_cnt != 1);

Could be merged with the multi_devices check above, accepts only one
without -m option.
--
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
Gui Hecheng June 24, 2014, 1:43 a.m. UTC | #2
On Mon, 2014-06-23 at 16:12 +0200, David Sterba wrote:
> On Thu, Jun 19, 2014 at 09:46:01AM +0800, Gui Hecheng wrote:
> > For btrfs-image,
> > 	dump 	may not come with option '-o'
> > 	-r	may not come with option '-c', '-s', '-w', dev_cnt != 1
> > 	-m	may not come with dev_cnt < 2
> > All of the above should be regarded as invalid combinations,
> > and the usage will show up.
> 
> The generic usage works, but is not very descriptive what really
> happened. Would be good to print a message as soon as an error is
> detectd. See below:
> 
> > @@ -2500,15 +2501,20 @@ int main(int argc, char *argv[])
> >  		}
> >  	}
> >  
> > -	if ((old_restore) && create)
> > -		print_usage();
> 
> In this case the old code makes more sense followed by the message that
> create and restore cannot be used at the same time.
> 
> > -	if (multi_devices && dev_cnt < 2)
> > -		print_usage();
> 
> Applies to both modes, eg. "not enoug devices specified for -m option".
> 
> > -	if (!multi_devices && dev_cnt != 1)
> > +	if (create) {
> > +		usage_error = old_restore;
> > +	} else {
> > +		usage_error = walk_trees || sanitize || compress_level;
> 
> Error message here if usage_error is set.
> 
> > +		if (multi_devices)
> > +			usage_error = usage_error || (dev_cnt < 2);
> > +		else
> > +			usage_error = usage_error || (dev_cnt != 1);
> 
> Could be merged with the multi_devices check above, accepts only one
> without -m option.

Yes, I'll arrange the error messages well soon. Thanks.


--
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 mbox

Patch

diff --git a/btrfs-image.c b/btrfs-image.c
index db5d193..549722c 100644
--- a/btrfs-image.c
+++ b/btrfs-image.c
@@ -2462,6 +2462,7 @@  int main(int argc, char *argv[])
 	int ret;
 	int sanitize = 0;
 	int dev_cnt = 0;
+	int usage_error = 0;
 	FILE *out;
 
 	while (1) {
@@ -2500,15 +2501,20 @@  int main(int argc, char *argv[])
 		}
 	}
 
-	if ((old_restore) && create)
-		print_usage();
-
 	argc = argc - optind;
 	dev_cnt = argc - 1;
 
-	if (multi_devices && dev_cnt < 2)
-		print_usage();
-	if (!multi_devices && dev_cnt != 1)
+	if (create) {
+		usage_error = old_restore;
+	} else {
+		usage_error = walk_trees || sanitize || compress_level;
+		if (multi_devices)
+			usage_error = usage_error || (dev_cnt < 2);
+		else
+			usage_error = usage_error || (dev_cnt != 1);
+	}
+
+	if (usage_error)
 		print_usage();
 
 	source = argv[optind];