qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Arun Menon <armenon@redhat.com>
To: Fabiano Rosas <farosas@suse.de>
Cc: qemu-devel@nongnu.org, "Peter Xu" <peterx@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>,
	"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>,
	"Thomas Huth" <thuth@redhat.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>,
	"Matthew Rosato" <mjrosato@linux.ibm.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"David Hildenbrand" <david@redhat.com>,
	"Ilya Leoshkevich" <iii@linux.ibm.com>,
	"Nicholas Piggin" <npiggin@gmail.com>,
	"Harsh Prateek Bora" <harshpb@linux.ibm.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Fam Zheng" <fam@euphon.net>,
	"Alex Williamson" <alex.williamson@redhat.com>,
	"Cédric Le Goater" <clg@redhat.com>,
	"Steve Sistare" <steven.sistare@oracle.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	qemu-s390x@nongnu.org, qemu-ppc@nongnu.org,
	"Hailiang Zhang" <zhanghailiang@xfusion.com>,
	"Stefan Berger" <stefanb@linux.vnet.ibm.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	qemu-arm@nongnu.org, "Daniel P. Berrangé" <berrange@redhat.com>
Subject: Re: [PATCH v11 09/27] migration: push Error **errp into qemu_loadvm_state_main()
Date: Wed, 20 Aug 2025 22:57:22 +0530	[thread overview]
Message-ID: <aKYFep9deUh0-EO9@armenon-kvm.bengluru.csb> (raw)
In-Reply-To: <874iu8z8w1.fsf@suse.de>

