Blame SOURCES/0046-v2v-Force-format-of-input-to-be-specified.patch

62f9b7
From 350baba10cbef38f7e2829927c2768c7f913e82f Mon Sep 17 00:00:00 2001
62f9b7
From: "Richard W.M. Jones" <rjones@redhat.com>
62f9b7
Date: Tue, 23 Nov 2021 09:58:50 +0000
62f9b7
Subject: [PATCH] v2v: Force format of input to be specified
62f9b7
62f9b7
qemu 6.1 unnecessarily insists on the backing format of files being
62f9b7
set.  Change the type of the input disk so the format is no longer an
62f9b7
option, but must be set by the input mode.
62f9b7
62f9b7
This change is only required on the 1.44 branch, since modular
62f9b7
virt-v2v uses the qemu-nbd -s (snapshot) option to do the equivalent
62f9b7
which seems to handle the backing format automatically.
62f9b7
62f9b7
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2025769
62f9b7
Reported-by: Vera Wu
62f9b7
(cherry picked from commit 40cfe6da0861ca6360f670e254c71ed923a0402f)
62f9b7
---
62f9b7
 v2v/input_disk.ml                  |  2 +-
62f9b7
 v2v/input_libvirt_vcenter_https.ml |  2 +-
62f9b7
 v2v/input_libvirt_vddk.ml          |  2 +-
62f9b7
 v2v/input_vmx.ml                   |  2 +-
62f9b7
 v2v/parse_libvirt_xml.ml           | 13 +++++++++----
62f9b7
 v2v/parse_ovf_from_ova.ml          |  2 +-
62f9b7
 v2v/types.ml                       |  9 +++------
62f9b7
 v2v/types.mli                      |  2 +-
62f9b7
 v2v/v2v.ml                         | 19 +++++++------------
62f9b7
 9 files changed, 25 insertions(+), 28 deletions(-)
62f9b7
62f9b7
diff --git a/v2v/input_disk.ml b/v2v/input_disk.ml
62f9b7
index 4e403003..beaa9a4d 100644
62f9b7
--- a/v2v/input_disk.ml
62f9b7
+++ b/v2v/input_disk.ml
62f9b7
@@ -64,7 +64,7 @@ class input_disk input_format disk = object
62f9b7
     let disk = {
62f9b7
       s_disk_id = 0;
62f9b7
       s_qemu_uri = disk_absolute;
62f9b7
-      s_format = Some format;
62f9b7
+      s_format = format;
62f9b7
       s_controller = None;
62f9b7
     } in
62f9b7
 
62f9b7
diff --git a/v2v/input_libvirt_vcenter_https.ml b/v2v/input_libvirt_vcenter_https.ml
62f9b7
index ed2e5eed..f3c55b79 100644
62f9b7
--- a/v2v/input_libvirt_vcenter_https.ml
62f9b7
+++ b/v2v/input_libvirt_vcenter_https.ml
62f9b7
@@ -84,7 +84,7 @@ object (self)
62f9b7
         (* The libvirt ESX driver doesn't normally specify a format, but
62f9b7
          * the format of the -flat file is *always* raw, so force it here.
62f9b7
          *)
62f9b7
-        { disk with s_qemu_uri = qemu_uri; s_format = Some "raw" }
62f9b7
+        { disk with s_qemu_uri = qemu_uri; s_format = "raw" }
62f9b7
     ) disks in
62f9b7
 
62f9b7
     source, disks
62f9b7
diff --git a/v2v/input_libvirt_vddk.ml b/v2v/input_libvirt_vddk.ml
62f9b7
index 75fd146e..9463f6ba 100644
62f9b7
--- a/v2v/input_libvirt_vddk.ml
62f9b7
+++ b/v2v/input_libvirt_vddk.ml
62f9b7
@@ -187,7 +187,7 @@ object (self)
62f9b7
          (* nbdkit always presents us with the raw disk blocks from
62f9b7
           * the guest, so force the format to raw here.
62f9b7
           *)
62f9b7
-         { disk with s_qemu_uri = qemu_uri; s_format = Some "raw" }
62f9b7
+         { disk with s_qemu_uri = qemu_uri; s_format = "raw" }
62f9b7
     ) disks in
62f9b7
 
62f9b7
     source, disks
