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 <changpeng.liu@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/445657
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Changpeng Liu 2019-03-04 23:29:37 -05:00 committed by Jim Harris
parent 8e4d6b3d0d
commit 84245b7202
3 changed files with 62 additions and 2 deletions

View File

@ -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.

View File

@ -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.
*

View File

@ -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)