From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56120) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5VSU-00050H-M1 for qemu-devel@nongnu.org; Thu, 18 Jun 2015 04:46:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z5VSS-0004HA-5g for qemu-devel@nongnu.org; Thu, 18 Jun 2015 04:46:02 -0400 From: Wen Congyang Date: Thu, 18 Jun 2015 16:49:16 +0800 Message-ID: <1434617361-17778-12-git-send-email-wency@cn.fujitsu.com> In-Reply-To: <1434617361-17778-1-git-send-email-wency@cn.fujitsu.com> References: <1434617361-17778-1-git-send-email-wency@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH COLO-Block v6 11/16] Add new block driver interfaces to control block replication List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu devel , Fam Zheng , Max Reitz , Paolo Bonzini 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 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 59071d4..06222bf 100644 --- a/block.c +++ b/block.c @@ -4424,3 +4424,43 @@ void bdrv_disconnect(BlockDriverState *bs) bdrv_disconnect(bs->file); } } + +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 4b3a2b9..573d39f 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -610,4 +610,9 @@ BlockAcctStats *bdrv_get_stats(BlockDriverState *bs); void bdrv_connect(BlockDriverState *bs, Error **errp); void bdrv_disconnect(BlockDriverState *bs); +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 a3e5372..27ff3da 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -293,6 +293,20 @@ struct BlockDriver { void (*bdrv_connect)(BlockDriverState *bs, Error **errp); void (*bdrv_disconnect)(BlockDriverState *bs); + 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 -- 2.4.3