qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH COLO-Frame v6 05/31] migration: Integrate COLO check


From: zhanghailiang
Subject: [Qemu-devel] [PATCH COLO-Frame v6 05/31] migration: Integrate COLO checkpoint process into loadvm
Date: Thu, 18 Jun 2015 16:58:29 +0800

Switch from normal migration loadvm process into COLO checkpoint process if
COLO mode is enabled.

Signed-off-by: zhanghailiang <address@hidden>
Signed-off-by: Li Zhijian <address@hidden>
Signed-off-by: Lai Jiangshan <address@hidden>
Signed-off-by: Yang Hongyang <address@hidden>
---
 include/migration/migration-colo.h | 13 +++++++++++++
 migration/colo-comm.c              | 10 ++++++++++
 migration/colo.c                   | 20 ++++++++++++++++++++
 migration/migration.c              | 26 +++++++++++++++++++++++++-
 stubs/migration-colo.c             | 10 ++++++++++
 trace-events                       |  1 +
 6 files changed, 79 insertions(+), 1 deletion(-)

diff --git a/include/migration/migration-colo.h 
b/include/migration/migration-colo.h
index b4f75c2..b2798f7 100644
--- a/include/migration/migration-colo.h
+++ b/include/migration/migration-colo.h
@@ -15,11 +15,24 @@
 
 #include "qemu-common.h"
 #include "migration/migration.h"
+#include "block/coroutine.h"
+#include "qemu/thread.h"
 
 bool colo_supported(void);
 void colo_info_mig_init(void);
 
+struct colo_incoming {
+    QEMUFile *file;
+    QemuThread thread;
+};
+
 void colo_init_checkpointer(MigrationState *s);
 bool migrate_in_colo_state(void);
 
+/* loadvm */
+extern Coroutine *migration_incoming_co;
+bool loadvm_enable_colo(void);
+void loadvm_exit_colo(void);
+void *colo_process_incoming_checkpoints(void *opaque);
+bool loadvm_in_colo_state(void);
 #endif
diff --git a/migration/colo-comm.c b/migration/colo-comm.c
index 0b76eb4..f8be027 100644
--- a/migration/colo-comm.c
+++ b/migration/colo-comm.c
@@ -45,3 +45,13 @@ void colo_info_mig_init(void)
     register_savevm_live(NULL, "colo", -1, 1,
                          &savevm_colo_info_handlers, NULL);
 }
+
+bool loadvm_enable_colo(void)
+{
+    return colo_requested;
+}
+
+void loadvm_exit_colo(void)
+{
+    colo_requested = false;
+}
diff --git a/migration/colo.c b/migration/colo.c
index 1ff4e55..45f9efd 100644
--- a/migration/colo.c
+++ b/migration/colo.c
@@ -13,8 +13,10 @@
 #include "sysemu/sysemu.h"
 #include "migration/migration-colo.h"
 #include "trace.h"
+#include "qemu/error-report.h"
 
 static QEMUBH *colo_bh;
+static Coroutine *colo;
 
 bool colo_supported(void)
 {
@@ -27,6 +29,11 @@ bool migrate_in_colo_state(void)
     return (s->state == MIGRATION_STATUS_COLO);
 }
 
+bool loadvm_in_colo_state(void)
+{
+    return colo != NULL;
+}
+
 static void *colo_thread(void *opaque)
 {
     MigrationState *s = opaque;
@@ -71,3 +78,16 @@ void colo_init_checkpointer(MigrationState *s)
     colo_bh = qemu_bh_new(colo_start_checkpointer, s);
     qemu_bh_schedule(colo_bh);
 }
+
+void *colo_process_incoming_checkpoints(void *opaque)
+{
+    colo = qemu_coroutine_self();
+    assert(colo != NULL);
+
+    /* TODO: COLO checkpoint restore loop */
+
+    colo = NULL;
+    loadvm_exit_colo();
+
+    return NULL;
+}
diff --git a/migration/migration.c b/migration/migration.c
index 0589fc8..72763b6 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -135,6 +135,7 @@ void qemu_start_incoming_migration(const char *uri, Error 
**errp)
     }
 }
 
+Coroutine *migration_incoming_co;
 static void process_incoming_migration_co(void *opaque)
 {
     QEMUFile *f = opaque;
@@ -145,7 +146,24 @@ static void process_incoming_migration_co(void *opaque)
 
     ret = qemu_loadvm_state(f);
 
-    qemu_fclose(f);
+    /* we get colo info, and know if we are in colo mode */
+    if (loadvm_enable_colo()) {
+        struct colo_incoming *colo_in = g_malloc0(sizeof(*colo_in));
+
+        colo_in->file = f;
+        migration_incoming_co = qemu_coroutine_self();
+        qemu_thread_create(&colo_in->thread, "colo incoming",
+             colo_process_incoming_checkpoints, colo_in, QEMU_THREAD_JOINABLE);
+        qemu_coroutine_yield();
+        migration_incoming_co = NULL;
+#if 0
+        /* FIXME  wait checkpoint incoming thread exit, and free resource */
+        qemu_thread_join(&colo_in->thread);
+        g_free(colo_in);
+#endif
+    } else {
+        qemu_fclose(f);
+    }
     free_xbzrle_decoded_buf();
     migration_incoming_state_destroy();
 
@@ -593,6 +611,12 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
         return;
     }
 
+    if (loadvm_in_colo_state()) {
+        error_setg(errp, "Secondary VM is not allowed to do migration while"
+                   "in COLO status");
+        return;
+    }
+
     if (runstate_check(RUN_STATE_INMIGRATE)) {
         error_setg(errp, "Guest is waiting for an incoming migration");
         return;
diff --git a/stubs/migration-colo.c b/stubs/migration-colo.c
index c0bb8d8..827ee1f 100644
--- a/stubs/migration-colo.c
+++ b/stubs/migration-colo.c
@@ -22,6 +22,16 @@ bool migrate_in_colo_state(void)
     return false;
 }
 
+bool loadvm_in_colo_state(void)
+{
+    return false;
+}
+
 void colo_init_checkpointer(MigrationState *s)
 {
 }
+
+void *colo_process_incoming_checkpoints(void *opaque)
+{
+    return NULL;
+}
diff --git a/trace-events b/trace-events
index ae0a460..af05a12 100644
--- a/trace-events
+++ b/trace-events
@@ -1471,6 +1471,7 @@ colo_info_load(const char *msg) "%s"
 
 # migration/colo.c
 colo_vm_state_change(const char *old, const char *new) "Change '%s' => '%s'"
+colo_receive_message(const char *msg) "Receive '%s'"
 
 # kvm-all.c
 kvm_ioctl(int type, void *arg) "type 0x%x, arg %p"
-- 
1.7.12.4





reply via email to

[Prev in Thread] Current Thread [Next in Thread]