Block replication for continuous checkpoints
v8 cover Block replication for continuous checkpoints
Block replication is a very important feature which is used for continuous checkpoints(for example: COLO).
You can the detailed information about block replication from here:
http://wiki.qemu.org/Features/BlockReplication
Usage:
Please refer to docs/block-replication.txt
You can get the patch here:
https://github.com/coloft/qemu/tree/wency/block-replication-v8
You can get the patch with framework here:
https://github.com/coloft/qemu/tree/wency/colo_framework_v8
TODO:
1. Continuous block replication. It will be started after basic functions are accepted.
Wen Congyang (18):
Add new block driver interface to add/delete a BDS's child
quorum: implement block driver interfaces add/delete a BDS's child
hmp: add monitor command to add/remove a child
introduce a new API qemu_opts_absorb_qdict_by_index()
quorum: allow ignoring child errors
introduce a new API to enable/disable attach device model introduce a new API to check if blk is attached
block: make bdrv_put_ref_bh_schedule() as a public API
Backup: clear all bitmap when doing block checkpoint allow writing to the backing file
Allow creating backup jobs when opening BDS
block: Allow references for backing files
docs: block replication's description
Add new block driver interfaces to control block replication skip nbd_target when starting block replication
quorum: implement block driver interfaces for block replication Implement new driver for block replication
Add a new API to start/stop replication, do checkpoint to all BDSes
block.c | 266 ++++++++++++++++++++++++- block/Makefile.objs | 3 +- block/backup.c | 13 ++ block/block-backend.c | 33 +++ block/quorum.c | 244 ++++++++++++++++++++++- block/replication.c | 443 +++++++++++++++++++++++++++++++++++++++++ blockdev.c | 90 ++++++--- blockjob.c | 10 + docs/block-replication.txt | 182 +++++++++++++++++ hmp-commands.hx | 28 +++ include/block/block.h | 15 ++ include/block/block_int.h | 19 ++ include/block/blockjob.h | 12 ++ include/qemu/option.h | 2 + include/sysemu/block-backend.h | 3 + include/sysemu/blockdev.h | 2 + qapi/block.json | 16 ++ util/qemu-option.c | 44 ++++ 18 files changed, 1378 insertions(+), 47 deletions(-) create mode 100644 block/replication.c create mode 100644 docs/block-replication.txt
Signature · 1 line
2.4.3
PATCH v8 1/18 Add new block driver interface to add/delete a BDS's child
In some cases, we want to take a quorum child offline, and take another child online.
--- block.c | 39 +++++++++++++++++++++++++++++++++++++++ include/block/block.h | 4 ++++ include/block/block_int.h | 5 +++++ 3 files changed, 48 insertions(+)
block.c +39 -0
@@ -4195,3 +4195,42 @@ BlockAcctStats *bdrv_get_stats(BlockDriverState *bs) {return &bs->stats; } + +/* +* Hot add/remove a BDS's child. So the user can take a child offline when +* it is broken and take a new child online +*/ +void bdrv_add_child (BlockDriverState *bs,QDict *options,Error **errp) +{ + +if (!bs->drv || !bs->drv->bdrv_add_child) { +error_setg (errp,"this feature or command is not currently supported" ); +return ; + } + + bs->drv->bdrv_add_child (bs, options, errp); +} + +void bdrv_del_child (BlockDriverState *bs,BlockDriverState *child_bs, +Error **errp) +{ +BdrvChild *child; + +if (!bs->drv || !bs->drv->bdrv_del_child) { +error_setg (errp,"this feature or command is not currently supported" ); +return ; + } + + QLIST_FOREACH(child, &bs->children, next) { +if (child->bs == child_bs) { +break ; + } + } + +if (!child) { +error_setg (errp,"Invalid child" ); +return ; + } + + bs->drv->bdrv_del_child (bs, child_bs, errp); +}
include/block/block.h +4 -0
@@ -609,4 +609,8 @@ void bdrv_flush_io_queue(BlockDriverState *bs);BlockAcctStats *bdrv_get_stats (BlockDriverState *bs); +void bdrv_add_child (BlockDriverState *bs,QDict *options,Error **errp); +void bdrv_del_child (BlockDriverState *bs,BlockDriverState *child, +Error **errp); +#endif
include/block/block_int.h +5 -0
@@ -288,6 +288,11 @@ struct BlockDriver {*/ int (*bdrv_probe_geometry)(BlockDriverState *bs,HDGeometry *geo); +void (*bdrv_add_child)(BlockDriverState *bs,QDict *options, +Error **errp); +void (*bdrv_del_child)(BlockDriverState *bs,BlockDriverState *child, +Error **errp); +QLIST_ENTRY (BlockDriver) list; };
Signature · 1 line
2.4.3
PATCH v8 2/18 quorum: implement block driver interfaces add/delete a BDS's child
In reply to Wen Congyang--- block/quorum.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 2 deletions(-)
block/quorum.c +71 -2
@@ -67,6 +67,9 @@ typedef struct QuorumVotes { typedef struct BDRVQuorumState { BlockDriverState **bs; /* children BlockDriverStates */ int num_children; /* children count */ + int max_children; /* The maximum children count, we need to reallocate + * bs if num_children will larger than maximum. + */ int threshold; /* if less than threshold children reads gave the * same result a quorum error occurs. */
@@ -879,9 +882,9 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags, ret = -EINVAL ; goto exit; } -if (s->num_children <2 ) { +if (s->num_children <1 ) {error_setg (&local_err, -"Number of provided children must be greater than 1" ); +"Number of provided children must be 1 or more" ); ret = -EINVAL ; goto exit; }
@@ -930,6 +933,7 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags,/* allocate the children BlockDriverState array */ s->bs = g_new0(BlockDriverState *, s->num_children); opened =g_new0 (bool, s->num_children); + s->max_children = s->num_children;for (i =0 ; i < s->num_children; i++) {char indexstr[32 ];
@@ -1000,6 +1004,68 @@ static void quorum_attach_aio_context(BlockDriverState *bs, } } +static void quorum_add_child (BlockDriverState *bs,QDict *options,Error **errp) +{ +BDRVQuorumState *s = bs->opaque; +int ret; +Error *local_err =NULL ; + +bdrv_drain (bs); + +if (s->num_children == s->max_children) { +if (s->max_children >=INT_MAX ) { +error_setg (errp,"Too many children" ); +return ; + } + + s->bs = g_renew(BlockDriverState *, s->bs, s->max_children + 1); + s->bs[s->num_children] =NULL ; + s->max_children +=1 ; + } + + ret =bdrv_open_image (&s->bs[s->num_children],NULL , options,"child" , bs, + &child_format, false, &local_err); +if (ret <0 ) { +error_propagate (errp, local_err); +return ; + } + s->num_children++; +} + +static void quorum_del_child (BlockDriverState *bs,BlockDriverState *child_bs, +Error **errp) +{ +BDRVQuorumState *s = bs->opaque; +int i; + +for (i =0 ; i < s->num_children; i++) { +if (s->bs[i] == child_bs) { +break ; + } + } + +if (i == s->num_children) { +error_setg (errp,"Invalid child" ); +return ; + } + +if (s->num_children <= s->threshold) { +error_setg (errp,"Cannot remove any more child" ); +return ; + } + +if (s->num_children ==1 ) { +error_setg (errp,"Cannot remove the last child" ); +return ; + } + +bdrv_drain (bs); +/* We can safe remove this child now */ +memmove (&s->bs[i], &s->bs[i+1 ], (s->num_children - i -1 ) *sizeof (void *)); + s->num_children--; + s->bs[s->num_children] =NULL ; +} +static void quorum_refresh_filename (BlockDriverState *bs) {BDRVQuorumState *s = bs->opaque;
@@ -1054,6 +1120,9 @@ static BlockDriver bdrv_quorum = { .bdrv_detach_aio_context = quorum_detach_aio_context, .bdrv_attach_aio_context = quorum_attach_aio_context, + .bdrv_add_child = quorum_add_child, + .bdrv_del_child = quorum_del_child, + .is_filter = true, .bdrv_recurse_is_first_non_filter = quorum_recurse_is_first_non_filter, };
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH COLO-BLOCK v8 02/18] quorum: implement block driver interfaces add/delete a BDS's child
Quoted 4 lines · Wen Congyang
Signed-off-by Wen Congyang <[email protected]>Signed-off-by zhanghailiang <[email protected]>Signed-off-by Gonglei <[email protected]>Cc Alberto Garcia <[email protected]>
Sorry for being so late with this, I was on holidays during July.
Quoted 11 lines
block/quorum.c +11
-0+static void quorum_del_child (BlockDriverState *bs,BlockDriverState *child_bs, +Error **errp) +{ +BDRVQuorumState *s = bs->opaque; +int i; + +for (i =0 ; i < s->num_children; i++) { +if (s->bs[i] == child_bs) { +break ; + } + }
block/quorum.c static void quorum_attach_aio_context(BlockDriverState *bs, · line 1055
Quoted 10 lines
block/quorum.c +10
-0+ +if (i == s->num_children) { +error_setg (errp,"Invalid child" ); +return ; + } + +if (s->num_children <= s->threshold) { +error_setg (errp,"Cannot remove any more child" ); +return ; + }
I think that should be "Cannot remove any more children".
You could also make it a bit more explanatory by saying "The number of children cannot be lower than the vote threshold" or something like that.
block/quorum.c static void quorum_attach_aio_context(BlockDriverState *bs, · line 1064
Quoted 3 lines
block/quorum.c +3
-0+bdrv_drain (bs); +/* We can safe remove this child now */ +memmove (&s->bs[i], &s->bs[i+1 ], (s->num_children - i -1 ) *sizeof (void *));
s/safe/safely/
Apart from that, the code looks good to me, so
Berto
Re: [Qemu-devel] [PATCH COLO-BLOCK v8 02/18] quorum: implement block driver interfaces add/delete a BDS's child
Quoted 40 lines · Alberto Garcia
Quoted 4 lines · Wen Congyang
Signed-off-by Wen Congyang <[email protected]>Signed-off-by zhanghailiang <[email protected]>Signed-off-by Gonglei <[email protected]>Cc Alberto Garcia <[email protected]>Sorry for being so late with this, I was on holidays during July.
Quoted 11 lines
block/quorum.c +11
-0+static void quorum_del_child (BlockDriverState *bs,BlockDriverState *child_bs, +Error **errp) +{ +BDRVQuorumState *s = bs->opaque; +int i; + +for (i =0 ; i < s->num_children; i++) { +if (s->bs[i] == child_bs) { +break ; + } + }block/quorum.c static void quorum_attach_aio_context(BlockDriverState *bs, · line 1055
Quoted 10 lines
block/quorum.c +10
-0+ +if (i == s->num_children) { +error_setg (errp,"Invalid child" ); +return ; + } + +if (s->num_children <= s->threshold) { +error_setg (errp,"Cannot remove any more child" ); +return ; + }I think that should be "Cannot remove any more children".
You could also make it a bit more explanatory by saying "The number of children cannot be lower than the vote threshold" or something like that.
block/quorum.c static void quorum_attach_aio_context(BlockDriverState *bs, · line 1064
Quoted 3 lines
block/quorum.c +3
-0+bdrv_drain (bs); +/* We can safe remove this child now */ +memmove (&s->bs[i], &s->bs[i+1 ], (s->num_children - i -1 ) *sizeof (void *));
Quoted 5 lines
s/safe/safely/
Apart from that, the code looks good to me, so
Reviewed-by Alberto Garcia <[email protected]>
Thanks, I have send add/delete a quorum child separately. This patch is changed one line:
unref child_bs when it is removed.
I will update that patch and add your reviewed-by in that patchset.
Thanks
Wen Congyang
Quoted 4 lines
Berto
.
PATCH v8 3/18 hmp: add monitor command to add/remove a child
In reply to Wen Congyang--- blockdev.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++ hmp-commands.hx | 28 +++++++++++++++++++++++++ include/sysemu/blockdev.h | 2 ++ 3 files changed, 83 insertions(+)
blockdev.c +53 -0
@@ -2186,6 +2186,59 @@ void hmp_drive_del(Monitor *mon, const QDict *qdict)aio_context_release (aio_context); } +void hmp_child_add (Monitor *mon,const QDict *qdict) +{ +const char *id =qdict_get_str (qdict,"id" ); +const char *optstr =qdict_get_str (qdict,"opts" ); +QemuOpts *opts; +QDict *bs_opts =qdict_new (); +BlockDriverState *bs; +Error *local_err =NULL ; + + opts =drive_def (optstr); +if (!opts) { +/* We have reported error in drive_def */ +return ; + } + bs_opts =qemu_opts_to_qdict (opts, bs_opts); + + bs =bdrv_lookup_bs (id, id, &local_err); +if (!bs) { +error_report_err (local_err); +return ; + } + +bdrv_add_child (bs, bs_opts, &local_err); +if (local_err) { +error_report_err (local_err); + } +} + +void hmp_child_del (Monitor *mon,const QDict *qdict) +{ +const char *id =qdict_get_str (qdict,"id" ); +const char *child_id =qdict_get_str (qdict,"child" ); +BlockDriverState *bs, *child_bs; +Error *local_err =NULL ; + + bs =bdrv_lookup_bs (id, id, &local_err); +if (!bs) { +error_report_err (local_err); +return ; + } + + child_bs =bdrv_lookup_bs (child_id, child_id, &local_err); +if (!child_bs) { +error_report_err (local_err); +return ; + } + +bdrv_del_child (bs, child_bs, &local_err); +if (local_err) { +error_report_err (local_err); + } +} +void qmp_block_resize (bool has_device,const char *device,bool has_node_name,const char *node_name,int64_t size,Error **errp)
hmp-commands.hx +28 -0
@@ -193,6 +193,34 @@ actions (drive options rerror, werror). ETEXI { + .name = "child_add", + .args_type = "id:B,opts:s", + .params = "device child.file=file", + .help = "add a child to a BDS", + .mhandler.cmd = hmp_child_add, + }, + +STEXI +@item child_add @var{device} @var{options} +@findex child_add +Add a child to the block device. +ETEXI + + { + .name = "child_del", + .args_type = "id:B,child:B", + .params = "parent child", + .help = "remove a child from a BDS", + .mhandler.cmd = hmp_child_del, + }, + +STEXI +@item child_del @var{parent device} @var{child device} +@findex child_del +Remove a child from the parent device. +ETEXI + + { .name = "change", .args_type = "device:B,target:F,arg:s?", .params = "device filename [format]",
include/sysemu/blockdev.h +2 -0
@@ -67,4 +67,6 @@ void qmp_change_blockdev(const char *device, const char *filename, const char *format, Error **errp);void hmp_commit (Monitor *mon,const QDict *qdict);void hmp_drive_del (Monitor *mon,const QDict *qdict); +void hmp_child_add (Monitor *mon,const QDict *qdict); +void hmp_child_del (Monitor *mon,const QDict *qdict);#endif
Signature · 1 line
2.4.3
PATCH v8 4/18 introduce a new API qemu_opts_absorb_qdict_by_index()
In reply to Wen Congyang--- include/qemu/option.h | 2 ++ util/qemu-option.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+)
include/qemu/option.h +2 -0
@@ -129,6 +129,8 @@ QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict, Error **errp);QDict *qemu_opts_to_qdict (QemuOpts *opts,QDict *qdict);void qemu_opts_absorb_qdict (QemuOpts *opts,QDict *qdict,Error **errp); +void qemu_opts_absorb_qdict_by_index (QemuOpts *opts,QDict *qdict, +const char *index,Error **errp);typedef int (*qemu_opts_loopfunc )(void *opaque,QemuOpts *opts,Error **errp); int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func,
util/qemu-option.c +44 -0
50 lines not on this page · raw message
Signature · 1 line
2.4.3
PATCH v8 5/18 quorum: allow ignoring child errors
In reply to Wen CongyangIf the child is not ready, read/write/getlength/flush will return -errno. It is not critical error, and can be ignored:
1. read/write:
Just not report the error event.
2. getlength:
just ignore it. If all children's getlength return -errno, and be ignored, return -EIO.
3. flush:
Just ignore it. If all children's getlength return -errno, and be ignored, return 0.
Usage: children.x.ignore-errors=true
--- block/quorum.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 87 insertions(+), 7 deletions(-)
block/quorum.c +87 -7
@@ -31,6 +31,7 @@#define QUORUM_OPT_BLKVERIFY "blkverify"#define QUORUM_OPT_REWRITE "rewrite-corrupted"#define QUORUM_OPT_READ_PATTERN "read-pattern" +#define QUORUM_CHILDREN_OPT_IGNORE_ERRORS "ignore-errors"/* This union holds a vote hash value */ typedef union QuorumVoteValue {
@@ -66,6 +67,7 @@ typedef struct QuorumVotes {/* the following structure holds the state of one quorum instance */ typedef struct BDRVQuorumState { BlockDriverState **bs; /* children BlockDriverStates */ + bool *ignore_errors; /* ignore children's error? */ int num_children; /* children count */ int max_children; /* The maximum children count, we need to reallocate * bs if num_children will larger than maximum.
@@ -101,6 +103,7 @@ typedef struct QuorumChildRequest {uint8_t *buf;int ret;QuorumAIOCB *parent; +int index; } QuorumChildRequest;/* Quorum will use the following structure to track progress of each read/write
@@ -213,6 +216,7 @@ static QuorumAIOCB *quorum_aio_get(BDRVQuorumState *s, acb->qcrs[i].buf =NULL ; acb->qcrs[i].ret =0 ; acb->qcrs[i].parent = acb; + acb->qcrs[i].index = i; }return acb;
@@ -306,7 +310,7 @@ static void quorum_aio_cb(void *opaque, int ret) acb->count++;if (ret ==0 ) { acb->success_count++; - }else { + }else if (!s->ignore_errors[sacb->index]) {quorum_report_bad (acb, sacb->aiocb->bs->node_name, ret); }assert (acb->count <= s->num_children);
@@ -721,19 +725,31 @@ static BlockAIOCB *quorum_aio_writev(BlockDriverState *bs,static int64_t quorum_getlength (BlockDriverState *bs) {BDRVQuorumState *s = bs->opaque; -int64_t result; +int64_t result = -EIO ;int i;/* check that all file have the same length */ - result =bdrv_getlength (s->bs[0 ]); -if (result <0 ) { -return result; - } -for (i =1 ; i < s->num_children; i++) { +for (i =0 ; i < s->num_children; i++) {int64_t value =bdrv_getlength (s->bs[i]); +if (value <0 ) {return value; } + +if (value ==0 && s->ignore_errors[i]) { +/* +* If the child is not ready, it cannot return -errno, +* otherwise refresh_total_sectors() will fail when +* we open the child. +*/ +continue ; + } + +if (result == -EIO ) { + result = value; +continue ; + } +if (value != result) {return -EIO ; }
@@ -771,6 +787,9 @@ static coroutine_fn int quorum_co_flush(BlockDriverState *bs)for (i =0 ; i < s->num_children; i++) { result =bdrv_co_flush (s->bs[i]); +if (result <0 && s->ignore_errors[i]) { + result =0 ; + } result_value.l = result;quorum_count_vote (&error_votes, &result_value, i); }
@@ -845,6 +864,19 @@ static QemuOptsList quorum_runtime_opts = { }, }; +static QemuOptsList quorum_children_common_opts = { + .name ="quorum children" , + .head =QTAILQ_HEAD_INITIALIZER (quorum_children_common_opts.head), + .desc = { + { + .name =QUORUM_CHILDREN_OPT_IGNORE_ERRORS , + .type =QEMU_OPT_BOOL , + .help ="ignore child I/O error" , + }, + {/* end of list */ } + }, +}; +static int parse_read_pattern (const char *opt) {int i;
@@ -863,6 +895,37 @@ static int parse_read_pattern(const char *opt)return -EINVAL ; } +static int parse_children_options (BDRVQuorumState *s,QDict *options, +const char *indexstr,int index, +Error **errp) +{ +QemuOpts *children_opts =NULL ; +Error *local_err =NULL ; +int ret =0 ; +bool value; + + children_opts =qemu_opts_create (&quorum_children_common_opts,NULL ,0 , + &error_abort); +qemu_opts_absorb_qdict_by_index (children_opts, options, indexstr, + &local_err); +if (local_err) { + ret = -EINVAL ; + goto out; + } + + value =qemu_opt_get_bool (children_opts,QUORUM_CHILDREN_OPT_IGNORE_ERRORS , + false); + s->ignore_errors[index] = value; + +out: +qemu_opts_del (children_opts); +/* propagate error */ +if (local_err) { +error_propagate (errp, local_err); + } +return ret; +} +static int quorum_open (BlockDriverState *bs,QDict *options,int flags,Error **errp) {
@@ -934,12 +997,18 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags, s->bs = g_new0(BlockDriverState *, s->num_children); opened =g_new0 (bool, s->num_children); s->max_children = s->num_children; + s->ignore_errors =g_new0 (bool, s->num_children);for (i =0 ; i < s->num_children; i++) {char indexstr[32 ]; ret =snprintf (indexstr,32 ,"children.%d" , i);assert (ret <32 ); + ret =parse_children_options (s, options, indexstr, i, &local_err); +if (ret <0 ) { + goto close_exit; + } + ret =bdrv_open_image (&s->bs[i],NULL , options, indexstr, bs, &child_format, false, &local_err);if (ret <0 ) {
@@ -981,6 +1050,7 @@ static void quorum_close(BlockDriverState *bs) }g_free (s->bs); +g_free (s->ignore_errors); }static void quorum_detach_aio_context (BlockDriverState *bs)
@@ -1019,10 +1089,18 @@ static void quorum_add_child(BlockDriverState *bs, QDict *options, Error **errp) } s->bs = g_renew(BlockDriverState *, s->bs, s->max_children + 1); + s->ignore_errors =g_renew (bool, s->ignore_errors, s->max_children +1 ); s->bs[s->num_children] =NULL ; s->max_children +=1 ; } + ret =parse_children_options (s, options,"child" , s->num_children, + &local_err); +if (ret <0 ) { +error_propagate (errp, local_err); +return ; + } + ret =bdrv_open_image (&s->bs[s->num_children],NULL , options,"child" , bs, &child_format, false, &local_err);if (ret <0 ) {
@@ -1062,6 +1140,8 @@ static void quorum_del_child(BlockDriverState *bs, BlockDriverState *child_bs,bdrv_drain (bs);/* We can safe remove this child now */ memmove (&s->bs[i], &s->bs[i+1 ], (s->num_children - i -1 ) *sizeof (void *)); +memmove (&s->ignore_errors[i], &s->ignore_errors[i+1 ], + (s->num_children - i -1 ) *sizeof (bool )); s->num_children--; s->bs[s->num_children] =NULL ; }
Signature · 1 line
2.4.3
PATCH v8 6/18 introduce a new API to enable/disable attach device model
In reply to Wen Congyang--- block/block-backend.c | 24 ++++++++++++++++++++++++ include/sysemu/block-backend.h | 2 ++ 2 files changed, 26 insertions(+)
block/block-backend.c +24 -0
@@ -344,6 +344,30 @@ void *blk_get_attached_dev(BlockBackend *blk) }/* +* Disable to attach a device mode to @blk. +* Return 0 on success, -EBUSY when a device model is attached already. +*/ +int blk_disable_attach_dev (BlockBackend *blk) +{ +if (blk->dev) { +return blk->dev == (void *)-1 ?0 : -EBUSY ; + } + + blk->dev = (void *)-1 ; +return 0 ; +} + +/* +* Enable to attach a device mode to @blk. +*/ +void blk_enable_attach_dev (BlockBackend *blk) +{ +if (blk->dev == (void *)-1 ) { + blk->dev =NULL ; + } +} + +/* * Set @blk's device model callbacks to @ops. * @opaque is the opaque argument to pass to the callbacks. * This is for use by device models.
include/sysemu/block-backend.h +2 -0
@@ -80,6 +80,8 @@ int blk_attach_dev(BlockBackend *blk, void *dev);void blk_attach_dev_nofail (BlockBackend *blk,void *dev);void blk_detach_dev (BlockBackend *blk,void *dev);void *blk_get_attached_dev (BlockBackend *blk); +int blk_disable_attach_dev (BlockBackend *blk); +void blk_enable_attach_dev (BlockBackend *blk);void blk_set_dev_ops (BlockBackend *blk,const BlockDevOps *ops,void *opaque);int blk_read (BlockBackend *blk,int64_t sector_num,uint8_t *buf,int nb_sectors);
Signature · 1 line
2.4.3
PATCH v8 7/18 introduce a new API to check if blk is attached
In reply to Wen Congyang--- block.c | 4 ++-- block/block-backend.c | 9 +++++++++ include/sysemu/block-backend.h | 1 + 3 files changed, 12 insertions(+), 2 deletions(-)
block.c +2 -2
@@ -2032,7 +2032,7 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old) }/* bs_new must be unattached and shouldn't have anything fancy enabled */ -assert (!bs_new->blk); +assert (!blk_is_attached (bs_new->blk));assert (QLIST_EMPTY (&bs_new->dirty_bitmaps));assert (bs_new->job ==NULL );assert (bs_new->io_limits_enabled == false);
@@ -2049,7 +2049,7 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old)bdrv_move_feature_fields (bs_new, &tmp);/* bs_new must remain unattached */ -assert (!bs_new->blk); +assert (!blk_is_attached (bs_new->blk));/* Check a few fields that should remain attached to the device */ assert (bs_new->job ==NULL );
block/block-backend.c +9 -0
@@ -368,6 +368,15 @@ void blk_enable_attach_dev(BlockBackend *blk) }/* +* Return true if a device model is attached to @blk already, +* otherwise, return false. +*/ +bool blk_is_attached (BlockBackend *blk) +{ +return blk !=NULL && blk->dev !=NULL && blk->dev != (void *)-1 ; +} + +/* * Set @blk's device model callbacks to @ops. * @opaque is the opaque argument to pass to the callbacks. * This is for use by device models.
include/sysemu/block-backend.h +1 -0
@@ -82,6 +82,7 @@ void blk_detach_dev(BlockBackend *blk, void *dev);void *blk_get_attached_dev (BlockBackend *blk);int blk_disable_attach_dev (BlockBackend *blk);void blk_enable_attach_dev (BlockBackend *blk); +bool blk_is_attached (BlockBackend *blk);void blk_set_dev_ops (BlockBackend *blk,const BlockDevOps *ops,void *opaque);int blk_read (BlockBackend *blk,int64_t sector_num,uint8_t *buf,int nb_sectors);
Signature · 1 line
2.4.3
PATCH v8 8/18 block: make bdrv_put_ref_bh_schedule() as a public API
In reply to Wen Congyang--- block.c | 25 +++++++++++++++++++++++++ blockdev.c | 37 ++++++------------------------------- include/block/block.h | 1 + 3 files changed, 32 insertions(+), 31 deletions(-)
block.c +25 -0
@@ -3562,6 +3562,31 @@ void bdrv_unref(BlockDriverState *bs) } } +typedef struct { +QEMUBH *bh; +BlockDriverState *bs; +}BDRVPutRefBH ; + +static void bdrv_put_ref_bh (void *opaque) +{ +BDRVPutRefBH *s = opaque; + +bdrv_unref (s->bs); +qemu_bh_delete (s->bh); +g_free (s); +} + +/* Release a BDS reference in a BH */ +void bdrv_put_ref_bh_schedule (BlockDriverState *bs) +{ +BDRVPutRefBH *s; + + s =g_new (BDRVPutRefBH,1 ); + s->bh =qemu_bh_new (bdrv_put_ref_bh, s); + s->bs = bs; +qemu_bh_schedule (s->bh); +} +struct BdrvOpBlocker {Error *reason;QLIST_ENTRY (BdrvOpBlocker) list;
blockdev.c +6 -31
@@ -276,37 +276,6 @@ static void bdrv_format_print(void *opaque, const char *name)error_printf (" %s" , name); } -typedef struct { -QEMUBH *bh; -BlockDriverState *bs; -}BDRVPutRefBH ; - -static void bdrv_put_ref_bh (void *opaque) -{ -BDRVPutRefBH *s = opaque; - -bdrv_unref (s->bs); -qemu_bh_delete (s->bh); -g_free (s); -} - -/* -* Release a BDS reference in a BH -* -* It is not safe to use bdrv_unref() from a callback function when the callers -* still need the BlockDriverState. In such cases we schedule a BH to release -* the reference. -*/ -static void bdrv_put_ref_bh_schedule (BlockDriverState *bs) -{ -BDRVPutRefBH *s; - - s =g_new (BDRVPutRefBH,1 ); - s->bh =qemu_bh_new (bdrv_put_ref_bh, s); - s->bs = bs; -qemu_bh_schedule (s->bh); -} -static int parse_block_error_action (const char *buf,bool is_read,Error **errp) {if (!strcmp (buf,"ignore" )) {
@@ -2326,6 +2295,12 @@ static void block_job_cb(void *opaque, int ret)block_job_event_completed (bs->job, msg); } + +/* +* It is not safe to use bdrv_unref() from a callback function when the +* callers still need the BlockDriverState. In such cases we schedule +* a BH to release the reference. +*/ bdrv_put_ref_bh_schedule (bs); }
include/block/block.h +1 -0
@@ -507,6 +507,7 @@ void bdrv_disable_copy_on_read(BlockDriverState *bs);void bdrv_ref (BlockDriverState *bs);void bdrv_unref (BlockDriverState *bs); +void bdrv_put_ref_bh_schedule (BlockDriverState *bs);bool bdrv_op_is_blocked (BlockDriverState *bs,BlockOpType op,Error **errp);void bdrv_op_block (BlockDriverState *bs,BlockOpType op,Error *reason);
Signature · 1 line
2.4.3
PATCH v8 9/18 Backup: clear all bitmap when doing block checkpoint
In reply to Wen Congyang--- block/backup.c | 13 +++++++++++++ blockjob.c | 10 ++++++++++ include/block/blockjob.h | 12 ++++++++++++ 3 files changed, 35 insertions(+)
block/backup.c +13 -0
@@ -211,11 +211,24 @@ static void backup_iostatus_reset(BlockJob *job)bdrv_iostatus_reset (s->target); } +static void backup_do_checkpoint (BlockJob *job,Error **errp) +{ +BackupBlockJob *backup_job =container_of (job, BackupBlockJob, common); + +if (backup_job->sync_mode !=MIRROR_SYNC_MODE_NONE ) { +error_setg (errp,"this feature or command is not currently supported" ); +return ; + } + +hbitmap_reset_all (backup_job->bitmap); +} +static const BlockJobDriver backup_job_driver = { .instance_size =sizeof (BackupBlockJob), .job_type =BLOCK_JOB_TYPE_BACKUP , .set_speed = backup_set_speed, .iostatus_reset = backup_iostatus_reset, + .do_checkpoint = backup_do_checkpoint, }; static BlockErrorAction backup_error_action(BackupBlockJob *job,
blockjob.c +10 -0
@@ -400,3 +400,13 @@ void block_job_defer_to_main_loop(BlockJob *job,qemu_bh_schedule (data->bh); } + +void block_job_do_checkpoint (BlockJob *job,Error **errp) +{ +if (!job->driver->do_checkpoint) { +error_setg (errp,"this feature or command is not currently supported" ); +return ; + } + + job->driver->do_checkpoint (job, errp); +}
include/block/blockjob.h +12 -0
@@ -50,6 +50,9 @@ typedef struct BlockJobDriver {* manually. */ void (*complete)(BlockJob *job,Error **errp); + +/** Optional callback for job types that support checkpoint. */ +void (*do_checkpoint)(BlockJob *job,Error **errp); } BlockJobDriver;/**
@@ -348,4 +351,13 @@ void block_job_defer_to_main_loop(BlockJob *job, BlockJobDeferToMainLoopFn *fn, void *opaque); +/** +* block_job_do_checkpoint: +* @job: The job. +* @errp: Error object. +* +* Do block checkpoint on the specified job. +*/ +void block_job_do_checkpoint (BlockJob *job,Error **errp); +#endif
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH COLO-BLOCK v8 09/18] Backup: clear all bitmap when doing block checkpoint
Quoted 15 lines · * Wen Congyang ([email protected]) wrote:
Signed-off-by Wen Congyang <[email protected]>Signed-off-by zhanghailiang <[email protected]>Signed-off-by Gonglei <[email protected]>Cc Jeff Cody <[email protected]>--- block/backup.c | 13 +++++++++++++ blockjob.c | 10 ++++++++++ include/block/blockjob.h | 12 ++++++++++++ 3 files changed, 35 insertions(+)block/backup.c +0
-0
block/backup.c static void backup_iostatus_reset(BlockJob *job) · line 219
Quoted 9 lines
block/backup.c +6
-0@@ -211,11 +211,24 @@ static void backup_iostatus_reset(BlockJob *job)bdrv_iostatus_reset (s->target); } +static void backup_do_checkpoint (BlockJob *job,Error **errp) +{ +BackupBlockJob *backup_job =container_of (job, BackupBlockJob, common); + +if (backup_job->sync_mode !=MIRROR_SYNC_MODE_NONE ) { +error_setg (errp,"this feature or command is not currently supported" );
You use this text in a few different errors in the block code; we've currently got one test machine which is producing it and we haven't yet figured out which one of the exit paths is doing it. Please make each one unique and state an identifier; e.g. "checkpoint on block backup in sync ... for blockjob ..." (I'm not sure what exaclty makes sense for block jobs - but something like that).
Dave
Quoted 64 lines
block/backup.c +7
-0+return ; + } + +hbitmap_reset_all (backup_job->bitmap); +} +static const BlockJobDriver backup_job_driver = { .instance_size =sizeof (BackupBlockJob), .job_type =BLOCK_JOB_TYPE_BACKUP , .set_speed = backup_set_speed, .iostatus_reset = backup_iostatus_reset, + .do_checkpoint = backup_do_checkpoint, }; static BlockErrorAction backup_error_action(BackupBlockJob *job,blockjob.c +10
-0@@ -400,3 +400,13 @@ void block_job_defer_to_main_loop(BlockJob *job,qemu_bh_schedule (data->bh); } + +void block_job_do_checkpoint (BlockJob *job,Error **errp) +{ +if (!job->driver->do_checkpoint) { +error_setg (errp,"this feature or command is not currently supported" ); +return ; + } + + job->driver->do_checkpoint (job, errp); +}include/block/blockjob.h +12
-0@@ -50,6 +50,9 @@ typedef struct BlockJobDriver {* manually. */ void (*complete)(BlockJob *job,Error **errp); + +/** Optional callback for job types that support checkpoint. */ +void (*do_checkpoint)(BlockJob *job,Error **errp); } BlockJobDriver;/** @@ -348,4 +351,13 @@ void block_job_defer_to_main_loop(BlockJob *job, BlockJobDeferToMainLoopFn *fn, void *opaque); +/** +* block_job_do_checkpoint: +* @job: The job. +* @errp: Error object. +* +* Do block checkpoint on the specified job. +*/ +void block_job_do_checkpoint (BlockJob *job,Error **errp); +#endif Signature · 1 line
2.4.3
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH COLO-BLOCK v8 09/18] Backup: clear all bitmap when doing block checkpoint
Quoted 19 lines · Dr. David Alan Gilbert
Quoted 18 lines · * Wen Congyang ([email protected]) wrote:
Signed-off-by Wen Congyang <[email protected]>Signed-off-by zhanghailiang <[email protected]>Signed-off-by Gonglei <[email protected]>Cc Jeff Cody <[email protected]>--- block/backup.c | 13 +++++++++++++ blockjob.c | 10 ++++++++++ include/block/blockjob.h | 12 ++++++++++++ 3 files changed, 35 insertions(+)block/backup.c +0
-0@@ -211,11 +211,24 @@ static void backup_iostatus_reset(BlockJob *job)bdrv_iostatus_reset (s->target); }
Quoted 12 lines
block/backup.c static void backup_iostatus_reset(BlockJob *job) · line 219
Quoted 6 lines
block/backup.c +6
-0+static void backup_do_checkpoint (BlockJob *job,Error **errp) +{ +BackupBlockJob *backup_job =container_of (job, BackupBlockJob, common); + +if (backup_job->sync_mode !=MIRROR_SYNC_MODE_NONE ) { +error_setg (errp,"this feature or command is not currently supported" );You use this text in a few different errors in the block code; we've currently got one test machine which is producing it and we haven't yet figured out which one of the exit paths is doing it. Please make each one unique and state an identifier; e.g. "checkpoint on block backup in sync ... for blockjob ..." (I'm not sure what exaclty makes sense for block jobs - but something like that).
OK, I will check all error messages.
Thanks
Wen Congyang
Quoted 71 lines
Dave
Quoted 64 lines
block/backup.c +7
-0+return ; + } + +hbitmap_reset_all (backup_job->bitmap); +} +static const BlockJobDriver backup_job_driver = { .instance_size =sizeof (BackupBlockJob), .job_type =BLOCK_JOB_TYPE_BACKUP , .set_speed = backup_set_speed, .iostatus_reset = backup_iostatus_reset, + .do_checkpoint = backup_do_checkpoint, }; static BlockErrorAction backup_error_action(BackupBlockJob *job,blockjob.c +10
-0@@ -400,3 +400,13 @@ void block_job_defer_to_main_loop(BlockJob *job,qemu_bh_schedule (data->bh); } + +void block_job_do_checkpoint (BlockJob *job,Error **errp) +{ +if (!job->driver->do_checkpoint) { +error_setg (errp,"this feature or command is not currently supported" ); +return ; + } + + job->driver->do_checkpoint (job, errp); +}include/block/blockjob.h +12
-0@@ -50,6 +50,9 @@ typedef struct BlockJobDriver {* manually. */ void (*complete)(BlockJob *job,Error **errp); + +/** Optional callback for job types that support checkpoint. */ +void (*do_checkpoint)(BlockJob *job,Error **errp); } BlockJobDriver;/** @@ -348,4 +351,13 @@ void block_job_defer_to_main_loop(BlockJob *job, BlockJobDeferToMainLoopFn *fn, void *opaque); +/** +* block_job_do_checkpoint: +* @job: The job. +* @errp: Error object. +* +* Do block checkpoint on the specified job. +*/ +void block_job_do_checkpoint (BlockJob *job,Error **errp); +#endif Signature · 1 line
2.4.3--
Dr. David Alan Gilbert / [email protected] / Manchester, UK .
PATCH v8 10/18 allow writing to the backing file
In reply to Wen Congyang--- block.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-)
block.c +40 -1
@@ -747,6 +747,15 @@ static const BdrvChildRole child_backing = { .inherit_flags = bdrv_backing_flags, }; +static int bdrv_backing_rw_flags (int flags) +{ +return bdrv_backing_flags (flags) |BDRV_O_RDWR ; +} + +static const BdrvChildRole child_backing_rw = { + .inherit_flags = bdrv_backing_rw_flags, +}; +static int bdrv_open_flags (BlockDriverState *bs,int flags) {int open_flags = flags |BDRV_O_CACHE_WB ;
@@ -1133,6 +1142,20 @@ out:bdrv_refresh_limits (bs,NULL ); } +#define ALLOW_WRITE_BACKING_FILE "allow-write-backing-file" +static QemuOptsList backing_file_opts = { + .name ="backing_file" , + .head =QTAILQ_HEAD_INITIALIZER (backing_file_opts.head), + .desc = { + { + .name =ALLOW_WRITE_BACKING_FILE , + .type =QEMU_OPT_BOOL , + .help ="allow write to backing file" , + }, + {/* end of list */ } + }, +}; +/* * Opens the backing file for a BlockDriverState if not yet open *
@@ -1147,6 +1170,9 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)int ret =0 ;BlockDriverState *backing_hd;Error *local_err =NULL ; +QemuOpts *opts =NULL ; +bool child_rw = false; +const BdrvChildRole *child_role =NULL ;if (bs->backing_hd !=NULL ) {QDECREF (options);
@@ -1159,6 +1185,18 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp) } bs->open_flags &= ~BDRV_O_NO_BACKING ; + + opts =qemu_opts_create (&backing_file_opts,NULL ,0 , &error_abort); +qemu_opts_absorb_qdict (opts, options, &local_err); +if (local_err) { + ret = -EINVAL ; +error_propagate (errp, local_err); +QDECREF (options); + goto free_exit; + } + child_rw =qemu_opt_get_bool (opts,ALLOW_WRITE_BACKING_FILE , false); + child_role = child_rw ? &child_backing_rw : &child_backing; +if (qdict_haskey (options,"file.filename" )) { backing_filename[0 ] ='\0' ; }else if (bs->backing_file[0 ] =='\0' &&qdict_size (options) ==0 ) {
@@ -1191,7 +1229,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)assert (bs->backing_hd ==NULL ); ret =bdrv_open_inherit (&backing_hd, *backing_filename ? backing_filename :NULL , -NULL , options,0 , bs, &child_backing, +NULL , options,0 , bs, child_role,NULL , &local_err);if (ret <0 ) {bdrv_unref (backing_hd);
@@ -1205,6 +1243,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)bdrv_set_backing_hd (bs, backing_hd); free_exit: +qemu_opts_del (opts);g_free (backing_filename);return ret; }
Signature · 1 line
2.4.3
PATCH v8 11/18 Allow creating backup jobs when opening BDS
In reply to Wen CongyangWhen opening BDS, we need to create backup jobs for image-fleecing.
--- block/Makefile.objs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/Makefile.objs +1 -1
@@ -22,10 +22,10 @@ block-obj-$(CONFIG_ARCHIPELAGO) += archipelago.o block-obj-$(CONFIG_LIBSSH2) += ssh.o block-obj-y += accounting.o block-obj-y += write-threshold.o +block-obj-y += backup.o common-obj-y += stream.o common-obj-y += commit.o -common-obj-y += backup.o iscsi.o-cflags := $(LIBISCSI_CFLAGS) iscsi.o-libs := $(LIBISCSI_LIBS)
Signature · 1 line
2.4.3
PATCH v8 12/18 block: Allow references for backing files
In reply to Wen CongyangUsage:
-drive file=xxx,id=Y, \
-drive file=xxxx,id=X,backing.backing_reference=Y
It will create such backing chain:
{virtio-blk dev 'Y'} {virtio-blk dev 'X'}
| |
| |
v v
[base] <- [mid] <- ( Y ) <----------------- ( X )--- block.c | 39 +++++++++++++++++++++++++++++++++++---- include/block/block.h | 1 + 2 files changed, 36 insertions(+), 4 deletions(-)
block.c +35 -4
@@ -1143,6 +1143,7 @@ out: }#define ALLOW_WRITE_BACKING_FILE "allow-write-backing-file" +#define BACKING_REFERENCE "backing_reference"static QemuOptsList backing_file_opts = { .name ="backing_file" , .head =QTAILQ_HEAD_INITIALIZER (backing_file_opts.head),
@@ -1152,6 +1153,11 @@ static QemuOptsList backing_file_opts = { .type = QEMU_OPT_BOOL, .help = "allow write to backing file", }, + { + .name = BACKING_REFERENCE, + .type = QEMU_OPT_STRING, + .help = "reference to the exsiting BDS", + }, {/* end of list */ } }, };
@@ -1168,11 +1174,12 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp) {char *backing_filename =g_malloc0 (PATH_MAX );int ret =0 ; -BlockDriverState *backing_hd; +BlockDriverState *backing_hd =NULL ;Error *local_err =NULL ;QemuOpts *opts =NULL ;bool child_rw = false;const BdrvChildRole *child_role =NULL ; +const char *reference =NULL ;if (bs->backing_hd !=NULL ) {QDECREF (options);
@@ -1195,9 +1202,10 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp) goto free_exit; } child_rw =qemu_opt_get_bool (opts,ALLOW_WRITE_BACKING_FILE , false); + reference =qemu_opt_get (opts,BACKING_REFERENCE ); child_role = child_rw ? &child_backing_rw : &child_backing; -if (qdict_haskey (options,"file.filename" )) { +if (qdict_haskey (options,"file.filename" ) || reference) { backing_filename[0 ] ='\0' ; }else if (bs->backing_file[0 ] =='\0' &&qdict_size (options) ==0 ) {QDECREF (options);
@@ -1220,7 +1228,9 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp) goto free_exit; } - backing_hd =bdrv_new (); +if (!reference) { + backing_hd =bdrv_new (); + }if (bs->backing_format[0 ] !='\0' && !qdict_haskey (options,"driver" )) {qdict_put (options,"driver" ,qstring_from_str (bs->backing_format));
@@ -1229,7 +1239,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)assert (bs->backing_hd ==NULL ); ret =bdrv_open_inherit (&backing_hd, *backing_filename ? backing_filename :NULL , -NULL , options,0 , bs, child_role, + reference, options,0 , bs, child_role,NULL , &local_err);if (ret <0 ) {bdrv_unref (backing_hd);
@@ -1240,12 +1250,30 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)error_free (local_err); goto free_exit; } +if (reference) { +if (bdrv_op_is_blocked (backing_hd,BLOCK_OP_TYPE_BACKING_REFERENCE , + errp)) { + ret = -EBUSY ; + goto free_reference_exit; + } +if (backing_hd->blk &&blk_disable_attach_dev (backing_hd->blk)) { +error_setg (errp,"backing_hd %s is used by the other device model" , + reference); + ret = -EBUSY ; + goto free_reference_exit; + } + }bdrv_set_backing_hd (bs, backing_hd); free_exit:qemu_opts_del (opts);g_free (backing_filename);return ret; + +free_reference_exit: +bdrv_unref (backing_hd); + bs->open_flags |=BDRV_O_NO_BACKING ; + goto free_exit; }/*
@@ -1899,6 +1927,9 @@ void bdrv_close(BlockDriverState *bs)if (bs->backing_hd) {BlockDriverState *backing_hd = bs->backing_hd;bdrv_set_backing_hd (bs,NULL ); +if (backing_hd->blk) { +blk_enable_attach_dev (backing_hd->blk); + }bdrv_unref (backing_hd); } bs->drv->bdrv_close (bs);
include/block/block.h +1 -0
@@ -168,6 +168,7 @@ typedef enum BlockOpType {BLOCK_OP_TYPE_RESIZE ,BLOCK_OP_TYPE_STREAM ,BLOCK_OP_TYPE_REPLACE , +BLOCK_OP_TYPE_BACKING_REFERENCE ,BLOCK_OP_TYPE_MAX , } BlockOpType;
Signature · 1 line
2.4.3
PATCH v8 13/18 docs: block replication's description
In reply to Wen Congyang--- docs/block-replication.txt | 182 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 docs/block-replication.txt
docs/block-replication.txt new file +182 -0
@@ -0,0 +1,182 @@ +Block replication +---------------------------------------- +Copyright Fujitsu, Corp. 2015 +Copyright (c) 2015 Intel Corporation +Copyright (c) 2015 HUAWEI TECHNOLOGIES CO., LTD. + +This work is licensed under the terms of the GNU GPL, version 2 or later. +See the COPYING file in the top-level directory. + +Block replication is used for continuous checkpoints. It is designed +for COLO (COurse-grain LOck-stepping) where the Secondary VM is running. +It can also be applied for FT/HA (Fault-tolerance/High Assurance) scenario, +where the Secondary VM is not running. + +This document gives an overview of block replication's design. + +== Background == +High availability solutions such as micro checkpoint and COLO will do +consecutive checkpoints. The VM state of Primary VM and Secondary VM is +identical right after a VM checkpoint, but becomes different as the VM +executes till the next checkpoint. To support disk contents checkpoint, +the modified disk contents in the Secondary VM must be buffered, and are +only dropped at next checkpoint time. To reduce the network transportation +effort at the time of checkpoint, the disk modification operations of +Primary disk are asynchronously forwarded to the Secondary node. + +== Workflow == +The following is the image of block replication workflow: + + +----------------------+ +------------------------+ + |Primary Write Requests| |Secondary Write Requests| + +----------------------+ +------------------------+ + | | + | (4) + | V + | /-------------\ + | Copy and Forward | | + |---------(1)----------+ | Disk Buffer | + | | | | + | (3) \-------------/ + | speculative ^ + | write through (2) + | | | + V V | + +--------------+ +----------------+ + | Primary Disk | | Secondary Disk | + +--------------+ +----------------+ + + 1) Primary write requests will be copied and forwarded to Secondary + QEMU. + 2) Before Primary write requests are written to Secondary disk, the + original sector content will be read from Secondary disk and + buffered in the Disk buffer, but it will not overwrite the existing + sector content(it could be from either "Secondary Write Requests" or + previous COW of "Primary Write Requests") in the Disk buffer. + 3) Primary write requests will be written to Secondary disk. + 4) Secondary write requests will be buffered in the Disk buffer and it + will overwrite the existing sector content in the buffer. + +== Architecture == +We are going to implement block replication from many basic +blocks that are already in QEMU. + + virtio-blk || + ^ || .---------- + | || | Secondary + 1 Quorum || '---------- + / \ || + / \ || + Primary 2 filter + disk ^ virtio-blk + | ^ + 3 NBD -------> 3 NBD | + client || server 2 filter + || ^ ^ +--------. || | | +Primary | || Secondary disk <--------- hidden-disk 5 <--------- active-disk 4 +--------' || | backing ^ backing + || | | + || | | + || '-------------------------' + || drive-backup sync=none + +1) The disk on the primary is represented by a block device with two +children, providing replication between a primary disk and the host that +runs the secondary VM. The read pattern for quorum can be extended to +make the primary always read from the local disk instead of going through +NBD. + +2) The new block filter(the name is replication) will control the block +replication. + +3) The secondary disk receives writes from the primary VM through QEMU's +embedded NBD server (speculative write-through). + +4) The disk on the secondary is represented by a custom block device +(called active-disk). It should be an empty disk, and the format should +support bdrv_make_empty() and backing file. + +5) The hidden-disk is created automatically. It buffers the original content +that is modified by the primary VM. It should also be an empty disk, and +the driver supports bdrv_make_empty() and backing file. + +== Failure Handling == +There are 6 internal errors when block replication is running: +1. I/O error on primary disk +2. Forwarding primary write requests failed +3. Backup failed +4. I/O error on secondary disk +5. I/O error on active disk +6. Making active disk or hidden disk empty failed +In case 1 and 5, we just report the error to the disk layer. In case 2, 3, +4 and 6, we just report block replication's error to FT/HA manager(which +decides when to do a new checkpoint, when to do failover). +There is one internal error when doing failover: +1. Commiting the data in active disk/hidden disk to secondary disk failed +We just to report this error to FT/HA manager. + +== New block driver interface == +We add three block driver interfaces to control block replication: +a. bdrv_start_replication() + Start block replication, called in migration/checkpoint thread. + We must call bdrv_start_replication() in secondary QEMU before + calling bdrv_start_replication() in primary QEMU. The caller + must hold the I/O mutex lock if it is in migration/checkpoint + thread. +b. bdrv_do_checkpoint() + This interface is called after all VM state is transferred to + Secondary QEMU. The Disk buffer will be dropped in this interface. + The caller must hold the I/O mutex lock if it is in migration/checkpoint + thread. +c. bdrv_stop_replication() + It is called on failover. We will flush the Disk buffer into + Secondary Disk and stop block replication. The vm should be stopped + before calling it. The caller must hold the I/O mutex lock if it is + in migration/checkpoint thread. + +== Usage == +Primary: + -drive if=xxx,driver=quorum,read-pattern=fifo,id=disk1\ + children.0.file.filename=1.raw,\ + children.0.driver=raw,\ + + Run qmp command in primary qemu: + child_add disk1 child.driver=replication,child.mode=primary,\ + child.file.host=xxx,child.file.port=xxx,\ + child.file.driver=nbd,child.ignore-errors=on + Note: + 1. There should be only one NBD Client for each primary disk. + 2. host is the secondary physical machine's hostname or IP + 3. Each disk must have its own export name. + 4. It is all a single argument to -drive and child_add, and you should + ignore the leading whitespace. + 5. The qmp command line must be run after running qmp command line in + secondary qemu. + +Secondary: + -drive if=none,driver=raw,file=1.raw,id=colo1 \ + -drive if=xxx,driver=replication,mode=secondary,\ + file.file.filename=active_disk.qcow2,\ + file.driver=qcow2,\ + file.backing.file.filename=hidden_disk.qcow2,\ + file.backing.driver=qcow2,\ + file.backing.allow-write-backing-file=on,\ + file.backing.backing.backing_reference=colo1\ + + Then run qmp command in secondary qemu: + nbd-server-start host:port + nbd-server-add -w colo1 + + Note: + 1. The export name in secondary QEMU command line is the secondary + disk's id. + 2. The export name for the same disk must be the same + 3. The qmp command nbd-server-start and nbd-server-add must be run + before running the qmp command migrate on primary QEMU + 4. Don't use nbd-server-start's other options + 5. Active disk, hidden disk and nbd target's length should be the + same. + 6. It is better to put active disk and hidden disk in ramdisk. + 7. It is all a single argument to -drive, and you should ignore + the leading whitespace.
Signature · 1 line
2.4.3
PATCH v8 14/18 Add new block driver interfaces to control block replication
In reply to Wen Congyang--- block.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/block/block.h | 5 +++++ include/block/block_int.h | 14 ++++++++++++++ qapi/block.json | 16 ++++++++++++++++ 4 files changed, 75 insertions(+)
block.c +40 -0
@@ -4329,3 +4329,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" ); + } +}
include/block/block.h +5 -0
@@ -615,4 +615,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
include/block/block_int.h +14 -0
@@ -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; };
qapi/block.json +16 -0
@@ -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
Signature · 1 line
2.4.3
PATCH v8 15/18 skip nbd_target when starting block replication
In reply to Wen Congyang--- block.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
block.c +12 -0
@@ -4335,6 +4335,10 @@ void bdrv_start_replication(BlockDriverState *bs, ReplicationMode mode, {BlockDriver *drv = bs->drv; +if (bdrv_op_is_blocked (bs,BLOCK_OP_TYPE_BACKING_REFERENCE ,NULL )) { +return ; + } +if (drv && drv->bdrv_start_replication) { drv->bdrv_start_replication (bs, mode, errp); }else if (bs->file) {
@@ -4348,6 +4352,10 @@ void bdrv_do_checkpoint(BlockDriverState *bs, Error **errp) {BlockDriver *drv = bs->drv; +if (bdrv_op_is_blocked (bs,BLOCK_OP_TYPE_BACKING_REFERENCE ,NULL )) { +return ; + } +if (drv && drv->bdrv_do_checkpoint) { drv->bdrv_do_checkpoint (bs, errp); }else if (bs->file) {
@@ -4361,6 +4369,10 @@ void bdrv_stop_replication(BlockDriverState *bs, bool failover, Error **errp) {BlockDriver *drv = bs->drv; +if (bdrv_op_is_blocked (bs,BLOCK_OP_TYPE_BACKING_REFERENCE ,NULL )) { +return ; + } +if (drv && drv->bdrv_stop_replication) { drv->bdrv_stop_replication (bs, failover, errp); }else if (bs->file) {
Signature · 1 line
2.4.3
PATCH v8 16/18 quorum: implement block driver interfaces for block replication
In reply to Wen Congyang--- block/quorum.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+)
block/quorum.c +77 -0
@@ -88,6 +88,8 @@ typedef struct BDRVQuorumState {*/ QuorumReadPattern read_pattern; + +int replication_index;/* store which child supports block replication */ } BDRVQuorumState;typedef struct QuorumAIOCB QuorumAIOCB ;
@@ -1019,6 +1021,7 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags, }g_free (opened); + s->replication_index =-1 ; goto exit; close_exit:
@@ -1179,6 +1182,76 @@ static void quorum_refresh_filename(BlockDriverState *bs) bs->full_open_options = opts; } +static void quorum_start_replication (BlockDriverState *bs,ReplicationMode mode, +Error **errp) +{ +BDRVQuorumState *s = bs->opaque; +int count =0 , i, index; +Error *local_err =NULL ; + +/* +* TODO: support REPLICATION_MODE_SECONDARY if we allow secondary +* QEMU becoming primary QEMU. +*/ +if (mode !=REPLICATION_MODE_PRIMARY ) { +error_setg (errp,"The replication mode for quorum should be 'primary'" ); +return ; + } + +if (s->read_pattern !=QUORUM_READ_PATTERN_FIFO ) { +error_setg (errp,"Block replication needs read pattern 'fifo'" ); +return ; + } + +for (i =0 ; i < s->num_children; i++) { +bdrv_start_replication (s->bs[i], mode, &local_err); +if (local_err) { +error_free (local_err); + local_err =NULL ; + }else { + count++; + index = i; + } + } + +if (count ==0 ) { +error_setg (errp,"No child supports block replication" ); + }else if (count >1 ) { +for (i =0 ; i < s->num_children; i++) { +bdrv_stop_replication (s->bs[i], false,NULL ); + } +error_setg (errp,"Too many children support block replication" ); + }else { + s->replication_index = index; + } +} + +static void quorum_do_checkpoint (BlockDriverState *bs,Error **errp) +{ +BDRVQuorumState *s = bs->opaque; + +if (s->replication_index <0 ) { +error_setg (errp,"Block replication is not running" ); +return ; + } + +bdrv_do_checkpoint (s->bs[s->replication_index], errp); +} + +static void quorum_stop_replication (BlockDriverState *bs,bool failover, +Error **errp) +{ +BDRVQuorumState *s = bs->opaque; + +if (s->replication_index <0 ) { +error_setg (errp,"Block replication is not running" ); +return ; + } + +bdrv_stop_replication (s->bs[s->replication_index], failover, errp); + s->replication_index =-1 ; +} +static BlockDriver bdrv_quorum = { .format_name ="quorum" , .protocol_name ="quorum" ,
@@ -1205,6 +1278,10 @@ static BlockDriver bdrv_quorum = { .is_filter = true, .bdrv_recurse_is_first_non_filter = quorum_recurse_is_first_non_filter, + + .bdrv_start_replication = quorum_start_replication, + .bdrv_do_checkpoint = quorum_do_checkpoint, + .bdrv_stop_replication = quorum_stop_replication, };static void bdrv_quorum_init (void )
Signature · 1 line
2.4.3
PATCH v8 17/18 Implement new driver for block replication
In reply to Wen Congyang--- block/Makefile.objs | 1 + block/replication.c | 443 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 444 insertions(+) create mode 100644 block/replication.c
block/Makefile.objs +1 -0
@@ -23,6 +23,7 @@ block-obj-$(CONFIG_LIBSSH2) += ssh.o block-obj-y += accounting.o block-obj-y += write-threshold.o block-obj-y += backup.o +block-obj-y += replication.o common-obj-y += stream.o common-obj-y += commit.o
block/replication.c new file +443 -0
443 lines not on this page · raw message
Signature · 1 line
2.4.3
PATCH v8 18/18 Add a new API to start/stop replication, do checkpoint to all BDSes
In reply to Wen Congyang--- block.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/block/block.h | 4 +++ 2 files changed, 72 insertions(+)
block.c +68 -0
@@ -4381,3 +4381,71 @@ void bdrv_stop_replication(BlockDriverState *bs, bool failover, Error **errp)error_setg (errp,"this feature or command is not currently supported" ); } } + +void bdrv_start_replication_all (ReplicationMode mode,Error **errp) +{ +BlockDriverState *bs =NULL , *temp =NULL ; +Error *local_err =NULL ; + +while ((bs =bdrv_next (bs))) { +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 (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 (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 ; + } + } +}
include/block/block.h +4 -0
@@ -620,4 +620,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
Signature · 1 line
2.4.3
Ping...
Does anyone have time to review this patchset? The block replication is not only for COLO. All other HA/FT can reuse it(for example, microcheckpoint).
Thanks
Wen Congyang
Quoted 61 lines · Wen Congyang
Block replication is a very important feature which is used for continuous checkpoints(for example: COLO).
You can the detailed information about block replication from here:
http://wiki.qemu.org/Features/BlockReplicationUsage:
Please refer todocs/block-replication.txtYou can get the patch here:
https://github.com/coloft/qemu/tree/wency/block-replication-v8You can get the patch with framework here:
https://github.com/coloft/qemu/tree/wency/colo_framework_v8TODO:
1. Continuous block replication. It will be started after basic functions are accepted.Wen Congyang (18):
Add new block driver interface to add/delete a BDS's child
quorum: implement block driver interfaces add/delete a BDS's child
hmp: add monitor command to add/remove a child
introduce a new APIqemu_opts_absorb_qdict_by_index()
quorum: allow ignoring child errors
introduce a new API to enable/disable attach device model introduce a new API to check if blk is attached
block: makebdrv_put_ref_bh_schedule()as a public API
Backup: clear all bitmap when doing block checkpoint allow writing to the backing file
Allow creating backup jobs when opening BDS
block: Allow references for backing files
docs: block replication's description
Add new block driver interfaces to control block replication skipnbd_targetwhen starting block replication
quorum: implement block driver interfaces for block replication Implement new driver for block replication
Add a new API to start/stop replication, do checkpoint to all BDSesblock.c | 266 ++++++++++++++++++++++++- block/Makefile.objs | 3 +- block/backup.c | 13 ++ block/block-backend.c | 33 +++ block/quorum.c | 244 ++++++++++++++++++++++- block/replication.c | 443 +++++++++++++++++++++++++++++++++++++++++ blockdev.c | 90 ++++++--- blockjob.c | 10 + docs/block-replication.txt | 182 +++++++++++++++++ hmp-commands.hx | 28 +++ include/block/block.h | 15 ++ include/block/block_int.h | 19 ++ include/block/blockjob.h | 12 ++ include/qemu/option.h | 2 + include/sysemu/block-backend.h | 3 + include/sysemu/blockdev.h | 2 + qapi/block.json | 16 ++ util/qemu-option.c | 44 ++++ 18 files changed, 1378 insertions(+), 47 deletions(-) create mode 100644 block/replication.c create mode 100644 docs/block-replication.txt