bdev/nvme: Merge populate_namespaces() and its callback into nvme_bdev_ctrlr_create()
The following changes will require nvme_bdev_ctrlr_create() to be asynchronous. As a preparation, merge nvme_ctrlr_populate_namespaces() and populate_namespaces_cb() into nvme_bdev_ctrlr_create(). Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Change-Id: I623f927da072d746b4bd83314c0f5bcb9cc34ef0 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7043 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Reviewed-by: Paul Luse <paul.e.luse@intel.com> Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
cd820331a2
commit
1aa2537480
@ -1716,11 +1716,11 @@ populate_namespaces_cb(struct nvme_async_probe_ctx *ctx, size_t count, int rc)
|
||||
}
|
||||
|
||||
static int
|
||||
nvme_bdev_ctrlr_create(struct spdk_nvme_ctrlr *ctrlr,
|
||||
const char *name,
|
||||
const struct spdk_nvme_transport_id *trid,
|
||||
uint32_t prchk_flags,
|
||||
struct nvme_bdev_ctrlr **_nvme_bdev_ctrlr)
|
||||
_nvme_bdev_ctrlr_create(struct spdk_nvme_ctrlr *ctrlr,
|
||||
const char *name,
|
||||
const struct spdk_nvme_transport_id *trid,
|
||||
uint32_t prchk_flags,
|
||||
struct nvme_bdev_ctrlr **_nvme_bdev_ctrlr)
|
||||
{
|
||||
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr;
|
||||
struct nvme_bdev_ctrlr_trid *trid_entry;
|
||||
@ -1837,16 +1837,39 @@ err_init_mutex:
|
||||
return rc;
|
||||
}
|
||||
|
||||
static void
|
||||
nvme_bdev_ctrlr_create(struct spdk_nvme_ctrlr *ctrlr,
|
||||
const char *name,
|
||||
const struct spdk_nvme_transport_id *trid,
|
||||
uint32_t prchk_flags,
|
||||
struct nvme_async_probe_ctx *ctx)
|
||||
{
|
||||
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr = NULL;
|
||||
int rc;
|
||||
|
||||
rc = _nvme_bdev_ctrlr_create(ctrlr, name, trid, prchk_flags, &nvme_bdev_ctrlr);
|
||||
if (rc != 0) {
|
||||
SPDK_ERRLOG("Failed to create new NVMe controller\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
nvme_ctrlr_populate_namespaces(nvme_bdev_ctrlr, ctx);
|
||||
return;
|
||||
|
||||
err:
|
||||
if (ctx != NULL) {
|
||||
populate_namespaces_cb(ctx, 0, rc);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr;
|
||||
struct nvme_probe_ctx *ctx = cb_ctx;
|
||||
char *name = NULL;
|
||||
uint32_t prchk_flags = 0;
|
||||
size_t i;
|
||||
int rc;
|
||||
|
||||
if (ctx) {
|
||||
for (i = 0; i < ctx->count; i++) {
|
||||
@ -1866,14 +1889,7 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
|
||||
|
||||
SPDK_DEBUGLOG(bdev_nvme, "Attached to %s (%s)\n", trid->traddr, name);
|
||||
|
||||
rc = nvme_bdev_ctrlr_create(ctrlr, name, trid, prchk_flags, &nvme_bdev_ctrlr);
|
||||
if (rc != 0) {
|
||||
SPDK_ERRLOG("Failed to create new NVMe controller\n");
|
||||
free(name);
|
||||
return;
|
||||
}
|
||||
|
||||
nvme_ctrlr_populate_namespaces(nvme_bdev_ctrlr, NULL);
|
||||
nvme_bdev_ctrlr_create(ctrlr, name, trid, prchk_flags, NULL);
|
||||
|
||||
free(name);
|
||||
}
|
||||
@ -2193,21 +2209,12 @@ connect_attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
|
||||
rc = bdev_nvme_add_trid(nvme_bdev_ctrlr, ctrlr, &ctx->trid);
|
||||
|
||||
spdk_nvme_detach(ctrlr);
|
||||
goto exit;
|
||||
|
||||
populate_namespaces_cb(ctx, 0, rc);
|
||||
return;
|
||||
}
|
||||
|
||||
rc = nvme_bdev_ctrlr_create(ctrlr, ctx->base_name, &ctx->trid, ctx->prchk_flags,
|
||||
&nvme_bdev_ctrlr);
|
||||
if (rc) {
|
||||
SPDK_ERRLOG("Failed to create new device\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
nvme_ctrlr_populate_namespaces(nvme_bdev_ctrlr, ctx);
|
||||
return;
|
||||
|
||||
exit:
|
||||
populate_namespaces_cb(ctx, 0, rc);
|
||||
nvme_bdev_ctrlr_create(ctrlr, ctx->base_name, &ctx->trid, ctx->prchk_flags, ctx);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -962,8 +962,7 @@ test_create_ctrlr(void)
|
||||
|
||||
ut_init_trid(&trid);
|
||||
|
||||
rc = nvme_bdev_ctrlr_create(&ctrlr, "nvme0", &trid, 0, NULL);
|
||||
CU_ASSERT(rc == 0);
|
||||
nvme_bdev_ctrlr_create(&ctrlr, "nvme0", &trid, 0, NULL);
|
||||
|
||||
CU_ASSERT(nvme_bdev_ctrlr_get_by_name("nvme0") != NULL);
|
||||
|
||||
@ -993,8 +992,9 @@ test_reset_ctrlr(void)
|
||||
|
||||
set_thread(0);
|
||||
|
||||
rc = nvme_bdev_ctrlr_create(&ctrlr, "nvme0", &trid, 0, &nvme_bdev_ctrlr);
|
||||
CU_ASSERT(rc == 0);
|
||||
nvme_bdev_ctrlr_create(&ctrlr, "nvme0", &trid, 0, NULL);
|
||||
|
||||
nvme_bdev_ctrlr = nvme_bdev_ctrlr_get_by_name("nvme0");
|
||||
SPDK_CU_ASSERT_FATAL(nvme_bdev_ctrlr != NULL);
|
||||
|
||||
curr_trid = TAILQ_FIRST(&nvme_bdev_ctrlr->trids);
|
||||
@ -1097,8 +1097,9 @@ test_race_between_reset_and_destruct_ctrlr(void)
|
||||
|
||||
set_thread(0);
|
||||
|
||||
rc = nvme_bdev_ctrlr_create(&ctrlr, "nvme0", &trid, 0, &nvme_bdev_ctrlr);
|
||||
CU_ASSERT(rc == 0);
|
||||
nvme_bdev_ctrlr_create(&ctrlr, "nvme0", &trid, 0, NULL);
|
||||
|
||||
nvme_bdev_ctrlr = nvme_bdev_ctrlr_get_by_name("nvme0");
|
||||
SPDK_CU_ASSERT_FATAL(nvme_bdev_ctrlr != NULL);
|
||||
|
||||
ch1 = spdk_get_io_channel(nvme_bdev_ctrlr);
|
||||
@ -1172,8 +1173,9 @@ test_failover_ctrlr(void)
|
||||
|
||||
set_thread(0);
|
||||
|
||||
rc = nvme_bdev_ctrlr_create(&ctrlr, "nvme0", &trid1, 0, &nvme_bdev_ctrlr);
|
||||
CU_ASSERT(rc == 0);
|
||||
nvme_bdev_ctrlr_create(&ctrlr, "nvme0", &trid1, 0, NULL);
|
||||
|
||||
nvme_bdev_ctrlr = nvme_bdev_ctrlr_get_by_name("nvme0");
|
||||
SPDK_CU_ASSERT_FATAL(nvme_bdev_ctrlr != NULL);
|
||||
|
||||
ch1 = spdk_get_io_channel(nvme_bdev_ctrlr);
|
||||
@ -1320,8 +1322,9 @@ test_pending_reset(void)
|
||||
|
||||
set_thread(0);
|
||||
|
||||
rc = nvme_bdev_ctrlr_create(&ctrlr, "nvme0", &trid, 0, &nvme_bdev_ctrlr);
|
||||
CU_ASSERT(rc == 0);
|
||||
nvme_bdev_ctrlr_create(&ctrlr, "nvme0", &trid, 0, NULL);
|
||||
|
||||
nvme_bdev_ctrlr = nvme_bdev_ctrlr_get_by_name("nvme0");
|
||||
SPDK_CU_ASSERT_FATAL(nvme_bdev_ctrlr != NULL);
|
||||
|
||||
ch1 = spdk_get_io_channel(nvme_bdev_ctrlr);
|
||||
@ -1560,8 +1563,9 @@ test_reconnect_qpair(void)
|
||||
ut_init_trid(&trid);
|
||||
TAILQ_INIT(&ctrlr.active_io_qpairs);
|
||||
|
||||
rc = nvme_bdev_ctrlr_create(&ctrlr, "nvme0", &trid, 0, &nvme_bdev_ctrlr);
|
||||
CU_ASSERT(rc == 0);
|
||||
nvme_bdev_ctrlr_create(&ctrlr, "nvme0", &trid, 0, NULL);
|
||||
|
||||
nvme_bdev_ctrlr = nvme_bdev_ctrlr_get_by_name("nvme0");
|
||||
SPDK_CU_ASSERT_FATAL(nvme_bdev_ctrlr != NULL);
|
||||
|
||||
ch = spdk_get_io_channel(nvme_bdev_ctrlr);
|
||||
@ -1870,8 +1874,9 @@ test_remove_trid(void)
|
||||
|
||||
set_thread(0);
|
||||
|
||||
rc = nvme_bdev_ctrlr_create(&ctrlr, "nvme0", &trid1, 0, &nvme_bdev_ctrlr);
|
||||
CU_ASSERT(rc == 0);
|
||||
nvme_bdev_ctrlr_create(&ctrlr, "nvme0", &trid1, 0, NULL);
|
||||
|
||||
nvme_bdev_ctrlr = nvme_bdev_ctrlr_get_by_name("nvme0");
|
||||
SPDK_CU_ASSERT_FATAL(nvme_bdev_ctrlr != NULL);
|
||||
|
||||
rc = bdev_nvme_add_trid(nvme_bdev_ctrlr, &ctrlr, &trid2);
|
||||
@ -1919,8 +1924,10 @@ test_remove_trid(void)
|
||||
|
||||
CU_ASSERT(nvme_bdev_ctrlr_get_by_name("nvme0") == NULL);
|
||||
|
||||
rc = nvme_bdev_ctrlr_create(&ctrlr, "nvme0", &trid1, 0, &nvme_bdev_ctrlr);
|
||||
CU_ASSERT(rc == 0);
|
||||
nvme_bdev_ctrlr_create(&ctrlr, "nvme0", &trid1, 0, NULL);
|
||||
|
||||
nvme_bdev_ctrlr = nvme_bdev_ctrlr_get_by_name("nvme0");
|
||||
SPDK_CU_ASSERT_FATAL(nvme_bdev_ctrlr != NULL);
|
||||
|
||||
rc = bdev_nvme_add_trid(nvme_bdev_ctrlr, &ctrlr, &trid2);
|
||||
CU_ASSERT(rc == 0);
|
||||
@ -2121,8 +2128,9 @@ test_get_io_qpair(void)
|
||||
|
||||
set_thread(0);
|
||||
|
||||
rc = nvme_bdev_ctrlr_create(&ctrlr, "nvme0", &trid, 0, &nvme_bdev_ctrlr);
|
||||
CU_ASSERT(rc == 0);
|
||||
nvme_bdev_ctrlr_create(&ctrlr, "nvme0", &trid, 0, NULL);
|
||||
|
||||
nvme_bdev_ctrlr = nvme_bdev_ctrlr_get_by_name("nvme0");
|
||||
SPDK_CU_ASSERT_FATAL(nvme_bdev_ctrlr != NULL);
|
||||
|
||||
ch = spdk_get_io_channel(nvme_bdev_ctrlr);
|
||||
|
Loading…
Reference in New Issue
Block a user