bdev/nvme: make the controller trid a pointer.
This lends itself to easily changing the trid during failover. Signed-off-by: Seth Howell <seth.howell@intel.com> Change-Id: Iae21a98de4f9dd1192a50abac0ec7fb0dd8a2e99 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/2882 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
parent
3a1f5364d2
commit
af9e73302f
@ -841,13 +841,13 @@ bdev_nvme_dump_info_json(void *ctx, struct spdk_json_write_ctx *w)
|
||||
|
||||
spdk_json_write_named_object_begin(w, "nvme");
|
||||
|
||||
if (nvme_bdev_ctrlr->trid.trtype == SPDK_NVME_TRANSPORT_PCIE) {
|
||||
spdk_json_write_named_string(w, "pci_address", nvme_bdev_ctrlr->trid.traddr);
|
||||
if (nvme_bdev_ctrlr->trid->trtype == SPDK_NVME_TRANSPORT_PCIE) {
|
||||
spdk_json_write_named_string(w, "pci_address", nvme_bdev_ctrlr->trid->traddr);
|
||||
}
|
||||
|
||||
spdk_json_write_named_object_begin(w, "trid");
|
||||
|
||||
nvme_bdev_dump_trid_json(&nvme_bdev_ctrlr->trid, w);
|
||||
nvme_bdev_dump_trid_json(nvme_bdev_ctrlr->trid, w);
|
||||
|
||||
spdk_json_write_object_end(w);
|
||||
|
||||
@ -1358,10 +1358,19 @@ create_ctrlr(struct spdk_nvme_ctrlr *ctrlr,
|
||||
SPDK_ERRLOG("Failed to allocate device struct\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@ -1374,6 +1383,7 @@ create_ctrlr(struct spdk_nvme_ctrlr *ctrlr,
|
||||
free(nvme_bdev_ctrlr->namespaces[i - 1]);
|
||||
}
|
||||
free(nvme_bdev_ctrlr->namespaces);
|
||||
free(nvme_bdev_ctrlr->trid);
|
||||
free(nvme_bdev_ctrlr);
|
||||
return -ENOMEM;
|
||||
}
|
||||
@ -1382,10 +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;
|
||||
*nvme_bdev_ctrlr->trid = *trid;
|
||||
nvme_bdev_ctrlr->name = strdup(name);
|
||||
if (nvme_bdev_ctrlr->name == NULL) {
|
||||
free(nvme_bdev_ctrlr->namespaces);
|
||||
free(nvme_bdev_ctrlr->trid);
|
||||
free(nvme_bdev_ctrlr);
|
||||
return -ENOMEM;
|
||||
}
|
||||
@ -1396,6 +1407,7 @@ create_ctrlr(struct spdk_nvme_ctrlr *ctrlr,
|
||||
SPDK_ERRLOG("Unable to initialize OCSSD controller\n");
|
||||
free(nvme_bdev_ctrlr->name);
|
||||
free(nvme_bdev_ctrlr->namespaces);
|
||||
free(nvme_bdev_ctrlr->trid);
|
||||
free(nvme_bdev_ctrlr);
|
||||
return rc;
|
||||
}
|
||||
@ -1787,12 +1799,12 @@ bdev_nvme_delete(const char *name)
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (nvme_bdev_ctrlr->trid.trtype == SPDK_NVME_TRANSPORT_PCIE) {
|
||||
if (nvme_bdev_ctrlr->trid->trtype == SPDK_NVME_TRANSPORT_PCIE) {
|
||||
entry = calloc(1, sizeof(*entry));
|
||||
if (!entry) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
entry->trid = nvme_bdev_ctrlr->trid;
|
||||
entry->trid = *nvme_bdev_ctrlr->trid;
|
||||
TAILQ_INSERT_TAIL(&g_skipped_nvme_ctrlrs, entry, tailq);
|
||||
}
|
||||
|
||||
@ -2636,31 +2648,31 @@ bdev_nvme_get_spdk_running_config(FILE *fp)
|
||||
const char *trtype;
|
||||
const char *prchk_flags;
|
||||
|
||||
trtype = spdk_nvme_transport_id_trtype_str(nvme_bdev_ctrlr->trid.trtype);
|
||||
trtype = spdk_nvme_transport_id_trtype_str(nvme_bdev_ctrlr->trid->trtype);
|
||||
if (!trtype) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (nvme_bdev_ctrlr->trid.trtype == SPDK_NVME_TRANSPORT_PCIE) {
|
||||
if (nvme_bdev_ctrlr->trid->trtype == SPDK_NVME_TRANSPORT_PCIE) {
|
||||
fprintf(fp, "TransportID \"trtype:%s traddr:%s\" %s\n",
|
||||
trtype,
|
||||
nvme_bdev_ctrlr->trid.traddr, nvme_bdev_ctrlr->name);
|
||||
nvme_bdev_ctrlr->trid->traddr, nvme_bdev_ctrlr->name);
|
||||
} else {
|
||||
const char *adrfam;
|
||||
|
||||
adrfam = spdk_nvme_transport_id_adrfam_str(nvme_bdev_ctrlr->trid.adrfam);
|
||||
adrfam = spdk_nvme_transport_id_adrfam_str(nvme_bdev_ctrlr->trid->adrfam);
|
||||
prchk_flags = spdk_nvme_prchk_flags_str(nvme_bdev_ctrlr->prchk_flags);
|
||||
|
||||
if (adrfam) {
|
||||
fprintf(fp, "TransportID \"trtype:%s adrfam:%s traddr:%s trsvcid:%s subnqn:%s\" %s",
|
||||
trtype, adrfam,
|
||||
nvme_bdev_ctrlr->trid.traddr, nvme_bdev_ctrlr->trid.trsvcid,
|
||||
nvme_bdev_ctrlr->trid.subnqn, nvme_bdev_ctrlr->name);
|
||||
nvme_bdev_ctrlr->trid->traddr, nvme_bdev_ctrlr->trid->trsvcid,
|
||||
nvme_bdev_ctrlr->trid->subnqn, nvme_bdev_ctrlr->name);
|
||||
} else {
|
||||
fprintf(fp, "TransportID \"trtype:%s traddr:%s trsvcid:%s subnqn:%s\" %s",
|
||||
trtype,
|
||||
nvme_bdev_ctrlr->trid.traddr, nvme_bdev_ctrlr->trid.trsvcid,
|
||||
nvme_bdev_ctrlr->trid.subnqn, nvme_bdev_ctrlr->name);
|
||||
nvme_bdev_ctrlr->trid->traddr, nvme_bdev_ctrlr->trid->trsvcid,
|
||||
nvme_bdev_ctrlr->trid->subnqn, nvme_bdev_ctrlr->name);
|
||||
}
|
||||
|
||||
if (prchk_flags) {
|
||||
@ -2768,7 +2780,7 @@ bdev_nvme_config_json(struct spdk_json_write_ctx *w)
|
||||
|
||||
pthread_mutex_lock(&g_bdev_nvme_mutex);
|
||||
TAILQ_FOREACH(nvme_bdev_ctrlr, &g_nvme_bdev_ctrlrs, tailq) {
|
||||
trid = &nvme_bdev_ctrlr->trid;
|
||||
trid = nvme_bdev_ctrlr->trid;
|
||||
|
||||
spdk_json_write_object_begin(w);
|
||||
|
||||
|
@ -357,7 +357,7 @@ rpc_dump_nvme_controller_info(struct spdk_json_write_ctx *w,
|
||||
{
|
||||
struct spdk_nvme_transport_id *trid;
|
||||
|
||||
trid = &nvme_bdev_ctrlr->trid;
|
||||
trid = nvme_bdev_ctrlr->trid;
|
||||
|
||||
spdk_json_write_object_begin(w);
|
||||
spdk_json_write_named_string(w, "name", nvme_bdev_ctrlr->name);
|
||||
|
@ -45,7 +45,7 @@ nvme_bdev_ctrlr_get(const struct spdk_nvme_transport_id *trid)
|
||||
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr;
|
||||
|
||||
TAILQ_FOREACH(nvme_bdev_ctrlr, &g_nvme_bdev_ctrlrs, tailq) {
|
||||
if (spdk_nvme_transport_id_compare(trid, &nvme_bdev_ctrlr->trid) == 0) {
|
||||
if (spdk_nvme_transport_id_compare(trid, nvme_bdev_ctrlr->trid) == 0) {
|
||||
return nvme_bdev_ctrlr;
|
||||
}
|
||||
}
|
||||
@ -128,6 +128,7 @@ nvme_bdev_unregister_cb(void *io_device)
|
||||
free(nvme_bdev_ctrlr->namespaces[i]);
|
||||
}
|
||||
free(nvme_bdev_ctrlr->namespaces);
|
||||
free(nvme_bdev_ctrlr->trid);
|
||||
free(nvme_bdev_ctrlr);
|
||||
|
||||
pthread_mutex_lock(&g_bdev_nvme_mutex);
|
||||
|
@ -76,7 +76,7 @@ struct nvme_bdev_ctrlr {
|
||||
* target for CONTROLLER IDENTIFY command during initialization
|
||||
*/
|
||||
struct spdk_nvme_ctrlr *ctrlr;
|
||||
struct spdk_nvme_transport_id trid;
|
||||
struct spdk_nvme_transport_id *trid;
|
||||
char *name;
|
||||
int ref;
|
||||
bool resetting;
|
||||
|
@ -211,10 +211,13 @@ 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);
|
||||
|
||||
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;
|
||||
*nvme_bdev_ctrlr->trid = *trid;
|
||||
nvme_bdev_ctrlr->name = strdup(name);
|
||||
|
||||
for (nsid = 0; nsid < ctrlr->ns_count; ++nsid) {
|
||||
|
Loading…
Reference in New Issue
Block a user