]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme-cli : Add Namespace Rescan Command
authorjeffreyalien <jeff.lien@wdc.com>
Fri, 22 Sep 2017 21:51:45 +0000 (16:51 -0500)
committerKeith Busch <keith.busch@intel.com>
Fri, 22 Sep 2017 22:06:09 +0000 (18:06 -0400)
Signed-off-by: jeffreyalien <jeff.lien@wdc.com>
Signed-off-by: Keith Busch <keith.busch@intel.com>
nvme-builtin.h
nvme-ioctl.c
nvme-ioctl.h
nvme.c

index b24c25b98d80f0639400491d2b5a14ec063eec5e..a96d42e5a7ffb2cf3618abc2bd015906d7b59553 100644 (file)
@@ -46,6 +46,7 @@ COMMAND_LIST(
        ENTRY("sanitize-log", "Retrive sanitize log, show it", sanitize_log)
        ENTRY("reset", "Resets the controller", reset)
        ENTRY("subsystem-reset", "Resets the controller", subsystem_reset)
+       ENTRY("ns-rescan", "Rescans the NVME namespaces", ns_rescan)
        ENTRY("show-regs", "Shows the controller registers. Requires admin character device", show_registers)
        ENTRY("discover", "Discover NVMeoF subsystems", discover_cmd)
        ENTRY("connect-all", "Discover and Connect to NVMeoF subsystems", connect_all_cmd)
index 52243fa2e6e0a8862d22aa4224189b2c46403581..1843faf7d110ec07687ad70d73ce71cb0bdb5a1f 100644 (file)
@@ -58,6 +58,16 @@ int nvme_reset_controller(int fd)
        return ioctl(fd, NVME_IOCTL_RESET);
 }
 
+int nvme_ns_rescan(int fd)
+{
+       int ret;
+
+       ret = nvme_verify_chr(fd);
+       if (ret)
+               return ret;
+       return ioctl(fd, NVME_IOCTL_RESCAN);
+}
+
 int nvme_get_nsid(int fd)
 {
        static struct stat nvme_stat;
index 4aee90af9cf51cb43ba0b7d30887b0adc9469bfa..6b3e0b44740457de89e8fab3fc74a18f35b18ba9 100644 (file)
@@ -115,6 +115,7 @@ int nvme_sec_recv(int fd, __u32 nsid, __u8 nssf, __u16 spsp,
 
 int nvme_subsystem_reset(int fd);
 int nvme_reset_controller(int fd);
+int nvme_ns_rescan(int fd);
 
 int nvme_dir_send(int fd, __u32 nsid, __u16 dspec, __u8 dtype, __u8 doper,
                  __u32 data_len, __u32 dw12, void *data, __u32 *result);
diff --git a/nvme.c b/nvme.c
index d747be45cbffc5afa152058e5217d15a70ea3bcf..74a4fd0975a45ac2f0ca01dd907058eb632d81e3 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -1501,6 +1501,27 @@ static int reset(int argc, char **argv, struct command *cmd, struct plugin *plug
        return err;
 }
 
+static int ns_rescan(int argc, char **argv, struct command *cmd, struct plugin *plugin)
+{
+       const char *desc = "Rescans the NVMe namespaces\n";
+       int err, fd;
+
+       const struct argconfig_commandline_options command_line_options[] = {
+               {NULL}
+       };
+
+       fd = parse_and_open(argc, argv, desc, command_line_options, NULL, 0);
+       if (fd < 0)
+               return fd;
+
+       err = nvme_ns_rescan(fd);
+       if (err < 0) {
+               perror("Namespace Rescan");
+               return errno;
+       }
+       return err;
+}
+
 static int sanitize(int argc, char **argv, struct command *cmd, struct plugin *plugin)
 {
        char *desc = "Send a sanitize command.";