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

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