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: Shuhei 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: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
This commit is contained in:
Shuhei Matsumoto 2021-06-14 06:16:46 +09:00 committed by Tomasz Zawadzki
parent fcad162082
commit 0f4cebebbf

View File

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