Skip to content

Commit

Permalink
virtio: introduce device specific migration calls
Browse files Browse the repository at this point in the history
In order to migrate virtio subsections, they should be streamed after
the device itself. We need the device specific code to be called from
the common migration code to achieve this. This patch introduces load
and save methods for this purpose.

Suggested-by: Andreas Färber <afaerber@suse.de>
Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
Reviewed-by: Alexander Graf <agraf@suse.de>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
  • Loading branch information
gkurz authored and mstsirkin committed Jun 29, 2014
1 parent e38e943 commit 1b5fc0d
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion hw/block/virtio-blk.c
Expand Up @@ -635,7 +635,7 @@ static int virtio_blk_load(QEMUFile *f, void *opaque, int version_id)
if (version_id != 2)
return -EINVAL;

ret = virtio_load(vdev, f);
ret = virtio_load(vdev, f, version_id);
if (ret) {
return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion hw/char/virtio-serial-bus.c
Expand Up @@ -670,7 +670,7 @@ static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id)
}

/* The virtio device */
ret = virtio_load(VIRTIO_DEVICE(s), f);
ret = virtio_load(VIRTIO_DEVICE(s), f, version_id);
if (ret) {
return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion hw/net/virtio-net.c
Expand Up @@ -1362,7 +1362,7 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
if (version_id < 2 || version_id > VIRTIO_NET_VM_VERSION)
return -EINVAL;

ret = virtio_load(vdev, f);
ret = virtio_load(vdev, f, version_id);
if (ret) {
return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion hw/scsi/virtio-scsi.c
Expand Up @@ -549,7 +549,7 @@ static int virtio_scsi_load(QEMUFile *f, void *opaque, int version_id)
VirtIODevice *vdev = VIRTIO_DEVICE(opaque);
int ret;

ret = virtio_load(vdev, f);
ret = virtio_load(vdev, f, version_id);
if (ret) {
return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion hw/virtio/virtio-balloon.c
Expand Up @@ -343,7 +343,7 @@ static int virtio_balloon_load(QEMUFile *f, void *opaque, int version_id)
if (version_id != 1)
return -EINVAL;

ret = virtio_load(vdev, f);
ret = virtio_load(vdev, f, version_id);
if (ret) {
return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion hw/virtio/virtio-rng.c
Expand Up @@ -113,7 +113,7 @@ static int virtio_rng_load(QEMUFile *f, void *opaque, int version_id)
if (version_id != 1) {
return -EINVAL;
}
virtio_load(vdev, f);
virtio_load(vdev, f, version_id);

/* We may have an element ready but couldn't process it due to a quota
* limit. Make sure to try again after live migration when the quota may
Expand Down
13 changes: 12 additions & 1 deletion hw/virtio/virtio.c
Expand Up @@ -843,6 +843,7 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
{
BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
int i;

if (k->save_config) {
Expand Down Expand Up @@ -877,6 +878,10 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
k->save_queue(qbus->parent, i, f);
}
}

if (vdc->save != NULL) {
vdc->save(vdev, f);
}
}

int virtio_set_features(VirtIODevice *vdev, uint32_t val)
Expand All @@ -895,7 +900,7 @@ int virtio_set_features(VirtIODevice *vdev, uint32_t val)
return bad ? -1 : 0;
}

int virtio_load(VirtIODevice *vdev, QEMUFile *f)
int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
{
int i, ret;
int32_t config_len;
Expand All @@ -904,6 +909,7 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
uint32_t supported_features;
BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);

if (k->load_config) {
ret = k->load_config(qbus->parent, f);
Expand Down Expand Up @@ -983,6 +989,11 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
}

virtio_notify_vector(vdev, VIRTIO_NO_VECTOR);

if (vdc->load != NULL) {
return vdc->load(vdev, f, version_id);
}

return 0;
}

Expand Down
4 changes: 3 additions & 1 deletion include/hw/virtio/virtio.h
Expand Up @@ -150,6 +150,8 @@ typedef struct VirtioDeviceClass {
* must mask in frontend instead.
*/
void (*guest_notifier_mask)(VirtIODevice *vdev, int n, bool mask);
void (*save)(VirtIODevice *vdev, QEMUFile *f);
int (*load)(VirtIODevice *vdev, QEMUFile *f, int version_id);
} VirtioDeviceClass;

void virtio_init(VirtIODevice *vdev, const char *name,
Expand Down Expand Up @@ -184,7 +186,7 @@ void virtio_notify(VirtIODevice *vdev, VirtQueue *vq);

void virtio_save(VirtIODevice *vdev, QEMUFile *f);

int virtio_load(VirtIODevice *vdev, QEMUFile *f);
int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id);

void virtio_notify_config(VirtIODevice *vdev);

Expand Down

0 comments on commit 1b5fc0d

Please sign in to comment.