COLO block replication supports shared disk case
v4 cover COLO block replication supports shared disk case
COLO block replication doesn't support the shared disk case, Here we try to implement it and this is the 4th version.
Please review and any commits are welcomed.
v4:
- Add proper comment for primary_disk in patch 2 (Stefan)
- Call bdrv_invalidate_cache() while do checkpoint for shared disk in patch 5
v3:
- Fix some comments from Stefan and Eric
v2:
- Drop the patch which add a blk_root() helper
- Fix some comments from Changlong
zhanghailiang (6):
docs/block-replication: Add description for shared-disk case
replication: add shared-disk and shared-disk-id options
replication: Split out backup_do_checkpoint() from
secondary_do_checkpoint()
replication: fix code logic with the new shared_disk option
replication: Implement block replication for shared disk case nbd/replication: implement .bdrv_get_info() for nbd and replication
driver
block/nbd.c | 12 +++ block/replication.c | 198 ++++++++++++++++++++++++++++++++++----------- docs/block-replication.txt | 139 ++++++++++++++++++++++++++++++- qapi/block-core.json | 10 ++- 4 files changed, 306 insertions(+), 53 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v4 1/6 docs/block-replication: Add description for shared-disk case
Introuduce the scenario of shared-disk block replication and how to use it.
--- docs/block-replication.txt | 139 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 135 insertions(+), 4 deletions(-)
docs/block-replication.txt +135 -4
@@ -24,7 +24,7 @@ only dropped at next checkpoint time. To reduce the network transportation effort during a vmstate checkpoint, the disk modification operations of the Primary disk are asynchronously forwarded to the Secondary node. -== Workflow == +== Non-shared disk workflow == The following is the image of block replication workflow: +----------------------+ +------------------------+
@@ -57,7 +57,7 @@ The following is the image of block replication workflow: 4) Secondary write requests will be buffered in the Disk buffer and it will overwrite the existing sector content in the buffer. -== Architecture == +== Non-shared disk architecture == We are going to implement block replication from many basic blocks that are already in QEMU.
@@ -106,6 +106,74 @@ any state that would otherwise be lost by the speculative write-through of the NBD server into the secondary disk. So before block replication, the primary disk and secondary disk should contain the same data. +== Shared Disk Mode Workflow == +The following is the image of block replication workflow: + + +----------------------+ +------------------------+ + |Primary Write Requests| |Secondary Write Requests| + +----------------------+ +------------------------+ + | | + | (4) + | V + | /-------------\ + | (2)Forward and write through | | + | +--------------------------> | Disk Buffer | + | | | | + | | \-------------/ + | |(1)read | + | | | + (3)write | | | backing file + V | | + +-----------------------------+ | + | Shared Disk | <-----+ + +-----------------------------+ + + 1) Primary writes will read original data and forward it to Secondary + QEMU. + 2) Before Primary write requests are written to Shared disk, the + original sector content will be read from Shared disk and + forwarded and buffered in the Disk buffer on the secondary site, + 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 Shared disk. + 4) Secondary write requests will be buffered in the Disk buffer and it + will overwrite the existing sector content in the buffer. + +== Shared Disk Mode Architecture == +We are going to implement block replication from many basic +blocks that are already in QEMU. + virtio-blk || .---------- + / || | Secondary + / || '---------- + / || virtio-blk + / || | + | || replication(5) + | NBD --------> NBD (2) | + | client || server ---> hidden disk <-- active disk(4) + | ^ || | + | replication(1) || | + | | || | + | +-----------------' || | + (3) |drive-backup sync=none || | +--------. | +-----------------+ || | +Primary | | | || backing | +--------' | | || | + V | | + +-------------------------------------------+ | + | shared disk | <----------+ + +-------------------------------------------+ + + + 1) Primary writes will read original data and forward it to Secondary + QEMU. + 2) The hidden-disk 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. + 3) Primary write requests will be written to Shared disk. + 4) Secondary write requests will be buffered in the active disk and it + will overwrite the existing sector content in the buffer. + == Failure Handling == There are 7 internal errors when block replication is running: 1. I/O error on primary disk
@@ -145,7 +213,7 @@ d. replication_stop_all() things except failover. The caller must hold the I/O mutex lock if it is in migration/checkpoint thread. -== Usage == +== Non-shared disk usage == Primary: -drive if=xxx,driver=quorum,read-pattern=fifo,id=colo1,vote-threshold=1,\ children.0.file.filename=1.raw,\
@@ -234,6 +302,69 @@ Secondary: The primary host is down, so we should do the following thing: { 'execute': 'nbd-server-stop' } +== Shared disk usage == +Primary: + -drive if=virtio,id=primary_disk0,file.filename=1.raw,driver=raw + +Issue qmp command: + { 'execute': 'blockdev-add', + 'arguments': { + 'driver': 'replication', + 'node-name': 'rep', + 'mode': 'primary', + 'shared-disk-id': 'primary_disk0', + 'shared-disk': true, + 'file': { + 'driver': 'nbd', + 'export': 'hidden_disk0', + 'server': { + 'type': 'inet', + 'data': { + 'host': 'xxx.xxx.xxx.xxx', + 'port': 'yyy' + } + } + } + } + } + +Secondary: + -drive if=none,driver=qcow2,file.filename=/mnt/ramfs/hidden_disk.img,id=hidden_disk0,\ + backing.driver=raw,backing.file.filename=1.raw \ + -drive if=virtio,id=active-disk0,driver=replication,mode=secondary,\ + file.driver=qcow2,top-id=active-disk0,\ + file.file.filename=/mnt/ramfs/active_disk.img,\ + file.backing=hidden_disk0,shared-disk=on + +Issue qmp command: +1. { 'execute': 'nbd-server-start', + 'arguments': { + 'addr': { + 'type': 'inet', + 'data': { + 'host': '0', + 'port': 'yyy' + } + } + } + } +2. { 'execute': 'nbd-server-add', + 'arguments': { + 'device': 'hidden_disk0', + 'writable': true + } + } + +After Failover: +Primary: + { 'execute': 'x-blockdev-del', + 'arguments': { + 'node-name': 'rep' + } + } + +Secondary: + {'execute': 'nbd-server-stop' } + TODO: 1. Continuous block replication -2. Shared disk
Signature · 1 line
1.8.3.1
PATCH v4 2/6 replication: add shared-disk and shared-disk-id options
In reply to zhanghailiangWe use these two options to identify which disk is shared
---
v4:
- Add proper comment for primary_disk (Stefan)
v2:
- Move g_free(s->shared_disk_id) to the common fail process place (Stefan)
- Fix comments for these two options
--- block/replication.c | 43 +++++++++++++++++++++++++++++++++++++++++-- qapi/block-core.json | 10 +++++++++- 2 files changed, 50 insertions(+), 3 deletions(-)
block/replication.c +41 -2
@@ -25,9 +25,12 @@ typedef struct BDRVReplicationState { ReplicationMode mode; int replication_state; + bool is_shared_disk; + char *shared_disk_id; BdrvChild *active_disk; BdrvChild *hidden_disk; BdrvChild *secondary_disk; + BdrvChild *primary_disk; char *top_id; ReplicationState *rs; Error *blocker;
@@ -53,6 +56,9 @@ static void replication_stop(ReplicationState *rs, bool failover,#define REPLICATION_MODE "mode"#define REPLICATION_TOP_ID "top-id" +#define REPLICATION_SHARED_DISK "shared-disk" +#define REPLICATION_SHARED_DISK_ID "shared-disk-id" +static QemuOptsList replication_runtime_opts = { .name ="replication" , .head =QTAILQ_HEAD_INITIALIZER (replication_runtime_opts.head),
@@ -65,6 +71,14 @@ static QemuOptsList replication_runtime_opts = { .name = REPLICATION_TOP_ID, .type = QEMU_OPT_STRING, }, + { + .name = REPLICATION_SHARED_DISK_ID, + .type = QEMU_OPT_STRING, + }, + { + .name = REPLICATION_SHARED_DISK, + .type = QEMU_OPT_BOOL, + }, {/* end of list */ } }, };
@@ -85,6 +99,9 @@ static int replication_open(BlockDriverState *bs, QDict *options,QemuOpts *opts =NULL ;const char *mode;const char *top_id; +const char *shared_disk_id; +BlockBackend *blk; +BlockDriverState *tmp_bs; bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file, false, errp);
@@ -125,12 +142,33 @@ static int replication_open(BlockDriverState *bs, QDict *options, "The option mode's value should be primary or secondary"); goto fail; } + s->is_shared_disk =qemu_opt_get_bool (opts,REPLICATION_SHARED_DISK , + false); +if (s->is_shared_disk && (s->mode ==REPLICATION_MODE_PRIMARY )) { + shared_disk_id =qemu_opt_get (opts,REPLICATION_SHARED_DISK_ID ); +if (!shared_disk_id) { +error_setg (&local_err,"Missing shared disk blk option" ); + goto fail; + } + s->shared_disk_id =g_strdup (shared_disk_id); + blk =blk_by_name (s->shared_disk_id); +if (!blk) { +error_setg (&local_err,"There is no %s block" , s->shared_disk_id); + goto fail; + } +/* We have a BlockBackend for the primary disk but use BdrvChild for +* consistency - active_disk, secondary_disk, etc are also BdrvChild. +*/ + tmp_bs =blk_bs (blk); + s->primary_disk =QLIST_FIRST (&tmp_bs->parents); + } s->rs =replication_new (bs, &replication_ops); - ret =0 ; - +qemu_opts_del (opts); +return 0 ; fail: +g_free (s->shared_disk_id);qemu_opts_del (opts);error_propagate (errp, local_err);
@@ -141,6 +179,7 @@ static void replication_close(BlockDriverState *bs) {BDRVReplicationState *s = bs->opaque; +g_free (s->shared_disk_id);if (s->replication_state ==BLOCK_REPLICATION_RUNNING ) {replication_stop (s->rs, false,NULL ); }
qapi/block-core.json +9 -1
@@ -2661,12 +2661,20 @@ # node who owns the replication node chain. Must not be given in # primary mode. # +# @shared-disk-id: Id of shared disk while is replication mode, if @shared-disk +# is true, this option is required (Since: 2.10) +# +# @shared-disk: To indicate whether or not a disk is shared by primary VM +# and secondary VM. (The default is false) (Since: 2.10) +# # Since: 2.9 ## { 'struct': 'BlockdevOptionsReplication', 'base': 'BlockdevOptionsGenericFormat', 'data': { 'mode': 'ReplicationMode', - '*top-id': 'str' } } + '*top-id': 'str', + '*shared-disk-id': 'str', + '*shared-disk': 'bool' } } ## # @NFSTransport:
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v4 2/6] replication: add shared-disk and shared-disk-id options
Quoted 24 lines · zhanghailiang
We use these two options to identify which disk is shared
Signed-off-by zhanghailiang <[email protected]>Signed-off-by Wen Congyang <[email protected]>Signed-off-by Zhang Chen <[email protected]>---
v4:
- Add proper comment forprimary_disk(Stefan)
v2:
- Moveg_free(s->shared_disk_id)to the common fail process place (Stefan)
- Fix comments for these two options
---+++
b/qapi/block-core.jsonqapi/block-core.json +5
-0@@ -2661,12 +2661,20 @@ # node who owns the replication node chain. Must not be given in # primary mode. # +# @shared-disk-id: Id of shared disk while is replication mode, if @shared-disk +# is true, this option is required (Since: 2.10) +# +# @shared-disk: To indicate whether or not a disk is shared by primary VM +# and secondary VM. (The default is false) (Since: 2.10)
qapi/block-core.json line 2677
Quoted 10 lines
qapi/block-core.json +4
-1+# # Since: 2.9 ## { 'struct': 'BlockdevOptionsReplication', 'base': 'BlockdevOptionsGenericFormat', 'data': { 'mode': 'ReplicationMode', - '*top-id': 'str' } } + '*top-id': 'str', + '*shared-disk-id': 'str', + '*shared-disk': 'bool' } }
Do we need a separate bool and string? Or is it sufficient to say that if shared-disk is omitted, we are not sharing, and that if a shared-disk string is present, then we are sharing and it names the id of the shared disk.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH v4 2/6] replication: add shared-disk and shared-disk-id options
Quoted 30 lines · Eric Blake
Quoted 29 lines · zhanghailiang
We use these two options to identify which disk is shared
Signed-off-by zhanghailiang <[email protected]>Signed-off-by Wen Congyang <[email protected]>Signed-off-by Zhang Chen <[email protected]>---
v4:
- Add proper comment forprimary_disk(Stefan)
v2:
- Moveg_free(s->shared_disk_id)to the common fail process place (Stefan)
- Fix comments for these two options
---
+++b/qapi/block-core.jsonqapi/block-core.json +6
-0@@ -2661,12 +2661,20 @@ # node who owns the replication node chain. Must not be given in # primary mode. # +# @shared-disk-id: Id of shared disk while is replication mode, if @shared-disk +# is true, this option is required (Since: 2.10) +# +# @shared-disk: To indicate whether or not a disk is shared by primary VM +# and secondary VM. (The default is false) (Since: 2.10) +# # Since: 2.9 ## { 'struct': 'BlockdevOptionsReplication', 'base': 'BlockdevOptionsGenericFormat', 'data': { 'mode': 'ReplicationMode',
Quoted 8 lines
qapi/block-core.json line 2677
Quoted 4 lines
qapi/block-core.json +3
-1- '*top-id': 'str' } } + '*top-id': 'str', + '*shared-disk-id': 'str', + '*shared-disk': 'bool' } }Do we need a separate bool and string? Or is it sufficient to say that if shared-disk is omitted, we are not sharing, and that if a shared-disk string is present, then we are sharing and it names the id of the shared disk.
Er, Yes, We need both of them, the command line of secondary sides is like:
-drive if=virtio,id=active-disk0,driver=replication,mode=secondary,\
file.driver=qcow2,top-id=active-disk0,\
file.file.filename=/mnt/ramfs/active_disk.img,\
file.backing=hidden_disk0,shared-disk=on
We only need the bool shared-disk to indicate whether disk is sharing or not, but
for primary side, we need to the blockdev-add command to tell primary which disk is shared.
{ 'execute': 'blockdev-add',
'arguments': {
'driver': 'replication',
'node-name': 'rep',
'mode': 'primary',
'shared-disk-id': 'primary_disk0',
'shared-disk': true,
'file': {
'driver': 'nbd',
'export': 'hidden_disk0',
'server': {
'type': 'inet',
'data': {
'host': 'xxx.xxx.xxx.xxx',
'port': 'yyy'
}
}
}
}}
Re: [Qemu-devel] [PATCH v4 2/6] replication: add shared-disk and shared-disk-id options
In reply to zhanghailiangQuoted 70 lines · zhanghailiang
We use these two options to identify which disk is shared
Signed-off-by zhanghailiang <[email protected]>Signed-off-by Wen Congyang <[email protected]>Signed-off-by Zhang Chen <[email protected]>---
v4:
- Add proper comment forprimary_disk(Stefan)
v2:
- Moveg_free(s->shared_disk_id)to the common fail process place (Stefan)
- Fix comments for these two options--- block/replication.c | 43 +++++++++++++++++++++++++++++++++++++++++-- qapi/block-core.json | 10 +++++++++- 2 files changed, 50 insertions(+), 3 deletions(-)block/replication.c +17
-0@@ -25,9 +25,12 @@ typedef struct BDRVReplicationState { ReplicationMode mode; int replication_state; + bool is_shared_disk; + char *shared_disk_id; BdrvChild *active_disk; BdrvChild *hidden_disk; BdrvChild *secondary_disk; + BdrvChild *primary_disk; char *top_id; ReplicationState *rs; Error *blocker;@@ -53,6 +56,9 @@ static void replication_stop(ReplicationState *rs, bool failover,#define REPLICATION_MODE "mode"#define REPLICATION_TOP_ID "top-id" +#define REPLICATION_SHARED_DISK "shared-disk" +#define REPLICATION_SHARED_DISK_ID "shared-disk-id" +static QemuOptsList replication_runtime_opts = { .name ="replication" , .head =QTAILQ_HEAD_INITIALIZER (replication_runtime_opts.head),@@ -65,6 +71,14 @@ static QemuOptsList replication_runtime_opts = { .name = REPLICATION_TOP_ID, .type = QEMU_OPT_STRING, }, + { + .name = REPLICATION_SHARED_DISK_ID, + .type = QEMU_OPT_STRING, + }, + { + .name = REPLICATION_SHARED_DISK, + .type = QEMU_OPT_BOOL, + }, {/* end of list */ } }, };@@ -85,6 +99,9 @@ static int replication_open(BlockDriverState *bs, QDict *options,QemuOpts *opts =NULL ;const char *mode;const char *top_id; +const char *shared_disk_id; +BlockBackend *blk; +BlockDriverState *tmp_bs; bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file, false, errp);
block/replication.c static int replication_open(BlockDriverState *bs, QDict *options, · line 146
Quoted 5 lines
block/replication.c +2
-0@@ -125,12 +142,33 @@ static int replication_open(BlockDriverState *bs, QDict *options, "The option mode's value should be primary or secondary"); goto fail; } + s->is_shared_disk = qemu_opt_get_bool(opts, REPLICATION_SHARED_DISK, +
What If secondary side is supplied with 'REPLICATION_SHARED_DISK_ID'? Pls refer f4f2539bc to pefect the logical.
Quoted 44 lines
block/replication.c +22
-2false); +if (s->is_shared_disk && (s->mode ==REPLICATION_MODE_PRIMARY )) { + shared_disk_id =qemu_opt_get (opts,REPLICATION_SHARED_DISK_ID ); +if (!shared_disk_id) { +error_setg (&local_err,"Missing shared disk blk option" ); + goto fail; + } + s->shared_disk_id =g_strdup (shared_disk_id); + blk =blk_by_name (s->shared_disk_id); +if (!blk) { +error_setg (&local_err,"There is no %s block" , s->shared_disk_id); + goto fail; + } +/* We have a BlockBackend for the primary disk but use BdrvChild for +* consistency - active_disk, secondary_disk, etc are also BdrvChild. +*/ + tmp_bs =blk_bs (blk); + s->primary_disk =QLIST_FIRST (&tmp_bs->parents); + } s->rs =replication_new (bs, &replication_ops); - ret =0 ; - +qemu_opts_del (opts); +return 0 ; fail: +g_free (s->shared_disk_id);qemu_opts_del (opts);error_propagate (errp, local_err);@@ -141,6 +179,7 @@ static void replication_close(BlockDriverState *bs) {BDRVReplicationState *s = bs->opaque; +g_free (s->shared_disk_id);if (s->replication_state ==BLOCK_REPLICATION_RUNNING ) {replication_stop (s->rs, false,NULL ); }qapi/block-core.json +0
-0
qapi/block-core.json line 2666
Quoted 6 lines
qapi/block-core.json +3
-0@@ -2661,12 +2661,20 @@ # node who owns the replication node chain. Must not be given in # primary mode. # +# @shared-disk-id: Id of shared disk while is replication mode, if @shared-disk +# is true, this option is required (Since: 2.10) +#
Further explanations:
For @shared-disk-id, it must/only be given when @shared-disk enable on Primary side.
qapi/block-core.json line 2669
Quoted 3 lines
qapi/block-core.json +3
-0+# @shared-disk: To indicate whether or not a disk is shared by primary VM +# and secondary VM. (The default is false) (Since: 2.10) +#
Further explanations:
For @shared-disk, it must be given or not-given on both side at the same time.
Quoted 12 lines
qapi/block-core.json +3
-1# Since: 2.9 ## { 'struct': 'BlockdevOptionsReplication', 'base': 'BlockdevOptionsGenericFormat', 'data': { 'mode': 'ReplicationMode', - '*top-id': 'str' } } + '*top-id': 'str', + '*shared-disk-id': 'str', + '*shared-disk': 'bool' } } ## # @NFSTransport:
Re: [Qemu-devel] [PATCH v4 2/6] replication: add shared-disk and shared-disk-id options
Quoted 69 lines · Xie Changlong
Quoted 67 lines · zhanghailiang
We use these two options to identify which disk is shared
Signed-off-by zhanghailiang <[email protected]>Signed-off-by Wen Congyang <[email protected]>Signed-off-by Zhang Chen <[email protected]>---
v4:
- Add proper comment forprimary_disk(Stefan)
v2:
- Moveg_free(s->shared_disk_id)to the common fail process place (Stefan)
- Fix comments for these two options--- block/replication.c | 43 +++++++++++++++++++++++++++++++++++++++++-- qapi/block-core.json | 10 +++++++++- 2 files changed, 50 insertions(+), 3 deletions(-)block/replication.c +17
-0@@ -25,9 +25,12 @@ typedef struct BDRVReplicationState { ReplicationMode mode; int replication_state; + bool is_shared_disk; + char *shared_disk_id; BdrvChild *active_disk; BdrvChild *hidden_disk; BdrvChild *secondary_disk; + BdrvChild *primary_disk; char *top_id; ReplicationState *rs; Error *blocker;@@ -53,6 +56,9 @@ static void replication_stop(ReplicationState *rs, bool failover,#define REPLICATION_MODE "mode"#define REPLICATION_TOP_ID "top-id" +#define REPLICATION_SHARED_DISK "shared-disk" +#define REPLICATION_SHARED_DISK_ID "shared-disk-id" +static QemuOptsList replication_runtime_opts = { .name ="replication" , .head =QTAILQ_HEAD_INITIALIZER (replication_runtime_opts.head),@@ -65,6 +71,14 @@ static QemuOptsList replication_runtime_opts = { .name = REPLICATION_TOP_ID, .type = QEMU_OPT_STRING, }, + { + .name = REPLICATION_SHARED_DISK_ID, + .type = QEMU_OPT_STRING, + }, + { + .name = REPLICATION_SHARED_DISK, + .type = QEMU_OPT_BOOL, + }, {/* end of list */ } }, };@@ -85,6 +99,9 @@ static int replication_open(BlockDriverState *bs, QDict *options,QemuOpts *opts =NULL ;const char *mode;const char *top_id; +const char *shared_disk_id; +BlockBackend *blk; +BlockDriverState *tmp_bs;
Quoted 10 lines
block/replication.c static int replication_open(BlockDriverState *bs, QDict *options, · line 146
Quoted 8 lines
block/replication.c +2
-0bs->file =bdrv_open_child (NULL , options,"file" , bs, &child_file, false, errp);@@ -125,12 +142,33 @@ static int replication_open(BlockDriverState *bs, QDict *options, "The option mode's value should be primary or secondary"); goto fail; } + s->is_shared_disk = qemu_opt_get_bool(opts, REPLICATION_SHARED_DISK, +What If secondary side is supplied with '
REPLICATION_SHARED_DISK_ID'? Pls referf4f2539bcto pefect the logical.
Hmm, we should not configure it for secondary side, i'll fix it in next version.
Quoted 52 lines
Quoted 44 lines
block/replication.c +22
-2false); +if (s->is_shared_disk && (s->mode ==REPLICATION_MODE_PRIMARY )) { + shared_disk_id =qemu_opt_get (opts,REPLICATION_SHARED_DISK_ID ); +if (!shared_disk_id) { +error_setg (&local_err,"Missing shared disk blk option" ); + goto fail; + } + s->shared_disk_id =g_strdup (shared_disk_id); + blk =blk_by_name (s->shared_disk_id); +if (!blk) { +error_setg (&local_err,"There is no %s block" , s->shared_disk_id); + goto fail; + } +/* We have a BlockBackend for the primary disk but use BdrvChild for +* consistency - active_disk, secondary_disk, etc are also BdrvChild. +*/ + tmp_bs =blk_bs (blk); + s->primary_disk =QLIST_FIRST (&tmp_bs->parents); + } s->rs =replication_new (bs, &replication_ops); - ret =0 ; - +qemu_opts_del (opts); +return 0 ; fail: +g_free (s->shared_disk_id);qemu_opts_del (opts);error_propagate (errp, local_err);@@ -141,6 +179,7 @@ static void replication_close(BlockDriverState *bs) {BDRVReplicationState *s = bs->opaque; +g_free (s->shared_disk_id);if (s->replication_state ==BLOCK_REPLICATION_RUNNING ) {replication_stop (s->rs, false,NULL ); }qapi/block-core.json +0
-0qapi/block-core.json line 2666
Quoted 6 lines
qapi/block-core.json +3
-0@@ -2661,12 +2661,20 @@ # node who owns the replication node chain. Must not be given in # primary mode. # +# @shared-disk-id: Id of shared disk while is replication mode, if @shared-disk +# is true, this option is required (Since: 2.10) +#Further explanations:
Quoted 2 lines
For @shared-disk-id, it must/only be given when @shared-disk enable on Primary side.
OK.
Quoted 7 lines
qapi/block-core.json line 2669
Quoted 3 lines
qapi/block-core.json +3
-0+# @shared-disk: To indicate whether or not a disk is shared by primary VM +# and secondary VM. (The default is false) (Since: 2.10) +#Further explanations:
For @shared-disk, it must be given or not-given on both side at the same time.
OK, will fix it, thanks.
Quoted 17 lines
qapi/block-core.json line 2680
Quoted 12 lines
qapi/block-core.json +3
-1# Since: 2.9 ## { 'struct': 'BlockdevOptionsReplication', 'base': 'BlockdevOptionsGenericFormat', 'data': { 'mode': 'ReplicationMode', - '*top-id': 'str' } } + '*top-id': 'str', + '*shared-disk-id': 'str', + '*shared-disk': 'bool' } } ## # @NFSTransport:.
Re: [Qemu-devel] [Qemu-block] [PATCH v4 2/6] replication: add shared-disk and shared-disk-id options
In reply to zhanghailiangQuoted 12 lines · zhanghailiang
We use these two options to identify which disk is shared
Signed-off-by zhanghailiang <[email protected]>Signed-off-by Wen Congyang <[email protected]>Signed-off-by Zhang Chen <[email protected]>---
v4:
- Add proper comment forprimary_disk(Stefan)
v2:
- Moveg_free(s->shared_disk_id)to the common fail process place (Stefan)
- Fix comments for these two options
Quoted 4 lines
--- block/replication.c | 43 +++++++++++++++++++++++++++++++++++++++++-- qapi/block-core.json | 10 +++++++++- 2 files changed, 50 insertions(+), 3 deletions(-)
Aside from the ongoing discussion about this patch...
Re: [Qemu-devel] [Qemu-block] [PATCH v4 2/6] replication: add shared-disk and shared-disk-id options
Quoted 17 lines · Stefan Hajnoczi
Quoted 12 lines · zhanghailiang
We use these two options to identify which disk is shared
Signed-off-by zhanghailiang <[email protected]>Signed-off-by Wen Congyang <[email protected]>Signed-off-by Zhang Chen <[email protected]>---
v4:
- Add proper comment forprimary_disk(Stefan)
v2:
- Moveg_free(s->shared_disk_id)to the common fail process place (Stefan)
- Fix comments for these two optionsQuoted 4 lines
--- block/replication.c | 43 +++++++++++++++++++++++++++++++++++++++++-- qapi/block-core.json | 10 +++++++++- 2 files changed, 50 insertions(+), 3 deletions(-)
Quoted 3 lines
Aside from the ongoing discussion about this patch...
Reviewed-by Stefan Hajnoczi <[email protected]>
Thanks, I'll fix the related problems found by changlong.
PATCH v4 3/6 replication: Split out backup_do_checkpoint() from secondary_do_checkpoint()
In reply to zhanghailiangThe helper backup_do_checkpoint() will be used for primary related codes. Here we split it out from secondary_do_checkpoint().
Besides, it is unnecessary to call backup_do_checkpoint() in replication starting and normally stop replication path. We only need call it while do real checkpointing.
--- block/replication.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-)
block/replication.c +19 -17
@@ -352,20 +352,8 @@ static bool replication_recurse_is_first_non_filter(BlockDriverState *bs,static void secondary_do_checkpoint (BDRVReplicationState *s,Error **errp) { -Error *local_err =NULL ;int ret; -if (!s->secondary_disk->bs->job) { -error_setg (errp,"Backup job was cancelled unexpectedly" ); -return ; - } - -backup_do_checkpoint (s->secondary_disk->bs->job, &local_err); -if (local_err) { -error_propagate (errp, local_err); -return ; - } - ret = s->active_disk->bs->drv->bdrv_make_empty (s->active_disk->bs);if (ret <0 ) {error_setg (errp,"Cannot make active disk empty" );
@@ -578,6 +566,8 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode,return ; }block_job_start (job); + +secondary_do_checkpoint (s, errp);break ;default :aio_context_release (aio_context);
@@ -586,10 +576,6 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode, s->replication_state =BLOCK_REPLICATION_RUNNING ; -if (s->mode ==REPLICATION_MODE_SECONDARY ) { -secondary_do_checkpoint (s, errp); - } - s->error =0 ;aio_context_release (aio_context); }
@@ -599,13 +585,29 @@ static void replication_do_checkpoint(ReplicationState *rs, Error **errp)BlockDriverState *bs = rs->opaque;BDRVReplicationState *s;AioContext *aio_context; +Error *local_err =NULL ; aio_context =bdrv_get_aio_context (bs);aio_context_acquire (aio_context); s = bs->opaque; -if (s->mode ==REPLICATION_MODE_SECONDARY ) { +switch (s->mode) { +case REPLICATION_MODE_PRIMARY : +break ; +case REPLICATION_MODE_SECONDARY : +if (!s->secondary_disk->bs->job) { +error_setg (errp,"Backup job was cancelled unexpectedly" ); +break ; + } +backup_do_checkpoint (s->secondary_disk->bs->job, &local_err); +if (local_err) { +error_propagate (errp, local_err); +break ; + }secondary_do_checkpoint (s, errp); +break ; +default : +abort (); }aio_context_release (aio_context); }
Signature · 1 line
1.8.3.1
PATCH v4 4/6 replication: fix code logic with the new shared_disk option
In reply to zhanghailiangSome code logic only be needed in non-shared disk, here we adjust these codes to prepare for shared disk scenario.
--- block/replication.c | 73 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 32 deletions(-)
block/replication.c +41 -32
@@ -539,33 +539,40 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode,return ; } -/* start backup job now */ -error_setg (&s->blocker, -"Block device is in use by internal backup job" ); - - top_bs =bdrv_lookup_bs (s->top_id, s->top_id,NULL ); -if (!top_bs || !bdrv_is_root_node (top_bs) || - !check_top_bs (top_bs, bs)) { -error_setg (errp,"No top_bs or it is invalid" ); -reopen_backing_file (bs, false,NULL ); -aio_context_release (aio_context); -return ; - } -bdrv_op_block_all (top_bs, s->blocker); -bdrv_op_unblock (top_bs,BLOCK_OP_TYPE_DATAPLANE , s->blocker); - - job =backup_job_create (NULL , s->secondary_disk->bs, s->hidden_disk->bs, -0 ,MIRROR_SYNC_MODE_NONE ,NULL , false, +/* +* Only in the case of non-shared disk, +* the backup job is in the secondary side +*/ +if (!s->is_shared_disk) { +/* start backup job now */ +error_setg (&s->blocker, +"Block device is in use by internal backup job" ); + + top_bs =bdrv_lookup_bs (s->top_id, s->top_id,NULL ); +if (!top_bs || !bdrv_is_root_node (top_bs) || + !check_top_bs (top_bs, bs)) { +error_setg (errp,"No top_bs or it is invalid" ); +reopen_backing_file (bs, false,NULL ); +aio_context_release (aio_context); +return ; + } + +bdrv_op_block_all (top_bs, s->blocker); +bdrv_op_unblock (top_bs,BLOCK_OP_TYPE_DATAPLANE , s->blocker); + job =backup_job_create (NULL , s->secondary_disk->bs, + s->hidden_disk->bs,0 , +MIRROR_SYNC_MODE_NONE ,NULL , false,BLOCKDEV_ON_ERROR_REPORT ,BLOCKDEV_ON_ERROR_REPORT ,BLOCK_JOB_INTERNAL , backup_job_completed, bs,NULL , &local_err); -if (local_err) { -error_propagate (errp, local_err); -backup_job_cleanup (bs); -aio_context_release (aio_context); -return ; +if (local_err) { +error_propagate (errp, local_err); +backup_job_cleanup (bs); +aio_context_release (aio_context); +return ; + } +block_job_start (job); } -block_job_start (job);secondary_do_checkpoint (s, errp);break ;
@@ -595,14 +602,16 @@ static void replication_do_checkpoint(ReplicationState *rs, Error **errp)case REPLICATION_MODE_PRIMARY :break ;case REPLICATION_MODE_SECONDARY : -if (!s->secondary_disk->bs->job) { -error_setg (errp,"Backup job was cancelled unexpectedly" ); -break ; - } -backup_do_checkpoint (s->secondary_disk->bs->job, &local_err); -if (local_err) { -error_propagate (errp, local_err); -break ; +if (!s->is_shared_disk) { +if (!s->secondary_disk->bs->job) { +error_setg (errp,"Backup job was cancelled unexpectedly" ); +break ; + } +backup_do_checkpoint (s->secondary_disk->bs->job, &local_err); +if (local_err) { +error_propagate (errp, local_err); +break ; + } }secondary_do_checkpoint (s, errp);break ;
@@ -683,7 +692,7 @@ static void replication_stop(ReplicationState *rs, bool failover, Error **errp)* before the BDS is closed, because we will access hidden * disk, secondary disk in backup_job_completed(). */ -if (s->secondary_disk->bs->job) { +if (!s->is_shared_disk && s->secondary_disk->bs->job) {block_job_cancel_sync (s->secondary_disk->bs->job); }
Signature · 1 line
1.8.3.1
PATCH v4 5/6 replication: Implement block replication for shared disk case
In reply to zhanghailiangJust as the scenario of non-shared disk block replication, we are going to implement block replication from many basic blocks that are already in QEMU.
The architecture is:
virtio-blk || .----------
/ || | Secondary
/ || '----------
/ || virtio-blk
/ || |
| || replication(5)
| NBD --------> NBD (2) |
| client || server ---> hidden disk <-- active disk(4)
| ^ || |
| replication(1) || |
| | || |
| +-----------------' || |
(3) |drive-backup sync=none || |
--------. | +-----------------+ || |
Primary | | | || backing |
--------' | | || |
V | |
+-------------------------------------------+ |
| shared disk | <----------+
+-------------------------------------------+ 1) Primary writes will read original data and forward it to Secondary QEMU.
2) 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.
3) Primary write requests will be written to Shared disk.
4) Secondary write requests will be buffered in the active disk and it will overwrite the existing sector content in the buffer.
---
v4:
- Call bdrv_invalidate_cache() while do checkpoint for shared disk
--- block/replication.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 6 deletions(-)
block/replication.c +52 -6
@@ -253,7 +253,7 @@ static coroutine_fn int replication_co_readv(BlockDriverState *bs, QEMUIOVector *qiov) {BDRVReplicationState *s = bs->opaque; -BdrvChild *child = s->secondary_disk; +BdrvChild *child = s->is_shared_disk ? s->primary_disk : s->secondary_disk;BlockJob *job =NULL ;CowRequest req;int ret;
@@ -435,7 +435,12 @@ static void backup_job_completed(void *opaque, int ret) s->error = -EIO ; } -backup_job_cleanup (bs); +if (s->mode ==REPLICATION_MODE_PRIMARY ) { + s->replication_state =BLOCK_REPLICATION_DONE ; + s->error =0 ; + }else { +backup_job_cleanup (bs); + } }static bool check_top_bs (BlockDriverState *top_bs,BlockDriverState *bs)
@@ -487,6 +492,19 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode,switch (s->mode) {case REPLICATION_MODE_PRIMARY : +if (s->is_shared_disk) { + job =backup_job_create (NULL , s->primary_disk->bs, bs,0 , +MIRROR_SYNC_MODE_NONE ,NULL , false,BLOCKDEV_ON_ERROR_REPORT , +BLOCKDEV_ON_ERROR_REPORT ,BLOCK_JOB_INTERNAL , + backup_job_completed, bs,NULL , &local_err); +if (local_err) { +error_propagate (errp, local_err); +backup_job_cleanup (bs); +aio_context_release (aio_context); +return ; + } +block_job_start (job); + }break ;case REPLICATION_MODE_SECONDARY : s->active_disk = bs->file;
@@ -505,7 +523,8 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode, } s->secondary_disk = s->hidden_disk->bs->backing; -if (!s->secondary_disk->bs || !bdrv_has_blk (s->secondary_disk->bs)) { +if (!s->secondary_disk->bs || + (!s->is_shared_disk && !bdrv_has_blk (s->secondary_disk->bs))) {error_setg (errp,"The secondary disk doesn't have block backend" );aio_context_release (aio_context);return ;
@@ -600,11 +619,24 @@ static void replication_do_checkpoint(ReplicationState *rs, Error **errp)switch (s->mode) {case REPLICATION_MODE_PRIMARY : +if (s->is_shared_disk) { +if (!s->primary_disk->bs->job) { +error_setg (errp,"Primary backup job was cancelled" +" unexpectedly" ); +break ; + } + +backup_do_checkpoint (s->primary_disk->bs->job, &local_err); +if (local_err) { +error_propagate (errp, local_err); + } + }break ;case REPLICATION_MODE_SECONDARY :if (!s->is_shared_disk) {if (!s->secondary_disk->bs->job) { -error_setg (errp,"Backup job was cancelled unexpectedly" ); +error_setg (errp,"Secondary backup job was cancelled" +" unexpectedly" );break ; }backup_do_checkpoint (s->secondary_disk->bs->job, &local_err);
@@ -612,6 +644,16 @@ static void replication_do_checkpoint(ReplicationState *rs, Error **errp)error_propagate (errp, local_err);break ; } + }else { +/* +* For shared disk, we need to force SVM to re-read metadata +* that is loaded in memory, or there will be inconsistent. +*/ +bdrv_invalidate_cache (s->secondary_disk->bs, &local_err); +if (local_err) { +error_propagate (errp, local_err); +break ; + } }secondary_do_checkpoint (s, errp);break ;
@@ -683,8 +725,12 @@ static void replication_stop(ReplicationState *rs, bool failover, Error **errp)switch (s->mode) {case REPLICATION_MODE_PRIMARY : - s->replication_state =BLOCK_REPLICATION_DONE ; - s->error =0 ; +if (s->is_shared_disk && s->primary_disk->bs->job) { +block_job_cancel (s->primary_disk->bs->job); + }else { + s->replication_state =BLOCK_REPLICATION_DONE ; + s->error =0 ; + }break ;case REPLICATION_MODE_SECONDARY :/*
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v4 5/6] replication: Implement block replication for shared disk case
block/replication.c static void replication_do_checkpoint(ReplicationState *rs, Error **errp) · line 652
Quoted 10 lines · zhanghailiang
block/replication.c +6
-0@@ -612,6 +644,16 @@ static void replication_do_checkpoint(ReplicationState *rs, Error **errp)error_propagate (errp, local_err);break ; } + }else { +/* +* For shared disk, we need to force SVM to re-read metadata +* that is loaded in memory, or there will be inconsistent. +*/ +bdrv_invalidate_cache (s->secondary_disk->bs, &local_err);
I'm not sure this call has any effect:
if (!(bs->open_flags & BDRV_O_INACTIVE)) {
return;
}Is BDRV_O_INACTIVE set?
Re: [Qemu-devel] [PATCH v4 5/6] replication: Implement block replication for shared disk case
Quoted 13 lines · Stefan Hajnoczi
block/replication.c static void replication_do_checkpoint(ReplicationState *rs, Error **errp) · line 652
Quoted 10 lines · zhanghailiang
block/replication.c +6
-0@@ -612,6 +644,16 @@ static void replication_do_checkpoint(ReplicationState *rs, Error **errp)error_propagate (errp, local_err);break ; } + }else { +/* +* For shared disk, we need to force SVM to re-read metadata +* that is loaded in memory, or there will be inconsistent. +*/ +bdrv_invalidate_cache (s->secondary_disk->bs, &local_err);I'm not sure this call has any effect:
Quoted 5 lines
if (!(bs->open_flags & BDRV_O_INACTIVE)) { return; }Is
BDRV_O_INACTIVEset?
No, you are right, it does not take any effect. So should we set this flag for secondary_disk ? Is it enough to set this flag only, or should we call bdrv_inactivate_recurse() ? To be honest, i'm not quite familiar with this parts.
Thanks,
Hailiang
PATCH v4 6/6 nbd/replication: implement .bdrv_get_info() for nbd and replication driver
In reply to zhanghailiangWithout this callback, there will be an error reports in the primary side:
"qemu-system-x86_64: Couldn't determine the cluster size of the target image, which has no backing file: Operation not supported
Aborting, since this may create an unusable destination image"
For nbd driver, it doesn't have cluster size, so here we return a fake value for it.
This patch should be dropped if Eric's nbd patch be merged.
https://lists.gnu.org/archive/html/qemu-block/2017-02/msg00825.html
'[PATCH v4 7/8] nbd: Implement NBD_INFO_BLOCK_SIZE on server'.
--- block/nbd.c | 12 ++++++++++++ block/replication.c | 6 ++++++ 2 files changed, 18 insertions(+)
block/nbd.c +12 -0
@@ -43,6 +43,8 @@#define EN_OPTSTR ":exportname=" +#define NBD_FAKE_CLUSTER_SIZE 512 + typedef struct BDRVNBDState { NBDClientSession client;
@@ -561,6 +563,13 @@ static void nbd_refresh_filename(BlockDriverState *bs, QDict *options) bs->full_open_options = opts; } +static int nbd_get_info (BlockDriverState *bs,BlockDriverInfo *bdi) +{ + bdi->cluster_size =NBD_FAKE_CLUSTER_SIZE ; + +return 0 ; +} +static BlockDriver bdrv_nbd = { .format_name ="nbd" , .protocol_name ="nbd" ,
@@ -578,6 +587,7 @@ static BlockDriver bdrv_nbd = { .bdrv_detach_aio_context = nbd_detach_aio_context, .bdrv_attach_aio_context = nbd_attach_aio_context, .bdrv_refresh_filename = nbd_refresh_filename, + .bdrv_get_info = nbd_get_info, };static BlockDriver bdrv_nbd_tcp = {
@@ -597,6 +607,7 @@ static BlockDriver bdrv_nbd_tcp = { .bdrv_detach_aio_context = nbd_detach_aio_context, .bdrv_attach_aio_context = nbd_attach_aio_context, .bdrv_refresh_filename = nbd_refresh_filename, + .bdrv_get_info = nbd_get_info, };static BlockDriver bdrv_nbd_unix = {
@@ -616,6 +627,7 @@ static BlockDriver bdrv_nbd_unix = { .bdrv_detach_aio_context = nbd_detach_aio_context, .bdrv_attach_aio_context = nbd_attach_aio_context, .bdrv_refresh_filename = nbd_refresh_filename, + .bdrv_get_info = nbd_get_info, };static void bdrv_nbd_init (void )
block/replication.c +6 -0
@@ -761,6 +761,11 @@ static void replication_stop(ReplicationState *rs, bool failover, Error **errp)aio_context_release (aio_context); } +static int replication_get_info (BlockDriverState *bs,BlockDriverInfo *bdi) +{ +return bdrv_get_info (bs->file->bs, bdi); +} +BlockDriver bdrv_replication = { .format_name ="replication" , .protocol_name ="replication" ,
@@ -774,6 +779,7 @@ BlockDriver bdrv_replication = { .bdrv_co_readv = replication_co_readv, .bdrv_co_writev = replication_co_writev, + .bdrv_get_info = replication_get_info, .is_filter = true, .bdrv_recurse_is_first_non_filter = replication_recurse_is_first_non_filter,
Signature · 1 line
1.8.3.1
Quoted 7 lines · zhanghailiang
COLO block replication doesn't support the shared disk case, Here we try to implement it and this is the 4th version.
Please review and any commits are welcomed.
Cc Dr. David Alan Gilbert (git) <[email protected]>
Sorry for the delay. Feel free to ping me if I don't review within a few days when you post a patch.
Quoted 32 lines
v4:
- Add proper comment forprimary_diskin patch 2 (Stefan)
- Callbdrv_invalidate_cache()while do checkpoint for shared disk in patch 5v3:
- Fix some comments from Stefan and Ericv2:
- Drop the patch which add ablk_root()helper
- Fix some comments from Changlongzhanghailiang (6):
docs/block-replication: Add description for shared-disk case
replication: add shared-disk and shared-disk-id options
replication: Split outbackup_do_checkpoint()from
secondary_do_checkpoint()
replication: fix code logic with the newshared_diskoption
replication: Implement block replication for shared disk case nbd/replication: implement .bdrv_get_info() for nbd and replication
driverblock/nbd.c | 12 +++ block/replication.c | 198 ++++++++++++++++++++++++++++++++++----------- docs/block-replication.txt | 139 ++++++++++++++++++++++++++++++- qapi/block-core.json | 10 ++- 4 files changed, 306 insertions(+), 53 deletions(-)Signature · 1 line
1.8.3.1
Quoted 10 lines · Stefan Hajnoczi
Quoted 7 lines · zhanghailiang
COLO block replication doesn't support the shared disk case, Here we try to implement it and this is the 4th version.
Please review and any commits are welcomed.
Cc Dr. David Alan Gilbert (git) <[email protected]>Sorry for the delay. Feel free to ping me if I don't review within a few days when you post a patch.
That is OK. :) , I was doing other things these days, and it is not quite urgent ... thanks.
Quoted 32 lines
Quoted 32 lines
v4:
- Add proper comment forprimary_diskin patch 2 (Stefan)
- Callbdrv_invalidate_cache()while do checkpoint for shared disk in patch 5v3:
- Fix some comments from Stefan and Ericv2:
- Drop the patch which add ablk_root()helper
- Fix some comments from Changlongzhanghailiang (6):
docs/block-replication: Add description for shared-disk case
replication: add shared-disk and shared-disk-id options
replication: Split outbackup_do_checkpoint()from
secondary_do_checkpoint()
replication: fix code logic with the newshared_diskoption
replication: Implement block replication for shared disk case nbd/replication: implement .bdrv_get_info() for nbd and replication
driverblock/nbd.c | 12 +++ block/replication.c | 198 ++++++++++++++++++++++++++++++++++----------- docs/block-replication.txt | 139 ++++++++++++++++++++++++++++++- qapi/block-core.json | 10 ++- 4 files changed, 306 insertions(+), 53 deletions(-)Signature · 1 line
1.8.3.1
HI, Hai Liang
Is there recently any plan to post libvirt support for COLO feature?
Regards,
Zhi Yong Wu
Quoted 40 lines · zhanghailiang
COLO block replication doesn't support the shared disk case, Here we try to implement it and this is the 4th version.
Please review and any commits are welcomed.
Cc Dr. David Alan Gilbert (git) <[email protected]>v4:
- Add proper comment forprimary_diskin patch 2 (Stefan)
- Callbdrv_invalidate_cache()while do checkpoint for shared disk in patch 5v3:
- Fix some comments from Stefan and Ericv2:
- Drop the patch which add ablk_root()helper
- Fix some comments from Changlongzhanghailiang (6):
docs/block-replication: Add description for shared-disk case
replication: add shared-disk and shared-disk-id options
replication: Split outbackup_do_checkpoint()from
secondary_do_checkpoint()
replication: fix code logic with the newshared_diskoption
replication: Implement block replication for shared disk case nbd/replication: implement .bdrv_get_info() for nbd and replication
driverblock/nbd.c | 12 +++ block/replication.c | 198 ++++++++++++++++++++++++++++++++++----------- docs/block-replication.txt | 139 ++++++++++++++++++++++++++++++- qapi/block-core.json | 10 ++- 4 files changed, 306 insertions(+), 53 deletions(-)Signature · 1 line
1.8.3.1