qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Arun Menon <armenon@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
	"Cornelia Huck" <cohuck@redhat.com>,
	"Halil Pasic" <pasic@linux.ibm.com>,
	"Eric Farman" <farman@linux.ibm.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"David Hildenbrand" <david@redhat.com>,
	"Ilya Leoshkevich" <iii@linux.ibm.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Fam Zheng" <fam@euphon.net>,
	"Nicholas Piggin" <npiggin@gmail.com>,
	"Daniel Henrique Barboza" <danielhb413@gmail.com>,
	"Harsh Prateek Bora" <harshpb@linux.ibm.com>,
	"Alex Williamson" <alex.williamson@redhat.com>,
	"Cédric Le Goater" <clg@redhat.com>,
	"Peter Xu" <peterx@redhat.com>, "Fabiano Rosas" <farosas@suse.de>,
	"Hailiang Zhang" <zhanghailiang@xfusion.com>,
	"Steve Sistare" <steven.sistare@oracle.com>,
	qemu-s390x@nongnu.org, qemu-ppc@nongnu.org,
	"Stefan Berger" <stefanb@linux.vnet.ibm.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Akihiko Odaki" <odaki@rsg.ci.i.u-tokyo.ac.jp>,
	"Dmitry Osipenko" <dmitry.osipenko@collabora.com>,
	"Matthew Rosato" <mjrosato@linux.ibm.com>,
	"Arun Menon" <armenon@redhat.com>
Subject: [PATCH v7 23/24] migration: Add error-parameterized function variants in VMSD struct
Date: Fri, 25 Jul 2025 17:49:02 +0530	[thread overview]
Message-ID: <20250725-propagate_tpm_error-v7-23-d52704443975@redhat.com> (raw)
In-Reply-To: <20250725-propagate_tpm_error-v7-0-d52704443975@redhat.com>

- We need to have good error reporting in the callbacks in
  VMStateDescription struct. Specifically pre_save, post_save,
  pre_load and post_load callbacks.
- It is not possible to change these functions everywhere in one
  patch, therefore, we introduce a duplicate set of callbacks
  with Error object passed to them.
- So, in this commit, we implement 'errp' variants of these callbacks,
  introducing an explicit Error object parameter.
- This is a functional step towards transitioning the entire codebase
  to the new error-parameterized functions.
- Deliberately called in mutual exclusion from their counterparts,
  to prevent conflicts during the transition.
- New impls should preferentally use 'errp' variants of
  these methods, and existing impls incrementally converted.
  The variants without 'errp' are intended to be removed
  once all usage is converted.

Signed-off-by: Arun Menon <armenon@redhat.com>
---
 include/migration/vmstate.h | 11 ++++++++
 migration/vmstate.c         | 62 +++++++++++++++++++++++++++++++++++++++------
 2 files changed, 65 insertions(+), 8 deletions(-)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 056781b1c21e737583f081594d9f88b32adfd674..53fa72c1bbde399be02c88fc8745fdbb79bfd7c8 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -200,15 +200,26 @@ struct VMStateDescription {
      * exclusive. For this reason, also early_setup VMSDs are migrated in a
      * QEMU_VM_SECTION_FULL section, while save_setup() data is migrated in
      * a QEMU_VM_SECTION_START section.
+     *
+     * There are duplicate impls of the post/pre save/load hooks.
+     * New impls should preferentally use 'errp' variants of these
+     * methods and existing impls incrementally converted.
+     * The variants without 'errp' are intended to be removed
+     * once all usage is converted.
      */
+
     bool early_setup;
     int version_id;
     int minimum_version_id;
     MigrationPriority priority;
     int (*pre_load)(void *opaque);
+    int (*pre_load_errp)(void *opaque, Error **errp);
     int (*post_load)(void *opaque, int version_id);
+    int (*post_load_errp)(void *opaque, int version_id, Error **errp);
     int (*pre_save)(void *opaque);
+    int (*pre_save_errp)(void *opaque, Error **errp);
     int (*post_save)(void *opaque);
+    int (*post_save_errp)(void *opaque, Error **errp);
     bool (*needed)(void *opaque);
     bool (*dev_unplug_pending)(void *opaque);
 
diff --git a/migration/vmstate.c b/migration/vmstate.c
index bb5e9bf38d6ee7619ceb3e9da29209581c3c12eb..e427ef49b2b1991b0a3cdb14d641c197e00014b0 100644
--- a/migration/vmstate.c
+++ b/migration/vmstate.c
@@ -152,7 +152,16 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
         trace_vmstate_load_state_end(vmsd->name, "too old", -EINVAL);
         return -EINVAL;
     }
