From d7d03bd36ab2138d311308eaff7482b695c5d7e7 Mon Sep 17 00:00:00 2001 From: Seth Howell Date: Thu, 26 Sep 2019 14:29:18 -0700 Subject: [PATCH] nvme: store the probe destroy_cb in the ctrlr. Making this structure available from the ctrlr allows us to call the remove callback when the controller is failed/removed on transports other than pcie. Change-Id: I2c66dfef12b039c0d6daf7df83da745757818006 Signed-off-by: Seth Howell Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/469636 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- lib/nvme/nvme.c | 2 ++ lib/nvme/nvme_internal.h | 4 ++++ lib/nvme/nvme_pcie.c | 8 ++++---- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/nvme/nvme.c b/lib/nvme/nvme.c index 49c75e54f..af08c0636 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 b6138118c..b3e6434cb 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 609bfa176..d830e4af5 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); } }