Commit 0b81c11a authored by Seth Howell's avatar Seth Howell Committed by Jim Harris
Browse files

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: default avatarSeth Howell <seth.howell@intel.com>
Change-Id: I24a8cf13e60e6cc0d5b6374da33c8a4e5b6c499a
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/3069


Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 1973d10b
Loading
Loading
Loading
Loading
+47 −0
Original line number Diff line number Diff line
@@ -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,
+1 −0
Original line number Diff line number Diff line
@@ -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,