qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH COLO-Frame v7 06/34] migration: Integrate COLO check


From: zhanghailiang
Subject: [Qemu-devel] [PATCH COLO-Frame v7 06/34] migration: Integrate COLO checkpoint process into loadvm
Date: Thu, 9 Jul 2015 11:16:14 +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/colo.h | 13 +++++++++++++
 migration/colo-comm.c    | 10 ++++++++++
 migration/colo.c         | 20 ++++++++++++++++++++
 migration/migration.c    | 44 +++++++++++++++++++++++++++++++++++---------
 stubs/migration-colo.c   | 10 ++++++++++
 trace-events             |  1 +
 6 files changed, 89 insertions(+), 9 deletions(-)

diff --git a/include/migration/colo.h b/include/migration/colo.h
index 2320594..4344d29 100644
--- a/include/migration/colo.h
+++ b/include/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 3c8e361..049e96c 100644
--- a/migration/colo-comm.c
+++ b/migration/colo-comm.c
@@ -61,3 +61,13 @@ void colo_info_mig_init(void)
 {
     vmstate_register(NULL, 0, &colo_state, &colo_info);
 }
+
+bool loadvm_enable_colo(void)
+{
+    return colo_info.colo_requested;
+}
+
+void loadvm_exit_colo(void)
+{
+    colo_info.colo_requested = 0;
+}
diff --git a/migration/colo.c b/migration/colo.c
index 33a5a48..e1ffd1f 100644
--- a/migration/colo.c
+++ b/migration/colo.c
@@ -13,8 +13,10 @@
 #include "sysemu/sysemu.h"
 #include "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 fefa47b..1140012 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -253,6 +253,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;
@@ -263,7 +264,33 @@ static void process_incoming_migration_co(void *opaque)
     migrate_generate_event(MIGRATION_STATUS_ACTIVE);
     ret = qemu_loadvm_state(f);
 
-    qemu_fclose(f);
+    if (!ret) {
+        /* Make sure all file formats flush their mutable metadata */
+        bdrv_invalidate_cache_all(&local_err);
+        if (local_err) {
+            error_report_err(local_err);
+            migrate_decompress_threads_join();
+            exit(EXIT_FAILURE);
+        }
+    }
+    /* we get colo info, and know if we are in colo mode */
+    if (!ret && 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();
 
@@ -276,14 +303,6 @@ static void process_incoming_migration_co(void *opaque)
     migrate_generate_event(MIGRATION_STATUS_COMPLETED);
     qemu_announce_self();
 
-    /* Make sure all file formats flush their mutable metadata */
-    bdrv_invalidate_cache_all(&local_err);
-    if (local_err) {
-        error_report_err(local_err);
-        migrate_decompress_threads_join();
-        exit(EXIT_FAILURE);
-    }
-
     /* runstate == "" means that we haven't received it through the
      * wire, so we obey autostart.  runstate == runing means that we
      * need to run it, we need to make sure that we do it after
@@ -720,6 +739,13 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
         error_setg(errp, QERR_MIGRATION_ACTIVE);
         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 96aa9d7..a2edd96 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 125a33b..c34c7c4 100644
--- a/trace-events
+++ b/trace-events
@@ -1474,6 +1474,7 @@ 
rdma_start_outgoing_migration_after_rdma_source_init(void) ""
 
 # 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]