nvme: Support multiple spdk_nvme_connect to same device
Change-Id: I0b3e5d263ab15798302a2a32dfe860f29641fc06 Signed-off-by: Ben Walker <benjamin.walker@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/453009 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:
parent
19182431c8
commit
59467b3a39
@ -391,6 +391,7 @@ nvme_driver_init(void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* This function must only be called while holding g_spdk_nvme_driver->lock */
|
||||
int
|
||||
nvme_ctrlr_probe(const struct spdk_nvme_transport_id *trid,
|
||||
struct spdk_nvme_probe_ctx *probe_ctx, void *devhandle)
|
||||
@ -403,6 +404,21 @@ nvme_ctrlr_probe(const struct spdk_nvme_transport_id *trid,
|
||||
spdk_nvme_ctrlr_get_default_ctrlr_opts(&opts, sizeof(opts));
|
||||
|
||||
if (!probe_ctx->probe_cb || probe_ctx->probe_cb(probe_ctx->cb_ctx, trid, &opts)) {
|
||||
ctrlr = spdk_nvme_get_ctrlr_by_trid_unsafe(trid);
|
||||
if (ctrlr) {
|
||||
/* This ctrlr already exists.
|
||||
* Increase the ref count before calling attach_cb() as the user may
|
||||
* call nvme_detach() immediately. */
|
||||
nvme_ctrlr_proc_get_ref(ctrlr);
|
||||
|
||||
if (probe_ctx->attach_cb) {
|
||||
nvme_robust_mutex_unlock(&g_spdk_nvme_driver->lock);
|
||||
probe_ctx->attach_cb(probe_ctx->cb_ctx, &ctrlr->trid, ctrlr, &ctrlr->opts);
|
||||
nvme_robust_mutex_lock(&g_spdk_nvme_driver->lock);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
ctrlr = nvme_transport_ctrlr_construct(trid, &opts, devhandle);
|
||||
if (ctrlr == NULL) {
|
||||
SPDK_ERRLOG("Failed to construct NVMe controller for SSD: %s\n", trid->traddr);
|
||||
|
@ -725,6 +725,8 @@ test_nvme_ctrlr_probe(void)
|
||||
void *cb_ctx = NULL;
|
||||
struct spdk_nvme_ctrlr *dummy = NULL;
|
||||
|
||||
nvme_driver_init();
|
||||
|
||||
/* test when probe_cb returns false */
|
||||
|
||||
MOCK_SET(dummy_probe_cb, false);
|
||||
@ -740,8 +742,6 @@ test_nvme_ctrlr_probe(void)
|
||||
CU_ASSERT(rc == -1);
|
||||
|
||||
/* happy path */
|
||||
g_spdk_nvme_driver = malloc(sizeof(struct nvme_driver));
|
||||
SPDK_CU_ASSERT_FATAL(g_spdk_nvme_driver != NULL);
|
||||
MOCK_SET(dummy_probe_cb, true);
|
||||
MOCK_SET(nvme_transport_ctrlr_construct, &ctrlr);
|
||||
spdk_nvme_probe_ctx_init(&probe_ctx, &trid, cb_ctx, dummy_probe_cb, NULL, NULL);
|
||||
|
Loading…
Reference in New Issue
Block a user