Misc patches to aid migration v2 Remus support
v6 cover Misc patches to aid migration v2 Remus support
This is the combination of Andrew Cooper's misc patches and mine to aid migration v2 Remus support.
See individual patches for details.
Git tree available at:
https://github.com/macrosheep/xen/tree/misc-remus-v6
v5->v6
Some minor changes, typos etc.
v4->v5
Most of the changes are trival, like drop brackets in DECLARE_HYPERCALL_BUFFER_SHADOW(), drop stray blank line etc. Except the 6th patch which add a do{}while (0) in xc_hypercall_buffer_free_pages macro.
Summary of changes:
M = modified
A = acked
N = new
no mark = unchanged from last round
Andrew Cooper (4):
A libxc/migration: Be rather stricter with illformed callers
libxc/save: Adjust stream-position callbacks for checkpointed streams
A libxc/migration: Specification update for CHECKPOINT records
libxc/migration: Pass checkpoint information into the save algorithm.
Yang Hongyang (12):
M tools/libxc: unused attribute in DECLARE_HYPERCALL_BUFFER_SHADOW
tools/libxc: add a check in xc_hypercall_buffer_free_pages macro libxc/save: introduce setup() and cleanup() on save libxc/save: rename to_send to dirty_bitmap libxc/save: adjust the memory allocation for migration libxc/save: remove bitmap param from send_some_pages libxc/save: rename send_some_pages to send_dirty_pages libxc/save: reuse send_dirty_pages() in send_all_pages() libxc/restore: introduce process_record() libxc/restore: split read/handle qemu info
N libxc/restore: introduce setup() and cleanup() on restore N libxc/restore: add checkpointed flag to the restore context
docs/specs/libxc-migration-stream.pandoc | 29 +++++- tools/libxc/include/xenctrl.h | 8 +- tools/libxc/include/xenguest.h | 1 + tools/libxc/xc_bitops.h | 5 + tools/libxc/xc_sr_common.c | 1 + tools/libxc/xc_sr_common.h | 33 ++++-- tools/libxc/xc_sr_restore.c | 130 +++++++++++++++-------- tools/libxc/xc_sr_restore_x86_hvm.c | 28 ++++- tools/libxc/xc_sr_save.c | 171 ++++++++++++++++--------------- tools/libxc/xc_sr_save_x86_hvm.c | 30 +++--- tools/libxc/xc_sr_save_x86_pv.c | 29 ++++-- tools/libxc/xc_sr_stream_format.h | 1 + tools/libxl/libxl_dom.c | 1 + 13 files changed, 303 insertions(+), 164 deletions(-)
Signature · 1 line
1.9.1
PATCH v6 1/16 libxc/migration: Be rather stricter with illformed callers
From: Andrew Cooper <[email protected]>
The migration code itself should be able to validly assume all mandatory callbacks are set up.
--- tools/libxc/xc_sr_save.c | 4 ++++ tools/libxc/xc_sr_save_x86_hvm.c | 7 ------- 2 files changed, 4 insertions(+), 7 deletions(-)
tools/libxc/xc_sr_save.c +4 -0
@@ -738,6 +738,10 @@ int xc_domain_save2(xc_interface *xch, int io_fd, uint32_t dom, ctx.save.max_iterations =5 ; ctx.save.dirty_threshold =50 ; +/* Sanity checks for callbacks. */ +if ( hvm ) +assert (callbacks->switch_qemu_logdirty); +IPRINTF ("In experimental %s" , __func__);DPRINTF ("fd %d, dom %u, max_iters %u, max_factor %u, flags %u, hvm %d" , io_fd, dom, max_iters, max_factor, flags, hvm);
tools/libxc/xc_sr_save_x86_hvm.c +0 -7
@@ -166,13 +166,6 @@ 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) ) {
Signature · 1 line
1.9.1
PATCH v6 2/16 libxc/save: Adjust stream-position callbacks for checkpointed streams
In reply to Yang HongyangFrom: Andrew Cooper <[email protected]>
There are some records which should only be sent once in the stream, and not repeated for each checkpoint. {start,end}_of_stream() become per-checkpoint, and a new start_of_stream() is introduced.
There is no resulting change record order, but the X86_PV_INFO record is identified as once per stream. Currently the X86_PV_P2M_FRAMES record is as well, but this is because of an implementation bug and can move back to being on an as-needed basis when fixed.
In addition, a few minor adjustments of comments and layout.
--- tools/libxc/xc_sr_common.h | 21 +++++++++++++-------- tools/libxc/xc_sr_save.c | 10 +++++++--- tools/libxc/xc_sr_save_x86_hvm.c | 23 +++++++++++++++-------- tools/libxc/xc_sr_save_x86_pv.c | 29 +++++++++++++++++++---------- 4 files changed, 54 insertions(+), 29 deletions(-)
tools/libxc/xc_sr_common.h +13 -8
@@ -61,19 +61,24 @@ struct xc_sr_save_opsint (*setup)(struct xc_sr_context *ctx);/** -* Write records which need to be at the start of the stream. This is -* called after the Image and Domain headers are written. (Any records -* which need to be ahead of the memory.) +* Send records which need to be at the start of the stream. This is +* called once, after the Image and Domain headers are written. */ int (*start_of_stream)(struct xc_sr_context *ctx);/** -* Write records which need to be at the end of the stream, following the -* complete memory contents. The caller shall handle writing the END -* record into the stream. (Any records which need to be after the memory -* is complete.) +* Send records which need to be at the start of a checkpoint. This is +* called once, or once per checkpoint in a checkpointed stream, and is +* ahead of memory data. */ -int (*end_of_stream)(struct xc_sr_context *ctx); +int (*start_of_checkpoint)(struct xc_sr_context *ctx); + +/** +* Send records which need to be at the end of the checkpoint. This is +* called once, or once per checkpoint in a checkpointed stream, and is +* after the memory data. +*/ +int (*end_of_checkpoint)(struct xc_sr_context *ctx);/** * Clean up the local environment. Will be called exactly once, either
tools/libxc/xc_sr_save.c +7 -3
@@ -662,6 +662,10 @@ static int save(struct xc_sr_context *ctx, uint16_t guest_type)if ( rc ) goto err; + rc = ctx->save.ops.start_of_checkpoint (ctx); +if ( rc ) + goto err; +if ( ctx->save.live ) rc =send_domain_memory_live (ctx);else
@@ -678,12 +682,12 @@ static int save(struct xc_sr_context *ctx, uint16_t guest_type) goto err; } -xc_report_progress_single (xch,"End of stream" ); - - rc = ctx->save.ops.end_of_stream (ctx); + rc = ctx->save.ops.end_of_checkpoint (ctx);if ( rc ) goto err; +xc_report_progress_single (xch,"End of stream" ); + rc =write_end_record (ctx);if ( rc ) goto err;
tools/libxc/xc_sr_save_x86_hvm.c +15 -8
@@ -184,7 +184,13 @@ static int x86_hvm_start_of_stream(struct xc_sr_context *ctx)return 0 ; } -static int x86_hvm_end_of_stream (struct xc_sr_context *ctx) +static int x86_hvm_start_of_checkpoint (struct xc_sr_context *ctx) +{ +/* no-op */ +return 0 ; +} + +static int x86_hvm_end_of_checkpoint (struct xc_sr_context *ctx) {int rc;
@@ -209,7 +215,7 @@ static int x86_hvm_end_of_stream(struct xc_sr_context *ctx)if ( rc )return rc; -return rc; +return 0 ; }static int x86_hvm_cleanup (struct xc_sr_context *ctx)
@@ -230,12 +236,13 @@ static int x86_hvm_cleanup(struct xc_sr_context *ctx)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, + .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, + .start_of_checkpoint = x86_hvm_start_of_checkpoint, + .end_of_checkpoint = x86_hvm_end_of_checkpoint, + .cleanup = x86_hvm_cleanup, };/*
tools/libxc/xc_sr_save_x86_pv.c +19 -10
@@ -816,6 +816,12 @@ static int x86_pv_start_of_stream(struct xc_sr_context *ctx)if ( rc )return rc; +/* +* Ideally should be able to change during migration. Currently +* corruption will occur if the contents or location of the P2M changes +* during the live migration loop. If one is very lucky, the breakage +* will not be subtle. +*/ rc =write_x86_pv_p2m_frames (ctx);if ( rc )return rc;
@@ -823,10 +829,12 @@ static int x86_pv_start_of_stream(struct xc_sr_context *ctx)return 0 ; } -/* -* save_ops function. Writes tail records information into the stream. -*/ -static int x86_pv_end_of_stream (struct xc_sr_context *ctx) +static int x86_pv_start_of_checkpoint (struct xc_sr_context *ctx) +{ +return 0 ; +} + +static int x86_pv_end_of_checkpoint (struct xc_sr_context *ctx) {int rc;
@@ -866,12 +874,13 @@ static int x86_pv_cleanup(struct xc_sr_context *ctx)struct xc_sr_save_ops save_ops_x86_pv = { - .pfn_to_gfn = x86_pv_pfn_to_gfn, - .normalise_page = x86_pv_normalise_page, - .setup = x86_pv_setup, - .start_of_stream = x86_pv_start_of_stream, - .end_of_stream = x86_pv_end_of_stream, - .cleanup = x86_pv_cleanup, + .pfn_to_gfn = x86_pv_pfn_to_gfn, + .normalise_page = x86_pv_normalise_page, + .setup = x86_pv_setup, + .start_of_stream = x86_pv_start_of_stream, + .start_of_checkpoint = x86_pv_start_of_checkpoint, + .end_of_checkpoint = x86_pv_end_of_checkpoint, + .cleanup = x86_pv_cleanup, };/*
Signature · 1 line
1.9.1
Re: [PATCH v6 02/16] libxc/save: Adjust stream-position callbacks for checkpointed streams
Quoted 6 lines · Yang Hongyang
From: Andrew Cooper <[email protected]>
There are some records which should only be sent once in the stream, and not repeated for each checkpoint. {start,end}_of_stream() become per-checkpoint, and a new
start_of_stream()is introduced.
Quoted 8 lines
There is no resulting change record order, but the
X86_PV_INFOrecord is identified as once per stream. Currently theX86_PV_P2M_FRAMESrecord is as well, but this is because of an implementation bug and can move back to being on an as-needed basis when fixed.In addition, a few minor adjustments of comments and layout.
Signed-off-by Andrew Cooper <[email protected]>
You pointed me to the docs in v5, so my previous
stands.
(just replying here so I don't have to check two threads when I come to reply).
PATCH v6 3/16 libxc/migration: Specification update for CHECKPOINT records
In reply to Yang HongyangFrom: Andrew Cooper <[email protected]>
Checkpointed streams need to signal the end of a consistent view of VM state, and the start of the libxl data.
--- docs/specs/libxc-migration-stream.pandoc | 29 ++++++++++++++++++++++++++--- tools/libxc/xc_sr_common.c | 1 + tools/libxc/xc_sr_stream_format.h | 1 + 3 files changed, 28 insertions(+), 3 deletions(-)
docs/specs/libxc-migration-stream.pandoc +26 -3
@@ -37,8 +37,6 @@ Not Yet Included The following features are not yet fully specified and will be included in a future draft. -* Remus - * Page data compression. * ARM
@@ -227,7 +225,9 @@ type 0x00000000: END 0x0000000D: VERIFY - 0x0000000E - 0x7FFFFFFF: Reserved for future _mandatory_ + 0x0000000E: CHECKPOINT + + 0x0000000F - 0x7FFFFFFF: Reserved for future _mandatory_ records. 0x80000000 - 0xFFFFFFFF: Reserved for future _optional_
@@ -578,6 +578,29 @@ The verify record contains no fields; its body_length is 0. \clearpage +CHECKPOINT +---------- + +A checkpoint record indicates that all the preceding records in the stream +represent a consistent view of VM state. + + 0 1 2 3 4 5 6 7 octet + +-------------------------------------------------+ + +The checkpoint record contains no fields; its body_length is 0 + +If the stream is embedded in a higher level toolstack stream, the +CHECKPOINT record marks the end of the libxc portion of the stream +and the stream is handed back to the higher level for further +processing. + +The higher level stream may then hand the stream back to libxc to +process another set of records for the next consistent VM state +snapshot. This next set of records may be terminated by another +CHECKPOINT record or an END record. + +\clearpage + Layout ======
tools/libxc/xc_sr_common.c +1 -0
@@ -34,6 +34,7 @@ static const char *mandatory_rec_types[] = [REC_TYPE_TOOLSTACK] = "Toolstack", [REC_TYPE_X86_PV_VCPU_MSRS] = "x86 PV vcpu msrs", [REC_TYPE_VERIFY] = "Verify", + [REC_TYPE_CHECKPOINT] = "Checkpoint", };const char *rec_type_to_str (uint32_t type)
tools/libxc/xc_sr_stream_format.h +1 -0
@@ -74,6 +74,7 @@ struct xc_sr_rhdr#define REC_TYPE_TOOLSTACK 0x0000000bU#define REC_TYPE_X86_PV_VCPU_MSRS 0x0000000cU#define REC_TYPE_VERIFY 0x0000000dU +#define REC_TYPE_CHECKPOINT 0x0000000eU#define REC_TYPE_OPTIONAL 0x80000000U
Signature · 1 line
1.9.1
PATCH v6 4/16 libxc/migration: Pass checkpoint information into the save algorithm.
In reply to Yang HongyangFrom: Andrew Cooper <[email protected]>
--- tools/libxc/include/xenguest.h | 1 + tools/libxc/xc_sr_common.h | 3 +++ tools/libxc/xc_sr_save.c | 3 +++ tools/libxl/libxl_dom.c | 1 + 4 files changed, 8 insertions(+)
tools/libxc/include/xenguest.h +1 -0
@@ -30,6 +30,7 @@#define XCFLAGS_HVM (1 << 2)#define XCFLAGS_STDVGA (1 << 3)#define XCFLAGS_CHECKPOINT_COMPRESS (1 << 4) +#define XCFLAGS_CHECKPOINTED (1 << 5)#define X86_64_B_SIZE 64#define X86_32_B_SIZE 32
tools/libxc/xc_sr_common.h +3 -0
@@ -174,6 +174,9 @@ struct xc_sr_context/* Live migrate vs non live suspend. */ bool live; +/* Plain VM, or checkpoints over time. */ +bool checkpointed; +/* Further debugging information in the stream. */ bool debug;
tools/libxc/xc_sr_save.c +3 -0
@@ -732,6 +732,7 @@ int xc_domain_save2(xc_interface *xch, int io_fd, uint32_t dom, ctx.save.callbacks = callbacks; ctx.save.live = !!(flags &XCFLAGS_LIVE ); ctx.save.debug = !!(flags &XCFLAGS_DEBUG ); + ctx.save.checkpointed = !!(flags &XCFLAGS_CHECKPOINTED );/* * TODO: Find some time to better tweak the live migration algorithm.
@@ -745,6 +746,8 @@ int xc_domain_save2(xc_interface *xch, int io_fd, uint32_t dom,/* Sanity checks for callbacks. */ if ( hvm )assert (callbacks->switch_qemu_logdirty); +if ( ctx.save.checkpointed ) +assert (callbacks->checkpoint && callbacks->postcopy);IPRINTF ("In experimental %s" , __func__); DPRINTF("fd %d, dom %u, max_iters %u, max_factor %u, flags %u, hvm %d",
tools/libxl/libxl_dom.c +1 -0
@@ -2003,6 +2003,7 @@ void libxl__domain_suspend(libxl__egc *egc, libxl__domain_suspend_state *dss)if (r_info !=NULL ) { dss->interval = r_info->interval; + dss->xcflags |=XCFLAGS_CHECKPOINTED ;if (libxl_defbool_val (r_info->compression)) dss->xcflags |=XCFLAGS_CHECKPOINT_COMPRESS ; }
Signature · 1 line
1.9.1
Re: [PATCH v6 04/16] libxc/migration: Pass checkpoint information into the save algorithm.
Quoted 3 lines · Yang Hongyang
From: Andrew Cooper <[email protected]>
Signed-off-by Andrew Cooper <[email protected]>
As I mentioned in v5 (after you sent v6) please propose a few words about how this works with the v1 code and then:
Quoted 69 lines
CC Ian Jackson <[email protected]>CC Wei Liu <[email protected]>CC Yang Hongyang <[email protected]>--- tools/libxc/include/xenguest.h | 1 + tools/libxc/xc_sr_common.h | 3 +++ tools/libxc/xc_sr_save.c | 3 +++ tools/libxl/libxl_dom.c | 1 + 4 files changed, 8 insertions(+)tools/libxc/include/xenguest.h +1
-0@@ -30,6 +30,7 @@#define XCFLAGS_HVM (1 << 2)#define XCFLAGS_STDVGA (1 << 3)#define XCFLAGS_CHECKPOINT_COMPRESS (1 << 4) +#define XCFLAGS_CHECKPOINTED (1 << 5)#define X86_64_B_SIZE 64#define X86_32_B_SIZE 32tools/libxc/xc_sr_common.h +3
-0@@ -174,6 +174,9 @@ struct xc_sr_context/* Live migrate vs non live suspend. */ bool live; +/* Plain VM, or checkpoints over time. */ +bool checkpointed; +/* Further debugging information in the stream. */ bool debug;tools/libxc/xc_sr_save.c +3
-0@@ -732,6 +732,7 @@ int xc_domain_save2(xc_interface *xch, int io_fd, uint32_t dom, ctx.save.callbacks = callbacks; ctx.save.live = !!(flags &XCFLAGS_LIVE ); ctx.save.debug = !!(flags &XCFLAGS_DEBUG ); + ctx.save.checkpointed = !!(flags &XCFLAGS_CHECKPOINTED );/* * TODO: Find some time to better tweak the live migration algorithm. @@ -745,6 +746,8 @@ int xc_domain_save2(xc_interface *xch, int io_fd, uint32_t dom,/* Sanity checks for callbacks. */ if ( hvm )assert (callbacks->switch_qemu_logdirty); +if ( ctx.save.checkpointed ) +assert (callbacks->checkpoint && callbacks->postcopy);IPRINTF ("In experimental %s" , __func__); DPRINTF("fd %d, dom %u, max_iters %u, max_factor %u, flags %u, hvm %d",tools/libxl/libxl_dom.c +1
-0@@ -2003,6 +2003,7 @@ void libxl__domain_suspend(libxl__egc *egc, libxl__domain_suspend_state *dss)if (r_info !=NULL ) { dss->interval = r_info->interval; + dss->xcflags |=XCFLAGS_CHECKPOINTED ;if (libxl_defbool_val (r_info->compression)) dss->xcflags |=XCFLAGS_CHECKPOINT_COMPRESS ; }
Re: [PATCH v6 04/16] libxc/migration: Pass checkpoint information into the save algorithm.
Quoted 9 lines · Ian Campbell
Quoted 3 lines · Yang Hongyang
From: Andrew Cooper <[email protected]>
Signed-off-by Andrew Cooper <[email protected]>As I mentioned in v5 (after you sent v6) please propose a few words about how this works with the v1 code and then:
Acked-by Ian Campbell <[email protected]>
Actually since this is the only thing left for this series and timezones suggest you won't be around until tomorrow I'm going to use:
The old code checks the callbacks "postcopy & checkpoint", if the callbacks exists, it will call them. However this is unreliable, so add this flag to explicitly indicate a checkpointed stream in the new code. This is backward compatible with the legacy migration just don't know this flag and will ignore it.
(which is basically you explanation from v5 reworded slightly to fit a commit log)
Quoted 77 lines
Quoted 63 lines
CC Ian Jackson <[email protected]>CC Wei Liu <[email protected]>CC Yang Hongyang <[email protected]>--- tools/libxc/include/xenguest.h | 1 + tools/libxc/xc_sr_common.h | 3 +++ tools/libxc/xc_sr_save.c | 3 +++ tools/libxl/libxl_dom.c | 1 + 4 files changed, 8 insertions(+)tools/libxc/include/xenguest.h +1
-0@@ -30,6 +30,7 @@#define XCFLAGS_HVM (1 << 2)#define XCFLAGS_STDVGA (1 << 3)#define XCFLAGS_CHECKPOINT_COMPRESS (1 << 4) +#define XCFLAGS_CHECKPOINTED (1 << 5)#define X86_64_B_SIZE 64#define X86_32_B_SIZE 32tools/libxc/xc_sr_common.h +3
-0@@ -174,6 +174,9 @@ struct xc_sr_context/* Live migrate vs non live suspend. */ bool live; +/* Plain VM, or checkpoints over time. */ +bool checkpointed; +/* Further debugging information in the stream. */ bool debug;tools/libxc/xc_sr_save.c +3
-0@@ -732,6 +732,7 @@ int xc_domain_save2(xc_interface *xch, int io_fd, uint32_t dom, ctx.save.callbacks = callbacks; ctx.save.live = !!(flags &XCFLAGS_LIVE ); ctx.save.debug = !!(flags &XCFLAGS_DEBUG ); + ctx.save.checkpointed = !!(flags &XCFLAGS_CHECKPOINTED );/* * TODO: Find some time to better tweak the live migration algorithm. @@ -745,6 +746,8 @@ int xc_domain_save2(xc_interface *xch, int io_fd, uint32_t dom,/* Sanity checks for callbacks. */ if ( hvm )assert (callbacks->switch_qemu_logdirty); +if ( ctx.save.checkpointed ) +assert (callbacks->checkpoint && callbacks->postcopy);IPRINTF ("In experimental %s" , __func__); DPRINTF("fd %d, dom %u, max_iters %u, max_factor %u, flags %u, hvm %d",tools/libxl/libxl_dom.c +0
-0tools/libxl/libxl_dom.c void libxl__domain_suspend(libxl__egc *egc, libxl__domain_suspend_state *dss) · line 2009
Quoted 7 lines
tools/libxl/libxl_dom.c +1
-0@@ -2003,6 +2003,7 @@ void libxl__domain_suspend(libxl__egc *egc, libxl__domain_suspend_state *dss)if (r_info !=NULL ) { dss->interval = r_info->interval; + dss->xcflags |=XCFLAGS_CHECKPOINTED ;if (libxl_defbool_val (r_info->compression)) dss->xcflags |=XCFLAGS_CHECKPOINT_COMPRESS ; }_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v6 5/16 tools/libxc: unused attribute in DECLARE_HYPERCALL_BUFFER_SHADOW
In reply to Yang HongyangThere are cases where we only need to use the hypercall buffer data, and do not use the xc_hypercall_buffer_t struct. DECLARE_HYPERCALL_BUFFER_SHADOW defines a user pointer that can allow us to access the hypercall buffer data but it also defines a xc_hypercall_buffer_t that we don't use, the compiler will report arg unused error.
Add __attribute__((unused)) before xc_hypercall_buffer_t to avoid the compiler error.
Example cases:
In send_all_pages(), we only need to use the hypercall buffer data which is a dirty bitmap, we set the dirty bitmap to all dirty and call send_dirty_pages, we will not use the xc_hypercall_buffer_t and hypercall to retrieve the dirty bitmap.
In send_some_pages(), we will also only need to use the dirty_bitmap. the retrieve dirty bitmap hypercall are done by the caller.
--- tools/libxc/include/xenctrl.h | 1 + 1 file changed, 1 insertion(+)
tools/libxc/include/xenctrl.h +1 -0
@@ -289,6 +289,7 @@ typedef struct xc_hypercall_buffer xc_hypercall_buffer_t;*/ #define DECLARE_HYPERCALL_BUFFER_SHADOW (_type, _name, _hbuf) \ _type *(_name) = (_hbuf)->hbuf; \ + __attribute__((unused)) \ xc_hypercall_buffer_t XC__HYPERCALL_BUFFER_NAME(_name) = { \ .hbuf = (void *)-1, \ .param_shadow = (_hbuf), \
Signature · 1 line
1.9.1
Re: [PATCH v6 05/16] tools/libxc: unused attribute in DECLARE_HYPERCALL_BUFFER_SHADOW
Quoted 17 lines · Yang Hongyang
There are cases where we only need to use the hypercall buffer data, and do not use the
xc_hypercall_buffer_tstruct.DECLARE_HYPERCALL_BUFFER_SHADOWdefines a user pointer that can allow us to access the hypercall buffer data but it also defines axc_hypercall_buffer_tthat we don't use, the compiler will report arg unused error.
Add __attribute__((unused)) beforexc_hypercall_buffer_tto avoid the compiler error.Example cases:
Insend_all_pages(), we only need to use the hypercall buffer data which is a dirty bitmap, we set the dirty bitmap to all dirty and callsend_dirty_pages, we will not use thexc_hypercall_buffer_tand hypercall to retrieve the dirty bitmap.
Insend_some_pages(), we will also only need to use thedirty_bitmap. the retrieve dirty bitmap hypercall are done by the caller.
Quoted 1 line
Signed-off-by Yang Hongyang <[email protected]>
PATCH v6 6/16 tools/libxc: add a check in xc_hypercall_buffer_free_pages macro
In reply to Yang HongyangWhen we use a DECLARE_HYPERCALL_BUFFER_SHADOW define a user pointer '_name' and a shadow xc_hypercall_buffer_t. then call xc_hypercall_buffer_free_pages(_xch, _name, _nr), the complier will report '_name' unused error, it's because xc_hypercall_buffer_free_pages() is a MACRO and '_name' transparently converted to the hypercall buffer. it confused the caller because xc_hypercall_buffer_free_pages() do look like a function and take '_name' as an arg.
Add an if check to let the compiler think we are actually using the argument '_name'.
--- tools/libxc/include/xenctrl.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
tools/libxc/include/xenctrl.h +6 -1
@@ -350,7 +350,12 @@ void xc__hypercall_buffer_free(xc_interface *xch, xc_hypercall_buffer_t *b);void *xc__hypercall_buffer_alloc_pages (xc_interface *xch,xc_hypercall_buffer_t *b,int nr_pages);#define xc_hypercall_buffer_alloc_pages (_xch, _name, _nr) xc__hypercall_buffer_alloc_pages(_xch, HYPERCALL_BUFFER(_name), _nr)void xc__hypercall_buffer_free_pages (xc_interface *xch,xc_hypercall_buffer_t *b,int nr_pages); -#define xc_hypercall_buffer_free_pages (_xch, _name, _nr) xc__hypercall_buffer_free_pages(_xch, HYPERCALL_BUFFER(_name), _nr) +#define xc_hypercall_buffer_free_pages (_xch, _name, _nr) \ + do { \ + if ( _name ) \ + xc__hypercall_buffer_free_pages(_xch, HYPERCALL_BUFFER(_name), \ + _nr); \ + } while (0)/* * Array of hypercall buffers.
Signature · 1 line
1.9.1
Re: [PATCH v6 06/16] tools/libxc: add a check in xc_hypercall_buffer_free_pages macro
Quoted 1 line · Yang Hongyang
When we use a
DECLARE_HYPERCALL_BUFFER_SHADOWdefine a user
^it defines
Quoted 2 lines
pointer '
_name' and a shadowxc_hypercall_buffer_t. then callxc_hypercall_buffer_free_pages(_xch, _name, _nr),
^When then calling
Quoted 1 line
the complier will report '
_name' unused error, it's because
^drop it's
Quoted 1 line
xc_hypercall_buffer_free_pages()is a MACRO and '_name'
^is
Quoted 1 line
transparently converted to the hypercall buffer. it confused
confuses
Quoted 1 line
the caller because
xc_hypercall_buffer_free_pages()do look
looks
Quoted 1 line
like a function and take '
_name' as an arg.
takes
Quoted 4 lines
Add an if check to let the compiler think we are actually using the argument '
_name'.Signed-off-by Yang Hongyang <[email protected]>
I can fix those on commit if there is no other reason for a v7.
PATCH v6 7/16 libxc/save: introduce setup() and cleanup() on save
In reply to Yang Hongyangintroduce setup() and cleanup() which subsume the ctx->save.ops.{setup,cleanup}() calls.
The SHADOW_OP_OFF hypercall also included in the cleanup().
--- tools/libxc/xc_sr_save.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-)
tools/libxc/xc_sr_save.c +27 -7
@@ -637,6 +637,31 @@ static int send_domain_memory_nonlive(struct xc_sr_context *ctx)return rc; } +static int setup (struct xc_sr_context *ctx) +{ +int rc; + + rc = ctx->save.ops.setup (ctx); +if ( rc ) + goto err; + + rc =0 ; + + err: +return rc; +} + +static void cleanup (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; + +xc_shadow_control (xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_OFF , +NULL ,0 ,NULL ,0 ,NULL ); + +if ( ctx->save.ops.cleanup (ctx) ) +PERROR ("Failed to clean up" ); +} +/* * Save a domain. */
@@ -648,7 +673,7 @@ static int save(struct xc_sr_context *ctx, uint16_t guest_type)IPRINTF ("Saving domain %d, type %s" , ctx->domid,dhdr_type_to_str (guest_type)); - rc = ctx->save.ops.setup (ctx); + rc =setup (ctx);if ( rc ) goto err;
@@ -701,12 +726,7 @@ static int save(struct xc_sr_context *ctx, uint16_t guest_type)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" ); +cleanup (ctx);if ( saved_rc ) {
Signature · 1 line
1.9.1
Re: [PATCH v6 07/16] libxc/save: introduce setup() and cleanup() on save
Quoted 3 lines · Yang Hongyang
introduce
setup()andcleanup()which subsume the ctx->save.ops.{setup,cleanup}() calls.
TheSHADOW_OP_OFFhypercall also included in thecleanup().
^is also
Quoted 2 lines
Signed-off-by Yang Hongyang <[email protected]>
PATCH v6 8/16 libxc/save: rename to_send to dirty_bitmap
In reply to Yang Hongyangrename to_send to dirty_bitmap.
--- tools/libxc/xc_sr_save.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
tools/libxc/xc_sr_save.c +11 -11
@@ -475,20 +475,20 @@ static int update_progress_string(struct xc_sr_context *ctx,static int send_domain_memory_live (struct xc_sr_context *ctx) {xc_interface *xch = ctx->xch; - DECLARE_HYPERCALL_BUFFER(unsigned long, to_send); + DECLARE_HYPERCALL_BUFFER(unsigned long, dirty_bitmap);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))); + dirty_bitmap =xc_hypercall_buffer_alloc_pages ( + xch, dirty_bitmap,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 ) +if ( !ctx->save.batch_pfns || !dirty_bitmap || !ctx->save.deferred_pages ) {ERROR ("Unable to allocate memory for to_{send,fix}/batch bitmaps" ); goto out;
@@ -512,7 +512,7 @@ static int send_domain_memory_live(struct xc_sr_context *ctx) {if (xc_shadow_control ( xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_CLEAN , -HYPERCALL_BUFFER (to_send), ctx->save.p2m_size, +HYPERCALL_BUFFER (dirty_bitmap), ctx->save.p2m_size,NULL ,0 , &stats) != ctx->save.p2m_size ) {PERROR ("Failed to retrieve logdirty bitmap" );
@@ -527,7 +527,7 @@ static int send_domain_memory_live(struct xc_sr_context *ctx)if ( rc ) goto out; - rc =send_some_pages (ctx, to_send, stats.dirty_count); + rc =send_some_pages (ctx, dirty_bitmap, stats.dirty_count);if ( rc ) goto out; }
@@ -538,7 +538,7 @@ static int send_domain_memory_live(struct xc_sr_context *ctx)if (xc_shadow_control ( xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_CLEAN , -HYPERCALL_BUFFER (to_send), ctx->save.p2m_size, +HYPERCALL_BUFFER (dirty_bitmap), ctx->save.p2m_size,NULL ,0 , &stats) != ctx->save.p2m_size ) {PERROR ("Failed to retrieve logdirty bitmap" );
@@ -550,9 +550,9 @@ static int send_domain_memory_live(struct xc_sr_context *ctx)if ( rc ) goto out; -bitmap_or (to_send, ctx->save.deferred_pages, ctx->save.p2m_size); +bitmap_or (dirty_bitmap, ctx->save.deferred_pages, ctx->save.p2m_size); - rc =send_some_pages (ctx, to_send, + rc =send_some_pages (ctx, dirty_bitmap, stats.dirty_count + ctx->save.nr_deferred_pages);if ( rc ) goto out;
@@ -578,7 +578,7 @@ static int send_domain_memory_live(struct xc_sr_context *ctx)if (xc_shadow_control ( xch, ctx->domid,XEN_DOMCTL_SHADOW_OP_PEEK , -HYPERCALL_BUFFER (to_send), ctx->save.p2m_size, +HYPERCALL_BUFFER (dirty_bitmap), ctx->save.p2m_size,NULL ,0 , &stats) != ctx->save.p2m_size ) {PERROR ("Failed to retrieve logdirty bitmap" );
@@ -593,7 +593,7 @@ static int send_domain_memory_live(struct xc_sr_context *ctx) out:xc_set_progress_prefix (xch,NULL );free (progress_str); -xc_hypercall_buffer_free_pages (xch, to_send, +xc_hypercall_buffer_free_pages (xch, dirty_bitmap,NRPAGES (bitmap_size (ctx->save.p2m_size)));free (ctx->save.deferred_pages);free (ctx->save.batch_pfns);
Signature · 1 line
1.9.1
Re: [PATCH v6 08/16] libxc/save: rename to_send to dirty_bitmap
Quoted 3 lines · Yang Hongyang
rename
to_sendtodirty_bitmap.Signed-off-by Yang Hongyang <[email protected]>
PATCH v6 9/16 libxc/save: adjust the memory allocation for migration
In reply to Yang HongyangMove the memory allocation before the concrete live/nolive save in order to avoid the free/alloc memory loop when using Remus.
--- tools/libxc/xc_sr_common.h | 1 + tools/libxc/xc_sr_save.c | 60 ++++++++++++++++++++++------------------------ 2 files changed, 29 insertions(+), 32 deletions(-)
tools/libxc/xc_sr_common.h +1 -0
@@ -190,6 +190,7 @@ struct xc_sr_contextunsigned nr_batch_pfns;unsigned long *deferred_pages;unsigned long nr_deferred_pages; +xc_hypercall_buffer_t dirty_bitmap_hbuf; } save; struct /* Restore data. */
tools/libxc/xc_sr_save.c +28 -32
106 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [PATCH v6 09/16] libxc/save: adjust the memory allocation for migration
Quoted 4 lines · Yang Hongyang
Move the memory allocation before the concrete live/nolive save in order to avoid the free/alloc memory loop when using Remus.
Signed-off-by Yang Hongyang <[email protected]>
PATCH v6 10/16 libxc/save: remove bitmap param from send_some_pages
In reply to Yang HongyangIn last patch we added dirty bitmap to the save context, we no longer need to pass this param to send_some_pages. We can get dirty bitmap from the save context. 'entries' should stay as it is a useful sanity check.
--- tools/libxc/xc_sr_save.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
tools/libxc/xc_sr_save.c +6 -6
@@ -374,23 +374,24 @@ static int send_all_pages(struct xc_sr_context *ctx) }/* -* Send a subset of pages in the guests p2m, according to the provided bitmap. +* Send a subset of pages in the guests p2m, according to the dirty 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; + DECLARE_HYPERCALL_BUFFER_SHADOW(unsigned long, dirty_bitmap, + &ctx->save.dirty_bitmap_hbuf);for ( p =0 , written =0 ; p < ctx->save.p2m_size; ++p ) { -if ( !test_bit (p, bitmap) ) +if ( !test_bit (p, dirty_bitmap) )continue ; rc =add_to_batch (ctx, p);
@@ -515,7 +516,7 @@ static int send_domain_memory_live(struct xc_sr_context *ctx)if ( rc ) goto out; - rc =send_some_pages (ctx, dirty_bitmap, stats.dirty_count); + rc =send_some_pages (ctx, stats.dirty_count);if ( rc ) goto out; }
@@ -540,8 +541,7 @@ static int send_domain_memory_live(struct xc_sr_context *ctx)bitmap_or (dirty_bitmap, ctx->save.deferred_pages, ctx->save.p2m_size); - rc =send_some_pages (ctx, dirty_bitmap, - stats.dirty_count + ctx->save.nr_deferred_pages); + rc =send_some_pages (ctx, stats.dirty_count + ctx->save.nr_deferred_pages);if ( rc ) goto out;
Signature · 1 line
1.9.1
Re: [PATCH v6 10/16] libxc/save: remove bitmap param from send_some_pages
Quoted 6 lines · Yang Hongyang
In last patch we added dirty bitmap to the save context, we no longer need to pass this param to
send_some_pages. We can get dirty bitmap from the save context. 'entries' should stay as it is a useful sanity check.Signed-off-by Yang Hongyang <[email protected]>
PATCH v6 11/16 libxc/save: rename send_some_pages to send_dirty_pages
In reply to Yang Hongyangrename send_some_pages to send_dirty_pages, no functional change.
--- tools/libxc/xc_sr_save.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tools/libxc/xc_sr_save.c +4 -4
@@ -379,8 +379,8 @@ static int send_all_pages(struct xc_sr_context *ctx)* * Bitmap is bounded by p2m_size. */ -static int send_some_pages (struct xc_sr_context *ctx, -unsigned long entries) +static int send_dirty_pages (struct xc_sr_context *ctx, +unsigned long entries) {xc_interface *xch = ctx->xch;xen_pfn_t p;
@@ -516,7 +516,7 @@ static int send_domain_memory_live(struct xc_sr_context *ctx)if ( rc ) goto out; - rc =send_some_pages (ctx, stats.dirty_count); + rc =send_dirty_pages (ctx, stats.dirty_count);if ( rc ) goto out; }
@@ -541,7 +541,7 @@ static int send_domain_memory_live(struct xc_sr_context *ctx)bitmap_or (dirty_bitmap, ctx->save.deferred_pages, ctx->save.p2m_size); - rc =send_some_pages (ctx, stats.dirty_count + ctx->save.nr_deferred_pages); + rc =send_dirty_pages (ctx, stats.dirty_count + ctx->save.nr_deferred_pages);if ( rc ) goto out;
Signature · 1 line
1.9.1
Re: [PATCH v6 11/16] libxc/save: rename send_some_pages to send_dirty_pages
Quoted 7 lines · Yang Hongyang
rename
send_some_pagestosend_dirty_pages, no functional change.Signed-off-by Yang Hongyang <[email protected]>CC Ian Campbell <[email protected]>CC Ian Jackson <[email protected]>CC Wei Liu <[email protected]>CC Andrew Cooper <[email protected]>
Quoted 37 lines
--- tools/libxc/xc_sr_save.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)tools/libxc/xc_sr_save.c +4
-4@@ -379,8 +379,8 @@ static int send_all_pages(struct xc_sr_context *ctx)* * Bitmap is bounded by p2m_size. */ -static int send_some_pages (struct xc_sr_context *ctx, -unsigned long entries) +static int send_dirty_pages (struct xc_sr_context *ctx, +unsigned long entries) {xc_interface *xch = ctx->xch;xen_pfn_t p;@@ -516,7 +516,7 @@ static int send_domain_memory_live(struct xc_sr_context *ctx)if ( rc ) goto out; - rc =send_some_pages (ctx, stats.dirty_count); + rc =send_dirty_pages (ctx, stats.dirty_count);if ( rc ) goto out; }@@ -541,7 +541,7 @@ static int send_domain_memory_live(struct xc_sr_context *ctx)bitmap_or (dirty_bitmap, ctx->save.deferred_pages, ctx->save.p2m_size); - rc =send_some_pages (ctx, stats.dirty_count + ctx->save.nr_deferred_pages); + rc =send_dirty_pages (ctx, stats.dirty_count + ctx->save.nr_deferred_pages);if ( rc ) goto out;
Ian Campbell
Acked-byRe: [PATCH v6 11/16] libxc/save: rename send_some_pages to send_dirty_pages
Quoted 10 lines · Andrew Cooper
Quoted 7 lines · Yang Hongyang
rename
send_some_pagestosend_dirty_pages, no functional change.Signed-off-by Yang Hongyang <[email protected]>CC Ian Campbell <[email protected]>CC Ian Jackson <[email protected]>CC Wei Liu <[email protected]>CC Andrew Cooper <[email protected]>Reviewed-by Andrew Cooper <[email protected]>
PATCH v6 12/16 libxc/save: reuse send_dirty_pages() in send_all_pages()
In reply to Yang Hongyangintroduce bitmap_set() to set the entire bitmap.
in send_all_pages(), set the entire bitmap and call send_dirty_pages().
--- tools/libxc/xc_bitops.h | 5 +++++ tools/libxc/xc_sr_save.c | 44 ++++++++++++++------------------------------ 2 files changed, 19 insertions(+), 30 deletions(-)
tools/libxc/xc_bitops.h +5 -0
@@ -26,6 +26,11 @@ static inline unsigned long *bitmap_alloc(int nr_bits)return calloc (1 ,bitmap_size (nr_bits)); } +static inline void bitmap_set (unsigned long *addr,int nr_bits) +{ +memset (addr,0xff ,bitmap_size (nr_bits)); +} +static inline void bitmap_clear (unsigned long *addr,int nr_bits) {memset (addr,0 ,bitmap_size (nr_bits));
tools/libxc/xc_sr_save.c +14 -30
56 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [PATCH v6 12/16] libxc/save: reuse send_dirty_pages() in send_all_pages()
Quoted 4 lines · Yang Hongyang
introduce
bitmap_set()to set the entire bitmap.
insend_all_pages(), set the entire bitmap and callsend_dirty_pages().Signed-off-by Yang Hongyang <[email protected]>
PATCH v6 13/16 libxc/restore: introduce process_record()
In reply to Yang HongyangMove record handle codes into a function process_record(). It will be used multiple times by Remus.
No functional change.
--- tools/libxc/xc_sr_restore.c | 77 +++++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 34 deletions(-)
tools/libxc/xc_sr_restore.c +43 -34
@@ -468,6 +468,48 @@ static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec)return rc; } +static int process_record (struct xc_sr_context *ctx,struct xc_sr_record *rec) +{ +xc_interface *xch = ctx->xch; +int rc =0 ; + +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 ("Mandatory record %#x (%s) not handled" , + rec->type,rec_type_to_str (rec->type)); + rc =-1 ; + } + } + +return rc; +} +/* * Restore a domain. */
@@ -498,40 +540,7 @@ static int restore(struct xc_sr_context *ctx)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 ("Mandatory record %#x (%s) not handled" , - rec.type,rec_type_to_str (rec.type)); - rc =-1 ; - } - } - + rc =process_record (ctx, &rec);if ( rc ) goto err;
Signature · 1 line
1.9.1
Re: [PATCH v6 13/16] libxc/restore: introduce process_record()
Quoted 5 lines · Yang Hongyang
Move record handle codes into a function
process_record(). It will be used multiple times by Remus.
No functional change.Signed-off-by Yang Hongyang <[email protected]>
PATCH v6 14/16 libxc/restore: split read/handle qemu info
In reply to Yang HongyangSplit read/handle qemu info. The receiving of qemu info should be done while we receive the migration stream, handle_qemu will be called when the stream complete. Otherwise, it will break Remus because read_record() won't read qemu info and stream_complete will be called at failover.
--- tools/libxc/xc_sr_common.h | 5 +++++ tools/libxc/xc_sr_restore.c | 12 ++++++++++++ tools/libxc/xc_sr_restore_x86_hvm.c | 28 +++++++++++++++++++++++++--- 3 files changed, 42 insertions(+), 3 deletions(-)
tools/libxc/xc_sr_common.h +5 -0
@@ -288,6 +288,11 @@ struct xc_sr_context/* HVM context blob. */ void *context;size_t contextsz; + +#ifdef XG_LIBXL_HVM_COMPAT +uint32_t qlen; +void *qbuf; +#endif } restore; }; } x86_hvm;
tools/libxc/xc_sr_restore.c +12 -0
@@ -510,6 +510,9 @@ static int process_record(struct xc_sr_context *ctx, struct xc_sr_record *rec)return rc; } +#ifdef XG_LIBXL_HVM_COMPAT +extern int read_qemu (struct xc_sr_context *ctx); +#endif /* * Restore a domain. */
@@ -546,6 +549,15 @@ static int restore(struct xc_sr_context *ctx) }while ( rec.type !=REC_TYPE_END ); +#ifdef XG_LIBXL_HVM_COMPAT +if ( ctx->dominfo.hvm ) + { + rc =read_qemu (ctx); +if ( rc ) + goto err; + } +#endif + rc = ctx->restore.ops.stream_complete (ctx);if ( rc ) goto err;
tools/libxc/xc_sr_restore_x86_hvm.c +25 -3
@@ -94,14 +94,14 @@ static int handle_hvm_params(struct xc_sr_context *ctx, }#ifdef XG_LIBXL_HVM_COMPAT -static int handle_qemu (struct xc_sr_context *ctx) +int read_qemu (struct xc_sr_context *ctx); +int read_qemu (struct xc_sr_context *ctx) {xc_interface *xch = ctx->xch; -char qemusig[21 ], path[256 ]; +char qemusig[21 ];uint32_t qlen;void *qbuf =NULL ;int rc =-1 ; -FILE *fp =NULL ;if (read_exact (ctx->fd, qemusig,sizeof (qemusig)) ) {
@@ -137,6 +137,28 @@ static int handle_qemu(struct xc_sr_context *ctx) goto out; } +/* With Remus, this could be read many times */ +if ( ctx->x86_hvm.restore.qbuf ) +free (ctx->x86_hvm.restore.qbuf); + ctx->x86_hvm.restore.qbuf = qbuf; + ctx->x86_hvm.restore.qlen = qlen; + rc =0 ; + +out: +if (rc) +free (qbuf); +return rc; +} + +static int handle_qemu (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; +char path[256 ]; +uint32_t qlen = ctx->x86_hvm.restore.qlen; +void *qbuf = ctx->x86_hvm.restore.qbuf; +int rc =-1 ; +FILE *fp =NULL ; +sprintf (path,XC_DEVICE_MODEL_RESTORE_FILE ".%u" , ctx->domid); fp =fopen (path,"wb" );if ( !fp )
Signature · 1 line
1.9.1
Re: [PATCH v6 14/16] libxc/restore: split read/handle qemu info
Quoted 7 lines · Yang Hongyang
Split read/handle qemu info. The receiving of qemu info should be done while we receive the migration stream,
handle_qemuwill be called when the stream complete. Otherwise, it will break Remus becauseread_record()won't read qemu info andstream_completewill be called at failover.
Quoted 5 lines
Signed-off-by Yang Hongyang <[email protected]>CC Ian Campbell <[email protected]>CC Ian Jackson <[email protected]>CC Wei Liu <[email protected]>CC Andrew Cooper <[email protected]>
Andy seemed happy with this in v4, so:
PATCH v6 15/16 libxc/restore: introduce setup() and cleanup() on restore
In reply to Yang Hongyangintroduce setup() and cleanup() which subsume the ctx->restore.ops.{setup,cleanup}() calls and also do memory alloc/free.
--- tools/libxc/xc_sr_restore.c | 48 ++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 14 deletions(-)
tools/libxc/xc_sr_restore.c +34 -14
@@ -510,6 +510,38 @@ static int process_record(struct xc_sr_context *ctx, struct xc_sr_record *rec)return rc; } +static int setup (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; +int rc; + + 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" ); + rc =-1 ; + goto err; + } + + err: +return rc; +} + +static void cleanup (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; + +free (ctx->restore.populated_pfns); +if ( ctx->restore.ops.cleanup (ctx) ) +PERROR ("Failed to clean up" ); +} +#ifdef XG_LIBXL_HVM_COMPAT extern int read_qemu (struct xc_sr_context *ctx);#endif
@@ -524,19 +556,10 @@ static int restore(struct xc_sr_context *ctx)IPRINTF ("Restoring domain" ); - rc = ctx->restore.ops.setup (ctx); + rc =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);
@@ -571,10 +594,7 @@ static int restore(struct xc_sr_context *ctx)PERROR ("Restore failed" ); done: -free (ctx->restore.populated_pfns); - rc = ctx->restore.ops.cleanup (ctx); -if ( rc ) -PERROR ("Failed to clean up" ); +cleanup (ctx);if ( saved_rc ) {
Signature · 1 line
1.9.1
Re: [PATCH v6 15/16] libxc/restore: introduce setup() and cleanup() on restore
Quoted 9 lines · Yang Hongyang
introduce
setup()andcleanup()which subsume the ctx->restore.ops.{setup,cleanup}() calls and also do memory alloc/free.Signed-off-by Yang Hongyang <[email protected]>CC Andrew Cooper <[email protected]>CC Ian Campbell <[email protected]>CC Ian Jackson <[email protected]>CC Wei Liu <[email protected]>
Quoted 80 lines
--- tools/libxc/xc_sr_restore.c | 48 ++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 14 deletions(-)tools/libxc/xc_sr_restore.c +34
-14@@ -510,6 +510,38 @@ static int process_record(struct xc_sr_context *ctx, struct xc_sr_record *rec)return rc; } +static int setup (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; +int rc; + + 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" ); + rc =-1 ; + goto err; + } + + err: +return rc; +} + +static void cleanup (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; + +free (ctx->restore.populated_pfns); +if ( ctx->restore.ops.cleanup (ctx) ) +PERROR ("Failed to clean up" ); +} +#ifdef XG_LIBXL_HVM_COMPAT extern int read_qemu (struct xc_sr_context *ctx);#endif @@ -524,19 +556,10 @@ static int restore(struct xc_sr_context *ctx)IPRINTF ("Restoring domain" ); - rc = ctx->restore.ops.setup (ctx); + rc =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);@@ -571,10 +594,7 @@ static int restore(struct xc_sr_context *ctx)PERROR ("Restore failed" ); done: -free (ctx->restore.populated_pfns); - rc = ctx->restore.ops.cleanup (ctx); -if ( rc ) -PERROR ("Failed to clean up" ); +cleanup (ctx);if ( saved_rc ) {
Ian Campbell
Acked-byRe: [PATCH v6 15/16] libxc/restore: introduce setup() and cleanup() on restore
Quoted 7 lines · Andrew Cooper
Quoted 6 lines · Yang Hongyang
introduce
setup()andcleanup()which subsume the
ctx->restore.ops.{setup,cleanup}() calls and also
do memory alloc/free.Signed-off-by Yang Hongyang <[email protected]>CC Andrew Cooper <[email protected]>
PATCH v6 16/16 libxc/restore: add checkpointed flag to the restore context
In reply to Yang Hongyangadd checkpointed flag to the restore context.
--- tools/libxc/xc_sr_common.h | 3 +++ tools/libxc/xc_sr_restore.c | 1 + 2 files changed, 4 insertions(+)
tools/libxc/xc_sr_common.h +3 -0
@@ -205,6 +205,9 @@ struct xc_sr_contextuint32_t guest_type;uint32_t guest_page_size; +/* Plain VM, or checkpoints over time. */ +bool checkpointed; +/* * Xenstore and Console parameters. * INPUT: evtchn & domid
tools/libxc/xc_sr_restore.c +1 -0
@@ -624,6 +624,7 @@ int xc_domain_restore2(xc_interface *xch, int io_fd, uint32_t dom, ctx.restore.console_domid = console_domid; ctx.restore.xenstore_evtchn = store_evtchn; ctx.restore.xenstore_domid = store_domid; + ctx.restore.checkpointed = checkpointed_stream; ctx.restore.callbacks = callbacks;IPRINTF ("In experimental %s" , __func__);
Signature · 1 line
1.9.1
Re: [PATCH v6 16/16] libxc/restore: add checkpointed flag to the restore context
Quoted 3 lines · Yang Hongyang
add checkpointed flag to the restore context.
Signed-off-by Yang Hongyang <[email protected]>
Ian Campbell
AppliedQuoted 2 lines · Yang Hongyang
This is the combination of Andrew Cooper's misc patches and mine to aid migration v2 Remus support.
Applied, thanks. I made a few changes to some commit logs, I hope that's ok.
Quoted 7 lines · Ian Campbell
Quoted 2 lines · Yang Hongyang
This is the combination of Andrew Cooper's misc patches and mine to aid migration v2 Remus support.
Applied, thanks. I made a few changes to some commit logs, I hope that's ok.
That's great! Thank you!
Quoted 4 lines
.
Signature · 2 lines
Thanks, Yang.