From patchwork Wed Dec 2 05:38:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Congyang X-Patchwork-Id: 551181 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 1400A1401DA for ; Wed, 2 Dec 2015 16:39:57 +1100 (AEDT) Received: from localhost ([::1]:56342 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a408x-0003NI-7Z for incoming@patchwork.ozlabs.org; Wed, 02 Dec 2015 00:39:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58265) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a408U-0002Q5-Uz for qemu-devel@nongnu.org; Wed, 02 Dec 2015 00:39:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a408U-0004UT-1J for qemu-devel@nongnu.org; Wed, 02 Dec 2015 00:39:26 -0500 Received: from [59.151.112.132] (port=49167 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a408P-0004T0-3w; Wed, 02 Dec 2015 00:39:21 -0500 X-IronPort-AV: E=Sophos;i="5.20,346,1444665600"; d="scan'208";a="1072306" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 02 Dec 2015 13:39:08 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id C5CBC409256D; Wed, 2 Dec 2015 13:39:03 +0800 (CST) Received: from [10.167.226.52] (10.167.226.52) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server id 14.3.181.6; Wed, 2 Dec 2015 13:39:03 +0800 To: qemu devel , Fam Zheng , Max Reitz , Paolo Bonzini , Kevin Wolf , Stefan Hajnoczi References: <1449034311-4094-1-git-send-email-wency@cn.fujitsu.com> From: Wen Congyang Message-ID: <565E83D6.9000204@cn.fujitsu.com> Date: Wed, 2 Dec 2015 13:38:30 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <1449034311-4094-1-git-send-email-wency@cn.fujitsu.com> X-Originating-IP: [10.167.226.52] X-yoursite-MailScanner-Information: Please contact the ISP for more information X-yoursite-MailScanner-ID: C5CBC409256D.A9EDA X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: wency@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: zhanghailiang , qemu block , Jiang Yunhong , Dong Eddie , "Dr. David Alan Gilbert" , "Michael R. Hines" , Gonglei Subject: [Qemu-devel] [Patch v12 resend 10/10] Add a new API to start/stop replication, do checkpoint to all BDSes 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.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/block/block.h | 4 +++ 2 files changed, 87 insertions(+) diff --git a/block.c b/block.c index 213bee8..09ee7f1 100644 --- a/block.c +++ b/block.c @@ -4433,3 +4433,86 @@ void bdrv_stop_replication(BlockDriverState *bs, bool failover, Error **errp) " replication", bs->filename); } } + +void bdrv_start_replication_all(ReplicationMode mode, Error **errp) +{ + BlockDriverState *bs = NULL, *temp = NULL; + Error *local_err = NULL; + + while ((bs = bdrv_next(bs))) { + if (!QLIST_EMPTY(&bs->parents)) { + /* It is not top BDS */ + continue; + } + + if (bdrv_is_read_only(bs) || !bdrv_is_inserted(bs)) { + continue; + } + + bdrv_start_replication(bs, mode, &local_err); + if (local_err) { + error_propagate(errp, local_err); + goto fail; + } + } + + return; + +fail: + while ((temp = bdrv_next(temp)) && bs != temp) { + bdrv_stop_replication(temp, false, NULL); + } +} + +void bdrv_do_checkpoint_all(Error **errp) +{ + BlockDriverState *bs = NULL; + Error *local_err = NULL; + + while ((bs = bdrv_next(bs))) { + if (!QLIST_EMPTY(&bs->parents)) { + /* It is not top BDS */ + continue; + } + + if (bdrv_is_read_only(bs) || !bdrv_is_inserted(bs)) { + continue; + } + + bdrv_do_checkpoint(bs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + } +} + +void bdrv_stop_replication_all(bool failover, Error **errp) +{ + BlockDriverState *bs = NULL; + Error *local_err = NULL; + + while ((bs = bdrv_next(bs))) { + if (!QLIST_EMPTY(&bs->parents)) { + /* It is not top BDS */ + continue; + } + + if (bdrv_is_read_only(bs) || !bdrv_is_inserted(bs)) { + continue; + } + + bdrv_stop_replication(bs, failover, &local_err); + if (!errp) { + /* + * The caller doesn't care the result, they just + * want to stop all block's replication. + */ + continue; + } + if (local_err) { + error_propagate(errp, local_err); + return; + } + } +} diff --git a/include/block/block.h b/include/block/block.h index cd39d50..39d246c 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -653,4 +653,8 @@ void bdrv_start_replication(BlockDriverState *bs, ReplicationMode mode, void bdrv_do_checkpoint(BlockDriverState *bs, Error **errp); void bdrv_stop_replication(BlockDriverState *bs, bool failover, Error **errp); +void bdrv_start_replication_all(ReplicationMode mode, Error **errp); +void bdrv_do_checkpoint_all(Error **errp); +void bdrv_stop_replication_all(bool failover, Error **errp); + #endif