From 0b81c11ab8e6a4746831cfda3996c7bdc2fefc62 Mon Sep 17 00:00:00 2001 From: Seth Howell Date: Thu, 25 Jun 2020 10:06:56 -0700 Subject: [PATCH] module/bdev: add a function to remove trid from ctrlr. This will allow us to further develop the ecosystem for multipath failover support. Signed-off-by: Seth Howell Change-Id: I24a8cf13e60e6cc0d5b6374da33c8a4e5b6c499a Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/3069 Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Aleksey Marchuk Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- module/bdev/nvme/bdev_nvme.c | 47 ++++++++++++++++++++++++++++++++++++ module/bdev/nvme/bdev_nvme.h | 1 + 2 files changed, 48 insertions(+) diff --git a/module/bdev/nvme/bdev_nvme.c b/module/bdev/nvme/bdev_nvme.c index cc665b71c..8f8da2219 100644 --- a/module/bdev/nvme/bdev_nvme.c +++ b/module/bdev/nvme/bdev_nvme.c @@ -1836,6 +1836,53 @@ out: return rc; } +int +bdev_nvme_remove_trid(const char *name, struct spdk_nvme_transport_id *trid) +{ + struct nvme_bdev_ctrlr *nvme_bdev_ctrlr; + struct nvme_bdev_ctrlr_trid *ctrlr_trid, *tmp_trid; + + 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; + } + + /* case 1: we are currently using the path to be removed. */ + if (!spdk_nvme_transport_id_compare(trid, nvme_bdev_ctrlr->connected_trid)) { + ctrlr_trid = TAILQ_FIRST(&nvme_bdev_ctrlr->trids); + assert(nvme_bdev_ctrlr->connected_trid == &ctrlr_trid->trid); + /* case 1A: the current path is the only path. */ + if (!TAILQ_NEXT(ctrlr_trid, link)) { + return bdev_nvme_delete(name); + } + + /* case 1B: there is an alternative path. */ + if (bdev_nvme_reset(nvme_bdev_ctrlr, NULL, true) == -EAGAIN) { + return -EAGAIN; + } + assert(nvme_bdev_ctrlr->connected_trid != &ctrlr_trid->trid); + TAILQ_REMOVE(&nvme_bdev_ctrlr->trids, ctrlr_trid, link); + free(ctrlr_trid); + return 0; + } + /* case 2: We are not using the specified path. */ + TAILQ_FOREACH_SAFE(ctrlr_trid, &nvme_bdev_ctrlr->trids, link, tmp_trid) { + if (!spdk_nvme_transport_id_compare(&ctrlr_trid->trid, trid)) { + TAILQ_REMOVE(&nvme_bdev_ctrlr->trids, ctrlr_trid, link); + free(ctrlr_trid); + return 0; + } + } + + /* case 2A: The address isn't even in the registered list. */ + return -ENXIO; +} + 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 62c3f5265..388fa91df 100644 --- a/module/bdev/nvme/bdev_nvme.h +++ b/module/bdev/nvme/bdev_nvme.h @@ -67,6 +67,7 @@ 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_trid(const char *name, struct spdk_nvme_transport_id *trid); +int bdev_nvme_remove_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,