diff mbox

[11/13] virtio-input: Wrap in vmstate

Message ID 1466536447-30146-12-git-send-email-dgilbert@redhat.com
State New
Headers show

Commit Message

Dr. David Alan Gilbert June 21, 2016, 7:14 p.m. UTC
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

Forcibly convert it to a vmstate wrapper;  proper conversion
comes later.

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 hw/input/virtio-input.c | 26 ++++++--------------------
 1 file changed, 6 insertions(+), 20 deletions(-)

Comments

Gerd Hoffmann June 22, 2016, 6:48 a.m. UTC | #1
On Di, 2016-06-21 at 20:14 +0100, Dr. David Alan Gilbert (git) wrote:
> From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> 
> Forcibly convert it to a vmstate wrapper;  proper conversion
> comes later.

FYI: Should be an easy target for proper conversion as virtio-input
doesn't need to save any device-specific state beside the usual virtio
and pci bits.

cheers,
  Gerd
Dr. David Alan Gilbert June 22, 2016, 9:54 a.m. UTC | #2
* Gerd Hoffmann (kraxel@redhat.com) wrote:
> On Di, 2016-06-21 at 20:14 +0100, Dr. David Alan Gilbert (git) wrote:
> > From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> > 
> > Forcibly convert it to a vmstate wrapper;  proper conversion
> > comes later.
> 
> FYI: Should be an easy target for proper conversion as virtio-input
> doesn't need to save any device-specific state beside the usual virtio
> and pci bits.

Thanks; what would a good test for virtio-input to be to make sure
migration works; got a recommended command line?

Dave

> 
> cheers,
>   Gerd
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
Gerd Hoffmann June 22, 2016, 10:29 a.m. UTC | #3
On Mi, 2016-06-22 at 10:54 +0100, Dr. David Alan Gilbert wrote:
> * Gerd Hoffmann (kraxel@redhat.com) wrote:
> > On Di, 2016-06-21 at 20:14 +0100, Dr. David Alan Gilbert (git) wrote:
> > > From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> > > 
> > > Forcibly convert it to a vmstate wrapper;  proper conversion
> > > comes later.
> > 
> > FYI: Should be an easy target for proper conversion as virtio-input
> > doesn't need to save any device-specific state beside the usual virtio
> > and pci bits.
> 
> Thanks; what would a good test for virtio-input to be to make sure
> migration works; got a recommended command line?

Drop "-device usb-tablet", add "-device virtio-tablet-pci" instead,
mouse input should continue to work just fine (assuming your guest
kernel is new enough).

cheers,
  Gerd
Cornelia Huck June 23, 2016, 8:07 a.m. UTC | #4
On Tue, 21 Jun 2016 20:14:05 +0100
"Dr. David Alan Gilbert (git)" <dgilbert@redhat.com> wrote:

> From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> 
> Forcibly convert it to a vmstate wrapper;  proper conversion
> comes later.
> 
> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> ---
>  hw/input/virtio-input.c | 26 ++++++--------------------
>  1 file changed, 6 insertions(+), 20 deletions(-)

Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
diff mbox

Patch

diff --git a/hw/input/virtio-input.c b/hw/input/virtio-input.c
index f59749a..848090f 100644
--- a/hw/input/virtio-input.c
+++ b/hw/input/virtio-input.c
@@ -216,26 +216,14 @@  static void virtio_input_reset(VirtIODevice *vdev)
     }
 }
 
-static void virtio_input_save(QEMUFile *f, void *opaque)
-{
-    VirtIOInput *vinput = opaque;
-    VirtIODevice *vdev = VIRTIO_DEVICE(vinput);
-
-    virtio_save(vdev, f);
-}
-
-static int virtio_input_load(QEMUFile *f, void *opaque, int version_id)
+static int virtio_input_load(QEMUFile *f, void *opaque, size_t size)
 {
     VirtIOInput *vinput = opaque;
     VirtIOInputClass *vic = VIRTIO_INPUT_GET_CLASS(vinput);
     VirtIODevice *vdev = VIRTIO_DEVICE(vinput);
     int ret;
 
-    if (version_id != VIRTIO_INPUT_VM_VERSION) {
-        return -EINVAL;
-    }
-
-    ret = virtio_load(vdev, f, version_id);
+    ret = virtio_load(vdev, f, VIRTIO_INPUT_VM_VERSION);
     if (ret) {
         return ret;
     }
@@ -279,20 +267,14 @@  static void virtio_input_device_realize(DeviceState *dev, Error **errp)
                 vinput->cfg_size);
     vinput->evt = virtio_add_queue(vdev, 64, virtio_input_handle_evt);
     vinput->sts = virtio_add_queue(vdev, 64, virtio_input_handle_sts);
-
-    register_savevm(dev, "virtio-input", -1, VIRTIO_INPUT_VM_VERSION,
-                    virtio_input_save, virtio_input_load, vinput);
 }
 
 static void virtio_input_device_unrealize(DeviceState *dev, Error **errp)
 {
     VirtIOInputClass *vic = VIRTIO_INPUT_GET_CLASS(dev);
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
-    VirtIOInput *vinput = VIRTIO_INPUT(dev);
     Error *local_err = NULL;
 
-    unregister_savevm(dev, "virtio-input", vinput);
-
     if (vic->unrealize) {
         vic->unrealize(dev, &local_err);
         if (local_err) {
@@ -303,6 +285,9 @@  static void virtio_input_device_unrealize(DeviceState *dev, Error **errp)
     virtio_cleanup(vdev);
 }
 
+VMSTATE_VIRTIO_DEVICE(input, VIRTIO_INPUT_VM_VERSION, virtio_input_load,
+                      virtio_vmstate_save);
+
 static Property virtio_input_properties[] = {
     DEFINE_PROP_STRING("serial", VirtIOInput, serial),
     DEFINE_PROP_END_OF_LIST(),
@@ -314,6 +299,7 @@  static void virtio_input_class_init(ObjectClass *klass, void *data)
     VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
 
     dc->props          = virtio_input_properties;
+    dc->vmsd           = &vmstate_virtio_input;
     set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
     vdc->realize      = virtio_input_device_realize;
     vdc->unrealize    = virtio_input_device_unrealize;