From: Jeremy Kerr Date: Thu, 14 Jul 2022 07:01:22 +0000 (+0800) Subject: nvme: Simplify ns list identify X-Git-Tag: v2.1.2~3^2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=683e3c38db813cc028f6c29ecb07eab188453d2b;p=users%2Fsagi%2Fnvme-cli.git nvme: Simplify ns list identify 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 [dwagner: changed how the struct args is initialized] Signed-off-by: Daniel Wagner --- diff --git a/nvme.c b/nvme.c index 0bc88766..4096a91e 100644 --- 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)