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é <berra...@redhat.com> Signed-off-by: Arun Menon <arme...@redhat.com> --- migration/colo.c | 4 ++-- migration/savevm.c | 25 ++++++++++++++----------- migration/savevm.h | 3 ++- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/migration/colo.c b/migration/colo.c index 981bd4bf9ced8b45b4c5d494acae119a174ee974..03edf870e2bc9c724fc27e26e7ba54a40c13399e 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -686,11 +686,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"); return; } diff --git a/migration/savevm.c b/migration/savevm.c index 679abf7c668ea7990da10ca8caba09fbb7bdd2ea..ba146f91427f2a36880aadeb16b11ab2b7df099a 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2108,7 +2108,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, NULL); /* * This is tricky, but, mis->from_src_file can change after it @@ -2459,9 +2459,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); } trace_loadvm_handle_cmd_packaged_main(ret); qemu_fclose(packf); @@ -3059,7 +3059,8 @@ 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) { uint8_t section_type; int ret = 0; @@ -3068,8 +3069,10 @@ 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); break; } @@ -3077,20 +3080,20 @@ retry: switch (section_type) { case QEMU_VM_SECTION_START: case QEMU_VM_SECTION_FULL: - ret = qemu_loadvm_section_start_full(f, section_type, NULL); + ret = qemu_loadvm_section_start_full(f, section_type, errp); if (ret < 0) { goto out; } break; case QEMU_VM_SECTION_PART: case QEMU_VM_SECTION_END: - ret = qemu_loadvm_section_part_end(f, section_type, NULL); + ret = qemu_loadvm_section_part_end(f, section_type, errp); if (ret < 0) { goto out; } break; case QEMU_VM_COMMAND: - ret = loadvm_process_command(f, NULL); + ret = loadvm_process_command(f, errp); trace_qemu_loadvm_state_section_command(ret); if ((ret < 0) || (ret == LOADVM_QUIT)) { goto out; @@ -3100,7 +3103,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); ret = -EINVAL; goto out; } @@ -3164,7 +3167,7 @@ int qemu_loadvm_state(QEMUFile *f) cpu_synchronize_all_pre_loadvm(); - ret = qemu_loadvm_state_main(f, mis); + ret = qemu_loadvm_state_main(f, mis, NULL); qemu_event_set(&mis->main_thread_load_event); trace_qemu_loadvm_state_post_main(ret); @@ -3238,7 +3241,7 @@ int qemu_load_device_state(QEMUFile *f) int ret; /* Load QEMU_VM_SECTION_FULL section */ - ret = qemu_loadvm_state_main(f, mis); + ret = qemu_loadvm_state_main(f, mis, NULL); if (ret < 0) { error_report("Failed to load device state: %d", ret); return ret; diff --git a/migration/savevm.h b/migration/savevm.h index 2d5e9c716686f06720325e82fe90c75335ced1de..fd7419e6ff90062970ed246b3ea71e6d49a6e372 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); 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); int qemu_loadvm_approve_switchover(void); int qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f, -- 2.50.0