From 84245b72026b786d6c20be840e9d7f7843b02960 Mon Sep 17 00:00:00 2001 From: Changpeng Liu Date: Mon, 4 Mar 2019 23:29:37 -0500 Subject: [PATCH] nvme: add spdk_nvme_connect_async() API Users may want to connect specified controller at running time, so this API will connect to the controller and return probe context to users, users must call spdk_nvme_probe_poll_async() to initialize the controller to the READY state before using it. Change-Id: I232886b000454ee826ea73c4e1043d0d18ee0ec6 Signed-off-by: Changpeng Liu Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/445657 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- CHANGELOG.md | 8 ++++++-- include/spdk/nvme.h | 23 +++++++++++++++++++++++ lib/nvme/nvme.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94b4edc14..f0f488ef5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,8 +8,12 @@ spdk_app_start() now only accepts a single context argument. ### nvme -Added asynchronous probe support. New APIs spdk_nvme_probe_async() and -spdk_nvme_probe_poll_async() were added to enable this feature. +Added asynchronous probe support. New APIs spdk_nvme_probe_async(), +spdk_nvme_connect_async() and spdk_nvme_probe_poll_async() were added to +enable this feature, spdk_nvme_probe_async() and spdk_nvme_connect_async() +return a context associated with the specified controllers. Users then call +spdk_nvme_probe_poll_async() until it returns 0, indicating that the operation +is completed with success. New API spdk_nvme_ctrlr_get_flags() was added. diff --git a/include/spdk/nvme.h b/include/spdk/nvme.h index 0e134ea63..6d289d123 100644 --- a/include/spdk/nvme.h +++ b/include/spdk/nvme.h @@ -578,6 +578,29 @@ struct spdk_nvme_ctrlr *spdk_nvme_connect(const struct spdk_nvme_transport_id *t struct spdk_nvme_probe_ctx; +/** + * Connect the NVMe driver to the device located at the given transport ID. + * + * The function will return a probe context on success, controller associates with + * the context is not ready for use, user must call spdk_nvme_probe_poll_async() + * until spdk_nvme_probe_poll_async() returns 0. + * + * \param trid The transport ID indicating which device to connect. If the trtype + * is PCIe, this will connect the local PCIe bus. If the trtype is RDMA, the traddr + * and trsvcid must point at the location of an NVMe-oF service. + * \param opts NVMe controller initialization options. Default values will be used + * if the user does not specify the options. The controller may not support all + * requested parameters. + * \param attach_cb will be called once the NVMe controller has been attached + * to the userspace driver. + * + * \return probe context on success, NULL on failure. + * + */ +struct spdk_nvme_probe_ctx *spdk_nvme_connect_async(const struct spdk_nvme_transport_id *trid, + const struct spdk_nvme_ctrlr_opts *opts, + spdk_nvme_attach_cb attach_cb); + /** * Probe and add controllers to the probe context list. * diff --git a/lib/nvme/nvme.c b/lib/nvme/nvme.c index b99565f9e..83329ac38 100644 --- a/lib/nvme/nvme.c +++ b/lib/nvme/nvme.c @@ -1101,4 +1101,37 @@ spdk_nvme_probe_poll_async(struct spdk_nvme_probe_ctx *probe_ctx) return -EAGAIN; } +struct spdk_nvme_probe_ctx * +spdk_nvme_connect_async(const struct spdk_nvme_transport_id *trid, + const struct spdk_nvme_ctrlr_opts *opts, + spdk_nvme_attach_cb attach_cb) +{ + int rc; + spdk_nvme_probe_cb probe_cb = NULL; + struct spdk_nvme_probe_ctx *probe_ctx; + + rc = nvme_driver_init(); + if (rc != 0) { + return NULL; + } + + probe_ctx = calloc(1, sizeof(*probe_ctx)); + if (!probe_ctx) { + return NULL; + } + + if (opts) { + probe_cb = spdk_nvme_connect_probe_cb; + } + + spdk_nvme_probe_ctx_init(probe_ctx, trid, (void *)opts, probe_cb, attach_cb, NULL); + rc = spdk_nvme_probe_internal(probe_ctx, true); + if (rc != 0) { + free(probe_ctx); + return NULL; + } + + return probe_ctx; +} + SPDK_LOG_REGISTER_COMPONENT("nvme", SPDK_LOG_NVME)