COLO block replication doesn't support the shared disk case, Here we try to implement it.
Just 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 will 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 buffe For more details, please refer to patch 1. The complete codes can be found from the link: https://github.com/coloft/qemu/tree/colo-v5.1-developing-COLO-frame-v21-with-shared-disk Test steps: 1. Secondary: # x86_64-softmmu/qemu-system-x86_64 -boot c -m 2048 -smp 2 -qmp stdio -vnc :9 -name secondary -enable-kvm -cpu qemu64,+kvmclock -device piix3-usb-uhci -drive if=none,driver=qcow2,file.filename=/mnt/ramfs/hidden_disk.img,id=hidden_disk0,backing.driver=raw,backing.file.filename=/work/kvm/suse11_sp3_64 -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 -incoming tcp:0:9999 Issue qmp commands: {'execute':'qmp_capabilities'} {'execute': 'nbd-server-start', 'arguments': {'addr': {'type': 'inet', 'data': {'host': '0', 'port': '9998'} } } } {'execute': 'nbd-server-add', 'arguments': {'device': 'hidden_disk0', 'writable': true } } 2.Primary: # x86_64-softmmu/qemu-system-x86_64 -enable-kvm -m 2048 -smp 2 -qmp stdio -vnc :9 -name primary -cpu qemu64,+kvmclock -device piix3-usb-uhci -drive if=virtio,id=primary_disk0,file.filename=/work/kvm/suse11_sp3_64,driver=raw -S Issue qmp commands: {'execute':'qmp_capabilities'} {'execute': 'human-monitor-command', 'arguments': {'command-line': 'drive_add -n buddy driver=replication,mode=primary,file.driver=nbd,file.host=9.42.3.17,file.port=9998,file.export=hidden_disk0,shared-disk-id=primary_disk0,shared-disk=on,node-name=rep'}} {'execute': 'migrate-set-capabilities', 'arguments': {'capabilities': [ {'capability': 'x-colo', 'state': true } ] } } {'execute': 'migrate', 'arguments': {'uri': 'tcp:9.42.3.17:9999' } } 3. Failover Secondary side: Issue qmp commands: { 'execute': 'nbd-server-stop' } { "execute": "x-colo-lost-heartbeat" } Please review and any commits are welcomed. Cc: Juan Quintela <quint...@redhat.com> Cc: Amit Shah <amit.s...@redhat.com> Cc: Dr. David Alan Gilbert (git) <dgilb...@redhat.com> zhanghailiang (7): docs/block-replication: Add description for shared-disk case block-backend: Introduce blk_root() helper 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/block-backend.c | 5 ++ block/nbd.c | 12 ++++ block/replication.c | 146 +++++++++++++++++++++++++++++++---------- docs/block-replication.txt | 131 ++++++++++++++++++++++++++++++++++-- include/sysemu/block-backend.h | 1 + 5 files changed, 258 insertions(+), 37 deletions(-) -- 1.8.3.1