On 29.04.24 22:39, Peter Xu wrote:
On Mon, Apr 29, 2024 at 10:14:25PM +0300, Vladimir Sementsov-Ogievskiy wrote:
Unify error reporting in the function. This simplifies the following
commit, which will not-exit-on-error behavior variant to the function.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsement...@yandex-team.ru>
Reviewed-by: Fabiano Rosas <faro...@suse.de>
---
  migration/migration.c | 17 ++++++++++-------
  1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/migration/migration.c b/migration/migration.c
index 58fd5819bc..5489ff96df 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -748,11 +748,12 @@ process_incoming_migration_co(void *opaque)
      MigrationIncomingState *mis = migration_incoming_get_current();
      PostcopyState ps;
      int ret;
+    Error *local_err = NULL;
assert(mis->from_src_file); if (compress_threads_load_setup(mis->from_src_file)) {
-        error_report("Failed to setup decompress threads");
+        error_setg(&local_err, "Failed to setup decompress threads");
          goto fail;
      }
@@ -789,16 +790,12 @@ process_incoming_migration_co(void *opaque)
      }
if (ret < 0) {
-        if (migrate_has_error(s)) {
-            WITH_QEMU_LOCK_GUARD(&s->error_mutex) {
-                error_report_err(error_copy(s->error));
-            }
-        }
-        error_report("load of migration failed: %s", strerror(-ret));
+        error_setg(&local_err, "load of migration failed: %s", strerror(-ret));
          goto fail;
      }
if (colo_incoming_co() < 0) {
+        error_setg(&local_err, "colo incoming failed");
          goto fail;
      }
@@ -809,6 +806,12 @@ fail:
                        MIGRATION_STATUS_FAILED);
      migration_incoming_state_destroy();
+ if (migrate_has_error(s)) {
+        WITH_QEMU_LOCK_GUARD(&s->error_mutex) {
+            error_report_err(error_copy(s->error));
+        }
+    }
+    error_report_err(local_err);

Here migrate_has_error() will always return true?  If so we can drop it.

Meanwhile, IMHO it's easier we simply always keep the earliest error we see
and report that only, local_err is just one of the errors and whoever
reaches first will be reported.  Something like:

   migrate_set_error(local_err);
   WITH_QEMU_LOCK_GUARD(&s->error_mutex) {
       error_report_err(error_copy(s->error));
   }
   exit(EXIT_FAILURE);

Then when with the exit-on-error thing:

   migrate_set_error(local_err);
   if (exit_on_error) {
     WITH_QEMU_LOCK_GUARD(&s->error_mutex) {
       error_report_err(error_copy(s->error));
     }
     exit(EXIT_FAILURE);
   }

Would this looks slightly cleaner?


Yes, looks better, will do so

--
Best regards,
Vladimir


Reply via email to