From patchwork Fri Feb 5 04:18:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Changlong Xie X-Patchwork-Id: 8231261 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id F15F49F1C1 for ; Fri, 5 Feb 2016 04:22:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3334E20397 for ; Fri, 5 Feb 2016 04:22:21 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 374A32027D for ; Fri, 5 Feb 2016 04:22:20 +0000 (UTC) Received: from localhost ([::1]:45888 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRXuV-0004ZR-Jk for patchwork-qemu-devel@patchwork.kernel.org; Thu, 04 Feb 2016 23:22:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40837) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRXpp-0004kN-Fg for qemu-devel@nongnu.org; Thu, 04 Feb 2016 23:17:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aRXpn-0006Yu-TG for qemu-devel@nongnu.org; Thu, 04 Feb 2016 23:17:29 -0500 Received: from [59.151.112.132] (port=59629 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRXpk-0006UM-22; Thu, 04 Feb 2016 23:17:25 -0500 X-IronPort-AV: E=Sophos;i="5.20,346,1444665600"; d="scan'208";a="3343059" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 05 Feb 2016 12:17:03 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id 30BE941B7210; Fri, 5 Feb 2016 12:16:00 +0800 (CST) Received: from changlox.g08.fujitsu.local (10.167.225.55) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Fri, 5 Feb 2016 12:16:57 +0800 From: Changlong Xie To: qemu devel , Fam Zheng , Max Reitz , Paolo Bonzini , Kevin Wolf , Stefan Hajnoczi Date: Fri, 5 Feb 2016 12:18:06 +0800 Message-ID: <1454645888-28826-8-git-send-email-xiecl.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1454645888-28826-1-git-send-email-xiecl.fnst@cn.fujitsu.com> References: <1454645888-28826-1-git-send-email-xiecl.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.225.55] X-yoursite-MailScanner-ID: 30BE941B7210.AEC47 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xiecl.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: qemu block , Jiang Yunhong , Dong Eddie , "Dr. David Alan Gilbert" , "Michael R. Hines" , Gonglei , zhanghailiang Subject: [Qemu-devel] [PATCH v15 7/9] Introduce new APIs to do replication operation 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Wen Congyang Signed-off-by: zhanghailiang Signed-off-by: Gonglei Signed-off-by: Changlong Xie --- Makefile.objs | 1 + qapi/block-core.json | 13 ++++++++ replication.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++ replication.h | 53 +++++++++++++++++++++++++++++ 4 files changed, 161 insertions(+) create mode 100644 replication.c create mode 100644 replication.h diff --git a/Makefile.objs b/Makefile.objs index 06b95c7..a8c74b7 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -15,6 +15,7 @@ block-obj-$(CONFIG_POSIX) += aio-posix.o block-obj-$(CONFIG_WIN32) += aio-win32.o block-obj-y += block/ block-obj-y += qemu-io-cmds.o +block-obj-y += replication.o block-obj-m = block/ diff --git a/qapi/block-core.json b/qapi/block-core.json index 7e9e8fe..12362b8 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2002,6 +2002,19 @@ '*read-pattern': 'QuorumReadPattern' } } ## +# @ReplicationMode +# +# An enumeration of replication modes. +# +# @primary: Primary mode, the vm's state will be sent to secondary QEMU. +# +# @secondary: Secondary mode, receive the vm's state from primary QEMU. +# +# Since: 2.6 +## +{ 'enum' : 'ReplicationMode', 'data' : [ 'primary', 'secondary' ] } + +## # @BlockdevOptions # # Options for creating a block device. diff --git a/replication.c b/replication.c new file mode 100644 index 0000000..e8ac2f0 --- /dev/null +++ b/replication.c @@ -0,0 +1,94 @@ +/* + * Replication filter + * + * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD. + * Copyright (c) 2016 Intel Corporation + * Copyright (c) 2016 FUJITSU LIMITED + * + * Author: + * Wen Congyang + * + * 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 "replication.h" + +static QLIST_HEAD(, ReplicationState) replication_states; + +ReplicationState *replication_new(void *opaque, ReplicationOps *ops) +{ + ReplicationState *rs; + + rs = g_new0(ReplicationState, 1); + rs->opaque = opaque; + rs->ops = ops; + QLIST_INSERT_HEAD(&replication_states, rs, node); + + return rs; +} + +void replication_remove(ReplicationState *rs) +{ + QLIST_REMOVE(rs, node); + g_free(rs); +} + +/* + * The caller of the function *MUST* make sure vm stopped + */ +void replication_start_all(ReplicationMode mode, Error **errp) +{ + ReplicationState *rs, *next; + + QLIST_FOREACH_SAFE(rs, &replication_states, node, next) { + if (rs->ops && rs->ops->start) { + rs->ops->start(rs, mode, errp); + } + if (*errp != NULL) { + return; + } + } +} + +void replication_do_checkpoint_all(Error **errp) +{ + ReplicationState *rs, *next; + + QLIST_FOREACH_SAFE(rs, &replication_states, node, next) { + if (rs->ops && rs->ops->checkpoint) { + rs->ops->checkpoint(rs, errp); + } + if (*errp != NULL) { + return; + } + } +} + +void replication_get_error_all(Error **errp) +{ + ReplicationState *rs, *next; + + QLIST_FOREACH_SAFE(rs, &replication_states, node, next) { + if (rs->ops && rs->ops->get_error) { + rs->ops->get_error(rs, errp); + } + if (*errp != NULL) { + return; + } + } +} + +void replication_stop_all(bool failover, Error **errp) +{ + ReplicationState *rs, *next; + + QLIST_FOREACH_SAFE(rs, &replication_states, node, next) { + if (rs->ops && rs->ops->stop) { + rs->ops->stop(rs, failover, errp); + } + if (*errp != NULL) { + return; + } + } +} diff --git a/replication.h b/replication.h new file mode 100644 index 0000000..faea649 --- /dev/null +++ b/replication.h @@ -0,0 +1,53 @@ +/* + * Replication filter + * + * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD. + * Copyright (c) 2016 Intel Corporation + * Copyright (c) 2016 FUJITSU LIMITED + * + * Author: + * Wen Congyang + * + * 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 REPLICATION_H +#define REPLICATION_H + +#include "sysemu/sysemu.h" + +typedef struct ReplicationOps ReplicationOps; +typedef struct ReplicationState ReplicationState; +typedef void (*Start)(ReplicationState *rs, ReplicationMode mode, Error **errp); +typedef void (*Stop)(ReplicationState *rs, bool failover, Error **errp); +typedef void (*Checkpoint)(ReplicationState *rs, Error **errp); +typedef void (*GetError)(ReplicationState *rs, Error **errp); + +struct ReplicationState { + void *opaque; + ReplicationOps *ops; + QLIST_ENTRY(ReplicationState) node; +}; + +struct ReplicationOps{ + Start start; + Checkpoint checkpoint; + GetError get_error; + Stop stop; +}; + + +ReplicationState *replication_new(void *opaque, ReplicationOps *ops); + +void replication_remove(ReplicationState *rs); + +void replication_start_all(ReplicationMode mode, Error **errp); + +void replication_do_checkpoint_all(Error **errp); + +void replication_get_error_all(Error **errp); + +void replication_stop_all(bool failover, Error **errp); + +#endif /* REPLICATION_H */