Migration v2 (libxc)
v9 cover Migration v2 (libxc)
Presented here is v9 of the Migration v2 series (libxc subset), which is able to function when transparently inserted under an unmodified xl/libxl.
The main purpose of v9 is to rebase over the build issue caused by 341fac7b "xen/mem_event: Cleanup mem_event names in rings, functions and domctls" renaming one of the HVM parameters. In addition, there are a couple of bugfixes spotted by Coverity, and some refactoring of a few "mfn" variables which should have been "gfn". No major changes from v8.
This series can be found on a 'saverestore2-v9' at
http://xenbits.xen.org/git-http/people/andrewcoop/xen.git
To experiment, simply set XG_MIGRATION_V2 in xl's environment. For migration, the easiest way is to tweak libxl-save-helper to be a shell script
root@vitruvias:/home# cat /usr/lib/xen/bin/libxl-save-helper #!/bin/bash export XG_MIGRATION_V2=x exec /usr/lib/xen/bin/libxl-save-helper.bin "$@"
which will ensure that XG_MIGRATION_V2 gets set in the environment for both the source and destination of migration.
Patches 1 and 2 are prerequisites
Patches 3 to 13 are the meat of the series Patch 14 is the design document
Patch 15 is the compat layer for unmodified libxl
Please experiment!
~Andrew
PATCH v9 1/15 tools/libxc: Implement writev_exact() in the same style as write_exact()
This implementation of writev_exact() will cope with an iovcnt greater than IOV_MAX because glibc will actually let this work anyway, and it is very useful not to have to work about this in the caller of writev_exact(). The caller is still required to ensure that the sum of iov_len's doesn't overflow a ssize_t.
---
v8: Extra comments indicating why we loop when we do
--- tools/libxc/xc_private.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++ tools/libxc/xc_private.h | 14 ++++++++ 2 files changed, 99 insertions(+)
tools/libxc/xc_private.c +85 -0
@@ -867,6 +867,91 @@ int write_exact(int fd, const void *data, size_t size)return 0 ; } +#if defined(__MINIOS__) +/* +* MiniOS's libc doesn't know about writev(). Implement it as multiple write()s. +*/ +int writev_exact (int fd,const struct iovec *iov,int iovcnt) +{ +int rc, i; + +for ( i =0 ; i < iovcnt; ++i ) + { + rc =write_exact (fd, iov[i].iov_base, iov[i].iov_len); +if ( rc ) +return rc; + } + +return 0 ; +} +#else +int writev_exact (int fd,const struct iovec *iov,int iovcnt) +{ +struct iovec *local_iov =NULL ; +int rc =0 , iov_idx =0 , saved_errno =0 ; +ssize_t len; + +while ( iov_idx < iovcnt ) + { +/* +* Skip over iov[] entries with 0 length. +* +* This is needed to cover the case where we took a partial write and +* all remaining vectors are of 0 length. In such a case, the results +* from writev() are indistinguishable from EOF. +*/ +while ( iov[iov_idx].iov_len ==0 ) +if ( ++iov_idx == iovcnt ) + goto out; + + len =writev (fd, &iov[iov_idx],min (iovcnt - iov_idx,IOV_MAX )); + saved_errno = errno; + +if ( (len ==-1 ) && (errno ==EINTR ) ) +continue ; +if ( len <=0 ) + { + rc =-1 ; + goto out; + } + +/* Check iov[] to see whether we had a partial or complete write. */ +while ( (len >0 ) && (iov_idx < iovcnt) ) + { +if ( len >= iov[iov_idx].iov_len ) + len -= iov[iov_idx++].iov_len; +else + { +/* Partial write of iov[iov_idx]. Copy iov so we can adjust +* element iov_idx and resubmit the rest. */ +if ( !local_iov ) + { + local_iov =malloc (iovcnt *sizeof (*iov)); +if ( !local_iov ) + { + saved_errno =ENOMEM ; + goto out; + } + + iov =memcpy (local_iov, iov, iovcnt *sizeof (*iov)); + } + + local_iov[iov_idx].iov_base += len; + local_iov[iov_idx].iov_len -= len; +break ; + } + } + } + + saved_errno =0 ; + + out: +free (local_iov); + errno = saved_errno; +return rc; +} +#endif +int xc_ffs8 (uint8_t x) {int i;
tools/libxc/xc_private.h +14 -0
@@ -42,6 +42,19 @@#define VALGRIND_MAKE_MEM_UNDEFINED (addr, len)/* addr, len */ #endif +#if defined(__MINIOS__) +/* +* MiniOS's libc doesn't know about sys/uio.h or writev(). +* Declare enough of sys/uio.h to compile. +*/ +struct iovec { +void *iov_base; +size_t iov_len; +}; +#else +#include <sys/uio.h> +#endif +#define DECLARE_HYPERCALL privcmd_hypercall_t hypercall#define DECLARE_DOMCTL struct xen_domctl domctl#define DECLARE_SYSCTL struct xen_sysctl sysctl
@@ -395,6 +408,7 @@ int xc_add_mmu_update(xc_interface *xch, struct xc_mmu *mmu,/* Return 0 on success; -1 on error setting errno. */ int read_exact (int fd,void *data,size_t size);/* EOF => -1, errno=0 */ int write_exact (int fd,const void *data,size_t size); +int writev_exact (int fd,const struct iovec *iov,int iovcnt);int xc_ffs8 (uint8_t x);int xc_ffs16 (uint16_t x);
Signature · 1 line
1.7.10.4
Re: [PATCH v9 01/15] tools/libxc: Implement writev_exact() in the same style as write_exact()
Quoted 10 lines · Andrew Cooper
This implementation of
writev_exact()will cope with an iovcnt greater thanIOV_MAXbecause glibc will actually let this work anyway, and it is very useful not to have to work about this in the caller ofwritev_exact(). The caller is still required to ensure that the sum of iov_len's doesn't overflow assize_t.Signed-off-by Andrew Cooper <[email protected]>CC Ian Campbell <[email protected]>CC Ian Jackson <[email protected]>CC Wei Liu <[email protected]>
PATCH v9 2/15 libxc/progress: Extend the progress interface
In reply to Andrew CooperNot everything which needs reporting as progress comes with a range. Extend the interface to allow reporting of a single statement.
The programming interface now looks like:
xc_set_progress_prefix()
set the prefix string to be used
xc_report_progress_single()
report a single action
xc_report_progress_step()
report $X of $Y
The new programming interface is implemented in a compatible way with the existing caller interface (by reporting a single action as "0 of 0").
---
v8: Expand commit message
--- tools/libxc/xc_domain_restore.c | 3 ++- tools/libxc/xc_domain_save.c | 3 ++- tools/libxc/xc_private.c | 22 ++++++++++++++-------- tools/libxc/xc_private.h | 4 ++-- tools/libxc/xtl_core.c | 9 +++++---- 5 files changed, 25 insertions(+), 16 deletions(-)
tools/libxc/xc_domain_restore.c +2 -1
@@ -1622,7 +1622,8 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom, goto out; } -xc_report_progress_start (xch,"Reloading memory pages" , dinfo->p2m_size); +xc_set_progress_prefix (xch,"Reloading memory pages" ); +xc_report_progress_step (xch,0 , dinfo->p2m_size);/* * Now simply read each saved frame into its new machine frame.
tools/libxc/xc_domain_save.c +2 -1
@@ -1131,7 +1131,8 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter"Saving memory: iter %d (last sent %u skipped %u)" , iter, sent_this_iter, skip_this_iter); -xc_report_progress_start (xch, reportbuf, dinfo->p2m_size); +xc_set_progress_prefix (xch, reportbuf); +xc_report_progress_step (xch,0 , dinfo->p2m_size); iter++; sent_this_iter =0 ;
tools/libxc/xc_private.c +14 -8
@@ -388,18 +388,24 @@ void xc_osdep_log(xc_interface *xch, xentoollog_level level, int code, const chava_end (args); } -void xc_report_progress_start (xc_interface *xch,const char *doing, -unsigned long total) { +const char *xc_set_progress_prefix (xc_interface *xch,const char *doing) +{ +const char *old = xch->currently_progress_reporting; + xch->currently_progress_reporting = doing; -xtl_progress (xch->error_handler,"xc" , xch->currently_progress_reporting, -0 , total); +return old; +} + +void xc_report_progress_single (xc_interface *xch,const char *doing) +{ +xtl_progress (xch->error_handler,"xc" , doing,0 ,0 ); }void xc_report_progress_step (xc_interface *xch, -unsigned long done,unsigned long total) { -assert (xch->currently_progress_reporting); -xtl_progress (xch->error_handler,"xc" , xch->currently_progress_reporting, - done, total); +unsigned long done,unsigned long total) +{ +xtl_progress (xch->error_handler,"xc" , + xch->currently_progress_reporting ?:"???" , done, total); } int xc_get_pfn_type_batch(xc_interface *xch, uint32_t dom,
tools/libxc/xc_private.h +2 -2
@@ -133,8 +133,8 @@ void xc_report(xc_interface *xch, xentoollog_logger *lg, xentoollog_level, int code, const char *fmt, ...) __attribute__((format(printf,5,6))); -void xc_report_progress_start (xc_interface *xch,const char *doing, -unsigned long total); +const char *xc_set_progress_prefix (xc_interface *xch,const char *doing); +void xc_report_progress_single (xc_interface *xch,const char *doing);void xc_report_progress_step (xc_interface *xch,unsigned long done,unsigned long total);
tools/libxc/xtl_core.c +5 -4
@@ -66,13 +66,14 @@ void xtl_log(struct xentoollog_logger *logger,void xtl_progress (struct xentoollog_logger *logger,const char *context,const char *doing_what,unsigned long done,unsigned long total) { -int percent; +int percent =0 ;if (!logger->progress)return ; - percent = (total <LONG_MAX /100 ) - ? (done *100 ) / total - : done / ((total +99 ) /100 ); +if ( total ) + percent = (total <LONG_MAX /100 ) + ? (done *100 ) / total + : done / ((total +99 ) /100 ); logger->progress (logger, context, doing_what, percent, done, total); }
Signature · 1 line
1.7.10.4
Re: [PATCH v9 02/15] libxc/progress: Extend the progress interface
Quoted 11 lines · Andrew Cooper
Not everything which needs reporting as progress comes with a range. Extend the interface to allow reporting of a single statement.
The programming interface now looks like:
xc_set_progress_prefix()
set the prefix string to be used
xc_report_progress_single()
report a single action
xc_report_progress_step()
report $X of $Y
Quoted 2 lines
The new programming interface is implemented in a compatible way with the existing caller interface (by reporting a single action as "0 of 0").
I suppose the underlying motivation here is that there a difference between this new xc_report_progress_step and calling xc_report/v? IOW some difference between the semantics of the logger's ->vmessage and ->progress hooks. What is it though?
I suspected the distinction was in the automatic inclusion of xch->currently_progress_reporting into the messages, but you appear to make that non-mandatory below.
Speaking of which, I think it should be mandatory now to call xc_set_progress_prefix as it was to call progress_start before, and that both of your new functions should assert. Those who think they want to use xc_report_progress_single without calling xc_set_progress_prefix should be using xc_report() instead.
Ian.
Re: [PATCH v9 02/15] libxc/progress: Extend the progress interface
Quoted 12 lines · Ian Campbell
Quoted 11 lines · Andrew Cooper
Not everything which needs reporting as progress comes with a range. Extend the interface to allow reporting of a single statement.
The programming interface now looks like:
xc_set_progress_prefix()
set the prefix string to be used
xc_report_progress_single()
report a single action
xc_report_progress_step()
report $X of $Y
Quoted 6 lines
Quoted 2 lines
The new programming interface is implemented in a compatible way with the existing caller interface (by reporting a single action as "0 of 0").
I suppose the underlying motivation here is that there a difference between this new
xc_report_progress_stepand calling xc_report/v? IOW some difference between the semantics of the logger's ->vmessage and ->progress hooks. What is it though?
They arrive via separate callbacks to the callee.
xc_report_progress & friends come through the domain build logger (parameter 2 of xc_interface_open()) while other logging tends to come through the regular logger (parameter 1 of xc_interface_open()).
Technically speaking, xc_report/v does allow the caller to choose which logger is used, but also requires the caller to provide all the fine detail, which detracts from the readability of the callsite.
This new progress API attempts to resolve this by providing a high level way of putting a single message through the progress logger.
Quoted 10 lines
I suspected the distinction was in the automatic inclusion of
xch->currently_progress_reportinginto the messages, but you appear to make that non-mandatory below.Speaking of which, I think it should be mandatory now to call
xc_set_progress_prefixas it was to callprogress_startbefore, and that both of your new functions should assert. Those who think they want to usexc_report_progress_singlewithout callingxc_set_progress_prefixshould be usingxc_report()instead.
Technically speaking it is safe to use a NULL prefix; the vsprintf won't fall over.
I can assert() that these invariants are held, but it is not critical to the functionality.
~Andrew
Re: [PATCH v9 02/15] libxc/progress: Extend the progress interface
Quoted 26 lines · Andrew Cooper
Quoted 12 lines · Ian Campbell
Quoted 11 lines · Andrew Cooper
Not everything which needs reporting as progress comes with a range. Extend the interface to allow reporting of a single statement.
The programming interface now looks like:
xc_set_progress_prefix()
set the prefix string to be used
xc_report_progress_single()
report a single action
xc_report_progress_step()
report $X of $YQuoted 6 lines
Quoted 2 lines
The new programming interface is implemented in a compatible way with the existing caller interface (by reporting a single action as "0 of 0").
I suppose the underlying motivation here is that there a difference between this new
xc_report_progress_stepand calling xc_report/v? IOW some difference between the semantics of the logger's ->vmessage and ->progress hooks. What is it though?They arrive via separate callbacks to the callee.
xc_report_progress& friends come through the domain build logger (parameter 2 ofxc_interface_open()) while other logging tends to come through the regular logger (parameter 1 ofxc_interface_open()).
Quoted 6 lines
Technically speaking, xc_report/v does allow the caller to choose which logger is used, but also requires the caller to provide all the fine detail, which detracts from the readability of the callsite.
This new progress API attempts to resolve this by providing a high level way of putting a single message through the progress logger.
Makes sense, thanks.
Quoted 4 lines
Quoted 4 lines
I suspected the distinction was in the automatic inclusion of
xch->currently_progress_reportinginto the messages, but you appear to make that non-mandatory below.
Quoted 8 lines
Quoted 5 lines
Speaking of which, I think it should be mandatory now to call
xc_set_progress_prefixas it was to callprogress_startbefore, and that both of your new functions should assert. Those who think they want to usexc_report_progress_singlewithout callingxc_set_progress_prefixshould be usingxc_report()instead.Technically speaking it is safe to use a NULL prefix; the vsprintf won't fall over.
Having log message prefixed by "(null)" or whatever would be a bit rubbish. I think lets keep the current semantics (by asserting things have been set) and if there is a strong case to allow no prefix relax things in a subsequent patch which makes everywhere DTRT.
Quoted 2 lines
I can
assert()that these invariants are held, but it is not critical to the functionality.
Yes, please add the asserts for now.
Ian.
PATCH v9 3/15 tools/libxc: Migration v2 framework
In reply to Andrew CooperFor testing purposes, the environmental variable "XG_MIGRATION_V2" allows the two save/restore codepaths to coexist, and have a runtime switch.
---
v8: Adjust layout to compile with MiniOS
--- tools/libxc/Makefile | 2 ++ tools/libxc/include/xenguest.h | 13 +++++++++++++ tools/libxc/xc_domain_restore.c | 8 ++++++++ tools/libxc/xc_domain_save.c | 6 ++++++ tools/libxc/xc_sr_common.h | 15 +++++++++++++++ tools/libxc/xc_sr_restore.c | 23 +++++++++++++++++++++++ tools/libxc/xc_sr_save.c | 19 +++++++++++++++++++ 7 files changed, 86 insertions(+) create mode 100644 tools/libxc/xc_sr_common.h create mode 100644 tools/libxc/xc_sr_restore.c create mode 100644 tools/libxc/xc_sr_save.c
tools/libxc/Makefile +2 -0
@@ -53,6 +53,8 @@ GUEST_SRCS-y := GUEST_SRCS-y += xg_private.c xc_suspend.c ifeq ($(CONFIG_MIGRATE),y) GUEST_SRCS-y += xc_domain_restore.c xc_domain_save.c +GUEST_SRCS-y += xc_sr_restore.c +GUEST_SRCS-y += xc_sr_save.c GUEST_SRCS-y += xc_offline_page.c xc_compression.c else GUEST_SRCS-y += xc_nomigrate.c
tools/libxc/include/xenguest.h +13 -0
@@ -90,6 +90,10 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter uint32_t max_factor, uint32_t flags /* XCFLAGS_xxx */, struct save_callbacks* callbacks, int hvm); +/* Domain Save v2 */ +int xc_domain_save2 (xc_interface *xch,int io_fd,uint32_t dom,uint32_t max_iters, +uint32_t max_factor,uint32_t flags, +struct save_callbacks * callbacks,int hvm);/* callbacks provided by xc_domain_restore */ struct restore_callbacks {
@@ -126,6 +130,15 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom, unsigned int hvm, unsigned int pae, int superpages, int checkpointed_stream, struct restore_callbacks *callbacks); + +/* Domain Restore v2 */ +int xc_domain_restore2 (xc_interface *xch,int io_fd,uint32_t dom, +unsigned int store_evtchn,unsigned long *store_mfn, +domid_t store_domid,unsigned int console_evtchn, +unsigned long *console_mfn,domid_t console_domid, +unsigned int hvm,unsigned int pae,int superpages, +int checkpointed_stream, +struct restore_callbacks *callbacks);/** * xc_domain_restore writes a file to disk that contains the device * model saved state.
tools/libxc/xc_domain_restore.c +8 -0
@@ -1502,6 +1502,14 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,struct restore_ctx *ctx = &_ctx;struct domain_info_context *dinfo = &ctx->dinfo; +if (getenv ("XG_MIGRATION_V2" ) ) + { +return xc_domain_restore2 ( + xch, io_fd, dom, store_evtchn, store_mfn, + store_domid, console_evtchn, console_mfn, console_domid, + hvm, pae, superpages, checkpointed_stream, callbacks); + } +DPRINTF ("%s: starting restore of new domid %u" , __func__, dom);pagebuf_init (&pagebuf);
tools/libxc/xc_domain_save.c +6 -0
@@ -894,6 +894,12 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iterint completed =0 ; +if (getenv ("XG_MIGRATION_V2" ) ) + { +return xc_domain_save2 (xch, io_fd, dom, max_iters, + max_factor, flags, callbacks, hvm); + } +DPRINTF ("%s: starting save of domid %u" , __func__, dom);if ( hvm && !callbacks->switch_qemu_logdirty )
tools/libxc/xc_sr_common.h new file +15 -0
@@ -0,0 +1,15 @@ +#ifndef __COMMON__H +#define __COMMON__H + +#include "xg_private.h" + +#endif +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
tools/libxc/xc_sr_restore.c new file +23 -0
@@ -0,0 +1,23 @@ +#include "xc_sr_common.h" + +int xc_domain_restore2 (xc_interface *xch,int io_fd,uint32_t dom, +unsigned int store_evtchn,unsigned long *store_mfn, +domid_t store_domid,unsigned int console_evtchn, +unsigned long *console_mfn,domid_t console_domid, +unsigned int hvm,unsigned int pae,int superpages, +int checkpointed_stream, +struct restore_callbacks *callbacks) +{ +IPRINTF ("In experimental %s" , __func__); +return -1 ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
tools/libxc/xc_sr_save.c new file +19 -0
@@ -0,0 +1,19 @@ +#include "xc_sr_common.h" + +int xc_domain_save2 (xc_interface *xch,int io_fd,uint32_t dom, +uint32_t max_iters,uint32_t max_factor,uint32_t flags, +struct save_callbacks * callbacks,int hvm) +{ +IPRINTF ("In experimental %s" , __func__); +return -1 ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
1.7.10.4
Re: [PATCH v9 03/15] tools/libxc: Migration v2 framework
Quoted 4 lines · Andrew Cooper
For testing purposes, the environmental variable "
XG_MIGRATION_V2" allows the two save/restore codepaths to coexist, and have a runtime switch.Signed-off-by Andrew Cooper <[email protected]>
Ian.
PATCH v9 4/15 tools/libxc: C implementation of stream format
In reply to Andrew CooperProvide the C structures matching the binary (wire) format of the new stream format. All header/record fields are naturally aligned and explicit padding fields are used to ensure the correct layout (i.e., there is no need for any non-standard structure packing pragma or attribute).
Provide some helper functions for converting types to string for diagnostic purposes.
--- tools/libxc/Makefile | 1 + tools/libxc/xc_sr_common.c | 72 ++++++++++++++++++ tools/libxc/xc_sr_common.h | 8 ++ tools/libxc/xc_sr_stream_format.h | 148 +++++++++++++++++++++++++++++++++++++ 4 files changed, 229 insertions(+) create mode 100644 tools/libxc/xc_sr_common.c create mode 100644 tools/libxc/xc_sr_stream_format.h
tools/libxc/Makefile +1 -0
@@ -53,6 +53,7 @@ GUEST_SRCS-y := GUEST_SRCS-y += xg_private.c xc_suspend.c ifeq ($(CONFIG_MIGRATE),y) GUEST_SRCS-y += xc_domain_restore.c xc_domain_save.c +GUEST_SRCS-y += xc_sr_common.c GUEST_SRCS-y += xc_sr_restore.c GUEST_SRCS-y += xc_sr_save.c GUEST_SRCS-y += xc_offline_page.c xc_compression.c
tools/libxc/xc_sr_common.c new file +72 -0
72 lines not on this page · raw message
tools/libxc/xc_sr_common.h +8 -0
@@ -3,6 +3,14 @@#include "xg_private.h" +#include "xc_sr_stream_format.h" + +/* String representation of Domain Header types. */ +const char *dhdr_type_to_str (uint32_t type); + +/* String representation of Record types. */ +const char *rec_type_to_str (uint32_t type); +#endif /* * Local variables:
tools/libxc/xc_sr_stream_format.h new file +148 -0
148 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH v9 04/15] tools/libxc: C implementation of stream format
Quoted 6 lines · Andrew Cooper
Provide the C structures matching the binary (wire) format of the new stream format. All header/record fields are naturally aligned and explicit padding fields are used to ensure the correct layout (i.e., there is no need for any non-standard structure packing pragma or attribute).
Quoted 7 lines
Provide some helper functions for converting types to string for diagnostic purposes.
Signed-off-by Andrew Cooper <[email protected]>CC Ian Campbell <[email protected]>CC Ian Jackson <[email protected]>CC Wei Liu <[email protected]>
I think I already acked a substantially similar version of this in <[email protected]>, so given the lack of an intra-patch changelog here:
If there was some substantial change let me know and I'll actually read the patch.
Quoted 272 lines
--- tools/libxc/Makefile | 1 + tools/libxc/xc_sr_common.c | 72 ++++++++++++++++++ tools/libxc/xc_sr_common.h | 8 ++ tools/libxc/xc_sr_stream_format.h | 148 +++++++++++++++++++++++++++++++++++++ 4 files changed, 229 insertions(+) create mode 100644 tools/libxc/xc_sr_common.c create mode 100644 tools/libxc/xc_sr_stream_format.htools/libxc/Makefile +1
-0@@ -53,6 +53,7 @@ GUEST_SRCS-y := GUEST_SRCS-y += xg_private.c xc_suspend.c ifeq ($(CONFIG_MIGRATE),y) GUEST_SRCS-y += xc_domain_restore.c xc_domain_save.c +GUEST_SRCS-y += xc_sr_common.c GUEST_SRCS-y += xc_sr_restore.c GUEST_SRCS-y += xc_sr_save.c GUEST_SRCS-y += xc_offline_page.c xc_compression.ctools/libxc/xc_sr_common.c new file +72
-0@@ -0,0 +1,72 @@ +#include "xc_sr_common.h" + +static const char *dhdr_types[] = +{ + [DHDR_TYPE_X86_PV ] ="x86 PV" , + [DHDR_TYPE_X86_HVM ] ="x86 HVM" , + [DHDR_TYPE_X86_PVH ] ="x86 PVH" , + [DHDR_TYPE_ARM ] ="ARM" , +}; + +const char *dhdr_type_to_str (uint32_t type) +{ +if ( type <ARRAY_SIZE (dhdr_types) && dhdr_types[type] ) +return dhdr_types[type]; + +return "Reserved" ; +} + +static const char *mandatory_rec_types[] = +{ + [REC_TYPE_END ] ="End" , + [REC_TYPE_PAGE_DATA ] ="Page data" , + [REC_TYPE_X86_PV_INFO ] ="x86 PV info" , + [REC_TYPE_X86_PV_P2M_FRAMES ] ="x86 PV P2M frames" , + [REC_TYPE_X86_PV_VCPU_BASIC ] ="x86 PV vcpu basic" , + [REC_TYPE_X86_PV_VCPU_EXTENDED ] ="x86 PV vcpu extended" , + [REC_TYPE_X86_PV_VCPU_XSAVE ] ="x86 PV vcpu xsave" , + [REC_TYPE_SHARED_INFO ] ="Shared info" , + [REC_TYPE_TSC_INFO ] ="TSC info" , + [REC_TYPE_HVM_CONTEXT ] ="HVM context" , + [REC_TYPE_HVM_PARAMS ] ="HVM params" , + [REC_TYPE_TOOLSTACK ] ="Toolstack" , + [REC_TYPE_X86_PV_VCPU_MSRS ] ="x86 PV vcpu msrs" , + [REC_TYPE_VERIFY ] ="Verify" , +}; + +const char *rec_type_to_str (uint32_t type) +{ +if ( !(type &REC_TYPE_OPTIONAL ) ) + { +if ( (type <ARRAY_SIZE (mandatory_rec_types)) && + (mandatory_rec_types[type]) ) +return mandatory_rec_types[type]; + } + +return "Reserved" ; +} + +static void __attribute__((unused))build_assertions (void ) +{ +XC_BUILD_BUG_ON (sizeof (struct xc_sr_ihdr ) !=24 ); +XC_BUILD_BUG_ON (sizeof (struct xc_sr_dhdr ) !=16 ); +XC_BUILD_BUG_ON (sizeof (struct xc_sr_rhdr ) !=8 ); + +XC_BUILD_BUG_ON (sizeof (struct xc_sr_rec_page_data_header ) !=8 ); +XC_BUILD_BUG_ON (sizeof (struct xc_sr_rec_x86_pv_info ) !=8 ); +XC_BUILD_BUG_ON (sizeof (struct xc_sr_rec_x86_pv_p2m_frames ) !=8 ); +XC_BUILD_BUG_ON (sizeof (struct xc_sr_rec_x86_pv_vcpu_hdr ) !=8 ); +XC_BUILD_BUG_ON (sizeof (struct xc_sr_rec_tsc_info ) !=24 ); +XC_BUILD_BUG_ON (sizeof (struct xc_sr_rec_hvm_params_entry ) !=16 ); +XC_BUILD_BUG_ON (sizeof (struct xc_sr_rec_hvm_params ) !=8 ); +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ tools/libxc/xc_sr_common.h +8
-0@@ -3,6 +3,14 @@#include "xg_private.h" +#include "xc_sr_stream_format.h" + +/* String representation of Domain Header types. */ +const char *dhdr_type_to_str (uint32_t type); + +/* String representation of Record types. */ +const char *rec_type_to_str (uint32_t type); +#endif /* * Local variables: tools/libxc/xc_sr_stream_format.h new file +148
-0@@ -0,0 +1,148 @@ +#ifndef __STREAM_FORMAT__H +#define __STREAM_FORMAT__H + +/* +* C structures for the Migration v2 stream format. +* See docs/specs/libxc-migration-stream.pandoc +*/ + +#include <inttypes.h> + +/* +* Image Header +*/ +struct xc_sr_ihdr +{ +uint64_t marker; +uint32_t id; +uint32_t version; +uint16_t options; +uint16_t _res1; +uint32_t _res2; +}; + +#define IHDR_MARKER 0xffffffffffffffffULL +#define IHDR_ID 0x58454E46U +#define IHDR_VERSION 2 + +#define _IHDR_OPT_ENDIAN 0 +#define IHDR_OPT_LITTLE_ENDIAN (0 << _IHDR_OPT_ENDIAN) +#define IHDR_OPT_BIG_ENDIAN (1 << _IHDR_OPT_ENDIAN) + +/* +* Domain Header +*/ +struct xc_sr_dhdr +{ +uint32_t type; +uint16_t page_shift; +uint16_t _res1; +uint32_t xen_major; +uint32_t xen_minor; +}; + +#define DHDR_TYPE_X86_PV 0x00000001U +#define DHDR_TYPE_X86_HVM 0x00000002U +#define DHDR_TYPE_X86_PVH 0x00000003U +#define DHDR_TYPE_ARM 0x00000004U + +/* +* Record Header +*/ +struct xc_sr_rhdr +{ +uint32_t type; +uint32_t length; +}; + +/* All records must be aligned up to an 8 octet boundary */ +#define REC_ALIGN_ORDER (3U) +/* Somewhat arbitrary - 8MB */ +#define REC_LENGTH_MAX (8U << 20) + +#define REC_TYPE_END 0x00000000U +#define REC_TYPE_PAGE_DATA 0x00000001U +#define REC_TYPE_X86_PV_INFO 0x00000002U +#define REC_TYPE_X86_PV_P2M_FRAMES 0x00000003U +#define REC_TYPE_X86_PV_VCPU_BASIC 0x00000004U +#define REC_TYPE_X86_PV_VCPU_EXTENDED 0x00000005U +#define REC_TYPE_X86_PV_VCPU_XSAVE 0x00000006U +#define REC_TYPE_SHARED_INFO 0x00000007U +#define REC_TYPE_TSC_INFO 0x00000008U +#define REC_TYPE_HVM_CONTEXT 0x00000009U +#define REC_TYPE_HVM_PARAMS 0x0000000aU +#define REC_TYPE_TOOLSTACK 0x0000000bU +#define REC_TYPE_X86_PV_VCPU_MSRS 0x0000000cU +#define REC_TYPE_VERIFY 0x0000000dU + +#define REC_TYPE_OPTIONAL 0x80000000U + +/* PAGE_DATA */ +struct xc_sr_rec_page_data_header +{ +uint32_t count; +uint32_t _res1; +uint64_t pfn[0 ]; +}; + +#define PAGE_DATA_PFN_MASK 0x000fffffffffffffULL +#define PAGE_DATA_TYPE_MASK 0xf000000000000000ULL + +/* X86_PV_INFO */ +struct xc_sr_rec_x86_pv_info +{ +uint8_t guest_width; +uint8_t pt_levels; +uint8_t _res[6 ]; +}; + +/* X86_PV_P2M_FRAMES */ +struct xc_sr_rec_x86_pv_p2m_frames +{ +uint32_t start_pfn; +uint32_t end_pfn; +uint64_t p2m_pfns[0 ]; +}; + +/* X86_PV_VCPU_{BASIC,EXTENDED,XSAVE,MSRS} */ +struct xc_sr_rec_x86_pv_vcpu_hdr +{ +uint32_t vcpu_id; +uint32_t _res1; +uint8_t context[0 ]; +}; + +/* TSC_INFO */ +struct xc_sr_rec_tsc_info +{ +uint32_t mode; +uint32_t khz; +uint64_t nsec; +uint32_t incarnation; +uint32_t _res1; +}; + +/* HVM_PARAMS */ +struct xc_sr_rec_hvm_params_entry +{ +uint64_t index; +uint64_t value; +}; + +struct xc_sr_rec_hvm_params +{ +uint32_t count; +uint32_t _res1; +struct xc_sr_rec_hvm_params_entry param[0 ]; +}; + +#endif +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
PATCH v9 5/15 tools/libxc: noarch common code
In reply to Andrew CooperAdd the context structure used to keep state during the save/restore process.
Define the set of architecture or domain type specific operations with a set of callbacks (save_ops, and restore_ops).
Add common functions for writing records.
--- tools/libxc/xc_sr_common.c | 41 ++++++ tools/libxc/xc_sr_common.h | 309 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 350 insertions(+)
tools/libxc/xc_sr_common.c +41 -0
@@ -1,3 +1,5 @@ +#include <assert.h> +#include "xc_sr_common.h" static const char *dhdr_types[] =
@@ -46,6 +48,45 @@ const char *rec_type_to_str(uint32_t type)return "Reserved" ; } +int write_split_record (struct xc_sr_context *ctx,struct xc_sr_record *rec, +void *buf,size_t sz) +{ +static const char zeroes[(1u <<REC_ALIGN_ORDER ) -1 ] = {0 }; + +xc_interface *xch = ctx->xch; + typeof(rec->length) combined_length = rec->length + sz; +size_t record_length =ROUNDUP (combined_length,REC_ALIGN_ORDER ); +struct iovec parts[] = + { + { &rec->type,sizeof (rec->type) }, + { &combined_length,sizeof (combined_length) }, + { rec->data, rec->length }, + { buf, sz }, + { (void *)zeroes, record_length - combined_length }, + }; + +if ( record_length >REC_LENGTH_MAX ) + { +ERROR ("Record (0x%08x, %s) length %#x exceeds max (%#x)" , rec->type, +rec_type_to_str (rec->type), rec->length,REC_LENGTH_MAX ); +return -1 ; + } + +if ( rec->length ) +assert (rec->data); +if ( sz ) +assert (buf); + +if (writev_exact (ctx->fd, parts,ARRAY_SIZE (parts)) ) + goto err; + +return 0 ; + + err: +PERROR ("Unable to write record to stream" ); +return -1 ; +} +static void __attribute__((unused))build_assertions (void ) {XC_BUILD_BUG_ON (sizeof (struct xc_sr_ihdr ) !=24 );
tools/libxc/xc_sr_common.h +309 -0
322 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH v9 05/15] tools/libxc: noarch common code
Quoted 6 lines · Andrew Cooper
Add the context structure used to keep state during the save/restore process.
Define the set of architecture or domain type specific operations with a set of callbacks (
save_ops, andrestore_ops).
Quoted 6 lines
Add common functions for writing records.
Signed-off-by Andrew Cooper <[email protected]>CC Ian Campbell <[email protected]>CC Ian Jackson <[email protected]>CC Wei Liu <[email protected]>
This is, AFAICT, unmodified from the version I commented on in <[email protected]>.
My conditional ack from their still stands.
Ian.
PATCH v9 6/15 tools/libxc: x86 common code
In reply to Andrew CooperSave/restore records common to all x86 domain types (HVM, PV).
This is only the TSC_INFO record.
--- tools/libxc/Makefile | 1 + tools/libxc/xc_sr_common_x86.c | 54 ++++++++++++++++++++++++++++++++++++++++ tools/libxc/xc_sr_common_x86.h | 26 +++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 tools/libxc/xc_sr_common_x86.c create mode 100644 tools/libxc/xc_sr_common_x86.h
tools/libxc/Makefile +1 -0
@@ -54,6 +54,7 @@ GUEST_SRCS-y += xg_private.c xc_suspend.c ifeq ($(CONFIG_MIGRATE),y) GUEST_SRCS-y += xc_domain_restore.c xc_domain_save.c GUEST_SRCS-y += xc_sr_common.c +GUEST_SRCS-$(CONFIG_X86) += xc_sr_common_x86.c GUEST_SRCS-y += xc_sr_restore.c GUEST_SRCS-y += xc_sr_save.c GUEST_SRCS-y += xc_offline_page.c xc_compression.c
tools/libxc/xc_sr_common_x86.c new file +54 -0
54 lines not on this page · raw message
tools/libxc/xc_sr_common_x86.h new file +26 -0
@@ -0,0 +1,26 @@ +#ifndef __COMMON_X86__H +#define __COMMON_X86__H + +#include "xc_sr_common.h" + +/* +* Obtains a domains TSC information from Xen and writes a TSC_INFO record +* into the stream. +*/ +int write_tsc_info (struct xc_sr_context *ctx); + +/* +* Parses a TSC_INFO record and applies the result to the domain. +*/ +int handle_tsc_info (struct xc_sr_context *ctx,struct xc_sr_record *rec); + +#endif +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
1.7.10.4
PATCH v9 7/15 tools/libxc: x86 PV common code
In reply to Andrew CooperAdd functions common to save and restore of x86 PV guests. This includes functions for dealing with the P2M and M2P and the VCPU context.
--- tools/libxc/Makefile | 1 + tools/libxc/xc_sr_common_x86_pv.c | 210 +++++++++++++++++++++++++++++++++++++ tools/libxc/xc_sr_common_x86_pv.h | 102 ++++++++++++++++++ 3 files changed, 313 insertions(+) create mode 100644 tools/libxc/xc_sr_common_x86_pv.c create mode 100644 tools/libxc/xc_sr_common_x86_pv.h
tools/libxc/Makefile +1 -0
@@ -55,6 +55,7 @@ ifeq ($(CONFIG_MIGRATE),y) GUEST_SRCS-y += xc_domain_restore.c xc_domain_save.c GUEST_SRCS-y += xc_sr_common.c GUEST_SRCS-$(CONFIG_X86) += xc_sr_common_x86.c +GUEST_SRCS-$(CONFIG_X86) += xc_sr_common_x86_pv.c GUEST_SRCS-y += xc_sr_restore.c GUEST_SRCS-y += xc_sr_save.c GUEST_SRCS-y += xc_offline_page.c xc_compression.c
tools/libxc/xc_sr_common_x86_pv.c new file +210 -0
210 lines not on this page · raw message
tools/libxc/xc_sr_common_x86_pv.h new file +102 -0
102 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH v9 07/15] tools/libxc: x86 PV common code
Quoted 4 lines · Andrew Cooper
Add functions common to save and restore of x86 PV guests. This includes functions for dealing with the P2M and M2P and the VCPU context.
Signed-off-by Andrew Cooper <[email protected]>
PATCH v9 8/15 tools/libxc: x86 PV save code
In reply to Andrew CooperSave the x86 PV specific parts of a domain. This is the X86_PV_INFO record, the P2M_FRAMES, the X86_PV_SHARED_INFO, the three different VCPU context records, and the MSR records.
The normalise_page callback used by the common code when writing the PAGE_DATA records, converts MFNs in page tables to PFNs.
--- tools/libxc/Makefile | 1 + tools/libxc/xc_sr_common.h | 1 + tools/libxc/xc_sr_save_x86_pv.c | 860 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 862 insertions(+) create mode 100644 tools/libxc/xc_sr_save_x86_pv.c
tools/libxc/Makefile +1 -0
@@ -56,6 +56,7 @@ GUEST_SRCS-y += xc_domain_restore.c xc_domain_save.c GUEST_SRCS-y += xc_sr_common.c GUEST_SRCS-$(CONFIG_X86) += xc_sr_common_x86.c GUEST_SRCS-$(CONFIG_X86) += xc_sr_common_x86_pv.c +GUEST_SRCS-$(CONFIG_X86) += xc_sr_save_x86_pv.c GUEST_SRCS-y += xc_sr_restore.c GUEST_SRCS-y += xc_sr_save.c GUEST_SRCS-y += xc_offline_page.c xc_compression.c
tools/libxc/xc_sr_common.h +1 -0
@@ -285,6 +285,7 @@ struct xc_sr_context }; }; +extern struct xc_sr_save_ops save_ops_x86_pv;struct xc_sr_record {
tools/libxc/xc_sr_save_x86_pv.c new file +860 -0
860 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH v9 08/15] tools/libxc: x86 PV save code
Quoted 8 lines · Andrew Cooper
Save the x86 PV specific parts of a domain. This is the
X86_PV_INFOrecord, theP2M_FRAMES, theX86_PV_SHARED_INFO, the three different VCPU context records, and the MSR records.The
normalise_pagecallback used by the common code when writing thePAGE_DATArecords, converts MFNs in page tables to PFNs.Signed-off-by Andrew Cooper <[email protected]>
With one question:
tools/libxc/xc_sr_save_x86_pv.c line 48
Quoted 9 lines
tools/libxc/xc_sr_save_x86_pv.c new file +9
-0+#ifdef __x86_64__ +/* 64bit toolstack, 32bit guest. Expand any INVALID_MFN. */ +uint32_t s = ((uint32_t *)src)[x]; + + dst[x] = s == ~0U ?INVALID_MFN : s; +#else +/* 32bit toolstack, 64bit guest. Truncate their pointers */ + dst[x] = ((uint64_t *)src)[x]; +#endif
Would it not be better to propagate an error instead of truncating? Or at least log the first instance of such?
Ian.
Re: [PATCH v9 08/15] tools/libxc: x86 PV save code
Quoted 13 lines · Ian Campbell
Quoted 8 lines · Andrew Cooper
Save the x86 PV specific parts of a domain. This is the
X86_PV_INFOrecord, theP2M_FRAMES, theX86_PV_SHARED_INFO, the three different VCPU context records, and the MSR records.The
normalise_pagecallback used by the common code when writing thePAGE_DATArecords, converts MFNs in page tables to PFNs.Signed-off-by Andrew Cooper <[email protected]>Acked-by Ian Campbell <[email protected]>With one question:
Quoted 11 lines
tools/libxc/xc_sr_save_x86_pv.c line 48
Quoted 9 lines
tools/libxc/xc_sr_save_x86_pv.c new file +9
-0+#ifdef __x86_64__ +/* 64bit toolstack, 32bit guest. Expand any INVALID_MFN. */ +uint32_t s = ((uint32_t *)src)[x]; + + dst[x] = s == ~0U ?INVALID_MFN : s; +#else +/* 32bit toolstack, 64bit guest. Truncate their pointers */ + dst[x] = ((uint64_t *)src)[x]; +#endif Would it not be better to propagate an error instead of truncating? Or at least log the first instance of such?
There are valid truncations to be performed, from 64bit INVALID_MFN to 32bit INVALID_MFN.
For the invalid truncations, that is a little harder. The post-trucated values are the ones which are checked for validity (so is at least safe from that point of view), and will fail because of a p2m/m2p mismatch, completely aborting the migration.
Truncation will only actually occur if a domain has pages above the 16TB (44 bits) boundary, and a 32bit dom0 is simply not going to function on a server that size.
In other words, I don't think there is a practical situation where truncation would be an issue.
~Andrew
Re: [PATCH v9 08/15] tools/libxc: x86 PV save code
Quoted 34 lines · Andrew Cooper
Quoted 13 lines · Ian Campbell
Quoted 8 lines · Andrew Cooper
Save the x86 PV specific parts of a domain. This is the
X86_PV_INFOrecord, theP2M_FRAMES, theX86_PV_SHARED_INFO, the three different VCPU context records, and the MSR records.The
normalise_pagecallback used by the common code when writing thePAGE_DATArecords, converts MFNs in page tables to PFNs.Signed-off-by Andrew Cooper <[email protected]>Acked-by Ian Campbell <[email protected]>With one question:
Quoted 11 lines
tools/libxc/xc_sr_save_x86_pv.c line 48
Quoted 9 lines
tools/libxc/xc_sr_save_x86_pv.c new file +9
-0+#ifdef __x86_64__ +/* 64bit toolstack, 32bit guest. Expand any INVALID_MFN. */ +uint32_t s = ((uint32_t *)src)[x]; + + dst[x] = s == ~0U ?INVALID_MFN : s; +#else +/* 32bit toolstack, 64bit guest. Truncate their pointers */ + dst[x] = ((uint64_t *)src)[x]; +#endif Would it not be better to propagate an error instead of truncating? Or at least log the first instance of such?
There are valid truncations to be performed, from 64bit
INVALID_MFNto 32bitINVALID_MFN.For the invalid truncations, that is a little harder. The post-trucated values are the ones which are checked for validity (so is at least safe from that point of view), and will fail because of a p2m/m2p mismatch, completely aborting the migration.
Quoted 6 lines
Truncation will only actually occur if a domain has pages above the 16TB (44 bits) boundary, and a 32bit dom0 is simply not going to function on a server that size.
In other words, I don't think there is a practical situation where truncation would be an issue.
OK, good to know, thanks.
I wonder if it is worth putting some of that in a comment or perhaps the commit log?
PATCH v9 9/15 tools/libxc: x86 PV restore code
In reply to Andrew CooperRestore the x86 PV specific parts. The X86_PV_INFO, the P2M_FRAMES, SHARED_INFO, and VCPU context records.
The localise_page callback is called from the common PAGE_DATA code to convert PFNs in page tables to MFNs.
Page tables are pinned and the guest's P2M is updated when the stream is complete.
--- tools/libxc/Makefile | 1 + tools/libxc/xc_sr_common.h | 10 + tools/libxc/xc_sr_restore.c | 125 ++++ tools/libxc/xc_sr_restore_x86_pv.c | 1153 ++++++++++++++++++++++++++++++++++++ 4 files changed, 1289 insertions(+) create mode 100644 tools/libxc/xc_sr_restore_x86_pv.c
tools/libxc/Makefile +1 -0
@@ -56,6 +56,7 @@ GUEST_SRCS-y += xc_domain_restore.c xc_domain_save.c GUEST_SRCS-y += xc_sr_common.c GUEST_SRCS-$(CONFIG_X86) += xc_sr_common_x86.c GUEST_SRCS-$(CONFIG_X86) += xc_sr_common_x86_pv.c +GUEST_SRCS-$(CONFIG_X86) += xc_sr_restore_x86_pv.c GUEST_SRCS-$(CONFIG_X86) += xc_sr_save_x86_pv.c GUEST_SRCS-y += xc_sr_restore.c GUEST_SRCS-y += xc_sr_save.c
tools/libxc/xc_sr_common.h +10 -0
@@ -287,6 +287,8 @@ struct xc_sr_contextextern struct xc_sr_save_ops save_ops_x86_pv; +extern struct xc_sr_restore_ops restore_ops_x86_pv; +struct xc_sr_record {uint32_t type;
@@ -321,6 +323,14 @@ static inline int write_record(struct xc_sr_context *ctx, return write_split_record(ctx, rec, NULL, 0); } +/* +* This would ideally be private in restore.c, but is needed by +* x86_pv_localise_page() if we receive pagetables frames ahead of the +* contents of the frames they point at. +*/ +int populate_pfns (struct xc_sr_context *ctx,unsigned count, +const xen_pfn_t *original_pfns,const uint32_t *types); +#endif /* * Local variables:
tools/libxc/xc_sr_restore.c +125 -0
130 lines not on this page · raw message
tools/libxc/xc_sr_restore_x86_pv.c new file +1153 -0
1,153 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH v9 09/15] tools/libxc: x86 PV restore code
Quoted 4 lines · Andrew Cooper
Restore the x86 PV specific parts. The
X86_PV_INFO, theP2M_FRAMES, +/*
+ * Set a pfn as populated, expanding the tracking structures if needed. To
+ * avoid realloc()ing too excessivly, the size increased to the nearest power
excessively.
Quoted 2 lines
+/*
+ * Update details in a guestsstart_infostrucutre.
structure.
Quoted 3 lines
+/*
+ * Processes X86_PV_VCPU_{BASIC,EXTENDED,XSAVE,MSRS} records from the stream.
+ * The blobs are all stashed to one side as they need to be defered until the
deferred.
Quoted 2 lines
+ * very end of the stream, rather than being send to Xen at the point they
+ * arive in the stream. It performs all pre-hypercall size validation.
arrive.
Quoted 10 lines
+ */
tools/libxc/xc_sr_restore_x86_pv.c new file +9
-0+static int handle_x86_pv_vcpu_blob (struct xc_sr_context *ctx, +struct xc_sr_record *rec) +{ +xc_interface *xch = ctx->xch; +struct xc_sr_rec_x86_pv_vcpu_hdr *vhdr = rec->data; +struct xc_sr_x86_pv_restore_vcpu *vcpu; +const char *rec_name; +size_t blobsz; +void *blob;
tools/libxc/xc_sr_restore_x86_pv.c line 738
Quoted 10 lines
tools/libxc/xc_sr_restore_x86_pv.c new file +10
-0+int rc =-1 ; + +switch ( rec->type ) + { +#define RECNAME (x, y) case (x): rec_name = (y) ; break +RECNAME (REC_TYPE_X86_PV_VCPU_BASIC ,"X86_PV_VCPU_BASIC" ); +RECNAME (REC_TYPE_X86_PV_VCPU_EXTENDED ,"X86_PV_VCPU_EXTENDED" ); +RECNAME (REC_TYPE_X86_PV_VCPU_XSAVE ,"X86_PV_VCPU_XSAVE" ); +RECNAME (REC_TYPE_X86_PV_VCPU_MSRS ,"X86_PV_VCPU_MSRS" ); +#undef RECNAME
I can see the point of STOREREC below but not this one unless you were to use cpp pasting to add the REC_TYPE_ prefix to a single argument. Otherwise the macro invocation doesn't seem to actually be any terser than the expansion.
tools/libxc/xc_sr_restore_x86_pv.c line 740
Quoted 2 lines
tools/libxc/xc_sr_restore_x86_pv.c new file +2
-0+default : + ERROR("Unrecogised vcpu blob record %s (%u)",
Unrecognised.
tools/libxc/xc_sr_restore_x86_pv.c line 820
Quoted 5 lines
tools/libxc/xc_sr_restore_x86_pv.c new file +5
-0+#define RECSTORE (x, y) case (x): free(y); (y) = blob; (y ## sz) = blobsz; break +RECSTORE (REC_TYPE_X86_PV_VCPU_BASIC , vcpu->basic); +RECSTORE (REC_TYPE_X86_PV_VCPU_EXTENDED , vcpu->extd); +RECSTORE (REC_TYPE_X86_PV_VCPU_XSAVE , vcpu->xsave); +RECSTORE (REC_TYPE_X86_PV_VCPU_MSRS , vcpu->msr);
Could optionally move some of the prefix of the first argument into the macro too.
Ian.
PATCH v9 10/15 tools/libxc: x86 HVM save code
In reply to Andrew CooperSave the x86 HVM specific parts of the domain. This is considerably simpler than an x86 PV domain. Only the HVM_CONTEXT and HVM_PARAMS records are needed.
There is no need for any page normalisation.
--- tools/libxc/Makefile | 1 + tools/libxc/xc_sr_common.h | 1 + tools/libxc/xc_sr_save_x86_hvm.c | 220 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 222 insertions(+) create mode 100644 tools/libxc/xc_sr_save_x86_hvm.c
tools/libxc/Makefile +1 -0
@@ -58,6 +58,7 @@ GUEST_SRCS-$(CONFIG_X86) += xc_sr_common_x86.c GUEST_SRCS-$(CONFIG_X86) += xc_sr_common_x86_pv.c GUEST_SRCS-$(CONFIG_X86) += xc_sr_restore_x86_pv.c GUEST_SRCS-$(CONFIG_X86) += xc_sr_save_x86_pv.c +GUEST_SRCS-$(CONFIG_X86) += xc_sr_save_x86_hvm.c GUEST_SRCS-y += xc_sr_restore.c GUEST_SRCS-y += xc_sr_save.c GUEST_SRCS-y += xc_offline_page.c xc_compression.c
tools/libxc/xc_sr_common.h +1 -0
@@ -286,6 +286,7 @@ struct xc_sr_context };extern struct xc_sr_save_ops save_ops_x86_pv; +extern struct xc_sr_save_ops save_ops_x86_hvm;extern struct xc_sr_restore_ops restore_ops_x86_pv;
tools/libxc/xc_sr_save_x86_hvm.c new file +220 -0
220 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH v9 10/15] tools/libxc: x86 HVM save code
Quoted 149 lines · Andrew Cooper
Save the x86 HVM specific parts of the domain. This is considerably simpler than an x86 PV domain. Only the
HVM_CONTEXTandHVM_PARAMSrecords are needed.There is no need for any page normalisation.
Signed-off-by Andrew Cooper <[email protected]>CC Ian Campbell <[email protected]>CC Ian Jackson <[email protected]>CC Wei Liu <[email protected]>--- tools/libxc/Makefile | 1 + tools/libxc/xc_sr_common.h | 1 + tools/libxc/xc_sr_save_x86_hvm.c | 220 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 222 insertions(+) create mode 100644 tools/libxc/xc_sr_save_x86_hvm.ctools/libxc/Makefile +1
-0@@ -58,6 +58,7 @@ GUEST_SRCS-$(CONFIG_X86) += xc_sr_common_x86.c GUEST_SRCS-$(CONFIG_X86) += xc_sr_common_x86_pv.c GUEST_SRCS-$(CONFIG_X86) += xc_sr_restore_x86_pv.c GUEST_SRCS-$(CONFIG_X86) += xc_sr_save_x86_pv.c +GUEST_SRCS-$(CONFIG_X86) += xc_sr_save_x86_hvm.c GUEST_SRCS-y += xc_sr_restore.c GUEST_SRCS-y += xc_sr_save.c GUEST_SRCS-y += xc_offline_page.c xc_compression.ctools/libxc/xc_sr_common.h +1
-0@@ -286,6 +286,7 @@ struct xc_sr_context };extern struct xc_sr_save_ops save_ops_x86_pv; +extern struct xc_sr_save_ops save_ops_x86_hvm;extern struct xc_sr_restore_ops restore_ops_x86_pv;tools/libxc/xc_sr_save_x86_hvm.c new file +102
-0@@ -0,0 +1,220 @@ +#include <assert.h> + +#include "xc_sr_common_x86.h" + +#include <xen/hvm/params.h> + +/* +* Query for the HVM context and write an HVM_CONTEXT record into the stream. +*/ +static int write_hvm_context (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; +int rc, hvm_buf_size; +struct xc_sr_record hvm_rec = + { + .type =REC_TYPE_HVM_CONTEXT , + }; + + hvm_buf_size =xc_domain_hvm_getcontext (xch, ctx->domid,0 ,0 ); +if ( hvm_buf_size <0 ) + { +PERROR ("Couldn't get HVM context size from Xen" ); + rc =-1 ; + goto out; + } + + hvm_rec.data =malloc (hvm_buf_size); +if ( !hvm_rec.data ) + { +PERROR ("Couldn't allocate memory" ); + rc =-1 ; + goto out; + } + + hvm_buf_size =xc_domain_hvm_getcontext (xch, ctx->domid, + hvm_rec.data, hvm_buf_size); +if ( hvm_buf_size <0 ) + { +PERROR ("Couldn't get HVM context from Xen" ); + rc =-1 ; + goto out; + } + + hvm_rec.length = hvm_buf_size; + rc =write_record (ctx, &hvm_rec); +if ( rc <0 ) + { +PERROR ("error write HVM_CONTEXT record" ); + goto out; + } + + out: +free (hvm_rec.data); +return rc; +} + +/* +* Query for a range of HVM parameters and write an HVM_PARAMS record into the +* stream. +*/ +static int write_hvm_params (struct xc_sr_context *ctx) +{ +static const unsigned int params[] = { +HVM_PARAM_STORE_PFN , +HVM_PARAM_IOREQ_PFN , +HVM_PARAM_BUFIOREQ_PFN , +HVM_PARAM_PAGING_RING_PFN , +HVM_PARAM_MONITOR_RING_PFN , +HVM_PARAM_SHARING_RING_PFN , +HVM_PARAM_VM86_TSS , +HVM_PARAM_CONSOLE_PFN , +HVM_PARAM_ACPI_IOPORTS_LOCATION , +HVM_PARAM_VIRIDIAN , +HVM_PARAM_IDENT_PT , +HVM_PARAM_PAE_ENABLED , +HVM_PARAM_VM_GENERATION_ID_ADDR , +HVM_PARAM_IOREQ_SERVER_PFN , +HVM_PARAM_NR_IOREQ_SERVER_PAGES , + }; + +xc_interface *xch = ctx->xch; +struct xc_sr_rec_hvm_params_entry entries[ARRAY_SIZE (params)]; +struct xc_sr_rec_hvm_params hdr = { + .count =0 , + }; +struct xc_sr_record rec = { + .type =REC_TYPE_HVM_PARAMS , + .length =sizeof (hdr), + .data = &hdr, + }; +unsigned int i; +int rc; + +for ( i =0 ; i <ARRAY_SIZE (params); i++ ) + { +uint32_t index = params[i]; +uint64_t value; + + rc =xc_hvm_param_get (xch, ctx->domid, index, &value); +if ( rc ) + { +PERROR ("Failed to get HVMPARAM at index %u" , index);
tools/libxc/xc_sr_save_x86_hvm.c line 112
Quoted 10 lines
tools/libxc/xc_sr_save_x86_hvm.c new file +10
-0+return rc; + } + +if ( value !=0 ) + { + entries[hdr.count].index = index; + entries[hdr.count].value = value; + hdr.count++; + } + }
While reviewing my 'soft reset' series Ian C raised a question about the unsafeness of sequential get/set of HVM params:
http://lists.xen.org/archives/html/xen-devel/2015-01/msg01177.html
In case the concern is valid I think the requirements for migration are even stricter as we can migrate live. In case it is not, would it be possible to move your params[] array to some common place so it can be reused?
Quoted 108 lines
tools/libxc/xc_sr_save_x86_hvm.c new file +108
-0+ + rc =write_split_record (ctx, &rec, entries, hdr.count *sizeof (*entries)); +if ( rc ) +PERROR ("Failed to write HVM_PARAMS record" ); + +return rc; +} + +static xen_pfn_t x86_hvm_pfn_to_gfn (const struct xc_sr_context *ctx, +xen_pfn_t pfn) +{ +/* identity map */ +return pfn; +} + +static int x86_hvm_normalise_page (struct xc_sr_context *ctx, +xen_pfn_t type,void **page) +{ +/* no-op */ +return 0 ; +} + +static int x86_hvm_setup (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; + +if ( !ctx->save.callbacks->switch_qemu_logdirty ) + { +ERROR ("No switch_qemu_logdirty callback provided" ); + errno =EINVAL ; +return -1 ; + } + +if ( ctx->save.callbacks->switch_qemu_logdirty ( + ctx->domid,1 , ctx->save.callbacks->data) ) + { +PERROR ("Couldn't enable qemu log-dirty mode" ); +return -1 ; + } + + ctx->x86_hvm.save.qemu_enabled_logdirty = true; + +return 0 ; +} + +static int x86_hvm_start_of_stream (struct xc_sr_context *ctx) +{ +/* no-op */ +return 0 ; +} + +static int x86_hvm_end_of_stream (struct xc_sr_context *ctx) +{ +int rc; + +/* Write the TSC record. */ + rc =write_tsc_info (ctx); +if ( rc ) +return rc; + +/* Write the HVM_CONTEXT record. */ + rc =write_hvm_context (ctx); +if ( rc ) +return rc; + +/* Write HVM_PARAMS record contains applicable HVM params. */ + rc =write_hvm_params (ctx); +if ( rc ) +return rc; + +return rc; +} + +static int x86_hvm_cleanup (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; + +/* If qemu successfully enabled logdirty mode, attempt to disable. */ +if ( ctx->x86_hvm.save.qemu_enabled_logdirty && + ctx->save.callbacks->switch_qemu_logdirty ( + ctx->domid,0 , ctx->save.callbacks->data) ) + { +PERROR ("Couldn't disable qemu log-dirty mode" ); +return -1 ; + } + +return 0 ; +} + +struct xc_sr_save_ops save_ops_x86_hvm = +{ + .pfn_to_gfn = x86_hvm_pfn_to_gfn, + .normalise_page = x86_hvm_normalise_page, + .setup = x86_hvm_setup, + .start_of_stream = x86_hvm_start_of_stream, + .end_of_stream = x86_hvm_end_of_stream, + .cleanup = x86_hvm_cleanup, +}; + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
Vitaly
Re: [PATCH v9 10/15] tools/libxc: x86 HVM save code
Quoted 62 lines · Vitaly Kuznetsov
Quoted 46 lines · Andrew Cooper
tools/libxc/xc_sr_save_x86_hvm.c new file +46
-0+/* +* Query for a range of HVM parameters and write an HVM_PARAMS record into the +* stream. +*/ +static int write_hvm_params (struct xc_sr_context *ctx) +{ +static const unsigned int params[] = { +HVM_PARAM_STORE_PFN , +HVM_PARAM_IOREQ_PFN , +HVM_PARAM_BUFIOREQ_PFN , +HVM_PARAM_PAGING_RING_PFN , +HVM_PARAM_MONITOR_RING_PFN , +HVM_PARAM_SHARING_RING_PFN , +HVM_PARAM_VM86_TSS , +HVM_PARAM_CONSOLE_PFN , +HVM_PARAM_ACPI_IOPORTS_LOCATION , +HVM_PARAM_VIRIDIAN , +HVM_PARAM_IDENT_PT , +HVM_PARAM_PAE_ENABLED , +HVM_PARAM_VM_GENERATION_ID_ADDR , +HVM_PARAM_IOREQ_SERVER_PFN , +HVM_PARAM_NR_IOREQ_SERVER_PAGES , + }; + +xc_interface *xch = ctx->xch; +struct xc_sr_rec_hvm_params_entry entries[ARRAY_SIZE (params)]; +struct xc_sr_rec_hvm_params hdr = { + .count =0 , + }; +struct xc_sr_record rec = { + .type =REC_TYPE_HVM_PARAMS , + .length =sizeof (hdr), + .data = &hdr, + }; +unsigned int i; +int rc; + +for ( i =0 ; i <ARRAY_SIZE (params); i++ ) + { +uint32_t index = params[i]; +uint64_t value; + + rc =xc_hvm_param_get (xch, ctx->domid, index, &value); +if ( rc ) + { +PERROR ("Failed to get HVMPARAM at index %u" , index);tools/libxc/xc_sr_save_x86_hvm.c line 112
Quoted 10 lines
tools/libxc/xc_sr_save_x86_hvm.c new file +10
-0+return rc; + } + +if ( value !=0 ) + { + entries[hdr.count].index = index; + entries[hdr.count].value = value; + hdr.count++; + } + }While reviewing my 'soft reset' series Ian C raised a question about the unsafeness of sequential get/set of HVM params:
http://lists.xen.org/archives/html/xen-devel/2015-01/msg01177.html
Quoted 4 lines
In case the concern is valid I think the requirements for migration are even stricter as we can migrate live. In case it is not, would it be possible to move your params[] array to some common place so it can be reused?
This code currently mirrors what the old migration did. This was one area we deliberately didn't try to clean up (we were focusing on a functional replacement).
I am not a fan of hvm params. They are used as a dumping ground for things which IMO should live elsewhere. The result is this mess, without any clear direction of who owns which parameter, which should move on migration, which shouldn't etc. There are many areas of the toolstack which independently poke at the parameters.
I would be hesitant to blindly lift this code out, although it is probably the best start you will find.
What is really needed is formal statement of who owns which hvm params, and what their purpose is. That would at least be a good starting point for evaluating questions like this.
~Andrew
Re: [PATCH v9 10/15] tools/libxc: x86 HVM save code
Quoted 3 lines · Andrew Cooper
Quoted 3 lines
Quoted 3 lines
tools/libxc/xc_sr_save_x86_hvm.c new file +3
-0+static int write_hvm_params (struct xc_sr_context *ctx) +{ +static const unsigned int params[] = {
[...]
Quoted 7 lines
Quoted 4 lines
While reviewing my 'soft reset' series Ian C raised a question about the unsafeness of sequential get/set of HVM params:
http://lists.xen.org/archives/html/xen-devel/2015-01/msg01177.html
[...]This code currently mirrors what the old migration did. This was one area we deliberately didn't try to clean up (we were focusing on a functional replacement).
Apart from what else you say (which I agree with) I think all Vitaly was asking here was whether your params[] array could be moved into a location which was accessible to the rest of libxc.
In any case I would say it would be fine for the second user to refactor out any list which the first one added. Gentlemen, start your engines ;-)
Ian.
Re: [PATCH v9 10/15] tools/libxc: x86 HVM save code
In reply to Andrew CooperQuoted 7 lines · Andrew Cooper
Save the x86 HVM specific parts of the domain. This is considerably simpler than an x86 PV domain. Only the
HVM_CONTEXTandHVM_PARAMSrecords are needed.There is no need for any page normalisation.
Signed-off-by Andrew Cooper <[email protected]>
PATCH v9 11/15 tools/libxc: x86 HVM restore code
In reply to Andrew CooperRestore the x86 HVM specific parts of a domain. This is the HVM_CONTEXT and HVM_PARAMS records.
There is no need for any page localisation.
This also includes writing the trailing qemu save record to a file because this is what libxc currently does. This is intended to be moved into libxl proper in the future.
--- tools/libxc/Makefile | 1 + tools/libxc/xc_sr_common.h | 1 + tools/libxc/xc_sr_restore_x86_hvm.c | 225 +++++++++++++++++++++++++++++++++++ 3 files changed, 227 insertions(+) create mode 100644 tools/libxc/xc_sr_restore_x86_hvm.c
tools/libxc/Makefile +1 -0
@@ -57,6 +57,7 @@ GUEST_SRCS-y += xc_sr_common.c GUEST_SRCS-$(CONFIG_X86) += xc_sr_common_x86.c GUEST_SRCS-$(CONFIG_X86) += xc_sr_common_x86_pv.c GUEST_SRCS-$(CONFIG_X86) += xc_sr_restore_x86_pv.c +GUEST_SRCS-$(CONFIG_X86) += xc_sr_restore_x86_hvm.c GUEST_SRCS-$(CONFIG_X86) += xc_sr_save_x86_pv.c GUEST_SRCS-$(CONFIG_X86) += xc_sr_save_x86_hvm.c GUEST_SRCS-y += xc_sr_restore.c
tools/libxc/xc_sr_common.h +1 -0
@@ -289,6 +289,7 @@ struct xc_sr_contextextern struct xc_sr_save_ops save_ops_x86_hvm;extern struct xc_sr_restore_ops restore_ops_x86_pv; +extern struct xc_sr_restore_ops restore_ops_x86_hvm;struct xc_sr_record {
tools/libxc/xc_sr_restore_x86_hvm.c new file +225 -0
225 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH v9 11/15] tools/libxc: x86 HVM restore code
Quoted 10 lines · Andrew Cooper
Restore the x86 HVM specific parts of a domain. This is the
HVM_CONTEXTandHVM_PARAMSrecords.There is no need for any page localisation.
This also includes writing the trailing qemu save record to a file because this is what libxc currently does. This is intended to be moved into libxl proper in the future.
Signed-off-by Andrew Cooper <[email protected]>
PATCH v9 12/15 tools/libxc: noarch save code
In reply to Andrew CooperSave a domain, calling domain type specific function at the appropriate points. This implements the xc_domain_save2() API function which is equivalent to the existing xc_domain_save().
This writes the image and domain headers, and writes all the PAGE_DATA records using a "live" process.
--- tools/libxc/xc_sr_save.c | 777 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 776 insertions(+), 1 deletion(-)
tools/libxc/xc_sr_save.c +776 -1
@@ -1,11 +1,786 @@ +#include <assert.h> +#include <arpa/inet.h> +#include "xc_sr_common.h" +/* +* Writes an Image header and Domain header into the stream. +*/ +static int write_headers (struct xc_sr_context *ctx,uint16_t guest_type) +{ +xc_interface *xch = ctx->xch; +int32_t xen_version =xc_version (xch, XENVER_version,NULL ); +struct xc_sr_ihdr ihdr = + { + .marker =IHDR_MARKER , + .id =htonl (IHDR_ID ), + .version =htonl (IHDR_VERSION ), + .options =htons (IHDR_OPT_LITTLE_ENDIAN ), + }; +struct xc_sr_dhdr dhdr = + { + .type = guest_type, + .page_shift =XC_PAGE_SHIFT , + .xen_major = (xen_version >>16 ) &0xffff , + .xen_minor = (xen_version) &0xffff , + }; + +if ( xen_version <0 ) + { +PERROR ("Unable to obtain Xen Version" ); +return -1 ; + } + +if (write_exact (ctx->fd, &ihdr,sizeof (ihdr)) ) + { +PERROR ("Unable to write Image Header to stream" ); +return -1 ; + } + +if (write_exact (ctx->fd, &dhdr,sizeof (dhdr)) ) + { +PERROR ("Unable to write Domain Header to stream" ); +return -1 ; + } + +return 0 ; +} + +/* +* Writes an END record into the stream. +*/ +static int write_end_record (struct xc_sr_context *ctx) +{ +struct xc_sr_record end = {REC_TYPE_END ,0 ,NULL }; + +return write_record (ctx, &end); +} + +/* +* Writes a batch of memory as a PAGE_DATA record into the stream. The batch +* is constructed in ctx->save.batch_pfns. +* +* This function: +* - gets the types for each pfn in the batch. +* - for each pfn with real data: +* - maps and attempts to localise the pages. +* - construct and writes a PAGE_DATA record into the stream. +*/ +static int write_batch (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; +xen_pfn_t *mfns =NULL , *types =NULL ; +void *guest_mapping =NULL ; +void **guest_data =NULL ; +void **local_pages =NULL ; +int *errors =NULL , rc =-1 ; +unsigned i, p, nr_pages =0 ; +unsigned nr_pfns = ctx->save.nr_batch_pfns; +void *page, *orig_page; +uint64_t *rec_pfns =NULL ; +struct iovec *iov =NULL ;int iovcnt =0 ; +struct xc_sr_rec_page_data_header hdr = {0 }; +struct xc_sr_record rec = + { + .type =REC_TYPE_PAGE_DATA , + }; + +assert (nr_pfns !=0 ); + +/* Mfns of the batch pfns. */ + mfns =malloc (nr_pfns *sizeof (*mfns)); +/* Types of the batch pfns. */ + types =malloc (nr_pfns *sizeof (*types)); +/* Errors from attempting to map the gfns. */ + errors =malloc (nr_pfns *sizeof (*errors)); +/* Pointers to page data to send. Mapped gfns or local allocations. */ + guest_data =calloc (nr_pfns,sizeof (*guest_data)); +/* Pointers to locally allocated pages. Need freeing. */ + local_pages =calloc (nr_pfns,sizeof (*local_pages)); +/* iovec[] for writev(). */ + iov =malloc ((nr_pfns +4 ) *sizeof (*iov)); + +if ( !mfns || !types || !errors || !guest_data || !local_pages || !iov ) + { +ERROR ("Unable to allocate arrays for a batch of %u pages" , + nr_pfns); + goto err; + } + +for ( i =0 ; i < nr_pfns; ++i ) + { + types[i] = mfns[i] = ctx->save.ops.pfn_to_gfn (ctx, + ctx->save.batch_pfns[i]); + +/* Likely a ballooned page. */ +if ( mfns[i] ==INVALID_MFN ) + { +set_bit (ctx->save.batch_pfns[i], ctx->save.deferred_pages); + ++ctx->save.nr_deferred_pages; + } + } + + rc =xc_get_pfn_type_batch (xch, ctx->domid, nr_pfns, types); +if ( rc ) + { +PERROR ("Failed to get types for pfn batch" ); + goto err; + } + rc =-1 ; + +for ( i =0 ; i < nr_pfns; ++i ) + { +switch ( types[i] ) + { +case XEN_DOMCTL_PFINFO_BROKEN : +case XEN_DOMCTL_PFINFO_XALLOC : +case XEN_DOMCTL_PFINFO_XTAB : +continue ; + } + + mfns[nr_pages++] = mfns[i]; + } + +if ( nr_pages >0 ) + { + guest_mapping =xc_map_foreign_bulk ( + xch, ctx->domid,PROT_READ , mfns, errors, nr_pages); +if ( !guest_mapping ) + { +PERROR ("Failed to map guest pages" ); + goto err; + } + +for ( i =0 , p =0 ; i < nr_pfns; ++i ) + { +switch ( types[i] ) + { +case XEN_DOMCTL_PFINFO_BROKEN : +case XEN_DOMCTL_PFINFO_XALLOC : +case XEN_DOMCTL_PFINFO_XTAB : +continue ; + } + +if ( errors[p] ) + { +ERROR ("Mapping of pfn %#lx (mfn %#lx) failed %d" , + ctx->save.batch_pfns[i], mfns[p], errors[p]); + goto err; + } + + orig_page = page = guest_mapping + (p *PAGE_SIZE ); + rc = ctx->save.ops.normalise_page (ctx, types[i], &page); + +if ( orig_page != page ) + local_pages[i] = page; + +if ( rc ) + { +if ( rc ==-1 && errno ==EAGAIN ) + { +set_bit (ctx->save.batch_pfns[i], ctx->save.deferred_pages); + ++ctx->save.nr_deferred_pages; + types[i] =XEN_DOMCTL_PFINFO_XTAB ; + --nr_pages; + } +else + goto err; + } +else + guest_data[i] = page; + + rc =-1 ; + ++p; + } + } + + rec_pfns =malloc (nr_pfns *sizeof (*rec_pfns)); +if ( !rec_pfns ) + { +ERROR ("Unable to allocate %zu bytes of memory for page data pfn list" , + nr_pfns *sizeof (*rec_pfns)); + goto err; + } + + hdr.count = nr_pfns; + + rec.length =sizeof (hdr); + rec.length += nr_pfns *sizeof (*rec_pfns); + rec.length += nr_pages *PAGE_SIZE ; + +for ( i =0 ; i < nr_pfns; ++i ) + rec_pfns[i] = ((uint64_t )(types[i]) <<32 ) | ctx->save.batch_pfns[i]; + + iov[0 ].iov_base = &rec.type; + iov[0 ].iov_len =sizeof (rec.type); + + iov[1 ].iov_base = &rec.length; + iov[1 ].iov_len =sizeof (rec.length); + + iov[2 ].iov_base = &hdr; + iov[2 ].iov_len =sizeof (hdr); + + iov[3 ].iov_base = rec_pfns; + iov[3 ].iov_len = nr_pfns *sizeof (*rec_pfns); + + iovcnt =4 ; + +if ( nr_pages ) + { +for ( i =0 ; i < nr_pfns; ++i ) + { +if ( guest_data[i] ) + { + iov[iovcnt].iov_base = guest_data[i]; + iov[iovcnt].iov_len =PAGE_SIZE ; + iovcnt++; + --nr_pages; + } + } + } + +if (writev_exact (ctx->fd, iov, iovcnt) ) + { +PERROR ("Failed to write page data to stream" ); + goto err; + } + +/* Sanity check we have sent all the pages we expected to. */ +assert (nr_pages ==0 ); + rc = ctx->save.nr_batch_pfns =0 ; + + err: +free (rec_pfns); +if ( guest_mapping ) +munmap (guest_mapping, nr_pages *PAGE_SIZE ); +for ( i =0 ; local_pages && i < nr_pfns; ++i ) +free (local_pages[i]); +free (iov); +free (local_pages); +free (guest_data); +free (errors); +free (types); +free (mfns); + +return rc; +} + +/* +* Flush a batch of pfns into the stream. +*/ +static int flush_batch (struct xc_sr_context *ctx) +{ +int rc =0 ; + +if ( ctx->save.nr_batch_pfns ==0 ) +return rc; + + rc =write_batch (ctx); + +if ( !rc ) + { +VALGRIND_MAKE_MEM_UNDEFINED (ctx->save.batch_pfns, +MAX_BATCH_SIZE * +sizeof (*ctx->save.batch_pfns)); + } + +return rc; +} + +/* +* Add a single pfn to the batch, flushing the batch if full. +*/ +static int add_to_batch (struct xc_sr_context *ctx,xen_pfn_t pfn) +{ +int rc =0 ; + +if ( ctx->save.nr_batch_pfns ==MAX_BATCH_SIZE ) + rc =flush_batch (ctx); + +if ( rc ==0 ) + ctx->save.batch_pfns[ctx->save.nr_batch_pfns++] = pfn; + +return rc; +} + +/* +* Pause/suspend the domain, and refresh ctx->dominfo if required. +*/ +static int suspend_domain (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; + +/* TODO: Properly specify the return value from this callback. All +* implementations currently appear to return 1 for success, whereas +* the legacy code checks for != 0. */ +int cb_rc = ctx->save.callbacks->suspend (ctx->save.callbacks->data); + +if ( cb_rc ==0 ) + { +ERROR ("save callback suspend() failed: %d" , cb_rc); +return -1 ; + } + +/* Refresh domain information. */ +if ( (xc_domain_getinfo (xch, ctx->domid,1 , &ctx->dominfo) !=1 ) || + (ctx->dominfo.domid != ctx->domid) ) + { +PERROR ("Unable to refresh domain information" ); +return -1 ; + } + +/* Confirm the domain has actually been paused. */ +if ( !ctx->dominfo.shutdown || + (ctx->dominfo.shutdown_reason != SHUTDOWN_suspend) ) + { +ERROR ("Domain has not been suspended: shutdown %d, reason %d" , + ctx->dominfo.shutdown, ctx->dominfo.shutdown_reason); +return -1 ; + } + +xc_report_progress_single (xch,"Domain now suspended" ); + +return 0 ; +} + +/* +* Send all pages in the guests p2m. Used as the first iteration of the live +* migration loop, and for a non-live save. +*/ +static int send_all_pages (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; +xen_pfn_t p; +int rc; + +for ( p =0 ; p < ctx->save.p2m_size; ++p ) + { + rc =add_to_batch (ctx, p); +if ( rc ) +return rc; + +/* Update progress every 4MB worth of memory sent. */ +if ( (p & ((1U << (22 -12 )) -1 )) ==0 ) +xc_report_progress_step (xch, p, ctx->save.p2m_size); + } + + rc =flush_batch (ctx); +if ( rc ) +return rc; + +xc_report_progress_step (xch, ctx->save.p2m_size, + ctx->save.p2m_size); +return 0 ; +} + +/* +* Send a subset of pages in the guests p2m, according to the provided bitmap. +* Used for each subsequent iteration of the live migration loop. +* +* Bitmap is bounded by p2m_size. +*/ +static int send_some_pages (struct xc_sr_context *ctx, +unsigned long *bitmap, +unsigned long entries) +{ +xc_interface *xch = ctx->xch; +xen_pfn_t p; +unsigned long written; +int rc; + +for ( p =0 , written =0 ; p < ctx->save.p2m_size; ++p ) + { +if ( !test_bit (p, bitmap) ) +continue ; + + rc =add_to_batch (ctx, p); +if ( rc ) +return rc; + +/* Update progress every 4MB worth of memory sent. */ +if ( (written & ((1U << (22 -12 )) -1 )) ==0 ) +xc_report_progress_step (xch, written, entries); + + ++written; + } + + rc =flush_batch (ctx); +if ( rc ) +return rc; + +if ( written > entries ) +DPRINTF ("Bitmap contained more entries than expected..." ); + +xc_report_progress_step (xch, entries, entries); +return 0 ; +} + +static int enable_logdirty (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; +int on1 =0 , off =0 , on2 =0 ; +int rc; + +/* This juggling is required if logdirty is enabled for VRAM tracking. */ + rc =xc_shadow_control (xch, ctx->domid, +XEN_DOMCTL_SHADOW_OP_ENABLE_LOGDIRTY , +NULL ,0 ,NULL ,0 ,NULL ); +if ( rc <0 ) + { + on1 = errno; + rc =xc_shadow_control (xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_OFF , +NULL ,0 ,NULL ,0 ,NULL ); +if ( rc <0 ) + off = errno; +else { + rc =xc_shadow_control (xch, ctx->domid, +XEN_DOMCTL_SHADOW_OP_ENABLE_LOGDIRTY , +NULL ,0 ,NULL ,0 ,NULL ); +if ( rc <0 ) + on2 = errno; + } +if ( rc <0 ) + { +PERROR ("Failed to enable logdirty: %d,%d,%d" , on1, off, on2); +return rc; + } + } + +return 0 ; +} + +static int update_progress_string (struct xc_sr_context *ctx, +char **str,unsigned iter) +{ +xc_interface *xch = ctx->xch; +char *new_str =NULL ; + +if (asprintf (&new_str,"Memory iteration %u of %u" , + iter, ctx->save.max_iterations) ==-1 ) + { +PERROR ("Unable to allocate new progress string" ); +return -1 ; + } + +free (*str); + *str = new_str; + +xc_set_progress_prefix (xch, *str); +return 0 ; +} + +/* +* Send all domain memory. This is the heart of the live migration loop. +*/ +static int send_domain_memory_live (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; + DECLARE_HYPERCALL_BUFFER(unsigned long, to_send); +xc_shadow_op_stats_t stats = {0 , ctx->save.p2m_size }; +char *progress_str =NULL ; +unsigned x; +int rc =-1 ; + + to_send =xc_hypercall_buffer_alloc_pages ( + xch, to_send,NRPAGES (bitmap_size (ctx->save.p2m_size))); + + ctx->save.batch_pfns =malloc (MAX_BATCH_SIZE * +sizeof (*ctx->save.batch_pfns)); + ctx->save.deferred_pages =calloc (1 ,bitmap_size (ctx->save.p2m_size)); + +if ( !ctx->save.batch_pfns || !to_send || !ctx->save.deferred_pages ) + { +ERROR ("Unable to allocate memory for to_{send,fix}/batch bitmaps" ); + goto out; + } + + rc =enable_logdirty (ctx); +if ( rc ) + goto out; + + rc =update_progress_string (ctx, &progress_str,0 ); +if ( rc ) + goto out; + + rc =send_all_pages (ctx); +if ( rc ) + goto out; + +for ( x =1 ; + ((x < ctx->save.max_iterations) && + (stats.dirty_count > ctx->save.dirty_threshold)); ++x ) + { +if (xc_shadow_control ( + xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_CLEAN , +HYPERCALL_BUFFER (to_send), ctx->save.p2m_size, +NULL ,0 , &stats) != ctx->save.p2m_size ) + { +PERROR ("Failed to retrieve logdirty bitmap" ); + rc =-1 ; + goto out; + } + +if ( stats.dirty_count ==0 ) +break ; + + rc =update_progress_string (ctx, &progress_str, x); +if ( rc ) + goto out; + + rc =send_some_pages (ctx, to_send, stats.dirty_count); +if ( rc ) + goto out; + } + + rc =suspend_domain (ctx); +if ( rc ) + goto out; + +if (xc_shadow_control ( + xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_CLEAN , +HYPERCALL_BUFFER (to_send), ctx->save.p2m_size, +NULL ,0 , &stats) != ctx->save.p2m_size ) + { +PERROR ("Failed to retrieve logdirty bitmap" ); + rc =-1 ; + goto out; + } + + rc =update_progress_string (ctx, &progress_str, ctx->save.max_iterations); +if ( rc ) + goto out; + +bitmap_or (to_send, ctx->save.deferred_pages, ctx->save.p2m_size); + + rc =send_some_pages (ctx, to_send, + stats.dirty_count + ctx->save.nr_deferred_pages); +if ( rc ) + goto out; + +if ( ctx->save.debug ) + { +struct xc_sr_record rec = + { + .type =REC_TYPE_VERIFY , + .length =0 , + }; + +DPRINTF ("Enabling verify mode" ); + + rc =write_record (ctx, &rec); +if ( rc ) + goto out; + +xc_set_progress_prefix (xch,"Memory verify" ); + rc =send_all_pages (ctx); +if ( rc ) + goto out; + +if (xc_shadow_control ( + xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_PEEK , +HYPERCALL_BUFFER (to_send), ctx->save.p2m_size, +NULL ,0 , &stats) != ctx->save.p2m_size ) + { +PERROR ("Failed to retrieve logdirty bitmap" ); + rc =-1 ; + goto out; + } + +DPRINTF (" Further stats: faults %u, dirty %u" , + stats.fault_count, stats.dirty_count); + } + + out: +xc_set_progress_prefix (xch,NULL ); +free (progress_str); +xc_hypercall_buffer_free_pages (xch, to_send, +NRPAGES (bitmap_size (ctx->save.p2m_size))); +free (ctx->save.deferred_pages); +free (ctx->save.batch_pfns); +return rc; +} + +/* +* Send all domain memory, pausing the domain first. Generally used for +* suspend-to-file. +*/ +static int send_domain_memory_nonlive (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; +int rc =-1 ; + + ctx->save.batch_pfns =malloc (MAX_BATCH_SIZE * +sizeof (*ctx->save.batch_pfns)); + ctx->save.deferred_pages =calloc (1 ,bitmap_size (ctx->save.p2m_size)); + +if ( !ctx->save.batch_pfns || !ctx->save.deferred_pages ) + { +PERROR ("Failed to allocate memory for nonlive tracking structures" ); + errno =ENOMEM ; + goto err; + } + + rc =suspend_domain (ctx); +if ( rc ) + goto err; + +xc_set_progress_prefix (xch,"Memory" ); + + rc =send_all_pages (ctx); +if ( rc ) + goto err; + + err: +free (ctx->save.deferred_pages); +free (ctx->save.batch_pfns); + +return rc; +} + +/* +* Save a domain. +*/ +static int save (struct xc_sr_context *ctx,uint16_t guest_type) +{ +xc_interface *xch = ctx->xch; +int rc, saved_rc =0 , saved_errno =0 ; + +IPRINTF ("Saving domain %d, type %s" , + ctx->domid,dhdr_type_to_str (guest_type)); + + rc = ctx->save.ops.setup (ctx); +if ( rc ) + goto err; + +xc_report_progress_single (xch,"Start of stream" ); + + rc =write_headers (ctx, guest_type); +if ( rc ) + goto err; + + rc = ctx->save.ops.start_of_stream (ctx); +if ( rc ) + goto err; + +if ( ctx->save.live ) + rc =send_domain_memory_live (ctx); +else + rc =send_domain_memory_nonlive (ctx); + +if ( rc ) + goto err; + +if ( !ctx->dominfo.shutdown || + (ctx->dominfo.shutdown_reason != SHUTDOWN_suspend) ) + { +ERROR ("Domain has not been suspended" ); + rc =-1 ; + goto err; + } + +xc_report_progress_single (xch,"End of stream" ); + + rc = ctx->save.ops.end_of_stream (ctx); +if ( rc ) + goto err; + + rc =write_end_record (ctx); +if ( rc ) + goto err; + +xc_report_progress_single (xch,"Complete" ); + goto done; + + err: + saved_errno = errno; + saved_rc = rc; +PERROR ("Save failed" ); + + done: +xc_shadow_control (xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_OFF , +NULL ,0 ,NULL ,0 ,NULL ); + + rc = ctx->save.ops.cleanup (ctx); +if ( rc ) +PERROR ("Failed to clean up" ); + +if ( saved_rc ) + { + rc = saved_rc; + errno = saved_errno; + } + +return rc; +}; +int xc_domain_save2 (xc_interface *xch,int io_fd,uint32_t dom,uint32_t max_iters,uint32_t max_factor,uint32_t flags,struct save_callbacks * callbacks,int hvm) { +xen_pfn_t nr_pfns; +struct xc_sr_context ctx = + { + .xch = xch, + .fd = io_fd, + }; + +/* GCC 4.4 (of CentOS 6.x vintage) can' t initialise anonymous unions :( */ + ctx.save.callbacks = callbacks; + ctx.save.live = !!(flags &XCFLAGS_LIVE ); + ctx.save.debug = !!(flags &XCFLAGS_DEBUG ); + +/* +* TODO: Find some time to better tweak the live migration algorithm. +* +* These parameters are better than the legacy algorithm especially for +* busy guests. +*/ + ctx.save.max_iterations =5 ; + ctx.save.dirty_threshold =50 ; +IPRINTF ("In experimental %s" , __func__); -return -1 ; +DPRINTF ("fd %d, dom %u, max_iters %u, max_factor %u, flags %u, hvm %d" , + io_fd, dom, max_iters, max_factor, flags, hvm); + +if (xc_domain_getinfo (xch, dom,1 , &ctx.dominfo) !=1 ) + { +PERROR ("Failed to get domain info" ); +return -1 ; + } + +if ( ctx.dominfo.domid != dom ) + { +ERROR ("Domain %u does not exist" , dom); +return -1 ; + } + + ctx.domid = dom; + +if (xc_domain_nr_gpfns (xch, dom, &nr_pfns) <0 ) + { +PERROR ("Unable to obtain the guest p2m size" ); +return -1 ; + } + + ctx.save.p2m_size = nr_pfns; + +if ( ctx.save.p2m_size > ~XEN_DOMCTL_PFINFO_LTAB_MASK ) + { + errno =E2BIG ; +ERROR ("Cannot save this big a guest" ); +return -1 ; + } + +if ( ctx.dominfo.hvm ) + { + ctx.save.ops = save_ops_x86_hvm; +return save (&ctx,DHDR_TYPE_X86_HVM ); + } +else + { + ctx.save.ops = save_ops_x86_pv; +return save (&ctx,DHDR_TYPE_X86_PV ); + } }/*
Signature · 1 line
1.7.10.4
Re: [PATCH v9 12/15] tools/libxc: noarch save code
Quoted 8 lines · Andrew Cooper
Save a domain, calling domain type specific function at the appropriate points. This implements the
xc_domain_save2()API function which is equivalent to the existingxc_domain_save().This writes the image and domain headers, and writes all the
PAGE_DATArecords using a "live" process.Signed-off-by Andrew Cooper <[email protected]>
I think most people would describe noarch code as "generic" or "common", but otherwise:
PATCH v9 13/15 tools/libxc: noarch restore code
In reply to Andrew CooperRestore a domain from the new format. This reads and validates the domain and image header and loads the guest memory from the PAGE_DATA records, populating the p2m as it does so.
This provides the xc_domain_restore2() function as an alternative to the existing xc_domain_restore().
--- tools/libxc/xc_sr_restore.c | 503 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 501 insertions(+), 2 deletions(-)
tools/libxc/xc_sr_restore.c +501 -2
@@ -1,6 +1,133 @@ +#include <arpa/inet.h> +#include "xc_sr_common.h" /* +* Read and validate the Image and Domain headers. +*/ +static int read_headers (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; +struct xc_sr_ihdr ihdr; +struct xc_sr_dhdr dhdr; + +if (read_exact (ctx->fd, &ihdr,sizeof (ihdr)) ) + { +PERROR ("Failed to read Image Header from stream" ); +return -1 ; + } + + ihdr.id =ntohl (ihdr.id); + ihdr.version =ntohl (ihdr.version); + ihdr.options =ntohs (ihdr.options); + +if ( ihdr.marker !=IHDR_MARKER ) + { +ERROR ("Invalid marker: Got 0x%016" PRIx64, ihdr.marker); +return -1 ; + } +else if ( ihdr.id !=IHDR_ID ) + { +ERROR ("Invalid ID: Expected 0x%08x, Got 0x%08x" ,IHDR_ID , ihdr.id); +return -1 ; + } +else if ( ihdr.version !=IHDR_VERSION ) + { +ERROR ("Invalid Version: Expected %d, Got %d" , + ihdr.version,IHDR_VERSION ); +return -1 ; + } +else if ( ihdr.options &IHDR_OPT_BIG_ENDIAN ) + { +ERROR ("Unable to handle big endian streams" ); +return -1 ; + } + + ctx->restore.format_version = ihdr.version; + +if (read_exact (ctx->fd, &dhdr,sizeof (dhdr)) ) + { +PERROR ("Failed to read Domain Header from stream" ); +return -1 ; + } + + ctx->restore.guest_type = dhdr.type; + ctx->restore.guest_page_size = (1U << dhdr.page_shift); + +if ( dhdr.xen_major ==0 ) + { +IPRINTF ("Found %s domain, converted from legacy stream format" , +dhdr_type_to_str (dhdr.type)); +DPRINTF (" Legacy conversion script version %u" , dhdr.xen_minor); + } +else +IPRINTF ("Found %s domain from Xen %u.%u" , +dhdr_type_to_str (dhdr.type), dhdr.xen_major, dhdr.xen_minor); +return 0 ; +} + +/** +* Reads a record from the stream, and fills in the record structure. +* +* Returns 0 on success and non-0 on failure. +* +* On success, the records type and size shall be valid. +* - If size is 0, data shall be NULL. +* - If size is non-0, data shall be a buffer allocated by malloc() which must +* be passed to free() by the caller. +* +* On failure, the contents of the record structure are undefined. +*/ +static int read_record (struct xc_sr_context *ctx,struct xc_sr_record *rec) +{ +xc_interface *xch = ctx->xch; +struct xc_sr_rhdr rhdr; +size_t datasz; + +if (read_exact (ctx->fd, &rhdr,sizeof (rhdr)) ) + { +PERROR ("Failed to read Record Header from stream" ); +return -1 ; + } +else if ( rhdr.length >REC_LENGTH_MAX ) + { +ERROR ("Record (0x%08x, %s) length %#x exceeds max (%#x)" , rhdr.type, +rec_type_to_str (rhdr.type), rhdr.length,REC_LENGTH_MAX ); +return -1 ; + } + + datasz =ROUNDUP (rhdr.length,REC_ALIGN_ORDER ); + +if ( datasz ) + { + rec->data =malloc (datasz); + +if ( !rec->data ) + { +ERROR ("Unable to allocate %zu bytes for record data (0x%08x, %s)" , + datasz, rhdr.type,rec_type_to_str (rhdr.type)); +return -1 ; + } + +if (read_exact (ctx->fd, rec->data, datasz) ) + { +free (rec->data); + rec->data =NULL ; +PERROR ("Failed to read %zu bytes of data for record (0x%08x, %s)" , + datasz, rhdr.type,rec_type_to_str (rhdr.type)); +return -1 ; + } + } +else + rec->data =NULL ; + + rec->type = rhdr.type; + rec->length = rhdr.length; + +return 0 ; +}; + +/* * Is a pfn populated? */ static bool pfn_is_populated (const struct xc_sr_context *ctx,xen_pfn_t pfn)
@@ -125,16 +252,388 @@ int populate_pfns(struct xc_sr_context *ctx, unsigned count,return rc; } +/* +* Given a list of pfns, their types, and a block of page data from the +* stream, populate and record their types, map the relevent subset and copy +* the data into the guest. +*/ +static int process_page_data (struct xc_sr_context *ctx,unsigned count, +xen_pfn_t *pfns,uint32_t *types,void *page_data) +{ +xc_interface *xch = ctx->xch; +xen_pfn_t *mfns =malloc (count *sizeof (*mfns)); +int *map_errs =malloc (count *sizeof (*map_errs)); +int rc; +void *mapping =NULL , *guest_page =NULL ; +unsigned i,/* i indexes the pfns from the record. */ + j,/* j indexes the subset of pfns we decide to map. */ + nr_pages =0 ; + +if ( !mfns || !map_errs ) + { + rc =-1 ; +ERROR ("Failed to allocate %zu bytes to process page data" , + count * (sizeof (*mfns) +sizeof (*map_errs))); + goto err; + } + + rc =populate_pfns (ctx, count, pfns, types); +if ( rc ) + { +ERROR ("Failed to populate pfns for batch of %u pages" , count); + goto err; + } + +for ( i =0 ; i < count; ++i ) + { + ctx->restore.ops.set_page_type (ctx, pfns[i], types[i]); + +switch ( types[i] ) + { +case XEN_DOMCTL_PFINFO_NOTAB : + +case XEN_DOMCTL_PFINFO_L1TAB : +case XEN_DOMCTL_PFINFO_L1TAB |XEN_DOMCTL_PFINFO_LPINTAB : + +case XEN_DOMCTL_PFINFO_L2TAB : +case XEN_DOMCTL_PFINFO_L2TAB |XEN_DOMCTL_PFINFO_LPINTAB : + +case XEN_DOMCTL_PFINFO_L3TAB : +case XEN_DOMCTL_PFINFO_L3TAB |XEN_DOMCTL_PFINFO_LPINTAB : + +case XEN_DOMCTL_PFINFO_L4TAB : +case XEN_DOMCTL_PFINFO_L4TAB |XEN_DOMCTL_PFINFO_LPINTAB : + + mfns[nr_pages++] = ctx->restore.ops.pfn_to_gfn (ctx, pfns[i]); +break ; + } + } + +/* Nothing to do? */ +if ( nr_pages ==0 ) + goto done; + + mapping = guest_page =xc_map_foreign_bulk ( + xch, ctx->domid,PROT_READ |PROT_WRITE , + mfns, map_errs, nr_pages); +if ( !mapping ) + { + rc =-1 ; +PERROR ("Unable to map %u mfns for %u pages of data" , + nr_pages, count); + goto err; + } + +for ( i =0 , j =0 ; i < count; ++i ) + { +switch ( types[i] ) + { +case XEN_DOMCTL_PFINFO_XTAB : +case XEN_DOMCTL_PFINFO_BROKEN : +case XEN_DOMCTL_PFINFO_XALLOC : +/* No page data to deal with. */ +continue ; + } + +if ( map_errs[j] ) + { + rc =-1 ; +ERROR ("Mapping pfn %lx (mfn %lx, type %#x)failed with %d" , + pfns[i], mfns[j], types[i], map_errs[j]); + goto err; + } + +/* Undo page normalisation done by the saver. */ + rc = ctx->restore.ops.localise_page (ctx, types[i], page_data); +if ( rc ) + { +ERROR ("Failed to localise pfn %lx (type %#x)" , + pfns[i], types[i] >>XEN_DOMCTL_PFINFO_LTAB_SHIFT ); + goto err; + } + +if ( ctx->restore.verify ) + { +/* Verify mode - compare incoming data to what we already have. */ +if (memcmp (guest_page, page_data,PAGE_SIZE ) ) +ERROR ("verify pfn %lx failed (type %#x)" , + pfns[i], types[i] >>XEN_DOMCTL_PFINFO_LTAB_SHIFT ); + } +else + { +/* Regular mode - copy incoming data into place. */ +memcpy (guest_page, page_data,PAGE_SIZE ); + } + + ++j; + guest_page +=PAGE_SIZE ; + page_data +=PAGE_SIZE ; + } + + done: + rc =0 ; + + err: +if ( mapping ) +munmap (mapping, nr_pages *PAGE_SIZE ); + +free (map_errs); +free (mfns); + +return rc; +} + +/* +* Validate a PAGE_DATA record from the stream, and pass the results to +* process_page_data() to actually perform the legwork. +*/ +static int handle_page_data (struct xc_sr_context *ctx,struct xc_sr_record *rec) +{ +xc_interface *xch = ctx->xch; +struct xc_sr_rec_page_data_header *pages = rec->data; +unsigned i, pages_of_data =0 ; +int rc =-1 ; + +xen_pfn_t *pfns =NULL , pfn; +uint32_t *types =NULL , type; + +if ( rec->length <sizeof (*pages) ) + { +ERROR ("PAGE_DATA record truncated: length %u, min %zu" , + rec->length,sizeof (*pages)); + goto err; + } +else if ( pages->count <1 ) + { +ERROR ("Expected at least 1 pfn in PAGE_DATA record" ); + goto err; + } +else if ( rec->length <sizeof (*pages) + (pages->count *sizeof (uint64_t )) ) + { +ERROR ("PAGE_DATA record (length %u) too short to contain %u" +" pfns worth of information" , rec->length, pages->count); + goto err; + } + + pfns =malloc (pages->count *sizeof (*pfns)); + types =malloc (pages->count *sizeof (*types)); +if ( !pfns || !types ) + { +ERROR ("Unable to allocate enough memory for %u pfns" , + pages->count); + goto err; + } + +for ( i =0 ; i < pages->count; ++i ) + { + pfn = pages->pfn[i] &PAGE_DATA_PFN_MASK ; +if ( !ctx->restore.ops.pfn_is_valid (ctx, pfn) ) + { +ERROR ("pfn %#lx (index %u) outside domain maximum" , pfn, i); + goto err; + } + + type = (pages->pfn[i] &PAGE_DATA_TYPE_MASK ) >>32 ; +if ( ((type >>XEN_DOMCTL_PFINFO_LTAB_SHIFT ) >=5 ) && + ((type >>XEN_DOMCTL_PFINFO_LTAB_SHIFT ) <=8 ) ) + { +ERROR ("Invalid type %#x for pfn %#lx (index %u)" , type, pfn, i); + goto err; + } +else if ( type <XEN_DOMCTL_PFINFO_BROKEN ) +/* NOTAB and all L1 thru L4 tables (including pinned) should have +* a page worth of data in the record. */ + pages_of_data++; + + pfns[i] = pfn; + types[i] = type; + } + +if ( rec->length != (sizeof (*pages) + + (sizeof (uint64_t ) * pages->count) + + (PAGE_SIZE * pages_of_data)) ) + { +ERROR ("PAGE_DATA record wrong size: length %u, expected " +"%zu + %zu + %zu" , rec->length,sizeof (*pages), + (sizeof (uint64_t ) * pages->count), (PAGE_SIZE * pages_of_data)); + goto err; + } + + rc =process_page_data (ctx, pages->count, pfns, types, + &pages->pfn[pages->count]); + err: +free (types); +free (pfns); + +return rc; +} + +/* +* Restore a domain. +*/ +static int restore (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; +struct xc_sr_record rec; +int rc, saved_rc =0 , saved_errno =0 ; + +IPRINTF ("Restoring domain" ); + + rc = ctx->restore.ops.setup (ctx); +if ( rc ) + goto err; + + ctx->restore.max_populated_pfn = (32 *1024 /4 ) -1 ; + ctx->restore.populated_pfns =bitmap_alloc ( + ctx->restore.max_populated_pfn +1 ); +if ( !ctx->restore.populated_pfns ) + { +ERROR ("Unable to allocate memory for populated_pfns bitmap" ); + goto err; + } + +do + { + rc =read_record (ctx, &rec); +if ( rc ) + goto err; + +switch ( rec.type ) + { +case REC_TYPE_END : +break ; + +case REC_TYPE_PAGE_DATA : + rc =handle_page_data (ctx, &rec); +break ; + +case REC_TYPE_VERIFY : +DPRINTF ("Verify mode enabled" ); + ctx->restore.verify = true; +break ; + +default : + rc = ctx->restore.ops.process_record (ctx, &rec); +break ; + } + +free (rec.data); + +if ( rc ==RECORD_NOT_PROCESSED ) + { +if ( rec.type &REC_TYPE_OPTIONAL ) +DPRINTF ("Ignoring optional record %#x (%s)" , + rec.type,rec_type_to_str (rec.type)); +else + { +ERROR ("Manditory record %#x (%s) not handled" , + rec.type,rec_type_to_str (rec.type)); + rc =-1 ; + } + } + +if ( rc ) + goto err; + + }while ( rec.type !=REC_TYPE_END ); + + rc = ctx->restore.ops.stream_complete (ctx); +if ( rc ) + goto err; + +IPRINTF ("Restore successful" ); + goto done; + + err: + saved_errno = errno; + saved_rc = rc; +PERROR ("Restore failed" ); + + done: +free (ctx->restore.populated_pfns); + rc = ctx->restore.ops.cleanup (ctx); +if ( rc ) +PERROR ("Failed to clean up" ); + +if ( saved_rc ) + { + rc = saved_rc; + errno = saved_errno; + } + +return rc; +} +int xc_domain_restore2 (xc_interface *xch,int io_fd,uint32_t dom,unsigned int store_evtchn,unsigned long *store_mfn,domid_t store_domid,unsigned int console_evtchn, -unsigned long *console_mfn,domid_t console_domid, +unsigned long *console_gfn,domid_t console_domid,unsigned int hvm,unsigned int pae,int superpages,int checkpointed_stream,struct restore_callbacks *callbacks) { +struct xc_sr_context ctx = + { + .xch = xch, + .fd = io_fd, + }; + +/* GCC 4.4 (of CentOS 6.x vintage) can' t initialise anonymous unions. */ + ctx.restore.console_evtchn = console_evtchn; + ctx.restore.console_domid = console_domid; + ctx.restore.xenstore_evtchn = store_evtchn; + ctx.restore.xenstore_domid = store_domid; + ctx.restore.callbacks = callbacks; +IPRINTF ("In experimental %s" , __func__); -return -1 ; +DPRINTF ("fd %d, dom %u, hvm %u, pae %u, superpages %d" +", checkpointed_stream %d" , io_fd, dom, hvm, pae, + superpages, checkpointed_stream); + +if (xc_domain_getinfo (xch, dom,1 , &ctx.dominfo) !=1 ) + { +PERROR ("Failed to get domain info" ); +return -1 ; + } + +if ( ctx.dominfo.domid != dom ) + { +ERROR ("Domain %u does not exist" , dom); +return -1 ; + } + + ctx.domid = dom; + +if (read_headers (&ctx) ) +return -1 ; + +if ( ctx.dominfo.hvm ) + { + ctx.restore.ops = restore_ops_x86_hvm; +if (restore (&ctx) ) +return -1 ; + } +else + { + ctx.restore.ops = restore_ops_x86_pv; +if (restore (&ctx) ) +return -1 ; + } + +IPRINTF ("XenStore: mfn %#lx, dom %d, evt %u" , + ctx.restore.xenstore_gfn, + ctx.restore.xenstore_domid, + ctx.restore.xenstore_evtchn); + +IPRINTF ("Console: mfn %#lx, dom %d, evt %u" , + ctx.restore.console_gfn, + ctx.restore.console_domid, + ctx.restore.console_evtchn); + + *console_gfn = ctx.restore.console_gfn; + *store_mfn = ctx.restore.xenstore_gfn; + +return 0 ; }/*
Signature · 1 line
1.7.10.4
Re: [PATCH v9 13/15] tools/libxc: noarch restore code
Quoted 2 lines · Andrew Cooper
+/**
+ * Reads a record from the stream, and fills in the record structure.
Doesn't look to be a structured comment of any sort, so only one * needed on the opening.
Quoted 2 lines
+ * Given a list of pfns, their types, and a block of page data from the
+ * stream, populate and record their types, map the relevent subset and copy
relevant.
With those two nits addressed:
tools/libxc/xc_sr_restore.c int populate_pfns(struct xc_sr_context *ctx, unsigned count, · line 293
Quoted 7 lines
tools/libxc/xc_sr_restore.c +7
-0+for ( i =0 ; i < count; ++i ) + { + ctx->restore.ops.set_page_type (ctx, pfns[i], types[i]); + +switch ( types[i] ) + { +case XEN_DOMCTL_PFINFO_NOTAB :
For my own enlightenment:
What is in a NOTAB page and is it correct to uncanonicalise it?
Quoted 17 lines
tools/libxc/xc_sr_restore.c +17
-0+ +case XEN_DOMCTL_PFINFO_L1TAB : +case XEN_DOMCTL_PFINFO_L1TAB |XEN_DOMCTL_PFINFO_LPINTAB : + +case XEN_DOMCTL_PFINFO_L2TAB : +case XEN_DOMCTL_PFINFO_L2TAB |XEN_DOMCTL_PFINFO_LPINTAB : + +case XEN_DOMCTL_PFINFO_L3TAB : +case XEN_DOMCTL_PFINFO_L3TAB |XEN_DOMCTL_PFINFO_LPINTAB : + +case XEN_DOMCTL_PFINFO_L4TAB : +case XEN_DOMCTL_PFINFO_L4TAB |XEN_DOMCTL_PFINFO_LPINTAB : + + mfns[nr_pages++] = ctx->restore.ops.pfn_to_gfn (ctx, pfns[i]); +break ; + } + }
Re: [PATCH v9 13/15] tools/libxc: noarch restore code
Quoted 21 lines · Ian Campbell
Quoted 2 lines · Andrew Cooper
+/**
+ * Reads a record from the stream, and fills in the record structure.Doesn't look to be a structured comment of any sort, so only one * needed on the opening.
Quoted 2 lines
+ * Given a list of pfns, their types, and a block of page data from the
+ * stream, populate and record their types, map the relevent subset and copyrelevant.
With those two nits addressed:
Acked-by Ian Campbell <[email protected]>tools/libxc/xc_sr_restore.c int populate_pfns(struct xc_sr_context *ctx, unsigned count, · line 293
Quoted 7 lines
tools/libxc/xc_sr_restore.c +7
-0+for ( i =0 ; i < count; ++i ) + { + ctx->restore.ops.set_page_type (ctx, pfns[i], types[i]); + +switch ( types[i] ) + { +case XEN_DOMCTL_PFINFO_NOTAB :
Quoted 3 lines
For my own enlightenment:
What is in a NOTAB page and is it correct to uncanonicalise it?
Notab is a regular plain ram page. I think the name refers to "not a pagetable".
This loop is working out which guest frames to map, so data can be memcpy()'d in. It is a larger set than the pages which subsequently get uncanonicalised.
~Andrew
Quoted 18 lines
Quoted 18 lines
tools/libxc/xc_sr_restore.c +17
-0+ +case XEN_DOMCTL_PFINFO_L1TAB : +case XEN_DOMCTL_PFINFO_L1TAB |XEN_DOMCTL_PFINFO_LPINTAB : + +case XEN_DOMCTL_PFINFO_L2TAB : +case XEN_DOMCTL_PFINFO_L2TAB |XEN_DOMCTL_PFINFO_LPINTAB : + +case XEN_DOMCTL_PFINFO_L3TAB : +case XEN_DOMCTL_PFINFO_L3TAB |XEN_DOMCTL_PFINFO_LPINTAB : + +case XEN_DOMCTL_PFINFO_L4TAB : +case XEN_DOMCTL_PFINFO_L4TAB |XEN_DOMCTL_PFINFO_LPINTAB : + + mfns[nr_pages++] = ctx->restore.ops.pfn_to_gfn (ctx, pfns[i]); +break ; + } + }
Re: [PATCH v9 13/15] tools/libxc: noarch restore code
Quoted 24 lines · Andrew Cooper
Quoted 23 lines · Ian Campbell
Quoted 2 lines · Andrew Cooper
+/**
+ * Reads a record from the stream, and fills in the record structure.Doesn't look to be a structured comment of any sort, so only one * needed on the opening.
Quoted 2 lines
+ * Given a list of pfns, their types, and a block of page data from the
+ * stream, populate and record their types, map the relevent subset and copyrelevant.
With those two nits addressed:
Acked-by Ian Campbell <[email protected]>tools/libxc/xc_sr_restore.c int populate_pfns(struct xc_sr_context *ctx, unsigned count, · line 293
Quoted 7 lines
tools/libxc/xc_sr_restore.c +7
-0+for ( i =0 ; i < count; ++i ) + { + ctx->restore.ops.set_page_type (ctx, pfns[i], types[i]); + +switch ( types[i] ) + { +case XEN_DOMCTL_PFINFO_NOTAB :For my own enlightenment:
Quoted 8 lines
Quoted 1 line
What is in a NOTAB page and is it correct to uncanonicalise it?
Notab is a regular plain ram page. I think the name refers to "not a pagetable".
This loop is working out which guest frames to map, so data can be memcpy()'d in. It is a larger set than the pages which subsequently get uncanonicalised.
Ah, for some reason I thought we were doing the uncanon here, but I see now we aren't, thanks!
PATCH v9 14/15 docs: libxc migration stream specification
In reply to Andrew CooperAdd the specification for a new migration stream format. The document includes all the details but to summarize:
The existing (legacy) format is dependant on the word size of the toolstack. This prevents domains from migrating from hosts running 32-bit toolstacks to hosts running 64-bit toolstacks (and vice-versa).
The legacy format lacks any version information making it difficult to extend in compatible way.
The new format has a header (the image header) with version information, a domain header with basic information of the domain and a stream of records for the image data.
The format will be used for future domain types (such as on ARM).
The specification is pandoc format (an extended markdown format) and the documentation build system is extended to support pandoc format documents.
--- docs/Makefile | 11 +- docs/specs/libxc-migration-stream.pandoc | 672 ++++++++++++++++++++++++++++++ 2 files changed, 682 insertions(+), 1 deletion(-) create mode 100644 docs/specs/libxc-migration-stream.pandoc
docs/Makefile +10 -1
@@ -16,19 +16,24 @@ MARKDOWNSRC-y := $(sort $(wildcard misc/*.markdown)) TXTSRC-y := $(sort $(wildcard misc/*.txt)) +PANDOCSRC-y += $(sort $(wildcard specs/*.pandoc)) + DOC_MAN1 := $(patsubst man/%.pod.1,man1/%.1,$(MAN1SRC-y)) DOC_MAN5 := $(patsubst man/%.pod.5,man5/%.5,$(MAN5SRC-y)) DOC_HTML := $(patsubst %.markdown,html/%.html,$(MARKDOWNSRC-y)) \ + $(patsubst %.pandoc,html/%.html,$(PANDOCSRC-y)) \ $(patsubst man/%.pod.1,html/man/%.1.html,$(MAN1SRC-y)) \ $(patsubst man/%.pod.5,html/man/%.5.html,$(MAN5SRC-y)) \ $(patsubst %.txt,html/%.txt,$(TXTSRC-y)) \ $(patsubst %,html/hypercall/%/index.html,$(DOC_ARCHES)) DOC_TXT := $(patsubst %.txt,txt/%.txt,$(TXTSRC-y)) \ $(patsubst %.markdown,txt/%.txt,$(MARKDOWNSRC-y)) \ + $(patsubst %.pandoc,txt/%.txt,$(PANDOCSRC-y)) \ $(patsubst man/%.pod.1,txt/man/%.1.txt,$(MAN1SRC-y)) \ $(patsubst man/%.pod.5,txt/man/%.5.txt,$(MAN5SRC-y)) -DOC_PDF := $(patsubst %.markdown,pdf/%.pdf,$(MARKDOWNSRC-y)) +DOC_PDF := $(patsubst %.markdown,pdf/%.pdf,$(MARKDOWNSRC-y)) \ + $(patsubst %.pandoc,pdf/%.pdf,$(PANDOCSRC-y)) .PHONY: all all: build
@@ -191,6 +196,10 @@ pdf/%.pdf: %.markdown $(INSTALL_DIR) $(@D) pandoc -N --toc --standalone $< --output $@ +pdf/%.pdf txt/%.txt html/%.html: %.pandoc + $(INSTALL_DIR) $(@D) + pandoc --number-sections --toc --standalone $< --output $@ + ifeq (,$(findstring clean,$(MAKECMDGOALS))) $(XEN_ROOT)/config/Docs.mk: $(error You have to run ./configure before building docs)
docs/specs/libxc-migration-stream.pandoc new file +672 -0
672 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH v9 14/15] docs: libxc migration stream specification
Quoted 14 lines · Andrew Cooper
Add the specification for a new migration stream format. The document includes all the details but to summarize:
The existing (legacy) format is dependant on the word size of the toolstack. This prevents domains from migrating from hosts running 32-bit toolstacks to hosts running 64-bit toolstacks (and vice-versa).
The legacy format lacks any version information making it difficult to extend in compatible way.
The new format has a header (the image header) with version information, a domain header with basic information of the domain and a stream of records for the image data.
Quoted 6 lines
The format will be used for future domain types (such as on ARM).
The specification is pandoc format (an extended markdown format) and the documentation build system is extended to support pandoc format documents.
Signed-off-by Andrew Cooper <[email protected]>
I've read this before so I don't think I'll read it again, so I'll take it on trust that it represents the code and that you've run a spell checker over it (;-)).
Some things relating to:
docs/Makefile pdf/%.pdf: %.markdown · line 201
Quoted 3 lines
docs/Makefile +3
-0+pdf/%.pdf txt/%.txt html/%.html: %.pandoc + $(INSTALL_DIR) $(@D) + pandoc --number-sections --toc --standalone $< --output $@
docs/Makefile seems to handle pandc not being available via pdf targets already, although it's not clear if that will affect this rule, but it certainly doesn't look to do anything for txt or html sections.
IOW what happens if pandoc isn't installed?
The existing code also seems to incorrectly not use the $(PANDOC) variable which configure helpfully provides.
Is pandoc a superset of markdown? Would it be worth feeding .markdown docs to it in preference?
Ian.
Re: [PATCH v9 14/15] docs: libxc migration stream specification
Quoted 25 lines · Ian Campbell
Quoted 14 lines · Andrew Cooper
Add the specification for a new migration stream format. The document includes all the details but to summarize:
The existing (legacy) format is dependant on the word size of the toolstack. This prevents domains from migrating from hosts running 32-bit toolstacks to hosts running 64-bit toolstacks (and vice-versa).
The legacy format lacks any version information making it difficult to extend in compatible way.
The new format has a header (the image header) with version information, a domain header with basic information of the domain and a stream of records for the image data.
Quoted 6 lines
The format will be used for future domain types (such as on ARM).
The specification is pandoc format (an extended markdown format) and the documentation build system is extended to support pandoc format documents.
Signed-off-by Andrew Cooper <[email protected]>I've read this before so I don't think I'll read it again, so I'll take it on trust that it represents the code and that you've run a spell checker over it (;-)).
Quoted 7 lines
Some things relating to:
docs/Makefile pdf/%.pdf: %.markdown · line 201
Quoted 3 lines
docs/Makefile +3
-0+pdf/%.pdf txt/%.txt html/%.html: %.pandoc + $(INSTALL_DIR) $(@D) + pandoc --number-sections --toc --standalone $< --output $@docs/Makefile seems to handle pandc not being available via pdf targets already, although it's not clear if that will affect this rule, but it certainly doesn't look to do anything for txt or html sections.
The rules are somewhat special. This rule doesn't collide with any existing ones. It covers building stuff from .pandoc, whereas the other rule covers building .pdf from .markdown
Quoted 2 lines
IOW what happens if pandoc isn't installed?
Good question - I will need to fix that.
Quoted 3 lines
The existing code also seems to incorrectly not use the $(PANDOC) variable which configure helpfully provides.
Oops - that was me in 869d9ca2 where I also introduced the ./configure side of things.
Quoted 3 lines
Is pandoc a superset of markdown? Would it be worth feeding .markdown docs to it in preference?
Yes, and that is a longterm plan I have. IMO, pandoc makes far nicer documents than markdown.
Re: [PATCH v9 14/15] docs: libxc migration stream specification
Quoted 30 lines · Andrew Cooper
Quoted 29 lines · Ian Campbell
Quoted 14 lines · Andrew Cooper
Add the specification for a new migration stream format. The document includes all the details but to summarize:
The existing (legacy) format is dependant on the word size of the toolstack. This prevents domains from migrating from hosts running 32-bit toolstacks to hosts running 64-bit toolstacks (and vice-versa).
The legacy format lacks any version information making it difficult to extend in compatible way.
The new format has a header (the image header) with version information, a domain header with basic information of the domain and a stream of records for the image data.
Quoted 6 lines
The format will be used for future domain types (such as on ARM).
The specification is pandoc format (an extended markdown format) and the documentation build system is extended to support pandoc format documents.
Signed-off-by Andrew Cooper <[email protected]>I've read this before so I don't think I'll read it again, so I'll take it on trust that it represents the code and that you've run a spell checker over it (;-)).
Some things relating to:
Quoted 3 lines
docs/Makefile +3
-0+pdf/%.pdf txt/%.txt html/%.html: %.pandoc + $(INSTALL_DIR) $(@D) + pandoc --number-sections --toc --standalone $< --output $@
Quoted 7 lines
Quoted 3 lines
docs/Makefile seems to handle pandc not being available via pdf targets already, although it's not clear if that will affect this rule, but it certainly doesn't look to do anything for txt or html sections.
The rules are somewhat special. This rule doesn't collide with any existing ones. It covers building stuff from .pandoc, whereas the other rule covers building .pdf from .markdown
The other bit of code I was referring to was building *.pdf, so I think it would omit calling this rule as well as the one from .markdown,
Quoted 3 lines
Quoted 1 line
IOW what happens if pandoc isn't installed?
Good question - I will need to fix that.
Thanks.
Quoted 7 lines
Quoted 4 lines
The existing code also seems to incorrectly not use the $(PANDOC) variable which configure helpfully provides.
Oops - that was me in
869d9ca2where I also introduced the ./configure side of things.
Will you fix it? (In this patch is fine)
Quoted 5 lines
Quoted 2 lines
Is pandoc a superset of markdown? Would it be worth feeding .markdown docs to it in preference?
Yes, and that is a longterm plan I have. IMO, pandoc makes far nicer documents than markdown.
I've not looked, but ok ;-)
Re: [PATCH v9 14/15] docs: libxc migration stream specification
In reply to Andrew CooperQuoted 2 lines · Andrew Cooper
Add the specification for a new migration stream format. The document includes all the details but to summarize:
As the original/principle author of this specification can this be reflected in the commit author, please?
David
Re: [PATCH v9 14/15] docs: libxc migration stream specification
Quoted 8 lines · David Vrabel
Quoted 2 lines · Andrew Cooper
Add the specification for a new migration stream format. The document includes all the details but to summarize:
As the original/principle author of this specification can this be reflected in the commit author, please?
David
Ok. FWIW, you are the principle author in the document itself.
~Andrew
PATCH v9 15/15 tools/libxc: Migration v2 compatibility for unmodified libxl
In reply to Andrew CooperThese changes cause migration v2 to behave similarly enough to legacy migration to function for HVM guests under an unmodified xl/libxl.
The migration v2 work for libxl will fix the layering issues with the toolstack and qemu records, at which point this patch will be unneeded.
It is however included here for people wishing to experiment with migration v2 ahead of the libxl work.
--- tools/libxc/Makefile | 2 + tools/libxc/xc_sr_restore_x86_hvm.c | 102 +++++++++++++++++++++++++++++++++++ tools/libxc/xc_sr_save_x86_hvm.c | 36 +++++++++++++ 3 files changed, 140 insertions(+)
tools/libxc/Makefile +2 -0
@@ -63,6 +63,8 @@ GUEST_SRCS-$(CONFIG_X86) += xc_sr_save_x86_hvm.c GUEST_SRCS-y += xc_sr_restore.c GUEST_SRCS-y += xc_sr_save.c GUEST_SRCS-y += xc_offline_page.c xc_compression.c +$(patsubst %.c,%.o,$(GUEST_SRCS-y)): CFLAGS += -DXG_LIBXL_HVM_COMPAT +$(patsubst %.c,%.opic,$(GUEST_SRCS-y)): CFLAGS += -DXG_LIBXL_HVM_COMPAT else GUEST_SRCS-y += xc_nomigrate.c endif
tools/libxc/xc_sr_restore_x86_hvm.c +102 -0
126 lines not on this page · raw message
tools/libxc/xc_sr_save_x86_hvm.c +36 -0
@@ -118,6 +118,36 @@ static int write_hvm_params(struct xc_sr_context *ctx)return rc; } +#ifdef XG_LIBXL_HVM_COMPAT +static int write_toolstack (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; +struct xc_sr_record rec = { + .type =REC_TYPE_TOOLSTACK , + .length =0 , + }; +uint8_t *buf; +uint32_t len; +int rc; + +if ( !ctx->save.callbacks || !ctx->save.callbacks->toolstack_save ) +return 0 ; + +if ( ctx->save.callbacks->toolstack_save ( + ctx->domid, &buf, &len, ctx->save.callbacks->data) <0 ) + { +PERROR ("Error calling toolstack_save" ); +return -1 ; + } + + rc =write_split_record (ctx, &rec, buf, len); +if ( rc <0 ) +PERROR ("Error writing TOOLSTACK record" ); +free (buf); +return rc; +} +#endif +static xen_pfn_t x86_hvm_pfn_to_gfn (const struct xc_sr_context *ctx,xen_pfn_t pfn) {
@@ -170,6 +200,12 @@ static int x86_hvm_end_of_stream(struct xc_sr_context *ctx)if ( rc )return rc; +#ifdef XG_LIBXL_HVM_COMPAT + rc =write_toolstack (ctx); +if ( rc ) +return rc; +#endif +/* Write the HVM_CONTEXT record. */ rc =write_hvm_context (ctx);if ( rc )
Signature · 1 line
1.7.10.4
Re: [PATCH v9 15/15] tools/libxc: Migration v2 compatibility for unmodified libxl
Quoted 8 lines · Andrew Cooper
These changes cause migration v2 to behave similarly enough to legacy migration to function for HVM guests under an unmodified xl/libxl.
The migration v2 work for libxl will fix the layering issues with the toolstack and qemu records, at which point this patch will be unneeded.
It is however included here for people wishing to experiment with migration v2 ahead of the libxl work.
I think it's ultimately up to Wei as RM but I'd be in favour of actually enabling this now, i.e. behaving as if XG_MIGRATION_V2 were set by default and removing all the old stuff.
Any idea if this is a sufficient compat layer for the existing remus functionality?
tools/libxc/xc_sr_restore_x86_hvm.c static int handle_hvm_params(struct xc_sr_context *ctx, · line 97
Quoted 2 lines
tools/libxc/xc_sr_restore_x86_hvm.c +2
-0+#ifdef XG_LIBXL_HVM_COMPAT +static int dump_qemu (struct xc_sr_context *ctx)
dump_ made me thing this was going the other way (i.e. saving it), could you s/dump/handle/ please? I think that matches the prevailing naming scheme better
Apart from that last one:
Ian.
Re: [PATCH v9 15/15] tools/libxc: Migration v2 compatibility for unmodified libxl
Quoted 7 lines · Ian Campbell
Quoted 6 lines · Andrew Cooper
These changes cause migration v2 to behave similarly enough to legacy migration to function for HVM guests under an unmodified xl/libxl.
The migration v2 work for libxl will fix the layering issues with the toolstack and qemu records, at which point this patch will be unneeded.
Quoted 8 lines
Quoted 2 lines
It is however included here for people wishing to experiment with migration v2 ahead of the libxl work.
I think it's ultimately up to Wei as RM but I'd be in favour of actually enabling this now, i.e. behaving as if
XG_MIGRATION_V2were set by default and removing all the old stuff.Any idea if this is a sufficient compat layer for the existing remus functionality?
If this were to be enabled by default, remus would break. (Also, I wanted to offer a way for it to be very easily tested without flipping the big switch right now, in case there was something I missed)
There was a remus/migration v2 series posted ages, but no followup to first round review because I believe the guys were busy trying to get remus/libxl in at the same time.
Quoted 6 lines
tools/libxc/xc_sr_restore_x86_hvm.c static int handle_hvm_params(struct xc_sr_context *ctx, · line 97
Quoted 3 lines
tools/libxc/xc_sr_restore_x86_hvm.c +2
-0+#ifdef XG_LIBXL_HVM_COMPAT +static int dump_qemu (struct xc_sr_context *ctx)
dump_made me thing this was going the other way (i.e. saving it), could you s/dump/handle/ please? I think that matches the prevailing naming scheme better
Ok. The dump_ name was inherited from the legacy code, then hidden in an #if 0 for a large part of development.
~Andrew
Quoted 6 lines
Apart from that last one:
Acked-by Ian Campbell <[email protected]>Ian.
Re: [PATCH v9 15/15] tools/libxc: Migration v2 compatibility for unmodified libxl
Quoted 17 lines · Andrew Cooper
Quoted 7 lines · Ian Campbell
Quoted 6 lines · Andrew Cooper
These changes cause migration v2 to behave similarly enough to legacy migration to function for HVM guests under an unmodified xl/libxl.
The migration v2 work for libxl will fix the layering issues with the toolstack and qemu records, at which point this patch will be unneeded.
Quoted 8 lines
Quoted 2 lines
It is however included here for people wishing to experiment with migration v2 ahead of the libxl work.
I think it's ultimately up to Wei as RM but I'd be in favour of actually enabling this now, i.e. behaving as if
XG_MIGRATION_V2were set by default and removing all the old stuff.Any idea if this is a sufficient compat layer for the existing remus functionality?
Quoted 7 lines
If this were to be enabled by default, remus would break. (Also, I wanted to offer a way for it to be very easily tested without flipping the big switch right now, in case there was something I missed)
There was a remus/migration v2 series posted ages, but no followup to first round review because I believe the guys were busy trying to get remus/libxl in at the same time.
Lets add those guys to the CC list then. It looks like they were on the "Migration v2 and related work for 4.6" thread so this should come as no surprise.
Quoted 18 lines
Quoted 5 lines
tools/libxc/xc_sr_restore_x86_hvm.c static int handle_hvm_params(struct xc_sr_context *ctx, · line 97
Quoted 2 lines
tools/libxc/xc_sr_restore_x86_hvm.c +2
-0+#ifdef XG_LIBXL_HVM_COMPAT +static int dump_qemu (struct xc_sr_context *ctx)
dump_made me thing this was going the other way (i.e. saving it), could you s/dump/handle/ please? I think that matches the prevailing naming scheme betterOk. The
dump_name was inherited from the legacy code, then hidden in an #if 0 for a large part of development.~Andrew
Quoted 6 lines
Apart from that last one:
Acked-by Ian Campbell <[email protected]>Ian.