[Pkg-libvirt-commits] [libguestfs] 251/266: p2v: Add p2v.output* controls so we can control where the output ends up.

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 3 14:42:52 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag debian/1%1.27.35-1
in repository libguestfs.

commit c516d2d07dd0d1e4429ec84d2e9ebe02a951c5b5
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Mon Sep 1 17:16:52 2014 +0100

    p2v: Add p2v.output* controls so we can control where the output ends up.
    
    This still needs to be implemented through the GUI.
---
 p2v/config.c     |  11 ++++++
 p2v/conversion.c | 105 +++++++++++++++++++++++++++++++++++++++++++------------
 p2v/kernel.c     |  33 +++++++++++++++++
 p2v/main.c       |   6 ++++
 p2v/p2v.h        |   8 +++++
 p2v/virt-p2v.pod |  27 +++++++++++++-
 6 files changed, 167 insertions(+), 23 deletions(-)

diff --git a/p2v/config.c b/p2v/config.c
index dafb687..e3ac2a6 100644
--- a/p2v/config.c
+++ b/p2v/config.c
@@ -46,6 +46,8 @@ new_config (void)
 #endif
   c->port = 22;
 
+  c->output_allocation = OUTPUT_ALLOCATION_NONE;
+
   return c;
 }
 
@@ -71,6 +73,12 @@ copy_config (struct config *old)
     c->removable = guestfs___copy_string_list (c->removable);
   if (c->interfaces)
     c->interfaces = guestfs___copy_string_list (c->interfaces);
+  if (c->output)
+    c->output = strdup (c->output);
+  if (c->output_format)
+    c->output_format = strdup (c->output_format);
+  if (c->output_storage)
+    c->output_storage = strdup (c->output_storage);
 
   return c;
 }
@@ -85,5 +93,8 @@ free_config (struct config *c)
   guestfs___free_string_list (c->disks);
   guestfs___free_string_list (c->removable);
   guestfs___free_string_list (c->interfaces);
+  free (c->output);
+  free (c->output_format);
+  free (c->output_storage);
   free (c);
 }
diff --git a/p2v/conversion.c b/p2v/conversion.c
index cea4e94..69ebb5b 100644
--- a/p2v/conversion.c
+++ b/p2v/conversion.c
@@ -46,6 +46,7 @@ struct data_conn {
   int nbd_remote_port;      /* remote NBD port on conversion server */
 };
 
+static int send_quoted (mexp_h *, const char *s);
 static pid_t start_qemu_nbd (int nbd_local_port, const char *device);
 static void cleanup_data_conns (struct data_conn *data_conns, size_t nr);
 static char *generate_libvirt_xml (struct config *, struct data_conn *);
