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 <benjamin.walker@intel.com>
Change-Id: I404ca48666b566fd3248a3f56b25ea6509fa8d38
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10099
Community-CI: Mellanox Build Bot
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Ben Walker 2021-11-03 12:07:12 -07:00 committed by Jim Harris
parent 6ccc8c1a39
commit 7ffc8833f6

View File

@ -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;