Remus support for Migration-v2
v3 cover Remus support for Migration-v2
This patchset implement the Remus support for Migration v2 but without memory compressing.
Git tree available at:
https://github.com/macrosheep/xen/tree/Remus-newmig-v3
This patchset is based on
[PATCH v5 00/14] Misc patches to aid migration v2 Remus support
https://github.com/macrosheep/xen/tree/misc-remus-v5
Yang Hongyang (3):
libxc/save: implement Remus checkpointed save libxc/restore: add checkpointed flag to the restore context libxc/restore: implement Remus checkpointed restore
tools/libxc/xc_sr_common.h | 16 ++++++ tools/libxc/xc_sr_restore.c | 125 +++++++++++++++++++++++++++++++++++++++----- tools/libxc/xc_sr_save.c | 73 +++++++++++++++++++------- 3 files changed, 183 insertions(+), 31 deletions(-)
Signature · 1 line
1.9.1
PATCH v3 1/3 libxc/save: implement Remus checkpointed save
With Remus, the save flow should be:
live migration->{ periodically save(checkpointed save) }
--- tools/libxc/xc_sr_save.c | 73 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 19 deletions(-)
tools/libxc/xc_sr_save.c +54 -19
@@ -57,6 +57,16 @@ static int write_end_record(struct xc_sr_context *ctx) }/* +* Writes an CHECKPOINT record into the stream. +*/ +static int write_checkpoint_record (struct xc_sr_context *ctx) +{ +struct xc_sr_record checkpoint = {REC_TYPE_CHECKPOINT ,0 ,NULL }; + +return write_record (ctx, &checkpoint); +} + +/* * Writes a batch of memory as a PAGE_DATA record into the stream. The batch * is constructed in ctx->save.batch_pfns. *
@@ -467,6 +477,9 @@ static int send_domain_memory_live(struct xc_sr_context *ctx) DECLARE_HYPERCALL_BUFFER_SHADOW(unsigned long, dirty_bitmap, &ctx->save.dirty_bitmap_hbuf); +if ( !ctx->save.live ) + goto last_iter; + rc =enable_logdirty (ctx);if ( rc ) goto out;
@@ -505,6 +518,7 @@ static int send_domain_memory_live(struct xc_sr_context *ctx) goto out; } + last_iter: rc =suspend_domain (ctx);if ( rc ) goto out;
@@ -667,29 +681,50 @@ 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; +do { + rc = ctx->save.ops.start_of_checkpoint (ctx); +if ( rc ) + goto err; -if ( ctx->save.live ) - rc =send_domain_memory_live (ctx); -else - rc =send_domain_memory_nonlive (ctx); +if ( ctx->save.live || ctx->save.checkpointed ) + rc =send_domain_memory_live (ctx); +else + rc =send_domain_memory_nonlive (ctx); -if ( rc ) - goto err; +if ( rc ) + goto err; -if ( !ctx->dominfo.shutdown || - (ctx->dominfo.shutdown_reason != SHUTDOWN_suspend) ) - { -ERROR ("Domain has not been suspended" ); - rc =-1 ; - goto err; - } +if ( !ctx->dominfo.shutdown || + (ctx->dominfo.shutdown_reason != SHUTDOWN_suspend) ) + { +ERROR ("Domain has not been suspended" ); + rc =-1 ; + goto err; + } - rc = ctx->save.ops.end_of_checkpoint (ctx); -if ( rc ) - goto err; + rc = ctx->save.ops.end_of_checkpoint (ctx); +if ( rc ) + goto err; + +if ( ctx->save.checkpointed ) { +if ( ctx->save.live ) { +/* End of live migration, we are sending checkpointed stream */ + ctx->save.live = false; + } + + rc =write_checkpoint_record (ctx); +if ( rc ) + goto err; + + ctx->save.callbacks->postcopy (ctx->save.callbacks->data); + + rc = ctx->save.callbacks->checkpoint (ctx->save.callbacks->data); +if ( rc >0 ) +IPRINTF ("Checkpointed save" ); +else + ctx->save.checkpointed = false; + } + }while ( ctx->save.checkpointed );xc_report_progress_single (xch,"End of stream" );
Signature · 1 line
1.9.1
Re: [PATCH Remus v3 1/3] libxc/save: implement Remus checkpointed save
Quoted 34 lines · Yang Hongyang
With Remus, the save flow should be:
live migration->{ periodically save(checkpointed save) }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]>--- tools/libxc/xc_sr_save.c | 73 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 19 deletions(-)tools/libxc/xc_sr_save.c +10
-0@@ -57,6 +57,16 @@ static int write_end_record(struct xc_sr_context *ctx) }/* +* Writes an CHECKPOINT record into the stream. +*/ +static int write_checkpoint_record (struct xc_sr_context *ctx) +{ +struct xc_sr_record checkpoint = {REC_TYPE_CHECKPOINT ,0 ,NULL }; + +return write_record (ctx, &checkpoint); +} + +/* * Writes a batch of memory as a PAGE_DATA record into the stream. The batch * is constructed in ctx->save.batch_pfns. *
tools/libxc/xc_sr_save.c static int send_domain_memory_live(struct xc_sr_context *ctx) · line 482
Quoted 6 lines
tools/libxc/xc_sr_save.c +3
-0@@ -467,6 +477,9 @@ static int send_domain_memory_live(struct xc_sr_context *ctx) DECLARE_HYPERCALL_BUFFER_SHADOW(unsigned long, dirty_bitmap, &ctx->save.dirty_bitmap_hbuf); +if ( !ctx->save.live ) + goto last_iter; +
I really want to avoid this code getting into the same spiders web as it used to be with goto, but I cannot suggest a better alternative.
However, please leave a comment explaining that subsequent checkpointed loop skip the live part and pause straight away.
Quoted 51 lines
tools/libxc/xc_sr_save.c +18
-16rc =enable_logdirty (ctx);if ( rc ) goto out;@@ -505,6 +518,7 @@ static int send_domain_memory_live(struct xc_sr_context *ctx) goto out; } + last_iter: rc =suspend_domain (ctx);if ( rc ) goto out;@@ -667,29 +681,50 @@ 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; + do { + rc = ctx->save.ops.start_of_checkpoint(ctx); + if ( rc ) + goto err; -if ( ctx->save.live ) - rc =send_domain_memory_live (ctx); -else - rc =send_domain_memory_nonlive (ctx); + if ( ctx->save.live || ctx->save.checkpointed ) + rc = send_domain_memory_live(ctx); + else + rc = send_domain_memory_nonlive(ctx); -if ( rc ) - goto err; + if ( rc ) + goto err; -if ( !ctx->dominfo.shutdown || - (ctx->dominfo.shutdown_reason != SHUTDOWN_suspend) ) - { -ERROR ("Domain has not been suspended" ); - rc =-1 ; - goto err; - } + if ( !ctx->dominfo.shutdown || + (ctx->dominfo.shutdown_reason != SHUTDOWN_suspend) ) + { + ERROR("Domain has not been suspended"); + rc = -1; + goto err; + }
tools/libxc/xc_sr_save.c static int save(struct xc_sr_context *ctx, uint16_t guest_type) · line 710
Quoted 10 lines
tools/libxc/xc_sr_save.c +6
-3- rc = ctx->save.ops.end_of_checkpoint (ctx); -if ( rc ) - goto err; + rc = ctx->save.ops.end_of_checkpoint (ctx); +if ( rc ) + goto err; + +if ( ctx->save.checkpointed ) { +if ( ctx->save.live ) {
Coding style. libxc is admittedly inconsistent, but follows hypervisor style, so { on the next line.
tools/libxc/xc_sr_save.c static int save(struct xc_sr_context *ctx, uint16_t guest_type) · line 723
Quoted 13 lines
tools/libxc/xc_sr_save.c +13
-0+/* End of live migration, we are sending checkpointed stream */ + ctx->save.live = false; + } + + rc =write_checkpoint_record (ctx); +if ( rc ) + goto err; + + ctx->save.callbacks->postcopy (ctx->save.callbacks->data); + + rc = ctx->save.callbacks->checkpoint (ctx->save.callbacks->data); +if ( rc >0 ) +IPRINTF ("Checkpointed save" );
This should probably be progress information , soxc_report_progress_single()
Otherwise, Reviewed-by: Andrew Cooper <[email protected]>
(I think this code is a bit of an improvement over xc_domain_save.c)
Quoted 7 lines
tools/libxc/xc_sr_save.c +4
-0+else + ctx->save.checkpointed = false; + } + }while ( ctx->save.checkpointed );xc_report_progress_single (xch,"End of stream" );
Re: [PATCH Remus v3 1/3] libxc/save: implement Remus checkpointed save
Quoted 45 lines · Andrew Cooper
Quoted 34 lines · Yang Hongyang
With Remus, the save flow should be:
live migration->{ periodically save(checkpointed save) }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]>--- tools/libxc/xc_sr_save.c | 73 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 19 deletions(-)tools/libxc/xc_sr_save.c +10
-0@@ -57,6 +57,16 @@ static int write_end_record(struct xc_sr_context *ctx) }/* +* Writes an CHECKPOINT record into the stream. +*/ +static int write_checkpoint_record (struct xc_sr_context *ctx) +{ +struct xc_sr_record checkpoint = {REC_TYPE_CHECKPOINT ,0 ,NULL }; + +return write_record (ctx, &checkpoint); +} + +/* * Writes a batch of memory as a PAGE_DATA record into the stream. The batch * is constructed in ctx->save.batch_pfns. * tools/libxc/xc_sr_save.c static int send_domain_memory_live(struct xc_sr_context *ctx) · line 482
Quoted 6 lines
tools/libxc/xc_sr_save.c +3
-0@@ -467,6 +477,9 @@ static int send_domain_memory_live(struct xc_sr_context *ctx) DECLARE_HYPERCALL_BUFFER_SHADOW(unsigned long, dirty_bitmap, &ctx->save.dirty_bitmap_hbuf); +if ( !ctx->save.live ) + goto last_iter; +I really want to avoid this code getting into the same spiders web as it used to be with goto, but I cannot suggest a better alternative.
Quoted 2 lines
However, please leave a comment explaining that subsequent checkpointed loop skip the live part and pause straight away.
OK
Quoted 53 lines
Quoted 53 lines
tools/libxc/xc_sr_save.c +18
-16rc =enable_logdirty (ctx);if ( rc ) goto out;@@ -505,6 +518,7 @@ static int send_domain_memory_live(struct xc_sr_context *ctx) goto out; } + last_iter: rc =suspend_domain (ctx);if ( rc ) goto out;@@ -667,29 +681,50 @@ 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; + do { + rc = ctx->save.ops.start_of_checkpoint(ctx); + if ( rc ) + goto err; -if ( ctx->save.live ) - rc =send_domain_memory_live (ctx); -else - rc =send_domain_memory_nonlive (ctx); + if ( ctx->save.live || ctx->save.checkpointed ) + rc = send_domain_memory_live(ctx); + else + rc = send_domain_memory_nonlive(ctx); -if ( rc ) - goto err; + if ( rc ) + goto err; -if ( !ctx->dominfo.shutdown || - (ctx->dominfo.shutdown_reason != SHUTDOWN_suspend) ) - { -ERROR ("Domain has not been suspended" ); - rc =-1 ; - goto err; - } + if ( !ctx->dominfo.shutdown || + (ctx->dominfo.shutdown_reason != SHUTDOWN_suspend) ) + { + ERROR("Domain has not been suspended"); + rc = -1; + goto err; + }
Quoted 12 lines
tools/libxc/xc_sr_save.c static int save(struct xc_sr_context *ctx, uint16_t guest_type) · line 710
Quoted 9 lines
tools/libxc/xc_sr_save.c +6
-3- rc = ctx->save.ops.end_of_checkpoint (ctx); -if ( rc ) - goto err; + rc = ctx->save.ops.end_of_checkpoint (ctx); +if ( rc ) + goto err; + +if ( ctx->save.checkpointed ) { +if ( ctx->save.live ) {Coding style. libxc is admittedly inconsistent, but follows hypervisor style, so { on the next line.
OK
Quoted 17 lines
Quoted 4 lines
tools/libxc/xc_sr_save.c +3
-0+/* End of live migration, we are sending checkpointed stream */ + ctx->save.live = false; + }tools/libxc/xc_sr_save.c static int save(struct xc_sr_context *ctx, uint16_t guest_type) · line 723
Quoted 10 lines
tools/libxc/xc_sr_save.c +10
-0+ + rc =write_checkpoint_record (ctx); +if ( rc ) + goto err; + + ctx->save.callbacks->postcopy (ctx->save.callbacks->data); + + rc = ctx->save.callbacks->checkpoint (ctx->save.callbacks->data); +if ( rc >0 ) +IPRINTF ("Checkpointed save" );This should probably be progress information , so
xc_report_progress_single()
Will fix.
Quoted 15 lines
Otherwise, Reviewed-by: Andrew Cooper <[email protected]>
(I think this code is a bit of an improvement over
xc_domain_save.c)tools/libxc/xc_sr_save.c static int save(struct xc_sr_context *ctx, uint16_t guest_type) · line 730
Quoted 7 lines
tools/libxc/xc_sr_save.c +4
-0+else + ctx->save.checkpointed = false; + } + }while ( ctx->save.checkpointed );xc_report_progress_single (xch,"End of stream" );.
Signature · 2 lines
Thanks, Yang.
PATCH v3 2/3 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
@@ -604,6 +604,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 Remus v3 2/3] libxc/restore: add checkpointed flag to the restore context
Quoted 7 lines · Yang Hongyang
add checkpointed flag to the restore context.
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]>
This appears unused, given the new restore code.
~Andrew
Quoted 31 lines
--- 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@@ -604,6 +604,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__);
Re: [PATCH Remus v3 2/3] libxc/restore: add checkpointed flag to the restore context
Quoted 10 lines · Andrew Cooper
Quoted 7 lines · Yang Hongyang
add checkpointed flag to the restore context.
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]>This appears unused, given the new restore code.
This is used by handle_checkpoint() for the sanity check.
Quoted 37 lines
~Andrew
Quoted 24 lines
--- 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 +0
-0tools/libxc/xc_sr_restore.c int xc_domain_restore2(xc_interface *xch, int io_fd, uint32_t dom, · line 610
Quoted 7 lines
tools/libxc/xc_sr_restore.c +1
-0@@ -604,6 +604,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 · 2 lines
Thanks, Yang.
Re: [PATCH Remus v3 2/3] libxc/restore: add checkpointed flag to the restore context
Quoted 12 lines · Yang Hongyang
Quoted 9 lines · Andrew Cooper
Quoted 7 lines · Yang Hongyang
add checkpointed flag to the restore context.
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 3 lines
Quoted 1 line
This appears unused, given the new restore code.
This is used by
handle_checkpoint()for the sanity check.
Ah yes, and I have realised that it will need to be used when I fix up the qemu record handling in the future, so Reviewed-by: Andrew Cooper <[email protected]>
Quoted 40 lines
Quoted 39 lines
~Andrew
Quoted 31 lines
--- 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@@ -604,6 +604,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;Quoted 1 line
IPRINTF("In experimental %s", __func__);.
PATCH v3 3/3 libxc/restore: implement Remus checkpointed restore
In reply to Yang HongyangWith Remus, the restore flow should be:
the first full migration stream -> { periodically restore stream }
--- tools/libxc/xc_sr_common.h | 13 +++++ tools/libxc/xc_sr_restore.c | 124 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 125 insertions(+), 12 deletions(-)
tools/libxc/xc_sr_common.h +13 -0
@@ -208,6 +208,19 @@ struct xc_sr_context/* Plain VM, or checkpoints over time. */ bool checkpointed; +/* Currently buffering records between a checkpoint */ +bool buffer_all_records; + +/* +* With Remus, we buffer the records sent by primary at checkpoint, +* in case the primary will fail, we can recover from the last +* checkpoint state. +* This should be enough because primary only send dirty pages at +* checkpoint. +*/ +#define MAX_BUF_RECORDS 1024 +struct xc_sr_record *buffered_records[MAX_BUF_RECORDS ]; +/* * Xenstore and Console parameters. * INPUT: evtchn & domid
tools/libxc/xc_sr_restore.c +112 -12
163 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [PATCH Remus v3 3/3] libxc/restore: implement Remus checkpointed restore
Quoted 18 lines · Yang Hongyang
With Remus, the restore flow should be:
the first full migration stream -> { periodically restore stream }Signed-off-by Yang Hongyang <[email protected]>Signed-off-by Andrew Cooper <[email protected]>CC Ian Campbell <[email protected]>CC Ian Jackson <[email protected]>CC Wei Liu <[email protected]>--- tools/libxc/xc_sr_common.h | 13 +++++ tools/libxc/xc_sr_restore.c | 124 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 125 insertions(+), 12 deletions(-)tools/libxc/xc_sr_common.h +0
-0
tools/libxc/xc_sr_common.h struct xc_sr_context · line 215
Quoted 8 lines
tools/libxc/xc_sr_common.h +5
-0@@ -208,6 +208,19 @@ struct xc_sr_context/* Plain VM, or checkpoints over time. */ bool checkpointed; +/* Currently buffering records between a checkpoint */ +bool buffer_all_records; + +/* +* With Remus, we buffer the records sent by primary at checkpoint,
"sent by the primary"
tools/libxc/xc_sr_common.h struct xc_sr_context · line 221
Quoted 6 lines
tools/libxc/xc_sr_common.h +6
-0+* in case the primary will fail, we can recover from the last +* checkpoint state. +* This should be enough because primary only send dirty pages at +* checkpoint. +*/ +#define MAX_BUF_RECORDS 1024
As a general point, it occurs to me that this might be better as a linked list, rather than having a hard limit. A burst of activity on the primary could potentially hit this limit
tools/libxc/xc_sr_common.h struct xc_sr_context · line 222
Quoted 1 line
tools/libxc/xc_sr_common.h +1
-0+struct xc_sr_record *buffered_records[MAX_BUF_RECORDS ];
Your data handling will be much more simple if this were struct xc_sr_record *buffered_records; and you do a one-time allocation of MAX_BUF_RECORDS * sizeof(struct xc_sr_record), although it will require an index integer as well.
It would probably be best to factor out setup() and clean() just like you did for the save side.
Quoted 9 lines
tools/libxc/xc_sr_common.h +1
-0+/* * Xenstore and Console parameters. * INPUT: evtchn & domid tools/libxc/xc_sr_restore.c +0
-0
tools/libxc/xc_sr_restore.c static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec) · line 475
Quoted 8 lines
tools/libxc/xc_sr_restore.c +5
-0@@ -468,10 +468,83 @@ 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); +static int handle_checkpoint (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; +int rc =0 , i;
Always an unsigned i for populated_pfnsindexing an array please.
Quoted 13 lines
tools/libxc/xc_sr_restore.c +13
-0+struct xc_sr_record *rec; + +if ( !ctx->restore.checkpointed ) + { +ERROR ("Found checkpoint in non-checkpointed stream" ); + rc =-1 ; + goto err; + } + +if ( ctx->restore.buffer_all_records ) + { +IPRINTF ("All records buffered" ); +
tools/libxc/xc_sr_restore.c static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec) · line 498
Quoted 10 lines
tools/libxc/xc_sr_restore.c +10
-0+/* +* We need to set buffer_all_records to false in +* order to process records instead of buffer records. +* buffer_all_records should be set back to true after +* we successfully processed all records. +*/ + ctx->restore.buffer_all_records = false; + i =0 ; + rec = ctx->restore.buffered_records[i++]; +while (rec)
Style (hypervisor style).
Quoted 74 lines
tools/libxc/xc_sr_restore.c +51
-2+ { + rc =process_record (ctx, rec); +free (rec); + ctx->restore.buffered_records[i-1 ] =NULL ; +if ( rc ) + goto err; + + rec = ctx->restore.buffered_records[i++]; + } +IPRINTF ("All records processed" ); + ctx->restore.buffer_all_records = true; + } +else + ctx->restore.buffer_all_records = true; + + err: +return rc; +} +static int process_record (struct xc_sr_context *ctx,struct xc_sr_record *rec) {xc_interface *xch = ctx->xch; -int rc =0 ; +int rc =0 , i; +struct xc_sr_record *buf_rec; + +if ( ctx->restore.buffer_all_records && + rec->type !=REC_TYPE_END && + rec->type !=REC_TYPE_CHECKPOINT ) + { + buf_rec =malloc (sizeof (struct xc_sr_record )); +if (!buf_rec) + { +ERROR ("Unable to allocate memory for record" ); +return -1 ; + } +memcpy (buf_rec, rec,sizeof (struct xc_sr_record )); + +for ( i =0 ; i <MAX_BUF_RECORDS ; i++ ) +if ( !ctx->restore.buffered_records[i] ) +break ; + +if ( i >=MAX_BUF_RECORDS ) + { +ERROR ("There are too many records within a checkpoint" ); +return -1 ; + } + ctx->restore.buffered_records[i] = buf_rec; +return 0 ; + }switch ( rec->type ) {@@ -487,6 +560,10 @@ static int process_record(struct xc_sr_context *ctx, struct xc_sr_record *rec) ctx->restore.verify = true;break ; +case REC_TYPE_CHECKPOINT : + rc =handle_checkpoint (ctx); +break ; +default : rc = ctx->restore.ops.process_record (ctx, rec);break ;@@ -520,7 +597,7 @@ static int restore(struct xc_sr_context *ctx) {xc_interface *xch = ctx->xch;struct xc_sr_record rec; -int rc, saved_rc =0 , saved_errno =0 ; +int rc, saved_rc =0 , saved_errno =0 , i;IPRINTF ("Restoring domain" );
tools/libxc/xc_sr_restore.c static int restore(struct xc_sr_context *ctx) · line 623
Quoted 7 lines
tools/libxc/xc_sr_restore.c +3
-1@@ -541,7 +618,27 @@ static int restore(struct xc_sr_context *ctx) { rc =read_record (ctx, &rec);if ( rc ) - goto err; + { +if ( ctx->restore.buffer_all_records ) + goto err_buf;
Please can we choose a label sufficiently different to "err".
"resume_from_checkpoint" perhaps?
~Andrew
Quoted 56 lines
tools/libxc/xc_sr_restore.c +30
-9+else + goto err; + } + +#ifdef XG_LIBXL_HVM_COMPAT +if ( ctx->dominfo.hvm && + (rec.type ==REC_TYPE_END || rec.type ==REC_TYPE_CHECKPOINT ) ) + { + rc =read_qemu (ctx); +if ( rc ) + { +if ( ctx->restore.buffer_all_records ) + goto err_buf; +else + goto err; + } + } +#endif rc =process_record (ctx, &rec);if ( rc )@@ -549,15 +646,11 @@ 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 - + err_buf: +/* +* With Remus, if we reach here, there must be some error on primary, +* failover from the last checkpoint state. +*/ rc = ctx->restore.ops.stream_complete (ctx);if ( rc ) goto err;@@ -571,6 +664,13 @@ static int restore(struct xc_sr_context *ctx)PERROR ("Restore failed" ); done: +for ( i =0 ; i <MAX_BUF_RECORDS ; i++) + { +if ( ctx->restore.buffered_records[i] ) { +free (ctx->restore.buffered_records[i]->data); +free (ctx->restore.buffered_records[i]); + } + }free (ctx->restore.populated_pfns); rc = ctx->restore.ops.cleanup (ctx);if ( rc )
Re: [PATCH Remus v3 3/3] libxc/restore: implement Remus checkpointed restore
Quoted 13 lines · Andrew Cooper
Quoted 13 lines
tools/libxc/xc_sr_common.h +1
-0+/* * Xenstore and Console parameters. * INPUT: evtchn & domid tools/libxc/xc_sr_restore.c +0
-0@@ -468,10 +468,83 @@ static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec)return rc; }
Quoted 6 lines
tools/libxc/xc_sr_restore.c static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec) · line 475
Quoted 5 lines
tools/libxc/xc_sr_restore.c +5
-0+static int process_record (struct xc_sr_context *ctx,struct xc_sr_record *rec); +static int handle_checkpoint (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; +int rc =0 , i;Always an unsigned i for
populated_pfnsindexingan array please.
Erm - not sure what happened here. Ignore the "populated_pfns" please. Sorry.
~Andrew
Re: [PATCH Remus v3 3/3] libxc/restore: implement Remus checkpointed restore
In reply to Andrew CooperQuoted 37 lines · Andrew Cooper
Quoted 18 lines · Yang Hongyang
With Remus, the restore flow should be:
the first full migration stream -> { periodically restore stream }Signed-off-by Yang Hongyang <[email protected]>Signed-off-by Andrew Cooper <[email protected]>CC Ian Campbell <[email protected]>CC Ian Jackson <[email protected]>CC Wei Liu <[email protected]>--- tools/libxc/xc_sr_common.h | 13 +++++ tools/libxc/xc_sr_restore.c | 124 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 125 insertions(+), 12 deletions(-)tools/libxc/xc_sr_common.h +0
-0tools/libxc/xc_sr_common.h struct xc_sr_context · line 215
Quoted 8 lines
tools/libxc/xc_sr_common.h +5
-0@@ -208,6 +208,19 @@ struct xc_sr_context/* Plain VM, or checkpoints over time. */ bool checkpointed; +/* Currently buffering records between a checkpoint */ +bool buffer_all_records; + +/* +* With Remus, we buffer the records sent by primary at checkpoint, "sent by the primary"
tools/libxc/xc_sr_common.h struct xc_sr_context · line 221
Quoted 6 lines
tools/libxc/xc_sr_common.h +6
-0+* in case the primary will fail, we can recover from the last +* checkpoint state. +* This should be enough because primary only send dirty pages at +* checkpoint. +*/ +#define MAX_BUF_RECORDS 1024
Quoted 3 lines
As a general point, it occurs to me that this might be better as a linked list, rather than having a hard limit. A burst of activity on the primary could potentially hit this limit
There are only few records at every checkpoint in my test, mostly under 10, probably because I don't do much operations in the Guest. This limit can be adjusted later by further testing.
Even with linked list, we still need a limit IMO, otherwise it will eat too much memory.
Quoted 7 lines
tools/libxc/xc_sr_common.h struct xc_sr_context · line 222
Quoted 2 lines
tools/libxc/xc_sr_common.h +1
-0+struct xc_sr_record *buffered_records[MAX_BUF_RECORDS ];Your data handling will be much more simple if this were struct
xc_sr_record*buffered_records; and you do a one-time allocation ofMAX_BUF_RECORDS*sizeof(struct xc_sr_record), although it will require an index integer as well.
Good point, it will avoid the alloc/free of the struct xc_sr_record, I will add a 'buffered_rec_num' to the context also.
Quoted 3 lines
It would probably be best to factor out
setup()andclean()just like you did for the save side.
OK.
Quoted 8 lines
Quoted 8 lines
tools/libxc/xc_sr_common.h +1
-0+/* * Xenstore and Console parameters. * INPUT: evtchn & domid tools/libxc/xc_sr_restore.c +0
-1--- a/tools/libxc/xc_sr_restore.c
[...]
Quoted 11 lines
tools/libxc/xc_sr_restore.c static int restore(struct xc_sr_context *ctx) · line 623
Quoted 8 lines
tools/libxc/xc_sr_restore.c +3
-1@@ -541,7 +618,27 @@ static int restore(struct xc_sr_context *ctx) { rc =read_record (ctx, &rec);if ( rc ) - goto err; + { +if ( ctx->restore.buffer_all_records ) + goto err_buf;Please can we choose a label sufficiently different to "err".
Quoted 1 line
"
resume_from_checkpoint" perhaps?
I think "remus_failover" is better? If you don't have objections, I will use it as the label.
Quoted 62 lines
~Andrew
Quoted 46 lines
tools/libxc/xc_sr_restore.c +23
-9+else + goto err; + } + +#ifdef XG_LIBXL_HVM_COMPAT +if ( ctx->dominfo.hvm && + (rec.type ==REC_TYPE_END || rec.type ==REC_TYPE_CHECKPOINT ) ) + { + rc =read_qemu (ctx); +if ( rc ) + { +if ( ctx->restore.buffer_all_records ) + goto err_buf; +else + goto err; + } + } +#endif rc =process_record (ctx, &rec);if ( rc )@@ -549,15 +646,11 @@ 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 - + err_buf: +/* +* With Remus, if we reach here, there must be some error on primary, +* failover from the last checkpoint state. +*/ rc = ctx->restore.ops.stream_complete (ctx);if ( rc ) goto err;@@ -571,6 +664,13 @@ static int restore(struct xc_sr_context *ctx)PERROR ("Restore failed" ); done:tools/libxc/xc_sr_restore.c static int restore(struct xc_sr_context *ctx) · line 676
Quoted 10 lines
tools/libxc/xc_sr_restore.c +7
-0+for ( i =0 ; i <MAX_BUF_RECORDS ; i++) + { +if ( ctx->restore.buffered_records[i] ) { +free (ctx->restore.buffered_records[i]->data); +free (ctx->restore.buffered_records[i]); + } + }free (ctx->restore.populated_pfns); rc = ctx->restore.ops.cleanup (ctx);if ( rc ).
Signature · 2 lines
Thanks, Yang.
Re: [PATCH Remus v3 3/3] libxc/restore: implement Remus checkpointed restore
Quoted 12 lines · Yang Hongyang
Quoted 12 lines
tools/libxc/xc_sr_restore.c static int restore(struct xc_sr_context *ctx) · line 623
Quoted 9 lines
tools/libxc/xc_sr_restore.c +3
-1@@ -541,7 +618,27 @@ static int restore(struct xc_sr_context *ctx) { rc =read_record (ctx, &rec);if ( rc ) - goto err; + { +if ( ctx->restore.buffer_all_records ) + goto err_buf;Please can we choose a label sufficiently different to "err".
Quoted 4 lines
Quoted 1 line
"
resume_from_checkpoint" perhaps?I think "
remus_failover" is better? If you don't have objections, I will use it as the label.
Fine by me.
~Andrew