static GlobalState global_state;
-int global_state_store(void)
+static void global_state_do_store(RunState state)
{
- if (!runstate_store((char *)global_state.runstate,
- sizeof(global_state.runstate))) {
- error_report("runstate name too big: %s", global_state.runstate);
- trace_migrate_state_too_big();
- return -EINVAL;
- }
- return 0;
+ const char *state_str = RunState_str(state);
+ assert(strlen(state_str) < sizeof(global_state.runstate));
+ strpadcpy((char *)global_state.runstate, sizeof(global_state.runstate),
+ state_str, '\0');
+}
+
+void global_state_store(void)
+{
+ global_state_do_store(runstate_get());
}
void global_state_store_running(void)
{
- const char *state = RunState_str(RUN_STATE_RUNNING);
- assert(strlen(state) < sizeof(global_state.runstate));
- strpadcpy((char *)global_state.runstate, sizeof(global_state.runstate),
- state, '\0');
+ global_state_do_store(RUN_STATE_RUNNING);
}
bool global_state_received(void)
s->downtime_start = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER, NULL);
s->vm_was_running = runstate_is_running();
- ret = global_state_store();
-
- if (!ret) {
- ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
- trace_migration_completion_vm_stop(ret);
- if (ret >= 0) {
- ret = migration_maybe_pause(s, ¤t_active_state,
- MIGRATION_STATUS_DEVICE);
- }
- if (ret >= 0) {
- /*
- * Inactivate disks except in COLO, and track that we
- * have done so in order to remember to reactivate
- * them if migration fails or is cancelled.
- */
- s->block_inactive = !migrate_colo();
- migration_rate_set(RATE_LIMIT_DISABLED);
- ret = qemu_savevm_state_complete_precopy(s->to_dst_file, false,
- s->block_inactive);
- }
+ global_state_store();
+
+ ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
+ trace_migration_completion_vm_stop(ret);
+ if (ret >= 0) {
+ ret = migration_maybe_pause(s, ¤t_active_state,
+ MIGRATION_STATUS_DEVICE);
+ }
+ if (ret >= 0) {
+ /*
+ * Inactivate disks except in COLO, and track that we
+ * have done so in order to remember to reactivate
+ * them if migration fails or is cancelled.
+ */
+ s->block_inactive = !migrate_colo();
+ migration_rate_set(RATE_LIMIT_DISABLED);
+ ret = qemu_savevm_state_complete_precopy(s->to_dst_file, false,
+ s->block_inactive);
}
+
qemu_mutex_unlock_iothread();
if (ret < 0) {
qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER, NULL);
s->vm_was_running = runstate_is_running();
- if (global_state_store()) {
- goto fail;
- }
+ global_state_store();
/* Forcibly stop VM before saving state of vCPUs and devices */
if (vm_stop_force_state(RUN_STATE_PAUSED)) {
goto fail;