Patchwork virtio-blk: Create exit function to unregister savevm

login
register
mail settings
Submitter Alex Williamson
Date July 20, 2010, 5:14 p.m.
Message ID <20100720171422.9288.21469.stgit@localhost6.localdomain6>
Download mbox | patch
Permalink /patch/59348/
State New
Headers show

Comments

Alex Williamson - July 20, 2010, 5:14 p.m.
Otherwise we can't migrate after we've removed a virtio block device.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---

 hw/virtio-blk.c |    8 ++++++++
 hw/virtio-pci.c |    1 +
 hw/virtio.h     |    1 +
 3 files changed, 10 insertions(+), 0 deletions(-)
Kevin Wolf - July 21, 2010, 2:06 p.m.
Am 20.07.2010 19:14, schrieb Alex Williamson:
> Otherwise we can't migrate after we've removed a virtio block device.
> 
> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Thanks, applied to the block branch.

Kevin

Patch

diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index f50069d..490cd41 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -28,6 +28,7 @@  typedef struct VirtIOBlock
     BlockConf *conf;
     unsigned short sector_mask;
     char sn[BLOCK_SERIAL_STRLEN];
+    DeviceState *qdev;
 } VirtIOBlock;
 
 static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev)
@@ -522,9 +523,16 @@  VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf)
     s->vq = virtio_add_queue(&s->vdev, 128, virtio_blk_handle_output);
 
     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);
     bdrv_set_removable(s->bs, 0);
 
     return &s->vdev;
 }
+
+void virtio_blk_exit(VirtIODevice *vdev)
+{
+    VirtIOBlock *s = to_virtio_blk(vdev);
+    unregister_savevm(s->qdev, "virtio-blk", s);
+}
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 31a711e..17c3d15 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -569,6 +569,7 @@  static int virtio_blk_exit_pci(PCIDevice *pci_dev)
 {
     VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
 
+    virtio_blk_exit(proxy->vdev);
     blockdev_mark_auto_del(proxy->block.bs);
     return virtio_exit_pci(pci_dev);
 }
diff --git a/hw/virtio.h b/hw/virtio.h
index e4306cd..30e472a 100644
--- a/hw/virtio.h
+++ b/hw/virtio.h
@@ -194,6 +194,7 @@  VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf);
 
 
 void virtio_net_exit(VirtIODevice *vdev);
+void virtio_blk_exit(VirtIODevice *vdev);
 
 #define DEFINE_VIRTIO_COMMON_FEATURES(_state, _field) \
 	DEFINE_PROP_BIT("indirect_desc", _state, _field, \