[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH v3 COLOPre 21/26] tools/libxl: refactor write stream to support back channel



From: Wen Congyang <wency@xxxxxxxxxxxxxx>

Signed-off-by: Wen Congyang <wency@xxxxxxxxxxxxxx>
---
 tools/libxl/libxl_dom_save.c     |  7 +++++--
 tools/libxl/libxl_internal.h     |  9 +++++----
 tools/libxl/libxl_remus.c        |  8 +++++---
 tools/libxl/libxl_stream_write.c | 22 ++++++++++++++++++----
 4 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/tools/libxl/libxl_dom_save.c b/tools/libxl/libxl_dom_save.c
index 5797148..9a3b33d 100644
--- a/tools/libxl/libxl_dom_save.c
+++ b/tools/libxl/libxl_dom_save.c
@@ -30,7 +30,7 @@ struct libxl__physmap_info {
 /*========================= Domain save ============================*/
 
 static void stream_done(libxl__egc *egc,
-                        libxl__domain_save_state *dss, int rc);
+                        libxl__stream_write_state *stream, int rc);
 static void domain_save_done(libxl__egc *egc,
                              libxl__domain_save_state *dss, int rc);
 
@@ -445,6 +445,7 @@ void libxl__domain_save(libxl__egc *egc, 
libxl__domain_save_state *dss)
 
     dss->sws.fd = dss->fd;
     dss->sws.ao = dss->ao;
+    dss->sws.back_channel = false;
     dss->sws.completion_callback = stream_done;
 
     libxl__stream_write_start(egc, &dss->sws);
@@ -455,8 +456,10 @@ void libxl__domain_save(libxl__egc *egc, 
libxl__domain_save_state *dss)
 }
 
 static void stream_done(libxl__egc *egc,
-                        libxl__domain_save_state *dss, int rc)
+                        libxl__stream_write_state *stream, int rc)
 {
+    libxl__domain_save_state *dss = CONTAINER_OF(stream, *dss, sws);
+
     domain_save_done(egc, dss, rc);
 }
 
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 13d8271..82a327c 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -2877,12 +2877,13 @@ struct libxl__stream_write_state {
     libxl__ao *ao;
     int fd;
     uint32_t domid;
+    bool back_channel;
     void (*completion_callback)(libxl__egc *egc,
-                                libxl__domain_save_state *dss,
-                                int rc);
-    void (*checkpoint_callback)(libxl__egc *egc,
-                                libxl__domain_save_state *dss,
+                                libxl__stream_write_state *stream,
                                 int rc);
+    void (*write_records_callback)(libxl__egc *egc,
+                                   libxl__stream_write_state *stream,
+                                   int rc);
     /* Private */
     int rc;
     int joined_rc;
diff --git a/tools/libxl/libxl_remus.c b/tools/libxl/libxl_remus.c
index 01cc9e7..e143b21 100644
--- a/tools/libxl/libxl_remus.c
+++ b/tools/libxl/libxl_remus.c
@@ -205,7 +205,7 @@ out:
 /*----- remus asynchronous checkpoint callback -----*/
 
 static void remus_checkpoint_stream_written(
-                    libxl__egc *egc, libxl__domain_save_state *dss, int rc);
+                    libxl__egc *egc, libxl__stream_write_state *stream, int 
rc);
 static void remus_devices_commit_cb(libxl__egc *egc,
                                     libxl__remus_devices_state *rds,
                                     int rc);
@@ -219,13 +219,15 @@ void libxl__remus_domain_save_checkpoint_callback(void 
*data)
     libxl__egc *egc = dss->shs.egc;
     STATE_AO_GC(dss->ao);
 
-    dss->sws.checkpoint_callback = remus_checkpoint_stream_written;
+    dss->sws.write_records_callback = remus_checkpoint_stream_written;
     libxl__stream_write_start_checkpoint(egc, &dss->sws);
 }
 
 static void remus_checkpoint_stream_written(
-                libxl__egc *egc, libxl__domain_save_state *dss, int rc)
+                libxl__egc *egc, libxl__stream_write_state *stream, int rc)
 {
+    libxl__domain_save_state *dss = CONTAINER_OF(stream, *dss, sws);
+
     /* Convenience aliases */
     libxl__remus_devices_state *const rds = &dss->rds;
 
diff --git a/tools/libxl/libxl_stream_write.c b/tools/libxl/libxl_stream_write.c
index 1ebe306..3f981f0 100644
--- a/tools/libxl/libxl_stream_write.c
+++ b/tools/libxl/libxl_stream_write.c
@@ -48,6 +48,13 @@
  *  - Toolstack record
  *  - if (hvm), Qemu record
  *  - Checkpoint end record
+ *
+ * For back channel stream:
+ * - libxl__stream_write_start()
+ *    - Set up the stream to running state
+ *
+ * - Add a new API to write the record. When the record is written
+ *   out, call stream->write_records_callback() to return.
  */
 
 static const uint8_t zero_padding[1U << REC_ALIGN_ORDER] = { 0 };
@@ -111,6 +118,9 @@ void libxl__stream_write_start(libxl__egc *egc,
     assert(!stream->running);
     stream->running = true;
 
+    if (stream->back_channel)
+        return;
+
     memset(dc, 0, sizeof(*dc));
     dc->readwhat = "";
     dc->copywhat = "suspend header";
@@ -143,6 +153,7 @@ void libxl__stream_write_start_checkpoint(libxl__egc *egc,
 {
     assert(stream->running);
     assert(!stream->in_checkpoint);
+    assert(!stream->back_channel);
     stream->in_checkpoint = true;
 
     write_toolstack_record(egc, stream);
@@ -178,6 +189,11 @@ static void stream_failed(libxl__egc *egc,
         return;
     }
 
+    if (stream->back_channel) {
+        stream->completion_callback(egc, stream, rc);
+        return;
+    }
+
     if (stream->running) {
         stream->running = false;
         stream_done(egc, stream);
@@ -231,7 +247,7 @@ static void check_stream_finished(libxl__egc *egc,
         LOG(DEBUG, "save/restore still in use");
     else {
         LOG(INFO, "Join complete: result %d", stream->joined_rc);
-        stream->completion_callback(egc, dss, stream->joined_rc);
+        stream->completion_callback(egc, stream, stream->joined_rc);
     }
 }
 
@@ -577,11 +593,9 @@ static void checkpoint_done(libxl__egc *egc,
                             libxl__stream_write_state *stream,
                             int rc)
 {
-    libxl__domain_save_state *dss = CONTAINER_OF(stream, *dss, sws);
-
     assert(stream->in_checkpoint);
     stream->in_checkpoint = false;
-    stream->checkpoint_callback(egc, dss, rc);
+    stream->write_records_callback(egc, stream, rc);
 }
 
 static void write_checkpoint_end_record(libxl__egc *egc,
-- 
1.9.1


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


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.