Blame SOURCES/0009-convert-determine-machine-type-and-virtio-1.0-from-o.patch

3156cb
From f0cea012d0183edf6f7b769c28d5038593f3fe6a Mon Sep 17 00:00:00 2001
3156cb
From: Laszlo Ersek <lersek@redhat.com>
3156cb
Date: Thu, 6 Jan 2022 15:09:10 +0100
3156cb
Subject: [PATCH] convert: determine machine type and virtio-1.0 from osinfo
3156cb
 for x86 guests
3156cb
3156cb
Determine the machine type and virtio-1.0 support from osinfo, for x86
3156cb
guests. This connects the previous two parts of this series.
3156cb
3156cb
Keep the original logic from commit ac39fa292c31 ("v2v: Set machine type
3156cb
explicitly for outputs which support it (RHBZ#1581428).", 2020-12-04) for
3156cb
non-x86 guests, and for the case when libosinfo does not recognize the
3156cb
guest OS.
3156cb
3156cb
Update the "cdrom", "floppy", and "i-ova" test cases, which all use a
3156cb
(phony) Windows 7 image -- Windows 7 does not support virtio-1.0-only
3156cb
devices, according to libosinfo.
3156cb
3156cb
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1942325
3156cb
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
3156cb
Message-Id: <20220106140910.13695-10-lersek@redhat.com>
3156cb
Acked-by: Richard W.M. Jones <rjones@redhat.com>
3156cb
---
3156cb
 convert/convert_linux.ml       | 51 +++++++++++++++++++++-------------
3156cb
 convert/convert_windows.ml     | 32 ++++++++++++++-------
3156cb
 tests/test-v2v-cdrom.expected  |  2 +-
3156cb
 tests/test-v2v-floppy.expected |  2 +-
3156cb
 tests/test-v2v-i-ova.xml       |  8 +++---
3156cb
 5 files changed, 60 insertions(+), 35 deletions(-)
3156cb
3156cb
diff --git a/convert/convert_linux.ml b/convert/convert_linux.ml
3156cb
index 3f1114ad..45ce069a 100644
3156cb
--- a/convert/convert_linux.ml
3156cb
+++ b/convert/convert_linux.ml
3156cb
@@ -123,26 +123,39 @@ let convert (g : G.guestfs) source inspect keep_serial_console _ =
3156cb
 
3156cb
     SELinux_relabel.relabel g;
3156cb
 
3156cb
-    (* Pivot on the year 2007.  Any Linux distro from earlier than
3156cb
-     * 2007 should use i440fx, anything 2007 or newer should use q35.
3156cb
-     * XXX Look up this information in libosinfo in future.
3156cb
-     *)
3156cb
-    let machine =
3156cb
-      match inspect.i_arch, inspect.i_distro, inspect.i_major_version with
3156cb
-      | ("i386"|"x86_64"), "fedora", _ -> Q35
3156cb
-      | ("i386"|"x86_64"), ("rhel"|"centos"|"scientificlinux"|
3156cb
-                            "redhat-based"|"oraclelinux"), major ->
3156cb
-         if major <= 4 then I440FX else Q35
3156cb
-      | ("i386"|"x86_64"), ("sles"|"suse-based"|"opensuse"), major ->
3156cb
-         if major < 10 then I440FX else Q35
3156cb
-      | ("i386"|"x86_64"), ("debian"|"ubuntu"|"linuxmint"|
3156cb
-                            "kalilinux"), major ->
3156cb
-         if major < 4 then I440FX else Q35
3156cb
+    let machine, virtio_1_0 =
3156cb
+      match inspect.i_arch with
3156cb
+      | ("i386"|"x86_64") ->
3156cb
+        (try
3156cb
+           let os = Libosinfo_utils.get_os_by_short_id inspect.i_osinfo in
3156cb
+           let devices = os#get_devices () in
3156cb
+           debug "libosinfo devices for OS \"%s\":\n%s" inspect.i_osinfo
3156cb
+             (Libosinfo_utils.string_of_osinfo_device_list devices);
3156cb
+           let { Libosinfo_utils.q35; vio10 } =
3156cb
+             Libosinfo_utils.os_support_of_osinfo_device_list devices in
3156cb
+           (if q35 then Q35 else I440FX), vio10
3156cb
+         with
3156cb
+         | Not_found ->
3156cb
+           (* Pivot on the year 2007.  Any Linux distro from earlier than 2007
3156cb
+            * should use i440fx, anything 2007 or newer should use q35.
3156cb
+            *)
3156cb
+           (match inspect.i_distro, inspect.i_major_version with
3156cb
+            | "fedora", _ -> Q35
3156cb
+            | ("rhel"|"centos"|"scientificlinux"|"redhat-based"|"oraclelinux"),
3156cb
+              major ->
3156cb
+              if major <= 4 then I440FX else Q35
3156cb
+            | ("sles"|"suse-based"|"opensuse"), major ->
3156cb
+              if major < 10 then I440FX else Q35
3156cb
+            | ("debian"|"ubuntu"|"linuxmint"|"kalilinux"), major ->
3156cb
+              if major < 4 then I440FX else Q35
3156cb
 
3156cb
-      (* reasonable default for all modern Linux kernels *)
3156cb
-      | ("i386"|"x86_64"), _, _ -> Q35
3156cb
+            (* reasonable default for all modern Linux kernels *)
3156cb
+            | _, _ -> Q35
3156cb
+           ), true
3156cb
+        )
3156cb
 
3156cb
-      | _ -> Virt in
3156cb
+      | _ -> Virt, true
3156cb
+    in
3156cb
 
3156cb
     (* Return guest capabilities from the convert () function. *)
3156cb
     let guestcaps = {
3156cb
@@ -155,7 +168,7 @@ let convert (g : G.guestfs) source inspect keep_serial_console _ =
3156cb
       gcaps_machine = machine;
3156cb
       gcaps_arch = Utils.kvm_arch inspect.i_arch;
3156cb
       gcaps_acpi = acpi;
3156cb
-      gcaps_virtio_1_0 = true;
3156cb
+      gcaps_virtio_1_0 = virtio_1_0;
3156cb
     } in
3156cb
 
3156cb
     guestcaps
3156cb
diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml
3156cb
index 30e494ea..1c2d17f2 100644
3156cb
--- a/convert/convert_windows.ml
3156cb
+++ b/convert/convert_windows.ml
3156cb
@@ -238,15 +238,27 @@ let convert (g : G.guestfs) _ inspect _ static_ips =
3156cb
         warning (f_"this guest has Anti-Virus (AV) software and a new virtio block device driver was installed.  In some circumstances, AV may prevent new drivers from working (resulting in a 7B boot error).  If this happens, try disabling AV before doing the conversion.");
3156cb
     );
3156cb
 
3156cb
-    (* Pivot on the year 2007.  Any Windows version from earlier than
3156cb
-     * 2007 should use i440fx, anything 2007 or newer should use q35.
3156cb
-     * Luckily this coincides almost exactly with the release of NT 6.
3156cb
-     * XXX Look up this information in libosinfo in future.
3156cb
-     *)
3156cb
-    let machine =
3156cb
-      match inspect.i_arch, inspect.i_major_version with
3156cb
-      | ("i386"|"x86_64"), major -> if major < 6 then I440FX else Q35
3156cb
-      | _ -> Virt in
3156cb
+    let machine, virtio_1_0 =
3156cb
+      match inspect.i_arch with
3156cb
+      | ("i386"|"x86_64") ->
3156cb
+        (try
3156cb
+           let os = Libosinfo_utils.get_os_by_short_id inspect.i_osinfo in
3156cb
+           let devices = os#get_devices () in
3156cb
+           debug "libosinfo devices for OS \"%s\":\n%s" inspect.i_osinfo
3156cb
+             (Libosinfo_utils.string_of_osinfo_device_list devices);
3156cb
+           let { Libosinfo_utils.q35; vio10 } =
3156cb
+             Libosinfo_utils.os_support_of_osinfo_device_list devices in
3156cb
+           (if q35 then Q35 else I440FX), vio10
3156cb
+         with
3156cb
+         | Not_found ->
3156cb
+           (* Pivot on the year 2007.  Any Windows version from earlier than
3156cb
+            * 2007 should use i440fx, anything 2007 or newer should use q35.
3156cb
+            * Luckily this coincides almost exactly with the release of NT 6.
3156cb
+            *)
3156cb
+           (if inspect.i_major_version < 6 then I440FX else Q35), true
3156cb
+        )
3156cb
+      | _ -> Virt, true
3156cb
+    in
3156cb
 
3156cb
     (* Return guest capabilities from the convert () function. *)
3156cb
     let guestcaps = {
3156cb
@@ -259,7 +271,7 @@ let convert (g : G.guestfs) _ inspect _ static_ips =
3156cb
       gcaps_machine = machine;
3156cb
       gcaps_arch = Utils.kvm_arch inspect.i_arch;
3156cb
       gcaps_acpi = true;
3156cb
-      gcaps_virtio_1_0 = true;
3156cb
+      gcaps_virtio_1_0 = virtio_1_0;
3156cb
     } in
3156cb
 
3156cb
     guestcaps
3156cb
diff --git a/tests/test-v2v-cdrom.expected b/tests/test-v2v-cdrom.expected
3156cb
index 17bd152d..b9504929 100644
3156cb
--- a/tests/test-v2v-cdrom.expected
3156cb
+++ b/tests/test-v2v-cdrom.expected
3156cb
@@ -1,4 +1,4 @@
3156cb
-    <disk type='file' device='disk'>
3156cb
+    <disk type='file' device='disk' model='virtio-transitional'>
3156cb
       <driver name='qemu' type='raw'/>
3156cb
       <target dev='vda' bus='virtio'/>
3156cb
     </disk>
3156cb
diff --git a/tests/test-v2v-floppy.expected b/tests/test-v2v-floppy.expected
3156cb
index a718c21f..f4b67954 100644
3156cb
--- a/tests/test-v2v-floppy.expected
3156cb
+++ b/tests/test-v2v-floppy.expected
3156cb
@@ -1,4 +1,4 @@
3156cb
-    <disk type='file' device='disk'>
3156cb
+    <disk type='file' device='disk' model='virtio-transitional'>
3156cb
       <driver name='qemu' type='raw'/>
3156cb
       <target dev='vda' bus='virtio'/>
3156cb
     </disk>
3156cb
diff --git a/tests/test-v2v-i-ova.xml b/tests/test-v2v-i-ova.xml
3156cb
index 9f3c1974..2b6a8de0 100644
3156cb
--- a/tests/test-v2v-i-ova.xml
3156cb
+++ b/tests/test-v2v-i-ova.xml
3156cb
@@ -21,7 +21,7 @@
3156cb
   <on_reboot>restart</on_reboot>
3156cb
   <on_crash>restart</on_crash>
3156cb
   <devices>
3156cb
-    <disk type='file' device='disk'>
3156cb
+    <disk type='file' device='disk' model='virtio-transitional'>
3156cb
       <driver name='qemu' type='raw'/>
3156cb
       <source file='TestOva-sda'/>
3156cb
       <target dev='vda' bus='virtio'/>
3156cb
@@ -36,16 +36,16 @@
3156cb
     </disk>
3156cb
     <interface type='bridge'>
3156cb
       <source bridge='VM Network'/>
3156cb
-      <model type='virtio'/>
3156cb
+      <model type='virtio-transitional'/>
3156cb
     </interface>
3156cb
     <video>
3156cb
       <model type='vga' vram='16384' heads='1'/>
3156cb
     </video>
3156cb
     <graphics type='vnc' autoport='yes' port='-1'/>
3156cb
-    <rng model='virtio'>
3156cb
+    <rng model='virtio-transitional'>
3156cb
       <backend model='random'>/dev/urandom</backend>
3156cb
     </rng>
3156cb
-    <memballoon model='virtio'/>
3156cb
+    <memballoon model='virtio-transitional'/>
3156cb
     <viosock model='none'/>
3156cb
     <input type='tablet' bus='usb'/>
3156cb
     <input type='mouse' bus='ps2'/>
3156cb
-- 
3156cb
2.31.1
3156cb