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

[Xen-devel] [PATCH RFC v3 03/12] Migration with Local Disks Mirroring: Refactored migrate_read_fixedmessage



The function migrate_fixed_message is going to be used in the libxl create and
save flow for event synchronization during migration. It needs to be accessible
from libxl_create and libxl_dom_save and thus it is moved to libxl_utils.

Signed-off-by: Bruno Alvisio <bruno.alvisio@xxxxxxxxx>
---
 tools/libxl/libxl_utils.c | 21 +++++++++++++++++++
 tools/libxl/libxl_utils.h |  3 +++
 tools/xl/xl_migrate.c     | 52 +++++++++++++++--------------------------------
 3 files changed, 40 insertions(+), 36 deletions(-)

diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c
index 507ee56..5139320 100644
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -510,6 +510,27 @@ int libxl__read_sysfs_file_contents(libxl__gc *gc, const 
char *filename,
 READ_WRITE_EXACTLY(read, 1, /* */)
 READ_WRITE_EXACTLY(write, 0, const)
 
+int libxl_read_fixedmessage(libxl_ctx *ctx, int fd, const void *msg, int msgsz,
+                            const char *what, const char *rune)
+{
+    char buf[msgsz];
+    const char *stream;
+    int rc;
+
+    stream = rune ? "migration receiver stream" : "migration stream";
+    rc = libxl_read_exactly(ctx, fd, buf, msgsz, stream, what);
+    if (rc) return 1;
+
+    if (memcmp(buf, msg, msgsz)) {
+        fprintf(stderr, "%s contained unexpected data instead of %s\n",
+                stream, what);
+        if (rune)
+            fprintf(stderr, "(command run was: %s )\n", rune);
+        return 1;
+    }
+    return 0;
+}
+
 int libxl__remove_file(libxl__gc *gc, const char *path)
 {
     for (;;) {
diff --git a/tools/libxl/libxl_utils.h b/tools/libxl/libxl_utils.h
index 9e743dc..d1e80ef 100644
--- a/tools/libxl/libxl_utils.h
+++ b/tools/libxl/libxl_utils.h
@@ -56,6 +56,9 @@ int libxl_write_exactly(libxl_ctx *ctx, int fd, const void 
*data,
    * logged using filename (which is only used for logging) and what
    * (which may be 0). */
 
+int libxl_read_fixedmessage(libxl_ctx *ctx, int fd, const void *msg, int msgsz,
+                            const char *what, const char *rune);
+
 int libxl_pipe(libxl_ctx *ctx, int pipes[2]);
   /* Just like pipe(2), but log errors. */
 
diff --git a/tools/xl/xl_migrate.c b/tools/xl/xl_migrate.c
index 1f0e87d..33d39e8 100644
--- a/tools/xl/xl_migrate.c
+++ b/tools/xl/xl_migrate.c
@@ -68,26 +68,6 @@ static pid_t create_migration_child(const char *rune, int 
*send_fd,
     return child;
 }
 
-static int migrate_read_fixedmessage(int fd, const void *msg, int msgsz,
-                                     const char *what, const char *rune) {
-    char buf[msgsz];
-    const char *stream;
-    int rc;
-
-    stream = rune ? "migration receiver stream" : "migration stream";
-    rc = libxl_read_exactly(ctx, fd, buf, msgsz, stream, what);
-    if (rc) return 1;
-
-    if (memcmp(buf, msg, msgsz)) {
-        fprintf(stderr, "%s contained unexpected data instead of %s\n",
-                stream, what);
-        if (rune)
-            fprintf(stderr, "(command run was: %s )\n", rune);
-        return 1;
-    }
-    return 0;
-}
-
 static void migration_child_report(int recv_fd) {
     pid_t child;
     int status, sr;
@@ -162,9 +142,9 @@ static void migrate_do_preamble(int send_fd, int recv_fd, 
pid_t child,
         exit(EXIT_FAILURE);
     }
 
-    rc = migrate_read_fixedmessage(recv_fd, migrate_receiver_banner,
-                                   sizeof(migrate_receiver_banner)-1,
-                                   "banner", rune);
+    rc = libxl_read_fixedmessage(ctx, recv_fd, migrate_receiver_banner,
+                                 sizeof(migrate_receiver_banner)-1,
+                                 "banner", rune);
     if (rc) {
         close(send_fd);
         migration_child_report(recv_fd);
@@ -219,9 +199,9 @@ static void migrate_domain(uint32_t domid, const char 
*rune, int debug,
     // Should only be printed when debugging as it's a bit messy with
     // progress indication.
 
-    rc = migrate_read_fixedmessage(recv_fd, migrate_receiver_ready,
-                                   sizeof(migrate_receiver_ready),
-                                   "ready message", rune);
+    rc = libxl_read_fixedmessage(ctx, recv_fd, migrate_receiver_ready,
+                                 sizeof(migrate_receiver_ready),
+                                 "ready message", rune);
     if (rc) goto failed_resume;
 
     xtl_stdiostream_adjust_flags(logger, 0, XTL_STDIOSTREAM_HIDE_PROGRESS);
@@ -251,9 +231,9 @@ static void migrate_domain(uint32_t domid, const char 
*rune, int debug,
                              "migration stream", "GO message");
     if (rc) goto failed_badly;
 
-    rc = migrate_read_fixedmessage(recv_fd, migrate_report,
-                                   sizeof(migrate_report),
-                                   "success/failure report message", rune);
+    rc = libxl_read_fixedmessage(ctx, recv_fd, migrate_report,
+                                 sizeof(migrate_report),
+                                 "success/failure report message", rune);
     if (rc) goto failed_badly;
 
     rc = libxl_read_exactly(ctx, recv_fd,
@@ -265,10 +245,10 @@ static void migrate_domain(uint32_t domid, const char 
*rune, int debug,
         fprintf(stderr, "migration sender: Target reports startup failure"
                 " (status code %d).\n", rc_buf);
 
-        rc = migrate_read_fixedmessage(recv_fd, migrate_permission_to_go,
-                                       sizeof(migrate_permission_to_go),
-                                       "permission for sender to resume",
-                                       rune);
+        rc = libxl_read_fixedmessage(ctx, recv_fd, migrate_permission_to_go,
+                                     sizeof(migrate_permission_to_go),
+                                     "permission for sender to resume",
+                                     rune);
         if (rc) goto failed_badly;
 
         fprintf(stderr, "migration sender: Trying to resume at our end.\n");
@@ -416,9 +396,9 @@ static void migrate_receive(int debug, int daemonize, int 
monitor,
                              "migration ack stream", "ready message");
     if (rc) exit(EXIT_FAILURE);
 
-    rc = migrate_read_fixedmessage(recv_fd, migrate_permission_to_go,
-                                   sizeof(migrate_permission_to_go),
-                                   "GO message", 0);
+    rc = libxl_read_fixedmessage(ctx, recv_fd, migrate_permission_to_go,
+                                 sizeof(migrate_permission_to_go),
+                                 "GO message", 0);
     if (rc) goto perhaps_destroy_notify_rc;
 
     fprintf(stderr, "migration target: Got permission, starting domain.\n");
-- 
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

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