From 13827a74a893f5f0ab34d728e8ff13dac698d442 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Thu, 1 Dec 2016 11:16:32 -0700 Subject: [PATCH] nvme: do not detach automatically on hot remove The user's remove_cb should detach the NVMe controller when it can ensure that it is no longer in use. In the interim (between remove_cb and spdk_nvme_detach()), the controller will remain in a failed state, so any new I/O submissions will return an error code but not crash. examples/nvme/hotplug is not yet updated for this change, but that will be done in a separate patch. Change-Id: I8827ba36f9688ccb734e7871f20f11ec11e88f96 Signed-off-by: Daniel Verkamp --- include/spdk/nvme.h | 6 ++++++ lib/nvme/nvme.c | 9 --------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/include/spdk/nvme.h b/include/spdk/nvme.h index 20f4b7d0b..3b15c01da 100644 --- a/include/spdk/nvme.h +++ b/include/spdk/nvme.h @@ -218,6 +218,12 @@ typedef void (*spdk_nvme_attach_cb)(void *cb_ctx, const struct spdk_nvme_probe_i * Callback for spdk_nvme_probe() to report that a device attached to the userspace NVMe driver * has been removed from the system. * + * The controller will remain in a failed state (any new I/O submitted will fail). + * + * The controller must be detached from the userspace driver by calling spdk_nvme_detach() + * once the controller is no longer in use. It is up to the library user to ensure that + * no other threads are using the controller before calling spdk_nvme_detach(). + * * \param ctrlr NVMe controller instance that was removed. */ typedef void (*spdk_nvme_remove_cb)(void *cb_ctx, struct spdk_nvme_ctrlr *ctrlr); diff --git a/lib/nvme/nvme.c b/lib/nvme/nvme.c index df3f53e52..51123e264 100644 --- a/lib/nvme/nvme.c +++ b/lib/nvme/nvme.c @@ -489,7 +489,6 @@ static int nvme_hotplug_monitor(void *cb_ctx, spdk_nvme_probe_cb probe_cb, spdk_nvme_attach_cb attach_cb, spdk_nvme_remove_cb remove_cb) { - int rc = 0; struct spdk_nvme_ctrlr *ctrlr; struct spdk_uevent event; @@ -522,14 +521,6 @@ nvme_hotplug_monitor(void *cb_ctx, spdk_nvme_probe_cb probe_cb, spdk_nvme_attach if (remove_cb) { remove_cb(cb_ctx, ctrlr); } - if (spdk_process_is_primary()) { - rc = spdk_nvme_detach(ctrlr); - if (rc) { - SPDK_ERRLOG("Failed to hot detach nvme address: %04x:%04x:%04x.%u\n", - event.pci_addr.domain, event.pci_addr.bus, event.pci_addr.dev, - event.pci_addr.func); - } - } } } }