Signed-off-by: Wen Congyang <we...@cn.fujitsu.com> Signed-off-by: zhanghailiang <zhang.zhanghaili...@huawei.com> Signed-off-by: Gonglei <arei.gong...@huawei.com> Cc: Luiz Capitulino <lcapitul...@redhat.com> Cc: Michael Roth <mdr...@linux.vnet.ibm.com> Reviewed-by: Paolo Bonzini <pbonz...@redhat.com> --- 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 050f919..54d5b29 100644 --- a/block.c +++ b/block.c @@ -4213,3 +4213,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 ed5b8e5..c98adfb 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -596,4 +596,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 da29fa7..761e6ff 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 e313465..56e469d 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.1.0