From patchwork Tue Sep 19 18:00:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dr. David Alan Gilbert" X-Patchwork-Id: 815766 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xxW5Q6JV6z9s7c for ; Wed, 20 Sep 2017 04:06:02 +1000 (AEST) Received: from localhost ([::1]:44667 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duMuG-0001GB-U5 for incoming@patchwork.ozlabs.org; Tue, 19 Sep 2017 14:06:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37018) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duMpS-0005vw-TG for qemu-devel@nongnu.org; Tue, 19 Sep 2017 14:01:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1duMpR-0000C4-LX for qemu-devel@nongnu.org; Tue, 19 Sep 2017 14:01:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54736) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1duMpR-00009Y-Cl for qemu-devel@nongnu.org; Tue, 19 Sep 2017 14:01:01 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5C74C7E431; Tue, 19 Sep 2017 18:01:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5C74C7E431 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=dgilbert@redhat.com Received: from dgilbert-t530.redhat.com (ovpn-117-120.ams2.redhat.com [10.36.117.120]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0CDB45D97C; Tue, 19 Sep 2017 18:00:58 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, quintela@redhat.com, peterx@redhat.com Date: Tue, 19 Sep 2017 19:00:38 +0100 Message-Id: <20170919180038.26056-6-dgilbert@redhat.com> In-Reply-To: <20170919180038.26056-1-dgilbert@redhat.com> References: <20170919180038.26056-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 19 Sep 2017 18:01:00 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 5/5] migration: Route more error paths X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, cohuck@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: "Dr. David Alan Gilbert" vmstate_save is called in a few places, and 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 there own error paths need fixing. Signed-off-by: Dr. David Alan Gilbert --- hw/display/virtio-gpu.c | 4 +--- hw/virtio/virtio.c | 13 +++++++------ include/hw/virtio/virtio.h | 2 +- migration/vmstate-types.c | 11 ++++++++--- tests/test-vmstate.c | 6 +++--- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 622ee300f9..c9494e8a79 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -996,9 +996,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, diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 464947f76d..860333788b 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -1899,7 +1899,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); @@ -1949,20 +1949,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 */ diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 80c45c321e..5abada6966 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -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; diff --git a/migration/vmstate-types.c b/migration/vmstate-types.c index c056c98bdb..48184c380d 100644 --- a/migration/vmstate-types.c +++ b/migration/vmstate-types.c @@ -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); diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c index e643ac662b..ab3e430c2c 100644 --- a/tests/test-vmstate.c +++ b/tests/test-vmstate.c @@ -70,7 +70,7 @@ 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); + g_assert(!vmstate_save_state(f, desc, obj, NULL)); qemu_put_byte(f, QEMU_VM_EOF); g_assert(!qemu_file_get_error(f)); qemu_fclose(f); @@ -381,7 +381,7 @@ 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); + g_assert(!vmstate_save_state(fsave, &vmstate_skipping, &obj, NULL)); g_assert(!qemu_file_get_error(fsave)); uint8_t expected[] = { @@ -402,7 +402,7 @@ 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); + g_assert(!vmstate_save_state(fsave, &vmstate_skipping, &obj, NULL)); g_assert(!qemu_file_get_error(fsave)); uint8_t expected[] = {