62f9b7
diff --git a/v2v/input_vmx.ml b/v2v/input_vmx.ml
62f9b7
index 7a7647e5..a4ed999a 100644
62f9b7
--- a/v2v/input_vmx.ml
62f9b7
+++ b/v2v/input_vmx.ml
62f9b7
@@ -190,7 +190,7 @@ and find_hdds ?bandwidth input_password vmx vmx_source
62f9b7
            let uri, format = qemu_uri_of_filename ?bandwidth input_password
62f9b7
                                                   vmx_source filename in
62f9b7
            let s = { s_disk_id = (-1);
62f9b7
-                     s_qemu_uri = uri; s_format = Some format;
62f9b7
+                     s_qemu_uri = uri; s_format = format;
62f9b7
                      s_controller = Some controller } in
62f9b7
            Some (c, t, s)
62f9b7
         | _ -> None
62f9b7
diff --git a/v2v/parse_libvirt_xml.ml b/v2v/parse_libvirt_xml.ml
62f9b7
index fffc5a24..27e08135 100644
62f9b7
--- a/v2v/parse_libvirt_xml.ml
62f9b7
+++ b/v2v/parse_libvirt_xml.ml
62f9b7
@@ -270,9 +270,10 @@ let parse_libvirt_xml ?bandwidth ?conn xml =
62f9b7
 
62f9b7
       let format =
62f9b7
         match xpath_string "driver/@type" with
62f9b7
-        | Some "aio" -> Some "raw" (* Xen wierdness *)
62f9b7
-        | None -> None
62f9b7
-        | Some format -> Some format in
62f9b7
+        | Some "aio" -> "raw" (* Xen wierdness *)
62f9b7
+        | Some format -> format
62f9b7
+        | None ->
62f9b7
+           error (f_"<disk><driver type=\"format\"> attribute is missing from the libvirt XML") in
62f9b7
 
