mirror of
https://gitlab.com/qemu-project/qemu
synced 2024-09-06 01:43:39 +00:00
migration: stop vm for cpr
When migration for cpr is initiated, stop the vm and set state RUN_STATE_FINISH_MIGRATE before ram is saved. This eliminates the possibility of ram and device state being out of sync, and guarantees that a guest in the suspended state remains suspended, because qmp_cont rejects a cont command in the RUN_STATE_FINISH_MIGRATE state. Signed-off-by: Steve Sistare <steven.sistare@oracle.com> Reviewed-by: Peter Xu <peterx@redhat.com> Link: https://lore.kernel.org/r/1708622920-68779-11-git-send-email-steven.sistare@oracle.com Signed-off-by: Peter Xu <peterx@redhat.com>
This commit is contained in:
parent
4af667f87c
commit
9867d4ddd0
|
@ -60,6 +60,7 @@ void migration_object_init(void);
|
|||
void migration_shutdown(void);
|
||||
bool migration_is_idle(void);
|
||||
bool migration_is_active(MigrationState *);
|
||||
bool migrate_mode_is_cpr(MigrationState *);
|
||||
|
||||
typedef enum MigrationEventType {
|
||||
MIG_EVENT_PRECOPY_SETUP,
|
||||
|
|
|
@ -167,11 +167,19 @@ static gint page_request_addr_cmp(gconstpointer ap, gconstpointer bp)
|
|||
return (a > b) - (a < b);
|
||||
}
|
||||
|
||||
int migration_stop_vm(RunState state)
|
||||
static int migration_stop_vm(MigrationState *s, RunState state)
|
||||
{
|
||||
int ret = vm_stop_force_state(state);
|
||||
int ret;
|
||||
|
||||
migration_downtime_start(s);
|
||||
|
||||
s->vm_old_state = runstate_get();
|
||||
global_state_store();
|
||||
|
||||
ret = vm_stop_force_state(state);
|
||||
|
||||
trace_vmstate_downtime_checkpoint("src-vm-stopped");
|
||||
trace_migration_completion_vm_stop(ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -1602,6 +1610,11 @@ bool migration_is_active(MigrationState *s)
|
|||
s->state == MIGRATION_STATUS_POSTCOPY_ACTIVE);
|
||||
}
|
||||
|
||||
bool migrate_mode_is_cpr(MigrationState *s)
|
||||
{
|
||||
return s->parameters.mode == MIG_MODE_CPR_REBOOT;
|
||||
}
|
||||
|
||||
int migrate_init(MigrationState *s, Error **errp)
|
||||
{
|
||||
int ret;
|
||||
|
@ -2454,10 +2467,7 @@ static int postcopy_start(MigrationState *ms, Error **errp)
|
|||
bql_lock();
|
||||
trace_postcopy_start_set_run();
|
||||
|
||||
migration_downtime_start(ms);
|
||||
|
||||
global_state_store();
|
||||
ret = migration_stop_vm(RUN_STATE_FINISH_MIGRATE);
|
||||
ret = migration_stop_vm(ms, RUN_STATE_FINISH_MIGRATE);
|
||||
if (ret < 0) {
|
||||
goto fail;
|
||||
}
|
||||
|
@ -2652,16 +2662,13 @@ static int migration_completion_precopy(MigrationState *s,
|
|||
int ret;
|
||||
|
||||
bql_lock();
|
||||
migration_downtime_start(s);
|
||||
|
||||
s->vm_old_state = runstate_get();
|
||||
global_state_store();
|
||||
|
||||
ret = migration_stop_vm(RUN_STATE_FINISH_MIGRATE);
|
||||
trace_migration_completion_vm_stop(ret);
|
||||
if (!migrate_mode_is_cpr(s)) {
|
||||
ret = migration_stop_vm(s, RUN_STATE_FINISH_MIGRATE);
|
||||
if (ret < 0) {
|
||||
goto out_unlock;
|
||||
}
|
||||
}
|
||||
|
||||
ret = migration_maybe_pause(s, current_active_state,
|
||||
MIGRATION_STATUS_DEVICE);
|
||||
|
@ -3500,15 +3507,10 @@ static void *bg_migration_thread(void *opaque)
|
|||
s->setup_time = qemu_clock_get_ms(QEMU_CLOCK_HOST) - setup_start;
|
||||
|
||||
trace_migration_thread_setup_complete();
|
||||
migration_downtime_start(s);
|
||||
|
||||
bql_lock();
|
||||
|
||||
s->vm_old_state = runstate_get();
|
||||
|
||||
global_state_store();
|
||||
/* Forcibly stop VM before saving state of vCPUs and devices */
|
||||
if (migration_stop_vm(RUN_STATE_PAUSED)) {
|
||||
if (migration_stop_vm(s, RUN_STATE_PAUSED)) {
|
||||
goto fail;
|
||||
}
|
||||
/*
|
||||
|
@ -3584,6 +3586,7 @@ void migrate_fd_connect(MigrationState *s, Error *error_in)
|
|||
Error *local_err = NULL;
|
||||
uint64_t rate_limit;
|
||||
bool resume = s->state == MIGRATION_STATUS_POSTCOPY_PAUSED;
|
||||
int ret;
|
||||
|
||||
/*
|
||||
* If there's a previous error, free it and prepare for another one.
|
||||
|
@ -3655,6 +3658,14 @@ void migrate_fd_connect(MigrationState *s, Error *error_in)
|
|||
return;
|
||||
}
|
||||
|
||||
if (migrate_mode_is_cpr(s)) {
|
||||
ret = migration_stop_vm(s, RUN_STATE_FINISH_MIGRATE);
|
||||
if (ret < 0) {
|
||||
error_setg(&local_err, "migration_stop_vm failed, error %d", -ret);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
if (migrate_background_snapshot()) {
|
||||
qemu_thread_create(&s->thread, "bg_snapshot",
|
||||
bg_migration_thread, s, QEMU_THREAD_JOINABLE);
|
||||
|
|
|
@ -541,6 +541,4 @@ int migration_rp_wait(MigrationState *s);
|
|||
*/
|
||||
void migration_rp_kick(MigrationState *s);
|
||||
|
||||
int migration_stop_vm(RunState state);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue