From patchwork Thu Feb 12 03:07:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Congyang X-Patchwork-Id: 439005 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 12F2D140129 for ; Thu, 12 Feb 2015 14:06:26 +1100 (AEDT) Received: from localhost ([::1]:47980 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLk6i-0003Mq-5i for incoming@patchwork.ozlabs.org; Wed, 11 Feb 2015 22:06:24 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60941) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLk5k-00024b-V0 for qemu-devel@nongnu.org; Wed, 11 Feb 2015 22:05:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YLk5e-00016p-F7 for qemu-devel@nongnu.org; Wed, 11 Feb 2015 22:05:24 -0500 Received: from [59.151.112.132] (port=8994 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLk5e-00016B-3T for qemu-devel@nongnu.org; Wed, 11 Feb 2015 22:05:18 -0500 X-IronPort-AV: E=Sophos;i="5.04,848,1406563200"; d="scan'208";a="57476525" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 12 Feb 2015 11:01:34 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t1C34Lf2030049; Thu, 12 Feb 2015 11:04:21 +0800 Received: from G08FNSTD140052.g08.fujitsu.local (10.167.226.52) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Thu, 12 Feb 2015 11:05:07 +0800 From: Wen Congyang To: qemu devel , Kevin Wolf , Stefan Hajnoczi , Paolo Bonzini Date: Thu, 12 Feb 2015 11:07:09 +0800 Message-ID: <1423710438-14377-6-git-send-email-wency@cn.fujitsu.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1423710438-14377-1-git-send-email-wency@cn.fujitsu.com> References: <1423710438-14377-1-git-send-email-wency@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.52] X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Cc: Lai Jiangshan , Jiang Yunhong , Dong Eddie , "Dr. David Alan Gilbert" , Gonglei , Yang Hongyang , zhanghailiang Subject: [Qemu-devel] [RFC PATCH 05/14] quorom: implement block driver interfaces for block replication 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 Signed-off-by: Wen Congyang Signed-off-by: zhanghailiang Signed-off-by: Gonglei --- block/quorum.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/block/quorum.c b/block/quorum.c index e6aff5f..c8479b4 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -1070,6 +1070,71 @@ static void quorum_refresh_filename(BlockDriverState *bs) bs->full_open_options = opts; } +static int quorum_stop_replication(BlockDriverState *bs); +static int quorum_start_replication(BlockDriverState *bs, int mode) +{ + BDRVQuorumState *s = bs->opaque; + int ret = -1, i; + + /* + * TODO: support COLO_SECONDARY_MODE if we allow secondary + * QEMU becoming primary QEMU. + */ + if (mode != COLO_PRIMARY_MODE) { + return -1; + } + + if (s->read_pattern != QUORUM_READ_PATTERN_FIRST) { + return -1; + } + + /* NBD client should not be the first child */ + if (bdrv_start_replication(s->bs[0], mode) == 0) { + bdrv_stop_replication(s->bs[0]); + return -1; + } + + for (i = 1; i < s->num_children; i++) { + if (bdrv_start_replication(s->bs[i], mode) == 0) { + ret++; + } + } + + if (ret > 0) { + quorum_stop_replication(bs); + } + + return ret ? -1 : 0; +} + +static int quorum_do_checkpoint(BlockDriverState *bs) +{ + BDRVQuorumState *s = bs->opaque; + int i; + + for (i = 1; i < s->num_children; i++) { + if (bdrv_do_checkpoint(s->bs[i]) == 0) { + return 0; + } + } + + return -1; +} + +static int quorum_stop_replication(BlockDriverState *bs) +{ + BDRVQuorumState *s = bs->opaque; + int ret = -1, i; + + for (i = 0; i < s->num_children; i++) { + if (bdrv_stop_replication(s->bs[i]) == 0) { + ret++; + } + } + + return ret ? -1 : 0; +} + static BlockDriver bdrv_quorum = { .format_name = "quorum", .protocol_name = "quorum", @@ -1093,6 +1158,10 @@ static BlockDriver bdrv_quorum = { .is_filter = true, .bdrv_recurse_is_first_non_filter = quorum_recurse_is_first_non_filter, + + .bdrv_start_replication = quorum_start_replication, + .bdrv_do_checkpoint = quorum_do_checkpoint, + .bdrv_stop_replication = quorum_stop_replication, }; static void bdrv_quorum_init(void)