[Libguestfs] [PATCH] v2v: -o null: Force output format to be raw sparse.

Richard W.M. Jones rjones at redhat.com
Fri Mar 10 14:04:04 UTC 2017


When converting and throwing away the output (-o null), the input
format should not really matter.  However it does currently matter for
a couple of reasons:

(1) If the input is not raw or qcow2, then you'll get the error below
because virt-v2v wants to write the same output format as input format
but only allows raw or qcow2 as output formats:

  virt-v2v: error: output format should be 'raw' or 'qcow2'.

(2) If you use -o null -oa preallocated then a non-sparse temporary
disk is created before being deleted, but that just wastes disk space
for no reason.

Therefore this change

(i) prevents '-o null -oa preallocated' from being specified on the
command line,

(ii) prevents '-o null -of <anything>',

(iii) forces the output (temporary file) to be raw sparse.
---
 v2v/cmdline.ml | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/v2v/cmdline.ml b/v2v/cmdline.ml
index f417dea..a72aa49 100644
--- a/v2v/cmdline.ml
+++ b/v2v/cmdline.ml
@@ -337,7 +337,7 @@ read the man page virt-v2v(1).
   (* Parse the output mode. *)
   if output_mode <> `Not_set && in_place then
     error (f_"-o and --in-place cannot be used at the same time");
-  let output =
+  let output, output_format, output_alloc =
     match output_mode with
     | `Glance ->
       if output_conn <> None then
@@ -348,7 +348,8 @@ read the man page virt-v2v(1).
         error (f_"-o glance: --qemu-boot option cannot be used in this output mode");
       if not do_copy then
         error (f_"--no-copy and '-o glance' cannot be used at the same time");
-      Output_glance.output_glance ()
+      Output_glance.output_glance (),
+      output_format, output_alloc
 
     | `Not_set
     | `Libvirt ->
@@ -358,7 +359,8 @@ read the man page virt-v2v(1).
         error (f_"-o libvirt: --qemu-boot option cannot be used in this output mode");
       if not do_copy then
         error (f_"--no-copy and '-o libvirt' cannot be used at the same time");
-      Output_libvirt.output_libvirt output_conn output_storage
+      Output_libvirt.output_libvirt output_conn output_storage,
+      output_format, output_alloc
 
     | `Local ->
       let os =
@@ -370,16 +372,23 @@ read the man page virt-v2v(1).
         | Some d -> d in
       if qemu_boot then
         error (f_"-o local: --qemu-boot option cannot be used in this output mode");
-      Output_local.output_local os
+      Output_local.output_local os,
+      output_format, output_alloc
 
     | `Null ->
+      if output_alloc <> Sparse then
+        error (f_"-o null: -oa option cannot be used in this output mode");
       if output_conn <> None then
         error (f_"-o null: -oc option cannot be used in this output mode");
+      if output_format <> None then
+        error (f_"-o null: -of option cannot be used in this output mode");
       if output_storage <> None then
         error (f_"-o null: -os option cannot be used in this output mode");
       if qemu_boot then
         error (f_"-o null: --qemu-boot option cannot be used in this output mode");
-      Output_null.output_null ()
+      Output_null.output_null (),
+      (* Force output format to raw sparse in -o null mode. *)
+      Some "raw", Sparse
 
     | `QEmu ->
       let os =
@@ -389,7 +398,8 @@ read the man page virt-v2v(1).
         | Some d when not (is_directory d) ->
            error (f_"-os %s: output directory does not exist or is not a directory") d
         | Some d -> d in
-      Output_qemu.output_qemu os qemu_boot
+      Output_qemu.output_qemu os qemu_boot,
+      output_format, output_alloc
 
     | `RHV ->
       let os =
@@ -399,7 +409,8 @@ read the man page virt-v2v(1).
         | Some d -> d in
       if qemu_boot then
         error (f_"-o rhv: --qemu-boot option cannot be used in this output mode");
-      Output_rhv.output_rhv os output_alloc
+      Output_rhv.output_rhv os output_alloc,
+      output_format, output_alloc
 
     | `VDSM ->
       let os =
@@ -423,7 +434,8 @@ read the man page virt-v2v(1).
         ovf_output = vdsm_ovf_output;
         compat = vdsm_compat;
       } in
-      Output_vdsm.output_vdsm os vdsm_params output_alloc in
+      Output_vdsm.output_vdsm os vdsm_params output_alloc,
+      output_format, output_alloc in
 
   {
     compressed = compressed; debug_overlays = debug_overlays;
-- 
2.9.3




More information about the Libguestfs mailing list