@@ -197,32 +198,65 @@ start_conversion (struct config *config,
   if (notify_ui)
     notify_ui (NOTIFY_STATUS, _("Doing conversion ..."));
 
-  if (mexp_printf (control_h,
-                   "( "
-                   "%s"
-                   "virt-v2v"
-                   "%s"
-                   " -i libvirtxml"
-                   " -o local -os /tmp" /* XXX */
-                   " --root first"
-                   " %s/guest.xml"
-                   " </dev/null" /* stdin */
-                   " 2>&1"       /* output */
-                   " ;"
-                   " echo $? > %s/status"
-                   " )"
-                   " | tee %s/virt-v2v-conversion-log.txt"
-                   " ;"
-                   " exit"
-                   "\n",
+  /* Build the virt-v2v command up in pieces to make the quoting
+   * slightly more sane.
+   */
+  if (mexp_printf (control_h, "( %s virt-v2v%s -i libvirtxml",
                    config->sudo ? "sudo " : "",
-                   config->verbose ? " -v -x" : "",
-                   remote_dir,
-                   remote_dir,
-                   remote_dir) == -1) {
+                   config->verbose ? " -v -x" : "") == -1) {
+  printf_fail:
     set_conversion_error ("mexp_printf: virt-v2v command: %m");
     goto out;
   }
+  if (config->output) {         /* -o */
+    if (mexp_printf (control_h, " -o ") == -1)
+      goto printf_fail;
+    if (send_quoted (control_h, config->output) == -1)
+      goto printf_fail;
+  }
+  switch (config->output_allocation) { /* -oa */
+  case OUTPUT_ALLOCATION_NONE:
+    /* nothing */
+    break;
+  case OUTPUT_ALLOCATION_SPARSE:
+    if (mexp_printf (control_h, " -oa sparse") == -1)
+      goto printf_fail;
+    break;
+  case OUTPUT_ALLOCATION_PREALLOCATED:
+    if (mexp_printf (control_h, " -oa preallocated") == -1)
+      goto printf_fail;
+    break;
+  default:
+    abort ();
+  }
+  if (config->output_format) {  /* -of */
+    if (mexp_printf (control_h, " -of ") == -1)
+      goto printf_fail;
+    if (send_quoted (control_h, config->output_format) == -1)
+      goto printf_fail;
+  }
+  if (config->output_storage) { /* -os */
+    if (mexp_printf (control_h, " -os ") == -1)
+      goto printf_fail;
+    if (send_quoted (control_h, config->output_storage) == -1)
+      goto printf_fail;
+  }
+  if (mexp_printf (control_h, " --root first") == -1)
+    goto printf_fail;
+  if (mexp_printf (control_h, " %s/guest.xml", remote_dir) == -1)
+    goto printf_fail;
+  /* no stdin, and send stdout and stderr to the same place */
+  if (mexp_printf (control_h, " </dev/null 2>&1") == -1)
+    goto printf_fail;
+  if (mexp_printf (control_h, " ; echo $? > %s/status", remote_dir) == -1)
+    goto printf_fail;
+  if (mexp_printf (control_h, " ) | tee %s/virt-v2v-conversion-log.txt",
+                   remote_dir) == -1)
+    goto printf_fail;
+  if (mexp_printf (control_h, "; exit") == -1)
+    goto printf_fail;
+  if (mexp_printf (control_h, "\n") == -1)
+    goto printf_fail;
 
   /* Read output from the virt-v2v process and echo it through the
    * notify function, until virt-v2v closes the connection.
@@ -257,6 +291,26 @@ start_conversion (struct config *config,
   return ret;
 }
 
+/* Send a shell-quoted string to remote. */
+static int
+send_quoted (mexp_h *h, const char *s)
+{
+  if (mexp_printf (h, "\"") == -1)
+    return -1;
+  while (*s) {
+    if (*s == '$' || *s == '`' || *s == '\\' || *s == '"') {
+      if (mexp_printf (h, "\\") == -1)
+        return -1;
+    }
+    if (mexp_printf (h, "%c", *s) == -1)
+      return -1;
+    ++s;
+  }
+  if (mexp_printf (h, "\"") == -1)
+    return -1;
+  return 0;
+}
+
 /* Note: returns process ID (> 0) or 0 if there is an error. */
 static pid_t
 start_qemu_nbd (int port, const char *device)
@@ -480,6 +534,13 @@ debug_parameters (struct config *config)
       fprintf (stderr, " %s", config->interfaces[i]);
   }
   fprintf (stderr, "\n");
+  fprintf (stderr, "output . . . . .   %s\n",
+           config->output ? config->output : "none");
+  fprintf (stderr, "output alloc . .   %d\n", config->output_allocation);
+  fprintf (stderr, "output format  .   %s\n",
+           config->output_format ? config->output_format : "none");
+  fprintf (stderr, "output storage .   %s\n",
+           config->output_storage ? config->output_storage : "none");
   fprintf (stderr, "\n");
 #endif
 }
diff --git a/p2v/kernel.c b/p2v/kernel.c
index 1148945..64432fd 100644
--- a/p2v/kernel.c
+++ b/p2v/kernel.c
@@ -161,6 +161,39 @@ kernel_configuration (struct config *config, const char *cmdline)
     config->interfaces = guestfs___split_string (',', t);
   }
 
