[PATCHv8] nvme: fix refcounting imbalance when all paths are down
Christoph Hellwig
hch at lst.de
Fri Jul 16 01:23:20 PDT 2021
> Changes to v7:
> - Move the list_del() call outside of nvme_mpath_check_last_path()
> Changes to v6:
> - Move the list_del() into nvme_mpath_check_last_path()
> - Drop the tests for GENHD_FL_UP
> Changes to v5:
> - Synchronize between nvme_init_ns_head() and nvme_mpath_check_last_path()
> - Check for removed gendisk in nvme_ns_head_submit_bio()
> Changes to v4:
> - Call del_gendisk() in nvme_mpath_check_last_path() to avoid deadlock
> Changes to v3:
> - Simplify if() clause to detect duplicate namespaces
> Changes to v2:
> - Drop memcpy() statement
> Changes to v1:
> - Always check NSIDs after reattach
The changelog belongs under the ---.
The patch also does not actually apply due to changes in 5.14-rc, so
please respin it.
> - nvme_mpath_check_last_path(ns);
> + /* Synchronize with nvme_init_ns_head() */
> + mutex_lock(&ns->head->subsys->lock);
> + if (list_empty(&ns->head->list)) {
> + list_del_init(&ns->head->entry);
> + last_path = true;
> + }
> + mutex_unlock(&ns->head->subsys->lock);
> + if (last_path)
> + nvme_mpath_check_last_path(ns->head);
And while we're at it - nvme_mpath_check_last_path is a little misnamed
now as we know this is the last path when we call it now. Maybe this
function should inherit the nvme_mpath_remove_disk name and ther other
half should become nvme_mpath_cleanup_disk?
> +void nvme_mpath_remove_disk(struct nvme_ns_head *head)
> +{
> + if (!head->disk)
> + return;
> blk_set_queue_dying(head->disk->queue);
> /* make sure all pending bios are cleaned up */
> kblockd_schedule_work(&head->requeue_work);
> flush_work(&head->requeue_work);
> blk_cleanup_queue(head->disk->queue);
> - if (!test_bit(NVME_NSHEAD_DISK_LIVE, &head->flags)) {
> + if (!test_and_clear_bit(NVME_NSHEAD_DISK_LIVE, &head->flags)) {
This is where the conflict happens. But given that with the above
changes we can't find the ns_head any more once nvme_ns_remove
decided it actually is the last path I don't think we even need to
clear NVME_NSHEAD_DISK_LIVE any more. This was only needed when we
tried to reuse the ns_head.
More information about the Linux-nvme
mailing list