Commit 0f4cebeb authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Tomasz Zawadzki
Browse files

bdev/nvme: Factor out registering nvme_bdev_ctrlr and populating ns into a helper function



Factor out registering nvme_bdev_ctrlr as io_device and populating
namespaces after creating nvme_bdev_ctrlr into a helper function.

We extract spdk_io_device_register() from nvme_bdev_ctrlr_create()
because free(NULL) is correct but spdk_io_device_unregister(NULL) is
not allowed, and hence it is very simple if we call spdk_io_device_register()
only after nvme_bdev_ctrlr is successfully created.

Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: Ia4d85ccf96f3ef62e51db9d08ec606d4100c7ebd
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8317


Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
parent fcad1620
Loading
Loading
Loading
Loading
+14 −7
Original line number Diff line number Diff line
@@ -1806,6 +1806,19 @@ populate_namespaces_cb(struct nvme_async_probe_ctx *ctx, size_t count, int rc)
	}
}

static void
nvme_bdev_ctrlr_create_done(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr,
			    struct nvme_async_probe_ctx *ctx)
{
	spdk_io_device_register(nvme_bdev_ctrlr,
				bdev_nvme_create_path_cb,
				bdev_nvme_destroy_path_cb,
				sizeof(struct nvme_io_path),
				nvme_bdev_ctrlr->name);

	nvme_ctrlr_populate_namespaces(nvme_bdev_ctrlr, ctx);
}

static int
nvme_bdev_ctrlr_create(struct spdk_nvme_ctrlr *ctrlr,
		       const char *name,
@@ -1884,12 +1897,6 @@ nvme_bdev_ctrlr_create(struct spdk_nvme_ctrlr *ctrlr,

	nvme_bdev_ctrlr->prchk_flags = prchk_flags;

	spdk_io_device_register(nvme_bdev_ctrlr,
				bdev_nvme_create_path_cb,
				bdev_nvme_destroy_path_cb,
				sizeof(struct nvme_io_path),
				name);

	nvme_bdev_ctrlr->adminq_timer_poller = SPDK_POLLER_REGISTER(bdev_nvme_poll_adminq, nvme_bdev_ctrlr,
					       g_opts.nvme_adminq_poll_period_us);

@@ -1908,7 +1915,7 @@ nvme_bdev_ctrlr_create(struct spdk_nvme_ctrlr *ctrlr,
		nvme_bdev_ctrlr->opal_dev = spdk_opal_dev_construct(nvme_bdev_ctrlr->ctrlr);
	}

	nvme_ctrlr_populate_namespaces(nvme_bdev_ctrlr, ctx);
	nvme_bdev_ctrlr_create_done(nvme_bdev_ctrlr, ctx);
	return 0;

err: