]> git.proxmox.com Git - mirror_qemu.git/blob - net/colo-compare.c
COLO-compare: Rename compare function and remove duplicate codes
[mirror_qemu.git] / net / colo-compare.c
1 /*
2 * COarse-grain LOck-stepping Virtual Machines for Non-stop Service (COLO)
3 * (a.k.a. Fault Tolerance or Continuous Replication)
4 *
5 * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
6 * Copyright (c) 2016 FUJITSU LIMITED
7 * Copyright (c) 2016 Intel Corporation
8 *
9 * Author: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
10 *
11 * This work is licensed under the terms of the GNU GPL, version 2 or
12 * later. See the COPYING file in the top-level directory.
13 */
14
15 #include "qemu/osdep.h"
16 #include "qemu/error-report.h"
17 #include "trace.h"
18 #include "qemu-common.h"
19 #include "qapi/qmp/qerror.h"
20 #include "qapi/error.h"
21 #include "net/net.h"
22 #include "net/eth.h"
23 #include "qom/object_interfaces.h"
24 #include "qemu/iov.h"
25 #include "qom/object.h"
26 #include "qemu/typedefs.h"
27 #include "net/queue.h"
28 #include "sysemu/char.h"
29 #include "qemu/sockets.h"
30 #include "qapi-visit.h"
31 #include "net/colo.h"
32
33 #define TYPE_COLO_COMPARE "colo-compare"
34 #define COLO_COMPARE(obj) \
35 OBJECT_CHECK(CompareState, (obj), TYPE_COLO_COMPARE)
36
37 #define COMPARE_READ_LEN_MAX NET_BUFSIZE
38 #define MAX_QUEUE_SIZE 1024
39
40 /* TODO: Should be configurable */
41 #define REGULAR_PACKET_CHECK_MS 3000
42
43 /*
44 + CompareState ++
45 | |
46 +---------------+ +---------------+ +---------------+
47 |conn list +--->conn +--------->conn |
48 +---------------+ +---------------+ +---------------+
49 | | | | | |
50 +---------------+ +---v----+ +---v----+ +---v----+ +---v----+
51 |primary | |secondary |primary | |secondary
52 |packet | |packet + |packet | |packet +
53 +--------+ +--------+ +--------+ +--------+
54 | | | |
55 +---v----+ +---v----+ +---v----+ +---v----+
56 |primary | |secondary |primary | |secondary
57 |packet | |packet + |packet | |packet +
58 +--------+ +--------+ +--------+ +--------+
59 | | | |
60 +---v----+ +---v----+ +---v----+ +---v----+
61 |primary | |secondary |primary | |secondary
62 |packet | |packet + |packet | |packet +
63 +--------+ +--------+ +--------+ +--------+
64 */
65 typedef struct CompareState {
66 Object parent;
67
68 char *pri_indev;
69 char *sec_indev;
70 char *outdev;
71 CharBackend chr_pri_in;
72 CharBackend chr_sec_in;
73 CharBackend chr_out;
74 SocketReadState pri_rs;
75 SocketReadState sec_rs;
76
77 /* connection list: the connections belonged to this NIC could be found
78 * in this list.
79 * element type: Connection
80 */
81 GQueue conn_list;
82 /* hashtable to save connection */
83 GHashTable *connection_track_table;
84 /* compare thread, a thread for each NIC */
85 QemuThread thread;
86
87 GMainContext *worker_context;
88 GMainLoop *compare_loop;
89 } CompareState;
90
91 typedef struct CompareClass {
92 ObjectClass parent_class;
93 } CompareClass;
94
95 enum {
96 PRIMARY_IN = 0,
97 SECONDARY_IN,
98 };
99
100 static int compare_chr_send(CharBackend *out,
101 const uint8_t *buf,
102 uint32_t size);
103
104 static gint seq_sorter(Packet *a, Packet *b, gpointer data)
105 {
106 struct tcphdr *atcp, *btcp;
107
108 atcp = (struct tcphdr *)(a->transport_header);
109 btcp = (struct tcphdr *)(b->transport_header);
110 return ntohl(atcp->th_seq) - ntohl(btcp->th_seq);
111 }
112
113 /*
114 * Return 0 on success, if return -1 means the pkt
115 * is unsupported(arp and ipv6) and will be sent later
116 */
117 static int packet_enqueue(CompareState *s, int mode)
118 {
119 ConnectionKey key;
120 Packet *pkt = NULL;
121 Connection *conn;
122
123 if (mode == PRIMARY_IN) {
124 pkt = packet_new(s->pri_rs.buf, s->pri_rs.packet_len);
125 } else {
126 pkt = packet_new(s->sec_rs.buf, s->sec_rs.packet_len);
127 }
128
129 if (parse_packet_early(pkt)) {
130 packet_destroy(pkt, NULL);
131 pkt = NULL;
132 return -1;
133 }
134 fill_connection_key(pkt, &key);
135
136 conn = connection_get(s->connection_track_table,
137 &key,
138 &s->conn_list);
139
140 if (!conn->processing) {
141 g_queue_push_tail(&s->conn_list, conn);
142 conn->processing = true;
143 }
144
145 if (mode == PRIMARY_IN) {
146 if (g_queue_get_length(&conn->primary_list) <=
147 MAX_QUEUE_SIZE) {
148 g_queue_push_tail(&conn->primary_list, pkt);
149 if (conn->ip_proto == IPPROTO_TCP) {
150 g_queue_sort(&conn->primary_list,
151 (GCompareDataFunc)seq_sorter,
152 NULL);
153 }
154 } else {
155 error_report("colo compare primary queue size too big,"
156 "drop packet");
157 }
158 } else {
159 if (g_queue_get_length(&conn->secondary_list) <=
160 MAX_QUEUE_SIZE) {
161 g_queue_push_tail(&conn->secondary_list, pkt);
162 if (conn->ip_proto == IPPROTO_TCP) {
163 g_queue_sort(&conn->secondary_list,
164 (GCompareDataFunc)seq_sorter,
165 NULL);
166 }
167 } else {
168 error_report("colo compare secondary queue size too big,"
169 "drop packet");
170 }
171 }
172
173 return 0;
174 }
175
176 /*
177 * The IP packets sent by primary and secondary
178 * will be compared in here
179 * TODO support ip fragment, Out-Of-Order
180 * return: 0 means packet same
181 * > 0 || < 0 means packet different
182 */
183 static int colo_packet_compare_common(Packet *ppkt, Packet *spkt)
184 {
185 trace_colo_compare_ip_info(ppkt->size, inet_ntoa(ppkt->ip->ip_src),
186 inet_ntoa(ppkt->ip->ip_dst), spkt->size,
187 inet_ntoa(spkt->ip->ip_src),
188 inet_ntoa(spkt->ip->ip_dst));
189
190 if (ppkt->size == spkt->size) {
191 return memcmp(ppkt->data, spkt->data, spkt->size);
192 } else {
193 trace_colo_compare_main("Net packet size are not the same");
194 return -1;
195 }
196 }
197
198 /*
199 * Called from the compare thread on the primary
200 * for compare tcp packet
201 * compare_tcp copied from Dr. David Alan Gilbert's branch
202 */
203 static int colo_packet_compare_tcp(Packet *spkt, Packet *ppkt)
204 {
205 struct tcphdr *ptcp, *stcp;
206 int res;
207
208 trace_colo_compare_main("compare tcp");
209
210 if (ppkt->size != spkt->size) {
211 if (trace_event_get_state(TRACE_COLO_COMPARE_MISCOMPARE)) {
212 trace_colo_compare_main("pkt size not same");
213 }
214 return -1;
215 }
216
217 ptcp = (struct tcphdr *)ppkt->transport_header;
218 stcp = (struct tcphdr *)spkt->transport_header;
219
220 /*
221 * The 'identification' field in the IP header is *very* random
222 * it almost never matches. Fudge this by ignoring differences in
223 * unfragmented packets; they'll normally sort themselves out if different
224 * anyway, and it should recover at the TCP level.
225 * An alternative would be to get both the primary and secondary to rewrite
226 * somehow; but that would need some sync traffic to sync the state
227 */
228 if (ntohs(ppkt->ip->ip_off) & IP_DF) {
229 spkt->ip->ip_id = ppkt->ip->ip_id;
230 /* and the sum will be different if the IDs were different */
231 spkt->ip->ip_sum = ppkt->ip->ip_sum;
232 }
233
234 res = memcmp(ppkt->data + ETH_HLEN, spkt->data + ETH_HLEN,
235 (spkt->size - ETH_HLEN));
236
237 if (res != 0 && trace_event_get_state(TRACE_COLO_COMPARE_MISCOMPARE)) {
238 trace_colo_compare_pkt_info_src(inet_ntoa(ppkt->ip->ip_src),
239 ntohl(stcp->th_seq),
240 ntohl(stcp->th_ack),
241 res, stcp->th_flags,
242 spkt->size);
243
244 trace_colo_compare_pkt_info_dst(inet_ntoa(ppkt->ip->ip_dst),
245 ntohl(ptcp->th_seq),
246 ntohl(ptcp->th_ack),
247 res, ptcp->th_flags,
248 ppkt->size);
249
250 qemu_hexdump((char *)ppkt->data, stderr,
251 "colo-compare ppkt", ppkt->size);
252 qemu_hexdump((char *)spkt->data, stderr,
253 "colo-compare spkt", spkt->size);
254 }
255
256 return res;
257 }
258
259 /*
260 * Called from the compare thread on the primary
261 * for compare udp packet
262 */
263 static int colo_packet_compare_udp(Packet *spkt, Packet *ppkt)
264 {
265 int ret;
266
267 trace_colo_compare_main("compare udp");
268
269 ret = colo_packet_compare_common(ppkt, spkt);
270
271 if (ret) {
272 trace_colo_compare_udp_miscompare("primary pkt size", ppkt->size);
273 qemu_hexdump((char *)ppkt->data, stderr, "colo-compare", ppkt->size);
274 trace_colo_compare_udp_miscompare("Secondary pkt size", spkt->size);
275 qemu_hexdump((char *)spkt->data, stderr, "colo-compare", spkt->size);
276 }
277
278 return ret;
279 }
280
281 /*
282 * Called from the compare thread on the primary
283 * for compare icmp packet
284 */
285 static int colo_packet_compare_icmp(Packet *spkt, Packet *ppkt)
286 {
287 trace_colo_compare_main("compare icmp");
288
289 if (colo_packet_compare_common(ppkt, spkt)) {
290 trace_colo_compare_icmp_miscompare("primary pkt size",
291 ppkt->size);
292 qemu_hexdump((char *)ppkt->data, stderr, "colo-compare",
293 ppkt->size);
294 trace_colo_compare_icmp_miscompare("Secondary pkt size",
295 spkt->size);
296 qemu_hexdump((char *)spkt->data, stderr, "colo-compare",
297 spkt->size);
298 return -1;
299 } else {
300 return 0;
301 }
302 }
303
304 /*
305 * Called from the compare thread on the primary
306 * for compare other packet
307 */
308 static int colo_packet_compare_other(Packet *spkt, Packet *ppkt)
309 {
310 trace_colo_compare_main("compare other");
311 trace_colo_compare_ip_info(ppkt->size, inet_ntoa(ppkt->ip->ip_src),
312 inet_ntoa(ppkt->ip->ip_dst), spkt->size,
313 inet_ntoa(spkt->ip->ip_src),
314 inet_ntoa(spkt->ip->ip_dst));
315 return colo_packet_compare_common(ppkt, spkt);
316 }
317
318 static int colo_old_packet_check_one(Packet *pkt, int64_t *check_time)
319 {
320 int64_t now = qemu_clock_get_ms(QEMU_CLOCK_HOST);
321
322 if ((now - pkt->creation_ms) > (*check_time)) {
323 trace_colo_old_packet_check_found(pkt->creation_ms);
324 return 0;
325 } else {
326 return 1;
327 }
328 }
329
330 static void colo_old_packet_check_one_conn(void *opaque,
331 void *user_data)
332 {
333 Connection *conn = opaque;
334 GList *result = NULL;
335 int64_t check_time = REGULAR_PACKET_CHECK_MS;
336
337 result = g_queue_find_custom(&conn->primary_list,
338 &check_time,
339 (GCompareFunc)colo_old_packet_check_one);
340
341 if (result) {
342 /* do checkpoint will flush old packet */
343 /* TODO: colo_notify_checkpoint();*/
344 }
345 }
346
347 /*
348 * Look for old packets that the secondary hasn't matched,
349 * if we have some then we have to checkpoint to wake
350 * the secondary up.
351 */
352 static void colo_old_packet_check(void *opaque)
353 {
354 CompareState *s = opaque;
355
356 g_queue_foreach(&s->conn_list, colo_old_packet_check_one_conn, NULL);
357 }
358
359 /*
360 * Called from the compare thread on the primary
361 * for compare connection
362 */
363 static void colo_compare_connection(void *opaque, void *user_data)
364 {
365 CompareState *s = user_data;
366 Connection *conn = opaque;
367 Packet *pkt = NULL;
368 GList *result = NULL;
369 int ret;
370
371 while (!g_queue_is_empty(&conn->primary_list) &&
372 !g_queue_is_empty(&conn->secondary_list)) {
373 pkt = g_queue_pop_tail(&conn->primary_list);
374 switch (conn->ip_proto) {
375 case IPPROTO_TCP:
376 result = g_queue_find_custom(&conn->secondary_list,
377 pkt, (GCompareFunc)colo_packet_compare_tcp);
378 break;
379 case IPPROTO_UDP:
380 result = g_queue_find_custom(&conn->secondary_list,
381 pkt, (GCompareFunc)colo_packet_compare_udp);
382 break;
383 case IPPROTO_ICMP:
384 result = g_queue_find_custom(&conn->secondary_list,
385 pkt, (GCompareFunc)colo_packet_compare_icmp);
386 break;
387 default:
388 result = g_queue_find_custom(&conn->secondary_list,
389 pkt, (GCompareFunc)colo_packet_compare_other);
390 break;
391 }
392
393 if (result) {
394 ret = compare_chr_send(&s->chr_out, pkt->data, pkt->size);
395 if (ret < 0) {
396 error_report("colo_send_primary_packet failed");
397 }
398 trace_colo_compare_main("packet same and release packet");
399 g_queue_remove(&conn->secondary_list, result->data);
400 packet_destroy(pkt, NULL);
401 } else {
402 /*
403 * If one packet arrive late, the secondary_list or
404 * primary_list will be empty, so we can't compare it
405 * until next comparison.
406 */
407 trace_colo_compare_main("packet different");
408 g_queue_push_tail(&conn->primary_list, pkt);
409 /* TODO: colo_notify_checkpoint();*/
410 break;
411 }
412 }
413 }
414
415 static int compare_chr_send(CharBackend *out,
416 const uint8_t *buf,
417 uint32_t size)
418 {
419 int ret = 0;
420 uint32_t len = htonl(size);
421
422 if (!size) {
423 return 0;
424 }
425
426 ret = qemu_chr_fe_write_all(out, (uint8_t *)&len, sizeof(len));
427 if (ret != sizeof(len)) {
428 goto err;
429 }
430
431 ret = qemu_chr_fe_write_all(out, (uint8_t *)buf, size);
432 if (ret != size) {
433 goto err;
434 }
435
436 return 0;
437
438 err:
439 return ret < 0 ? ret : -EIO;
440 }
441
442 static int compare_chr_can_read(void *opaque)
443 {
444 return COMPARE_READ_LEN_MAX;
445 }
446
447 /*
448 * Called from the main thread on the primary for packets
449 * arriving over the socket from the primary.
450 */
451 static void compare_pri_chr_in(void *opaque, const uint8_t *buf, int size)
452 {
453 CompareState *s = COLO_COMPARE(opaque);
454 int ret;
455
456 ret = net_fill_rstate(&s->pri_rs, buf, size);
457 if (ret == -1) {
458 qemu_chr_fe_set_handlers(&s->chr_pri_in, NULL, NULL, NULL,
459 NULL, NULL, true);
460 error_report("colo-compare primary_in error");
461 }
462 }
463
464 /*
465 * Called from the main thread on the primary for packets
466 * arriving over the socket from the secondary.
467 */
468 static void compare_sec_chr_in(void *opaque, const uint8_t *buf, int size)
469 {
470 CompareState *s = COLO_COMPARE(opaque);
471 int ret;
472
473 ret = net_fill_rstate(&s->sec_rs, buf, size);
474 if (ret == -1) {
475 qemu_chr_fe_set_handlers(&s->chr_sec_in, NULL, NULL, NULL,
476 NULL, NULL, true);
477 error_report("colo-compare secondary_in error");
478 }
479 }
480
481 /*
482 * Check old packet regularly so it can watch for any packets
483 * that the secondary hasn't produced equivalents of.
484 */
485 static gboolean check_old_packet_regular(void *opaque)
486 {
487 CompareState *s = opaque;
488
489 /* if have old packet we will notify checkpoint */
490 colo_old_packet_check(s);
491
492 return TRUE;
493 }
494
495 static void *colo_compare_thread(void *opaque)
496 {
497 CompareState *s = opaque;
498 GSource *timeout_source;
499
500 s->worker_context = g_main_context_new();
501
502 qemu_chr_fe_set_handlers(&s->chr_pri_in, compare_chr_can_read,
503 compare_pri_chr_in, NULL, s, s->worker_context, true);
504 qemu_chr_fe_set_handlers(&s->chr_sec_in, compare_chr_can_read,
505 compare_sec_chr_in, NULL, s, s->worker_context, true);
506
507 s->compare_loop = g_main_loop_new(s->worker_context, FALSE);
508
509 /* To kick any packets that the secondary doesn't match */
510 timeout_source = g_timeout_source_new(REGULAR_PACKET_CHECK_MS);
511 g_source_set_callback(timeout_source,
512 (GSourceFunc)check_old_packet_regular, s, NULL);
513 g_source_attach(timeout_source, s->worker_context);
514
515 g_main_loop_run(s->compare_loop);
516
517 g_source_unref(timeout_source);
518 g_main_loop_unref(s->compare_loop);
519 g_main_context_unref(s->worker_context);
520 return NULL;
521 }
522
523 static char *compare_get_pri_indev(Object *obj, Error **errp)
524 {
525 CompareState *s = COLO_COMPARE(obj);
526
527 return g_strdup(s->pri_indev);
528 }
529
530 static void compare_set_pri_indev(Object *obj, const char *value, Error **errp)
531 {
532 CompareState *s = COLO_COMPARE(obj);
533
534 g_free(s->pri_indev);
535 s->pri_indev = g_strdup(value);
536 }
537
538 static char *compare_get_sec_indev(Object *obj, Error **errp)
539 {
540 CompareState *s = COLO_COMPARE(obj);
541
542 return g_strdup(s->sec_indev);
543 }
544
545 static void compare_set_sec_indev(Object *obj, const char *value, Error **errp)
546 {
547 CompareState *s = COLO_COMPARE(obj);
548
549 g_free(s->sec_indev);
550 s->sec_indev = g_strdup(value);
551 }
552
553 static char *compare_get_outdev(Object *obj, Error **errp)
554 {
555 CompareState *s = COLO_COMPARE(obj);
556
557 return g_strdup(s->outdev);
558 }
559
560 static void compare_set_outdev(Object *obj, const char *value, Error **errp)
561 {
562 CompareState *s = COLO_COMPARE(obj);
563
564 g_free(s->outdev);
565 s->outdev = g_strdup(value);
566 }
567
568 static void compare_pri_rs_finalize(SocketReadState *pri_rs)
569 {
570 CompareState *s = container_of(pri_rs, CompareState, pri_rs);
571
572 if (packet_enqueue(s, PRIMARY_IN)) {
573 trace_colo_compare_main("primary: unsupported packet in");
574 compare_chr_send(&s->chr_out, pri_rs->buf, pri_rs->packet_len);
575 } else {
576 /* compare connection */
577 g_queue_foreach(&s->conn_list, colo_compare_connection, s);
578 }
579 }
580
581 static void compare_sec_rs_finalize(SocketReadState *sec_rs)
582 {
583 CompareState *s = container_of(sec_rs, CompareState, sec_rs);
584
585 if (packet_enqueue(s, SECONDARY_IN)) {
586 trace_colo_compare_main("secondary: unsupported packet in");
587 } else {
588 /* compare connection */
589 g_queue_foreach(&s->conn_list, colo_compare_connection, s);
590 }
591 }
592
593
594 /*
595 * Return 0 is success.
596 * Return 1 is failed.
597 */
598 static int find_and_check_chardev(Chardev **chr,
599 char *chr_name,
600 Error **errp)
601 {
602 *chr = qemu_chr_find(chr_name);
603 if (*chr == NULL) {
604 error_setg(errp, "Device '%s' not found",
605 chr_name);
606 return 1;
607 }
608
609 if (!qemu_chr_has_feature(*chr, QEMU_CHAR_FEATURE_RECONNECTABLE)) {
610 error_setg(errp, "chardev \"%s\" is not reconnectable",
611 chr_name);
612 return 1;
613 }
614
615 return 0;
616 }
617
618 /*
619 * Called from the main thread on the primary
620 * to setup colo-compare.
621 */
622 static void colo_compare_complete(UserCreatable *uc, Error **errp)
623 {
624 CompareState *s = COLO_COMPARE(uc);
625 Chardev *chr;
626 char thread_name[64];
627 static int compare_id;
628
629 if (!s->pri_indev || !s->sec_indev || !s->outdev) {
630 error_setg(errp, "colo compare needs 'primary_in' ,"
631 "'secondary_in','outdev' property set");
632 return;
633 } else if (!strcmp(s->pri_indev, s->outdev) ||
634 !strcmp(s->sec_indev, s->outdev) ||
635 !strcmp(s->pri_indev, s->sec_indev)) {
636 error_setg(errp, "'indev' and 'outdev' could not be same "
637 "for compare module");
638 return;
639 }
640
641 if (find_and_check_chardev(&chr, s->pri_indev, errp) ||
642 !qemu_chr_fe_init(&s->chr_pri_in, chr, errp)) {
643 return;
644 }
645
646 if (find_and_check_chardev(&chr, s->sec_indev, errp) ||
647 !qemu_chr_fe_init(&s->chr_sec_in, chr, errp)) {
648 return;
649 }
650
651 if (find_and_check_chardev(&chr, s->outdev, errp) ||
652 !qemu_chr_fe_init(&s->chr_out, chr, errp)) {
653 return;
654 }
655
656 net_socket_rs_init(&s->pri_rs, compare_pri_rs_finalize);
657 net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize);
658
659 g_queue_init(&s->conn_list);
660
661 s->connection_track_table = g_hash_table_new_full(connection_key_hash,
662 connection_key_equal,
663 g_free,
664 connection_destroy);
665
666 sprintf(thread_name, "colo-compare %d", compare_id);
667 qemu_thread_create(&s->thread, thread_name,
668 colo_compare_thread, s,
669 QEMU_THREAD_JOINABLE);
670 compare_id++;
671
672 return;
673 }
674
675 static void colo_flush_packets(void *opaque, void *user_data)
676 {
677 CompareState *s = user_data;
678 Connection *conn = opaque;
679 Packet *pkt = NULL;
680
681 while (!g_queue_is_empty(&conn->primary_list)) {
682 pkt = g_queue_pop_head(&conn->primary_list);
683 compare_chr_send(&s->chr_out, pkt->data, pkt->size);
684 packet_destroy(pkt, NULL);
685 }
686 while (!g_queue_is_empty(&conn->secondary_list)) {
687 pkt = g_queue_pop_head(&conn->secondary_list);
688 packet_destroy(pkt, NULL);
689 }
690 }
691
692 static void colo_compare_class_init(ObjectClass *oc, void *data)
693 {
694 UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
695
696 ucc->complete = colo_compare_complete;
697 }
698
699 static void colo_compare_init(Object *obj)
700 {
701 object_property_add_str(obj, "primary_in",
702 compare_get_pri_indev, compare_set_pri_indev,
703 NULL);
704 object_property_add_str(obj, "secondary_in",
705 compare_get_sec_indev, compare_set_sec_indev,
706 NULL);
707 object_property_add_str(obj, "outdev",
708 compare_get_outdev, compare_set_outdev,
709 NULL);
710 }
711
712 static void colo_compare_finalize(Object *obj)
713 {
714 CompareState *s = COLO_COMPARE(obj);
715
716 qemu_chr_fe_set_handlers(&s->chr_pri_in, NULL, NULL, NULL, NULL,
717 s->worker_context, true);
718 qemu_chr_fe_set_handlers(&s->chr_sec_in, NULL, NULL, NULL, NULL,
719 s->worker_context, true);
720 qemu_chr_fe_deinit(&s->chr_out);
721
722 g_main_loop_quit(s->compare_loop);
723 qemu_thread_join(&s->thread);
724
725 /* Release all unhandled packets after compare thead exited */
726 g_queue_foreach(&s->conn_list, colo_flush_packets, s);
727
728 g_queue_clear(&s->conn_list);
729
730 g_hash_table_destroy(s->connection_track_table);
731 g_free(s->pri_indev);
732 g_free(s->sec_indev);
733 g_free(s->outdev);
734 }
735
736 static const TypeInfo colo_compare_info = {
737 .name = TYPE_COLO_COMPARE,
738 .parent = TYPE_OBJECT,
739 .instance_size = sizeof(CompareState),
740 .instance_init = colo_compare_init,
741 .instance_finalize = colo_compare_finalize,
742 .class_size = sizeof(CompareClass),
743 .class_init = colo_compare_class_init,
744 .interfaces = (InterfaceInfo[]) {
745 { TYPE_USER_CREATABLE },
746 { }
747 }
748 };
749
750 static void register_types(void)
751 {
752 type_register_static(&colo_compare_info);
753 }
754
755 type_init(register_types);