Skip to contentSkip to conversation

xfs_io: support -c <cmd> without <file> args

PATCH NAK Amir Goldstein 2 participants 3 messages Dec 5, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs_io: support -c <cmd> without <file> args

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.

---
 io/init.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
io/init.c +14 -2
index a9191cf..785eb05 100644
@@ -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);
 }
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 10 lines · Amir Goldstein

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.

Quoted 6 lines

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.

NACK.

This does not fix any of the underlying problems. It just adds another WTF case to CLI processing as two things that should be equivlent now behave differently. i.e.

$ xfs_io -c "open foo" -c "open bar" -c file

and

$ xfs_io -c "open bar" -c file foo

will have different behaviour, even though the man page says they should be equivalent and do exactly the same thing.

Fix the underlying problems once and for all: do not hack bandaids into the code that only hides the symptom for your specific use case.

-Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#2 lore raw
Quoted 18 lines · Dave Chinner
Quoted 10 lines · Amir Goldstein

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.

Quoted 6 lines

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.

Quoted 8 lines

NACK.

This does not fix any of the underlying problems. It just adds another WTF case to CLI processing as two things that should be equivlent now behave differently. i.e.

$ xfs_io -c "open foo" -c "open bar" -c file

You meant:

$ xfs_io -c "open foo" -c "open bar"
Quoted 11 lines

and

$ xfs_io -c "open bar" -c file foo

will have different behaviour, even though the man page says they should be equivalent and do exactly the same thing.

Fix the underlying problems once and for all: do not hack bandaids into the code that only hides the symptom for your specific use case.

Dave,

I would be glad to fix the code, but you did not answer my question.

The "execute all commands per file" behavior is not documented, does not appear to have any known users and makes every attempt to parse "file" commands ambiguous.

Can we, in your option, do away with this behavior?

If the answer is yes, then the patch is even simpler then these 16 lines. Just replace the old init_args_command() with the new do_once_args_command().

Would you like me to re-submit the patch with this change?

Amir.