File xen.xl-timestamps.patch of Package xen

From: Olaf Hering <olaf@aepfle.de>
Date: Wed, 9 Sep 2020 11:12:57 +0200
Subject: xl timestamps

xl: optionally print timestamps during xl migrate

During 'xl -v.. migrate domU host' a large amount of debug is generated.
It is difficult to map each line to the sending and receiving side.
Also the time spent for migration is not reported.

With 'xl migrate -T domU host' both sides will print timestamps and
also the pid of the invoked xl process to make it more obvious which
side produced a given log line.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
---
 docs/man/xl.1.pod.in   |  4 ++++
 tools/xl/xl_cmdtable.c |  1 +
 tools/xl/xl_migrate.c  | 25 +++++++++++++++++++++----
 3 files changed, 26 insertions(+), 4 deletions(-)

--- a/docs/man/xl.1.pod.in
+++ b/docs/man/xl.1.pod.in
@@ -473,24 +473,28 @@ Use <sshcommand> instead of ssh.  String will be passed to sh. If empty, run
 <host> instead of ssh <host> xl migrate-receive [-d -e].
 
 =item B<-e>
 
 On the new <host>, do not wait in the background for the death of the
 domain. See the corresponding option of the I<create> subcommand.
 
 =item B<-C> I<config>
 
 Send the specified <config> file instead of the file used on creation of the
 domain.
 
+=item B<-T>
+
+Include timestamps in output.
+
 =item B<--debug>
 
 Display huge (!) amount of debug information during the migration process.
 
 =item B<-p>
 
 Leave the domain on the receive side paused after migration.
 
 =item B<-D>
 
 Preserve the B<domain-id> in the domain coniguration that is transferred
 such that it will be identical on the destination host, unless that
