]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme: Simplify ns list identify
authorJeremy Kerr <jk@codeconstruct.com.au>
Thu, 14 Jul 2022 07:01:22 +0000 (15:01 +0800)
committerDaniel Wagner <dwagner@suse.de>
Thu, 11 Aug 2022 07:44:36 +0000 (09:44 +0200)
Rather than multiplexing over four functions (which all then call
nvme_identify) just use nvme_identify directly, and set the identify
parameters according to the 'csi' and 'all' parameters.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
[dwagner: changed how the struct args is initialized]
Signed-off-by: Daniel Wagner <dwagner@suse.de>
nvme.c

diff --git a/nvme.c b/nvme.c
index 0bc88766504f37b03f3aca7d40b827ee6a0fa8bc..4096a91ead0f2475474318188f3bb260fa338045 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -2044,23 +2044,24 @@ static int list_ns(int argc, char **argv, struct command *cmd, struct plugin *pl
                goto close_fd;
        }
 
+       struct nvme_identify_args args = {
+               .args_size      = sizeof(args),
+               .fd             = fd,
+               .timeout        = NVME_DEFAULT_IOCTL_TIMEOUT,
+               .data           = &ns_list,
+               .nsid           = cfg.namespace_id - 1.
+       };
        if (cfg.csi < 0) {
-               if (cfg.all)
-                       err = nvme_identify_allocated_ns_list(fd,
-                               cfg.namespace_id - 1, &ns_list);
-               else
-                       err = nvme_identify_active_ns_list(fd,
-                               cfg.namespace_id - 1, &ns_list);
-
+               args.cns = cfg.all ? NVME_IDENTIFY_CNS_ALLOCATED_NS_LIST :
+                       NVME_IDENTIFY_CNS_NS_ACTIVE_LIST;
        } else {
-               if (cfg.all)
-                       err = nvme_identify_allocated_ns_list_csi(fd,
-                               cfg.namespace_id - 1, cfg.csi, &ns_list);
-               else
-                       err = nvme_identify_active_ns_list_csi(fd,
-                               cfg.namespace_id - 1, cfg.csi, &ns_list);
+               args.cns = cfg.all ? NVME_IDENTIFY_CNS_CSI_ALLOCATED_NS_LIST :
+                       NVME_IDENTIFY_CNS_CSI_NS_ACTIVE_LIST;
+               args.csi = cfg.csi;
        }
 
+       err = nvme_identify(&args);
+
        if (!err)
                nvme_show_list_ns(&ns_list, flags);
        else if (err > 0)