diff --git a/module/bdev/nvme/bdev_nvme.c b/module/bdev/nvme/bdev_nvme.c index f3c17d13a..11c2302fe 100644 --- a/module/bdev/nvme/bdev_nvme.c +++ b/module/bdev/nvme/bdev_nvme.c @@ -1350,7 +1350,6 @@ create_ctrlr(struct spdk_nvme_ctrlr *ctrlr, uint32_t prchk_flags) { struct nvme_bdev_ctrlr *nvme_bdev_ctrlr; - struct nvme_bdev_ctrlr_trid *trid_entry; uint32_t i; int rc; @@ -1359,25 +1358,23 @@ create_ctrlr(struct spdk_nvme_ctrlr *ctrlr, SPDK_ERRLOG("Failed to allocate device struct\n"); return -ENOMEM; } - TAILQ_INIT(&nvme_bdev_ctrlr->multipath_trids); + + nvme_bdev_ctrlr->trid = calloc(1, sizeof(*nvme_bdev_ctrlr->trid)); + if (nvme_bdev_ctrlr->trid == NULL) { + SPDK_ERRLOG("Failed to allocate device trid struct\n"); + free(nvme_bdev_ctrlr); + return -ENOMEM; + } + nvme_bdev_ctrlr->num_ns = spdk_nvme_ctrlr_get_num_ns(ctrlr); nvme_bdev_ctrlr->namespaces = calloc(nvme_bdev_ctrlr->num_ns, sizeof(struct nvme_bdev_ns *)); if (!nvme_bdev_ctrlr->namespaces) { SPDK_ERRLOG("Failed to allocate block namespaces pointer\n"); + free(nvme_bdev_ctrlr->trid); free(nvme_bdev_ctrlr); return -ENOMEM; } - trid_entry = calloc(1, sizeof(*trid_entry)); - if (trid_entry == NULL) { - SPDK_ERRLOG("Failed to allocate trid entry pointer\n"); - free(nvme_bdev_ctrlr->namespaces); - free(nvme_bdev_ctrlr); - return -ENOMEM; - } - - trid_entry->trid = *trid; - for (i = 0; i < nvme_bdev_ctrlr->num_ns; i++) { nvme_bdev_ctrlr->namespaces[i] = calloc(1, sizeof(struct nvme_bdev_ns)); if (nvme_bdev_ctrlr->namespaces[i] == NULL) { @@ -1385,8 +1382,8 @@ create_ctrlr(struct spdk_nvme_ctrlr *ctrlr, for (; i > 0; i--) { free(nvme_bdev_ctrlr->namespaces[i - 1]); } - free(trid_entry); free(nvme_bdev_ctrlr->namespaces); + free(nvme_bdev_ctrlr->trid); free(nvme_bdev_ctrlr); return -ENOMEM; } @@ -1395,11 +1392,11 @@ create_ctrlr(struct spdk_nvme_ctrlr *ctrlr, nvme_bdev_ctrlr->adminq_timer_poller = NULL; nvme_bdev_ctrlr->ctrlr = ctrlr; nvme_bdev_ctrlr->ref = 0; - nvme_bdev_ctrlr->trid = &trid_entry->trid; + *nvme_bdev_ctrlr->trid = *trid; nvme_bdev_ctrlr->name = strdup(name); if (nvme_bdev_ctrlr->name == NULL) { - free(trid_entry); free(nvme_bdev_ctrlr->namespaces); + free(nvme_bdev_ctrlr->trid); free(nvme_bdev_ctrlr); return -ENOMEM; } @@ -1408,9 +1405,9 @@ create_ctrlr(struct spdk_nvme_ctrlr *ctrlr, rc = bdev_ocssd_init_ctrlr(nvme_bdev_ctrlr); if (spdk_unlikely(rc != 0)) { SPDK_ERRLOG("Unable to initialize OCSSD controller\n"); - free(trid_entry); free(nvme_bdev_ctrlr->name); free(nvme_bdev_ctrlr->namespaces); + free(nvme_bdev_ctrlr->trid); free(nvme_bdev_ctrlr); return rc; } @@ -1441,8 +1438,6 @@ create_ctrlr(struct spdk_nvme_ctrlr *ctrlr, SPDK_ERRLOG("Failed to initialize Opal\n"); } } - - TAILQ_INSERT_HEAD(&nvme_bdev_ctrlr->multipath_trids, trid_entry, link); return 0; } @@ -1715,87 +1710,6 @@ bdev_nvme_async_poll(void *arg) return SPDK_POLLER_BUSY; } -int -bdev_nvme_add_multipath_trid(const char *name, struct spdk_nvme_transport_id *trid) -{ - struct nvme_bdev_ctrlr *nvme_bdev_ctrlr; - struct spdk_nvme_ctrlr *multipath_ctrlr; - struct spdk_nvme_ctrlr_opts opts; - uint32_t i; - struct spdk_nvme_ns *ns, *multipath_ns; - const struct spdk_nvme_ns_data *ns_data, *multipath_ns_data; - struct nvme_bdev_ctrlr_trid *multipath_trid; - int rc = 0; - - if (name == NULL) { - return -EINVAL; - } - - nvme_bdev_ctrlr = nvme_bdev_ctrlr_get_by_name(name); - if (nvme_bdev_ctrlr == NULL) { - SPDK_ERRLOG("Failed to find NVMe controller\n"); - return -ENODEV; - } - - /* Currently we only support failover to the same transport type. */ - if (nvme_bdev_ctrlr->trid->trtype != trid->trtype) { - return -EINVAL; - } - - /* Currently we only support failover to the same NQN. */ - if (strncmp(trid->subnqn, nvme_bdev_ctrlr->trid->subnqn, SPDK_NVMF_NQN_MAX_LEN)) { - return -EINVAL; - } - - /* Skip all the other checks if we've already registered this path. */ - TAILQ_FOREACH(multipath_trid, &nvme_bdev_ctrlr->multipath_trids, link) { - if (!memcmp(&multipath_trid->trid, trid, sizeof(struct spdk_nvme_transport_id))) { - return 0; - } - } - - spdk_nvme_ctrlr_get_default_ctrlr_opts(&opts, sizeof(opts)); - opts.transport_retry_count = g_opts.retry_count; - - multipath_ctrlr = spdk_nvme_connect(trid, &opts, sizeof(opts)); - - if (multipath_ctrlr == NULL) { - return -ENODEV; - } - - if (spdk_nvme_ctrlr_get_num_ns(multipath_ctrlr) != nvme_bdev_ctrlr->num_ns) { - rc = -EINVAL; - goto out; - } - - for (i = 1; i <= nvme_bdev_ctrlr->num_ns; i++) { - ns = spdk_nvme_ctrlr_get_ns(nvme_bdev_ctrlr->ctrlr, i); - multipath_ns = spdk_nvme_ctrlr_get_ns(multipath_ctrlr, i); - assert(ns != NULL); - assert(multipath_ns != NULL); - - ns_data = spdk_nvme_ns_get_data(ns); - multipath_ns_data = spdk_nvme_ns_get_data(multipath_ns); - if (memcmp(ns_data->nguid, multipath_ns_data->nguid, sizeof(ns_data->nguid))) { - rc = -EINVAL; - goto out; - } - } - -out: - spdk_nvme_detach(multipath_ctrlr); - if (rc == 0) { - multipath_trid = calloc(1, sizeof(*multipath_trid)); - if (multipath_trid == NULL) { - return -ENOMEM; - } - multipath_trid->trid = *trid; - TAILQ_INSERT_TAIL(&nvme_bdev_ctrlr->multipath_trids, multipath_trid, link); - } - - return rc; -} - int bdev_nvme_create(struct spdk_nvme_transport_id *trid, struct spdk_nvme_host_id *hostid, diff --git a/module/bdev/nvme/bdev_nvme.h b/module/bdev/nvme/bdev_nvme.h index d5de883bf..417c21cad 100644 --- a/module/bdev/nvme/bdev_nvme.h +++ b/module/bdev/nvme/bdev_nvme.h @@ -66,7 +66,6 @@ struct spdk_nvme_qpair *bdev_nvme_get_io_qpair(struct spdk_io_channel *ctrlr_io_ void bdev_nvme_get_opts(struct spdk_bdev_nvme_opts *opts); int bdev_nvme_set_opts(const struct spdk_bdev_nvme_opts *opts); int bdev_nvme_set_hotplug(bool enabled, uint64_t period_us, spdk_msg_fn cb, void *cb_ctx); -int bdev_nvme_add_multipath_trid(const char *name, struct spdk_nvme_transport_id *trid); int bdev_nvme_create(struct spdk_nvme_transport_id *trid, struct spdk_nvme_host_id *hostid, diff --git a/module/bdev/nvme/common.c b/module/bdev/nvme/common.c index 40ea3afee..c895f1102 100644 --- a/module/bdev/nvme/common.c +++ b/module/bdev/nvme/common.c @@ -116,7 +116,6 @@ static void nvme_bdev_unregister_cb(void *io_device) { struct nvme_bdev_ctrlr *nvme_bdev_ctrlr = io_device; - struct nvme_bdev_ctrlr_trid *multipath_trid, *tmp_trid; uint32_t i; pthread_mutex_lock(&g_bdev_nvme_mutex); @@ -128,13 +127,8 @@ nvme_bdev_unregister_cb(void *io_device) for (i = 0; i < nvme_bdev_ctrlr->num_ns; i++) { free(nvme_bdev_ctrlr->namespaces[i]); } - - TAILQ_FOREACH_SAFE(multipath_trid, &nvme_bdev_ctrlr->multipath_trids, link, tmp_trid) { - TAILQ_REMOVE(&nvme_bdev_ctrlr->multipath_trids, multipath_trid, link); - free(multipath_trid); - } - free(nvme_bdev_ctrlr->namespaces); + free(nvme_bdev_ctrlr->trid); free(nvme_bdev_ctrlr); pthread_mutex_lock(&g_bdev_nvme_mutex); diff --git a/module/bdev/nvme/common.h b/module/bdev/nvme/common.h index 1f7b37b68..eafed596b 100644 --- a/module/bdev/nvme/common.h +++ b/module/bdev/nvme/common.h @@ -69,44 +69,37 @@ struct nvme_bdev_ns { struct ocssd_bdev_ctrlr; -struct nvme_bdev_ctrlr_trid { - struct spdk_nvme_transport_id trid; - TAILQ_ENTRY(nvme_bdev_ctrlr_trid) link; -}; - struct nvme_bdev_ctrlr { /** * points to pinned, physically contiguous memory region; * contains 4KB IDENTIFY structure for controller which is * target for CONTROLLER IDENTIFY command during initialization */ - struct spdk_nvme_ctrlr *ctrlr; - struct spdk_nvme_transport_id *trid; - char *name; - int ref; - bool resetting; - bool destruct; + struct spdk_nvme_ctrlr *ctrlr; + struct spdk_nvme_transport_id *trid; + char *name; + int ref; + bool resetting; + bool destruct; /** * PI check flags. This flags is set to NVMe controllers created only * through bdev_nvme_attach_controller RPC or .INI config file. Hot added * NVMe controllers are not included. */ - uint32_t prchk_flags; - uint32_t num_ns; + uint32_t prchk_flags; + uint32_t num_ns; /** Array of pointers to namespaces indexed by nsid - 1 */ - struct nvme_bdev_ns **namespaces; + struct nvme_bdev_ns **namespaces; - struct spdk_opal_dev *opal_dev; + struct spdk_opal_dev *opal_dev; - struct spdk_poller *adminq_timer_poller; - struct spdk_poller *destruct_poller; + struct spdk_poller *adminq_timer_poller; + struct spdk_poller *destruct_poller; - struct ocssd_bdev_ctrlr *ocssd_ctrlr; + struct ocssd_bdev_ctrlr *ocssd_ctrlr; /** linked list pointer for device list */ - TAILQ_ENTRY(nvme_bdev_ctrlr) tailq; - - TAILQ_HEAD(, nvme_bdev_ctrlr_trid) multipath_trids; + TAILQ_ENTRY(nvme_bdev_ctrlr) tailq; }; struct nvme_bdev { diff --git a/test/unit/lib/bdev/bdev_ocssd.c/bdev_ocssd_ut.c b/test/unit/lib/bdev/bdev_ocssd.c/bdev_ocssd_ut.c index 8a90e91b2..a2f8e7f71 100644 --- a/test/unit/lib/bdev/bdev_ocssd.c/bdev_ocssd_ut.c +++ b/test/unit/lib/bdev/bdev_ocssd.c/bdev_ocssd_ut.c @@ -198,7 +198,6 @@ create_nvme_bdev_controller(const struct spdk_nvme_transport_id *trid, const cha { struct spdk_nvme_ctrlr *ctrlr; struct nvme_bdev_ctrlr *nvme_bdev_ctrlr; - struct nvme_bdev_ctrlr_trid *trid_entry; uint32_t nsid; ctrlr = find_controller(trid); @@ -212,15 +211,15 @@ create_nvme_bdev_controller(const struct spdk_nvme_transport_id *trid, const cha nvme_bdev_ctrlr->namespaces = calloc(ctrlr->ns_count, sizeof(struct nvme_bdev_ns *)); SPDK_CU_ASSERT_FATAL(nvme_bdev_ctrlr->namespaces != NULL); - trid_entry = calloc(1, sizeof(struct nvme_bdev_ctrlr_trid)); - SPDK_CU_ASSERT_FATAL(trid_entry != NULL); - trid_entry->trid = *trid; + nvme_bdev_ctrlr->trid = calloc(1, sizeof(struct spdk_nvme_transport_id)); + SPDK_CU_ASSERT_FATAL(nvme_bdev_ctrlr->trid != NULL); nvme_bdev_ctrlr->ctrlr = ctrlr; nvme_bdev_ctrlr->num_ns = ctrlr->ns_count; nvme_bdev_ctrlr->ref = 0; - nvme_bdev_ctrlr->trid = &trid_entry->trid; + *nvme_bdev_ctrlr->trid = *trid; nvme_bdev_ctrlr->name = strdup(name); + for (nsid = 0; nsid < ctrlr->ns_count; ++nsid) { nvme_bdev_ctrlr->namespaces[nsid] = calloc(1, sizeof(struct nvme_bdev_ns)); SPDK_CU_ASSERT_FATAL(nvme_bdev_ctrlr->namespaces[nsid] != NULL); @@ -240,9 +239,6 @@ create_nvme_bdev_controller(const struct spdk_nvme_transport_id *trid, const cha TAILQ_INSERT_TAIL(&g_nvme_bdev_ctrlrs, nvme_bdev_ctrlr, tailq); - TAILQ_INIT(&nvme_bdev_ctrlr->multipath_trids); - TAILQ_INSERT_HEAD(&nvme_bdev_ctrlr->multipath_trids, trid_entry, link); - return nvme_bdev_ctrlr; }