From patchwork Fri Nov 27 12:27:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Chen X-Patchwork-Id: 549431 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 1BD7A1402D4 for ; Fri, 27 Nov 2015 23:27:10 +1100 (AEDT) Received: from localhost ([::1]:56250 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a2I7G-0008SC-1M for incoming@patchwork.ozlabs.org; Fri, 27 Nov 2015 07:27:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52458) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a2I6f-0007LA-T3 for qemu-devel@nongnu.org; Fri, 27 Nov 2015 07:26:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a2I6e-0002vn-BQ for qemu-devel@nongnu.org; Fri, 27 Nov 2015 07:26:29 -0500 Received: from [59.151.112.132] (port=43907 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a2I6d-0002gO-JF for qemu-devel@nongnu.org; Fri, 27 Nov 2015 07:26:28 -0500 X-IronPort-AV: E=Sophos;i="5.20,346,1444665600"; d="scan'208";a="918274" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 27 Nov 2015 20:26:02 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id A39774043095; Fri, 27 Nov 2015 20:25:54 +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:54 +0800 From: Zhang Chen To: qemu devel , Jason Wang , Stefan Hajnoczi Date: Fri, 27 Nov 2015 20:27:25 +0800 Message-ID: <1448627251-11186-4-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: A39774043095.ABFC5 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 3/9] colo-proxy: add colo-proxy framework 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 Colo-proxy is a plugin of qemu netfilter like filter-buffer and dump Signed-off-by: zhangchen --- net/Makefile.objs | 1 + net/colo-proxy.c | 139 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ net/colo-proxy.h | 63 +++++++++++++++++++++++++ 3 files changed, 203 insertions(+) create mode 100644 net/colo-proxy.c create mode 100644 net/colo-proxy.h diff --git a/net/Makefile.objs b/net/Makefile.objs index 5fa2f97..95670f2 100644 --- a/net/Makefile.objs +++ b/net/Makefile.objs @@ -15,3 +15,4 @@ common-obj-$(CONFIG_VDE) += vde.o common-obj-$(CONFIG_NETMAP) += netmap.o common-obj-y += filter.o common-obj-y += filter-buffer.o +common-obj-y += colo-proxy.o diff --git a/net/colo-proxy.c b/net/colo-proxy.c new file mode 100644 index 0000000..98c2699 --- /dev/null +++ b/net/colo-proxy.c @@ -0,0 +1,139 @@ +/* + * COarse-grain LOck-stepping Virtual Machines for Non-stop Service (COLO) + * (a.k.a. Fault Tolerance or Continuous Replication) + * + * Copyright (c) 2015 HUAWEI TECHNOLOGIES CO., LTD. + * Copyright (c) 2015 FUJITSU LIMITED + * Copyright (c) 2015 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. + */ + +#include "colo-proxy.h" + +#define __DEBUG__ + +#ifdef __DEBUG__ +#define DEBUG(format, ...) printf(format, ##__VA_ARGS__) +#else +#define DEBUG(format, ...) +#endif + + +static ssize_t colo_proxy_receive_iov(NetFilterState *nf, + NetClientState *sender, + unsigned flags, + const struct iovec *iov, + int iovcnt, + NetPacketSent *sent_cb) +{ + /* + * We return size when buffer a packet, the sender will take it as + * a already sent packet, so sent_cb should not be called later. + * + */ + ColoProxyState *s = FILTER_COLO_PROXY(nf); + if (s->colo_mode == COLO_PRIMARY_MODE) { + /* colo_proxy_primary_handler */ + } else { + /* colo_proxy_primary_handler */ + } + return iov_size(iov, iovcnt); +} + +static void colo_proxy_cleanup(NetFilterState *nf) +{ + /* cleanup */ +} + + +static void colo_proxy_setup(NetFilterState *nf, Error **errp) +{ + ColoProxyState *s = FILTER_COLO_PROXY(nf); + if (!s->addr) { + error_setg(errp, "filter colo_proxy needs 'addr' \ + property set!"); + return; + } + + if (nf->direction != NET_FILTER_DIRECTION_ALL) { + printf("colo need queue all packet,\ + please startup colo-proxy with queue=all\n"); + return; + } + + s->sockfd = -1; + s->has_failover = false; + colo_do_checkpoint = false; + g_queue_init(&s->unprocessed_connections); + + if (!strcmp(mode, PRIMARY_MODE)) { + s->colo_mode = COLO_PRIMARY_MODE; + } else if (!strcmp(mode, SECONDARY_MODE)) { + s->colo_mode = COLO_SECONDARY_MODE; + } else { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "mode", + "primary or secondary"); + return; + } +} + +static void colo_proxy_class_init(ObjectClass *oc, void *data) +{ + NetFilterClass *nfc = NETFILTER_CLASS(oc); + + nfc->setup = colo_proxy_setup; + nfc->cleanup = colo_proxy_cleanup; + nfc->receive_iov = colo_proxy_receive_iov; +} + +static char *colo_proxy_get_mode(Object *obj, Error **errp) +{ + return g_strdup(mode); +} + +static void colo_proxy_set_mode(Object *obj, const char *value, Error **errp) +{ + g_free(mode); + mode = g_strdup(value); +} + +static char *colo_proxy_get_addr(Object *obj, Error **errp) +{ + ColoProxyState *s = FILTER_COLO_PROXY(obj); + + return g_strdup(s->addr); +} + +static void colo_proxy_set_addr(Object *obj, const char *value, Error **errp) +{ + ColoProxyState *s = FILTER_COLO_PROXY(obj); + g_free(s->addr); + s->addr = g_strdup(value); +} + +static void colo_proxy_init(Object *obj) +{ + object_property_add_str(obj, "mode", colo_proxy_get_mode, + colo_proxy_set_mode, NULL); + object_property_add_str(obj, "addr", colo_proxy_get_addr, + colo_proxy_set_addr, NULL); +} + +static const TypeInfo colo_proxy_info = { + .name = TYPE_FILTER_COLO_PROXY, + .parent = TYPE_NETFILTER, + .class_init = colo_proxy_class_init, + .instance_init = colo_proxy_init, + .instance_size = sizeof(ColoProxyState), +}; + +static void register_types(void) +{ + type_register_static(&colo_proxy_info); +} + +type_init(register_types); diff --git a/net/colo-proxy.h b/net/colo-proxy.h new file mode 100644 index 0000000..94afbc7 --- /dev/null +++ b/net/colo-proxy.h @@ -0,0 +1,63 @@ +/* + * COarse-grain LOck-stepping Virtual Machines for Non-stop Service (COLO) + * (a.k.a. Fault Tolerance or Continuous Replication) + * + * Copyright (c) 2015 HUAWEI TECHNOLOGIES CO., LTD. + * Copyright (c) 2015 FUJITSU LIMITED + * Copyright (c) 2015 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_PROXY_H +#define QEMU_COLO_PROXY_H + +#include "net/filter.h" +#include "net/queue.h" +#include "qemu-common.h" +#include "qemu/iov.h" +#include "qapi/qmp/qerror.h" +#include "qapi-visit.h" +#include "qom/object.h" +#include "qemu/sockets.h" +#include "qemu/main-loop.h" +#include +#include "qemu/jhash.h" +#include "qemu/coroutine.h" + +#define FILTER_COLO_PROXY(obj) \ + OBJECT_CHECK(ColoProxyState, (obj), TYPE_FILTER_COLO_PROXY) + +#define TYPE_FILTER_COLO_PROXY "colo-proxy" +#define PRIMARY_MODE "primary" +#define SECONDARY_MODE "secondary" + +typedef enum { + COLO_PRIMARY_MODE, /* primary mode */ + COLO_SECONDARY_MODE, /* secondary mode */ +} mode_type; + +typedef struct ColoProxyState { + NetFilterState parent_obj; + NetQueue *incoming_queue; /* guest normal net queue */ + NetFilterDirection direction; /* packet direction */ + mode_type colo_mode; /* colo mode (primary or + * secondary) + */ + char *addr; /* primary colo connect addr + * or secondary server addr + */ + int sockfd; /* primary client socket fd or + * secondary server socket fd + */ + bool has_failover; /* colo failover flag */ + GHashTable *unprocessed_packets; /* hashtable to save connection */ + GQueue unprocessed_connections; /* to save unprocessed_connections */ + Coroutine *co; +} ColoProxyState; + +#endif /* QEMU_COLO_PROXY_H */