--- a/tools/xl/xl_cmdtable.c
+++ b/tools/xl/xl_cmdtable.c
@@ -158,24 +158,25 @@ struct cmd_spec cmd_table[] = {
     },
     { "migrate",
       &main_migrate, 0, 1,
       "Migrate a domain to another host",
       "[options] <Domain> <host>",
       "-h              Print this help.\n"
       "-C <config>     Send <config> instead of config file from creation.\n"
       "-s <sshcommand> Use <sshcommand> instead of ssh.  String will be passed\n"
       "                to sh. If empty, run <host> instead of ssh <host> xl\n"
       "                migrate-receive [-d -e]\n"
       "-e              Do not wait in the background (on <host>) for the death\n"
       "                of the domain.\n"
+      "-T              Show timestamps during the migration process.\n"
       "--debug         Print huge (!) amount of debug during the migration process.\n"
       "-p              Do not unpause domain after migrating it.\n"
       "-D              Preserve the domain id"
     },
     { "restore",
       &main_restore, 0, 1,
       "Restore a domain from a saved state",
       "[options] [<ConfigFile>] <CheckpointFile>",
       "-h                       Print this help.\n"
       "-p                       Do not unpause domain after restoring it.\n"
       "-e                       Do not wait in the background for the death of the domain.\n"
       "-d                       Enable debug messages.\n"
--- a/tools/xl/xl_migrate.c
+++ b/tools/xl/xl_migrate.c
@@ -23,24 +23,26 @@
 #include <unistd.h>
 
 #include <libxl.h>
 #include <libxl_utils.h>
 #include <libxlutil.h>
 
 #include "xl.h"
 #include "xl_utils.h"
 #include "xl_parse.h"
 
 #ifndef LIBXL_HAVE_NO_SUSPEND_RESUME
 
+static bool timestamps;
+
 static pid_t create_migration_child(const char *rune, int *send_fd,
                                         int *recv_fd)
 {
     int sendpipe[2], recvpipe[2];
     pid_t child;
 
     if (!rune || !send_fd || !recv_fd)
         return -1;
 
     MUST( libxl_pipe(ctx, sendpipe) );
     MUST( libxl_pipe(ctx, recvpipe) );
 
@@ -178,40 +180,43 @@ static void migrate_do_preamble(int send_fd, int recv_fd, pid_t child,
 
 static void migrate_domain(uint32_t domid, int preserve_domid,
                            const char *rune, int debug,
                            const char *override_config_file)
 {
     pid_t child = -1;
     int rc;
     int send_fd = -1, recv_fd = -1;
     char *away_domname;
     char rc_buf;
     uint8_t *config_data;
     int config_len, flags = LIBXL_SUSPEND_LIVE;
+    unsigned xtl_flags = XTL_STDIOSTREAM_HIDE_PROGRESS;
 
     save_domain_core_begin(domid, preserve_domid, override_config_file,
                            &config_data, &config_len);
 
     if (!config_len) {
         fprintf(stderr, "No config file stored for running domain and "
                 "none supplied - cannot migrate.\n");
         exit(EXIT_FAILURE);
     }
 
     child = create_migration_child(rune, &send_fd, &recv_fd);
 
     migrate_do_preamble(send_fd, recv_fd, child, config_data, config_len,
                         rune);
 
-    xtl_stdiostream_adjust_flags(logger, XTL_STDIOSTREAM_HIDE_PROGRESS, 0);
+    if (timestamps)
+        xtl_flags |= XTL_STDIOSTREAM_SHOW_DATE | XTL_STDIOSTREAM_SHOW_PID;
+    xtl_stdiostream_adjust_flags(logger, xtl_flags, 0);
 
     if (debug)
         flags |= LIBXL_SUSPEND_DEBUG;
     rc = libxl_domain_suspend(ctx, domid, send_fd, flags, NULL);
     if (rc) {
         fprintf(stderr, "migration sender: libxl_domain_suspend failed"
                 " (rc=%d)\n", rc);
         if (rc == ERROR_GUEST_TIMEDOUT)
             goto failed_suspend;
         else
             goto failed_resume;
     }
@@ -319,24 +324,29 @@ static void migrate_domain(uint32_t domid, int preserve_domid,
 static void migrate_receive(int debug, int daemonize, int monitor,
                             int pause_after_migration,
                             int send_fd, int recv_fd,
                             libxl_checkpointed_stream checkpointed,
                             char *colo_proxy_script,
                             bool userspace_colo_proxy)
 {
     uint32_t domid;
     int rc, rc2;
     char rc_buf;
     char *migration_domname;
     struct domain_create dom_info;
+    unsigned xtl_flags = 0;
+
+    if (timestamps)
+        xtl_flags |= XTL_STDIOSTREAM_SHOW_DATE | XTL_STDIOSTREAM_SHOW_PID;
+    xtl_stdiostream_adjust_flags(logger, xtl_flags, 0);
 
     signal(SIGPIPE, SIG_IGN);
     /* if we get SIGPIPE we'd rather just have it as an error */
 
     fprintf(stderr, "migration target: Ready to receive domain.\n");
 
     CHK_ERRNOVAL(libxl_write_exactly(
                      ctx, send_fd, migrate_receiver_banner,
                      sizeof(migrate_receiver_banner)-1,
                      "migration ack stream", "banner") );
 
     memset(&dom_info, 0, sizeof(dom_info));
@@ -482,25 +492,25 @@ int main_migrate_receive(int argc, char **argv)
     libxl_checkpointed_stream checkpointed = LIBXL_CHECKPOINTED_STREAM_NONE;
     int opt;
     bool userspace_colo_proxy = false;
     char *script = NULL;
     static struct option opts[] = {
         {"colo", 0, 0, 0x100},
         /* It is a shame that the management code for disk is not here. */
         {"coloft-script", 1, 0, 0x200},
         {"userspace-colo-proxy", 0, 0, 0x300},
         COMMON_LONG_OPTS
     };
 
-    SWITCH_FOREACH_OPT(opt, "Fedrp", opts, "migrate-receive", 0) {
+    SWITCH_FOREACH_OPT(opt, "FedrpT", opts, "migrate-receive", 0) {
     case 'F':
         daemonize = 0;
         break;
     case 'e':
         daemonize = 0;
         monitor = 0;
         break;
     case 'd':
         debug = 1;
         break;
     case 'r':
         checkpointed = LIBXL_CHECKPOINTED_STREAM_REMUS;
@@ -508,24 +518,27 @@ int main_migrate_receive(int argc, char **argv)
     case 0x100:
         checkpointed = LIBXL_CHECKPOINTED_STREAM_COLO;
         break;
     case 0x200:
         script = optarg;
         break;
     case 0x300:
         userspace_colo_proxy = true;
         break;
     case 'p':
         pause_after_migration = 1;
         break;
+    case 'T':
+        timestamps = 1;
+        break;
     }
 
     if (argc-optind != 0) {
         help("migrate-receive");
         return EXIT_FAILURE;
     }
     migrate_receive(debug, daemonize, monitor, pause_after_migration,
                     STDOUT_FILENO, STDIN_FILENO,
                     checkpointed, script, userspace_colo_proxy);
 
     return EXIT_SUCCESS;
 }
@@ -536,38 +549,41 @@ int main_migrate(int argc, char **argv)
     const char *config_filename = NULL;
     const char *ssh_command = "ssh";
     char *rune = NULL;
     char *host;
     int opt, daemonize = 1, monitor = 1, debug = 0, pause_after_migration = 0;
     int preserve_domid = 0;
     static struct option opts[] = {
         {"debug", 0, 0, 0x100},
         {"live", 0, 0, 0x200},
         COMMON_LONG_OPTS
     };
 
-    SWITCH_FOREACH_OPT(opt, "FC:s:epD", opts, "migrate", 2) {
+    SWITCH_FOREACH_OPT(opt, "FC:s:eTpD", opts, "migrate", 2) {
     case 'C':
         config_filename = optarg;
         break;
     case 's':
         ssh_command = optarg;
         break;
     case 'F':
         daemonize = 0;
         break;
     case 'e':
         daemonize = 0;
         monitor = 0;
         break;
+    case 'T':
+        timestamps = 1;
+        break;
     case 'p':
         pause_after_migration = 1;
         break;
     case 'D':
         preserve_domid = 1;
         break;
     case 0x100: /* --debug */
         debug = 1;
         break;
     case 0x200: /* --live */
         /* ignored for compatibility with xm */
         break;
@@ -583,29 +599,30 @@ int main_migrate(int argc, char **argv)
     } else {
         char verbose_buf[minmsglevel_default+3];
         int verbose_len;
         verbose_buf[0] = ' ';
         verbose_buf[1] = '-';
         memset(verbose_buf+2, 'v', minmsglevel_default);
         verbose_buf[sizeof(verbose_buf)-1] = 0;
         if (minmsglevel == minmsglevel_default) {
             verbose_len = 0;
         } else {
             verbose_len = (minmsglevel_default - minmsglevel) + 2;
         }
-        xasprintf(&rune, "exec %s %s xl%s%.*s migrate-receive%s%s%s",
+        xasprintf(&rune, "exec %s %s xl%s%.*s migrate-receive%s%s%s%s",
                   ssh_command, host,
                   pass_tty_arg ? " -t" : "",
                   verbose_len, verbose_buf,
                   daemonize ? "" : " -e",
+                  timestamps ? " -T" : "",
                   debug ? " -d" : "",
                   pause_after_migration ? " -p" : "");
     }
 
     migrate_domain(domid, preserve_domid, rune, debug, config_filename);
     return EXIT_SUCCESS;
 }
 
 int main_remus(int argc, char **argv)
 {
     uint32_t domid;
     int opt, rc, daemonize = 1;
openSUSE Build Service is sponsored by