From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37473) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZtZKI-0004dG-Qn for qemu-devel@nongnu.org; Tue, 03 Nov 2015 06:00:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZtZKE-0002mB-I1 for qemu-devel@nongnu.org; Tue, 03 Nov 2015 06:00:30 -0500 From: Wen Congyang Date: Tue, 3 Nov 2015 18:58:49 +0800 Message-ID: <1446548329-17475-13-git-send-email-wency@cn.fujitsu.com> In-Reply-To: <1446548329-17475-1-git-send-email-wency@cn.fujitsu.com> References: <1446548329-17475-1-git-send-email-wency@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH v11 12/12] Add a new API to start/stop replication, do checkpoint to all BDSes List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu devel , Fam Zheng , Max Reitz , Paolo Bonzini , Stefan Hajnoczi Cc: Kevin Wolf , qemu block , Jiang Yunhong , Dong Eddie , "Dr. David Alan Gilbert" , "Michael R. Hines" , Gonglei , zhanghailiang 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 04b928c..517fa4b 100644 --- a/block.c +++ b/block.c @@ -4208,3 +4208,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 288e14e..8427969 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -643,4 +643,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 -- 2.4.3