Introduce COLO-Proxy
v14 cover Introduce COLO-Proxy
COLO-proxy is a part of COLO project. COLO project is composed of COLO-frame, COLO-proxy and block-replication. It is used to compare the network package to help COLO decide whether to do checkpoint. With COLO-proxy's help, COLO greatly improves the performance.
The filter-redirector, filter-mirror, colo-compare and filter-rewriter compose the COLO-proxy.
COLO-compare
It is used to compare the network package to help COLO decide whether to do checkpoint.
Filter-rewriter
It will rewrite some of secondary packet to make secondary guest's connection established successfully. In this module we will rewrite tcp packet's ack to the secondary from primary,and rewrite tcp packet's seq to the primary from secondary.
The full version in this github:
https://github.com/zhangckid/qemu/tree/colo-v2.7-proxy-mode-compare-and-rewriter-sep8
v14:
- fix some coding style problems
- move patch "add docs/colo-proxy.txt" to the end of this series
- fix the mingw build issue
v13:
- add docs/colo-proxy.txt
- add MAINTAINERS
- remove unnecessary .h
- remove QTAILQ_ENTRY(CompareState)
- fix some comments
- add find_and_check_chardev() to avoid code duplication
- remove the "is_unix" in patch3
- change error_report() to trace in patch4
- use l2hdr_len here instead of ETH_HLEP
- fix code style
- remove colo_rm_connection()
- remove hashtable_size
- change g_queue_foreach() to g_queue_find_custom() in patch7
- change trace_colo_compare_tcp_miscompare() to fprintf() in patch8
- add codes not queue vlan packets
v12:
- add qemu-char: Add qemu_chr_add_handlers_full() for GMaincontext to this series as the first patch.
- update COLO net ascii figure.
- add chardev socket check.
- fix some typo.
- add some comments.
- rename net/colo-base.c to net/colo.c
- rename network/transport_layer to network/transport_header.
- move the job that clear coon_list when hashtable_size oversize to connection_get.
- reuse connection_destroy() do colo_rm_connection().
- fix pkt mem leak in colo_compare_connection(). (result be released in g_queue_remove(), so it were not leak)
- rename thread_name "compare" to "colo-compare".
- change icmp compare to memcmp().
v11:
- Make patch 5 to a independent patch series.
[PATCH V3] qemu-char: Add qemu_chr_add_handlers_full() for GMaincontext
- For Jason's comments, merge filter-rewriter to this series.
(patch 7,8,9)
- Add reverse_connection_key()
- remove conn_list in filter-rewriter
- remove unprocessed_connections
- add some comments
v10:
- fix typo
- Should we make patch 5 independent with this series? This patch just add a API for qemu-char.
v9:
p5:
- use chr_update_read_handler_full() replace
the chr_update_read_handler()
- use io_watch_poll_prepare_full() replace
the io_watch_poll_prepare()
- use io_watch_poll_funcs_full replace
the io_watch_poll_funcs
- avoid code duplication
v8:
p5:
- add new patch:
qemu-char: Add qemu_chr_add_handlers_full() for GMaincontext
v7:
p5:
- add [PATCH]qemu-char: Fix context for g_source_attach() in this patch series.
v6:
p6:
- add more commit log.
- fix icmp comparison to compare all packet.
p5:
- add more cpmments in commit log.
- change REGULAR_CHECK_MS to REGULAR_PACKET_CHECK_MS
- make check old packet independent to compare thread
- remove thread_status
p4:
- change this patch only about
Connection and ConnectionKey.
- add some comments in commit log.
- remove mode in fill_connection_key().
- fix some comments and bug.
- move colo_conn_state to patch of
"work with colo-frame"
- remove conn_list_lock.
- add MAX_QUEUE_SIZE, if primary_list or
secondary_list biger than MAX_QUEUE_SIZE
we will drop packet.
p3:
- add new independent kernel jhash patch.
p2:
- add new independent colo-base patch.
p1:
- add a ascii figure and some comments to explain it
- move trace.h to p2
- move QTAILQ_HEAD(, CompareState) net_compares to patch of "work with colo-frame"
- add some comments in qemu-option.hx
v5:
p3:
- comments from Jason
we poll and handle chardev in comapre thread, Through this way, there's no need for extra synchronization with main loop
this depend on another patch:
qemu-char: Fix context for g_source_attach()
- remove QemuEvent
p2:
- remove conn->list_lock
p1:
- move compare_pri/sec_chr_in to p3
- move compare_chr_send to p2
v4:
p4:
- add some comments
- fix some trace-events
- fix tcp compare error
p3:
- add rcu_read_lock().
- fix trace name
- fix jason's other comments
- rebase some Dave's branch function
p2:
- colo_compare_connection() change g_queue_push_head() to
- g_queue_push_tail() match to sorted order.
- remove pkt->s
- move data structure to colo-base.h
- add colo-base.c reuse codes for filter-rewriter
- add some filter-rewriter needs struct
- depends on previous SocketReadState patch
p1:
- except move qemu_chr_add_handlers()
to colo thread
- remove class_finalize
- remove secondary arp codes
- depends on previous SocketReadState patch
v3:
- rebase colo-compare to colo-frame v2.7
- fix most of Dave's comments
(except RCU)
- add TCP,UDP,ICMP and other packet comparison
- add trace-event
- add some comments
- other bug fix
- add RFC index
- add usage in patch 1/4
v2:
- add jhash.h
v1:
- initial patch
Zhang Chen (12):
qemu-char: Add qemu_chr_add_handlers_full() for GMaincontext
colo-compare: introduce colo compare initialization net/colo.c: add colo.c to define and handle packet
Jhash: add linux kernel jhashtable in qemu
colo-compare: track connection and enqueue packet
colo-compare: introduce packet comparison thread
colo-compare: add TCP,UDP,ICMP packet comparison
filter-rewriter: introduce filter-rewriter initialization
filter-rewriter: track connection and parse packet
filter-rewriter: rewrite tcp packet to keep secondary connection
MAINTAINERS: add maintainer for COLO-proxy
docs: Add documentation for COLO-proxy
MAINTAINERS | 9 + docs/colo-proxy.txt | 188 ++++++++++++ include/qemu/jhash.h | 59 ++++ include/sysemu/char.h | 11 +- net/Makefile.objs | 3 + net/colo-compare.c | 781 ++++++++++++++++++++++++++++++++++++++++++++++++++ net/colo.c | 212 ++++++++++++++ net/colo.h | 88 ++++++ net/filter-rewriter.c | 263 +++++++++++++++++ qemu-char.c | 77 +++-- qemu-options.hx | 52 ++++ trace-events | 16 ++ vl.c | 4 +- 13 files changed, 1737 insertions(+), 26 deletions(-) create mode 100644 docs/colo-proxy.txt create mode 100644 include/qemu/jhash.h create mode 100644 net/colo-compare.c create mode 100644 net/colo.c create mode 100644 net/colo.h create mode 100644 net/filter-rewriter.c
Signature · 1 line
2.7.4
PATCH v14 1/12 qemu-char: Add qemu_chr_add_handlers_full() for GMaincontext
Add qemu_chr_add_handlers_full() API, we can use this API pass in a GMainContext,make handler run in the context rather than main_loop.
This comments from Daniel P . Berrange.
--- include/sysemu/char.h | 11 +++++++- qemu-char.c | 77 +++++++++++++++++++++++++++++++++++---------------- 2 files changed, 63 insertions(+), 25 deletions(-)
include/sysemu/char.h +10 -1
@@ -65,7 +65,8 @@ struct CharDriverState {int (*chr_sync_read)(struct CharDriverState *s,const uint8_t *buf,int len);GSource *(*chr_add_watch)(struct CharDriverState *s,GIOCondition cond); -void (*chr_update_read_handler)(struct CharDriverState *s); +void (*chr_update_read_handler)(struct CharDriverState *s, +GMainContext *context);int (*chr_ioctl)(struct CharDriverState *s,int cmd,void *arg);int (*get_msgfds)(struct CharDriverState *s,int * fds,int num);int (*set_msgfds)(struct CharDriverState *s,int *fds,int num);
@@ -422,6 +423,14 @@ void qemu_chr_add_handlers(CharDriverState *s, IOEventHandler *fd_event, void *opaque); +/* This API can make handler run in the context what you pass to. */ +void qemu_chr_add_handlers_full (CharDriverState *s, +IOCanReadHandler *fd_can_read, +IOReadHandler *fd_read, +IOEventHandler *fd_event, +void *opaque, +GMainContext *context); +void qemu_chr_be_generic_open (CharDriverState *s);void qemu_chr_accept_input (CharDriverState *s);int qemu_chr_add_client (CharDriverState *s,int fd);
qemu-char.c +53 -24
193 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v14 2/12 colo-compare: introduce colo compare initialization
In reply to Zhang ChenThis a COLO net ascii figure:
Primary qemu Secondary qemu
+--------------------------------------------------------------+ +----------------------------------------------------------------+
| +----------------------------------------------------------+ | | +-----------------------------------------------------------+ |
| | | | | | | |
| | guest | | | | guest | |
| | | | | | | |
| +-------^--------------------------+-----------------------+ | | +---------------------+--------+----------------------------+ |
| | | | | ^ | |
| | | | | | | |
| | +------------------------------------------------------+ | | | |
|netfilter| | | | | | netfilter | | |
| +----------+ +----------------------------+ | | | +-----------------------------------------------------------+ |
| | | | | | out | | | | | | filter excute order | |
| | | | +-----------------------------+ | | | | | | +-------------------> | |
| | | | | | | | | | | | | | TCP | |
| | +-----+--+-+ +-----v----+ +-----v----+ |pri +----+----+sec| | | | +------------+ +---+----+---v+rewriter++ +------------+ | |
| | | | | | | | |in | |in | | | | | | | | | | | | |
| | | filter | | filter | | filter +------> colo <------+ +--------> filter +--> adjust | adjust +--> filter | | |
| | | mirror | |redirector| |redirector| | | compare | | | | | | redirector | | ack | seq | | redirector | | |
| | | | | | | | | | | | | | | | | | | | | | | |
| | +----^-----+ +----+-----+ +----------+ | +---------+ | | | | +------------+ +--------+--------------+ +---+--------+ | |
| | | tx | rx rx | | | | | tx all | rx | |
| | | | | | | | +-----------------------------------------------------------+ |
| | | +--------------+ | | | | | |
| | | filter excute order | | | | | | |
| | | +----------------> | | | +--------------------------------------------------------+ |
| +-----------------------------------------+ | | |
| | | | | |
+--------------------------------------------------------------+ +----------------------------------------------------------------+
|guest receive | guest send
| |
+--------+----------------------------v------------------------+
| | NOTE: filter direction is rx/tx/all
| tap | rx:receive packets sent to the netdev
| | tx:receive packets sent by the netdev
+--------------------------------------------------------------+In COLO-compare, we do packet comparing job.
Packets coming from the primary char indev will be sent to outdev. Packets coming from the secondary char dev will be dropped after comparing. colo-comapre need two input chardev and one output chardev:
primary_in=chardev1-id (source: primary send packet) secondary_in=chardev2-id (source: secondary send packet) outdev=chardev3-id
usage:
primary:
-netdev tap,id=hn0,vhost=off,script=/etc/qemu-ifup,downscript=/etc/qemu-ifdown -device e1000,id=e0,netdev=hn0,mac=52:a4:00:12:78:66
-chardev socket,id=mirror0,host=3.3.3.3,port=9003,server,nowait
-chardev socket,id=compare1,host=3.3.3.3,port=9004,server,nowait
-chardev socket,id=compare0,host=3.3.3.3,port=9001,server,nowait
-chardev socket,id=compare0-0,host=3.3.3.3,port=9001
-chardev socket,id=compare_out,host=3.3.3.3,port=9005,server,nowait
-chardev socket,id=compare_out0,host=3.3.3.3,port=9005
-object filter-mirror,id=m0,netdev=hn0,queue=tx,outdev=mirror0
-object filter-redirector,netdev=hn0,id=redire0,queue=rx,indev=compare_out -object filter-redirector,netdev=hn0,id=redire1,queue=rx,outdev=compare0 -object colo-compare,id=comp0,primary_in=compare0-0,secondary_in=compare1,outdev=compare_out0
secondary:
-netdev tap,id=hn0,vhost=off,script=/etc/qemu-ifup,down script=/etc/qemu-ifdown -device e1000,netdev=hn0,mac=52:a4:00:12:78:66
-chardev socket,id=red0,host=3.3.3.3,port=9003
-chardev socket,id=red1,host=3.3.3.3,port=9004
-object filter-redirector,id=f1,netdev=hn0,queue=tx,indev=red0 -object filter-redirector,id=f2,netdev=hn0,queue=rx,outdev=red1
--- net/Makefile.objs | 1 + net/colo-compare.c | 270 +++++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-options.hx | 39 ++++++++ vl.c | 3 +- 4 files changed, 312 insertions(+), 1 deletion(-) create mode 100644 net/colo-compare.c
net/Makefile.objs +1 -0
@@ -16,3 +16,4 @@ common-obj-$(CONFIG_NETMAP) += netmap.o common-obj-y += filter.o common-obj-y += filter-buffer.o common-obj-y += filter-mirror.o +common-obj-y += colo-compare.o
net/colo-compare.c new file +270 -0
270 lines not on this page · raw message
qemu-options.hx +39 -0
@@ -3887,6 +3887,45 @@ Dump the network traffic on netdev @var{dev} to the file specified by The file format is libpcap, so it can be analyzed with tools such as tcpdump or Wireshark. +@item -object colo-compare,id=@var{id},primary_in=@var{chardevid},secondary_in=@var{chardevid}, +outdev=@var{chardevid} + +Colo-compare gets packet from primary_in@var{chardevid} and secondary_in@var{chardevid}, than compare primary packet with +secondary packet. If the packets are same, we will output primary +packet to outdev@var{chardevid}, else we will notify colo-frame +do checkpoint and send primary packet to outdev@var{chardevid}. + +we must use it with the help of filter-mirror and filter-redirector. + +@example + +primary: +-netdev tap,id=hn0,vhost=off,script=/etc/qemu-ifup,downscript=/etc/qemu-ifdown +-device e1000,id=e0,netdev=hn0,mac=52:a4:00:12:78:66 +-chardev socket,id=mirror0,host=3.3.3.3,port=9003,server,nowait +-chardev socket,id=compare1,host=3.3.3.3,port=9004,server,nowait +-chardev socket,id=compare0,host=3.3.3.3,port=9001,server,nowait +-chardev socket,id=compare0-0,host=3.3.3.3,port=9001 +-chardev socket,id=compare_out,host=3.3.3.3,port=9005,server,nowait +-chardev socket,id=compare_out0,host=3.3.3.3,port=9005 +-object filter-mirror,id=m0,netdev=hn0,queue=tx,outdev=mirror0 +-object filter-redirector,netdev=hn0,id=redire0,queue=rx,indev=compare_out +-object filter-redirector,netdev=hn0,id=redire1,queue=rx,outdev=compare0 +-object colo-compare,id=comp0,primary_in=compare0-0,secondary_in=compare1,outdev=compare_out0 + +secondary: +-netdev tap,id=hn0,vhost=off,script=/etc/qemu-ifup,down script=/etc/qemu-ifdown +-device e1000,netdev=hn0,mac=52:a4:00:12:78:66 +-chardev socket,id=red0,host=3.3.3.3,port=9003 +-chardev socket,id=red1,host=3.3.3.3,port=9004 +-object filter-redirector,id=f1,netdev=hn0,queue=tx,indev=red0 +-object filter-redirector,id=f2,netdev=hn0,queue=rx,outdev=red1 + +@end example + +If you want to know the detail of above command line, you can read +the colo-compare git log. + @item -object secret,id=@var{id},data=@var{string},format=@var{raw|base64}[,keyid=@var{secretid},iv=@var{string}] @item -object secret,id=@var{id},file=@var{filename},format=@var{raw|base64}[,keyid=@var{secretid},iv=@var{string}]
vl.c +2 -1
@@ -2806,7 +2806,8 @@ static bool object_create_initial(const char *type)if (g_str_equal (type,"filter-buffer" ) ||g_str_equal (type,"filter-dump" ) ||g_str_equal (type,"filter-mirror" ) || -g_str_equal (type,"filter-redirector" )) { +g_str_equal (type,"filter-redirector" ) || +g_str_equal (type,"colo-compare" )) {return false; }
Signature · 1 line
2.7.4
PATCH v14 3/12 net/colo.c: add colo.c to define and handle packet
In reply to Zhang ChenThe net/colo.c is used by colo-compare and filter-rewriter. this can share common data structure like net packet, and other functions.
--- net/Makefile.objs | 1 + net/colo-compare.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++-- net/colo.c | 86 ++++++++++++++++++++++++++++++++++++++++ net/colo.h | 37 +++++++++++++++++ trace-events | 6 +++ 5 files changed, 240 insertions(+), 4 deletions(-) create mode 100644 net/colo.c create mode 100644 net/colo.h
net/Makefile.objs +1 -0
@@ -17,3 +17,4 @@ common-obj-y += filter.o common-obj-y += filter-buffer.o common-obj-y += filter-mirror.o common-obj-y += colo-compare.o +common-obj-y += colo.o
net/colo-compare.c +110 -4
159 lines not on this page · raw message
net/colo.c new file +86 -0
86 lines not on this page · raw message
net/colo.h new file +37 -0
@@ -0,0 +1,37 @@ +/* +* 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 <[email protected]> +* +* 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_PROXY_H +#define QEMU_COLO_PROXY_H + +#include "slirp/slirp.h" + +#define HASHTABLE_MAX_SIZE 16384 + +typedef struct Packet { +void *data; +union { +uint8_t *network_header; +struct ip *ip; + }; +uint8_t *transport_header; +int size; +}Packet ; + +int parse_packet_early (Packet *pkt); +void connection_hashtable_reset (GHashTable *connection_track_table); +Packet *packet_new (const void *data,int size); +void packet_destroy (void *opaque,void *user_data); + +#endif /* QEMU_COLO_PROXY_H */
trace-events +6 -0
@@ -140,6 +140,12 @@ memory_region_subpage_write(int cpu_index, void *mr, uint64_t offset, uint64_t v memory_region_tb_read(int cpu_index, uint64_t addr, uint64_t value, unsigned size) "cpu %d addr %#"PRIx64" value %#"PRIx64" size %u" memory_region_tb_write(int cpu_index, uint64_t addr, uint64_t value, unsigned size) "cpu %d addr %#"PRIx64" value %#"PRIx64" size %u" +# net/colo.c +colo_proxy_main(const char *chr) ": %s" + +# net/colo-compare.c +colo_compare_main(const char *chr) ": %s" + ### Guest events, keep at bottom # @vaddr: Access' virtual address.
Signature · 1 line
2.7.4
PATCH v14 4/12 Jhash: add linux kernel jhashtable in qemu
In reply to Zhang ChenJhash will be used by colo-compare and filter-rewriter to save and lookup net connection info
--- include/qemu/jhash.h | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ net/colo.h | 1 + 2 files changed, 60 insertions(+) create mode 100644 include/qemu/jhash.h
include/qemu/jhash.h new file +59 -0
@@ -0,0 +1,59 @@ +/* jhash.h: Jenkins hash support. +* +* Copyright (C) 2006. Bob Jenkins ([email protected]) +* +* http://burtleburtle.net/bob/hash/ +* +* These are the credits from Bob's sources: +* +* lookup3.c, by Bob Jenkins, May 2006, Public Domain. +* +* These are functions for producing 32-bit hashes for hash table lookup. +* hashword(), hashlittle(), hashlittle2(), hashbig(), mix(), and final() +* are externally useful functions. Routines to test the hash are included +* if SELF_TEST is defined. You can use this free for any purpose. It's in +* the public domain. It has no warranty. +* +* Copyright (C) 2009-2010 Jozsef Kadlecsik ([email protected]) +* +* I've modified Bob's hash to be useful in the Linux kernel, and +* any bugs present are my fault. +* Jozsef +*/ + +#ifndef QEMU_JHASH_H__ +#define QEMU_JHASH_H__ + +#include "qemu/bitops.h" + +/* +* hashtable relation copy from linux kernel jhash +*/ + +/* __jhash_mix -- mix 3 32-bit values reversibly. */ +#define __jhash_mix (a, b, c) \ +{ \ + a -= c; a ^= rol32(c, 4); c += b; \ + b -= a; b ^= rol32(a, 6); a += c; \ + c -= b; c ^= rol32(b, 8); b += a; \ + a -= c; a ^= rol32(c, 16); c += b; \ + b -= a; b ^= rol32(a, 19); a += c; \ + c -= b; c ^= rol32(b, 4); b += a; \ +} + +/* __jhash_final - final mixing of 3 32-bit values (a,b,c) into c */ +#define __jhash_final (a, b, c) \ +{ \ + c ^= b; c -= rol32(b, 14); \ + a ^= c; a -= rol32(c, 11); \ + b ^= a; b -= rol32(a, 25); \ + c ^= b; c -= rol32(b, 16); \ + a ^= c; a -= rol32(c, 4); \ + b ^= a; b -= rol32(a, 14); \ + c ^= b; c -= rol32(b, 24); \ +} + +/* An arbitrary initial parameter */ +#define JHASH_INITVAL 0xdeadbeef + +#endif /* QEMU_JHASH_H__ */
net/colo.h +1 -0
@@ -16,6 +16,7 @@#define QEMU_COLO_PROXY_H #include "slirp/slirp.h" +#include "qemu/jhash.h" #define HASHTABLE_MAX_SIZE 16384
Signature · 1 line
2.7.4
PATCH v14 5/12 colo-compare: track connection and enqueue packet
In reply to Zhang ChenIn this patch we use kernel jhash table to track connection, and then enqueue net packet like this:
+ CompareState ++
| |
+---------------+ +---------------+ +---------------+
|conn list +--->conn +--------->conn |
+---------------+ +---------------+ +---------------+
| | | | | |
+---------------+ +---v----+ +---v----+ +---v----+ +---v----+
|primary | |secondary |primary | |secondary
|packet | |packet + |packet | |packet +
+--------+ +--------+ +--------+ +--------+
| | | |
+---v----+ +---v----+ +---v----+ +---v----+
|primary | |secondary |primary | |secondary
|packet | |packet + |packet | |packet +
+--------+ +--------+ +--------+ +--------+
| | | |
+---v----+ +---v----+ +---v----+ +---v----+
|primary | |secondary |primary | |secondary
|packet | |packet + |packet | |packet +
+--------+ +--------+ +--------+ +--------+We use conn_list to record connection info.
When we want to enqueue a packet, firstly get the connection from connection_track_table. then push the packet to g_queue(pri/sec) in it's own conn.
--- net/colo-compare.c | 53 +++++++++++++++++++++----- net/colo.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++ net/colo.h | 39 +++++++++++++++++++ 3 files changed, 191 insertions(+), 10 deletions(-)
net/colo-compare.c +43 -10
@@ -33,6 +33,8 @@#define COLO_COMPARE (obj) \ OBJECT_CHECK(CompareState, (obj), TYPE_COLO_COMPARE) +#define MAX_QUEUE_SIZE 1024 +/* + CompareState ++ | |
@@ -67,6 +69,11 @@ typedef struct CompareState {SocketReadState pri_rs;SocketReadState sec_rs; +/* connection list: the connections belonged to this NIC could be found +* in this list. +* element type: Connection +*/ +GQueue conn_list;/* hashtable to save connection */ GHashTable *connection_track_table; } CompareState;
@@ -94,7 +101,9 @@ static int compare_chr_send(CharDriverState *out,*/ static int packet_enqueue (CompareState *s,int mode) { +ConnectionKey key = {0 };Packet *pkt =NULL ; +Connection *conn;if (mode ==PRIMARY_IN ) { pkt =packet_new (s->pri_rs.buf, s->pri_rs.packet_len);
@@ -107,17 +116,34 @@ static int packet_enqueue(CompareState *s, int mode) pkt =NULL ;return -1 ; } -/* TODO: get connection key from pkt */ +fill_connection_key (pkt, &key); -/* -* TODO: use connection key get conn from -* connection_track_table -*/ + conn =connection_get (s->connection_track_table, + &key, + &s->conn_list); -/* -* TODO: insert pkt to it's conn->primary_list -* or conn->secondary_list -*/ +if (!conn->processing) { +g_queue_push_tail (&s->conn_list, conn); + conn->processing = true; + } + +if (mode ==PRIMARY_IN ) { +if (g_queue_get_length (&conn->primary_list) <= +MAX_QUEUE_SIZE ) { +g_queue_push_tail (&conn->primary_list, pkt); + }else { +error_report ("colo compare primary queue size too big," +"drop packet" ); + } + }else { +if (g_queue_get_length (&conn->secondary_list) <= +MAX_QUEUE_SIZE ) { +g_queue_push_tail (&conn->secondary_list, pkt); + }else { +error_report ("colo compare secondary queue size too big," +"drop packet" ); + } + }return 0 ; }
@@ -308,7 +334,12 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp)net_socket_rs_init (&s->pri_rs, compare_pri_rs_finalize);net_socket_rs_init (&s->sec_rs, compare_sec_rs_finalize); -/* use g_hash_table_new_full() to new a hashtable */ +g_queue_init (&s->conn_list); + + s->connection_track_table =g_hash_table_new_full (connection_key_hash, + connection_key_equal, + g_free, + connection_destroy);return ; }
@@ -349,6 +380,8 @@ static void colo_compare_finalize(Object *obj)qemu_chr_fe_release (s->chr_out); } +g_queue_free (&s->conn_list); +g_free (s->pri_indev);g_free (s->sec_indev);g_free (s->outdev);
net/colo.c +109 -0
124 lines not on this page · raw message
net/colo.h +39 -0
@@ -20,6 +20,18 @@#define HASHTABLE_MAX_SIZE 16384 +#ifndef IPPROTO_DCCP +#define IPPROTO_DCCP 33 +#endif + +#ifndef IPPROTO_SCTP +#define IPPROTO_SCTP 132 +#endif + +#ifndef IPPROTO_UDPLITE +#define IPPROTO_UDPLITE 136 +#endif + typedef struct Packet { void *data; union {
@@ -30,7 +42,34 @@ typedef struct Packet {int size; } Packet; +typedef struct ConnectionKey { +/* (src, dst) must be grouped, in the same way than in IP header */ +struct in_addr src; +struct in_addr dst; +uint16_t src_port; +uint16_t dst_port; +uint8_t ip_proto; +} QEMU_PACKED ConnectionKey; + +typedef struct Connection { +/* connection primary send queue: element type: Packet */ +GQueue primary_list; +/* connection secondary send queue: element type: Packet */ +GQueue secondary_list; +/* flag to enqueue unprocessed_connections */ +bool processing; +uint8_t ip_proto; +}Connection ; + +uint32_t connection_key_hash (const void *opaque); +int connection_key_equal (const void *opaque1,const void *opaque2);int parse_packet_early (Packet *pkt); +void fill_connection_key (Packet *pkt,ConnectionKey *key); +Connection *connection_new (ConnectionKey *key); +void connection_destroy (void *opaque); +Connection *connection_get (GHashTable *connection_track_table, +ConnectionKey *key, +GQueue *conn_list);void connection_hashtable_reset (GHashTable *connection_track_table);Packet *packet_new (const void *data,int size);void packet_destroy (void *opaque,void *user_data);
Signature · 1 line
2.7.4
PATCH v14 6/12 colo-compare: introduce packet comparison thread
In reply to Zhang ChenIf primary packet is same with secondary packet, we will send primary packet and drop secondary packet, otherwise notify COLO frame to do checkpoint. If primary packet comes but secondary packet does not, after REGULAR_PACKET_CHECK_MS milliseconds we set the primary packet as old_packet,then do a checkpoint.
--- net/colo-compare.c | 233 +++++++++++++++++++++++++++++++++++++++++++++++++++++ net/colo.c | 1 + net/colo.h | 3 + trace-events | 2 + 4 files changed, 239 insertions(+)
net/colo-compare.c +233 -0
@@ -33,8 +33,12 @@#define COLO_COMPARE (obj) \ OBJECT_CHECK(CompareState, (obj), TYPE_COLO_COMPARE) +#define COMPARE_READ_LEN_MAX NET_BUFSIZE#define MAX_QUEUE_SIZE 1024 +/* TODO: Should be configurable */ +#define REGULAR_PACKET_CHECK_MS 3000 +/* + CompareState ++ | |
@@ -76,6 +80,11 @@ typedef struct CompareState {GQueue conn_list;/* hashtable to save connection */ GHashTable *connection_track_table; +/* compare thread, a thread for each NIC */ +QemuThread thread; +/* Timer used on the primary to find packets that are never matched */ +QEMUTimer *timer; +QemuMutex timer_check_lock; } CompareState; typedef struct CompareClass {
@@ -148,6 +157,118 @@ static int packet_enqueue(CompareState *s, int mode)return 0 ; } +/* +* The IP packets sent by primary and secondary +* will be compared in here +* TODO support ip fragment, Out-Of-Order +* return: 0 means packet same +* > 0 || < 0 means packet different +*/ +static int colo_packet_compare (Packet *ppkt,Packet *spkt) +{ +trace_colo_compare_ip_info (ppkt->size,inet_ntoa (ppkt->ip->ip_src), +inet_ntoa (ppkt->ip->ip_dst), spkt->size, +inet_ntoa (spkt->ip->ip_src), +inet_ntoa (spkt->ip->ip_dst)); + +if (ppkt->size == spkt->size) { +return memcmp (ppkt->data, spkt->data, spkt->size); + }else { +return -1 ; + } +} + +static int colo_packet_compare_all (Packet *spkt,Packet *ppkt) +{ +trace_colo_compare_main ("compare all" ); +return colo_packet_compare (ppkt, spkt); +} + +static int colo_old_packet_check_one (Packet *pkt,int64_t *check_time) +{ +int64_t now =qemu_clock_get_ms (QEMU_CLOCK_HOST ); + +if ((now - pkt->creation_ms) > (*check_time)) { +trace_colo_old_packet_check_found (pkt->creation_ms); +return 0 ; + }else { +return 1 ; + } +} + +static void colo_old_packet_check_one_conn (void *opaque, +void *user_data) +{ +Connection *conn = opaque; +GList *result =NULL ; +int64_t check_time =REGULAR_PACKET_CHECK_MS ; + + result =g_queue_find_custom (&conn->primary_list, + &check_time, + (GCompareFunc )colo_old_packet_check_one); + +if (result) { +/* do checkpoint will flush old packet */ +/* TODO: colo_notify_checkpoint();*/ + } +} + +/* +* Look for old packets that the secondary hasn't matched, +* if we have some then we have to checkpoint to wake +* the secondary up. +*/ +static void colo_old_packet_check (void *opaque) +{ +CompareState *s = opaque; + +g_queue_foreach (&s->conn_list, colo_old_packet_check_one_conn,NULL ); +} + +/* +* Called from the compare thread on the primary +* for compare connection +*/ +static void colo_compare_connection (void *opaque,void *user_data) +{ +CompareState *s = user_data; +Connection *conn = opaque; +Packet *pkt =NULL ; +GList *result =NULL ; +int ret; + +while (!g_queue_is_empty (&conn->primary_list) && + !g_queue_is_empty (&conn->secondary_list)) { +qemu_mutex_lock (&s->timer_check_lock); + pkt =g_queue_pop_tail (&conn->primary_list); +qemu_mutex_unlock (&s->timer_check_lock); + result =g_queue_find_custom (&conn->secondary_list, + pkt, (GCompareFunc )colo_packet_compare_all); + +if (result) { + ret =compare_chr_send (s->chr_out, pkt->data, pkt->size); +if (ret <0 ) { +error_report ("colo_send_primary_packet failed" ); + } +trace_colo_compare_main ("packet same and release packet" ); +g_queue_remove (&conn->secondary_list, result->data); +packet_destroy (pkt,NULL ); + }else { +/* +* If one packet arrive late, the secondary_list or +* primary_list will be empty, so we can't compare it +* until next comparison. +*/ +trace_colo_compare_main ("packet different" ); +qemu_mutex_lock (&s->timer_check_lock); +g_queue_push_tail (&conn->primary_list, pkt); +qemu_mutex_unlock (&s->timer_check_lock); +/* TODO: colo_notify_checkpoint();*/ +break ; + } + } +} +static int compare_chr_send (CharDriverState *out,const uint8_t *buf,uint32_t size)
@@ -175,6 +296,65 @@ err:return ret <0 ? ret : -EIO ; } +static int compare_chr_can_read (void *opaque) +{ +return COMPARE_READ_LEN_MAX ; +} + +/* +* Called from the main thread on the primary for packets +* arriving over the socket from the primary. +*/ +static void compare_pri_chr_in (void *opaque,const uint8_t *buf,int size) +{ +CompareState *s =COLO_COMPARE (opaque); +int ret; + + ret =net_fill_rstate (&s->pri_rs, buf, size); +if (ret ==-1 ) { +qemu_chr_add_handlers (s->chr_pri_in,NULL ,NULL ,NULL ,NULL ); +error_report ("colo-compare primary_in error" ); + } +} + +/* +* Called from the main thread on the primary for packets +* arriving over the socket from the secondary. +*/ +static void compare_sec_chr_in (void *opaque,const uint8_t *buf,int size) +{ +CompareState *s =COLO_COMPARE (opaque); +int ret; + + ret =net_fill_rstate (&s->sec_rs, buf, size); +if (ret ==-1 ) { +qemu_chr_add_handlers (s->chr_sec_in,NULL ,NULL ,NULL ,NULL ); +error_report ("colo-compare secondary_in error" ); + } +} + +static void *colo_compare_thread (void *opaque) +{ +GMainContext *worker_context; +GMainLoop *compare_loop; +CompareState *s = opaque; + + worker_context =g_main_context_new (); + +qemu_chr_add_handlers_full (s->chr_pri_in, compare_chr_can_read, + compare_pri_chr_in,NULL , s, worker_context); +qemu_chr_add_handlers_full (s->chr_sec_in, compare_chr_can_read, + compare_sec_chr_in,NULL , s, worker_context); + + compare_loop =g_main_loop_new (worker_context, FALSE); + +g_main_loop_run (compare_loop); + +g_main_loop_unref (compare_loop); +g_main_context_unref (worker_context); +return NULL ; +} +static char *compare_get_pri_indev (Object *obj,Error **errp) {CompareState *s =COLO_COMPARE (obj);
@@ -227,6 +407,9 @@ static void compare_pri_rs_finalize(SocketReadState *pri_rs)if (packet_enqueue (s,PRIMARY_IN )) {trace_colo_compare_main ("primary: unsupported packet in" );compare_chr_send (s->chr_out, pri_rs->buf, pri_rs->packet_len); + }else { +/* compare connection */ +g_queue_foreach (&s->conn_list, colo_compare_connection, s); } }
@@ -236,6 +419,9 @@ static void compare_sec_rs_finalize(SocketReadState *sec_rs)if (packet_enqueue (s,SECONDARY_IN )) {trace_colo_compare_main ("secondary: unsupported packet in" ); + }else { +/* compare connection */ +g_queue_foreach (&s->conn_list, colo_compare_connection, s); } }
@@ -294,12 +480,34 @@ static int find_and_check_chardev(CharDriverState **chr, }/* +* Check old packet regularly so it can watch for any packets +* that the secondary hasn't produced equivalents of. +*/ +static void check_old_packet_regular (void *opaque) +{ +CompareState *s = opaque; + +timer_mod (s->timer,qemu_clock_get_ms (QEMU_CLOCK_VIRTUAL ) + +REGULAR_PACKET_CHECK_MS ); +/* if have old packet we will notify checkpoint */ +/* +* TODO: Make timer handler run in compare thread +* like qemu_chr_add_handlers_full. +*/ +qemu_mutex_lock (&s->timer_check_lock); +colo_old_packet_check (s); +qemu_mutex_unlock (&s->timer_check_lock); +} + +/* * Called from the main thread on the primary * to setup colo-compare. */ static void colo_compare_complete (UserCreatable *uc,Error **errp) {CompareState *s =COLO_COMPARE (uc); +char thread_name[64 ]; +static int compare_id;if (!s->pri_indev || !s->sec_indev || !s->outdev) { error_setg(errp, "colo compare needs 'primary_in' ,"
@@ -335,12 +543,25 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp)net_socket_rs_init (&s->sec_rs, compare_sec_rs_finalize);g_queue_init (&s->conn_list); +qemu_mutex_init (&s->timer_check_lock); s->connection_track_table =g_hash_table_new_full (connection_key_hash, connection_key_equal, g_free, connection_destroy); +sprintf (thread_name,"colo-compare %d" , compare_id); +qemu_thread_create (&s->thread, thread_name, + colo_compare_thread, s, +QEMU_THREAD_JOINABLE ); + compare_id++; + +/* A regular timer to kick any packets that the secondary doesn't match */ + s->timer =timer_new_ms (QEMU_CLOCK_VIRTUAL ,/* Only when guest runs */ + check_old_packet_regular, s); +timer_mod (s->timer,qemu_clock_get_ms (QEMU_CLOCK_VIRTUAL ) + +REGULAR_PACKET_CHECK_MS ); +return ; }
@@ -382,6 +603,18 @@ static void colo_compare_finalize(Object *obj)g_queue_free (&s->conn_list); +if (qemu_thread_is_self (&s->thread)) { +/* compare connection */ +g_queue_foreach (&s->conn_list, colo_compare_connection, s); +qemu_thread_join (&s->thread); + } + +if (s->timer) { +timer_del (s->timer); + } + +qemu_mutex_destroy (&s->timer_check_lock); +g_free (s->pri_indev);g_free (s->sec_indev);g_free (s->outdev);
net/colo.c +1 -0
@@ -144,6 +144,7 @@ Packet *packet_new(const void *data, int size) pkt->data =g_memdup (data, size); pkt->size = size; + pkt->creation_ms =qemu_clock_get_ms (QEMU_CLOCK_HOST );return pkt; }
net/colo.h +3 -0
@@ -17,6 +17,7 @@#include "slirp/slirp.h" #include "qemu/jhash.h" +#include "qemu/timer.h" #define HASHTABLE_MAX_SIZE 16384
@@ -40,6 +41,8 @@ typedef struct Packet { };uint8_t *transport_header;int size; +/* Time of packet creation, in wall clock ms */ +int64_t creation_ms; } Packet; typedef struct ConnectionKey {
trace-events +2 -0
@@ -145,6 +145,8 @@ colo_proxy_main(const char *chr) ": %s" # net/colo-compare.c colo_compare_main(const char *chr) ": %s" +colo_compare_ip_info(int psize, const char *sta, const char *stb, int ssize, const char *stc, const char *std) "ppkt size = %d, ip_src = %s, ip_dst = %s, spkt size = %d, ip_src = %s, ip_dst = %s" +colo_old_packet_check_found(int64_t old_time) "%" PRId64 ### Guest events, keep at bottom
Signature · 1 line
2.7.4
PATCH v14 7/12 colo-compare: add TCP, UDP, ICMP packet comparison
In reply to Zhang ChenWe add TCP,UDP,ICMP packet comparison to replace IP packet comparison. This can increase the accuracy of the package comparison.
Less checkpoint more efficiency.
--- net/colo-compare.c | 147 +++++++++++++++++++++++++++++++++++++++++++++++++++-- trace-events | 3 ++ 2 files changed, 146 insertions(+), 4 deletions(-)
net/colo-compare.c +143 -4
@@ -19,6 +19,7 @@#include "qapi/qmp/qerror.h" #include "qapi/error.h" #include "net/net.h" +#include "net/eth.h" #include "qom/object_interfaces.h" #include "qemu/iov.h" #include "qom/object.h"
@@ -178,9 +179,131 @@ static int colo_packet_compare(Packet *ppkt, Packet *spkt) } } -static int colo_packet_compare_all (Packet *spkt,Packet *ppkt) +/* +* Called from the compare thread on the primary +* for compare tcp packet +* compare_tcp copied from Dr. David Alan Gilbert's branch +*/ +static int colo_packet_compare_tcp (Packet *spkt,Packet *ppkt) +{ +struct tcphdr *ptcp, *stcp; +int res; +char *sdebug, *ddebug; + +trace_colo_compare_main ("compare tcp" ); +if (ppkt->size != spkt->size) { +if (trace_event_get_state (TRACE_COLO_COMPARE_MISCOMPARE )) { +trace_colo_compare_main ("pkt size not same" ); + } +return -1 ; + } + + ptcp = (struct tcphdr *)ppkt->transport_header; + stcp = (struct tcphdr *)spkt->transport_header; + +/* +* The 'identification' field in the IP header is *very* random +* it almost never matches. Fudge this by ignoring differences in +* unfragmented packets; they'll normally sort themselves out if different +* anyway, and it should recover at the TCP level. +* An alternative would be to get both the primary and secondary to rewrite +* somehow; but that would need some sync traffic to sync the state +*/ +if (ntohs (ppkt->ip->ip_off) &IP_DF ) { + spkt->ip->ip_id = ppkt->ip->ip_id; +/* and the sum will be different if the IDs were different */ + spkt->ip->ip_sum = ppkt->ip->ip_sum; + } + + res =memcmp (ppkt->data +ETH_HLEN , spkt->data +ETH_HLEN , + (spkt->size -ETH_HLEN )); + +if (res !=0 &&trace_event_get_state (TRACE_COLO_COMPARE_MISCOMPARE )) { + sdebug =strdup (inet_ntoa (ppkt->ip->ip_src)); + ddebug =strdup (inet_ntoa (ppkt->ip->ip_dst)); +fprintf (stderr,"%s: src/dst: %s/%s p: seq/ack=%u/%u" +" s: seq/ack=%u/%u res=%d flags=%x/%x\n" , + __func__, sdebug, ddebug, + (unsigned int )ntohl (ptcp->th_seq), + (unsigned int )ntohl (ptcp->th_ack), + (unsigned int )ntohl (stcp->th_seq), + (unsigned int )ntohl (stcp->th_ack), + res, ptcp->th_flags, stcp->th_flags); + +fprintf (stderr,"Primary len = %d\n" , ppkt->size); +qemu_hexdump ((char *)ppkt->data, stderr,"colo-compare" , ppkt->size); +fprintf (stderr,"Secondary len = %d\n" , spkt->size); +qemu_hexdump ((char *)spkt->data, stderr,"colo-compare" , spkt->size); + +g_free (sdebug); +g_free (ddebug); + } + +return res; +} + +/* +* Called from the compare thread on the primary +* for compare udp packet +*/ +static int colo_packet_compare_udp (Packet *spkt,Packet *ppkt) +{ +int ret; + +trace_colo_compare_main ("compare udp" ); + ret =colo_packet_compare (ppkt, spkt); + +if (ret) { +trace_colo_compare_udp_miscompare ("primary pkt size" , ppkt->size); +qemu_hexdump ((char *)ppkt->data, stderr,"colo-compare" , ppkt->size); +trace_colo_compare_udp_miscompare ("Secondary pkt size" , spkt->size); +qemu_hexdump ((char *)spkt->data, stderr,"colo-compare" , spkt->size); + } + +return ret; +} + +/* +* Called from the compare thread on the primary +* for compare icmp packet +*/ +static int colo_packet_compare_icmp (Packet *spkt,Packet *ppkt) { -trace_colo_compare_main ("compare all" ); +int network_length; + +trace_colo_compare_main ("compare icmp" ); + network_length = ppkt->ip->ip_hl *4 ; +if (ppkt->size != spkt->size || + ppkt->size < network_length +ETH_HLEN ) { +return -1 ; + } + +if (colo_packet_compare (ppkt, spkt)) { +trace_colo_compare_icmp_miscompare ("primary pkt size" , + ppkt->size); +qemu_hexdump ((char *)ppkt->data, stderr,"colo-compare" , + ppkt->size); +trace_colo_compare_icmp_miscompare ("Secondary pkt size" , + spkt->size); +qemu_hexdump ((char *)spkt->data, stderr,"colo-compare" , + spkt->size); +return -1 ; + }else { +return 0 ; + } +} + +/* +* Called from the compare thread on the primary +* for compare other packet +*/ +static int colo_packet_compare_other (Packet *spkt,Packet *ppkt) +{ +trace_colo_compare_main ("compare other" ); +trace_colo_compare_ip_info (ppkt->size,inet_ntoa (ppkt->ip->ip_src), +inet_ntoa (ppkt->ip->ip_dst), spkt->size, +inet_ntoa (spkt->ip->ip_src), +inet_ntoa (spkt->ip->ip_dst));return colo_packet_compare (ppkt, spkt); }
@@ -242,8 +365,24 @@ static void colo_compare_connection(void *opaque, void *user_data)qemu_mutex_lock (&s->timer_check_lock); pkt =g_queue_pop_tail (&conn->primary_list);qemu_mutex_unlock (&s->timer_check_lock); - result =g_queue_find_custom (&conn->secondary_list, - pkt, (GCompareFunc )colo_packet_compare_all); +switch (conn->ip_proto) { +case IPPROTO_TCP : + result =g_queue_find_custom (&conn->secondary_list, + pkt, (GCompareFunc )colo_packet_compare_tcp); +break ; +case IPPROTO_UDP : + result =g_queue_find_custom (&conn->secondary_list, + pkt, (GCompareFunc )colo_packet_compare_udp); +break ; +case IPPROTO_ICMP : + result =g_queue_find_custom (&conn->secondary_list, + pkt, (GCompareFunc )colo_packet_compare_icmp); +break ; +default : + result =g_queue_find_custom (&conn->secondary_list, + pkt, (GCompareFunc )colo_packet_compare_other); +break ; + }if (result) { ret =compare_chr_send (s->chr_out, pkt->data, pkt->size);
trace-events +3 -0
@@ -145,8 +145,11 @@ colo_proxy_main(const char *chr) ": %s" # net/colo-compare.c colo_compare_main(const char *chr) ": %s" +colo_compare_udp_miscompare(const char *sta, int size) ": %s = %d" +colo_compare_icmp_miscompare(const char *sta, int size) ": %s = %d" colo_compare_ip_info(int psize, const char *sta, const char *stb, int ssize, const char *stc, const char *std) "ppkt size = %d, ip_src = %s, ip_dst = %s, spkt size = %d, ip_src = %s, ip_dst = %s" colo_old_packet_check_found(int64_t old_time) "%" PRId64 +colo_compare_miscompare(void) "" ### Guest events, keep at bottom
Signature · 1 line
2.7.4
PATCH v14 8/12 filter-rewriter: introduce filter-rewriter initialization
In reply to Zhang ChenFilter-rewriter is a part of COLO project.
It will rewrite some of secondary packet to make secondary guest's tcp connection established successfully. In this module we will rewrite tcp packet's ack to the secondary from primary,and rewrite tcp packet's seq to the primary from secondary.
usage:
colo secondary:
-object filter-redirector,id=f1,netdev=hn0,queue=tx,indev=red0 -object filter-redirector,id=f2,netdev=hn0,queue=rx,outdev=red1 -object filter-rewriter,id=rew0,netdev=hn0,queue=all
--- net/Makefile.objs | 1 + net/filter-rewriter.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-options.hx | 13 +++++++ vl.c | 3 +- 4 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 net/filter-rewriter.c
net/Makefile.objs +1 -0
@@ -18,3 +18,4 @@ common-obj-y += filter-buffer.o common-obj-y += filter-mirror.o common-obj-y += colo-compare.o common-obj-y += colo.o +common-obj-y += filter-rewriter.o
net/filter-rewriter.c new file +105 -0
105 lines not on this page · raw message
qemu-options.hx +13 -0
@@ -3880,6 +3880,19 @@ Create a filter-redirector we need to differ outdev id from indev id, id can not be the same. we can just use indev or outdev, but at least one of indev or outdev need to be specified. +@item -object filter-rewriter,id=@var{id},netdev=@var{netdevid},rewriter-mode=@var{mode}[,queue=@var{all|rx|tx}] + +Filter-rewriter is a part of COLO project.It will rewrite tcp packet to +secondary from primary to keep secondary tcp connection,and rewrite +tcp packet to primary from secondary make tcp packet can be handled by +client. + +usage: +colo secondary: +-object filter-redirector,id=f1,netdev=hn0,queue=tx,indev=red0 +-object filter-redirector,id=f2,netdev=hn0,queue=rx,outdev=red1 +-object filter-rewriter,id=rew0,netdev=hn0,queue=all + @item -object filter-dump,id=@var{id},netdev=@var{dev},file=@var{filename}][,maxlen=@var{len}] Dump the network traffic on netdev @var{dev} to the file specified by
vl.c +2 -1
@@ -2807,7 +2807,8 @@ static bool object_create_initial(const char *type) g_str_equal(type, "filter-dump") || g_str_equal(type, "filter-mirror") || g_str_equal(type, "filter-redirector") || - g_str_equal(type, "colo-compare")) { + g_str_equal(type, "colo-compare") || + g_str_equal(type, "filter-rewriter")) {return false; }
Signature · 1 line
2.7.4
PATCH v14 9/12 filter-rewriter: track connection and parse packet
In reply to Zhang ChenWe use net/colo.h to track connection and parse packet
--- net/colo.c | 14 ++++++++++++++ net/colo.h | 1 + net/filter-rewriter.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+)
net/colo.c +14 -0
@@ -115,6 +115,20 @@ void fill_connection_key(Packet *pkt, ConnectionKey *key) } } +void reverse_connection_key (ConnectionKey *key) +{ +struct in_addr tmp_ip; +uint16_t tmp_port; + + tmp_ip = key->src; + key->src = key->dst; + key->dst = tmp_ip; + + tmp_port = key->src_port; + key->src_port = key->dst_port; + key->dst_port = tmp_port; +} +Connection *connection_new (ConnectionKey *key) {Connection *conn =g_slice_new (Connection);
net/colo.h +1 -0
@@ -68,6 +68,7 @@ uint32_t connection_key_hash(const void *opaque);int connection_key_equal (const void *opaque1,const void *opaque2);int parse_packet_early (Packet *pkt);void fill_connection_key (Packet *pkt,ConnectionKey *key); +void reverse_connection_key (ConnectionKey *key);Connection *connection_new (ConnectionKey *key);void connection_destroy (void *opaque); Connection *connection_get(GHashTable *connection_track_table,
net/filter-rewriter.c +50 -0
67 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v14 10/12 filter-rewriter: rewrite tcp packet to keep secondary connection
In reply to Zhang ChenWe will rewrite tcp packet secondary received and sent. When colo guest is a tcp server.
Firstly, client start a tcp handshake. the packet's seq=client_seq, ack=0,flag=SYN. COLO primary guest get this pkt and mirror(filter-mirror) to secondary guest, secondary get it use filter-redirector. Then,primary guest response pkt (seq=primary_seq,ack=client_seq+1,flag=ACK|SYN).
secondary guest response pkt (seq=secondary_seq,ack=client_seq+1,flag=ACK|SYN).
In here,we use filter-rewriter save the secondary_seq to it's tcp connection. Finally handshake,client send pkt (seq=client_seq+1,ack=primary_seq+1,flag=ACK). Here,filter-rewriter can get primary_seq, and rewrite ack from primary_seq+1 to secondary_seq+1, recalculate checksum. So the secondary tcp connection kept good.
When we send/recv packet.
client send pkt(seq=client_seq+1+data_len,ack=primary_seq+1,flag=ACK|PSH). filter-rewriter rewrite ack and send to secondary guest.
primary guest response pkt (seq=primary_seq+1,ack=client_seq+1+data_len,flag=ACK) secondary guest response pkt (seq=secondary_seq+1,ack=client_seq+1+data_len,flag=ACK) we rewrite secondary guest seq from secondary_seq+1 to primary_seq+1. So tcp connection kept good.
In code We use offset( = secondary_seq - primary_seq ) to rewrite seq or ack.handle_primary_tcp_pkt: tcp_pkt->th_ack += offset;handle_secondary_tcp_pkt: tcp_pkt->th_seq -= offset;
--- net/colo.c | 2 + net/colo.h | 7 ++++ net/filter-rewriter.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++++- trace-events | 5 +++ 4 files changed, 124 insertions(+), 2 deletions(-)
net/colo.c +2 -0
@@ -135,6 +135,8 @@ Connection *connection_new(ConnectionKey *key) conn->ip_proto = key->ip_proto; conn->processing = false; + conn->offset =0 ; + conn->syn_flag =0 ;g_queue_init (&conn->primary_list);g_queue_init (&conn->secondary_list);
net/colo.h +7 -0
@@ -62,6 +62,13 @@ typedef struct Connection {/* flag to enqueue unprocessed_connections */ bool processing;uint8_t ip_proto; +/* offset = secondary_seq - primary_seq */ +tcp_seq offset; +/* +* we use this flag update offset func +* run once in independent tcp connection +*/ +int syn_flag; } Connection;uint32_t connection_key_hash (const void *opaque);
net/filter-rewriter.c +110 -2
132 lines not on this page · raw message
trace-events +5 -0
@@ -151,6 +151,11 @@ colo_compare_ip_info(int psize, const char *sta, const char *stb, int ssize, con colo_old_packet_check_found(int64_t old_time) "%" PRId64 colo_compare_miscompare(void) "" +# net/filter-rewriter.c +colo_filter_rewriter_debug(void) "" +colo_filter_rewriter_pkt_info(const char *func, const char *src, const char *dst, uint32_t seq, uint32_t ack, uint32_t flag) "%s: src/dst: %s/%s p: seq/ack=%u/%u flags=%x\n" +colo_filter_rewriter_conn_offset(uint32_t offset) ": offset=%u\n" + ### Guest events, keep at bottom # @vaddr: Access' virtual address.
Signature · 1 line
2.7.4
PATCH v14 11/12 MAINTAINERS: add maintainer for COLO-proxy
In reply to Zhang Chenadd Zhang Chen and Li zhijian as co-maintainers of COLO-proxy.
--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)
MAINTAINERS +9 -0
@@ -1330,6 +1330,15 @@ F: include/qemu/throttle.h F: util/throttle.c L: [email protected] +COLO Proxy +M: Zhang Chen <[email protected]> +M: Li Zhijian <[email protected]> +S: Supported +F: docs/colo-proxy.txt +F: net/colo* +F: net/filter-rewriter.c +F: net/filter-mirror.c + Usermode Emulation ------------------ Overall
Signature · 1 line
2.7.4
PATCH v14 12/12 docs: Add documentation for COLO-proxy
In reply to Zhang ChenIntroduce the design of COLO-proxy, and how to use it.
--- docs/colo-proxy.txt | 188 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100644 docs/colo-proxy.txt
docs/colo-proxy.txt new file +188 -0
@@ -0,0 +1,188 @@ +COLO-proxy +---------- +Copyright (c) 2016 Intel Corporation +Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD. +Copyright (c) 2016 Fujitsu, Corp. + +This work is licensed under the terms of the GNU GPL, version 2 or later. +See the COPYING file in the top-level directory. + +This document gives an overview of COLO proxy's design. + +== Background == +COLO-proxy is a part of COLO project. It is used +to compare the network package to help COLO decide +whether to do checkpoint. With COLO-proxy's help, +COLO greatly improves the performance. + +The filter-redirector, filter-mirror, colo-compare +and filter-rewriter compose the COLO-proxy. + +== Architecture == + +COLO-Proxy is based on qemu netfilter and it's a plugin for qemu netfilter +(except colo-compare). It keep Secondary VM connect normally to +client and compare packets sent by PVM with sent by SVM. +If the packet difference, notify COLO-frame to do checkpoint and send +all primary packet has queued. Otherwise just send the queued primary +packet and drop the queued secondary packet. + +Below is a COLO proxy ascii figure: + + Primary qemu Secondary qemu ++--------------------------------------------------------------+ +----------------------------------------------------------------+ +| +----------------------------------------------------------+ | | +-----------------------------------------------------------+ | +| | | | | | | | +| | guest | | | | guest | | +| | | | | | | | +| +-------^--------------------------+-----------------------+ | | +---------------------+--------+----------------------------+ | +| | | | | ^ | | +| | | | | | | | +| | +------------------------------------------------------+ | | | | +|netfilter| | | | | | netfilter | | | +| +----------+ +----------------------------+ | | | +-----------------------------------------------------------+ | +| | | | | | out | | | | | | filter excute order | | +| | | | +-----------------------------+ | | | | | | +-------------------> | | +| | | | | | | | | | | | | | TCP | | +| | +-----+--+-+ +-----v----+ +-----v----+ |pri +----+----+sec| | | | +------------+ +---+----+---v+rewriter++ +------------+ | | +| | | | | | | | |in | |in | | | | | | | | | | | | | +| | | filter | | filter | | filter +------> colo <------+ +--------> filter +--> adjust | adjust +--> filter | | | +| | | mirror | |redirector| |redirector| | | compare | | | | | | redirector | | ack | seq | | redirector | | | +| | | | | | | | | | | | | | | | | | | | | | | | +| | +----^-----+ +----+-----+ +----------+ | +---------+ | | | | +------------+ +--------+--------------+ +---+--------+ | | +| | | tx | rx rx | | | | | tx all | rx | | +| | | | | | | | +-----------------------------------------------------------+ | +| | | +--------------+ | | | | | | +| | | filter excute order | | | | | | | +| | | +----------------> | | | +--------------------------------------------------------+ | +| +-----------------------------------------+ | | | +| | | | | | ++--------------------------------------------------------------+ +----------------------------------------------------------------+ + |guest receive | guest send + | | ++--------+----------------------------v------------------------+ +| | NOTE: filter direction is rx/tx/all +| tap | rx:receive packets sent to the netdev +| | tx:receive packets sent by the netdev ++--------------------------------------------------------------+ + +1.Guest receive packet route: + +Primary: + +Tap --> Mirror Client Filter +Mirror client will send packet to guest,at the +same time, copy and forward packet to secondary +mirror server. + +Secondary: + +Mirror Server Filter --> TCP Rewriter +If receive packet is TCP packet,we will adjust ack +and update TCP checksum, then send to secondary +guest. Otherwise directly send to guest. + +2.Guest send packet route: + +Primary: + +Guest --> Redirect Server Filter +Redirect server filter receive primary guest packet +but do nothing, just pass to next filter. + +Redirect Server Filter --> COLO-Compare +COLO-compare receive primary guest packet then +waiting scondary redirect packet to compare it. +If packet same,send queued primary packet and clear +queued secondary packet, Otherwise send primary packet +and do checkpoint. + +COLO-Compare --> Another Redirector Filter +The redirector get packet from colo-compare by use +chardev socket. + +Redirector Filter --> Tap +Send the packet. + +Secondary: + +Guest --> TCP Rewriter Filter +If the packet is TCP packet,we will adjust seq +and update TCP checksum. Then send it to +redirect client filter. Otherwise directly send to +redirect client filter. + +Redirect Client Filter --> Redirect Server Filter +Forward packet to primary. + +== Components introduction == + +Filter-mirror is a netfilter plugin. +It gives qemu the ability to mirror +packets to a chardev. + +Filter-redirector is a netfilter plugin. +It gives qemu the ability to redirect net packet. +Redirector can redirect filter's net packet to outdev, +and redirect indev's packet to filter. + + filter + + + redirector | + +--------------+ + | | | + | | | + | | | + indev +---------+ +----------> outdev + | | | + | | | + | | | + +--------------+ + | + v + filter + +COLO-compare, we do packet comparing job. +Packets coming from the primary char indev will be sent to outdev. +Packets coming from the secondary char dev will be dropped after comparing. +COLO-comapre need two input chardev and one output chardev: +primary_in=chardev1-id (source: primary send packet) +secondary_in=chardev2-id (source: secondary send packet) +outdev=chardev3-id + +Filter-rewriter will rewrite some of secondary packet to make +secondary guest's tcp connection established successfully. +In this module we will rewrite tcp packet's ack to the secondary +from primary,and rewrite tcp packet's seq to the primary from +secondary. + +== Usage == + +Here, we use demo ip and port discribe more clearly. +Primary(ip:3.3.3.3): +-netdev tap,id=hn0,vhost=off,script=/etc/qemu-ifup,downscript=/etc/qemu-ifdown +-device e1000,id=e0,netdev=hn0,mac=52:a4:00:12:78:66 +-chardev socket,id=mirror0,host=3.3.3.3,port=9003,server,nowait +-chardev socket,id=compare1,host=3.3.3.3,port=9004,server,nowait +-chardev socket,id=compare0,host=3.3.3.3,port=9001,server,nowait +-chardev socket,id=compare0-0,host=3.3.3.3,port=9001 +-chardev socket,id=compare_out,host=3.3.3.3,port=9005,server,nowait +-chardev socket,id=compare_out0,host=3.3.3.3,port=9005 +-object filter-mirror,id=m0,netdev=hn0,queue=tx,outdev=mirror0 +-object filter-redirector,netdev=hn0,id=redire0,queue=rx,indev=compare_out +-object filter-redirector,netdev=hn0,id=redire1,queue=rx,outdev=compare0 +-object colo-compare,id=comp0,primary_in=compare0-0,secondary_in=compare1,outdev=compare_out0 + +Secondary(ip:3.3.3.8): +-netdev tap,id=hn0,vhost=off,script=/etc/qemu-ifup,down script=/etc/qemu-ifdown +-device e1000,netdev=hn0,mac=52:a4:00:12:78:66 +-chardev socket,id=red0,host=3.3.3.3,port=9003 +-chardev socket,id=red1,host=3.3.3.3,port=9004 +-object filter-redirector,id=f1,netdev=hn0,queue=tx,indev=red0 +-object filter-redirector,id=f2,netdev=hn0,queue=rx,outdev=red1 + +Note: + a.COLO-proxy must work with COLO-frame and Block-replication. + b.Primary COLO must be started firstly, because COLO-proxy needs + chardev socket server running before secondary started. + c.Filter-rewriter only rewrite tcp packet.
Signature · 1 line
2.7.4
Jason Wang
AppliedQuoted 20 lines · Zhang Chen
COLO-proxy is a part of COLO project. COLO project is composed of COLO-frame, COLO-proxy and block-replication. It is used to compare the network package to help COLO decide whether to do checkpoint. With COLO-proxy's help, COLO greatly improves the performance.
The filter-redirector, filter-mirror, colo-compare and filter-rewriter compose the COLO-proxy.
COLO-compare
It is used to compare the network package to help COLO decide whether to do checkpoint.Filter-rewriter
It will rewrite some of secondary packet to make secondary guest's connection established successfully. In this module we will rewrite tcp packet's ack to the secondary from primary,and rewrite tcp packet's seq to the primary from secondary.
Quoted 7 lines
The full version in this github:
https://github.com/zhangckid/qemu/tree/colo-v2.7-proxy-mode-compare-and-rewriter-sep8v14:
- fix some coding style problems
- move patch "adddocs/colo-proxy.txt" to the end of this series
- fix the mingw build issue
Applied, thanks.
Quoted 201 lines
v13:
- adddocs/colo-proxy.txt
- addMAINTAINERS
- remove unnecessary .h
- removeQTAILQ_ENTRY(CompareState)
- fix some comments
- addfind_and_check_chardev()to avoid code duplication
- remove the "is_unix" in patch3
- changeerror_report()to trace in patch4
- usel2hdr_lenhere instead ofETH_HLEP
- fix code style
- removecolo_rm_connection()
- removehashtable_size
- changeg_queue_foreach()tog_queue_find_custom()in patch7
- changetrace_colo_compare_tcp_miscompare()tofprintf()in patch8
- add codes not queue vlan packetsv12:
- add qemu-char: Addqemu_chr_add_handlers_full()for GMaincontext to this series as the first patch.
- update COLO net ascii figure.
- add chardev socket check.
- fix some typo.
- add some comments.
- renamenet/colo-base.ctonet/colo.c
- rename network/transport_layer to network/transport_header.
- move the job that clearcoon_listwhenhashtable_sizeoversize toconnection_get.
- reuseconnection_destroy()docolo_rm_connection().
- fix pkt mem leak incolo_compare_connection(). (result be released ing_queue_remove(), so it were not leak)
- renamethread_name"compare" to "colo-compare".
- change icmp compare tomemcmp().v11:
- Make patch 5 to a independent patch series.
[PATCH V3] qemu-char: Addqemu_chr_add_handlers_full()for GMaincontext
- For Jason's comments, merge filter-rewriter to this series.(patch 7,8,9)- Add
reverse_connection_key()
- removeconn_listin filter-rewriter
- removeunprocessed_connections
- add some commentsv10:
- fix typo
- Should we make patch 5 independent with this series? This patch just add a API for qemu-char.v9:
p5:
- usechr_update_read_handler_full()replace
thechr_update_read_handler()
- useio_watch_poll_prepare_full()replace
theio_watch_poll_prepare()
- useio_watch_poll_funcs_fullreplace
theio_watch_poll_funcs
- avoid code duplicationv8:
p5:
- add new patch:
qemu-char: Addqemu_chr_add_handlers_full()for GMaincontextv7:
p5:
- add [PATCH]qemu-char: Fix context forg_source_attach()in this patch series.v6:
p6:
- add more commit log.
- fix icmp comparison to compare all packet.p5:
- add more cpmments in commit log.
- changeREGULAR_CHECK_MStoREGULAR_PACKET_CHECK_MS
- make check old packet independent to compare thread
- removethread_statusp4:
- change this patch only about
Connection and ConnectionKey.
- add some comments in commit log.
- remove mode infill_connection_key().
- fix some comments and bug.
- movecolo_conn_stateto patch of
"work with colo-frame"
- removeconn_list_lock.
- addMAX_QUEUE_SIZE, ifprimary_listor
secondary_listbiger thanMAX_QUEUE_SIZE
we will drop packet.p3:
- add new independent kernel jhash patch.p2:
- add new independent colo-base patch.p1:
- add a ascii figure and some comments to explain it
- movetrace.hto p2
- moveQTAILQ_HEAD(, CompareState)net_comparesto patch of "work with colo-frame"
- add some comments in qemu-option.hxv5:
p3:
- comments from Jason
we poll and handle chardev in comapre thread, Through this way, there's no need for extra synchronization with main loop
this depend on another patch:
qemu-char: Fix context forg_source_attach()
- remove QemuEvent
p2:
- removeconn->list_lock
p1:
- move compare_pri/sec_chr_in to p3
- movecompare_chr_sendto p2v4:
p4:
- add some comments
- fix some trace-events
- fix tcp compare error
p3:
- addrcu_read_lock().
- fix trace name
- fix jason's other comments
- rebase some Dave's branch function
p2:
-colo_compare_connection()changeg_queue_push_head()to
-g_queue_push_tail()match to sorted order.
- removepkt->s
- move data structure tocolo-base.h
- addcolo-base.creuse codes for filter-rewriter
- add some filter-rewriter needs struct
- depends on previous SocketReadState patch
p1:
- except moveqemu_chr_add_handlers()
to colo thread
- removeclass_finalize
- remove secondary arp codes
- depends on previous SocketReadState patchv3:
- rebase colo-compare to colo-frame v2.7
- fix most of Dave's comments
(except RCU)
- add TCP,UDP,ICMP and other packet comparison
- add trace-event
- add some comments
- other bug fix
- add RFC index
- add usage in patch 1/4v2:
- addjhash.hv1:
- initial patchZhang Chen (12):
qemu-char: Addqemu_chr_add_handlers_full()for GMaincontext
colo-compare: introduce colo compare initializationnet/colo.c: addcolo.cto define and handle packet
Jhash: add linux kernel jhashtable in qemu
colo-compare: track connection and enqueue packet
colo-compare: introduce packet comparison thread
colo-compare: add TCP,UDP,ICMP packet comparison
filter-rewriter: introduce filter-rewriter initialization
filter-rewriter: track connection and parse packet
filter-rewriter: rewrite tcp packet to keep secondary connection
MAINTAINERS: add maintainer for COLO-proxy
docs: Add documentation for COLO-proxyMAINTAINERS | 9 + docs/colo-proxy.txt | 188 ++++++++++++ include/qemu/jhash.h | 59 ++++ include/sysemu/char.h | 11 +- net/Makefile.objs | 3 + net/colo-compare.c | 781 ++++++++++++++++++++++++++++++++++++++++++++++++++ net/colo.c | 212 ++++++++++++++ net/colo.h | 88 ++++++ net/filter-rewriter.c | 263 +++++++++++++++++ qemu-char.c | 77 +++-- qemu-options.hx | 52 ++++ trace-events | 16 ++ vl.c | 4 +- 13 files changed, 1737 insertions(+), 26 deletions(-)create mode 100644
docs/colo-proxy.txt
create mode 100644include/qemu/jhash.h
create mode 100644net/colo-compare.c
create mode 100644net/colo.c
create mode 100644net/colo.h
create mode 100644net/filter-rewriter.c