block: fix surprise removal for drivers calling blk_set_queue_dying
authorChristoph Hellwig <hch@lst.de>
Thu, 17 Feb 2022 07:52:31 +0000 (08:52 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 23 Feb 2022 11:03:15 +0000 (12:03 +0100)
commit 7a5428dcb7902700b830e912feee4e845df7c019 upstream.

Various block drivers call blk_set_queue_dying to mark a disk as dead due
to surprise removal events, but since commit 8e141f9eb803 that doesn't
work given that the GD_DEAD flag needs to be set to stop I/O.

Replace the driver calls to blk_set_queue_dying with a new (and properly
documented) blk_mark_disk_dead API, and fold blk_set_queue_dying into the
only remaining caller.

Fixes: 8e141f9eb803 ("block: drain file system I/O on del_gendisk")
Reported-by: Markus Blöchl <markus.bloechl@ipetronik.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Link: https://lore.kernel.org/r/20220217075231.1140-1-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
block/blk-core.c
block/genhd.c
drivers/block/mtip32xx/mtip32xx.c
drivers/block/rbd.c
drivers/block/xen-blkfront.c
drivers/md/dm.c
drivers/nvme/host/core.c
drivers/nvme/host/multipath.c
include/linux/blkdev.h

index d42a0f3ff73615c398ae396f2f3b49a5f9b546ab..42ac3a985c2d7da6790c1ead186bc4132a3d165a 100644 (file)
@@ -350,13 +350,6 @@ void blk_queue_start_drain(struct request_queue *q)
        wake_up_all(&q->mq_freeze_wq);
 }
 
-void blk_set_queue_dying(struct request_queue *q)
-{
-       blk_queue_flag_set(QUEUE_FLAG_DYING, q);
-       blk_queue_start_drain(q);
-}
-EXPORT_SYMBOL_GPL(blk_set_queue_dying);
-
 /**
  * blk_cleanup_queue - shutdown a request queue
  * @q: request queue to shutdown
@@ -374,7 +367,8 @@ void blk_cleanup_queue(struct request_queue *q)
        WARN_ON_ONCE(blk_queue_registered(q));
 
        /* mark @q DYING, no new request or merges will be allowed afterwards */
-       blk_set_queue_dying(q);
+       blk_queue_flag_set(QUEUE_FLAG_DYING, q);
+       blk_queue_start_drain(q);
 
        blk_queue_flag_set(QUEUE_FLAG_NOMERGES, q);
        blk_queue_flag_set(QUEUE_FLAG_NOXMERGES, q);
index de789d1a1e3d2d7b7b377ec293ec47e032a16c98..2dcedbe4ef0464071d2a2eff5a69c14ec326d523 100644 (file)
@@ -544,6 +544,20 @@ out_free_ext_minor:
 }
 EXPORT_SYMBOL(device_add_disk);
 
+/**
+ * blk_mark_disk_dead - mark a disk as dead
+ * @disk: disk to mark as dead
+ *
+ * Mark as disk as dead (e.g. surprise removed) and don't accept any new I/O
+ * to this disk.
+ */
+void blk_mark_disk_dead(struct gendisk *disk)
+{
+       set_bit(GD_DEAD, &disk->state);
+       blk_queue_start_drain(disk->queue);
+}
+EXPORT_SYMBOL_GPL(blk_mark_disk_dead);
+
 /**
  * del_gendisk - remove the gendisk
  * @disk: the struct gendisk to remove
index 901855717cb53607d9e2309d333579166777ebab..ba61e72741eab1c4a1268d2ada9914f4cd205ebf 100644 (file)
@@ -4112,7 +4112,7 @@ static void mtip_pci_remove(struct pci_dev *pdev)
                        "Completion workers still active!\n");
        }
 
-       blk_set_queue_dying(dd->queue);
+       blk_mark_disk_dead(dd->disk);
        set_bit(MTIP_DDF_REMOVE_PENDING_BIT, &dd->dd_flag);
 
        /* Clean up the block layer. */
index e65c9d706f6fbaf174b49f84d0b52899571ea6af..c4a52f33604dcf8aaff23233f914ddfe62258244 100644 (file)
@@ -7182,7 +7182,7 @@ static ssize_t do_rbd_remove(struct bus_type *bus,
                 * IO to complete/fail.
                 */
                blk_mq_freeze_queue(rbd_dev->disk->queue);
-               blk_set_queue_dying(rbd_dev->disk->queue);
+               blk_mark_disk_dead(rbd_dev->disk);
        }
 
        del_gendisk(rbd_dev->disk);
index 4dbb71230d6e76a8d613555921901408eb157c18..3efd341959832a008ae917ae77756a75180547a5 100644 (file)
@@ -2128,7 +2128,7 @@ static void blkfront_closing(struct blkfront_info *info)
 
        /* No more blkif_request(). */
        blk_mq_stop_hw_queues(info->rq);
-       blk_set_queue_dying(info->rq);
+       blk_mark_disk_dead(info->gd);
        set_capacity(info->gd, 0);
 
        for_each_rinfo(info, rinfo, i) {
index b75ff6b2b9525c2376252cb046369b6c86c089af..5f33700d1247344f070838973767a9fd396c65d9 100644 (file)
@@ -2156,7 +2156,7 @@ static void __dm_destroy(struct mapped_device *md, bool wait)
        set_bit(DMF_FREEING, &md->flags);
        spin_unlock(&_minor_lock);
 
-       blk_set_queue_dying(md->queue);
+       blk_mark_disk_dead(md->disk);
 
        /*
         * Take suspend_lock so that presuspend and postsuspend methods
index 8aa92ebb8b7c184d7ad66f73cdfee5fac2cbac03..a480e1af48e8e39bfad225435435db194db7da5b 100644 (file)
@@ -131,7 +131,7 @@ static void nvme_set_queue_dying(struct nvme_ns *ns)
        if (test_and_set_bit(NVME_NS_DEAD, &ns->flags))
                return;
 
-       blk_set_queue_dying(ns->queue);
+       blk_mark_disk_dead(ns->disk);
        blk_mq_unquiesce_queue(ns->queue);
 
        set_capacity_and_notify(ns->disk, 0);
index 2f76969408b272ad8fb950a0bfba20ba907cab81..727520c397109203aa98dae966a4eaac957b67fe 100644 (file)
@@ -792,7 +792,7 @@ void nvme_mpath_remove_disk(struct nvme_ns_head *head)
 {
        if (!head->disk)
                return;
-       blk_set_queue_dying(head->disk->queue);
+       blk_mark_disk_dead(head->disk);
        /* make sure all pending bios are cleaned up */
        kblockd_schedule_work(&head->requeue_work);
        flush_work(&head->requeue_work);
index be8e7a55d803cf08489f8bbe6cb3607c495da3e1..413c0148c0ce565fbfbf0902a6001c3cb7916c65 100644 (file)
@@ -1184,7 +1184,8 @@ extern void blk_dump_rq_flags(struct request *, char *);
 
 bool __must_check blk_get_queue(struct request_queue *);
 extern void blk_put_queue(struct request_queue *);
-extern void blk_set_queue_dying(struct request_queue *);
+
+void blk_mark_disk_dead(struct gendisk *disk);
 
 #ifdef CONFIG_BLOCK
 /*