diff options
author | Michael S. Tsirkin <mst@redhat.com> | 2011-01-10 14:28:40 +0200 |
---|---|---|
committer | Michael S. Tsirkin <mst@redhat.com> | 2011-01-10 14:44:07 +0200 |
commit | 85cf2a8d7435754f685a26f95dcb43a93a84ff60 (patch) | |
tree | 2924eccb9ec1ac1e450e36316515b4f1bb353c3d /hw/virtio.c | |
parent | 3dbca8e6a7a5be52c3251ad03bf30d73301babf3 (diff) |
virtio: move vmstate change tracking to core
Move tracking vmstate change from virtio-net to virtio.c
as it is going to be used by virito-blk and virtio-pci
for the ioeventfd support.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'hw/virtio.c')
-rw-r--r-- | hw/virtio.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/hw/virtio.c b/hw/virtio.c index 07dbf868fd..1d20be2ca3 100644 --- a/hw/virtio.c +++ b/hw/virtio.c @@ -743,11 +743,31 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f) void virtio_cleanup(VirtIODevice *vdev) { + qemu_del_vm_change_state_handler(vdev->vmstate); if (vdev->config) qemu_free(vdev->config); qemu_free(vdev->vq); } +static void virtio_vmstate_change(void *opaque, int running, int reason) +{ + VirtIODevice *vdev = opaque; + bool backend_run = running && (vdev->status & VIRTIO_CONFIG_S_DRIVER_OK); + vdev->vm_running = running; + + if (backend_run) { + virtio_set_status(vdev, vdev->status); + } + + if (vdev->binding->vmstate_change) { + vdev->binding->vmstate_change(vdev->binding_opaque, backend_run); + } + + if (!backend_run) { + virtio_set_status(vdev, vdev->status); + } +} + VirtIODevice *virtio_common_init(const char *name, uint16_t device_id, size_t config_size, size_t struct_size) { @@ -774,6 +794,8 @@ VirtIODevice *virtio_common_init(const char *name, uint16_t device_id, else vdev->config = NULL; + vdev->vmstate = qemu_add_vm_change_state_handler(virtio_vmstate_change, vdev); + return vdev; } |