Commit 5c8809e6 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

nvme: remove dead controllers from a work item

Compared to the kthread this gives us multiple call prevention for free.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarKeith Busch <keith.busch@intel.com>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
parent fd634f41
...@@ -80,7 +80,7 @@ struct nvme_iod; ...@@ -80,7 +80,7 @@ struct nvme_iod;
static int nvme_reset(struct nvme_dev *dev); static int nvme_reset(struct nvme_dev *dev);
static void nvme_process_cq(struct nvme_queue *nvmeq); static void nvme_process_cq(struct nvme_queue *nvmeq);
static void nvme_unmap_data(struct nvme_dev *dev, struct nvme_iod *iod); static void nvme_unmap_data(struct nvme_dev *dev, struct nvme_iod *iod);
static void nvme_dead_ctrl(struct nvme_dev *dev); static void nvme_remove_dead_ctrl(struct nvme_dev *dev);
static void nvme_dev_shutdown(struct nvme_dev *dev); static void nvme_dev_shutdown(struct nvme_dev *dev);
struct async_cmd_info { struct async_cmd_info {
...@@ -113,6 +113,7 @@ struct nvme_dev { ...@@ -113,6 +113,7 @@ struct nvme_dev {
void __iomem *bar; void __iomem *bar;
struct work_struct reset_work; struct work_struct reset_work;
struct work_struct scan_work; struct work_struct scan_work;
struct work_struct remove_work;
struct mutex shutdown_lock; struct mutex shutdown_lock;
bool subsystem; bool subsystem;
void __iomem *cmb; void __iomem *cmb;
...@@ -2218,31 +2219,25 @@ static void nvme_reset_work(struct work_struct *work) ...@@ -2218,31 +2219,25 @@ static void nvme_reset_work(struct work_struct *work)
unmap: unmap:
nvme_dev_unmap(dev); nvme_dev_unmap(dev);
out: out:
if (!work_pending(&dev->reset_work)) nvme_remove_dead_ctrl(dev);
nvme_dead_ctrl(dev);
} }
static int nvme_remove_dead_ctrl(void *arg) static void nvme_remove_dead_ctrl_work(struct work_struct *work)
{ {
struct nvme_dev *dev = (struct nvme_dev *)arg; struct nvme_dev *dev = container_of(work, struct nvme_dev, remove_work);
struct pci_dev *pdev = to_pci_dev(dev->dev); struct pci_dev *pdev = to_pci_dev(dev->dev);
if (pci_get_drvdata(pdev)) if (pci_get_drvdata(pdev))
pci_stop_and_remove_bus_device_locked(pdev); pci_stop_and_remove_bus_device_locked(pdev);
nvme_put_ctrl(&dev->ctrl); nvme_put_ctrl(&dev->ctrl);
return 0;
} }
static void nvme_dead_ctrl(struct nvme_dev *dev) static void nvme_remove_dead_ctrl(struct nvme_dev *dev)
{ {
dev_warn(dev->dev, "Device failed to resume\n"); dev_warn(dev->dev, "Removing after probe failure\n");
kref_get(&dev->ctrl.kref); kref_get(&dev->ctrl.kref);
if (IS_ERR(kthread_run(nvme_remove_dead_ctrl, dev, "nvme%d", if (!schedule_work(&dev->remove_work))
dev->ctrl.instance))) {
dev_err(dev->dev,
"Failed to start controller remove task\n");
nvme_put_ctrl(&dev->ctrl); nvme_put_ctrl(&dev->ctrl);
}
} }
static int nvme_reset(struct nvme_dev *dev) static int nvme_reset(struct nvme_dev *dev)
...@@ -2323,6 +2318,7 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id) ...@@ -2323,6 +2318,7 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
INIT_LIST_HEAD(&dev->node); INIT_LIST_HEAD(&dev->node);
INIT_WORK(&dev->scan_work, nvme_dev_scan); INIT_WORK(&dev->scan_work, nvme_dev_scan);
INIT_WORK(&dev->reset_work, nvme_reset_work); INIT_WORK(&dev->reset_work, nvme_reset_work);
INIT_WORK(&dev->remove_work, nvme_remove_dead_ctrl_work);
mutex_init(&dev->shutdown_lock); mutex_init(&dev->shutdown_lock);
result = nvme_setup_prp_pools(dev); result = nvme_setup_prp_pools(dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment