Commit 7ed0904b authored by Seth Howell's avatar Seth Howell Committed by Tomasz Zawadzki
Browse files

lib/nvme: update trid struct with trstring.



The trtype should be stored as both an enum and string. This is intended to
help pave the way for pluggable NVMe-oF transports.

Signed-off-by: default avatarSeth Howell <seth.howell@intel.com>
Change-Id: I6af658d7a17c405e191ff401b80ab704c65497e7
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/478744


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarAlexey Marchuk <alexeymar@mellanox.com>
parent 6c274749
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -48,6 +48,11 @@ extern "C" {
#include "spdk/nvme_spec.h"
#include "spdk/nvmf_spec.h"

#define SPDK_NVME_TRANSPORT_NAME_FC	"FC"
#define SPDK_NVME_TRANSPORT_NAME_PCIE	"PCIE"
#define SPDK_NVME_TRANSPORT_NAME_RDMA	"RDMA"
#define SPDK_NVME_TRANSPORT_NAME_TCP	"TCP"

/**
 * Opaque handle to a controller. Returned by spdk_nvme_probe()'s attach_cb.
 */
@@ -293,6 +298,11 @@ typedef enum spdk_nvme_transport_type spdk_nvme_transport_type_t;
 * spdk_nvme_transport_id_parse().
 */
struct spdk_nvme_transport_id {
	/**
	 * NVMe transport string.
	 */
	char trstring[SPDK_NVMF_TRSTRING_MAX_LEN + 1];

	/**
	 * NVMe transport type.
	 */
@@ -394,6 +404,17 @@ enum spdk_nvme_ctrlr_flags {
 */
int spdk_nvme_transport_id_parse(struct spdk_nvme_transport_id *trid, const char *str);


/**
 * Fill in the trtype and trstring fields of this trid based on a known transport type.
 *
 * \param trid The trid to fill out.
 * \param trtype The transport type to use for filling the trid fields. Only valid for
 * transport types referenced in the NVMe-oF spec.
 */
void spdk_nvme_trid_populate_transport(struct spdk_nvme_transport_id *trid,
				       enum spdk_nvme_transport_type trtype);

/**
 * Parse the string representation of a host ID.
 *
@@ -419,6 +440,18 @@ int spdk_nvme_transport_id_parse(struct spdk_nvme_transport_id *trid, const char
 */
int spdk_nvme_host_id_parse(struct spdk_nvme_host_id *hostid, const char *str);

/**
 * Parse the string representation of a transport ID tranport type into the trid struct.
 *
 * \param trid The trid to write to
 * \param trstring Input string representation of transport type (e.g. "PCIe", "RDMA").
 *
 * \return 0 if parsing was successful and trtype is filled out, or negated errno
 * values if the provided string was an invalid transport string.
 */
int spdk_nvme_transport_id_populate_trstring(struct spdk_nvme_transport_id *trid,
		const char *trstring);

/**
 * Parse the string representation of a transport ID tranport type.
 *
+1 −0
Original line number Diff line number Diff line
@@ -334,6 +334,7 @@ SPDK_STATIC_ASSERT(sizeof(struct spdk_nvmf_fabric_prop_set_cmd) == 64, "Incorrec

#define SPDK_DOMAIN_LABEL_MAX_LEN 63 /* RFC 1034 max domain label length */

#define SPDK_NVMF_TRSTRING_MAX_LEN 32
#define SPDK_NVMF_TRADDR_MAX_LEN 256
#define SPDK_NVMF_TRSVCID_MAX_LEN 32

+58 −1
Original line number Diff line number Diff line
@@ -637,7 +637,7 @@ spdk_nvme_probe(const struct spdk_nvme_transport_id *trid, void *cb_ctx,

	if (trid == NULL) {
		memset(&trid_pcie, 0, sizeof(trid_pcie));
		trid_pcie.trtype = SPDK_NVME_TRANSPORT_PCIE;
		spdk_nvme_trid_populate_transport(&trid_pcie, SPDK_NVME_TRANSPORT_PCIE);
		trid = &trid_pcie;
	}

@@ -701,6 +701,59 @@ spdk_nvme_connect(const struct spdk_nvme_transport_id *trid,
	return ctrlr;
}

void
spdk_nvme_trid_populate_transport(struct spdk_nvme_transport_id *trid,
				  enum spdk_nvme_transport_type trtype)
{
	const char *trstring;

	trid->trtype = trtype;
	switch (trtype) {
	case SPDK_NVME_TRANSPORT_FC:
		trstring = SPDK_NVME_TRANSPORT_NAME_FC;
		break;
	case SPDK_NVME_TRANSPORT_PCIE:
		trstring = SPDK_NVME_TRANSPORT_NAME_PCIE;
		break;
	case SPDK_NVME_TRANSPORT_RDMA:
		trstring = SPDK_NVME_TRANSPORT_NAME_RDMA;
		break;
	case SPDK_NVME_TRANSPORT_TCP:
		trstring = SPDK_NVME_TRANSPORT_NAME_TCP;
		break;
	default:
		SPDK_ERRLOG("don't use this for custom transports\n");
		break;
	}
	snprintf(trid->trstring, SPDK_NVMF_TRSTRING_MAX_LEN, "%s", trstring);
}

int
spdk_nvme_transport_id_populate_trstring(struct spdk_nvme_transport_id *trid, const char *trstring)
{
	int len, i, rc;

	if (trstring == NULL) {
		return -EINVAL;
	}

	len = strnlen(trstring, SPDK_NVMF_TRSTRING_MAX_LEN);
	if (len == SPDK_NVMF_TRSTRING_MAX_LEN) {
		return -EINVAL;
	}

	rc = snprintf(trid->trstring, SPDK_NVMF_TRSTRING_MAX_LEN, "%s", trstring);
	if (rc < 0) {
		return rc;
	}

	/* cast official trstring to uppercase version of input. */
	for (i = 0; i < len; i++) {
		trid->trstring[i] = toupper(trid->trstring[i]);
	}
	return 0;
}

int
spdk_nvme_transport_id_parse_trtype(enum spdk_nvme_transport_type *trtype, const char *str)
{
@@ -853,6 +906,10 @@ spdk_nvme_transport_id_parse(struct spdk_nvme_transport_id *trid, const char *st
		}

		if (strcasecmp(key, "trtype") == 0) {
			if (spdk_nvme_transport_id_populate_trstring(trid, val) != 0) {
				SPDK_ERRLOG("invalid transport '%s'\n", val);
				return -EINVAL;
			}
			if (spdk_nvme_transport_id_parse_trtype(&trid->trtype, val) != 0) {
				SPDK_ERRLOG("Unknown trtype '%s'\n", val);
				return -EINVAL;
+1 −0
Original line number Diff line number Diff line
@@ -160,6 +160,7 @@ nvme_fabric_discover_probe(struct spdk_nvmf_discovery_log_page_entry *entry,
	}

	trid.trtype = entry->trtype;
	spdk_nvme_transport_id_populate_trstring(&trid, spdk_nvme_transport_id_trtype_str(entry->trtype));
	if (!spdk_nvme_transport_available(trid.trtype)) {
		SPDK_WARNLOG("NVMe transport type %u not available; skipping probe\n",
			     trid.trtype);
+3 −3
Original line number Diff line number Diff line
@@ -286,7 +286,7 @@ _nvme_pcie_hotplug_monitor(struct spdk_nvme_probe_ctx *probe_ctx)
				struct spdk_nvme_transport_id trid;

				memset(&trid, 0, sizeof(trid));
				trid.trtype = SPDK_NVME_TRANSPORT_PCIE;
				spdk_nvme_trid_populate_transport(&trid, SPDK_NVME_TRANSPORT_PCIE);
				snprintf(trid.traddr, sizeof(trid.traddr), "%s", event.traddr);

				ctrlr = spdk_nvme_get_ctrlr_by_trid_unsafe(&trid);
@@ -729,7 +729,7 @@ pcie_nvme_enum_cb(void *ctx, struct spdk_pci_device *pci_dev)

	pci_addr = spdk_pci_device_get_addr(pci_dev);

	trid.trtype = SPDK_NVME_TRANSPORT_PCIE;
	spdk_nvme_trid_populate_transport(&trid, SPDK_NVME_TRANSPORT_PCIE);
	spdk_pci_addr_fmt(trid.traddr, sizeof(trid.traddr), &pci_addr);

	ctrlr = spdk_nvme_get_ctrlr_by_trid_unsafe(&trid);
@@ -828,7 +828,7 @@ struct spdk_nvme_ctrlr *nvme_pcie_ctrlr_construct(const struct spdk_nvme_transpo

	pctrlr->is_remapped = false;
	pctrlr->ctrlr.is_removed = false;
	pctrlr->ctrlr.trid.trtype = SPDK_NVME_TRANSPORT_PCIE;
	spdk_nvme_trid_populate_transport(&pctrlr->ctrlr.trid, SPDK_NVME_TRANSPORT_PCIE);
	pctrlr->devhandle = devhandle;
	pctrlr->ctrlr.opts = *opts;
	memcpy(&pctrlr->ctrlr.trid, trid, sizeof(pctrlr->ctrlr.trid));
Loading