Add virtblk_notify() as virtio_driver's notify() callback. When a transport driver is notified that a device disappeared it should invoke this callback to prevent further request queueing. Subsequent block layer calls of virtio_blk's request function will fail, resulting in appropriate I/O errors. Signed-off-by: Heinz Graalfs <graalfs@xxxxxxxxxxxxxxxxxx> --- drivers/block/virtio_blk.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index 2d43be4..04fd635 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -11,6 +11,7 @@ #include <linux/string_helpers.h> #include <scsi/scsi_cmnd.h> #include <linux/idr.h> +#include <linux/notifier.h> #define PART_BITS 4 @@ -901,6 +902,21 @@ static void virtblk_remove(struct virtio_device *vdev) ida_simple_remove(&vd_index_ida, index); } +static int virtblk_notify(struct virtio_device *vdev, int event) +{ + struct virtio_blk *vblk = vdev->priv; + unsigned long flags; + + if (event == VDEV_GONE) { + spin_lock_irqsave(vblk->disk->queue->queue_lock, flags); + queue_flag_set(QUEUE_FLAG_DYING, vblk->disk->queue); + queue_flag_set(QUEUE_FLAG_NOMERGES, vblk->disk->queue); + queue_flag_set(QUEUE_FLAG_NOXMERGES, vblk->disk->queue); + spin_unlock_irqrestore(vblk->disk->queue->queue_lock, flags); + } + return NOTIFY_DONE; +} + #ifdef CONFIG_PM static int virtblk_freeze(struct virtio_device *vdev) { @@ -961,6 +977,7 @@ static struct virtio_driver virtio_blk = { .probe = virtblk_probe, .remove = virtblk_remove, .config_changed = virtblk_config_changed, + .notify = virtblk_notify, #ifdef CONFIG_PM .freeze = virtblk_freeze, .restore = virtblk_restore, -- 1.8.3.1 _______________________________________________ Virtualization mailing list Virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx https://lists.linuxfoundation.org/mailman/listinfo/virtualization