From patchwork Tue Jan 24 14:05:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhanghailiang X-Patchwork-Id: 9535277 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 506D06042D for ; Tue, 24 Jan 2017 14:12:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 391F7280CF for ; Tue, 24 Jan 2017 14:12:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2DD44280F4; Tue, 24 Jan 2017 14:12:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4C9B4280CF for ; Tue, 24 Jan 2017 14:12:00 +0000 (UTC) Received: from localhost ([::1]:50113 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cW1pH-0000Kj-Cj for patchwork-qemu-devel@patchwork.kernel.org; Tue, 24 Jan 2017 09:11:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58352) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cW1lz-00068g-OV for qemu-devel@nongnu.org; Tue, 24 Jan 2017 09:08:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cW1lx-0005pB-2B for qemu-devel@nongnu.org; Tue, 24 Jan 2017 09:08:35 -0500 Received: from szxga01-in.huawei.com ([58.251.152.64]:24094) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1cW1lw-0005gQ-AT for qemu-devel@nongnu.org; Tue, 24 Jan 2017 09:08:33 -0500 Received: from 172.24.1.47 (EHLO szxeml427-hub.china.huawei.com) ([172.24.1.47]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DYH24425; Tue, 24 Jan 2017 22:06:20 +0800 (CST) Received: from localhost (10.177.24.212) by szxeml427-hub.china.huawei.com (10.82.67.182) with Microsoft SMTP Server id 14.3.235.1; Tue, 24 Jan 2017 22:06:12 +0800 From: zhanghailiang To: , Date: Tue, 24 Jan 2017 22:05:47 +0800 Message-ID: <1485266748-15340-3-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 2.7.2.windows.1 In-Reply-To: <1485266748-15340-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1485266748-15340-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.24.212] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020206.58875F5D.02F1, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 1130cc737414bb5d0ef106a146fbe5d6 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 58.251.152.64 Subject: [Qemu-devel] [PATCH 2/3] colo-compare: add API to flush all queued packets while do checkpoint X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lizhijian@cn.fujitsu.com, zhangchen.fnst@cn.fujitsu.com, zhanghailiang Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Zhang Chen While COLO does checkpoint, we need to flush all queued packets of COLO proxy, use a new API to do these things, and export it which will be used by COLO frame. Signed-off-by: Zhang Chen Signed-off-by: zhanghailiang --- net/colo-compare.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ net/colo-compare.h | 20 ++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 net/colo-compare.h diff --git a/net/colo-compare.c b/net/colo-compare.c index 9bea62a..2ad577b 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -29,11 +29,15 @@ #include "qemu/sockets.h" #include "qapi-visit.h" #include "net/colo.h" +#include "net/colo-compare.h" #define TYPE_COLO_COMPARE "colo-compare" #define COLO_COMPARE(obj) \ OBJECT_CHECK(CompareState, (obj), TYPE_COLO_COMPARE) +static QTAILQ_HEAD(, CompareState) net_compares = + QTAILQ_HEAD_INITIALIZER(net_compares); + #define COMPARE_READ_LEN_MAX NET_BUFSIZE #define MAX_QUEUE_SIZE 1024 @@ -88,6 +92,8 @@ typedef struct CompareState { /* Timer used on the primary to find packets that are never matched */ QEMUTimer *timer; + + QTAILQ_ENTRY(CompareState) next; } CompareState; typedef struct CompareClass { @@ -181,6 +187,39 @@ static int packet_enqueue(CompareState *s, int mode) return 0; } +static void colo_flush_connection(void *opaque, void *user_data) +{ + CompareState *s = user_data; + Connection *conn = opaque; + Packet *pkt = NULL; + + qemu_mutex_lock(&conn->conn_lock); + while (!g_queue_is_empty(&conn->primary_list)) { + pkt = g_queue_pop_head(&conn->primary_list); + compare_chr_send(&s->chr_out, pkt->data, pkt->size); + packet_destroy(pkt, NULL); + } + while (!g_queue_is_empty(&conn->secondary_list)) { + pkt = g_queue_pop_head(&conn->secondary_list); + packet_destroy(pkt, NULL); + } + qemu_mutex_unlock(&conn->conn_lock); +} + +/* Fix Me: better to use notifier way */ +void colo_compare_do_checkpoint(void) +{ + CompareState *s; + + trace_colo_compare_main("colo_compare_do_checkpoint"); + + QTAILQ_FOREACH(s, &net_compares, next) { + qemu_mutex_lock(&s->conn_list_lock); + g_queue_foreach(&s->conn_list, colo_flush_connection, s); + qemu_mutex_unlock(&s->conn_list_lock); + } +} + /* * The IP packets sent by primary and secondary * will be compared in here @@ -387,6 +426,11 @@ static void colo_compare_connection(void *opaque, void *user_data) while (!g_queue_is_empty(&conn->primary_list) && !g_queue_is_empty(&conn->secondary_list)) { pkt = g_queue_pop_tail(&conn->primary_list); + if (!pkt) { + error_report("colo-compare pop pkt failed"); + return; + } + switch (conn->ip_proto) { case IPPROTO_TCP: result = g_queue_find_custom(&conn->secondary_list, @@ -726,6 +770,10 @@ static void colo_compare_finalize(Object *obj) qemu_chr_fe_deinit(&s->chr_sec_in); qemu_chr_fe_deinit(&s->chr_out); + if (!QTAILQ_EMPTY(&net_compares)) { + QTAILQ_REMOVE(&net_compares, s, next); + } + g_queue_free(&s->conn_list); if (qemu_thread_is_self(&s->thread)) { diff --git a/net/colo-compare.h b/net/colo-compare.h new file mode 100644 index 0000000..44f9014 --- /dev/null +++ b/net/colo-compare.h @@ -0,0 +1,20 @@ +/* + * COarse-grain LOck-stepping Virtual Machines for Non-stop Service (COLO) + * (a.k.a. Fault Tolerance or Continuous Replication) + * + * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD. + * Copyright (c) 2016 FUJITSU LIMITED + * Copyright (c) 2016 Intel Corporation + * + * Author: Zhang Chen + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * later. See the COPYING file in the top-level directory. + */ + +#ifndef QEMU_COLO_COMPARE_H +#define QEMU_COLO_COMPARE_H + +void colo_compare_do_checkpoint(void); + +#endif /* QEMU_COLO_COMPARE_H */