From patchwork Tue Jun 30 03:34:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Congyang X-Patchwork-Id: 489491 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 0ADD0140780 for ; Tue, 30 Jun 2015 13:40:26 +1000 (AEST) Received: from localhost ([::1]:44873 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z9mPI-0000je-0L for incoming@patchwork.ozlabs.org; Mon, 29 Jun 2015 23:40:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53085) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z9mGm-00022s-0V for qemu-devel@nongnu.org; Mon, 29 Jun 2015 23:31:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z9mGk-00006E-Tx for qemu-devel@nongnu.org; Mon, 29 Jun 2015 23:31:35 -0400 Received: from [59.151.112.132] (port=5460 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z9mGi-0008Fa-7W; Mon, 29 Jun 2015 23:31:34 -0400 X-IronPort-AV: E=Sophos;i="5.13,665,1427731200"; d="scan'208";a="97890047" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 30 Jun 2015 11:35:16 +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 t5U3TbQp028025; Tue, 30 Jun 2015 11:29:37 +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; Tue, 30 Jun 2015 11:31:16 +0800 From: Wen Congyang To: qemu devel , Fam Zheng , Max Reitz , Paolo Bonzini Date: Tue, 30 Jun 2015 11:34:42 +0800 Message-ID: <1435635285-5804-15-git-send-email-wency@cn.fujitsu.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1435635285-5804-1-git-send-email-wency@cn.fujitsu.com> References: <1435635285-5804-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: Kevin Wolf , qemu block , Lai Jiangshan , Jiang Yunhong , Dong Eddie , "Dr. David Alan Gilbert" , Luiz Capitulino , Gonglei , Stefan Hajnoczi , Yang Hongyang , Michael Roth , zhanghailiang Subject: [Qemu-devel] [PATCH COLO-BLOCK v7 14/17] Add new block driver interfaces to control 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 Cc: Luiz Capitulino Cc: Michael Roth Reviewed-by: Paolo Bonzini --- block.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/block/block.h | 5 +++++ include/block/block_int.h | 14 ++++++++++++++ qapi/block.json | 16 ++++++++++++++++ 4 files changed, 75 insertions(+) diff --git a/block.c b/block.c index 587990a..1cfbbf9 100644 --- a/block.c +++ b/block.c @@ -4341,3 +4341,43 @@ void bdrv_del_child(BlockDriverState *bs, BlockDriverState *child_bs, bs->drv->bdrv_del_child(bs, child_bs, errp); } + +void bdrv_start_replication(BlockDriverState *bs, ReplicationMode mode, + Error **errp) +{ + BlockDriver *drv = bs->drv; + + if (drv && drv->bdrv_start_replication) { + drv->bdrv_start_replication(bs, mode, errp); + } else if (bs->file) { + bdrv_start_replication(bs->file, mode, errp); + } else { + error_setg(errp, "this feature or command is not currently supported"); + } +} + +void bdrv_do_checkpoint(BlockDriverState *bs, Error **errp) +{ + BlockDriver *drv = bs->drv; + + if (drv && drv->bdrv_do_checkpoint) { + drv->bdrv_do_checkpoint(bs, errp); + } else if (bs->file) { + bdrv_do_checkpoint(bs->file, errp); + } else { + error_setg(errp, "this feature or command is not currently supported"); + } +} + +void bdrv_stop_replication(BlockDriverState *bs, bool failover, Error **errp) +{ + BlockDriver *drv = bs->drv; + + if (drv && drv->bdrv_stop_replication) { + drv->bdrv_stop_replication(bs, failover, errp); + } else if (bs->file) { + bdrv_stop_replication(bs->file, failover, errp); + } else { + error_setg(errp, "this feature or command is not currently supported"); + } +} diff --git a/include/block/block.h b/include/block/block.h index 65c9974..7657dee 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -611,4 +611,9 @@ void bdrv_add_child(BlockDriverState *bs, QDict *options, Error **errp); void bdrv_del_child(BlockDriverState *bs, BlockDriverState *child, Error **errp); +void bdrv_start_replication(BlockDriverState *bs, ReplicationMode mode, + Error **errp); +void bdrv_do_checkpoint(BlockDriverState *bs, Error **errp); +void bdrv_stop_replication(BlockDriverState *bs, bool failover, Error **errp); + #endif diff --git a/include/block/block_int.h b/include/block/block_int.h index d7af9e3..dac492a 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -293,6 +293,20 @@ struct BlockDriver { void (*bdrv_del_child)(BlockDriverState *bs, BlockDriverState *child, Error **errp); + void (*bdrv_start_replication)(BlockDriverState *bs, ReplicationMode mode, + Error **errp); + /* Drop Disk buffer when doing checkpoint. */ + void (*bdrv_do_checkpoint)(BlockDriverState *bs, Error **errp); + /* + * After failover, we should flush Disk buffer into secondary disk + * and stop block replication. + * + * If the guest is shutdown, we should drop Disk buffer and stop + * block representation. + */ + void (*bdrv_stop_replication)(BlockDriverState *bs, bool failover, + Error **errp); + QLIST_ENTRY(BlockDriver) list; }; diff --git a/qapi/block.json b/qapi/block.json index aad645c..04dc4c2 100644 --- a/qapi/block.json +++ b/qapi/block.json @@ -40,6 +40,22 @@ 'data': ['auto', 'none', 'lba', 'large', 'rechs']} ## +# @ReplicationMode +# +# An enumeration of replication modes. +# +# @unprotected: Replication is not started or after failover. +# +# @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.4 +## +{ 'enum' : 'ReplicationMode', + 'data' : ['unprotected', 'primary', 'secondary']} + +## # @BlockdevSnapshotInternal # # @device: the name of the device to generate the snapshot from