A snapshot of a paused VM left it in finish-migrate, where it stayed until the VM was restarted. vm_needs_start only recorded whether the VM had been running, so there was nothing to restore a paused VM to.
Store the run state instead and put it back, similar to migration_iteration_finish(). Signed-off-by: Erik Fastermann <[email protected]> --- ...async-for-background-state-snapshots.patch | 57 ++++++++++++------- ...add-optional-buffer-size-to-QEMUFile.patch | 6 +- ...se-migration-blocker-check-for-snaps.patch | 4 +- 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/debian/patches/pve/0017-PVE-add-savevm-async-for-background-state-snapshots.patch b/debian/patches/pve/0017-PVE-add-savevm-async-for-background-state-snapshots.patch index 94908d7..9a4a049 100644 --- a/debian/patches/pve/0017-PVE-add-savevm-async-for-background-state-snapshots.patch +++ b/debian/patches/pve/0017-PVE-add-savevm-async-for-background-state-snapshots.patch @@ -40,7 +40,8 @@ Signed-off-by: Fiona Ebner <[email protected]> [EF: drop QIOChannel reference free migration vmdesc release resources on start failure path - include reason when file open fails] + include reason when file open fails + restore run state from before snapshot] Signed-off-by: Erik Fastermann <[email protected]> --- hmp-commands-info.hx | 13 + @@ -48,13 +49,13 @@ Signed-off-by: Erik Fastermann <[email protected]> include/migration/snapshot.h | 2 + include/monitor/hmp.h | 3 + migration/meson.build | 1 + - migration/savevm-async.c | 634 +++++++++++++++++++++++++++++++++++ - monitor/hmp-cmds.c | 38 +++ + migration/savevm-async.c | 648 +++++++++++++++++++++++++++++++++++ + monitor/hmp-cmds.c | 38 ++ qapi/migration.json | 34 ++ qapi/misc.json | 25 ++ qemu-options.hx | 12 + system/vl.c | 10 + - 11 files changed, 789 insertions(+) + 11 files changed, 803 insertions(+) create mode 100644 migration/savevm-async.c diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx @@ -152,10 +153,10 @@ index 0222d5ea6e..90d62d5723 100644 ), gnutls, zlib) diff --git a/migration/savevm-async.c b/migration/savevm-async.c new file mode 100644 -index 0000000000..56c60b345f +index 0000000000..fe455016ab --- /dev/null +++ b/migration/savevm-async.c -@@ -0,0 +1,634 @@ +@@ -0,0 +1,648 @@ +#include "qemu/osdep.h" +#include "migration/channel-savevm-async.h" +#include "migration/migration.h" @@ -210,7 +211,7 @@ index 0000000000..56c60b345f + int state; + Error *error; + Error *blocker; -+ bool vm_needs_start; ++ RunState vm_old_state; + bool skip_vm_start; + QEMUFile *file; + int64_t total_time; @@ -230,6 +231,24 @@ index 0000000000..56c60b345f + return snap_state.state == SAVE_STATE_COMPLETED && snap_state.skip_vm_start; +} + ++static void restore_vm_old_state(void) ++{ ++ RunState old_state = snap_state.vm_old_state; ++ ++ if (old_state == RUN_STATE__MAX) { ++ return; ++ } ++ snap_state.vm_old_state = RUN_STATE__MAX; ++ ++ if (runstate_is_live(old_state)) { ++ if (!should_skip_vm_start() && !runstate_check(RUN_STATE_SHUTDOWN)) { ++ vm_start(); ++ } ++ } else if (runstate_check(RUN_STATE_FINISH_MIGRATE)) { ++ runstate_set(old_state); ++ } ++} ++ +SaveVMInfo *qmp_query_savevm(Error **errp) +{ + SaveVMInfo *info = g_malloc0(sizeof(*info)); @@ -352,7 +371,7 @@ index 0000000000..56c60b345f + */ + blk_set_aio_context(snap_state.target, qemu_get_aio_context(), NULL); + -+ snap_state.vm_needs_start = runstate_is_running(); ++ snap_state.vm_old_state = runstate_get(); + ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE); + if (ret < 0) { + save_snapshot_error("vm_stop_force_state error %d", ret); @@ -396,12 +415,7 @@ index 0000000000..56c60b345f + save_snapshot_error("process_savevm_cleanup: invalid state: %d", + snap_state.state); + } -+ if (snap_state.vm_needs_start) { -+ if (!should_skip_vm_start()) { -+ vm_start(); -+ } -+ snap_state.vm_needs_start = false; -+ } ++ restore_vm_old_state(); + + DPRINTF("timing: process_savevm_finalize (full) took %ld ms\n", + qemu_clock_get_ms(QEMU_CLOCK_REALTIME) - start_time); @@ -529,12 +543,18 @@ index 0000000000..56c60b345f + return; + } + ++ if (runstate_check(RUN_STATE_INMIGRATE)) { ++ error_setg(errp, "There's an incoming migration in progress"); ++ return; ++ } ++ + /* initialize snapshot info */ + snap_state.bs_pos = 0; + snap_state.total_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME); + snap_state.blocker = NULL; + snap_state.target_close_wait = (QemuCoSleep){ .to_wake = NULL }; + snap_state.skip_vm_start = has_skip_vm_start && skip_vm_start; ++ snap_state.vm_old_state = RUN_STATE__MAX; + + if (snap_state.error) { + error_free(snap_state.error); @@ -542,7 +562,7 @@ index 0000000000..56c60b345f + } + + if (!statefile) { -+ snap_state.vm_needs_start = runstate_is_running(); ++ snap_state.vm_old_state = runstate_get(); + vm_stop(RUN_STATE_SAVE_VM); + snap_state.state = SAVE_STATE_COMPLETED; + return; @@ -703,12 +723,7 @@ index 0000000000..56c60b345f + return; + } + -+ if (snap_state.vm_needs_start) { -+ if (!should_skip_vm_start()) { -+ vm_start(); -+ } -+ snap_state.vm_needs_start = false; -+ } ++ restore_vm_old_state(); + + qemu_coroutine_enter(wait_for_close); +} diff --git a/debian/patches/pve/0018-PVE-add-optional-buffer-size-to-QEMUFile.patch b/debian/patches/pve/0018-PVE-add-optional-buffer-size-to-QEMUFile.patch index 4345f42..e29c721 100644 --- a/debian/patches/pve/0018-PVE-add-optional-buffer-size-to-QEMUFile.patch +++ b/debian/patches/pve/0018-PVE-add-optional-buffer-size-to-QEMUFile.patch @@ -186,10 +186,10 @@ index a390554208..eda093b16a 100644 G_DEFINE_AUTOPTR_CLEANUP_FUNC(QEMUFile, qemu_fclose) diff --git a/migration/savevm-async.c b/migration/savevm-async.c -index 56c60b345f..a460970dd5 100644 +index fe455016ab..91a3f404fb 100644 --- a/migration/savevm-async.c +++ b/migration/savevm-async.c -@@ -425,7 +425,7 @@ void qmp_savevm_start(const char *statefile, bool has_skip_vm_start, +@@ -444,7 +444,7 @@ void qmp_savevm_start(const char *statefile, bool has_skip_vm_start, QIOChannel *ioc = QIO_CHANNEL(qio_channel_savevm_async_new(snap_state.target, &snap_state.bs_pos)); @@ -198,7 +198,7 @@ index 56c60b345f..a460970dd5 100644 object_unref(ioc); if (!snap_state.file) { -@@ -589,7 +589,7 @@ int load_snapshot_from_blockdev(const char *filename, Error **errp) +@@ -603,7 +603,7 @@ int load_snapshot_from_blockdev(const char *filename, Error **errp) /* restore the VM state */ QIOChannel *ioc = QIO_CHANNEL(qio_channel_savevm_async_new(be, &bs_pos)); diff --git a/debian/patches/pve/0046-savevm-async-reuse-migration-blocker-check-for-snaps.patch b/debian/patches/pve/0046-savevm-async-reuse-migration-blocker-check-for-snaps.patch index d87875b..410f13b 100644 --- a/debian/patches/pve/0046-savevm-async-reuse-migration-blocker-check-for-snaps.patch +++ b/debian/patches/pve/0046-savevm-async-reuse-migration-blocker-check-for-snaps.patch @@ -136,10 +136,10 @@ index b6888daced..80eb0dcd1f 100644 bool migration_in_postcopy(void); bool migration_postcopy_is_alive(MigrationStatus state); diff --git a/migration/savevm-async.c b/migration/savevm-async.c -index a460970dd5..b703c5d5a3 100644 +index 91a3f404fb..6c16000898 100644 --- a/migration/savevm-async.c +++ b/migration/savevm-async.c -@@ -390,7 +390,7 @@ void qmp_savevm_start(const char *statefile, bool has_skip_vm_start, +@@ -409,7 +409,7 @@ void qmp_savevm_start(const char *statefile, bool has_skip_vm_start, return; } -- 2.47.3
