From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57384) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWrKd-0007iT-EO for qemu-devel@nongnu.org; Fri, 19 Feb 2016 15:07:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aWrKa-0007rm-3y for qemu-devel@nongnu.org; Fri, 19 Feb 2016 15:07:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44515) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWrKZ-0007ri-TA for qemu-devel@nongnu.org; Fri, 19 Feb 2016 15:07:12 -0500 Date: Fri, 19 Feb 2016 20:07:06 +0000 From: "Dr. David Alan Gilbert" Message-ID: <20160219200705.GM2412@work-vm> References: <1450780978-19123-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> <1450780978-19123-10-git-send-email-zhangchen.fnst@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1450780978-19123-10-git-send-email-zhangchen.fnst@cn.fujitsu.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [RFC PATCH v2 09/10] net/colo-proxy: Compare pri pkt to sec pkt List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Zhang Chen Cc: zhanghailiang , Li Zhijian , Gui jianfeng , Jason Wang , "eddie.dong" , qemu devel , Huang peng , Gong lei , Stefan Hajnoczi , jan.kiszka@siemens.com, Yang Hongyang * Zhang Chen (zhangchen.fnst@cn.fujitsu.com) wrote: > From: zhangchen >=20 > We will compare packet sent by primary guest > to secondary guest,if same,send primary packet. > else we will notify colo to do checkpoint to > make secondary guset running same as primary >=20 > Signed-off-by: zhangchen > Signed-off-by: zhanghailiang > --- > net/colo-proxy.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++= ++++++++ > 1 file changed, 64 insertions(+) >=20 > diff --git a/net/colo-proxy.c b/net/colo-proxy.c > index 06bab80..abb289f 100644 > --- a/net/colo-proxy.c > +++ b/net/colo-proxy.c > @@ -602,6 +602,70 @@ static void colo_proxy_notify_checkpoint(void) > colo_do_checkpoint =3D true; > } > =20 > +/* > + * The IP packets sent by primary and secondary > + * will be comparison in here > + * TODO=EF=BC=9A support ip fragment > + * return: 0 means packet same > + * > 0 || < 0 means packet different > + */ > +static int colo_packet_compare(Packet *ppkt, Packet *spkt) > +{ > + trace_colo_proxy("colo_packet_compare data ppkt"); > + trace_colo_proxy_packet_size(ppkt->size); > + trace_colo_proxy_packet_src(inet_ntoa(ppkt->ip->ip_src)); > + trace_colo_proxy_packet_dst(inet_ntoa(ppkt->ip->ip_dst)); > + colo_proxy_dump_packet(ppkt); > + trace_colo_proxy("colo_packet_compare data spkt"); > + trace_colo_proxy_packet_size(spkt->size); > + trace_colo_proxy_packet_src(inet_ntoa(spkt->ip->ip_src)); > + trace_colo_proxy_packet_dst(inet_ntoa(spkt->ip->ip_dst)); > + colo_proxy_dump_packet(spkt); > + > + if (ppkt->size =3D=3D spkt->size) { > + return memcmp(ppkt->data, spkt->data, spkt->size); > + } else { > + trace_colo_proxy("colo_packet_compare size not same"); > + return -1; > + } > +} > + > +static void colo_compare_connection(void *opaque, void *user_data) > +{ > + Connection *conn =3D opaque; > + Packet *pkt =3D NULL; > + GList *result =3D NULL; > + > + while (!g_queue_is_empty(&conn->primary_list) && > + !g_queue_is_empty(&conn->secondary_list)) { > + pkt =3D g_queue_pop_head(&conn->primary_list); > + result =3D g_queue_find_custom(&conn->secondary_list, > + pkt, (GCompareFunc)colo_packet_compare); Are you sure the 'ppkt' and 'spkt' are the right way around in colo_packe= t_compare? (Not that in this simple version it makes much difference). My reading of g_queue_find_custom's man page is that the first parameter of the compare function comes from the list, which is the secondary. > + if (result) { > + colo_send_primary_packet(pkt, NULL); > + trace_colo_proxy("packet same and release packet"); > + } else { > + g_queue_push_tail(&conn->primary_list, pkt); You pop the packets off the head of the primary list above, but push it back to the tail here; why do you reorder? Dave > + trace_colo_proxy("packet different"); > + colo_proxy_notify_checkpoint(); > + break; > + } > + } > +} > + > +static void *colo_proxy_compare_thread(void *opaque) > +{ > + COLOProxyState *s =3D opaque; > + > + while (s->status =3D=3D COLO_PROXY_RUNNING) { > + qemu_event_wait(&s->need_compare_ev); > + qemu_event_reset(&s->need_compare_ev); > + g_queue_foreach(&s->conn_list, colo_compare_connection, NULL); > + } > + > + return NULL; > +} > + > static void colo_proxy_start_one(NetFilterState *nf, > void *opaque, Error **errp) > { > --=20 > 1.9.1 >=20 >=20 >=20 >=20 -- Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK