diff mbox

[3/3] COLO-compare: Add colo-compare Xen notify

Message ID 1488278902-11223-4-git-send-email-zhangchen.fnst@cn.fujitsu.com
State New
Headers show

Commit Message

Zhang Chen Feb. 28, 2017, 10:48 a.m. UTC
This patch have some TODO job.
Depend on patch:
https://lists.nongnu.org/archive/html/qemu-devel/2017-02/msg05055.html

Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
---
 net/colo-compare.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
diff mbox

Patch

diff --git a/net/colo-compare.c b/net/colo-compare.c
index 947a9e2..073d1f8 100644
--- a/net/colo-compare.c
+++ b/net/colo-compare.c
@@ -103,6 +103,7 @@  enum {
 static int compare_chr_send(CharBackend *out,
                             const uint8_t *buf,
                             uint32_t size);
+static void colo_flush_packets(void *opaque, void *user_data);
 
 static gint seq_sorter(Packet *a, Packet *b, gpointer data)
 {
@@ -430,6 +431,15 @@  static void colo_compare_connection(void *opaque, void *user_data)
             trace_colo_compare_main("packet different");
             g_queue_push_tail(&conn->primary_list, pkt);
             /* TODO: colo_notify_checkpoint();*/
+            /* If we have notify_dev that means COLO run on Xen */
+            if (s->notify_dev) {
+                char msg[] = "DO_CHECKPOINT";
+                ret = compare_chr_send(&s->chr_notify_dev, (uint8_t *)msg,
+                                       strlen(msg));
+                if (ret < 0) {
+                    error_report("Notify Xen COLO-frame failed");
+                }
+            }
             break;
         }
     }
@@ -645,7 +655,26 @@  static void compare_sec_rs_finalize(SocketReadState *sec_rs)
 
 static void compare_notify_rs_finalize(SocketReadState *notify_rs)
 {
+    CompareState *s = container_of(notify_rs, CompareState, notify_rs);
+
     /* Get Xen colo-frame's notify and handle the message */
+    char *data = g_memdup(notify_rs->buf, notify_rs->packet_len);
+    char msg[] = "COLO_COMPARE_GET_XEN_INIT";
+    int ret;
+
+    if (!strcmp(data, "COLO_USERSPACE_PROXY_INIT")) {
+        ret = compare_chr_send(&s->chr_notify_dev, (uint8_t *)msg,
+                               strlen(msg));
+        if (ret < 0) {
+            error_report("Notify Xen COLO-frame INIT failed");
+        }
+    }
+
+    if (!strcmp(data, "COLO_CHECKPOINT")) {
+        /* colo-compare do checkpoint, flush pri packet and remove sec packet */
+        g_queue_foreach(&s->conn_list, colo_flush_packets, s);
+    }
+
 }
 
 /*