Prerequisite patches for COLO
cover Prerequisite patches for COLO
This patchset is Prerequisite for COLO feature. For what COLO is, refer to http://wiki.xen.org/wiki/COLO_-_Coarse_Grain_Lock_Stepping
This patchset is based on:
[PATCH v1 0/5] Misc cleanups for libxl
http://lists.xenproject.org/archives/html/xen-devel/2015-05/msg02591.html
and is taken from previous sent RFC v5 COLO patches.
You can also get the patchset from:
https://github.com/macrosheep/xen/tree/pre-colo-v1
Wen Congyang (4):
tools/libxc: support to resume uncooperative HVM guests tools/libxl: Introduce a new internal API libxl__domain_unpause() tools/libxl: Update libxl_save_msgs_gen.pl to support return data from
xl to xc
tools/libxl: Add back channel to allow migration target send data back
Yang Hongyang (8):
libxc/restore: zero ioreq page only one time
tools/libxc: export xc_bitops.h
tools/libxl: introduce a new API libxl__domain_restore() to load qemu
state
tools/libxl: Update libxl__domain_unpause() to support qemu-xen tools/libxl: introduce libxl__domain_common_switch_qemu_logdirty() tools/libxl: rename remus device to checkpoint device tools/libxl: adjust the indentation
tools/libxl: don't touch remus in checkpoint_device
tools/libxc/include/xc_bitops.h | 76 ++++++++ tools/libxc/xc_bitops.h | 76 -------- tools/libxc/xc_resume.c | 22 ++- tools/libxc/xc_sr_restore_x86_hvm.c | 3 +- tools/libxl/Makefile | 5 +- tools/libxl/libxl.c | 62 +++++-- tools/libxl/libxl_checkpoint_device.c | 282 +++++++++++++++++++++++++++++ tools/libxl/libxl_create.c | 14 +- tools/libxl/libxl_dom_restore.c | 76 ++++++++ tools/libxl/libxl_dom_save.c | 81 +++++---- tools/libxl/libxl_internal.h | 171 ++++++++++-------- tools/libxl/libxl_netbuffer.c | 117 ++++++------ tools/libxl/libxl_nonetbuffer.c | 10 +- tools/libxl/libxl_qmp.c | 10 ++ tools/libxl/libxl_remus.c | 145 ++++++++++----- tools/libxl/libxl_remus_device.c | 327 ---------------------------------- tools/libxl/libxl_remus_disk_drbd.c | 56 +++--- tools/libxl/libxl_save_callout.c | 31 ++++ tools/libxl/libxl_save_helper.c | 17 ++ tools/libxl/libxl_save_msgs_gen.pl | 65 ++++++- tools/libxl/libxl_types.idl | 11 +- tools/libxl/xl_cmdimpl.c | 7 + 22 files changed, 991 insertions(+), 673 deletions(-) create mode 100644 tools/libxc/include/xc_bitops.h delete mode 100644 tools/libxc/xc_bitops.h create mode 100644 tools/libxl/libxl_checkpoint_device.c create mode 100644 tools/libxl/libxl_dom_restore.c delete mode 100644 tools/libxl/libxl_remus_device.c
Signature · 1 line
1.9.1
PATCH 1/12 tools/libxc: support to resume uncooperative HVM guests
From: Wen Congyang <[email protected]>
For PVHVM, the hypercall return code is 0, and it can be resumed in a new domain context.
we suspend PVHVM and resume it is like this:
1. suspend it via evtchn
2. modifty the return code to 1
3. the guest know that the suspend is cancelled, we will use fast path to resume it.
Under COLO, we will update the guest's state(modify memory, cpu's registers, device status...). In this case, we cannot use the fast path to resume it. Keep the return code 0, and use a slow path to resume the guest. We have updated the guest state, so we call it a new domain context.
For HVM, the hypercall is a NOP.
--- tools/libxc/xc_resume.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-)
tools/libxc/xc_resume.c +18 -4
@@ -109,6 +109,23 @@ static int xc_domain_resume_cooperative(xc_interface *xch, uint32_t domid)return do_domctl (xch, &domctl); } +static int xc_domain_resume_hvm (xc_interface *xch,uint32_t domid) +{ +DECLARE_DOMCTL ; + +/* +* If it is PVHVM, the hypercall return code is 0, because this +* is not a fast path resume, we do not modify_returncode as in +* xc_domain_resume_cooperative. +* (resuming it in a new domain context) +* +* If it is a HVM, the hypercall is a NOP. +*/ + domctl.cmd = XEN_DOMCTL_resumedomain; + domctl.domain = domid; +return do_domctl (xch, &domctl); +} +static int xc_domain_resume_any (xc_interface *xch,uint32_t domid) {DECLARE_DOMCTL ;
@@ -138,10 +155,7 @@ static int xc_domain_resume_any(xc_interface *xch, uint32_t domid)*/ #if defined(__i386__) || defined(__x86_64__)if ( info.hvm ) - { -ERROR ("Cannot resume uncooperative HVM guests" ); -return rc; - } +return xc_domain_resume_hvm (xch, domid);if (xc_domain_get_guest_width (xch, domid, &dinfo->guest_width) !=0 ) {
Signature · 1 line
1.9.1
PATCH 2/12 libxc/restore: zero ioreq page only one time
In reply to Yang Hongyangioreq 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_sr_restore_x86_hvm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/libxc/xc_sr_restore_x86_hvm.c +2 -1
@@ -78,7 +78,8 @@ static int handle_hvm_params(struct xc_sr_context *ctx,break ;case HVM_PARAM_IOREQ_PFN :case HVM_PARAM_BUFIOREQ_PFN : -xc_clear_domain_page (xch, ctx->domid, entry->value); +if ( !ctx->restore.buffer_all_records ) +xc_clear_domain_page (xch, ctx->domid, entry->value);break ; }
Signature · 1 line
1.9.1
Re: [PATCH v1 COLO Pre 02/12] libxc/restore: zero ioreq page only one time
Quoted 11 lines · Yang Hongyang
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 cannot zero the ioreq page more than one time.
The
ioreq->stateis alwaysSTATE_IOREQ_NONEafter the vm is suspended, so it is OK if we only zero it one time.Signed-off-by Yang Hongyang <[email protected]>Signed-off-by Wen congyang <[email protected]>CC Andrew Cooper <[email protected]>
Is the qemu process for the secondary running at this point? If so, this is very much unsafe.
~Andrew
Quoted 18 lines
--- tools/libxc/xc_sr_restore_x86_hvm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)tools/libxc/xc_sr_restore_x86_hvm.c +2
-1@@ -78,7 +78,8 @@ static int handle_hvm_params(struct xc_sr_context *ctx,break ;case HVM_PARAM_IOREQ_PFN :case HVM_PARAM_BUFIOREQ_PFN : -xc_clear_domain_page (xch, ctx->domid, entry->value); +if ( !ctx->restore.buffer_all_records ) +xc_clear_domain_page (xch, ctx->domid, entry->value);break ; }
Re: [PATCH v1 COLO Pre 02/12] libxc/restore: zero ioreq page only one time
Quoted 9 lines · Andrew Cooper
Quoted 8 lines · Yang Hongyang
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 cannot zero the ioreq page more than one time.
The
ioreq->stateis alwaysSTATE_IOREQ_NONEafter the vm is suspended, so it is OK if we only zero it one time.
Quoted 6 lines
Quoted 3 lines
Signed-off-by Yang Hongyang <[email protected]>Signed-off-by Wen congyang <[email protected]>CC Andrew Cooper <[email protected]>Is the qemu process for the secondary running at this point? If so, this is very much unsafe.
No, we restore the secondary vm while it has been suspended. The problem is that: the ioreq page containes evtchn which is used by hypervisor to notify qemu. Before migration finished, we can clear it because the evtchn is invalid, and qemu will allocate it and save it in ioreq page later.
Thanks
Wen Congyang
Quoted 24 lines
~Andrew
Quoted 9 lines
--- tools/libxc/xc_sr_restore_x86_hvm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)tools/libxc/xc_sr_restore_x86_hvm.c +0
-0tools/libxc/xc_sr_restore_x86_hvm.c static int handle_hvm_params(struct xc_sr_context *ctx, · line 85
Quoted 9 lines
tools/libxc/xc_sr_restore_x86_hvm.c +2
-1@@ -78,7 +78,8 @@ static int handle_hvm_params(struct xc_sr_context *ctx,break ;case HVM_PARAM_IOREQ_PFN :case HVM_PARAM_BUFIOREQ_PFN : -xc_clear_domain_page (xch, ctx->domid, entry->value); +if ( !ctx->restore.buffer_all_records ) +xc_clear_domain_page (xch, ctx->domid, entry->value);break ; }.
PATCH 3/12 tools/libxc: export xc_bitops.h
In reply to Yang HongyangWhen we are under COLO, we will send dirty page bitmap info from secondary to primary at every checkpoint. So we need to get/test the dirty page bitmap. We just expose xc_bitops.h for libxl use.
NOTE:
Need to make clean and rerun configure to get it compiled.
--- tools/libxc/include/xc_bitops.h | 76 +++++++++++++++++++++++++++++++++++++++++ tools/libxc/xc_bitops.h | 76 ----------------------------------------- 2 files changed, 76 insertions(+), 76 deletions(-) create mode 100644 tools/libxc/include/xc_bitops.h delete mode 100644 tools/libxc/xc_bitops.h
tools/libxc/include/xc_bitops.h new file +76 -0
@@ -0,0 +1,76 @@ +#ifndef XC_BITOPS_H +#define XC_BITOPS_H 1 + +/* bitmap operations for single threaded access */ + +#include <stdlib.h> +#include <string.h> + +#define BITS_PER_LONG (sizeof(unsigned long) * 8) +#define ORDER_LONG (sizeof(unsigned long) == 4 ? 5 : 6) + +#define BITMAP_ENTRY (_nr,_bmap) ((_bmap))[(_nr)/BITS_PER_LONG] +#define BITMAP_SHIFT (_nr) ((_nr) % BITS_PER_LONG) + +/* calculate required space for number of longs needed to hold nr_bits */ +static inline int bitmap_size (int nr_bits) +{ +int nr_long, nr_bytes; + nr_long = (nr_bits +BITS_PER_LONG -1 ) >>ORDER_LONG ; + nr_bytes = nr_long *sizeof (unsigned long ); +return nr_bytes; +} + +static inline unsigned long *bitmap_alloc (int nr_bits) +{ +return calloc (1 ,bitmap_size (nr_bits)); +} + +static inline void bitmap_set (unsigned long *addr,int nr_bits) +{ +memset (addr,0xff ,bitmap_size (nr_bits)); +} + +static inline void bitmap_clear (unsigned long *addr,int nr_bits) +{ +memset (addr,0 ,bitmap_size (nr_bits)); +} + +static inline int test_bit (int nr,unsigned long *addr) +{ +return (BITMAP_ENTRY (nr, addr) >>BITMAP_SHIFT (nr)) &1 ; +} + +static inline void clear_bit (int nr,unsigned long *addr) +{ +BITMAP_ENTRY (nr, addr) &= ~(1UL <<BITMAP_SHIFT (nr)); +} + +static inline void set_bit (int nr,unsigned long *addr) +{ +BITMAP_ENTRY (nr, addr) |= (1UL <<BITMAP_SHIFT (nr)); +} + +static inline int test_and_clear_bit (int nr,unsigned long *addr) +{ +int oldbit =test_bit (nr, addr); +clear_bit (nr, addr); +return oldbit; +} + +static inline int test_and_set_bit (int nr,unsigned long *addr) +{ +int oldbit =test_bit (nr, addr); +set_bit (nr, addr); +return oldbit; +} + +static inline void bitmap_or (unsigned long *dst,const unsigned long *other, +int nr_bits) +{ +int i, nr_longs = (bitmap_size (nr_bits) /sizeof (unsigned long )); +for ( i =0 ; i < nr_longs; ++i ) + dst[i] |= other[i]; +} + +#endif /* XC_BITOPS_H */
tools/libxc/xc_bitops.h deleted +0 -76
76 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [PATCH v1 COLO Pre 03/12] tools/libxc: export xc_bitops.h
Quoted 8 lines · Yang Hongyang
When we are under COLO, we will send dirty page bitmap info from secondary to primary at every checkpoint. So we need to get/test the dirty page bitmap. We just expose
xc_bitops.hfor libxl use.NOTE:
Need to make clean and rerun configure to get it compiled.Signed-off-by Yang Hongyang <[email protected]>
I like this change, but lets take the opportunity to fix some of the issues in it.
Quoted 13 lines
--- tools/libxc/include/xc_bitops.h | 76 +++++++++++++++++++++++++++++++++++++++++ tools/libxc/xc_bitops.h | 76 ----------------------------------------- 2 files changed, 76 insertions(+), 76 deletions(-) create mode 100644 tools/libxc/include/xc_bitops.h delete mode 100644 tools/libxc/xc_bitops.htools/libxc/include/xc_bitops.h new file +0
-0
tools/libxc/include/xc_bitops.h line 2
Quoted 2 lines
tools/libxc/include/xc_bitops.h new file +2
-0@@ -0,0 +1,76 @@ +#ifndef XC_BITOPS_H +#define XC_BITOPS_H 1
No need for a 1 here
tools/libxc/include/xc_bitops.h line 9
Quoted 7 lines
tools/libxc/include/xc_bitops.h new file +7
-0+ +/* bitmap operations for single threaded access */ + +#include <stdlib.h> +#include <string.h> + +#define BITS_PER_LONG (sizeof(unsigned long) * 8)
All defines like this need XC_ prefixes, and CHAR_BIT should be used in preference to 8.
tools/libxc/include/xc_bitops.h line 10
Quoted 1 line
tools/libxc/include/xc_bitops.h new file +1
-0+#define ORDER_LONG (sizeof(unsigned long) == 4 ? 5 : 6)
This name is misleading, as it is in terms of bits not bytes. XC_BITMAP_SHIFT perhaps?
tools/libxc/include/xc_bitops.h line 13
Quoted 3 lines
tools/libxc/include/xc_bitops.h new file +3
-0+ +#define BITMAP_ENTRY (_nr,_bmap) ((_bmap))[(_nr)/BITS_PER_LONG] +#define BITMAP_SHIFT (_nr) ((_nr) % BITS_PER_LONG)
I would recommend dropping these and open coding the few cases below. It would be far more clear.
tools/libxc/include/xc_bitops.h line 16
Quoted 3 lines
tools/libxc/include/xc_bitops.h new file +3
-0+ +/* calculate required space for number of longs needed to hold nr_bits */ +static inline int bitmap_size (int nr_bits)
"int" has been inappropriate everywhere in this file. unsigned long please (or settle on unsigned int everywhere)
tools/libxc/include/xc_bitops.h line 19
Quoted 3 lines
tools/libxc/include/xc_bitops.h new file +3
-0+{ +int nr_long, nr_bytes; + nr_long = (nr_bits +BITS_PER_LONG -1 ) >>ORDER_LONG ;
This calculation can overflow.
(nr_bits >> ORDER_LONG) + !!(nr_bits % BITS_PER_LONG)
Quoted 10 lines
tools/libxc/include/xc_bitops.h new file +10
-0+ nr_bytes = nr_long *sizeof (unsigned long ); +return nr_bytes; +} + +static inline unsigned long *bitmap_alloc (int nr_bits) +{ +return calloc (1 ,bitmap_size (nr_bits)); +} + +static inline void bitmap_set (unsigned long *addr,int nr_bits)
tools/libxc/include/xc_bitops.h line 39
Quoted 10 lines
tools/libxc/include/xc_bitops.h new file +10
-0+{ +memset (addr,0xff ,bitmap_size (nr_bits)); +} + +static inline void bitmap_clear (unsigned long *addr,int nr_bits) +{ +memset (addr,0 ,bitmap_size (nr_bits)); +} + +static inline int test_bit (int nr,unsigned long *addr)
const *addr, as this is a read-only operation.
tools/libxc/include/xc_bitops.h line 52
Quoted 13 lines
tools/libxc/include/xc_bitops.h new file +13
-0+{ +return (BITMAP_ENTRY (nr, addr) >>BITMAP_SHIFT (nr)) &1 ; +} + +static inline void clear_bit (int nr,unsigned long *addr) +{ +BITMAP_ENTRY (nr, addr) &= ~(1UL <<BITMAP_SHIFT (nr)); +} + +static inline void set_bit (int nr,unsigned long *addr) +{ +BITMAP_ENTRY (nr, addr) |= (1UL <<BITMAP_SHIFT (nr)); +}
It would be nice to be consistent on whether the bitmap pointer or the bit is the first parameter. Perhaps a second cleanup patch which makes this consistent and adjusts all current callers.
~Andrew
Quoted 106 lines
tools/libxc/include/xc_bitops.h new file +24
-0+ +static inline int test_and_clear_bit (int nr,unsigned long *addr) +{ +int oldbit =test_bit (nr, addr); +clear_bit (nr, addr); +return oldbit; +} + +static inline int test_and_set_bit (int nr,unsigned long *addr) +{ +int oldbit =test_bit (nr, addr); +set_bit (nr, addr); +return oldbit; +} + +static inline void bitmap_or (unsigned long *dst,const unsigned long *other, +int nr_bits) +{ +int i, nr_longs = (bitmap_size (nr_bits) /sizeof (unsigned long )); +for ( i =0 ; i < nr_longs; ++i ) + dst[i] |= other[i]; +} + +#endif /* XC_BITOPS_H */ tools/libxc/xc_bitops.h deleted +0
-76@@ -1,76 +0,0 @@ -#ifndef XC_BITOPS_H -#define XC_BITOPS_H 1 - -/* bitmap operations for single threaded access */ - -#include <stdlib.h> -#include <string.h> - -#define BITS_PER_LONG (sizeof(unsigned long) * 8) -#define ORDER_LONG (sizeof(unsigned long) == 4 ? 5 : 6) - -#define BITMAP_ENTRY (_nr,_bmap) ((_bmap))[(_nr)/BITS_PER_LONG] -#define BITMAP_SHIFT (_nr) ((_nr) % BITS_PER_LONG) - -/* calculate required space for number of longs needed to hold nr_bits */ -static inline int bitmap_size (int nr_bits) -{ -int nr_long, nr_bytes; - nr_long = (nr_bits +BITS_PER_LONG -1 ) >>ORDER_LONG ; - nr_bytes = nr_long *sizeof (unsigned long ); -return nr_bytes; -} - -static inline unsigned long *bitmap_alloc (int nr_bits) -{ -return calloc (1 ,bitmap_size (nr_bits)); -} - -static inline void bitmap_set (unsigned long *addr,int nr_bits) -{ -memset (addr,0xff ,bitmap_size (nr_bits)); -} - -static inline void bitmap_clear (unsigned long *addr,int nr_bits) -{ -memset (addr,0 ,bitmap_size (nr_bits)); -} - -static inline int test_bit (int nr,unsigned long *addr) -{ -return (BITMAP_ENTRY (nr, addr) >>BITMAP_SHIFT (nr)) &1 ; -} - -static inline void clear_bit (int nr,unsigned long *addr) -{ -BITMAP_ENTRY (nr, addr) &= ~(1UL <<BITMAP_SHIFT (nr)); -} - -static inline void set_bit (int nr,unsigned long *addr) -{ -BITMAP_ENTRY (nr, addr) |= (1UL <<BITMAP_SHIFT (nr)); -} - -static inline int test_and_clear_bit (int nr,unsigned long *addr) -{ -int oldbit =test_bit (nr, addr); -clear_bit (nr, addr); -return oldbit; -} - -static inline int test_and_set_bit (int nr,unsigned long *addr) -{ -int oldbit =test_bit (nr, addr); -set_bit (nr, addr); -return oldbit; -} - -static inline void bitmap_or (unsigned long *dst,const unsigned long *other, -int nr_bits) -{ -int i, nr_longs = (bitmap_size (nr_bits) /sizeof (unsigned long )); -for ( i =0 ; i < nr_longs; ++i ) - dst[i] |= other[i]; -} - -#endif /* XC_BITOPS_H */
Re: [PATCH v1 COLO Pre 03/12] tools/libxc: export xc_bitops.h
Quoted 5 lines · Andrew Cooper
Quoted 4 lines · Yang Hongyang
When we are under COLO, we will send dirty page bitmap info from secondary to primary at every checkpoint. So we need to get/test the dirty page bitmap. We just expose
xc_bitops.hfor libxl use.
Quoted 7 lines
Quoted 4 lines
NOTE:
Need to make clean and rerun configure to get it compiled.Signed-off-by Yang Hongyang <[email protected]>I like this change, but lets take the opportunity to fix some of the issues in it.
Thanks, will fix in next version.
Quoted 209 lines
Quoted 14 lines
--- tools/libxc/include/xc_bitops.h | 76 +++++++++++++++++++++++++++++++++++++++++ tools/libxc/xc_bitops.h | 76 ----------------------------------------- 2 files changed, 76 insertions(+), 76 deletions(-)create mode 100644
tools/libxc/include/xc_bitops.hdelete mode 100644tools/libxc/xc_bitops.htools/libxc/include/xc_bitops.h new file +0
-0tools/libxc/include/xc_bitops.h line 2
Quoted 2 lines
tools/libxc/include/xc_bitops.h new file +2
-0@@ -0,0 +1,76 @@ +#ifndef XC_BITOPS_H +#define XC_BITOPS_H 1No need for a 1 here
tools/libxc/include/xc_bitops.h line 9
Quoted 7 lines
tools/libxc/include/xc_bitops.h new file +7
-0+ +/* bitmap operations for single threaded access */ + +#include <stdlib.h> +#include <string.h> + +#define BITS_PER_LONG (sizeof(unsigned long) * 8)All defines like this need
XC_prefixes, andCHAR_BITshould be used in preference to 8.tools/libxc/include/xc_bitops.h line 10
Quoted 1 line
tools/libxc/include/xc_bitops.h new file +1
-0+#define ORDER_LONG (sizeof(unsigned long) == 4 ? 5 : 6)This name is misleading, as it is in terms of bits not bytes.
XC_BITMAP_SHIFTperhaps?tools/libxc/include/xc_bitops.h line 13
Quoted 3 lines
tools/libxc/include/xc_bitops.h new file +3
-0+ +#define BITMAP_ENTRY (_nr,_bmap) ((_bmap))[(_nr)/BITS_PER_LONG] +#define BITMAP_SHIFT (_nr) ((_nr) % BITS_PER_LONG)I would recommend dropping these and open coding the few cases below. It would be far more clear.
tools/libxc/include/xc_bitops.h line 16
Quoted 3 lines
tools/libxc/include/xc_bitops.h new file +3
-0+ +/* calculate required space for number of longs needed to hold nr_bits */ +static inline int bitmap_size (int nr_bits)"int" has been inappropriate everywhere in this file. unsigned long please (or settle on unsigned int everywhere)
tools/libxc/include/xc_bitops.h line 19
Quoted 3 lines
tools/libxc/include/xc_bitops.h new file +3
-0+{ +int nr_long, nr_bytes; + nr_long = (nr_bits +BITS_PER_LONG -1 ) >>ORDER_LONG ;This calculation can overflow.
(
nr_bits>>ORDER_LONG) + !!(nr_bits %BITS_PER_LONG)Quoted 10 lines
tools/libxc/include/xc_bitops.h new file +10
-0+ nr_bytes = nr_long *sizeof (unsigned long ); +return nr_bytes; +} + +static inline unsigned long *bitmap_alloc (int nr_bits) +{ +return calloc (1 ,bitmap_size (nr_bits)); +} + +static inline void bitmap_set (unsigned long *addr,int nr_bits)tools/libxc/include/xc_bitops.h line 39
Quoted 10 lines
tools/libxc/include/xc_bitops.h new file +10
-0+{ +memset (addr,0xff ,bitmap_size (nr_bits)); +} + +static inline void bitmap_clear (unsigned long *addr,int nr_bits) +{ +memset (addr,0 ,bitmap_size (nr_bits)); +} + +static inline int test_bit (int nr,unsigned long *addr)const *addr, as this is a read-only operation.
tools/libxc/include/xc_bitops.h line 52
Quoted 13 lines
tools/libxc/include/xc_bitops.h new file +13
-0+{ +return (BITMAP_ENTRY (nr, addr) >>BITMAP_SHIFT (nr)) &1 ; +} + +static inline void clear_bit (int nr,unsigned long *addr) +{ +BITMAP_ENTRY (nr, addr) &= ~(1UL <<BITMAP_SHIFT (nr)); +} + +static inline void set_bit (int nr,unsigned long *addr) +{ +BITMAP_ENTRY (nr, addr) |= (1UL <<BITMAP_SHIFT (nr)); +}It would be nice to be consistent on whether the bitmap pointer or the bit is the first parameter. Perhaps a second cleanup patch which makes this consistent and adjusts all current callers.
~Andrew
Quoted 96 lines
tools/libxc/include/xc_bitops.h new file +24
-0+ +static inline int test_and_clear_bit (int nr,unsigned long *addr) +{ +int oldbit =test_bit (nr, addr); +clear_bit (nr, addr); +return oldbit; +} + +static inline int test_and_set_bit (int nr,unsigned long *addr) +{ +int oldbit =test_bit (nr, addr); +set_bit (nr, addr); +return oldbit; +} + +static inline void bitmap_or (unsigned long *dst,const unsigned long *other, +int nr_bits) +{ +int i, nr_longs = (bitmap_size (nr_bits) /sizeof (unsigned long )); +for ( i =0 ; i < nr_longs; ++i ) + dst[i] |= other[i]; +} + +#endif /* XC_BITOPS_H */ tools/libxc/xc_bitops.h deleted +0
-66@@ -1,76 +0,0 @@ -#ifndef XC_BITOPS_H -#define XC_BITOPS_H 1 - -/* bitmap operations for single threaded access */ - -#include <stdlib.h> -#include <string.h> - -#define BITS_PER_LONG (sizeof(unsigned long) * 8) -#define ORDER_LONG (sizeof(unsigned long) == 4 ? 5 : 6) - -#define BITMAP_ENTRY (_nr,_bmap) ((_bmap))[(_nr)/BITS_PER_LONG] -#define BITMAP_SHIFT (_nr) ((_nr) % BITS_PER_LONG) - -/* calculate required space for number of longs needed to hold nr_bits */ -static inline int bitmap_size (int nr_bits) -{ -int nr_long, nr_bytes; - nr_long = (nr_bits +BITS_PER_LONG -1 ) >>ORDER_LONG ; - nr_bytes = nr_long *sizeof (unsigned long ); -return nr_bytes; -} - -static inline unsigned long *bitmap_alloc (int nr_bits) -{ -return calloc (1 ,bitmap_size (nr_bits)); -} - -static inline void bitmap_set (unsigned long *addr,int nr_bits) -{ -memset (addr,0xff ,bitmap_size (nr_bits)); -} - -static inline void bitmap_clear (unsigned long *addr,int nr_bits) -{ -memset (addr,0 ,bitmap_size (nr_bits)); -} - -static inline int test_bit (int nr,unsigned long *addr) -{ -return (BITMAP_ENTRY (nr, addr) >>BITMAP_SHIFT (nr)) &1 ; -} - -static inline void clear_bit (int nr,unsigned long *addr) -{ -BITMAP_ENTRY (nr, addr) &= ~(1UL <<BITMAP_SHIFT (nr)); -} - -static inline void set_bit (int nr,unsigned long *addr) -{ -BITMAP_ENTRY (nr, addr) |= (1UL <<BITMAP_SHIFT (nr)); -} - -static inline int test_and_clear_bit (int nr,unsigned long *addr) -{ -int oldbit =test_bit (nr, addr); -clear_bit (nr, addr); -return oldbit; -} - -static inline int test_and_set_bit (int nr,unsigned long *addr) -{ -int oldbit =test_bit (nr, addr); -set_bit (nr, addr); -return oldbit; -}tools/libxc/xc_bitops.h line 76
Quoted 10 lines
tools/libxc/xc_bitops.h deleted +0
-10- -static inline void bitmap_or (unsigned long *dst,const unsigned long *other, -int nr_bits) -{ -int i, nr_longs = (bitmap_size (nr_bits) /sizeof (unsigned long )); -for ( i =0 ; i < nr_longs; ++i ) - dst[i] |= other[i]; -} - -#endif /* XC_BITOPS_H */ .
Signature · 2 lines
Thanks, Yang.
Re: [PATCH v1 COLO Pre 03/12] tools/libxc: export xc_bitops.h
Quoted 10 lines · Yang Hongyang
Quoted 8 lines · Andrew Cooper
Quoted 7 lines · Yang Hongyang
When we are under COLO, we will send dirty page bitmap info from secondary to primary at every checkpoint. So we need to get/test the dirty page bitmap. We just expose
xc_bitops.hfor libxl use.NOTE:
Need to make clean and rerun configure to get it compiled.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Yang Hongyang <[email protected]>I like this change, but lets take the opportunity to fix some of the issues in it.
Thanks, will fix in next version.
Please do fix and move in two separate patches, probably fix first although I don't mind overall.
Ian.
Re: [PATCH v1 COLO Pre 03/12] tools/libxc: export xc_bitops.h
Quoted 13 lines · Ian Campbell
Quoted 12 lines · Yang Hongyang
Quoted 10 lines · Andrew Cooper
Quoted 8 lines · Yang Hongyang
When we are under COLO, we will send dirty page bitmap info from secondary to primary at every checkpoint. So we need to get/test the dirty page bitmap. We just expose
xc_bitops.hfor libxl use.NOTE:
Need to make clean and rerun configure to get it compiled.Signed-off-by Yang Hongyang <[email protected]>
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
I like this change, but lets take the opportunity to fix some of the issues in it.
Thanks, will fix in next version.
Please do fix and move in two separate patches, probably fix first although I don't mind overall.
Sure, will do.
Quoted 5 lines
Ian.
.
Signature · 2 lines
Thanks, Yang.
PATCH 4/12 tools/libxl: introduce a new API libxl__domain_restore() to load qemu state
In reply to Yang HongyangSecondary vm is running in colo mode. So we will do the following things again and again:
1. suspend both primay vm and secondary vm
2. sync the state
3. resume both primary vm and secondary vm
We will send qemu's state each time in step2, and slave's qemu should read it each time before resuming secondary vm. Introduce a new API libxl__domain_restore() to do it. This API should be called before resuming secondary vm.
--- tools/libxl/Makefile | 3 +- tools/libxl/libxl_dom_restore.c | 76 +++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_internal.h | 4 +++ tools/libxl/libxl_qmp.c | 10 ++++++ 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 tools/libxl/libxl_dom_restore.c
tools/libxl/Makefile +2 -1
@@ -96,7 +96,8 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \ libxl_json.o libxl_aoutils.o libxl_numa.o libxl_vnuma.o \ libxl_save_callout.o _libxl_save_msgs_callout.o \ libxl_qmp.o libxl_event.o libxl_fork.o libxl_dom_suspend.o \ - libxl_toolstack.o libxl_dom_save.o $(LIBXL_OBJS-y) + libxl_toolstack.o libxl_dom_save.o libxl_dom_restore.o \ + $(LIBXL_OBJS-y) LIBXL_OBJS += libxl_genid.o LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o
tools/libxl/libxl_dom_restore.c new file +76 -0
76 lines not on this page · raw message
tools/libxl/libxl_internal.h +4 -0
@@ -1022,6 +1022,7 @@ _hidden int libxl__domain_rename(libxl__gc *gc, uint32_t domid, _hidden int libxl__toolstack_restore(uint32_t domid, const uint8_t *buf,uint32_t size,void *data); +_hidden int libxl__domain_restore_device_model(libxl__gc *gc, uint32_t domid); _hidden int libxl__domain_resume_device_model(libxl__gc *gc, uint32_t domid); _hidden const char *libxl__userdata_path(libxl__gc *gc, uint32_t domid,
@@ -1039,6 +1040,7 @@ _hidden int libxl__userdata_store(libxl__gc *gc, uint32_t domid,const char *userdata_userid, const uint8_t *data, int datalen); +_hidden int libxl__domain_restore(libxl__gc *gc, uint32_t domid); _hidden int libxl__domain_resume(libxl__gc *gc, uint32_t domid,int suspend_cancel);
@@ -1650,6 +1652,8 @@ _hidden int libxl__qmp_stop(libxl__gc *gc, int domid); _hidden int libxl__qmp_resume(libxl__gc *gc, int domid);/* Save current QEMU state into fd. */ _hidden int libxl__qmp_save(libxl__gc *gc, int domid, const char *filename); +/* Load current QEMU state from fd. */ +_hidden int libxl__qmp_restore(libxl__gc *gc, int domid, const char *filename);/* Set dirty bitmap logging status */ _hidden int libxl__qmp_set_global_dirty_log(libxl__gc *gc, int domid, bool enable); _hidden int libxl__qmp_insert_cdrom(libxl__gc *gc, int domid, const libxl_device_disk *disk);
tools/libxl/libxl_qmp.c +10 -0
@@ -892,6 +892,16 @@ int libxl__qmp_save(libxl__gc *gc, int domid, const char *filename) NULL, NULL); } +int libxl__qmp_restore (libxl__gc *gc,int domid,const char *state_file) +{ +libxl__json_object *args =NULL ; + +qmp_parameters_add_string (gc, &args,"filename" , state_file); + +return qmp_run_command (gc, domid,"xen-load-devices-state" , args, +NULL ,NULL ); +} +static int qmp_change (libxl__gc *gc,libxl__qmp_handler *qmp,char *device,char *target,char *arg) {
Signature · 1 line
1.9.1
Re: [PATCH v1 COLO Pre 04/12] tools/libxl: introduce a new API libxl__domain_restore() to load qemu state
Quoted 152 lines · Yang Hongyang
Secondary vm is running in colo mode. So we will do the following things again and again:
1. suspend both primay vm and secondary vm
2. sync the state
3. resume both primary vm and secondary vm
We will send qemu's state each time in step2, and slave's qemu should read it each time before resuming secondary vm. Introduce a new APIlibxl__domain_restore()to do it. This API should be called before resuming secondary vm.Signed-off-by Yang Hongyang <[email protected]>Signed-off-by Wen Congyang <[email protected]>--- tools/libxl/Makefile | 3 +- tools/libxl/libxl_dom_restore.c | 76 +++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_internal.h | 4 +++ tools/libxl/libxl_qmp.c | 10 ++++++ 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 tools/libxl/libxl_dom_restore.ctools/libxl/Makefile +2
-1@@ -96,7 +96,8 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \ libxl_json.o libxl_aoutils.o libxl_numa.o libxl_vnuma.o \ libxl_save_callout.o _libxl_save_msgs_callout.o \ libxl_qmp.o libxl_event.o libxl_fork.o libxl_dom_suspend.o \ - libxl_toolstack.o libxl_dom_save.o $(LIBXL_OBJS-y) + libxl_toolstack.o libxl_dom_save.o libxl_dom_restore.o \ + $(LIBXL_OBJS-y) LIBXL_OBJS += libxl_genid.o LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.otools/libxl/libxl_dom_restore.c new file +76
-0@@ -0,0 +1,76 @@ +/* +* Copyright (C) 2015 FUJITSU LIMITED +* Author Yang Hongyang <[email protected]> +* 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 and later. 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. +*/ + +#include "libxl_osdeps.h" /* must come before any other headers */ + +#include "libxl_internal.h" + +/*----- main code for restoring, in order of execution -----*/ + +int libxl__domain_restore (libxl__gc *gc,uint32_t domid) +{ +int rc =0 ; + +libxl_domain_type type =libxl__domain_type (gc, domid); +if (type !=LIBXL_DOMAIN_TYPE_HVM ) { + rc =ERROR_FAIL ; + goto out; + } + + rc =libxl__domain_restore_device_model (gc, domid); +if (rc) +LOG (ERROR ,"failed to restore device mode for domain %u:%d" , + domid, rc); +out: +return rc; +} + +int libxl__domain_restore_device_model (libxl__gc *gc,uint32_t domid) +{ +char *state_file; +int rc; + +switch (libxl__device_model_version_running (gc, domid)) { +case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL : +/* not supported now */ + rc =ERROR_INVAL ; +break ; +case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN : +/* +* This function may be called too many times for the same gc, +* so we use NOGC, and free the memory before return to avoid +* OOM. +*/ + state_file =libxl__sprintf (NOGC , +XC_DEVICE_MODEL_RESTORE_FILE ".%d" , + domid); + rc =libxl__qmp_restore (gc, domid, state_file); +free (state_file); +break ; +default : + rc =ERROR_INVAL ; + } + +return rc; +} + +/* +* Local variables: +* mode: C +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ tools/libxl/libxl_internal.h +4
-0@@ -1022,6 +1022,7 @@ _hidden int libxl__domain_rename(libxl__gc *gc, uint32_t domid, _hidden int libxl__toolstack_restore(uint32_t domid, const uint8_t *buf,uint32_t size,void *data); +_hidden int libxl__domain_restore_device_model(libxl__gc *gc, uint32_t domid); _hidden int libxl__domain_resume_device_model(libxl__gc *gc, uint32_t domid); _hidden const char *libxl__userdata_path(libxl__gc *gc, uint32_t domid,@@ -1039,6 +1040,7 @@ _hidden int libxl__userdata_store(libxl__gc *gc, uint32_t domid,const char *userdata_userid, const uint8_t *data, int datalen); +_hidden int libxl__domain_restore(libxl__gc *gc, uint32_t domid); _hidden int libxl__domain_resume(libxl__gc *gc, uint32_t domid,int suspend_cancel);@@ -1650,6 +1652,8 @@ _hidden int libxl__qmp_stop(libxl__gc *gc, int domid); _hidden int libxl__qmp_resume(libxl__gc *gc, int domid);/* Save current QEMU state into fd. */ _hidden int libxl__qmp_save(libxl__gc *gc, int domid, const char *filename); +/* Load current QEMU state from fd. */ +_hidden int libxl__qmp_restore(libxl__gc *gc, int domid, const char *filename);/* Set dirty bitmap logging status */ _hidden int libxl__qmp_set_global_dirty_log(libxl__gc *gc, int domid, bool enable); _hidden int libxl__qmp_insert_cdrom(libxl__gc *gc, int domid, const libxl_device_disk *disk);tools/libxl/libxl_qmp.c +0
-0@@ -892,6 +892,16 @@ int libxl__qmp_save(libxl__gc *gc, int domid, const char *filename) NULL, NULL);
tools/libxl/libxl_qmp.c int libxl__qmp_save(libxl__gc *gc, int domid, const char *filename) · line 902
Quoted 10 lines
tools/libxl/libxl_qmp.c +8
-0} +int libxl__qmp_restore (libxl__gc *gc,int domid,const char *state_file) +{ +libxl__json_object *args =NULL ; + +qmp_parameters_add_string (gc, &args,"filename" , state_file); + +return qmp_run_command (gc, domid,"xen-load-devices-state" , args, +NULL ,NULL );
IIRC, this is a new qmp command. Post the patch for qemu together?
Thanks
Wen Congyang
Quoted 6 lines
tools/libxl/libxl_qmp.c +2
-0+} +static int qmp_change (libxl__gc *gc,libxl__qmp_handler *qmp,char *device,char *target,char *arg) {
Re: [PATCH v1 COLO Pre 04/12] tools/libxl: introduce a new API libxl__domain_restore() to load qemu state
Quoted 1 line · Wen Congyang
On 06/02/2015 05:26 PM, Yang Hongyang wrote:
[...]
Quoted 11 lines
tools/libxl/libxl_qmp.c int libxl__qmp_save(libxl__gc *gc, int domid, const char *filename) · line 902
Quoted 9 lines
tools/libxl/libxl_qmp.c +8
-0+int libxl__qmp_restore (libxl__gc *gc,int domid,const char *state_file) +{ +libxl__json_object *args =NULL ; + +qmp_parameters_add_string (gc, &args,"filename" , state_file); + +return qmp_run_command (gc, domid,"xen-load-devices-state" , args, +NULL ,NULL );IIRC, this is a new qmp command. Post the patch for qemu together?
Sure, will post it to qemu upstream.
Quoted 13 lines
Thanks
Wen Congyangtools/libxl/libxl_qmp.c int libxl__qmp_save(libxl__gc *gc, int domid, const char *filename) · line 907
Quoted 6 lines
tools/libxl/libxl_qmp.c +2
-0+} +static int qmp_change (libxl__gc *gc,libxl__qmp_handler *qmp,char *device,char *target,char *arg) {.
Signature · 2 lines
Thanks, Yang.
PATCH 5/12 tools/libxl: Introduce a new internal API libxl__domain_unpause()
In reply to Yang HongyangFrom: Wen Congyang <[email protected]>
The guest is paused after libxl_domain_create_restore(). Secondary vm is running in colo mode. So we need to unpause the guest. The current API libxl_domain_unpause() is not an internal API. Introduce a new API to support it. No functional change.
--- tools/libxl/libxl.c | 20 ++++++++++++++------ tools/libxl/libxl_internal.h | 1 + 2 files changed, 15 insertions(+), 6 deletions(-)
tools/libxl/libxl.c +14 -6
@@ -966,9 +966,8 @@ out:return AO_INPROGRESS ; } -int libxl_domain_unpause (libxl_ctx *ctx,uint32_t domid) +int libxl__domain_unpause (libxl__gc *gc,uint32_t domid) { -GC_INIT (ctx);char *path;char *state;int ret, rc =0 ;
@@ -980,7 +979,7 @@ int libxl_domain_unpause(libxl_ctx *ctx, uint32_t domid) }if (type ==LIBXL_DOMAIN_TYPE_HVM ) { -uint32_t dm_domid =libxl_get_stubdom_id (ctx, domid); +uint32_t dm_domid =libxl_get_stubdom_id (CTX , domid); path =libxl__device_model_xs_path (gc, dm_domid, domid,"/state" ); state =libxl__xs_read (gc,XBT_NULL , path);
@@ -990,12 +989,21 @@ int libxl_domain_unpause(libxl_ctx *ctx, uint32_t domid) NULL, NULL, NULL); } } - ret =xc_domain_unpause (ctx->xch, domid); -if (ret<0 ) { -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"unpausing domain %d" , domid); + + ret =xc_domain_unpause (CTX ->xch, domid); +if (ret <0 ) { +LIBXL__LOG_ERRNO (CTX ,LIBXL__LOG_ERROR ,"unpausing domain %d" , domid); rc =ERROR_FAIL ; } out: +return rc; +} + +int libxl_domain_unpause (libxl_ctx *ctx,uint32_t domid) +{ +GC_INIT (ctx); +int rc =libxl__domain_unpause (gc, domid); +GC_FREE ;return rc; }
tools/libxl/libxl_internal.h +1 -0
@@ -1043,6 +1043,7 @@ _hidden int libxl__userdata_store(libxl__gc *gc, uint32_t domid, _hidden int libxl__domain_restore(libxl__gc *gc, uint32_t domid); _hidden int libxl__domain_resume(libxl__gc *gc, uint32_t domid,int suspend_cancel); +_hidden int libxl__domain_unpause(libxl__gc *gc, uint32_t domid);/* returns 0 or 1, or a libxl error code */ _hidden int libxl__domain_pvcontrol_available(libxl__gc *gc, uint32_t domid);
Signature · 1 line
1.9.1
PATCH 6/12 tools/libxl: Update libxl__domain_unpause() to support qemu-xen
In reply to Yang HongyangCurrently, libxl__domain_unpause() only supports qemu-xen-traditional. Update it to support qemu-xen.
--- tools/libxl/libxl.c | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-)
tools/libxl/libxl.c +33 -9
@@ -966,10 +966,37 @@ out:return AO_INPROGRESS ; } -int libxl__domain_unpause (libxl__gc *gc,uint32_t domid) +static int libxl__domain_unpause_device_model (libxl__gc *gc,uint32_t domid) {char *path;char *state; + +switch (libxl__device_model_version_running (gc, domid)) { +case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL : { +uint32_t dm_domid =libxl_get_stubdom_id (CTX , domid); + + path =libxl__device_model_xs_path (gc, dm_domid, domid,"/state" ); + state =libxl__xs_read (gc,XBT_NULL , path); +if (state !=NULL && !strcmp (state,"paused" )) { +libxl__qemu_traditional_cmd (gc, domid,"continue" ); +libxl__wait_for_device_model_deprecated (gc, domid,"running" , +NULL ,NULL ,NULL ); + } +break ; + } +case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN : +if (libxl__qmp_resume (gc, domid)) +return ERROR_FAIL ; +break ; +default : +return ERROR_INVAL ; + } + +return 0 ; +} + +int libxl__domain_unpause (libxl__gc *gc,uint32_t domid) +{int ret, rc =0 ;libxl_domain_type type =libxl__domain_type (gc, domid);
@@ -979,14 +1006,11 @@ int libxl__domain_unpause(libxl__gc *gc, uint32_t domid) }if (type ==LIBXL_DOMAIN_TYPE_HVM ) { -uint32_t dm_domid =libxl_get_stubdom_id (CTX , domid); - - path =libxl__device_model_xs_path (gc, dm_domid, domid,"/state" ); - state =libxl__xs_read (gc,XBT_NULL , path); -if (state !=NULL && !strcmp (state,"paused" )) { -libxl__qemu_traditional_cmd (gc, domid,"continue" ); -libxl__wait_for_device_model_deprecated (gc, domid,"running" , -NULL ,NULL ,NULL ); + rc =libxl__domain_unpause_device_model (gc, domid); +if (rc <0 ) { +LOG (ERROR ,"failed to unpause device model for domain %u:%d" , + domid, rc); + goto out; } }
Signature · 1 line
1.9.1
PATCH 7/12 tools/libxl: introduce libxl__domain_common_switch_qemu_logdirty()
In reply to Yang HongyangSecondary vm is running in colo mode, we need to send secondary vm's dirty page information to master at checkpoint, so we have to enable qemu logdirty on secondary.
libxl__domain_suspend_common_switch_qemu_logdirty() is to enable qemu logdirty. But it uses domain_save_state, and calls libxl__xc_domain_saverestore_async_callback_done() before exits. This can not be used for secondary vm.
Update libxl__domain_suspend_common_switch_qemu_logdirty() to introduce a new API libxl__domain_common_switch_qemu_logdirty(). This API only uses libxl__logdirty_switch, and calls lds->callback before exits.
--- tools/libxl/libxl_dom_save.c | 78 ++++++++++++++++++++++++++------------------ tools/libxl/libxl_internal.h | 8 +++++ 2 files changed, 54 insertions(+), 32 deletions(-)
tools/libxl/libxl_dom_save.c +46 -32
@@ -32,7 +32,7 @@ static void switch_logdirty_timeout(libxl__egc *egc, libxl__ev_time *ev,static void switch_logdirty_xswatch (libxl__egc *egc,libxl__ev_xswatch *,const char *watch_path,const char *event_path);static void switch_logdirty_done (libxl__egc *egc, -libxl__domain_save_state *dss,int ok); +libxl__logdirty_switch *lds,int ok);static void logdirty_init (libxl__logdirty_switch *lds) {
@@ -42,13 +42,10 @@ static void logdirty_init(libxl__logdirty_switch *lds) }static void domain_suspend_switch_qemu_xen_traditional_logdirty - (int domid,unsigned enable, -libxl__save_helper_state *shs) + (libxl__egc *egc,int domid,unsigned enable, +libxl__logdirty_switch *lds) { -libxl__egc *egc = shs->egc; -libxl__domain_save_state *dss =CONTAINER_OF (shs, *dss, shs); -libxl__logdirty_switch *lds = &dss->logdirty; -STATE_AO_GC (dss->ao); +STATE_AO_GC (lds->ao);int rc;xs_transaction_t t =0 ;const char *got;
@@ -110,64 +107,81 @@ static void domain_suspend_switch_qemu_xen_traditional_logdirty out:LOG (ERROR ,"logdirty switch failed (rc=%d), aborting suspend" ,rc);libxl__xs_transaction_abort (gc, &t); -switch_logdirty_done (egc,dss,-1 ); +switch_logdirty_done (egc,lds,-1 ); }static void domain_suspend_switch_qemu_xen_logdirty - (int domid,unsigned enable, -libxl__save_helper_state *shs) + (libxl__egc *egc,int domid,unsigned enable, +libxl__logdirty_switch *lds) { -libxl__egc *egc = shs->egc; -libxl__domain_save_state *dss =CONTAINER_OF (shs, *dss, shs); -STATE_AO_GC (dss->ao); +STATE_AO_GC (lds->ao);int rc; rc =libxl__qmp_set_global_dirty_log (gc, domid, enable);if (!rc) { -libxl__xc_domain_saverestore_async_callback_done (egc, shs,0 ); + lds->callback (egc, lds,0 ); }else {LOG (ERROR ,"logdirty switch failed (rc=%d), aborting suspend" ,rc); -libxl__xc_domain_saverestore_async_callback_done (egc, shs,-1 ); + lds->callback (egc, lds,-1 ); } } +static void libxl__domain_suspend_switch_qemu_logdirty_done + (libxl__egc *egc,libxl__logdirty_switch *lds,int rc) +{ +libxl__domain_save_state *dss =CONTAINER_OF (lds, *dss, logdirty); + +libxl__xc_domain_saverestore_async_callback_done (egc, &dss->shs, rc); +} +void libxl__domain_suspend_common_switch_qemu_logdirty (int domid,unsigned enable,void *user) {libxl__save_helper_state *shs = user;libxl__egc *egc = shs->egc;libxl__domain_save_state *dss =CONTAINER_OF (shs, *dss, shs); -STATE_AO_GC (dss->ao); + +/* convenience aliases */ +libxl__logdirty_switch *const lds = &dss->logdirty; + + lds->callback = libxl__domain_suspend_switch_qemu_logdirty_done; +libxl__domain_common_switch_qemu_logdirty (egc, domid, enable, lds); +} + +void libxl__domain_common_switch_qemu_logdirty (libxl__egc *egc, +int domid,unsigned enable, +libxl__logdirty_switch *lds) +{ +STATE_AO_GC (lds->ao);switch (libxl__device_model_version_running (gc, domid)) {case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL : -domain_suspend_switch_qemu_xen_traditional_logdirty (domid, enable, shs); +domain_suspend_switch_qemu_xen_traditional_logdirty (egc, domid, enable, + lds);break ;case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN : -domain_suspend_switch_qemu_xen_logdirty (domid, enable, shs); +domain_suspend_switch_qemu_xen_logdirty (egc, domid, enable, lds);break ;default :LOG (ERROR ,"logdirty switch failed" ", no valid device model version found, aborting suspend" ); -libxl__xc_domain_saverestore_async_callback_done (egc, shs,-1 ); + lds->callback (egc, lds,-1 ); } }static void switch_logdirty_timeout (libxl__egc *egc,libxl__ev_time *ev,const struct timeval *requested_abs) { -libxl__domain_save_state *dss =CONTAINER_OF (ev, *dss, logdirty.timeout); -STATE_AO_GC (dss->ao); +libxl__logdirty_switch *lds =CONTAINER_OF (ev, *lds, timeout); +STATE_AO_GC (lds->ao);LOG (ERROR ,"logdirty switch: wait for device model timed out" ); -switch_logdirty_done (egc,dss,-1 ); +switch_logdirty_done (egc,lds,-1 ); }static void switch_logdirty_xswatch (libxl__egc *egc,libxl__ev_xswatch *watch,const char *watch_path,const char *event_path) { -libxl__domain_save_state *dss = -CONTAINER_OF (watch, *dss, logdirty.watch); -libxl__logdirty_switch *lds = &dss->logdirty; -STATE_AO_GC (dss->ao); +libxl__logdirty_switch *lds =CONTAINER_OF (watch, *lds, watch); +STATE_AO_GC (lds->ao);const char *got;xs_transaction_t t =0 ;int rc;
@@ -211,24 +225,23 @@ static void switch_logdirty_xswatch(libxl__egc *egc, libxl__ev_xswatch *watch,libxl__xs_transaction_abort (gc, &t);if (!rc) { -switch_logdirty_done (egc,dss,0 ); +switch_logdirty_done (egc,lds,0 ); }else if (rc <0 ) {LOG (ERROR ,"logdirty switch: failed (rc=%d)" ,rc); -switch_logdirty_done (egc,dss,-1 ); +switch_logdirty_done (egc,lds,-1 ); } }static void switch_logdirty_done (libxl__egc *egc, -libxl__domain_save_state *dss, +libxl__logdirty_switch *lds,int broke) { -STATE_AO_GC (dss->ao); -libxl__logdirty_switch *lds = &dss->logdirty; +STATE_AO_GC (lds->ao);libxl__ev_xswatch_deregister (gc, &lds->watch);libxl__ev_time_deregister (gc, &lds->timeout); -libxl__xc_domain_saverestore_async_callback_done (egc, &dss->shs, broke); + lds->callback (egc, lds, broke); }/*----- main code for saving, in order of execution -----*/
@@ -253,6 +266,7 @@ void libxl__domain_save(libxl__egc *egc, libxl__domain_save_state *dss)libxl__domain_suspend_state *dss2 = &dss->dss;logdirty_init (&dss->logdirty); + dss->logdirty.ao = ao;libxl__xswait_init (&dss2->pvcontrol);libxl__ev_evtchn_init (&dss2->guest_evtchn);libxl__ev_xswatch_init (&dss2->guest_watch);
tools/libxl/libxl_internal.h +8 -0
@@ -2836,6 +2836,11 @@ typedef void libxl__save_device_model_cb(libxl__egc*, libxl__domain_save_state*, int rc); typedef struct libxl__logdirty_switch { + /* set by caller of libxl__domain_common_switch_qemu_logdirty */ + libxl__ao *ao; + void (*callback)(libxl__egc *egc, struct libxl__logdirty_switch *lds, + int rc); + const char *cmd; const char *cmd_path; const char *ret_path;
@@ -3178,6 +3183,9 @@ void libxl__xc_domain_saverestore_async_callback_done(libxl__egc *egc, _hidden void libxl__domain_suspend_common_switch_qemu_logdirty (int domid,unsigned int enable,void *data); +_hidden void libxl__domain_common_switch_qemu_logdirty(libxl__egc *egc, +int domid,unsigned enable, +libxl__logdirty_switch *lds); _hidden int libxl__toolstack_save(uint32_t domid, uint8_t **buf,uint32_t *len,void *data);
Signature · 1 line
1.9.1
PATCH 8/12 tools/libxl: Update libxl_save_msgs_gen.pl to support return data from xl to xc
In reply to Yang HongyangFrom: Wen Congyang <[email protected]>
Currently, 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
@@ -3179,6 +3179,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.1
PATCH 9/12 tools/libxl: Add back channel to allow migration target send data back
In reply to Yang HongyangFrom: Wen Congyang <[email protected]>
In 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
@@ -865,7 +865,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
@@ -1577,8 +1577,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) {
@@ -1591,6 +1591,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);
@@ -1619,7 +1620,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 ); }
@@ -1629,7 +1630,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
@@ -2873,6 +2873,7 @@ struct libxl__domain_save_state {uint32_t domid;int fd; +int recv_fd;libxl_domain_type type;int live;int debug;
@@ -3142,6 +3143,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
@@ -198,6 +198,12 @@ libxl_viridian_enlightenment = Enumeration("viridian_enlightenment", [ (3, "reference_tsc"), ]) +libxl_checkpointed_stream = Enumeration("checkpointed_stream", [ + (0, "NONE"), + (1, "REMUS"), + (2, "COLO"), + ], init_val = 0) + # # Complex libxl types #
@@ -346,6 +352,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 */ };
@@ -2533,6 +2534,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;
@@ -2549,6 +2551,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 );
@@ -2723,6 +2726,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,
@@ -4266,6 +4270,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;
@@ -4436,6 +4441,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;
@@ -4886,6 +4892,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.1
PATCH 10/12 tools/libxl: rename remus device to checkpoint device
In reply to Yang HongyangThis 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 +- tools/libxl/libxl_checkpoint_device.c | 327 ++++++++++++++++++++++++++++++++++ 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_device.c | 327 ---------------------------------- tools/libxl/libxl_remus_disk_drbd.c | 52 +++--- tools/libxl/libxl_types.idl | 4 +- 9 files changed, 510 insertions(+), 510 deletions(-) create mode 100644 tools/libxl/libxl_checkpoint_device.c delete mode 100644 tools/libxl/libxl_remus_device.c
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 libxl_libfdt_compat.o
tools/libxl/libxl_checkpoint_device.c new file +327 -0
327 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
194 lines not on this page · raw message
tools/libxl/libxl_remus_device.c deleted +0 -327
327 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"), (-20, "VNUMA_CONFIG_INVALID"), (-21, "DOMAIN_NOTFOUND"), ], value_namespace = "")
Signature · 1 line
1.9.1
PATCH 11/12 tools/libxl: adjust the indentation
In reply to Yang HongyangThis is just tidying up after the previous automatic renaming.
--- tools/libxl/libxl_checkpoint_device.c | 21 +++++++++++---------- tools/libxl/libxl_internal.h | 19 +++++++++++-------- tools/libxl/libxl_remus.c | 9 ++++++--- 3 files changed, 28 insertions(+), 21 deletions(-)
tools/libxl/libxl_checkpoint_device.c +11 -10
@@ -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;
@@ -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 +11 -8
@@ -2672,7 +2672,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
@@ -2733,7 +2734,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
@@ -2741,7 +2743,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;
@@ -2754,7 +2756,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). */
@@ -2816,13 +2819,13 @@ struct libxl__checkpoint_device { _hidden void libxl__checkpoint_devices_setup(libxl__egc *egc,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 +6 -3
@@ -20,9 +20,11 @@/*----- Remus setup and teardown -----*/ 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_save_state *dss) {/* Convenience aliases */
@@ -71,7 +73,8 @@ static void libxl_remus_setup_done(libxl__egc *egc, }static void libxl_remus_setup_failed (libxl__egc *egc, -libxl__checkpoint_devices_state *cds,int rc) +libxl__checkpoint_devices_state *cds, +int rc) {libxl__domain_save_state *dss =CONTAINER_OF (cds, *dss, cds);STATE_AO_GC (dss->ao);
Signature · 1 line
1.9.1
PATCH 12/12 tools/libxl: don't touch remus in checkpoint_device
In reply to Yang HongyangCheckpoint 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_save.c | 3 +- tools/libxl/libxl_internal.h | 40 ++++++++++------ tools/libxl/libxl_netbuffer.c | 51 +++++++++++--------- tools/libxl/libxl_remus.c | 90 ++++++++++++++++++++++++++++------- tools/libxl/libxl_remus_disk_drbd.c | 8 ++-- 7 files changed, 136 insertions(+), 110 deletions(-)
tools/libxl/libxl.c +1 -1
@@ -874,7 +874,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_save.c +1 -2
@@ -298,7 +298,6 @@ void libxl__domain_save(libxl__egc *egc, libxl__domain_save_state *dss) dss2->ao = ao;if (r_info !=NULL ) { - dss->interval = r_info->interval; dss->xcflags |=XCFLAGS_CHECKPOINTED ;if (libxl_defbool_val (r_info->compression)) dss->xcflags |=XCFLAGS_CHECKPOINT_COMPRESS ;
@@ -492,7 +491,7 @@ static void domain_save_done(libxl__egc *egc,* from sending checkpoints. Teardown the network buffers and * release netlink resources. This is an async op. */ -libxl__remus_teardown (egc, dss, rc); +libxl__remus_teardown (egc, &dss->rs, rc);return ; }
tools/libxl/libxl_internal.h +25 -15
@@ -2749,6 +2749,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 -----*/
@@ -2769,16 +2771,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; };/*
@@ -2826,6 +2818,26 @@ _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 -----*/
@@ -2885,9 +2897,7 @@ struct libxl__domain_save_state {libxl__domain_suspend_state dss;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 */
@@ -3228,9 +3238,9 @@ void libxl__remus_domain_suspend_callback(void *data);void libxl__remus_domain_resume_callback (void *data);void libxl__remus_domain_checkpoint_callback (void *data);/* Remus setup and teardown*/ -void libxl__remus_setup (libxl__egc *egc,libxl__domain_save_state *dss); +void libxl__remus_setup (libxl__egc *egc,libxl__remus_state *rs);void libxl__remus_teardown (libxl__egc *egc, -libxl__domain_save_state *dss, +libxl__remus_state *rs,int rc);
tools/libxl/libxl_netbuffer.c +29 -22
148 lines not on this page · raw message
tools/libxl/libxl_remus.c +72 -18
205 lines not on this page · raw message
tools/libxl/libxl_remus_disk_drbd.c +5 -3
@@ -28,10 +28,11 @@ 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 +97,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 +109,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.1