Linux-XFS Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2] xfs_io: Make -D and -R options incompatible explicitly
@ 2020-07-24  6:32 Xiao Yang
  2020-07-30  0:45 ` Eric Sandeen
  0 siblings, 1 reply; 2+ messages in thread
From: Xiao Yang @ 2020-07-24  6:32 UTC (permalink / raw)
  To: linux-xfs; +Cc: sandeen, darrick.wong, david, hch, Xiao Yang

-D and -R options are mutually exclusive actually but many commands
can accept them at the same time and process them differently(e.g.
chattr alway chooses -D option or cowextsize accepts the last one
specified), so make these commands have the consistent behavior that
don't accept them concurrently.

1) Make them incompatible by setting argmax to 1 if commands can accept
   single option(i.e. lsattr, lsproj).
2) Make them incompatible by adding check if commands can accept multiple
   options(i.e. chattr, chproj, extsize, cowextsize).

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 io/attr.c       |  9 +++++++--
 io/cowextsize.c |  9 +++++++--
 io/open.c       | 22 +++++++++++++++-------
 3 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/io/attr.c b/io/attr.c
index 80e28514..181ff089 100644
--- a/io/attr.c
+++ b/io/attr.c
@@ -191,12 +191,10 @@ lsattr_f(
 	while ((c = getopt(argc, argv, "DRav")) != EOF) {
 		switch (c) {
 		case 'D':
-			recurse_all = 0;
 			recurse_dir = 1;
 			break;
 		case 'R':
 			recurse_all = 1;
-			recurse_dir = 0;
 			break;
 		case 'a':
 			aflag = 1;
@@ -320,6 +318,13 @@ chattr_f(
 		}
 	}
 
+	if (recurse_all && recurse_dir) {
+		fprintf(stderr, _("%s: -R and -D options are mutually exclusive\n"),
+			progname);
+		exitcode = 1;
+		return 0;
+	}
+
 	if (recurse_all || recurse_dir) {
 		nftw(name, chattr_callback,
 			100, FTW_PHYS | FTW_MOUNT | FTW_DEPTH);
diff --git a/io/cowextsize.c b/io/cowextsize.c
index 54963443..f6b134df 100644
--- a/io/cowextsize.c
+++ b/io/cowextsize.c
@@ -141,12 +141,10 @@ cowextsize_f(
 	while ((c = getopt(argc, argv, "DR")) != EOF) {
 		switch (c) {
 		case 'D':
-			recurse_all = 0;
 			recurse_dir = 1;
 			break;
 		case 'R':
 			recurse_all = 1;
-			recurse_dir = 0;
 			break;
 		default:
 			return command_usage(&cowextsize_cmd);
@@ -165,6 +163,13 @@ cowextsize_f(
 		cowextsize = -1;
 	}
 
+	if (recurse_all && recurse_dir) {
+		fprintf(stderr, _("%s: -R and -D options are mutually exclusive\n"),
+			progname);
+		exitcode = 1;
+		return 0;
+	}
+
 	if (recurse_all || recurse_dir)
 		nftw(file->name, (cowextsize >= 0) ?
 			set_cowextsize_callback : get_cowextsize_callback,
diff --git a/io/open.c b/io/open.c
index 9a8b5e5c..d8072664 100644
--- a/io/open.c
+++ b/io/open.c
@@ -426,12 +426,10 @@ lsproj_f(
 	while ((c = getopt(argc, argv, "DR")) != EOF) {
 		switch (c) {
 		case 'D':
-			recurse_all = 0;
 			recurse_dir = 1;
 			break;
 		case 'R':
 			recurse_all = 1;
-			recurse_dir = 0;
 			break;
 		default:
 			exitcode = 1;
@@ -504,12 +502,10 @@ chproj_f(
 	while ((c = getopt(argc, argv, "DR")) != EOF) {
 		switch (c) {
 		case 'D':
-			recurse_all = 0;
 			recurse_dir = 1;
 			break;
 		case 'R':
 			recurse_all = 1;
-			recurse_dir = 0;
 			break;
 		default:
 			exitcode = 1;
@@ -529,6 +525,13 @@ chproj_f(
 		return 0;
 	}
 
+	if (recurse_all && recurse_dir) {
+		fprintf(stderr, _("%s: -R and -D options are mutually exclusive\n"),
+			progname);
+		exitcode = 1;
+		return 0;
+	}
+
 	if (recurse_all || recurse_dir)
 		nftw(file->name, chproj_callback,
 			100, FTW_PHYS | FTW_MOUNT | FTW_DEPTH);
@@ -661,12 +664,10 @@ extsize_f(
 	while ((c = getopt(argc, argv, "DR")) != EOF) {
 		switch (c) {
 		case 'D':
-			recurse_all = 0;
 			recurse_dir = 1;
 			break;
 		case 'R':
 			recurse_all = 1;
-			recurse_dir = 0;
 			break;
 		default:
 			exitcode = 1;
@@ -686,6 +687,13 @@ extsize_f(
 		extsize = -1;
 	}
 
+	if (recurse_all && recurse_dir) {
+		fprintf(stderr, _("%s: -R and -D options are mutually exclusive\n"),
+			progname);
+		exitcode = 1;
+		return 0;
+	}
+
 	if (recurse_all || recurse_dir) {
 		nftw(file->name, (extsize >= 0) ?
 			set_extsize_callback : get_extsize_callback,
@@ -960,7 +968,7 @@ open_init(void)
 	lsproj_cmd.cfunc = lsproj_f;
 	lsproj_cmd.args = _("[-D | -R]");
 	lsproj_cmd.argmin = 0;
-	lsproj_cmd.argmax = -1;
+	lsproj_cmd.argmax = 1;
 	lsproj_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
 	lsproj_cmd.oneline =
 		_("list project identifier set on the currently open file");
-- 
2.21.0




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] xfs_io: Make -D and -R options incompatible explicitly
  2020-07-24  6:32 [PATCH v2] xfs_io: Make -D and -R options incompatible explicitly Xiao Yang
@ 2020-07-30  0:45 ` Eric Sandeen
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Sandeen @ 2020-07-30  0:45 UTC (permalink / raw)
  To: Xiao Yang, linux-xfs; +Cc: darrick.wong, david, hch

On 7/23/20 11:32 PM, Xiao Yang wrote:
> -D and -R options are mutually exclusive actually but many commands
> can accept them at the same time and process them differently(e.g.
> chattr alway chooses -D option or cowextsize accepts the last one
> specified), so make these commands have the consistent behavior that
> don't accept them concurrently.
> 
> 1) Make them incompatible by setting argmax to 1 if commands can accept
>    single option(i.e. lsattr, lsproj).

I see that lsattr already has argmax=1, so I guess that was ok.
Still good to remove the extra vars from the cases.

> 2) Make them incompatible by adding check if commands can accept multiple
>    options(i.e. chattr, chproj, extsize, cowextsize).
> 
> Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>

Thank you for cleaning all of these up.

Reviewed-by: Eric Sandeen <sandeen@redhat.com>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-24  6:32 [PATCH v2] xfs_io: Make -D and -R options incompatible explicitly Xiao Yang
2020-07-30  0:45 ` Eric Sandeen

Linux-XFS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-xfs/0 linux-xfs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-xfs linux-xfs/ https://lore.kernel.org/linux-xfs \
		linux-xfs@vger.kernel.org
	public-inbox-index linux-xfs

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-xfs


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git