lib/nvme: add spdk_nvme_transport_available_by_name

This new api function will enable us to work with custom transports.

This is needed to enable properly parsing and comparing custom transport
IDs that may all resolve to the same enum value.

Signed-off-by: Seth Howell <seth.howell@intel.com>
Change-Id: I26aa3cb8f76f8273f564799d9b2af8041ea0d219
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/478752
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Seth Howell 2019-12-23 16:08:43 -07:00 committed by Tomasz Zawadzki
parent f038354efa
commit 771d759312
9 changed files with 33 additions and 12 deletions

View File

@ -1684,7 +1684,7 @@ parse_args(int argc, char **argv)
{
int op, rc;
g_trid.trtype = SPDK_NVME_TRANSPORT_PCIE;
spdk_nvme_trid_populate_transport(&g_trid, SPDK_NVME_TRANSPORT_PCIE);
snprintf(g_trid.subnqn, sizeof(g_trid.subnqn), "%s", SPDK_NVMF_DISCOVERY_NQN);
while ((op = getopt(argc, argv, "d:i:p:r:xHL:V")) != -1) {

View File

@ -544,10 +544,22 @@ const char *spdk_nvme_prchk_flags_str(uint32_t prchk_flags);
*
* \param trtype NVMe over Fabrics transport type to check.
*
* \return true if trtype is supported or false if it is not supported.
* \return true if trtype is supported or false if it is not supported or if
* SPDK_NVME_TRANSPORT_CUSTOM is supplied as trtype since it can represent multiple
* transports.
*/
bool spdk_nvme_transport_available(enum spdk_nvme_transport_type trtype);
/**
* Determine whether the NVMe library can handle a specific NVMe over Fabrics
* transport type.
*
* \param transport_name Name of the NVMe over Fabrics transport type to check.
*
* \return true if transport_name is supported or false if it is not supported.
*/
bool spdk_nvme_transport_available_by_name(const char *transport_name);
/**
* Callback for spdk_nvme_probe() enumeration.
*

View File

@ -558,7 +558,7 @@ spdk_nvme_probe_internal(struct spdk_nvme_probe_ctx *probe_ctx,
int rc;
struct spdk_nvme_ctrlr *ctrlr, *ctrlr_tmp;
if (!spdk_nvme_transport_available(probe_ctx->trid.trtype)) {
if (!spdk_nvme_transport_available_by_name(probe_ctx->trid.trstring)) {
SPDK_ERRLOG("NVMe trtype %u not available\n", probe_ctx->trid.trtype);
return -1;
}

View File

@ -161,7 +161,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)) {
if (!spdk_nvme_transport_available_by_name(trid.trstring)) {
SPDK_WARNLOG("NVMe transport type %u not available; skipping probe\n",
trid.trtype);
return;

View File

@ -96,6 +96,15 @@ spdk_nvme_transport_available(enum spdk_nvme_transport_type trtype)
return false;
}
bool
spdk_nvme_transport_available_by_name(const char *transport_name)
{
enum spdk_nvme_transport_type trtype;
spdk_nvme_transport_id_parse_trtype(&trtype, transport_name);
return spdk_nvme_transport_available(trtype);
}
struct spdk_nvme_ctrlr *nvme_transport_ctrlr_construct(const struct spdk_nvme_transport_id *trid,
const struct spdk_nvme_ctrlr_opts *opts,
void *devhandle)

View File

@ -308,7 +308,7 @@ parse_args(int argc, char **argv)
int op, rc;
long int val;
g_trid.trtype = SPDK_NVME_TRANSPORT_PCIE;
spdk_nvme_trid_populate_transport(&g_trid, SPDK_NVME_TRANSPORT_PCIE);
snprintf(g_trid.subnqn, sizeof(g_trid.subnqn), "%s", SPDK_NVMF_DISCOVERY_NQN);
while ((op = getopt(argc, argv, "n:r:t:HL:T")) != -1) {

View File

@ -44,8 +44,8 @@
DEFINE_STUB_V(nvme_ctrlr_proc_get_ref, (struct spdk_nvme_ctrlr *ctrlr));
DEFINE_STUB_V(nvme_ctrlr_proc_put_ref, (struct spdk_nvme_ctrlr *ctrlr));
DEFINE_STUB_V(nvme_ctrlr_fail, (struct spdk_nvme_ctrlr *ctrlr, bool hotremove));
DEFINE_STUB(spdk_nvme_transport_available, bool,
(enum spdk_nvme_transport_type trtype), true);
DEFINE_STUB(spdk_nvme_transport_available_by_name, bool,
(const char *transport_name), true);
/* return anything non-NULL, this won't be deferenced anywhere in this test */
DEFINE_STUB(spdk_nvme_ctrlr_get_current_process, struct spdk_nvme_ctrlr_process *,
(struct spdk_nvme_ctrlr *ctrlr), (struct spdk_nvme_ctrlr_process *)(uintptr_t)0x1);
@ -178,7 +178,7 @@ test_spdk_nvme_probe(void)
* called for any controllers already initialized by the primary
* process.
*/
MOCK_SET(spdk_nvme_transport_available, false);
MOCK_SET(spdk_nvme_transport_available_by_name, false);
MOCK_SET(spdk_process_is_primary, true);
dummy.initialized = true;
g_spdk_nvme_driver = &dummy;
@ -186,7 +186,7 @@ test_spdk_nvme_probe(void)
CU_ASSERT(rc == -1);
/* driver init passes, transport available, secondary call attach_cb */
MOCK_SET(spdk_nvme_transport_available, true);
MOCK_SET(spdk_nvme_transport_available_by_name, true);
MOCK_SET(spdk_process_is_primary, false);
MOCK_SET(spdk_memzone_lookup, g_spdk_nvme_driver);
dummy.initialized = true;
@ -240,7 +240,7 @@ test_spdk_nvme_connect(void)
/* driver init passes, transport available, secondary process connects ctrlr */
MOCK_SET(spdk_process_is_primary, false);
MOCK_SET(spdk_memzone_lookup, g_spdk_nvme_driver);
MOCK_SET(spdk_nvme_transport_available, true);
MOCK_SET(spdk_nvme_transport_available_by_name, true);
memset(&trid, 0, sizeof(trid));
trid.trtype = SPDK_NVME_TRANSPORT_PCIE;
ret_ctrlr = spdk_nvme_connect(&trid, NULL, 0);

View File

@ -70,7 +70,7 @@ static int nvme_request_next_sge(void *cb_arg, void **address, uint32_t *length)
}
bool
spdk_nvme_transport_available(enum spdk_nvme_transport_type trtype)
spdk_nvme_transport_available_by_name(const char *transport_name)
{
return true;
}

View File

@ -85,7 +85,7 @@ spdk_nvme_ctrlr_get_default_ctrlr_opts(struct spdk_nvme_ctrlr_opts *opts, size_t
}
bool
spdk_nvme_transport_available(enum spdk_nvme_transport_type trtype)
spdk_nvme_transport_available_by_name(const char *transport_name)
{
return true;
}