+  r = strstr (cmdline, "p2v.output=");
+  if (r) {
+    r += 5+6;
+    len = strcspn (r, " ");
+    free (config->output);
+    config->output = strndup (r, len);
+  }
+
+  r = strstr (cmdline, "p2v.output_allocation=sparse");
+  if (r)
+    config->output_allocation = OUTPUT_ALLOCATION_SPARSE;
+
+  r = strstr (cmdline, "p2v.output_allocation=preallocated");
+  if (r)
+    config->output_allocation = OUTPUT_ALLOCATION_PREALLOCATED;
+
+  r = strstr (cmdline, "p2v.output_format=");
+  if (r) {
+    r += 5+13;
+    len = strcspn (r, " ");
+    free (config->output_format);
+    config->output_format = strndup (r, len);
+  }
+
+  r = strstr (cmdline, "p2v.output_storage=");
+  if (r) {
+    r += 5+14;
+    len = strcspn (r, " ");
+    free (config->output_storage);
+    config->output_storage = strndup (r, len);
+  }
+
+  /* Perform the conversion in text mode. */
   if (start_conversion (config, notify_ui_callback) == -1) {
     const char *err = get_conversion_error ();
 
diff --git a/p2v/main.c b/p2v/main.c
index df4f10c..0f75a9c 100644
--- a/p2v/main.c
+++ b/p2v/main.c
@@ -266,6 +266,12 @@ set_config_defaults (struct config *config)
   find_all_interfaces ();
   if (all_interfaces)
     config->interfaces = guestfs___copy_string_list (all_interfaces);
+
+  /* Default output drops the guest onto /var/tmp on the conversion
+   * server, a hopefully safe default.
+   */
+  config->output = strdup ("local");
+  config->output_storage = strdup ("/var/tmp");
 }
 
 static int
diff --git a/p2v/p2v.h b/p2v/p2v.h
index 2d0249f..4251d0b 100644
--- a/p2v/p2v.h
+++ b/p2v/p2v.h
@@ -65,12 +65,20 @@ struct config {
   char **disks;
   char **removable;
   char **interfaces;
+  char *output;
+  int output_allocation;
+  char *output_format;
+  char *output_storage;
 };
 
 #define FLAG_ACPI 1
 #define FLAG_APIC 2
 #define FLAG_PAE  4
 
+#define OUTPUT_ALLOCATION_NONE         0
+#define OUTPUT_ALLOCATION_SPARSE       1
+#define OUTPUT_ALLOCATION_PREALLOCATED 2
+
 extern struct config *new_config (void);
 extern struct config *copy_config (struct config *);
 extern void free_config (struct config *);
diff --git a/p2v/virt-p2v.pod b/p2v/virt-p2v.pod
index 0837abd..52f4b18 100644
--- a/p2v/virt-p2v.pod
+++ b/p2v/virt-p2v.pod
@@ -77,7 +77,7 @@ in the C<pxelinux.cfg> file.  For example:
  PROMPT 0
  LABEL p2v
    KERNEL virt-p2v-vmlinuz
-   APPEND initrd=virt-p2v-initrd p2v.server=conv.example.com p2v.password=secret
+   APPEND initrd=virt-p2v-initrd p2v.server=conv.example.com p2v.password=secret p2v.output=libvirt
 
 You have to set some or all of the following command line arguments:
 
@@ -161,6 +161,31 @@ Note that the content of removable media is never copied over.
 A list of network interfaces to convert.  The default is to create
 virtual network interfaces for every physical network interface found.
 
+=item B<p2v.output=[libvirt|local|...]>
+
+Set the output mode.  This is the same as the virt-v2v I<-o> option.
+See L<virt-v2v(1)/OPTIONS>.
+
+If not specified, the default is C<local>, and the converted guest is
+written to C</var/tmp>.
+
+=item B<p2v.output_allocation=sparse|preallocated>
+
+Set the output allocation mode.  This is the same as the virt-v2v
+I<-oa> option.  See L<virt-v2v(1)/OPTIONS>.
+
+=item B<p2v.output_format=raw|sparse|...>
+
+Set the output format.  This is the same as the virt-v2v I<-oa>
+option.  See L<virt-v2v(1)/OPTIONS>.
+
+=item B<p2v.output_storage=...>
+
+Set the output storage.  This is the same as the virt-v2v I<-os>
+option.  See L<virt-v2v(1)/OPTIONS>.
+
+If not specified, the default is C</var/tmp> (on the conversion server).
+
 =item B<ip=dhcp>
 
 Use DHCP for configuring the network interface (this is the default).

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list