migration: Route more error paths

vmstate_save_state is called in lots of places.
Route error returns from the easier cases back up;  there are lots
of more complex cases where their own error paths need fixing.

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Message-Id: <20170925112917.21340-7-dgilbert@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
  Commit message fix up as Peter's review
This commit is contained in:
Dr. David Alan Gilbert 2017-09-25 12:29:17 +01:00
parent 687433f611
commit 2f168d0708
5 changed files with 23 additions and 16 deletions

View File

@ -1050,9 +1050,7 @@ static int virtio_gpu_save(QEMUFile *f, void *opaque, size_t size,
}
qemu_put_be32(f, 0); /* end of list */
vmstate_save_state(f, &vmstate_virtio_gpu_scanouts, g, NULL);
return 0;
return vmstate_save_state(f, &vmstate_virtio_gpu_scanouts, g, NULL);
}
static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size,

View File

@ -1897,7 +1897,7 @@ static const VMStateDescription vmstate_virtio = {
}
};
void virtio_save(VirtIODevice *vdev, QEMUFile *f)
int virtio_save(VirtIODevice *vdev, QEMUFile *f)
{
BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
@ -1947,20 +1947,21 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
}
if (vdc->vmsd) {
vmstate_save_state(f, vdc->vmsd, vdev, NULL);
int ret = vmstate_save_state(f, vdc->vmsd, vdev, NULL);
if (ret) {
return ret;
}
}
/* Subsections */
vmstate_save_state(f, &vmstate_virtio, vdev, NULL);
return vmstate_save_state(f, &vmstate_virtio, vdev, NULL);
}
/* A wrapper for use as a VMState .put function */
static int virtio_device_put(QEMUFile *f, void *opaque, size_t size,
VMStateField *field, QJSON *vmdesc)
{
virtio_save(VIRTIO_DEVICE(opaque), f);
return 0;
return virtio_save(VIRTIO_DEVICE(opaque), f);
}
/* A wrapper for use as a VMState .get function */

View File

@ -188,7 +188,7 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,
void virtio_notify_irqfd(VirtIODevice *vdev, VirtQueue *vq);
void virtio_notify(VirtIODevice *vdev, VirtQueue *vq);
void virtio_save(VirtIODevice *vdev, QEMUFile *f);
int virtio_save(VirtIODevice *vdev, QEMUFile *f);
extern const VMStateInfo virtio_vmstate_info;

View File

@ -550,13 +550,14 @@ static int put_tmp(QEMUFile *f, void *pv, size_t size, VMStateField *field,
{
const VMStateDescription *vmsd = field->vmsd;
void *tmp = g_malloc(size);
int ret;
/* Writes the parent field which is at the start of the tmp */
*(void **)tmp = pv;
vmstate_save_state(f, vmsd, tmp, vmdesc);
ret = vmstate_save_state(f, vmsd, tmp, vmdesc);
g_free(tmp);
return 0;
return ret;
}
const VMStateInfo vmstate_info_tmp = {
@ -657,12 +658,16 @@ static int put_qtailq(QEMUFile *f, void *pv, size_t unused_size,
/* offset of the QTAILQ entry in a QTAILQ element*/
size_t entry_offset = field->start;
void *elm;
int ret;
trace_put_qtailq(vmsd->name, vmsd->version_id);
QTAILQ_RAW_FOREACH(elm, pv, entry_offset) {
qemu_put_byte(f, true);
vmstate_save_state(f, vmsd, elm, vmdesc);
ret = vmstate_save_state(f, vmsd, elm, vmdesc);
if (ret) {
return ret;
}
}
qemu_put_byte(f, false);

View File

@ -70,7 +70,8 @@ static void save_vmstate(const VMStateDescription *desc, void *obj)
QEMUFile *f = open_test_file(true);
/* Save file with vmstate */
vmstate_save_state(f, desc, obj, NULL);
int ret = vmstate_save_state(f, desc, obj, NULL);
g_assert(!ret);
qemu_put_byte(f, QEMU_VM_EOF);
g_assert(!qemu_file_get_error(f));
qemu_fclose(f);
@ -381,7 +382,8 @@ static void test_save_noskip(void)
QEMUFile *fsave = open_test_file(true);
TestStruct obj = { .a = 1, .b = 2, .c = 3, .d = 4, .e = 5, .f = 6,
.skip_c_e = false };
vmstate_save_state(fsave, &vmstate_skipping, &obj, NULL);
int ret = vmstate_save_state(fsave, &vmstate_skipping, &obj, NULL);
g_assert(!ret);
g_assert(!qemu_file_get_error(fsave));
uint8_t expected[] = {
@ -402,7 +404,8 @@ static void test_save_skip(void)
QEMUFile *fsave = open_test_file(true);
TestStruct obj = { .a = 1, .b = 2, .c = 3, .d = 4, .e = 5, .f = 6,
.skip_c_e = true };
vmstate_save_state(fsave, &vmstate_skipping, &obj, NULL);
int ret = vmstate_save_state(fsave, &vmstate_skipping, &obj, NULL);
g_assert(!ret);
g_assert(!qemu_file_get_error(fsave));
uint8_t expected[] = {