From patchwork Fri Nov 27 12:27:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Chen X-Patchwork-Id: 549448 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id EB2BD1402B8 for ; Fri, 27 Nov 2015 23:33:51 +1100 (AEDT) Received: from localhost ([::1]:56322 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a2IDl-0002DU-N6 for incoming@patchwork.ozlabs.org; Fri, 27 Nov 2015 07:33:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52500) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a2I6h-0007NR-4D for qemu-devel@nongnu.org; Fri, 27 Nov 2015 07:26:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a2I6f-0002wZ-VL for qemu-devel@nongnu.org; Fri, 27 Nov 2015 07:26:31 -0500 Received: from [59.151.112.132] (port=49652 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a2I6f-0002nQ-Gz for qemu-devel@nongnu.org; Fri, 27 Nov 2015 07:26:29 -0500 X-IronPort-AV: E=Sophos;i="5.20,346,1444665600"; d="scan'208";a="918283" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 27 Nov 2015 20:26:10 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 8463E4066D0B; Fri, 27 Nov 2015 20:25:56 +0800 (CST) Received: from G08FNSTD140215.g08.fujitsu.local (10.167.226.56) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Fri, 27 Nov 2015 20:25:56 +0800 From: Zhang Chen To: qemu devel , Jason Wang , Stefan Hajnoczi Date: Fri, 27 Nov 2015 20:27:27 +0800 Message-ID: <1448627251-11186-6-git-send-email-zhangchen.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1448627251-11186-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> References: <1448627251-11186-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.56] X-yoursite-MailScanner-Information: Please contact the ISP for more information X-yoursite-MailScanner-ID: 8463E4066D0B.AD09B X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: zhangchen.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Cc: Li Zhijian , Gui jianfeng , "eddie.dong" , "Dr. David Alan Gilbert" , Huang peng , Gong lei , jan.kiszka@siemens.com, Zhang Chen , zhanghailiang Subject: [Qemu-devel] [RFC PATCH 5/9] net/colo-proxy: add colo packet handler X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: zhangchen add primary and secondary handler Signed-off-by: zhangchen --- net/colo-proxy.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 103 insertions(+), 2 deletions(-) diff --git a/net/colo-proxy.c b/net/colo-proxy.c index 89d9616..ece5661 100644 --- a/net/colo-proxy.c +++ b/net/colo-proxy.c @@ -25,6 +25,101 @@ static char *mode; static bool colo_do_checkpoint; +/* + * colo primary handle host's normal send and + * recv packets to primary guest + * return: >= 0 success + * < 0 failed + */ +static ssize_t colo_proxy_primary_handler(NetFilterState *nf, + NetClientState *sender, + unsigned flags, + const struct iovec *iov, + int iovcnt, + NetPacketSent *sent_cb) +{ + ssize_t ret = 0; + int direction; + + if (sender == nf->netdev) { + /* This packet is sent by netdev itself */ + direction = NET_FILTER_DIRECTION_TX; + } else { + direction = NET_FILTER_DIRECTION_RX; + } + /* + * if packet's direction=rx + * enqueue packets to primary queue + * and wait secondary queue to compare + * if packet's direction=tx + * enqueue packets then send packets to + * secondary and flush queued packets + */ + + if (colo_do_checkpoint) { + colo_proxy_do_checkpoint(nf); + } + + if (direction == NET_FILTER_DIRECTION_RX) { + /* TODO: enqueue_primary_packet */ + } else { + /* TODO: forward packets to another */ + } + + return ret; +} + +/* + * colo secondary handle host's normal send and + * recv packets to secondary guest + * return: >= 0 success + * < 0 failed + */ +static ssize_t colo_proxy_secondary_handler(NetFilterState *nf, + NetClientState *sender, + unsigned flags, + const struct iovec *iov, + int iovcnt, + NetPacketSent *sent_cb) +{ + ColoProxyState *s = FILTER_COLO_PROXY(nf); + int direction; + ssize_t ret = 0; + + if (sender == nf->netdev) { + /* This packet is sent by netdev itself */ + direction = NET_FILTER_DIRECTION_TX; + } else { + direction = NET_FILTER_DIRECTION_RX; + } + /* + * if packet's direction=rx + * enqueue packets and send to + * primary QEMU + * if packet's direction=tx + * record PVM's packet inital seq & adjust + * client's ack,send adjusted packets to SVM(next version will be do) + */ + + if (direction == NET_FILTER_DIRECTION_RX) { + if (colo_has_failover(nf)) { + qemu_net_queue_send_iov(s->incoming_queue, sender, flags, iov, + iovcnt, NULL); + return 1; + } else { + /* TODO: forward packets to another */ + } + + } else { + if (colo_has_failover(nf)) { + qemu_net_queue_send_iov(s->incoming_queue, sender, flags, iov, + iovcnt, NULL); + } + return 1; + } + return ret; +} + static ssize_t colo_proxy_receive_iov(NetFilterState *nf, NetClientState *sender, unsigned flags, @@ -38,10 +133,16 @@ static ssize_t colo_proxy_receive_iov(NetFilterState *nf, * */ ColoProxyState *s = FILTER_COLO_PROXY(nf); + ssize_t ret = 0; if (s->colo_mode == COLO_PRIMARY_MODE) { - /* colo_proxy_primary_handler */ + ret = colo_proxy_primary_handler(nf, sender, flags, + iov, iovcnt, sent_cb); } else { - /* colo_proxy_primary_handler */ + ret = colo_proxy_secondary_handler(nf, sender, flags, + iov, iovcnt, sent_cb); + } + if (ret < 0) { + DEBUG("colo_proxy_receive_iov running failed\n"); } return iov_size(iov, iovcnt); }