nvme: move probe context as a internal data structure

Users should not access the internal probe context fields when
using the asynchronous probe API, so change spdk_nvme_probe_async()
to let it can only return the probe context pointer.

Change-Id: I0413c2d8db6cbe4539ad80919ed34dd621a9df70
Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.gerrithub.io/c/445870
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-02-21 20:22:40 -05:00 committed by Jim Harris
parent 2fefd9f53c
commit 30bbf3d944
4 changed files with 59 additions and 50 deletions

View File

@ -4,8 +4,8 @@
### nvme
Added asynchronous probe support. New APIs spdk_nvme_probe_ctx_init(), 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() and
spdk_nvme_probe_poll_async() were added to enable this feature.
### raid

View File

@ -566,19 +566,14 @@ struct spdk_nvme_ctrlr *spdk_nvme_connect(const struct spdk_nvme_transport_id *t
const struct spdk_nvme_ctrlr_opts *opts,
size_t opts_size);
struct spdk_nvme_probe_ctx {
struct spdk_nvme_transport_id trid;
void *cb_ctx;
spdk_nvme_probe_cb probe_cb;
spdk_nvme_attach_cb attach_cb;
spdk_nvme_remove_cb remove_cb;
TAILQ_HEAD(, spdk_nvme_ctrlr) init_ctrlrs;
};
struct spdk_nvme_probe_ctx;
/**
* Initialize a context to track the probe result based on transport ID.
* Probe and add controllers to the probe context list.
*
* Users must call spdk_nvme_probe_poll_async() to initialize
* controllers in the probe context list to the READY state.
*
* \param probe_ctx Context used to track probe actions.
* \param trid The transport ID indicating which bus to enumerate. If the trtype
* is PCIe or trid is NULL, this will scan the local PCIe bus. If the trtype is
* RDMA, the traddr and trsvcid must point at the location of an NVMe-oF discovery
@ -592,25 +587,13 @@ struct spdk_nvme_probe_ctx {
* spdk_nvme_probe() call but are no longer attached to the system. Optional;
* specify NULL if removal notices are not desired.
*
* \return probe context on success, NULL on failure.
*/
void spdk_nvme_probe_ctx_init(struct spdk_nvme_probe_ctx *probe_ctx,
const struct spdk_nvme_transport_id *trid,
void *cb_ctx,
spdk_nvme_probe_cb probe_cb,
spdk_nvme_attach_cb attach_cb,
spdk_nvme_remove_cb remove_cb);
/**
* Probe and add controllers to the probe context list.
*
* Users must call spdk_nvme_probe_poll_async() to initialize
* controllers in the probe context list to the READY state.
*
* \param probe_ctx Context used to track probe actions.
*
* \return 0 on success, -1 on failure.
*/
int spdk_nvme_probe_async(struct spdk_nvme_probe_ctx *probe_ctx);
struct spdk_nvme_probe_ctx *spdk_nvme_probe_async(const struct spdk_nvme_transport_id *trid,
void *cb_ctx,
spdk_nvme_probe_cb probe_cb,
spdk_nvme_attach_cb attach_cb,
spdk_nvme_remove_cb remove_cb);
/**
* Start controllers in the context list.

View File

@ -585,6 +585,22 @@ spdk_nvme_probe_internal(struct spdk_nvme_probe_ctx *probe_ctx,
return 0;
}
static void
spdk_nvme_probe_ctx_init(struct spdk_nvme_probe_ctx *probe_ctx,
const struct spdk_nvme_transport_id *trid,
void *cb_ctx,
spdk_nvme_probe_cb probe_cb,
spdk_nvme_attach_cb attach_cb,
spdk_nvme_remove_cb remove_cb)
{
probe_ctx->trid = *trid;
probe_ctx->cb_ctx = cb_ctx;
probe_ctx->probe_cb = probe_cb;
probe_ctx->attach_cb = attach_cb;
probe_ctx->remove_cb = remove_cb;
TAILQ_INIT(&probe_ctx->init_ctrlrs);
}
int
spdk_nvme_probe(const struct spdk_nvme_transport_id *trid, void *cb_ctx,
spdk_nvme_probe_cb probe_cb, spdk_nvme_attach_cb attach_cb,
@ -1046,33 +1062,34 @@ spdk_nvme_prchk_flags_str(uint32_t prchk_flags)
}
}
void
spdk_nvme_probe_ctx_init(struct spdk_nvme_probe_ctx *probe_ctx,
const struct spdk_nvme_transport_id *trid,
void *cb_ctx,
spdk_nvme_probe_cb probe_cb,
spdk_nvme_attach_cb attach_cb,
spdk_nvme_remove_cb remove_cb)
{
probe_ctx->trid = *trid;
probe_ctx->cb_ctx = cb_ctx;
probe_ctx->probe_cb = probe_cb;
probe_ctx->attach_cb = attach_cb;
probe_ctx->remove_cb = remove_cb;
TAILQ_INIT(&probe_ctx->init_ctrlrs);
}
int
spdk_nvme_probe_async(struct spdk_nvme_probe_ctx *probe_ctx)
struct spdk_nvme_probe_ctx *
spdk_nvme_probe_async(const struct spdk_nvme_transport_id *trid,
void *cb_ctx,
spdk_nvme_probe_cb probe_cb,
spdk_nvme_attach_cb attach_cb,
spdk_nvme_remove_cb remove_cb)
{
int rc;
struct spdk_nvme_probe_ctx *probe_ctx;
rc = nvme_driver_init();
if (rc != 0) {
return rc;
return NULL;
}
return spdk_nvme_probe_internal(probe_ctx, false);
probe_ctx = calloc(1, sizeof(*probe_ctx));
if (!probe_ctx) {
return NULL;
}
spdk_nvme_probe_ctx_init(probe_ctx, trid, cb_ctx, probe_cb, attach_cb, remove_cb);
rc = spdk_nvme_probe_internal(probe_ctx, false);
if (rc != 0) {
free(probe_ctx);
return NULL;
}
return probe_ctx;
}
bool

View File

@ -691,6 +691,15 @@ struct spdk_nvme_ctrlr {
uint32_t outstanding_aborts;
};
struct spdk_nvme_probe_ctx {
struct spdk_nvme_transport_id trid;
void *cb_ctx;
spdk_nvme_probe_cb probe_cb;
spdk_nvme_attach_cb attach_cb;
spdk_nvme_remove_cb remove_cb;
TAILQ_HEAD(, spdk_nvme_ctrlr) init_ctrlrs;
};
struct nvme_driver {
pthread_mutex_t lock;