mirror of https://gitee.com/openkylin/qemu.git
migration: Wait for semaphore before completing migration
Wait for a semaphore before completing the migration, if the previously added capability was enabled. Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Reviewed-by: Peter Xu <peterx@redhat.com> Reviewed-by: Juan Quintela <quintela@redhat.com> Signed-off-by: Juan Quintela <quintela@redhat.com>
This commit is contained in:
parent
31e060774c
commit
e91d8951d5
|
@ -1957,6 +1957,39 @@ fail:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* migration_maybe_pause: Pause if required to by
|
||||||
|
* migrate_pause_before_switchover called with the iothread locked
|
||||||
|
* Returns: 0 on success
|
||||||
|
*/
|
||||||
|
static int migration_maybe_pause(MigrationState *s, int *current_active_state)
|
||||||
|
{
|
||||||
|
if (!migrate_pause_before_switchover()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Since leaving this state is not atomic with posting the semaphore
|
||||||
|
* it's possible that someone could have issued multiple migrate_continue
|
||||||
|
* and the semaphore is incorrectly positive at this point;
|
||||||
|
* the docs say it's undefined to reinit a semaphore that's already
|
||||||
|
* init'd, so use timedwait to eat up any existing posts.
|
||||||
|
*/
|
||||||
|
while (qemu_sem_timedwait(&s->pause_sem, 1) == 0) {
|
||||||
|
/* This block intentionally left blank */
|
||||||
|
}
|
||||||
|
|
||||||
|
qemu_mutex_unlock_iothread();
|
||||||
|
migrate_set_state(&s->state, *current_active_state,
|
||||||
|
MIGRATION_STATUS_PRE_SWITCHOVER);
|
||||||
|
qemu_sem_wait(&s->pause_sem);
|
||||||
|
migrate_set_state(&s->state, MIGRATION_STATUS_PRE_SWITCHOVER,
|
||||||
|
MIGRATION_STATUS_DEVICE);
|
||||||
|
*current_active_state = MIGRATION_STATUS_DEVICE;
|
||||||
|
qemu_mutex_lock_iothread();
|
||||||
|
|
||||||
|
return s->state == MIGRATION_STATUS_DEVICE ? 0 : -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* migration_completion: Used by migration_thread when there's not much left.
|
* migration_completion: Used by migration_thread when there's not much left.
|
||||||
* The caller 'breaks' the loop when this returns.
|
* The caller 'breaks' the loop when this returns.
|
||||||
|
@ -1982,6 +2015,9 @@ static void migration_completion(MigrationState *s, int current_active_state,
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
bool inactivate = !migrate_colo_enabled();
|
bool inactivate = !migrate_colo_enabled();
|
||||||
ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
|
ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
|
||||||
|
if (ret >= 0) {
|
||||||
|
ret = migration_maybe_pause(s, ¤t_active_state);
|
||||||
|
}
|
||||||
if (ret >= 0) {
|
if (ret >= 0) {
|
||||||
qemu_file_set_rate_limit(s->to_dst_file, INT64_MAX);
|
qemu_file_set_rate_limit(s->to_dst_file, INT64_MAX);
|
||||||
ret = qemu_savevm_state_complete_precopy(s->to_dst_file, false,
|
ret = qemu_savevm_state_complete_precopy(s->to_dst_file, false,
|
||||||
|
@ -2363,6 +2399,7 @@ static void migration_instance_finalize(Object *obj)
|
||||||
|
|
||||||
g_free(params->tls_hostname);
|
g_free(params->tls_hostname);
|
||||||
g_free(params->tls_creds);
|
g_free(params->tls_creds);
|
||||||
|
qemu_sem_destroy(&ms->pause_sem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void migration_instance_init(Object *obj)
|
static void migration_instance_init(Object *obj)
|
||||||
|
@ -2373,6 +2410,7 @@ static void migration_instance_init(Object *obj)
|
||||||
ms->state = MIGRATION_STATUS_NONE;
|
ms->state = MIGRATION_STATUS_NONE;
|
||||||
ms->xbzrle_cache_size = DEFAULT_MIGRATE_CACHE_SIZE;
|
ms->xbzrle_cache_size = DEFAULT_MIGRATE_CACHE_SIZE;
|
||||||
ms->mbps = -1;
|
ms->mbps = -1;
|
||||||
|
qemu_sem_init(&ms->pause_sem, 0);
|
||||||
|
|
||||||
params->tls_hostname = g_strdup("");
|
params->tls_hostname = g_strdup("");
|
||||||
params->tls_creds = g_strdup("");
|
params->tls_creds = g_strdup("");
|
||||||
|
|
|
@ -121,6 +121,9 @@ struct MigrationState
|
||||||
/* Flag set once the migration thread called bdrv_inactivate_all */
|
/* Flag set once the migration thread called bdrv_inactivate_all */
|
||||||
bool block_inactive;
|
bool block_inactive;
|
||||||
|
|
||||||
|
/* Migration is paused due to pause-before-switchover */
|
||||||
|
QemuSemaphore pause_sem;
|
||||||
|
|
||||||
/* The semaphore is used to notify COLO thread that failover is finished */
|
/* The semaphore is used to notify COLO thread that failover is finished */
|
||||||
QemuSemaphore colo_exit_sem;
|
QemuSemaphore colo_exit_sem;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue