lib/nvme: split out function to get ops.

Signed-off-by: Seth Howell <seth.howell@intel.com>
Change-Id: I7664e6ca16f323fd7032b2c8afd6b9467897a014
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/478872
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-26 15:06:20 -07:00 committed by Tomasz Zawadzki
parent e4eef6975c
commit bf6b1122dc
2 changed files with 20 additions and 7 deletions

View File

@ -1117,6 +1117,8 @@ bool nvme_completion_is_retry(const struct spdk_nvme_cpl *cpl);
struct spdk_nvme_ctrlr *spdk_nvme_get_ctrlr_by_trid_unsafe( struct spdk_nvme_ctrlr *spdk_nvme_get_ctrlr_by_trid_unsafe(
const struct spdk_nvme_transport_id *trid); const struct spdk_nvme_transport_id *trid);
const struct nvme_transport *nvme_get_transport(const char *transport_name);
/* Transport specific functions */ /* Transport specific functions */
#define DECLARE_TRANSPORT(name) \ #define DECLARE_TRANSPORT(name) \
struct spdk_nvme_ctrlr *nvme_ ## name ## _ctrlr_construct(const struct spdk_nvme_transport_id *trid, const struct spdk_nvme_ctrlr_opts *opts, \ struct spdk_nvme_ctrlr *nvme_ ## name ## _ctrlr_construct(const struct spdk_nvme_transport_id *trid, const struct spdk_nvme_ctrlr_opts *opts, \

View File

@ -109,17 +109,28 @@ spdk_nvme_transport_available_by_name(const char *transport_name)
return spdk_nvme_transport_available(trtype); return spdk_nvme_transport_available(trtype);
} }
const struct nvme_transport *
nvme_get_transport(const char *transport_name)
{
struct nvme_transport *registered_transport;
TAILQ_FOREACH(registered_transport, &g_spdk_nvme_transports, link) {
if (strcasecmp(transport_name, registered_transport->ops.name) == 0) {
return registered_transport;
}
}
return NULL;
}
void void
spdk_nvme_transport_register(const struct spdk_nvme_transport_ops *ops) spdk_nvme_transport_register(const struct spdk_nvme_transport_ops *ops)
{ {
struct nvme_transport *registered_transport, *new_transport; struct nvme_transport *new_transport;
TAILQ_FOREACH(registered_transport, &g_spdk_nvme_transports, link) { if (nvme_get_transport(ops->name)) {
if (strcasecmp(ops->name, registered_transport->ops.name) == 0) { SPDK_ERRLOG("Double registering NVMe transport %s is prohibited.\n", ops->name);
SPDK_ERRLOG("Double registering NVMe transport %s is prohibited.\n", ops->name); assert(false);
assert(false);
return;
}
} }
new_transport = calloc(1, sizeof(*new_transport)); new_transport = calloc(1, sizeof(*new_transport));