diff mbox

[35/41] virtio-balloon: port to vmstate

Message ID a5fa09e2a026b8fc0e3504b24eefb0738cb14b7c.1259754427.git.quintela@redhat.com
State New
Headers show

Commit Message

Juan Quintela Dec. 2, 2009, 12:04 p.m. UTC
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/virtio-balloon.c |   38 +++++++++++++-------------------------
 1 files changed, 13 insertions(+), 25 deletions(-)
diff mbox

Patch

diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index 6f60fb1..f461c32 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -139,30 +139,18 @@  static ram_addr_t virtio_balloon_to_target(void *opaque, ram_addr_t target)
     return ram_size - (dev->actual << VIRTIO_BALLOON_PFN_SHIFT);
 }

-static void virtio_balloon_save(QEMUFile *f, void *opaque)
-{
-    VirtIOBalloon *s = opaque;
-
-    virtio_save(&s->vdev, f);
-
-    qemu_put_be32(f, s->num_pages);
-    qemu_put_be32(f, s->actual);
-}
-
-static int virtio_balloon_load(QEMUFile *f, void *opaque, int version_id)
-{
-    VirtIOBalloon *s = opaque;
-
-    if (version_id != 1)
-        return -EINVAL;
-
-    virtio_load(&s->vdev, f);
-
-    s->num_pages = qemu_get_be32(f);
-    s->actual = qemu_get_be32(f);
-
-    return 0;
-}
+static const VMStateDescription vmstate_virtio_balloon = {
+    .name = "virtio-balloon",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField []) {
+        VMSTATE_VIRTIO(vdev, VirtIOBalloon),
+        VMSTATE_UINT32(num_pages, VirtIOBalloon),
+        VMSTATE_UINT32(actual, VirtIOBalloon),
+        VMSTATE_END_OF_LIST()
+    }
+};

 VirtIODevice *virtio_balloon_init(DeviceState *dev)
 {
@@ -181,7 +169,7 @@  VirtIODevice *virtio_balloon_init(DeviceState *dev)

     qemu_add_balloon_handler(virtio_balloon_to_target, s);

-    register_savevm("virtio-balloon", -1, 1, virtio_balloon_save, virtio_balloon_load, s);
+    vmstate_register(-1, &vmstate_virtio_balloon, s);

     return &s->vdev;
 }