Commit 45d8309e authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Jim Harris
Browse files

bdev/nvme: Factor out deleting secondary trid into a helper function



Factor out deleting secondary trid from bdev_nvme_delete() into a
helper function bdev_nvme_delete_secondary_trid().

This will make the following changes simpler.

Besides, fix a typo, the case should be not 1B but 2B.

Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: Iba21efa0d8036ed15d2743a2548df05e866089d6
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7123


Community-CI: Broadcom CI
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarPaul Luse <paul.e.luse@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
parent 08e2210a
Loading
Loading
Loading
Loading
+25 −12
Original line number Diff line number Diff line
@@ -2356,11 +2356,32 @@ bdev_nvme_create(struct spdk_nvme_transport_id *trid,
	return 0;
}

static int
bdev_nvme_delete_secondary_trid(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr,
				const struct spdk_nvme_transport_id *trid)
{
	struct nvme_bdev_ctrlr_trid	*ctrlr_trid, *tmp_trid;

	if (!spdk_nvme_transport_id_compare(trid, nvme_bdev_ctrlr->connected_trid)) {
		return -EBUSY;
	}

	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;
		}
	}

	return -ENXIO;
}

int
bdev_nvme_delete(const char *name, const struct spdk_nvme_transport_id *trid)
{
	struct nvme_bdev_ctrlr		*nvme_bdev_ctrlr;
	struct nvme_bdev_ctrlr_trid	*ctrlr_trid, *tmp_trid;
	struct nvme_bdev_ctrlr_trid	*ctrlr_trid;

	if (name == NULL) {
		return -EINVAL;
@@ -2386,20 +2407,12 @@ bdev_nvme_delete(const char *name, const struct spdk_nvme_transport_id *trid)
			return _bdev_nvme_delete(nvme_bdev_ctrlr, false);
		}

		/* case 1B: there is an alternative path. */
		/* case 2B: there is an alternative path. */
		return bdev_nvme_failover(nvme_bdev_ctrlr, true);
	}
	/* case 3: 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 3A: The address isn't even in the registered list. */
	return -ENXIO;
	/* case 3: We are not using the specified path. */
	return bdev_nvme_delete_secondary_trid(nvme_bdev_ctrlr, trid);
}

static int