summaryrefslogtreecommitdiffstats
path: root/drivers/nvme
diff options
context:
space:
mode:
authorKeith Busch <keith.busch@intel.com>2015-11-28 09:41:02 -0500
committerJens Axboe <axboe@fb.com>2015-12-22 11:38:33 -0500
commit53029b0441bbd263dbb2ee6429572b1732dad4de (patch)
tree28c6524a7fc5c56c019835d12c16c3ef2baca51b /drivers/nvme
parent92f7a1624bbc2361b96db81de89aee1baae40da9 (diff)
NVMe: Remove device management handles on remove
We don't want to allow new references to open on a device that is removed. This ties the lifetime of these handles to the physical device's presence rather than to the open reference count. Signed-off-by: Keith Busch <keith.busch@intel.com> Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'drivers/nvme')
-rw-r--r--drivers/nvme/host/core.c13
-rw-r--r--drivers/nvme/host/nvme.h1
-rw-r--r--drivers/nvme/host/pci.c1
3 files changed, 11 insertions, 4 deletions
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 96e05327ecf6..25cb1929e985 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1200,17 +1200,22 @@ static void nvme_release_instance(struct nvme_ctrl *ctrl)
1200 spin_unlock(&dev_list_lock); 1200 spin_unlock(&dev_list_lock);
1201} 1201}
1202 1202
1203static void nvme_free_ctrl(struct kref *kref) 1203void nvme_uninit_ctrl(struct nvme_ctrl *ctrl)
1204{ 1204 {
1205 struct nvme_ctrl *ctrl = container_of(kref, struct nvme_ctrl, kref); 1205 device_remove_file(ctrl->device, &dev_attr_reset_controller);
1206 device_destroy(nvme_class, MKDEV(nvme_char_major, ctrl->instance));
1206 1207
1207 spin_lock(&dev_list_lock); 1208 spin_lock(&dev_list_lock);
1208 list_del(&ctrl->node); 1209 list_del(&ctrl->node);
1209 spin_unlock(&dev_list_lock); 1210 spin_unlock(&dev_list_lock);
1211}
1212
1213static void nvme_free_ctrl(struct kref *kref)
1214{
1215 struct nvme_ctrl *ctrl = container_of(kref, struct nvme_ctrl, kref);
1210 1216
1211 put_device(ctrl->device); 1217 put_device(ctrl->device);
1212 nvme_release_instance(ctrl); 1218 nvme_release_instance(ctrl);
1213 device_destroy(nvme_class, MKDEV(nvme_char_major, ctrl->instance));
1214 1219
1215 ctrl->ops->free_ctrl(ctrl); 1220 ctrl->ops->free_ctrl(ctrl);
1216} 1221}
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 2965c469da4a..aa4b42ecbebe 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -221,6 +221,7 @@ int nvme_enable_ctrl(struct nvme_ctrl *ctrl, u64 cap);
221int nvme_shutdown_ctrl(struct nvme_ctrl *ctrl); 221int nvme_shutdown_ctrl(struct nvme_ctrl *ctrl);
222int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev, 222int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
223 const struct nvme_ctrl_ops *ops, unsigned long quirks); 223 const struct nvme_ctrl_ops *ops, unsigned long quirks);
224void nvme_uninit_ctrl(struct nvme_ctrl *ctrl);
224void nvme_put_ctrl(struct nvme_ctrl *ctrl); 225void nvme_put_ctrl(struct nvme_ctrl *ctrl);
225int nvme_init_identify(struct nvme_ctrl *ctrl); 226int nvme_init_identify(struct nvme_ctrl *ctrl);
226 227
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index a909a8ba228a..c83f0d8a592b 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -2373,6 +2373,7 @@ static void nvme_remove(struct pci_dev *pdev)
2373 flush_work(&dev->reset_work); 2373 flush_work(&dev->reset_work);
2374 flush_work(&dev->scan_work); 2374 flush_work(&dev->scan_work);
2375 nvme_remove_namespaces(&dev->ctrl); 2375 nvme_remove_namespaces(&dev->ctrl);
2376 nvme_uninit_ctrl(&dev->ctrl);
2376 nvme_dev_shutdown(dev); 2377 nvme_dev_shutdown(dev);
2377 nvme_dev_remove_admin(dev); 2378 nvme_dev_remove_admin(dev);
2378 nvme_free_queues(dev, 0); 2379 nvme_free_queues(dev, 0);