[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH COLO-Frame v9 19/32] COLO: Implement failover work f
From: |
zhanghailiang |
Subject: |
[Qemu-devel] [PATCH COLO-Frame v9 19/32] COLO: Implement failover work for Primary VM |
Date: |
Wed, 2 Sep 2015 16:23:06 +0800 |
For PVM, if there is failover request from users.
The colo thread will exit the loop while the failover BH does the
cleanup work and resumes VM.
Signed-off-by: zhanghailiang <address@hidden>
Signed-off-by: Li Zhijian <address@hidden>
---
include/migration/colo.h | 4 +++
include/migration/failover.h | 1 +
migration/colo-failover.c | 7 ++++-
migration/colo.c | 64 +++++++++++++++++++++++++++++++++++++++-----
4 files changed, 69 insertions(+), 7 deletions(-)
diff --git a/include/migration/colo.h b/include/migration/colo.h
index 21f5c5d..5f6072e 100644
--- a/include/migration/colo.h
+++ b/include/migration/colo.h
@@ -37,4 +37,8 @@ int get_colo_mode(void);
int colo_init_ram_cache(void);
void colo_release_ram_cache(void);
void colo_flush_ram_cache(void);
+
+/* failover */
+void colo_do_failover(MigrationState *s);
+
#endif
diff --git a/include/migration/failover.h b/include/migration/failover.h
index 882c625..fba3931 100644
--- a/include/migration/failover.h
+++ b/include/migration/failover.h
@@ -26,5 +26,6 @@ void failover_init_state(void);
int failover_set_state(int old_state, int new_state);
int failover_get_state(void);
void failover_request_active(Error **errp);
+bool failover_request_is_active(void);
#endif
diff --git a/migration/colo-failover.c b/migration/colo-failover.c
index e055551..7299674 100644
--- a/migration/colo-failover.c
+++ b/migration/colo-failover.c
@@ -32,7 +32,7 @@ static void colo_failover_bh(void *opaque)
error_report(" Unkown error for failover, old_state=%d", old_state);
return;
}
- /*TODO: Do failover work */
+ colo_do_failover(NULL);
}
void failover_request_active(Error **errp)
@@ -67,6 +67,11 @@ int failover_get_state(void)
return atomic_read(&failover_state);
}
+bool failover_request_is_active(void)
+{
+ return ((failover_get_state() != FAILOVER_STATUS_NONE));
+}
+
void qmp_colo_lost_heartbeat(Error **errp)
{
if (get_colo_mode() == COLO_MODE_UNKNOWN) {
diff --git a/migration/colo.c b/migration/colo.c
index 6c48dca..6aa6d18 100644
--- a/migration/colo.c
+++ b/migration/colo.c
@@ -48,6 +48,45 @@ bool migration_incoming_in_colo_state(void)
return (mis && (mis->state == MIGRATION_STATUS_COLO));
}
+static bool colo_runstate_is_stopped(void)
+{
+ return runstate_check(RUN_STATE_COLO) || !runstate_is_running();
+}
+
+static void primary_vm_do_failover(void)
+{
+ MigrationState *s = migrate_get_current();
+ int old_state;
+
+ if (s->state != MIGRATION_STATUS_FAILED) {
+ migrate_set_state(&s->state, MIGRATION_STATUS_COLO,
+ MIGRATION_STATUS_COMPLETED);
+ }
+ qemu_bh_schedule(s->cleanup_bh);
+
+ vm_start();
+
+ old_state = failover_set_state(FAILOVER_STATUS_HANDLING,
+ FAILOVER_STATUS_COMPLETED);
+ if (old_state != FAILOVER_STATUS_HANDLING) {
+ error_report("Serious error while do failover for Primary VM,"
+ "old_state: %d", old_state);
+ return;
+ }
+}
+
+void colo_do_failover(MigrationState *s)
+{
+ /* Make sure vm stopped while failover */
+ if (!colo_runstate_is_stopped()) {
+ vm_stop_force_state(RUN_STATE_COLO);
+ }
+
+ if (get_colo_mode() == COLO_MODE_PRIMARY) {
+ primary_vm_do_failover();
+ }
+}
+
/* colo checkpoint control helper */
static int colo_ctl_put(QEMUFile *f, uint32_t cmd, uint64_t value)
{
@@ -132,9 +171,23 @@ static int colo_do_checkpoint_transaction(MigrationState
*s,
/* suspend and save vm state to colo buffer */
qemu_mutex_lock_iothread();
+ if (failover_request_is_active()) {
+ qemu_mutex_unlock_iothread();
+ ret = -1;
+ goto out;
+ }
+ /* suspend and save vm state to colo buffer */
vm_stop_force_state(RUN_STATE_COLO);
qemu_mutex_unlock_iothread();
trace_colo_vm_state_change("run", "stop");
+ /*
+ * failover request bh could be called after
+ * vm_stop_force_state so we check failover_request_is_active() again.
+ */
+ if (failover_request_is_active()) {
+ ret = -1;
+ goto out;
+ }
/* Disable block migration */
s->params.blk = 0;
@@ -234,6 +287,11 @@ static void *colo_thread(void *opaque)
trace_colo_vm_state_change("stop", "run");
while (s->state == MIGRATION_STATUS_COLO) {
+ if (failover_request_is_active()) {
+ error_report("failover request");
+ goto out;
+ }
+
current_time = qemu_clock_get_ms(QEMU_CLOCK_HOST);
if (current_time - checkpoint_time < CHECKPOINT_MAX_PEROID) {
g_usleep(100000);
@@ -251,8 +309,6 @@ out:
if (ret < 0) {
error_report("Detect some error: %s", strerror(-ret));
}
- migrate_set_state(&s->state, MIGRATION_STATUS_COLO,
- MIGRATION_STATUS_COMPLETED);
qsb_free(buffer);
buffer = NULL;
@@ -261,10 +317,6 @@ out:
qemu_fclose(s->from_dst_file);
}
- qemu_mutex_lock_iothread();
- qemu_bh_schedule(s->cleanup_bh);
- qemu_mutex_unlock_iothread();
-
return NULL;
}
--
1.8.3.1
- [Qemu-devel] [PATCH COLO-Frame v9 11/32] QEMUSizedBuffer: Introduce two help functions for qsb, (continued)
- [Qemu-devel] [PATCH COLO-Frame v9 11/32] QEMUSizedBuffer: Introduce two help functions for qsb, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 12/32] COLO: Save PVM state to secondary side when do checkpoint, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 08/32] COLO/migration: establish a new communication path from destination to source, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 02/32] migration: Introduce capability 'colo' to migration, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 06/32] migration: Integrate COLO checkpoint process into loadvm, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 16/32] COLO: synchronize PVM's state to SVM periodically, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 14/32] COLO: Load VMState into qsb before restore it, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 15/32] COLO: Flush PVM's cached RAM into SVM's memory, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 07/32] migration: Rename the'file' member of MigrationState and MigrationIncomingState, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 13/32] COLO: Load PVM's dirty pages into SVM's RAM cache temporarily, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 19/32] COLO: Implement failover work for Primary VM,
zhanghailiang <=
- [Qemu-devel] [PATCH COLO-Frame v9 20/32] COLO: Implement failover work for Secondary VM, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 17/32] COLO failover: Introduce a new command to trigger a failover, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 21/32] COLO: implement default failover treatment, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 10/32] COLO: Add a new RunState RUN_STATE_COLO, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 23/32] COLO failover: Shutdown related socket fd when do failover, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 18/32] COLO failover: Introduce state to record failover process, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 24/32] COLO failover: Don't do failover during loading VM's state, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 22/32] qmp event: Add event notification for COLO error, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 26/32] COLO: Implement shutdown checkpoint, zhanghailiang, 2015/09/02
- [Qemu-devel] [PATCH COLO-Frame v9 30/32] COLO: Split qemu_savevm_state_begin out of checkpoint process, zhanghailiang, 2015/09/02