[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH COLO-Frame v16 19/35] COLO: Implement failover work
From: |
zhanghailiang |
Subject: |
[Qemu-devel] [PATCH COLO-Frame v16 19/35] COLO: Implement failover work for Primary VM |
Date: |
Fri, 8 Apr 2016 14:26:21 +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>
Reviewed-by: Dr. David Alan Gilbert <address@hidden>
---
v13:
- Add Reviewed-by tag
v12:
- Fix error report and remove unnecessary check in
primary_vm_do_failover() (Dave's suggestion)
v11:
- Don't call migration_end() in primary_vm_do_failover(),
The cleanup work will be done in migration_thread().
- Remove vm_start() in primary_vm_do_failover() which also been
done in migraiton_thread()
v10:
- Call migration_end() in primary_vm_do_failover()
---
include/migration/colo.h | 3 +++
include/migration/failover.h | 1 +
migration/colo-failover.c | 7 +++++-
migration/colo.c | 53 +++++++++++++++++++++++++++++++++++++++++---
4 files changed, 60 insertions(+), 4 deletions(-)
diff --git a/include/migration/colo.h b/include/migration/colo.h
index e9ac2c3..e32eef4 100644
--- a/include/migration/colo.h
+++ b/include/migration/colo.h
@@ -32,4 +32,7 @@ void *colo_process_incoming_thread(void *opaque);
bool migration_incoming_in_colo_state(void);
COLOMode get_colo_mode(void);
+
+/* failover */
+void colo_do_failover(MigrationState *s);
#endif
diff --git a/include/migration/failover.h b/include/migration/failover.h
index fe71bb4..c4bd81e 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 69aac55..fa84172 100644
--- a/migration/colo-failover.c
+++ b/migration/colo-failover.c
@@ -33,7 +33,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)
@@ -68,6 +68,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_x_colo_lost_heartbeat(Error **errp)
{
if (get_colo_mode() == COLO_MODE_UNKNOWN) {
diff --git a/migration/colo.c b/migration/colo.c
index af1f8c2..bdde182 100644
--- a/migration/colo.c
+++ b/migration/colo.c
@@ -41,6 +41,40 @@ 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;
+
+ migrate_set_state(&s->state, MIGRATION_STATUS_COLO,
+ MIGRATION_STATUS_COMPLETED);
+
+ old_state = failover_set_state(FAILOVER_STATUS_HANDLING,
+ FAILOVER_STATUS_COMPLETED);
+ if (old_state != FAILOVER_STATUS_HANDLING) {
+ error_report("Incorrect state (%d) while doing failover for Primary
VM",
+ 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();
+ }
+}
+
static void colo_send_message(QEMUFile *f, COLOMessage msg,
Error **errp)
{
@@ -167,9 +201,20 @@ static int colo_do_checkpoint_transaction(MigrationState
*s,
}
qemu_mutex_lock_iothread();
+ if (failover_request_is_active()) {
+ qemu_mutex_unlock_iothread();
+ goto out;
+ }
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()) {
+ goto out;
+ }
/* Disable block migration */
s->params.blk = 0;
@@ -267,6 +312,11 @@ static void colo_process_checkpoint(MigrationState *s)
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 <
s->parameters[MIGRATION_PARAMETER_X_CHECKPOINT_DELAY]) {
@@ -289,9 +339,6 @@ out:
if (local_err) {
error_report_err(local_err);
}
- migrate_set_state(&s->state, MIGRATION_STATUS_COLO,
- MIGRATION_STATUS_COMPLETED);
-
qsb_free(buffer);
buffer = NULL;
--
1.8.3.1
- [Qemu-devel] [PATCH COLO-Frame v16 16/35] COLO: synchronize PVM's state to SVM periodically, (continued)
- [Qemu-devel] [PATCH COLO-Frame v16 16/35] COLO: synchronize PVM's state to SVM periodically, zhanghailiang, 2016/04/08
- [Qemu-devel] [PATCH COLO-Frame v16 26/35] savevm: Introduce two helper functions for save/find loadvm_handlers entry, zhanghailiang, 2016/04/08
- [Qemu-devel] [PATCH COLO-Frame v16 27/35] migration/savevm: Add new helpers to process the different stages of loadvm, zhanghailiang, 2016/04/08
- [Qemu-devel] [PATCH COLO-Frame v16 28/35] migration/savevm: Export two helper functions for savevm process, zhanghailiang, 2016/04/08
- [Qemu-devel] [PATCH COLO-Frame v16 24/35] COLO: Process shutdown command for VM in COLO state, zhanghailiang, 2016/04/08
- [Qemu-devel] [PATCH COLO-Frame v16 21/35] qmp event: Add COLO_EXIT event to notify users while exited from COLO, zhanghailiang, 2016/04/08
- [Qemu-devel] [PATCH COLO-Frame v16 19/35] COLO: Implement failover work for Primary VM,
zhanghailiang <=
- [Qemu-devel] [PATCH COLO-Frame v16 11/35] COLO: Load PVM's dirty pages into SVM's RAM cache temporarily, zhanghailiang, 2016/04/08
- [Qemu-devel] [PATCH COLO-Frame v16 17/35] COLO failover: Introduce a new command to trigger a failover, zhanghailiang, 2016/04/08
- [Qemu-devel] [PATCH COLO-Frame v16 18/35] COLO failover: Introduce state to record failover process, zhanghailiang, 2016/04/08
- [Qemu-devel] [PATCH COLO-Frame v16 25/35] COLO: Update the global runstate after going into colo state, zhanghailiang, 2016/04/08
- [Qemu-devel] [PATCH COLO-Frame v16 30/35] COLO: Split qemu_savevm_state_begin out of checkpoint process, zhanghailiang, 2016/04/08
- [Qemu-devel] [PATCH COLO-Frame v16 32/35] net: Add notifier/callback for netdev init, zhanghailiang, 2016/04/08
- [Qemu-devel] [PATCH COLO-Frame v16 15/35] COLO: Add checkpoint-delay parameter for migrate-set-parameters, zhanghailiang, 2016/04/08