Migration Stream v2
cover Migration Stream v2
Hello,
Presented here for early review is a basic implementation of PV guest migration using the v2 stream format.
PV non-live migration is believed-working; i.e. xl save/restore.
One caveat is 32bit PV domains and 64 bit toolstacks, which is expected not to work currently. There is an architectural problem when using the toolstack domains m2p to shoot Xen mappings from a PV guest, which is hidden by another over-aggressive bug in the live part of v1 migration, which is why v1 currently works (albeit with a risk of shooting too many guest PTEs). As 'live' is not yet implemented in v2, the second bug has not been replicated.
The code has been a clean rewrite, using the v1 code as a reference but avoiding obsolete areas (e.g. how to modify the pagetables of a 32 non-pae guest on 32bit pae Xen).
Some design decisions have been take very deliberately (e.g. splitting the logic for PV and hvm migration) while others have been more along the lines of "I think its a sensible thing to do given a lack of any evidence/opinion to the contrary".
The error handling is known to only semi-consistent. Functions return 0 for success and non-zero for failure. This is typically -1, although errno is not always relevant. However, the logging messages should all be relevant and correct. Making this properly consistent will involve wider effort across all of libxc.
Patches:
* 1 is a gross hack to allow the two versions to coexist
* 2 is mainly a header file following the specification (draft E)
* 3 is a set of python scripts for validation of streams
* 4 is some common PV code
* 5 is an implementation of PV save
* 6 is an implementation of PV restore
The rough order of forthcoming work is:
* Fix architectural bug (new hypercall required)
* Get live migration working without the risk of corrupting 32bit guests
* Get HVM migration working (conceptually easier)
* Get some of the optional features working (tmem blobs, etc)
An area needing discussing is how to do v1 -> v2 transformations for a one-time upgrade. There is a (very basic currently) python script which can pick a v1 stream, and a separate python library to write v2 streams.
One option would be to combine these two into a program which takes two fds, which libxc can exec() out to. There is deliberate flexibility in the v2 restore code which allows a v1 -> v2 transformation on a stream without seeking.
Anyway - the code is presented for initial comment/query/critisixm.
~Andrew
PATCH 1/6 tools/libxc: save/restore v2 framework
For testing purposes, the environmental variable "XG_MIGRATION_V2" allows the two save/restore codepaths to coexist, and have a runtime switch.
It is indended that once this series is less RFC, the v2 framework will completely replace v1.
--- tools/libxc/Makefile | 1 + tools/libxc/saverestore/common.h | 15 +++++++++++++++ tools/libxc/saverestore/restore.c | 23 +++++++++++++++++++++++ tools/libxc/saverestore/save.c | 20 ++++++++++++++++++++ tools/libxc/xc_domain_restore.c | 8 ++++++++ tools/libxc/xc_domain_save.c | 7 +++++++ tools/libxc/xenguest.h | 14 ++++++++++++++ 7 files changed, 88 insertions(+) create mode 100644 tools/libxc/saverestore/common.h create mode 100644 tools/libxc/saverestore/restore.c create mode 100644 tools/libxc/saverestore/save.c
tools/libxc/Makefile +1 -0
@@ -44,6 +44,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 += $(wildcard saverestore/*.c) GUEST_SRCS-y += xc_offline_page.c xc_compression.c else GUEST_SRCS-y += xc_nomigrate.c
tools/libxc/saverestore/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/saverestore/restore.c new file +23 -0
@@ -0,0 +1,23 @@ +#include "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/saverestore/save.c new file +20 -0
@@ -0,0 +1,20 @@ +#include "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, +unsigned long vm_generationid_addr) +{ +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_domain_restore.c +8 -0
@@ -1468,6 +1468,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 +7 -0
@@ -895,6 +895,13 @@ 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, + vm_generationid_addr); + } +DPRINTF ("%s: starting save of domid %u" , __func__, dom);if ( hvm && !callbacks->switch_qemu_logdirty )
tools/libxc/xenguest.h +14 -0
@@ -89,6 +89,11 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter struct save_callbacks* callbacks, int hvm, unsigned long vm_generationid_addr); +/* 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, +unsigned long vm_generationid_addr);/* callbacks provided by xc_domain_restore */ struct restore_callbacks {
@@ -128,6 +133,15 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom, int no_incr_generationid, int checkpointed_stream, unsigned long *vm_generationid_addr, 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.
Signature · 1 line
1.7.10.4
PATCH 2/6 tools/libxc: Stream specification and some common code
In reply to Andrew Cooper--- tools/libxc/saverestore/common.c | 59 ++++++++++++++ tools/libxc/saverestore/common.h | 8 ++ tools/libxc/saverestore/stream_format.h | 130 +++++++++++++++++++++++++++++++ 3 files changed, 197 insertions(+) create mode 100644 tools/libxc/saverestore/common.c create mode 100644 tools/libxc/saverestore/stream_format.h
tools/libxc/saverestore/common.c new file +59 -0
@@ -0,0 +1,59 @@ +#include "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_x86_pv_shared_info] ="x86 PV shared info" , + [REC_TYPE_tsc_info] ="TSC info" , +}; + +/* +static const char *optional_rec_types[] = +{ +}; +*/ + +const char *rec_type_to_str (uint32_t type) +{ +if ( type & REC_TYPE_optional ) +return "Reserved" ; + +if ( ((type & REC_TYPE_optional) ==0 ) && + (type <ARRAY_SIZE (mandatory_rec_types)) && + (mandatory_rec_types[type]) ) +return mandatory_rec_types[type]; + +return "Reserved" ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
tools/libxc/saverestore/common.h +8 -0
@@ -3,6 +3,14 @@#include "../xg_private.h" +#include "stream_format.h" + +// TODO: Find a better place to put this... +#define ARRAY_SIZE (a) (sizeof(a) / sizeof(a[0])) + +const char *dhdr_type_to_str (uint32_t type); +const char *rec_type_to_str (uint32_t type); +#endif /* * Local variables:
tools/libxc/saverestore/stream_format.h new file +130 -0
130 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH 3/6 tools/libxc: Scripts for inspection/valdiation of legacy and new streams
In reply to Andrew Cooper--- tools/libxc/saverestore/scripts/generate.py | 59 ++++ .../libxc/saverestore/scripts/inspect-legacy32.py | 167 ++++++++++ tools/libxc/saverestore/scripts/streamspec.py | 89 ++++++ tools/libxc/saverestore/scripts/verify.py | 330 ++++++++++++++++++++ 4 files changed, 645 insertions(+) create mode 100755 tools/libxc/saverestore/scripts/generate.py create mode 100755 tools/libxc/saverestore/scripts/inspect-legacy32.py create mode 100644 tools/libxc/saverestore/scripts/streamspec.py create mode 100755 tools/libxc/saverestore/scripts/verify.py
tools/libxc/saverestore/scripts/generate.py new file +59 -0
@@ -0,0 +1,59 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from streamspec import * +import struct, sys + +ihdr = struct.pack(IHDR_FORMAT, + 0xffffffffffffffff, # Marker + IHDR_IDENT, # "XENF" in ASCII + 1, # Version + IHDR_OPT_LE, # Options + 0, 0 # Reserved + ) + +def emit_record(type, data): + length = len(data) + + r = struct.pack(RH_FORMAT, type, length) + r += data + + padding_len = (8 - (length & 7)) & 7 + r += '\x00' * padding_len + + sys.stdout.write(r) + + +def emit_pv(): + + dhdr = struct.pack(DHDR_FORMAT, + DHDR_TYPE_x86_pv, # Type + 12, # Page size + 0, # Reserved + 4, # Xen major + 5 # Xen minor + ) + + sys.stdout.write(ihdr) + sys.stdout.write(dhdr) + + x86_pv_info = struct.pack(X86_PV_INFO_FORMAT, + 8, # Guest width + 4, # Guest levels + 0 # Options + ) + + emit_record(REC_TYPE_x86_pv_info, x86_pv_info) + emit_record(REC_TYPE_end, "") + return 0 + + +def main(argv = sys.argv): + + if len(argv) == 0 or argv[0] == "pv": + return emit_pv() + else: + return 1 + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:]))
tools/libxc/saverestore/scripts/inspect-legacy32.py new file +167 -0
167 lines not on this page · raw message
tools/libxc/saverestore/scripts/streamspec.py new file +89 -0
89 lines not on this page · raw message
tools/libxc/saverestore/scripts/verify.py new file +330 -0
330 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH 4/6 tools/libxc: x86 pv common code
In reply to Andrew Cooper--- tools/libxc/saverestore/common.h | 79 ++++++++++++ tools/libxc/saverestore/common_x86_pv.c | 208 +++++++++++++++++++++++++++++++ tools/libxc/saverestore/common_x86_pv.h | 105 ++++++++++++++++ 3 files changed, 392 insertions(+) create mode 100644 tools/libxc/saverestore/common_x86_pv.c create mode 100644 tools/libxc/saverestore/common_x86_pv.h
tools/libxc/saverestore/common.h +79 -0
@@ -1,8 +1,16 @@#ifndef __COMMON__H#define __COMMON__H +// Hack out junk from the namespace +#define mfn_to_pfn __UNUSED_mfn_to_pfn +#define pfn_to_mfn __UNUSED_pfn_to_mfn +#include "../xg_private.h" +#undef mfn_to_pfn +#undef pfn_to_mfn + +#include "stream_format.h" // TODO: Find a better place to put this...
@@ -11,6 +19,77 @@const char *dhdr_type_to_str (uint32_t type);const char *rec_type_to_str (uint32_t type); +struct context +{ +xc_interface *xch; +uint32_t domid; +int fd; + +xc_dominfo_t dominfo; + +union + { +struct + { +/* From Image Header */ +uint32_t format_version; + +/* From Domain Header */ +uint32_t guest_type; +uint32_t guest_page_size; + +unsigned long xenstore_mfn, console_mfn; +unsigned int xenstore_evtchn, console_evtchn; +domid_t xenstore_domid, console_domid; + } restore; + +struct + { +struct save_callbacks *callbacks; + } save; + }; + +union + { +struct + { +/* 4 or 8; 32 or 64 bit domain */ +unsigned int width; +/* 3 or 4 pagetable levels */ +unsigned int levels; + + +/* Maximum Xen frame */ +unsigned long max_mfn; +/* Read-only machine to phys map */ +xen_pfn_t *m2p; +/* firtst m2p mfn. Incorrectly based on toolstack bitness - FIXME */ +xen_pfn_t m2p_mfn0; +/* Number of m2p frames mapped */ +unsigned long nr_m2p_frames; + + +/* Maximum guest frame */ +unsigned long max_pfn; +/* Frames per page in guest p2m */ +unsigned int fpp; + +/* Number of frames making up the p2m */ +unsigned int p2m_frames; +/* Guest's phys to machine map. Mapped read-only (save) or +* allocated locally (restore). Uses guest unsigned longs. */ +void *p2m; +/* The guest pfns containing the p2m leaves */ +xen_pfn_t *p2m_pfns; +/* Types for each page */ +uint32_t *pfn_types; + +/* Read-only mapping of guests shared info page */ +shared_info_any_t *shinfo; + } x86_pv; + }; +}; +#endif /* * Local variables:
tools/libxc/saverestore/common_x86_pv.c new file +208 -0
208 lines not on this page · raw message
tools/libxc/saverestore/common_x86_pv.h new file +105 -0
105 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH 5/6 tools/libxc: x86 pv save implementation
In reply to Andrew Cooper--- tools/libxc/saverestore/common.c | 36 ++ tools/libxc/saverestore/common.h | 53 +++ tools/libxc/saverestore/save.c | 33 +- tools/libxc/saverestore/save_x86_pv.c | 843 +++++++++++++++++++++++++++++++++ 4 files changed, 964 insertions(+), 1 deletion(-) create mode 100644 tools/libxc/saverestore/save_x86_pv.c
tools/libxc/saverestore/common.c +36 -0
@@ -1,3 +1,5 @@ +#include <assert.h> +#include "common.h" static const char *dhdr_types[] =
@@ -48,6 +50,40 @@ const char *rec_type_to_str(uint32_t type)return "Reserved" ; } +int write_split_record (struct context *ctx,struct record *rec, +void *buf,size_t sz) +{ +static const char zeroes[7 ] = {0 }; +xc_interface *xch = ctx->xch; +uint32_t combined_length = rec->length + sz; +size_t record_length = (combined_length +7 ) & ~7UL ; + +if ( record_length >REC_LENGTH_MAX ) + { +ERROR ("Record (0x%08" PRIx32", %s) length 0x%" PRIx32 +" exceeds max (0x%" PRIx32")" , 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 (write_exact (ctx->fd, &rec->type,sizeof rec->type) || +write_exact (ctx->fd, &combined_length,sizeof rec->length) || + (rec->length &&write_exact (ctx->fd, rec->data, rec->length)) || + (sz &&write_exact (ctx->fd, buf, sz)) || +write_exact (ctx->fd, zeroes, record_length - combined_length) ) + { +PERROR ("Unable to write record to stream" ); +return -1 ; + } + +return 0 ; +} +/* * Local variables: * mode: C
tools/libxc/saverestore/common.h +53 -0
66 lines not on this page · raw message
tools/libxc/saverestore/save.c +32 -1
@@ -5,8 +5,39 @@ int xc_domain_save2(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_ite struct save_callbacks* callbacks, int hvm, unsigned long vm_generationid_addr) { + struct context ctx = + { + .xch = xch, + .fd = io_fd, + }; + +/* Older GCC cant initialise anonymous unions */ + ctx.save.callbacks = callbacks; +IPRINTF ("In experimental %s" , __func__); -return -1 ; + +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 %d does not exist" , dom); +return -1 ; + } + + ctx.domid = dom; +IPRINTF ("Saving domain %d" , dom); + +if ( ctx.dominfo.hvm ) + { +ERROR ("HVM Save not supported yet" ); +return -1 ; + } +else +return save_x86_pv (&ctx); }/*
tools/libxc/saverestore/save_x86_pv.c new file +843 -0
843 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH 6/6 tools/libxc: x86 pv restore implementation
In reply to Andrew Cooper--- tools/libxc/saverestore/common.c | 51 ++ tools/libxc/saverestore/common.h | 35 ++ tools/libxc/saverestore/restore.c | 112 +++- tools/libxc/saverestore/restore_x86_pv.c | 977 ++++++++++++++++++++++++++++++ 4 files changed, 1174 insertions(+), 1 deletion(-) create mode 100644 tools/libxc/saverestore/restore_x86_pv.c
tools/libxc/saverestore/common.c +51 -0
@@ -84,6 +84,57 @@ int write_split_record(struct context *ctx, struct record *rec,return 0 ; } +int read_record (struct context *ctx,struct record *rec) +{ +xc_interface *xch = ctx->xch; +struct 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%08" PRIx32", %s) length 0x%" PRIx32 +" exceeds max (0x%" PRIx32")" , + rhdr.type,rec_type_to_str (rhdr.type), + rhdr.length,REC_LENGTH_MAX ); +return -1 ; + } + + datasz = (rhdr.length +7 ) & ~7U ; + +if ( datasz ) + { + rec->data =malloc (datasz); + +if ( !rec->data ) + { +ERROR ("Unable to allocate %zu bytes for record data (0x%08" PRIx32", %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%08" PRIx32", %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 ; +}; +/* * Local variables: * mode: C
tools/libxc/saverestore/common.h +35 -0
@@ -7,9 +7,12 @@#include "../xg_private.h" #include "../xg_save_restore.h" +#include "../xc_dom.h" #undef GET_FIELD#undef SET_FIELD +#undef MEMCPY_FIELD +#undef MEMSET_ARRAY_FIELD#undef mfn_to_pfn#undef pfn_to_mfn
@@ -95,6 +98,8 @@ struct context/* Saves an x86 PV domain. */ int save_x86_pv (struct context *ctx); +/* Restores an x86 PV domain. */ +int restore_x86_pv (struct context *ctx);struct record {
@@ -118,6 +123,22 @@ struct record (_p)->x32._f = (_v); \ }) +/* memcpy field _f from _s to _d, of an *_any union */ +#define MEMCPY_FIELD (_c, _d, _s, _f) \ + ({ if ( (_c)->x86_pv.width == 8 ) \ + memcpy(&(_d)->x64._f, &(_s)->x64._f, sizeof((_d)->x64._f)); \ + else \ + memcpy(&(_d)->x32._f, &(_s)->x32._f, sizeof((_d)->x32._f)); \ + }) + +/* memset array field _f with value _v, from an *_any union */ +#define MEMSET_ARRAY_FIELD (_c, _d, _f, _v) \ + ({ if ( (_c)->x86_pv.width == 8 ) \ + memset(&(_d)->x64._f[0], (_v), sizeof((_d)->x64._f)); \ + else \ + memset(&(_d)->x32._f[0], (_v), sizeof((_d)->x32._f)); \ + }) +/* * Writes a split record to the stream, applying correct padding where * appropriate. It is common when sending records containing blobs from Xen
@@ -143,6 +164,20 @@ static inline int write_record(struct context *ctx, struct record *rec) return write_split_record(ctx, rec, NULL, 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. +*/ +int read_record (struct context *ctx,struct record *rec); +#endif /* * Local variables:
tools/libxc/saverestore/restore.c +111 -1
124 lines not on this page · raw message
tools/libxc/saverestore/restore_x86_pv.c new file +977 -0
977 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Quoted 4 lines · Andrew Cooper
Some design decisions have been take very deliberately (e.g. splitting the logic for PV and hvm migration) while others have been more along the lines of "I think its a sensible thing to do given a lack of any evidence/opinion to the contrary".
Is there some indication of which is which?
Should we check in the desigh/spec which was previously posted as part of this?
Quoted 5 lines
The error handling is known to only semi-consistent. Functions return 0 for success and non-zero for failure. This is typically -1, although errno is not always relevant. However, the logging messages should all be relevant and correct. Making this properly consistent will involve wider effort across all of libxc.
It would be useful if the new code was correct at least so far as its own behaviour went (meaning no need to fix functions it calls as part of this).
Quoted 7 lines
An area needing discussing is how to do v1 -> v2 transformations for a one-time upgrade. There is a (very basic currently) python script which can pick a v1 stream, and a separate python library to write v2 streams.
One option would be to combine these two into a program which takes two fds, which libxc can
exec()out to. There is deliberate flexibility in the v2 restore code which allows a v1 -> v2 transformation on a stream without seeking.
forking/execing in libxc might be problematic, fitting it into libxl might be easier, since it has infrastructure for that sort of thing.
Or maybe the fact that most of this already happens in a process which libxl spawns for that purpose means that libxc can safely fork because the application in that case is under our control.
Ian.
Quoted 6 lines · Ian Campbell
Quoted 4 lines · Andrew Cooper
Some design decisions have been take very deliberately (e.g. splitting the logic for PV and hvm migration) while others have been more along the lines of "I think its a sensible thing to do given a lack of any evidence/opinion to the contrary".
Is there some indication of which is which?
Not really, given the clean rewrite, and also that it is only partially complete.
Quoted 3 lines
Should we check in the desigh/spec which was previously posted as part of this?
I knew I forgot something...
http://xenbits.xen.org/people/andrewcoop/domain-save-format-E.pdf
Quoted 9 lines
Quoted 6 lines
The error handling is known to only semi-consistent. Functions return 0 for success and non-zero for failure. This is typically -1, although errno is not always relevant. However, the logging messages should all be relevant and correct. Making this properly consistent will involve wider effort across all of libxc.
It would be useful if the new code was correct at least so far as its own behaviour went (meaning no need to fix functions it calls as part of this).
libxc is too broken for that to be possible, (including such gems as the save_callbacks functions which is not specified as to how to indicate success or error, and have developed at least 3 different flavours)
Currently, the state of play is "if you get non0, something went wrong. Please read the log for relevant information" Once we get a libxc_err_t (or so, given a discussion down the pub) capable of expressing more meaningful error problems, most codepaths (including these new ones) will need updating, although starting from a fairly-consistent position will be much easier than not.
Quoted 10 lines
Quoted 8 lines
An area needing discussing is how to do v1 -> v2 transformations for a one-time upgrade. There is a (very basic currently) python script which can pick a v1 stream, and a separate python library to write v2 streams.
One option would be to combine these two into a program which takes two fds, which libxc can
exec()out to. There is deliberate flexibility in the v2 restore code which allows a v1 -> v2 transformation on a stream without seeking.forking/execing in libxc might be problematic, fitting it into libxl might be easier, since it has infrastructure for that sort of thing.
libxl is not the only user of libxc, and fixing it there would not help the other consumers of libxc.
Furthermore, unless the consumer has an out-of-band detection method (libxl can easily be made to have, Xapi less so easy, and no idea about other consumers), xc_domain_restore() is the first piece of code capable of detecting a legacy stream without needing to seek.
Quoted 4 lines
Or maybe the fact that most of this already happens in a process which libxl spawns for that purpose means that libxc can safely fork because the application in that case is under our control.
Exactly the same for Xapi, which uses a separate process which functions similarly to xc_save/restore but does domain build as well, which is why I am hoping this is an acceptable way of fixing the problem.
~Andrew
Quoted 2 lines · Andrew Cooper
Quoted 1 line · Ian Campbell
On Wed, 2014-04-09 at 19:28 +0100, Andrew Cooper wrote:
....
Quoted 15 lines
Quoted 10 lines
Quoted 7 lines
The error handling is known to only semi-consistent. Functions return 0 for success and non-zero for failure. This is typically -1, although errno is not always relevant. However, the logging messages should all be relevant and correct. Making this properly consistent will involve wider effort across all of libxc.
It would be useful if the new code was correct at least so far as its own behaviour went (meaning no need to fix functions it calls as part of this).
libxc is too broken for that to be possible, (including such gems as the
save_callbacksfunctions which is not specified as to how to indicate success or error, and have developed at least 3 different flavours)
Quoted 7 lines
Currently, the state of play is "if you get non0, something went wrong. Please read the log for relevant information" Once we get a
libxc_err_t(or so, given a discussion down the pub) capable of expressing more meaningful error problems, most codepaths (including these new ones) will need updating, although starting from a fairly-consistent position will be much easier than not.
I agree with Ian, we should have a first patch that just replace xc_domain_save/xc_domain_restore. We can fix functions return and error later in another set of patches.
Quoted 20 lines
Quoted 10 lines
Quoted 8 lines
An area needing discussing is how to do v1 -> v2 transformations for a one-time upgrade. There is a (very basic currently) python script which can pick a v1 stream, and a separate python library to write v2 streams.
One option would be to combine these two into a program which takes two fds, which libxc can
exec()out to. There is deliberate flexibility in the v2 restore code which allows a v1 -> v2 transformation on a stream without seeking.forking/execing in libxc might be problematic, fitting it into libxl might be easier, since it has infrastructure for that sort of thing.
libxl is not the only user of libxc, and fixing it there would not help the other consumers of libxc.
Furthermore, unless the consumer has an out-of-band detection method (libxl can easily be made to have, Xapi less so easy, and no idea about other consumers),
xc_domain_restore()is the first piece of code capable of detecting a legacy stream without needing to seek.Quoted 1 line
Quoted 8 lines
Quoted 3 lines
Or maybe the fact that most of this already happens in a process which libxl spawns for that purpose means that libxc can safely fork because the application in that case is under our control.
Exactly the same for Xapi, which uses a separate process which functions similarly to xc_save/restore but does domain build as well, which is why I am hoping this is an acceptable way of fixing the problem.
IMO we should just replace xc_domain_restore. xc_domain_restore is executed in a the helper process which can fork easily a process if needed. The idea is that xc_domain_restore read first bytes of the stream (4 is enough) and if not valid it possibly fork and call python code (or whatever) passing handle and bytes read and getting a new handle with converted data. If you think probably we'll call fork before any libxc function.
Another consideration about these patches should be file names and code split thinking about ARM migration too. Too many functions are in x86 specific files. For instance xc_domain_restore2 (in restore.c) should call a restore_arch_pv instead of a restore_x86_pv.
Frediano
Quoted 23 lines · Frediano Ziglio
Quoted 2 lines · Andrew Cooper
Quoted 1 line · Ian Campbell
On Wed, 2014-04-09 at 19:28 +0100, Andrew Cooper wrote:
....
Quoted 12 lines
Quoted 8 lines
Quoted 5 lines
The error handling is known to only semi-consistent. Functions return 0 for success and non-zero for failure. This is typically -1, although errno is not always relevant. However, the logging messages should all be relevant and correct. Making this properly consistent will involve wider effort across all of libxc.
It would be useful if the new code was correct at least so far as its own behaviour went (meaning no need to fix functions it calls as part of this).
libxc is too broken for that to be possible, (including such gems as the
save_callbacksfunctions which is not specified as to how to indicate success or error, and have developed at least 3 different flavours)Quoted 7 lines
Currently, the state of play is "if you get non0, something went wrong. Please read the log for relevant information" Once we get a
libxc_err_t(or so, given a discussion down the pub) capable of expressing more meaningful error problems, most codepaths (including these new ones) will need updating, although starting from a fairly-consistent position will be much easier than not.
Quoted 3 lines
I agree with Ian, we should have a first patch that just replace xc_domain_save/xc_domain_restore. We can fix functions return and error later in another set of patches.
Which is surely agreeing with me... unless I am getting rather confused?
Quoted 5 lines
Another consideration about these patches should be file names and code split thinking about ARM migration too. Too many functions are in x86 specific files. For instance
xc_domain_restore2(inrestore.c) should call arestore_arch_pvinstead of arestore_x86_pv.
Very specifically not. xc_domain_restore2() currently contains domain-agnostic restoration code. Yet-to-implement are restore_x86_hvm() and restore_arm() which are expected to be in restore_{x68_hvm,arm}.c. It is possible that some of the current helper functions in restore_x86_pv.c should be prompted to common.
This is explicitly to undo the current rats nest of code in xc_domain_{save,restore}(). I don't know why the PV and HVM migration code was merged together in the past, but they have almost nothing in common other than the format of the page batches (not even the content), and wedging the code together has resulted in functions substantially more complicated than the sum of their useful parts.
~Andrew
Quoted 12 lines · Andrew Cooper
Quoted 6 lines · Ian Campbell
Quoted 4 lines · Andrew Cooper
Some design decisions have been take very deliberately (e.g. splitting the logic for PV and hvm migration) while others have been more along the lines of "I think its a sensible thing to do given a lack of any evidence/opinion to the contrary".
Is there some indication of which is which?
Not really, given the clean rewrite, and also that it is only partially complete.
Quoted 1 line
Quoted 6 lines
Quoted 2 lines
Should we check in the desigh/spec which was previously posted as part of this?
I knew I forgot something...
http://xenbits.xen.org/people/andrewcoop/domain-save-format-E.pdf
What did you imagine might constitute an "Optional" record?
Other than that, everything looks sensible so far -- but having only save/restore of one guest type is the easy bit. It's when you start to have to multiplex across {PV, HVM, PVH} x {disk, network, remus} that things are going to get more "interesting".
-George
Quoted 18 lines · George Dunlap
Quoted 7 lines · Andrew Cooper
Quoted 6 lines · Ian Campbell
Quoted 4 lines · Andrew Cooper
Some design decisions have been take very deliberately (e.g. splitting the logic for PV and hvm migration) while others have been more along the lines of "I think its a sensible thing to do given a lack of any evidence/opinion to the contrary".
Is there some indication of which is which?
Quoted 8 lines
Not really, given the clean rewrite, and also that it is only partially complete.
Quoted 2 lines
Should we check in the desigh/spec which was previously posted as part of this?
I knew I forgot something...
http://xenbits.xen.org/people/andrewcoop/domain-save-format-E.pdf
Quoted 8 lines
What did you imagine might constitute an "Optional" record?
Other than that, everything looks sensible so far -- but having only save/restore of one guest type is the easy bit. It's when you start to have to multiplex across {PV, HVM, PVH} x {disk, network, remus} that things are going to get more "interesting".
-George
I did not opt for optional records, nor did I author them into the spec. Frankly, I cannot forsee a need for anything other than mandatory records. Nothing required for migration can possibly be optional, and anything else is likely to be toolstack data which necessarily has to be ahead of the domain in the migration stream so the receiving toolstack can create a suitable domain for the new xc_domain_restore() to restore into.
As for multiplexing, I have been considering that given the implementation of the live part of migration (which now works, as of a few hours ago).
Domain save and domain restore are two very very different operations. Save involves prodding at a live domain and stuffing values into a stream. Restore involves taking stuff from a stream and updating paused state.
A lot of the structure of save is common to all types of domain and roughly follows:
send some headers
start logdirty
send some preamble state (p2m size, p2m etc)
while consulting dirty bitmap:
send some memory
pause domain
send remaining memory
send postamble state (vcpus, tsc, qemu blob etc)
send end record
I was considering writing a common save routine with domain/arch hooks. This would allow for one canonical implementation of the save code (including how to do the 'live' bit, or how to apply remus) while separating the architecture bits.
Restore on the other hand is much more simple, and just involves reading records from the stream in the order found and applying the required changes to the specified domain. Each architecture can have a do {} while() loop which accepts valid records for the specific type of domain.
I will experiment with the domain/arch hooks when implementing HVM migration (which should be rather more simple)
~Andrew
Quoted 17 lines · Andrew Cooper
Quoted 16 lines · George Dunlap
Quoted 14 lines · Andrew Cooper
Quoted 6 lines · Ian Campbell
Quoted 4 lines · Andrew Cooper
Some design decisions have been take very deliberately (e.g. splitting the logic for PV and hvm migration) while others have been more along the lines of "I think its a sensible thing to do given a lack of any evidence/opinion to the contrary".
Is there some indication of which is which?
Not really, given the clean rewrite, and also that it is only partially complete.
Quoted 2 lines
Should we check in the desigh/spec which was previously posted as part of this?
I knew I forgot something...
Quoted 7 lines
Quoted 4 lines
What did you imagine might constitute an "Optional" record?
I did not opt for optional records, nor did I author them into the spec.
So sometimes tone is hard to read in an e-mail; your tone here seems a bit defensive, or at least rather strident; which seemed strange to me, but when I looked back at what I wrote, I realized that it could be read with a more sarcastic / biting tone than I intended.
So, I don't know if you read it that way, but if you did, sorry about the misunderstanding; I was just being curious. :-)
And if you didn't mean your tone to be strident, or it was strident for some other reason, nevermind. :-)
-George
Quoted 36 lines · George Dunlap
Quoted 22 lines · Andrew Cooper
Quoted 21 lines · George Dunlap
Quoted 19 lines · Andrew Cooper
Quoted 9 lines · Ian Campbell
Quoted 7 lines · Andrew Cooper
Some design decisions have been take very deliberately (e.g. splitting the
logic for PV and hvm migration) while others have been more along the lines of
"I think its a sensible thing to do given a lack of any evidence/opinion to
the contrary".Is there some indication of which is which?
Not really, given the clean rewrite, and also that it is only partially
complete.Quoted 3 lines
Should we check in the desigh/spec which was previously posted as part
of this?I knew I forgot something...
Quoted 7 lines
Quoted 4 lines
What did you imagine might constitute an "Optional" record?
I did not opt for optional records, nor did I author them into the spec.
So sometimes tone is hard to read in an e-mail; your tone here seems a bit defensive, or at least rather strident; which seemed strange to me, but when I looked back at what I wrote, I realized that it could be read with a more sarcastic / biting tone than I intended.
Quoted 8 lines
So, I don't know if you read it that way, but if you did, sorry about the misunderstanding; I was just being curious. :-)
And if you didn't mean your tone to be strident, or it was strident for some other reason, nevermind. :-)
-George
I honestly don't know for certain what my tone was intending to be. As far as thoughts went, it was very much "I am writing an email, but holding people up going to the pub, where I would also like to be".
Perhaps in retrospect the wording wasn't as good as it could have been.
As for optional records themselves; I don't have an objection to them being in the spec, but I can't see any practical use for them. They do no harm being specified yet unused (and I more important things to do with my time than try to argue against them).
~Andrew
Quoted 17 lines · George Dunlap
Quoted 15 lines · Andrew Cooper
Quoted 6 lines · Ian Campbell
Quoted 4 lines · Andrew Cooper
Some design decisions have been take very deliberately (e.g. splitting the logic for PV and hvm migration) while others have been more along the lines of "I think its a sensible thing to do given a lack of any evidence/opinion to the contrary".
Is there some indication of which is which?
Not really, given the clean rewrite, and also that it is only partially complete.
Quoted 3 lines
Should we check in the desigh/spec which was previously posted as part of this?
Quoted 6 lines
Quoted 3 lines
I knew I forgot something...
http://xenbits.xen.org/people/andrewcoop/domain-save-format-E.pdf
What did you imagine might constitute an "Optional" record?
This was something Ian Jackson asked for and it seems like a useful capabilitity to have for future use. Not sure what it might be used for yet.
David
Quoted 23 lines · David Vrabel
Quoted 22 lines · George Dunlap
Quoted 18 lines · Andrew Cooper
Quoted 6 lines · Ian Campbell
Quoted 4 lines · Andrew Cooper
Some design decisions have been take very deliberately (e.g. splitting the logic for PV and hvm migration) while others have been more along the lines of "I think its a sensible thing to do given a lack of any evidence/opinion to the contrary".
Is there some indication of which is which?
Not really, given the clean rewrite, and also that it is only partially complete.
Quoted 3 lines
Should we check in the desigh/spec which was previously posted as part of this?
I knew I forgot something...
http://xenbits.xen.org/people/andrewcoop/domain-save-format-E.pdf
Quoted 7 lines
Quoted 1 line
What did you imagine might constitute an "Optional" record?
This was something Ian Jackson asked for and it seems like a useful capabilitity to have for future use. Not sure what it might be used for yet.
David
Upper layers can stick stuff like machine descriptions (ie: "Web server for selling") or other more technical (original host name/ip, specific modifications of host like the "User agent" stuff in http, preferred migration encapsulation).
The definition of optional is you can discard it and machine will work the same.
Frediano
David Vrabel writes ("Re: [Xen-devel] [PATCH 0/6] [VERY RFC] Migration Stream v2"):
Quoted 6 lines · George Dunlap
Quoted 1 line
What did you imagine might constitute an "Optional" record?
This was something Ian Jackson asked for and it seems like a useful capabilitity to have for future use. Not sure what it might be used for yet.
Right.
Long experience with protocol design has taught me that protocols should almost always have both an extensibility mechanism which is ignored by ignorant receivers, and one which causes ignorant receivers to abort.
I don't know yet what we might use it for. However, we should test that it works (ie is ignored by) the receiver (or it will be useless).
Ian.
Quoted 10 lines · Ian Jackson
David Vrabel writes ("Re: [Xen-devel] [PATCH 0/6] [VERY RFC] Migration Stream v2"):
Quoted 6 lines · George Dunlap
Quoted 1 line
What did you imagine might constitute an "Optional" record?
This was something Ian Jackson asked for and it seems like a useful capabilitity to have for future use. Not sure what it might be used for yet.
Right.
Quoted 7 lines
Long experience with protocol design has taught me that protocols should almost always have both an extensibility mechanism which is ignored by ignorant receivers, and one which causes ignorant receivers to abort.
I don't know yet what we might use it for. However, we should test that it works (ie is ignored by) the receiver (or it will be useless).
Yes, this is the main concern. 2 billion record types should be plenty for the "required" field, so the 2 billion allocated for "optional" shouldn't be a big loss. :-) The main risk would be if something which is, in fact, required for proper operation on the far side is marked "optional". I guess as long as we have an "ignore everything optional" test case we should be OK.
-George
Quoted 6 lines · Andrew Cooper
Hello,
Presented here for early review is a basic implementation of PV guest migration using the v2 stream format.
PV non-live migration is believed-working; i.e. xl save/restore.
Based on comments I've seen elsewhere I think the state of the art has moved on pretty significantly since this posting. Unless you'd like me to I intend skip reviewing this iteration in favour of the next, is that OK or would you still like comments on this one?
Ian.
Quoted 6 lines · Ian Campbell
Quoted 5 lines · Andrew Cooper
Hello,
Presented here for early review is a basic implementation of PV guest migration using the v2 stream format.
Quoted 8 lines
Quoted 1 line
PV non-live migration is believed-working; i.e. xl save/restore.
Based on comments I've seen elsewhere I think the state of the art has moved on pretty significantly since this posting. Unless you'd like me to I intend skip reviewing this iteration in favour of the next, is that OK or would you still like comments on this one?
Ian.
Feel free to skip the review of this series if you wish.
The current state of play is that PV migration is completely working.
I am fixing a batching issue. The first version of the code did the really obvious, dumb, slow actions, for simplicity, and is now being updated to batch mapping hypercalls for speed.
David is working on HVM migration which is substantially more simple than PV.
I hope to have another series posted before the end of the week.
~Andrew
Quoted 1 line · Andrew Cooper
Feel free to skip the review of this series if you wish.
Done ;-)
Quoted 10 lines
The current state of play is that PV migration is completely working.
I am fixing a batching issue. The first version of the code did the really obvious, dumb, slow actions, for simplicity, and is now being updated to batch mapping hypercalls for speed.
David is working on HVM migration which is substantially more simple than PV.
I hope to have another series posted before the end of the week.
Excellent. </Burns>
Ian.