@@ -29,11 +29,15 @@
#include "qemu/sockets.h"
#include "qapi-visit.h"
#include "net/colo.h"
+#include "net/colo-compare.h"
#define TYPE_COLO_COMPARE "colo-compare"
#define COLO_COMPARE(obj) \
OBJECT_CHECK(CompareState, (obj), TYPE_COLO_COMPARE)
+static QTAILQ_HEAD(, CompareState) net_compares =
+ QTAILQ_HEAD_INITIALIZER(net_compares);
+
#define COMPARE_READ_LEN_MAX NET_BUFSIZE
#define MAX_QUEUE_SIZE 1024
@@ -88,6 +92,8 @@ typedef struct CompareState {
/* Timer used on the primary to find packets that are never matched */
QEMUTimer *timer;
+
+ QTAILQ_ENTRY(CompareState) next;
} CompareState;
typedef struct CompareClass {
@@ -181,6 +187,39 @@ static int packet_enqueue(CompareState *s, int mode)
return 0;
}
+static void colo_flush_connection(void *opaque, void *user_data)
+{
+ CompareState *s = user_data;
+ Connection *conn = opaque;
+ Packet *pkt = NULL;
+
+ qemu_mutex_lock(&conn->conn_lock);
+ while (!g_queue_is_empty(&conn->primary_list)) {
+ pkt = g_queue_pop_head(&conn->primary_list);
+ compare_chr_send(&s->chr_out, pkt->data, pkt->size);
+ packet_destroy(pkt, NULL);
+ }
+ while (!g_queue_is_empty(&conn->secondary_list)) {
+ pkt = g_queue_pop_head(&conn->secondary_list);
+ packet_destroy(pkt, NULL);
+ }
+ qemu_mutex_unlock(&conn->conn_lock);
+}
+
+/* Fix Me: better to use notifier way */
+void colo_compare_do_checkpoint(void)
+{
+ CompareState *s;
+
+ trace_colo_compare_main("colo_compare_do_checkpoint");
+
+ QTAILQ_FOREACH(s, &net_compares, next) {
+ qemu_mutex_lock(&s->conn_list_lock);
+ g_queue_foreach(&s->conn_list, colo_flush_connection, s);
+ qemu_mutex_unlock(&s->conn_list_lock);
+ }
+}
+
/*
* The IP packets sent by primary and secondary
* will be compared in here
@@ -387,6 +426,11 @@ static void colo_compare_connection(void *opaque, void *user_data)
while (!g_queue_is_empty(&conn->primary_list) &&
!g_queue_is_empty(&conn->secondary_list)) {
pkt = g_queue_pop_tail(&conn->primary_list);
+ if (!pkt) {
+ error_report("colo-compare pop pkt failed");
+ return;
+ }
+
switch (conn->ip_proto) {
case IPPROTO_TCP:
result = g_queue_find_custom(&conn->secondary_list,
@@ -726,6 +770,10 @@ static void colo_compare_finalize(Object *obj)
qemu_chr_fe_deinit(&s->chr_sec_in);
qemu_chr_fe_deinit(&s->chr_out);
+ if (!QTAILQ_EMPTY(&net_compares)) {
+ QTAILQ_REMOVE(&net_compares, s, next);
+ }
+
g_queue_free(&s->conn_list);
if (qemu_thread_is_self(&s->thread)) {
new file mode 100644
@@ -0,0 +1,20 @@
+/*
+ * COarse-grain LOck-stepping Virtual Machines for Non-stop Service (COLO)
+ * (a.k.a. Fault Tolerance or Continuous Replication)
+ *
+ * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
+ * Copyright (c) 2016 FUJITSU LIMITED
+ * Copyright (c) 2016 Intel Corporation
+ *
+ * Author: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * later. See the COPYING file in the top-level directory.
+ */
+
+#ifndef QEMU_COLO_COMPARE_H
+#define QEMU_COLO_COMPARE_H
+
+void colo_compare_do_checkpoint(void);
+
+#endif /* QEMU_COLO_COMPARE_H */