From 5a588715d90df39265393ed170e01252811e66ae Mon Sep 17 00:00:00 2001 From: Darek Stojaczyk Date: Wed, 31 Oct 2018 11:37:05 +0100 Subject: [PATCH] nvme: detach PCI device in secondary process We only detached the PCI device on the controller destruction, which happens just once - in the primary process, but secondary process needs the PCI detach as well. Requesting to hotremove the NVMe PCIe controller in secondary process is broken, because DPDK will still keep the device reference and won't allow SPDK to hotplug it again. Fix this by detaching the local PCI device whenever removing a secondary process from spdk_nvme_ctrlr. This does require an additional transport check in the generic NVMe layer, but I found it an overkill to create a multi-process transport abstraction just for this case. Change-Id: I812dc1c878ade5b149556806228a2afcb49f0b17 Signed-off-by: Darek Stojaczyk Reviewed-on: https://review.gerrithub.io/431487 Tested-by: SPDK CI Jenkins Chandler-Test-Pool: SPDK Automated Test System Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- lib/nvme/nvme_ctrlr.c | 4 ++++ test/unit/lib/nvme/nvme_ctrlr.c/nvme_ctrlr_ut.c | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/lib/nvme/nvme_ctrlr.c b/lib/nvme/nvme_ctrlr.c index 69ae08783..df94396db 100644 --- a/lib/nvme/nvme_ctrlr.c +++ b/lib/nvme/nvme_ctrlr.c @@ -1650,6 +1650,10 @@ nvme_ctrlr_remove_process(struct spdk_nvme_ctrlr *ctrlr, TAILQ_REMOVE(&ctrlr->active_procs, proc, tailq); + if (!proc->is_primary && ctrlr->trid.trtype == SPDK_NVME_TRANSPORT_PCIE) { + spdk_pci_device_detach(proc->devhandle); + } + spdk_dma_free(proc); } diff --git a/test/unit/lib/nvme/nvme_ctrlr.c/nvme_ctrlr_ut.c b/test/unit/lib/nvme/nvme_ctrlr.c/nvme_ctrlr_ut.c index db7469ff0..26f98e01b 100644 --- a/test/unit/lib/nvme/nvme_ctrlr.c/nvme_ctrlr_ut.c +++ b/test/unit/lib/nvme/nvme_ctrlr.c/nvme_ctrlr_ut.c @@ -421,6 +421,11 @@ nvme_ns_construct(struct spdk_nvme_ns *ns, uint32_t id, return 0; } +void +spdk_pci_device_detach(struct spdk_pci_device *device) +{ +} + #define DECLARE_AND_CONSTRUCT_CTRLR() \ struct spdk_nvme_ctrlr ctrlr = {}; \ struct spdk_nvme_qpair adminq = {}; \