diff --git a/lib/nvme/nvme.c b/lib/nvme/nvme.c index 49c75e54f2..af08c06367 100644 --- a/lib/nvme/nvme.c +++ b/lib/nvme/nvme.c @@ -426,6 +426,8 @@ nvme_ctrlr_probe(const struct spdk_nvme_transport_id *trid, SPDK_ERRLOG("Failed to construct NVMe controller for SSD: %s\n", trid->traddr); return -1; } + ctrlr->remove_cb = probe_ctx->remove_cb; + ctrlr->cb_ctx = probe_ctx->cb_ctx; TAILQ_INSERT_TAIL(&probe_ctx->init_ctrlrs, ctrlr, tailq); return 0; diff --git a/lib/nvme/nvme_internal.h b/lib/nvme/nvme_internal.h index b6138118ce..b3e6434cb7 100644 --- a/lib/nvme/nvme_internal.h +++ b/lib/nvme/nvme_internal.h @@ -701,6 +701,10 @@ struct spdk_nvme_ctrlr { STAILQ_HEAD(, nvme_request) queued_aborts; uint32_t outstanding_aborts; + + /* CB to notify the user when the ctrlr is removed/failed. */ + spdk_nvme_remove_cb remove_cb; + void *cb_ctx; }; struct spdk_nvme_probe_ctx { diff --git a/lib/nvme/nvme_pcie.c b/lib/nvme/nvme_pcie.c index 609bfa1769..d830e4af5e 100644 --- a/lib/nvme/nvme_pcie.c +++ b/lib/nvme/nvme_pcie.c @@ -299,9 +299,9 @@ _nvme_pcie_hotplug_monitor(struct spdk_nvme_probe_ctx *probe_ctx) nvme_ctrlr_fail(ctrlr, true); /* get the user app to clean up and stop I/O */ - if (probe_ctx->remove_cb) { + if (ctrlr->remove_cb) { nvme_robust_mutex_unlock(&g_spdk_nvme_driver->lock); - probe_ctx->remove_cb(probe_ctx->cb_ctx, ctrlr); + ctrlr->remove_cb(probe_ctx->cb_ctx, ctrlr); nvme_robust_mutex_lock(&g_spdk_nvme_driver->lock); } } @@ -331,9 +331,9 @@ _nvme_pcie_hotplug_monitor(struct spdk_nvme_probe_ctx *probe_ctx) if (do_remove) { nvme_ctrlr_fail(ctrlr, true); - if (probe_ctx->remove_cb) { + if (ctrlr->remove_cb) { nvme_robust_mutex_unlock(&g_spdk_nvme_driver->lock); - probe_ctx->remove_cb(probe_ctx->cb_ctx, ctrlr); + ctrlr->remove_cb(probe_ctx->cb_ctx, ctrlr); nvme_robust_mutex_lock(&g_spdk_nvme_driver->lock); } }