From: Wen Congyang <we...@cn.fujitsu.com>

Signed-off-by: Wen Congyang <we...@cn.fujitsu.com>
---
 tools/libxl/libxl_internal.h     |  4 ++
 tools/libxl/libxl_stream_write.c | 92 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 96 insertions(+)

diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 7f591ee..1ef6fc8 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -2905,6 +2905,7 @@ struct libxl__stream_write_state {
     size_t padding;
     bool running;
     bool in_checkpoint;
+    bool in_colo_context;
     libxl__datacopier_state dc;
 };
 
@@ -2913,6 +2914,9 @@ _hidden void libxl__stream_write_start(libxl__egc *egc,
 
 _hidden void libxl__stream_write_start_checkpoint(
     libxl__egc *egc, libxl__stream_write_state *stream);
+_hidden void libxl__stream_write_colo_context(
+    libxl__egc *egc, libxl__stream_write_state *stream,
+    libxl_sr_colo_context *colo_context);
 
 _hidden void libxl__stream_write_abort(libxl__egc *egc,
                                        libxl__stream_write_state *stream,
diff --git a/tools/libxl/libxl_stream_write.c b/tools/libxl/libxl_stream_write.c
index 3f981f0..a445189 100644
--- a/tools/libxl/libxl_stream_write.c
+++ b/tools/libxl/libxl_stream_write.c
@@ -107,6 +107,15 @@ static void checkpoint_end_record_done(libxl__egc *egc,
                                        libxl__datacopier_state *dc,
                                        int onwrite, int errnoval);
 
+static void write_colo_context(libxl__egc *egc,
+                               libxl__stream_write_state *stream,
+                               libxl_sr_colo_context *colo_context);
+static void write_colo_context_done(libxl__egc *egc,
+                              libxl__datacopier_state *dc,
+                              int onwrite, int errnoval);
+static void colo_context_done(libxl__egc *egc,
+                              libxl__stream_write_state *stream, int rc);
+
 void libxl__stream_write_start(libxl__egc *egc,
                                libxl__stream_write_state *stream)
 {
@@ -154,11 +163,24 @@ void libxl__stream_write_start_checkpoint(libxl__egc *egc,
     assert(stream->running);
     assert(!stream->in_checkpoint);
     assert(!stream->back_channel);
+    assert(!stream->in_colo_context);
     stream->in_checkpoint = true;
 
     write_toolstack_record(egc, stream);
 }
 
+void libxl__stream_write_colo_context(libxl__egc *egc,
+                                      libxl__stream_write_state *stream,
+                                      libxl_sr_colo_context *colo_context)
+{
+    assert(stream->running);
+    assert(!stream->in_checkpoint);
+    assert(!stream->in_colo_context);
+    stream->in_colo_context = true;
+
+    write_colo_context(egc, stream, colo_context);
+}
+
 void libxl__stream_write_abort(libxl__egc *egc,
                                libxl__stream_write_state *stream, int rc)
 {
@@ -171,6 +193,7 @@ static void stream_success(libxl__egc *egc, 
libxl__stream_write_state *stream)
     stream->running = false;
 
     assert(!stream->in_checkpoint);
+    assert(!stream->in_colo_context);
     stream_done(egc, stream);
 }
 
@@ -189,6 +212,11 @@ static void stream_failed(libxl__egc *egc,
         return;
     }
 
+    if (stream->in_colo_context) {
+        colo_context_done(egc, stream, rc);
+        return;
+    }
+
     if (stream->back_channel) {
         stream->completion_callback(egc, stream, rc);
         return;
@@ -207,6 +235,7 @@ static void stream_done(libxl__egc *egc,
 
     assert(!stream->running);
     assert(!stream->in_checkpoint);
+    assert(!stream->in_colo_context);
 
     check_stream_finished(egc, dss, stream->rc, "stream");
 }
@@ -544,6 +573,61 @@ static void emulator_padding_done(libxl__egc *egc,
     stream_failed(egc, stream, ret);
 }
 
+static void write_colo_context(libxl__egc *egc,
+                               libxl__stream_write_state *stream,
+                               libxl_sr_colo_context *colo_context)
+{
+    libxl__datacopier_state *dc = &stream->dc;
+    STATE_AO_GC(stream->ao);
+    struct libxl_sr_rec_hdr rec = { REC_TYPE_COLO_CONTEXT, 0 };
+    int ret = 0;
+    uint32_t padding_len;
+
+    dc->copywhat = "colo context record";
+    dc->writewhat = "save/migration stream";
+    dc->callback = write_colo_context_done;
+
+    ret = libxl__datacopier_start(dc);
+    if (ret)
+        goto err;
+
+    rec.length = sizeof(*colo_context);
+
+    libxl__datacopier_prefixdata(egc, dc, &rec, sizeof(rec));
+    libxl__datacopier_prefixdata(egc, dc, colo_context, rec.length);
+
+    padding_len = ROUNDUP(rec.length, REC_ALIGN_ORDER) - rec.length;
+    if (padding_len)
+        libxl__datacopier_prefixdata(egc, dc, zero_padding, padding_len);
+
+    return;
+
+ err:
+    assert(ret);
+    stream_failed(egc, stream, ret);
+}
+
+static void write_colo_context_done(libxl__egc *egc,
+                                    libxl__datacopier_state *dc,
+                                    int onwrite, int errnoval)
+{
+    libxl__stream_write_state *stream = CONTAINER_OF(dc, *stream, dc);
+    STATE_AO_GC(stream->ao);
+    int ret = 0;
+
+    if (onwrite || errnoval) {
+        ret = ERROR_FAIL;
+        goto err;
+    }
+
+    colo_context_done(egc, stream, 0);
+    return;
+
+ err:
+    assert(ret);
+    stream_failed(egc, stream, ret);
+}
+
 static void write_end_record(libxl__egc *egc,
                              libxl__stream_write_state *stream)
 {
@@ -645,6 +729,14 @@ static void checkpoint_end_record_done(libxl__egc *egc,
     stream_failed(egc, stream, ret);
 }
 
+static void colo_context_done(libxl__egc *egc,
+                              libxl__stream_write_state *stream, int rc)
+{
+    assert(stream->in_colo_context);
+    stream->in_colo_context = false;
+    stream->write_records_callback(egc, stream, rc);
+}
+
 /*
  * Local variables:
  * mode: C
-- 
1.9.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

Reply via email to