COarse-grain LOck-stepping Virtual Machines for Non-stop Service
v4 cover COarse-grain LOck-stepping Virtual Machines for Non-stop Service
This patchset is not for xen-4.5, so I will stop to update it until xen 4.5 is released.
Virtual machine (VM) replication is a well known technique for providing application-agnostic software-implemented hardware fault tolerance - "non-stop service". Currently, remus provides this function, but it buffers all output packets, and the latency is unacceptable.
In xen summit 2012, We introduce a new VM replication solution: colo (COarse-grain LOck-stepping virtual machine). The presentation is in the following URL:
http://www.slideshare.net/xen_com_mgr/colo-coarsegrain-lockstepping-virtual-machines-for-nonstop-service
Here is the summary of the solution:
Quoted 1 line
From the client's point of view, as long as the client observes identical
responses from the primary and secondary VMs, according to the service semantics, then the secondary vm is a valid replica of the primary vm, and can successfully take over when a hardware failure of the primary vm is detected.
This patchset is RFC, and implements the framework and disk replication of COLO:
1. Both primary vm and secondary vm are running
2. do checkoint
3. disk replication(use blktap2)
3. nic replication(use colo-agent)
This patchset is based on bugfix, and colo-prepare patchset, and use migration v1. Only supports hvm guest now. The codes are also hosted on github:
https://github.com/wencongyang/xen/tree/colo-v4
TODO list:
1. Use migration v2 to implement COLO
2. support pvm
Known bugs:
1. Secondary vm may crash due to triple fault.
Usage:
1. update the vm's configfile:
disk:
disk = [ 'format=raw,devtype=disk,access=w,vdev=hda,backendtype=tap,filter=colo,filter-params=192.168.3.1:9000,target=/root/images/hvm/hvm_nopv/hvm.img' ]
nic:
vif = [ 'mac=00:16:4f:00:00:11, bridge=br0, model=e1000, forwarddev=eth0' ] Note: the forwarddev of primary and secondary host should be connected directly, and no other app uses it. If you don't have such nic, you can use vlan to make it.
2. build colo-agent:
You can get colo-agent from github:
https://github.com/wencongyang/colo-agent
3. run:
xl remus -c -u <domname> <secondary host IP>
Patch 1-4 : update remus to reuse remus device codes Patch 5-13 : COLO framework related codes
Patch 14 : implement block-colo
Patch 15 : implement disk replication
Patch 16-18: implement nic replication
Patch 19 : A patch for qemu-xen
Change from v3 to v4:
1. rebase to newest xen
2. bug fix
Changlog from v2 to v3:
1. rebase to newest remus
2. add nic replication support
Changlog from v1 to v2:
1. rebase to newest remus
2. add disk replication support
Wen Congyang (18):
move remus related codes to libxl_remus.c
rename remus device to checkpoint device
adjust the indentation
don't touch remus in checkpoint_device
Update libxl_save_msgs_gen.pl to support return data from xl to xc Allow slave sends data to master
secondary vm suspend/resume/checkpoint code
primary vm suspend/get_dirty_pfn/resume/checkpoint code
xc_domain_save: flush cache before calling callbacks->postcopy() in
colo mode
COLO: xc related codes
send store mfn and console mfn to xl before resuming secondary vm implement the cmdline for COLO
tools: xc_doamin_restore: zero ioreq page only one time
block-colo: implement colo disk replication
libxl/colo: setup and control disk replication for blktap2 backends setup and control colo-agent for primary vm
setup and control colo-agent for secondary vm
colo: cmdline switches and config vars to control colo-agent
.gitignore | 1 +
docs/man/xl.conf.pod.5 | 6 +
docs/man/xl.pod.1 | 12 +-
tools/blktap2/drivers/Makefile | 3 +
tools/blktap2/drivers/block-colo.c | 1132 ++++++++++++++++++++
tools/blktap2/drivers/block-remus.c | 4 +-
tools/blktap2/drivers/block-replication.c | 262 ++++-
tools/blktap2/drivers/block-replication.h | 77 +-
tools/blktap2/drivers/tapdisk-disktype.c | 9 +
tools/blktap2/drivers/tapdisk-disktype.h | 3 +-
tools/hotplug/Linux/Makefile | 2 +
tools/hotplug/Linux/colo-agent-setup | 210 ++++
tools/hotplug/Linux/remus-netbuf-setup | 45 +-
tools/hotplug/Linux/xen-network-ft.sh | 102 ++
tools/libxc/include/xenguest.h | 40 +
tools/libxc/xc_domain_restore.c | 106 +-
tools/libxc/xc_domain_save.c | 63 +-
tools/libxl/Makefile | 11 +-
tools/libxl/colo-tc.c | 589 ++++++++++
tools/libxl/libxl.c | 85 +-
...xl_remus_device.c => libxl_checkpoint_device.c} | 233 ++--
tools/libxl/libxl_colo.h | 48 +
tools/libxl/libxl_colo_nic.c | 312 ++++++
tools/libxl/libxl_colo_restore.c | 1003 +++++++++++++++++
tools/libxl/libxl_colo_save.c | 809 ++++++++++++++
tools/libxl/libxl_colo_save_disk_blktap2.c | 219 ++++
tools/libxl/libxl_create.c | 152 ++-
tools/libxl/libxl_dom.c | 234 +---
tools/libxl/libxl_internal.h | 218 ++--
tools/libxl/libxl_netbuffer.c | 117 +-
tools/libxl/libxl_noblktap2.c | 29 +
tools/libxl/libxl_nonetbuffer.c | 10 +-
tools/libxl/libxl_remus.c | 373 +++++++
tools/libxl/libxl_remus.h | 27 +
tools/libxl/libxl_remus_disk_drbd.c | 57 +-
tools/libxl/libxl_save_callout.c | 37 +-
tools/libxl/libxl_save_helper.c | 17 +
tools/libxl/libxl_save_msgs_gen.pl | 74 +-
tools/libxl/libxl_types.idl | 14 +-
tools/libxl/xl.c | 3 +
tools/libxl/xl.h | 1 +
tools/libxl/xl_cmdimpl.c | 100 +-
tools/libxl/xl_cmdtable.c | 4 +-
43 files changed, 6164 insertions(+), 689 deletions(-)
create mode 100644 tools/blktap2/drivers/block-colo.c
create mode 100755 tools/hotplug/Linux/colo-agent-setup
create mode 100644 tools/hotplug/Linux/xen-network-ft.sh
create mode 100644 tools/libxl/colo-tc.c
rename tools/libxl/{libxl_remus_device.c => libxl_checkpoint_device.c} (47%)
create mode 100644 tools/libxl/libxl_colo.h
create mode 100644 tools/libxl/libxl_colo_nic.c
create mode 100644 tools/libxl/libxl_colo_restore.c
create mode 100644 tools/libxl/libxl_colo_save.c
create mode 100644 tools/libxl/libxl_colo_save_disk_blktap2.c
create mode 100644 tools/libxl/libxl_remus.c
create mode 100644 tools/libxl/libxl_remus.hSignature · 1 line
1.9.3
[Qemu-devel] [PATCH 19/18] Introduce "xen-load-devices-state"
Introduce a "xen-load-devices-state" QAPI command that can be used to load the state of all devices, but not the RAM or the block devices of the VM.
We only have hmp commands savevm/loadvm, and qmp commands xen-save-devices-state.
We use this new command for COLO:
1. suspend both primay vm and secondary vm
2. sync the state
3. resume both primary vm and secondary vm
In such case, we need to update all devices's state in any time.
--- qapi-schema.json | 18 ++++++++++++++++++ qmp-commands.hx | 27 +++++++++++++++++++++++++++ savevm.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+)
qapi-schema.json +18 -0
@@ -4689,3 +4689,21 @@ 'btn' : 'InputBtnEvent', 'rel' : 'InputMoveEvent', 'abs' : 'InputMoveEvent' } } + +## +# @xen-load-devices-state: +# +# Load the state of all devices from file. The RAM and the block devices +# of the VM are not loaded by this command. +# +# @filename: the file to load the state of the devices from as binary +# data. See xen-save-devices-state.txt for a description of the binary +# format. +# +# Returns: Nothing on success +# If @filename cannot be opened, OpenFileFailed +# If an I/O error occurs while reading the file, IOError +# +# Since: 2.0 +## +{ 'command': 'xen-load-devices-state', 'data': {'filename': 'str'} }
qmp-commands.hx +27 -0
@@ -586,6 +586,33 @@ Example: EQMP { + .name = "xen-load-devices-state", + .args_type = "filename:F", + .mhandler.cmd_new = qmp_marshal_input_xen_load_devices_state, + }, + +SQMP +xen-load-devices-state +------- + +Load the state of all devices from file. The RAM and the block devices +of the VM are not loaded by this command. + +Arguments: + +- "filename": the file to load the state of the devices from as binary +data. See xen-save-devices-state.txt for a description of the binary +format. + +Example: + +-> { "execute": "xen-load-devices-state", + "arguments": { "filename": "/tmp/resume" } } +<- { "return": {} } + +EQMP + + { .name = "xen-set-global-dirty-log", .args_type = "enable:b", .mhandler.cmd_new = qmp_marshal_input_xen_set_global_dirty_log,
savevm.c +36 -0
@@ -41,6 +41,7 @@#include "qemu/iov.h" #include "block/snapshot.h" #include "block/qapi.h" +#include "hw/xen/xen.h" #define SELF_ANNOUNCE_ROUNDS 5
@@ -802,6 +803,14 @@ int qemu_loadvm_state(QEMUFile *f) goto out; } +/* Validate if it is a device's state */ +if (xen_enabled () && se->is_ram) { +fprintf (stderr,"loadvm: %s RAM loading not allowed on Xen\n" , + idstr); + ret = -EINVAL ; + goto out; + } +/* Add entry */ le =g_malloc0 (sizeof (*le));
@@ -1027,6 +1036,33 @@ void qmp_xen_save_devices_state(const char *filename, Error **errp) } } +void qmp_xen_load_devices_state (const char *filename,Error **errp) +{ +QEMUFile *f; +int saved_vm_running; +int ret; + + saved_vm_running =runstate_is_running (); +vm_stop (RUN_STATE_RESTORE_VM ); + + f =qemu_fopen (filename,"rb" ); +if (!f) { +error_setg_file_open (errp, errno, filename); + goto out; + } + + ret =qemu_loadvm_state (f); +qemu_fclose (f); +if (ret <0 ) { +error_set (errp,QERR_IO_ERROR ); + } + +out: +if (saved_vm_running) { +vm_start (); + } +} +int load_vmstate (const char *name) {BlockDriverState *bs, *bs_vm_state;
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH 19/18] Introduce "xen-load-devices-state"
Quoted 25 lines · Wen Congyang
Introduce a "xen-load-devices-state" QAPI command that can be used to load the state of all devices, but not the RAM or the block devices of the VM.
We only have hmp commands savevm/loadvm, and qmp commands xen-save-devices-state.
We use this new command for COLO:
1. suspend both primay vm and secondary vm
2. sync the state
3. resume both primary vm and secondary vmIn such case, we need to update all devices's state in any time.
Signed-off-by Wen Congyang <[email protected]>Cc qemu-devl <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Paolo Bonzini <[email protected]>--- qapi-schema.json | 18 ++++++++++++++++++ qmp-commands.hx | 27 +++++++++++++++++++++++++++ savevm.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+)
qapi-schema.json line 4709
Quoted 4 lines
qapi-schema.json +4
-0+# +# Since: 2.0 +## +{ 'command': 'xen-load-devices-state', 'data': {'filename': 'str'} }
s/2.0/2.2/ - if you even get it in 2.2 (haven't we already passed soft freeze, but this is a feature addition?)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [Qemu-devel] [PATCH 19/18] Introduce "xen-load-devices-state"
Quoted 26 lines · Eric Blake
Quoted 24 lines · Wen Congyang
Introduce a "xen-load-devices-state" QAPI command that can be used to load the state of all devices, but not the RAM or the block devices of the VM.
We only have hmp commands savevm/loadvm, and qmp commands xen-save-devices-state.
We use this new command for COLO:
1. suspend both primay vm and secondary vm
2. sync the state
3. resume both primary vm and secondary vmIn such case, we need to update all devices's state in any time.
Signed-off-by Wen Congyang <[email protected]>Cc qemu-devl <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Paolo Bonzini <[email protected]>--- qapi-schema.json | 18 ++++++++++++++++++ qmp-commands.hx | 27 +++++++++++++++++++++++++++ savevm.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+)
Quoted 8 lines
qapi-schema.json line 4709
Quoted 4 lines
qapi-schema.json +4
-0+# +# Since: 2.0 +## +{ 'command': 'xen-load-devices-state', 'data': {'filename': 'str'} }s/2.0/2.2/ - if you even get it in 2.2 (haven't we already passed soft freeze, but this is a feature addition?)
I forgot to update it. I will update it in the next version. But this qmp command is for COLO, so I don't post the next version until xen-4.5 is released.
Thanks
Wen Congyang
Re: [Qemu-devel] [PATCH 19/18] Introduce "xen-load-devices-state"
In reply to Eric BlakeQuoted 26 lines · Eric Blake
Quoted 24 lines · Wen Congyang
Introduce a "xen-load-devices-state" QAPI command that can be used to load the state of all devices, but not the RAM or the block devices of the VM.
We only have hmp commands savevm/loadvm, and qmp commands xen-save-devices-state.
We use this new command for COLO:
1. suspend both primay vm and secondary vm
2. sync the state
3. resume both primary vm and secondary vmIn such case, we need to update all devices's state in any time.
Signed-off-by Wen Congyang <[email protected]>Cc qemu-devl <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Paolo Bonzini <[email protected]>--- qapi-schema.json | 18 ++++++++++++++++++ qmp-commands.hx | 27 +++++++++++++++++++++++++++ savevm.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+)
Quoted 8 lines
qapi-schema.json line 4709
Quoted 4 lines
qapi-schema.json +4
-0+# +# Since: 2.0 +## +{ 'command': 'xen-load-devices-state', 'data': {'filename': 'str'} }s/2.0/2.2/ - if you even get it in 2.2 (haven't we already passed soft freeze, but this is a feature addition?)
I forgot to update it. I will update it in the next version. But this qmp command is for COLO, so I don't post the next version until xen-4.5 is released.
Thanks
Wen Congyang
Re: [Qemu-devel] [PATCH 19/18] Introduce "xen-load-devices-state"
In reply to Wen CongyangQuoted 12 lines · Wen Congyang
Introduce a "xen-load-devices-state" QAPI command that can be used to load the state of all devices, but not the RAM or the block devices of the VM.
We only have hmp commands savevm/loadvm, and qmp commands xen-save-devices-state.
We use this new command for COLO:
1. suspend both primay vm and secondary vm
2. sync the state
3. resume both primary vm and secondary vm
Quoted 6 lines
In such case, we need to update all devices's state in any time.
Signed-off-by Wen Congyang <[email protected]>Cc qemu-devl <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Paolo Bonzini <[email protected]>
The patch looks OK to me, far better than the previous version, but I am no QMP expert.
Quoted 134 lines
qapi-schema.json | 18 ++++++++++++++++++ qmp-commands.hx | 27 +++++++++++++++++++++++++++ savevm.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+)qapi-schema.json +18
-0@@ -4689,3 +4689,21 @@ 'btn' : 'InputBtnEvent', 'rel' : 'InputMoveEvent', 'abs' : 'InputMoveEvent' } } + +## +# @xen-load-devices-state: +# +# Load the state of all devices from file. The RAM and the block devices +# of the VM are not loaded by this command. +# +# @filename: the file to load the state of the devices from as binary +# data. See xen-save-devices-state.txt for a description of the binary +# format. +# +# Returns: Nothing on success +# If @filename cannot be opened, OpenFileFailed +# If an I/O error occurs while reading the file, IOError +# +# Since: 2.0 +## +{ 'command': 'xen-load-devices-state', 'data': {'filename': 'str'} }qmp-commands.hx +27
-0@@ -586,6 +586,33 @@ Example: EQMP { + .name = "xen-load-devices-state", + .args_type = "filename:F", + .mhandler.cmd_new = qmp_marshal_input_xen_load_devices_state, + }, + +SQMP +xen-load-devices-state +------- + +Load the state of all devices from file. The RAM and the block devices +of the VM are not loaded by this command. + +Arguments: + +- "filename": the file to load the state of the devices from as binary +data. See xen-save-devices-state.txt for a description of the binary +format. + +Example: + +-> { "execute": "xen-load-devices-state", + "arguments": { "filename": "/tmp/resume" } } +<- { "return": {} } + +EQMP + + { .name = "xen-set-global-dirty-log", .args_type = "enable:b", .mhandler.cmd_new = qmp_marshal_input_xen_set_global_dirty_log,savevm.c +36
-0@@ -41,6 +41,7 @@#include "qemu/iov.h" #include "block/snapshot.h" #include "block/qapi.h" +#include "hw/xen/xen.h" #define SELF_ANNOUNCE_ROUNDS 5@@ -802,6 +803,14 @@ int qemu_loadvm_state(QEMUFile *f) goto out; } +/* Validate if it is a device's state */ +if (xen_enabled () && se->is_ram) { +fprintf (stderr,"loadvm: %s RAM loading not allowed on Xen\n" , + idstr); + ret = -EINVAL ; + goto out; + } +/* Add entry */ le =g_malloc0 (sizeof (*le));@@ -1027,6 +1036,33 @@ void qmp_xen_save_devices_state(const char *filename, Error **errp) } } +void qmp_xen_load_devices_state (const char *filename,Error **errp) +{ +QEMUFile *f; +int saved_vm_running; +int ret; + + saved_vm_running =runstate_is_running (); +vm_stop (RUN_STATE_RESTORE_VM ); + + f =qemu_fopen (filename,"rb" ); +if (!f) { +error_setg_file_open (errp, errno, filename); + goto out; + } + + ret =qemu_loadvm_state (f); +qemu_fclose (f); +if (ret <0 ) { +error_set (errp,QERR_IO_ERROR ); + } + +out: +if (saved_vm_running) { +vm_start (); + } +} +int load_vmstate (const char *name) {BlockDriverState *bs, *bs_vm_state;Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH 19/18] Introduce "xen-load-devices-state"
In reply to Wen CongyangQuoted 12 lines · Wen Congyang
Introduce a "xen-load-devices-state" QAPI command that can be used to load the state of all devices, but not the RAM or the block devices of the VM.
We only have hmp commands savevm/loadvm, and qmp commands xen-save-devices-state.
We use this new command for COLO:
1. suspend both primay vm and secondary vm
2. sync the state
3. resume both primary vm and secondary vm
Quoted 6 lines
In such case, we need to update all devices's state in any time.
Signed-off-by Wen Congyang <[email protected]>Cc qemu-devl <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Paolo Bonzini <[email protected]>
The patch looks OK to me, far better than the previous version, but I am no QMP expert.
Quoted 134 lines
qapi-schema.json | 18 ++++++++++++++++++ qmp-commands.hx | 27 +++++++++++++++++++++++++++ savevm.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+)qapi-schema.json +18
-0@@ -4689,3 +4689,21 @@ 'btn' : 'InputBtnEvent', 'rel' : 'InputMoveEvent', 'abs' : 'InputMoveEvent' } } + +## +# @xen-load-devices-state: +# +# Load the state of all devices from file. The RAM and the block devices +# of the VM are not loaded by this command. +# +# @filename: the file to load the state of the devices from as binary +# data. See xen-save-devices-state.txt for a description of the binary +# format. +# +# Returns: Nothing on success +# If @filename cannot be opened, OpenFileFailed +# If an I/O error occurs while reading the file, IOError +# +# Since: 2.0 +## +{ 'command': 'xen-load-devices-state', 'data': {'filename': 'str'} }qmp-commands.hx +27
-0@@ -586,6 +586,33 @@ Example: EQMP { + .name = "xen-load-devices-state", + .args_type = "filename:F", + .mhandler.cmd_new = qmp_marshal_input_xen_load_devices_state, + }, + +SQMP +xen-load-devices-state +------- + +Load the state of all devices from file. The RAM and the block devices +of the VM are not loaded by this command. + +Arguments: + +- "filename": the file to load the state of the devices from as binary +data. See xen-save-devices-state.txt for a description of the binary +format. + +Example: + +-> { "execute": "xen-load-devices-state", + "arguments": { "filename": "/tmp/resume" } } +<- { "return": {} } + +EQMP + + { .name = "xen-set-global-dirty-log", .args_type = "enable:b", .mhandler.cmd_new = qmp_marshal_input_xen_set_global_dirty_log,savevm.c +36
-0@@ -41,6 +41,7 @@#include "qemu/iov.h" #include "block/snapshot.h" #include "block/qapi.h" +#include "hw/xen/xen.h" #define SELF_ANNOUNCE_ROUNDS 5@@ -802,6 +803,14 @@ int qemu_loadvm_state(QEMUFile *f) goto out; } +/* Validate if it is a device's state */ +if (xen_enabled () && se->is_ram) { +fprintf (stderr,"loadvm: %s RAM loading not allowed on Xen\n" , + idstr); + ret = -EINVAL ; + goto out; + } +/* Add entry */ le =g_malloc0 (sizeof (*le));@@ -1027,6 +1036,33 @@ void qmp_xen_save_devices_state(const char *filename, Error **errp) } } +void qmp_xen_load_devices_state (const char *filename,Error **errp) +{ +QEMUFile *f; +int saved_vm_running; +int ret; + + saved_vm_running =runstate_is_running (); +vm_stop (RUN_STATE_RESTORE_VM ); + + f =qemu_fopen (filename,"rb" ); +if (!f) { +error_setg_file_open (errp, errno, filename); + goto out; + } + + ret =qemu_loadvm_state (f); +qemu_fclose (f); +if (ret <0 ) { +error_set (errp,QERR_IO_ERROR ); + } + +out: +if (saved_vm_running) { +vm_start (); + } +} +int load_vmstate (const char *name) {BlockDriverState *bs, *bs_vm_state;Signature · 1 line
1.9.3
RFC PATCH v4 1/18 move remus related codes to libxl_remus.c
In reply to Wen Congyanglibxl_domain_remus_start() is external API, and is not moved.
--- tools/libxl/Makefile | 2 +- tools/libxl/libxl.c | 57 +-------- tools/libxl/libxl_dom.c | 220 +------------------------------- tools/libxl/libxl_remus.c | 318 ++++++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_remus.h | 28 ++++ 5 files changed, 352 insertions(+), 273 deletions(-) create mode 100644 tools/libxl/libxl_remus.c create mode 100644 tools/libxl/libxl_remus.h
tools/libxl/Makefile +1 -1
@@ -56,7 +56,7 @@ else LIBXL_OBJS-y += libxl_nonetbuffer.o endif -LIBXL_OBJS-y += libxl_remus_device.o libxl_remus_disk_drbd.o +LIBXL_OBJS-y += libxl_remus.o libxl_remus_device.o libxl_remus_disk_drbd.o LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o libxl_psr.o LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o
tools/libxl/libxl.c +2 -55
82 lines not on this page · raw message
tools/libxl/libxl_dom.c +3 -217
247 lines not on this page · raw message
tools/libxl/libxl_remus.c new file +318 -0
318 lines not on this page · raw message
tools/libxl/libxl_remus.h new file +28 -0
@@ -0,0 +1,28 @@ +/* +* Copyright (C) 2014 FUJITSU LIMITED +* Author Wen Congyang <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License as published +* by the Free Software Foundation; version 2.1 only. with the special +* exception on linking described in file LICENSE. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +*/ + +#ifndef LIBXL_REMUS_H +#define LIBXL_REMUS_H + +void libxl__remus_setup (libxl__egc *egc, +libxl__domain_suspend_state *dss); +void libxl__remus_teardown (libxl__egc *egc, +libxl__domain_suspend_state *dss, +int rc); +void libxl__remus_domain_suspend_callback (void *data); +void libxl__remus_domain_resume_callback (void *data); +void libxl__remus_domain_checkpoint_callback (void *data); + +#endif
Signature · 1 line
1.9.3
RFC PATCH v4 2/18 rename remus device to checkpoint device
In reply to Wen CongyangThis patch is auto generated by the following commands:
1. git mv tools/libxl/libxl_remus_device.c tools/libxl/libxl_checkpoint_device.c
2. perl -pi -e 's/libxl_remus_device/libxl_checkpoint_device/g' tools/libxl/Makefile
3. perl -pi -e 's/\blibxl__remus_devices/libxl__checkpoint_devices/g' tools/libxl/*.[ch]
4. perl -pi -e 's/\blibxl__remus_device\b/libxl__checkpoint_device/g' tools/libxl/*.[ch]
5. perl -pi -e 's/\blibxl__remus_device_instance_ops\b/libxl__checkpoint_device_instance_ops/g' tools/libxl/*.[ch]
6. perl -pi -e 's/\blibxl__remus_callback\b/libxl__checkpoint_callback/g' tools/libxl/*.[ch]
7. perl -pi -e 's/\bremus_device_init\b/checkpoint_device_init/g' tools/libxl/*.[ch]
8. perl -pi -e 's/\bremus_devices_setup\b/checkpoint_devices_setup/g' tools/libxl/*.[ch]
9. perl -pi -e 's/\bdefine_remus_checkpoint_api\b/define_checkpoint_api/g' tools/libxl/*.[ch]
10. perl -pi -e 's/\brds\b/cds/g' tools/libxl/*.[ch]
11. perl -pi -e 's/REMUS_DEVICE/CHECKPOINT_DEVICE/g' tools/libxl/*.[ch] tools/libxl/*.idl
12. perl -pi -e 's/REMUS_DEVOPS/CHECKPOINT_DEVOPS/g' tools/libxl/*.[ch] tools/libxl/*.idl
13. perl -pi -e 's/\bremus\b/checkpoint/g' tools/libxl/libxl_checkpoint_device.[ch]
14. perl -pi -e 's/\bremus device/checkpoint device/g' tools/libxl/libxl_internal.h
15. perl -pi -e 's/\bRemus device/checkpoint device/g' tools/libxl/libxl_internal.h
16. perl -pi -e 's/\bremus abstract/checkpoint abstract/g' tools/libxl/libxl_internal.h
17. perl -pi -e 's/\bremus invocation/checkpoint invocation/g' tools/libxl/libxl_internal.h
18. perl -pi -e 's/\blibxl__remus_device_\(/libxl__checkpoint_device_(/g' tools/libxl/libxl_internal.h
---
tools/libxl/Makefile | 2 +-
...xl_remus_device.c => libxl_checkpoint_device.c} | 198 ++++++++++-----------
tools/libxl/libxl_internal.h | 112 ++++++------
tools/libxl/libxl_netbuffer.c | 108 +++++------
tools/libxl/libxl_nonetbuffer.c | 10 +-
tools/libxl/libxl_remus.c | 78 ++++----
tools/libxl/libxl_remus_disk_drbd.c | 52 +++---
tools/libxl/libxl_types.idl | 4 +-
8 files changed, 282 insertions(+), 282 deletions(-)
rename tools/libxl/{libxl_remus_device.c => libxl_checkpoint_device.c} (52%)tools/libxl/Makefile +1 -1
@@ -56,7 +56,7 @@ else LIBXL_OBJS-y += libxl_nonetbuffer.o endif -LIBXL_OBJS-y += libxl_remus.o libxl_remus_device.o libxl_remus_disk_drbd.o +LIBXL_OBJS-y += libxl_remus.o libxl_checkpoint_device.o libxl_remus_disk_drbd.o LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o libxl_psr.o LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o
tools/libxl/libxl_checkpoint_device.c renamed from tools/libxl/libxl_remus_device.c +99 -99
359 lines not on this page · raw message
tools/libxl/libxl_internal.h +56 -56
214 lines not on this page · raw message
tools/libxl/libxl_netbuffer.c +54 -54
301 lines not on this page · raw message
tools/libxl/libxl_nonetbuffer.c +5 -5
@@ -22,25 +22,25 @@ int libxl__netbuffer_enabled(libxl__gc *gc)return 0 ; } -int init_subkind_nic (libxl__remus_devices_state *rds) +int init_subkind_nic (libxl__checkpoint_devices_state *cds) {return 0 ; } -void cleanup_subkind_nic (libxl__remus_devices_state *rds) +void cleanup_subkind_nic (libxl__checkpoint_devices_state *cds) {return ; } -static void nic_setup (libxl__egc *egc,libxl__remus_device *dev) +static void nic_setup (libxl__egc *egc,libxl__checkpoint_device *dev) { -STATE_AO_GC (dev->rds->ao); +STATE_AO_GC (dev->cds->ao); dev->aodev.rc =ERROR_FAIL ; dev->aodev.callback (egc, &dev->aodev); } -const libxl__remus_device_instance_ops remus_device_nic = { +const libxl__checkpoint_device_instance_ops remus_device_nic = { .kind =LIBXL__DEVICE_KIND_VIF , .setup = nic_setup, };
tools/libxl/libxl_remus.c +39 -39
201 lines not on this page · raw message
tools/libxl/libxl_remus_disk_drbd.c +26 -26
152 lines not on this page · raw message
tools/libxl/libxl_types.idl +2 -2
@@ -61,8 +61,8 @@ libxl_error = Enumeration("error", [ (-15, "LOCK_FAIL"), (-16, "JSON_CONFIG_EMPTY"), (-17, "DEVICE_EXISTS"), - (-18, "REMUS_DEVOPS_DOES_NOT_MATCH"), - (-19, "REMUS_DEVICE_NOT_SUPPORTED"), + (-18, "CHECKPOINT_DEVOPS_DOES_NOT_MATCH"), + (-19, "CHECKPOINT_DEVICE_NOT_SUPPORTED"), ], value_namespace = "") libxl_domain_type = Enumeration("domain_type", [
Signature · 1 line
1.9.3
RFC PATCH v4 3/18 adjust the indentation
In reply to Wen Congyang--- tools/libxl/libxl_checkpoint_device.c | 23 ++++++++++++----------- tools/libxl/libxl_internal.h | 21 ++++++++++++--------- tools/libxl/libxl_remus.c | 12 ++++++++---- 3 files changed, 32 insertions(+), 24 deletions(-)
tools/libxl/libxl_checkpoint_device.c +12 -11
@@ -73,9 +73,9 @@ static void devices_teardown_cb(libxl__egc *egc,/* checkpoint device setup and teardown */ static libxl__checkpoint_device *checkpoint_device_init (libxl__egc *egc, -libxl__checkpoint_devices_state *cds, -libxl__device_kind kind, -void *libxl_dev) +libxl__checkpoint_devices_state *cds, +libxl__device_kind kind, +void *libxl_dev) {libxl__checkpoint_device *dev =NULL ;
@@ -89,9 +89,10 @@ static libxl__checkpoint_device* checkpoint_device_init(libxl__egc *egc, }static void checkpoint_devices_setup (libxl__egc *egc, -libxl__checkpoint_devices_state *cds); +libxl__checkpoint_devices_state *cds); -void libxl__checkpoint_devices_setup (libxl__egc *egc,libxl__checkpoint_devices_state *cds) +void libxl__checkpoint_devices_setup (libxl__egc *egc, +libxl__checkpoint_devices_state *cds) {int i, rc;
@@ -137,7 +138,7 @@ out: }static void checkpoint_devices_setup (libxl__egc *egc, -libxl__checkpoint_devices_state *cds) +libxl__checkpoint_devices_state *cds) {int i, rc;
@@ -223,7 +224,7 @@ static void all_devices_setup_cb(libxl__egc *egc, }void libxl__checkpoint_devices_teardown (libxl__egc *egc, -libxl__checkpoint_devices_state *cds) +libxl__checkpoint_devices_state *cds) {int i;libxl__checkpoint_device *dev;
@@ -285,12 +286,12 @@ static void devices_checkpoint_cb(libxl__egc *egc,/* API implementations */ -#define define_checkpoint_api (api) \ -void libxl__checkpoint_devices_##api(libxl__egc *egc, \ - libxl__checkpoint_devices_state *cds) \ +#define define_checkpoint_api (api) \ +void libxl__checkpoint_devices_##api(libxl__egc *egc, \ + libxl__checkpoint_devices_state *cds) \ { \ int i; \ - libxl__checkpoint_device *dev; \ + libxl__checkpoint_device *dev; \ \ STATE_AO_GC(cds->ao); \ \
tools/libxl/libxl_internal.h +12 -9
@@ -2657,7 +2657,8 @@ typedef struct libxl__save_helper_state {* Each device type needs to implement the interfaces specified in * the libxl__checkpoint_device_instance_ops if it wishes to support Remus. * -* The high-level control flow through the checkpoint device layer is shown below: +* The high-level control flow through the checkpoint device layer is shown +* below: * * xl remus * |-> libxl_domain_remus_start
@@ -2718,7 +2719,8 @@ int init_subkind_drbd_disk(libxl__checkpoint_devices_state *cds);void cleanup_subkind_drbd_disk (libxl__checkpoint_devices_state *cds);typedef void libxl__checkpoint_callback (libxl__egc *, -libxl__checkpoint_devices_state *,int rc); +libxl__checkpoint_devices_state *, +int rc);/* * State associated with a checkpoint invocation, including parameters
@@ -2726,7 +2728,7 @@ typedef void libxl__checkpoint_callback(libxl__egc *,* save/restore machinery. */ struct libxl__checkpoint_devices_state { -/*---- must be set by caller of libxl__checkpoint_device_(setup|teardown) ----*/ +/*-- must be set by caller of libxl__checkpoint_device_(setup|teardown) --*/ libxl__ao *ao;uint32_t domid;
@@ -2739,7 +2741,8 @@ struct libxl__checkpoint_devices_state {/* * this array is allocated before setup the checkpoint devices by the * checkpoint abstract layer. -* devs may be NULL, means there's no checkpoint devices that has been set up. +* devs may be NULL, means there's no checkpoint devices that has been +* set up. * the size of this array is 'num_devices', which is the total number * of libxl nic devices and disk devices(num_nics + num_disks). */
@@ -2799,15 +2802,15 @@ struct libxl__checkpoint_device {/* the following 5 APIs are async ops, call cds->callback when done */ _hidden void libxl__checkpoint_devices_setup(libxl__egc *egc, -libxl__checkpoint_devices_state *cds); +libxl__checkpoint_devices_state *cds); _hidden void libxl__checkpoint_devices_teardown(libxl__egc *egc, -libxl__checkpoint_devices_state *cds); +libxl__checkpoint_devices_state *cds); _hidden void libxl__checkpoint_devices_postsuspend(libxl__egc *egc, -libxl__checkpoint_devices_state *cds); +libxl__checkpoint_devices_state *cds); _hidden void libxl__checkpoint_devices_preresume(libxl__egc *egc, -libxl__checkpoint_devices_state *cds); +libxl__checkpoint_devices_state *cds); _hidden void libxl__checkpoint_devices_commit(libxl__egc *egc, -libxl__checkpoint_devices_state *cds); +libxl__checkpoint_devices_state *cds); _hidden int libxl__netbuffer_enabled(libxl__gc *gc);/*----- Domain suspend (save) state structure -----*/
tools/libxl/libxl_remus.c +8 -4
@@ -21,9 +21,11 @@/*----- remus: setup the environment -----*/ static void libxl__remus_setup_done (libxl__egc *egc, -libxl__checkpoint_devices_state *cds,int rc); +libxl__checkpoint_devices_state *cds, +int rc);static void libxl__remus_setup_failed (libxl__egc *egc, -libxl__checkpoint_devices_state *cds,int rc); +libxl__checkpoint_devices_state *cds, +int rc);void libxl__remus_setup (libxl__egc *egc,libxl__domain_suspend_state *dss)
@@ -57,7 +59,8 @@ out: }static void libxl__remus_setup_done (libxl__egc *egc, -libxl__checkpoint_devices_state *cds,int rc) +libxl__checkpoint_devices_state *cds, +int rc) {libxl__domain_suspend_state *dss =CONTAINER_OF (cds, *dss, cds);STATE_AO_GC (dss->ao);
@@ -222,7 +225,8 @@ out:/*----- remus: wait a new checkpoint -----*/ static void remus_checkpoint_dm_saved (libxl__egc *egc, -libxl__domain_suspend_state *dss,int rc); +libxl__domain_suspend_state *dss, +int rc);static void remus_devices_commit_cb (libxl__egc *egc,libxl__checkpoint_devices_state *cds,int rc);
Signature · 1 line
1.9.3
RFC PATCH v4 4/18 don't touch remus in checkpoint_device
In reply to Wen CongyangCheckpoint device is an abstract layer to do checkpoint. COLO can also use it to do checkpoint. But there are
still some codes in checkpoint device which touch remus:
1. remus_ops: we use remus ops directly in checkpoint device. Store it in checkpoint device state.
2. concrete layer's private member: add a new structure remus state, and move them to remus state.
3. init/cleanup device subkind: we call (init|cleanup)_subkind_nic and (init|cleanup)_subkind_drbd_disk directly in checkpoint device. Call them before calling libxl__checkpoint_devices_setup() or after calling libxl__checkpoint_devices_teardown().
--- tools/libxl/libxl.c | 2 +- tools/libxl/libxl_checkpoint_device.c | 52 ++------------------ tools/libxl/libxl_dom.c | 3 +- tools/libxl/libxl_internal.h | 37 ++++++++++----- tools/libxl/libxl_netbuffer.c | 51 +++++++++++--------- tools/libxl/libxl_remus.c | 89 +++++++++++++++++++++++++++-------- tools/libxl/libxl_remus.h | 5 +- tools/libxl/libxl_remus_disk_drbd.c | 9 ++-- 8 files changed, 136 insertions(+), 112 deletions(-)
tools/libxl/libxl.c +1 -1
@@ -858,7 +858,7 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,assert (info);/* Point of no return */ -libxl__remus_setup (egc, dss); +libxl__remus_setup (egc, &dss->rs);return AO_INPROGRESS ; out:
tools/libxl/libxl_checkpoint_device.c +3 -49
85 lines not on this page · raw message
tools/libxl/libxl_dom.c +1 -2
@@ -1698,7 +1698,6 @@ void libxl__domain_suspend(libxl__egc *egc, libxl__domain_suspend_state *dss) dss2->save_dm =1 ;if (r_info !=NULL ) { - dss->interval = r_info->interval;if (libxl_defbool_val (r_info->compression)) dss->xcflags |=XCFLAGS_CHECKPOINT_COMPRESS ; }
@@ -1880,7 +1879,7 @@ static void domain_suspend_done(libxl__egc *egc, dss2->guest_evtchn.port, &dss2->guest_evtchn_lockfd);if (dss->remus) { -libxl__remus_teardown (egc, dss, rc); +libxl__remus_teardown (egc, &dss->rs, rc);return ; }
tools/libxl/libxl_internal.h +24 -13
@@ -2734,6 +2734,8 @@ struct libxl__checkpoint_devices_state {uint32_t domid;libxl__checkpoint_callback *callback;int device_kind_flags; +/* The ops must be pointer array, and the last ops must be NULL */ +const libxl__checkpoint_device_instance_ops **ops;/*----- private for abstract layer only -----*/
@@ -2754,16 +2756,6 @@ struct libxl__checkpoint_devices_state {int num_disks;libxl__multidev multidev; - -/*----- private for concrete (device-specific) layer only -----*/ - -/* private for nic device subkind ops */ -char *netbufscript; -struct nl_sock *nlsock; -struct nl_cache *qdisc_cache; - -/* private for drbd disk subkind ops */ -char *drbd_probe_script; };/*
@@ -2811,6 +2803,27 @@ _hidden void libxl__checkpoint_devices_preresume(libxl__egc *egc, libxl__checkpoint_devices_state *cds); _hidden void libxl__checkpoint_devices_commit(libxl__egc *egc,libxl__checkpoint_devices_state *cds); + +/*----- Remus related state structure -----*/ +typedef struct libxl__remus_state libxl__remus_state ; +struct libxl__remus_state { +/* private */ +libxl__ev_time checkpoint_timeout;/* used for Remus checkpoint */ +int interval;/* checkpoint interval */ + +/* abstract layer */ +libxl__checkpoint_devices_state cds; + +/*----- private for concrete (device-specific) layer only -----*/ +/* private for nic device subkind ops */ +char *netbufscript; +struct nl_sock *nlsock; +struct nl_cache *qdisc_cache; + +/* private for drbd disk subkind ops */ +char *drbd_probe_script; +}; + _hidden int libxl__netbuffer_enabled(libxl__gc *gc);/*----- Domain suspend (save) state structure -----*/
@@ -2874,9 +2887,7 @@ struct libxl__domain_suspend_state {libxl__domain_suspend_state2 dss2;int hvm;int xcflags; -libxl__checkpoint_devices_state cds; -libxl__ev_time checkpoint_timeout;/* used for Remus checkpoint */ -int interval;/* checkpoint interval (for Remus) */ +libxl__remus_state rs;libxl__save_helper_state shs;libxl__logdirty_switch logdirty;/* private for libxl__domain_save_device_model */
tools/libxl/libxl_netbuffer.c +29 -22
148 lines not on this page · raw message
tools/libxl/libxl_remus.c +70 -19
207 lines not on this page · raw message
tools/libxl/libxl_remus.h +2 -3
@@ -16,10 +16,9 @@#ifndef LIBXL_REMUS_H #define LIBXL_REMUS_H -void libxl__remus_setup (libxl__egc *egc, -libxl__domain_suspend_state *dss); +void libxl__remus_setup (libxl__egc *egc,libxl__remus_state *rs);void libxl__remus_teardown (libxl__egc *egc, -libxl__domain_suspend_state *dss, +libxl__remus_state *rs,int rc);void libxl__remus_domain_suspend_callback (void *data);void libxl__remus_domain_resume_callback (void *data);
tools/libxl/libxl_remus_disk_drbd.c +6 -3
@@ -28,10 +28,12 @@ typedef struct libxl__remus_drbd_disk {int init_subkind_drbd_disk (libxl__checkpoint_devices_state *cds) { +libxl__remus_state *rs =CONTAINER_OF (cds, *rs, cds); +STATE_AO_GC (cds->ao); - cds->drbd_probe_script =GCSPRINTF ("%s/block-drbd-probe" , -libxl__xen_script_dir_path ()); + rs->drbd_probe_script =GCSPRINTF ("%s/block-drbd-probe" , +libxl__xen_script_dir_path ());return 0 ; }
@@ -96,6 +98,7 @@ static void match_async_exec(libxl__egc *egc, libxl__checkpoint_device *dev)int arraysize, nr =0 , rc;const libxl_device_disk *disk = dev->backend_dev;libxl__async_exec_state *aes = &dev->aodev.aes; +libxl__remus_state *rs =CONTAINER_OF (dev->cds, *rs, cds);STATE_AO_GC (dev->cds->ao);/* setup env & args */
@@ -107,7 +110,7 @@ static void match_async_exec(libxl__egc *egc, libxl__checkpoint_device *dev) arraysize =3 ; nr =0 ;GCNEW_ARRAY (aes->args, arraysize); - aes->args[nr++] = dev->cds->drbd_probe_script; + aes->args[nr++] = rs->drbd_probe_script; aes->args[nr++] = disk->pdev_path; aes->args[nr++] =NULL ;assert (nr <= arraysize);
Signature · 1 line
1.9.3
RFC PATCH v4 5/18 Update libxl_save_msgs_gen.pl to support return data from xl to xc
In reply to Wen CongyangCurrently, all callbacks return an integer value or void. We cannot return some data to xc via callback. Update libxl_save_msgs_gen.pl to support this case.
--- tools/libxl/libxl_internal.h | 3 ++ tools/libxl/libxl_save_callout.c | 31 ++++++++++++++++++ tools/libxl/libxl_save_helper.c | 17 ++++++++++ tools/libxl/libxl_save_msgs_gen.pl | 65 ++++++++++++++++++++++++++++++++++---- 4 files changed, 109 insertions(+), 7 deletions(-)
tools/libxl/libxl_internal.h +3 -0
@@ -3184,6 +3184,9 @@ _hidden void libxl__xc_domain_save_done(libxl__egc*, void *dss_void,* When they are ready to indicate completion, they call this. */ void libxl__xc_domain_saverestore_async_callback_done (libxl__egc *egc,libxl__save_helper_state *shs,int return_value); +void libxl__xc_domain_saverestore_async_callback_done_with_data (libxl__egc *egc, +libxl__save_helper_state *shs, +const void *data,uint64_t size); _hidden void libxl__domain_suspend_common_switch_qemu_logdirty
tools/libxl/libxl_save_callout.c +31 -0
@@ -145,6 +145,15 @@ void libxl__xc_domain_saverestore_async_callback_done(libxl__egc *egc, shs->egc =0 ; } +void libxl__xc_domain_saverestore_async_callback_done_with_data (libxl__egc *egc, +libxl__save_helper_state *shs, +const void *data,uint64_t size) +{ + shs->egc = egc; +libxl__srm_callout_sendreply_data (data, size, shs); + shs->egc =0 ; +} +/*----- helper execution -----*/ static void run_helper(libxl__egc *egc, libxl__save_helper_state *shs,
@@ -370,6 +379,28 @@ void libxl__srm_callout_sendreply(int r, void *user)helper_failed (egc, shs,ERROR_FAIL ); } +void libxl__srm_callout_sendreply_data (const void *data,uint64_t size,void *user) +{ +libxl__save_helper_state *shs = user; +libxl__egc *egc = shs->egc; +STATE_AO_GC (shs->ao); +int errnoval; + + errnoval =libxl_write_exactly (CTX ,libxl__carefd_fd (shs->pipes[0 ]), + &size,sizeof (size), shs->stdin_what, +"callback return data length" ); +if (errnoval) + goto out; + + errnoval =libxl_write_exactly (CTX ,libxl__carefd_fd (shs->pipes[0 ]), + data, size, shs->stdin_what, +"callback return data" ); + +out: +if (errnoval) +helper_failed (egc, shs,ERROR_FAIL ); +} +void libxl__srm_callout_callback_log (uint32_t level,uint32_t errnoval,const char *context,const char *formatted,void *user) {
tools/libxl/libxl_save_helper.c +17 -0
@@ -155,6 +155,23 @@ int helper_getreply(void *user)return v; } +uint8_t *helper_getreply_data (void *user) +{ +uint64_t size; +int r =read_exactly (0 , &size,sizeof (size)); +uint8_t *data; + +if (r <=0 ) +exit (-2 ); + + data =helper_allocbuf (size, user); + r =read_exactly (0 , data, size); +if (r <=0 ) +exit (-2 ); + +return data; +} +/*----- other callbacks -----*/ static int toolstack_save_fd;
tools/libxl/libxl_save_msgs_gen.pl +58 -7
135 lines not on this page · raw message
Signature · 1 line
1.9.3
RFC PATCH v4 6/18 Allow slave sends data to master
In reply to Wen CongyangIn colo mode, slave needs to send data to master, but the io_fd only can be written in master, and only can be read in slave. Save recv_fd in domain_suspend_state, and send_fd in domain_create_state.
--- tools/libxl/libxl.c | 2 +- tools/libxl/libxl_create.c | 14 ++++++++++---- tools/libxl/libxl_internal.h | 2 ++ tools/libxl/libxl_types.idl | 7 +++++++ tools/libxl/xl_cmdimpl.c | 7 +++++++ 5 files changed, 27 insertions(+), 5 deletions(-)
tools/libxl/libxl.c +1 -1
@@ -849,7 +849,7 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info, dss->callback = remus_failover_cb; dss->domid = domid; dss->fd = send_fd; -/* TODO do something with recv_fd */ + dss->recv_fd = recv_fd; dss->type = type; dss->live =1 ; dss->debug =0 ;
tools/libxl/libxl_create.c +10 -4
@@ -1491,8 +1491,8 @@ static void domain_create_cb(libxl__egc *egc, int rc, uint32_t domid);static int do_domain_create (libxl_ctx *ctx,libxl_domain_config *d_config, -uint32_t *domid, -int restore_fd,int checkpointed_stream, +uint32_t *domid,int restore_fd, +int send_fd,int checkpointed_stream,const libxl_asyncop_how *ao_how,const libxl_asyncprogress_how *aop_console_how) {
@@ -1505,6 +1505,7 @@ static int do_domain_create(libxl_ctx *ctx, libxl_domain_config *d_config,libxl_domain_config_init (&cdcs->dcs.guest_config_saved);libxl_domain_config_copy (ctx, &cdcs->dcs.guest_config_saved, d_config); cdcs->dcs.restore_fd = restore_fd; + cdcs->dcs.send_fd = send_fd; cdcs->dcs.callback = domain_create_cb; cdcs->dcs.checkpointed_stream = checkpointed_stream;libxl__ao_progress_gethow (&cdcs->dcs.aop_console_how, aop_console_how);
@@ -1533,7 +1534,7 @@ int libxl_domain_create_new(libxl_ctx *ctx, libxl_domain_config *d_config,const libxl_asyncop_how *ao_how, const libxl_asyncprogress_how *aop_console_how) { - return do_domain_create(ctx, d_config, domid, -1, 0, + return do_domain_create(ctx, d_config, domid, -1, -1, 0,ao_how ,aop_console_how ); }
@@ -1543,7 +1544,12 @@ int libxl_domain_create_restore(libxl_ctx *ctx, libxl_domain_config *d_config,const libxl_asyncop_how *ao_how, const libxl_asyncprogress_how *aop_console_how) { - return do_domain_create(ctx, d_config, domid, restore_fd, + int send_fd = -1; + +if (params->checkpointed_stream ==LIBXL_CHECKPOINTED_STREAM_COLO ) + send_fd = params->send_fd; + +return do_domain_create (ctx, d_config, domid, restore_fd, send_fd, params->checkpointed_stream, ao_how, aop_console_how); }
tools/libxl/libxl_internal.h +2 -0
@@ -2879,6 +2879,7 @@ struct libxl__domain_suspend_state {uint32_t domid;int fd; +int recv_fd;libxl_domain_type type;int live;int debug;
@@ -3144,6 +3145,7 @@ struct libxl__domain_create_state {libxl_domain_config *guest_config;libxl_domain_config guest_config_saved;/* vanilla config */ int restore_fd; +int send_fd;libxl__domain_create_cb *callback;libxl_asyncprogress_how aop_console_how;/* private to domain_create */
tools/libxl/libxl_types.idl +7 -0
@@ -194,6 +194,12 @@ libxl_viridian_enlightenment = Enumeration("viridian_enlightenment", [ (2, "time_ref_count"), ]) +libxl_checkpointed_stream = Enumeration("checkpointed_stream", [ + (0, "NONE"), + (1, "REMUS"), + (2, "COLO"), + ], init_val = 0) + # # Complex libxl types #
@@ -340,6 +346,7 @@ libxl_domain_create_info = Struct("domain_create_info",[ libxl_domain_restore_params = Struct("domain_restore_params", [ ("checkpointed_stream", integer), + ("send_fd", integer), ]) libxl_domain_sched_params = Struct("domain_sched_params",[
tools/libxl/xl_cmdimpl.c +7 -0
@@ -154,6 +154,7 @@ struct domain_create {const char *extra_config;/* extra config string */ const char *restore_file;int migrate_fd;/* -1 means none */ +int send_fd;/* -1 means none */ char **migration_domname_r;/* from malloc */ };
@@ -2309,6 +2310,7 @@ static uint32_t create_domain(struct domain_create *dom_info)void *config_data =0 ;int config_len =0 ;int restore_fd =-1 ; +int send_fd =-1 ;const libxl_asyncprogress_how *autoconnect_console_how;struct save_file_header hdr;
@@ -2325,6 +2327,7 @@ static uint32_t create_domain(struct domain_create *dom_info)if (migrate_fd >=0 ) { restore_source ="<incoming migration stream>" ; restore_fd = migrate_fd; + send_fd = dom_info->send_fd; }else { restore_source = restore_file; restore_fd =open (restore_file,O_RDONLY );
@@ -2498,6 +2501,7 @@ start:libxl_domain_restore_params_init (¶ms); params.checkpointed_stream = dom_info->checkpointed_stream; + params.send_fd = send_fd; ret = libxl_domain_create_restore(ctx, &d_config, &domid, restore_fd, ¶ms,
@@ -4032,6 +4036,7 @@ static void migrate_receive(int debug, int daemonize, int monitor, dom_info.monitor = monitor; dom_info.paused =1 ; dom_info.migrate_fd = recv_fd; + dom_info.send_fd = send_fd; dom_info.migration_domname_r = &migration_domname; dom_info.checkpointed_stream = remus;
@@ -4202,6 +4207,7 @@ int main_restore(int argc, char **argv) dom_info.config_file = config_file; dom_info.restore_file = checkpoint_file; dom_info.migrate_fd =-1 ; + dom_info.send_fd =-1 ; dom_info.vnc = vnc; dom_info.vncautopass = vncautopass; dom_info.console_autoconnect = console_autoconnect;
@@ -4641,6 +4647,7 @@ int main_create(int argc, char **argv) dom_info.config_file = filename; dom_info.extra_config = extra_config; dom_info.migrate_fd =-1 ; + dom_info.send_fd =-1 ; dom_info.vnc = vnc; dom_info.vncautopass = vncautopass; dom_info.console_autoconnect = console_autoconnect;
Signature · 1 line
1.9.3
RFC PATCH v4 7/18 secondary vm suspend/resume/checkpoint code
In reply to Wen CongyangSecondary vm is running in colo mode. So we will do
the following things again and again:
1. Resume secondary vm
a. Send LIBXL_COLO_SVM_READY to master
b. If it is resumed the first time, call libxl__xc_domain_restore_done()
to build the secondary vm. We should also enable secondary vm's logdirty. Otherwise, call libxl__domain_resume() to resume secondary vm.
c. Send LIBXL_COLO_SVM_RESUMED to master
2. Wait a new checkpoint
a. Read LIBXL_COLO_NEW_CHECKPOINT from master
3. Suspend secondary vm
a. Suspend secondary vm
b. Get secondary vm's dirty page information
c. Send LIBXL_COLO_SVM_SUSPENDED to master
d. Send secondary vm's dirty page information to master(count + pfn list)
--- tools/libxc/include/xenguest.h | 20 + tools/libxl/Makefile | 1 + tools/libxl/libxl_colo.h | 38 ++ tools/libxl/libxl_colo_restore.c | 896 +++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_create.c | 116 ++++- tools/libxl/libxl_dom.c | 2 +- tools/libxl/libxl_internal.h | 22 + tools/libxl/libxl_save_callout.c | 6 +- tools/libxl/libxl_save_msgs_gen.pl | 6 +- 9 files changed, 1100 insertions(+), 7 deletions(-) create mode 100644 tools/libxl/libxl_colo.h create mode 100644 tools/libxl/libxl_colo_restore.c
tools/libxc/include/xenguest.h +20 -0
@@ -91,6 +91,26 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter/* callbacks provided by xc_domain_restore */ struct restore_callbacks { +/* Called after a new checkpoint to suspend the guest. +*/ +int (*suspend)(void * data); + +/* Called after the secondary vm is ready to resume. +* Callback function resumes the guest & the device model, +* returns to xc_domain_restore. +*/ +int (*postcopy)(void * data); + +/* callback to wait a new checkpoint +* +* returns: +* 0: terminate checkpointing gracefully +* 1: take another checkpoint */ +int (*checkpoint)(void * data); + +/* Enable qemu-dm logging dirty pages to xen */ +int (*switch_qemu_logdirty)(int domid,unsigned enable,void *data);/* HVM only */ +/* callback to restore toolstack specific data */ int (*toolstack_restore)(uint32_t domid,const uint8_t *buf,uint32_t size,void * data);
tools/libxl/Makefile +1 -0
@@ -57,6 +57,7 @@ LIBXL_OBJS-y += libxl_nonetbuffer.o endif LIBXL_OBJS-y += libxl_remus.o libxl_checkpoint_device.o libxl_remus_disk_drbd.o +LIBXL_OBJS-y += libxl_colo_restore.o LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o libxl_psr.o LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o
tools/libxl/libxl_colo.h new file +38 -0
@@ -0,0 +1,38 @@ +/* +* Copyright (C) 2014 FUJITSU LIMITED +* Author: Wen Congyang <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License as published +* by the Free Software Foundation; version 2.1 only. with the special +* exception on linking described in file LICENSE. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +*/ + +#ifndef LIBXL_COLO_H +#define LIBXL_COLO_H + +/* +* values to control suspend/resume primary vm and secondary vm +* at the same time +*/ +enum { +LIBXL_COLO_NEW_CHECKPOINT =1 , +LIBXL_COLO_SVM_SUSPENDED , +LIBXL_COLO_SVM_READY , +LIBXL_COLO_SVM_RESUMED , +}; + +extern void libxl__colo_restore_done (libxl__egc *egc,void *dcs_void, +int ret,int retval,int errnoval); +extern void libxl__colo_restore_setup (libxl__egc *egc, +libxl__colo_restore_state *crs); +extern void libxl__colo_restore_teardown (libxl__egc *egc, +libxl__colo_restore_state *crs, +int rc); + +#endif
tools/libxl/libxl_colo_restore.c new file +896 -0
896 lines not on this page · raw message
tools/libxl/libxl_create.c +114 -2
146 lines not on this page · raw message
tools/libxl/libxl_dom.c +1 -1
@@ -947,7 +947,7 @@ static void switch_logdirty_xswatch(libxl__egc *egc, libxl__ev_xswatch*,static void switch_logdirty_done (libxl__egc *egc,libxl__logdirty_switch *lds,int ok); -static void logdirty_init (libxl__logdirty_switch *lds) +void logdirty_init (libxl__logdirty_switch *lds) { lds->cmd_path =0 ;libxl__ev_xswatch_init (&lds->watch);
tools/libxl/libxl_internal.h +22 -0
@@ -2848,6 +2848,7 @@ struct libxl__logdirty_switch {libxl__ev_xswatch watch;libxl__ev_time timeout; }; +_hidden void logdirty_init(libxl__logdirty_switch *lds);/* * libxl__domain_suspend_state is for saving guest, not
@@ -3139,6 +3140,26 @@ typedef void libxl__domain_create_cb(libxl__egc *egc, libxl__domain_create_state*, int rc, uint32_t domid); +/* colo related structure */ +typedef struct libxl__colo_restore_state libxl__colo_restore_state ; +typedef void libxl__colo_callback (libxl__egc *, +libxl__colo_restore_state *,int rc); +struct libxl__colo_restore_state { +/* must set by caller of libxl__colo_(setup|teardown) */ +libxl__ao *ao; +uint32_t domid; +int send_fd; +int recv_fd; +int hvm; +int pae; +int superpages; +libxl__colo_callback *callback; + +/* private, colo restore checkpoint state */ +libxl__domain_create_cb *saved_cb; +void *crcs; +}; +struct libxl__domain_create_state {/* filled in by user */ libxl__ao *ao;
@@ -3152,6 +3173,7 @@ struct libxl__domain_create_state {int guest_domid;int checkpointed_stream;libxl__domain_build_state build_state; +libxl__colo_restore_state crs;libxl__bootloader_state bl;libxl__stub_dm_spawn_state dmss;/* If we're not doing stubdom, we use only dmss.dm,
tools/libxl/libxl_save_callout.c +5 -1
@@ -15,6 +15,7 @@#include "libxl_osdeps.h" #include "libxl_internal.h" +#include "libxl_colo.h" /* stream_fd is as from the caller (eventually, the application). * It may be 0, 1 or 2, in which case we need to dup it elsewhere.
@@ -65,7 +66,10 @@ void libxl__xc_domain_restore(libxl__egc *egc, libxl__domain_create_state *dcs, dcs->shs.ao = ao; dcs->shs.domid = domid; dcs->shs.recv_callback = libxl__srm_callout_received_restore; - dcs->shs.completion_callback = libxl__xc_domain_restore_done; +if (dcs->checkpointed_stream ==LIBXL_CHECKPOINTED_STREAM_COLO ) + dcs->shs.completion_callback = libxl__colo_restore_done; +else + dcs->shs.completion_callback = libxl__xc_domain_restore_done; dcs->shs.caller_state = dcs; dcs->shs.need_results =1 ; dcs->shs.toolstack_data_file =0 ;
tools/libxl/libxl_save_msgs_gen.pl +3 -3
@@ -24,9 +24,9 @@ our @msgs = ( STRING doing_what), 'unsigned long', 'done', 'unsigned long', 'total'] ], - [ 3, 'scxA', "suspend", [] ], - [ 4, 'scxA', "postcopy", [] ], - [ 5, 'scxA', "checkpoint", [] ], + [ 3, 'srcxA', "suspend", [] ], + [ 4, 'srcxA', "postcopy", [] ], + [ 5, 'srcxA', "checkpoint", [] ], [ 6, 'scxA', "switch_qemu_logdirty", [qw(int domid unsigned enable)] ], # toolstack_save done entirely `by hand'
Signature · 1 line
1.9.3
RFC PATCH v4 8/18 primary vm suspend/get_dirty_pfn/resume/checkpoint code
In reply to Wen CongyangWe will do the following things again and again:
1. Suspend primary vm
a. Suspend primary vm
b. do postsuspend
c. Read LIBXL_COLO_SVM_SUSPENDED to master
d. Read secondary vm's dirty page information to master(count + pfn list)
2. Get dirty pfn list
a. Return secondary vm's dirty pfn list
3. Resume primary vm
a. Read LIBXL_COLO_SVM_READY from slave
b. Do presume
c. Resume primary vm
d. Read LIBXL_COLO_SVM_RESUMED from slave
4. Wait a new checkpoint
a. Wait a new checkpoint(not implemented)
b. Send LIBXL_COLO_NEW_CHECKPOINT to slave
--- tools/libxc/include/xenguest.h | 12 + tools/libxl/Makefile | 2 +- tools/libxl/libxl.c | 6 +- tools/libxl/libxl_colo.h | 10 + tools/libxl/libxl_colo_save.c | 608 +++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_dom.c | 13 +- tools/libxl/libxl_internal.h | 32 +- tools/libxl/libxl_save_msgs_gen.pl | 1 + tools/libxl/libxl_types.idl | 1 + 9 files changed, 677 insertions(+), 8 deletions(-) create mode 100644 tools/libxl/libxl_colo_save.c
tools/libxc/include/xenguest.h +12 -0
@@ -72,6 +72,18 @@ struct save_callbacks {*/ int (*toolstack_save)(uint32_t domid,uint8_t **buf,uint32_t *len,void *data); +/* Called after the guest is suspended. +* +* returns the list of dirty pfn: +* struct { +* uint64_t count; +* uint64_t pfn[]; +* }; +* +* Note: the caller must free the return value. +*/ +uint8_t *(*get_dirty_pfn)(void *data); +/* to be provided as the last argument to each callback function */ void * data; };
tools/libxl/Makefile +1 -1
@@ -57,7 +57,7 @@ LIBXL_OBJS-y += libxl_nonetbuffer.o endif LIBXL_OBJS-y += libxl_remus.o libxl_checkpoint_device.o libxl_remus_disk_drbd.o -LIBXL_OBJS-y += libxl_colo_restore.o +LIBXL_OBJS-y += libxl_colo_restore.o libxl_colo_save.o LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o libxl_psr.o LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o
tools/libxl/libxl.c +5 -1
@@ -18,6 +18,7 @@#include "libxl_internal.h" #include "libxl_remus.h" +#include "libxl_colo.h" #define PAGE_TO_MEMKB (pages) ((pages) * 4)#define BACKEND_STRING_SIZE 5
@@ -858,7 +859,10 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,assert (info);/* Point of no return */ -libxl__remus_setup (egc, &dss->rs); +if (libxl_defbool_val (info->colo)) +libxl__colo_save_setup (egc, &dss->css); +else +libxl__remus_setup (egc, &dss->rs);return AO_INPROGRESS ; out:
tools/libxl/libxl_colo.h +10 -0
@@ -35,4 +35,14 @@ extern void libxl__colo_restore_teardown(libxl__egc *egc,libxl__colo_restore_state *crs, int rc); +extern void libxl__colo_save_domain_suspend_callback (void *data); +extern void libxl__colo_save_domain_resume_callback (void *data); +extern void libxl__colo_save_domain_checkpoint_callback (void *data); +extern void libxl__colo_save_get_dirty_pfn_callback (void *data); +extern void libxl__colo_save_setup (libxl__egc *egc, +libxl__colo_save_state *css); +extern void libxl__colo_save_teardown (libxl__egc *egc, +libxl__colo_save_state *css, +int rc); +#endif
tools/libxl/libxl_colo_save.c new file +608 -0
608 lines not on this page · raw message
tools/libxl/libxl_dom.c +11 -2
@@ -20,6 +20,7 @@#include "libxl_internal.h" #include "libxl_arch.h" #include "libxl_remus.h" +#include "libxl_colo.h" #include <xc_dom.h> #include <xen/hvm/hvm_info_table.h>
@@ -1717,7 +1718,12 @@ void libxl__domain_suspend(libxl__egc *egc, libxl__domain_suspend_state *dss) }memset (callbacks,0 ,sizeof (*callbacks)); -if (r_info !=NULL ) { +if (r_info !=NULL &&libxl_defbool_val (r_info->colo)) { + callbacks->suspend = libxl__colo_save_domain_suspend_callback; + callbacks->postcopy = libxl__colo_save_domain_resume_callback; + callbacks->checkpoint = libxl__colo_save_domain_checkpoint_callback; + callbacks->get_dirty_pfn = libxl__colo_save_get_dirty_pfn_callback; + }else if (r_info !=NULL ) { callbacks->suspend = libxl__remus_domain_suspend_callback; callbacks->postcopy = libxl__remus_domain_resume_callback; callbacks->checkpoint = libxl__remus_domain_checkpoint_callback;
@@ -1878,7 +1884,10 @@ static void domain_suspend_done(libxl__egc *egc,xc_suspend_evtchn_release (CTX ->xch,CTX ->xce, domid, dss2->guest_evtchn.port, &dss2->guest_evtchn_lockfd); -if (dss->remus) { +if (dss->remus &&libxl_defbool_val (dss->remus->colo)) { +libxl__colo_save_teardown (egc, &dss->css, rc); +return ; + }else if (dss->remus) {libxl__remus_teardown (egc, &dss->rs, rc);return ; }
tools/libxl/libxl_internal.h +28 -4
@@ -2637,7 +2637,7 @@ typedef struct libxl__save_helper_state {/* * The abstract checkpoint device layer exposes a common * set of API to [external] libxl for manipulating devices attached to -* a guest protected by Remus. The device layer also exposes a set of +* a guest protected by Remus/COLO. The device layer also exposes a set of * [internal] interfaces that every device type must implement. * * The following API are exposed to libxl:
@@ -2655,7 +2655,7 @@ typedef struct libxl__save_helper_state {* +libxl__checkpoint_devices_commit * * Each device type needs to implement the interfaces specified in -* the libxl__checkpoint_device_instance_ops if it wishes to support Remus. +* the libxl__checkpoint_device_instance_ops if it wishes to support Remus/COLO. * * The high-level control flow through the checkpoint device layer is shown * below:
@@ -2675,7 +2675,7 @@ typedef struct libxl__checkpoint_device_instance_ops libxl__checkpoint_device_in/* * Interfaces to be implemented by every device subkind that wishes to -* support Remus. Functions must be implemented unless otherwise +* support Remus/COLO. Functions must be implemented unless otherwise * stated. Many of these functions are asynchronous. They call * dev->aodev.callback when done. The actual implementations may be * synchronous and call dev->aodev.callback directly (as the last
@@ -2826,6 +2826,25 @@ struct libxl__remus_state { _hidden int libxl__netbuffer_enabled(libxl__gc *gc); +/*----- colo related state structure -----*/ +typedef struct libxl__colo_save_state libxl__colo_save_state ; +struct libxl__colo_save_state { +libxl__checkpoint_devices_state cds; +int send_fd; +int recv_fd; + +/* private */ +libxl__datacopier_state dc; +libxl__datareader_state drs; +uint8_t section; +uint64_t count; +uint64_t *buff; +/* read section and count, and then store it in temp_buff */ +uint8_t temp_buff[9 ]; +void (*callback)(libxl__egc *,libxl__colo_save_state *); +bool svm_running; +}; +/*----- Domain suspend (save) state structure -----*/ typedef struct libxl__domain_suspend_state libxl__domain_suspend_state ;
@@ -2889,7 +2908,12 @@ struct libxl__domain_suspend_state {libxl__domain_suspend_state2 dss2;int hvm;int xcflags; -libxl__remus_state rs; +union { +/* for Remus */ +libxl__remus_state rs; +/* for COLO */ +libxl__colo_save_state css; + };libxl__save_helper_state shs;libxl__logdirty_switch logdirty;/* private for libxl__domain_save_device_model */
tools/libxl/libxl_save_msgs_gen.pl +1 -0
@@ -36,6 +36,7 @@ our @msgs = ( 'unsigned long', 'console_mfn'] ], [ 9, 'srW', "complete", [qw(int retval int errnoval)] ], + [ 10, 'scxAB', "get_dirty_pfn", [] ], ); #----------------------------------------
tools/libxl/libxl_types.idl +1 -0
@@ -664,6 +664,7 @@ libxl_domain_remus_info = Struct("domain_remus_info",[ ("netbuf", libxl_defbool), ("netbufscript", string), ("diskbuf", libxl_defbool), + ("colo", libxl_defbool) ]) libxl_event_type = Enumeration("event_type", [
Signature · 1 line
1.9.3
RFC PATCH v4 9/18 xc_domain_save: flush cache before calling callbacks->postcopy() in colo mode
In reply to Wen CongyangIn colo mode, secondary vm is running. We will use the io_fd to ensure that both primary vm and secondary vm are resumed at the same time. So we should call postcopy later.
--- tools/libxc/xc_domain_save.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
tools/libxc/xc_domain_save.c +14 -2
@@ -2082,10 +2082,15 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter out_rc: completed =1 ; -if ( !rc && callbacks->postcopy ) +/* +* COLO: secondary vm is running. We will use the io_fd to +* ensure that both primary vm and secondary vm are resumed +* at the same time. So we should call postcopy later. +*/ +if ( !rc && callbacks->postcopy && !callbacks->get_dirty_pfn ) callbacks->postcopy (callbacks->data); -/* guest has been resumed. Now we can compress data +/* Remus: guest has been resumed. Now we can compress data * at our own pace. */ if (!rc && compressing)
@@ -2113,6 +2118,13 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iterdiscard_file_cache (xch, io_fd,1 /* flush */ ); +/* +* COLO: send qemu device state and resume both +* primary vm and secondary vm now. +*/ +if ( !rc && callbacks->postcopy && callbacks->get_dirty_pfn ) + callbacks->postcopy (callbacks->data); +/* Enable compression now, finally */ compressing = (flags &XCFLAGS_CHECKPOINT_COMPRESS );
Signature · 1 line
1.9.3
RFC PATCH v4 10/18 COLO: xc related codes
In reply to Wen CongyangSave:
1. send XC_SAVE_ID_LAST_CHECKPOINT, so secondary vm can be resumed
2. call callbacks->get_dirty_pfn() after suspend primary vm if we are doing checkpoint.
Restore:
1. call the callbacks resume/checkpoint/suspend if secondary vm's status is the same as primary vm's status.
2. zero out tdata because we will use it zero out pagebuf.tdata.
3. don't apply the secondary vm's state when we failed to get new secondary vm's state, because we have applied it every checkpoint.
--- tools/libxc/xc_domain_restore.c | 82 +++++++++++++++++++++++++++++++++++------ tools/libxc/xc_domain_save.c | 49 +++++++++++++++++++++++- 2 files changed, 117 insertions(+), 14 deletions(-)
tools/libxc/xc_domain_restore.c +70 -12
@@ -1454,7 +1454,7 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,int nraces =0 ;/* The new domain's shared-info frame number. */ -unsigned long shared_info_frame; +unsigned long shared_info_frame =0 ;unsigned char shared_info_page[PAGE_SIZE ];/* saved contents from file */ shared_info_any_t *old_shared_info = (shared_info_any_t *)shared_info_page;
@@ -1504,6 +1504,8 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,DPRINTF ("%s: starting restore of new domid %u" , __func__, dom); + n = m =0 ; +pagebuf_init (&pagebuf);memset (&tailbuf,0 ,sizeof (tailbuf)); tailbuf.ishvm = hvm;
@@ -1629,7 +1631,6 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,* We uncanonicalise page tables as we go. */ - n = m =0 ; loadpages:for ( ; ; ) {
@@ -1793,26 +1794,45 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom, goto finish; } +new_checkpoint:// DPRINTF("Buffered checkpoint\n"); if (pagebuf_get (xch, ctx, &pagebuf, io_fd, dom) ) {PERROR ("error when buffering batch, finishing" ); -/* -* Remus: discard the current incomplete checkpoint and restore -* backup from the last complete checkpoint. -*/ - goto finish; +if ( callbacks && callbacks->checkpoint ) + { +/* COLO: discard the current incomplete checkpoint */ + rc =0 ; + goto failover; + } +else + { +/* +* Remus: discard the current incomplete checkpoint and restore +* backup from the last complete checkpoint. +*/ + goto finish; + } }memset (&tmptail,0 ,sizeof (tmptail)); tmptail.ishvm = hvm;if (buffer_tail (xch, ctx, &tmptail, io_fd, max_vcpu_id, vcpumap, ext_vcpucontext, vcpuextstate_size) <0 ) {ERROR ("error buffering image tail, finishing" ); -/* -* Remus: discard the current incomplete checkpoint and restore -* backup from the last complete checkpoint. -*/ - goto finish; +if ( callbacks && callbacks->checkpoint ) + { +/* COLO: discard the current incomplete checkpoint */ + rc =0 ; + goto failover; + } +else + { +/* +* Remus: discard the current incomplete checkpoint and restore +* backup from the last complete checkpoint. +*/ + goto finish; + } }tailbuf_free (&tailbuf);memcpy (&tailbuf, &tmptail,sizeof (tailbuf));
@@ -2301,6 +2321,7 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,free (tdata.data); goto out; } +memset (&tdata,0 ,sizeof (tdata)); }/* Dump the QEMU state to a state file for QEMU to load */
@@ -2368,6 +2389,43 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom, rc =0 ; out: +if ( !rc && callbacks && callbacks->checkpoint ) + { +#define HANDLE_CALLBACK_RETURN_VALUE (frc) \ + do { \ + if ( frc == 0 ) \ + { \ +/* Some internal error happens */ \ + rc =1 ; \ + goto out; \ + } \ +else if ( frc ==2 ) \ + { \ +/* Reading/writing error, do failover */ \ + rc =0 ; \ + goto failover; \ + } \ + }while (0 ) +/* COLO */ + +/* TODO: call restore_results */ + +/* Resume secondary vm */ + frc = callbacks->postcopy (callbacks->data); +HANDLE_CALLBACK_RETURN_VALUE (frc); + +/* wait for new checkpoint */ + frc = callbacks->checkpoint (callbacks->data); +HANDLE_CALLBACK_RETURN_VALUE (frc); + +/* suspend secondary vm */ + frc = callbacks->suspend (callbacks->data); +HANDLE_CALLBACK_RETURN_VALUE (frc); + + goto new_checkpoint; + } + +failover:if ( (rc !=0 ) && (dom !=0 ) )xc_domain_destroy (xch, dom);xc_hypercall_buffer_free (xch, ctxt);
tools/libxc/xc_domain_save.c +47 -2
77 lines not on this page · raw message
Signature · 1 line
1.9.3
RFC PATCH v4 11/18 send store mfn and console mfn to xl before resuming secondary vm
In reply to Wen CongyangWe will call libxl__xc_domain_restore_done() to rebuild secondary vm. But we need store mfn and console mfn when rebuilding secondary vm. So make restore_results is a function pointers in callbacks struct and struct {save,restore}_callbacks, and use this callback to send store mfn and console mfn to xl.
--- tools/libxc/include/xenguest.h | 8 ++++++++ tools/libxc/xc_domain_restore.c | 2 +- tools/libxl/libxl_colo_restore.c | 5 ----- tools/libxl/libxl_create.c | 1 + tools/libxl/libxl_save_msgs_gen.pl | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-)
tools/libxc/include/xenguest.h +8 -0
@@ -123,6 +123,14 @@ struct restore_callbacks {/* Enable qemu-dm logging dirty pages to xen */ int (*switch_qemu_logdirty)(int domid,unsigned enable,void *data);/* HVM only */ +/* +* callback to send store mfn and console mfn to xl +* if we want to resume vm before xc_domain_save() +* exits. +*/ +void (*restore_results)(unsigned long store_mfn,unsigned long console_mfn, +void *data); +/* callback to restore toolstack specific data */ int (*toolstack_restore)(uint32_t domid,const uint8_t *buf,uint32_t size,void * data);
tools/libxc/xc_domain_restore.c +1 -1
@@ -2408,7 +2408,7 @@ new_checkpoint: }while (0 )/* COLO */ -/* TODO: call restore_results */ + callbacks->restore_results (*store_mfn, *console_mfn, callbacks->data);/* Resume secondary vm */ frc = callbacks->postcopy (callbacks->data);
tools/libxl/libxl_colo_restore.c +0 -5
@@ -142,11 +142,6 @@ static void colo_resume_vm(libxl__egc *egc,return ; } -/* -* TODO: get store mfn and console mfn -* We should call the callback restore_results in -* xc_domain_restore() before resuming the guest. -*/ libxl__xc_domain_restore_done (egc, dcs,0 ,0 ,0 );return ;
tools/libxl/libxl_create.c +1 -0
@@ -1102,6 +1102,7 @@ static void domcreate_bootloader_done(libxl__egc *egc, rc =ERROR_INVAL ; goto out; } + callbacks->restore_results = libxl__srm_callout_callback_restore_results;if (checkpointed_stream ==LIBXL_CHECKPOINTED_STREAM_COLO ) { crs->ao = ao;
tools/libxl/libxl_save_msgs_gen.pl +1 -1
@@ -32,7 +32,7 @@ our @msgs = ( # toolstack_save done entirely `by hand' [ 7, 'rcxW', "toolstack_restore", [qw(uint32_t domid BLOCK tsdata)] ], - [ 8, 'r', "restore_results", ['unsigned long', 'store_mfn', + [ 8, 'rcx', "restore_results", ['unsigned long', 'store_mfn', 'unsigned long', 'console_mfn'] ], [ 9, 'srW', "complete", [qw(int retval int errnoval)] ],
Signature · 1 line
1.9.3
RFC PATCH v4 12/18 implement the cmdline for COLO
In reply to Wen CongyangAdd a new option -c to the command 'xl remus'. If you want to use COLO HA instead of Remus HA, please use -c option.
Update man pages to reflect the addition of a new option to 'xl remus' command.
Also add a new option -c to the internal command 'xl migrate-receive'.
--- docs/man/xl.pod.1 | 12 +++++++++-- tools/libxl/libxl.c | 16 ++++++++++++++ tools/libxl/xl_cmdimpl.c | 53 +++++++++++++++++++++++++++++++++++++++-------- tools/libxl/xl_cmdtable.c | 4 +++- 4 files changed, 73 insertions(+), 12 deletions(-)
docs/man/xl.pod.1 +10 -2
@@ -432,12 +432,15 @@ Print huge (!) amount of debug during the migration process. =item B<remus> [I<OPTIONS>] I<domain-id> I<host> -Enable Remus HA for domain. By default B<xl> relies on ssh as a transport -mechanism between the two hosts. +Enable Remus HA or COLO HA for domain. By default B<xl> relies on ssh as a +transport mechanism between the two hosts. N.B: Remus support in xl is still in experimental (proof-of-concept) phase. Disk replication support is limited to DRBD disks. + COLO support in xl is still in experimental (proof-of-concept) phase. + There is no support for network or disk at the moment. + B<OPTIONS> =over 4
@@ -483,6 +486,11 @@ Disable network output buffering. Requires enabling unsafe mode. Disable disk replication. Requires enabling unsafe mode. +=item B<-c> + +Enable COLO HA. It is conflict with B<-i> and B<-b>, and memory +checkpoint compression must be disabled. + =back =item B<pause> I<domain-id>
tools/libxl/libxl.c +16 -0
@@ -828,6 +828,22 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info, goto out; } +/* The caller must set this defbool */ +if (libxl_defbool_is_default (info->colo)) { +LOG (ERROR ,"colo mode must be enabled/disabled" ); + rc =ERROR_FAIL ; + goto out; + } + +if (libxl_defbool_val (info->colo)) { +libxl_defbool_setdefault (&info->compression, false); +if (libxl_defbool_val (info->compression)) { +LOG (ERROR ,"cannot use memory checkpoint compression in COLO mode" ); + rc =ERROR_FAIL ; + goto out; + } + } +libxl_defbool_setdefault (&info->allow_unsafe, false);libxl_defbool_setdefault (&info->blackhole, false);libxl_defbool_setdefault (&info->compression, true);
tools/libxl/xl_cmdimpl.c +44 -9
135 lines not on this page · raw message
tools/libxl/xl_cmdtable.c +3 -1
@@ -513,7 +513,9 @@ struct cmd_spec cmd_table[] = { "-b Replicate memory checkpoints to /dev/null (blackhole).\n" " Works only in unsafe mode.\n" "-n Disable network output buffering. Works only in unsafe mode.\n" - "-d Disable disk replication. Works only in unsafe mode." + "-d Disable disk replication. Works only in unsafe mode.\n" + "-c Enable COLO HA. It is conflict with -i and -b, and memory\n" + " checkpoint must be disabled" }, #endif { "devd",
Signature · 1 line
1.9.3
RFC PATCH v4 13/18 tools: xc_doamin_restore: zero ioreq page only one time
In reply to Wen Congyangioreq page contains evtchn which will be set when we resume the secondary vm the first time. The hypervisor will check if the evtchn is corrupted, so we cannot zero the ioreq page more than one time.
The ioreq->state is always STATE_IOREQ_NONE after the vm is suspended, so it is OK if we only zero it one time.
--- tools/libxc/xc_domain_restore.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
tools/libxc/xc_domain_restore.c +21 -3
@@ -1501,6 +1501,7 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,struct restore_ctx _ctx;struct restore_ctx *ctx = &_ctx;struct domain_info_context *dinfo = &ctx->dinfo; +int skip_clear_ioreq_page =0 ;DPRINTF ("%s: starting restore of new domid %u" , __func__, dom);
@@ -2331,13 +2332,30 @@ new_checkpoint: }/* These comms pages need to be zeroed at the start of day */ -if (xc_clear_domain_page (xch, dom, tailbuf.u.hvm.magicpfns[0 ]) || -xc_clear_domain_page (xch, dom, tailbuf.u.hvm.magicpfns[1 ]) || -xc_clear_domain_page (xch, dom, tailbuf.u.hvm.magicpfns[2 ]) ) +if (xc_clear_domain_page (xch, dom, tailbuf.u.hvm.magicpfns[2 ]) ) {PERROR ("error zeroing magic pages" ); goto out; } +if ( !skip_clear_ioreq_page ) + { +if (xc_clear_domain_page (xch, dom, tailbuf.u.hvm.magicpfns[0 ]) || +xc_clear_domain_page (xch, dom, tailbuf.u.hvm.magicpfns[1 ]) ) + { +PERROR ("error zeroing magic pages" ); + goto out; + } +/* +* ioreq page contains evtchn which will be set when we resume the +* secondary vm the first time. The hypervisor will check if the +* evtchn is corrupted, so we cann't clear the ioreq page more +* than one time. +* +* The ioreq->state is always STATE_IOREQ_NONE after the vm is +* suspended, so it is OK if we only clear it one time. +*/ + skip_clear_ioreq_page =1 ; + }if ( (frc =xc_hvm_param_set (xch, dom, HVM_PARAM_IOREQ_PFN, tailbuf.u.hvm.magicpfns[0]))
Signature · 1 line
1.9.3
RFC PATCH v4 14/18 block-colo: implement colo disk replication
In reply to Wen CongyangTODO:
update block-remus to use async io to instead of mread/mwrite.
--- tools/blktap2/drivers/Makefile | 3 + tools/blktap2/drivers/block-colo.c | 1132 +++++++++++++++++++++++++++++ tools/blktap2/drivers/block-remus.c | 4 +- tools/blktap2/drivers/block-replication.c | 262 ++++++- tools/blktap2/drivers/block-replication.h | 77 +- tools/blktap2/drivers/tapdisk-disktype.c | 9 + tools/blktap2/drivers/tapdisk-disktype.h | 3 +- 7 files changed, 1476 insertions(+), 14 deletions(-) create mode 100644 tools/blktap2/drivers/block-colo.c
tools/blktap2/drivers/Makefile +3 -0
@@ -31,6 +31,8 @@ REMUS-OBJS += hashtable_itr.o REMUS-OBJS += hashtable_utility.o REMUS-OBJS += block-replication.o +COLO-OBJS += block-colo.o + tapdisk2 tapdisk-stream tapdisk-diff $(QCOW_UTIL): AIOLIBS := -laio MEMSHRLIBS :=
@@ -77,6 +79,7 @@ BLK-OBJS-y += aes.o BLK-OBJS-y += md5.o BLK-OBJS-y += $(PORTABLE-OBJS-y) BLK-OBJS-y += $(REMUS-OBJS) +BLK-OBJS-y += $(COLO-OBJS) all: $(IBIN) lock-util qcow-util
tools/blktap2/drivers/block-colo.c new file +1132 -0
1,132 lines not on this page · raw message
tools/blktap2/drivers/block-remus.c +2 -2
@@ -672,7 +672,7 @@ static void server_do_wreq(td_driver_t *driver)if (ramdisk_cache_write_request (&s->ramdisk, *sector, *sectors, driver->info.sector_size, buf, -"remus" ) <0 ) { +"remus" ,1 ) <0 ) { rc =ERROR_INTERNAL ; goto err; }
@@ -693,7 +693,7 @@ static void server_do_creq(td_driver_t *driver)// RPRINTF("committing buffer\n"); -ramdisk_start_flush (&s->ramdisk); +ramdisk_start_flush (&s->ramdisk,1 );/* XXX this message should not be sent until flush completes! */ if (write (s->stream_fd.fd,TDREMUS_DONE ,strlen (TDREMUS_DONE )) !=4 )
tools/blktap2/drivers/block-replication.c +253 -9
304 lines not on this page · raw message
tools/blktap2/drivers/block-replication.h +75 -2
104 lines not on this page · raw message
tools/blktap2/drivers/tapdisk-disktype.c +9 -0
@@ -94,6 +94,12 @@ static const disk_info_t remus_disk = { 0, }; +static const disk_info_t colo_disk = { +"colo" , +"colo disk replicator (COLO)" , +0 , +}; +const disk_info_t *tapdisk_disk_types[] = { [DISK_TYPE_AIO ] = &aio_disk, [DISK_TYPE_SYNC ] = &sync_disk,
@@ -105,6 +111,7 @@ const disk_info_t *tapdisk_disk_types[] = { [DISK_TYPE_BLOCK_CACHE] = &block_cache_disk, [DISK_TYPE_LOG] = &log_disk, [DISK_TYPE_REMUS] = &remus_disk, + [DISK_TYPE_COLO] = &colo_disk, [DISK_TYPE_MAX] = NULL, };
@@ -119,6 +126,7 @@ extern struct tap_disk tapdisk_block_cache;extern struct tap_disk tapdisk_vhd_index;extern struct tap_disk tapdisk_log;extern struct tap_disk tapdisk_remus; +extern struct tap_disk tapdisk_colo;const struct tap_disk *tapdisk_disk_drivers[] = { [DISK_TYPE_AIO ] = &tapdisk_aio,
@@ -132,6 +140,7 @@ const struct tap_disk *tapdisk_disk_drivers[] = { [DISK_TYPE_BLOCK_CACHE] = &tapdisk_block_cache, [DISK_TYPE_LOG] = &tapdisk_log, [DISK_TYPE_REMUS] = &tapdisk_remus, + [DISK_TYPE_COLO] = &tapdisk_colo, [DISK_TYPE_MAX] = NULL, };
tools/blktap2/drivers/tapdisk-disktype.h +2 -1
@@ -39,7 +39,8 @@#define DISK_TYPE_BLOCK_CACHE 7#define DISK_TYPE_LOG 8#define DISK_TYPE_REMUS 9 -#define DISK_TYPE_MAX 10 +#define DISK_TYPE_COLO 10 +#define DISK_TYPE_MAX 11#define DISK_TYPE_NAME_MAX 32
Signature · 1 line
1.9.3
RFC PATCH v4 15/18 libxl/colo: setup and control disk replication for blktap2 backends
In reply to Wen CongyangThis patch adds the machinery required for protecting a guest's disk state, when the guest disk uses a blktap2 disk backend.
1. COLO blktap2 disk device: Implements the interfaces required by the checkpoint abstract device layer. A note about the implementation:
a) setup() is called for each disk attached to the guest.
During setup():
i) perform the sanity check: backend type should be LIBXL_DISK_BACKEND_TAP and format should be LIBXL_DISK_FORMAT_COLO.
ii) connect to the control socket: /var/run/tap/colo_xxx, xxx is
"host:port"(The character ':/' will be changed to '_').
b) The postsuspend callback() will write "flush" to this socket
c) The commit callback() will wait and read "done" from this socket
--- docs/man/xl.pod.1 | 3 +- tools/libxl/Makefile | 2 +- tools/libxl/libxl_colo_save.c | 36 ++++- tools/libxl/libxl_colo_save_disk_blktap2.c | 219 +++++++++++++++++++++++++++++ tools/libxl/libxl_create.c | 8 ++ tools/libxl/libxl_internal.h | 2 + tools/libxl/libxl_noblktap2.c | 29 ++++ 7 files changed, 295 insertions(+), 4 deletions(-) create mode 100644 tools/libxl/libxl_colo_save_disk_blktap2.c
docs/man/xl.pod.1 +2 -1
@@ -439,7 +439,8 @@ N.B: Remus support in xl is still in experimental (proof-of-concept) phase. Disk replication support is limited to DRBD disks. COLO support in xl is still in experimental (proof-of-concept) phase. - There is no support for network or disk at the moment. + There is no support for network at the moment. + Disk replication support is limited to blktap2 disks. B<OPTIONS>
tools/libxl/Makefile +1 -1
@@ -45,7 +45,7 @@ LIBXLU_LIBS = LIBXL_OBJS-y = osdeps.o libxl_paths.o libxl_bootloader.o flexarray.o ifeq ($(LIBXL_BLKTAP),y) -LIBXL_OBJS-y += libxl_blktap2.o +LIBXL_OBJS-y += libxl_blktap2.o libxl_colo_save_disk_blktap2.o else LIBXL_OBJS-y += libxl_noblktap2.o endif
tools/libxl/libxl_colo_save.c +34 -2
@@ -18,10 +18,36 @@#include "libxl_internal.h" #include "libxl_colo.h" +extern const libxl__checkpoint_device_instance_ops colo_save_device_blktap2_disk; +static const libxl__checkpoint_device_instance_ops *colo_ops[] = { + &colo_save_device_blktap2_disk,NULL , }; +/* ================= helper functions ================= */ +static int init_device_subkind (libxl__checkpoint_devices_state *cds) +{ +/* init device subkind-specific state in the libxl ctx */ +int rc; +STATE_AO_GC (cds->ao); + + rc =init_subkind_drbd_disk (cds); +if (rc) goto out; + + rc =0 ; +out: +return rc; +} + +static void cleanup_device_subkind (libxl__checkpoint_devices_state *cds) +{ +/* cleanup device subkind-specific state in the libxl ctx */ +STATE_AO_GC (cds->ao); + +cleanup_subkind_blktap2_disk (cds); +} +/* ================= colo: setup save environment ================= */ static void colo_save_setup_done(libxl__egc *egc, libxl__checkpoint_devices_state *cds,
@@ -48,13 +74,16 @@ void libxl__colo_save_setup(libxl__egc *egc, libxl__colo_save_state *css) css->recv_fd = dss->recv_fd; css->svm_running = false; -/* TODO: disk/nic support */ - cds->device_kind_flags =0 ; +/* TODO: nic support */ + cds->device_kind_flags = (1 <<LIBXL__DEVICE_KIND_VBD ); cds->ops = colo_ops; cds->callback = colo_save_setup_done; cds->ao = ao; cds->domid = dss->domid; +if (init_device_subkind (cds)) + goto out; +libxl__checkpoint_devices_setup (egc, &css->cds);return ;
@@ -92,6 +121,7 @@ static void colo_save_setup_failed(libxl__egc *egc,LOG (ERROR ,"COLO: failed to teardown device after setup failed" " for guest with domid %u, rc %d" , cds->domid, rc); +cleanup_device_subkind (cds);libxl__ao_complete (egc, ao, rc); }
@@ -122,6 +152,8 @@ static void colo_teardown_done(libxl__egc *egc, {libxl__colo_save_state *css =CONTAINER_OF (cds, *css, cds);libxl__domain_suspend_state *dss =CONTAINER_OF (css, *dss, css); + +cleanup_device_subkind (cds); dss->callback (egc, dss, rc); }
tools/libxl/libxl_colo_save_disk_blktap2.c new file +219 -0
219 lines not on this page · raw message
tools/libxl/libxl_create.c +8 -0
@@ -870,6 +870,14 @@ static void initiate_domain_create(libxl__egc *egc,for (i =0 ; i < d_config->num_disks; i++) { ret =libxl__device_disk_setdefault (gc, &d_config->disks[i]);if (ret) goto error_out; + +/* TODO: cleanup it when destroying the domain */ +if (d_config->disks[i].backend ==LIBXL_DISK_BACKEND_TAP && + d_config->disks[i].filter) +libxl__blktap_devpath (gc, d_config->disks[i].pdev_path, + d_config->disks[i].format, + d_config->disks[i].filter, + d_config->disks[i].filter_params); } dcs->bl.ao = ao;
tools/libxl/libxl_internal.h +2 -0
@@ -2717,6 +2717,8 @@ int init_subkind_nic(libxl__checkpoint_devices_state *cds);void cleanup_subkind_nic (libxl__checkpoint_devices_state *cds);int init_subkind_drbd_disk (libxl__checkpoint_devices_state *cds);void cleanup_subkind_drbd_disk (libxl__checkpoint_devices_state *cds); +int init_subkind_blktap2_disk (libxl__checkpoint_devices_state *cds); +void cleanup_subkind_blktap2_disk (libxl__checkpoint_devices_state *cds); typedef void libxl__checkpoint_callback(libxl__egc *, libxl__checkpoint_devices_state *,
tools/libxl/libxl_noblktap2.c +29 -0
@@ -37,6 +37,35 @@ int libxl__device_destroy_tapdisk(libxl__gc *gc,return 0 ; } +static int blktap2_colo_init (libxl__checkpoint_device *cds) +{ +return 0 ; +} + +static void blktap2_colo_cleanup (libxl__checkpoint_device *cds) +{ +return ; +} + +static void blktap2_colo_setup (libxl__checkpoint_device *cds) +{ + dev->aodev.rc =ERROR_FAIL ; + dev->aodev.callback (dev->cds->egc, &dev->aodev); +} + +static void blktap2_colo_teardown (libxl__checkpoint_device *cds) +{ +return ; +} + +const libxl__checkpoint_device_instance_ops colo_save_device_blktap2_disk = { + .kind =LIBXL__CHECKPOINT_DEVICE_DISK , + .init = blktap2_colo_init, + .cleanup = blktap2_colo_cleanup, + .setup = blktap2_colo_setup, + .teardown = blktap2_colo_teardown, +}; +/* * Local variables: * mode: C
Signature · 1 line
1.9.3
RFC PATCH v4 16/18 setup and control colo-agent for primary vm
In reply to Wen CongyangThis patch adds the machinery required for protecting a primary vm's network device state. This patch comprises of three parts:
1. Hotplug scripts: The colo-agent-setup script is responsible for setting up and tearing down the necessary infrastructure required for COLO agent. This script should be invoked by libxl for each of the guest's network interfaces, when starting or stopping COLO.
COLO agent is a agent that will compare the packets from primary vm and secondary vm, and trigger a new checkpoint if they are different.
Apart from returning success/failure indication via the usual hotplug entries in xenstore, this script also writes to xenstore, the name of the ifb device to be used to control COLO agent.
The script relies on libnl3 command line utilities to perform various setup/teardown functions. The script is confined to Linux platforms only since NetBSD does not seem to have libnl3.
2. Checkpoint network device: Implements the interfaces required by the checkpoint abstract device layer. A note about the implementation:
a) setup() and teardown() are called for each vif attached to the primary vm.
During setup(), the hotplug script is called to setup COLO agent for given vif. The script does the follow things:
i) choose two available IFB devices from system(called IFB_PRIMARY,
and IFB_SECONDARY), and set up the colo qdisc on these two ifb devices.
ii) copy and forward the egress traffic to the FORWARD device iii) redirect vif egress traffic to the IFB_PRIMARY device iv) redirect FORWARD device egress traffic to the IFB_SECONDARY device
During teardown(), the hotplug scripts are called again for each vif. The scripts does the follow things:
i) remove the vif->IFB_PRIMARY traffic redirection
ii) remove the FORWARD->IFB_SECONDARY traffic redirection iii) remove the vif->FORWARD traffic forwarding.
iv) release the two ifb devices and the colo qdisc associated with
them
b) The checkpoint callbacks are not for each vif. So we implement it in libxl_colo_save.c
3. colo-tc: a simple command like tc, and just for the qdisc colo.
--- .gitignore | 1 + tools/hotplug/Linux/Makefile | 2 + tools/hotplug/Linux/colo-agent-setup | 210 ++++++++++++ tools/hotplug/Linux/remus-netbuf-setup | 45 +-- tools/hotplug/Linux/xen-network-ft.sh | 102 ++++++ tools/libxl/Makefile | 8 +- tools/libxl/colo-tc.c | 589 +++++++++++++++++++++++++++++++++ tools/libxl/libxl.c | 6 + tools/libxl/libxl_colo_nic.c | 289 ++++++++++++++++ tools/libxl/libxl_colo_save.c | 177 +++++++++- tools/libxl/libxl_internal.h | 8 + tools/libxl/libxl_types.idl | 1 + tools/libxl/xl_cmdimpl.c | 3 + 13 files changed, 1390 insertions(+), 51 deletions(-) create mode 100755 tools/hotplug/Linux/colo-agent-setup create mode 100644 tools/hotplug/Linux/xen-network-ft.sh create mode 100644 tools/libxl/colo-tc.c create mode 100644 tools/libxl/libxl_colo_nic.c
.gitignore +1 -0
@@ -286,6 +286,7 @@ tools/libxl/*.pyc tools/libxl/libxl-save-helper tools/libxl/test_timedereg tools/libxl/xen-init-dom0 +tools/libxl/colo-tc tools/blktap2/control/tap-ctl tools/firmware/etherboot/eb-roms.h tools/firmware/etherboot/gpxe-git-snapshot.tar.gz
tools/hotplug/Linux/Makefile +2 -0
@@ -26,12 +26,14 @@ XEN_SCRIPTS += vscsi XEN_SCRIPTS += block-iscsi XEN_SCRIPTS += block-drbd-probe XEN_SCRIPTS += $(XEN_SCRIPTS-y) +XEN_SCRIPTS += colo-agent-setup SUBDIRS-$(CONFIG_SYSTEMD) += systemd XEN_SCRIPT_DATA = xen-script-common.sh locking.sh logging.sh XEN_SCRIPT_DATA += xen-hotplug-common.sh xen-network-common.sh vif-common.sh XEN_SCRIPT_DATA += block-common.sh +XEN_SCRIPT_DATA += xen-network-ft.sh UDEV_RULES_DIR = $(CONFIG_DIR)/udev UDEV_RULES = xen-backend.rules $(UDEV_RULES-y)
tools/hotplug/Linux/colo-agent-setup new file +210 -0
210 lines not on this page · raw message
tools/hotplug/Linux/remus-netbuf-setup +3 -42
63 lines not on this page · raw message
tools/hotplug/Linux/xen-network-ft.sh new file +102 -0
102 lines not on this page · raw message
tools/libxl/Makefile +6 -2
@@ -57,7 +57,7 @@ LIBXL_OBJS-y += libxl_nonetbuffer.o endif LIBXL_OBJS-y += libxl_remus.o libxl_checkpoint_device.o libxl_remus_disk_drbd.o -LIBXL_OBJS-y += libxl_colo_restore.o libxl_colo_save.o +LIBXL_OBJS-y += libxl_colo_restore.o libxl_colo_save.o libxl_colo_nic.o LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o libxl_psr.o LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o
@@ -126,7 +126,7 @@ LIBXLU_OBJS = libxlu_cfg_y.o libxlu_cfg_l.o libxlu_cfg.o \ libxlu_disk_l.o libxlu_disk.o libxlu_vif.o libxlu_pci.o $(LIBXLU_OBJS): CFLAGS += $(CFLAGS_libxenctrl) # For xentoollog.h -CLIENTS = xl testidl libxl-save-helper xen-init-dom0 +CLIENTS = xl testidl libxl-save-helper xen-init-dom0 colo-tc CFLAGS_XL += $(CFLAGS_libxenlight) CFLAGS_XL += -Wshadow
@@ -249,6 +249,9 @@ libxl-save-helper: $(SAVE_HELPER_OBJS) libxenlight.so testidl: testidl.o libxlutil.so libxenlight.so $(CC) $(LDFLAGS) -o $@ testidl.o libxlutil.so $(LDLIBS_libxenlight) $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) +colo-tc: colo-tc.o + $(CC) $(LDFLAGS) -o $@ colo-tc.o + .PHONY: install install: all $(INSTALL_DIR) $(DESTDIR)$(SBINDIR)
@@ -259,6 +262,7 @@ install: all $(INSTALL_PROG) xl $(DESTDIR)$(SBINDIR) $(INSTALL_PROG) xen-init-dom0 $(DESTDIR)$(LIBEXEC_BIN) $(INSTALL_PROG) libxl-save-helper $(DESTDIR)$(LIBEXEC_BIN) + $(INSTALL_PROG) colo-tc $(DESTDIR)$(LIBEXEC_BIN) $(INSTALL_SHLIB) libxenlight.so.$(MAJOR).$(MINOR) $(DESTDIR)$(LIBDIR) $(SYMLINK_SHLIB) libxenlight.so.$(MAJOR).$(MINOR) $(DESTDIR)$(LIBDIR)/libxenlight.so.$(MAJOR) $(SYMLINK_SHLIB) libxenlight.so.$(MAJOR) $(DESTDIR)$(LIBDIR)/libxenlight.so
tools/libxl/colo-tc.c new file +589 -0
589 lines not on this page · raw message
tools/libxl/libxl.c +6 -0
@@ -3371,6 +3371,11 @@ void libxl__device_nic_add(libxl__egc *egc, uint32_t domid,flexarray_append (back, nic->ifname); } +if (nic->forwarddev) { +flexarray_append (back,"forwarddev" ); +flexarray_append (back, nic->forwarddev); + } +flexarray_append (back,"mac" );flexarray_append (back,libxl__sprintf (gc,LIBXL_MAC_FMT ,LIBXL_MAC_BYTES (nic->mac)));
@@ -3494,6 +3499,7 @@ static int libxl__device_nic_from_xs_be(libxl__gc *gc, nic->ip =READ_BACKEND (NOGC ,"ip" ); nic->bridge =READ_BACKEND (NOGC ,"bridge" ); nic->script =READ_BACKEND (NOGC ,"script" ); + nic->forwarddev =READ_BACKEND (NOGC ,"forwarddev" );/* vif_ioemu nics use the same xenstore entries as vif interfaces */ tmp =READ_BACKEND (gc,"type" );
tools/libxl/libxl_colo_nic.c new file +289 -0
289 lines not on this page · raw message
tools/libxl/libxl_colo_save.c +170 -7
250 lines not on this page · raw message
tools/libxl/libxl_internal.h +8 -0
@@ -2719,6 +2719,8 @@ int init_subkind_drbd_disk(libxl__checkpoint_devices_state *cds);void cleanup_subkind_drbd_disk (libxl__checkpoint_devices_state *cds);int init_subkind_blktap2_disk (libxl__checkpoint_devices_state *cds);void cleanup_subkind_blktap2_disk (libxl__checkpoint_devices_state *cds); +int init_subkind_colo_nic (libxl__checkpoint_devices_state *cds); +void cleanup_subkind_colo_nic (libxl__checkpoint_devices_state *cds); typedef void libxl__checkpoint_callback(libxl__egc *, libxl__checkpoint_devices_state *,
@@ -2834,6 +2836,7 @@ struct libxl__colo_save_state {libxl__checkpoint_devices_state cds;int send_fd;int recv_fd; +char *colo_agent_script;/* private */ libxl__datacopier_state dc;
@@ -2845,6 +2848,11 @@ struct libxl__colo_save_state {uint8_t temp_buff[9 ];void (*callback)(libxl__egc *,libxl__colo_save_state *);bool svm_running; + +/* private, used by colo-agent */ +int fd; +int vm_fd; +libxl__ev_child child; };/*----- Domain suspend (save) state structure -----*/
tools/libxl/libxl_types.idl +1 -0
@@ -514,6 +514,7 @@ libxl_device_nic = Struct("device_nic", [ ("rate_bytes_per_interval", uint64), ("rate_interval_usecs", uint32), ("gatewaydev", string), + ("forwarddev", string) ]) libxl_device_pci = Struct("device_pci", [
tools/libxl/xl_cmdimpl.c +3 -0
@@ -1615,6 +1615,9 @@ static void parse_config_data(const char *config_source, }else if (!strcmp (p,"gatewaydev" )) {free (nic->gatewaydev); nic->gatewaydev =strdup (p2 +1 ); + }else if (!strcmp (p,"forwarddev" )) { +free (nic->forwarddev); + nic->forwarddev =strdup (p2 +1 ); } }while ((p =strtok (NULL ,"," )) !=NULL ); skip_nic:
Signature · 1 line
1.9.3
RFC PATCH v4 17/18 setup and control colo-agent for secondary vm
In reply to Wen CongyangThis patch adds the machinery required for protecting a secondary vm's network device state. This patch implements the interfaces required by the checkpoint abstract device layer. A note about the implementation:
a) setup() and teardown() are called for each vif attached to the secondary vm.
During setup(), the hotplug script is called to setup COLO agent for given vif. The script does the follow things:
i) redirect vif egress traffic to the FORWARD device ii) redirect FORWARD device egress traffic to vif
During teardown(), the hotplug scripts are called again for each vif. The scripts does the follow things:
i) remove the vif->FORWARD traffic redirection
ii) remove the FORWARD->vif traffic redirection
b) Nothing should be done for secondary vm's network device.
--- tools/libxl/libxl_colo_nic.c | 23 ++++++ tools/libxl/libxl_colo_restore.c | 152 +++++++++++++++++++++++++++++++++------ tools/libxl/libxl_internal.h | 2 + 3 files changed, 157 insertions(+), 20 deletions(-)
tools/libxl/libxl_colo_nic.c +23 -0
@@ -287,3 +287,26 @@ const libxl__checkpoint_device_instance_ops colo_save_device_nic = { .setup = colo_nic_save_setup, .teardown = colo_nic_save_teardown, }; + +/* ======== secondary ======== */ +static void colo_nic_restore_setup (libxl__egc *egc, +libxl__checkpoint_device *dev) +{ +libxl__colo_restore_state *crs =CONTAINER_OF (dev->cds, *crs, cds); + +colo_nic_setup (egc, dev, secondary, crs->colo_agent_script); +} + +static void colo_nic_restore_teardown (libxl__egc *egc, +libxl__checkpoint_device *dev) +{ +libxl__colo_restore_state *crs =CONTAINER_OF (dev->cds, *crs, cds); + +colo_nic_teardown (egc, dev, secondary, crs->colo_agent_script); +} + +const libxl__checkpoint_device_instance_ops colo_restore_device_nic = { + .kind =LIBXL__DEVICE_KIND_VIF , + .setup = colo_nic_restore_setup, + .teardown = colo_nic_restore_teardown, +};
tools/libxl/libxl_colo_restore.c +132 -20
224 lines not on this page · raw message
tools/libxl/libxl_internal.h +2 -0
@@ -3188,10 +3188,12 @@ struct libxl__colo_restore_state {int pae;int superpages;libxl__colo_callback *callback; +char *colo_agent_script;/* private, colo restore checkpoint state */ libxl__domain_create_cb *saved_cb;void *crcs; +libxl__checkpoint_devices_state cds; };struct libxl__domain_create_state {
Signature · 1 line
1.9.3
RFC PATCH v4 18/18 colo: cmdline switches and config vars to control colo-agent
In reply to Wen CongyangAdd cmdline switches to 'xl migrate-receive' command to specify a domain-specific hotplug script to setup COLO agent.
Add a new config var 'colo.default.agentscript' to xl.conf, that allows the user to override the default global script used to setup COLO agent.
--- docs/man/xl.conf.pod.5 | 6 ++++++ docs/man/xl.pod.1 | 1 - tools/libxl/libxl_colo_save.c | 6 ++++++ tools/libxl/libxl_create.c | 17 +++++++++++++--- tools/libxl/libxl_internal.h | 1 + tools/libxl/libxl_types.idl | 1 + tools/libxl/xl.c | 3 +++ tools/libxl/xl.h | 1 + tools/libxl/xl_cmdimpl.c | 47 ++++++++++++++++++++++++++++++++----------- 9 files changed, 67 insertions(+), 16 deletions(-)
docs/man/xl.conf.pod.5 +6 -0
@@ -111,6 +111,12 @@ Configures the default script used by Remus to setup network buffering. Default: C</etc/xen/scripts/remus-netbuf-setup> +=item B<colo.default.agentscript="PATH"> + +Configures the default script used by COLO to setup colo-agent. + +Default: C</etc/xen/scripts/colo-agent-setup> + =item B<output_format="json|sxp"> Configures the default output format used by xl when printing "machine
docs/man/xl.pod.1 +0 -1
@@ -439,7 +439,6 @@ N.B: Remus support in xl is still in experimental (proof-of-concept) phase. Disk replication support is limited to DRBD disks. COLO support in xl is still in experimental (proof-of-concept) phase. - There is no support for network at the moment. Disk replication support is limited to blktap2 disks. B<OPTIONS>
tools/libxl/libxl_colo_save.c +6 -0
@@ -231,6 +231,12 @@ void libxl__colo_save_setup(libxl__egc *egc, libxl__colo_save_state *css) css->vm_fd =-1 ;libxl__ev_child_init (&css->child); +if (dss->remus->netbufscript) + css->colo_agent_script =libxl__strdup (gc, dss->remus->netbufscript); +else + css->colo_agent_script =GCSPRINTF ("%s/colo-agent-setup" , +libxl__xen_script_dir_path ()); + cds->device_kind_flags = (1 <<LIBXL__DEVICE_KIND_VBD ) | (1 <<LIBXL__DEVICE_KIND_VIF ); cds->ops = colo_ops;
tools/libxl/libxl_create.c +14 -3
@@ -1121,6 +1121,11 @@ static void domcreate_bootloader_done(libxl__egc *egc, crs->superpages = superpages; crs->pae = pae; crs->callback = libxl__colo_restore_setup_done; +if (dcs->colo_agent_script) + crs->colo_agent_script =libxl__strdup (gc, dcs->colo_agent_script); +else + crs->colo_agent_script =GCSPRINTF ("%s/colo-agent-setup" , +libxl__xen_script_dir_path ());libxl__colo_restore_setup (egc, crs); }else libxl__xc_domain_restore(egc, dcs,
@@ -1614,6 +1619,7 @@ static void domain_create_cb(libxl__egc *egc,static int do_domain_create (libxl_ctx *ctx,libxl_domain_config *d_config,uint32_t *domid,int restore_fd,int send_fd,int checkpointed_stream, +const char *colo_agent_script,const libxl_asyncop_how *ao_how,const libxl_asyncprogress_how *aop_console_how) {
@@ -1629,6 +1635,7 @@ static int do_domain_create(libxl_ctx *ctx, libxl_domain_config *d_config, cdcs->dcs.send_fd = send_fd; cdcs->dcs.callback = domain_create_cb; cdcs->dcs.checkpointed_stream = checkpointed_stream; + cdcs->dcs.colo_agent_script = colo_agent_script;libxl__ao_progress_gethow (&cdcs->dcs.aop_console_how, aop_console_how); cdcs->domid_out = domid;
@@ -1655,7 +1662,7 @@ int libxl_domain_create_new(libxl_ctx *ctx, libxl_domain_config *d_config,const libxl_asyncop_how *ao_how, const libxl_asyncprogress_how *aop_console_how) { - return do_domain_create(ctx, d_config, domid, -1, -1, 0, + return do_domain_create(ctx, d_config, domid, -1, -1, 0, NULL,ao_how ,aop_console_how ); }
@@ -1666,12 +1673,16 @@ int libxl_domain_create_restore(libxl_ctx *ctx, libxl_domain_config *d_config, const libxl_asyncprogress_how *aop_console_how) {int send_fd =-1 ; +char *colo_agent_script =NULL ; -if (params->checkpointed_stream ==LIBXL_CHECKPOINTED_STREAM_COLO ) +if (params->checkpointed_stream ==LIBXL_CHECKPOINTED_STREAM_COLO ) { send_fd = params->send_fd; + colo_agent_script = params->colo_agent_script; + }return do_domain_create (ctx, d_config, domid, restore_fd, send_fd, - params->checkpointed_stream, ao_how, aop_console_how); + params->checkpointed_stream, colo_agent_script, + ao_how, aop_console_how); }/*
tools/libxl/libxl_internal.h +1 -0
@@ -3208,6 +3208,7 @@ struct libxl__domain_create_state {/* private to domain_create */ int guest_domid;int checkpointed_stream; +const char *colo_agent_script;libxl__domain_build_state build_state;libxl__colo_restore_state crs;libxl__bootloader_state bl;
tools/libxl/libxl_types.idl +1 -0
@@ -347,6 +347,7 @@ libxl_domain_create_info = Struct("domain_create_info",[ libxl_domain_restore_params = Struct("domain_restore_params", [ ("checkpointed_stream", integer), ("send_fd", integer), + ("colo_agent_script", string), ]) libxl_domain_sched_params = Struct("domain_sched_params",[
tools/libxl/xl.c +3 -0
@@ -45,6 +45,7 @@ char *default_bridge = NULL;char *default_gatewaydev =NULL ;char *default_vifbackend =NULL ;char *default_remus_netbufscript =NULL ; +char *default_colo_agent_script =NULL ;enum output_format default_output_format =OUTPUT_FORMAT_JSON ;int claim_mode =1 ;bool progress_use_cr =0 ;
@@ -179,6 +180,8 @@ static void parse_global_config(const char *configfile,xlu_cfg_replace_string (config,"remus.default.netbufscript" , &default_remus_netbufscript,0 ); +xlu_cfg_replace_string (config,"colo.default.agentscript" , + &default_colo_agent_script,0 );xlu_cfg_destroy (config); }
tools/libxl/xl.h +1 -0
@@ -178,6 +178,7 @@ extern char *default_bridge;extern char *default_gatewaydev;extern char *default_vifbackend;extern char *default_remus_netbufscript; +extern char *default_colo_agent_script;extern char *blkdev_start;enum output_format {
tools/libxl/xl_cmdimpl.c +35 -12
108 lines not on this page · raw message
Signature · 1 line
1.9.3
[PATCH 19/18] Introduce "xen-load-devices-state"
In reply to Wen CongyangIntroduce a "xen-load-devices-state" QAPI command that can be used to load the state of all devices, but not the RAM or the block devices of the VM.
We only have hmp commands savevm/loadvm, and qmp commands xen-save-devices-state.
We use this new command for COLO:
1. suspend both primay vm and secondary vm
2. sync the state
3. resume both primary vm and secondary vm
In such case, we need to update all devices's state in any time.
--- qapi-schema.json | 18 ++++++++++++++++++ qmp-commands.hx | 27 +++++++++++++++++++++++++++ savevm.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+)
qapi-schema.json +18 -0
@@ -4689,3 +4689,21 @@ 'btn' : 'InputBtnEvent', 'rel' : 'InputMoveEvent', 'abs' : 'InputMoveEvent' } } + +## +# @xen-load-devices-state: +# +# Load the state of all devices from file. The RAM and the block devices +# of the VM are not loaded by this command. +# +# @filename: the file to load the state of the devices from as binary +# data. See xen-save-devices-state.txt for a description of the binary +# format. +# +# Returns: Nothing on success +# If @filename cannot be opened, OpenFileFailed +# If an I/O error occurs while reading the file, IOError +# +# Since: 2.0 +## +{ 'command': 'xen-load-devices-state', 'data': {'filename': 'str'} }
qmp-commands.hx +27 -0
@@ -586,6 +586,33 @@ Example: EQMP { + .name = "xen-load-devices-state", + .args_type = "filename:F", + .mhandler.cmd_new = qmp_marshal_input_xen_load_devices_state, + }, + +SQMP +xen-load-devices-state +------- + +Load the state of all devices from file. The RAM and the block devices +of the VM are not loaded by this command. + +Arguments: + +- "filename": the file to load the state of the devices from as binary +data. See xen-save-devices-state.txt for a description of the binary +format. + +Example: + +-> { "execute": "xen-load-devices-state", + "arguments": { "filename": "/tmp/resume" } } +<- { "return": {} } + +EQMP + + { .name = "xen-set-global-dirty-log", .args_type = "enable:b", .mhandler.cmd_new = qmp_marshal_input_xen_set_global_dirty_log,
savevm.c +36 -0
@@ -41,6 +41,7 @@#include "qemu/iov.h" #include "block/snapshot.h" #include "block/qapi.h" +#include "hw/xen/xen.h" #define SELF_ANNOUNCE_ROUNDS 5
@@ -802,6 +803,14 @@ int qemu_loadvm_state(QEMUFile *f) goto out; } +/* Validate if it is a device's state */ +if (xen_enabled () && se->is_ram) { +fprintf (stderr,"loadvm: %s RAM loading not allowed on Xen\n" , + idstr); + ret = -EINVAL ; + goto out; + } +/* Add entry */ le =g_malloc0 (sizeof (*le));
@@ -1027,6 +1036,33 @@ void qmp_xen_save_devices_state(const char *filename, Error **errp) } } +void qmp_xen_load_devices_state (const char *filename,Error **errp) +{ +QEMUFile *f; +int saved_vm_running; +int ret; + + saved_vm_running =runstate_is_running (); +vm_stop (RUN_STATE_RESTORE_VM ); + + f =qemu_fopen (filename,"rb" ); +if (!f) { +error_setg_file_open (errp, errno, filename); + goto out; + } + + ret =qemu_loadvm_state (f); +qemu_fclose (f); +if (ret <0 ) { +error_set (errp,QERR_IO_ERROR ); + } + +out: +if (saved_vm_running) { +vm_start (); + } +} +int load_vmstate (const char *name) {BlockDriverState *bs, *bs_vm_state;
Signature · 1 line
1.9.3