]> www.infradead.org Git - users/hch/nvme-cli.git/commitdiff
update get_nsid for new api
authorKeith Busch <kbusch@kernel.org>
Fri, 5 Jun 2020 15:02:45 +0000 (08:02 -0700)
committerKeith Busch <kbusch@kernel.org>
Fri, 5 Jun 2020 17:02:11 +0000 (10:02 -0700)
Signed-off-by: Keith Busch <kbusch@kernel.org>
libnvme
nvme.c
plugins/huawei/huawei-nvme.c
plugins/lnvm/lnvm-nvme.c
plugins/netapp/netapp-nvme.c
plugins/virtium/virtium-nvme.c
plugins/zns/zns.c

diff --git a/libnvme b/libnvme
index 4b562745fb65d2eac5532ff59170eadb365fc7bc..0895b50cead4ebd39b1409e6f3e87e6423c0974b 160000 (submodule)
--- a/libnvme
+++ b/libnvme
@@ -1 +1 @@
-Subproject commit 4b562745fb65d2eac5532ff59170eadb365fc7bc
+Subproject commit 0895b50cead4ebd39b1409e6f3e87e6423c0974b
diff --git a/nvme.c b/nvme.c
index 5d5e9992324b5783ce5eddcdabcdf75d5002d164..856cf77a57173cbabef3e0eacbda049fbb6e2389 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -1136,13 +1136,9 @@ static int delete_ns(int argc, char **argv, struct command *cmd, struct plugin *
                goto ret;
 
        if (!cfg.namespace_id) {
-               cfg.namespace_id = nvme_get_nsid(fd);
-               if (cfg.namespace_id == 0) {
-                       err = -EINVAL;
-                       goto close_fd;
-               }
-               else if (cfg.namespace_id < 0) {
-                       err = cfg.namespace_id;
+               err = nvme_get_nsid(fd, &cfg.namespace_id);
+               if (err < 0) {
+                       perror("get-namespace-id");
                        goto close_fd;
                }
        }
@@ -1572,9 +1568,9 @@ static int ns_descs(int argc, char **argv, struct command *cmd, struct plugin *p
                flags = 0;
 
        if (!cfg.namespace_id) {
-               cfg.namespace_id = nvme_get_nsid(fd);
-               if (cfg.namespace_id < 0) {
-                       err = cfg.namespace_id;
+               err = nvme_get_nsid(fd, &cfg.namespace_id);
+               if (err < 0) {
+                       perror("get-namespace-id");
                        goto close_fd;
                }
        }
@@ -1614,7 +1610,7 @@ static int id_ns(int argc, char **argv, struct command *cmd, struct plugin *plug
        int err, fd;
 
        struct config {
-               int   namespace_id;
+               __u32 namespace_id;
                int   vendor_specific;
                int   raw_binary;
                int   human_readable;
@@ -1651,14 +1647,9 @@ static int id_ns(int argc, char **argv, struct command *cmd, struct plugin *plug
                flags |= VERBOSE;
 
        if (!cfg.namespace_id) {
-               cfg.namespace_id = nvme_get_nsid(fd);
-               if (cfg.namespace_id < 0) {
-                       fprintf(stderr,
-                               "Error: requesting namespace-id from non-block device\n");
-                       err = cfg.namespace_id;
-                       goto close_fd;
-               } else if (!cfg.namespace_id) {
-                       err = -EINVAL;
+               err = nvme_get_nsid(fd, &cfg.namespace_id);
+               if (err < 0) {
+                       perror("get-namespace-id");
                        goto close_fd;
                }
        }
@@ -1828,8 +1819,9 @@ close_fd:
 
 static int get_ns_id(int argc, char **argv, struct command *cmd, struct plugin *plugin)
 {
-       int err = 0, nsid, fd;
        const char *desc = "Get namespce ID of a the block device.";
+       int err, fd;
+       __u32 nsid;
 
        OPT_ARGS(opts) = {
                OPT_END()
@@ -1837,21 +1829,16 @@ static int get_ns_id(int argc, char **argv, struct command *cmd, struct plugin *
 
        err = fd = parse_and_open(argc, argv, desc, opts);
        if (fd < 0)
-               goto ret;
+               return errno;
 
-       nsid = nvme_get_nsid(fd);
-       if (nsid <= 0) {
+       err = nvme_get_nsid(fd, &nsid);
+       if (!err)
+               printf("%s: namespace-id:%u\n", devicename, nsid);
+       else
                perror(devicename);
-               err = errno;
-               goto close_fd;
-       }
-       err = 0;
-       printf("%s: namespace-id:%d\n", devicename, nsid);
 
-close_fd:
        close(fd);
-ret:
-       return nvme_status_to_errno(err, false);
+       return !err ? 0 : errno;
 }
 
 static int virtual_mgmt(int argc, char **argv, struct command *cmd, struct plugin *plugin)
@@ -2780,9 +2767,9 @@ static int format(int argc, char **argv, struct command *cmd, struct plugin *plu
                cfg.namespace_id = NVME_NSID_ALL;
        } else {
                if (!cfg.namespace_id) {
-                       cfg.namespace_id = nvme_get_nsid(fd);
-                       if (cfg.namespace_id < 0) {
-                               err = cfg.namespace_id;
+                       err = nvme_get_nsid(fd, &cfg.namespace_id);
+                       if (err < 0) {
+                               perror("get-namespace-id");
                                goto close_fd;
                        }
                }
@@ -3153,9 +3140,9 @@ static int dir_send(int argc, char **argv, struct command *cmd, struct plugin *p
                goto ret;
 
        if (!cfg.namespace_id) {
-               cfg.namespace_id = nvme_get_nsid(fd);
-               if (cfg.namespace_id < 0) {
-                       err = cfg.namespace_id;
+               err = nvme_get_nsid(fd, &cfg.namespace_id);
+               if (err < 0) {
+                       perror("get-namespace-id");
                        goto close_fd;
                }
        }
@@ -3247,9 +3234,9 @@ static int write_uncor(int argc, char **argv, struct command *cmd, struct plugin
                goto ret;
 
        if (!cfg.namespace_id) {
-               cfg.namespace_id = nvme_get_nsid(fd);
-               if (cfg.namespace_id < 0) {
-                       err = cfg.namespace_id;
+               err = nvme_get_nsid(fd, &cfg.namespace_id);
+               if (err < 0) {
+                       perror("get-namespace-id");
                        goto close_fd;
                }
        }
@@ -3327,9 +3314,9 @@ static int write_zeroes(int argc, char **argv, struct command *cmd, struct plugi
        if (cfg.deac)
                control |= NVME_IO_DEAC;
        if (!cfg.namespace_id) {
-               cfg.namespace_id = nvme_get_nsid(fd);
-               if (cfg.namespace_id < 0) {
-                       err = cfg.namespace_id;
+               err = nvme_get_nsid(fd, &cfg.namespace_id);
+               if (err < 0) {
+                       perror("get-namespace-id");
                        goto close_fd;
                }
        }
@@ -3406,9 +3393,9 @@ static int dsm(int argc, char **argv, struct command *cmd, struct plugin *plugin
        }
 
        if (!cfg.namespace_id) {
-               cfg.namespace_id = nvme_get_nsid(fd);
-               if (cfg.namespace_id < 0) {
-                       err = cfg.namespace_id;
+               err = nvme_get_nsid(fd, &cfg.namespace_id);
+               if (err < 0) {
+                       perror("get-namespace-id");
                        goto close_fd;
                }
        }
@@ -3453,9 +3440,9 @@ static int flush(int argc, char **argv, struct command *cmd, struct plugin *plug
                goto ret;
 
        if (!cfg.namespace_id) {
-               cfg.namespace_id = nvme_get_nsid(fd);
-               if (cfg.namespace_id < 0) {
-                       err = cfg.namespace_id;
+               err = nvme_get_nsid(fd, &cfg.namespace_id);
+               if (err < 0) {
+                       perror("get-namespace-id");
                        goto close_fd;
                }
        }
@@ -3510,9 +3497,9 @@ static int resv_acquire(int argc, char **argv, struct command *cmd, struct plugi
                goto ret;
 
        if (!cfg.namespace_id) {
-               cfg.namespace_id = nvme_get_nsid(fd);
-               if (cfg.namespace_id < 0) {
-                       err = cfg.namespace_id;
+               err = nvme_get_nsid(fd, &cfg.namespace_id);
+               if (err < 0) {
+                       perror("get-namespace-id");
                        goto close_fd;
                }
        }
@@ -3571,9 +3558,9 @@ static int resv_register(int argc, char **argv, struct command *cmd, struct plug
                goto ret;
 
        if (!cfg.namespace_id) {
-               cfg.namespace_id = nvme_get_nsid(fd);
-               if (cfg.namespace_id < 0) {
-                       err = cfg.namespace_id;
+               err = nvme_get_nsid(fd, &cfg.namespace_id);
+               if (err < 0) {
+                       perror("get-namespace-id");
                        goto close_fd;
                }
        }
@@ -3640,9 +3627,9 @@ static int resv_release(int argc, char **argv, struct command *cmd, struct plugi
                goto ret;
 
        if (!cfg.namespace_id) {
-               cfg.namespace_id = nvme_get_nsid(fd);
-               if (cfg.namespace_id < 0) {
-                       err = cfg.namespace_id;
+               err = nvme_get_nsid(fd, &cfg.namespace_id);
+               if (err < 0) {
+                       perror("get-namespace-id");
                        goto close_fd;
                }
        }
@@ -3710,9 +3697,9 @@ static int resv_report(int argc, char **argv, struct command *cmd, struct plugin
                flags = 0;
 
        if (!cfg.namespace_id) {
-               cfg.namespace_id = nvme_get_nsid(fd);
-               if (cfg.namespace_id < 0) {
-                       err = cfg.namespace_id;
+               err = nvme_get_nsid(fd, &cfg.namespace_id);
+               if (err < 0) {
+                       perror("get-namespace-id");
                        goto close_fd;
                }
        }
@@ -3797,7 +3784,7 @@ static int submit_io(int opcode, char *command, const char *desc,
                __u16 dsmgmt;
                __u16 app_tag_mask;
                __u16 app_tag;
-               int   namespace_id;
+               __u32 namespace_id;
                int   limited_retry;
                int   force_unit_access;
                int   show;
@@ -3835,9 +3822,9 @@ static int submit_io(int opcode, char *command, const char *desc,
                goto ret;
 
        if (!cfg.namespace_id) {
-               cfg.namespace_id = nvme_get_nsid(fd);
-               if (cfg.namespace_id <= 0) {
-                       err = cfg.namespace_id;
+               err = nvme_get_nsid(fd, &cfg.namespace_id);
+               if (err < 0) {
+                       perror("get-namespace-id");
                        goto close_fd;
                }
        }
@@ -4088,9 +4075,9 @@ static int verify_cmd(int argc, char **argv, struct command *cmd, struct plugin
                control |= NVME_IO_FUA;
 
        if (!cfg.namespace_id) {
-               cfg.namespace_id = nvme_get_nsid(fd);
-               if (cfg.namespace_id < 0) {
-                       err = cfg.namespace_id;
+               err = nvme_get_nsid(fd, &cfg.namespace_id);
+               if (err < 0) {
+                       perror("get-namespace-id");
                        goto close_fd;
                }
        }
index 8fe9fd3bf48e71bafe48af36324a52d8fa77996d..f79b7ee82e85086d4931348b986941210cd83487 100644 (file)
@@ -47,7 +47,7 @@
 struct huawei_list_item {
        char                node[1024];
        struct nvme_id_ctrl ctrl;
-       int                 nsid;
+       unsigned int        nsid;
        struct nvme_id_ns   ns;
        unsigned            block;
        char                ns_name[NS_NAME_LEN];
@@ -66,8 +66,7 @@ struct huawei_list_element_len {
 
 static int huawei_get_nvme_info(int fd, struct huawei_list_item *item, const char *node)
 {
-       int err;
-       int len;
+       int err, len;
        struct stat nvme_stat_info;
 
        memset(item, 0, sizeof(*item));
@@ -84,7 +83,13 @@ static int huawei_get_nvme_info(int fd, struct huawei_list_item *item, const cha
        }
 
        item->huawei_device = true;
-       item->nsid = nvme_get_nsid(fd);
+
+       err = nvme_get_nsid(fd, &item->nsid);
+       if (err < 0) {
+               perror("get-namespace-id");
+               return err;
+       }
+
        err = nvme_identify_ns(fd, item->nsid, &item->ns);
        if (err)
                return err;
index 0190f0bda9de12de3d74108dbfd7b0ab14d4b492..f6a24bff96641f789a1733f79aad308fb35cefbd 100644 (file)
@@ -1129,7 +1129,11 @@ static int lnvm_chunk_log(int argc, char **argv, struct command *cmd, struct plu
        else if (cfg.human_readable)
                flags |= VERBOSE;
 
-       nsid = nvme_get_nsid(fd);
+       err = nvme_get_nsid(fd, &nsid);
+       if (err < 0) {
+               perror("get-namespace-id");
+               goto close;
+       }
 
        /*
         * It needs to figure out how many bytes will be requested by this
index 746411d8be409098c76dce6bd63ffbeb10fdbb20..b99035558153a9ab630465d4606754b633565195 100644 (file)
@@ -57,14 +57,14 @@ enum {
 static const char *dev_path = "/dev/";
 
 struct smdevice_info {
-       int                     nsid;
+       unsigned int            nsid;
        struct nvme_id_ctrl     ctrl;
        struct nvme_id_ns       ns;
        char                    dev[265];
 };
 
 struct ontapdevice_info {
-       int                     nsid;
+       unsigned int            nsid;
        struct nvme_id_ctrl     ctrl;
        struct nvme_id_ns       ns;
        char                    nsdesc[4096];
@@ -403,7 +403,12 @@ static int netapp_smdevices_get_info(int fd, struct smdevice_info *item,
        if (strncmp("NetApp E-Series", item->ctrl.mn, 15) != 0)
                return 0; /* not the right model of controller */
 
-       item->nsid = nvme_get_nsid(fd);
+       err = nvme_get_nsid(fd, &item->nsid);
+       if (err < 0) {
+               perror("get-namespace-id");
+               return err;
+       }
+       
        err = nvme_identify_ns(fd, item->nsid, &item->ns);
        if (err) {
                fprintf(stderr, "Unable to identify namespace for %s (%s)\n",
@@ -431,7 +436,11 @@ static int netapp_ontapdevices_get_info(int fd, struct ontapdevice_info *item,
                /* not the right controller model */
                return 0;
 
-       item->nsid = nvme_get_nsid(fd);
+       err = nvme_get_nsid(fd, &item->nsid);
+       if (err < 0) {
+               perror("get-namespace-id");
+               return err;
+       }
 
        err = nvme_identify_ns(fd, item->nsid, &item->ns);
        if (err) {
index 1e62156664e95da1cce723ddeebd80aba85923ec..0076fb0b8afcae46e97a1af1a174e990aa7b12ee 100644 (file)
@@ -257,8 +257,8 @@ static int vt_add_entry_to_log(const int fd, const char *path, const struct vtvi
 {
        struct vtview_smart_log_entry smart;
        char filename[256] = "";
+       unsigned int nsid = 0;
        int ret = 0;
-       int nsid = 0;
 
        memset(smart.path, 0, sizeof(smart.path));
        strcpy(smart.path, path);
@@ -268,11 +268,11 @@ static int vt_add_entry_to_log(const int fd, const char *path, const struct vtvi
                strcpy(filename, cfg->output_file);
 
        smart.time_stamp = time(NULL);
-       nsid = nvme_get_nsid(fd);
 
-       if (nsid <= 0) {
-               printf("Cannot read namespace-id\n");
-               return -1;
+       ret = nvme_get_nsid(fd, &nsid);
+       if (ret < 0) {
+               perror("get-namespace-id");
+               return ret;
        }
 
        ret = nvme_identify_ns(fd, nsid, &smart.raw_ns);
index c4d834ac4b401418d442e39dc458680b9301b849..764e0db5dd8adb61e29009252a762be95ae4d073 100644 (file)
@@ -68,7 +68,7 @@ static int id_ns(int argc, char **argv, struct command *cmd, struct plugin *plug
 
        struct config {
                char *output_format;
-               int namespace_id;
+               __u32 namespace_id;
                int verbose;
        };
 
@@ -94,14 +94,9 @@ static int id_ns(int argc, char **argv, struct command *cmd, struct plugin *plug
                flags |= VERBOSE;
 
        if (!cfg.namespace_id) {
-               cfg.namespace_id = nvme_get_nsid(fd);
-               if (cfg.namespace_id <= 0) {
-                       if (!namespace_id) {
-                               errno = EINVAL;
-                               err = -1;
-                       } else
-                               err = cfg.namespace_id;
-                       fprintf(stderr, "Error: retrieving namespace-id\n");
+               err = nvme_get_nsid(fd, &cfg.namespace_id);
+               if (err < 0) {
+                       perror("get-namespace-id");
                        goto close_fd;
                }
        }
@@ -128,14 +123,9 @@ static int __zns_mgmt_send(int fd, __u32 namespace_id, __u64 zslba,
        int err;
 
        if (!namespace_id) {
-               namespace_id = nvme_get_nsid(fd);
-               if (namespace_id <= 0) {
-                       if (!namespace_id) {
-                               errno = EINVAL;
-                               err = -1;
-                       } else
-                               err = namespace_id;
-                       fprintf(stderr, "Error: retrieving namespace-id\n");
+               err = nvme_get_nsid(fd, &namespace_id);
+               if (err < 0) {
+                       perror("get-namespace-id");
                        goto close_fd;
                }
        }
@@ -456,7 +446,7 @@ static int report_zones(int argc, char **argv, struct command *cmd, struct plugi
        struct config {
                char *output_format;
                __u64 zslba;
-               int   namespace_id;
+               __u32 namespace_id;
                int   num_descs;
                int   state;
                bool  verbose;
@@ -491,14 +481,9 @@ static int report_zones(int argc, char **argv, struct command *cmd, struct plugi
                flags |= VERBOSE;
 
        if (!cfg.namespace_id) {
-               cfg.namespace_id = nvme_get_nsid(fd);
-               if (cfg.namespace_id <= 0) {
-                       if (!namespace_id) {
-                               errno = EINVAL;
-                               err = -1;
-                       } else
-                               err = cfg.namespace_id;
-                       fprintf(stderr, "Error: retrieving namespace-id\n");
+               err = nvme_get_nsid(fd, &cfg.namespace_id);
+               if (err < 0) {
+                       perror("get-namespace-id");
                        goto close_fd;
                }
        }
@@ -594,7 +579,7 @@ static int zone_append(int argc, char **argv, struct command *cmd, struct plugin
 
        err = fd = parse_and_open(argc, argv, desc, opts);
        if (fd < 0)
-               return errno;
+               return errno;
 
        if (!cfg.data_size) {
                fprintf(stderr, "Append size not provided\n");