Hi Fabiano,
Thanks for the review.
On Fri, Aug 15, 2025 at 04:23:42PM -0300, Fabiano Rosas wrote:
> Arun Menon <armenon@redhat.com> writes:
> 
> > 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 qemu_loadvm_state_main() must report an error
> > in errp, in case of failure.
> > loadvm_process_command also sets the errp object explicitly.
> >
> > Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
> > Signed-off-by: Arun Menon <armenon@redhat.com>
> > ---
> >  migration/colo.c   |  5 +++--
> >  migration/savevm.c | 36 +++++++++++++++++++-----------------
> >  migration/savevm.h |  3 ++-
> >  3 files changed, 24 insertions(+), 20 deletions(-)
> >
> > diff --git a/migration/colo.c b/migration/colo.c
> > index 0ba22ee76a13e313793f653f43a728e3c433bbc1..a96e4dba15516b71d1b315c736c3b4879ff04e58 100644
> > --- a/migration/colo.c
> > +++ b/migration/colo.c
> > @@ -659,6 +659,7 @@ void migrate_start_colo_process(MigrationState *s)
> >  static void colo_incoming_process_checkpoint(MigrationIncomingState *mis,
> >                        QEMUFile *fb, QIOChannelBuffer *bioc, Error **errp)
> >  {
> > +    ERRP_GUARD();
> 
> With my suggestion below, this goes away.
Yeah.
> 
> >      uint64_t total_size;
> >      uint64_t value;
> >      Error *local_err = NULL;
> > @@ -686,11 +687,11 @@ static void colo_incoming_process_checkpoint(MigrationIncomingState *mis,
> >  
> >      bql_lock();
> >      cpu_synchronize_all_states();
> > -    ret = qemu_loadvm_state_main(mis->from_src_file, mis);
> > +    ret = qemu_loadvm_state_main(mis->from_src_file, mis, errp);
> >      bql_unlock();
> >  
> >      if (ret < 0) {
> > -        error_setg(errp, "Load VM's live state (ram) error");
> > +        error_prepend(errp, "Load VM's live state (ram) error: ");
> 
> Another one to leave out. There's enough information downstream
> already. Also, this "(ram)" doesn't look right.
Yes, shall remove it.
> 
> >          return;
> >      }
> >  
> > diff --git a/migration/savevm.c b/migration/savevm.c
> > index 70e021597d884030c4a0dc2a7bc27d42a7371797..9ec07892cd6ea666431410657c840b6325377d97 100644
> > --- a/migration/savevm.c
> > +++ b/migration/savevm.c
> > @@ -2105,7 +2105,7 @@ static void *postcopy_ram_listen_thread(void *opaque)
> >      qemu_file_set_blocking(f, true);
> >  
> >      /* TODO: sanity check that only postcopiable data will be loaded here */
> > -    load_res = qemu_loadvm_state_main(f, mis);
> > +    load_res = qemu_loadvm_state_main(f, mis, &error_fatal);
> >  
> >      /*
> >       * This is tricky, but, mis->from_src_file can change after it
> > @@ -2407,6 +2407,7 @@ static int loadvm_postcopy_handle_resume(MigrationIncomingState *mis)
> >   */
> >  static int loadvm_handle_cmd_packaged(MigrationIncomingState *mis, Error **errp)
> >  {
> > +    ERRP_GUARD();
> >      int ret;
> >      size_t length;
> >      QIOChannelBuffer *bioc;
> > @@ -2456,9 +2457,9 @@ static int loadvm_handle_cmd_packaged(MigrationIncomingState *mis, Error **errp)
> >          qemu_coroutine_yield();
> >      } while (1);
> >  
> > -    ret = qemu_loadvm_state_main(packf, mis);
> > +    ret = qemu_loadvm_state_main(packf, mis, errp);
> >      if (ret < 0) {
> > -        error_setg(errp, "VM state load failed: %d", ret);
> > +        error_prepend(errp, "Loading VM state failed: %d: ", ret);
> 
> This is getting out of hand for code review, may I suggest you
> artificially trigger these errors, look at the resulting message and
> remove all the unnecessary wrapping? Each error_prepend is a candidate
> for removal if it will just state "load failed".
> 
> Using error_prepend partly defeats the purpose of propagating errp. We
> should only use it when there's valuable information to be provided.
I understand. I shall remove error_prepend from where it is not required.
> 
> >      }
> >      trace_loadvm_handle_cmd_packaged_main(ret);
> >      qemu_fclose(packf);
> > @@ -3080,18 +3081,21 @@ static bool postcopy_pause_incoming(MigrationIncomingState *mis)
> >      return true;
> >  }
> >  
> > -int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis)
> > +int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis,
> > +                           Error **errp)
> >  {
> > +    ERRP_GUARD();
> >      uint8_t section_type;
> >      int ret = 0;
> > -    Error *local_err = NULL;
> >  
> >  retry:
> >      while (true) {
> >          section_type = qemu_get_byte(f);
> >  
> > -        ret = qemu_file_get_error_obj_any(f, mis->postcopy_qemufile_dst, NULL);
> > +        ret = qemu_file_get_error_obj_any(f, mis->postcopy_qemufile_dst, errp);
> >          if (ret) {
> > +            error_prepend(errp, "Failed to load device state section ID: %d: ",
> > +                          ret);
> 
> We could drop some extra words here, the term 'section' is already quite
> representative.
> 
> "Failed to load section ID: stream error: %d: "
Thanks, will do.
> 
> 
> >              break;
> >          }
> >  
> > @@ -3112,10 +3116,7 @@ retry:
> >              }
> >              break;
> >          case QEMU_VM_COMMAND:
> > -            ret = loadvm_process_command(f, &local_err);
> > -            if (ret < 0) {
> > -                warn_report_err(local_err);
> > -            }
> > +            ret = loadvm_process_command(f, errp);
> 
> Good.
> 
> >              trace_qemu_loadvm_state_section_command(ret);
> >              if ((ret < 0) || (ret == LOADVM_QUIT)) {
> >                  goto out;
> > @@ -3125,7 +3126,7 @@ retry:
> >              /* This is the end of migration */
> >              goto out;
> >          default:
> > -            error_report("Unknown savevm section type %d", section_type);
> > +            error_setg(errp, "Unknown savevm section type %d", section_type);
> 
> Not sure if they're referring to "savevm" here as a generic term for
> vmstate/migration or if it was intended to say: "savevm wrote a section
> type that this loadvm instance doesn't understand".
> 
> Since you're here, could you fix this? Migration errors from source and
> destination are often interleaved in logs, we don't want to see the
> "savevm" word in a destination-side error message. Just put a small note
> in the commit message, no need for another patch.
Yes, shall remove savevm and amend the commit message.
> 
> >              ret = -EINVAL;
> >              goto out;
> >          }
> > @@ -3133,6 +3134,9 @@ retry:
> >  
> >  out:
> >      if (ret < 0) {
> > +        if (*errp == NULL) {
> > +            error_setg(errp, "Loading VM state failed: %d", ret);
> > +        }
> 
> Another candidate for removal, then we avoid having to dereference errp.
This is added so that errp is set in case of failure in paths that are not
converted yet in the series. The out label comes in handy.
This is removed in the future patch 4648a1849a
> 
> >          qemu_file_set_error(f, ret);
> >  
> >          /* Cancel bitmaps incoming regardless of recovery */
> > @@ -3153,6 +3157,7 @@ out:
> >              migrate_postcopy_ram() && postcopy_pause_incoming(mis)) {
> >              /* Reset f to point to the newly created channel */
> >              f = mis->from_src_file;
> > +            error_free_or_abort(errp);
> 
> What's this about?
The errp needs to be freed and reset to NULL if we go into retry and
intend to use the variable again.
> 
> >              goto retry;
> >          }
> >      }
> > @@ -3186,10 +3191,7 @@ int qemu_loadvm_state(QEMUFile *f, Error **errp)
> >  
> >      cpu_synchronize_all_pre_loadvm();
> >  
> > -    ret = qemu_loadvm_state_main(f, mis);
> > -    if (ret < 0) {
> > -        error_setg(errp, "Load VM state failed: %d", ret);
> > -    }
> > +    ret = qemu_loadvm_state_main(f, mis, errp);
> >      qemu_event_set(&mis->main_thread_load_event);
> >  
> >      trace_qemu_loadvm_state_post_main(ret);
> > @@ -3270,9 +3272,9 @@ int qemu_load_device_state(QEMUFile *f, Error **errp)
> >      int ret;
> >  
> >      /* Load QEMU_VM_SECTION_FULL section */
> > -    ret = qemu_loadvm_state_main(f, mis);
> > +    ret = qemu_loadvm_state_main(f, mis, errp);
> >      if (ret < 0) {
> > -        error_setg(errp, "Failed to load device state: %d", ret);
> > +        error_prepend(errp, "Failed to load device state: %d: ", ret);
Maybe this can also be removed.
> >          return ret;
> >      }
> >  
> > diff --git a/migration/savevm.h b/migration/savevm.h
> > index b12681839f0b1afa3255e45215d99c13a224b19f..c337e3e3d111a7f28a57b90f61e8f70b71803d4e 100644
> > --- a/migration/savevm.h
> > +++ b/migration/savevm.h
> > @@ -66,7 +66,8 @@ int qemu_save_device_state(QEMUFile *f);
> >  
> >  int qemu_loadvm_state(QEMUFile *f, Error **errp);
> >  void qemu_loadvm_state_cleanup(MigrationIncomingState *mis);
> > -int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis);
> > +int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis,
> > +                           Error **errp);
> >  int qemu_load_device_state(QEMUFile *f, Error **errp);
> >  int qemu_loadvm_approve_switchover(void);
> >  int qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f,
> 

