From 12933a32bf9e99ca86076c15e665d4f9222fa064 Mon Sep 17 00:00:00 2001 From: Keith Busch Date: Wed, 10 Jun 2020 11:15:24 -0700 Subject: [PATCH] fix zone management nsid reporting Signed-off-by: Keith Busch --- libnvme | 2 +- plugins/zns/zns.c | 31 +++++++++++++++++++------------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/libnvme b/libnvme index 6d14f18..a458217 160000 --- a/libnvme +++ b/libnvme @@ -1 +1 @@ -Subproject commit 6d14f18d883ebc3cbca4fce1666fdfe3d5a9eb42 +Subproject commit a4582173fe8072f80f5eef7eca77d52f853d81dc diff --git a/plugins/zns/zns.c b/plugins/zns/zns.c index 63b9f03..24c0a1c 100644 --- a/plugins/zns/zns.c +++ b/plugins/zns/zns.c @@ -121,14 +121,6 @@ static int __zns_mgmt_send(int fd, __u32 namespace_id, __u64 zslba, { int err; - if (!namespace_id) { - err = nvme_get_nsid(fd, &namespace_id); - if (err < 0) { - perror("get-namespace-id"); - goto close_fd; - } - } - err = nvme_zns_mgmt_send(fd, namespace_id, zslba, select_all, zsa, data_len, buf); close_fd: @@ -169,11 +161,19 @@ static int zns_mgmt_send(int argc, char **argv, struct command *cmd, struct plug if (fd < 0) goto free; + if (!cfg.namespace_id) { + err = nvme_get_nsid(fd, &cfg.namespace_id); + if (err < 0) { + perror("get-namespace-id"); + goto close_fd; + } + } + err = __zns_mgmt_send(fd, cfg.namespace_id, cfg.zslba, cfg.select_all, zsa, 0, NULL); if (!err) printf("%s: Success, action:%d zone:%"PRIx64" nsid:%d\n", command, - zsa, (uint64_t)zslba, cfg.namespace_id); + zsa, (uint64_t)cfg.zslba, cfg.namespace_id); else nvme_show_status(command, err); free: @@ -219,6 +219,14 @@ static int zone_mgmt_send(int argc, char **argv, struct command *cmd, struct plu if (fd < 0) return errno; + if (!cfg.namespace_id) { + err = nvme_get_nsid(fd, &cfg.namespace_id); + if (err < 0) { + perror("get-namespace-id"); + goto close_fd; + } + } + if (cfg.data_len) { if (posix_memalign(&buf, getpagesize(), cfg.data_len)) { fprintf(stderr, "can not allocate feature payload\n"); @@ -411,7 +419,6 @@ static int zone_mgmt_recv(int argc, char **argv, struct command *cmd, struct plu .output_format = "normal", }; - OPT_ARGS(opts) = { OPT_END() }; @@ -739,9 +746,9 @@ static int zone_append(int argc, char **argv, struct command *cmd, struct plugin printf("Success appended data to LBA %"PRIx64"\n", (uint64_t)result); else nvme_show_status("zone-append", err); - free_meta: - free(mbuf); + if (mbuf) + free(mbuf); close_mfd: if (cfg.metadata) close(mfd); -- 2.50.1