From: Peter Xu Date: Tue, 27 Jan 2026 18:52:51 +0000 (-0500) Subject: migration/bg-snapshot: Cleanup error paths X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7a6eeaf8109d6332412e72b724bac0a995b29840;p=thirdparty%2Fqemu.git migration/bg-snapshot: Cleanup error paths Cleanup bg_migration_thread() function on error handling. First of all, early_fail is almost only used to say if BQL is taken. Since we already have separate jumping labels, we don't really need it, hence removed. Also, since local_err is around, making sure every failure path will set a proper error string for the failure, then propagate to MigrationState.error. Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas Tested-by: Lukas Straub Link: https://lore.kernel.org/qemu-devel/20260127185254.3954634-22-peterx@redhat.com Signed-off-by: Fabiano Rosas --- diff --git a/migration/migration.c b/migration/migration.c index f81ac21d4e..f9eec4b25a 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -3628,7 +3628,6 @@ static void *bg_migration_thread(void *opaque) int64_t setup_start; MigThrError thr_error; QEMUFile *fb; - bool early_fail = true; Error *local_err = NULL; int ret; @@ -3674,10 +3673,7 @@ static void *bg_migration_thread(void *opaque) * devices to unplug. This to preserve migration state transitions. */ if (ret) { - migrate_error_propagate(s, local_err); - migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE, - MIGRATION_STATUS_FAILED); - goto fail_setup; + goto fail; } s->setup_time = qemu_clock_get_ms(QEMU_CLOCK_HOST) - setup_start; @@ -3687,11 +3683,13 @@ static void *bg_migration_thread(void *opaque) bql_lock(); if (migration_stop_vm(s, RUN_STATE_PAUSED)) { - goto fail; + error_setg(&local_err, "Failed to stop the VM"); + goto fail_with_bql; } if (qemu_savevm_state_non_iterable(fb)) { - goto fail; + error_setg(&local_err, "Failed to save non-iterable devices"); + goto fail_with_bql; } qemu_savevm_state_end_precopy(s, fb); @@ -3704,9 +3702,9 @@ static void *bg_migration_thread(void *opaque) /* Now initialize UFFD context and start tracking RAM writes */ if (ram_write_tracking_start()) { - goto fail; + error_setg(&local_err, "Failed to start write tracking"); + goto fail_with_bql; } - early_fail = false; /* * Start VM from BH handler to avoid write-fault lock here. @@ -3738,21 +3736,22 @@ static void *bg_migration_thread(void *opaque) } trace_migration_thread_after_loop(); + goto done; + +fail_with_bql: + bql_unlock(); fail: - if (early_fail) { - migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE, - MIGRATION_STATUS_FAILED); - bql_unlock(); - } + /* local_err is guaranteed to be set when reaching here */ + migrate_error_propagate(s, local_err); + migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE, + MIGRATION_STATUS_FAILED); -fail_setup: +done: bg_migration_iteration_finish(s); - qemu_fclose(fb); object_unref(OBJECT(s)); rcu_unregister_thread(); - return NULL; }