nvme-pci: Fix controller freeze wait disabling
authorKeith Busch <keith.busch@intel.com>
Tue, 14 May 2019 20:07:38 +0000 (14:07 -0600)
committerKeith Busch <keith.busch@intel.com>
Fri, 17 May 2019 17:01:02 +0000 (11:01 -0600)
If a controller disabling didn't start a freeze, don't wait for the
operation to complete.

Reviewed-by: Ming Lei <ming.lei@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Keith Busch <keith.busch@intel.com>
drivers/nvme/host/pci.c

index 2a8708c9ac18fa62b85c7333f0950b11dcf212d0..d4e4421600486614540f56b0d2c6f05ea04fcf93 100644 (file)
@@ -2376,7 +2376,7 @@ static void nvme_pci_disable(struct nvme_dev *dev)
 
 static void nvme_dev_disable(struct nvme_dev *dev, bool shutdown)
 {
-       bool dead = true;
+       bool dead = true, freeze = false;
        struct pci_dev *pdev = to_pci_dev(dev->dev);
 
        mutex_lock(&dev->shutdown_lock);
@@ -2384,8 +2384,10 @@ static void nvme_dev_disable(struct nvme_dev *dev, bool shutdown)
                u32 csts = readl(dev->bar + NVME_REG_CSTS);
 
                if (dev->ctrl.state == NVME_CTRL_LIVE ||
-                   dev->ctrl.state == NVME_CTRL_RESETTING)
+                   dev->ctrl.state == NVME_CTRL_RESETTING) {
+                       freeze = true;
                        nvme_start_freeze(&dev->ctrl);
+               }
                dead = !!((csts & NVME_CSTS_CFS) || !(csts & NVME_CSTS_RDY) ||
                        pdev->error_state  != pci_channel_io_normal);
        }
@@ -2394,10 +2396,8 @@ static void nvme_dev_disable(struct nvme_dev *dev, bool shutdown)
         * Give the controller a chance to complete all entered requests if
         * doing a safe shutdown.
         */
-       if (!dead) {
-               if (shutdown)
-                       nvme_wait_freeze_timeout(&dev->ctrl, NVME_IO_TIMEOUT);
-       }
+       if (!dead && shutdown && freeze)
+               nvme_wait_freeze_timeout(&dev->ctrl, NVME_IO_TIMEOUT);
 
        nvme_stop_queues(&dev->ctrl);