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

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