diff --git a/lib/nvme/nvme_ctrlr.c b/lib/nvme/nvme_ctrlr.c index fad4dd67f..524fbb8a7 100644 --- a/lib/nvme/nvme_ctrlr.c +++ b/lib/nvme/nvme_ctrlr.c @@ -585,8 +585,6 @@ nvme_ctrlr_set_supported_features(struct spdk_nvme_ctrlr *ctrlr) void nvme_ctrlr_fail(struct spdk_nvme_ctrlr *ctrlr, bool hot_remove) { - int had_lock; - /* * Set the flag here and leave the work failure of qpairs to * spdk_nvme_qpair_process_completions(). @@ -594,36 +592,8 @@ nvme_ctrlr_fail(struct spdk_nvme_ctrlr *ctrlr, bool hot_remove) if (hot_remove) { ctrlr->is_removed = true; } - - /* - * Return if we have already set the state to failed since we - * don't want to call the disconnect callback twice. - */ - if (ctrlr->is_failed) { - return; - } ctrlr->is_failed = true; SPDK_ERRLOG("ctrlr %s in failed state.\n", ctrlr->trid.traddr); - - if (ctrlr->remove_cb == NULL) { - return; - } - - /* - * In the pcie hotplug case, this function may be called with the - * global driver lock. In that case, we want to make sure that we - * release it before calling the remove callback and restore the - * old state afterwards. - * robust locks return EPERM if we try to unlock a lock we - * aren't holding. - */ - had_lock = (nvme_robust_mutex_unlock(&g_spdk_nvme_driver->lock) == 0); - - ctrlr->remove_cb(ctrlr->cb_ctx, ctrlr); - - if (had_lock) { - nvme_robust_mutex_lock(&g_spdk_nvme_driver->lock); - } } static void diff --git a/lib/nvme/nvme_pcie.c b/lib/nvme/nvme_pcie.c index 91a598acf..d830e4af5 100644 --- a/lib/nvme/nvme_pcie.c +++ b/lib/nvme/nvme_pcie.c @@ -296,8 +296,14 @@ _nvme_pcie_hotplug_monitor(struct spdk_nvme_probe_ctx *probe_ctx) SPDK_DEBUGLOG(SPDK_LOG_NVME, "remove nvme address: %s\n", event.traddr); - /* get the user app to clean up and stop I/O. */ nvme_ctrlr_fail(ctrlr, true); + + /* get the user app to clean up and stop I/O */ + if (ctrlr->remove_cb) { + nvme_robust_mutex_unlock(&g_spdk_nvme_driver->lock); + ctrlr->remove_cb(probe_ctx->cb_ctx, ctrlr); + nvme_robust_mutex_lock(&g_spdk_nvme_driver->lock); + } } } } @@ -325,6 +331,11 @@ _nvme_pcie_hotplug_monitor(struct spdk_nvme_probe_ctx *probe_ctx) if (do_remove) { nvme_ctrlr_fail(ctrlr, true); + if (ctrlr->remove_cb) { + nvme_robust_mutex_unlock(&g_spdk_nvme_driver->lock); + ctrlr->remove_cb(probe_ctx->cb_ctx, ctrlr); + nvme_robust_mutex_lock(&g_spdk_nvme_driver->lock); + } } } return 0;