Regards,
Arun



  reply	other threads:[~2025-08-20 17:29 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20250813-propagate_tpm_error-v11-0-b470a374b42d@redhat.com>
     [not found] ` <20250813-propagate_tpm_error-v11-1-b470a374b42d@redhat.com>
2025-08-15 14:44   ` [PATCH v11 01/27] migration: push Error **errp into vmstate_subsection_load() Fabiano Rosas
2025-08-15 20:06     ` Fabiano Rosas
2025-08-20 17:43       ` Arun Menon
     [not found] ` <20250813-propagate_tpm_error-v11-2-b470a374b42d@redhat.com>
2025-08-15 15:41   ` [PATCH v11 02/27] migration: push Error **errp into vmstate_load_state() Fabiano Rosas
2025-08-20  8:12     ` Arun Menon
2025-08-20 15:24       ` Fabiano Rosas
2025-08-20 17:07         ` Arun Menon
     [not found] ` <20250813-propagate_tpm_error-v11-3-b470a374b42d@redhat.com>
2025-08-15 15:58   ` [PATCH v11 03/27] migration: push Error **errp into qemu_loadvm_state_header() Fabiano Rosas
     [not found] ` <20250813-propagate_tpm_error-v11-4-b470a374b42d@redhat.com>
2025-08-15 16:41   ` [PATCH v11 04/27] migration: push Error **errp into vmstate_load() Fabiano Rosas
2025-08-20 17:31     ` Arun Menon
     [not found] ` <20250813-propagate_tpm_error-v11-5-b470a374b42d@redhat.com>
2025-08-15 18:35   ` [PATCH v11 05/27] migration: push Error **errp into loadvm_process_command() Fabiano Rosas
2025-08-20  9:08     ` Arun Menon
2025-08-20 13:42     ` Arun Menon
     [not found] ` <20250813-propagate_tpm_error-v11-6-b470a374b42d@redhat.com>
2025-08-15 18:39   ` [PATCH v11 06/27] migration: push Error **errp into loadvm_handle_cmd_packaged() Fabiano Rosas
     [not found] ` <20250813-propagate_tpm_error-v11-7-b470a374b42d@redhat.com>
2025-08-15 18:55   ` [PATCH v11 07/27] migration: push Error **errp into qemu_loadvm_state() Fabiano Rosas
2025-08-20 17:36     ` Arun Menon
     [not found] ` <20250813-propagate_tpm_error-v11-8-b470a374b42d@redhat.com>
2025-08-15 18:58   ` [PATCH v11 08/27] migration: push Error **errp into qemu_load_device_state() Fabiano Rosas
2025-08-20 17:36     ` Arun Menon
     [not found] ` <20250813-propagate_tpm_error-v11-9-b470a374b42d@redhat.com>
2025-08-15 19:23   ` [PATCH v11 09/27] migration: push Error **errp into qemu_loadvm_state_main() Fabiano Rosas
2025-08-20 17:27     ` Arun Menon [this message]
     [not found] ` <20250813-propagate_tpm_error-v11-10-b470a374b42d@redhat.com>
2025-08-15 19:29   ` [PATCH v11 10/27] migration: push Error **errp into qemu_loadvm_section_start_full() Fabiano Rosas
2025-08-20 17:35     ` Arun Menon
     [not found] ` <20250813-propagate_tpm_error-v11-11-b470a374b42d@redhat.com>
2025-08-15 19:35   ` [PATCH v11 11/27] migration: push Error **errp into qemu_loadvm_section_part_end() Fabiano Rosas
2025-08-20 17:34     ` Arun Menon
     [not found] ` <20250813-propagate_tpm_error-v11-14-b470a374b42d@redhat.com>
2025-08-15 19:37   ` [PATCH v11 14/27] migration: push Error **errp into ram_postcopy_incoming_init() Fabiano Rosas
     [not found] ` <20250813-propagate_tpm_error-v11-15-b470a374b42d@redhat.com>
2025-08-15 19:40   ` [PATCH v11 15/27] migration: push Error **errp into loadvm_postcopy_handle_advise() Fabiano Rosas
     [not found] ` <20250813-propagate_tpm_error-v11-16-b470a374b42d@redhat.com>
2025-08-15 19:41   ` [PATCH v11 16/27] migration: push Error **errp into loadvm_postcopy_handle_listen() Fabiano Rosas
     [not found] ` <20250813-propagate_tpm_error-v11-17-b470a374b42d@redhat.com>
2025-08-15 19:41   ` [PATCH v11 17/27] migration: push Error **errp into loadvm_postcopy_handle_run() Fabiano Rosas
     [not found] ` <20250813-propagate_tpm_error-v11-18-b470a374b42d@redhat.com>
2025-08-15 19:42   ` [PATCH v11 18/27] migration: push Error **errp into loadvm_postcopy_ram_handle_discard() Fabiano Rosas
     [not found] ` <20250813-propagate_tpm_error-v11-19-b470a374b42d@redhat.com>
2025-08-15 19:51   ` [PATCH v11 19/27] migration: push Error **errp into loadvm_handle_recv_bitmap() Fabiano Rosas
2025-08-20 17:32     ` Arun Menon
     [not found] ` <20250813-propagate_tpm_error-v11-20-b470a374b42d@redhat.com>
2025-08-15 19:51   ` [PATCH v11 20/27] migration: Return -1 on memory allocation failure in ram.c Fabiano Rosas
     [not found] ` <20250813-propagate_tpm_error-v11-21-b470a374b42d@redhat.com>
2025-08-15 19:53   ` [PATCH v11 21/27] migration: push Error **errp into loadvm_process_enable_colo() Fabiano Rosas
     [not found] ` <20250813-propagate_tpm_error-v11-22-b470a374b42d@redhat.com>
2025-08-15 19:53   ` [PATCH v11 22/27] migration: push Error **errp into loadvm_postcopy_handle_switchover_start() Fabiano Rosas
     [not found] ` <20250813-propagate_tpm_error-v11-23-b470a374b42d@redhat.com>
2025-08-15 19:57   ` [PATCH v11 23/27] migration: Capture error in postcopy_ram_listen_thread() Fabiano Rosas
2025-08-20 17:37     ` 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=aKYFep9deUh0-EO9@armenon-kvm.bengluru.csb \
    --to=armenon@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=alex.williamson@redhat.com \
    --cc=berrange@redhat.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=clg@redhat.com \
    --cc=cohuck@redhat.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=peter.maydell@linaro.org \
    --cc=peterx@redhat.com \
    --cc=qemu-arm@nongnu.org \
    --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).