1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Stefan Reiter <s.reiter@proxmox.com>
3 Date: Wed, 8 Apr 2020 15:29:03 +0200
4 Subject: [PATCH] PVE: savevm-async: set up migration state
6 code mostly adapted from upstream savevm.c
8 Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
10 savevm-async.c | 30 ++++++++++++++++++++++++++++--
11 1 file changed, 28 insertions(+), 2 deletions(-)
13 diff --git a/savevm-async.c b/savevm-async.c
14 index 790e27ae37..a38b15d652 100644
17 @@ -225,6 +225,7 @@ static void *process_savevm_thread(void *opaque)
21 + MigrationState *ms = migrate_get_current();
23 rcu_register_thread();
25 @@ -234,8 +235,7 @@ static void *process_savevm_thread(void *opaque)
28 save_snapshot_error("qemu_savevm_state_setup failed");
29 - rcu_unregister_thread();
34 while (snap_state.state == SAVE_STATE_ACTIVE) {
35 @@ -287,6 +287,12 @@ static void *process_savevm_thread(void *opaque)
36 qemu_bh_schedule(snap_state.cleanup_bh);
37 qemu_mutex_unlock_iothread();
40 + /* set migration state accordingly and clear soon-to-be stale file */
41 + migrate_set_state(&ms->state, MIGRATION_STATUS_SETUP,
42 + ret ? MIGRATION_STATUS_FAILED : MIGRATION_STATUS_COMPLETED);
43 + ms->to_dst_file = NULL;
45 rcu_unregister_thread();
48 @@ -294,6 +300,7 @@ static void *process_savevm_thread(void *opaque)
49 void qmp_savevm_start(bool has_statefile, const char *statefile, Error **errp)
51 Error *local_err = NULL;
52 + MigrationState *ms = migrate_get_current();
54 int bdrv_oflags = BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_NO_FLUSH;
56 @@ -303,6 +310,17 @@ void qmp_savevm_start(bool has_statefile, const char *statefile, Error **errp)
60 + if (migration_is_running(ms->state)) {
61 + error_set(errp, ERROR_CLASS_GENERIC_ERROR, QERR_MIGRATION_ACTIVE);
65 + if (migrate_use_block()) {
66 + error_set(errp, ERROR_CLASS_GENERIC_ERROR,
67 + "Block migration and snapshots are incompatible");
71 /* initialize snapshot info */
72 snap_state.saved_vm_running = runstate_is_running();
73 snap_state.bs_pos = 0;
74 @@ -341,6 +359,14 @@ void qmp_savevm_start(bool has_statefile, const char *statefile, Error **errp)
79 + * qemu_savevm_* paths use migration code and expect a migration state.
80 + * State is cleared in process_savevm_thread, but has to be initialized
81 + * here (blocking main thread, from QMP) to avoid race conditions.
84 + memset(&ram_counters, 0, sizeof(ram_counters));
85 + ms->to_dst_file = snap_state.file;
87 error_setg(&snap_state.blocker, "block device is in use by savevm");
88 blk_op_block_all(snap_state.target, snap_state.blocker);