[PATCH] nvme: remove pci device if no longer present

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch removes the PCI device from the kernel's topology tree
if the device is no longer present.

Commit ddf097ec1d44c9648c4738d7cf2819411b44253a (NVMe: Unbind driver on
failure) left the PCI device in the kernel's topology upon device failure.
However, this does not work well for the slot power off/on test cases.
After a slot power off, we need to manually remove the PCI device
before triggering the rescan, in order for the SSD to be rediscovered.

Fixes: ddf097ec1d44c9648c4738d7cf2819411b44253a
Signed-off-by: Wei Zhang <wzhang@xxxxxx>
Reviewed-by: Jens Axboe <axboe@xxxxxx>
---
 drivers/nvme/host/pci.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 32a98e2..094b22f 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -2174,8 +2174,19 @@ static void nvme_remove_dead_ctrl_work(struct work_struct *work)
 	struct pci_dev *pdev = to_pci_dev(dev->dev);
 
 	nvme_kill_queues(&dev->ctrl);
-	if (pci_get_drvdata(pdev))
-		device_release_driver(&pdev->dev);
+
+	/*
+	 * Remove the PCI device from the topology tree if the device is no longer
+	 * present.  Without removing, slot power off/on test cannot re-discover
+	 * the SSD.
+	 */
+	if (pci_get_drvdata(pdev)) {
+		if (!pci_device_is_present(pdev)) {
+			pci_stop_and_remove_bus_device_locked(pdev);
+		} else {
+			device_release_driver(&pdev->dev);
+		}
+	}
 	nvme_put_ctrl(&dev->ctrl);
 }
 
-- 
2.9.3




[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux