]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme-cli: Add nvme hostnqn generation option
authorSagi Grimberg <sagi@grimberg.me>
Thu, 12 Jan 2017 11:13:28 +0000 (13:13 +0200)
committerKeith Busch <keith.busch@intel.com>
Wed, 18 Jan 2017 17:10:05 +0000 (12:10 -0500)
Add option to generate a NVMe qualified name of a given host
(in the form of: nqn.2014-08.org.nvmexpress:NVMf:uuid:<some_uuid>).
This hostnqn will be used for fabrics discovery and connect functions.

Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Jay Freyensee <james_p_freyensee@linux.intel.com>
Makefile
nvme-builtin.h
nvme.c

index a8acd3fccab08f63daecebc5b151ef9fea8546f6..cb83001a70061d53a8d5008c0245869cdf69093f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,7 @@
 CFLAGS ?= -O2 -g -Wall -Werror
 CFLAGS += -std=gnu99
 CPPFLAGS += -D_GNU_SOURCE -D__CHECK_ENDIAN__
+LDFLAGS += -luuid
 NVME = nvme
 INSTALL ?= install
 DESTDIR =
index 5a26f692659551d2f9409ce01115f3ccd967126a..087fc1986b2f14ea0791ee4c05e7ca6d37fa0818 100644 (file)
@@ -48,6 +48,7 @@ COMMAND_LIST(
        ENTRY("connect-all", "Discover and Connect to NVMeoF subsystems", connect_all_cmd)
        ENTRY("connect", "Connect to NVMeoF subsystem", connect_cmd)
        ENTRY("disconnect", "Disconnect from NVMeoF subsystem", disconnect_cmd)
+       ENTRY("gen-hostnqn", "Generate NVMeoF host NQN", gen_hostnqn_cmd)
 );
 
 #endif
diff --git a/nvme.c b/nvme.c
index b97109b316bad3001398f5700f7b6a019ad0513b..24fdce9593bc800982cb78d0729278cb7a2585b9 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -44,6 +44,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/time.h>
+#include <uuid/uuid.h>
 
 #include "nvme-print.h"
 #include "nvme-ioctl.h"
@@ -2671,6 +2672,17 @@ static int admin_passthru(int argc, char **argv, struct command *cmd, struct plu
        return passthru(argc, argv, NVME_IOCTL_ADMIN_CMD, desc, cmd);
 }
 
+static int gen_hostnqn_cmd(int argc, char **argv, struct command *command, struct plugin *plugin)
+{
+       uuid_t uuid;
+       char uuid_str[37]; /* e.g. 1b4e28ba-2fa1-11d2-883f-0016d3cca427 + \0 */
+
+       uuid_generate_random(uuid);
+       uuid_unparse_lower(uuid, uuid_str);
+       printf("nqn.2014-08.org.nvmexpress:NVMf:uuid:%s\n", uuid_str);
+       return 0;
+}
+
 static int discover_cmd(int argc, char **argv, struct command *command, struct plugin *plugin)
 {
        const char *desc = "Send Get Log Page request to Discovery Controller.";