nvme: call the remove_cb in nvme_ctrlr_fail.

The remove callback is a built in way of alerting the user application
that we have removed a controller. Once we fail a controller, we never
move it back out of that state so it is in essence removed.

Change-Id: Iaad6bef0994e9ddd5a424f6b83502f9191b2de49
Signed-off-by: Seth Howell <seth.howell@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/469637
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@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:
Seth Howell 2019-09-26 14:56:53 -07:00 committed by Jim Harris
parent 128bd51ad0
commit bc4e31d6b2
2 changed files with 31 additions and 12 deletions

View File

@ -585,6 +585,8 @@ 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().
@ -592,8 +594,36 @@ 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

View File

@ -296,14 +296,8 @@ _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);
}
}
}
}
@ -331,11 +325,6 @@ _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;