]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme: update list-ns nsid option
authorMax Gurtovoy <maxg@mellanox.com>
Thu, 30 May 2019 09:43:22 +0000 (12:43 +0300)
committerKeith Busch <keith.busch@gmail.com>
Fri, 7 Jun 2019 16:16:30 +0000 (10:16 -0600)
This commit updates the optional nsid argument to define the wanted
nsid for start, instead of starting from nsid + 1. E.g. in case we've
wanted to get the list of namespaces starting from 1, before this
commit, we used the "--namespace-id=0" option. Nsid 0 is not valid in
NVMe spec, thus change it to start counting from the given nsid.

Reviewed-by: Minwoo Im <minwoo.im@samsung.com>
Signed-off-by: Max Gurtovoy <maxg@mellanox.com>
nvme.c

diff --git a/nvme.c b/nvme.c
index 9819fcb931e738f01422a3f5f2f7b0080359ad2f..9d763f509b22c40df7bf46438bc0be09b3f49c43 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -950,9 +950,9 @@ close_fd:
 
 static int list_ns(int argc, char **argv, struct command *cmd, struct plugin *plugin)
 {
-       const char *desc = "For the specified device, show the "\
-               "namespace list in a NVMe subsystem, optionally starting with a given namespace";
-       const char *namespace_id = "namespace number returned list should to start after";
+       const char *desc = "For the specified controller handle, show the "\
+               "namespace list in the associated NVMe subsystem, optionally starting with a given nsid.";
+       const char *namespace_id = "first nsid returned list should start from";
        const char *all = "show all namespaces in the subsystem, whether attached or inactive";
        int err, i, fd;
        __u32 ns_list[1024];
@@ -963,7 +963,7 @@ static int list_ns(int argc, char **argv, struct command *cmd, struct plugin *pl
        };
 
        struct config cfg = {
-               .namespace_id = 0,
+               .namespace_id = 1,
        };
 
        const struct argconfig_commandline_options command_line_options[] = {
@@ -976,7 +976,14 @@ static int list_ns(int argc, char **argv, struct command *cmd, struct plugin *pl
        if (fd < 0)
                return fd;
 
-       err = nvme_identify_ns_list(fd, cfg.namespace_id, !!cfg.all, ns_list);
+       if (!cfg.namespace_id) {
+               err = -EINVAL;
+               fprintf(stderr, "invalid nsid parameter\n");
+               goto close_fd;
+       }
+
+       err = nvme_identify_ns_list(fd, cfg.namespace_id - 1, !!cfg.all,
+                                   ns_list);
        if (!err) {
                for (i = 0; i < 1024; i++)
                        if (ns_list[i])
@@ -987,6 +994,7 @@ static int list_ns(int argc, char **argv, struct command *cmd, struct plugin *pl
        else
                perror("id namespace list");
 
+close_fd:
        close(fd);
 
        return err;