62f9b7
       (* The <disk type='...'> attribute may be 'block', 'file',
62f9b7
        * 'network' or 'volume'.  We ignore any other types.
62f9b7
@@ -339,7 +340,11 @@ let parse_libvirt_xml ?bandwidth ?conn xml =
62f9b7
           let xpath_string = Xpath_helpers.xpath_string xpathctx in
62f9b7
 
62f9b7
           (* Use the format specified in the volume itself. *)
62f9b7
-          let format = xpath_string "/volume/target/format/@type" in
62f9b7
+          let format =
62f9b7
+            match xpath_string "/volume/target/format/@type" with
62f9b7
+            | Some format -> format
62f9b7
+            | None ->
62f9b7
+               error (f_"<volume><target>.<format type=\"format\"> attribute is missing from the libvirt XML of volume %s") vol in
62f9b7
 
62f9b7
           (match xpath_string "/volume/@type" with
62f9b7
           | None | Some "file" ->
62f9b7
diff --git a/v2v/parse_ovf_from_ova.ml b/v2v/parse_ovf_from_ova.ml
62f9b7
index 758718a2..bc795166 100644
62f9b7
--- a/v2v/parse_ovf_from_ova.ml
62f9b7
+++ b/v2v/parse_ovf_from_ova.ml
62f9b7
@@ -157,7 +157,7 @@ and parse_disks xpathctx =
62f9b7
         source_disk = {
62f9b7
           s_disk_id = i;
62f9b7
           s_qemu_uri = "";
62f9b7
-          s_format = Some "vmdk";
62f9b7
+          s_format = "vmdk";
62f9b7
           s_controller = controller;
62f9b7
         };
62f9b7
         href = href;
62f9b7
diff --git a/v2v/types.ml b/v2v/types.ml
62f9b7
index 53daefed..e04bfacf 100644
62f9b7
--- a/v2v/types.ml
62f9b7
+++ b/v2v/types.ml
62f9b7
@@ -56,7 +56,7 @@ and source_firmware =
62f9b7
 and source_disk = {
62f9b7
   s_disk_id : int;
62f9b7
   s_qemu_uri : string;
62f9b7
-  s_format : string option;
62f9b7
+  s_format : string;
62f9b7
   s_controller : s_controller option;
62f9b7
 }
62f9b7
 and s_controller = Source_IDE | Source_SATA | Source_SCSI |
62f9b7
@@ -197,11 +197,8 @@ and string_of_source_firmware = function
62f9b7
 
62f9b7
 and string_of_source_disk { s_qemu_uri = qemu_uri; s_format = format;
62f9b7
                             s_controller = controller } =
62f9b7
-  sprintf "\t%s%s%s"
62f9b7
-    qemu_uri
62f9b7
-    (match format with
62f9b7
-    | None -> ""
62f9b7
-    | Some format -> " (" ^ format ^ ")")
62f9b7
+  sprintf "\t%s (%s)%s"
62f9b7
+    qemu_uri format
62f9b7
     (match controller with
62f9b7
     | None -> ""
62f9b7
     | Some controller -> " [" ^ string_of_controller controller ^ "]")
62f9b7
diff --git a/v2v/types.mli b/v2v/types.mli
62f9b7
index a9b0a70e..61a19eea 100644
62f9b7
--- a/v2v/types.mli
62f9b7
+++ b/v2v/types.mli
62f9b7
@@ -103,7 +103,7 @@ and source_firmware =
62f9b7
 and source_disk = {
62f9b7
   s_disk_id : int;                      (** A unique ID for each source disk. *)
62f9b7
   s_qemu_uri : string;                  (** QEMU URI of source disk. *)
62f9b7
-  s_format : string option;             (** Format. *)
62f9b7
+  s_format : string;                    (** Format of source disk. *)
62f9b7
   s_controller : s_controller option;   (** Controller, eg. IDE, SCSI. *)
62f9b7
 }
62f9b7
 (** A source disk. *)
62f9b7
diff --git a/v2v/v2v.ml b/v2v/v2v.ml
62f9b7
index 8af86687..203b93f1 100644
62f9b7
--- a/v2v/v2v.ml
62f9b7
+++ b/v2v/v2v.ml
62f9b7
@@ -293,12 +293,11 @@ and create_overlays source_disks =
62f9b7
        * should allow us to fstrim/blkdiscard and avoid copying
62f9b7
        * significant parts of the data over the wire.
62f9b7
        *)
62f9b7
-      let options =
62f9b7
-        "compat=1.1" ^
62f9b7
-          (match format with None -> ""
62f9b7
-                           | Some fmt -> ",backing_fmt=" ^ fmt) in
62f9b7
-      let cmd = [ "qemu-img"; "create"; "-q"; "-f"; "qcow2"; "-b"; qemu_uri;
62f9b7
-                  "-o"; options; overlay_file ] in
62f9b7
+      let cmd = [ "qemu-img"; "create"; "-q";
62f9b7
+                  "-o"; "compat=1.1";
62f9b7
+                  "-b"; qemu_uri; "-F"; format;
62f9b7
+                  "-f"; "qcow2";
62f9b7
+                  overlay_file ] in
62f9b7
       if run_command cmd <> 0 then
62f9b7
         error (f_"qemu-img command failed, see earlier errors");
62f9b7
 
62f9b7
@@ -344,7 +343,7 @@ and populate_overlays g overlays =
62f9b7
 and populate_disks g source_disks =
62f9b7
   List.iter (
62f9b7
     fun ({s_qemu_uri = qemu_uri; s_format = format}) ->
62f9b7
-      g#add_drive_opts qemu_uri ?format ~cachemode:"unsafe"
62f9b7
+      g#add_drive_opts qemu_uri ~format ~cachemode:"unsafe"
62f9b7
                           ~discard:"besteffort"
62f9b7
   ) source_disks
62f9b7
 
62f9b7
@@ -604,11 +603,7 @@ and get_target_formats cmdline output overlays =
62f9b7
         | None ->
62f9b7
            match cmdline.output_format with
62f9b7
            | Some format -> format
62f9b7
-           | None ->
62f9b7
-              match ov.ov_source.s_format with
62f9b7
-              | Some format -> format
62f9b7
-              | None ->
62f9b7
-                 error (f_"disk %s (%s) has no defined format.\n\nThe input metadata did not define the disk format (eg. raw/qcow2/etc) of this disk, and so virt-v2v will try to autodetect the format when reading it.\n\nHowever because the input format was not defined, we do not know what output format you want to use.  You have two choices: either define the original format in the source metadata, or use the ‘-of’ option to force the output format.") ov.ov_sd ov.ov_source.s_qemu_uri in
62f9b7
+           | None -> ov.ov_source.s_format in
62f9b7
 
62f9b7
       (* What really happens here is that the call to #disk_create
62f9b7
        * below fails if the format is not raw or qcow2.  We would