Commit 7e9386da authored by Tomasz Zawadzki's avatar Tomasz Zawadzki Committed by Tomasz Zawadzki
Browse files

bdev/nvme: simplify nvme_ctrlr_populate_namespaces() loop for adding new nvme_ns



Simplify the loop for adding new nvme_ns, switching from while() to for() and
reducing indentation by one level.

No functional change done in this patch.

Change-Id: If97e6bd55ae93e9d0736846567207945257911c1
Signed-off-by: default avatarTomasz Zawadzki <tomasz.zawadzki@nutanix.com>
Reviewed-on: https://review.spdk.io/c/spdk/spdk/+/26522


Tested-by: default avatarSPDK Automated Test System <spdkbot@gmail.com>
Reviewed-by: default avatarJacek Kalwas <jacek.kalwas@nutanix.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarBen Walker <ben@nvidia.com>
Reviewed-by: default avatarJim Harris <jim.harris@nvidia.com>
parent 9598f64c
Loading
Loading
Loading
Loading
+23 −24
Original line number Diff line number Diff line
@@ -5165,17 +5165,19 @@ nvme_ctrlr_populate_namespaces(struct nvme_ctrlr *nvme_ctrlr,
	}

	/* Loop through all of the namespaces at the nvme level and see if any of them are new */
	nsid = spdk_nvme_ctrlr_get_first_active_ns(ctrlr);
	while (nsid != 0) {
	for (nsid = spdk_nvme_ctrlr_get_first_active_ns(ctrlr); nsid != 0;
	     nsid = spdk_nvme_ctrlr_get_next_active_ns(ctrlr, nsid)) {
		nvme_ns = nvme_ctrlr_get_ns(nvme_ctrlr, nsid);
		if (nvme_ns != NULL) {
			continue;
		}

		if (nvme_ns == NULL) {
		/* Found a new one */

		nvme_ns = nvme_ns_alloc();
		if (nvme_ns == NULL) {
			NVME_CTRLR_ERRLOG(nvme_ctrlr, "Failed to allocate namespace\n");
			/* This just fails to attach the namespace. It may work on a future attempt. */
				nsid = spdk_nvme_ctrlr_get_next_active_ns(ctrlr, nsid);
			continue;
		}

@@ -5196,9 +5198,6 @@ nvme_ctrlr_populate_namespaces(struct nvme_ctrlr *nvme_ctrlr,
		nvme_ctrlr_populate_namespace(nvme_ctrlr, nvme_ns);
	}

		nsid = spdk_nvme_ctrlr_get_next_active_ns(ctrlr, nsid);
	}

	if (ctx) {
		/* Decrement this count now that the loop is over to account
		 * for the one we started with.  If the count is then 0, we