Skip to content

Commit

Permalink
NVMe: Remove device management handles on remove
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Keith Busch authored and Jens Axboe committed Dec 22, 2015
1 parent 92f7a16 commit 53029b0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
13 changes: 9 additions & 4 deletions drivers/nvme/host/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1200,17 +1200,22 @@ static void nvme_release_instance(struct nvme_ctrl *ctrl)
spin_unlock(&dev_list_lock);
}

static void nvme_free_ctrl(struct kref *kref)
{
struct nvme_ctrl *ctrl = container_of(kref, struct nvme_ctrl, kref);
void nvme_uninit_ctrl(struct nvme_ctrl *ctrl)
{
device_remove_file(ctrl->device, &dev_attr_reset_controller);
device_destroy(nvme_class, MKDEV(nvme_char_major, ctrl->instance));

spin_lock(&dev_list_lock);
list_del(&ctrl->node);
spin_unlock(&dev_list_lock);
}

static void nvme_free_ctrl(struct kref *kref)
{
struct nvme_ctrl *ctrl = container_of(kref, struct nvme_ctrl, kref);

put_device(ctrl->device);
nvme_release_instance(ctrl);
device_destroy(nvme_class, MKDEV(nvme_char_major, ctrl->instance));

ctrl->ops->free_ctrl(ctrl);
}
Expand Down
1 change: 1 addition & 0 deletions drivers/nvme/host/nvme.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ int nvme_enable_ctrl(struct nvme_ctrl *ctrl, u64 cap);
int nvme_shutdown_ctrl(struct nvme_ctrl *ctrl);
int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
const struct nvme_ctrl_ops *ops, unsigned long quirks);
void nvme_uninit_ctrl(struct nvme_ctrl *ctrl);
void nvme_put_ctrl(struct nvme_ctrl *ctrl);
int nvme_init_identify(struct nvme_ctrl *ctrl);

Expand Down
1 change: 1 addition & 0 deletions drivers/nvme/host/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -2373,6 +2373,7 @@ static void nvme_remove(struct pci_dev *pdev)
flush_work(&dev->reset_work);
flush_work(&dev->scan_work);
nvme_remove_namespaces(&dev->ctrl);
nvme_uninit_ctrl(&dev->ctrl);
nvme_dev_shutdown(dev);
nvme_dev_remove_admin(dev);
nvme_free_queues(dev, 0);
Expand Down

0 comments on commit 53029b0

Please sign in to comment.