Blame SOURCES/0027-p2v-Run-fewer-scp-commands.patch

a30de4
From 847f9845085f76be8a00eba10fd995fe5e25ea21 Mon Sep 17 00:00:00 2001
90a56e
From: "Richard W.M. Jones" <rjones@redhat.com>
90a56e
Date: Thu, 30 Mar 2017 13:13:03 +0100
90a56e
Subject: [PATCH] p2v: Run fewer 'scp' commands.
90a56e
90a56e
Each scp command takes a considerable amount of time -- several
90a56e
seconds -- because it must set up, authenticate and tear down a new
90a56e
connection.  Avoid this by combining several copies into a single
90a56e
command.
90a56e
90a56e
We still have to use two scp commands because we want to check that
90a56e
some files are copied and ignore failures in a second set of
90a56e
informational files.
90a56e
90a56e
(cherry picked from commit d178deeeb814471b9d70431626b6cd515a21d0c1)
90a56e
---
90a56e
 p2v/conversion.c | 31 +++++++++++--------------------
90a56e
 p2v/p2v.h        |  2 +-
90a56e
 p2v/ssh.c        | 25 +++++++++++++++++++++----
90a56e
 3 files changed, 33 insertions(+), 25 deletions(-)
90a56e
90a56e
diff --git a/p2v/conversion.c b/p2v/conversion.c
a30de4
index 94a466640..27c6b2f2d 100644
90a56e
--- a/p2v/conversion.c
90a56e
+++ b/p2v/conversion.c
90a56e
@@ -366,28 +366,19 @@ start_conversion (struct config *config,
90a56e
   }
90a56e
 
90a56e
   /* Copy the static files to the remote dir. */
90a56e
-  if (scp_file (config, name_file, remote_dir) == -1) {
90a56e
-    set_conversion_error ("scp: %s to %s: %s",
90a56e
-                          name_file, remote_dir, get_ssh_error ());
90a56e
+
90a56e
+  /* These three files must not fail, so check for errors here. */
90a56e
+  if (scp_file (config, remote_dir,
90a56e
+                name_file, libvirt_xml_file, wrapper_script, NULL) == -1) {
90a56e
+    set_conversion_error ("scp: %s: %s",
90a56e
+                          remote_dir, get_ssh_error ());
90a56e
     goto out;
90a56e
   }
90a56e
-  if (scp_file (config, libvirt_xml_file, remote_dir) == -1) {
90a56e
-    set_conversion_error ("scp: %s to %s: %s",
90a56e
-                          libvirt_xml_file, remote_dir, get_ssh_error ());
90a56e
-    goto out;
90a56e
-  }
90a56e
-  if (scp_file (config, wrapper_script, remote_dir) == -1) {
90a56e
-    set_conversion_error ("scp: %s to %s: %s",
90a56e
-                          wrapper_script, remote_dir, get_ssh_error ());
90a56e
-    goto out;
90a56e
-  }
90a56e
-  /* It's not essential that these files are copied. */
90a56e
-  ignore_value (scp_file (config, dmesg_file, remote_dir));
90a56e
-  ignore_value (scp_file (config, lscpu_file, remote_dir));
90a56e
-  ignore_value (scp_file (config, lspci_file, remote_dir));
90a56e
-  ignore_value (scp_file (config, lsscsi_file, remote_dir));
90a56e
-  ignore_value (scp_file (config, lsusb_file, remote_dir));
90a56e
-  ignore_value (scp_file (config, p2v_version_file, remote_dir));
90a56e
+
90a56e
+  /* It's not essential that these files are copied, so ignore errors. */
90a56e
+  ignore_value (scp_file (config, remote_dir,
90a56e
+                          dmesg_file, lscpu_file, lspci_file, lsscsi_file,
90a56e
+                          lsusb_file, p2v_version_file, NULL));
90a56e
 
90a56e
   /* Do the conversion.  This runs until virt-v2v exits. */
90a56e
   if (notify_ui)
90a56e
diff --git a/p2v/p2v.h b/p2v/p2v.h
46ce2f
index 5223aa216..b26648a01 100644
90a56e
--- a/p2v/p2v.h
90a56e
+++ b/p2v/p2v.h
90a56e
@@ -128,7 +128,7 @@ extern int test_connection (struct config *);
90a56e
 extern mexp_h *open_data_connection (struct config *, const char *local_ipaddr, int local_port, int *remote_port);
90a56e
 extern mexp_h *start_remote_connection (struct config *, const char *remote_dir);
90a56e
 extern const char *get_ssh_error (void);
90a56e
-extern int scp_file (struct config *config, const char *localfile, const char *remotefile);
90a56e
+extern int scp_file (struct config *config, const char *target, const char *local, ...) __attribute__((sentinel));
90a56e
 
90a56e
 /* nbd.c */
90a56e
 extern void set_nbd_option (const char *opt);
90a56e
diff --git a/p2v/ssh.c b/p2v/ssh.c
a30de4
index dfcab0e40..991888348 100644
90a56e
--- a/p2v/ssh.c
90a56e
+++ b/p2v/ssh.c
90a56e
@@ -572,14 +572,18 @@ start_ssh (unsigned spawn_flags, struct config *config,
90a56e
 #endif
90a56e
 
90a56e
 /**
90a56e
- * Upload a file to remote using L<scp(1)>.
90a56e
+ * Upload file(s) to remote using L<scp(1)>.
90a56e
+ *
90a56e
+ * Note that the target (directory or file) comes before the list of
90a56e
+ * local files, because the list of local files is a varargs list.
90a56e
  *
90a56e
  * This is a simplified version of L</start_ssh> above.
90a56e
  */
90a56e
 int
90a56e
-scp_file (struct config *config, const char *localfile, const char *remotefile)
90a56e
+scp_file (struct config *config, const char *target, const char *local, ...)
90a56e
 {
90a56e
   size_t i = 0;
90a56e
+  va_list args;
90a56e
   const size_t MAX_ARGS = 64;
90a56e
   const char *argv[MAX_ARGS];
90a56e
   char port_str[64];
90a56e
@@ -618,12 +622,25 @@ scp_file (struct config *config, const char *localfile, const char *remotefile)
90a56e
     ADD_ARG (argv, i, "-i");
90a56e
     ADD_ARG (argv, i, config->identity_file);
90a56e
   }
90a56e
-  ADD_ARG (argv, i, localfile);
90a56e
+
90a56e
+  /* Source files or directories.
90a56e
+   * Strictly speaking this could abort() if the list of files is
90a56e
+   * too long, but that never happens in virt-p2v. XXX
90a56e
+   */
90a56e
+  va_start (args, local);
90a56e
+  do ADD_ARG (argv, i, local);
90a56e
+  while ((local = va_arg (args, const char *)) != NULL);
90a56e
+  va_end (args);
90a56e
+
90a56e
+  /* The target file or directory.  We need to rewrite this as
90a56e
+   * "username@server:target".
90a56e
+   */
90a56e
   if (asprintf (&remote, "%s@%s:%s",
90a56e
                 config->username ? config->username : "root",
90a56e
-                config->server, remotefile) == -1)
90a56e
+                config->server, target) == -1)
90a56e
     error (EXIT_FAILURE, errno, "asprintf");
90a56e
   ADD_ARG (argv, i, remote);
90a56e
+
90a56e
   ADD_ARG (argv, i, NULL);
90a56e
 
90a56e
 #if DEBUG_STDERR
90a56e
-- 
a30de4
2.14.3
90a56e