Skip to contentSkip to conversation

nvme-cli: add support alias command with Firmware Activate

PATCH New Minwoo Im 1 participant 1 message Dec 17, 2017 NVMe

lore
Share & tools
lore

Minwoo Im

author
#0 lore raw

PATCH v2 1/3 nvme-cli: add support alias command with Firmware Activate

Firmware Activate command were known as "Firmware Activate" in NVMe 1.0 and 1.1. It has been changed to "Firmware Commit" since 1.2.

This patch will make it support a single alias for every subcommands. Also make "fw-activate" command to be registered in "fw-commit" as an alias for backward compatibility.

Signed-off-by Minwoo Im <minwoo.im.dev at gmail.com>
---
 cmd_handler.h  | 20 ++++++++++++++++----
 nvme-builtin.h |  2 +-
 nvme.c         |  2 +-
 plugin.c       |  3 ++-
 plugin.h       |  1 +
 5 files changed, 21 insertions(+), 7 deletions(-)
cmd_handler.h +16 -4
index b2e3e9d..d40740d 100644
@@ -8,7 +8,7 @@
 #define NAME(n, d)
 
 #undef ENTRY
-#define ENTRY(n, h, f) \
+#define ENTRY(n, h, f, ...) \
 static int f(int argc, char **argv, struct command *command, struct plugin *plugin);
 
 #undef COMMAND_LIST
@@ -28,14 +28,26 @@ static int f(int argc, char **argv, struct command *command, struct plugin *plug
 #undef NAME
 #define NAME(n, d)
 
-#undef ENTRY
-#define ENTRY(n, h, f)			\
+#undef ENTRY_W_ALIAS
+#define ENTRY_W_ALIAS(n, h, f, a)	\
 static struct command f ## _cmd = {	\
 	.name = n, 			\
 	.help = h, 			\
 	.fn = f, 			\
+	.alias = a, 			\
 };
 
+#undef ENTRY_WO_ALIAS
+#define ENTRY_WO_ALIAS(n, h, f)		\
+	ENTRY_W_ALIAS(n, h, f, NULL)
+
+#undef ENTRY_SEL
+#define ENTRY_SEL(n, h, f, a, CMD, ...) CMD
+
+#undef ENTRY
+#define ENTRY(...) 		\
+	ENTRY_SEL(__VA_ARGS__, ENTRY_W_ALIAS, ENTRY_WO_ALIAS)(__VA_ARGS__)
+
 #undef COMMAND_LIST
 #define COMMAND_LIST(args...) args
 
@@ -54,7 +66,7 @@ static struct command f ## _cmd = {	\
 #define NAME(n, d)
 
 #undef ENTRY
-#define ENTRY(n, h, f) &f ## _cmd,
+#define ENTRY(n, h, f, ...) &f ## _cmd,
 
 #undef COMMAND_LIST
 #define COMMAND_LIST(args...)	\
nvme-builtin.h +1 -1
index b06eb34..85f9f0f 100644
@@ -28,7 +28,7 @@ COMMAND_LIST(
 	ENTRY("set-feature", "Set a feature and show the resulting value", set_feature)
 	ENTRY("set-property", "Set a property and show the resulting value", set_property)
 	ENTRY("format", "Format namespace with new block format", format)
-	ENTRY("fw-activate", "Activate new firmware slot", fw_activate)
+	ENTRY("fw-commit", "Verify and commit firmware to a specific slot (fw-activate in old version < 1.2)", fw_commit, "fw-activate")
 	ENTRY("fw-download", "Download new firmware", fw_download)
 	ENTRY("admin-passthru", "Submit an arbitrary admin command, return results", admin_passthru)
 	ENTRY("io-passthru", "Submit an arbitrary IO command, return results", io_passthru)
nvme.c +1 -1
index 4b0b861..bb9feaa 100644
@@ -1780,7 +1780,7 @@ static char *nvme_fw_status_reset_type(__u32 status)
 	}
 }
 
-static int fw_activate(int argc, char **argv, struct command *cmd, struct plugin *plugin)
+static int fw_commit(int argc, char **argv, struct command *cmd, struct plugin *plugin)
 {
 	const char *desc = "Verify downloaded firmware image and "\
 		"commit to specific firmware slot. Device is not automatically "\
plugin.c +2 -1
index 6ca7882..5eb12bf 100644
@@ -133,7 +133,8 @@ int handle_plugin(int argc, char **argv, struct plugin *plugin)
 		if (!strcmp(str, "version"))
 			return version(plugin);
 		if (strcmp(str, cmd->name))
-			continue;
+			if (!cmd->alias || (cmd->alias && strcmp(str, cmd->alias)))
+				continue;
 
 		return (cmd->fn(argc, argv, cmd, plugin));
 	}
plugin.h +1 -0
index 68d93d1..91079fb 100644
@@ -26,6 +26,7 @@ struct command {
 	char *name;
 	char *help;
 	int (*fn)(int argc, char **argv, struct command *command, struct plugin *plugin);
+	char *alias;
 };
 
 void usage(struct plugin *plugin);
Signature · 1 line
2.7.4