Patchwork [1/1] virtio-blk: fix unplug + virsh reboot

login
register
mail settings
Submitter Christian Borntraeger
Date Feb. 22, 2013, 1:37 p.m.
Message ID <1361540230-2194-1-git-send-email-borntraeger@de.ibm.com>
Download mbox | patch
Permalink /patch/222535/
State New
Headers show

Comments

Christian Borntraeger - Feb. 22, 2013, 1:37 p.m.
virtio-blk registers a vmstate change handler. Unfortunately this
handler is not unregistered on unplug, leading to some random
crashes if the system is restarted, e.g. via virsh reboot.
Lets unregister the vmstate change handler if the device is removed.

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 hw/virtio-blk.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Stefan Hajnoczi - Feb. 25, 2013, 3:10 p.m.
On Fri, Feb 22, 2013 at 02:37:10PM +0100, Christian Borntraeger wrote:
> virtio-blk registers a vmstate change handler. Unfortunately this
> handler is not unregistered on unplug, leading to some random
> crashes if the system is restarted, e.g. via virsh reboot.
> Lets unregister the vmstate change handler if the device is removed.
> 
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> ---
>  hw/virtio-blk.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan

Patch

diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index cd25712..ec7c9bd 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -36,6 +36,7 @@  typedef struct VirtIOBlock
     VirtIOBlkConf *blk;
     unsigned short sector_mask;
     DeviceState *qdev;
+    VMChangeStateEntry *change;
 #ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
     VirtIOBlockDataPlane *dataplane;
 #endif
@@ -682,7 +683,7 @@  VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
     }
 #endif
 
-    qemu_add_vm_change_state_handler(virtio_blk_dma_restart_cb, s);
+    s->change = qemu_add_vm_change_state_handler(virtio_blk_dma_restart_cb, s);
     s->qdev = dev;
     register_savevm(dev, "virtio-blk", virtio_blk_id++, 2,
                     virtio_blk_save, virtio_blk_load, s);
@@ -703,6 +704,7 @@  void virtio_blk_exit(VirtIODevice *vdev)
     virtio_blk_data_plane_destroy(s->dataplane);
     s->dataplane = NULL;
 #endif
+    qemu_del_vm_change_state_handler(s->change);
     unregister_savevm(s->qdev, "virtio-blk", s);
     blockdev_mark_auto_del(s->bs);
     virtio_cleanup(vdev);