[v2,06/17] libxc/restore: Support v3 streams and handle STATIC_DATA_END
diff mbox series

Message ID 20200127143444.25538-7-andrew.cooper3@citrix.com
State New
Headers show
Series
  • Support CPUID/MSR data in migration streams
Related show

Commit Message

Andrew Cooper Jan. 27, 2020, 2:34 p.m. UTC
Higher level toolstacks may wish to know when the static data is complete, so
introduce a restore_callback for the purpose.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Ian Jackson <Ian.Jackson@citrix.com>
CC: Wei Liu <wl@xen.org>

v2:
 * Split/rearranged from v1
---
 tools/libxc/include/xenguest.h |  3 +++
 tools/libxc/xc_sr_common.h     |  3 +++
 tools/libxc/xc_sr_restore.c    | 29 +++++++++++++++++++++++++++--
 3 files changed, 33 insertions(+), 2 deletions(-)

Comments

Ian Jackson Feb. 24, 2020, 5:29 p.m. UTC | #1
Andrew Cooper writes ("[PATCH v2 06/17] libxc/restore: Support v3 streams and handle STATIC_DATA_END"):
> Higher level toolstacks may wish to know when the static data is complete, so
> introduce a restore_callback for the purpose.

Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>

Patch
diff mbox series

diff --git a/tools/libxc/include/xenguest.h b/tools/libxc/include/xenguest.h
index 19d828a7f2..efd90b0d42 100644
--- a/tools/libxc/include/xenguest.h
+++ b/tools/libxc/include/xenguest.h
@@ -139,6 +139,9 @@  int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom,
 
 /* callbacks provided by xc_domain_restore */
 struct restore_callbacks {
+    /* Called once the STATIC_DATA_END record has been received. */
+    int (*static_data_done)(void *data);
+
     /* Called after a new checkpoint to suspend the guest. */
     int (*suspend)(void *data);
 
diff --git a/tools/libxc/xc_sr_common.h b/tools/libxc/xc_sr_common.h
index 5dd51ccb15..ae0ab70f76 100644
--- a/tools/libxc/xc_sr_common.h
+++ b/tools/libxc/xc_sr_common.h
@@ -253,6 +253,9 @@  struct xc_sr_context
             /* Currently buffering records between a checkpoint */
             bool buffer_all_records;
 
+            /* Whether a STATIC_DATA_END record has been seen. */
+            bool seen_static_data_end;
+
 /*
  * With Remus/COLO, we buffer the records sent by the primary at checkpoint,
  * in case the primary will fail, we can recover from the last
diff --git a/tools/libxc/xc_sr_restore.c b/tools/libxc/xc_sr_restore.c
index dc2ffcf855..9c924387ae 100644
--- a/tools/libxc/xc_sr_restore.c
+++ b/tools/libxc/xc_sr_restore.c
@@ -35,9 +35,9 @@  static int read_headers(struct xc_sr_context *ctx)
         return -1;
     }
 
-    if ( ihdr.version != 2 )
+    if ( ihdr.version < 2 || ihdr.version > 3 )
     {
-        ERROR("Invalid Version: Expected 2, Got %d",
+        ERROR("Invalid Version: Expected 2 <= ver <= 3, Got %d",
               ihdr.version);
         return -1;
     }
@@ -631,6 +631,27 @@  static int buffer_record(struct xc_sr_context *ctx, struct xc_sr_record *rec)
     return 0;
 }
 
+static int handle_static_data_end(struct xc_sr_context *ctx)
+{
+    xc_interface *xch = ctx->xch;
+    int rc = 0;
+
+    if ( ctx->restore.seen_static_data_end )
+    {
+        ERROR("Multiple STATIC_DATA_END records found");
+        return -1;
+    }
+
+    ctx->restore.seen_static_data_end = true;
+
+    if ( ctx->restore.callbacks->static_data_done &&
+         (rc = ctx->restore.callbacks->static_data_done(
+             ctx->restore.callbacks->data) != 0) )
+        ERROR("static_data_done() callback failed: %d\n", rc);
+
+    return rc;
+}
+
 static int process_record(struct xc_sr_context *ctx, struct xc_sr_record *rec)
 {
     xc_interface *xch = ctx->xch;
@@ -654,6 +675,10 @@  static int process_record(struct xc_sr_context *ctx, struct xc_sr_record *rec)
         rc = handle_checkpoint(ctx);
         break;
 
+    case REC_TYPE_STATIC_DATA_END:
+        rc = handle_static_data_end(ctx);
+        break;
+
     default:
         rc = ctx->restore.ops.process_record(ctx, rec);
         break;