diff mbox

[v2] blockdev: reset werror/rerror on drive_del

Message ID 1370421194-27049-1-git-send-email-stefanha@redhat.com
State New
Headers show

Commit Message

Stefan Hajnoczi June 5, 2013, 8:33 a.m. UTC
Paolo Bonzini <pbonzini@redhat.com> suggested the following test case:

1. Launch a guest and wait at the GRUB boot menu:

  qemu-system-x86_64 -enable-kvm -m 1024 \
   -drive if=none,cache=none,file=test.img,id=foo,werror=stop,rerror=stop
   -device virtio-blk-pci,drive=foo,id=virtio0,addr=4

2. Hot unplug the device:

  (qemu) drive_del foo

3. Select the first boot menu entry

Without this patch the guest pauses due to ENOMEDIUM.  The guest is
stuck in a continuous pause loop since the I/O request is retried and
fails immediately again when the guest is resumed.

With this patch the error is reported to the guest.

Note that this scenario actually happens sometimes during libvirt disk
hot unplug, where device_del is followed by drive_del.  I/O may still be
submitted to the drive after drive_del if the guest does not process the
PCI hot unplug notification.

Reported-by: Dafna Ron <dron@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 blockdev.c      | 4 ++++
 hmp-commands.hx | 2 ++
 2 files changed, 6 insertions(+)

Comments

Kevin Wolf June 5, 2013, 9 a.m. UTC | #1
Am 05.06.2013 um 10:33 hat Stefan Hajnoczi geschrieben:
> Paolo Bonzini <pbonzini@redhat.com> suggested the following test case:
> 
> 1. Launch a guest and wait at the GRUB boot menu:
> 
>   qemu-system-x86_64 -enable-kvm -m 1024 \
>    -drive if=none,cache=none,file=test.img,id=foo,werror=stop,rerror=stop
>    -device virtio-blk-pci,drive=foo,id=virtio0,addr=4
> 
> 2. Hot unplug the device:
> 
>   (qemu) drive_del foo
> 
> 3. Select the first boot menu entry

Can we have a qtest or qemu-iotests version of this manual test case?

> Without this patch the guest pauses due to ENOMEDIUM.  The guest is
> stuck in a continuous pause loop since the I/O request is retried and
> fails immediately again when the guest is resumed.
> 
> With this patch the error is reported to the guest.
> 
> Note that this scenario actually happens sometimes during libvirt disk
> hot unplug, where device_del is followed by drive_del.  I/O may still be
> submitted to the drive after drive_del if the guest does not process the
> PCI hot unplug notification.
> 
> Reported-by: Dafna Ron <dron@redhat.com>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>

Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Stefan Hajnoczi June 5, 2013, 11:27 a.m. UTC | #2
On Wed, Jun 05, 2013 at 11:00:32AM +0200, Kevin Wolf wrote:
> Am 05.06.2013 um 10:33 hat Stefan Hajnoczi geschrieben:
> > Paolo Bonzini <pbonzini@redhat.com> suggested the following test case:
> > 
> > 1. Launch a guest and wait at the GRUB boot menu:
> > 
> >   qemu-system-x86_64 -enable-kvm -m 1024 \
> >    -drive if=none,cache=none,file=test.img,id=foo,werror=stop,rerror=stop
> >    -device virtio-blk-pci,drive=foo,id=virtio0,addr=4
> > 
> > 2. Hot unplug the device:
> > 
> >   (qemu) drive_del foo
> > 
> > 3. Select the first boot menu entry
> 
> Can we have a qtest or qemu-iotests version of this manual test case?

I will try to put something together.

Stefan
Stefan Hajnoczi June 5, 2013, 2:41 p.m. UTC | #3
On Wed, Jun 05, 2013 at 10:33:14AM +0200, Stefan Hajnoczi wrote:
> Paolo Bonzini <pbonzini@redhat.com> suggested the following test case:
> 
> 1. Launch a guest and wait at the GRUB boot menu:
> 
>   qemu-system-x86_64 -enable-kvm -m 1024 \
>    -drive if=none,cache=none,file=test.img,id=foo,werror=stop,rerror=stop
>    -device virtio-blk-pci,drive=foo,id=virtio0,addr=4
> 
> 2. Hot unplug the device:
> 
>   (qemu) drive_del foo
> 
> 3. Select the first boot menu entry
> 
> Without this patch the guest pauses due to ENOMEDIUM.  The guest is
> stuck in a continuous pause loop since the I/O request is retried and
> fails immediately again when the guest is resumed.
> 
> With this patch the error is reported to the guest.
> 
> Note that this scenario actually happens sometimes during libvirt disk
> hot unplug, where device_del is followed by drive_del.  I/O may still be
> submitted to the drive after drive_del if the guest does not process the
> PCI hot unplug notification.
> 
> Reported-by: Dafna Ron <dron@redhat.com>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  blockdev.c      | 4 ++++
>  hmp-commands.hx | 2 ++
>  2 files changed, 6 insertions(+)

Applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan
diff mbox

Patch

diff --git a/blockdev.c b/blockdev.c
index d1ec99a..6eb81a3 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1180,6 +1180,10 @@  int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
      */
     if (bdrv_get_attached_dev(bs)) {
         bdrv_make_anon(bs);
+
+        /* Further I/O must not pause the guest */
+        bdrv_set_on_error(bs, BLOCKDEV_ON_ERROR_REPORT,
+                          BLOCKDEV_ON_ERROR_REPORT);
     } else {
         drive_uninit(drive_get_by_blockdev(bs));
     }
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 9cea415..4f5a3fd 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -185,6 +185,8 @@  Remove host block device.  The result is that guest generated IO is no longer
 submitted against the host device underlying the disk.  Once a drive has
 been deleted, the QEMU Block layer returns -EIO which results in IO
 errors in the guest for applications that are reading/writing to the device.
+These errors are always reported to the guest, regardless of the drive's error
+actions (drive options rerror, werror).
 ETEXI
 
     {