From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E1958C83F1B for ; Wed, 16 Jul 2025 10:46:51 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubzdu-0000co-1i; Wed, 16 Jul 2025 06:45:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubzc0-00060y-99 for qemu-devel@nongnu.org; Wed, 16 Jul 2025 06:43:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubzbx-0000C7-II for qemu-devel@nongnu.org; Wed, 16 Jul 2025 06:43:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752662620; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J6SwAb1zJUchu11WQU3NyVT6lLA1w3lzPtkclnpi3MY=; b=UAiPq7a2JxSCNQFSN3adeTunBV6+muUz3YbawOJhlzmCc5vrg9kRRRl+ZMN/tC2PC8BPYJ wJduvAr3wAquupnUD18QEFuUJDaSQ5LhWEU7+jOv+XtbTaBlQKZqlFq8bk3B1aULKGNOrC 7FQ0NSNOlz6+Z+OmgcivXa2FEPI2Gf8= Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-612-aUDkz484PVqKdUN3XiVXRQ-1; Wed, 16 Jul 2025 06:43:39 -0400 X-MC-Unique: aUDkz484PVqKdUN3XiVXRQ-1 X-Mimecast-MFC-AGG-ID: aUDkz484PVqKdUN3XiVXRQ_1752662619 Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-235e1d66fa6so59939785ad.0 for ; Wed, 16 Jul 2025 03:43:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752662619; x=1753267419; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=J6SwAb1zJUchu11WQU3NyVT6lLA1w3lzPtkclnpi3MY=; b=eqLT89+3ADrKWduadT7Q5Yf1Y72ItMehXP8zO/9VSdRq3/tz9DUYZBpa2I7McNmc1j It3e2mKz4guY3rYQuv5BWFofErfna+JN9x0fjAGWuTVJ0jsGQ5R7O6wBItgU/iQabvyt dSkcs8CFb1t5rlq+dnmc7Dv9PZZ8I0O5Yjb2v0hjzDJ4GSkOiz7jnGj391oAy7dtbc/G 4B8hMkAFlcc3YQ+9DyE3lDPwquN/OyfXYarLjNn0l/5v7LloOl3Q8wGxczD3Y1nsw9tG atxoskDV3ckWrcAI0KLx5r2MUvOyXL2d+1TfCYUmc4gRt+155eRHRKaCgBpYhMNLcJjm zvtw== X-Gm-Message-State: AOJu0YxztZ/25e79jfxrgjXLj8yMOu3m9pia2Kq8W/3Urdh7BZZC74qS BbgSoJtVQOfKlh/K0lEv2KU7zdfFKAA46bFY5bGl4YG2yCNLjmCbwcUuwXxJ7KM6vk5UjJlaG7F DQWzqaKZadxQe+m+RWvz1l7jD0F4q9/wbRtb1ybn2sgHRzW1NTNAAOgZY X-Gm-Gg: ASbGnctkP2Xz2hp2gtlg/jNkKArntxdRBYGgj1jP3N+BU7P6w+xQtkqYw5RklCz4gQ8 DXeTq9rUHYjSooLyq3H6Jr8OeaE2NfmWRhNvV9sjmsDbEOdvrtKfIOP0KLbyKjMSI2z+bre1ib/ FXAkmUtMXKKt0fKxUOh8jCHFgs6AeOJ+q2JdiTUwXEW4yr/8Q/u5ZAE9joD8r8UweMH/B+92Y44 oklHavOsrNqHNiNP5oVAkT5/6kostUSUTv5Qm+qDK7Q7HmlRC5T6yHQOI7ogw0iEDGqKidX4WuV iI8TkjOFIJi9JtBW4hSLdWusjdUvDq0t4REaUq/QyzoLRHww8A== X-Received: by 2002:a17:902:da82:b0:231:d0a8:5179 with SMTP id d9443c01a7336-23e24f563f7mr40138865ad.23.1752662618368; Wed, 16 Jul 2025 03:43:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGE/BbTjUhhtAfmL75/cnp+xhARc89Dlldp405dqCHuqwfgkoieYukUpqkwLnoCnKIZrJu7GQ== X-Received: by 2002:a17:902:da82:b0:231:d0a8:5179 with SMTP id d9443c01a7336-23e24f563f7mr40138395ad.23.1752662617698; Wed, 16 Jul 2025 03:43:37 -0700 (PDT) Received: from armenon-kvm.bengluru.csb ([49.36.97.1]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-23de435baccsm123363265ad.227.2025.07.16.03.43.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Jul 2025 03:43:37 -0700 (PDT) From: Arun Menon Date: Wed, 16 Jul 2025 16:12:52 +0530 Subject: [PATCH v4 02/23] migration: push Error **errp into vmstate_load_state() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20250716-propagate_tpm_error-v4-2-7141902077c0@redhat.com> References: <20250716-propagate_tpm_error-v4-0-7141902077c0@redhat.com> In-Reply-To: <20250716-propagate_tpm_error-v4-0-7141902077c0@redhat.com> To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Marcel Apfelbaum , Cornelia Huck , Halil Pasic , Eric Farman , Richard Henderson , David Hildenbrand , Ilya Leoshkevich , Thomas Huth , Christian Borntraeger , Paolo Bonzini , Fam Zheng , Nicholas Piggin , Daniel Henrique Barboza , Harsh Prateek Bora , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Peter Xu , Fabiano Rosas , Hailiang Zhang , Steve Sistare , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Stefan Berger , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , Matthew Rosato , Arun Menon X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=19978; i=armenon@redhat.com; h=from:subject:message-id; bh=e6TH4vyyZWj7nA7MqR7/OvL6eEEYeRsSa4AqsRKwvYc=; b=owGbwMvMwCWWVaVqcZPfqI/xtFoSQ0Z5k53EBz3t4NO7lW5rb/2w9nSwxCqdn4ZpRkw7r2YnV OeZPmzuKGVhEONikBVTZGn4GiDbFFAYEWn78jrMHFYmkCEMXJwCMJFLqgx/uPRebfdkqxV+xs5j obSk4v0yH5WZpwNFNMKvPf72Lc4tkeEXc1Ska66b+N/ZzqeX7FtQoRP4dPn7VfeZornuinXla29 iBwA= X-Developer-Key: i=armenon@redhat.com; a=openpgp; fpr=80F5501D82507158593DE9D76A7A2538D90F328E Received-SPF: pass client-ip=170.10.133.124; envelope-from=armenon@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor. It is ensured that vmstate_load_state() must report an error in errp, in case of failure. Signed-off-by: Arun Menon --- hw/display/virtio-gpu.c | 2 +- hw/pci/pci.c | 2 +- hw/s390x/virtio-ccw.c | 2 +- hw/scsi/spapr_vscsi.c | 2 +- hw/vfio/pci.c | 2 +- hw/virtio/virtio-mmio.c | 2 +- hw/virtio/virtio-pci.c | 2 +- hw/virtio/virtio.c | 4 ++-- include/migration/vmstate.h | 2 +- migration/cpr.c | 4 ++-- migration/savevm.c | 6 ++++-- migration/vmstate-types.c | 10 +++++----- migration/vmstate.c | 43 +++++++++++++++++++++++++++---------------- tests/unit/test-vmstate.c | 18 +++++++++--------- ui/vdagent.c | 2 +- 15 files changed, 58 insertions(+), 45 deletions(-) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 0a1a625b0ea6cf26cb0d799171a57ed3d3ab2442..5d2ca8d8b864350133a674802d7316abd379591c 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -1343,7 +1343,7 @@ static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size, } /* load & apply scanout state */ - vmstate_load_state(f, &vmstate_virtio_gpu_scanouts, g, 1); + vmstate_load_state(f, &vmstate_virtio_gpu_scanouts, g, 1, NULL); return 0; } diff --git a/hw/pci/pci.c b/hw/pci/pci.c index c70b5ceebaf1f2b10768bd030526cbb518da2b8d..2ab5d30bb3c319ac1c7bfc9a2acf6a2b38082066 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -934,7 +934,7 @@ void pci_device_save(PCIDevice *s, QEMUFile *f) int pci_device_load(PCIDevice *s, QEMUFile *f) { int ret; - ret = vmstate_load_state(f, &vmstate_pci_device, s, s->version_id); + ret = vmstate_load_state(f, &vmstate_pci_device, s, s->version_id, NULL); /* Restore the interrupt status bit. */ pci_update_irq_status(s); return ret; diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c index d2f85b39f30f7fc82e0c600144c0a958e1269b2c..2f6feff2b0a22d7d7f6aecfd7e7870d8362f1a73 100644 --- a/hw/s390x/virtio-ccw.c +++ b/hw/s390x/virtio-ccw.c @@ -1136,7 +1136,7 @@ static void virtio_ccw_save_config(DeviceState *d, QEMUFile *f) static int virtio_ccw_load_config(DeviceState *d, QEMUFile *f) { VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d); - return vmstate_load_state(f, &vmstate_virtio_ccw_dev, dev, 1); + return vmstate_load_state(f, &vmstate_virtio_ccw_dev, dev, 1, NULL); } static void virtio_ccw_pre_plugged(DeviceState *d, Error **errp) diff --git a/hw/scsi/spapr_vscsi.c b/hw/scsi/spapr_vscsi.c index 20f70fb2729de78b9636a6b8c869695dab4f8902..573fdea668536b464bca11f001e9e0288e781493 100644 --- a/hw/scsi/spapr_vscsi.c +++ b/hw/scsi/spapr_vscsi.c @@ -648,7 +648,7 @@ static void *vscsi_load_request(QEMUFile *f, SCSIRequest *sreq) assert(!req->active); memset(req, 0, sizeof(*req)); - rc = vmstate_load_state(f, &vmstate_spapr_vscsi_req, req, 1); + rc = vmstate_load_state(f, &vmstate_spapr_vscsi_req, req, 1, NULL); if (rc) { fprintf(stderr, "VSCSI: failed loading request tag#%u\n", sreq->tag); return NULL; diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 1093b28df7c3f5f37e622e6d76a99ad8d2b7e01e..616b9563a39ab7773dce403e36f2854c93b66dd9 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2797,7 +2797,7 @@ static int vfio_pci_load_config(VFIODevice *vbasedev, QEMUFile *f) old_addr[bar] = pdev->io_regions[bar].addr; } - ret = vmstate_load_state(f, &vmstate_vfio_pci_config, vdev, 1); + ret = vmstate_load_state(f, &vmstate_vfio_pci_config, vdev, 1, NULL); if (ret) { return ret; } diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c index 532c67107ba1d2978a76cf49f9cdc1de1dea3e11..9058b1563462d4464dcba799643a583c93fb5683 100644 --- a/hw/virtio/virtio-mmio.c +++ b/hw/virtio/virtio-mmio.c @@ -619,7 +619,7 @@ static int virtio_mmio_load_extra_state(DeviceState *opaque, QEMUFile *f) { VirtIOMMIOProxy *proxy = VIRTIO_MMIO(opaque); - return vmstate_load_state(f, &vmstate_virtio_mmio, proxy, 1); + return vmstate_load_state(f, &vmstate_virtio_mmio, proxy, 1, NULL); } static bool virtio_mmio_has_extra_state(DeviceState *opaque) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index fba2372c93bfd648736b07e4bc83e7097baa58cb..50a1f5701754b88e8a1ee062d6eeedfd848cb4f5 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -160,7 +160,7 @@ static int virtio_pci_load_extra_state(DeviceState *d, QEMUFile *f) { VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); - return vmstate_load_state(f, &vmstate_virtio_pci, proxy, 1); + return vmstate_load_state(f, &vmstate_virtio_pci, proxy, 1, NULL); } static void virtio_pci_save_queue(DeviceState *d, int n, QEMUFile *f) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 82a285a31d1c0427d55f7cb73398adfc94e678fe..66d5941f68a4b9e1e5390bb0aa45fc6cd34e2a1e 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3317,14 +3317,14 @@ virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id) } if (vdc->vmsd) { - ret = vmstate_load_state(f, vdc->vmsd, vdev, version_id); + ret = vmstate_load_state(f, vdc->vmsd, vdev, version_id, NULL); if (ret) { return ret; } } /* Subsections */ - ret = vmstate_load_state(f, &vmstate_virtio, vdev, 1); + ret = vmstate_load_state(f, &vmstate_virtio, vdev, 1, NULL); if (ret) { return ret; } diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 1ff7bd9ac425ba67cd5ca7ad97bcf570f9e19abe..056781b1c21e737583f081594d9f88b32adfd674 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -1196,7 +1196,7 @@ extern const VMStateInfo vmstate_info_qlist; } int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, - void *opaque, int version_id); + void *opaque, int version_id, Error **errp); int vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, void *opaque, JSONWriter *vmdesc); int vmstate_save_state_with_err(QEMUFile *f, const VMStateDescription *vmsd, diff --git a/migration/cpr.c b/migration/cpr.c index 42ad0b0d500e5de57faf0c6517e216b2d1c0cacf..74fac9521717ec568d14dabcbcb574b19fc1da67 100644 --- a/migration/cpr.c +++ b/migration/cpr.c @@ -233,9 +233,9 @@ int cpr_state_load(MigrationChannel *channel, Error **errp) return -ENOTSUP; } - ret = vmstate_load_state(f, &vmstate_cpr_state, &cpr_state, 1); + ret = vmstate_load_state(f, &vmstate_cpr_state, &cpr_state, 1, errp); if (ret) { - error_setg(errp, "vmstate_load_state error %d", ret); + error_prepend(errp, "vmstate_load_state error %d ", ret); qemu_fclose(f); return ret; } diff --git a/migration/savevm.c b/migration/savevm.c index fabbeb296ae987d0c06ba6dafda63720205fecfd..ab947620f724874f325fb9fb59bef50b7c16fb51 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -969,7 +969,8 @@ static int vmstate_load(QEMUFile *f, SaveStateEntry *se) if (!se->vmsd) { /* Old style */ return se->ops->load_state(f, se->opaque, se->load_version_id); } - return vmstate_load_state(f, se->vmsd, se->opaque, se->load_version_id); + return vmstate_load_state(f, se->vmsd, se->opaque, se->load_version_id, + NULL); } static void vmstate_save_old_style(QEMUFile *f, SaveStateEntry *se, @@ -2839,7 +2840,8 @@ static int qemu_loadvm_state_header(QEMUFile *f) error_report("Configuration section missing"); return -EINVAL; } - ret = vmstate_load_state(f, &vmstate_configuration, &savevm_state, 0); + ret = vmstate_load_state(f, &vmstate_configuration, &savevm_state, 0, + NULL); if (ret) { return ret; diff --git a/migration/vmstate-types.c b/migration/vmstate-types.c index 741a588b7e18c6d37724b08a0101edc8bc74a0a5..1c5b76e1dd198030847971bc35637867c9d54fc0 100644 --- a/migration/vmstate-types.c +++ b/migration/vmstate-types.c @@ -549,7 +549,7 @@ static int get_tmp(QEMUFile *f, void *pv, size_t size, /* Writes the parent field which is at the start of the tmp */ *(void **)tmp = pv; - ret = vmstate_load_state(f, vmsd, tmp, version_id); + ret = vmstate_load_state(f, vmsd, tmp, version_id, NULL); g_free(tmp); return ret; } @@ -649,7 +649,7 @@ static int get_qtailq(QEMUFile *f, void *pv, size_t unused_size, while (qemu_get_byte(f)) { elm = g_malloc(size); - ret = vmstate_load_state(f, vmsd, elm, version_id); + ret = vmstate_load_state(f, vmsd, elm, version_id, NULL); if (ret) { return ret; } @@ -803,7 +803,7 @@ static int get_gtree(QEMUFile *f, void *pv, size_t unused_size, key = (void *)(uintptr_t)qemu_get_be64(f); } else { key = g_malloc0(key_size); - ret = vmstate_load_state(f, key_vmsd, key, version_id); + ret = vmstate_load_state(f, key_vmsd, key, version_id, NULL); if (ret) { error_report("%s : failed to load %s (%d)", field->name, key_vmsd->name, ret); @@ -811,7 +811,7 @@ static int get_gtree(QEMUFile *f, void *pv, size_t unused_size, } } val = g_malloc0(val_size); - ret = vmstate_load_state(f, val_vmsd, val, version_id); + ret = vmstate_load_state(f, val_vmsd, val, version_id, NULL); if (ret) { error_report("%s : failed to load %s (%d)", field->name, val_vmsd->name, ret); @@ -892,7 +892,7 @@ static int get_qlist(QEMUFile *f, void *pv, size_t unused_size, while (qemu_get_byte(f)) { elm = g_malloc(size); - ret = vmstate_load_state(f, vmsd, elm, version_id); + ret = vmstate_load_state(f, vmsd, elm, version_id, NULL); if (ret) { error_report("%s: failed to load %s (%d)", field->name, vmsd->name, ret); diff --git a/migration/vmstate.c b/migration/vmstate.c index 526668a020562f303d2ddf030b1c8466659b67be..078a00003023cc248fb16f05017d4c4251fd86df 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -132,29 +132,30 @@ static void vmstate_handle_alloc(void *ptr, const VMStateField *field, } int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, - void *opaque, int version_id) + void *opaque, int version_id, Error **errp) { const VMStateField *field = vmsd->fields; int ret = 0; trace_vmstate_load_state(vmsd->name, version_id); if (version_id > vmsd->version_id) { - error_report("%s: incoming version_id %d is too new " - "for local version_id %d", - vmsd->name, version_id, vmsd->version_id); + error_setg(errp, "%s: incoming version_id %d is too new " + "for local version_id %d", + vmsd->name, version_id, vmsd->version_id); trace_vmstate_load_state_end(vmsd->name, "too new", -EINVAL); return -EINVAL; } if (version_id < vmsd->minimum_version_id) { - error_report("%s: incoming version_id %d is too old " - "for local minimum version_id %d", - vmsd->name, version_id, vmsd->minimum_version_id); + error_setg(errp, "%s: incoming version_id %d is too old " + "for local minimum version_id %d", + vmsd->name, version_id, vmsd->minimum_version_id); trace_vmstate_load_state_end(vmsd->name, "too old", -EINVAL); return -EINVAL; } if (vmsd->pre_load) { ret = vmsd->pre_load(opaque); if (ret) { + error_setg(errp, "VM pre load failed : %d", ret); return ret; } } @@ -192,10 +193,12 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, if (inner_field->flags & VMS_STRUCT) { ret = vmstate_load_state(f, inner_field->vmsd, curr_elem, - inner_field->vmsd->version_id); + inner_field->vmsd->version_id, + errp); } else if (inner_field->flags & VMS_VSTRUCT) { ret = vmstate_load_state(f, inner_field->vmsd, curr_elem, - inner_field->struct_version_id); + inner_field->struct_version_id, + errp); } else { ret = inner_field->info->get(f, curr_elem, size, inner_field); @@ -211,27 +214,35 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, } if (ret < 0) { qemu_file_set_error(f, ret); - error_report("Failed to load %s:%s", vmsd->name, - field->name); + if (errp != NULL) { + error_prepend(errp, "Failed to load %s:%s ", vmsd->name, + field->name); + } else { + error_setg(errp, "Failed to load %s:%s", vmsd->name, + field->name); + } trace_vmstate_load_field_error(field->name, ret); return ret; } } } else if (field->flags & VMS_MUST_EXIST) { - error_report("Input validation failed: %s/%s", - vmsd->name, field->name); + error_setg(errp, "Input validation failed: %s/%s", + vmsd->name, field->name); return -1; } field++; } assert(field->flags == VMS_END); - ret = vmstate_subsection_load(f, vmsd, opaque, NULL); + ret = vmstate_subsection_load(f, vmsd, opaque, errp); if (ret != 0) { qemu_file_set_error(f, ret); return ret; } if (vmsd->post_load) { ret = vmsd->post_load(opaque, version_id); + if (ret < 0) { + error_setg(errp, "VM Post load failed : %d", ret); + } } trace_vmstate_load_state_end(vmsd->name, "end", ret); return ret; @@ -606,10 +617,10 @@ static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *vmsd, qemu_file_skip(f, len); /* idstr */ version_id = qemu_get_be32(f); - ret = vmstate_load_state(f, sub_vmsd, opaque, version_id); + ret = vmstate_load_state(f, sub_vmsd, opaque, version_id, errp); if (ret) { trace_vmstate_subsection_load_bad(vmsd->name, idstr, "(child)"); - error_setg(errp, "Loading VM subsection failed : %d", ret); + error_prepend(errp, "Loading VM subsection failed : %d ", ret); return ret; } } diff --git a/tests/unit/test-vmstate.c b/tests/unit/test-vmstate.c index 63f28f26f45691a70936d33e7341d16477a3471f..ca5e0ba1e3e5e2bb0a1ce39143a292f2c6f9420a 100644 --- a/tests/unit/test-vmstate.c +++ b/tests/unit/test-vmstate.c @@ -114,7 +114,7 @@ static int load_vmstate_one(const VMStateDescription *desc, void *obj, qemu_fclose(f); f = open_test_file(false); - ret = vmstate_load_state(f, desc, obj, version); + ret = vmstate_load_state(f, desc, obj, version, NULL); if (ret) { g_assert(qemu_file_get_error(f)); } else{ @@ -365,7 +365,7 @@ static void test_load_v1(void) QEMUFile *loading = open_test_file(false); TestStruct obj = { .b = 200, .e = 500, .f = 600 }; - vmstate_load_state(loading, &vmstate_versioned, &obj, 1); + vmstate_load_state(loading, &vmstate_versioned, &obj, 1, NULL); g_assert(!qemu_file_get_error(loading)); g_assert_cmpint(obj.a, ==, 10); g_assert_cmpint(obj.b, ==, 200); @@ -391,7 +391,7 @@ static void test_load_v2(void) QEMUFile *loading = open_test_file(false); TestStruct obj; - vmstate_load_state(loading, &vmstate_versioned, &obj, 2); + vmstate_load_state(loading, &vmstate_versioned, &obj, 2, NULL); g_assert_cmpint(obj.a, ==, 10); g_assert_cmpint(obj.b, ==, 20); g_assert_cmpint(obj.c, ==, 30); @@ -480,7 +480,7 @@ static void test_load_noskip(void) QEMUFile *loading = open_test_file(false); TestStruct obj = { .skip_c_e = false }; - vmstate_load_state(loading, &vmstate_skipping, &obj, 2); + vmstate_load_state(loading, &vmstate_skipping, &obj, 2, NULL); g_assert(!qemu_file_get_error(loading)); g_assert_cmpint(obj.a, ==, 10); g_assert_cmpint(obj.b, ==, 20); @@ -504,7 +504,7 @@ static void test_load_skip(void) QEMUFile *loading = open_test_file(false); TestStruct obj = { .skip_c_e = true, .c = 300, .e = 500 }; - vmstate_load_state(loading, &vmstate_skipping, &obj, 2); + vmstate_load_state(loading, &vmstate_skipping, &obj, 2, NULL); g_assert(!qemu_file_get_error(loading)); g_assert_cmpint(obj.a, ==, 10); g_assert_cmpint(obj.b, ==, 20); @@ -773,7 +773,7 @@ static void test_load_q(void) TestQtailq tgt; QTAILQ_INIT(&tgt.q); - vmstate_load_state(fload, &vmstate_q, &tgt, 1); + vmstate_load_state(fload, &vmstate_q, &tgt, 1, NULL); char eof = qemu_get_byte(fload); g_assert(!qemu_file_get_error(fload)); g_assert_cmpint(tgt.i16, ==, obj_q.i16); @@ -1127,7 +1127,7 @@ static void test_gtree_load_domain(void) fload = open_test_file(false); - vmstate_load_state(fload, &vmstate_domain, dest_domain, 1); + vmstate_load_state(fload, &vmstate_domain, dest_domain, 1, NULL); eof = qemu_get_byte(fload); g_assert(!qemu_file_get_error(fload)); g_assert_cmpint(orig_domain->id, ==, dest_domain->id); @@ -1241,7 +1241,7 @@ static void test_gtree_load_iommu(void) qemu_fclose(fsave); fload = open_test_file(false); - vmstate_load_state(fload, &vmstate_iommu, dest_iommu, 1); + vmstate_load_state(fload, &vmstate_iommu, dest_iommu, 1, NULL); eof = qemu_get_byte(fload); g_assert(!qemu_file_get_error(fload)); g_assert_cmpint(orig_iommu->id, ==, dest_iommu->id); @@ -1376,7 +1376,7 @@ static void test_load_qlist(void) qemu_fclose(fsave); fload = open_test_file(false); - vmstate_load_state(fload, &vmstate_container, dest_container, 1); + vmstate_load_state(fload, &vmstate_container, dest_container, 1, NULL); eof = qemu_get_byte(fload); g_assert(!qemu_file_get_error(fload)); g_assert_cmpint(eof, ==, QEMU_VM_EOF); diff --git a/ui/vdagent.c b/ui/vdagent.c index c0746fe5b168fdc7aeb4866de2ba0c3387566649..83457dee0767433ad0778b37b41b9c673a0e1860 100644 --- a/ui/vdagent.c +++ b/ui/vdagent.c @@ -1008,7 +1008,7 @@ static int get_cbinfo(QEMUFile *f, void *pv, size_t size, vdagent_clipboard_peer_register(vd); - ret = vmstate_load_state(f, &vmstate_cbinfo_array, &cbinfo, 0); + ret = vmstate_load_state(f, &vmstate_cbinfo_array, &cbinfo, 0, NULL); if (ret) { return ret; } -- 2.50.0