All of lore.kernel.org
 help / color / mirror / Atom feed
From: Amir Goldstein <amir73il@gmail.com>
To: Dave Chinner <david@fromorbit.com>
Cc: Eryu Guan <eguan@redhat.com>,
	linux-xfs@vger.kernel.org, fstests@vger.kernel.org
Subject: [PATCH] xfs_io: support -c <cmd> without <file> args
Date: Mon,  5 Dec 2016 09:04:45 +0200	[thread overview]
Message-ID: <1480921485-14888-1-git-send-email-amir73il@gmail.com> (raw)

There is an undocumented and possibly unused feature in xfs_io
where all commands are executed per file given in the file args list.

This feature creates ambiguity when trying to execute commands
such as "open" and "file" from command line.

When running xfs_io -c <cmd> without any file args, xfs_io exits
without doing anything. This behavior is undocumented and does not
make much sense either.

Change the behavior in the case where no file args are given in
command line to execute every command exactly once, exactly as if
the commands where executed from an interactive shell.

This enables writing proper xfs_io scripts in command line, which
include "open" and "file" commands.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 io/init.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/io/init.c b/io/init.c
index a9191cf..785eb05 100644
--- a/io/init.c
+++ b/io/init.c
@@ -91,7 +91,7 @@ init_commands(void)
 }
 
 static int
-init_args_command(
+per_file_args_command(
 	int	index)
 {
 	if (index >= filecount)
@@ -101,6 +101,13 @@ init_args_command(
 }
 
 static int
+do_once_args_command(
+	int	index)
+{
+	return !index;
+}
+
+static int
 init_check_command(
 	const cmdinfo_t	*ct)
 {
@@ -214,7 +221,12 @@ init(
 	}
 
 	init_commands();
-	add_args_command(init_args_command);
+	/*
+	 * If file args exist, execute all commands for every file.
+	 * Otherwise, execute every command once exactly as in interactive mode.
+	 */
+	add_args_command(filecount ? per_file_args_command :
+			 do_once_args_command);
 	add_check_command(init_check_command);
 }
 
-- 
2.7.4


             reply	other threads:[~2016-12-05  7:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-05  7:04 Amir Goldstein [this message]
2016-12-05 11:02 ` [PATCH] xfs_io: support -c <cmd> without <file> args Dave Chinner
2016-12-05 11:27   ` Amir Goldstein

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1480921485-14888-1-git-send-email-amir73il@gmail.com \
    --to=amir73il@gmail.com \
    --cc=david@fromorbit.com \
    --cc=eguan@redhat.com \
    --cc=fstests@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.