migration: Set migration error in migration_completion()

After commit 9425ef3f99 ("migration: Use migrate_has_error() in
close_return_path_on_source()"), close_return_path_on_source() assumes
that migration error is set if an error occurs during migration.

This may not be true if migration errors in migration_completion(). For
example, if qemu_savevm_state_complete_precopy() errors, migration error
will not be set.

This in turn, will cause a migration hang bug, similar to the bug that
was fixed by commit 22b04245f0 ("migration: Join the return path
thread before releasing to_dst_file"), as shutdown() will not be issued
for the return-path channel.

Fix it by ensuring migration error is set in case of error in
migration_completion().

Signed-off-by: Avihai Horon <avihaih@nvidia.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Fixes: 9425ef3f99 ("migration: Use migrate_has_error() in close_return_path_on_source()")
Acked-by: Cédric Le Goater <clg@redhat.com>
Link: https://lore.kernel.org/r/20240328140252.16756-2-avihaih@nvidia.com
Signed-off-by: Peter Xu <peterx@redhat.com>
This commit is contained in:
Avihai Horon 2024-03-28 16:02:51 +02:00 committed by Peter Xu
parent b9dbf6f9bf
commit 30158d8850

View File

@ -2799,6 +2799,7 @@ static void migration_completion(MigrationState *s)
{
int ret = 0;
int current_active_state = s->state;
Error *local_err = NULL;
if (s->state == MIGRATION_STATUS_ACTIVE) {
ret = migration_completion_precopy(s, &current_active_state);
@ -2832,6 +2833,15 @@ static void migration_completion(MigrationState *s)
return;
fail:
if (qemu_file_get_error_obj(s->to_dst_file, &local_err)) {
migrate_set_error(s, local_err);
error_free(local_err);
} else if (ret) {
error_setg_errno(&local_err, -ret, "Error in migration completion");
migrate_set_error(s, local_err);
error_free(local_err);
}
migration_completion_failed(s, current_active_state);
}