-    if (vmsd->pre_load) {
+    if (vmsd->pre_load_errp) {
+        ret = vmsd->pre_load_errp(opaque, errp);
+        if (ret) {
+            error_prepend(errp, "VM pre load failed for: '%s', "
+                          "version_id: '%d', minimum version_id: '%d', "
+                          "ret: %d: ", vmsd->name, vmsd->version_id,
+                          vmsd->minimum_version_id, ret);
+            return ret;
+        }
+    } else if (vmsd->pre_load) {
         ret = vmsd->pre_load(opaque);
         if (ret) {
             error_setg(errp, "VM pre load failed for: '%s', "
@@ -236,7 +245,14 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
         qemu_file_set_error(f, ret);
         return ret;
     }
-    if (vmsd->post_load) {
+    if (vmsd->post_load_errp) {
+        ret = vmsd->post_load_errp(opaque, version_id, errp);
+        if (ret < 0) {
+            error_prepend(errp, "VM Post load failed for: %s, version_id: %d, "
+                          "minimum_version: %d, ret: %d: ", vmsd->name,
+                          vmsd->version_id, vmsd->minimum_version_id, ret);
+        }
+    } else if (vmsd->post_load) {
         ret = vmsd->post_load(opaque, version_id);
         if (ret < 0) {
             error_setg(errp,
@@ -412,11 +428,19 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,
                          void *opaque, JSONWriter *vmdesc, int version_id, Error **errp)
 {
     int ret = 0;
+    Error *local_err = NULL;
     const VMStateField *field = vmsd->fields;
 
     trace_vmstate_save_state_top(vmsd->name);
 
-    if (vmsd->pre_save) {
+    if (vmsd->pre_save_errp) {
+        ret = vmsd->pre_save_errp(opaque, errp);
+        trace_vmstate_save_state_pre_save_res(vmsd->name, ret);
+        if (ret) {
+            error_prepend(errp, "pre-save failed: %s: ", vmsd->name);
+            return ret;
+        }
+    } else if (vmsd->pre_save) {
         ret = vmsd->pre_save(opaque);
         trace_vmstate_save_state_pre_save_res(vmsd->name, ret);
         if (ret) {
@@ -524,10 +548,22 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,
                 }
 
                 if (ret) {
-                    error_setg(errp, "Save of field %s/%s failed",
-                                vmsd->name, field->name);
-                    if (vmsd->post_save) {
-                        vmsd->post_save(opaque);
+                    if (*errp == NULL) {
+                        error_setg(errp, "Save of field %s/%s failed",
+                                   vmsd->name, field->name);
+                    }
+                    if (vmsd->post_save_errp) {
+                        int ps_ret = vmsd->post_save_errp(opaque, &local_err);
+                        if (ps_ret < 0) {
+                            error_free_or_abort(errp);
+                            error_propagate(errp, local_err);
+                            ret = ps_ret;
+                        }
+                    } else if (vmsd->post_save) {
+                        int ps_ret = vmsd->post_save(opaque);
+                        if (ps_ret < 0) {
+                            ret = ps_ret;
+                        }
                     }
                     return ret;
                 }
@@ -554,7 +590,17 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,
 
     ret = vmstate_subsection_save(f, vmsd, opaque, vmdesc, errp);
 
-    if (vmsd->post_save) {
+    if (vmsd->post_save_errp) {
+        int ps_ret = vmsd->post_save_errp(opaque, &local_err);
+        if (!ret && ps_ret) {
+            ret = ps_ret;
+            error_propagate(errp, local_err);
+        } else if (ret && ps_ret) {
+            error_free_or_abort(errp);
+            error_propagate(errp, local_err);
+            ret = ps_ret;
+        }
+    } else if (vmsd->post_save) {
         int ps_ret = vmsd->post_save(opaque);
         if (!ret && ps_ret) {
             ret = ps_ret;

-- 
2.50.0



  parent reply	other threads:[~2025-07-25 12:30 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-25 12:18 [PATCH v7 00/24] migration: propagate vTPM errors using Error objects Arun Menon
2025-07-25 12:18 ` [PATCH v7 01/24] migration: push Error **errp into vmstate_subsection_load() Arun Menon
2025-07-25 13:46   ` Marc-André Lureau
2025-07-28  8:44     ` Marc-André Lureau
2025-07-28  9:01       ` Daniel P. Berrangé
2025-07-28  9:59         ` Marc-André Lureau
2025-07-28 10:06           ` Daniel P. Berrangé
2025-07-29  7:23       ` Arun Menon
2025-07-25 12:18 ` [PATCH v7 02/24] migration: push Error **errp into vmstate_load_state() Arun Menon
2025-07-25 13:48   ` Marc-André Lureau
2025-07-28 10:14     ` Marc-André Lureau
2025-07-29  7:24       ` Arun Menon
2025-07-25 12:18 ` [PATCH v7 03/24] migration: push Error **errp into qemu_loadvm_state_header() Arun Menon
2025-07-25 13:51   ` Marc-André Lureau
2025-07-25 12:18 ` [PATCH v7 04/24] migration: push Error **errp into vmstate_load() Arun Menon
2025-07-25 13:56   ` Marc-André Lureau
2025-07-25 12:18 ` [PATCH v7 05/24] migration: push Error **errp into qemu_loadvm_section_start_full() Arun Menon
2025-07-25 12:18 ` [PATCH v7 06/24] migration: push Error **errp into qemu_loadvm_section_part_end() Arun Menon
2025-07-25 12:18 ` [PATCH v7 07/24] migration: Update qemu_file_get_return_path() docs and remove dead checks Arun Menon
2025-07-28  8:46   ` Marc-André Lureau
2025-07-25 12:18 ` [PATCH v7 08/24] migration: make loadvm_postcopy_handle_resume() void Arun Menon
2025-07-28 10:25   ` Marc-André Lureau
2025-07-29  7:25     ` Arun Menon
2025-07-25 12:18 ` [PATCH v7 09/24] migration: push Error **errp into loadvm_process_command() Arun Menon
2025-07-28  8:53   ` Marc-André Lureau
2025-07-28  9:05     ` Daniel P. Berrangé
2025-07-25 12:18 ` [PATCH v7 10/24] migration: push Error **errp into loadvm_handle_cmd_packaged() Arun Menon
2025-07-25 12:18 ` [PATCH v7 11/24] migration: push Error **errp into ram_postcopy_incoming_init() Arun Menon
2025-07-28 10:00   ` Marc-André Lureau
2025-07-25 12:18 ` [PATCH v7 12/24] migration: push Error **errp into loadvm_postcopy_handle_advise() Arun Menon
2025-07-28 10:04   ` Marc-André Lureau
2025-07-25 12:18 ` [PATCH v7 13/24] migration: push Error **errp into loadvm_postcopy_handle_listen() Arun Menon
2025-07-25 12:18 ` [PATCH v7 14/24] migration: push Error **errp into loadvm_postcopy_handle_run() Arun Menon
2025-07-25 12:18 ` [PATCH v7 15/24] migration: push Error **errp into loadvm_postcopy_ram_handle_discard() Arun Menon
2025-07-25 12:18 ` [PATCH v7 16/24] migration: push Error **errp into loadvm_handle_recv_bitmap() Arun Menon
2025-07-25 12:18 ` [PATCH v7 17/24] migration: push Error **errp into loadvm_process_enable_colo() Arun Menon
2025-07-25 12:18 ` [PATCH v7 18/24] migration: push Error **errp into loadvm_postcopy_handle_switchover_start() Arun Menon
2025-07-25 12:18 ` [PATCH v7 19/24] migration: push Error **errp into qemu_loadvm_state_main() Arun Menon
2025-07-25 12:18 ` [PATCH v7 20/24] migration: push Error **errp into qemu_loadvm_state() Arun Menon
2025-07-25 12:19 ` [PATCH v7 21/24] migration: push Error **errp into qemu_load_device_state() Arun Menon
2025-07-25 12:19 ` [PATCH v7 22/24] migration: Capture error in postcopy_ram_listen_thread() Arun Menon
2025-07-28 10:34   ` Marc-André Lureau
2025-07-25 12:19 ` Arun Menon [this message]
2025-07-26 12:48   ` [PATCH v7 23/24] migration: Add error-parameterized function variants in VMSD struct Akihiko Odaki
2025-07-28 10:54     ` Arun Menon
2025-07-29  8:24       ` Akihiko Odaki
2025-07-28 11:07   ` Marc-André Lureau
2025-07-28 15:20     ` Arun Menon
2025-07-25 12:19 ` [PATCH v7 24/24] backends/tpm: Propagate vTPM error on migration failure Arun Menon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250725-propagate_tpm_error-v7-23-d52704443975@redhat.com \
    --to=armenon@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=alex.williamson@redhat.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=clg@redhat.com \
    --cc=cohuck@redhat.com \
    --cc=danielhb413@gmail.com \
    --cc=david@redhat.com \
    --cc=dmitry.osipenko@collabora.com \
    --cc=fam@euphon.net \
    --cc=farman@linux.ibm.com \
    --cc=farosas@suse.de \
    --cc=harshpb@linux.ibm.com \
    --cc=iii@linux.ibm.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mjrosato@linux.ibm.com \
    --cc=mst@redhat.com \
    --cc=npiggin@gmail.com \
    --cc=odaki@rsg.ci.i.u-tokyo.ac.jp \
    --cc=pasic@linux.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=stefanb@linux.vnet.ibm.com \
    --cc=steven.sistare@oracle.com \
    --cc=thuth@redhat.com \
    --cc=zhanghailiang@xfusion.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).