virtio vmstatification
cover virtio vmstatification
From: "Dr. David Alan Gilbert" <[email protected]>
Hi,
This contains part of a series I previously posted as an RFC;
it contains just the code to add the vmsd hook to virtio and the simple case for balloon. The networking code will have to wait until my VMSTATE_WITH_TMP macros go in and there's some other stuff I need to figure out for the other devices. However, it seems right to get the hook in for anyone else who wants to do stuff.
Since the RFC I've added an assert to ensure that you can only have either the new vmsd hook or the old ->load/save methods.
Dave
Dr. David Alan Gilbert (2):
virtio/migration: Add VMStateDescription to VirtioDeviceClass virtio/migration: Migrate balloon to VMState
hw/virtio/virtio-balloon.c | 31 +++++++++++++++---------------- hw/virtio/virtio.c | 14 ++++++++++++++ include/hw/virtio/virtio.h | 4 ++++ 3 files changed, 33 insertions(+), 16 deletions(-)
Signature · 1 line
2.9.3
PATCH 1/2 virtio/migration: Add VMStateDescription to VirtioDeviceClass
From: "Dr. David Alan Gilbert" <[email protected]>
Provide a vmsd pointer for VirtIO devices to use instead of the load/save methods.
We'll eventually kill off the load/save methods.
--- hw/virtio/virtio.c | 14 ++++++++++++++ include/hw/virtio/virtio.h | 4 ++++ 2 files changed, 18 insertions(+)
hw/virtio/virtio.c +14 -0
@@ -1635,6 +1635,10 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f) vdc->save (vdev, f); } +if (vdc->vmsd) { +vmstate_save_state (f, vdc->vmsd, vdev,NULL ); + } +/* Subsections */ vmstate_save_state (f, &vmstate_virtio, vdev,NULL ); }
@@ -1781,6 +1785,13 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id) } } +if (vdc->vmsd) { + ret =vmstate_load_state (f, vdc->vmsd, vdev, version_id); +if (ret) { +return ret; + } + } +/* Subsections */ ret =vmstate_load_state (f, &vmstate_virtio, vdev,1 );if (ret) {
@@ -2118,6 +2129,9 @@ static void virtio_device_realize(DeviceState *dev, Error **errp)VirtioDeviceClass *vdc =VIRTIO_DEVICE_GET_CLASS (dev);Error *err =NULL ; +/* Devices should either use vmsd or the load/save methods */ +assert (!vdc->vmsd || !vdc->load); +if (vdc->realize !=NULL ) { vdc->realize (dev, &err);if (err !=NULL ) {
include/hw/virtio/virtio.h +4 -0
@@ -125,8 +125,12 @@ typedef struct VirtioDeviceClass {* must mask in frontend instead. */ void (*guest_notifier_mask)(VirtIODevice *vdev,int n,bool mask); +/* Saving and loading of a device; trying to deprecate save/load +* use vmsd for new devices. +*/ void (*save)(VirtIODevice *vdev,QEMUFile *f);int (*load)(VirtIODevice *vdev,QEMUFile *f,int version_id); +const VMStateDescription *vmsd; } VirtioDeviceClass; void virtio_instance_init_common(Object *proxy_obj, void *data,
Signature · 1 line
2.9.3
Re: [Qemu-devel] [PATCH 1/2] virtio/migration: Add VMStateDescription to VirtioDeviceClass
Quoted 8 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
Provide a vmsd pointer for VirtIO devices to use instead of the load/save methods.
We'll eventually kill off the load/save methods.
Signed-off-by Dr. David Alan Gilbert <[email protected]>
PATCH 2/2 virtio/migration: Migrate balloon to VMState
In reply to Dr. David Alan Gilbert (git)From: "Dr. David Alan Gilbert" <[email protected]>
Replace the load/save with a vmsd.
--- hw/virtio/virtio-balloon.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-)
hw/virtio/virtio-balloon.c +15 -16
@@ -394,21 +394,9 @@ static void virtio_balloon_to_target(void *opaque, ram_addr_t target)trace_virtio_balloon_to_target (target, dev->num_pages); } -static void virtio_balloon_save_device (VirtIODevice *vdev,QEMUFile *f) +static int virtio_balloon_post_load_device (void *opaque,int version_id) { -VirtIOBalloon *s =VIRTIO_BALLOON (vdev); - -qemu_put_be32 (f, s->num_pages); -qemu_put_be32 (f, s->actual); -} - -static int virtio_balloon_load_device (VirtIODevice *vdev,QEMUFile *f, -int version_id) -{ -VirtIOBalloon *s =VIRTIO_BALLOON (vdev); - - s->num_pages =qemu_get_be32 (f); - s->actual =qemu_get_be32 (f); +VirtIOBalloon *s =VIRTIO_BALLOON (opaque);if (balloon_stats_enabled (s)) {balloon_stats_change_timer (s, s->stats_poll_interval);
@@ -416,6 +404,18 @@ static int virtio_balloon_load_device(VirtIODevice *vdev, QEMUFile *f,return 0 ; } +static const VMStateDescription vmstate_virtio_balloon_device = { + .name ="virtio-balloon-device" , + .version_id =1 , + .minimum_version_id =1 , + .post_load = virtio_balloon_post_load_device, + .fields = (VMStateField []) { +VMSTATE_UINT32 (num_pages, VirtIOBalloon), +VMSTATE_UINT32 (actual, VirtIOBalloon), +VMSTATE_END_OF_LIST () + }, +}; +static void virtio_balloon_device_realize (DeviceState *dev,Error **errp) {VirtIODevice *vdev =VIRTIO_DEVICE (dev);
@@ -517,9 +517,8 @@ static void virtio_balloon_class_init(ObjectClass *klass, void *data) vdc->get_config = virtio_balloon_get_config; vdc->set_config = virtio_balloon_set_config; vdc->get_features = virtio_balloon_get_features; - vdc->save = virtio_balloon_save_device; - vdc->load = virtio_balloon_load_device; vdc->set_status = virtio_balloon_set_status; + vdc->vmsd = &vmstate_virtio_balloon_device; }static const TypeInfo virtio_balloon_info = {
Signature · 1 line
2.9.3
Re: [Qemu-devel] [PATCH 2/2] virtio/migration: Migrate balloon to VMState
Quoted 5 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
Replace the load/save with a vmsd.
Signed-off-by Dr. David Alan Gilbert <[email protected]>