From 7ffc8833f63f49d44eccffdc6dd712236df7ca56 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Wed, 3 Nov 2021 12:07:12 -0700 Subject: [PATCH] examples/nvme/hello_world: Iterate only active namespaces Avoid registering inactive namespaces in the example. They can't be used for I/O. Signed-off-by: Ben Walker Change-Id: I404ca48666b566fd3248a3f56b25ea6509fa8d38 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10099 Community-CI: Mellanox Build Bot Community-CI: Broadcom CI Tested-by: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Shuhei Matsumoto Reviewed-by: Aleksey Marchuk Reviewed-by: Jim Harris --- examples/nvme/hello_world/hello_world.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/nvme/hello_world/hello_world.c b/examples/nvme/hello_world/hello_world.c index 29bb583a0..ed1a91513 100644 --- a/examples/nvme/hello_world/hello_world.c +++ b/examples/nvme/hello_world/hello_world.c @@ -321,7 +321,7 @@ static void attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid, struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_ctrlr_opts *opts) { - int nsid, num_ns; + int nsid; struct ctrlr_entry *entry; struct spdk_nvme_ns *ns; const struct spdk_nvme_ctrlr_data *cdata; @@ -357,9 +357,8 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid, * * Note that in NVMe, namespace IDs start at 1, not 0. */ - num_ns = spdk_nvme_ctrlr_get_num_ns(ctrlr); - printf("Using controller %s with %d namespaces.\n", entry->name, num_ns); - for (nsid = 1; nsid <= num_ns; nsid++) { + for (nsid = spdk_nvme_ctrlr_get_first_active_ns(ctrlr); nsid != 0; + nsid = spdk_nvme_ctrlr_get_next_active_ns(ctrlr, nsid)) { ns = spdk_nvme_ctrlr_get_ns(ctrlr, nsid); if (ns == NULL) { continue;