[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 08/21] migration: Wait for semaphore before completin
From: |
Juan Quintela |
Subject: |
[Qemu-devel] [PULL 08/21] migration: Wait for semaphore before completing migration |
Date: |
Mon, 23 Oct 2017 18:07:47 +0200 |
From: "Dr. David Alan Gilbert" <address@hidden>
Wait for a semaphore before completing the migration,
if the previously added capability was enabled.
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
Reviewed-by: Peter Xu <address@hidden>
Reviewed-by: Juan Quintela <address@hidden>
Signed-off-by: Juan Quintela <address@hidden>
---
migration/migration.c | 38 ++++++++++++++++++++++++++++++++++++++
migration/migration.h | 3 +++
2 files changed, 41 insertions(+)
diff --git a/migration/migration.c b/migration/migration.c
index f15372e007..ef84d2c1fb 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -1958,6 +1958,39 @@ fail:
}
/**
+ * 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.
* The caller 'breaks' the loop when this returns.
*
@@ -1983,6 +2016,9 @@ static void migration_completion(MigrationState *s, int
current_active_state,
bool inactivate = !migrate_colo_enabled();
ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
if (ret >= 0) {
+ ret = migration_maybe_pause(s, ¤t_active_state);
+ }
+ if (ret >= 0) {
qemu_file_set_rate_limit(s->to_dst_file, INT64_MAX);
ret = qemu_savevm_state_complete_precopy(s->to_dst_file, false,
inactivate);
@@ -2363,6 +2399,7 @@ static void migration_instance_finalize(Object *obj)
g_free(params->tls_hostname);
g_free(params->tls_creds);
+ qemu_sem_destroy(&ms->pause_sem);
}
static void migration_instance_init(Object *obj)
@@ -2373,6 +2410,7 @@ static void migration_instance_init(Object *obj)
ms->state = MIGRATION_STATUS_NONE;
ms->xbzrle_cache_size = DEFAULT_MIGRATE_CACHE_SIZE;
ms->mbps = -1;
+ qemu_sem_init(&ms->pause_sem, 0);
params->tls_hostname = g_strdup("");
params->tls_creds = g_strdup("");
diff --git a/migration/migration.h b/migration/migration.h
index 969866303e..cd988a99b9 100644
--- a/migration/migration.h
+++ b/migration/migration.h
@@ -121,6 +121,9 @@ struct MigrationState
/* Flag set once the migration thread called bdrv_inactivate_all */
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 */
QemuSemaphore colo_exit_sem;
--
2.13.6
- [Qemu-devel] [PULL 00/21] Migration pull request, Juan Quintela, 2017/10/23
- [Qemu-devel] [PULL 01/21] migration: Fix migrate_test_apply for multifd parameters, Juan Quintela, 2017/10/23
- [Qemu-devel] [PULL 03/21] migration: Make cache size elements use the right types, Juan Quintela, 2017/10/23
- [Qemu-devel] [PULL 04/21] migration: Move xbzrle cache resize error handling to xbzrle_cache_resize, Juan Quintela, 2017/10/23
- [Qemu-devel] [PULL 02/21] migratiom: Remove max_item_age parameter, Juan Quintela, 2017/10/23
- [Qemu-devel] [PULL 05/21] migration: Make cache_init() take an error parameter, Juan Quintela, 2017/10/23
- [Qemu-devel] [PULL 06/21] migration: Add 'pause-before-switchover' capability, Juan Quintela, 2017/10/23
- [Qemu-devel] [PULL 08/21] migration: Wait for semaphore before completing migration,
Juan Quintela <=
- [Qemu-devel] [PULL 09/21] migration: migrate-continue, Juan Quintela, 2017/10/23
- [Qemu-devel] [PULL 10/21] migrate: HMP migate_continue, Juan Quintela, 2017/10/23
- [Qemu-devel] [PULL 07/21] migration: Add 'pre-switchover' and 'device' statuses, Juan Quintela, 2017/10/23
- [Qemu-devel] [PULL 11/21] migration: allow cancel to unpause, Juan Quintela, 2017/10/23
- [Qemu-devel] [PULL 12/21] migration: pause-before-switchover for postcopy, Juan Quintela, 2017/10/23
- [Qemu-devel] [PULL 13/21] migration: provide ram_state_init(), Juan Quintela, 2017/10/23
- [Qemu-devel] [PULL 14/21] migration: provide ram_state_cleanup, Juan Quintela, 2017/10/23
- [Qemu-devel] [PULL 15/21] migration: clean up xbzrle cache init/destroy, Juan Quintela, 2017/10/23
- [Qemu-devel] [PULL 16/21] migration: new ram_init_bitmaps(), Juan Quintela, 2017/10/23
- [Qemu-devel] [PULL 17/21] migration: postcopy_place_page factoring out, Juan Quintela, 2017/10/23