]> www.infradead.org Git - users/hch/nvme-cli.git/commitdiff
And intel vendor specific extensions
authorKeith Busch <keith.busch@intel.com>
Tue, 7 Jun 2016 17:53:49 +0000 (11:53 -0600)
committerKeith Busch <keith.busch@intel.com>
Wed, 8 Jun 2016 23:26:06 +0000 (17:26 -0600)
Signed-off-by: Keith Busch <keith.busch@intel.com>
Makefile
intel-nvme.c [new file with mode: 0644]
intel-nvme.h [new file with mode: 0644]
nvme.c
nvme.h
plugin.c

index 34169be1c89e976b54e3cc30924046f07c99d541..841cc08b930887bb29e184fad9fc3bfc072f4861 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -31,7 +31,7 @@ override CFLAGS += -DNVME_VERSION='"$(NVME_VERSION)"'
 NVME_DPKG_VERSION=1~`lsb_release -sc`
 
 OBJS := argconfig.o suffix.o parser.o nvme-print.o nvme-ioctl.o \
-       nvme-lightnvm.o fabrics.o json.o plugin.o
+       nvme-lightnvm.o fabrics.o json.o plugin.o intel-nvme.o
 
 nvme: nvme.c nvme.h $(OBJS) NVME-VERSION-FILE
        $(CC) $(CPPFLAGS) $(CFLAGS) nvme.c $(LDFLAGS) -o $(NVME) $(OBJS)
diff --git a/intel-nvme.c b/intel-nvme.c
new file mode 100644 (file)
index 0000000..12f6b06
--- /dev/null
@@ -0,0 +1,63 @@
+#include <stdio.h>
+
+#include "nvme.h"
+#include "nvme-print.h"
+#include "nvme-ioctl.h"
+#include "plugin.h"
+
+#include "argconfig.h"
+#include "suffix.h"
+
+#define CREATE_CMD
+#include "intel-nvme.h"
+
+static struct plugin intel_nvme = {
+       .name = "intel",
+       .desc = "Intel vendor specific extensions",
+       .next = NULL,
+       .commands = commands,
+};
+static void init() __attribute__((constructor));
+static void init()
+{
+       register_extension(&intel_nvme);
+}
+
+static int get_additional_smart_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
+{
+       struct nvme_additional_smart_log smart_log;
+       int err, fd;
+       char *desc = "Get Intel vendor specific additional smart log (optionally, "\
+                     "for the specified namespace), and show it.";
+       const char *namespace = "(optional) desired namespace";
+       const char *raw = "dump output in binary format";
+       struct config {
+               __u32 namespace_id;
+               int   raw_binary;
+       };
+
+       struct config cfg = {
+               .namespace_id = 0xffffffff,
+       };
+
+       const struct argconfig_commandline_options command_line_options[] = {
+               {"namespace-id", 'n', "NUM", CFG_POSITIVE, &cfg.namespace_id, required_argument, namespace},
+               {"raw-binary",   'b', "",    CFG_NONE,     &cfg.raw_binary,   no_argument,       raw},
+               {0}
+       };
+
+       fd = parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
+
+       err = nvme_intel_smart_log(fd, cfg.namespace_id, &smart_log);
+       if (!err) {
+               if (!cfg.raw_binary)
+                       show_intel_smart_log(&smart_log, cfg.namespace_id, devicename);
+               else
+                       d_raw((unsigned char *)&smart_log, sizeof(smart_log));
+       }
+       else if (err > 0)
+               fprintf(stderr, "NVMe Status:%s(%x)\n",
+                                       nvme_status_to_string(err), err);
+       return err;
+}
diff --git a/intel-nvme.h b/intel-nvme.h
new file mode 100644 (file)
index 0000000..68b6e19
--- /dev/null
@@ -0,0 +1,15 @@
+#undef CMD_INC_FILE
+#define CMD_INC_FILE intel-nvme
+
+#if !defined(INTEL_NVME) || defined(CMD_HEADER_MULTI_READ)
+#define INTEL_NVME
+
+#include "cmd.h"
+
+COMMAND_LIST(
+       ENTRY("smart-log-add", "Retrieve Intel SMART Log, show it", get_additional_smart_log)
+);
+
+#endif
+
+#include "define_cmd.h"
diff --git a/nvme.c b/nvme.c
index 193096fdf7ed9454a4e69c7155abf6fc9eff8eec..f5ba87a1573c6bb1d9e14dc3508f1e1978ba6385 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -63,7 +63,7 @@
 
 static int fd;
 static struct stat nvme_stat;
-static const char *devicename;
+const char *devicename;
 
 static const char nvme_version_string[] = NVME_VERSION;
 
@@ -132,11 +132,12 @@ static void get_dev(int argc, char **argv)
        open_dev((const char *)argv[optind]);
 }
 
-static void parse_and_open(int argc, char **argv, const char *desc,
+int parse_and_open(int argc, char **argv, const char *desc,
        const struct argconfig_commandline_options *clo, void *cfg, size_t size)
 {
        argconfig_parse(argc, argv, desc, clo, cfg, size);
        get_dev(argc, argv);
+       return fd;
 }
 
 const char *output_format = "Output format: normal|json|binary";
@@ -2888,7 +2889,7 @@ static int disconnect_cmd(int argc, char **argv, struct command *command, struct
        return disconnect(desc, argc, argv);
 }
 
-void register_extention(struct plugin *plugin)
+void register_extension(struct plugin *plugin)
 {
        plugin->parent = &nvme;
 
diff --git a/nvme.h b/nvme.h
index 00df2b82c9ccfc3904107fc4146c2dc763064a16..bbf664c29c0005b855570e9d77ba01ee567cb183 100644 (file)
--- a/nvme.h
+++ b/nvme.h
@@ -592,4 +592,10 @@ struct nvmf_disc_rsp_page_hdr {
 
 void register_extension(struct plugin *plugin);
 
+#include "argconfig.h"
+int parse_and_open(int argc, char **argv, const char *desc,
+       const struct argconfig_commandline_options *clo, void *cfg, size_t size);
+
+extern const char *devicename;
+
 #endif /* _NVME_H */
index 9fbf8407ed6ad642871a0a79f8de1460ad7249dc..1b52a00b29fc2170ac2a2577281c05d439b3cd92 100644 (file)
--- a/plugin.c
+++ b/plugin.c
@@ -147,6 +147,7 @@ int handle_plugin(int argc, char **argv, struct plugin *plugin)
                        continue;
                }
                return handle_plugin(argc - 1, &argv[1], extension);
+               extension = extension->next;
        }
        return -1;
 }