From 771d759312d61f999b32b3bd309ca15c3fc6c8e3 Mon Sep 17 00:00:00 2001 From: Seth Howell Date: Mon, 23 Dec 2019 16:08:43 -0700 Subject: [PATCH] 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 Change-Id: I26aa3cb8f76f8273f564799d9b2af8041ea0d219 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/478752 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- examples/nvme/identify/identify.c | 2 +- include/spdk/nvme.h | 14 +++++++++++++- lib/nvme/nvme.c | 2 +- lib/nvme/nvme_fabric.c | 2 +- lib/nvme/nvme_transport.c | 9 +++++++++ test/nvme/aer/aer.c | 2 +- test/unit/lib/nvme/nvme.c/nvme_ut.c | 10 +++++----- test/unit/lib/nvme/nvme_ns_cmd.c/nvme_ns_cmd_ut.c | 2 +- .../nvme_ns_ocssd_cmd.c/nvme_ns_ocssd_cmd_ut.c | 2 +- 9 files changed, 33 insertions(+), 12 deletions(-) diff --git a/examples/nvme/identify/identify.c b/examples/nvme/identify/identify.c index cb73e179a..481fbe9ff 100644 --- a/examples/nvme/identify/identify.c +++ b/examples/nvme/identify/identify.c @@ -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) { diff --git a/include/spdk/nvme.h b/include/spdk/nvme.h index 0bb0f28c3..deae3eb77 100644 --- a/include/spdk/nvme.h +++ b/include/spdk/nvme.h @@ -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. * diff --git a/lib/nvme/nvme.c b/lib/nvme/nvme.c index 1361866cc..7d7a7abf8 100644 --- a/lib/nvme/nvme.c +++ b/lib/nvme/nvme.c @@ -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; } diff --git a/lib/nvme/nvme_fabric.c b/lib/nvme/nvme_fabric.c index d7c103a23..019af4f0c 100644 --- a/lib/nvme/nvme_fabric.c +++ b/lib/nvme/nvme_fabric.c @@ -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; diff --git a/lib/nvme/nvme_transport.c b/lib/nvme/nvme_transport.c index f1766736c..18c146c94 100644 --- a/lib/nvme/nvme_transport.c +++ b/lib/nvme/nvme_transport.c @@ -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) diff --git a/test/nvme/aer/aer.c b/test/nvme/aer/aer.c index 22171bb70..701109ced 100644 --- a/test/nvme/aer/aer.c +++ b/test/nvme/aer/aer.c @@ -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) { diff --git a/test/unit/lib/nvme/nvme.c/nvme_ut.c b/test/unit/lib/nvme/nvme.c/nvme_ut.c index 17e6f4057..7a337670d 100644 --- a/test/unit/lib/nvme/nvme.c/nvme_ut.c +++ b/test/unit/lib/nvme/nvme.c/nvme_ut.c @@ -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); diff --git a/test/unit/lib/nvme/nvme_ns_cmd.c/nvme_ns_cmd_ut.c b/test/unit/lib/nvme/nvme_ns_cmd.c/nvme_ns_cmd_ut.c index d72005143..d6d5c1c64 100644 --- a/test/unit/lib/nvme/nvme_ns_cmd.c/nvme_ns_cmd_ut.c +++ b/test/unit/lib/nvme/nvme_ns_cmd.c/nvme_ns_cmd_ut.c @@ -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; } diff --git a/test/unit/lib/nvme/nvme_ns_ocssd_cmd.c/nvme_ns_ocssd_cmd_ut.c b/test/unit/lib/nvme/nvme_ns_ocssd_cmd.c/nvme_ns_ocssd_cmd_ut.c index f621482ef..9f5457dde 100644 --- a/test/unit/lib/nvme/nvme_ns_ocssd_cmd.c/nvme_ns_ocssd_cmd_ut.c +++ b/test/unit/lib/nvme/nvme_ns_ocssd_cmd.c/nvme_ns_ocssd_cmd_ut.c @@ -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; }