COarse-grain LOck-stepping(COLO) Virtual Machines for Non-stop Service (FT)
v10 cover COarse-grain LOck-stepping(COLO) Virtual Machines for Non-stop Service (FT)
This is the 10th version of COLO.
Still, this version of COLO is only support periodic checkpoint, just like MicroCheckpointing and Remus does. We call it 'periodic' mode, the normal 'colo' mode is based on packets compare module, which is not supported for now. The compare module 'proxy' is in the process of development.
The 'peroidic' mode is based on netfilter which has been merged. It uses the 'filter-buffer' to buffer and release packets. Patch 32 ~ Patch 36 export several APIs for netfilter to support this capability.
As usual, here is only COLO frame part, you can get the whole codes from github:
https://github.com/coloft/qemu/commits/colo-v2.1-periodic-mode
Test procedure:
1. Startup qemu
Primary side:
#x86_64-softmmu/qemu-system-x86_64 -enable-kvm -netdev tap,id=hn0,script=/etc/qemu-ifup,downscript=/etc/qemu-ifdown -device virtio-net-pci,id=net-pci0,netdev=hn0,mac=52:54:00:12:34:66 -boot c -drive if=virtio,id=colo-disk1,driver=quorum,read-pattern=fifo,vote-threshold=1,children.0.file.filename=/mnt/sdd/pure_IMG/linux/redhat/rhel_6.5_64_2U_ide,children.0.driver=raw -vnc :7 -m 2048 -smp 2 -device piix3-usb-uhci -device usb-tablet -monitor stdio -S
Secondary side:
#x86_64-softmmu/qemu-system-x86_64 -enable-kvm -netdev tap,id=hn0,script=/etc/qemu-ifup,downscript=/etc/qemu-ifdown -device virtio-net-pci,id=net-pci0,netdev=hn0,mac=52:54:00:12:34:66 -boot c -drive if=none,id=colo-disk1,file.filename=/dev/null,driver=raw -drive if=virtio,id=active-disk1,throttling.bps-total=70000000,driver=replication,mode=secondary,file.driver=qcow2,file.file.filename=/mnt/ramfs/active_disk.img,file.backing.allow-write-backing-file=on,file.backing.driver=qcow2,file.backing.file.filename=/mnt/ramfs/hidden_disk.img,file.backing.backing.allow-write-backing-file=on,file.backing.backing.file.filename=/mnt/sdd/pure_IMG/linux/redhat/rhel_6.5_64_2U_ide,file.backing.backing.driver=raw,file.backing.backing.node-name=sdisk -vnc :7 -m 2048 -smp 2 -device piix3-usb-uhci -device usb-tablet -monitor stdio -incoming tcp:0:8881
2. On Secondary VM's QEMU monitor, issue command
(qemu) blockdev_remove_medium colo-disk1
(qemu) blockdev_insert_medium colo-disk1 sdisk
(qemu) nbd_server_start 192.168.2.88:8880
(qemu) nbd_server_add -w colo-disk1
3. On Primary VM's QEMU monitor, issue command:
(qemu) drive_add buddy driver=replication,mode=primary,file.driver=nbd,file.host=192.168.2.88,file.port=8880,file.export=colo-disk1,node-name=test3,if=none (qemu) blockdev_change add colo-disk1 buddy test3
(qemu) migrate_set_capability x-colo on
(qemu) migrate tcp:192.168.2.88:8881
4. After the above steps, you will see, whenever you make changes to PVM, SVM will be synced. You can by issue command "migrate_set_parameter checkpoint-delay 2000"
to change the checkpoint period time.
5. Failover test
You can kill Primary VM and run 'x_colo_lost_heartbeat' in Secondary VM's monitor at the same time, then SVM will failover and client will not feel this change.
COLO is a totally new feature which is still in early stage, your comments and feedback are warmly welcomed.
TODO:
1. implement packets compare module (proxy) in qemu
2. checkpoint based on proxy in qemu
3. The capability of continuous FT
v10:
- Rename 'colo_lost_heartbeat' command to experimental 'x_colo_lost_heartbeat'
- Rename migration capability 'colo' to 'x-colo' (Eric's suggestion)
- Simplify the process of primary side by dropping colo thread and reusing migration thread. (Dave's suggestion)
- Add several netfilter related APIs to support buffer/release packets for COLO (patch 32 ~ patch 36)
zhanghailiang (38):
configure: Add parameter for configure to enable/disable COLO support
migration: Introduce capability 'x-colo' to migration
COLO: migrate colo related info to secondary node
migration: Add state records for migration incoming
migration: Integrate COLO checkpoint process into migration
migration: Integrate COLO checkpoint process into loadvm
migration: Rename the'file' member of MigrationState and
MigrationIncomingState
COLO/migration: establish a new communication path from destination to
source
COLO: Implement colo checkpoint protocol
COLO: Add a new RunState RUN_STATE_COLO
QEMUSizedBuffer: Introduce two help functions for qsb
COLO: Save PVM state to secondary side when do checkpoint
COLO: Load PVM's dirty pages into SVM's RAM cache temporarily
COLO: Load VMState into qsb before restore it
ram/COLO: Record pages received from PVM by re-using migration dirty
bitmap
COLO: Flush PVM's cached RAM into SVM's memory
COLO: synchronize PVM's state to SVM periodically
COLO failover: Introduce a new command to trigger a failover COLO failover: Introduce state to record failover process
COLO: Implement failover work for Primary VM
COLO: Implement failover work for Secondary VM
COLO: implement default failover treatment
qmp event: Add event notification for COLO error
COLO failover: Shutdown related socket fd when do failover COLO failover: Don't do failover during loading VM's state
COLO: Control the checkpoint delay time by migrate-set-parameters
command
COLO: Process shutdown command for VM in COLO state
COLO: Update the global runstate after going into colo state
savevm: Split load vm state function qemu_loadvm_state
COLO: Separate the process of saving/loading ram and device state
COLO: Split qemu_savevm_state_begin out of checkpoint process
netfilter: Add a public API to release all the buffered packets
netfilter: Introduce an API to delete the timer of all buffer-filters
filter-buffer: Accept zero interval
netfilter: Introduce a API to automatically add filter-buffer for each
netdev
netfilter: Introduce an API to delete all the automatically added
netfilters
colo: Use the netfilter to buffer and release packets
COLO: Add block replication into colo process
configure | 11 + docs/qmp-events.txt | 17 + hmp-commands.hx | 15 + hmp.c | 15 + hmp.h | 1 + include/exec/ram_addr.h | 1 + include/migration/colo.h | 44 +++ include/migration/failover.h | 33 ++ include/migration/migration.h | 17 +- include/migration/qemu-file.h | 3 +- include/net/filter.h | 5 + include/net/net.h | 7 + include/sysemu/sysemu.h | 8 + migration/Makefile.objs | 2 + migration/colo-comm.c | 71 ++++ migration/colo-failover.c | 83 +++++ migration/colo.c | 788 ++++++++++++++++++++++++++++++++++++++++++ migration/exec.c | 4 +- migration/fd.c | 4 +- migration/migration.c | 178 +++++++--- migration/qemu-file-buf.c | 58 ++++ migration/ram.c | 177 +++++++++- migration/savevm.c | 309 +++++++++++++---- migration/tcp.c | 4 +- migration/unix.c | 4 +- net/filter-buffer.c | 143 +++++++- net/filter.c | 15 + net/net.c | 44 +++ qapi-schema.json | 105 +++++- qapi/event.json | 17 + qmp-commands.hx | 22 +- stubs/Makefile.objs | 1 + stubs/migration-colo.c | 45 +++ trace-events | 9 + vl.c | 37 +- 35 files changed, 2130 insertions(+), 167 deletions(-) create mode 100644 include/migration/colo.h create mode 100644 include/migration/failover.h create mode 100644 migration/colo-comm.c create mode 100644 migration/colo-failover.c create mode 100644 migration/colo.c create mode 100644 stubs/migration-colo.c
Signature · 1 line
1.8.3.1
PATCH v10 1/38 configure: Add parameter for configure to enable/disable COLO support
configure --enable-colo/--disable-colo to switch COLO support on/off.
COLO support is off by default.
--- configure | 11 +++++++++++ 1 file changed, 11 insertions(+)
configure +11 -0
@@ -257,6 +257,7 @@ xfs="" vhost_net="no" vhost_scsi="no" kvm="no" +colo="no" rdma="" gprof="no" debug_tcg="no"
@@ -929,6 +930,10 @@ for opt do ;; --enable-kvm) kvm="yes" ;; + --disable-colo) colo="no" + ;; + --enable-colo) colo="yes" + ;; --disable-tcg-interpreter) tcg_interpreter="no" ;; --enable-tcg-interpreter) tcg_interpreter="yes"
@@ -1353,6 +1358,7 @@ disabled with --disable-FEATURE, default is enabled if available: fdt fdt device tree bluez bluez stack connectivity kvm KVM acceleration support + colo COarse-grain LOck-stepping VM for Non-stop Service rdma RDMA-based migration support uuid uuid support vde support for vde network
@@ -4732,6 +4738,7 @@ echo "Linux AIO support $linux_aio" echo "ATTR/XATTR support $attr" echo "Install blobs $blobs" echo "KVM support $kvm" +echo "COLO support $colo" echo "RDMA support $rdma" echo "TCG interpreter $tcg_interpreter" echo "fdt support $fdt"
@@ -5321,6 +5328,10 @@ if have_backend "ftrace"; then fi echo "CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak +if test "$colo" = "yes"; then + echo "CONFIG_COLO=y" >> $config_host_mak +fi + if test "$rdma" = "yes" ; then echo "CONFIG_RDMA=y" >> $config_host_mak fi
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH COLO-Frame v10 01/38] configure: Add parameter for configure to enable/disable COLO support
Quoted 3 lines · zhanghailiang
configure --enable-colo/--disable-colo to switch COLO support on/off.
COLO support is off by default.
Off by default risks bit-rot for people not building it; it's generally best to default to off only if the feature requires dragging in extra libraries or similar build items not likely to be present in all development environments (and even then, auto-probing for required prerequisites is nicer than hard-coding off). Would on-by-default be a saner choice, or would that drag in too many extra dependencies for building?
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH COLO-Frame v10 01/38] configure: Add parameter for configure to enable/disable COLO support
Hi Eric,
Quoted 5 lines · Eric Blake
Quoted 3 lines · zhanghailiang
configure --enable-colo/--disable-colo to switch COLO support on/off.
COLO support is off by default.
Quoted 8 lines
Off by default risks bit-rot for people not building it; it's generally best to default to off only if the feature requires dragging in extra libraries or similar build items not likely to be present in all development environments (and even then, auto-probing for required prerequisites is nicer than hard-coding off). Would on-by-default be a saner choice, or would that drag in too many extra dependencies for building?
In old version, which uses kernel proxy, we have to install relevant nfnetlink libraries.
For the new version, we have dropped kernel proxy, so it is OK to turn it On by default. I will fix it in next version :)
Thanks,
zhanghailiang
PATCH v10 2/38 migration: Introduce capability 'x-colo' to migration
In reply to zhanghailiangWe add helper function colo_supported() to indicate whether colo is supported or not, with which we use to control whether or not showing 'x-colo' string to users, they can use qmp command 'query-migrate-capabilities' or hmp command 'info migrate_capabilities' to learn if colo is supported.
---
v10:
- Rename capability 'colo' to experimental 'x-colo' (Eric's suggestion).
- Rename migrate_enable_colo() to migrate_colo_enabled() (Eric's suggestion).
--- include/migration/colo.h | 20 ++++++++++++++++++++ include/migration/migration.h | 1 + migration/Makefile.objs | 1 + migration/colo.c | 18 ++++++++++++++++++ migration/migration.c | 17 +++++++++++++++++ qapi-schema.json | 6 +++++- qmp-commands.hx | 1 + stubs/Makefile.objs | 1 + stubs/migration-colo.c | 18 ++++++++++++++++++ 9 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 include/migration/colo.h create mode 100644 migration/colo.c create mode 100644 stubs/migration-colo.c
include/migration/colo.h new file +20 -0
@@ -0,0 +1,20 @@ +/* +* COarse-grain LOck-stepping Virtual Machines for Non-stop Service (COLO) +* (a.k.a. Fault Tolerance or Continuous Replication) +* +* Copyright (c) 2015 HUAWEI TECHNOLOGIES CO., LTD. +* Copyright (c) 2015 FUJITSU LIMITED +* Copyright (c) 2015 Intel Corporation +* +* This work is licensed under the terms of the GNU GPL, version 2 or +* later. See the COPYING file in the top-level directory. +*/ + +#ifndef QEMU_COLO_H +#define QEMU_COLO_H + +#include "qemu-common.h" + +bool colo_supported (void ); + +#endif
include/migration/migration.h +1 -0
@@ -170,6 +170,7 @@ int xbzrle_decode_buffer(uint8_t *src, int slen, uint8_t *dst, int dlen);int migrate_use_xbzrle (void );int64_t migrate_xbzrle_cache_size (void ); +bool migrate_colo_enabled (void );int64_t xbzrle_cache_resize (int64_t new_size);
migration/Makefile.objs +1 -0
@@ -1,4 +1,5 @@ common-obj-y += migration.o tcp.o +common-obj-$(CONFIG_COLO) += colo.o common-obj-y += vmstate.o common-obj-y += qemu-file.o qemu-file-buf.o qemu-file-unix.o qemu-file-stdio.o common-obj-y += xbzrle.o
migration/colo.c new file +18 -0
@@ -0,0 +1,18 @@ +/* +* COarse-grain LOck-stepping Virtual Machines for Non-stop Service (COLO) +* (a.k.a. Fault Tolerance or Continuous Replication) +* +* Copyright (c) 2015 HUAWEI TECHNOLOGIES CO., LTD. +* Copyright (c) 2015 FUJITSU LIMITED +* Copyright (c) 2015 Intel Corporation +* +* This work is licensed under the terms of the GNU GPL, version 2 or +* later. See the COPYING file in the top-level directory. +*/ + +#include "migration/colo.h" + +bool colo_supported (void ) +{ +return true; +}
migration/migration.c +17 -0
@@ -30,6 +30,7 @@#include "qapi/util.h" #include "qapi-event.h" #include "qom/cpu.h" +#include "migration/colo.h" #define MAX_THROTTLE (32 << 20)/* Migration transfer speed throttling */
@@ -364,6 +365,9 @@ MigrationCapabilityStatusList *qmp_query_migrate_capabilities(Error **errp) caps =NULL ;/* silence compiler warning */ for (i =0 ; i <MIGRATION_CAPABILITY_MAX ; i++) { +if (i ==MIGRATION_CAPABILITY_X_COLO && !colo_supported ()) { +continue ; + }if (head ==NULL ) { head =g_malloc0 (sizeof (*caps)); caps = head;
@@ -513,6 +517,13 @@ void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params, }for (cap = params; cap; cap = cap->next) { +if (cap->value->capability ==MIGRATION_CAPABILITY_X_COLO && + !colo_supported ()) { +error_setg (errp,"COLO is not currently supported, please" +" configure with --enable-colo option in order to" +" support COLO feature" ); +continue ; + } s->enabled_capabilities[cap->value->capability] = cap->value->state; } }
@@ -1018,6 +1029,12 @@ fail:migrate_set_state (s,MIGRATION_STATUS_ACTIVE ,MIGRATION_STATUS_FAILED ); } +bool migrate_colo_enabled (void ) +{ +MigrationState *s =migrate_get_current (); +return s->enabled_capabilities[MIGRATION_CAPABILITY_X_COLO ]; +} +/* migration thread support */ static void *migration_thread (void *opaque)
qapi-schema.json +5 -1
@@ -540,11 +540,15 @@ # @auto-converge: If enabled, QEMU will automatically throttle down the guest # to speed up convergence of RAM migration. (since 1.6) # +# @x-colo: If enabled, migration will never end, and the state of the VM on the +# primary side will be migrated continuously to the VM on secondary +# side. (since 2.5) +# # Since: 1.2 ## { 'enum': 'MigrationCapability', 'data': ['xbzrle', 'rdma-pin-all', 'auto-converge', 'zero-blocks', - 'compress', 'events'] } + 'compress', 'events', 'x-colo'] } ## # @MigrationCapabilityStatus
qmp-commands.hx +1 -0
@@ -3498,6 +3498,7 @@ Query current migration capabilities - "rdma-pin-all" : RDMA Pin Page state (json-bool) - "auto-converge" : Auto Converge state (json-bool) - "zero-blocks" : Zero Blocks state (json-bool) + - "x-colo" : COarse-Grain LOck Stepping for Non-stop Service (json-bool) Arguments:
stubs/Makefile.objs +1 -0
@@ -35,3 +35,4 @@ stub-obj-y += kvm.o stub-obj-y += qmp_pc_dimm_device_list.o stub-obj-y += target-monitor-defs.o stub-obj-y += vhost.o +stub-obj-y += migration-colo.o
stubs/migration-colo.c new file +18 -0
@@ -0,0 +1,18 @@ +/* +* COarse-grain LOck-stepping Virtual Machines for Non-stop Service (COLO) +* (a.k.a. Fault Tolerance or Continuous Replication) +* +* Copyright (c) 2015 HUAWEI TECHNOLOGIES CO., LTD. +* Copyright (c) 2015 FUJITSU LIMITED +* Copyright (c) 2015 Intel Corporation +* +* This work is licensed under the terms of the GNU GPL, version 2 or +* later. See the COPYING file in the top-level directory. +*/ + +#include "migration/colo.h" + +bool colo_supported (void ) +{ +return false; +}
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH COLO-Frame v10 02/38] migration: Introduce capability 'x-colo' to migration
Quoted 20 lines · zhanghailiang
We add helper function
colo_supported()to indicate whether colo is supported or not, with which we use to control whether or not showing 'x-colo' string to users, they can use qmp command 'query-migrate-capabilities' or hmp command 'infomigrate_capabilities' to learn if colo is supported.Cc Juan Quintela <[email protected]>Cc Amit Shah <[email protected]>Cc Eric Blake <[email protected]>Cc Markus Armbruster <[email protected]>Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>Signed-off-by Gonglei <[email protected]>---
v10:
- Rename capability 'colo' to experimental 'x-colo' (Eric's suggestion).
- Renamemigrate_enable_colo()tomigrate_colo_enabled()(Eric's suggestion).+++
b/qapi-schema.json
qapi-schema.json line 545
Quoted 6 lines
qapi-schema.json +3
-0@@ -540,11 +540,15 @@ # @auto-converge: If enabled, QEMU will automatically throttle down the guest # to speed up convergence of RAM migration. (since 1.6) # +# @x-colo: If enabled, migration will never end, and the state of the VM on the +# primary side will be migrated continuously to the VM on secondary +# side. (since 2.5)
I think this has missed 2.5, so you'll need to tweak it to say 2.6.
With that fixed,
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH COLO-Frame v10 02/38] migration: Introduce capability 'x-colo' to migration
Quoted 19 lines · Eric Blake
Quoted 17 lines · zhanghailiang
We add helper function
colo_supported()to indicate whether colo is supported or not, with which we use to control whether or not showing 'x-colo' string to users, they can use qmp command 'query-migrate-capabilities' or hmp command 'infomigrate_capabilities' to learn if colo is supported.Cc Juan Quintela <[email protected]>Cc Amit Shah <[email protected]>Cc Eric Blake <[email protected]>Cc Markus Armbruster <[email protected]>Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>Signed-off-by Gonglei <[email protected]>---
v10:
- Rename capability 'colo' to experimental 'x-colo' (Eric's suggestion).
- Renamemigrate_enable_colo()tomigrate_colo_enabled()(Eric's suggestion).
Quoted 11 lines
qapi-schema.json line 545
Quoted 8 lines
+++
b/qapi-schema.jsonqapi-schema.json +3
-0@@ -540,11 +540,15 @@ # @auto-converge: If enabled, QEMU will automatically throttle down the guest # to speed up convergence of RAM migration. (since 1.6) # +# @x-colo: If enabled, migration will never end, and the state of the VM on the +# primary side will be migrated continuously to the VM on secondary +# side. (since 2.5)I think this has missed 2.5, so you'll need to tweak it to say 2.6.
Yes, will update it in next version.
Quoted 3 lines
With that fixed,
Reviewed-by Eric Blake <[email protected]>
Thanks.
PATCH v10 3/38 COLO: migrate colo related info to secondary node
In reply to zhanghailiangWe can know if VM in destination should go into COLO mode by refer to the info that been migrated from PVM.
We skip this section if colo is not enabled (i.e. migrate_set_capability colo off), so that, It not break compatibility with migration however the --enable-colo/disable-colo on the source/destination;
---
v10:
- Use VMSTATE_BOOL instead of VMSTATE_UNIT32 for 'colo_requested' (Dave's suggestion).
--- include/migration/colo.h | 2 ++ migration/Makefile.objs | 1 + migration/colo-comm.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ vl.c | 3 ++- 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 migration/colo-comm.c
include/migration/colo.h +2 -0
@@ -14,7 +14,9 @@#define QEMU_COLO_H #include "qemu-common.h" +#include "migration/migration.h" bool colo_supported (void ); +void colo_info_mig_init (void );#endif
migration/Makefile.objs +1 -0
@@ -1,5 +1,6 @@ common-obj-y += migration.o tcp.o common-obj-$(CONFIG_COLO) += colo.o +common-obj-y += colo-comm.o common-obj-y += vmstate.o common-obj-y += qemu-file.o qemu-file-buf.o qemu-file-unix.o qemu-file-stdio.o common-obj-y += xbzrle.o
migration/colo-comm.c new file +50 -0
50 lines not on this page · raw message
vl.c +2 -1
@@ -91,6 +91,7 @@ int main(int argc, char **argv)#include "sysemu/dma.h" #include "audio/audio.h" #include "migration/migration.h" +#include "migration/colo.h" #include "sysemu/kvm.h" #include "qapi/qmp/qjson.h" #include "qemu/option.h"
@@ -4421,7 +4422,7 @@ int main(int argc, char **argv, char **envp)blk_mig_init ();ram_mig_init (); - +colo_info_mig_init ();/* If the currently selected machine wishes to override the units-per-bus * property of its default HBA interface type, do so now. */ if (machine_class->units_per_default_bus) {
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH COLO-Frame v10 03/38] COLO: migrate colo related info to secondary node
Quoted 10 lines · * zhanghailiang ([email protected]) wrote:
We can know if VM in destination should go into COLO mode by refer to the info that been migrated from PVM.
We skip this section if colo is not enabled (i.e.
migrate_set_capabilitycolo off), so that, It not break compatibility with migration however the --enable-colo/disable-colo on the source/destination;Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>Signed-off-by Gonglei <[email protected]>
Quoted 117 lines
---
v10:
- UseVMSTATE_BOOLinstead ofVMSTATE_UNIT32for 'colo_requested' (Dave's suggestion).--- include/migration/colo.h | 2 ++ migration/Makefile.objs | 1 + migration/colo-comm.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ vl.c | 3 ++- 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 migration/colo-comm.cinclude/migration/colo.h +2
-0@@ -14,7 +14,9 @@#define QEMU_COLO_H #include "qemu-common.h" +#include "migration/migration.h" bool colo_supported (void ); +void colo_info_mig_init (void );#endif migration/Makefile.objs +1
-0@@ -1,5 +1,6 @@ common-obj-y += migration.o tcp.o common-obj-$(CONFIG_COLO) += colo.o +common-obj-y += colo-comm.o common-obj-y += vmstate.o common-obj-y += qemu-file.o qemu-file-buf.o qemu-file-unix.o qemu-file-stdio.o common-obj-y += xbzrle.omigration/colo-comm.c new file +50
-0@@ -0,0 +1,50 @@ +/* +* COarse-grain LOck-stepping Virtual Machines for Non-stop Service (COLO) +* (a.k.a. Fault Tolerance or Continuous Replication) +* +* Copyright (c) 2015 HUAWEI TECHNOLOGIES CO., LTD. +* Copyright (c) 2015 FUJITSU LIMITED +* Copyright (c) 2015 Intel Corporation +* +* This work is licensed under the terms of the GNU GPL, version 2 or +* later. See the COPYING file in the top-level directory. +* +*/ + +#include <migration/colo.h> +#include "trace.h" + +typedef struct { +bool colo_requested; +}COLOInfo ; + +static COLOInfo colo_info; + +static void colo_info_pre_save (void *opaque) +{ +COLOInfo *s = opaque; + + s->colo_requested =migrate_colo_enabled (); +} + +static bool colo_info_need (void *opaque) +{ +return migrate_colo_enabled (); +} + +static const VMStateDescription colo_state = { + .name ="COLOState" , + .version_id =1 , + .minimum_version_id =1 , + .pre_save = colo_info_pre_save, + .needed = colo_info_need, + .fields = (VMStateField []) { +VMSTATE_BOOL (colo_requested, COLOInfo), +VMSTATE_END_OF_LIST () + }, +}; + +void colo_info_mig_init (void ) +{ +vmstate_register (NULL ,0 , &colo_state, &colo_info); +}vl.c +2
-1@@ -91,6 +91,7 @@ int main(int argc, char **argv)#include "sysemu/dma.h" #include "audio/audio.h" #include "migration/migration.h" +#include "migration/colo.h" #include "sysemu/kvm.h" #include "qapi/qmp/qjson.h" #include "qemu/option.h" @@ -4421,7 +4422,7 @@ int main(int argc, char **argv, char **envp)blk_mig_init ();ram_mig_init (); - +colo_info_mig_init ();/* If the currently selected machine wishes to override the units-per-bus * property of its default HBA interface type, do so now. */ if (machine_class->units_per_default_bus) {Signature · 1 line
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
PATCH v10 4/38 migration: Add state records for migration incoming
In reply to zhanghailiangFor migration destination, we also need to know its state, we will use it in COLO.
Here we add a new member 'state' for MigrationIncomingState, and also use migrate_set_state() to modify its value. We fix the first parameter of migrate_set_state(), and make it public.
--- include/migration/migration.h | 3 +++ migration/migration.c | 43 +++++++++++++++++++++++++++---------------- 2 files changed, 30 insertions(+), 16 deletions(-)
include/migration/migration.h +3 -0
@@ -50,6 +50,7 @@ typedef QLIST_HEAD(, LoadStateEntry) LoadStateEntry_Head;struct MigrationIncomingState {QEMUFile *file; +int state;/* See savevm.c */ LoadStateEntry_Head loadvm_handlers; };
@@ -82,6 +83,8 @@ struct MigrationStateint64_t dirty_sync_count; }; +void migrate_set_state (int *state,int old_state,int new_state); +void process_incoming_migration (QEMUFile *f);void qemu_start_incoming_migration (const char *uri,Error **errp);
migration/migration.c +27 -16
134 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v10 5/38 migration: Integrate COLO checkpoint process into migration
In reply to zhanghailiangAdd a migrate state: MIGRATION_STATUS_COLO, enter this migration state after the first live migration successfully finished.
We reuse migration thread, so if colo is enabled by user, migration thread will go into the process of colo.
---
v10: Simplify process by dropping colo thread and reusing migration thread.
(Dave's suggestion)
--- include/migration/colo.h | 3 +++ migration/colo.c | 31 +++++++++++++++++++++++++++++++ migration/migration.c | 19 +++++++++++++++---- qapi-schema.json | 2 +- stubs/migration-colo.c | 9 +++++++++ trace-events | 3 +++ 6 files changed, 62 insertions(+), 5 deletions(-)
include/migration/colo.h +3 -0
@@ -19,4 +19,7 @@bool colo_supported (void );void colo_info_mig_init (void ); +void migrate_start_colo_process (MigrationState *s); +bool migration_in_colo_state (void ); +#endif
migration/colo.c +31 -0
@@ -10,9 +10,40 @@* later. See the COPYING file in the top-level directory. */ +#include "sysemu/sysemu.h" #include "migration/colo.h" +#include "trace.h" bool colo_supported (void ) {return true; } + +bool migration_in_colo_state (void ) +{ +MigrationState *s =migrate_get_current (); + +return (s->state ==MIGRATION_STATUS_COLO ); +} + +static void colo_process_checkpoint (MigrationState *s) +{ +qemu_mutex_lock_iothread (); +vm_start (); +qemu_mutex_unlock_iothread (); +trace_colo_vm_state_change ("stop" ,"run" ); + +/*TODO: COLO checkpoint savevm loop*/ + +migrate_set_state (&s->state,MIGRATION_STATUS_COLO , +MIGRATION_STATUS_COMPLETED ); +} + +void migrate_start_colo_process (MigrationState *s) +{ +qemu_mutex_unlock_iothread (); +migrate_set_state (&s->state,MIGRATION_STATUS_ACTIVE , +MIGRATION_STATUS_COLO ); +colo_process_checkpoint (s); +qemu_mutex_lock_iothread (); +}
migration/migration.c +15 -4
@@ -475,6 +475,10 @@ MigrationInfo *qmp_query_migrate(Error **errp)get_xbzrle_cache_stats (info);break ; +case MIGRATION_STATUS_COLO : + info->has_status = true; +/* TODO: display COLO specific information (checkpoint info etc.) */ +break ;case MIGRATION_STATUS_COMPLETED :get_xbzrle_cache_stats (info);
@@ -793,7 +797,8 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,if (s->state ==MIGRATION_STATUS_ACTIVE || s->state ==MIGRATION_STATUS_SETUP || - s->state ==MIGRATION_STATUS_CANCELLING ) { + s->state ==MIGRATION_STATUS_CANCELLING || + s->state ==MIGRATION_STATUS_COLO ) {error_setg (errp,QERR_MIGRATION_ACTIVE );return ; }
@@ -1030,8 +1035,11 @@ static void migration_completion(MigrationState *s, bool *old_vm_running, goto fail; } -migrate_set_state (&s->state,MIGRATION_STATUS_ACTIVE , -MIGRATION_STATUS_COMPLETED ); +if (!migrate_colo_enabled ()) { +migrate_set_state (&s->state,MIGRATION_STATUS_ACTIVE , +MIGRATION_STATUS_COMPLETED ); + } +return ; fail:
@@ -1056,6 +1064,7 @@ static void *migration_thread(void *opaque)int64_t max_size =0 ;int64_t start_time = initial_time;bool old_vm_running = false; +bool enable_colo =migrate_colo_enabled ();rcu_register_thread ();
@@ -1130,7 +1139,9 @@ static void *migration_thread(void *opaque) }runstate_set (RUN_STATE_POSTMIGRATE ); }else { -if (old_vm_running) { +if (s->state ==MIGRATION_STATUS_ACTIVE && enable_colo) { +migrate_start_colo_process (s); + }else if (old_vm_running) {vm_start (); } }
qapi-schema.json +1 -1
@@ -439,7 +439,7 @@ ## { 'enum': 'MigrationStatus', 'data': [ 'none', 'setup', 'cancelling', 'cancelled', - 'active', 'completed', 'failed' ] } + 'active', 'completed', 'failed', 'colo' ] } ## # @MigrationInfo
stubs/migration-colo.c +9 -0
@@ -16,3 +16,12 @@ bool colo_supported(void) {return false; } + +bool migration_in_colo_state (void ) +{ +return false; +} + +void migrate_start_colo_process (MigrationState *s) +{ +}
trace-events +3 -0
@@ -1497,6 +1497,9 @@ rdma_start_incoming_migration_after_rdma_listen(void) "" rdma_start_outgoing_migration_after_rdma_connect(void) "" rdma_start_outgoing_migration_after_rdma_source_init(void) "" +# migration/colo.c +colo_vm_state_change(const char *old, const char *new) "Change '%s' => '%s'" + # kvm-all.c kvm_ioctl(int type, void *arg) "type 0x%x, arg %p" kvm_vm_ioctl(int type, void *arg) "type 0x%x, arg %p"
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH COLO-Frame v10 05/38] migration: Integrate COLO checkpoint process into migration
Quoted 9 lines · * zhanghailiang ([email protected]) wrote:
Add a migrate state:
MIGRATION_STATUS_COLO, enter this migration state after the first live migration successfully finished.We reuse migration thread, so if colo is enabled by user, migration thread will go into the process of colo.
Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>Signed-off-by Gonglei <[email protected]>
Quoted 175 lines
---
v10: Simplify process by dropping colo thread and reusing migration thread.
(Dave's suggestion)--- include/migration/colo.h | 3 +++ migration/colo.c | 31 +++++++++++++++++++++++++++++++ migration/migration.c | 19 +++++++++++++++---- qapi-schema.json | 2 +- stubs/migration-colo.c | 9 +++++++++ trace-events | 3 +++ 6 files changed, 62 insertions(+), 5 deletions(-)include/migration/colo.h +3
-0@@ -19,4 +19,7 @@bool colo_supported (void );void colo_info_mig_init (void ); +void migrate_start_colo_process (MigrationState *s); +bool migration_in_colo_state (void ); +#endif migration/colo.c +31
-0@@ -10,9 +10,40 @@* later. See the COPYING file in the top-level directory. */ +#include "sysemu/sysemu.h" #include "migration/colo.h" +#include "trace.h" bool colo_supported (void ) {return true; } + +bool migration_in_colo_state (void ) +{ +MigrationState *s =migrate_get_current (); + +return (s->state ==MIGRATION_STATUS_COLO ); +} + +static void colo_process_checkpoint (MigrationState *s) +{ +qemu_mutex_lock_iothread (); +vm_start (); +qemu_mutex_unlock_iothread (); +trace_colo_vm_state_change ("stop" ,"run" ); + +/*TODO: COLO checkpoint savevm loop*/ + +migrate_set_state (&s->state,MIGRATION_STATUS_COLO , +MIGRATION_STATUS_COMPLETED ); +} + +void migrate_start_colo_process (MigrationState *s) +{ +qemu_mutex_unlock_iothread (); +migrate_set_state (&s->state,MIGRATION_STATUS_ACTIVE , +MIGRATION_STATUS_COLO ); +colo_process_checkpoint (s); +qemu_mutex_lock_iothread (); +}migration/migration.c +15
-4@@ -475,6 +475,10 @@ MigrationInfo *qmp_query_migrate(Error **errp)get_xbzrle_cache_stats (info);break ; +case MIGRATION_STATUS_COLO : + info->has_status = true; +/* TODO: display COLO specific information (checkpoint info etc.) */ +break ;case MIGRATION_STATUS_COMPLETED :get_xbzrle_cache_stats (info);@@ -793,7 +797,8 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,if (s->state ==MIGRATION_STATUS_ACTIVE || s->state ==MIGRATION_STATUS_SETUP || - s->state ==MIGRATION_STATUS_CANCELLING ) { + s->state ==MIGRATION_STATUS_CANCELLING || + s->state ==MIGRATION_STATUS_COLO ) {error_setg (errp,QERR_MIGRATION_ACTIVE );return ; }@@ -1030,8 +1035,11 @@ static void migration_completion(MigrationState *s, bool *old_vm_running, goto fail; } -migrate_set_state (&s->state,MIGRATION_STATUS_ACTIVE , -MIGRATION_STATUS_COMPLETED ); +if (!migrate_colo_enabled ()) { +migrate_set_state (&s->state,MIGRATION_STATUS_ACTIVE , +MIGRATION_STATUS_COMPLETED ); + } +return ; fail:@@ -1056,6 +1064,7 @@ static void *migration_thread(void *opaque)int64_t max_size =0 ;int64_t start_time = initial_time;bool old_vm_running = false; +bool enable_colo =migrate_colo_enabled ();rcu_register_thread ();@@ -1130,7 +1139,9 @@ static void *migration_thread(void *opaque) }runstate_set (RUN_STATE_POSTMIGRATE ); }else { -if (old_vm_running) { +if (s->state ==MIGRATION_STATUS_ACTIVE && enable_colo) { +migrate_start_colo_process (s); + }else if (old_vm_running) {vm_start (); } }qapi-schema.json +1
-1@@ -439,7 +439,7 @@ ## { 'enum': 'MigrationStatus', 'data': [ 'none', 'setup', 'cancelling', 'cancelled', - 'active', 'completed', 'failed' ] } + 'active', 'completed', 'failed', 'colo' ] } ## # @MigrationInfostubs/migration-colo.c +9
-0@@ -16,3 +16,12 @@ bool colo_supported(void) {return false; } + +bool migration_in_colo_state (void ) +{ +return false; +} + +void migrate_start_colo_process (MigrationState *s) +{ +}trace-events +3
-0@@ -1497,6 +1497,9 @@ rdma_start_incoming_migration_after_rdma_listen(void) "" rdma_start_outgoing_migration_after_rdma_connect(void) "" rdma_start_outgoing_migration_after_rdma_source_init(void) "" +# migration/colo.c +colo_vm_state_change(const char *old, const char *new) "Change '%s' => '%s'" + # kvm-all.c kvm_ioctl(int type, void *arg) "type 0x%x, arg %p" kvm_vm_ioctl(int type, void *arg) "type 0x%x, arg %p"Signature · 1 line
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH COLO-Frame v10 05/38] migration: Integrate COLO checkpoint process into migration
In reply to zhanghailiangQuoted 16 lines · zhanghailiang
Add a migrate state:
MIGRATION_STATUS_COLO, enter this migration state after the first live migration successfully finished.We reuse migration thread, so if colo is enabled by user, migration thread will go into the process of colo.
Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>Signed-off-by Gonglei <[email protected]>---
v10: Simplify process by dropping colo thread and reusing migration thread.
(Dave's suggestion)
---+++
b/qapi-schema.json
qapi-schema.json line 443
Quoted 6 lines
qapi-schema.json +1
-1@@ -439,7 +439,7 @@ ## { 'enum': 'MigrationStatus', 'data': [ 'none', 'setup', 'cancelling', 'cancelled', - 'active', 'completed', 'failed' ] } + 'active', 'completed', 'failed', 'colo' ] }
Missing documentation of the new state, including a '(since 2.6)' tag.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH COLO-Frame v10 05/38] migration: Integrate COLO checkpoint process into migration
Quoted 15 lines · Eric Blake
Quoted 13 lines · zhanghailiang
Add a migrate state:
MIGRATION_STATUS_COLO, enter this migration state after the first live migration successfully finished.We reuse migration thread, so if colo is enabled by user, migration thread will go into the process of colo.
Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>Signed-off-by Gonglei <[email protected]>---
v10: Simplify process by dropping colo thread and reusing migration thread.
(Dave's suggestion)
---
Quoted 11 lines
qapi-schema.json line 443
Quoted 8 lines
+++
b/qapi-schema.jsonqapi-schema.json +1
-1@@ -439,7 +439,7 @@ ## { 'enum': 'MigrationStatus', 'data': [ 'none', 'setup', 'cancelling', 'cancelled', - 'active', 'completed', 'failed' ] } + 'active', 'completed', 'failed', 'colo' ] }Missing documentation of the new state, including a '(since 2.6)' tag.
Good catch, i will fix it in next version, thanks.
PATCH v10 6/38 migration: Integrate COLO checkpoint process into loadvm
In reply to zhanghailiangSwitch from normal migration loadvm process into COLO checkpoint process if COLO mode is enabled.
We add three new members to struct MigrationIncomingState, 'have_colo_incoming_thread' and 'colo_incoming_thread' record the colo related threads for secondary VM, 'migration_incoming_co' records the original migration incoming coroutine.
---
v10: fix a bug about fd leak which is found by Dave.
--- include/migration/colo.h | 7 +++++++ include/migration/migration.h | 7 +++++++ migration/colo-comm.c | 10 ++++++++++ migration/colo.c | 22 ++++++++++++++++++++++ migration/migration.c | 21 +++++++++++++++++++++ stubs/migration-colo.c | 10 ++++++++++ 6 files changed, 77 insertions(+)
include/migration/colo.h +7 -0
@@ -15,6 +15,8 @@#include "qemu-common.h" #include "migration/migration.h" +#include "qemu/coroutine_int.h" +#include "qemu/thread.h" bool colo_supported (void );void colo_info_mig_init (void );
@@ -22,4 +24,9 @@ void colo_info_mig_init(void);void migrate_start_colo_process (MigrationState *s);bool migration_in_colo_state (void ); +/* loadvm */ +bool migration_incoming_enable_colo (void ); +void migration_incoming_exit_colo (void ); +void *colo_process_incoming_thread (void *opaque); +bool migration_incoming_in_colo_state (void );#endif
include/migration/migration.h +7 -0
@@ -22,6 +22,7 @@#include "migration/vmstate.h" #include "qapi-types.h" #include "exec/cpu-common.h" +#include "qemu/coroutine_int.h" #define QEMU_VM_FILE_MAGIC 0x5145564d#define QEMU_VM_FILE_VERSION_COMPAT 0x00000002
@@ -51,6 +52,12 @@ struct MigrationIncomingState {QEMUFile *file;int state; + +bool have_colo_incoming_thread; +QemuThread colo_incoming_thread; +/* The coroutine we should enter (back) after failover */ +Coroutine *migration_incoming_co; +/* See savevm.c */ LoadStateEntry_Head loadvm_handlers; };
migration/colo-comm.c +10 -0
@@ -48,3 +48,13 @@ void colo_info_mig_init(void) {vmstate_register (NULL ,0 , &colo_state, &colo_info); } + +bool migration_incoming_enable_colo (void ) +{ +return colo_info.colo_requested; +} + +void migration_incoming_exit_colo (void ) +{ + colo_info.colo_requested =0 ; +}
migration/colo.c +22 -0
@@ -13,6 +13,7 @@#include "sysemu/sysemu.h" #include "migration/colo.h" #include "trace.h" +#include "qemu/error-report.h" bool colo_supported (void ) {
@@ -26,6 +27,13 @@ bool migration_in_colo_state(void)return (s->state ==MIGRATION_STATUS_COLO ); } +bool migration_incoming_in_colo_state (void ) +{ +MigrationIncomingState *mis =migration_incoming_get_current (); + +return mis && (mis->state ==MIGRATION_STATUS_COLO ); +} +static void colo_process_checkpoint (MigrationState *s) {qemu_mutex_lock_iothread ();
@@ -47,3 +55,17 @@ void migrate_start_colo_process(MigrationState *s)colo_process_checkpoint (s);qemu_mutex_lock_iothread (); } + +void *colo_process_incoming_thread (void *opaque) +{ +MigrationIncomingState *mis = opaque; + +migrate_set_state (&mis->state,MIGRATION_STATUS_ACTIVE , +MIGRATION_STATUS_COLO ); + +/* TODO: COLO checkpoint restore loop */ + +migration_incoming_exit_colo (); + +return NULL ; +}
migration/migration.c +21 -0
@@ -288,6 +288,27 @@ static void process_incoming_migration_co(void *opaque) MIGRATION_STATUS_ACTIVE); ret =qemu_loadvm_state (f); +if (!ret) { +/* Make sure all file formats flush their mutable metadata */ +bdrv_invalidate_cache_all (&local_err); +if (local_err) { +error_report_err (local_err); +migrate_decompress_threads_join (); +exit (EXIT_FAILURE ); + } + } +/* we get colo info, and know if we are in colo mode */ +if (!ret &&migration_incoming_enable_colo ()) { + mis->migration_incoming_co =qemu_coroutine_self (); +qemu_thread_create (&mis->colo_incoming_thread,"colo incoming" , + colo_process_incoming_thread, mis,QEMU_THREAD_JOINABLE ); + mis->have_colo_incoming_thread = true; +qemu_coroutine_yield (); + +/* Wait checkpoint incoming thread exit before free resource */ +qemu_thread_join (&mis->colo_incoming_thread); + } +qemu_fclose (f);free_xbzrle_decoded_buf ();migration_incoming_state_destroy ();
stubs/migration-colo.c +10 -0
@@ -22,6 +22,16 @@ bool migration_in_colo_state(void)return false; } +bool migration_incoming_in_colo_state (void ) +{ +return false; +} +void migrate_start_colo_process (MigrationState *s) { } + +void *colo_process_incoming_thread (void *opaque) +{ +return NULL ; +}
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH COLO-Frame v10 06/38] migration: Integrate COLO checkpoint process into loadvm
Quoted 10 lines · * zhanghailiang ([email protected]) wrote:
Switch from normal migration loadvm process into COLO checkpoint process if COLO mode is enabled.
We add three new members to struct MigrationIncomingState, 'have_colo_incoming_thread' and 'colo_incoming_thread' record the colo related threads for secondary VM, 'migration_incoming_co' records the original migration incoming coroutine.Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>---
v10: fix a bug about fd leak which is found by Dave.
<snip>
Quoted 7 lines
migration/migration.c +0
-0@@ -288,6 +288,27 @@ static void process_incoming_migration_co(void *opaque) MIGRATION_STATUS_ACTIVE); ret =qemu_loadvm_state (f);
migration/migration.c static void process_incoming_migration_co(void *opaque) · line 299
Quoted 10 lines
migration/migration.c +9
-0+if (!ret) { +/* Make sure all file formats flush their mutable metadata */ +bdrv_invalidate_cache_all (&local_err); +if (local_err) { +error_report_err (local_err); +migrate_decompress_threads_join (); +exit (EXIT_FAILURE ); + } + }
Are you moving this code? Because I think the bdrv_invalidate_cache_all is a few lines below here - just....
Quoted 5 lines
migration/migration.c +5
-0+/* we get colo info, and know if we are in colo mode */ +if (!ret &&migration_incoming_enable_colo ()) { + mis->migration_incoming_co =qemu_coroutine_self (); +qemu_thread_create (&mis->colo_incoming_thread,"colo incoming" , + colo_process_incoming_thread, mis,QEMU_THREAD_JOINABLE );
migration/migration.c static void process_incoming_migration_co(void *opaque) · line 314
Quoted 10 lines
migration/migration.c +7
-0+ mis->have_colo_incoming_thread = true; +qemu_coroutine_yield (); + +/* Wait checkpoint incoming thread exit before free resource */ +qemu_thread_join (&mis->colo_incoming_thread); + } +qemu_fclose (f);free_xbzrle_decoded_buf ();migration_incoming_state_destroy ();
.... here in my current head world; so shouldn't you be deleting the bdrv_invalidate_cache_all here?
(Otherwise OK)
Dave
Quoted 25 lines
stubs/migration-colo.c +10
-0@@ -22,6 +22,16 @@ bool migration_in_colo_state(void)return false; } +bool migration_incoming_in_colo_state (void ) +{ +return false; +} +void migrate_start_colo_process (MigrationState *s) { } + +void *colo_process_incoming_thread (void *opaque) +{ +return NULL ; +}Signature · 1 line
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH COLO-Frame v10 06/38] migration: Integrate COLO checkpoint process into loadvm
Quoted 46 lines · Dr. David Alan Gilbert
Quoted 10 lines · * zhanghailiang ([email protected]) wrote:
Switch from normal migration loadvm process into COLO checkpoint process if COLO mode is enabled.
We add three new members to struct MigrationIncomingState, 'have_colo_incoming_thread' and 'colo_incoming_thread' record the colo related threads for secondary VM, 'migration_incoming_co' records the original migration incoming coroutine.Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>---
v10: fix a bug about fd leak which is found by Dave.<snip>
Quoted 7 lines
migration/migration.c +0
-0@@ -288,6 +288,27 @@ static void process_incoming_migration_co(void *opaque) MIGRATION_STATUS_ACTIVE); ret =qemu_loadvm_state (f);migration/migration.c static void process_incoming_migration_co(void *opaque) · line 299
Quoted 10 lines
migration/migration.c +9
-0+if (!ret) { +/* Make sure all file formats flush their mutable metadata */ +bdrv_invalidate_cache_all (&local_err); +if (local_err) { +error_report_err (local_err); +migrate_decompress_threads_join (); +exit (EXIT_FAILURE ); + } + }Are you moving this code? Because I think the
bdrv_invalidate_cache_allis a few lines below here - just....Quoted 11 lines
migration/migration.c +11
-0+/* we get colo info, and know if we are in colo mode */ +if (!ret &&migration_incoming_enable_colo ()) { + mis->migration_incoming_co =qemu_coroutine_self (); +qemu_thread_create (&mis->colo_incoming_thread,"colo incoming" , + colo_process_incoming_thread, mis,QEMU_THREAD_JOINABLE ); + mis->have_colo_incoming_thread = true; +qemu_coroutine_yield (); + +/* Wait checkpoint incoming thread exit before free resource */ +qemu_thread_join (&mis->colo_incoming_thread); + }
Quoted 9 lines
migration/migration.c static void process_incoming_migration_co(void *opaque) · line 314
Quoted 4 lines
migration/migration.c +1
-0+qemu_fclose (f);free_xbzrle_decoded_buf ();migration_incoming_state_destroy ();.... here in my current head world; so shouldn't you be deleting the
bdrv_invalidate_cache_allhere?
Good catch! I deleted it in patch 38, which should be moved into this patch. I will fix it in next version.
Thanks,
zhanghailiang
Quoted 34 lines
(Otherwise OK)
Dave
Quoted 22 lines
stubs/migration-colo.c +10
-1@@ -22,6 +22,16 @@ bool migration_in_colo_state(void)return false; } +bool migration_incoming_in_colo_state (void ) +{ +return false; +} +void migrate_start_colo_process (MigrationState *s) { } + +void *colo_process_incoming_thread (void *opaque) +{ +return NULL ; +} --Quoted 3 lines
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK.
PATCH v10 7/38 migration: Rename the'file' member of MigrationState and MigrationIncomingState
In reply to zhanghailiangRename the 'file' member of MigrationState to 'to_dst_file' and Rename the 'file' member of MigrationIncomingState to 'from_src_file'.
For now, there are only one path direction for migration, it is from source side to destination side, but for colo and post-copy, we need both directions communication, so here we rename the file member to indicate this path.
---
Will be dropped if post-copy is merged.
--- include/migration/migration.h | 4 ++-- migration/exec.c | 4 ++-- migration/fd.c | 4 ++-- migration/migration.c | 48 ++++++++++++++++++++++--------------------- migration/tcp.c | 4 ++-- migration/unix.c | 4 ++-- 6 files changed, 35 insertions(+), 33 deletions(-)
include/migration/migration.h +2 -2
@@ -49,7 +49,7 @@ typedef QLIST_HEAD(, LoadStateEntry) LoadStateEntry_Head;/* State for the incoming migration */ struct MigrationIncomingState { -QEMUFile *file; +QEMUFile *from_src_file;int state;
@@ -73,7 +73,7 @@ struct MigrationStatesize_t xfer_limit;QemuThread thread;QEMUBH *cleanup_bh; -QEMUFile *file; +QEMUFile *to_dst_file;int parameters[MIGRATION_PARAMETER_MAX ];int state;
migration/exec.c +2 -2
@@ -36,8 +36,8 @@void exec_start_outgoing_migration (MigrationState *s,const char *command,Error **errp) { - s->file =qemu_popen_cmd (command,"w" ); -if (s->file ==NULL ) { + s->to_dst_file =qemu_popen_cmd (command,"w" ); +if (s->to_dst_file ==NULL ) {error_setg_errno (errp, errno,"failed to popen the migration target" );return ; }
migration/fd.c +2 -2
@@ -50,9 +50,9 @@ void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error ** }if (fd_is_socket (fd)) { - s->file =qemu_fopen_socket (fd,"wb" ); + s->to_dst_file =qemu_fopen_socket (fd,"wb" ); }else { - s->file =qemu_fdopen (fd,"wb" ); + s->to_dst_file =qemu_fdopen (fd,"wb" ); }migrate_fd_connect (s);
migration/migration.c +25 -23
142 lines not on this page · raw message
migration/tcp.c +2 -2
@@ -39,11 +39,11 @@ static void tcp_wait_for_connect(int fd, Error *err, void *opaque)if (fd <0 ) {DPRINTF ("migrate connect error: %s\n" ,error_get_pretty (err)); - s->file =NULL ; + s->to_dst_file =NULL ;migrate_fd_error (s); }else {DPRINTF ("migrate connect success\n" ); - s->file =qemu_fopen_socket (fd,"wb" ); + s->to_dst_file =qemu_fopen_socket (fd,"wb" );migrate_fd_connect (s); } }
migration/unix.c +2 -2
@@ -39,11 +39,11 @@ static void unix_wait_for_connect(int fd, Error *err, void *opaque)if (fd <0 ) {DPRINTF ("migrate connect error: %s\n" ,error_get_pretty (err)); - s->file =NULL ; + s->to_dst_file =NULL ;migrate_fd_error (s); }else {DPRINTF ("migrate connect success\n" ); - s->file =qemu_fopen_socket (fd,"wb" ); + s->to_dst_file =qemu_fopen_socket (fd,"wb" );migrate_fd_connect (s); } }
Signature · 1 line
1.8.3.1
PATCH v10 8/38 COLO/migration: establish a new communication path from destination to source
In reply to zhanghailiangAdd a new member 'to_src_file' to MigrationIncomingState and a new member 'from_dst_file' to MigrationState.
They will be used for returning messages from destination to source. It will also be used by post-copy migration.
---
v10: fix the the error log (Dave's suggestion).
--- include/migration/migration.h | 3 ++- migration/colo.c | 44 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-)
include/migration/migration.h +2 -1
@@ -50,7 +50,7 @@ typedef QLIST_HEAD(, LoadStateEntry) LoadStateEntry_Head;/* State for the incoming migration */ struct MigrationIncomingState {QEMUFile *from_src_file; - +QEMUFile *to_src_file;int state;bool have_colo_incoming_thread;
@@ -74,6 +74,7 @@ struct MigrationStateQemuThread thread;QEMUBH *cleanup_bh;QEMUFile *to_dst_file; +QEMUFile *from_dst_file;int parameters[MIGRATION_PARAMETER_MAX ];int state;
migration/colo.c +44 -0
70 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v10 9/38 COLO: Implement colo checkpoint protocol
In reply to zhanghailiangWe need communications protocol of user-defined to control the checkpoint process.
The new checkpoint request is started by Primary VM, and the interactive process like below:
Checkpoint synchronizing points,
Primary Secondary
'checkpoint-request' @ ----------------------------->
Suspend (In hybrid mode)
'checkpoint-reply' <------------------------------ @
Suspend&Save state
'vmstate-send' @ ----------------------------->
Send state Receive state
'vmstate-received' <------------------------------ @
Release packets Load state
'vmstate-load' <------------------------------ @
Resume Resume (In hybrid mode)
Start Comparing (In hybrid mode)
NOTE:
1) '@' who sends the message
2) Every sync-point is synchronized by two sides with only one handshake(single direction) for low-latency.
If more strict synchronization is required, a opposite direction sync-point should be added.
3) Since sync-points are single direction, the remote side may go forward a lot when this side just receives the sync-point.
4) For now, we only support 'periodic' checkpoint, for which the Secondary VM is not running, later we will support 'hybrid' mode.
---
v10:
- Rename enum COLOCmd to COLOCommand (Eric's suggestion).
- Remove unused 'ram-steal'
--- migration/colo.c | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- qapi-schema.json | 27 ++++++++ trace-events | 2 + 3 files changed, 219 insertions(+), 2 deletions(-)
migration/colo.c +190 -2
@@ -10,10 +10,12 @@* later. See the COPYING file in the top-level directory. */ +#include <unistd.h> #include "sysemu/sysemu.h" #include "migration/colo.h" #include "trace.h" #include "qemu/error-report.h" +#include "qemu/sockets.h" bool colo_supported (void ) {
@@ -34,6 +36,103 @@ bool migration_incoming_in_colo_state(void)return mis && (mis->state ==MIGRATION_STATUS_COLO ); } +/* colo checkpoint control helper */ +static int colo_ctl_put (QEMUFile *f,uint32_t cmd,uint64_t value) +{ +int ret =0 ; + +qemu_put_be32 (f, cmd); +qemu_put_be64 (f, value); +qemu_fflush (f); + + ret =qemu_file_get_error (f); +trace_colo_ctl_put (COLOCommand_lookup[cmd], value); + +return ret; +} + +static int colo_ctl_get_cmd (QEMUFile *f,uint32_t *cmd) +{ +int ret =0 ; + + *cmd =qemu_get_be32 (f); + ret =qemu_file_get_error (f); +if (ret <0 ) { +return ret; + } +if (*cmd >=COLO_COMMAND_MAX ) { +error_report ("Invalid colo command, get cmd:%d" , *cmd); +return -EINVAL ; + } +trace_colo_ctl_get (COLOCommand_lookup[*cmd]); + +return 0 ; +} + +static int colo_ctl_get (QEMUFile *f,uint32_t require) +{ +int ret; +uint32_t cmd; +uint64_t value; + + ret =colo_ctl_get_cmd (f, &cmd); +if (ret <0 ) { +return ret; + } +if (cmd != require) { +error_report ("Unexpect colo command, expect:%d, but get cmd:%d" , + require, cmd); +return -EINVAL ; + } + + value =qemu_get_be64 (f); + ret =qemu_file_get_error (f); +if (ret <0 ) { +return ret; + } + +return value; +} + +static int colo_do_checkpoint_transaction (MigrationState *s) +{ +int ret; + + ret =colo_ctl_put (s->to_dst_file,COLO_COMMAND_CHECKPOINT_REQUEST ,0 ); +if (ret <0 ) { + goto out; + } + + ret =colo_ctl_get (s->from_dst_file,COLO_COMMAND_CHECKPOINT_REPLY ); +if (ret <0 ) { + goto out; + } + +/* TODO: suspend and save vm state to colo buffer */ + + ret =colo_ctl_put (s->to_dst_file,COLO_COMMAND_VMSTATE_SEND ,0 ); +if (ret <0 ) { + goto out; + } + +/* TODO: send vmstate to Secondary */ + + ret =colo_ctl_get (s->from_dst_file,COLO_COMMAND_VMSTATE_RECEIVED ); +if (ret <0 ) { + goto out; + } + + ret =colo_ctl_get (s->from_dst_file,COLO_COMMAND_VMSTATE_LOADED ); +if (ret <0 ) { + goto out; + } + +/* TODO: resume Primary */ + +out: +return ret; +} +static void colo_process_checkpoint (MigrationState *s) {int fd, ret =0 ;
@@ -51,12 +150,27 @@ static void colo_process_checkpoint(MigrationState *s) goto out; } +/* +* Wait for Secondary finish loading vm states and enter COLO +* restore. +*/ + ret =colo_ctl_get (s->from_dst_file,COLO_COMMAND_CHECKPOINT_READY ); +if (ret <0 ) { + goto out; + } +qemu_mutex_lock_iothread ();vm_start ();qemu_mutex_unlock_iothread ();trace_colo_vm_state_change ("stop" ,"run" ); -/*TODO: COLO checkpoint savevm loop*/ +while (s->state ==MIGRATION_STATUS_COLO ) { +/* start a colo checkpoint */ + ret =colo_do_checkpoint_transaction (s); +if (ret <0 ) { + goto out; + } + } out:if (ret <0 ) {
@@ -79,6 +193,39 @@ void migrate_start_colo_process(MigrationState *s)qemu_mutex_lock_iothread (); } +/* +* return: +* 0: start a checkpoint +* -1: some error happened, exit colo restore +*/ +static int colo_wait_handle_cmd (QEMUFile *f,int *checkpoint_request) +{ +int ret; +uint32_t cmd; +uint64_t value; + + ret =colo_ctl_get_cmd (f, &cmd); +if (ret <0 ) { +/* do failover ? */ +return ret; + } +/* Fix me: this value should be 0, which is not so good, +* should be used for checking ? +*/ + value =qemu_get_be64 (f); +if (value !=0 ) { +return -EINVAL ; + } + +switch (cmd) { +case COLO_COMMAND_CHECKPOINT_REQUEST : + *checkpoint_request =1 ; +return 0 ; +default : +return -EINVAL ; + } +} +void *colo_process_incoming_thread (void *opaque) {MigrationIncomingState *mis = opaque;
@@ -98,7 +245,48 @@ void *colo_process_incoming_thread(void *opaque)error_report ("colo incoming thread: Open QEMUFile to_src_file failed" ); goto out; } -/* TODO: COLO checkpoint restore loop */ + + ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_CHECKPOINT_READY ,0 ); +if (ret <0 ) { + goto out; + } + +while (mis->state ==MIGRATION_STATUS_COLO ) { +int request =0 ; +int ret =colo_wait_handle_cmd (mis->from_src_file, &request); + +if (ret <0 ) { +break ; + }else { +if (!request) { +continue ; + } + } + + ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_CHECKPOINT_REPLY ,0 ); +if (ret <0 ) { + goto out; + } + + ret =colo_ctl_get (mis->from_src_file,COLO_COMMAND_VMSTATE_SEND ); +if (ret <0 ) { + goto out; + } + +/* TODO: read migration data into colo buffer */ + + ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_VMSTATE_RECEIVED ,0 ); +if (ret <0 ) { + goto out; + } + +/* TODO: load vm state */ + + ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_VMSTATE_LOADED ,0 ); +if (ret <0 ) { + goto out; + } + } out:if (ret <0 ) {
qapi-schema.json +27 -0
@@ -702,6 +702,33 @@ '*tls-port': 'int', '*cert-subject': 'str' } } ## +# @COLOCommand +# +# The colo command +# +# @invalid: unknown command +# +# @checkpoint-ready: SVM is ready for checkpointing +# +# @checkpoint-request: PVM tells SVM to prepare for new checkpointing +# +# @checkpoint-reply: SVM gets PVM's checkpoint request +# +# @vmstate-send: VM's state will be sent by PVM. +# +# @vmstate-size: The total size of VMstate. +# +# @vmstate-received: VM's state has been received by SVM +# +# @vmstate-loaded: VM's state has been loaded by SVM +# +# Since: 2.5 +## +{ 'enum': 'COLOCommand', + 'data': [ 'invalid', 'checkpoint-ready', 'checkpoint-request', + 'checkpoint-reply', 'vmstate-send', 'vmstate-size', + 'vmstate-received', 'vmstate-loaded' ] } + # @MouseInfo: # # Information about a mouse device.
trace-events +2 -0
@@ -1499,6 +1499,8 @@ rdma_start_outgoing_migration_after_rdma_source_init(void) "" # migration/colo.c colo_vm_state_change(const char *old, const char *new) "Change '%s' => '%s'" +colo_ctl_put(const char *msg, uint64_t value) "Send '%s' cmd, value: %" PRIu64"" +colo_ctl_get(const char *msg) "Receive '%s' cmd" # kvm-all.c kvm_ioctl(int type, void *arg) "type 0x%x, arg %p"
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH COLO-Frame v10 09/38] COLO: Implement colo checkpoint protocol
Quoted 7 lines · * zhanghailiang ([email protected]) wrote:
We need communications protocol of user-defined to control the checkpoint process.
The new checkpoint request is started by Primary VM, and the interactive process like below:
Checkpoint synchronizing points,
Quoted 5 lines
Primary Secondary
'checkpoint-request' @ ----------------------------->
Suspend (In hybrid mode)
'checkpoint-reply' <------------------------------ @
Suspend&Save state
Why is this initial pair necessary? Can't you just start with the vmstate-send and save the extra request pair/round trip? On the 2nd checkpoint we know the SVM already received the previous checkpoint because we got it's first vmstate-load.
I guess in full-COLO (rather than simple checkpoint) you can get the secondary to do some of it's stopping/cleanup after it sends the checkpoint-reply but before vmstate-send, so you can hide some of the time.
(Perhaps add a comment to explain)
Quoted 101 lines
'vmstate-send' @ ----------------------------->
Send state Receive state
'vmstate-received' <------------------------------ @
Release packets Load state
'vmstate-load' <------------------------------ @
Resume Resume (In hybrid mode)Start Comparing (In hybrid mode)
NOTE:
1) '@' who sends the message
2) Every sync-point is synchronized by two sides with only one handshake(single direction) for low-latency.
If more strict synchronization is required, a opposite direction sync-point should be added.
3) Since sync-points are single direction, the remote side may go forward a lot when this side just receives the sync-point.
4) For now, we only support 'periodic' checkpoint, for which the Secondary VM is not running, later we will support 'hybrid' mode.Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>Signed-off-by Gonglei <[email protected]>Cc Eric Blake <[email protected]>---
v10:
- Rename enum COLOCmd to COLOCommand (Eric's suggestion).
- Remove unused 'ram-steal'--- migration/colo.c | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- qapi-schema.json | 27 ++++++++ trace-events | 2 + 3 files changed, 219 insertions(+), 2 deletions(-)migration/colo.c +49
-0@@ -10,10 +10,12 @@* later. See the COPYING file in the top-level directory. */ +#include <unistd.h> #include "sysemu/sysemu.h" #include "migration/colo.h" #include "trace.h" #include "qemu/error-report.h" +#include "qemu/sockets.h" bool colo_supported (void ) {@@ -34,6 +36,103 @@ bool migration_incoming_in_colo_state(void)return mis && (mis->state ==MIGRATION_STATUS_COLO ); } +/* colo checkpoint control helper */ +static int colo_ctl_put (QEMUFile *f,uint32_t cmd,uint64_t value) +{ +int ret =0 ; + +qemu_put_be32 (f, cmd); +qemu_put_be64 (f, value); +qemu_fflush (f); + + ret =qemu_file_get_error (f); +trace_colo_ctl_put (COLOCommand_lookup[cmd], value); + +return ret; +} + +static int colo_ctl_get_cmd (QEMUFile *f,uint32_t *cmd) +{ +int ret =0 ; + + *cmd =qemu_get_be32 (f); + ret =qemu_file_get_error (f); +if (ret <0 ) { +return ret; + } +if (*cmd >=COLO_COMMAND_MAX ) { +error_report ("Invalid colo command, get cmd:%d" , *cmd); +return -EINVAL ; + } +trace_colo_ctl_get (COLOCommand_lookup[*cmd]); + +return 0 ; +} + +static int colo_ctl_get (QEMUFile *f,uint32_t require) +{ +int ret; +uint32_t cmd; +uint64_t value; + + ret =colo_ctl_get_cmd (f, &cmd); +if (ret <0 ) { +return ret; + } +if (cmd != require) { +error_report ("Unexpect colo command, expect:%d, but get cmd:%d" , + require, cmd); +return -EINVAL ;
migration/colo.c bool migration_incoming_in_colo_state(void) · line 95
Quoted 10 lines
migration/colo.c +10
-0+ } + + value =qemu_get_be64 (f); + ret =qemu_file_get_error (f); +if (ret <0 ) { +return ret; + } + +return value; +}
Should the return type be uint64_t since you're returning value? But then you're also using it to return an error code; so perhaps
it might be better to have a uint64_t *value parameter to
return the value separately; or define the range that the value can actually take.
(Also very minor typo: 'got' not 'get' in a few errors)
Quoted 85 lines
migration/colo.c +65
-1+static int colo_do_checkpoint_transaction (MigrationState *s) +{ +int ret; + + ret =colo_ctl_put (s->to_dst_file,COLO_COMMAND_CHECKPOINT_REQUEST ,0 ); +if (ret <0 ) { + goto out; + } + + ret =colo_ctl_get (s->from_dst_file,COLO_COMMAND_CHECKPOINT_REPLY ); +if (ret <0 ) { + goto out; + } + +/* TODO: suspend and save vm state to colo buffer */ + + ret =colo_ctl_put (s->to_dst_file,COLO_COMMAND_VMSTATE_SEND ,0 ); +if (ret <0 ) { + goto out; + } + +/* TODO: send vmstate to Secondary */ + + ret =colo_ctl_get (s->from_dst_file,COLO_COMMAND_VMSTATE_RECEIVED ); +if (ret <0 ) { + goto out; + }> + + ret =colo_ctl_get (s->from_dst_file,COLO_COMMAND_VMSTATE_LOADED ); +if (ret <0 ) { + goto out; + } + +/* TODO: resume Primary */ + +out: +return ret; +} +static void colo_process_checkpoint (MigrationState *s) {int fd, ret =0 ;@@ -51,12 +150,27 @@ static void colo_process_checkpoint(MigrationState *s) goto out; } +/* +* Wait for Secondary finish loading vm states and enter COLO +* restore. +*/ + ret =colo_ctl_get (s->from_dst_file,COLO_COMMAND_CHECKPOINT_READY ); +if (ret <0 ) { + goto out; + } +qemu_mutex_lock_iothread ();vm_start ();qemu_mutex_unlock_iothread ();trace_colo_vm_state_change ("stop" ,"run" ); -/*TODO: COLO checkpoint savevm loop*/ +while (s->state ==MIGRATION_STATUS_COLO ) { +/* start a colo checkpoint */ + ret =colo_do_checkpoint_transaction (s); +if (ret <0 ) { + goto out; + } + } out:if (ret <0 ) {@@ -79,6 +193,39 @@ void migrate_start_colo_process(MigrationState *s)qemu_mutex_lock_iothread (); } +/* +* return: +* 0: start a checkpoint +* -1: some error happened, exit colo restore +*/ +static int colo_wait_handle_cmd (QEMUFile *f,int *checkpoint_request) +{ +int ret; +uint32_t cmd; +uint64_t value; +
migration/colo.c void migrate_start_colo_process(MigrationState *s) · line 216
Quoted 10 lines
migration/colo.c +10
-0+ ret =colo_ctl_get_cmd (f, &cmd); +if (ret <0 ) { +/* do failover ? */ +return ret; + } +/* Fix me: this value should be 0, which is not so good, +* should be used for checking ? +*/ + value =qemu_get_be64 (f); +if (value !=0 ) {
should output error message as well?
Quoted 120 lines
migration/colo.c +54
-1+return -EINVAL ; + } + +switch (cmd) { +case COLO_COMMAND_CHECKPOINT_REQUEST : + *checkpoint_request =1 ; +return 0 ; +default : +return -EINVAL ; + } +} +void *colo_process_incoming_thread (void *opaque) {MigrationIncomingState *mis = opaque;@@ -98,7 +245,48 @@ void *colo_process_incoming_thread(void *opaque)error_report ("colo incoming thread: Open QEMUFile to_src_file failed" ); goto out; } -/* TODO: COLO checkpoint restore loop */ + + ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_CHECKPOINT_READY ,0 ); +if (ret <0 ) { + goto out; + } + +while (mis->state ==MIGRATION_STATUS_COLO ) { +int request =0 ; +int ret =colo_wait_handle_cmd (mis->from_src_file, &request); + +if (ret <0 ) { +break ; + }else { +if (!request) { +continue ; + } + } + + ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_CHECKPOINT_REPLY ,0 ); +if (ret <0 ) { + goto out; + } + + ret =colo_ctl_get (mis->from_src_file,COLO_COMMAND_VMSTATE_SEND ); +if (ret <0 ) { + goto out; + } + +/* TODO: read migration data into colo buffer */ + + ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_VMSTATE_RECEIVED ,0 ); +if (ret <0 ) { + goto out; + } + +/* TODO: load vm state */ + + ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_VMSTATE_LOADED ,0 ); +if (ret <0 ) { + goto out; + } + } out:if (ret <0 ) {qapi-schema.json +27
-0@@ -702,6 +702,33 @@ '*tls-port': 'int', '*cert-subject': 'str' } } ## +# @COLOCommand +# +# The colo command +# +# @invalid: unknown command +# +# @checkpoint-ready: SVM is ready for checkpointing +# +# @checkpoint-request: PVM tells SVM to prepare for new checkpointing +# +# @checkpoint-reply: SVM gets PVM's checkpoint request +# +# @vmstate-send: VM's state will be sent by PVM. +# +# @vmstate-size: The total size of VMstate. +# +# @vmstate-received: VM's state has been received by SVM +# +# @vmstate-loaded: VM's state has been loaded by SVM +# +# Since: 2.5 +## +{ 'enum': 'COLOCommand', + 'data': [ 'invalid', 'checkpoint-ready', 'checkpoint-request', + 'checkpoint-reply', 'vmstate-send', 'vmstate-size', + 'vmstate-received', 'vmstate-loaded' ] } + # @MouseInfo: # # Information about a mouse device.trace-events +2
-0@@ -1499,6 +1499,8 @@ rdma_start_outgoing_migration_after_rdma_source_init(void) "" # migration/colo.c colo_vm_state_change(const char *old, const char *new) "Change '%s' => '%s'" +colo_ctl_put(const char *msg, uint64_t value) "Send '%s' cmd, value: %" PRIu64"" +colo_ctl_get(const char *msg) "Receive '%s' cmd" # kvm-all.c kvm_ioctl(int type, void *arg) "type 0x%x, arg %p"Signature · 1 line
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH COLO-Frame v10 09/38] COLO: Implement colo checkpoint protocol
Quoted 14 lines · Dr. David Alan Gilbert
Quoted 7 lines · * zhanghailiang ([email protected]) wrote:
We need communications protocol of user-defined to control the checkpoint process.
The new checkpoint request is started by Primary VM, and the interactive process like below:
Checkpoint synchronizing points,Quoted 5 lines
Primary Secondary
'checkpoint-request' @ ----------------------------->
Suspend (In hybrid mode)
'checkpoint-reply' <------------------------------ @
Suspend&Save state
Quoted 5 lines
Why is this initial pair necessary? Can't you just start with the vmstate-send and save the extra request pair/round trip? On the 2nd checkpoint we know the SVM already received the previous checkpoint because we got it's first vmstate-load.
Yes, we can certainly drop this handshaking in simple checkpoint mode.
But we still need to do some initial work (preparing work) in simple checkpoint mode. And i'm not sure if this initial work is time-wasting or not. We choose to do this preparing work before send the 'checkpoint-reply' to reducing VM's STOP time as possible as we can.
Quoted 2 lines
I guess in full-COLO (rather than simple checkpoint) you can get the secondary to do some of it's stopping/cleanup after it sends the checkpoint-reply
Actually, we do it before it sends 'checkpoint-reply' :)
Quoted 5 lines
but before vmstate-send, so you can hide some of the time.
(Perhaps add a comment to explain)
OK, I will add more comment about this.
Quoted 109 lines
Quoted 109 lines
'vmstate-send' @ ----------------------------->
Send state Receive state
'vmstate-received' <------------------------------ @
Release packets Load state
'vmstate-load' <------------------------------ @
Resume Resume (In hybrid mode)Start Comparing (In hybrid mode)
NOTE:
1) '@' who sends the message
2) Every sync-point is synchronized by two sides with only one handshake(single direction) for low-latency.
If more strict synchronization is required, a opposite direction sync-point should be added.
3) Since sync-points are single direction, the remote side may go forward a lot when this side just receives the sync-point.
4) For now, we only support 'periodic' checkpoint, for which the Secondary VM is not running, later we will support 'hybrid' mode.Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>Signed-off-by Gonglei <[email protected]>Cc Eric Blake <[email protected]>---
v10:
- Rename enum COLOCmd to COLOCommand (Eric's suggestion).
- Remove unused 'ram-steal'--- migration/colo.c | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- qapi-schema.json | 27 ++++++++ trace-events | 2 + 3 files changed, 219 insertions(+), 2 deletions(-)migration/colo.c +57
-0@@ -10,10 +10,12 @@* later. See the COPYING file in the top-level directory. */ +#include <unistd.h> #include "sysemu/sysemu.h" #include "migration/colo.h" #include "trace.h" #include "qemu/error-report.h" +#include "qemu/sockets.h" bool colo_supported (void ) {@@ -34,6 +36,103 @@ bool migration_incoming_in_colo_state(void)return mis && (mis->state ==MIGRATION_STATUS_COLO ); } +/* colo checkpoint control helper */ +static int colo_ctl_put (QEMUFile *f,uint32_t cmd,uint64_t value) +{ +int ret =0 ; + +qemu_put_be32 (f, cmd); +qemu_put_be64 (f, value); +qemu_fflush (f); + + ret =qemu_file_get_error (f); +trace_colo_ctl_put (COLOCommand_lookup[cmd], value); + +return ret; +} + +static int colo_ctl_get_cmd (QEMUFile *f,uint32_t *cmd) +{ +int ret =0 ; + + *cmd =qemu_get_be32 (f); + ret =qemu_file_get_error (f); +if (ret <0 ) { +return ret; + } +if (*cmd >=COLO_COMMAND_MAX ) { +error_report ("Invalid colo command, get cmd:%d" , *cmd); +return -EINVAL ; + } +trace_colo_ctl_get (COLOCommand_lookup[*cmd]); + +return 0 ; +} + +static int colo_ctl_get (QEMUFile *f,uint32_t require) +{ +int ret; +uint32_t cmd; +uint64_t value; + + ret =colo_ctl_get_cmd (f, &cmd); +if (ret <0 ) { +return ret; + } +if (cmd != require) { +error_report ("Unexpect colo command, expect:%d, but get cmd:%d" , + require, cmd); +return -EINVAL ; + } + + value =qemu_get_be64 (f); + ret =qemu_file_get_error (f); +if (ret <0 ) { +return ret; + } +
Quoted 9 lines
migration/colo.c bool migration_incoming_in_colo_state(void) · line 95
Quoted 2 lines
migration/colo.c +2
-0+return value; +}Should the return type be
uint64_tsince you're returning value? But then you're also using it to return an error code; so perhaps
it might be better to have auint64_t*value parameter to
return the value separately; or define the range that the value can actually take.
Good catch. Use parameter to return 'value' is a good idea, Will fix it in next version.
Thanks,
zhanghailiang
Quoted 226 lines
(Also very minor typo: 'got' not 'get' in a few errors)
Quoted 85 lines
migration/colo.c +65
-1+static int colo_do_checkpoint_transaction (MigrationState *s) +{ +int ret; + + ret =colo_ctl_put (s->to_dst_file,COLO_COMMAND_CHECKPOINT_REQUEST ,0 ); +if (ret <0 ) { + goto out; + } + + ret =colo_ctl_get (s->from_dst_file,COLO_COMMAND_CHECKPOINT_REPLY ); +if (ret <0 ) { + goto out; + } + +/* TODO: suspend and save vm state to colo buffer */ + + ret =colo_ctl_put (s->to_dst_file,COLO_COMMAND_VMSTATE_SEND ,0 ); +if (ret <0 ) { + goto out; + } + +/* TODO: send vmstate to Secondary */ + + ret =colo_ctl_get (s->from_dst_file,COLO_COMMAND_VMSTATE_RECEIVED ); +if (ret <0 ) { + goto out; + }> + + ret =colo_ctl_get (s->from_dst_file,COLO_COMMAND_VMSTATE_LOADED ); +if (ret <0 ) { + goto out; + } + +/* TODO: resume Primary */ + +out: +return ret; +} +static void colo_process_checkpoint (MigrationState *s) {int fd, ret =0 ;@@ -51,12 +150,27 @@ static void colo_process_checkpoint(MigrationState *s) goto out; } +/* +* Wait for Secondary finish loading vm states and enter COLO +* restore. +*/ + ret =colo_ctl_get (s->from_dst_file,COLO_COMMAND_CHECKPOINT_READY ); +if (ret <0 ) { + goto out; + } +qemu_mutex_lock_iothread ();vm_start ();qemu_mutex_unlock_iothread ();trace_colo_vm_state_change ("stop" ,"run" ); -/*TODO: COLO checkpoint savevm loop*/ +while (s->state ==MIGRATION_STATUS_COLO ) { +/* start a colo checkpoint */ + ret =colo_do_checkpoint_transaction (s); +if (ret <0 ) { + goto out; + } + } out:if (ret <0 ) {@@ -79,6 +193,39 @@ void migrate_start_colo_process(MigrationState *s)qemu_mutex_lock_iothread (); } +/* +* return: +* 0: start a checkpoint +* -1: some error happened, exit colo restore +*/ +static int colo_wait_handle_cmd (QEMUFile *f,int *checkpoint_request) +{ +int ret; +uint32_t cmd; +uint64_t value; +migration/colo.c void migrate_start_colo_process(MigrationState *s) · line 216
Quoted 10 lines
migration/colo.c +10
-0+ ret =colo_ctl_get_cmd (f, &cmd); +if (ret <0 ) { +/* do failover ? */ +return ret; + } +/* Fix me: this value should be 0, which is not so good, +* should be used for checking ? +*/ + value =qemu_get_be64 (f); +if (value !=0 ) {should output error message as well?
Quoted 117 lines
migration/colo.c +54
-1+return -EINVAL ; + } + +switch (cmd) { +case COLO_COMMAND_CHECKPOINT_REQUEST : + *checkpoint_request =1 ; +return 0 ; +default : +return -EINVAL ; + } +} +void *colo_process_incoming_thread (void *opaque) {MigrationIncomingState *mis = opaque;@@ -98,7 +245,48 @@ void *colo_process_incoming_thread(void *opaque)error_report ("colo incoming thread: Open QEMUFile to_src_file failed" ); goto out; } -/* TODO: COLO checkpoint restore loop */ + + ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_CHECKPOINT_READY ,0 ); +if (ret <0 ) { + goto out; + } + +while (mis->state ==MIGRATION_STATUS_COLO ) { +int request =0 ; +int ret =colo_wait_handle_cmd (mis->from_src_file, &request); + +if (ret <0 ) { +break ; + }else { +if (!request) { +continue ; + } + } + + ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_CHECKPOINT_REPLY ,0 ); +if (ret <0 ) { + goto out; + } + + ret =colo_ctl_get (mis->from_src_file,COLO_COMMAND_VMSTATE_SEND ); +if (ret <0 ) { + goto out; + } + +/* TODO: read migration data into colo buffer */ + + ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_VMSTATE_RECEIVED ,0 ); +if (ret <0 ) { + goto out; + } + +/* TODO: load vm state */ + + ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_VMSTATE_LOADED ,0 ); +if (ret <0 ) { + goto out; + } + } out:if (ret <0 ) {qapi-schema.json +27
-0@@ -702,6 +702,33 @@ '*tls-port': 'int', '*cert-subject': 'str' } } ## +# @COLOCommand +# +# The colo command +# +# @invalid: unknown command +# +# @checkpoint-ready: SVM is ready for checkpointing +# +# @checkpoint-request: PVM tells SVM to prepare for new checkpointing +# +# @checkpoint-reply: SVM gets PVM's checkpoint request +# +# @vmstate-send: VM's state will be sent by PVM. +# +# @vmstate-size: The total size of VMstate. +# +# @vmstate-received: VM's state has been received by SVM +# +# @vmstate-loaded: VM's state has been loaded by SVM +# +# Since: 2.5 +## +{ 'enum': 'COLOCommand', + 'data': [ 'invalid', 'checkpoint-ready', 'checkpoint-request', + 'checkpoint-reply', 'vmstate-send', 'vmstate-size', + 'vmstate-received', 'vmstate-loaded' ] } + # @MouseInfo: # # Information about a mouse device.trace-events +2
-1@@ -1499,6 +1499,8 @@ rdma_start_outgoing_migration_after_rdma_source_init(void) "" # migration/colo.c colo_vm_state_change(const char *old, const char *new) "Change '%s' => '%s'" +colo_ctl_put(const char *msg, uint64_t value) "Send '%s' cmd, value: %" PRIu64"" +colo_ctl_get(const char *msg) "Receive '%s' cmd" # kvm-all.c kvm_ioctl(int type, void *arg) "type 0x%x, arg %p" --Quoted 3 lines
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK.
Re: [Qemu-devel] [PATCH COLO-Frame v10 09/38] COLO: Implement colo checkpoint protocol
Quoted 15 lines · zhanghailiang
Quoted 14 lines · Dr. David Alan Gilbert
Quoted 12 lines · * zhanghailiang ([email protected]) wrote:
We need communications protocol of user-defined to control the checkpoint process.
The new checkpoint request is started by Primary VM, and the interactive process like below:
Checkpoint synchronizing points,Primary Secondary
'checkpoint-request' @ ----------------------------->
Suspend (In hybrid mode)
'checkpoint-reply' <------------------------------ @
Suspend&Save state
Quoted 6 lines
Quoted 5 lines
Why is this initial pair necessary? Can't you just start with the vmstate-send and save the extra request pair/round trip? On the 2nd checkpoint we know the SVM already received the previous checkpoint because we got it's first vmstate-load.
Er, i have made some mistake, before 'checkpoint-request' command, we have a 'checkpoint-ready' communication, which is sent by SVM to PVM, to tell PVM that SVM is ready for checkpoint. We do the initial work before send 'checkpoint-ready' in Secondary.
So, yes, you are right, this 'checkpoint-reply' is unnecessary for simple checkpoint mode. I will remove it or maybe just add more comment about this, and add 'checkpoint-ready' in the comment.
Quoted 370 lines
Yes, we can certainly drop this handshaking in simple checkpoint mode.
But we still need to do some initial work (preparing work) in simple checkpoint mode. And i'm not sure if this initial work is time-wasting or not. We choose to do this preparing work before send the 'checkpoint-reply' to reducing VM's STOP time as possible as we can.Quoted 2 lines
I guess in full-COLO (rather than simple checkpoint) you can get the secondary to do some of it's stopping/cleanup after it sends the checkpoint-reply
Actually, we do it before it sends 'checkpoint-reply' :)
Quoted 5 lines
but before vmstate-send, so you can hide some of the time.
(Perhaps add a comment to explain)
OK, I will add more comment about this.
Quoted 109 lines
Quoted 109 lines
'vmstate-send' @ ----------------------------->
Send state Receive state
'vmstate-received' <------------------------------ @
Release packets Load state
'vmstate-load' <------------------------------ @
Resume Resume (In hybrid mode)Start Comparing (In hybrid mode)
NOTE:
1) '@' who sends the message
2) Every sync-point is synchronized by two sides with only one handshake(single direction) for low-latency.
If more strict synchronization is required, a opposite direction sync-point should be added.
3) Since sync-points are single direction, the remote side may go forward a lot when this side just receives the sync-point.
4) For now, we only support 'periodic' checkpoint, for which the Secondary VM is not running, later we will support 'hybrid' mode.Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>Signed-off-by Gonglei <[email protected]>Cc Eric Blake <[email protected]>---
v10:
- Rename enum COLOCmd to COLOCommand (Eric's suggestion).
- Remove unused 'ram-steal'--- migration/colo.c | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- qapi-schema.json | 27 ++++++++ trace-events | 2 + 3 files changed, 219 insertions(+), 2 deletions(-)migration/colo.c +57
-0@@ -10,10 +10,12 @@* later. See the COPYING file in the top-level directory. */ +#include <unistd.h> #include "sysemu/sysemu.h" #include "migration/colo.h" #include "trace.h" #include "qemu/error-report.h" +#include "qemu/sockets.h" bool colo_supported (void ) {@@ -34,6 +36,103 @@ bool migration_incoming_in_colo_state(void)return mis && (mis->state ==MIGRATION_STATUS_COLO ); } +/* colo checkpoint control helper */ +static int colo_ctl_put (QEMUFile *f,uint32_t cmd,uint64_t value) +{ +int ret =0 ; + +qemu_put_be32 (f, cmd); +qemu_put_be64 (f, value); +qemu_fflush (f); + + ret =qemu_file_get_error (f); +trace_colo_ctl_put (COLOCommand_lookup[cmd], value); + +return ret; +} + +static int colo_ctl_get_cmd (QEMUFile *f,uint32_t *cmd) +{ +int ret =0 ; + + *cmd =qemu_get_be32 (f); + ret =qemu_file_get_error (f); +if (ret <0 ) { +return ret; + } +if (*cmd >=COLO_COMMAND_MAX ) { +error_report ("Invalid colo command, get cmd:%d" , *cmd); +return -EINVAL ; + } +trace_colo_ctl_get (COLOCommand_lookup[*cmd]); + +return 0 ; +} + +static int colo_ctl_get (QEMUFile *f,uint32_t require) +{ +int ret; +uint32_t cmd; +uint64_t value; + + ret =colo_ctl_get_cmd (f, &cmd); +if (ret <0 ) { +return ret; + } +if (cmd != require) { +error_report ("Unexpect colo command, expect:%d, but get cmd:%d" , + require, cmd); +return -EINVAL ; + } + + value =qemu_get_be64 (f); + ret =qemu_file_get_error (f); +if (ret <0 ) { +return ret; + } +Quoted 9 lines
migration/colo.c bool migration_incoming_in_colo_state(void) · line 95
Quoted 2 lines
migration/colo.c +2
-0+return value; +}Should the return type be
uint64_tsince you're returning value? But then you're also using it to return an error code; so perhaps
it might be better to have auint64_t*value parameter to
return the value separately; or define the range that the value can actually take.Good catch. Use parameter to return 'value' is a good idea, Will fix it in next version.
Thanks,
zhanghailiangQuoted 226 lines
(Also very minor typo: 'got' not 'get' in a few errors)
Quoted 85 lines
migration/colo.c +65
-1+static int colo_do_checkpoint_transaction (MigrationState *s) +{ +int ret; + + ret =colo_ctl_put (s->to_dst_file,COLO_COMMAND_CHECKPOINT_REQUEST ,0 ); +if (ret <0 ) { + goto out; + } + + ret =colo_ctl_get (s->from_dst_file,COLO_COMMAND_CHECKPOINT_REPLY ); +if (ret <0 ) { + goto out; + } + +/* TODO: suspend and save vm state to colo buffer */ + + ret =colo_ctl_put (s->to_dst_file,COLO_COMMAND_VMSTATE_SEND ,0 ); +if (ret <0 ) { + goto out; + } + +/* TODO: send vmstate to Secondary */ + + ret =colo_ctl_get (s->from_dst_file,COLO_COMMAND_VMSTATE_RECEIVED ); +if (ret <0 ) { + goto out; + }> + + ret =colo_ctl_get (s->from_dst_file,COLO_COMMAND_VMSTATE_LOADED ); +if (ret <0 ) { + goto out; + } + +/* TODO: resume Primary */ + +out: +return ret; +} +static void colo_process_checkpoint (MigrationState *s) {int fd, ret =0 ;@@ -51,12 +150,27 @@ static void colo_process_checkpoint(MigrationState *s) goto out; } +/* +* Wait for Secondary finish loading vm states and enter COLO +* restore. +*/ + ret =colo_ctl_get (s->from_dst_file,COLO_COMMAND_CHECKPOINT_READY ); +if (ret <0 ) { + goto out; + } +qemu_mutex_lock_iothread ();vm_start ();qemu_mutex_unlock_iothread ();trace_colo_vm_state_change ("stop" ,"run" ); -/*TODO: COLO checkpoint savevm loop*/ +while (s->state ==MIGRATION_STATUS_COLO ) { +/* start a colo checkpoint */ + ret =colo_do_checkpoint_transaction (s); +if (ret <0 ) { + goto out; + } + } out:if (ret <0 ) {@@ -79,6 +193,39 @@ void migrate_start_colo_process(MigrationState *s)qemu_mutex_lock_iothread (); } +/* +* return: +* 0: start a checkpoint +* -1: some error happened, exit colo restore +*/ +static int colo_wait_handle_cmd (QEMUFile *f,int *checkpoint_request) +{ +int ret; +uint32_t cmd; +uint64_t value; +migration/colo.c void migrate_start_colo_process(MigrationState *s) · line 216
Quoted 10 lines
migration/colo.c +10
-0+ ret =colo_ctl_get_cmd (f, &cmd); +if (ret <0 ) { +/* do failover ? */ +return ret; + } +/* Fix me: this value should be 0, which is not so good, +* should be used for checking ? +*/ + value =qemu_get_be64 (f); +if (value !=0 ) {should output error message as well?
Quoted 117 lines
migration/colo.c +54
-1+return -EINVAL ; + } + +switch (cmd) { +case COLO_COMMAND_CHECKPOINT_REQUEST : + *checkpoint_request =1 ; +return 0 ; +default : +return -EINVAL ; + } +} +void *colo_process_incoming_thread (void *opaque) {MigrationIncomingState *mis = opaque;@@ -98,7 +245,48 @@ void *colo_process_incoming_thread(void *opaque)error_report ("colo incoming thread: Open QEMUFile to_src_file failed" ); goto out; } -/* TODO: COLO checkpoint restore loop */ + + ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_CHECKPOINT_READY ,0 ); +if (ret <0 ) { + goto out; + } + +while (mis->state ==MIGRATION_STATUS_COLO ) { +int request =0 ; +int ret =colo_wait_handle_cmd (mis->from_src_file, &request); + +if (ret <0 ) { +break ; + }else { +if (!request) { +continue ; + } + } + + ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_CHECKPOINT_REPLY ,0 ); +if (ret <0 ) { + goto out; + } + + ret =colo_ctl_get (mis->from_src_file,COLO_COMMAND_VMSTATE_SEND ); +if (ret <0 ) { + goto out; + } + +/* TODO: read migration data into colo buffer */ + + ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_VMSTATE_RECEIVED ,0 ); +if (ret <0 ) { + goto out; + } + +/* TODO: load vm state */ + + ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_VMSTATE_LOADED ,0 ); +if (ret <0 ) { + goto out; + } + } out:if (ret <0 ) {qapi-schema.json +27
-0@@ -702,6 +702,33 @@ '*tls-port': 'int', '*cert-subject': 'str' } } ## +# @COLOCommand +# +# The colo command +# +# @invalid: unknown command +# +# @checkpoint-ready: SVM is ready for checkpointing +# +# @checkpoint-request: PVM tells SVM to prepare for new checkpointing +# +# @checkpoint-reply: SVM gets PVM's checkpoint request +# +# @vmstate-send: VM's state will be sent by PVM. +# +# @vmstate-size: The total size of VMstate. +# +# @vmstate-received: VM's state has been received by SVM +# +# @vmstate-loaded: VM's state has been loaded by SVM +# +# Since: 2.5 +## +{ 'enum': 'COLOCommand', + 'data': [ 'invalid', 'checkpoint-ready', 'checkpoint-request', + 'checkpoint-reply', 'vmstate-send', 'vmstate-size', + 'vmstate-received', 'vmstate-loaded' ] } + # @MouseInfo: # # Information about a mouse device.trace-events +2
-1@@ -1499,6 +1499,8 @@ rdma_start_outgoing_migration_after_rdma_source_init(void) "" # migration/colo.c colo_vm_state_change(const char *old, const char *new) "Change '%s' => '%s'" +colo_ctl_put(const char *msg, uint64_t value) "Send '%s' cmd, value: %" PRIu64"" +colo_ctl_get(const char *msg) "Receive '%s' cmd" # kvm-all.c kvm_ioctl(int type, void *arg) "type 0x%x, arg %p" --Quoted 3 lines
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK.
Re: [Qemu-devel] [PATCH COLO-Frame v10 09/38] COLO: Implement colo checkpoint protocol
In reply to zhanghailiangQuoted 31 lines · zhanghailiang
We need communications protocol of user-defined to control the checkpoint process.
The new checkpoint request is started by Primary VM, and the interactive process like below:
Checkpoint synchronizing points,Primary Secondary
'checkpoint-request' @ ----------------------------->
Suspend (In hybrid mode)
'checkpoint-reply' <------------------------------ @
Suspend&Save state
'vmstate-send' @ ----------------------------->
Send state Receive state
'vmstate-received' <------------------------------ @
Release packets Load state
'vmstate-load' <------------------------------ @
Resume Resume (In hybrid mode)Start Comparing (In hybrid mode)
NOTE:
1) '@' who sends the message
2) Every sync-point is synchronized by two sides with only one handshake(single direction) for low-latency.
If more strict synchronization is required, a opposite direction sync-point should be added.
3) Since sync-points are single direction, the remote side may go forward a lot when this side just receives the sync-point.
4) For now, we only support 'periodic' checkpoint, for which the Secondary VM is not running, later we will support 'hybrid' mode.
Quoted 8 lines
Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>Signed-off-by Gonglei <[email protected]>Cc Eric Blake <[email protected]>---
v10:
- Rename enum COLOCmd to COLOCommand (Eric's suggestion).
- Remove unused 'ram-steal'
Interface review only:
qapi-schema.json line 707
Quoted 8 lines
+++
b/qapi-schema.jsonqapi-schema.json +3
-0@@ -702,6 +702,33 @@ '*tls-port': 'int', '*cert-subject': 'str' } } ## +# @COLOCommand +# +# The colo command
Still might be nice to spell out what COLO means here, but it's fairly obvious this will be related to anything else COLO, so I'm not too worried.
Quoted 8 lines
qapi-schema.json +8
-0+# +# @invalid: unknown command +# +# @checkpoint-ready: SVM is ready for checkpointing +# +# @checkpoint-request: PVM tells SVM to prepare for new checkpointing +# +# @checkpoint-reply: SVM gets PVM's checkpoint request
qapi-schema.json line 725
Quoted 10 lines
qapi-schema.json +10
-0+# +# @vmstate-send: VM's state will be sent by PVM. +# +# @vmstate-size: The total size of VMstate. +# +# @vmstate-received: VM's state has been received by SVM +# +# @vmstate-loaded: VM's state has been loaded by SVM +# +# Since: 2.5
Will need a tweak to say 2.6. Otherwise looks okay.
Quoted 6 lines
qapi-schema.json +6
-0+## +{ 'enum': 'COLOCommand', + 'data': [ 'invalid', 'checkpoint-ready', 'checkpoint-request', + 'checkpoint-reply', 'vmstate-send', 'vmstate-size', + 'vmstate-received', 'vmstate-loaded' ] } +
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH COLO-Frame v10 09/38] COLO: Implement colo checkpoint protocol
Quoted 48 lines · Eric Blake
Quoted 31 lines · zhanghailiang
We need communications protocol of user-defined to control the checkpoint process.
The new checkpoint request is started by Primary VM, and the interactive process like below:
Checkpoint synchronizing points,Primary Secondary
'checkpoint-request' @ ----------------------------->
Suspend (In hybrid mode)
'checkpoint-reply' <------------------------------ @
Suspend&Save state
'vmstate-send' @ ----------------------------->
Send state Receive state
'vmstate-received' <------------------------------ @
Release packets Load state
'vmstate-load' <------------------------------ @
Resume Resume (In hybrid mode)Start Comparing (In hybrid mode)
NOTE:
1) '@' who sends the message
2) Every sync-point is synchronized by two sides with only one handshake(single direction) for low-latency.
If more strict synchronization is required, a opposite direction sync-point should be added.
3) Since sync-points are single direction, the remote side may go forward a lot when this side just receives the sync-point.
4) For now, we only support 'periodic' checkpoint, for which the Secondary VM is not running, later we will support 'hybrid' mode.Quoted 8 lines
Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>Signed-off-by Gonglei <[email protected]>Cc Eric Blake <[email protected]>---
v10:
- Rename enum COLOCmd to COLOCommand (Eric's suggestion).
- Remove unused 'ram-steal'Interface review only:
Quoted 4 lines
+++
b/qapi-schema.jsonqapi-schema.json +0
-0@@ -702,6 +702,33 @@ '*tls-port': 'int', '*cert-subject': 'str' } }
Quoted 8 lines
qapi-schema.json line 707
Quoted 4 lines
qapi-schema.json +3
-0## +# @COLOCommand +# +# The colo commandStill might be nice to spell out what COLO means here, but it's fairly obvious this will be related to anything else COLO, so I'm not too worried.
Hmm, i think the best way to solve the abbreviation problem is to give the full name where it appears for the first time ;)
Quoted 12 lines
Quoted 12 lines
qapi-schema.json +12
-0+# +# @invalid: unknown command +# +# @checkpoint-ready: SVM is ready for checkpointing +# +# @checkpoint-request: PVM tells SVM to prepare for new checkpointing +# +# @checkpoint-reply: SVM gets PVM's checkpoint request +# +# @vmstate-send: VM's state will be sent by PVM. +# +# @vmstate-size: The total size of VMstate.
Quoted 9 lines
qapi-schema.json line 725
Quoted 6 lines
qapi-schema.json +6
-0+# +# @vmstate-received: VM's state has been received by SVM +# +# @vmstate-loaded: VM's state has been loaded by SVM +# +# Since: 2.5Will need a tweak to say 2.6. Otherwise looks okay.
OK, i will update it. Thanks.
Quoted 8 lines
Quoted 6 lines
qapi-schema.json +6
-0+## +{ 'enum': 'COLOCommand', + 'data': [ 'invalid', 'checkpoint-ready', 'checkpoint-request', + 'checkpoint-reply', 'vmstate-send', 'vmstate-size', + 'vmstate-received', 'vmstate-loaded' ] } +
PATCH v10 10/38 COLO: Add a new RunState RUN_STATE_COLO
In reply to zhanghailiangGuest will enter this state when paused to save/restore VM state under colo checkpoint.
--- qapi-schema.json | 7 ++++++- vl.c | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-)
qapi-schema.json +6 -1
@@ -154,12 +154,15 @@ # @watchdog: the watchdog action is configured to pause and has been triggered # # @guest-panicked: guest has been panicked as a result of guest OS panic +# +# @colo: guest is paused to save/restore VM state under colo checkpoint (since +# 2.5) ## { 'enum': 'RunState', 'data': [ 'debug', 'inmigrate', 'internal-error', 'io-error', 'paused', 'postmigrate', 'prelaunch', 'finish-migrate', 'restore-vm', 'running', 'save-vm', 'shutdown', 'suspended', 'watchdog', - 'guest-panicked' ] } + 'guest-panicked', 'colo' ] } ## # @StatusInfo:
@@ -434,6 +437,8 @@ # # @failed: some error occurred during migration process. # +# @colo: VM is in the process of fault tolerance. (since 2.5) +# # Since: 2.3 # ##
vl.c +8 -0
@@ -586,6 +586,7 @@ static const RunStateTransition runstate_transitions_def[] = { { RUN_STATE_INMIGRATE, RUN_STATE_WATCHDOG }, { RUN_STATE_INMIGRATE, RUN_STATE_GUEST_PANICKED }, { RUN_STATE_INMIGRATE, RUN_STATE_FINISH_MIGRATE }, + { RUN_STATE_INMIGRATE, RUN_STATE_COLO }, { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PAUSED }, { RUN_STATE_INTERNAL_ERROR, RUN_STATE_FINISH_MIGRATE },
@@ -595,6 +596,7 @@ static const RunStateTransition runstate_transitions_def[] = { { RUN_STATE_PAUSED, RUN_STATE_RUNNING }, { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE }, + { RUN_STATE_PAUSED, RUN_STATE_COLO}, { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING }, { RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE },
@@ -605,9 +607,12 @@ static const RunStateTransition runstate_transitions_def[] = { { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING }, { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE }, + { RUN_STATE_FINISH_MIGRATE, RUN_STATE_COLO}, { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING }, + { RUN_STATE_COLO, RUN_STATE_RUNNING }, + { RUN_STATE_RUNNING, RUN_STATE_DEBUG }, { RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR }, { RUN_STATE_RUNNING, RUN_STATE_IO_ERROR },
@@ -618,6 +623,7 @@ static const RunStateTransition runstate_transitions_def[] = { { RUN_STATE_RUNNING, RUN_STATE_SHUTDOWN }, { RUN_STATE_RUNNING, RUN_STATE_WATCHDOG }, { RUN_STATE_RUNNING, RUN_STATE_GUEST_PANICKED }, + { RUN_STATE_RUNNING, RUN_STATE_COLO}, { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING },
@@ -628,9 +634,11 @@ static const RunStateTransition runstate_transitions_def[] = { { RUN_STATE_RUNNING, RUN_STATE_SUSPENDED }, { RUN_STATE_SUSPENDED, RUN_STATE_RUNNING }, { RUN_STATE_SUSPENDED, RUN_STATE_FINISH_MIGRATE }, + { RUN_STATE_SUSPENDED, RUN_STATE_COLO}, { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING }, { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE }, + { RUN_STATE_WATCHDOG, RUN_STATE_COLO}, { RUN_STATE_GUEST_PANICKED, RUN_STATE_RUNNING }, { RUN_STATE_GUEST_PANICKED, RUN_STATE_FINISH_MIGRATE },
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH COLO-Frame v10 10/38] COLO: Add a new RunState RUN_STATE_COLO
Quoted 2 lines · * zhanghailiang ([email protected]) wrote:
Guest will enter this state when paused to save/restore VM state under colo checkpoint.
Quoted 100 lines
Cc Eric Blake <[email protected]>Cc Markus Armbruster <[email protected]>Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>Signed-off-by Gonglei <[email protected]>Reviewed-by Dr. David Alan Gilbert <[email protected]>Reviewed-by Eric Blake <[email protected]>--- qapi-schema.json | 7 ++++++- vl.c | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-)qapi-schema.json +6
-1@@ -154,12 +154,15 @@ # @watchdog: the watchdog action is configured to pause and has been triggered # # @guest-panicked: guest has been panicked as a result of guest OS panic +# +# @colo: guest is paused to save/restore VM state under colo checkpoint (since +# 2.5) ## { 'enum': 'RunState', 'data': [ 'debug', 'inmigrate', 'internal-error', 'io-error', 'paused', 'postmigrate', 'prelaunch', 'finish-migrate', 'restore-vm', 'running', 'save-vm', 'shutdown', 'suspended', 'watchdog', - 'guest-panicked' ] } + 'guest-panicked', 'colo' ] } ## # @StatusInfo:@@ -434,6 +437,8 @@ # # @failed: some error occurred during migration process. # +# @colo: VM is in the process of fault tolerance. (since 2.5) +# # Since: 2.3 # ##vl.c +8
-0@@ -586,6 +586,7 @@ static const RunStateTransition runstate_transitions_def[] = { { RUN_STATE_INMIGRATE, RUN_STATE_WATCHDOG }, { RUN_STATE_INMIGRATE, RUN_STATE_GUEST_PANICKED }, { RUN_STATE_INMIGRATE, RUN_STATE_FINISH_MIGRATE }, + { RUN_STATE_INMIGRATE, RUN_STATE_COLO }, { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PAUSED }, { RUN_STATE_INTERNAL_ERROR, RUN_STATE_FINISH_MIGRATE },@@ -595,6 +596,7 @@ static const RunStateTransition runstate_transitions_def[] = { { RUN_STATE_PAUSED, RUN_STATE_RUNNING }, { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE }, + { RUN_STATE_PAUSED, RUN_STATE_COLO}, { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING }, { RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE },@@ -605,9 +607,12 @@ static const RunStateTransition runstate_transitions_def[] = { { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING }, { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE }, + { RUN_STATE_FINISH_MIGRATE, RUN_STATE_COLO}, { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING }, + { RUN_STATE_COLO, RUN_STATE_RUNNING }, + { RUN_STATE_RUNNING, RUN_STATE_DEBUG }, { RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR }, { RUN_STATE_RUNNING, RUN_STATE_IO_ERROR },@@ -618,6 +623,7 @@ static const RunStateTransition runstate_transitions_def[] = { { RUN_STATE_RUNNING, RUN_STATE_SHUTDOWN }, { RUN_STATE_RUNNING, RUN_STATE_WATCHDOG }, { RUN_STATE_RUNNING, RUN_STATE_GUEST_PANICKED }, + { RUN_STATE_RUNNING, RUN_STATE_COLO}, { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING },@@ -628,9 +634,11 @@ static const RunStateTransition runstate_transitions_def[] = { { RUN_STATE_RUNNING, RUN_STATE_SUSPENDED }, { RUN_STATE_SUSPENDED, RUN_STATE_RUNNING }, { RUN_STATE_SUSPENDED, RUN_STATE_FINISH_MIGRATE }, + { RUN_STATE_SUSPENDED, RUN_STATE_COLO}, { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING }, { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE }, + { RUN_STATE_WATCHDOG, RUN_STATE_COLO}, { RUN_STATE_GUEST_PANICKED, RUN_STATE_RUNNING }, { RUN_STATE_GUEST_PANICKED, RUN_STATE_FINISH_MIGRATE },Signature · 1 line
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH COLO-Frame v10 10/38] COLO: Add a new RunState RUN_STATE_COLO
In reply to zhanghailiangQuoted 20 lines · zhanghailiang
Guest will enter this state when paused to save/restore VM state under colo checkpoint.
Cc Eric Blake <[email protected]>Cc Markus Armbruster <[email protected]>Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>Signed-off-by Gonglei <[email protected]>Reviewed-by Dr. David Alan Gilbert <[email protected]>Reviewed-by Eric Blake <[email protected]>--- qapi-schema.json | 7 ++++++- vl.c | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-)qapi-schema.json +0
-0
qapi-schema.json line 159
Quoted 6 lines
qapi-schema.json +3
-0@@ -154,12 +154,15 @@ # @watchdog: the watchdog action is configured to pause and has been triggered # # @guest-panicked: guest has been panicked as a result of guest OS panic +# +# @colo: guest is paused to save/restore VM state under colo checkpoint (since +# 2.5)
Will need a tweak to 2.6;
Quoted 11 lines
qapi-schema.json +1
-1## { 'enum': 'RunState', 'data': [ 'debug', 'inmigrate', 'internal-error', 'io-error', 'paused', 'postmigrate', 'prelaunch', 'finish-migrate', 'restore-vm', 'running', 'save-vm', 'shutdown', 'suspended', 'watchdog', - 'guest-panicked' ] } + 'guest-panicked', 'colo' ] } ## # @StatusInfo:
qapi-schema.json line 440
Quoted 4 lines
qapi-schema.json +1
-0@@ -434,6 +437,8 @@ # # @failed: some error occurred during migration process. # +# @colo: VM is in the process of fault tolerance. (since 2.5)
Likewise. But my R-b still stands after that minor tweak.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH COLO-Frame v10 10/38] COLO: Add a new RunState RUN_STATE_COLO
Quoted 16 lines · Eric Blake
Quoted 15 lines · zhanghailiang
Guest will enter this state when paused to save/restore VM state under colo checkpoint.
Cc Eric Blake <[email protected]>Cc Markus Armbruster <[email protected]>Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>Signed-off-by Gonglei <[email protected]>Reviewed-by Dr. David Alan Gilbert <[email protected]>Reviewed-by Eric Blake <[email protected]>--- qapi-schema.json | 7 ++++++- vl.c | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-)
Quoted 14 lines
qapi-schema.json line 159
Quoted 11 lines
qapi-schema.json +3
-0@@ -154,12 +154,15 @@ # @watchdog: the watchdog action is configured to pause and has been triggered # # @guest-panicked: guest has been panicked as a result of guest OS panic +# +# @colo: guest is paused to save/restore VM state under colo checkpoint (since +# 2.5)Will need a tweak to 2.6;
OK, i will update it in next version
Quoted 8 lines
Quoted 8 lines
qapi-schema.json +1
-1## { 'enum': 'RunState', 'data': [ 'debug', 'inmigrate', 'internal-error', 'io-error', 'paused', 'postmigrate', 'prelaunch', 'finish-migrate', 'restore-vm', 'running', 'save-vm', 'shutdown', 'suspended', 'watchdog', - 'guest-panicked' ] } + 'guest-panicked', 'colo' ] }
Quoted 10 lines
qapi-schema.json line 440
Quoted 7 lines
qapi-schema.json +1
-0## # @StatusInfo:@@ -434,6 +437,8 @@ # # @failed: some error occurred during migration process. # +# @colo: VM is in the process of fault tolerance. (since 2.5)Likewise. But my R-b still stands after that minor tweak.
Thanks.
PATCH v10 11/38 QEMUSizedBuffer: Introduce two help functions for qsb
In reply to zhanghailiangIntroduce two new QEMUSizedBuffer APIs which will be used by COLO to buffer VM state:
One is qsb_put_buffer(), which put the content of a given QEMUSizedBuffer into QEMUFile, this is used to send buffered VM state to secondary. Another is qsb_fill_buffer(), read 'size' bytes of data from the file into qsb, this is used to get VM state from socket into a buffer.
--- include/migration/qemu-file.h | 3 ++- migration/qemu-file-buf.c | 58 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-)
include/migration/qemu-file.h +2 -1
@@ -144,7 +144,8 @@ ssize_t qsb_get_buffer(const QEMUSizedBuffer *, off_t start, size_t count, uint8_t *buf);ssize_t qsb_write_at (QEMUSizedBuffer *qsb,const uint8_t *buf,off_t pos,size_t count); - +void qsb_put_buffer (QEMUFile *f,QEMUSizedBuffer *qsb,int size); +int qsb_fill_buffer (QEMUSizedBuffer *qsb,QEMUFile *f,int size);/* * For use on files opened with qemu_bufopen
migration/qemu-file-buf.c +58 -0
64 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH COLO-Frame v10 11/38] QEMUSizedBuffer: Introduce two help functions for qsb
Quoted 20 lines · * zhanghailiang ([email protected]) wrote:
Introduce two new QEMUSizedBuffer APIs which will be used by COLO to buffer VM state:
One isqsb_put_buffer(), which put the content of a given QEMUSizedBuffer into QEMUFile, this is used to send buffered VM state to secondary. Another isqsb_fill_buffer(), read 'size' bytes of data from the file into qsb, this is used to get VM state from socket into a buffer.Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>Reviewed-by Dr. David Alan Gilbert <[email protected]>--- include/migration/qemu-file.h | 3 ++- migration/qemu-file-buf.c | 58 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-)include/migration/qemu-file.h +0
-0
include/migration/qemu-file.h ssize_t qsb_get_buffer(const QEMUSizedBuffer *, off_t start, size_t count, · line 148
Quoted 6 lines
include/migration/qemu-file.h +2
-1@@ -144,7 +144,8 @@ ssize_t qsb_get_buffer(const QEMUSizedBuffer *, off_t start, size_t count, uint8_t *buf);ssize_t qsb_write_at (QEMUSizedBuffer *qsb,const uint8_t *buf,off_t pos,size_t count); - +void qsb_put_buffer (QEMUFile *f,QEMUSizedBuffer *qsb,int size); +int qsb_fill_buffer (QEMUSizedBuffer *qsb,QEMUFile *f,int size);
I made most of the qemu_file use size_t back in August; cna you update this please.
Dave
Quoted 76 lines
include/migration/qemu-file.h +0
-0/* * For use on files opened with qemu_bufopen migration/qemu-file-buf.c +58
-0@@ -366,6 +366,64 @@ ssize_t qsb_write_at(QEMUSizedBuffer *qsb, const uint8_t *source,return count; } + +/** +* Put the content of a given QEMUSizedBuffer into QEMUFile. +* +* @f: A QEMUFile +* @qsb: A QEMUSizedBuffer +* @size: size of content to write +*/ +void qsb_put_buffer (QEMUFile *f,QEMUSizedBuffer *qsb,int size) +{ +int i, l; + +for (i =0 ; i < qsb->n_iov && size >0 ; i++) { + l =MIN (qsb->iov[i].iov_len, size); +qemu_put_buffer (f, qsb->iov[i].iov_base, l); + size -= l; + } +} + +/* +* Read 'size' bytes of data from the file into qsb. +* always fill from pos 0 and used after qsb_create(). +* +* It will return size bytes unless there was an error, in which case it will +* return as many as it managed to read (assuming blocking fd's which +* all current QEMUFile are) +*/ +int qsb_fill_buffer (QEMUSizedBuffer *qsb,QEMUFile *f,int size) +{ +ssize_t rc =qsb_grow (qsb, size); +int pending = size, i; + qsb->used =0 ; +uint8_t *buf =NULL ; + +if (rc <0 ) { +return rc; + } + +for (i =0 ; i < qsb->n_iov && pending >0 ; i++) { +int doneone =0 ; +/* read until iov full */ +while (doneone < qsb->iov[i].iov_len && pending >0 ) { +int readone =0 ; + buf = qsb->iov[i].iov_base; + readone =qemu_get_buffer (f, buf, +MIN (qsb->iov[i].iov_len - doneone, pending)); +if (readone ==0 ) { +return qsb->used; + } + buf += readone; + doneone += readone; + pending -= readone; + qsb->used += readone; + } + } +return qsb->used; +} + typedef struct QEMUBuffer { QEMUSizedBuffer *qsb; QEMUFile *file;Signature · 1 line
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH COLO-Frame v10 11/38] QEMUSizedBuffer: Introduce two help functions for qsb
Quoted 16 lines · Dr. David Alan Gilbert
Quoted 15 lines · * zhanghailiang ([email protected]) wrote:
Introduce two new QEMUSizedBuffer APIs which will be used by COLO to buffer VM state:
One isqsb_put_buffer(), which put the content of a given QEMUSizedBuffer into QEMUFile, this is used to send buffered VM state to secondary. Another isqsb_fill_buffer(), read 'size' bytes of data from the file into qsb, this is used to get VM state from socket into a buffer.Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>Reviewed-by Dr. David Alan Gilbert <[email protected]>--- include/migration/qemu-file.h | 3 ++- migration/qemu-file-buf.c | 58 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-)
Quoted 14 lines
include/migration/qemu-file.h ssize_t qsb_get_buffer(const QEMUSizedBuffer *, off_t start, size_t count, · line 148
Quoted 11 lines
include/migration/qemu-file.h +2
-1@@ -144,7 +144,8 @@ ssize_t qsb_get_buffer(const QEMUSizedBuffer *, off_t start, size_t count, uint8_t *buf);ssize_t qsb_write_at (QEMUSizedBuffer *qsb,const uint8_t *buf,off_t pos,size_t count); - +void qsb_put_buffer (QEMUFile *f,QEMUSizedBuffer *qsb,int size); +int qsb_fill_buffer (QEMUSizedBuffer *qsb,QEMUFile *f,int size);I made most of the
qemu_fileusesize_tback in August; cna you update this please.
Of course, Will do that in next version, thanks.
Quoted 83 lines
Dave
Quoted 73 lines
include/migration/qemu-file.h +0
-0/* * For use on files opened with qemu_bufopen migration/qemu-file-buf.c +58
-1@@ -366,6 +366,64 @@ ssize_t qsb_write_at(QEMUSizedBuffer *qsb, const uint8_t *source,return count; } + +/** +* Put the content of a given QEMUSizedBuffer into QEMUFile. +* +* @f: A QEMUFile +* @qsb: A QEMUSizedBuffer +* @size: size of content to write +*/ +void qsb_put_buffer (QEMUFile *f,QEMUSizedBuffer *qsb,int size) +{ +int i, l; + +for (i =0 ; i < qsb->n_iov && size >0 ; i++) { + l =MIN (qsb->iov[i].iov_len, size); +qemu_put_buffer (f, qsb->iov[i].iov_base, l); + size -= l; + } +} + +/* +* Read 'size' bytes of data from the file into qsb. +* always fill from pos 0 and used after qsb_create(). +* +* It will return size bytes unless there was an error, in which case it will +* return as many as it managed to read (assuming blocking fd's which +* all current QEMUFile are) +*/ +int qsb_fill_buffer (QEMUSizedBuffer *qsb,QEMUFile *f,int size) +{ +ssize_t rc =qsb_grow (qsb, size); +int pending = size, i; + qsb->used =0 ; +uint8_t *buf =NULL ; + +if (rc <0 ) { +return rc; + } + +for (i =0 ; i < qsb->n_iov && pending >0 ; i++) { +int doneone =0 ; +/* read until iov full */ +while (doneone < qsb->iov[i].iov_len && pending >0 ) { +int readone =0 ; + buf = qsb->iov[i].iov_base; + readone =qemu_get_buffer (f, buf, +MIN (qsb->iov[i].iov_len - doneone, pending)); +if (readone ==0 ) { +return qsb->used; + } + buf += readone; + doneone += readone; + pending -= readone; + qsb->used += readone; + } + } +return qsb->used; +} + typedef struct QEMUBuffer { QEMUSizedBuffer *qsb; QEMUFile *file; --Quoted 3 lines
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK.
PATCH v10 12/38 COLO: Save PVM state to secondary side when do checkpoint
In reply to zhanghailiangThe main process of checkpoint is to synchronize SVM with PVM. VM's state includes ram and device state. So we will migrate PVM's state to SVM when do checkpoint, just like migration does.
We will cache PVM's state in slave, we use QEMUSizedBuffer
to store the data, we need to know the size of VM state, so in master, we use qsb to store VM state temporarily, get the data size by call qsb_get_length() and then migrate the data to the qsb in the secondary side.
--- migration/colo.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++---- migration/ram.c | 47 +++++++++++++++++++++++++++++-------- migration/savevm.c | 2 +- 3 files changed, 101 insertions(+), 16 deletions(-)
migration/colo.c +63 -5
@@ -17,6 +17,9 @@#include "qemu/error-report.h" #include "qemu/sockets.h" +/* colo buffer */ +#define COLO_BUFFER_BASE_SIZE (4 * 1024 * 1024) +bool colo_supported (void ) {return true;
@@ -94,9 +97,12 @@ static int colo_ctl_get(QEMUFile *f, uint32_t require)return value; } -static int colo_do_checkpoint_transaction (MigrationState *s) +static int colo_do_checkpoint_transaction (MigrationState *s, +QEMUSizedBuffer *buffer) {int ret; +size_t size; +QEMUFile *trans =NULL ; ret =colo_ctl_put (s->to_dst_file,COLO_COMMAND_CHECKPOINT_REQUEST ,0 );if (ret <0 ) {
@@ -107,15 +113,47 @@ static int colo_do_checkpoint_transaction(MigrationState *s)if (ret <0 ) { goto out; } +/* Reset colo buffer and open it for write */ +qsb_set_length (buffer,0 ); + trans =qemu_bufopen ("w" , buffer); +if (!trans) { +error_report ("Open colo buffer for write failed" ); + goto out; + } -/* TODO: suspend and save vm state to colo buffer */ +qemu_mutex_lock_iothread (); +vm_stop_force_state (RUN_STATE_COLO ); +qemu_mutex_unlock_iothread (); +trace_colo_vm_state_change ("run" ,"stop" ); + +/* Disable block migration */ + s->params.blk =0 ; + s->params.shared =0 ; +qemu_savevm_state_header (trans); +qemu_savevm_state_begin (trans, &s->params); +qemu_mutex_lock_iothread (); +qemu_savevm_state_complete (trans); +qemu_mutex_unlock_iothread (); + +qemu_fflush (trans); ret =colo_ctl_put (s->to_dst_file,COLO_COMMAND_VMSTATE_SEND ,0 );if (ret <0 ) { goto out; } +/* we send the total size of the vmstate first */ + size =qsb_get_length (buffer); + ret =colo_ctl_put (s->to_dst_file,COLO_COMMAND_VMSTATE_SIZE , size); +if (ret <0 ) { + goto out; + } -/* TODO: send vmstate to Secondary */ +qsb_put_buffer (s->to_dst_file, buffer, size); +qemu_fflush (s->to_dst_file); + ret =qemu_file_get_error (s->to_dst_file); +if (ret <0 ) { + goto out; + } ret =colo_ctl_get (s->from_dst_file,COLO_COMMAND_VMSTATE_RECEIVED );if (ret <0 ) {
@@ -127,14 +165,24 @@ static int colo_do_checkpoint_transaction(MigrationState *s) goto out; } -/* TODO: resume Primary */ + ret =0 ; +/* resume master */ +qemu_mutex_lock_iothread (); +vm_start (); +qemu_mutex_unlock_iothread (); +trace_colo_vm_state_change ("stop" ,"run" ); out: +if (trans) { +qemu_fclose (trans); + } +return ret; }static void colo_process_checkpoint (MigrationState *s) { +QEMUSizedBuffer *buffer =NULL ;int fd, ret =0 ;/* Dup the fd of to_dst_file */
@@ -159,6 +207,13 @@ static void colo_process_checkpoint(MigrationState *s) goto out; } + buffer =qsb_create (NULL ,COLO_BUFFER_BASE_SIZE ); +if (buffer ==NULL ) { + ret = -ENOMEM ; +error_report ("Failed to allocate buffer!" ); + goto out; + } +qemu_mutex_lock_iothread ();vm_start ();qemu_mutex_unlock_iothread ();
@@ -166,7 +221,7 @@ static void colo_process_checkpoint(MigrationState *s)while (s->state ==MIGRATION_STATUS_COLO ) {/* start a colo checkpoint */ - ret =colo_do_checkpoint_transaction (s); + ret =colo_do_checkpoint_transaction (s, buffer);if (ret <0 ) { goto out; }
@@ -179,6 +234,9 @@ out:migrate_set_state (&s->state,MIGRATION_STATUS_COLO ,MIGRATION_STATUS_COMPLETED ); +qsb_free (buffer); + buffer =NULL ; +if (s->from_dst_file) {qemu_fclose (s->from_dst_file); }
migration/ram.c +37 -10
79 lines not on this page · raw message
migration/savevm.c +1 -1
@@ -48,7 +48,7 @@#include "qemu/iov.h" #include "block/snapshot.h" #include "block/qapi.h" - +#include "migration/colo.h" #ifndef ETH_P_RARP #define ETH_P_RARP 0x8035
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH COLO-Frame v10 12/38] COLO: Save PVM state to secondary side when do checkpoint
Quoted 123 lines · * zhanghailiang ([email protected]) wrote:
The main process of checkpoint is to synchronize SVM with PVM. VM's state includes ram and device state. So we will migrate PVM's state to SVM when do checkpoint, just like migration does.
We will cache PVM's state in slave, we use QEMUSizedBuffer
to store the data, we need to know the size of VM state, so in master, we use qsb to store VM state temporarily, get the data size by callqsb_get_length()and then migrate the data to the qsb in the secondary side.Signed-off-by zhanghailiang <[email protected]>Signed-off-by Gonglei <[email protected]>Signed-off-by Li Zhijian <[email protected]>--- migration/colo.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++---- migration/ram.c | 47 +++++++++++++++++++++++++++++-------- migration/savevm.c | 2 +- 3 files changed, 101 insertions(+), 16 deletions(-)migration/colo.c +52
-4@@ -17,6 +17,9 @@#include "qemu/error-report.h" #include "qemu/sockets.h" +/* colo buffer */ +#define COLO_BUFFER_BASE_SIZE (4 * 1024 * 1024) +bool colo_supported (void ) {return true;@@ -94,9 +97,12 @@ static int colo_ctl_get(QEMUFile *f, uint32_t require)return value; } -static int colo_do_checkpoint_transaction (MigrationState *s) +static int colo_do_checkpoint_transaction (MigrationState *s, +QEMUSizedBuffer *buffer) {int ret; +size_t size; +QEMUFile *trans =NULL ; ret =colo_ctl_put (s->to_dst_file,COLO_COMMAND_CHECKPOINT_REQUEST ,0 );if (ret <0 ) {@@ -107,15 +113,47 @@ static int colo_do_checkpoint_transaction(MigrationState *s)if (ret <0 ) { goto out; } +/* Reset colo buffer and open it for write */ +qsb_set_length (buffer,0 ); + trans =qemu_bufopen ("w" , buffer); +if (!trans) { +error_report ("Open colo buffer for write failed" ); + goto out; + } -/* TODO: suspend and save vm state to colo buffer */ +qemu_mutex_lock_iothread (); +vm_stop_force_state (RUN_STATE_COLO ); +qemu_mutex_unlock_iothread (); +trace_colo_vm_state_change ("run" ,"stop" ); + +/* Disable block migration */ + s->params.blk =0 ; + s->params.shared =0 ; +qemu_savevm_state_header (trans); +qemu_savevm_state_begin (trans, &s->params); +qemu_mutex_lock_iothread (); +qemu_savevm_state_complete (trans); +qemu_mutex_unlock_iothread (); + +qemu_fflush (trans); ret =colo_ctl_put (s->to_dst_file,COLO_COMMAND_VMSTATE_SEND ,0 );if (ret <0 ) { goto out; } +/* we send the total size of the vmstate first */ + size =qsb_get_length (buffer); + ret =colo_ctl_put (s->to_dst_file,COLO_COMMAND_VMSTATE_SIZE , size); +if (ret <0 ) { + goto out; + } -/* TODO: send vmstate to Secondary */ +qsb_put_buffer (s->to_dst_file, buffer, size); +qemu_fflush (s->to_dst_file); + ret =qemu_file_get_error (s->to_dst_file); +if (ret <0 ) { + goto out; + } ret =colo_ctl_get (s->from_dst_file,COLO_COMMAND_VMSTATE_RECEIVED );if (ret <0 ) {@@ -127,14 +165,24 @@ static int colo_do_checkpoint_transaction(MigrationState *s) goto out; } -/* TODO: resume Primary */ + ret =0 ; +/* resume master */ +qemu_mutex_lock_iothread (); +vm_start (); +qemu_mutex_unlock_iothread (); +trace_colo_vm_state_change ("stop" ,"run" ); out: +if (trans) { +qemu_fclose (trans); + } +return ret; }static void colo_process_checkpoint (MigrationState *s) { +QEMUSizedBuffer *buffer =NULL ;int fd, ret =0 ;/* Dup the fd of to_dst_file */
migration/colo.c static void colo_process_checkpoint(MigrationState *s) · line 213
Quoted 7 lines
migration/colo.c +4
-0@@ -159,6 +207,13 @@ static void colo_process_checkpoint(MigrationState *s) goto out; } + buffer =qsb_create (NULL ,COLO_BUFFER_BASE_SIZE ); +if (buffer ==NULL ) { + ret = -ENOMEM ; +error_report ("Failed to allocate buffer!" );
Please say 'Failed to allocate colo buffer'; QEMU has lots and lots of buffers.
Quoted 55 lines
migration/colo.c +7
-1+ goto out; + } +qemu_mutex_lock_iothread ();vm_start ();qemu_mutex_unlock_iothread ();@@ -166,7 +221,7 @@ static void colo_process_checkpoint(MigrationState *s)while (s->state ==MIGRATION_STATUS_COLO ) {/* start a colo checkpoint */ - ret =colo_do_checkpoint_transaction (s); + ret =colo_do_checkpoint_transaction (s, buffer);if (ret <0 ) { goto out; }@@ -179,6 +234,9 @@ out:migrate_set_state (&s->state,MIGRATION_STATUS_COLO ,MIGRATION_STATUS_COMPLETED ); +qsb_free (buffer); + buffer =NULL ; +if (s->from_dst_file) {qemu_fclose (s->from_dst_file); }migration/ram.c +2
-8@@ -38,6 +38,7 @@#include "trace.h" #include "exec/ram_addr.h" #include "qemu/rcu_queue.h" +#include "migration/colo.h" #ifdef DEBUG_MIGRATION_RAM #define DPRINTF (fmt, ...) \@@ -1165,15 +1166,8 @@ void migration_bitmap_extend(ram_addr_t old, ram_addr_t new) } } -/* Each of ram_save_setup, ram_save_iterate and ram_save_complete has -* long-running RCU critical section. When rcu-reclaims in the code -* start to become numerous it will be necessary to reduce the -* granularity of these critical sections. -*/ - -static int ram_save_setup (QEMUFile *f,void *opaque) +static int ram_save_init_globals (void ) { -RAMBlock *block;int64_t ram_bitmap_pages;/* Size of bitmap in pages, including gaps */ dirty_rate_high_cnt =0 ;
migration/ram.c static int ram_save_setup(QEMUFile *f, void *opaque) · line 1233
Quoted 7 lines
migration/ram.c +4
-0@@ -1233,6 +1227,31 @@ static int ram_save_setup(QEMUFile *f, void *opaque)migration_bitmap_sync ();qemu_mutex_unlock_ramlist ();qemu_mutex_unlock_iothread (); +rcu_read_unlock (); + +return 0 ; +}
It surprises me you want migration_bitmap_sync in ram_save_init_globals(), but I guess you want the first sync at the start.
Quoted 55 lines
migration/ram.c +30
-2+/* Each of ram_save_setup, ram_save_iterate and ram_save_complete has +* long-running RCU critical section. When rcu-reclaims in the code +* start to become numerous it will be necessary to reduce the +* granularity of these critical sections. +*/ + +static int ram_save_setup (QEMUFile *f,void *opaque) +{ +RAMBlock *block; + +/* +* migration has already setup the bitmap, reuse it. +*/ +if (!migration_in_colo_state ()) { +if (ram_save_init_globals () <0 ) { +return -1 ; + } + } + +rcu_read_lock ();qemu_put_be64 (f,ram_bytes_total () |RAM_SAVE_FLAG_MEM_SIZE );@@ -1332,7 +1351,8 @@ static int ram_save_complete(QEMUFile *f, void *opaque)while (true) {int pages; - pages =ram_find_and_save_block (f, true, &bytes_transferred); + pages =ram_find_and_save_block (f, !migration_in_colo_state (), + &bytes_transferred);/* no more blocks to sent */ if (pages ==0 ) {break ;@@ -1343,8 +1363,15 @@ static int ram_save_complete(QEMUFile *f, void *opaque)ram_control_after_iterate (f,RAM_CONTROL_FINISH );rcu_read_unlock (); +/* +* Since we need to reuse dirty bitmap in colo, +* don't cleanup the bitmap. +*/ +if (!migrate_colo_enabled () || +migration_has_failed (migrate_get_current ())) { +migration_end (); + } -migration_end ();qemu_put_be64 (f,RAM_SAVE_FLAG_EOS );return 0 ;migration/savevm.c +0
-0
migration/savevm.c line 54
Quoted 8 lines
migration/savevm.c +1
-1@@ -48,7 +48,7 @@#include "qemu/iov.h" #include "block/snapshot.h" #include "block/qapi.h" - +#include "migration/colo.h" #ifndef ETH_P_RARP #define ETH_P_RARP 0x8035
Wrong patch?
So other than those minor things:
but watch out for the recent changes to migrate_end that went in a few days ago.
Dave
Quoted 4 lines
Signature · 1 line
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH COLO-Frame v10 12/38] COLO: Save PVM state to secondary side when do checkpoint
Quoted 127 lines · Dr. David Alan Gilbert
Quoted 126 lines · * zhanghailiang ([email protected]) wrote:
The main process of checkpoint is to synchronize SVM with PVM. VM's state includes ram and device state. So we will migrate PVM's state to SVM when do checkpoint, just like migration does.
We will cache PVM's state in slave, we use QEMUSizedBuffer
to store the data, we need to know the size of VM state, so in master, we use qsb to store VM state temporarily, get the data size by callqsb_get_length()and then migrate the data to the qsb in the secondary side.Signed-off-by zhanghailiang <[email protected]>Signed-off-by Gonglei <[email protected]>Signed-off-by Li Zhijian <[email protected]>--- migration/colo.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++---- migration/ram.c | 47 +++++++++++++++++++++++++++++-------- migration/savevm.c | 2 +- 3 files changed, 101 insertions(+), 16 deletions(-)migration/colo.c +52
-4@@ -17,6 +17,9 @@#include "qemu/error-report.h" #include "qemu/sockets.h" +/* colo buffer */ +#define COLO_BUFFER_BASE_SIZE (4 * 1024 * 1024) +bool colo_supported (void ) {return true;@@ -94,9 +97,12 @@ static int colo_ctl_get(QEMUFile *f, uint32_t require)return value; } -static int colo_do_checkpoint_transaction (MigrationState *s) +static int colo_do_checkpoint_transaction (MigrationState *s, +QEMUSizedBuffer *buffer) {int ret; +size_t size; +QEMUFile *trans =NULL ; ret =colo_ctl_put (s->to_dst_file,COLO_COMMAND_CHECKPOINT_REQUEST ,0 );if (ret <0 ) {@@ -107,15 +113,47 @@ static int colo_do_checkpoint_transaction(MigrationState *s)if (ret <0 ) { goto out; } +/* Reset colo buffer and open it for write */ +qsb_set_length (buffer,0 ); + trans =qemu_bufopen ("w" , buffer); +if (!trans) { +error_report ("Open colo buffer for write failed" ); + goto out; + } -/* TODO: suspend and save vm state to colo buffer */ +qemu_mutex_lock_iothread (); +vm_stop_force_state (RUN_STATE_COLO ); +qemu_mutex_unlock_iothread (); +trace_colo_vm_state_change ("run" ,"stop" ); + +/* Disable block migration */ + s->params.blk =0 ; + s->params.shared =0 ; +qemu_savevm_state_header (trans); +qemu_savevm_state_begin (trans, &s->params); +qemu_mutex_lock_iothread (); +qemu_savevm_state_complete (trans); +qemu_mutex_unlock_iothread (); + +qemu_fflush (trans); ret =colo_ctl_put (s->to_dst_file,COLO_COMMAND_VMSTATE_SEND ,0 );if (ret <0 ) { goto out; } +/* we send the total size of the vmstate first */ + size =qsb_get_length (buffer); + ret =colo_ctl_put (s->to_dst_file,COLO_COMMAND_VMSTATE_SIZE , size); +if (ret <0 ) { + goto out; + } -/* TODO: send vmstate to Secondary */ +qsb_put_buffer (s->to_dst_file, buffer, size); +qemu_fflush (s->to_dst_file); + ret =qemu_file_get_error (s->to_dst_file); +if (ret <0 ) { + goto out; + } ret =colo_ctl_get (s->from_dst_file,COLO_COMMAND_VMSTATE_RECEIVED );if (ret <0 ) {@@ -127,14 +165,24 @@ static int colo_do_checkpoint_transaction(MigrationState *s) goto out; } -/* TODO: resume Primary */ + ret =0 ; +/* resume master */ +qemu_mutex_lock_iothread (); +vm_start (); +qemu_mutex_unlock_iothread (); +trace_colo_vm_state_change ("stop" ,"run" ); out: +if (trans) { +qemu_fclose (trans); + } +return ret; }static void colo_process_checkpoint (MigrationState *s) { +QEMUSizedBuffer *buffer =NULL ;int fd, ret =0 ;/* Dup the fd of to_dst_file */ @@ -159,6 +207,13 @@ static void colo_process_checkpoint(MigrationState *s) goto out; }
Quoted 7 lines
migration/colo.c static void colo_process_checkpoint(MigrationState *s) · line 213
Quoted 4 lines
migration/colo.c +4
-0+ buffer =qsb_create (NULL ,COLO_BUFFER_BASE_SIZE ); +if (buffer ==NULL ) { + ret = -ENOMEM ; +error_report ("Failed to allocate buffer!" );Please say 'Failed to allocate colo buffer'; QEMU has lots and lots of buffers.
OK, will fix it in next version.
Quoted 53 lines
Quoted 53 lines
migration/colo.c +7
-1+ goto out; + } +qemu_mutex_lock_iothread ();vm_start ();qemu_mutex_unlock_iothread ();@@ -166,7 +221,7 @@ static void colo_process_checkpoint(MigrationState *s)while (s->state ==MIGRATION_STATUS_COLO ) {/* start a colo checkpoint */ - ret =colo_do_checkpoint_transaction (s); + ret =colo_do_checkpoint_transaction (s, buffer);if (ret <0 ) { goto out; }@@ -179,6 +234,9 @@ out:migrate_set_state (&s->state,MIGRATION_STATUS_COLO ,MIGRATION_STATUS_COMPLETED ); +qsb_free (buffer); + buffer =NULL ; +if (s->from_dst_file) {qemu_fclose (s->from_dst_file); }migration/ram.c +2
-8@@ -38,6 +38,7 @@#include "trace.h" #include "exec/ram_addr.h" #include "qemu/rcu_queue.h" +#include "migration/colo.h" #ifdef DEBUG_MIGRATION_RAM #define DPRINTF (fmt, ...) \@@ -1165,15 +1166,8 @@ void migration_bitmap_extend(ram_addr_t old, ram_addr_t new) } } -/* Each of ram_save_setup, ram_save_iterate and ram_save_complete has -* long-running RCU critical section. When rcu-reclaims in the code -* start to become numerous it will be necessary to reduce the -* granularity of these critical sections. -*/ - -static int ram_save_setup (QEMUFile *f,void *opaque) +static int ram_save_init_globals (void ) { -RAMBlock *block;int64_t ram_bitmap_pages;/* Size of bitmap in pages, including gaps */
Quoted 13 lines
migration/ram.c static int ram_save_setup(QEMUFile *f, void *opaque) · line 1233
Quoted 9 lines
migration/ram.c +4
-0dirty_rate_high_cnt =0 ;@@ -1233,6 +1227,31 @@ static int ram_save_setup(QEMUFile *f, void *opaque)migration_bitmap_sync ();qemu_mutex_unlock_ramlist ();qemu_mutex_unlock_iothread (); +rcu_read_unlock (); + +return 0 ; +}It surprises me you want
migration_bitmap_syncinram_save_init_globals(), but I guess you want the first sync at the start.
Er, sorry,i don't quite understand.
Here. I just split part codes of ram_save_setup()
into a helper function ram_save_init_global(), to make it more clear. We can't do initial work for twice. Is there any thing wrong ?
Quoted 61 lines
Quoted 61 lines
migration/ram.c +30
-2+/* Each of ram_save_setup, ram_save_iterate and ram_save_complete has +* long-running RCU critical section. When rcu-reclaims in the code +* start to become numerous it will be necessary to reduce the +* granularity of these critical sections. +*/ + +static int ram_save_setup (QEMUFile *f,void *opaque) +{ +RAMBlock *block; + +/* +* migration has already setup the bitmap, reuse it. +*/ +if (!migration_in_colo_state ()) { +if (ram_save_init_globals () <0 ) { +return -1 ; + } + } + +rcu_read_lock ();qemu_put_be64 (f,ram_bytes_total () |RAM_SAVE_FLAG_MEM_SIZE );@@ -1332,7 +1351,8 @@ static int ram_save_complete(QEMUFile *f, void *opaque)while (true) {int pages; - pages =ram_find_and_save_block (f, true, &bytes_transferred); + pages =ram_find_and_save_block (f, !migration_in_colo_state (), + &bytes_transferred);/* no more blocks to sent */ if (pages ==0 ) {break ;@@ -1343,8 +1363,15 @@ static int ram_save_complete(QEMUFile *f, void *opaque)ram_control_after_iterate (f,RAM_CONTROL_FINISH );rcu_read_unlock (); +/* +* Since we need to reuse dirty bitmap in colo, +* don't cleanup the bitmap. +*/ +if (!migrate_colo_enabled () || +migration_has_failed (migrate_get_current ())) { +migration_end (); + } -migration_end ();qemu_put_be64 (f,RAM_SAVE_FLAG_EOS );return 0 ;migration/savevm.c +1
-1@@ -48,7 +48,7 @@#include "qemu/iov.h" #include "block/snapshot.h" #include "block/qapi.h" - +#include "migration/colo.h"
Quoted 5 lines
migration/savevm.c line 54
Quoted 2 lines
migration/savevm.c +0
-0#ifndef ETH_P_RARP #define ETH_P_RARP 0x8035Wrong patch?
No, we have call migration_in_colo_state() in qemu_savevm_state_begin(). So we have to include "migration/colo.h"
Quoted 8 lines
So other than those minor things:
Reviewed-by Dr. David Alan Gilbert <[email protected]>but watch out for the recent changes to
migrate_endthat went in a few days ago.
Thanks for reminding me, i have rebased that. ;)
zhanghailiang
Quoted 11 lines
Dave
Quoted 4 lines
--
1.8.3.1--
Dr. David Alan Gilbert / [email protected] / Manchester, UK.
Re: [Qemu-devel] [PATCH COLO-Frame v10 12/38] COLO: Save PVM state to secondary side when do checkpoint
Quoted 205 lines · * zhanghailiang ([email protected]) wrote:
Quoted 127 lines · Dr. David Alan Gilbert
Quoted 126 lines · * zhanghailiang ([email protected]) wrote:
The main process of checkpoint is to synchronize SVM with PVM. VM's state includes ram and device state. So we will migrate PVM's state to SVM when do checkpoint, just like migration does.
We will cache PVM's state in slave, we use QEMUSizedBuffer
to store the data, we need to know the size of VM state, so in master, we use qsb to store VM state temporarily, get the data size by callqsb_get_length()and then migrate the data to the qsb in the secondary side.Signed-off-by zhanghailiang <[email protected]>Signed-off-by Gonglei <[email protected]>Signed-off-by Li Zhijian <[email protected]>--- migration/colo.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++---- migration/ram.c | 47 +++++++++++++++++++++++++++++-------- migration/savevm.c | 2 +- 3 files changed, 101 insertions(+), 16 deletions(-)migration/colo.c +52
-4@@ -17,6 +17,9 @@#include "qemu/error-report.h" #include "qemu/sockets.h" +/* colo buffer */ +#define COLO_BUFFER_BASE_SIZE (4 * 1024 * 1024) +bool colo_supported (void ) {return true;@@ -94,9 +97,12 @@ static int colo_ctl_get(QEMUFile *f, uint32_t require)return value; } -static int colo_do_checkpoint_transaction (MigrationState *s) +static int colo_do_checkpoint_transaction (MigrationState *s, +QEMUSizedBuffer *buffer) {int ret; +size_t size; +QEMUFile *trans =NULL ; ret =colo_ctl_put (s->to_dst_file,COLO_COMMAND_CHECKPOINT_REQUEST ,0 );if (ret <0 ) {@@ -107,15 +113,47 @@ static int colo_do_checkpoint_transaction(MigrationState *s)if (ret <0 ) { goto out; } +/* Reset colo buffer and open it for write */ +qsb_set_length (buffer,0 ); + trans =qemu_bufopen ("w" , buffer); +if (!trans) { +error_report ("Open colo buffer for write failed" ); + goto out; + } -/* TODO: suspend and save vm state to colo buffer */ +qemu_mutex_lock_iothread (); +vm_stop_force_state (RUN_STATE_COLO ); +qemu_mutex_unlock_iothread (); +trace_colo_vm_state_change ("run" ,"stop" ); + +/* Disable block migration */ + s->params.blk =0 ; + s->params.shared =0 ; +qemu_savevm_state_header (trans); +qemu_savevm_state_begin (trans, &s->params); +qemu_mutex_lock_iothread (); +qemu_savevm_state_complete (trans); +qemu_mutex_unlock_iothread (); + +qemu_fflush (trans); ret =colo_ctl_put (s->to_dst_file,COLO_COMMAND_VMSTATE_SEND ,0 );if (ret <0 ) { goto out; } +/* we send the total size of the vmstate first */ + size =qsb_get_length (buffer); + ret =colo_ctl_put (s->to_dst_file,COLO_COMMAND_VMSTATE_SIZE , size); +if (ret <0 ) { + goto out; + } -/* TODO: send vmstate to Secondary */ +qsb_put_buffer (s->to_dst_file, buffer, size); +qemu_fflush (s->to_dst_file); + ret =qemu_file_get_error (s->to_dst_file); +if (ret <0 ) { + goto out; + } ret =colo_ctl_get (s->from_dst_file,COLO_COMMAND_VMSTATE_RECEIVED );if (ret <0 ) {@@ -127,14 +165,24 @@ static int colo_do_checkpoint_transaction(MigrationState *s) goto out; } -/* TODO: resume Primary */ + ret =0 ; +/* resume master */ +qemu_mutex_lock_iothread (); +vm_start (); +qemu_mutex_unlock_iothread (); +trace_colo_vm_state_change ("stop" ,"run" ); out: +if (trans) { +qemu_fclose (trans); + } +return ret; }static void colo_process_checkpoint (MigrationState *s) { +QEMUSizedBuffer *buffer =NULL ;int fd, ret =0 ;/* Dup the fd of to_dst_file */ @@ -159,6 +207,13 @@ static void colo_process_checkpoint(MigrationState *s) goto out; }Quoted 7 lines
migration/colo.c static void colo_process_checkpoint(MigrationState *s) · line 213
Quoted 4 lines
migration/colo.c +4
-0+ buffer =qsb_create (NULL ,COLO_BUFFER_BASE_SIZE ); +if (buffer ==NULL ) { + ret = -ENOMEM ; +error_report ("Failed to allocate buffer!" );Please say 'Failed to allocate colo buffer'; QEMU has lots and lots of buffers.
OK, will fix it in next version.
Quoted 53 lines
Quoted 53 lines
migration/colo.c +7
-1+ goto out; + } +qemu_mutex_lock_iothread ();vm_start ();qemu_mutex_unlock_iothread ();@@ -166,7 +221,7 @@ static void colo_process_checkpoint(MigrationState *s)while (s->state ==MIGRATION_STATUS_COLO ) {/* start a colo checkpoint */ - ret =colo_do_checkpoint_transaction (s); + ret =colo_do_checkpoint_transaction (s, buffer);if (ret <0 ) { goto out; }@@ -179,6 +234,9 @@ out:migrate_set_state (&s->state,MIGRATION_STATUS_COLO ,MIGRATION_STATUS_COMPLETED ); +qsb_free (buffer); + buffer =NULL ; +if (s->from_dst_file) {qemu_fclose (s->from_dst_file); }migration/ram.c +2
-8@@ -38,6 +38,7 @@#include "trace.h" #include "exec/ram_addr.h" #include "qemu/rcu_queue.h" +#include "migration/colo.h" #ifdef DEBUG_MIGRATION_RAM #define DPRINTF (fmt, ...) \@@ -1165,15 +1166,8 @@ void migration_bitmap_extend(ram_addr_t old, ram_addr_t new) } } -/* Each of ram_save_setup, ram_save_iterate and ram_save_complete has -* long-running RCU critical section. When rcu-reclaims in the code -* start to become numerous it will be necessary to reduce the -* granularity of these critical sections. -*/ - -static int ram_save_setup (QEMUFile *f,void *opaque) +static int ram_save_init_globals (void ) { -RAMBlock *block;int64_t ram_bitmap_pages;/* Size of bitmap in pages, including gaps */ Quoted 13 lines
migration/ram.c static int ram_save_setup(QEMUFile *f, void *opaque) · line 1233
Quoted 9 lines
migration/ram.c +4
-0dirty_rate_high_cnt =0 ;@@ -1233,6 +1227,31 @@ static int ram_save_setup(QEMUFile *f, void *opaque)migration_bitmap_sync ();qemu_mutex_unlock_ramlist ();qemu_mutex_unlock_iothread (); +rcu_read_unlock (); + +return 0 ; +}It surprises me you want
migration_bitmap_syncinram_save_init_globals(), but I guess you want the first sync at the start.
Quoted 4 lines
Er, sorry,i don't quite understand.
Here. I just split part codes ofram_save_setup()
into a helper functionram_save_init_global(), to make it more clear. We can't do initial work for twice. Is there any thing wrong ?
No, that's OK - it just seemed odd for a function like 'init_globals' to do such a big side effect of doing the sync; but yes, it makes sense since it's just a split.
Quoted 61 lines
Quoted 61 lines
Quoted 61 lines
migration/ram.c +30
-2+/* Each of ram_save_setup, ram_save_iterate and ram_save_complete has +* long-running RCU critical section. When rcu-reclaims in the code +* start to become numerous it will be necessary to reduce the +* granularity of these critical sections. +*/ + +static int ram_save_setup (QEMUFile *f,void *opaque) +{ +RAMBlock *block; + +/* +* migration has already setup the bitmap, reuse it. +*/ +if (!migration_in_colo_state ()) { +if (ram_save_init_globals () <0 ) { +return -1 ; + } + } + +rcu_read_lock ();qemu_put_be64 (f,ram_bytes_total () |RAM_SAVE_FLAG_MEM_SIZE );@@ -1332,7 +1351,8 @@ static int ram_save_complete(QEMUFile *f, void *opaque)while (true) {int pages; - pages =ram_find_and_save_block (f, true, &bytes_transferred); + pages =ram_find_and_save_block (f, !migration_in_colo_state (), + &bytes_transferred);/* no more blocks to sent */ if (pages ==0 ) {break ;@@ -1343,8 +1363,15 @@ static int ram_save_complete(QEMUFile *f, void *opaque)ram_control_after_iterate (f,RAM_CONTROL_FINISH );rcu_read_unlock (); +/* +* Since we need to reuse dirty bitmap in colo, +* don't cleanup the bitmap. +*/ +if (!migrate_colo_enabled () || +migration_has_failed (migrate_get_current ())) { +migration_end (); + } -migration_end ();qemu_put_be64 (f,RAM_SAVE_FLAG_EOS );return 0 ;migration/savevm.c +1
-1@@ -48,7 +48,7 @@#include "qemu/iov.h" #include "block/snapshot.h" #include "block/qapi.h" - +#include "migration/colo.h"
Quoted 8 lines
Quoted 5 lines
migration/savevm.c line 54
Quoted 2 lines
migration/savevm.c +0
-0#ifndef ETH_P_RARP #define ETH_P_RARP 0x8035Wrong patch?
No, we have call
migration_in_colo_state()inqemu_savevm_state_begin(). So we have to include "migration/colo.h"
I don't think you use it in savevm.c until patch 30, so you can add the #include in patch 30 (or whichever is the patch that first needs it).
Dave
Quoted 6 lines
Quoted 6 lines
So other than those minor things:
Reviewed-by Dr. David Alan Gilbert <[email protected]>
Quoted 21 lines
Quoted 3 lines
but watch out for the recent changes to
migrate_endthat went in a few days ago.Thanks for reminding me, i have rebased that. ;)
zhanghailiang
Quoted 11 lines
Dave
Quoted 4 lines
--
1.8.3.1--
Dr. David Alan Gilbert / [email protected] / Manchester, UK.
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH COLO-Frame v10 12/38] COLO: Save PVM state to secondary side when do checkpoint
Quoted 282 lines · Dr. David Alan Gilbert
Quoted 205 lines · * zhanghailiang ([email protected]) wrote:
Quoted 127 lines · Dr. David Alan Gilbert
Quoted 126 lines · * zhanghailiang ([email protected]) wrote:
The main process of checkpoint is to synchronize SVM with PVM. VM's state includes ram and device state. So we will migrate PVM's state to SVM when do checkpoint, just like migration does.
We will cache PVM's state in slave, we use QEMUSizedBuffer
to store the data, we need to know the size of VM state, so in master, we use qsb to store VM state temporarily, get the data size by callqsb_get_length()and then migrate the data to the qsb in the secondary side.Signed-off-by zhanghailiang <[email protected]>Signed-off-by Gonglei <[email protected]>Signed-off-by Li Zhijian <[email protected]>--- migration/colo.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++---- migration/ram.c | 47 +++++++++++++++++++++++++++++-------- migration/savevm.c | 2 +- 3 files changed, 101 insertions(+), 16 deletions(-)migration/colo.c +52
-4@@ -17,6 +17,9 @@#include "qemu/error-report.h" #include "qemu/sockets.h" +/* colo buffer */ +#define COLO_BUFFER_BASE_SIZE (4 * 1024 * 1024) +bool colo_supported (void ) {return true;@@ -94,9 +97,12 @@ static int colo_ctl_get(QEMUFile *f, uint32_t require)return value; } -static int colo_do_checkpoint_transaction (MigrationState *s) +static int colo_do_checkpoint_transaction (MigrationState *s, +QEMUSizedBuffer *buffer) {int ret; +size_t size; +QEMUFile *trans =NULL ; ret =colo_ctl_put (s->to_dst_file,COLO_COMMAND_CHECKPOINT_REQUEST ,0 );if (ret <0 ) {@@ -107,15 +113,47 @@ static int colo_do_checkpoint_transaction(MigrationState *s)if (ret <0 ) { goto out; } +/* Reset colo buffer and open it for write */ +qsb_set_length (buffer,0 ); + trans =qemu_bufopen ("w" , buffer); +if (!trans) { +error_report ("Open colo buffer for write failed" ); + goto out; + } -/* TODO: suspend and save vm state to colo buffer */ +qemu_mutex_lock_iothread (); +vm_stop_force_state (RUN_STATE_COLO ); +qemu_mutex_unlock_iothread (); +trace_colo_vm_state_change ("run" ,"stop" ); + +/* Disable block migration */ + s->params.blk =0 ; + s->params.shared =0 ; +qemu_savevm_state_header (trans); +qemu_savevm_state_begin (trans, &s->params); +qemu_mutex_lock_iothread (); +qemu_savevm_state_complete (trans); +qemu_mutex_unlock_iothread (); + +qemu_fflush (trans); ret =colo_ctl_put (s->to_dst_file,COLO_COMMAND_VMSTATE_SEND ,0 );if (ret <0 ) { goto out; } +/* we send the total size of the vmstate first */ + size =qsb_get_length (buffer); + ret =colo_ctl_put (s->to_dst_file,COLO_COMMAND_VMSTATE_SIZE , size); +if (ret <0 ) { + goto out; + } -/* TODO: send vmstate to Secondary */ +qsb_put_buffer (s->to_dst_file, buffer, size); +qemu_fflush (s->to_dst_file); + ret =qemu_file_get_error (s->to_dst_file); +if (ret <0 ) { + goto out; + } ret =colo_ctl_get (s->from_dst_file,COLO_COMMAND_VMSTATE_RECEIVED );if (ret <0 ) {@@ -127,14 +165,24 @@ static int colo_do_checkpoint_transaction(MigrationState *s) goto out; } -/* TODO: resume Primary */ + ret =0 ; +/* resume master */ +qemu_mutex_lock_iothread (); +vm_start (); +qemu_mutex_unlock_iothread (); +trace_colo_vm_state_change ("stop" ,"run" ); out: +if (trans) { +qemu_fclose (trans); + } +return ret; }static void colo_process_checkpoint (MigrationState *s) { +QEMUSizedBuffer *buffer =NULL ;int fd, ret =0 ;/* Dup the fd of to_dst_file */ @@ -159,6 +207,13 @@ static void colo_process_checkpoint(MigrationState *s) goto out; }Quoted 7 lines
migration/colo.c static void colo_process_checkpoint(MigrationState *s) · line 213
Quoted 4 lines
migration/colo.c +4
-0+ buffer =qsb_create (NULL ,COLO_BUFFER_BASE_SIZE ); +if (buffer ==NULL ) { + ret = -ENOMEM ; +error_report ("Failed to allocate buffer!" );Please say 'Failed to allocate colo buffer'; QEMU has lots and lots of buffers.
OK, will fix it in next version.
Quoted 53 lines
Quoted 53 lines
migration/colo.c +7
-1+ goto out; + } +qemu_mutex_lock_iothread ();vm_start ();qemu_mutex_unlock_iothread ();@@ -166,7 +221,7 @@ static void colo_process_checkpoint(MigrationState *s)while (s->state ==MIGRATION_STATUS_COLO ) {/* start a colo checkpoint */ - ret =colo_do_checkpoint_transaction (s); + ret =colo_do_checkpoint_transaction (s, buffer);if (ret <0 ) { goto out; }@@ -179,6 +234,9 @@ out:migrate_set_state (&s->state,MIGRATION_STATUS_COLO ,MIGRATION_STATUS_COMPLETED ); +qsb_free (buffer); + buffer =NULL ; +if (s->from_dst_file) {qemu_fclose (s->from_dst_file); }migration/ram.c +2
-8@@ -38,6 +38,7 @@#include "trace.h" #include "exec/ram_addr.h" #include "qemu/rcu_queue.h" +#include "migration/colo.h" #ifdef DEBUG_MIGRATION_RAM #define DPRINTF (fmt, ...) \@@ -1165,15 +1166,8 @@ void migration_bitmap_extend(ram_addr_t old, ram_addr_t new) } } -/* Each of ram_save_setup, ram_save_iterate and ram_save_complete has -* long-running RCU critical section. When rcu-reclaims in the code -* start to become numerous it will be necessary to reduce the -* granularity of these critical sections. -*/ - -static int ram_save_setup (QEMUFile *f,void *opaque) +static int ram_save_init_globals (void ) { -RAMBlock *block;int64_t ram_bitmap_pages;/* Size of bitmap in pages, including gaps */ Quoted 13 lines
migration/ram.c static int ram_save_setup(QEMUFile *f, void *opaque) · line 1233
Quoted 9 lines
migration/ram.c +4
-0dirty_rate_high_cnt =0 ;@@ -1233,6 +1227,31 @@ static int ram_save_setup(QEMUFile *f, void *opaque)migration_bitmap_sync ();qemu_mutex_unlock_ramlist ();qemu_mutex_unlock_iothread (); +rcu_read_unlock (); + +return 0 ; +}It surprises me you want
migration_bitmap_syncinram_save_init_globals(), but I guess you want the first sync at the start.Quoted 4 lines
Er, sorry,i don't quite understand.
Here. I just split part codes ofram_save_setup()
into a helper functionram_save_init_global(), to make it more clear. We can't do initial work for twice. Is there any thing wrong ?No, that's OK - it just seemed odd for a function like '
init_globals' to do such a big side effect of doing the sync; but yes, it makes sense since it's just a split.Quoted 67 lines
Quoted 66 lines
Quoted 55 lines
migration/ram.c +30
-2+/* Each of ram_save_setup, ram_save_iterate and ram_save_complete has +* long-running RCU critical section. When rcu-reclaims in the code +* start to become numerous it will be necessary to reduce the +* granularity of these critical sections. +*/ + +static int ram_save_setup (QEMUFile *f,void *opaque) +{ +RAMBlock *block; + +/* +* migration has already setup the bitmap, reuse it. +*/ +if (!migration_in_colo_state ()) { +if (ram_save_init_globals () <0 ) { +return -1 ; + } + } + +rcu_read_lock ();qemu_put_be64 (f,ram_bytes_total () |RAM_SAVE_FLAG_MEM_SIZE );@@ -1332,7 +1351,8 @@ static int ram_save_complete(QEMUFile *f, void *opaque)while (true) {int pages; - pages =ram_find_and_save_block (f, true, &bytes_transferred); + pages =ram_find_and_save_block (f, !migration_in_colo_state (), + &bytes_transferred);/* no more blocks to sent */ if (pages ==0 ) {break ;@@ -1343,8 +1363,15 @@ static int ram_save_complete(QEMUFile *f, void *opaque)ram_control_after_iterate (f,RAM_CONTROL_FINISH );rcu_read_unlock (); +/* +* Since we need to reuse dirty bitmap in colo, +* don't cleanup the bitmap. +*/ +if (!migrate_colo_enabled () || +migration_has_failed (migrate_get_current ())) { +migration_end (); + } -migration_end ();qemu_put_be64 (f,RAM_SAVE_FLAG_EOS );return 0 ;migration/savevm.c +0
-0migration/savevm.c line 54
Quoted 8 lines
migration/savevm.c +1
-1@@ -48,7 +48,7 @@#include "qemu/iov.h" #include "block/snapshot.h" #include "block/qapi.h" - +#include "migration/colo.h" #ifndef ETH_P_RARP #define ETH_P_RARP 0x8035Wrong patch?
Quoted 6 lines
Quoted 2 lines
No, we have call
migration_in_colo_state()inqemu_savevm_state_begin(). So we have to include "migration/colo.h"I don't think you use it in
savevm.cuntil patch 30, so you can add the #include in patch 30 (or whichever is the patch that first needs it).
Ha, I know what you mean. And yes, you are right,
we shouldn't call migration_in_colo_state() in qemu_savevm_state_begin() here. Good catch. I will fix it in next version. Thanks.
Quoted 35 lines
Dave
Quoted 6 lines
Quoted 6 lines
So other than those minor things:
Reviewed-by Dr. David Alan Gilbert <[email protected]>Quoted 21 lines
Quoted 3 lines
but watch out for the recent changes to
migrate_endthat went in a few days ago.Thanks for reminding me, i have rebased that. ;)
zhanghailiang
Quoted 11 lines
Dave
Quoted 4 lines
--
1.8.3.1--
Dr. David Alan Gilbert / [email protected] / Manchester, UK.
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK.
PATCH v10 13/38 COLO: Load PVM's dirty pages into SVM's RAM cache temporarily
In reply to zhanghailiangWe should not load PVM's state directly into SVM, because there maybe some errors happen when SVM is receving data, which will break SVM.
We need to ensure receving all data before load the state into SVM. We use an extra memory to cache these data (PVM's ram). The ram cache in secondary side is initially the same as SVM/PVM's memory. And in the process of checkpoint, we cache the dirty pages of PVM into this ram cache firstly, so this ram cache always the same as PVM's memory at every checkpoint, then we flush this cached ram to SVM after we receive all PVM's state.
---
v10: Split the process of dirty pages recording into a new patch
--- include/exec/ram_addr.h | 1 + include/migration/colo.h | 3 +++ migration/colo.c | 14 +++++++++-- migration/ram.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 75 insertions(+), 4 deletions(-)
include/exec/ram_addr.h +1 -0
@@ -28,6 +28,7 @@ struct RAMBlock {struct rcu_head rcu;struct MemoryRegion *mr;uint8_t *host; +uint8_t *host_cache;/* For colo, VM's ram cache */ ram_addr_t offset;ram_addr_t used_length;ram_addr_t max_length;
include/migration/colo.h +3 -0
@@ -29,4 +29,7 @@ bool migration_incoming_enable_colo(void);void migration_incoming_exit_colo (void );void *colo_process_incoming_thread (void *opaque);bool migration_incoming_in_colo_state (void ); +/* ram cache */ +int colo_init_ram_cache (void ); +void colo_release_ram_cache (void );#endif
migration/colo.c +12 -2
@@ -304,6 +304,12 @@ void *colo_process_incoming_thread(void *opaque) goto out; } + ret =colo_init_ram_cache (); +if (ret <0 ) { +error_report ("Failed to initialize ram cache" ); + goto out; + } + ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_CHECKPOINT_READY ,0 );if (ret <0 ) { goto out;
@@ -331,14 +337,14 @@ void *colo_process_incoming_thread(void *opaque) goto out; } -/* TODO: read migration data into colo buffer */ +/* TODO Load VM state */ ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_VMSTATE_RECEIVED ,0 );if (ret <0 ) { goto out; } -/* TODO: load vm state */ +/* TODO: flush vm state */ ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_VMSTATE_LOADED ,0 );if (ret <0 ) {
@@ -352,6 +358,10 @@ out: strerror(-ret)); } +qemu_mutex_lock_iothread (); +colo_release_ram_cache (); +qemu_mutex_unlock_iothread (); +if (mis->to_src_file) {qemu_fclose (mis->to_src_file); }
migration/ram.c +59 -2
85 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH COLO-Frame v10 13/38] COLO: Load PVM's dirty pages into SVM's RAM cache temporarily
Quoted 27 lines · * zhanghailiang ([email protected]) wrote:
We should not load PVM's state directly into SVM, because there maybe some errors happen when SVM is receving data, which will break SVM.
We need to ensure receving all data before load the state into SVM. We use an extra memory to cache these data (PVM's ram). The ram cache in secondary side is initially the same as SVM/PVM's memory. And in the process of checkpoint, we cache the dirty pages of PVM into this ram cache firstly, so this ram cache always the same as PVM's memory at every checkpoint, then we flush this cached ram to SVM after we receive all PVM's state.
Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>Signed-off-by Gonglei <[email protected]>---
v10: Split the process of dirty pages recording into a new patch--- include/exec/ram_addr.h | 1 + include/migration/colo.h | 3 +++ migration/colo.c | 14 +++++++++-- migration/ram.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 75 insertions(+), 4 deletions(-)include/exec/ram_addr.h +0
-0
include/exec/ram_addr.h struct RAMBlock { · line 31
Quoted 4 lines
include/exec/ram_addr.h +1
-0@@ -28,6 +28,7 @@ struct RAMBlock {struct rcu_head rcu;struct MemoryRegion *mr;uint8_t *host; +uint8_t *host_cache;/* For colo, VM's ram cache */
I suggest you make the name have 'colo' in it; e.g. colo_cache; 'host_cache' is a bit generic.
Quoted 36 lines
include/exec/ram_addr.h +0
-0ram_addr_t offset;ram_addr_t used_length;ram_addr_t max_length;include/migration/colo.h +3
-0@@ -29,4 +29,7 @@ bool migration_incoming_enable_colo(void);void migration_incoming_exit_colo (void );void *colo_process_incoming_thread (void *opaque);bool migration_incoming_in_colo_state (void ); +/* ram cache */ +int colo_init_ram_cache (void ); +void colo_release_ram_cache (void );#endif migration/colo.c +6
-0@@ -304,6 +304,12 @@ void *colo_process_incoming_thread(void *opaque) goto out; } + ret =colo_init_ram_cache (); +if (ret <0 ) { +error_report ("Failed to initialize ram cache" ); + goto out; + } + ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_CHECKPOINT_READY ,0 );if (ret <0 ) { goto out;@@ -331,14 +337,14 @@ void *colo_process_incoming_thread(void *opaque) goto out; }
migration/colo.c void *colo_process_incoming_thread(void *opaque) · line 347
Quoted 10 lines
migration/colo.c +2
-2-/* TODO: read migration data into colo buffer */ +/* TODO Load VM state */ ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_VMSTATE_RECEIVED ,0 );if (ret <0 ) { goto out; } -/* TODO: load vm state */ +/* TODO: flush vm state */
Do you really need to update/change the TODOs here?
Quoted 59 lines
migration/colo.c +4
-0ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_VMSTATE_LOADED ,0 );if (ret <0 ) {@@ -352,6 +358,10 @@ out: strerror(-ret)); } +qemu_mutex_lock_iothread (); +colo_release_ram_cache (); +qemu_mutex_unlock_iothread (); +if (mis->to_src_file) {qemu_fclose (mis->to_src_file); }migration/ram.c +15
-2@@ -222,6 +222,7 @@ static RAMBlock *last_sent_block;static ram_addr_t last_offset;static QemuMutex migration_bitmap_mutex;static uint64_t migration_dirty_pages; +static bool ram_cache_enable;static uint32_t last_version;static bool ram_bulk_stage;@@ -1446,7 +1447,11 @@ static inline void *host_from_stream_offset(QEMUFile *f,return NULL ; } -return block->host + offset; +if (ram_cache_enable) { +return block->host_cache + offset; + }else { +return block->host + offset; + } } len =qemu_get_byte (f);@@ -1456,7 +1461,11 @@ static inline void *host_from_stream_offset(QEMUFile *f, QLIST_FOREACH_RCU(block, &ram_list.blocks, next) {if (!strncmp (id, block->idstr,sizeof (id)) && block->max_length > offset) { -return block->host + offset; +if (ram_cache_enable) { +return block->host_cache + offset; + }else { +return block->host + offset; + } } }@@ -1707,6 +1716,54 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)return ret; } +/* +* colo cache: this is for secondary VM, we cache the whole +* memory of the secondary VM, it will be called after first migration. +*/
migration/ram.c static int ram_load(QEMUFile *f, void *opaque, int version_id) · line 1732
Quoted 10 lines
migration/ram.c +10
-0+int colo_init_ram_cache (void ) +{ +RAMBlock *block; + +rcu_read_lock (); + QLIST_FOREACH_RCU(block, &ram_list.blocks, next) { + block->host_cache =qemu_anon_ram_alloc (block->used_length,NULL ); +if (!block->host_cache) { + goto out_locked; + }
Please print an error message; stating the function, block name and size that failed.
Quoted 41 lines
migration/ram.c +34
-0+memcpy (block->host_cache, block->host, block->used_length); + } +rcu_read_unlock (); + ram_cache_enable = true; +return 0 ; + +out_locked: + QLIST_FOREACH_RCU(block, &ram_list.blocks, next) { +if (block->host_cache) { +qemu_anon_ram_free (block->host_cache, block->used_length); + block->host_cache =NULL ; + } + } + +rcu_read_unlock (); +return -errno; +} + +void colo_release_ram_cache (void ) +{ +RAMBlock *block; + + ram_cache_enable = false; + +rcu_read_lock (); + QLIST_FOREACH_RCU(block, &ram_list.blocks, next) { +if (block->host_cache) { +qemu_anon_ram_free (block->host_cache, block->used_length); + block->host_cache =NULL ; + } + } +rcu_read_unlock (); +} +static SaveVMHandlers savevm_ram_handlers = { .save_live_setup = ram_save_setup, .save_live_iterate = ram_save_iterate,Signature · 1 line
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH COLO-Frame v10 13/38] COLO: Load PVM's dirty pages into SVM's RAM cache temporarily
Quoted 23 lines · Dr. David Alan Gilbert
Quoted 22 lines · * zhanghailiang ([email protected]) wrote:
We should not load PVM's state directly into SVM, because there maybe some errors happen when SVM is receving data, which will break SVM.
We need to ensure receving all data before load the state into SVM. We use an extra memory to cache these data (PVM's ram). The ram cache in secondary side is initially the same as SVM/PVM's memory. And in the process of checkpoint, we cache the dirty pages of PVM into this ram cache firstly, so this ram cache always the same as PVM's memory at every checkpoint, then we flush this cached ram to SVM after we receive all PVM's state.
Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>Signed-off-by Gonglei <[email protected]>---
v10: Split the process of dirty pages recording into a new patch--- include/exec/ram_addr.h | 1 + include/migration/colo.h | 3 +++ migration/colo.c | 14 +++++++++-- migration/ram.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 75 insertions(+), 4 deletions(-)
Quoted 13 lines
include/exec/ram_addr.h struct RAMBlock { · line 31
Quoted 9 lines
include/exec/ram_addr.h +1
-0@@ -28,6 +28,7 @@ struct RAMBlock {struct rcu_head rcu;struct MemoryRegion *mr;uint8_t *host; +uint8_t *host_cache;/* For colo, VM's ram cache */ I suggest you make the name have 'colo' in it; e.g.
colo_cache; 'host_cache' is a bit generic.
Hmm, this change makes sense, will update it in next version.
Quoted 44 lines
Quoted 44 lines
include/exec/ram_addr.h +0
-0ram_addr_t offset;ram_addr_t used_length;ram_addr_t max_length;include/migration/colo.h +3
-0@@ -29,4 +29,7 @@ bool migration_incoming_enable_colo(void);void migration_incoming_exit_colo (void );void *colo_process_incoming_thread (void *opaque);bool migration_incoming_in_colo_state (void ); +/* ram cache */ +int colo_init_ram_cache (void ); +void colo_release_ram_cache (void );#endif migration/colo.c +7
-1@@ -304,6 +304,12 @@ void *colo_process_incoming_thread(void *opaque) goto out; } + ret =colo_init_ram_cache (); +if (ret <0 ) { +error_report ("Failed to initialize ram cache" ); + goto out; + } + ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_CHECKPOINT_READY ,0 );if (ret <0 ) { goto out;@@ -331,14 +337,14 @@ void *colo_process_incoming_thread(void *opaque) goto out; } -/* TODO: read migration data into colo buffer */ +/* TODO Load VM state */ ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_VMSTATE_RECEIVED ,0 );if (ret <0 ) { goto out; }
Quoted 5 lines
migration/colo.c void *colo_process_incoming_thread(void *opaque) · line 347
Quoted 2 lines
migration/colo.c +1
-1-/* TODO: load vm state */ +/* TODO: flush vm state */ Do you really need to update/change the TODOs here?
No, i will drop this ;)
Quoted 64 lines
Quoted 64 lines
migration/colo.c +4
-0ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_VMSTATE_LOADED ,0 );if (ret <0 ) {@@ -352,6 +358,10 @@ out: strerror(-ret)); } +qemu_mutex_lock_iothread (); +colo_release_ram_cache (); +qemu_mutex_unlock_iothread (); +if (mis->to_src_file) {qemu_fclose (mis->to_src_file); }migration/ram.c +20
-2@@ -222,6 +222,7 @@ static RAMBlock *last_sent_block;static ram_addr_t last_offset;static QemuMutex migration_bitmap_mutex;static uint64_t migration_dirty_pages; +static bool ram_cache_enable;static uint32_t last_version;static bool ram_bulk_stage;@@ -1446,7 +1447,11 @@ static inline void *host_from_stream_offset(QEMUFile *f,return NULL ; } -return block->host + offset; +if (ram_cache_enable) { +return block->host_cache + offset; + }else { +return block->host + offset; + } } len =qemu_get_byte (f);@@ -1456,7 +1461,11 @@ static inline void *host_from_stream_offset(QEMUFile *f, QLIST_FOREACH_RCU(block, &ram_list.blocks, next) {if (!strncmp (id, block->idstr,sizeof (id)) && block->max_length > offset) { -return block->host + offset; +if (ram_cache_enable) { +return block->host_cache + offset; + }else { +return block->host + offset; + } } }@@ -1707,6 +1716,54 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)return ret; } +/* +* colo cache: this is for secondary VM, we cache the whole +* memory of the secondary VM, it will be called after first migration. +*/ +int colo_init_ram_cache (void ) +{ +RAMBlock *block; + +rcu_read_lock ();
Quoted 9 lines
migration/ram.c static int ram_load(QEMUFile *f, void *opaque, int version_id) · line 1732
Quoted 5 lines
migration/ram.c +5
-0+ QLIST_FOREACH_RCU(block, &ram_list.blocks, next) { + block->host_cache =qemu_anon_ram_alloc (block->used_length,NULL ); +if (!block->host_cache) { + goto out_locked; + }Please print an error message; stating the function, block name and size that failed.
Good idea, will fix in next version, thanks.
Quoted 46 lines
Quoted 38 lines
migration/ram.c +34
-1+memcpy (block->host_cache, block->host, block->used_length); + } +rcu_read_unlock (); + ram_cache_enable = true; +return 0 ; + +out_locked: + QLIST_FOREACH_RCU(block, &ram_list.blocks, next) { +if (block->host_cache) { +qemu_anon_ram_free (block->host_cache, block->used_length); + block->host_cache =NULL ; + } + } + +rcu_read_unlock (); +return -errno; +} + +void colo_release_ram_cache (void ) +{ +RAMBlock *block; + + ram_cache_enable = false; + +rcu_read_lock (); + QLIST_FOREACH_RCU(block, &ram_list.blocks, next) { +if (block->host_cache) { +qemu_anon_ram_free (block->host_cache, block->used_length); + block->host_cache =NULL ; + } + } +rcu_read_unlock (); +} +static SaveVMHandlers savevm_ram_handlers = { .save_live_setup = ram_save_setup, .save_live_iterate = ram_save_iterate, --Quoted 3 lines
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK.
PATCH v10 14/38 COLO: Load VMState into qsb before restore it
In reply to zhanghailiangWe should not destroy the state of SVM (Secondary VM) until we receive the whole state from the PVM (Primary VM), in case the primary fails in the middle of sending the state, so, here we cache the device state in Secondary before restore it.
Besides, we should call qemu_system_reset() before load VM state, which can ensure the data is intact.
--- migration/colo.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-)
migration/colo.c +46 -1
@@ -287,6 +287,9 @@ static int colo_wait_handle_cmd(QEMUFile *f, int *checkpoint_request)void *colo_process_incoming_thread (void *opaque) {MigrationIncomingState *mis = opaque; +QEMUFile *fb =NULL ; +QEMUSizedBuffer *buffer =NULL ;/* Cache incoming device state */ +int total_size;int fd, ret =0 ; migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE,
@@ -310,6 +313,12 @@ void *colo_process_incoming_thread(void *opaque) goto out; } + buffer =qsb_create (NULL ,COLO_BUFFER_BASE_SIZE ); +if (buffer ==NULL ) { +error_report ("Failed to allocate colo buffer!" ); + goto out; + } + ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_CHECKPOINT_READY ,0 );if (ret <0 ) { goto out;
@@ -337,19 +346,50 @@ void *colo_process_incoming_thread(void *opaque) goto out; } -/* TODO Load VM state */ +/* read the VM state total size first */ + total_size =colo_ctl_get (mis->from_src_file, +COLO_COMMAND_VMSTATE_SIZE ); +if (total_size <=0 ) { + goto out; + } + +/* read vm device state into colo buffer */ + ret =qsb_fill_buffer (buffer, mis->from_src_file, total_size); +if (ret != total_size) { +error_report ("can't get all migration data" ); + goto out; + } ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_VMSTATE_RECEIVED ,0 );if (ret <0 ) { goto out; } +/* open colo buffer for read */ + fb =qemu_bufopen ("r" , buffer); +if (!fb) { +error_report ("can't open colo buffer for read" ); + goto out; + } + +qemu_mutex_lock_iothread (); +qemu_system_reset (VMRESET_SILENT ); +if (qemu_loadvm_state (fb) <0 ) { +error_report ("COLO: loadvm failed" ); +qemu_mutex_unlock_iothread (); + goto out; + } +qemu_mutex_unlock_iothread (); +/* TODO: flush vm state */ ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_VMSTATE_LOADED ,0 );if (ret <0 ) { goto out; } + +qemu_fclose (fb); + fb =NULL ; } out:
@@ -358,6 +398,11 @@ out: strerror(-ret)); } +if (fb) { +qemu_fclose (fb); + } +qsb_free (buffer); +qemu_mutex_lock_iothread ();colo_release_ram_cache ();qemu_mutex_unlock_iothread ();
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH COLO-Frame v10 14/38] COLO: Load VMState into qsb before restore it
Quoted 43 lines · * zhanghailiang ([email protected]) wrote:
We should not destroy the state of SVM (Secondary VM) until we receive the whole state from the PVM (Primary VM), in case the primary fails in the middle of sending the state, so, here we cache the device state in Secondary before restore it.
Besides, we should call
qemu_system_reset()before load VM state, which can ensure the data is intact.Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>Signed-off-by Gonglei <[email protected]>Reviewed-by Dr. David Alan Gilbert <[email protected]>--- migration/colo.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-)migration/colo.c +9
-0@@ -287,6 +287,9 @@ static int colo_wait_handle_cmd(QEMUFile *f, int *checkpoint_request)void *colo_process_incoming_thread (void *opaque) {MigrationIncomingState *mis = opaque; +QEMUFile *fb =NULL ; +QEMUSizedBuffer *buffer =NULL ;/* Cache incoming device state */ +int total_size;int fd, ret =0 ; migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE,@@ -310,6 +313,12 @@ void *colo_process_incoming_thread(void *opaque) goto out; } + buffer =qsb_create (NULL ,COLO_BUFFER_BASE_SIZE ); +if (buffer ==NULL ) { +error_report ("Failed to allocate colo buffer!" ); + goto out; + } + ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_CHECKPOINT_READY ,0 );if (ret <0 ) { goto out;
migration/colo.c void *colo_process_incoming_thread(void *opaque) · line 352
Quoted 8 lines
migration/colo.c +4
-1@@ -337,19 +346,50 @@ void *colo_process_incoming_thread(void *opaque) goto out; } -/* TODO Load VM state */ +/* read the VM state total size first */ + total_size =colo_ctl_get (mis->from_src_file, +COLO_COMMAND_VMSTATE_SIZE ); +if (total_size <=0 ) {
Error message?
migration/colo.c void *colo_process_incoming_thread(void *opaque) · line 354
Quoted 2 lines
migration/colo.c +2
-0+ goto out; + }
OK, and when you fix up the colo_ctl_get in the previous patch to take a separate pointer for value, you can make total_size a size_t.
Other than those, it looks good.
Dave
Quoted 56 lines
migration/colo.c +30
-0+/* read vm device state into colo buffer */ + ret =qsb_fill_buffer (buffer, mis->from_src_file, total_size); +if (ret != total_size) { +error_report ("can't get all migration data" ); + goto out; + } ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_VMSTATE_RECEIVED ,0 );if (ret <0 ) { goto out; } +/* open colo buffer for read */ + fb =qemu_bufopen ("r" , buffer); +if (!fb) { +error_report ("can't open colo buffer for read" ); + goto out; + } + +qemu_mutex_lock_iothread (); +qemu_system_reset (VMRESET_SILENT ); +if (qemu_loadvm_state (fb) <0 ) { +error_report ("COLO: loadvm failed" ); +qemu_mutex_unlock_iothread (); + goto out; + } +qemu_mutex_unlock_iothread (); +/* TODO: flush vm state */ ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_VMSTATE_LOADED ,0 );if (ret <0 ) { goto out; } + +qemu_fclose (fb); + fb =NULL ; } out:@@ -358,6 +398,11 @@ out: strerror(-ret)); } +if (fb) { +qemu_fclose (fb); + } +qsb_free (buffer); +qemu_mutex_lock_iothread ();colo_release_ram_cache ();qemu_mutex_unlock_iothread ();Signature · 1 line
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH COLO-Frame v10 14/38] COLO: Load VMState into qsb before restore it
Quoted 47 lines · Dr. David Alan Gilbert
Quoted 46 lines · * zhanghailiang ([email protected]) wrote:
We should not destroy the state of SVM (Secondary VM) until we receive the whole state from the PVM (Primary VM), in case the primary fails in the middle of sending the state, so, here we cache the device state in Secondary before restore it.
Besides, we should call
qemu_system_reset()before load VM state, which can ensure the data is intact.Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>Signed-off-by Gonglei <[email protected]>Reviewed-by Dr. David Alan Gilbert <[email protected]>--- migration/colo.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-)migration/colo.c +9
-0@@ -287,6 +287,9 @@ static int colo_wait_handle_cmd(QEMUFile *f, int *checkpoint_request)void *colo_process_incoming_thread (void *opaque) {MigrationIncomingState *mis = opaque; +QEMUFile *fb =NULL ; +QEMUSizedBuffer *buffer =NULL ;/* Cache incoming device state */ +int total_size;int fd, ret =0 ; migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE,@@ -310,6 +313,12 @@ void *colo_process_incoming_thread(void *opaque) goto out; } + buffer =qsb_create (NULL ,COLO_BUFFER_BASE_SIZE ); +if (buffer ==NULL ) { +error_report ("Failed to allocate colo buffer!" ); + goto out; + } + ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_CHECKPOINT_READY ,0 );if (ret <0 ) { goto out;@@ -337,19 +346,50 @@ void *colo_process_incoming_thread(void *opaque) goto out; }
Quoted 8 lines
migration/colo.c void *colo_process_incoming_thread(void *opaque) · line 352
Quoted 5 lines
migration/colo.c +4
-1-/* TODO Load VM state */ +/* read the VM state total size first */ + total_size =colo_ctl_get (mis->from_src_file, +COLO_COMMAND_VMSTATE_SIZE ); +if (total_size <=0 ) {Error message?
OK, we need one.
Quoted 6 lines
migration/colo.c void *colo_process_incoming_thread(void *opaque) · line 354
Quoted 2 lines
migration/colo.c +2
-0+ goto out; + }OK, and when you fix up the
colo_ctl_getin the previous patch to take a separate pointer for value, you can maketotal_sizeasize_t.
Yes, i have updated it after addressing your review comment on patch 11.
Quoted 3 lines
Other than those, it looks good.
Thanks.
Quoted 63 lines
Dave
Quoted 53 lines
migration/colo.c +30
-1+/* read vm device state into colo buffer */ + ret =qsb_fill_buffer (buffer, mis->from_src_file, total_size); +if (ret != total_size) { +error_report ("can't get all migration data" ); + goto out; + } ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_VMSTATE_RECEIVED ,0 );if (ret <0 ) { goto out; } +/* open colo buffer for read */ + fb =qemu_bufopen ("r" , buffer); +if (!fb) { +error_report ("can't open colo buffer for read" ); + goto out; + } + +qemu_mutex_lock_iothread (); +qemu_system_reset (VMRESET_SILENT ); +if (qemu_loadvm_state (fb) <0 ) { +error_report ("COLO: loadvm failed" ); +qemu_mutex_unlock_iothread (); + goto out; + } +qemu_mutex_unlock_iothread (); +/* TODO: flush vm state */ ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_VMSTATE_LOADED ,0 );if (ret <0 ) { goto out; } + +qemu_fclose (fb); + fb =NULL ; } out:@@ -358,6 +398,11 @@ out: strerror(-ret)); } +if (fb) { +qemu_fclose (fb); + } +qsb_free (buffer); +qemu_mutex_lock_iothread ();colo_release_ram_cache ();qemu_mutex_unlock_iothread (); --Quoted 3 lines
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK.
PATCH v10 15/38 ram/COLO: Record pages received from PVM by re-using migration dirty bitmap
In reply to zhanghailiangWe need to record the address of the dirty pages that received from PVM, It will help flushing pages that cached into SVM.
---
v10:
- New patch split from v9's patch 13
- Rebase to master to use 'migration_bitmap_rcu'
--- migration/ram.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
migration/ram.c +35 -0
@@ -1448,6 +1448,18 @@ static inline void *host_from_stream_offset(QEMUFile *f, }if (ram_cache_enable) { +unsigned long *bitmap; +long k = (block->mr->ram_addr + offset) >>TARGET_PAGE_BITS ; + + bitmap =atomic_rcu_read (&migration_bitmap_rcu)->bmap; +/* +* During colo checkpoint, we need bitmap of these migrated pages. +* It help us to decide which pages in ram cache should be flushed +* into VM's RAM later. +*/ +if (!test_and_set_bit (k, bitmap)) { + migration_dirty_pages++; + }return block->host_cache + offset; }else {return block->host + offset;
@@ -1462,6 +1474,13 @@ static inline void *host_from_stream_offset(QEMUFile *f,if (!strncmp (id, block->idstr,sizeof (id)) && block->max_length > offset) {if (ram_cache_enable) { +unsigned long *bitmap; +long k = (block->mr->ram_addr + offset) >>TARGET_PAGE_BITS ; + + bitmap =atomic_rcu_read (&migration_bitmap_rcu)->bmap; +if (!test_and_set_bit (k, bitmap)) { + migration_dirty_pages++; + }return block->host_cache + offset; }else {return block->host + offset;
@@ -1723,6 +1742,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)int colo_init_ram_cache (void ) {RAMBlock *block; +int64_t ram_cache_pages =last_ram_offset () >>TARGET_PAGE_BITS ;rcu_read_lock (); QLIST_FOREACH_RCU(block, &ram_list.blocks, next) {
@@ -1734,6 +1754,15 @@ int colo_init_ram_cache(void) }rcu_read_unlock (); ram_cache_enable = true; +/* +* Record the dirty pages that sent by PVM, we use this dirty bitmap together +* with to decide which page in cache should be flushed into SVM's RAM. Here +* we use the same name 'migration_bitmap_rcu' as for migration. +*/ + migration_bitmap_rcu = g_new(struct BitmapRcu, 1); + migration_bitmap_rcu->bmap =bitmap_new (ram_cache_pages); + migration_dirty_pages =0 ; +return 0 ; out_locked:
@@ -1751,9 +1780,15 @@ out_locked:void colo_release_ram_cache (void ) {RAMBlock *block; +struct BitmapRcu *bitmap = migration_bitmap_rcu; ram_cache_enable = false; +atomic_rcu_set (&migration_bitmap_rcu,NULL ); +if (bitmap) { +call_rcu (bitmap, migration_bitmap_free, rcu); + } +rcu_read_lock (); QLIST_FOREACH_RCU(block, &ram_list.blocks, next) {if (block->host_cache) {
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH COLO-Frame v10 15/38] ram/COLO: Record pages received from PVM by re-using migration dirty bitmap
Quoted 22 lines · * zhanghailiang ([email protected]) wrote:
We need to record the address of the dirty pages that received from PVM, It will help flushing pages that cached into SVM.
Signed-off-by zhanghailiang <[email protected]>---
v10:
- New patch split from v9's patch 13
- Rebase to master to use 'migration_bitmap_rcu'--- migration/ram.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)migration/ram.c +2
-0@@ -1448,6 +1448,18 @@ static inline void *host_from_stream_offset(QEMUFile *f, }if (ram_cache_enable) { +unsigned long *bitmap; +long k = (block->mr->ram_addr + offset) >>TARGET_PAGE_BITS ;
migration/ram.c static inline void *host_from_stream_offset(QEMUFile *f, · line 1462
Quoted 10 lines
migration/ram.c +10
-0+ + bitmap =atomic_rcu_read (&migration_bitmap_rcu)->bmap; +/* +* During colo checkpoint, we need bitmap of these migrated pages. +* It help us to decide which pages in ram cache should be flushed +* into VM's RAM later. +*/ +if (!test_and_set_bit (k, bitmap)) { + migration_dirty_pages++; + }
I don't like having this in host_from_stream_offset; if you look
at the current ram_load there is only a single call to host_from_stream_offset, so it's now much easier for you to move it into a separate function.
Quoted 26 lines
migration/ram.c +8
-0return block->host_cache + offset; }else {return block->host + offset;@@ -1462,6 +1474,13 @@ static inline void *host_from_stream_offset(QEMUFile *f,if (!strncmp (id, block->idstr,sizeof (id)) && block->max_length > offset) {if (ram_cache_enable) { +unsigned long *bitmap; +long k = (block->mr->ram_addr + offset) >>TARGET_PAGE_BITS ; + + bitmap =atomic_rcu_read (&migration_bitmap_rcu)->bmap; +if (!test_and_set_bit (k, bitmap)) { + migration_dirty_pages++; + }return block->host_cache + offset; }else {return block->host + offset;@@ -1723,6 +1742,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)int colo_init_ram_cache (void ) {RAMBlock *block; +int64_t ram_cache_pages =last_ram_offset () >>TARGET_PAGE_BITS ;rcu_read_lock (); QLIST_FOREACH_RCU(block, &ram_list.blocks, next) {
migration/ram.c int colo_init_ram_cache(void) · line 1762
Quoted 9 lines
migration/ram.c +6
-0@@ -1734,6 +1754,15 @@ int colo_init_ram_cache(void) }rcu_read_unlock (); ram_cache_enable = true; +/* +* Record the dirty pages that sent by PVM, we use this dirty bitmap together +* with to decide which page in cache should be flushed into SVM's RAM. Here +* we use the same name 'migration_bitmap_rcu' as for migration. +*/ + migration_bitmap_rcu = g_new(struct BitmapRcu, 1);
Please update that to g_new0 (I changed the other use when I added postcopy).
Dave
Quoted 26 lines
migration/ram.c +9
-0+ migration_bitmap_rcu->bmap =bitmap_new (ram_cache_pages); + migration_dirty_pages =0 ; +return 0 ; out_locked:@@ -1751,9 +1780,15 @@ out_locked:void colo_release_ram_cache (void ) {RAMBlock *block; +struct BitmapRcu *bitmap = migration_bitmap_rcu; ram_cache_enable = false; +atomic_rcu_set (&migration_bitmap_rcu,NULL ); +if (bitmap) { +call_rcu (bitmap, migration_bitmap_free, rcu); + } +rcu_read_lock (); QLIST_FOREACH_RCU(block, &ram_list.blocks, next) {if (block->host_cache) {Signature · 1 line
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH COLO-Frame v10 15/38] ram/COLO: Record pages received from PVM by re-using migration dirty bitmap
Quoted 29 lines · Dr. David Alan Gilbert
Quoted 28 lines · * zhanghailiang ([email protected]) wrote:
We need to record the address of the dirty pages that received from PVM, It will help flushing pages that cached into SVM.
Signed-off-by zhanghailiang <[email protected]>---
v10:
- New patch split from v9's patch 13
- Rebase to master to use 'migration_bitmap_rcu'--- migration/ram.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)migration/ram.c +8
-0@@ -1448,6 +1448,18 @@ static inline void *host_from_stream_offset(QEMUFile *f, }if (ram_cache_enable) { +unsigned long *bitmap; +long k = (block->mr->ram_addr + offset) >>TARGET_PAGE_BITS ; + + bitmap =atomic_rcu_read (&migration_bitmap_rcu)->bmap; +/* +* During colo checkpoint, we need bitmap of these migrated pages. +* It help us to decide which pages in ram cache should be flushed +* into VM's RAM later.
Quoted 9 lines
migration/ram.c static inline void *host_from_stream_offset(QEMUFile *f, · line 1462
Quoted 4 lines
migration/ram.c +4
-0+*/ +if (!test_and_set_bit (k, bitmap)) { + migration_dirty_pages++; + }I don't like having this in
host_from_stream_offset; if you look
at the currentram_loadthere is only a single call tohost_from_stream_offset, so it's now much easier for you to move it into a separate function.
Hmm, that's really a good idea, i will split it in next version.
Quoted 23 lines
Quoted 23 lines
migration/ram.c +8
-0return block->host_cache + offset; }else {return block->host + offset;@@ -1462,6 +1474,13 @@ static inline void *host_from_stream_offset(QEMUFile *f,if (!strncmp (id, block->idstr,sizeof (id)) && block->max_length > offset) {if (ram_cache_enable) { +unsigned long *bitmap; +long k = (block->mr->ram_addr + offset) >>TARGET_PAGE_BITS ; + + bitmap =atomic_rcu_read (&migration_bitmap_rcu)->bmap; +if (!test_and_set_bit (k, bitmap)) { + migration_dirty_pages++; + }return block->host_cache + offset; }else {return block->host + offset;@@ -1723,6 +1742,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)int colo_init_ram_cache (void ) {RAMBlock *block; +int64_t ram_cache_pages =last_ram_offset () >>TARGET_PAGE_BITS ;
Quoted 15 lines
migration/ram.c int colo_init_ram_cache(void) · line 1762
Quoted 12 lines
migration/ram.c +6
-0rcu_read_lock (); QLIST_FOREACH_RCU(block, &ram_list.blocks, next) {@@ -1734,6 +1754,15 @@ int colo_init_ram_cache(void) }rcu_read_unlock (); ram_cache_enable = true; +/* +* Record the dirty pages that sent by PVM, we use this dirty bitmap together +* with to decide which page in cache should be flushed into SVM's RAM. Here +* we use the same name 'migration_bitmap_rcu' as for migration. +*/ + migration_bitmap_rcu = g_new(struct BitmapRcu, 1);Please update that to
g_new0(I changed the other use when I added postcopy).
OK, thanks.
Quoted 33 lines
Dave
Quoted 23 lines
migration/ram.c +9
-1+ migration_bitmap_rcu->bmap =bitmap_new (ram_cache_pages); + migration_dirty_pages =0 ; +return 0 ; out_locked:@@ -1751,9 +1780,15 @@ out_locked:void colo_release_ram_cache (void ) {RAMBlock *block; +struct BitmapRcu *bitmap = migration_bitmap_rcu; ram_cache_enable = false; +atomic_rcu_set (&migration_bitmap_rcu,NULL ); +if (bitmap) { +call_rcu (bitmap, migration_bitmap_free, rcu); + } +rcu_read_lock (); QLIST_FOREACH_RCU(block, &ram_list.blocks, next) {if (block->host_cache) { --Quoted 3 lines
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK.
PATCH v10 16/38 COLO: Flush PVM's cached RAM into SVM's memory
In reply to zhanghailiangDuring the time of VM's running, PVM may dirty some pages, we will transfer PVM's dirty pages to SVM and store them into SVM's RAM cache at next checkpoint time. So, the content of SVM's RAM cache will always be some with PVM's memory after checkpoint.
Instead of flushing all content of PVM's RAM cache into SVM's MEMORY, we do this in a more efficient way:
Only flush any page that dirtied by PVM since last checkpoint. In this way, we can ensure SVM's memory same with PVM's.
Besides, we must ensure flush RAM cache before load device state.
---
v10: trace the number of dirty pages that be received.
--- include/migration/colo.h | 1 + migration/colo.c | 2 -- migration/ram.c | 40 ++++++++++++++++++++++++++++++++++++++++ trace-events | 1 + 4 files changed, 42 insertions(+), 2 deletions(-)
include/migration/colo.h +1 -0
@@ -32,4 +32,5 @@ bool migration_incoming_in_colo_state(void);/* ram cache */ int colo_init_ram_cache (void );void colo_release_ram_cache (void ); +void colo_flush_ram_cache (void );#endif
migration/colo.c +0 -2
@@ -381,8 +381,6 @@ void *colo_process_incoming_thread(void *opaque) }qemu_mutex_unlock_iothread (); -/* TODO: flush vm state */ - ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_VMSTATE_LOADED ,0 );if (ret <0 ) { goto out;
migration/ram.c +40 -0
@@ -1601,6 +1601,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)int flags =0 , ret =0 ;static uint64_t seq_iter;int len =0 ; +bool need_flush = false; seq_iter++;
@@ -1669,6 +1670,8 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) ret = -EINVAL ;break ; } + + need_flush = true; ch =qemu_get_byte (f);ram_handle_compressed (host, ch,TARGET_PAGE_SIZE );break ;
@@ -1679,6 +1682,8 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) ret = -EINVAL ;break ; } + + need_flush = true;qemu_get_buffer (f, host,TARGET_PAGE_SIZE );break ;case RAM_SAVE_FLAG_COMPRESS_PAGE :
@@ -1711,6 +1716,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) ret = -EINVAL ;break ; } + need_flush = true;break ;case RAM_SAVE_FLAG_EOS :/* normal exit */
@@ -1730,6 +1736,11 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) }rcu_read_unlock (); + +if (!ret && ram_cache_enable && need_flush) { +DPRINTF ("Flush ram_cache\n" ); +colo_flush_ram_cache (); + }DPRINTF ("Completed load of VM with exit code %d seq iteration " "%" PRIu64"\n" , ret, seq_iter);return ret;
@@ -1799,6 +1810,35 @@ void colo_release_ram_cache(void)rcu_read_unlock (); } +/* +* Flush content of RAM cache into SVM's memory. +* Only flush the pages that be dirtied by PVM or SVM or both. +*/ +void colo_flush_ram_cache (void ) +{ +RAMBlock *block =NULL ; +void *dst_host; +void *src_host; +ram_addr_t offset =0 ; + +trace_colo_flush_ram_cache (migration_dirty_pages); +rcu_read_lock (); + block =QLIST_FIRST_RCU (&ram_list.blocks); +while (block) { + offset =migration_bitmap_find_and_reset_dirty (block, offset); +if (offset >= block->used_length) { + offset =0 ; + block =QLIST_NEXT_RCU (block, next); + }else { + dst_host = block->host + offset; + src_host = block->host_cache + offset; +memcpy (dst_host, src_host,TARGET_PAGE_SIZE ); + } + } +rcu_read_unlock (); +assert (migration_dirty_pages ==0 ); +} +static SaveVMHandlers savevm_ram_handlers = { .save_live_setup = ram_save_setup, .save_live_iterate = ram_save_iterate,
trace-events +1 -0
@@ -1232,6 +1232,7 @@ qemu_file_fclose(void) "" migration_bitmap_sync_start(void) "" migration_bitmap_sync_end(uint64_t dirty_pages) "dirty_pages %" PRIu64"" migration_throttle(void) "" +colo_flush_ram_cache(uint64_t dirty_pages) "dirty_pages %" PRIu64"" # hw/display/qxl.c disable qxl_interface_set_mm_time(int qid, uint32_t mm_time) "%d %d"
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH COLO-Frame v10 16/38] COLO: Flush PVM's cached RAM into SVM's memory
Quoted 11 lines · * zhanghailiang ([email protected]) wrote:
During the time of VM's running, PVM may dirty some pages, we will transfer PVM's dirty pages to SVM and store them into SVM's RAM cache at next checkpoint time. So, the content of SVM's RAM cache will always be some with PVM's memory after checkpoint.
Instead of flushing all content of PVM's RAM cache into SVM's MEMORY, we do this in a more efficient way:
Only flush any page that dirtied by PVM since last checkpoint. In this way, we can ensure SVM's memory same with PVM's.Besides, we must ensure flush RAM cache before load device state.
Yes, just a couple of minor comments below; mostly OK.
Quoted 66 lines
Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>Signed-off-by Gonglei <[email protected]>---
v10: trace the number of dirty pages that be received.--- include/migration/colo.h | 1 + migration/colo.c | 2 -- migration/ram.c | 40 ++++++++++++++++++++++++++++++++++++++++ trace-events | 1 + 4 files changed, 42 insertions(+), 2 deletions(-)include/migration/colo.h +1
-0@@ -32,4 +32,5 @@ bool migration_incoming_in_colo_state(void);/* ram cache */ int colo_init_ram_cache (void );void colo_release_ram_cache (void ); +void colo_flush_ram_cache (void );#endif migration/colo.c +0
-2@@ -381,8 +381,6 @@ void *colo_process_incoming_thread(void *opaque) }qemu_mutex_unlock_iothread (); -/* TODO: flush vm state */ - ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_VMSTATE_LOADED ,0 );if (ret <0 ) { goto out;migration/ram.c +5
-0@@ -1601,6 +1601,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)int flags =0 , ret =0 ;static uint64_t seq_iter;int len =0 ; +bool need_flush = false; seq_iter++;@@ -1669,6 +1670,8 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) ret = -EINVAL ;break ; } + + need_flush = true; ch =qemu_get_byte (f);ram_handle_compressed (host, ch,TARGET_PAGE_SIZE );break ;@@ -1679,6 +1682,8 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) ret = -EINVAL ;break ; } + + need_flush = true;qemu_get_buffer (f, host,TARGET_PAGE_SIZE );break ;case RAM_SAVE_FLAG_COMPRESS_PAGE :
migration/ram.c static int ram_load(QEMUFile *f, void *opaque, int version_id) · line 1719
Quoted 4 lines
migration/ram.c +1
-0@@ -1711,6 +1716,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) ret = -EINVAL ;break ; } + need_flush = true;
You can probably move the 'need_flush' to the big if near the top of the loop in the current version.
migration/ram.c static int ram_load(QEMUFile *f, void *opaque, int version_id) · line 1741
Quoted 10 lines
migration/ram.c +3
-0break ;case RAM_SAVE_FLAG_EOS :/* normal exit */ @@ -1730,6 +1736,11 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) }rcu_read_unlock (); + +if (!ret && ram_cache_enable && need_flush) { +DPRINTF ("Flush ram_cache\n" );
trace_
Quoted 15 lines
migration/ram.c +8
-0+colo_flush_ram_cache (); + }DPRINTF ("Completed load of VM with exit code %d seq iteration " "%" PRIu64"\n" , ret, seq_iter);return ret;@@ -1799,6 +1810,35 @@ void colo_release_ram_cache(void)rcu_read_unlock (); } +/* +* Flush content of RAM cache into SVM's memory. +* Only flush the pages that be dirtied by PVM or SVM or both. +*/ +void colo_flush_ram_cache (void ) +{
migration/ram.c void colo_release_ram_cache(void) · line 1828
Quoted 10 lines
migration/ram.c +10
-0+RAMBlock *block =NULL ; +void *dst_host; +void *src_host; +ram_addr_t offset =0 ; + +trace_colo_flush_ram_cache (migration_dirty_pages); +rcu_read_lock (); + block =QLIST_FIRST_RCU (&ram_list.blocks); +while (block) { + offset =migration_bitmap_find_and_reset_dirty (block, offset);
You'll need to rework that a little (I split that into migration_bitmap_find_dirty and migration_bitmap_clear_dirty)
Quoted 32 lines
migration/ram.c +13
-0+if (offset >= block->used_length) { + offset =0 ; + block =QLIST_NEXT_RCU (block, next); + }else { + dst_host = block->host + offset; + src_host = block->host_cache + offset; +memcpy (dst_host, src_host,TARGET_PAGE_SIZE ); + } + } +rcu_read_unlock (); +assert (migration_dirty_pages ==0 ); +} +static SaveVMHandlers savevm_ram_handlers = { .save_live_setup = ram_save_setup, .save_live_iterate = ram_save_iterate,trace-events +1
-0@@ -1232,6 +1232,7 @@ qemu_file_fclose(void) "" migration_bitmap_sync_start(void) "" migration_bitmap_sync_end(uint64_t dirty_pages) "dirty_pages %" PRIu64"" migration_throttle(void) "" +colo_flush_ram_cache(uint64_t dirty_pages) "dirty_pages %" PRIu64"" # hw/display/qxl.c disable qxl_interface_set_mm_time(int qid, uint32_t mm_time) "%d %d"Signature · 1 line
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH COLO-Frame v10 16/38] COLO: Flush PVM's cached RAM into SVM's memory
Quoted 80 lines · Dr. David Alan Gilbert
Quoted 11 lines · * zhanghailiang ([email protected]) wrote:
During the time of VM's running, PVM may dirty some pages, we will transfer PVM's dirty pages to SVM and store them into SVM's RAM cache at next checkpoint time. So, the content of SVM's RAM cache will always be some with PVM's memory after checkpoint.
Instead of flushing all content of PVM's RAM cache into SVM's MEMORY, we do this in a more efficient way:
Only flush any page that dirtied by PVM since last checkpoint. In this way, we can ensure SVM's memory same with PVM's.Besides, we must ensure flush RAM cache before load device state.
Yes, just a couple of minor comments below; mostly OK.
Quoted 65 lines
Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>Signed-off-by Gonglei <[email protected]>---
v10: trace the number of dirty pages that be received.--- include/migration/colo.h | 1 + migration/colo.c | 2 -- migration/ram.c | 40 ++++++++++++++++++++++++++++++++++++++++ trace-events | 1 + 4 files changed, 42 insertions(+), 2 deletions(-)include/migration/colo.h +1
-0@@ -32,4 +32,5 @@ bool migration_incoming_in_colo_state(void);/* ram cache */ int colo_init_ram_cache (void );void colo_release_ram_cache (void ); +void colo_flush_ram_cache (void );#endif migration/colo.c +0
-2@@ -381,8 +381,6 @@ void *colo_process_incoming_thread(void *opaque) }qemu_mutex_unlock_iothread (); -/* TODO: flush vm state */ - ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_VMSTATE_LOADED ,0 );if (ret <0 ) { goto out;migration/ram.c +5
-0@@ -1601,6 +1601,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)int flags =0 , ret =0 ;static uint64_t seq_iter;int len =0 ; +bool need_flush = false; seq_iter++;@@ -1669,6 +1670,8 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) ret = -EINVAL ;break ; } + + need_flush = true; ch =qemu_get_byte (f);ram_handle_compressed (host, ch,TARGET_PAGE_SIZE );break ;@@ -1679,6 +1682,8 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) ret = -EINVAL ;break ; } + + need_flush = true;qemu_get_buffer (f, host,TARGET_PAGE_SIZE );break ;case RAM_SAVE_FLAG_COMPRESS_PAGE :
Quoted 9 lines
migration/ram.c static int ram_load(QEMUFile *f, void *opaque, int version_id) · line 1719
Quoted 5 lines
migration/ram.c +1
-0@@ -1711,6 +1716,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) ret = -EINVAL ;break ; } + need_flush = true;You can probably move the '
need_flush' to the big if near the top of the loop in the current version.
Good catch, i will fix it in next version.
Quoted 6 lines
Quoted 6 lines
migration/ram.c +0
-0break ;case RAM_SAVE_FLAG_EOS :/* normal exit */ @@ -1730,6 +1736,11 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) }
Quoted 6 lines
migration/ram.c static int ram_load(QEMUFile *f, void *opaque, int version_id) · line 1741
Quoted 4 lines
migration/ram.c +3
-0rcu_read_unlock (); + +if (!ret && ram_cache_enable && need_flush) { +DPRINTF ("Flush ram_cache\n" );
trace_
Got it.
Quoted 21 lines
Quoted 21 lines
migration/ram.c +13
-0+colo_flush_ram_cache (); + }DPRINTF ("Completed load of VM with exit code %d seq iteration " "%" PRIu64"\n" , ret, seq_iter);return ret;@@ -1799,6 +1810,35 @@ void colo_release_ram_cache(void)rcu_read_unlock (); } +/* +* Flush content of RAM cache into SVM's memory. +* Only flush the pages that be dirtied by PVM or SVM or both. +*/ +void colo_flush_ram_cache (void ) +{ +RAMBlock *block =NULL ; +void *dst_host; +void *src_host; +ram_addr_t offset =0 ; +
Quoted 9 lines
migration/ram.c void colo_release_ram_cache(void) · line 1828
Quoted 5 lines
migration/ram.c +5
-0+trace_colo_flush_ram_cache (migration_dirty_pages); +rcu_read_lock (); + block =QLIST_FIRST_RCU (&ram_list.blocks); +while (block) { + offset =migration_bitmap_find_and_reset_dirty (block, offset);You'll need to rework that a little (I split that into
migration_bitmap_find_dirtyandmigration_bitmap_clear_dirty)
Yes, i have rebase it in my private branch after your post-copy merged. ;)
Thanks,
zhanghailiang
Quoted 37 lines
Quoted 29 lines
migration/ram.c +13
-0+if (offset >= block->used_length) { + offset =0 ; + block =QLIST_NEXT_RCU (block, next); + }else { + dst_host = block->host + offset; + src_host = block->host_cache + offset; +memcpy (dst_host, src_host,TARGET_PAGE_SIZE ); + } + } +rcu_read_unlock (); +assert (migration_dirty_pages ==0 ); +} +static SaveVMHandlers savevm_ram_handlers = { .save_live_setup = ram_save_setup, .save_live_iterate = ram_save_iterate,trace-events +1
-1@@ -1232,6 +1232,7 @@ qemu_file_fclose(void) "" migration_bitmap_sync_start(void) "" migration_bitmap_sync_end(uint64_t dirty_pages) "dirty_pages %" PRIu64"" migration_throttle(void) "" +colo_flush_ram_cache(uint64_t dirty_pages) "dirty_pages %" PRIu64"" # hw/display/qxl.c disable qxl_interface_set_mm_time(int qid, uint32_t mm_time) "%d %d" --Quoted 3 lines
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK.
PATCH v10 17/38 COLO: synchronize PVM's state to SVM periodically
In reply to zhanghailiangDo checkpoint periodically, the default interval is 200ms.
--- migration/colo.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
migration/colo.c +14 -0
@@ -11,12 +11,19 @@*/ #include <unistd.h> +#include "qemu/timer.h" #include "sysemu/sysemu.h" #include "migration/colo.h" #include "trace.h" #include "qemu/error-report.h" #include "qemu/sockets.h" +/* +* checkpoint interval: unit ms +* Note: Please change this default value to 10000 when we support hybrid mode. +*/ +#define CHECKPOINT_MAX_PEROID 200 +/* colo buffer */ #define COLO_BUFFER_BASE_SIZE (4 * 1024 * 1024)
@@ -183,6 +190,7 @@ out:static void colo_process_checkpoint (MigrationState *s) {QEMUSizedBuffer *buffer =NULL ; +int64_t current_time, checkpoint_time =qemu_clock_get_ms (QEMU_CLOCK_HOST );int fd, ret =0 ;/* Dup the fd of to_dst_file */
@@ -220,11 +228,17 @@ static void colo_process_checkpoint(MigrationState *s)trace_colo_vm_state_change ("stop" ,"run" );while (s->state ==MIGRATION_STATUS_COLO ) { + current_time =qemu_clock_get_ms (QEMU_CLOCK_HOST ); +if (current_time - checkpoint_time <CHECKPOINT_MAX_PEROID ) { +g_usleep (100000 ); +continue ; + }/* start a colo checkpoint */ ret =colo_do_checkpoint_transaction (s, buffer);if (ret <0 ) { goto out; } + checkpoint_time =qemu_clock_get_ms (QEMU_CLOCK_HOST ); } out:
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH COLO-Frame v10 17/38] COLO: synchronize PVM's state to SVM periodically
Quoted 18 lines · * zhanghailiang ([email protected]) wrote:
Do checkpoint periodically, the default interval is 200ms.
Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>--- migration/colo.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)migration/colo.c +1
-0@@ -11,12 +11,19 @@*/ #include <unistd.h> +#include "qemu/timer.h" #include "sysemu/sysemu.h"
migration/colo.c line 25
Quoted 10 lines
migration/colo.c +5
-0#include "migration/colo.h" #include "trace.h" #include "qemu/error-report.h" #include "qemu/sockets.h" +/* +* checkpoint interval: unit ms +* Note: Please change this default value to 10000 when we support hybrid mode. +*/ +#define CHECKPOINT_MAX_PEROID 200
Why not put the patch that makes this a configurable parameter before this, and then we can use it straight away?
Quoted 12 lines
migration/colo.c +1
-0/* colo buffer */ #define COLO_BUFFER_BASE_SIZE (4 * 1024 * 1024)@@ -183,6 +190,7 @@ out:static void colo_process_checkpoint (MigrationState *s) {QEMUSizedBuffer *buffer =NULL ; +int64_t current_time, checkpoint_time =qemu_clock_get_ms (QEMU_CLOCK_HOST );int fd, ret =0 ;/* Dup the fd of to_dst_file */
migration/colo.c static void colo_process_checkpoint(MigrationState *s) · line 235
Quoted 8 lines
migration/colo.c +5
-0@@ -220,11 +228,17 @@ static void colo_process_checkpoint(MigrationState *s)trace_colo_vm_state_change ("stop" ,"run" );while (s->state ==MIGRATION_STATUS_COLO ) { + current_time =qemu_clock_get_ms (QEMU_CLOCK_HOST ); +if (current_time - checkpoint_time <CHECKPOINT_MAX_PEROID ) { +g_usleep (100000 ); +continue ; + }
I'm a bit concerned at the 100ms wait, when the period is 200ms; depending how the times work out, couldn't we end up waiting for just under 300ms? - that's a big error - and it's even more weird when we make it configurable later.
I don't think we've got a sleep-until, which is a shame; but how about something like:
if (current_time - checkpoint_time < CHECKPOINT_MAX_PEROID) {
int64_t delay_ms;
delay_ms = CHECKPOINT_MAX_PERIOD - (current_time - checkpoint_time);
g_usleep (delay_ms * 1000);
}Dave
Quoted 13 lines
migration/colo.c +1
-0/* start a colo checkpoint */ ret =colo_do_checkpoint_transaction (s, buffer);if (ret <0 ) { goto out; } + checkpoint_time =qemu_clock_get_ms (QEMU_CLOCK_HOST ); } out:Signature · 1 line
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH COLO-Frame v10 17/38] COLO: synchronize PVM's state to SVM periodically
Quoted 24 lines · Dr. David Alan Gilbert
Quoted 23 lines · * zhanghailiang ([email protected]) wrote:
Do checkpoint periodically, the default interval is 200ms.
Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>--- migration/colo.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)migration/colo.c +1
-0@@ -11,12 +11,19 @@*/ #include <unistd.h> +#include "qemu/timer.h" #include "sysemu/sysemu.h" #include "migration/colo.h" #include "trace.h" #include "qemu/error-report.h" #include "qemu/sockets.h"
Quoted 9 lines
migration/colo.c line 25
Quoted 5 lines
migration/colo.c +5
-0+/* +* checkpoint interval: unit ms +* Note: Please change this default value to 10000 when we support hybrid mode. +*/ +#define CHECKPOINT_MAX_PEROID 200Why not put the patch that makes this a configurable parameter before this, and then we can use it straight away?
Do you mean setting this value by command "migrate_set_parameter" ? I have realized it in patch 26.
Quoted 14 lines
Quoted 14 lines
migration/colo.c +1
-0/* colo buffer */ #define COLO_BUFFER_BASE_SIZE (4 * 1024 * 1024)@@ -183,6 +190,7 @@ out:static void colo_process_checkpoint (MigrationState *s) {QEMUSizedBuffer *buffer =NULL ; +int64_t current_time, checkpoint_time =qemu_clock_get_ms (QEMU_CLOCK_HOST );int fd, ret =0 ;/* Dup the fd of to_dst_file */ @@ -220,11 +228,17 @@ static void colo_process_checkpoint(MigrationState *s)trace_colo_vm_state_change ("stop" ,"run" );
Quoted 12 lines
migration/colo.c static void colo_process_checkpoint(MigrationState *s) · line 235
Quoted 6 lines
migration/colo.c +5
-0while (s->state ==MIGRATION_STATUS_COLO ) { + current_time =qemu_clock_get_ms (QEMU_CLOCK_HOST ); +if (current_time - checkpoint_time <CHECKPOINT_MAX_PEROID ) { +g_usleep (100000 ); +continue ; + }I'm a bit concerned at the 100ms wait, when the period is 200ms; depending how the times work out, couldn't we end up waiting for just under 300ms? - that's a big error - and it's even more weird when we make it configurable later.
Agreed.
Quoted 9 lines
I don't think we've got a sleep-until, which is a shame; but how about something like:
if (current_time - checkpoint_time < CHECKPOINT_MAX_PEROID) { int64_t delay_ms; delay_ms = CHECKPOINT_MAX_PERIOD - (current_time - checkpoint_time); g_usleep (delay_ms * 1000); }
That's a reasonable modification. I will fix it like that in next version.
Thanks,
zhanghailiang
Quoted 20 lines
Dave
Quoted 10 lines
migration/colo.c +1
-1/* start a colo checkpoint */ ret =colo_do_checkpoint_transaction (s, buffer);if (ret <0 ) { goto out; } + checkpoint_time =qemu_clock_get_ms (QEMU_CLOCK_HOST ); } out: --Quoted 3 lines
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK.
Re: [Qemu-devel] [PATCH COLO-Frame v10 17/38] COLO: synchronize PVM's state to SVM periodically
Quoted 35 lines · * zhanghailiang ([email protected]) wrote:
Quoted 24 lines · Dr. David Alan Gilbert
Quoted 23 lines · * zhanghailiang ([email protected]) wrote:
Do checkpoint periodically, the default interval is 200ms.
Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>--- migration/colo.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)migration/colo.c +1
-0@@ -11,12 +11,19 @@*/ #include <unistd.h> +#include "qemu/timer.h" #include "sysemu/sysemu.h" #include "migration/colo.h" #include "trace.h" #include "qemu/error-report.h" #include "qemu/sockets.h" Quoted 9 lines
migration/colo.c line 25
Quoted 5 lines
migration/colo.c +5
-0+/* +* checkpoint interval: unit ms +* Note: Please change this default value to 10000 when we support hybrid mode. +*/ +#define CHECKPOINT_MAX_PEROID 200Why not put the patch that makes this a configurable parameter before this, and then we can use it straight away?
Quoted 2 lines
Do you mean setting this value by command "
migrate_set_parameter" ? I have realized it in patch 26.
Yes, I mean reorder the patch series; put the migrate_set_parameter addition before this patch, and then use it straight away.
Dave
Quoted 39 lines
Quoted 14 lines
Quoted 14 lines
migration/colo.c +1
-0/* colo buffer */ #define COLO_BUFFER_BASE_SIZE (4 * 1024 * 1024)@@ -183,6 +190,7 @@ out:static void colo_process_checkpoint (MigrationState *s) {QEMUSizedBuffer *buffer =NULL ; +int64_t current_time, checkpoint_time =qemu_clock_get_ms (QEMU_CLOCK_HOST );int fd, ret =0 ;/* Dup the fd of to_dst_file */ @@ -220,11 +228,17 @@ static void colo_process_checkpoint(MigrationState *s)trace_colo_vm_state_change ("stop" ,"run" );Quoted 12 lines
migration/colo.c static void colo_process_checkpoint(MigrationState *s) · line 235
Quoted 6 lines
migration/colo.c +5
-0while (s->state ==MIGRATION_STATUS_COLO ) { + current_time =qemu_clock_get_ms (QEMU_CLOCK_HOST ); +if (current_time - checkpoint_time <CHECKPOINT_MAX_PEROID ) { +g_usleep (100000 ); +continue ; + }I'm a bit concerned at the 100ms wait, when the period is 200ms; depending how the times work out, couldn't we end up waiting for just under 300ms? - that's a big error - and it's even more weird when we make it configurable later.
Agreed.
Quoted 9 lines
I don't think we've got a sleep-until, which is a shame; but how about something like:
if (current_time - checkpoint_time < CHECKPOINT_MAX_PEROID) { int64_t delay_ms; delay_ms = CHECKPOINT_MAX_PERIOD - (current_time - checkpoint_time); g_usleep (delay_ms * 1000); }
Quoted 27 lines
That's a reasonable modification. I will fix it like that in next version.
Thanks,
zhanghailiangQuoted 20 lines
Dave
Quoted 10 lines
migration/colo.c +1
-1/* start a colo checkpoint */ ret =colo_do_checkpoint_transaction (s, buffer);if (ret <0 ) { goto out; } + checkpoint_time =qemu_clock_get_ms (QEMU_CLOCK_HOST ); } out: --Quoted 3 lines
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK.
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH COLO-Frame v10 17/38] COLO: synchronize PVM's state to SVM periodically
Quoted 36 lines · Dr. David Alan Gilbert
Quoted 35 lines · * zhanghailiang ([email protected]) wrote:
Quoted 33 lines · Dr. David Alan Gilbert
Quoted 18 lines · * zhanghailiang ([email protected]) wrote:
Do checkpoint periodically, the default interval is 200ms.
Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>--- migration/colo.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)migration/colo.c +1
-0@@ -11,12 +11,19 @@*/ #include <unistd.h> +#include "qemu/timer.h" #include "sysemu/sysemu.h" migration/colo.c line 25
Quoted 10 lines
migration/colo.c +5
-0#include "migration/colo.h" #include "trace.h" #include "qemu/error-report.h" #include "qemu/sockets.h" +/* +* checkpoint interval: unit ms +* Note: Please change this default value to 10000 when we support hybrid mode. +*/ +#define CHECKPOINT_MAX_PEROID 200Why not put the patch that makes this a configurable parameter before this, and then we can use it straight away?
Quoted 5 lines
Quoted 2 lines
Do you mean setting this value by command "
migrate_set_parameter" ? I have realized it in patch 26.Yes, I mean reorder the patch series; put the
migrate_set_parameteraddition before this patch, and then use it straight away.
OK, i will reorder them, thanks.
Quoted 72 lines
Quoted 40 lines
Quoted 15 lines
Quoted 15 lines
migration/colo.c +1
-0/* colo buffer */ #define COLO_BUFFER_BASE_SIZE (4 * 1024 * 1024)@@ -183,6 +190,7 @@ out:static void colo_process_checkpoint (MigrationState *s) {QEMUSizedBuffer *buffer =NULL ; +int64_t current_time, checkpoint_time =qemu_clock_get_ms (QEMU_CLOCK_HOST );int fd, ret =0 ;/* Dup the fd of to_dst_file */ @@ -220,11 +228,17 @@ static void colo_process_checkpoint(MigrationState *s)trace_colo_vm_state_change ("stop" ,"run" );Quoted 12 lines
migration/colo.c static void colo_process_checkpoint(MigrationState *s) · line 235
Quoted 6 lines
migration/colo.c +5
-0while (s->state ==MIGRATION_STATUS_COLO ) { + current_time =qemu_clock_get_ms (QEMU_CLOCK_HOST ); +if (current_time - checkpoint_time <CHECKPOINT_MAX_PEROID ) { +g_usleep (100000 ); +continue ; + }I'm a bit concerned at the 100ms wait, when the period is 200ms; depending how the times work out, couldn't we end up waiting for just under 300ms? - that's a big error - and it's even more weird when we make it configurable later.
Agreed.
Quoted 9 lines
I don't think we've got a sleep-until, which is a shame; but how about something like:
if (current_time - checkpoint_time < CHECKPOINT_MAX_PEROID) { int64_t delay_ms; delay_ms = CHECKPOINT_MAX_PERIOD - (current_time - checkpoint_time); g_usleep (delay_ms * 1000); }Quoted 27 lines
That's a reasonable modification. I will fix it like that in next version.
Thanks,
zhanghailiangQuoted 20 lines
Dave
Quoted 10 lines
migration/colo.c +1
-1/* start a colo checkpoint */ ret =colo_do_checkpoint_transaction (s, buffer);if (ret <0 ) { goto out; } + checkpoint_time =qemu_clock_get_ms (QEMU_CLOCK_HOST ); } out: --Quoted 3 lines
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK.
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK.
PATCH v10 18/38 COLO failover: Introduce a new command to trigger a failover
In reply to zhanghailiangWe leave users to choose whatever heartbeat solution they want, if the heartbeat is lost, or other errors they detect, they can use experimental command 'x_colo_lost_heartbeat' to tell COLO to do failover, COLO will do operations accordingly.
For example, if the command is sent to the PVM, the Primary side will exit COLO mode and take over operation. If sent to the Secondary, the secondary will run failover work, then take over server operation to become the new Primary.
---
v10: Rename command colo_lost_hearbeat to experimental 'x_colo_lost_heartbeat'
--- hmp-commands.hx | 15 +++++++++++++++ hmp.c | 8 ++++++++ hmp.h | 1 + include/migration/colo.h | 4 ++++ include/migration/failover.h | 20 ++++++++++++++++++++ migration/Makefile.objs | 2 +- migration/colo-comm.c | 11 +++++++++++ migration/colo-failover.c | 41 +++++++++++++++++++++++++++++++++++++++++ migration/colo.c | 1 + qapi-schema.json | 26 ++++++++++++++++++++++++++ qmp-commands.hx | 19 +++++++++++++++++++ stubs/migration-colo.c | 8 ++++++++ 12 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 include/migration/failover.h create mode 100644 migration/colo-failover.c
hmp-commands.hx +15 -0
@@ -1071,6 +1071,21 @@ Set the parameter @var{parameter} for migration. ETEXI { + .name = "x_colo_lost_heartbeat", + .args_type = "", + .params = "", + .help = "Tell COLO that heartbeat is lost,\n\t\t\t" + "a failover or takeover is needed.", + .mhandler.cmd = hmp_x_colo_lost_heartbeat, + }, + +STEXI +@item x_colo_lost_heartbeat +@findex x_colo_lost_heartbeat +Tell COLO that heartbeat is lost, a failover or takeover is needed. +ETEXI + + { .name = "client_migrate_info", .args_type = "protocol:s,hostname:s,port:i?,tls-port:i?,cert-subject:s?", .params = "protocol hostname port tls-port cert-subject",
hmp.c +8 -0
@@ -1294,6 +1294,14 @@ void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)hmp_handle_error (mon, &err); } +void hmp_x_colo_lost_heartbeat (Monitor *mon,const QDict *qdict) +{ +Error *err =NULL ; + +qmp_x_colo_lost_heartbeat (&err); +hmp_handle_error (mon, &err); +} +void hmp_set_password (Monitor *mon,const QDict *qdict) {const char *protocol =qdict_get_str (qdict,"protocol" );
hmp.h +1 -0
@@ -69,6 +69,7 @@ void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict);void hmp_migrate_set_parameter (Monitor *mon,const QDict *qdict);void hmp_migrate_set_cache_size (Monitor *mon,const QDict *qdict);void hmp_client_migrate_info (Monitor *mon,const QDict *qdict); +void hmp_x_colo_lost_heartbeat (Monitor *mon,const QDict *qdict);void hmp_set_password (Monitor *mon,const QDict *qdict);void hmp_expire_password (Monitor *mon,const QDict *qdict);void hmp_eject (Monitor *mon,const QDict *qdict);
include/migration/colo.h +4 -0
@@ -17,6 +17,7 @@#include "migration/migration.h" #include "qemu/coroutine_int.h" #include "qemu/thread.h" +#include "qemu/main-loop.h" bool colo_supported (void );void colo_info_mig_init (void );
@@ -29,6 +30,9 @@ bool migration_incoming_enable_colo(void);void migration_incoming_exit_colo (void );void *colo_process_incoming_thread (void *opaque);bool migration_incoming_in_colo_state (void ); + +int get_colo_mode (void ); +/* ram cache */ int colo_init_ram_cache (void );void colo_release_ram_cache (void );
include/migration/failover.h new file +20 -0
@@ -0,0 +1,20 @@ +/* +* COarse-grain LOck-stepping Virtual Machines for Non-stop Service (COLO) +* (a.k.a. Fault Tolerance or Continuous Replication) +* +* Copyright (c) 2015 HUAWEI TECHNOLOGIES CO.,LTD. +* Copyright (c) 2015 FUJITSU LIMITED +* Copyright (c) 2015 Intel Corporation +* +* This work is licensed under the terms of the GNU GPL, version 2 or +* later. See the COPYING file in the top-level directory. +*/ + +#ifndef QEMU_FAILOVER_H +#define QEMU_FAILOVER_H + +#include "qemu-common.h" + +void failover_request_active (Error **errp); + +#endif
migration/Makefile.objs +1 -1
@@ -1,6 +1,6 @@ common-obj-y += migration.o tcp.o -common-obj-$(CONFIG_COLO) += colo.o common-obj-y += colo-comm.o +common-obj-$(CONFIG_COLO) += colo.o colo-failover.o common-obj-y += vmstate.o common-obj-y += qemu-file.o qemu-file-buf.o qemu-file-unix.o qemu-file-stdio.o common-obj-y += xbzrle.o
migration/colo-comm.c +11 -0
@@ -20,6 +20,17 @@ typedef struct {static COLOInfo colo_info; +int get_colo_mode (void ) +{ +if (migration_in_colo_state ()) { +return COLO_MODE_PRIMARY ; + }else if (migration_incoming_in_colo_state ()) { +return COLO_MODE_SECONDARY ; + }else { +return COLO_MODE_UNKNOWN ; + } +} +static void colo_info_pre_save (void *opaque) {COLOInfo *s = opaque;
migration/colo-failover.c new file +41 -0
41 lines not on this page · raw message
migration/colo.c +1 -0
@@ -17,6 +17,7 @@#include "trace.h" #include "qemu/error-report.h" #include "qemu/sockets.h" +#include "migration/failover.h" /* * checkpoint interval: unit ms
qapi-schema.json +26 -0
@@ -734,6 +734,32 @@ 'checkpoint-reply', 'vmstate-send', 'vmstate-size', 'vmstate-received', 'vmstate-loaded' ] } +## +# @COLOMode +# +# The colo mode +# +# @unknown: unknown mode +# +# @primary: master side +# +# @secondary: slave side +# +# Since: 2.5 +## +{ 'enum': 'COLOMode', + 'data': [ 'unknown', 'primary', 'secondary'] } + +## +# @x-colo-lost-heartbeat +# +# Tell qemu that heartbeat is lost, request it to do takeover procedures. +# +# Since: 2.5 +## +{ 'command': 'x-colo-lost-heartbeat' } + +## # @MouseInfo: # # Information about a mouse device.
qmp-commands.hx +19 -0
@@ -786,6 +786,25 @@ Example: EQMP { + .name = "x-colo-lost-heartbeat", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_x_colo_lost_heartbeat, + }, + +SQMP +x-colo-lost-heartbeat +-------------------- + +Tell COLO that heartbeat is lost, a failover or takeover is needed. + +Example: + +-> { "execute": "x-colo-lost-heartbeat" } +<- { "return": {} } + +EQMP + + { .name = "client_migrate_info", .args_type = "protocol:s,hostname:s,port:i?,tls-port:i?,cert-subject:s?", .params = "protocol hostname port tls-port cert-subject",
stubs/migration-colo.c +8 -0
@@ -11,6 +11,7 @@*/ #include "migration/colo.h" +#include "qmp-commands.h" bool colo_supported (void ) {
@@ -35,3 +36,10 @@ void *colo_process_incoming_thread(void *opaque) {return NULL ; } + +void qmp_x_colo_lost_heartbeat (Error **errp) +{ +error_setg (errp,"COLO is not supported, please rerun configure" +" with --enable-colo option in order to support" +" COLO feature" ); +}
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH COLO-Frame v10 18/38] COLO failover: Introduce a new command to trigger a failover
Quoted 20 lines · zhanghailiang
We leave users to choose whatever heartbeat solution they want, if the heartbeat is lost, or other errors they detect, they can use experimental command '
x_colo_lost_heartbeat' to tell COLO to do failover, COLO will do operations accordingly.For example, if the command is sent to the PVM, the Primary side will exit COLO mode and take over operation. If sent to the Secondary, the secondary will run failover work, then take over server operation to become the new Primary.
Cc Luiz Capitulino <[email protected]>Cc Eric Blake <[email protected]>Cc Markus Armbruster <[email protected]>Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>---
v10: Rename commandcolo_lost_hearbeatto experimental 'x_colo_lost_heartbeat'
---
include/migration/colo.h bool migration_incoming_enable_colo(void); · line 34
Quoted 5 lines
include/migration/colo.h +2
-0@@ -29,6 +30,9 @@ bool migration_incoming_enable_colo(void);void migration_incoming_exit_colo (void );void *colo_process_incoming_thread (void *opaque);bool migration_incoming_in_colo_state (void ); + +int get_colo_mode (void );
Should this return an enum type instead of an int?
Quoted 5 lines
migration/colo-comm.c +1
-0+++ b/migration/colo-comm.c@@ -20,6 +20,17 @@ typedef struct {static COLOInfo colo_info;
migration/colo-comm.c typedef struct { · line 32
Quoted 10 lines
migration/colo-comm.c +10
-0+int get_colo_mode (void ) +{ +if (migration_in_colo_state ()) { +return COLO_MODE_PRIMARY ; + }else if (migration_incoming_in_colo_state ()) { +return COLO_MODE_SECONDARY ; + }else { +return COLO_MODE_UNKNOWN ; + } +}
Particularly since it is always returning values of the same enum.
Not fatal to the patch, so much as a style issue.
migration/colo-failover.c line 37
Quoted 5 lines
migration/colo-failover.c new file +5
-0+void qmp_x_colo_lost_heartbeat (Error **errp) +{ +if (get_colo_mode () ==COLO_MODE_UNKNOWN ) { +error_setg (errp,QERR_FEATURE_DISABLED ,"colo" ); +return ;
We've slowly been trying to get rid of QERR_ usage. But you aren't the first user, and a global cleanup may be better. So I can overlook it for now.
Quoted 16 lines
+++
b/qapi-schema.jsonqapi-schema.json +11
-0@@ -734,6 +734,32 @@ 'checkpoint-reply', 'vmstate-send', 'vmstate-size', 'vmstate-received', 'vmstate-loaded' ] } +## +# @COLOMode +# +# The colo mode +# +# @unknown: unknown mode +# +# @primary: master side +# +# @secondary: slave side +#
qapi-schema.json line 757
Quoted 10 lines
qapi-schema.json +10
-0+# Since: 2.5 +## +{ 'enum': 'COLOMode', + 'data': [ 'unknown', 'primary', 'secondary'] } + +## +# @x-colo-lost-heartbeat +# +# Tell qemu that heartbeat is lost, request it to do takeover procedures. +#
The docs here are rather short, compared to your commit message (in particular, the fact that it causes a different action depending on whether it is sent to primary [takeover] or secondary [failover]).
Review line 758
Quoted 1 line
(quoted diff) +1
-0+# Since: 2.5
2.6 in both places.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH COLO-Frame v10 18/38] COLO failover: Introduce a new command to trigger a failover
Quoted 48 lines · Eric Blake
Quoted 20 lines · zhanghailiang
We leave users to choose whatever heartbeat solution they want, if the heartbeat is lost, or other errors they detect, they can use experimental command '
x_colo_lost_heartbeat' to tell COLO to do failover, COLO will do operations accordingly.For example, if the command is sent to the PVM, the Primary side will exit COLO mode and take over operation. If sent to the Secondary, the secondary will run failover work, then take over server operation to become the new Primary.
Cc Luiz Capitulino <[email protected]>Cc Eric Blake <[email protected]>Cc Markus Armbruster <[email protected]>Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>---
v10: Rename commandcolo_lost_hearbeatto experimental 'x_colo_lost_heartbeat'
---include/migration/colo.h bool migration_incoming_enable_colo(void); · line 34
Quoted 5 lines
include/migration/colo.h +2
-0@@ -29,6 +30,9 @@ bool migration_incoming_enable_colo(void);void migration_incoming_exit_colo (void );void *colo_process_incoming_thread (void *opaque);bool migration_incoming_in_colo_state (void ); + +int get_colo_mode (void );Should this return an enum type instead of an int?
Quoted 5 lines
migration/colo-comm.c +1
-0+++ b/migration/colo-comm.c@@ -20,6 +20,17 @@ typedef struct {static COLOInfo colo_info;migration/colo-comm.c typedef struct { · line 32
Quoted 10 lines
migration/colo-comm.c +10
-0+int get_colo_mode (void ) +{ +if (migration_in_colo_state ()) { +return COLO_MODE_PRIMARY ; + }else if (migration_incoming_in_colo_state ()) { +return COLO_MODE_SECONDARY ; + }else { +return COLO_MODE_UNKNOWN ; + } +}Particularly since it is always returning values of the same enum.
Quoted 2 lines
Not fatal to the patch, so much as a style issue.
Seems reasonable. I will fix it in next version.
Quoted 11 lines
migration/colo-failover.c line 37
Quoted 6 lines
migration/colo-failover.c new file +5
-0+void qmp_x_colo_lost_heartbeat (Error **errp) +{ +if (get_colo_mode () ==COLO_MODE_UNKNOWN ) { +error_setg (errp,QERR_FEATURE_DISABLED ,"colo" ); +return ;We've slowly been trying to get rid of
QERR_usage. But you aren't the first user, and a global cleanup may be better. So I can overlook it for now.
Yes, there are still several places in qemu that use 'QERR_FEATURE_DISABLED', How to cleanup them ? Change it to 'error_setg(errp, "COLO feature is not enabled") here ?
Quoted 22 lines
Quoted 22 lines
+++
b/qapi-schema.jsonqapi-schema.json +17
-0@@ -734,6 +734,32 @@ 'checkpoint-reply', 'vmstate-send', 'vmstate-size', 'vmstate-received', 'vmstate-loaded' ] } +## +# @COLOMode +# +# The colo mode +# +# @unknown: unknown mode +# +# @primary: master side +# +# @secondary: slave side +# +# Since: 2.5 +## +{ 'enum': 'COLOMode', + 'data': [ 'unknown', 'primary', 'secondary'] } + +##
Quoted 9 lines
qapi-schema.json line 757
Quoted 4 lines
qapi-schema.json +4
-0+# @x-colo-lost-heartbeat +# +# Tell qemu that heartbeat is lost, request it to do takeover procedures. +#The docs here are rather short, compared to your commit message (in particular, the fact that it causes a different action depending on whether it is sent to primary [takeover] or secondary [failover]).
Ok, I will add more comments here. Thanks.
Quoted 4 lines
Review line 758
Quoted 1 line
(quoted diff) +1
-0+# Since: 2.52.6 in both places.
PATCH v10 19/38 COLO failover: Introduce state to record failover process
In reply to zhanghailiangWhen handling failover, we do different things according to the different stage of failover process, here we introduce a global atomic variable to record the status of failover.
We add four failover status to indicate the different stage of failover process. You should use the helpers to get and set the value.
--- include/migration/failover.h | 10 ++++++++++ migration/colo-failover.c | 37 +++++++++++++++++++++++++++++++++++++ migration/colo.c | 4 ++++ trace-events | 1 + 4 files changed, 52 insertions(+)
include/migration/failover.h +10 -0
@@ -15,6 +15,16 @@#include "qemu-common.h" +typedef enum COLOFailoverStatus { +FAILOVER_STATUS_NONE =0 , +FAILOVER_STATUS_REQUEST =1 ,/* Request but not handled */ +FAILOVER_STATUS_HANDLING =2 ,/* In the process of handling failover */ +FAILOVER_STATUS_COMPLETED =3 ,/* Finish the failover process */ +}COLOFailoverStatus ; + +void failover_init_state (void ); +int failover_set_state (int old_state,int new_state); +int failover_get_state (void );void failover_request_active (Error **errp);#endif
migration/colo-failover.c +37 -0
@@ -14,22 +14,59 @@#include "migration/failover.h" #include "qmp-commands.h" #include "qapi/qmp/qerror.h" +#include "qemu/error-report.h" +#include "trace.h" static QEMUBH *failover_bh; +static COLOFailoverStatus failover_state;static void colo_failover_bh (void *opaque) { +int old_state; +qemu_bh_delete (failover_bh); failover_bh =NULL ; + old_state =failover_set_state (FAILOVER_STATUS_REQUEST , +FAILOVER_STATUS_HANDLING ); +if (old_state !=FAILOVER_STATUS_REQUEST ) { +error_report (" Unkown error for failover, old_state=%d" , old_state); +return ; + }/*TODO: Do failover work */ }void failover_request_active (Error **errp) { +if (failover_set_state (FAILOVER_STATUS_NONE ,FAILOVER_STATUS_REQUEST ) + !=FAILOVER_STATUS_NONE ) { +error_setg (errp,"COLO failover is already actived" ); +return ; + } failover_bh =qemu_bh_new (colo_failover_bh,NULL );qemu_bh_schedule (failover_bh); } +void failover_init_state (void ) +{ + failover_state =FAILOVER_STATUS_NONE ; +} + +int failover_set_state (int old_state,int new_state) +{ +int old; + + old =atomic_cmpxchg (&failover_state, old_state, new_state);; +if (old == old_state) { +trace_colo_failover_set_state (new_state); + } +return old; +} + +int failover_get_state (void ) +{ +return atomic_read (&failover_state); +} +void qmp_x_colo_lost_heartbeat (Error **errp) {if (get_colo_mode () ==COLO_MODE_UNKNOWN ) {
migration/colo.c +4 -0
@@ -194,6 +194,8 @@ static void colo_process_checkpoint(MigrationState *s)int64_t current_time, checkpoint_time =qemu_clock_get_ms (QEMU_CLOCK_HOST );int fd, ret =0 ; +failover_init_state (); +/* Dup the fd of to_dst_file */ fd =dup (qemu_get_fd (s->to_dst_file));if (fd ==-1 ) {
@@ -310,6 +312,8 @@ void *colo_process_incoming_thread(void *opaque)migrate_set_state (&mis->state,MIGRATION_STATUS_ACTIVE ,MIGRATION_STATUS_COLO ); +failover_init_state (); + fd =dup (qemu_get_fd (mis->from_src_file));if (fd <0 ) { ret = -errno;
trace-events +1 -0
@@ -1502,6 +1502,7 @@ rdma_start_outgoing_migration_after_rdma_source_init(void) "" colo_vm_state_change(const char *old, const char *new) "Change '%s' => '%s'" colo_ctl_put(const char *msg, uint64_t value) "Send '%s' cmd, value: %" PRIu64"" colo_ctl_get(const char *msg) "Receive '%s' cmd" +colo_failover_set_state(int new_state) "new state %d" # kvm-all.c kvm_ioctl(int type, void *arg) "type 0x%x, arg %p"
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH COLO-Frame v10 19/38] COLO failover: Introduce state to record failover process
Quoted 20 lines · * zhanghailiang ([email protected]) wrote:
When handling failover, we do different things according to the different stage of failover process, here we introduce a global atomic variable to record the status of failover.
We add four failover status to indicate the different stage of failover process. You should use the helpers to get and set the value.
Signed-off-by zhanghailiang <[email protected]>--- include/migration/failover.h | 10 ++++++++++ migration/colo-failover.c | 37 +++++++++++++++++++++++++++++++++++++ migration/colo.c | 4 ++++ trace-events | 1 + 4 files changed, 52 insertions(+)include/migration/failover.h +0
-0
include/migration/failover.h line 23
Quoted 9 lines
include/migration/failover.h +6
-0@@ -15,6 +15,16 @@#include "qemu-common.h" +typedef enum COLOFailoverStatus { +FAILOVER_STATUS_NONE =0 , +FAILOVER_STATUS_REQUEST =1 ,/* Request but not handled */ +FAILOVER_STATUS_HANDLING =2 ,/* In the process of handling failover */ +FAILOVER_STATUS_COMPLETED =3 ,/* Finish the failover process */ +}COLOFailoverStatus ;
OK - there's a couple of typo's later, but other than those:
Quoted 21 lines
include/migration/failover.h +4
-0+ +void failover_init_state (void ); +int failover_set_state (int old_state,int new_state); +int failover_get_state (void );void failover_request_active (Error **errp);#endif migration/colo-failover.c +3
-0@@ -14,22 +14,59 @@#include "migration/failover.h" #include "qmp-commands.h" #include "qapi/qmp/qerror.h" +#include "qemu/error-report.h" +#include "trace.h" static QEMUBH *failover_bh; +static COLOFailoverStatus failover_state;
migration/colo-failover.c line 32
Quoted 10 lines
migration/colo-failover.c +6
-0static void colo_failover_bh (void *opaque) { +int old_state; +qemu_bh_delete (failover_bh); failover_bh =NULL ; + old_state =failover_set_state (FAILOVER_STATUS_REQUEST , +FAILOVER_STATUS_HANDLING ); +if (old_state !=FAILOVER_STATUS_REQUEST ) { +error_report (" Unkown error for failover, old_state=%d" , old_state);
Typo 'Unkown'
Quoted 16 lines
migration/colo-failover.c +7
-0+return ; + }/*TODO: Do failover work */ }void failover_request_active (Error **errp) { +if (failover_set_state (FAILOVER_STATUS_NONE ,FAILOVER_STATUS_REQUEST ) + !=FAILOVER_STATUS_NONE ) { +error_setg (errp,"COLO failover is already actived" ); +return ; + } failover_bh =qemu_bh_new (colo_failover_bh,NULL );qemu_bh_schedule (failover_bh); }
migration/colo-failover.c line 58
Quoted 10 lines
migration/colo-failover.c +10
-0+void failover_init_state (void ) +{ + failover_state =FAILOVER_STATUS_NONE ; +} + +int failover_set_state (int old_state,int new_state) +{ +int old; + + old =atomic_cmpxchg (&failover_state, old_state, new_state);;
Typo double ;;
Quoted 52 lines
migration/colo-failover.c +11
-0+if (old == old_state) { +trace_colo_failover_set_state (new_state); + } +return old; +} + +int failover_get_state (void ) +{ +return atomic_read (&failover_state); +} +void qmp_x_colo_lost_heartbeat (Error **errp) {if (get_colo_mode () ==COLO_MODE_UNKNOWN ) {migration/colo.c +4
-0@@ -194,6 +194,8 @@ static void colo_process_checkpoint(MigrationState *s)int64_t current_time, checkpoint_time =qemu_clock_get_ms (QEMU_CLOCK_HOST );int fd, ret =0 ; +failover_init_state (); +/* Dup the fd of to_dst_file */ fd =dup (qemu_get_fd (s->to_dst_file));if (fd ==-1 ) {@@ -310,6 +312,8 @@ void *colo_process_incoming_thread(void *opaque)migrate_set_state (&mis->state,MIGRATION_STATUS_ACTIVE ,MIGRATION_STATUS_COLO ); +failover_init_state (); + fd =dup (qemu_get_fd (mis->from_src_file));if (fd <0 ) { ret = -errno;trace-events +1
-0@@ -1502,6 +1502,7 @@ rdma_start_outgoing_migration_after_rdma_source_init(void) "" colo_vm_state_change(const char *old, const char *new) "Change '%s' => '%s'" colo_ctl_put(const char *msg, uint64_t value) "Send '%s' cmd, value: %" PRIu64"" colo_ctl_get(const char *msg) "Receive '%s' cmd" +colo_failover_set_state(int new_state) "new state %d" # kvm-all.c kvm_ioctl(int type, void *arg) "type 0x%x, arg %p"Signature · 1 line
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH COLO-Frame v10 19/38] COLO failover: Introduce state to record failover process
Quoted 24 lines · Dr. David Alan Gilbert
Quoted 23 lines · * zhanghailiang ([email protected]) wrote:
When handling failover, we do different things according to the different stage of failover process, here we introduce a global atomic variable to record the status of failover.
We add four failover status to indicate the different stage of failover process. You should use the helpers to get and set the value.
Signed-off-by zhanghailiang <[email protected]>--- include/migration/failover.h | 10 ++++++++++ migration/colo-failover.c | 37 +++++++++++++++++++++++++++++++++++++ migration/colo.c | 4 ++++ trace-events | 1 + 4 files changed, 52 insertions(+)include/migration/failover.h +0
-0@@ -15,6 +15,16 @@#include "qemu-common.h"
Quoted 9 lines
include/migration/failover.h line 23
Quoted 6 lines
include/migration/failover.h +6
-0+typedef enum COLOFailoverStatus { +FAILOVER_STATUS_NONE =0 , +FAILOVER_STATUS_REQUEST =1 ,/* Request but not handled */ +FAILOVER_STATUS_HANDLING =2 ,/* In the process of handling failover */ +FAILOVER_STATUS_COMPLETED =3 ,/* Finish the failover process */ +}COLOFailoverStatus ;OK - there's a couple of typo's later, but other than those:
I will fix them all in next version, thanks.
Quoted 122 lines
Reviewed-by Dr. David Alan Gilbert <[email protected]>Quoted 21 lines
include/migration/failover.h +4
-0+ +void failover_init_state (void ); +int failover_set_state (int old_state,int new_state); +int failover_get_state (void );void failover_request_active (Error **errp);#endif migration/colo-failover.c +3
-0@@ -14,22 +14,59 @@#include "migration/failover.h" #include "qmp-commands.h" #include "qapi/qmp/qerror.h" +#include "qemu/error-report.h" +#include "trace.h" static QEMUBH *failover_bh; +static COLOFailoverStatus failover_state;migration/colo-failover.c line 32
Quoted 10 lines
migration/colo-failover.c +6
-0static void colo_failover_bh (void *opaque) { +int old_state; +qemu_bh_delete (failover_bh); failover_bh =NULL ; + old_state =failover_set_state (FAILOVER_STATUS_REQUEST , +FAILOVER_STATUS_HANDLING ); +if (old_state !=FAILOVER_STATUS_REQUEST ) { +error_report (" Unkown error for failover, old_state=%d" , old_state);Typo 'Unkown'
Quoted 16 lines
migration/colo-failover.c +7
-0+return ; + }/*TODO: Do failover work */ }void failover_request_active (Error **errp) { +if (failover_set_state (FAILOVER_STATUS_NONE ,FAILOVER_STATUS_REQUEST ) + !=FAILOVER_STATUS_NONE ) { +error_setg (errp,"COLO failover is already actived" ); +return ; + } failover_bh =qemu_bh_new (colo_failover_bh,NULL );qemu_bh_schedule (failover_bh); }migration/colo-failover.c line 58
Quoted 10 lines
migration/colo-failover.c +10
-0+void failover_init_state (void ) +{ + failover_state =FAILOVER_STATUS_NONE ; +} + +int failover_set_state (int old_state,int new_state) +{ +int old; + + old =atomic_cmpxchg (&failover_state, old_state, new_state);;Typo double ;;
Quoted 49 lines
migration/colo-failover.c +11
-0+if (old == old_state) { +trace_colo_failover_set_state (new_state); + } +return old; +} + +int failover_get_state (void ) +{ +return atomic_read (&failover_state); +} +void qmp_x_colo_lost_heartbeat (Error **errp) {if (get_colo_mode () ==COLO_MODE_UNKNOWN ) {migration/colo.c +4
-0@@ -194,6 +194,8 @@ static void colo_process_checkpoint(MigrationState *s)int64_t current_time, checkpoint_time =qemu_clock_get_ms (QEMU_CLOCK_HOST );int fd, ret =0 ; +failover_init_state (); +/* Dup the fd of to_dst_file */ fd =dup (qemu_get_fd (s->to_dst_file));if (fd ==-1 ) {@@ -310,6 +312,8 @@ void *colo_process_incoming_thread(void *opaque)migrate_set_state (&mis->state,MIGRATION_STATUS_ACTIVE ,MIGRATION_STATUS_COLO ); +failover_init_state (); + fd =dup (qemu_get_fd (mis->from_src_file));if (fd <0 ) { ret = -errno;trace-events +1
-1@@ -1502,6 +1502,7 @@ rdma_start_outgoing_migration_after_rdma_source_init(void) "" colo_vm_state_change(const char *old, const char *new) "Change '%s' => '%s'" colo_ctl_put(const char *msg, uint64_t value) "Send '%s' cmd, value: %" PRIu64"" colo_ctl_get(const char *msg) "Receive '%s' cmd" +colo_failover_set_state(int new_state) "new state %d" # kvm-all.c kvm_ioctl(int type, void *arg) "type 0x%x, arg %p" --Quoted 3 lines
1.8.3.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK.
PATCH v10 20/38 COLO: Implement failover work for Primary VM
In reply to zhanghailiangFor PVM, if there is failover request from users.
The colo thread will exit the loop while the failover BH does the cleanup work and resumes VM.
---
v10: Call migration_end() in primary_vm_do_failover()
--- include/migration/colo.h | 4 +++ include/migration/failover.h | 1 + include/migration/migration.h | 1 + migration/colo-failover.c | 7 ++++- migration/colo.c | 59 +++++++++++++++++++++++++++++++++++++++++-- migration/ram.c | 2 +- 6 files changed, 70 insertions(+), 4 deletions(-)
include/migration/colo.h +4 -0
@@ -37,4 +37,8 @@ int get_colo_mode(void);int colo_init_ram_cache (void );void colo_release_ram_cache (void );void colo_flush_ram_cache (void ); + +/* failover */ +void colo_do_failover (MigrationState *s); +#endif
include/migration/failover.h +1 -0
@@ -26,5 +26,6 @@ void failover_init_state(void);int failover_set_state (int old_state,int new_state);int failover_get_state (void );void failover_request_active (Error **errp); +bool failover_request_is_active (void );#endif
include/migration/migration.h +1 -0
@@ -210,6 +210,7 @@ size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset, uint64_t *bytes_sent);void ram_mig_init (void ); +void migration_end (void );void savevm_skip_section_footers (void );void register_global_state (void );void global_state_set_optional (void );
migration/colo-failover.c +6 -1
@@ -32,7 +32,7 @@ static void colo_failover_bh(void *opaque)error_report (" Unkown error for failover, old_state=%d" , old_state);return ; } -/*TODO: Do failover work */ +colo_do_failover (NULL ); }void failover_request_active (Error **errp)
@@ -67,6 +67,11 @@ int failover_get_state(void)return atomic_read (&failover_state); } +bool failover_request_is_active (void ) +{ +return ((failover_get_state () !=FAILOVER_STATUS_NONE )); +} +void qmp_x_colo_lost_heartbeat (Error **errp) {if (get_colo_mode () ==COLO_MODE_UNKNOWN ) {
migration/colo.c +57 -2
86 lines not on this page · raw message
migration/ram.c +1 -1
@@ -1102,7 +1102,7 @@ static void migration_bitmap_free(struct BitmapRcu *bmap)g_free (bmap); } -static void migration_end (void ) +void migration_end (void ) {/* caller have hold iothread lock or is in a bh, so there is * no writing race against this migration_bitmap
Signature · 1 line
1.8.3.1
PATCH v10 21/38 COLO: Implement failover work for Secondary VM
In reply to zhanghailiangIf users require SVM to takeover work, colo incoming thread should exit from loop while failover BH helps backing to migration incoming coroutine.
--- migration/colo.c | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-)
migration/colo.c +38 -3
@@ -52,6 +52,33 @@ static bool colo_runstate_is_stopped(void)return runstate_check (RUN_STATE_COLO ) || !runstate_is_running (); } +static void secondary_vm_do_failover (void ) +{ +int old_state; +MigrationIncomingState *mis =migration_incoming_get_current (); + +migrate_set_state (&mis->state,MIGRATION_STATUS_COLO , +MIGRATION_STATUS_COMPLETED ); + +if (!autostart) { +error_report ("\"-S\" qemu option will be ignored in secondary side" ); +/* recover runstate to normal migration finish state */ + autostart = true; + } + + old_state =failover_set_state (FAILOVER_STATUS_HANDLING , +FAILOVER_STATUS_COMPLETED ); +if (old_state !=FAILOVER_STATUS_HANDLING ) { +error_report ("Serious error while do failover for secondary VM," +"old_state: %d" , old_state); +return ; + } +/* For Secondary VM, jump to incoming co */ +if (mis->migration_incoming_co) { +qemu_coroutine_enter (mis->migration_incoming_co,NULL ); + } +} +static void primary_vm_do_failover (void ) {MigrationState *s =migrate_get_current ();
@@ -83,6 +110,8 @@ void colo_do_failover(MigrationState *s)if (get_colo_mode () ==COLO_MODE_PRIMARY ) {primary_vm_do_failover (); + }else { +secondary_vm_do_failover (); } }
@@ -410,6 +439,11 @@ void *colo_process_incoming_thread(void *opaque) } } +if (failover_request_is_active ()) { +error_report ("failover request" ); + goto out; + } + ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_CHECKPOINT_REPLY ,0 );if (ret <0 ) { goto out;
@@ -474,10 +508,11 @@ out:qemu_fclose (fb); }qsb_free (buffer); - -qemu_mutex_lock_iothread (); +/* Here, we can ensure BH is hold the global lock, and will join colo +* incoming thread, so here it is not necessary to lock here again, +* or there will be a deadlock error. +*/ colo_release_ram_cache (); -qemu_mutex_unlock_iothread ();if (mis->to_src_file) {qemu_fclose (mis->to_src_file);
Signature · 1 line
1.8.3.1
PATCH v10 22/38 COLO: implement default failover treatment
In reply to zhanghailiangIf we detect some error in colo, we will wait for some time, hoping users also detect it. If users don't issue failover command. We will go into default failover procedure, which the PVM will takeover work while SVM is exit in default.
--- migration/colo.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
migration/colo.c +46 -0
@@ -25,6 +25,14 @@*/ #define CHECKPOINT_MAX_PEROID 200 +/* +* The delay time before qemu begin the procedure of default failover treatment. +* Unit: ms +* Fix me: This value should be able to change by command +* 'migrate-set-parameters' +*/ +#define DEFAULT_FAILOVER_DELAY 2000 +/* colo buffer */ #define COLO_BUFFER_BASE_SIZE (4 * 1024 * 1024)
@@ -273,6 +281,7 @@ static void colo_process_checkpoint(MigrationState *s) {QEMUSizedBuffer *buffer =NULL ;int64_t current_time, checkpoint_time =qemu_clock_get_ms (QEMU_CLOCK_HOST ); +int64_t error_time;int fd, ret =0 ;failover_init_state ();
@@ -331,8 +340,25 @@ static void colo_process_checkpoint(MigrationState *s) } out: + current_time = error_time =qemu_clock_get_ms (QEMU_CLOCK_HOST );if (ret <0 ) {error_report ("%s: %s" , __func__,strerror (-ret)); +/* Give users time to get involved in this verdict */ +while (current_time - error_time <=DEFAULT_FAILOVER_DELAY ) { +if (failover_request_is_active ()) { +error_report ("Primary VM will take over work" ); +break ; + } +usleep (100 *1000 ); + current_time =qemu_clock_get_ms (QEMU_CLOCK_HOST ); + } + +qemu_mutex_lock_iothread (); +if (!failover_request_is_active ()) { +error_report ("Primary VM will take over work in default" ); +failover_request_active (NULL ); + } +qemu_mutex_unlock_iothread (); }qsb_free (buffer);
@@ -391,6 +417,7 @@ void *colo_process_incoming_thread(void *opaque)QEMUFile *fb =NULL ;QEMUSizedBuffer *buffer =NULL ;/* Cache incoming device state */ int total_size; +int64_t error_time, current_time;int fd, ret =0 ; migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE,
@@ -499,9 +526,28 @@ void *colo_process_incoming_thread(void *opaque) } out: + current_time = error_time =qemu_clock_get_ms (QEMU_CLOCK_HOST );if (ret <0 ) {error_report ("colo incoming thread will exit, detect error: %s" ,strerror (-ret)); +/* Give users time to get involved in this verdict */ +while (current_time - error_time <=DEFAULT_FAILOVER_DELAY ) { +if (failover_request_is_active ()) { +error_report ("Secondary VM will take over work" ); +break ; + } +usleep (100 *1000 ); + current_time =qemu_clock_get_ms (QEMU_CLOCK_HOST ); + } +/* check flag again*/ +if (!failover_request_is_active ()) { +/* +* We assume that Primary VM is still alive according to +* heartbeat, just kill Secondary VM +*/ +error_report ("SVM is going to exit in default!" ); +exit (1 ); + } }if (fb) {
Signature · 1 line
1.8.3.1
PATCH v10 23/38 qmp event: Add event notification for COLO error
In reply to zhanghailiangIf some errors happen during VM's COLO FT stage, it's important to notify the users of this event. Together with 'colo_lost_heartbeat', users can intervene in COLO's failover work immediately.
If users don't want to get involved in COLO's failover verdict,
it is still necessary to notify users that we exit COLO mode.
--- docs/qmp-events.txt | 17 +++++++++++++++++ migration/colo.c | 13 +++++++++++++ qapi-schema.json | 16 ++++++++++++++++ qapi/event.json | 17 +++++++++++++++++ 4 files changed, 63 insertions(+)
docs/qmp-events.txt +17 -0
@@ -184,6 +184,23 @@ Example: Note: The "ready to complete" status is always reset by a BLOCK_JOB_ERROR event. +COLO_EXIT +--------- + +Emitted when VM finishes COLO mode due to some errors happening or +the request of users. + +Data: + + - "mode": COLO mode, primary or secondary side (json-string) + - "reason": the exit reason, internal error or external request. (json-string) + - "error": error message (json-string, operation) + +Example: + +{"timestamp": {"seconds": 2032141960, "microseconds": 417172}, + "event": "COLO_EXIT", "data": {"mode": "primary", "reason": "request" } } + DEVICE_DELETED --------------
migration/colo.c +13 -0
@@ -18,6 +18,7 @@#include "qemu/error-report.h" #include "qemu/sockets.h" #include "migration/failover.h" +#include "qapi-event.h" /* * checkpoint interval: unit ms
@@ -343,6 +344,9 @@ out: current_time = error_time =qemu_clock_get_ms (QEMU_CLOCK_HOST );if (ret <0 ) {error_report ("%s: %s" , __func__,strerror (-ret)); +qapi_event_send_colo_exit (COLO_MODE_PRIMARY ,COLO_EXIT_REASON_ERROR , + true,strerror (-ret),NULL ); +/* Give users time to get involved in this verdict */ while (current_time - error_time <=DEFAULT_FAILOVER_DELAY ) {if (failover_request_is_active ()) {
@@ -359,6 +363,9 @@ out:failover_request_active (NULL ); }qemu_mutex_unlock_iothread (); + }else { +qapi_event_send_colo_exit (COLO_MODE_PRIMARY ,COLO_EXIT_REASON_REQUEST , + false,NULL ,NULL ); }qsb_free (buffer);
@@ -530,6 +537,9 @@ out:if (ret <0 ) {error_report ("colo incoming thread will exit, detect error: %s" ,strerror (-ret)); +qapi_event_send_colo_exit (COLO_MODE_SECONDARY ,COLO_EXIT_REASON_ERROR , + true,strerror (-ret),NULL ); +/* Give users time to get involved in this verdict */ while (current_time - error_time <=DEFAULT_FAILOVER_DELAY ) {if (failover_request_is_active ()) {
@@ -548,6 +558,9 @@ out:error_report ("SVM is going to exit in default!" );exit (1 ); } + }else { +qapi_event_send_colo_exit (COLO_MODE_SECONDARY ,COLO_EXIT_REASON_REQUEST , + false,NULL ,NULL ); }if (fb) {
qapi-schema.json +16 -0
@@ -751,6 +751,22 @@ 'data': [ 'unknown', 'primary', 'secondary'] } ## +# @COLOExitReason +# +# The reason of COLO exit +# +# @unknow: unknown reason +# +# @request: COLO exit is due to an external request +# +# @error: COLO exit is due to an internal error +# +# Since: 2.5 +## +{ 'enum': 'COLOExitReason', + 'data': [ 'unknown', 'request', 'error'] } + +## # @x-colo-lost-heartbeat # # Tell qemu that heartbeat is lost, request it to do takeover procedures.
qapi/event.json +17 -0
@@ -255,6 +255,23 @@ 'data': {'status': 'MigrationStatus'}} ## +# @COLO_EXIT +# +# Emitted when VM finishes COLO mode due to some errors happening or +# the request of users. +# +# @mode: @COLOMode describing which side of VM is exit. +# +# @reason: @COLOExitReason describing the reason of colo exit. +# +# @error: #optional, error message. Only present on error happening. +# +# Since: 2.5 +## +{ 'event': 'COLO_EXIT', + 'data': {'mode': 'COLOMode', 'reason': 'COLOExitReason', '*error': 'str' } } + +## # @ACPI_DEVICE_OST # # Emitted when guest executes ACPI _OST method.
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH COLO-Frame v10 23/38] qmp event: Add event notification for COLO error
Quoted 5 lines · zhanghailiang
If some errors happen during VM's COLO FT stage, it's important to notify the users of this event. Together with '
colo_lost_heartbeat', users can intervene in COLO's failover work immediately.
If users don't want to get involved in COLO's failover verdict,
it is still necessary to notify users that we exit COLO mode.
s/exit/exited/
Quoted 17 lines
Cc Markus Armbruster <[email protected]>Cc Michael Roth <[email protected]>Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>--- docs/qmp-events.txt | 17 +++++++++++++++++ migration/colo.c | 13 +++++++++++++ qapi-schema.json | 16 ++++++++++++++++ qapi/event.json | 17 +++++++++++++++++ 4 files changed, 63 insertions(+)docs/qmp-events.txt +0
-0
docs/qmp-events.txt Example: · line 191
Quoted 8 lines
docs/qmp-events.txt +5
-0@@ -184,6 +184,23 @@ Example: Note: The "ready to complete" status is always reset by a BLOCK_JOB_ERROR event. +COLO_EXIT +--------- + +Emitted when VM finishes COLO mode due to some errors happening or +the request of users.
s/the/at the/
docs/qmp-events.txt line 756
Quoted 8 lines
docs/qmp-events.txt +4
-0+++ b/qapi-schema.json@@ -751,6 +751,22 @@ 'data': [ 'unknown', 'primary', 'secondary'] } ## +# @COLOExitReason +# +# The reason of COLO exit
s/of/for a/
docs/qmp-events.txt line 758
Quoted 2 lines
docs/qmp-events.txt +2
-0+# +# @unknow: unknown reason
s/unknow/unknown/
docs/qmp-events.txt line 764
Quoted 6 lines
docs/qmp-events.txt +6
-0+# +# @request: COLO exit is due to an external request +# +# @error: COLO exit is due to an internal error +# +# Since: 2.5
2.6 (but you already know that throughout the series, so I'll quit pointing it out)
docs/qmp-events.txt line 261
Quoted 9 lines
docs/qmp-events.txt +5
-0+++ b/qapi/event.json@@ -255,6 +255,23 @@ 'data': {'status': 'MigrationStatus'}} ## +# @COLO_EXIT +# +# Emitted when VM finishes COLO mode due to some errors happening or +# the request of users.
s/the/at the/
docs/qmp-events.txt line 263
Quoted 2 lines
docs/qmp-events.txt +2
-0+# +# @mode: @COLOMode describing which side of VM is exit.
Maybe:
@mode: Which COLO mode the VM was in when it exited.
docs/qmp-events.txt line 265
Quoted 2 lines
docs/qmp-events.txt +2
-0+# +# @reason: @COLOExitReason describing the reason of colo exit.
@reason: describes the reason for the COLO exit.
docs/qmp-events.txt line 272
Quoted 7 lines
docs/qmp-events.txt +7
-0+# +# @error: #optional, error message. Only present on error happening. +# +# Since: 2.5 +## +{ 'event': 'COLO_EXIT', + 'data': {'mode': 'COLOMode', 'reason': 'COLOExitReason', '*error': 'str' } }
Other than typos, the interface seems okay.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH COLO-Frame v10 23/38] qmp event: Add event notification for COLO error
Quoted 89 lines · Eric Blake
Quoted 5 lines · zhanghailiang
If some errors happen during VM's COLO FT stage, it's important to notify the users of this event. Together with '
colo_lost_heartbeat', users can intervene in COLO's failover work immediately.
If users don't want to get involved in COLO's failover verdict,
it is still necessary to notify users that we exit COLO mode.s/exit/exited/
Quoted 17 lines
Cc Markus Armbruster <[email protected]>Cc Michael Roth <[email protected]>Signed-off-by zhanghailiang <[email protected]>Signed-off-by Li Zhijian <[email protected]>--- docs/qmp-events.txt | 17 +++++++++++++++++ migration/colo.c | 13 +++++++++++++ qapi-schema.json | 16 ++++++++++++++++ qapi/event.json | 17 +++++++++++++++++ 4 files changed, 63 insertions(+)docs/qmp-events.txt +0
-0docs/qmp-events.txt Example: · line 191
Quoted 8 lines
docs/qmp-events.txt +5
-0@@ -184,6 +184,23 @@ Example: Note: The "ready to complete" status is always reset by a BLOCK_JOB_ERROR event. +COLO_EXIT +--------- + +Emitted when VM finishes COLO mode due to some errors happening or +the request of users.s/the/at the/
docs/qmp-events.txt line 756
Quoted 8 lines
docs/qmp-events.txt +4
-0+++ b/qapi-schema.json@@ -751,6 +751,22 @@ 'data': [ 'unknown', 'primary', 'secondary'] } ## +# @COLOExitReason +# +# The reason of COLO exits/of/for a/
docs/qmp-events.txt line 758
Quoted 2 lines
docs/qmp-events.txt +2
-0+# +# @unknow: unknown reasons/unknow/unknown/
docs/qmp-events.txt line 764
Quoted 6 lines
docs/qmp-events.txt +6
-0+# +# @request: COLO exit is due to an external request +# +# @error: COLO exit is due to an internal error +# +# Since: 2.52.6 (but you already know that throughout the series, so I'll quit pointing it out)
docs/qmp-events.txt line 261
Quoted 9 lines
docs/qmp-events.txt +5
-0+++ b/qapi/event.json@@ -255,6 +255,23 @@ 'data': {'status': 'MigrationStatus'}} ## +# @COLO_EXIT +# +# Emitted when VM finishes COLO mode due to some errors happening or +# the request of users.s/the/at the/
docs/qmp-events.txt line 263
Quoted 2 lines
docs/qmp-events.txt +2
-0+# +# @mode: @COLOMode describing which side of VM is exit.Maybe:
@mode: Which COLO mode the VM was in when it exited.
docs/qmp-events.txt line 265
Quoted 2 lines
docs/qmp-events.txt +2
-0+# +# @reason: @COLOExitReason describing the reason of colo exit.@reason: describes the reason for the COLO exit.
Quoted 10 lines
docs/qmp-events.txt line 272
Quoted 7 lines
docs/qmp-events.txt +7
-0+# +# @error: #optional, error message. Only present on error happening. +# +# Since: 2.5 +## +{ 'event': 'COLO_EXIT', + 'data': {'mode': 'COLOMode', 'reason': 'COLOExitReason', '*error': 'str' } }Other than typos, the interface seems okay.
OK, i will fix them in next version, thanks.
PATCH v10 24/38 COLO failover: Shutdown related socket fd when do failover
In reply to zhanghailiangIf the net connection between COLO's two sides is broken while colo/colo incoming thread is blocked in 'read'/'write' socket fd. It will not detect this error until connect timeout. It will be a long time.
Here we shutdown all the related socket file descriptors to wake up the blocking operation in failover BH. Besides, we should close the corresponding file descriptors after failvoer BH shutdown them, or there will be an error.
--- migration/colo.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-)
migration/colo.c +26 -2
@@ -74,6 +74,13 @@ static void secondary_vm_do_failover(void)/* recover runstate to normal migration finish state */ autostart = true; } +/* Make sure colo incoming thread not block in recv */ +if (mis->from_src_file) { +qemu_file_shutdown (mis->from_src_file); + } +if (mis->to_src_file) { +qemu_file_shutdown (mis->to_src_file); + } old_state =failover_set_state (FAILOVER_STATUS_HANDLING ,FAILOVER_STATUS_COMPLETED );
@@ -99,6 +106,13 @@ static void primary_vm_do_failover(void) }migration_end (); +if (s->from_dst_file) {/* Make sure colo thread no block in recv */ +qemu_file_shutdown (s->from_dst_file); + } +if (s->to_dst_file) { +qemu_file_shutdown (s->to_dst_file); + } +vm_start (); old_state = failover_set_state(FAILOVER_STATUS_HANDLING,
@@ -342,7 +356,7 @@ static void colo_process_checkpoint(MigrationState *s) out: current_time = error_time =qemu_clock_get_ms (QEMU_CLOCK_HOST ); -if (ret <0 ) { +if (ret <0 || (!ret && !failover_request_is_active ())) {error_report ("%s: %s" , __func__,strerror (-ret));qapi_event_send_colo_exit (COLO_MODE_PRIMARY ,COLO_EXIT_REASON_ERROR , true,strerror (-ret),NULL );
@@ -371,6 +385,11 @@ out:qsb_free (buffer); buffer =NULL ; +/* Hope this not to be too long to loop here */ +while (failover_get_state () !=FAILOVER_STATUS_COMPLETED ) { + ; + } +/* Must be called after failover BH is completed */ if (s->from_dst_file) {qemu_fclose (s->from_dst_file); }
@@ -534,7 +553,7 @@ void *colo_process_incoming_thread(void *opaque) out: current_time = error_time =qemu_clock_get_ms (QEMU_CLOCK_HOST ); -if (ret <0 ) { +if (ret <0 || (!ret && !failover_request_is_active ())) {error_report ("colo incoming thread will exit, detect error: %s" ,strerror (-ret)); qapi_event_send_colo_exit(COLO_MODE_SECONDARY, COLO_EXIT_REASON_ERROR,
@@ -573,6 +592,11 @@ out:*/ colo_release_ram_cache (); +/* Hope this not to be too long to loop here */ +while (failover_get_state () !=FAILOVER_STATUS_COMPLETED ) { + ; + } +/* Must be called after failover BH is completed */ if (mis->to_src_file) {qemu_fclose (mis->to_src_file); }
Signature · 1 line
1.8.3.1
PATCH v10 25/38 COLO failover: Don't do failover during loading VM's state
In reply to zhanghailiangWe should not do failover work while the main thread is loading VM's state, otherwise it will destroy the consistent of VM's memory and device state.
Here we add a new failover status 'RELAUNCH' which means we should relaunch the process of failover.
--- include/migration/failover.h | 2 ++ migration/colo.c | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+)
include/migration/failover.h +2 -0
@@ -20,6 +20,8 @@ typedef enum COLOFailoverStatus {FAILOVER_STATUS_REQUEST =1 ,/* Request but not handled */ FAILOVER_STATUS_HANDLING =2 ,/* In the process of handling failover */ FAILOVER_STATUS_COMPLETED =3 ,/* Finish the failover process */ +/* Optional, Relaunch the failover process, again 'NONE' -> 'COMPLETED' */ +FAILOVER_STATUS_RELAUNCH =4 , } COLOFailoverStatus;void failover_init_state (void );
migration/colo.c +24 -0
@@ -34,6 +34,7 @@*/ #define DEFAULT_FAILOVER_DELAY 2000 +static bool vmstate_loading;/* colo buffer */ #define COLO_BUFFER_BASE_SIZE (4 * 1024 * 1024)
@@ -66,6 +67,19 @@ static void secondary_vm_do_failover(void)int old_state;MigrationIncomingState *mis =migration_incoming_get_current (); +/* Can not do failover during the process of VM's loading VMstate, Or +* it will break the secondary VM. +*/ +if (vmstate_loading) { + old_state =failover_set_state (FAILOVER_STATUS_HANDLING , +FAILOVER_STATUS_RELAUNCH ); +if (old_state !=FAILOVER_STATUS_HANDLING ) { +error_report ("Unknow error while do failover for secondary VM," +"old_state: %d" , old_state); + } +return ; + } +migrate_set_state (&mis->state,MIGRATION_STATUS_COLO ,MIGRATION_STATUS_COMPLETED );
@@ -535,13 +549,23 @@ void *colo_process_incoming_thread(void *opaque)qemu_mutex_lock_iothread ();qemu_system_reset (VMRESET_SILENT ); + vmstate_loading = true;if (qemu_loadvm_state (fb) <0 ) {error_report ("COLO: loadvm failed" ); + vmstate_loading = false;qemu_mutex_unlock_iothread (); goto out; } + + vmstate_loading = false;qemu_mutex_unlock_iothread (); +if (failover_get_state () ==FAILOVER_STATUS_RELAUNCH ) { +failover_set_state (FAILOVER_STATUS_RELAUNCH ,FAILOVER_STATUS_NONE ); +failover_request_active (NULL ); + goto out; + } + ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_VMSTATE_LOADED ,0 );if (ret <0 ) { goto out;
Signature · 1 line
1.8.3.1
PATCH v10 26/38 COLO: Control the checkpoint delay time by migrate-set-parameters command
In reply to zhanghailiangAdd checkpoint-delay parameter for migrate-set-parameters, so that we can control the checkpoint frequency when COLO is in periodic mode.
---
v10: Fix related qmp command
--- hmp.c | 7 +++++++ migration/colo.c | 12 +++++------- migration/migration.c | 28 +++++++++++++++++++++++++++- qapi-schema.json | 19 ++++++++++++++++--- qmp-commands.hx | 2 +- 5 files changed, 56 insertions(+), 12 deletions(-)
hmp.c +7 -0
@@ -284,6 +284,9 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)monitor_printf (mon," %s: %" PRId64, MigrationParameter_lookup[MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT ], params->x_cpu_throttle_increment); +monitor_printf (mon," %s: %" PRId64, + MigrationParameter_lookup[MIGRATION_PARAMETER_CHECKPOINT_DELAY ], + params->checkpoint_delay);monitor_printf (mon,"\n" ); }
@@ -1235,6 +1238,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)bool has_decompress_threads = false;bool has_x_cpu_throttle_initial = false;bool has_x_cpu_throttle_increment = false; +bool has_checkpoint_delay = false;int i;for (i =0 ; i <MIGRATION_PARAMETER_MAX ; i++) {
@@ -1254,6 +1258,8 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)break ;case MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT : has_x_cpu_throttle_increment = true; +case MIGRATION_PARAMETER_CHECKPOINT_DELAY : + has_checkpoint_delay = true;break ; } qmp_migrate_set_parameters(has_compress_level, value,
@@ -1261,6 +1267,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) has_decompress_threads, value, has_x_cpu_throttle_initial, value, has_x_cpu_throttle_increment, value, + has_checkpoint_delay, value, &err);break ; }
migration/colo.c +5 -7
@@ -19,12 +19,8 @@#include "qemu/sockets.h" #include "migration/failover.h" #include "qapi-event.h" - -/* -* checkpoint interval: unit ms -* Note: Please change this default value to 10000 when we support hybrid mode. -*/ -#define CHECKPOINT_MAX_PEROID 200 +#include "qmp-commands.h" +#include "qapi-types.h" /* * The delay time before qemu begin the procedure of default failover treatment.
@@ -35,6 +31,7 @@#define DEFAULT_FAILOVER_DELAY 2000static bool vmstate_loading; +/* colo buffer */ #define COLO_BUFFER_BASE_SIZE (4 * 1024 * 1024)
@@ -356,7 +353,8 @@ static void colo_process_checkpoint(MigrationState *s) } current_time =qemu_clock_get_ms (QEMU_CLOCK_HOST ); -if (current_time - checkpoint_time <CHECKPOINT_MAX_PEROID ) { +if (current_time - checkpoint_time < + s->parameters[MIGRATION_PARAMETER_CHECKPOINT_DELAY ]) {g_usleep (100000 );continue ; }
migration/migration.c +27 -1
@@ -53,6 +53,11 @@/* Migration XBZRLE default cache size */ #define DEFAULT_MIGRATE_CACHE_SIZE (64 * 1024 * 1024) +/* The delay time (in ms) between two COLO checkpoints +* Note: Please change this default value to 10000 when we support hybrid mode. +*/ +#define DEFAULT_MIGRATE_CHECKPOINT_DELAY 200 +static NotifierList migration_state_notifiers =NOTIFIER_LIST_INITIALIZER (migration_state_notifiers);
@@ -80,6 +85,8 @@ MigrationState *migrate_get_current(void) DEFAULT_MIGRATE_X_CPU_THROTTLE_INITIAL, .parameters[MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT ] = DEFAULT_MIGRATE_X_CPU_THROTTLE_INCREMENT, + .parameters[MIGRATION_PARAMETER_CHECKPOINT_DELAY ] = + DEFAULT_MIGRATE_CHECKPOINT_DELAY, };return ¤t_migration;
@@ -426,6 +433,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp) s->parameters[MIGRATION_PARAMETER_X_CPU_THROTTLE_INITIAL ]; params->x_cpu_throttle_increment = s->parameters[MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT ]; + params->checkpoint_delay = + s->parameters[MIGRATION_PARAMETER_CHECKPOINT_DELAY ];return params; }
@@ -568,7 +577,10 @@ void qmp_migrate_set_parameters(bool has_compress_level,bool has_x_cpu_throttle_initial, int64_t x_cpu_throttle_initial, bool has_x_cpu_throttle_increment, - int64_t x_cpu_throttle_increment, Error **errp) + int64_t x_cpu_throttle_increment, + bool has_checkpoint_delay, + int64_t checkpoint_delay, + Error **errp) { MigrationState *s = migrate_get_current();
@@ -603,6 +615,11 @@ void qmp_migrate_set_parameters(bool has_compress_level,"x_cpu_throttle_increment" , "an integer in the range of 1 to 99"); } +if (has_checkpoint_delay && (checkpoint_delay <0 )) { +error_setg (errp,QERR_INVALID_PARAMETER_VALUE , +"checkpoint_delay" , +"is invalid, it should be positive" ); + }if (has_compress_level) { s->parameters[MIGRATION_PARAMETER_COMPRESS_LEVEL ] = compress_level;
@@ -623,6 +640,10 @@ void qmp_migrate_set_parameters(bool has_compress_level, s->parameters[MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT ] = x_cpu_throttle_increment; } + +if (has_checkpoint_delay) { + s->parameters[MIGRATION_PARAMETER_CHECKPOINT_DELAY ] = checkpoint_delay; + } }/* shared migration helpers */
@@ -743,6 +764,8 @@ static MigrationState *migrate_init(const MigrationParams *params) s->parameters[MIGRATION_PARAMETER_X_CPU_THROTTLE_INITIAL ];int x_cpu_throttle_increment = s->parameters[MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT ]; +int checkpoint_delay = + s->parameters[MIGRATION_PARAMETER_CHECKPOINT_DELAY ];memcpy (enabled_capabilities, s->enabled_capabilities,sizeof (enabled_capabilities));
@@ -762,6 +785,9 @@ static MigrationState *migrate_init(const MigrationParams *params) x_cpu_throttle_initial; s->parameters[MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT ] = x_cpu_throttle_increment; + s->parameters[MIGRATION_PARAMETER_CHECKPOINT_DELAY ] = + checkpoint_delay; + s->bandwidth_limit = bandwidth_limit;migrate_set_state (&s->state,MIGRATION_STATUS_NONE ,MIGRATION_STATUS_SETUP );
qapi-schema.json +16 -3
@@ -617,11 +617,16 @@ # @x-cpu-throttle-increment: throttle percentage increase each time # auto-converge detects that migration is not making # progress. The default value is 10. (Since 2.5) +# +# @checkpoint-delay: The delay time (in ms) between two COLO checkpoints in +# periodic mode. +# # Since: 2.4 ## { 'enum': 'MigrationParameter', 'data': ['compress-level', 'compress-threads', 'decompress-threads', - 'x-cpu-throttle-initial', 'x-cpu-throttle-increment'] } + 'x-cpu-throttle-initial', 'x-cpu-throttle-increment', + 'checkpoint-delay' ] } # # @migrate-set-parameters
@@ -641,6 +646,9 @@ # @x-cpu-throttle-increment: throttle percentage increase each time # auto-converge detects that migration is not making # progress. The default value is 10. (Since 2.5) +# +# @checkpoint-delay: the delay time between two checkpoints +# # Since: 2.4 ## { 'command': 'migrate-set-parameters',
@@ -648,7 +656,8 @@ '*compress-threads': 'int', '*decompress-threads': 'int', '*x-cpu-throttle-initial': 'int', - '*x-cpu-throttle-increment': 'int'} } + '*x-cpu-throttle-increment': 'int', + '*checkpoint-delay': 'int' } } # # @MigrationParameters
@@ -667,6 +676,8 @@ # auto-converge detects that migration is not making # progress. The default value is 10. (Since 2.5) # +# @checkpoint-delay: the delay time between two COLO checkpoints +# # Since: 2.4 ## { 'struct': 'MigrationParameters',
@@ -674,7 +685,9 @@ 'compress-threads': 'int', 'decompress-threads': 'int', 'x-cpu-throttle-initial': 'int', - 'x-cpu-throttle-increment': 'int'} } + 'x-cpu-throttle-increment': 'int', + 'checkpoint-delay': 'int'} } + ## # @query-migrate-parameters #
qmp-commands.hx +1 -1
@@ -3556,7 +3556,7 @@ EQMP { .name = "migrate-set-parameters", .args_type = - "compress-level:i?,compress-threads:i?,decompress-threads:i?", + "compress-level:i?,compress-threads:i?,decompress-threads:i?,checkpoint-delay:i?", .mhandler.cmd_new = qmp_marshal_migrate_set_parameters, }, SQMP
Signature · 1 line
1.8.3.1
PATCH v10 27/38 COLO: Process shutdown command for VM in COLO state
In reply to zhanghailiangIf VM is in COLO FT state, we should do some extra work before normal shutdown process. SVM will ignore the shutdown command if this command is issued directly to it, PVM will send the shutdown command to SVM if it gets this command.
--- include/sysemu/sysemu.h | 3 +++ migration/colo.c | 26 +++++++++++++++++++++++--- qapi-schema.json | 4 +++- vl.c | 26 ++++++++++++++++++++++++-- 4 files changed, 53 insertions(+), 6 deletions(-)
include/sysemu/sysemu.h +3 -0
@@ -52,6 +52,8 @@ typedef enum WakeupReason {QEMU_WAKEUP_REASON_OTHER , } WakeupReason; +extern int colo_shutdown_requested; +void qemu_system_reset_request (void );void qemu_system_suspend_request (void );void qemu_register_suspend_notifier (Notifier *notifier);
@@ -59,6 +61,7 @@ void qemu_system_wakeup_request(WakeupReason reason);void qemu_system_wakeup_enable (WakeupReason reason,bool enabled);void qemu_register_wakeup_notifier (Notifier *notifier);void qemu_system_shutdown_request (void ); +void qemu_system_shutdown_request_core (void );void qemu_system_powerdown_request (void );void qemu_register_powerdown_notifier (Notifier *notifier);void qemu_system_debug_request (void );
migration/colo.c +23 -3
@@ -210,7 +210,7 @@ static int colo_ctl_get(QEMUFile *f, uint32_t require)static int colo_do_checkpoint_transaction (MigrationState *s,QEMUSizedBuffer *buffer) { -int ret; +int colo_shutdown, ret;size_t size;QEMUFile *trans =NULL ;
@@ -237,6 +237,7 @@ static int colo_do_checkpoint_transaction(MigrationState *s, ret =-1 ; goto out; } + colo_shutdown = colo_shutdown_requested;vm_stop_force_state (RUN_STATE_COLO );qemu_mutex_unlock_iothread ();trace_colo_vm_state_change ("run" ,"stop" );
@@ -288,6 +289,15 @@ static int colo_do_checkpoint_transaction(MigrationState *s, goto out; } +if (colo_shutdown) { +colo_ctl_put (s->to_dst_file,COLO_COMMAND_GUEST_SHUTDOWN ,0 ); +qemu_fflush (s->to_dst_file); + colo_shutdown_requested =0 ; +qemu_system_shutdown_request_core (); +/* Fix me: Just let the colo thread exit ? */ +qemu_thread_exit (0 ); + } + ret =0 ;/* resume master */ qemu_mutex_lock_iothread ();
@@ -353,8 +363,9 @@ static void colo_process_checkpoint(MigrationState *s) } current_time =qemu_clock_get_ms (QEMU_CLOCK_HOST ); -if (current_time - checkpoint_time < - s->parameters[MIGRATION_PARAMETER_CHECKPOINT_DELAY ]) { +if ((current_time - checkpoint_time < + s->parameters[MIGRATION_PARAMETER_CHECKPOINT_DELAY ]) && + !colo_shutdown_requested) {g_usleep (100000 );continue ; }
@@ -444,6 +455,15 @@ static int colo_wait_handle_cmd(QEMUFile *f, int *checkpoint_request)case COLO_COMMAND_CHECKPOINT_REQUEST : *checkpoint_request =1 ;return 0 ; +case COLO_COMMAND_GUEST_SHUTDOWN : +qemu_mutex_lock_iothread (); +vm_stop_force_state (RUN_STATE_COLO ); +qemu_system_shutdown_request_core (); +qemu_mutex_unlock_iothread (); +/* the main thread will exit and termiante the whole +* process, do we need some cleanup? +*/ +qemu_thread_exit (0 );default :return -EINVAL ; }
qapi-schema.json +3 -1
@@ -740,12 +740,14 @@ # # @vmstate-loaded: VM's state has been loaded by SVM # +# @guest-shutdown: shutdown require from PVM to SVM +# # Since: 2.5 ## { 'enum': 'COLOCommand', 'data': [ 'invalid', 'checkpoint-ready', 'checkpoint-request', 'checkpoint-reply', 'vmstate-send', 'vmstate-size', - 'vmstate-received', 'vmstate-loaded' ] } + 'vmstate-received', 'vmstate-loaded', 'guest-shutdown' ] } ## # @COLOMode
vl.c +24 -2
@@ -1615,6 +1615,8 @@ static NotifierList wakeup_notifiers =NOTIFIER_LIST_INITIALIZER (wakeup_notifiers);static uint32_t wakeup_reason_mask = ~(1 <<QEMU_WAKEUP_REASON_NONE ); +int colo_shutdown_requested; +int qemu_shutdown_requested_get (void ) {return shutdown_requested;
@@ -1740,6 +1742,10 @@ void qemu_system_guest_panicked(void)void qemu_system_reset_request (void ) {if (no_reboot) { +qemu_system_shutdown_request (); +if (!shutdown_requested) {/* colo handle it ? */ +return ; + } shutdown_requested =1 ; }else { reset_requested =1 ;
@@ -1808,13 +1814,29 @@ void qemu_system_killed(int signal, pid_t pid)qemu_system_shutdown_request (); } -void qemu_system_shutdown_request (void ) +void qemu_system_shutdown_request_core (void ) { -trace_qemu_system_shutdown_request (); shutdown_requested =1 ;qemu_notify_event (); } +void qemu_system_shutdown_request (void ) +{ +trace_qemu_system_shutdown_request (); +/* +* if in colo mode, we need do some significant work before respond to the +* shutdown request. +*/ +if (migration_incoming_in_colo_state ()) { +return ;/* primary's responsibility */ + } +if (migration_in_colo_state ()) { + colo_shutdown_requested =1 ; +return ; + } +qemu_system_shutdown_request_core (); +} +static void qemu_system_powerdown (void ) {qapi_event_send_powerdown (&error_abort);
Signature · 1 line
1.8.3.1
PATCH v10 28/38 COLO: Update the global runstate after going into colo state
In reply to zhanghailiangIf we start qemu with -S, the runstate will change from 'prelaunch' to 'running' after going into colo state.
So it is necessary to update the global runstate after going into colo state.
--- migration/colo.c | 5 +++++ 1 file changed, 5 insertions(+)
migration/colo.c +5 -0
@@ -356,6 +356,11 @@ static void colo_process_checkpoint(MigrationState *s)qemu_mutex_unlock_iothread ();trace_colo_vm_state_change ("stop" ,"run" ); + ret =global_state_store (); +if (ret <0 ) { + goto out; + } +while (s->state ==MIGRATION_STATUS_COLO ) {if (failover_request_is_active ()) {error_report ("failover request" );
Signature · 1 line
1.8.3.1
PATCH v10 29/38 savevm: Split load vm state function qemu_loadvm_state
In reply to zhanghailiangqemu_loadvm_state is too long, and we can simplify it by splitting up with three helper functions.
--- migration/savevm.c | 165 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 96 insertions(+), 69 deletions(-)
migration/savevm.c +96 -69
@@ -1053,6 +1053,100 @@ void loadvm_free_handlers(MigrationIncomingState *mis) } } +static int +qemu_loadvm_section_start_full (QEMUFile *f,MigrationIncomingState *mis) +{ +uint32_t instance_id, version_id, section_id; +SaveStateEntry *se; +LoadStateEntry *le; +char idstr[256 ]; +int ret; + +/* Read section start */ + section_id =qemu_get_be32 (f); +if (!qemu_get_counted_string (f, idstr)) { +error_report ("Unable to read ID string for section %u" , + section_id); +return -EINVAL ; + } + instance_id =qemu_get_be32 (f); + version_id =qemu_get_be32 (f); + +trace_qemu_loadvm_state_section_startfull (section_id, idstr, + instance_id, version_id); +/* Find savevm section */ + se =find_se (idstr, instance_id); +if (se ==NULL ) { +error_report ("Unknown savevm section or instance '%s' %d" , + idstr, instance_id); + ret = -EINVAL ; +return ret; + } + +/* Validate version */ +if (version_id > se->version_id) { +error_report ("savevm: unsupported version %d for '%s' v%d" , + version_id, idstr, se->version_id); + ret = -EINVAL ; +return ret; + } + +/* Add entry */ + le =g_malloc0 (sizeof (*le)); + + le->se = se; + le->section_id = section_id; + le->version_id = version_id; +QLIST_INSERT_HEAD (&mis->loadvm_handlers, le, entry); + + ret =vmstate_load (f, le->se, le->version_id); +if (ret <0 ) { +error_report ("error while loading state for instance 0x%x of" +" device '%s'" , instance_id, idstr); +return ret; + } +if (!check_section_footer (f, le)) { + ret = -EINVAL ; +return ret; + } + +return 0 ; +} + +static int +qemu_loadvm_section_part_end (QEMUFile *f,MigrationIncomingState *mis) +{ +uint32_t section_id; +LoadStateEntry *le; +int ret; + + section_id =qemu_get_be32 (f); + +trace_qemu_loadvm_state_section_partend (section_id); + QLIST_FOREACH(le, &mis->loadvm_handlers, entry) { +if (le->section_id == section_id) { +break ; + } + } +if (le ==NULL ) { +error_report ("Unknown savevm section %d" , section_id); + ret = -EINVAL ; +return ret; + } + + ret =vmstate_load (f, le->se, le->version_id); +if (ret <0 ) { +error_report ("error while loading state section id %d(%s)" , + section_id, le->se->idstr); +return ret; + } +if (!check_section_footer (f, le)) { + ret = -EINVAL ; +return ret; + } + +return 0 ; +}int qemu_loadvm_state (QEMUFile *f) {MigrationIncomingState *mis =migration_incoming_get_current ();
@@ -1096,87 +1190,20 @@ int qemu_loadvm_state(QEMUFile *f) }while ((section_type =qemu_get_byte (f)) !=QEMU_VM_EOF ) { -uint32_t instance_id, version_id, section_id; -SaveStateEntry *se; -LoadStateEntry *le; -char idstr[256 ];trace_qemu_loadvm_state_section (section_type);switch (section_type) {case QEMU_VM_SECTION_START :case QEMU_VM_SECTION_FULL : -/* Read section start */ - section_id =qemu_get_be32 (f); -if (!qemu_get_counted_string (f, idstr)) { -error_report ("Unable to read ID string for section %u" , - section_id); -return -EINVAL ; - } - instance_id =qemu_get_be32 (f); - version_id =qemu_get_be32 (f); - -trace_qemu_loadvm_state_section_startfull (section_id, idstr, - instance_id, version_id); -/* Find savevm section */ - se =find_se (idstr, instance_id); -if (se ==NULL ) { -error_report ("Unknown savevm section or instance '%s' %d" , - idstr, instance_id); - ret = -EINVAL ; - goto out; - } - -/* Validate version */ -if (version_id > se->version_id) { -error_report ("savevm: unsupported version %d for '%s' v%d" , - version_id, idstr, se->version_id); - ret = -EINVAL ; - goto out; - } - -/* Add entry */ - le =g_malloc0 (sizeof (*le)); - - le->se = se; - le->section_id = section_id; - le->version_id = version_id; -QLIST_INSERT_HEAD (&mis->loadvm_handlers, le, entry); - - ret =vmstate_load (f, le->se, le->version_id); + ret =qemu_loadvm_section_start_full (f, mis);if (ret <0 ) { -error_report ("error while loading state for instance 0x%x of" -" device '%s'" , instance_id, idstr); - goto out; - } -if (!check_section_footer (f, le)) { - ret = -EINVAL ; goto out; }break ;case QEMU_VM_SECTION_PART :case QEMU_VM_SECTION_END : - section_id =qemu_get_be32 (f); - -trace_qemu_loadvm_state_section_partend (section_id); - QLIST_FOREACH(le, &mis->loadvm_handlers, entry) { -if (le->section_id == section_id) { -break ; - } - } -if (le ==NULL ) { -error_report ("Unknown savevm section %d" , section_id); - ret = -EINVAL ; - goto out; - } - - ret =vmstate_load (f, le->se, le->version_id); + ret =qemu_loadvm_section_part_end (f, mis);if (ret <0 ) { -error_report ("error while loading state section id %d(%s)" , - section_id, le->se->idstr); - goto out; - } -if (!check_section_footer (f, le)) { - ret = -EINVAL ; goto out; }break ;
Signature · 1 line
1.8.3.1
PATCH v10 30/38 COLO: Separate the process of saving/loading ram and device state
In reply to zhanghailiangWe separate the process of saving/loading ram and device state when do checkpoint, we add new helpers for save/load ram/device. With this change, we can directly transfer ram from master to slave without using QEMUSizeBuffer as assistant, which also reduce the size of extra memory been used during checkpoint.
Besides, we move the colo_flush_ram_cache to the proper position after the above change.
--- include/sysemu/sysemu.h | 5 ++ migration/colo.c | 43 +++++++++++---- migration/ram.c | 8 --- migration/savevm.c | 142 +++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 177 insertions(+), 21 deletions(-)
include/sysemu/sysemu.h +5 -0
@@ -94,7 +94,12 @@ int qemu_savevm_state_iterate(QEMUFile *f);void qemu_savevm_state_complete (QEMUFile *f);void qemu_savevm_state_cancel (void );uint64_t qemu_savevm_state_pending (QEMUFile *f,uint64_t max_size); +int qemu_save_ram_state (QEMUFile *f); +int qemu_save_device_state (QEMUFile *f);int qemu_loadvm_state (QEMUFile *f); +int qemu_loadvm_state_begin (QEMUFile *f); +int qemu_load_ram_state (QEMUFile *f); +int qemu_load_device_state (QEMUFile *f); typedef enum DisplayType {
migration/colo.c +33 -10
68 lines not on this page · raw message
migration/ram.c +0 -8
@@ -1601,7 +1601,6 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)int flags =0 , ret =0 ;static uint64_t seq_iter;int len =0 ; -bool need_flush = false; seq_iter++;
@@ -1671,7 +1670,6 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)break ; } - need_flush = true; ch =qemu_get_byte (f);ram_handle_compressed (host, ch,TARGET_PAGE_SIZE );break ;
@@ -1683,7 +1681,6 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)break ; } - need_flush = true;qemu_get_buffer (f, host,TARGET_PAGE_SIZE );break ;case RAM_SAVE_FLAG_COMPRESS_PAGE :
@@ -1716,7 +1713,6 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) ret = -EINVAL ;break ; } - need_flush = true;break ;case RAM_SAVE_FLAG_EOS :/* normal exit */
@@ -1737,10 +1733,6 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)rcu_read_unlock (); -if (!ret && ram_cache_enable && need_flush) { -DPRINTF ("Flush ram_cache\n" ); -colo_flush_ram_cache (); - }DPRINTF ("Completed load of VM with exit code %d seq iteration " "%" PRIu64"\n" , ret, seq_iter);return ret;
migration/savevm.c +139 -3
164 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v10 31/38 COLO: Split qemu_savevm_state_begin out of checkpoint process
In reply to zhanghailiangIt is unnecessary to call qemu_savevm_state_begin() in every checkponit process. It mainly sets up devices and does the first device state pass. These data will not change during the later checkpoint process. So, we split it out of colo_do_checkpoint_transaction(), in this way, we can reduce these data transferring in the later checkpoint.
--- migration/colo.c | 51 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 14 deletions(-)
migration/colo.c +37 -14
@@ -254,15 +254,6 @@ static int colo_do_checkpoint_transaction(MigrationState *s,if (ret <0 ) { goto out; } -/* Disable block migration */ - s->params.blk =0 ; - s->params.shared =0 ; -qemu_savevm_state_begin (s->to_dst_file, &s->params); - ret =qemu_file_get_error (s->to_dst_file); -if (ret <0 ) { -error_report ("save vm state begin error\n" ); - goto out; - }qemu_mutex_lock_iothread ();/* Note: device state is saved into buffer */
@@ -324,6 +315,21 @@ out:return ret; } +static int colo_prepare_before_save (MigrationState *s) +{ +int ret; +/* Disable block migration */ + s->params.blk =0 ; + s->params.shared =0 ; +qemu_savevm_state_begin (s->to_dst_file, &s->params); + ret =qemu_file_get_error (s->to_dst_file); +if (ret <0 ) { +error_report ("save vm state begin error\n" ); +return ret; + } +return 0 ; +} +static void colo_process_checkpoint (MigrationState *s) {QEMUSizedBuffer *buffer =NULL ;
@@ -346,6 +352,11 @@ static void colo_process_checkpoint(MigrationState *s) goto out; } + ret =colo_prepare_before_save (s); +if (ret <0 ) { + goto out; + } +/* * Wait for Secondary finish loading vm states and enter COLO * restore.
@@ -485,6 +496,18 @@ static int colo_wait_handle_cmd(QEMUFile *f, int *checkpoint_request) } } +static int colo_prepare_before_load (QEMUFile *f) +{ +int ret; + + ret =qemu_loadvm_state_begin (f); +if (ret <0 ) { +error_report ("load vm state begin error, ret=%d" , ret); +return ret; + } +return 0 ; +} +void *colo_process_incoming_thread (void *opaque) {MigrationIncomingState *mis = opaque;
@@ -523,6 +546,11 @@ void *colo_process_incoming_thread(void *opaque) goto out; } + ret =colo_prepare_before_load (mis->from_src_file); +if (ret <0 ) { + goto out; + } + ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_CHECKPOINT_READY ,0 );if (ret <0 ) { goto out;
@@ -555,11 +583,6 @@ void *colo_process_incoming_thread(void *opaque) goto out; } - ret =qemu_loadvm_state_begin (mis->from_src_file); -if (ret <0 ) { -error_report ("load vm state begin error, ret=%d" , ret); - goto out; - } ret =qemu_load_ram_state (mis->from_src_file);if (ret <0 ) {error_report ("load ram state error" );
Signature · 1 line
1.8.3.1
PATCH v10 32/38 netfilter: Add a public API to release all the buffered packets
In reply to zhanghailiangFor COLO or MC FT, We need a function to release all the buffered packets actively.
---
v10: new patch
--- include/net/filter.h | 1 + include/net/net.h | 4 ++++ net/filter-buffer.c | 15 +++++++++++++++ net/net.c | 24 ++++++++++++++++++++++++ 4 files changed, 44 insertions(+)
include/net/filter.h +1 -0
@@ -73,5 +73,6 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender,const struct iovec *iov, int iovcnt, void *opaque); +void filter_buffer_release_all (void );#endif /* QEMU_NET_FILTER_H */
include/net/net.h +4 -0
@@ -125,6 +125,10 @@ NetClientState *qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id, const char *client_str);typedef void (*qemu_nic_foreach )(NICState *nic,void *opaque);void qemu_foreach_nic (qemu_nic_foreach func,void *opaque); +typedef void (*qemu_netfilter_foreach )(NetFilterState *nf,void *opaque, +Error **errp); +void qemu_foreach_netfilter (qemu_netfilter_foreach func,void *opaque, +Error **errp);int qemu_can_send_packet (NetClientState *nc);ssize_t qemu_sendv_packet (NetClientState *nc,const struct iovec *iov,int iovcnt);
net/filter-buffer.c +15 -0
@@ -14,6 +14,7 @@#include "qapi/qmp/qerror.h" #include "qapi-visit.h" #include "qom/object.h" +#include "net/net.h" #define TYPE_FILTER_BUFFER "filter-buffer"
@@ -163,6 +164,20 @@ out:error_propagate (errp, local_err); } +static void filter_buffer_release_packets (NetFilterState *nf,void *opaque, +Error **errp) +{ +if (!strcmp (object_get_typename (OBJECT (nf)),TYPE_FILTER_BUFFER )) { +filter_buffer_flush (nf); + } +} + +/* public APIs */ +void filter_buffer_release_all (void ) +{ +qemu_foreach_netfilter (filter_buffer_release_packets,NULL ,NULL ); +} +static void filter_buffer_init (Object *obj) { object_property_add(obj, "interval", "int",
net/net.c +24 -0
@@ -259,6 +259,30 @@ static char *assign_name(NetClientState *nc1, const char *model)return g_strdup_printf ("%s.%d" , model, id); } +void qemu_foreach_netfilter (qemu_netfilter_foreach func,void *opaque, +Error **errp) +{ +NetClientState *nc; +NetFilterState *nf; + + QTAILQ_FOREACH(nc, &net_clients, next) { +if (nc->info->type ==NET_CLIENT_OPTIONS_KIND_NIC ) { +continue ; + } + QTAILQ_FOREACH(nf, &nc->filters, next) { +if (func) { +Error *local_err =NULL ; + +func (nf, opaque, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + } + } + } +} +static void qemu_net_client_destructor (NetClientState *nc) {g_free (nc);
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH COLO-Frame v10 32/38] netfilter: Add a public API to release all the buffered packets
Quoted 78 lines · zhanghailiang
For COLO or MC FT, We need a function to release all the buffered packets actively.
Signed-off-by zhanghailiang <[email protected]>Cc Jason Wang <[email protected]>---
v10: new patch--- include/net/filter.h | 1 + include/net/net.h | 4 ++++ net/filter-buffer.c | 15 +++++++++++++++ net/net.c | 24 ++++++++++++++++++++++++ 4 files changed, 44 insertions(+)include/net/filter.h +1
-0@@ -73,5 +73,6 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender,const struct iovec *iov, int iovcnt, void *opaque); +void filter_buffer_release_all (void );#endif /* QEMU_NET_FILTER_H */ include/net/net.h +4
-0@@ -125,6 +125,10 @@ NetClientState *qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id, const char *client_str);typedef void (*qemu_nic_foreach )(NICState *nic,void *opaque);void qemu_foreach_nic (qemu_nic_foreach func,void *opaque); +typedef void (*qemu_netfilter_foreach )(NetFilterState *nf,void *opaque, +Error **errp); +void qemu_foreach_netfilter (qemu_netfilter_foreach func,void *opaque, +Error **errp);int qemu_can_send_packet (NetClientState *nc);ssize_t qemu_sendv_packet (NetClientState *nc,const struct iovec *iov,int iovcnt);net/filter-buffer.c +15
-0@@ -14,6 +14,7 @@#include "qapi/qmp/qerror.h" #include "qapi-visit.h" #include "qom/object.h" +#include "net/net.h" #define TYPE_FILTER_BUFFER "filter-buffer"@@ -163,6 +164,20 @@ out:error_propagate (errp, local_err); } +static void filter_buffer_release_packets (NetFilterState *nf,void *opaque, +Error **errp) +{ +if (!strcmp (object_get_typename (OBJECT (nf)),TYPE_FILTER_BUFFER )) { +filter_buffer_flush (nf); + } +} + +/* public APIs */ +void filter_buffer_release_all (void ) +{ +qemu_foreach_netfilter (filter_buffer_release_packets,NULL ,NULL ); +} +static void filter_buffer_init (Object *obj) { object_property_add(obj, "interval", "int",net/net.c +0
-0
net/net.c static char *assign_name(NetClientState *nc1, const char *model) · line 268
Quoted 10 lines
net/net.c +7
-0@@ -259,6 +259,30 @@ static char *assign_name(NetClientState *nc1, const char *model)return g_strdup_printf ("%s.%d" , model, id); } +void qemu_foreach_netfilter (qemu_netfilter_foreach func,void *opaque, +Error **errp) +{ +NetClientState *nc; +NetFilterState *nf; + + QTAILQ_FOREACH(nc, &net_clients, next) {
Going through every filters this way might cause problem under multiqueue case. IIRC, Jason suggested that we implement multiqueue by this way: attach the same filter to all queues instead of attach the clone of the filter obj to other queues. So if we attach the same filter to all queues, going through filters this way will cause the func been called multiple(=num of queues) times.
Quoted 21 lines
net/net.c +17
-0+if (nc->info->type ==NET_CLIENT_OPTIONS_KIND_NIC ) { +continue ; + } + QTAILQ_FOREACH(nf, &nc->filters, next) { +if (func) { +Error *local_err =NULL ; + +func (nf, opaque, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + } + } + } +} +static void qemu_net_client_destructor (NetClientState *nc) {g_free (nc);
Signature · 2 lines
Thanks, Yang
Re: [Qemu-devel] [PATCH COLO-Frame v10 32/38] netfilter: Add a public API to release all the buffered packets
Quoted 82 lines · Yang Hongyang
Quoted 81 lines · zhanghailiang
For COLO or MC FT, We need a function to release all the buffered packets actively.
Signed-off-by zhanghailiang <[email protected]>Cc Jason Wang <[email protected]>---
v10: new patch--- include/net/filter.h | 1 + include/net/net.h | 4 ++++ net/filter-buffer.c | 15 +++++++++++++++ net/net.c | 24 ++++++++++++++++++++++++ 4 files changed, 44 insertions(+)include/net/filter.h +1
-0@@ -73,5 +73,6 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender,const struct iovec *iov, int iovcnt, void *opaque); +void filter_buffer_release_all (void );#endif /* QEMU_NET_FILTER_H */ include/net/net.h +4
-0@@ -125,6 +125,10 @@ NetClientState *qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id, const char *client_str);typedef void (*qemu_nic_foreach )(NICState *nic,void *opaque);void qemu_foreach_nic (qemu_nic_foreach func,void *opaque); +typedef void (*qemu_netfilter_foreach )(NetFilterState *nf,void *opaque, +Error **errp); +void qemu_foreach_netfilter (qemu_netfilter_foreach func,void *opaque, +Error **errp);int qemu_can_send_packet (NetClientState *nc);ssize_t qemu_sendv_packet (NetClientState *nc,const struct iovec *iov,int iovcnt);net/filter-buffer.c +15
-0@@ -14,6 +14,7 @@#include "qapi/qmp/qerror.h" #include "qapi-visit.h" #include "qom/object.h" +#include "net/net.h" #define TYPE_FILTER_BUFFER "filter-buffer"@@ -163,6 +164,20 @@ out:error_propagate (errp, local_err); } +static void filter_buffer_release_packets (NetFilterState *nf,void *opaque, +Error **errp) +{ +if (!strcmp (object_get_typename (OBJECT (nf)),TYPE_FILTER_BUFFER )) { +filter_buffer_flush (nf); + } +} + +/* public APIs */ +void filter_buffer_release_all (void ) +{ +qemu_foreach_netfilter (filter_buffer_release_packets,NULL ,NULL ); +} +static void filter_buffer_init (Object *obj) { object_property_add(obj, "interval", "int",net/net.c +0
-0@@ -259,6 +259,30 @@ static char *assign_name(NetClientState *nc1, const char *model)return g_strdup_printf ("%s.%d" , model, id); }
Quoted 15 lines
net/net.c static char *assign_name(NetClientState *nc1, const char *model) · line 268
Quoted 7 lines
net/net.c +7
-0+void qemu_foreach_netfilter (qemu_netfilter_foreach func,void *opaque, +Error **errp) +{ +NetClientState *nc; +NetFilterState *nf; + + QTAILQ_FOREACH(nc, &net_clients, next) {Going through every filters this way might cause problem under multiqueue case. IIRC, Jason suggested that we implement multiqueue by this way: attach the same filter to all queues instead of attach the clone of the filter obj to other queues. So if we attach the same filter to all queues, going through filters this way will cause the func been called multiple(=num of queues) times.
Got it, i will investigate it.
Thanks.
zhanghailiang
Quoted 22 lines
Quoted 21 lines
net/net.c +17
-0+if (nc->info->type ==NET_CLIENT_OPTIONS_KIND_NIC ) { +continue ; + } + QTAILQ_FOREACH(nf, &nc->filters, next) { +if (func) { +Error *local_err =NULL ; + +func (nf, opaque, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + } + } + } +} +static void qemu_net_client_destructor (NetClientState *nc) {g_free (nc);
PATCH v10 33/38 netfilter: Introduce an API to delete the timer of all buffer-filters
In reply to zhanghailiang---
v10: new patch
--- include/net/filter.h | 1 + net/filter-buffer.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+)
include/net/filter.h +1 -0
@@ -74,5 +74,6 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender,int iovcnt, void *opaque);void filter_buffer_release_all (void ); +void filter_buffer_del_all_timers (void );#endif /* QEMU_NET_FILTER_H */
net/filter-buffer.c +17 -0
@@ -178,6 +178,23 @@ void filter_buffer_release_all(void)qemu_foreach_netfilter (filter_buffer_release_packets,NULL ,NULL ); } +static void filter_buffer_del_timer (NetFilterState *nf,void *opaque, +Error **errp) +{ +if (!strcmp (object_get_typename (OBJECT (nf)),TYPE_FILTER_BUFFER )) { +FilterBufferState *s =FILTER_BUFFER (nf); + +if (s->interval) { +timer_del (&s->release_timer); + } + } +} + +void filter_buffer_del_all_timers (void ) +{ +qemu_foreach_netfilter (filter_buffer_del_timer,NULL ,NULL ); +} +static void filter_buffer_init (Object *obj) { object_property_add(obj, "interval", "int",
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH COLO-Frame v10 33/38] netfilter: Introduce an API to delete the timer of all buffer-filters
Can you explain why this is needed? Seems that this api hasn't been used in this series.
Quoted 49 lines · zhanghailiang
Signed-off-by zhanghailiang <[email protected]>Cc Jason Wang <[email protected]>---
v10: new patch--- include/net/filter.h | 1 + net/filter-buffer.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+)include/net/filter.h +1
-0@@ -74,5 +74,6 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender,int iovcnt, void *opaque);void filter_buffer_release_all (void ); +void filter_buffer_del_all_timers (void );#endif /* QEMU_NET_FILTER_H */ net/filter-buffer.c +17
-0@@ -178,6 +178,23 @@ void filter_buffer_release_all(void)qemu_foreach_netfilter (filter_buffer_release_packets,NULL ,NULL ); } +static void filter_buffer_del_timer (NetFilterState *nf,void *opaque, +Error **errp) +{ +if (!strcmp (object_get_typename (OBJECT (nf)),TYPE_FILTER_BUFFER )) { +FilterBufferState *s =FILTER_BUFFER (nf); + +if (s->interval) { +timer_del (&s->release_timer); + } + } +} + +void filter_buffer_del_all_timers (void ) +{ +qemu_foreach_netfilter (filter_buffer_del_timer,NULL ,NULL ); +} +static void filter_buffer_init (Object *obj) { object_property_add(obj, "interval", "int",
Signature · 2 lines
Thanks, Yang
Re: [Qemu-devel] [PATCH COLO-Frame v10 33/38] netfilter: Introduce an API to delete the timer of all buffer-filters
Hi,
Quoted 3 lines · Yang Hongyang
Can you explain why this is needed? Seems that this api hasn't been used in this series.
We will call it in colo_init_filter_buffers() which is introduced in patch 37, We should remove the timers of filter-buffers which are configured by users. Or there will be two places to release packets when we enable colo ft, one in timer callback, the other one in COLO when we do checkpoint.
Thanks,
zhanghailiang
Quoted 51 lines · zhanghailiang
Quoted 49 lines
Signed-off-by zhanghailiang <[email protected]>Cc Jason Wang <[email protected]>---
v10: new patch--- include/net/filter.h | 1 + net/filter-buffer.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+)include/net/filter.h +1
-0@@ -74,5 +74,6 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender,int iovcnt, void *opaque);void filter_buffer_release_all (void ); +void filter_buffer_del_all_timers (void );#endif /* QEMU_NET_FILTER_H */ net/filter-buffer.c +17
-0@@ -178,6 +178,23 @@ void filter_buffer_release_all(void)qemu_foreach_netfilter (filter_buffer_release_packets,NULL ,NULL ); } +static void filter_buffer_del_timer (NetFilterState *nf,void *opaque, +Error **errp) +{ +if (!strcmp (object_get_typename (OBJECT (nf)),TYPE_FILTER_BUFFER )) { +FilterBufferState *s =FILTER_BUFFER (nf); + +if (s->interval) { +timer_del (&s->release_timer); + } + } +} + +void filter_buffer_del_all_timers (void ) +{ +qemu_foreach_netfilter (filter_buffer_del_timer,NULL ,NULL ); +} +static void filter_buffer_init (Object *obj) { object_property_add(obj, "interval", "int",
Re: [Qemu-devel] [PATCH COLO-Frame v10 33/38] netfilter: Introduce an API to delete the timer of all buffer-filters
Quoted 16 lines · zhanghailiang
Hi,
Quoted 3 lines · Yang Hongyang
Can you explain why this is needed? Seems that this api hasn't been used in this series.
We will call it in
colo_init_filter_buffers()which is introduced in patch 37,
We should remove the timers of filter-buffers which are configured by users.
Or there will be two places to release packets when we enable colo ft, one in timer callback,
the other one in COLO when we do checkpoint.
Quoted 2 lines
Thanks,
zhanghailiang
Hi:
Then you'd better explain this in commit log.
Thanks
Quoted 57 lines
Quoted 55 lines · zhanghailiang
Quoted 52 lines
Signed-off-by zhanghailiang <[email protected]>Cc Jason Wang <[email protected]>---
v10: new patch--- include/net/filter.h | 1 + net/filter-buffer.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+)include/net/filter.h +1
-0@@ -74,5 +74,6 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender, int iovcnt, void *opaque);void filter_buffer_release_all (void ); +void filter_buffer_del_all_timers (void );#endif /* QEMU_NET_FILTER_H */net/filter-buffer.c +17
-0@@ -178,6 +178,23 @@ void filter_buffer_release_all(void)qemu_foreach_netfilter (filter_buffer_release_packets,NULL ,NULL ); } +static void filter_buffer_del_timer (NetFilterState *nf,void *opaque, +Error **errp) +{ +if (!strcmp (object_get_typename (OBJECT (nf)),TYPE_FILTER_BUFFER )) { +FilterBufferState *s =FILTER_BUFFER (nf); + +if (s->interval) { +timer_del (&s->release_timer); + } + } +} + +void filter_buffer_del_all_timers (void ) +{ +qemu_foreach_netfilter (filter_buffer_del_timer,NULL ,NULL ); +} +static void filter_buffer_init (Object *obj){ object_property_add(obj, "interval", "int",
Re: [Qemu-devel] [PATCH COLO-Frame v10 33/38] netfilter: Introduce an API to delete the timer of all buffer-filters
Quoted 19 lines · Jason Wang
Quoted 16 lines · zhanghailiang
Hi,
Quoted 3 lines · Yang Hongyang
Can you explain why this is needed? Seems that this api hasn't been used in this series.
We will call it in
colo_init_filter_buffers()which is introduced in patch 37,
We should remove the timers of filter-buffers which are configured by users.
Or there will be two places to release packets when we enable colo ft, one in timer callback,
the other one in COLO when we do checkpoint.
Quoted 7 lines
Quoted 2 lines
Thanks,
zhanghailiangHi:
Then you'd better explain this in commit log.
OK, will fix in next version, thanks.
Quoted 62 lines
Thanks
Quoted 47 lines
Quoted 47 lines · zhanghailiang
Quoted 45 lines
Signed-off-by zhanghailiang <[email protected]>Cc Jason Wang <[email protected]>---
v10: new patch--- include/net/filter.h | 1 + net/filter-buffer.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+)include/net/filter.h +1
-0@@ -74,5 +74,6 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender, int iovcnt, void *opaque);void filter_buffer_release_all (void ); +void filter_buffer_del_all_timers (void );#endif /* QEMU_NET_FILTER_H */net/filter-buffer.c +14
-0@@ -178,6 +178,23 @@ void filter_buffer_release_all(void)qemu_foreach_netfilter (filter_buffer_release_packets,NULL ,NULL ); } +static void filter_buffer_del_timer (NetFilterState *nf,void *opaque, +Error **errp) +{ +if (!strcmp (object_get_typename (OBJECT (nf)),TYPE_FILTER_BUFFER )) { +FilterBufferState *s =FILTER_BUFFER (nf); + +if (s->interval) { +timer_del (&s->release_timer); + } + } +} + +void filter_buffer_del_all_timers (void ) +{Quoted 10 lines
Quoted 8 lines
Quoted 7 lines
net/filter-buffer.c +3
-0+qemu_foreach_netfilter (filter_buffer_del_timer,NULL ,NULL ); +} +static void filter_buffer_init (Object *obj){ object_property_add(obj, "interval", "int",.
PATCH v10 34/38 filter-buffer: Accept zero interval
In reply to zhanghailiang---
v10: new patch
--- net/filter-buffer.c | 10 ---------- 1 file changed, 10 deletions(-)
net/filter-buffer.c +0 -10
@@ -104,16 +104,6 @@ static void filter_buffer_setup(NetFilterState *nf, Error **errp) {FilterBufferState *s =FILTER_BUFFER (nf); -/* -* We may want to accept zero interval when VM FT solutions like MC -* or COLO use this filter to release packets on demand. -*/ -if (!s->interval) { -error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"interval" , -"a non-zero interval" ); -return ; - } - s->incoming_queue =qemu_new_net_queue (qemu_netfilter_pass_to_next, nf);if (s->interval) { timer_init_us(&s->release_timer, QEMU_CLOCK_VIRTUAL,
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH COLO-Frame v10 34/38] filter-buffer: Accept zero interval
Some commit message would be better.
Quoted 2 lines · zhanghailiang
Signed-off-by zhanghailiang <[email protected]>Cc Jason Wang <[email protected]>
Quoted 28 lines
---
v10: new patch--- net/filter-buffer.c | 10 ---------- 1 file changed, 10 deletions(-)net/filter-buffer.c +0
-10@@ -104,16 +104,6 @@ static void filter_buffer_setup(NetFilterState *nf, Error **errp) {FilterBufferState *s =FILTER_BUFFER (nf); -/* -* We may want to accept zero interval when VM FT solutions like MC -* or COLO use this filter to release packets on demand. -*/ -if (!s->interval) { -error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"interval" , -"a non-zero interval" ); -return ; - } - s->incoming_queue =qemu_new_net_queue (qemu_netfilter_pass_to_next, nf);if (s->interval) { timer_init_us(&s->release_timer, QEMU_CLOCK_VIRTUAL,
Signature · 2 lines
Thanks, Yang
Re: [Qemu-devel] [PATCH COLO-Frame v10 34/38] filter-buffer: Accept zero interval
Quoted 1 line · Yang Hongyang
Some commit message would be better.
+1
Quoted 38 lines · zhanghailiang
Quoted 2 lines
Signed-off-by zhanghailiang <[email protected]>Cc Jason Wang <[email protected]>Reviewed-by Yang Hongyang <[email protected]>Quoted 30 lines
---
v10: new patch--- net/filter-buffer.c | 10 ---------- 1 file changed, 10 deletions(-)net/filter-buffer.c +0
-10@@ -104,16 +104,6 @@ static void filter_buffer_setup(NetFilterState *nf, Error **errp) {FilterBufferState *s =FILTER_BUFFER (nf); -/* -* We may want to accept zero interval when VM FT solutions like MC -* or COLO use this filter to release packets on demand. -*/ -if (!s->interval) { -error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"interval" , -"a non-zero interval" ); -return ; - } - s->incoming_queue =qemu_new_net_queue (qemu_netfilter_pass_to_next, nf);if (s->interval) { timer_init_us(&s->release_timer, QEMU_CLOCK_VIRTUAL,
PATCH v10 35/38 netfilter: Introduce a API to automatically add filter-buffer for each netdev
In reply to zhanghailiang---
v10: new patch
--- include/net/filter.h | 1 + include/net/net.h | 3 ++ net/filter-buffer.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ net/net.c | 20 +++++++++++++ 4 files changed, 108 insertions(+)
include/net/filter.h +1 -0
@@ -75,5 +75,6 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender, void *opaque);void filter_buffer_release_all (void );void filter_buffer_del_all_timers (void ); +void qemu_auto_add_filter_buffer (NetFilterDirection direction,Error **errp);#endif /* QEMU_NET_FILTER_H */
include/net/net.h +3 -0
@@ -129,6 +129,9 @@ typedef void (*qemu_netfilter_foreach)(NetFilterState *nf, void *opaque, Error **errp);void qemu_foreach_netfilter (qemu_netfilter_foreach func,void *opaque,Error **errp); +typedef void (*qemu_netdev_foreach )(NetClientState *nc,void *opaque, +Error **errp); +void qemu_foreach_netdev (qemu_netdev_foreach func,void *opaque,Error **errp);int qemu_can_send_packet (NetClientState *nc);ssize_t qemu_sendv_packet (NetClientState *nc,const struct iovec *iov,int iovcnt);
net/filter-buffer.c +84 -0
96 lines not on this page · raw message
net/net.c +20 -0
@@ -283,6 +283,26 @@ void qemu_foreach_netfilter(qemu_netfilter_foreach func, void *opaque, } } +void qemu_foreach_netdev (qemu_netdev_foreach func,void *opaque,Error **errp) +{ +NetClientState *nc; + + QTAILQ_FOREACH(nc, &net_clients, next) { +if (nc->info->type ==NET_CLIENT_OPTIONS_KIND_NIC ) { +continue ; + } +if (func) { +Error *local_err =NULL ; + +func (nc, opaque, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + } + } +} +static void qemu_net_client_destructor (NetClientState *nc) {g_free (nc);
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH COLO-Frame v10 35/38] netfilter: Introduce a API to automatically add filter-buffer for each netdev
Quoted 55 lines · zhanghailiang
Signed-off-by zhanghailiang <[email protected]>Cc Jason Wang <[email protected]>---
v10: new patch--- include/net/filter.h | 1 + include/net/net.h | 3 ++ net/filter-buffer.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ net/net.c | 20 +++++++++++++ 4 files changed, 108 insertions(+)include/net/filter.h +1
-0@@ -75,5 +75,6 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender, void *opaque);void filter_buffer_release_all (void );void filter_buffer_del_all_timers (void ); +void qemu_auto_add_filter_buffer (NetFilterDirection direction,Error **errp);#endif /* QEMU_NET_FILTER_H */ include/net/net.h +3
-0@@ -129,6 +129,9 @@ typedef void (*qemu_netfilter_foreach)(NetFilterState *nf, void *opaque, Error **errp);void qemu_foreach_netfilter (qemu_netfilter_foreach func,void *opaque,Error **errp); +typedef void (*qemu_netdev_foreach )(NetClientState *nc,void *opaque, +Error **errp); +void qemu_foreach_netdev (qemu_netdev_foreach func,void *opaque,Error **errp);int qemu_can_send_packet (NetClientState *nc);ssize_t qemu_sendv_packet (NetClientState *nc,const struct iovec *iov,int iovcnt);net/filter-buffer.c +5
-0@@ -15,6 +15,11 @@#include "qapi-visit.h" #include "qom/object.h" #include "net/net.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp-output-visitor.h" +#include "qapi/qmp-input-visitor.h" +#include "monitor/monitor.h" +#define TYPE_FILTER_BUFFER "filter-buffer"@@ -185,6 +190,85 @@ void filter_buffer_del_all_timers(void)qemu_foreach_netfilter (filter_buffer_del_timer,NULL ,NULL ); }
net/filter-buffer.c void filter_buffer_del_all_timers(void) · line 201
Quoted 10 lines
net/filter-buffer.c +9
-0+static void netdev_add_filter_buffer (NetClientState *nc,void *opaque, +Error **errp) +{ +NetFilterState *nf; +bool found = false; + + QTAILQ_FOREACH(nf, &nc->filters, next) { +if (!strcmp (object_get_typename (OBJECT (nf)),TYPE_FILTER_BUFFER )) { + found = true;
What if a filter-buffer already attached to a netdev, but has interval set?
Is this API really necessary?
Quoted 105 lines
net/filter-buffer.c +70
-0+break ; + } + } + +if (!found) { +QmpOutputVisitor *qov; +QmpInputVisitor *qiv; +Visitor *ov, *iv; +QObject *obj =NULL ; +QDict *qdict; +void *dummy =NULL ; +char *id =g_strdup_printf ("%s-%s.0" , nc->name,TYPE_FILTER_BUFFER ); +char *queue = (char *) opaque; +bool auto_add = true; +Error *err =NULL ; + + qov =qmp_output_visitor_new (); + ov =qmp_output_get_visitor (qov); +visit_start_struct (ov, &dummy,NULL ,NULL ,0 , &err); +if (err) { + goto out; + } +visit_type_str (ov, &nc->name,"netdev" , &err); +if (err) { + goto out; + } +visit_type_str (ov, &queue,"queue" , &err); +if (err) { + goto out; + } +visit_type_bool (ov, &auto_add,"auto" , &err); +if (err) { + goto out; + } +visit_end_struct (ov, &err); +if (err) { + goto out; + } + obj =qmp_output_get_qobject (qov); +g_assert (obj !=NULL ); + qdict =qobject_to_qdict (obj); +qmp_output_visitor_cleanup (qov); + + qiv =qmp_input_visitor_new (obj); + iv =qmp_input_get_visitor (qiv); +object_add (TYPE_FILTER_BUFFER , id, qdict, iv, &err); +qmp_input_visitor_cleanup (qiv); +qobject_decref (obj); +out: +g_free (id); +if (err) { +error_propagate (errp, err); + } + } +} +/* +* This will be used by COLO or MC FT, for which they will need +* to buffer all the packets of all VM's net devices, Here we check +* and automatically add netfilter for netdev that doesn't attach any buffer +* netfilter. +*/ +void qemu_auto_add_filter_buffer (NetFilterDirection direction,Error **errp) +{ +char *queue =g_strdup (NetFilterDirection_lookup[direction]); + +qemu_foreach_netdev (netdev_add_filter_buffer, queue, + errp); +g_free (queue); +} +static void filter_buffer_init (Object *obj) { object_property_add(obj, "interval", "int",net/net.c +20
-0@@ -283,6 +283,26 @@ void qemu_foreach_netfilter(qemu_netfilter_foreach func, void *opaque, } } +void qemu_foreach_netdev (qemu_netdev_foreach func,void *opaque,Error **errp) +{ +NetClientState *nc; + + QTAILQ_FOREACH(nc, &net_clients, next) { +if (nc->info->type ==NET_CLIENT_OPTIONS_KIND_NIC ) { +continue ; + } +if (func) { +Error *local_err =NULL ; + +func (nc, opaque, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + } + } +} +static void qemu_net_client_destructor (NetClientState *nc) {g_free (nc);
Signature · 2 lines
Thanks, Yang
Re: [Qemu-devel] [PATCH COLO-Frame v10 35/38] netfilter: Introduce a API to automatically add filter-buffer for each netdev
Quoted 59 lines · Yang Hongyang
Quoted 56 lines · zhanghailiang
Signed-off-by zhanghailiang <[email protected]>Cc Jason Wang <[email protected]>---
v10: new patch--- include/net/filter.h | 1 + include/net/net.h | 3 ++ net/filter-buffer.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ net/net.c | 20 +++++++++++++ 4 files changed, 108 insertions(+)include/net/filter.h +1
-0@@ -75,5 +75,6 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender, void *opaque);void filter_buffer_release_all (void );void filter_buffer_del_all_timers (void ); +void qemu_auto_add_filter_buffer (NetFilterDirection direction,Error **errp);#endif /* QEMU_NET_FILTER_H */ include/net/net.h +3
-0@@ -129,6 +129,9 @@ typedef void (*qemu_netfilter_foreach)(NetFilterState *nf, void *opaque, Error **errp);void qemu_foreach_netfilter (qemu_netfilter_foreach func,void *opaque,Error **errp); +typedef void (*qemu_netdev_foreach )(NetClientState *nc,void *opaque, +Error **errp); +void qemu_foreach_netdev (qemu_netdev_foreach func,void *opaque,Error **errp);int qemu_can_send_packet (NetClientState *nc);ssize_t qemu_sendv_packet (NetClientState *nc,const struct iovec *iov,int iovcnt);net/filter-buffer.c +5
-0@@ -15,6 +15,11 @@#include "qapi-visit.h" #include "qom/object.h" #include "net/net.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp-output-visitor.h" +#include "qapi/qmp-input-visitor.h" +#include "monitor/monitor.h" +#define TYPE_FILTER_BUFFER "filter-buffer"@@ -185,6 +190,85 @@ void filter_buffer_del_all_timers(void)qemu_foreach_netfilter (filter_buffer_del_timer,NULL ,NULL ); }
Quoted 14 lines
net/filter-buffer.c void filter_buffer_del_all_timers(void) · line 201
Quoted 9 lines
net/filter-buffer.c +9
-0+static void netdev_add_filter_buffer (NetClientState *nc,void *opaque, +Error **errp) +{ +NetFilterState *nf; +bool found = false; + + QTAILQ_FOREACH(nf, &nc->filters, next) { +if (!strcmp (object_get_typename (OBJECT (nf)),TYPE_FILTER_BUFFER )) { + found = true;What if a filter-buffer already attached to a netdev, but has interval set?
Is this API really necessary?
We will jump this netdev, but remove its filter-buffer timer. Meanwhile, we will release the packets all together in colo checkpoint process.
Besides, we should resume the timer after exit COLO. (We didn't do this in this version).
I don't know if it is a good idea to automatically add filter-buffer for the device that not configured with it. But it is really reduce the complexity of testing.
Quoted 106 lines
Quoted 105 lines
net/filter-buffer.c +70
-0+break ; + } + } + +if (!found) { +QmpOutputVisitor *qov; +QmpInputVisitor *qiv; +Visitor *ov, *iv; +QObject *obj =NULL ; +QDict *qdict; +void *dummy =NULL ; +char *id =g_strdup_printf ("%s-%s.0" , nc->name,TYPE_FILTER_BUFFER ); +char *queue = (char *) opaque; +bool auto_add = true; +Error *err =NULL ; + + qov =qmp_output_visitor_new (); + ov =qmp_output_get_visitor (qov); +visit_start_struct (ov, &dummy,NULL ,NULL ,0 , &err); +if (err) { + goto out; + } +visit_type_str (ov, &nc->name,"netdev" , &err); +if (err) { + goto out; + } +visit_type_str (ov, &queue,"queue" , &err); +if (err) { + goto out; + } +visit_type_bool (ov, &auto_add,"auto" , &err); +if (err) { + goto out; + } +visit_end_struct (ov, &err); +if (err) { + goto out; + } + obj =qmp_output_get_qobject (qov); +g_assert (obj !=NULL ); + qdict =qobject_to_qdict (obj); +qmp_output_visitor_cleanup (qov); + + qiv =qmp_input_visitor_new (obj); + iv =qmp_input_get_visitor (qiv); +object_add (TYPE_FILTER_BUFFER , id, qdict, iv, &err); +qmp_input_visitor_cleanup (qiv); +qobject_decref (obj); +out: +g_free (id); +if (err) { +error_propagate (errp, err); + } + } +} +/* +* This will be used by COLO or MC FT, for which they will need +* to buffer all the packets of all VM's net devices, Here we check +* and automatically add netfilter for netdev that doesn't attach any buffer +* netfilter. +*/ +void qemu_auto_add_filter_buffer (NetFilterDirection direction,Error **errp) +{ +char *queue =g_strdup (NetFilterDirection_lookup[direction]); + +qemu_foreach_netdev (netdev_add_filter_buffer, queue, + errp); +g_free (queue); +} +static void filter_buffer_init (Object *obj) { object_property_add(obj, "interval", "int",net/net.c +20
-0@@ -283,6 +283,26 @@ void qemu_foreach_netfilter(qemu_netfilter_foreach func, void *opaque, } } +void qemu_foreach_netdev (qemu_netdev_foreach func,void *opaque,Error **errp) +{ +NetClientState *nc; + + QTAILQ_FOREACH(nc, &net_clients, next) { +if (nc->info->type ==NET_CLIENT_OPTIONS_KIND_NIC ) { +continue ; + } +if (func) { +Error *local_err =NULL ; + +func (nc, opaque, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + } + } +} +static void qemu_net_client_destructor (NetClientState *nc) {g_free (nc);
Re: [Qemu-devel] [PATCH COLO-Frame v10 35/38] netfilter: Introduce a API to automatically add filter-buffer for each netdev
In reply to zhanghailiangQuoted 2 lines · zhanghailiang
Signed-off-by zhanghailiang <[email protected]>Cc Jason Wang <[email protected]>
Commit log please.
Quoted 123 lines
---
v10: new patch--- include/net/filter.h | 1 + include/net/net.h | 3 ++ net/filter-buffer.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ net/net.c | 20 +++++++++++++ 4 files changed, 108 insertions(+)include/net/filter.h +1
-0@@ -75,5 +75,6 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender, void *opaque);void filter_buffer_release_all (void );void filter_buffer_del_all_timers (void ); +void qemu_auto_add_filter_buffer (NetFilterDirection direction,Error **errp);#endif /* QEMU_NET_FILTER_H */ include/net/net.h +3
-0@@ -129,6 +129,9 @@ typedef void (*qemu_netfilter_foreach)(NetFilterState *nf, void *opaque, Error **errp);void qemu_foreach_netfilter (qemu_netfilter_foreach func,void *opaque,Error **errp); +typedef void (*qemu_netdev_foreach )(NetClientState *nc,void *opaque, +Error **errp); +void qemu_foreach_netdev (qemu_netdev_foreach func,void *opaque,Error **errp);int qemu_can_send_packet (NetClientState *nc);ssize_t qemu_sendv_packet (NetClientState *nc,const struct iovec *iov,int iovcnt);net/filter-buffer.c +74
-0@@ -15,6 +15,11 @@#include "qapi-visit.h" #include "qom/object.h" #include "net/net.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp-output-visitor.h" +#include "qapi/qmp-input-visitor.h" +#include "monitor/monitor.h" +#define TYPE_FILTER_BUFFER "filter-buffer"@@ -185,6 +190,85 @@ void filter_buffer_del_all_timers(void)qemu_foreach_netfilter (filter_buffer_del_timer,NULL ,NULL ); } +static void netdev_add_filter_buffer (NetClientState *nc,void *opaque, +Error **errp) +{ +NetFilterState *nf; +bool found = false; + + QTAILQ_FOREACH(nf, &nc->filters, next) { +if (!strcmp (object_get_typename (OBJECT (nf)),TYPE_FILTER_BUFFER )) { + found = true; +break ; + } + } + +if (!found) { +QmpOutputVisitor *qov; +QmpInputVisitor *qiv; +Visitor *ov, *iv; +QObject *obj =NULL ; +QDict *qdict; +void *dummy =NULL ; +char *id =g_strdup_printf ("%s-%s.0" , nc->name,TYPE_FILTER_BUFFER ); +char *queue = (char *) opaque; +bool auto_add = true; +Error *err =NULL ; + + qov =qmp_output_visitor_new (); + ov =qmp_output_get_visitor (qov); +visit_start_struct (ov, &dummy,NULL ,NULL ,0 , &err); +if (err) { + goto out; + } +visit_type_str (ov, &nc->name,"netdev" , &err); +if (err) { + goto out; + } +visit_type_str (ov, &queue,"queue" , &err); +if (err) { + goto out; + } +visit_type_bool (ov, &auto_add,"auto" , &err); +if (err) { + goto out; + } +visit_end_struct (ov, &err); +if (err) { + goto out; + } + obj =qmp_output_get_qobject (qov); +g_assert (obj !=NULL ); + qdict =qobject_to_qdict (obj); +qmp_output_visitor_cleanup (qov); + + qiv =qmp_input_visitor_new (obj); + iv =qmp_input_get_visitor (qiv); +object_add (TYPE_FILTER_BUFFER , id, qdict, iv, &err); +qmp_input_visitor_cleanup (qiv); +qobject_decref (obj); +out: +g_free (id); +if (err) { +error_propagate (errp, err); + } + } +} +/* +* This will be used by COLO or MC FT, for which they will need +* to buffer all the packets of all VM's net devices, Here we check +* and automatically add netfilter for netdev that doesn't attach any buffer +* netfilter.
net/filter-buffer.c void filter_buffer_del_all_timers(void) · line 271
Quoted 10 lines
net/filter-buffer.c +10
-0+*/ +void qemu_auto_add_filter_buffer (NetFilterDirection direction,Error **errp) +{ +char *queue =g_strdup (NetFilterDirection_lookup[direction]); + +qemu_foreach_netdev (netdev_add_filter_buffer, queue, + errp); +g_free (queue); +} +
This make me think for following questions:
- What if a nic is hot added after this "automatically" filter add?
- Maybe a better way is to have a default filter? It could be specified through qemu cli or other (And default filter could be 'nop' which means no filter) ?
Quoted 34 lines
net/filter-buffer.c +0
-0static void filter_buffer_init (Object *obj) { object_property_add(obj, "interval", "int",net/net.c +20
-0@@ -283,6 +283,26 @@ void qemu_foreach_netfilter(qemu_netfilter_foreach func, void *opaque, } } +void qemu_foreach_netdev (qemu_netdev_foreach func,void *opaque,Error **errp) +{ +NetClientState *nc; + + QTAILQ_FOREACH(nc, &net_clients, next) { +if (nc->info->type ==NET_CLIENT_OPTIONS_KIND_NIC ) { +continue ; + } +if (func) { +Error *local_err =NULL ; + +func (nc, opaque, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + } + } +} +static void qemu_net_client_destructor (NetClientState *nc) {g_free (nc);
Re: [Qemu-devel] [PATCH COLO-Frame v10 35/38] netfilter: Introduce a API to automatically add filter-buffer for each netdev
Quoted 144 lines · Jason Wang
Quoted 2 lines · zhanghailiang
Signed-off-by zhanghailiang <[email protected]>Cc Jason Wang <[email protected]>Commit log please.
Quoted 123 lines
---
v10: new patch--- include/net/filter.h | 1 + include/net/net.h | 3 ++ net/filter-buffer.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ net/net.c | 20 +++++++++++++ 4 files changed, 108 insertions(+)include/net/filter.h +1
-0@@ -75,5 +75,6 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender, void *opaque);void filter_buffer_release_all (void );void filter_buffer_del_all_timers (void ); +void qemu_auto_add_filter_buffer (NetFilterDirection direction,Error **errp);#endif /* QEMU_NET_FILTER_H */ include/net/net.h +3
-0@@ -129,6 +129,9 @@ typedef void (*qemu_netfilter_foreach)(NetFilterState *nf, void *opaque, Error **errp);void qemu_foreach_netfilter (qemu_netfilter_foreach func,void *opaque,Error **errp); +typedef void (*qemu_netdev_foreach )(NetClientState *nc,void *opaque, +Error **errp); +void qemu_foreach_netdev (qemu_netdev_foreach func,void *opaque,Error **errp);int qemu_can_send_packet (NetClientState *nc);ssize_t qemu_sendv_packet (NetClientState *nc,const struct iovec *iov,int iovcnt);net/filter-buffer.c +74
-0@@ -15,6 +15,11 @@#include "qapi-visit.h" #include "qom/object.h" #include "net/net.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp-output-visitor.h" +#include "qapi/qmp-input-visitor.h" +#include "monitor/monitor.h" +#define TYPE_FILTER_BUFFER "filter-buffer"@@ -185,6 +190,85 @@ void filter_buffer_del_all_timers(void)qemu_foreach_netfilter (filter_buffer_del_timer,NULL ,NULL ); } +static void netdev_add_filter_buffer (NetClientState *nc,void *opaque, +Error **errp) +{ +NetFilterState *nf; +bool found = false; + + QTAILQ_FOREACH(nf, &nc->filters, next) { +if (!strcmp (object_get_typename (OBJECT (nf)),TYPE_FILTER_BUFFER )) { + found = true; +break ; + } + } + +if (!found) { +QmpOutputVisitor *qov; +QmpInputVisitor *qiv; +Visitor *ov, *iv; +QObject *obj =NULL ; +QDict *qdict; +void *dummy =NULL ; +char *id =g_strdup_printf ("%s-%s.0" , nc->name,TYPE_FILTER_BUFFER ); +char *queue = (char *) opaque; +bool auto_add = true; +Error *err =NULL ; + + qov =qmp_output_visitor_new (); + ov =qmp_output_get_visitor (qov); +visit_start_struct (ov, &dummy,NULL ,NULL ,0 , &err); +if (err) { + goto out; + } +visit_type_str (ov, &nc->name,"netdev" , &err); +if (err) { + goto out; + } +visit_type_str (ov, &queue,"queue" , &err); +if (err) { + goto out; + } +visit_type_bool (ov, &auto_add,"auto" , &err); +if (err) { + goto out; + } +visit_end_struct (ov, &err); +if (err) { + goto out; + } + obj =qmp_output_get_qobject (qov); +g_assert (obj !=NULL ); + qdict =qobject_to_qdict (obj); +qmp_output_visitor_cleanup (qov); + + qiv =qmp_input_visitor_new (obj); + iv =qmp_input_get_visitor (qiv); +object_add (TYPE_FILTER_BUFFER , id, qdict, iv, &err); +qmp_input_visitor_cleanup (qiv); +qobject_decref (obj); +out: +g_free (id); +if (err) { +error_propagate (errp, err); + } + } +} +/* +* This will be used by COLO or MC FT, for which they will need +* to buffer all the packets of all VM's net devices, Here we check +* and automatically add netfilter for netdev that doesn't attach any buffer +* netfilter. net/filter-buffer.c void filter_buffer_del_all_timers(void) · line 271
Quoted 10 lines
net/filter-buffer.c +10
-0+*/ +void qemu_auto_add_filter_buffer (NetFilterDirection direction,Error **errp) +{ +char *queue =g_strdup (NetFilterDirection_lookup[direction]); + +qemu_foreach_netdev (netdev_add_filter_buffer, queue, + errp); +g_free (queue); +} +This make me think for following questions:
Quoted 1 line
- What if a nic is hot added after this "automatically" filter add?
Actually, we didn't support hotplug device when COLO is enabled, maybe we could support it in future.
If we support hotplug, and yes, it is a problem.
Quoted 4 lines
- Maybe a better way is to have a default filter? It could be specified through qemu cli or other (And default filter could be 'nop' which means no filter) ?
That's really a good idea, and we can enable packets 'buffer' capability only when needed. I will investigate ... :)
Thanks,
zhanghailiang
Quoted 38 lines
Quoted 24 lines
net/filter-buffer.c +0
-0static void filter_buffer_init (Object *obj) { object_property_add(obj, "interval", "int",net/net.c +13
-0@@ -283,6 +283,26 @@ void qemu_foreach_netfilter(qemu_netfilter_foreach func, void *opaque, } } +void qemu_foreach_netdev (qemu_netdev_foreach func,void *opaque,Error **errp) +{ +NetClientState *nc; + + QTAILQ_FOREACH(nc, &net_clients, next) { +if (nc->info->type ==NET_CLIENT_OPTIONS_KIND_NIC ) { +continue ; + } +if (func) { +Error *local_err =NULL ; + +func (nc, opaque, &local_err); +if (local_err) {net/net.c void qemu_foreach_netfilter(qemu_netfilter_foreach func, void *opaque, · line 308
Quoted 10 lines
net/net.c +7
-0+error_propagate (errp, local_err); +return ; + } + } + } +} +static void qemu_net_client_destructor (NetClientState *nc) {g_free (nc);.
Re: [Qemu-devel] [PATCH COLO-Frame v10 35/38] netfilter: Introduce a API to automatically add filter-buffer for each netdev
In reply to Jason WangHi Jason,
Quoted 144 lines · Jason Wang
Quoted 2 lines · zhanghailiang
Signed-off-by zhanghailiang <[email protected]>Cc Jason Wang <[email protected]>Commit log please.
Quoted 123 lines
---
v10: new patch--- include/net/filter.h | 1 + include/net/net.h | 3 ++ net/filter-buffer.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ net/net.c | 20 +++++++++++++ 4 files changed, 108 insertions(+)include/net/filter.h +1
-0@@ -75,5 +75,6 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender, void *opaque);void filter_buffer_release_all (void );void filter_buffer_del_all_timers (void ); +void qemu_auto_add_filter_buffer (NetFilterDirection direction,Error **errp);#endif /* QEMU_NET_FILTER_H */ include/net/net.h +3
-0@@ -129,6 +129,9 @@ typedef void (*qemu_netfilter_foreach)(NetFilterState *nf, void *opaque, Error **errp);void qemu_foreach_netfilter (qemu_netfilter_foreach func,void *opaque,Error **errp); +typedef void (*qemu_netdev_foreach )(NetClientState *nc,void *opaque, +Error **errp); +void qemu_foreach_netdev (qemu_netdev_foreach func,void *opaque,Error **errp);int qemu_can_send_packet (NetClientState *nc);ssize_t qemu_sendv_packet (NetClientState *nc,const struct iovec *iov,int iovcnt);net/filter-buffer.c +74
-0@@ -15,6 +15,11 @@#include "qapi-visit.h" #include "qom/object.h" #include "net/net.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp-output-visitor.h" +#include "qapi/qmp-input-visitor.h" +#include "monitor/monitor.h" +#define TYPE_FILTER_BUFFER "filter-buffer"@@ -185,6 +190,85 @@ void filter_buffer_del_all_timers(void)qemu_foreach_netfilter (filter_buffer_del_timer,NULL ,NULL ); } +static void netdev_add_filter_buffer (NetClientState *nc,void *opaque, +Error **errp) +{ +NetFilterState *nf; +bool found = false; + + QTAILQ_FOREACH(nf, &nc->filters, next) { +if (!strcmp (object_get_typename (OBJECT (nf)),TYPE_FILTER_BUFFER )) { + found = true; +break ; + } + } + +if (!found) { +QmpOutputVisitor *qov; +QmpInputVisitor *qiv; +Visitor *ov, *iv; +QObject *obj =NULL ; +QDict *qdict; +void *dummy =NULL ; +char *id =g_strdup_printf ("%s-%s.0" , nc->name,TYPE_FILTER_BUFFER ); +char *queue = (char *) opaque; +bool auto_add = true; +Error *err =NULL ; + + qov =qmp_output_visitor_new (); + ov =qmp_output_get_visitor (qov); +visit_start_struct (ov, &dummy,NULL ,NULL ,0 , &err); +if (err) { + goto out; + } +visit_type_str (ov, &nc->name,"netdev" , &err); +if (err) { + goto out; + } +visit_type_str (ov, &queue,"queue" , &err); +if (err) { + goto out; + } +visit_type_bool (ov, &auto_add,"auto" , &err); +if (err) { + goto out; + } +visit_end_struct (ov, &err); +if (err) { + goto out; + } + obj =qmp_output_get_qobject (qov); +g_assert (obj !=NULL ); + qdict =qobject_to_qdict (obj); +qmp_output_visitor_cleanup (qov); + + qiv =qmp_input_visitor_new (obj); + iv =qmp_input_get_visitor (qiv); +object_add (TYPE_FILTER_BUFFER , id, qdict, iv, &err); +qmp_input_visitor_cleanup (qiv); +qobject_decref (obj); +out: +g_free (id); +if (err) { +error_propagate (errp, err); + } + } +} +/* +* This will be used by COLO or MC FT, for which they will need +* to buffer all the packets of all VM's net devices, Here we check +* and automatically add netfilter for netdev that doesn't attach any buffer +* netfilter. net/filter-buffer.c void filter_buffer_del_all_timers(void) · line 271
Quoted 10 lines
net/filter-buffer.c +10
-0+*/ +void qemu_auto_add_filter_buffer (NetFilterDirection direction,Error **errp) +{ +char *queue =g_strdup (NetFilterDirection_lookup[direction]); + +qemu_foreach_netdev (netdev_add_filter_buffer, queue, + errp); +g_free (queue); +} +This make me think for following questions:
Quoted 5 lines
- What if a nic is hot added after this "automatically" filter add?
- Maybe a better way is to have a default filter? It could be specified through qemu cli or other (And default filter could be 'nop' which means no filter) ?
I have thought about this. I'd like to add this default buffer filter quietly,
not through qemu cli. In this way, we can still keep the buffer filter that configured by users, and keep its delay release packets capability. Though the delay time is not what users suppose. (This is only happened in COLO's periodic mode, in normal colo mode, the delay time is almost same with user's configure.)
What about call netdev_add_filter_buffer() in each netdev's init() ? I didn't found a common code path for every netdev in their init path.
Thanks,
zhanghailiang
Quoted 38 lines
Quoted 24 lines
net/filter-buffer.c +0
-0static void filter_buffer_init (Object *obj) { object_property_add(obj, "interval", "int",net/net.c +13
-0@@ -283,6 +283,26 @@ void qemu_foreach_netfilter(qemu_netfilter_foreach func, void *opaque, } } +void qemu_foreach_netdev (qemu_netdev_foreach func,void *opaque,Error **errp) +{ +NetClientState *nc; + + QTAILQ_FOREACH(nc, &net_clients, next) { +if (nc->info->type ==NET_CLIENT_OPTIONS_KIND_NIC ) { +continue ; + } +if (func) { +Error *local_err =NULL ; + +func (nc, opaque, &local_err); +if (local_err) {net/net.c void qemu_foreach_netfilter(qemu_netfilter_foreach func, void *opaque, · line 308
Quoted 10 lines
net/net.c +7
-0+error_propagate (errp, local_err); +return ; + } + } + } +} +static void qemu_net_client_destructor (NetClientState *nc) {g_free (nc);.
Re: [Qemu-devel] [PATCH COLO-Frame v10 35/38] netfilter: Introduce a API to automatically add filter-buffer for each netdev
Quoted 148 lines · zhanghailiang
Hi Jason,
Quoted 145 lines · Jason Wang
Quoted 2 lines · zhanghailiang
Signed-off-by zhanghailiang <[email protected]>Cc Jason Wang <[email protected]>Commit log please.
Quoted 123 lines
---
v10: new patch--- include/net/filter.h | 1 + include/net/net.h | 3 ++ net/filter-buffer.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ net/net.c | 20 +++++++++++++ 4 files changed, 108 insertions(+)include/net/filter.h +1
-0@@ -75,5 +75,6 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender, void *opaque);void filter_buffer_release_all (void );void filter_buffer_del_all_timers (void ); +void qemu_auto_add_filter_buffer (NetFilterDirection direction,Error **errp);#endif /* QEMU_NET_FILTER_H */ include/net/net.h +3
-0@@ -129,6 +129,9 @@ typedef void (*qemu_netfilter_foreach)(NetFilterState *nf, void *opaque, Error **errp);void qemu_foreach_netfilter (qemu_netfilter_foreach func,void *opaque,Error **errp); +typedef void (*qemu_netdev_foreach )(NetClientState *nc,void *opaque, +Error **errp); +void qemu_foreach_netdev (qemu_netdev_foreach func,void *opaque,Error **errp);int qemu_can_send_packet (NetClientState *nc);ssize_t qemu_sendv_packet (NetClientState *nc,const struct iovec *iov,int iovcnt);net/filter-buffer.c +74
-0@@ -15,6 +15,11 @@#include "qapi-visit.h" #include "qom/object.h" #include "net/net.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp-output-visitor.h" +#include "qapi/qmp-input-visitor.h" +#include "monitor/monitor.h" +#define TYPE_FILTER_BUFFER "filter-buffer"@@ -185,6 +190,85 @@ void filter_buffer_del_all_timers(void)qemu_foreach_netfilter (filter_buffer_del_timer,NULL ,NULL ); } +static void netdev_add_filter_buffer (NetClientState *nc,void *opaque, +Error **errp) +{ +NetFilterState *nf; +bool found = false; + + QTAILQ_FOREACH(nf, &nc->filters, next) { +if (!strcmp (object_get_typename (OBJECT (nf)),TYPE_FILTER_BUFFER )) { + found = true; +break ; + } + } + +if (!found) { +QmpOutputVisitor *qov; +QmpInputVisitor *qiv; +Visitor *ov, *iv; +QObject *obj =NULL ; +QDict *qdict; +void *dummy =NULL ; +char *id =g_strdup_printf ("%s-%s.0" , nc->name,TYPE_FILTER_BUFFER ); +char *queue = (char *) opaque; +bool auto_add = true; +Error *err =NULL ; + + qov =qmp_output_visitor_new (); + ov =qmp_output_get_visitor (qov); +visit_start_struct (ov, &dummy,NULL ,NULL ,0 , &err); +if (err) { + goto out; + } +visit_type_str (ov, &nc->name,"netdev" , &err); +if (err) { + goto out; + } +visit_type_str (ov, &queue,"queue" , &err); +if (err) { + goto out; + } +visit_type_bool (ov, &auto_add,"auto" , &err); +if (err) { + goto out; + } +visit_end_struct (ov, &err); +if (err) { + goto out; + } + obj =qmp_output_get_qobject (qov); +g_assert (obj !=NULL ); + qdict =qobject_to_qdict (obj); +qmp_output_visitor_cleanup (qov); + + qiv =qmp_input_visitor_new (obj); + iv =qmp_input_get_visitor (qiv); +object_add (TYPE_FILTER_BUFFER , id, qdict, iv, &err); +qmp_input_visitor_cleanup (qiv); +qobject_decref (obj); +out: +g_free (id); +if (err) { +error_propagate (errp, err); + } + } +} +/* +* This will be used by COLO or MC FT, for which they will need +* to buffer all the packets of all VM's net devices, Here we check +* and automatically add netfilter for netdev that doesn't attach any buffer +* netfilter. net/filter-buffer.c void filter_buffer_del_all_timers(void) · line 271
Quoted 10 lines
net/filter-buffer.c +10
-0+*/ +void qemu_auto_add_filter_buffer (NetFilterDirection direction,Error **errp) +{ +char *queue =g_strdup (NetFilterDirection_lookup[direction]); + +qemu_foreach_netdev (netdev_add_filter_buffer, queue, + errp); +g_free (queue); +} +This make me think for following questions:
- What if a nic is hot added after this "automatically" filter add?
IIRC, we don't allow the user to hotplug a device when colo is running.
Thanks
Wen Congyang
Quoted 60 lines
Quoted 4 lines
- Maybe a better way is to have a default filter? It could be specified through qemu cli or other (And default filter could be 'nop' which means no filter) ?
I have thought about this. I'd like to add this default buffer filter quietly,
not through qemu cli. In this way, we can still keep the buffer filter that configured by users, and keep its delay release packets capability. Though the delay time is not what users suppose. (This is only happened in COLO's periodic mode, in normal colo mode, the delay time is almost same with user's configure.)What about call
netdev_add_filter_buffer()in each netdev'sinit()? I didn't found a common code path for every netdev in their init path.Thanks,
zhanghailiangQuoted 29 lines
Quoted 29 lines
net/filter-buffer.c +0
-0static void filter_buffer_init (Object *obj) { object_property_add(obj, "interval", "int",net/net.c +18
-0@@ -283,6 +283,26 @@ void qemu_foreach_netfilter(qemu_netfilter_foreach func, void *opaque, } } +void qemu_foreach_netdev (qemu_netdev_foreach func,void *opaque,Error **errp) +{ +NetClientState *nc; + + QTAILQ_FOREACH(nc, &net_clients, next) { +if (nc->info->type ==NET_CLIENT_OPTIONS_KIND_NIC ) { +continue ; + } +if (func) { +Error *local_err =NULL ; + +func (nc, opaque, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + } + }Quoted 9 lines
net/net.c void qemu_foreach_netfilter(qemu_netfilter_foreach func, void *opaque, · line 308
Quoted 5 lines
net/net.c +2
-0+} +static void qemu_net_client_destructor (NetClientState *nc) {g_free (nc);.
.
Re: [Qemu-devel] [PATCH COLO-Frame v10 35/38] netfilter: Introduce a API to automatically add filter-buffer for each netdev
Quoted 15 lines · Wen Congyang
Quoted 14 lines · zhanghailiang
Quoted 14 lines
Hi Jason,
Quoted 11 lines · Jason Wang
Quoted 11 lines · zhanghailiang
Quoted 2 lines
Quoted 2 lines
Signed-off-by zhanghailiang <[email protected]>Cc Jason Wang <[email protected]>Commit log please.
Quoted 3 lines
Quoted 3 lines
---
v10: new patch
---
[...]
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 8 lines
Quoted 8 lines
net/filter-buffer.c +8
-0+} +/* +* This will be used by COLO or MC FT, for which they will need +* to buffer all the packets of all VM's net devices, Here we check +* and automatically add netfilter for netdev that doesn't attach any buffer +* netfilter. +*/ +void qemu_auto_add_filter_buffer (NetFilterDirection direction,Error **errp)Quoted 8 lines
net/filter-buffer.c void filter_buffer_del_all_timers(void) · line 271
Quoted 8 lines
net/filter-buffer.c +8
-0+{ +char *queue =g_strdup (NetFilterDirection_lookup[direction]); + +qemu_foreach_netdev (netdev_add_filter_buffer, queue, + errp); +g_free (queue); +} +This make me think for following questions:
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
- What if a nic is hot added after this "automatically" filter add?
IIRC, we don't allow the user to hotplug a device when colo is running.
Thanks
Wen Congyang
Even in the future? And how could forbid the user to do this, management?
Thanks
Re: [Qemu-devel] [PATCH COLO-Frame v10 35/38] netfilter: Introduce a API to automatically add filter-buffer for each netdev
Quoted 40 lines · Jason Wang
Quoted 15 lines · Wen Congyang
Quoted 14 lines · zhanghailiang
Quoted 14 lines
Hi Jason,
Quoted 11 lines · Jason Wang
Quoted 11 lines · zhanghailiang
Quoted 2 lines
Quoted 2 lines
Signed-off-by zhanghailiang <[email protected]>Cc Jason Wang <[email protected]>Commit log please.
Quoted 3 lines
Quoted 3 lines
---
v10: new patch
---[...]
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 8 lines
Quoted 8 lines
net/filter-buffer.c +8
-0+} +/* +* This will be used by COLO or MC FT, for which they will need +* to buffer all the packets of all VM's net devices, Here we check +* and automatically add netfilter for netdev that doesn't attach any buffer +* netfilter. +*/ +void qemu_auto_add_filter_buffer (NetFilterDirection direction,Error **errp)Quoted 8 lines
net/filter-buffer.c void filter_buffer_del_all_timers(void) · line 271
Quoted 8 lines
net/filter-buffer.c +8
-0+{ +char *queue =g_strdup (NetFilterDirection_lookup[direction]); + +qemu_foreach_netdev (netdev_add_filter_buffer, queue, + errp); +g_free (queue); +} +This make me think for following questions:
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
- What if a nic is hot added after this "automatically" filter add?
IIRC, we don't allow the user to hotplug a device when colo is running.
Thanks
Wen CongyangEven in the future? And how could forbid the user to do this, management?
If we allow the user to hotplug a device, we need to auto hotplug the same device in the secondary qemu. It is hard to implement it now.
We can add a new flag(for example: MONITOR_CMD_COLO_UNSUPPORTED), and do the check in handle_user_command() and handle_qmp_command().
Thanks
Wen Congyang
Quoted 4 lines
Thanks
.
Re: [Qemu-devel] [PATCH COLO-Frame v10 35/38] netfilter: Introduce a API to automatically add filter-buffer for each netdev
In reply to zhanghailiangQuoted 164 lines · zhanghailiang
Hi Jason,
Quoted 155 lines · Jason Wang
Quoted 2 lines · zhanghailiang
Signed-off-by zhanghailiang <[email protected]>Cc Jason Wang <[email protected]>Commit log please.
Quoted 136 lines
---
v10: new patch--- include/net/filter.h | 1 + include/net/net.h | 3 ++ net/filter-buffer.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ net/net.c | 20 +++++++++++++ 4 files changed, 108 insertions(+)include/net/filter.h +1
-0@@ -75,5 +75,6 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender, void *opaque);void filter_buffer_release_all (void );void filter_buffer_del_all_timers (void ); +void qemu_auto_add_filter_buffer (NetFilterDirection direction,Error **errp);#endif /* QEMU_NET_FILTER_H */include/net/net.h +3
-0@@ -129,6 +129,9 @@ typedef void (*qemu_netfilter_foreach)(NetFilterState *nf, void *opaque, Error **errp);void qemu_foreach_netfilter (qemu_netfilter_foreach func,void *opaque,Error **errp); +typedef void (*qemu_netdev_foreach )(NetClientState *nc,void *opaque, +Error **errp); +void qemu_foreach_netdev (qemu_netdev_foreach func,void *opaque,Error **errp);int
qemu_can_send_packet(NetClientState *nc);
ssize_tqemu_sendv_packet(NetClientState *nc, const struct iovec
*iov,int iovcnt);net/filter-buffer.c +73
-0@@ -15,6 +15,11 @@#include "qapi-visit.h" #include "qom/object.h" #include "net/net.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp-output-visitor.h" +#include "qapi/qmp-input-visitor.h" +#include "monitor/monitor.h" +#define TYPE_FILTER_BUFFER "filter-buffer"@@ -185,6 +190,85 @@ void filter_buffer_del_all_timers(void)qemu_foreach_netfilter (filter_buffer_del_timer,NULL ,NULL ); } +static void netdev_add_filter_buffer (NetClientState *nc,void *opaque, +Error **errp) +{ +NetFilterState *nf; +bool found = false; + + QTAILQ_FOREACH(nf, &nc->filters, next) { +if (!strcmp (object_get_typename (OBJECT (nf)),TYPE_FILTER_BUFFER )) { + found = true; +break ; + } + } + +if (!found) { +QmpOutputVisitor *qov; +QmpInputVisitor *qiv; +Visitor *ov, *iv; +QObject *obj =NULL ; +QDict *qdict; +void *dummy =NULL ; +char *id =g_strdup_printf ("%s-%s.0" , nc->name,TYPE_FILTER_BUFFER ); +char *queue = (char *) opaque; +bool auto_add = true; +Error *err =NULL ; + + qov =qmp_output_visitor_new (); + ov =qmp_output_get_visitor (qov); +visit_start_struct (ov, &dummy,NULL ,NULL ,0 , &err); +if (err) { + goto out; + } +visit_type_str (ov, &nc->name,"netdev" , &err); +if (err) { + goto out; + } +visit_type_str (ov, &queue,"queue" , &err); +if (err) { + goto out; + } +visit_type_bool (ov, &auto_add,"auto" , &err); +if (err) { + goto out; + } +visit_end_struct (ov, &err); +if (err) { + goto out; + } + obj =qmp_output_get_qobject (qov); +g_assert (obj !=NULL ); + qdict =qobject_to_qdict (obj); +qmp_output_visitor_cleanup (qov); + + qiv =qmp_input_visitor_new (obj); + iv =qmp_input_get_visitor (qiv); +object_add (TYPE_FILTER_BUFFER , id, qdict, iv, &err); +qmp_input_visitor_cleanup (qiv); +qobject_decref (obj); +out: +g_free (id); +if (err) { +error_propagate (errp, err); + } + } +} +/* +* This will be used by COLO or MC FT, for which they will need +* to buffer all the packets of all VM's net devices, Here we check +* and automatically add netfilter for netdev that doesn't attach any buffer
net/filter-buffer.c +3
-0+* netfilter. +*/ +void qemu_auto_add_filter_buffer(NetFilterDirection direction,Error **errp)
net/filter-buffer.c void filter_buffer_del_all_timers(void) · line 271
Quoted 8 lines
net/filter-buffer.c +8
-0+{ +char *queue =g_strdup (NetFilterDirection_lookup[direction]); + +qemu_foreach_netdev (netdev_add_filter_buffer, queue, + errp); +g_free (queue); +} +This make me think for following questions:
Quoted 5 lines
- What if a nic is hot added after this "automatically" filter add?
- Maybe a better way is to have a default filter? It could be specified through qemu cli or other (And default filter could be 'nop' which means no filter) ?
Quoted 4 lines
I have thought about this. I'd like to add this default buffer filter quietly,
not through qemu cli. In this way, we can still keep the buffer filter that configured by users,
Actually, this does not break the ones that added by user. We support attach more than one filters to be attached to a single netdev.
If I understand the case correctly (I was only partially cced in this series). Before each synchronization, you need:
1) add a buffer filter to each netdev
2) release all buffers on demand
3) delete all buffer filters
You can just remove step 1 if you know all device has a default buffer filter. And step 3 could be also removed if you can let buffer filter won't buffer any packet through a new command or other.
Quoted 5 lines
and keep its delay release packets capability. Though the delay time is not what
users suppose. (This is only happened in COLO's periodic mode, in normal colo mode, the delay time
is almost same with user's configure.)
This is not good unless you want to limit the buffer filter only for COLO. And I want also know the role of management: technically it can do all the above 3 steps ( And looks like management was a better place to do this).
Thanks
Quoted 50 lines
What about call
netdev_add_filter_buffer()in each netdev'sinit()? I didn't found a common code path for every netdev in their init path.Thanks,
zhanghailiangQuoted 40 lines
Quoted 34 lines
static void filter_buffer_init(Object *obj) { object_property_add(obj, "interval", "int",net/net.c +20
-0@@ -283,6 +283,26 @@ void qemu_foreach_netfilter(qemu_netfilter_foreach func, void *opaque, } } +void qemu_foreach_netdev(qemu_netdev_foreach func, void *opaque, Error **errp) +{ + NetClientState *nc; + + QTAILQ_FOREACH(nc, &net_clients, next) { +if (nc->info->type ==NET_CLIENT_OPTIONS_KIND_NIC ) { +continue ; + } +if (func) { +Error *local_err =NULL ; + +func (nc, opaque, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + } + } +} +static void qemu_net_client_destructor (NetClientState *nc)Quoted 2 lines
{ g_free(nc);.
Re: [Qemu-devel] [PATCH COLO-Frame v10 35/38] netfilter: Introduce a API to automatically add filter-buffer for each netdev
Quoted 167 lines · Jason Wang
Quoted 164 lines · zhanghailiang
Hi Jason,
Quoted 160 lines · Jason Wang
Quoted 2 lines · zhanghailiang
Signed-off-by zhanghailiang <[email protected]>Cc Jason Wang <[email protected]>Commit log please.
Quoted 136 lines
---
v10: new patch--- include/net/filter.h | 1 + include/net/net.h | 3 ++ net/filter-buffer.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ net/net.c | 20 +++++++++++++ 4 files changed, 108 insertions(+)include/net/filter.h +1
-0@@ -75,5 +75,6 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender, void *opaque);void filter_buffer_release_all (void );void filter_buffer_del_all_timers (void ); +void qemu_auto_add_filter_buffer (NetFilterDirection direction,Error **errp);#endif /* QEMU_NET_FILTER_H */include/net/net.h +3
-0@@ -129,6 +129,9 @@ typedef void (*qemu_netfilter_foreach)(NetFilterState *nf, void *opaque, Error **errp);void qemu_foreach_netfilter (qemu_netfilter_foreach func,void *opaque,Error **errp); +typedef void (*qemu_netdev_foreach )(NetClientState *nc,void *opaque, +Error **errp); +void qemu_foreach_netdev (qemu_netdev_foreach func,void *opaque,Error **errp);int
qemu_can_send_packet(NetClientState *nc);
ssize_tqemu_sendv_packet(NetClientState *nc, const struct iovec
*iov,int iovcnt);net/filter-buffer.c +73
-0@@ -15,6 +15,11 @@#include "qapi-visit.h" #include "qom/object.h" #include "net/net.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp-output-visitor.h" +#include "qapi/qmp-input-visitor.h" +#include "monitor/monitor.h" +#define TYPE_FILTER_BUFFER "filter-buffer"@@ -185,6 +190,85 @@ void filter_buffer_del_all_timers(void)qemu_foreach_netfilter (filter_buffer_del_timer,NULL ,NULL ); } +static void netdev_add_filter_buffer (NetClientState *nc,void *opaque, +Error **errp) +{ +NetFilterState *nf; +bool found = false; + + QTAILQ_FOREACH(nf, &nc->filters, next) { +if (!strcmp (object_get_typename (OBJECT (nf)),TYPE_FILTER_BUFFER )) { + found = true; +break ; + } + } + +if (!found) { +QmpOutputVisitor *qov; +QmpInputVisitor *qiv; +Visitor *ov, *iv; +QObject *obj =NULL ; +QDict *qdict; +void *dummy =NULL ; +char *id =g_strdup_printf ("%s-%s.0" , nc->name,TYPE_FILTER_BUFFER ); +char *queue = (char *) opaque; +bool auto_add = true; +Error *err =NULL ; + + qov =qmp_output_visitor_new (); + ov =qmp_output_get_visitor (qov); +visit_start_struct (ov, &dummy,NULL ,NULL ,0 , &err); +if (err) { + goto out; + } +visit_type_str (ov, &nc->name,"netdev" , &err); +if (err) { + goto out; + } +visit_type_str (ov, &queue,"queue" , &err); +if (err) { + goto out; + } +visit_type_bool (ov, &auto_add,"auto" , &err); +if (err) { + goto out; + } +visit_end_struct (ov, &err); +if (err) { + goto out; + } + obj =qmp_output_get_qobject (qov); +g_assert (obj !=NULL ); + qdict =qobject_to_qdict (obj); +qmp_output_visitor_cleanup (qov); + + qiv =qmp_input_visitor_new (obj); + iv =qmp_input_get_visitor (qiv); +object_add (TYPE_FILTER_BUFFER , id, qdict, iv, &err); +qmp_input_visitor_cleanup (qiv); +qobject_decref (obj); +out: +g_free (id); +if (err) { +error_propagate (errp, err); + } + } +} +/* +* This will be used by COLO or MC FT, for which they will need +* to buffer all the packets of all VM's net devices, Here we check +* and automatically add netfilter for netdev that doesn't attach any buffer
net/filter-buffer.c +3
-0+* netfilter. +*/ +void qemu_auto_add_filter_buffer(NetFilterDirection direction,Error **errp)
net/filter-buffer.c void filter_buffer_del_all_timers(void) · line 271
Quoted 8 lines
net/filter-buffer.c +8
-0+{ +char *queue =g_strdup (NetFilterDirection_lookup[direction]); + +qemu_foreach_netdev (netdev_add_filter_buffer, queue, + errp); +g_free (queue); +} +This make me think for following questions:
- What if a nic is hot added after this "automatically" filter add?
- Maybe a better way is to have a default filter? It could be specified through qemu cli or other (And default filter could be 'nop' which means no filter) ?
Quoted 8 lines
Quoted 4 lines
I have thought about this. I'd like to add this default buffer filter quietly,
not through qemu cli. In this way, we can still keep the buffer filter that configured by users,Actually, this does not break the ones that added by user. We support attach more than one filters to be attached to a single netdev.
Yes, and the packets will go through the default buffer filter before the ones that added by users. We only control the default buffer filter.
Quoted 7 lines
If I understand the case correctly (I was only partially cced in this series). Before each synchronization, you need:
1) add a buffer filter to each netdev
2) release all buffers on demand
3) delete all buffer filters
Actually, for now, we only do step 1) in COLO's init process, and do step 3) while exit COLO.
Quoted 4 lines
You can just remove step 1 if you know all device has a default buffer filter. And step 3 could be also removed if you can let buffer filter won't buffer any packet through a new command or other.
Agreed. We will not let the default buffer filter to buffer any packets, before we go into COLO process.
Quoted 7 lines
Quoted 5 lines
and keep its delay release packets capability. Though the delay time is not what
users suppose. (This is only happened in COLO's periodic mode, in normal colo mode, the delay time
is almost same with user's configure.)This is not good unless you want to limit the buffer filter only for
Er, maybe i didn't describe clearly. I mean the solution of adding default filter buffer will not break the ones that added by users. We only manage the default filter buffer, but the delay time of the buffer filter that added by users will be change :
New delay time = Checkpoint period + configured delay time.
Thanks,
zhanghailiang
Quoted 60 lines
COLO. And I want also know the role of management: technically it can do all the above 3 steps ( And looks like management was a better place to do this).
Thanks
Quoted 50 lines
What about call
netdev_add_filter_buffer()in each netdev'sinit()? I didn't found a common code path for every netdev in their init path.Thanks,
zhanghailiangQuoted 40 lines
Quoted 34 lines
static void filter_buffer_init(Object *obj) { object_property_add(obj, "interval", "int",net/net.c +20
-0@@ -283,6 +283,26 @@ void qemu_foreach_netfilter(qemu_netfilter_foreach func, void *opaque, } } +void qemu_foreach_netdev(qemu_netdev_foreach func, void *opaque, Error **errp) +{ + NetClientState *nc; + + QTAILQ_FOREACH(nc, &net_clients, next) { +if (nc->info->type ==NET_CLIENT_OPTIONS_KIND_NIC ) { +continue ; + } +if (func) { +Error *local_err =NULL ; + +func (nc, opaque, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + } + } +} +static void qemu_net_client_destructor (NetClientState *nc)Quoted 2 lines
{ g_free(nc);.
.
PATCH v10 36/38 netfilter: Introduce an API to delete all the automatically added netfilters
In reply to zhanghailiangWe add a new property 'auto' for netfilter to distinguish if netfilter is added by user or automatically added.
---
v10: new patch
--- include/net/filter.h | 2 ++ net/filter-buffer.c | 17 +++++++++++++++++ net/filter.c | 15 +++++++++++++++ 3 files changed, 34 insertions(+)
include/net/filter.h +2 -0
@@ -55,6 +55,7 @@ struct NetFilterState {char *netdev_id;NetClientState *netdev;NetFilterDirection direction; +bool auto_add;char info_str[256 ];QTAILQ_ENTRY (NetFilterState) next; };
@@ -76,5 +77,6 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender,void filter_buffer_release_all (void );void filter_buffer_del_all_timers (void );void qemu_auto_add_filter_buffer (NetFilterDirection direction,Error **errp); +void qemu_auto_del_filter_buffer (Error **errp);#endif /* QEMU_NET_FILTER_H */
net/filter-buffer.c +17 -0
@@ -19,6 +19,7 @@#include "qapi/qmp-output-visitor.h" #include "qapi/qmp-input-visitor.h" #include "monitor/monitor.h" +#include "qmp-commands.h" #define TYPE_FILTER_BUFFER "filter-buffer"
@@ -269,6 +270,22 @@ void qemu_auto_add_filter_buffer(NetFilterDirection direction, Error **errp)g_free (queue); } +static void netdev_del_filter_buffer (NetFilterState *nf,void *opaque, +Error **errp) +{ +if (!strcmp (object_get_typename (OBJECT (nf)),TYPE_FILTER_BUFFER ) && + nf->auto_add) { +char *id =object_get_canonical_path_component (OBJECT (nf)); + +qmp_object_del (id, errp); + } +} + +void qemu_auto_del_filter_buffer (Error **errp) +{ +qemu_foreach_netfilter (netdev_del_filter_buffer,NULL , errp); +} +static void filter_buffer_init (Object *obj) { object_property_add(obj, "interval", "int",
net/filter.c +15 -0
@@ -117,6 +117,18 @@ static void netfilter_set_direction(Object *obj, int direction, Error **errp) nf->direction = direction; } +static bool netfilter_get_auto_flag (Object *obj,Error **errp) +{ +NetFilterState *nf =NETFILTER (obj); +return nf->auto_add; +} + +static void netfilter_set_auto_flag (Object *obj,bool flag,Error **errp) +{ +NetFilterState *nf =NETFILTER (obj); + nf->auto_add = flag; +} +static void netfilter_init (Object *obj) { object_property_add_str(obj, "netdev",
@@ -126,6 +138,9 @@ static void netfilter_init(Object *obj) NetFilterDirection_lookup, netfilter_get_direction, netfilter_set_direction, NULL); +object_property_add_bool (obj,"auto" , + netfilter_get_auto_flag, netfilter_set_auto_flag, +NULL ); }static void netfilter_complete (UserCreatable *uc,Error **errp)
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH COLO-Frame v10 36/38] netfilter: Introduce an API to delete all the automatically added netfilters
Quoted 77 lines · zhanghailiang
We add a new property 'auto' for netfilter to distinguish if netfilter is added by user or automatically added.
Signed-off-by zhanghailiang <[email protected]>Cc Jason Wang <[email protected]>---
v10: new patch--- include/net/filter.h | 2 ++ net/filter-buffer.c | 17 +++++++++++++++++ net/filter.c | 15 +++++++++++++++ 3 files changed, 34 insertions(+)include/net/filter.h +2
-0@@ -55,6 +55,7 @@ struct NetFilterState {char *netdev_id;NetClientState *netdev;NetFilterDirection direction; +bool auto_add;char info_str[256 ];QTAILQ_ENTRY (NetFilterState) next; };@@ -76,5 +77,6 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender,void filter_buffer_release_all (void );void filter_buffer_del_all_timers (void );void qemu_auto_add_filter_buffer (NetFilterDirection direction,Error **errp); +void qemu_auto_del_filter_buffer (Error **errp);#endif /* QEMU_NET_FILTER_H */ net/filter-buffer.c +17
-0@@ -19,6 +19,7 @@#include "qapi/qmp-output-visitor.h" #include "qapi/qmp-input-visitor.h" #include "monitor/monitor.h" +#include "qmp-commands.h" #define TYPE_FILTER_BUFFER "filter-buffer"@@ -269,6 +270,22 @@ void qemu_auto_add_filter_buffer(NetFilterDirection direction, Error **errp)g_free (queue); } +static void netdev_del_filter_buffer (NetFilterState *nf,void *opaque, +Error **errp) +{ +if (!strcmp (object_get_typename (OBJECT (nf)),TYPE_FILTER_BUFFER ) && + nf->auto_add) { +char *id =object_get_canonical_path_component (OBJECT (nf)); + +qmp_object_del (id, errp); + } +} + +void qemu_auto_del_filter_buffer (Error **errp) +{ +qemu_foreach_netfilter (netdev_del_filter_buffer,NULL , errp); +} +static void filter_buffer_init (Object *obj) { object_property_add(obj, "interval", "int",net/filter.c +2
-0@@ -117,6 +117,18 @@ static void netfilter_set_direction(Object *obj, int direction, Error **errp) nf->direction = direction; } +static bool netfilter_get_auto_flag (Object *obj,Error **errp) +{
net/filter.c static void netfilter_set_direction(Object *obj, int direction, Error **errp) · line 131
Quoted 10 lines
net/filter.c +10
-0+NetFilterState *nf =NETFILTER (obj); +return nf->auto_add; +} + +static void netfilter_set_auto_flag (Object *obj,bool flag,Error **errp) +{ +NetFilterState *nf =NETFILTER (obj); + nf->auto_add = flag; +} +
This chunk of code should be in previous patch.
net/filter.c static void netfilter_init(Object *obj) · line 144
Quoted 11 lines
net/filter.c +3
-0static void netfilter_init (Object *obj) { object_property_add_str(obj, "netdev",@@ -126,6 +138,9 @@ static void netfilter_init(Object *obj) NetFilterDirection_lookup, netfilter_get_direction, netfilter_set_direction, NULL); +object_property_add_bool (obj,"auto" , + netfilter_get_auto_flag, netfilter_set_auto_flag, +NULL ); }
Ditto.
Quoted 3 lines
net/filter.c +0
-0static void netfilter_complete (UserCreatable *uc,Error **errp)
Signature · 2 lines
Thanks, Yang
PATCH v10 37/38 colo: Use the netfilter to buffer and release packets
In reply to zhanghailiang---
v10: Use the new API
--- migration/colo.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
migration/colo.c +29 -0
@@ -21,6 +21,8 @@#include "qapi-event.h" #include "qmp-commands.h" #include "qapi-types.h" +#include "net/filter.h" +#include "net/net.h" /* * The delay time before qemu begin the procedure of default failover treatment.
@@ -59,6 +61,24 @@ static bool colo_runstate_is_stopped(void)return runstate_check (RUN_STATE_COLO ) || !runstate_is_running (); } +static int colo_init_filter_buffers (void ) +{ +Error *local_err =NULL ; + +qemu_auto_add_filter_buffer (NET_FILTER_DIRECTION_RX , &local_err); +if (local_err) { +error_report_err (local_err); +return -1 ; + } +filter_buffer_del_all_timers (); +return 0 ; +} + +static void colo_cleanup_filter_buffers (void ) +{ +qemu_auto_del_filter_buffer (NULL ); +} +static void secondary_vm_do_failover (void ) {int old_state;
@@ -123,6 +143,7 @@ static void primary_vm_do_failover(void)if (s->to_dst_file) {qemu_file_shutdown (s->to_dst_file); } +colo_cleanup_filter_buffers ();vm_start ();
@@ -291,6 +312,8 @@ static int colo_do_checkpoint_transaction(MigrationState *s, goto out; } +filter_buffer_release_all (); +if (colo_shutdown) {colo_ctl_put (s->to_dst_file,COLO_COMMAND_GUEST_SHUTDOWN ,0 );qemu_fflush (s->to_dst_file);
@@ -339,6 +362,12 @@ static void colo_process_checkpoint(MigrationState *s)failover_init_state (); + ret =colo_init_filter_buffers (); +if (ret <0 ) { + ret = -EINVAL ; + goto out; + } +/* Dup the fd of to_dst_file */ fd =dup (qemu_get_fd (s->to_dst_file));if (fd ==-1 ) {
Signature · 1 line
1.8.3.1
PATCH v10 38/38 COLO: Add block replication into colo process
In reply to zhanghailiangMake sure master start block replication after slave's block replication started.
--- migration/colo.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++- migration/migration.c | 10 --------- trace-events | 2 ++ 3 files changed, 63 insertions(+), 11 deletions(-)
migration/colo.c +61 -1
@@ -23,6 +23,7 @@#include "qapi-types.h" #include "net/filter.h" #include "net/net.h" +#include "block/block_int.h" /* * The delay time before qemu begin the procedure of default failover treatment.
@@ -83,6 +84,7 @@ static void secondary_vm_do_failover(void) {int old_state;MigrationIncomingState *mis =migration_incoming_get_current (); +Error *local_err =NULL ;/* Can not do failover during the process of VM's loading VMstate, Or * it will break the secondary VM.
@@ -100,6 +102,12 @@ static void secondary_vm_do_failover(void)migrate_set_state (&mis->state,MIGRATION_STATUS_COLO ,MIGRATION_STATUS_COMPLETED ); +bdrv_stop_replication_all (true, &local_err); +if (local_err) { +error_report_err (local_err); + } +trace_colo_stop_block_replication ("failover" ); +if (!autostart) {error_report ("\"-S\" qemu option will be ignored in secondary side" );/* recover runstate to normal migration finish state */
@@ -130,6 +138,7 @@ static void primary_vm_do_failover(void) {MigrationState *s =migrate_get_current ();int old_state; +Error *local_err =NULL ;if (s->state !=MIGRATION_STATUS_FAILED ) { migrate_set_state(&s->state, MIGRATION_STATUS_COLO,
@@ -145,6 +154,12 @@ static void primary_vm_do_failover(void) }colo_cleanup_filter_buffers (); +bdrv_stop_replication_all (true, &local_err); +if (local_err) { +error_report_err (local_err); + } +trace_colo_stop_block_replication ("failover" ); +vm_start (); old_state = failover_set_state(FAILOVER_STATUS_HANDLING,
@@ -234,6 +249,7 @@ static int colo_do_checkpoint_transaction(MigrationState *s,int colo_shutdown, ret;size_t size;QEMUFile *trans =NULL ; +Error *local_err =NULL ; ret =colo_ctl_put (s->to_dst_file,COLO_COMMAND_CHECKPOINT_REQUEST ,0 );if (ret <0 ) {
@@ -271,6 +287,16 @@ static int colo_do_checkpoint_transaction(MigrationState *s, goto out; } +/* we call this api although this may do nothing on primary side */ +qemu_mutex_lock_iothread (); +bdrv_do_checkpoint_all (&local_err); +qemu_mutex_unlock_iothread (); +if (local_err) { +error_report_err (local_err); + ret =-1 ; + goto out; + } + ret =colo_ctl_put (s->to_dst_file,COLO_COMMAND_VMSTATE_SEND ,0 );if (ret <0 ) { goto out;
@@ -315,6 +341,10 @@ static int colo_do_checkpoint_transaction(MigrationState *s,filter_buffer_release_all ();if (colo_shutdown) { +qemu_mutex_lock_iothread (); +bdrv_stop_replication_all (false,NULL ); +trace_colo_stop_block_replication ("shutdown" ); +qemu_mutex_unlock_iothread ();colo_ctl_put (s->to_dst_file,COLO_COMMAND_GUEST_SHUTDOWN ,0 );qemu_fflush (s->to_dst_file); colo_shutdown_requested =0 ;
@@ -359,6 +389,7 @@ static void colo_process_checkpoint(MigrationState *s)int64_t current_time, checkpoint_time =qemu_clock_get_ms (QEMU_CLOCK_HOST );int64_t error_time;int fd, ret =0 ; +Error *local_err =NULL ;failover_init_state ();
@@ -403,6 +434,15 @@ static void colo_process_checkpoint(MigrationState *s) }qemu_mutex_lock_iothread (); +/* start block replication */ +bdrv_start_replication_all (REPLICATION_MODE_PRIMARY , &local_err); +if (local_err) { +qemu_mutex_unlock_iothread (); +error_report_err (local_err); + ret = -EINVAL ; + goto out; + } +trace_colo_start_block_replication ();vm_start ();qemu_mutex_unlock_iothread ();trace_colo_vm_state_change ("stop" ,"run" );
@@ -514,6 +554,8 @@ static int colo_wait_handle_cmd(QEMUFile *f, int *checkpoint_request)case COLO_COMMAND_GUEST_SHUTDOWN :qemu_mutex_lock_iothread ();vm_stop_force_state (RUN_STATE_COLO ); +bdrv_stop_replication_all (false,NULL ); +trace_colo_stop_block_replication ("shutdown" );qemu_system_shutdown_request_core ();qemu_mutex_unlock_iothread ();/* the main thread will exit and termiante the whole
@@ -545,6 +587,7 @@ void *colo_process_incoming_thread(void *opaque)int total_size;int64_t error_time, current_time;int fd, ret =0 ; +Error *local_err =NULL ;migrate_set_state (&mis->state,MIGRATION_STATUS_ACTIVE ,MIGRATION_STATUS_COLO );
@@ -580,6 +623,16 @@ void *colo_process_incoming_thread(void *opaque) goto out; } +qemu_mutex_lock_iothread (); +/* start block replication */ +bdrv_start_replication_all (REPLICATION_MODE_SECONDARY , &local_err); +qemu_mutex_unlock_iothread (); +if (local_err) { +error_report_err (local_err); + goto out; + } +trace_colo_start_block_replication (); + ret =colo_ctl_put (mis->to_src_file,COLO_COMMAND_CHECKPOINT_READY ,0 );if (ret <0 ) { goto out;
@@ -655,8 +708,15 @@ void *colo_process_incoming_thread(void *opaque) goto out; } - vmstate_loading = false; +/* discard colo disk buffer */ +bdrv_do_checkpoint_all (&local_err);qemu_mutex_unlock_iothread (); +if (local_err) { + vmstate_loading = false; + goto out; + } + + vmstate_loading = false;if (failover_get_state () ==FAILOVER_STATUS_RELAUNCH ) {failover_set_state (FAILOVER_STATUS_RELAUNCH ,FAILOVER_STATUS_NONE );
migration/migration.c +0 -10
@@ -328,16 +328,6 @@ static void process_incoming_migration_co(void *opaque)exit (EXIT_FAILURE ); } -/* Make sure all file formats flush their mutable metadata */ -bdrv_invalidate_cache_all (&local_err); -if (local_err) { -migrate_set_state (&mis->state,MIGRATION_STATUS_ACTIVE , -MIGRATION_STATUS_FAILED ); -error_report_err (local_err); -migrate_decompress_threads_join (); -exit (EXIT_FAILURE ); - } -/* * This must happen after all error conditions are dealt with and * we're sure the VM is going to be running on this host.
trace-events +2 -0
@@ -1503,6 +1503,8 @@ colo_vm_state_change(const char *old, const char *new) "Change '%s' => '%s'" colo_ctl_put(const char *msg, uint64_t value) "Send '%s' cmd, value: %" PRIu64"" colo_ctl_get(const char *msg) "Receive '%s' cmd" colo_failover_set_state(int new_state) "new state %d" +colo_start_block_replication(void) "Block replication is started" +colo_stop_block_replication(const char *reason) "Block replication is stopped(reason: '%s')" # kvm-all.c kvm_ioctl(int type, void *arg) "type 0x%x, arg %p"
Signature · 1 line
1.8.3.1