[Libguestfs] [v2v PATCH v2 7/7] convert/convert_windows: consult "best driver"'s dev list for virtio-1.0

Laszlo Ersek lersek at redhat.com
Tue Feb 1 12:32:19 UTC 2022


Life would be too simple if we could just call osinfo_os_get_all_devices()
for determining virtio-1.0 support for Windows guests. Now that we've
extracted the libosinfo logic that identifies the "best" virtio driver
(for copying its files into the guest), fetch the list of devices
supported by the same "best driver" as well. Use that list, in addition to
the one from osinfo_os_get_all_devices(), for determining (Q35 and)
virtio-1.0 support.

Thankfully this mess is not needed when converting Linux guests.

With this, we need to revert the data for three Windows-based test cases
to their pre-f0cea012d018 status (modulo intermediary commits 4f6b143c1cb3
("output: -o libvirt, qemu: Use correct device name for vsock",
2022-01-20) and 4c3d0b8b3b4b ("output: -o libvirt: Fix <graphics/> element
port/autoport", 2022-01-20)). The reason is that those tests all set the
VIRTIO_WIN environment variable, in which case we simply assume
"virtio_1_0 = true" on the fallback ("Not_found" exception) branch.

Fixes: f0cea012d0183edf6f7b769c28d5038593f3fe6a
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2043333
Signed-off-by: Laszlo Ersek <lersek at redhat.com>
---

Notes:
    v2:
    
    - mirror the behavior of "Windows_virtio.copy_drivers" exactly, with
      regard to:
    
      - the VIRTIO_WIN(_DIR) environment variables, and
    
      - "Libosinfo_utils.best_driver" not finding any matching driver.
    
      (The behavior upon "Libosinfo_utils.get_os_by_short_id" failing was
      consistent with "Windows_virtio.copy_drivers" in v1 already.)

 convert/windows_virtio.mli     |  6 +++++-
 convert/convert_windows.ml     | 26 +++++++++++++++++++++++---
 tests/test-v2v-cdrom.expected  |  2 +-
 tests/test-v2v-floppy.expected |  2 +-
 tests/test-v2v-i-ova.xml       |  8 ++++----
 5 files changed, 34 insertions(+), 10 deletions(-)

diff --git a/convert/windows_virtio.mli b/convert/windows_virtio.mli
index 53603d240553..a92cc01da6df 100644
--- a/convert/windows_virtio.mli
+++ b/convert/windows_virtio.mli
@@ -13,13 +13,17 @@
  *
  * You should have received a copy of the GNU General Public License along
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *)
 
-(** Functions for installing Windows virtio drivers. *)
+(** Values and functions for installing Windows virtio drivers. *)
+
+val virtio_win_from_env : bool
+(** [virtio_win_from_env] is true iff at least one of the VIRTIO_WIN and
+    VIRTIO_WIN_DIR variables is present in the environment. *)
 
 val install_drivers
     : Registry.t -> Types.inspect ->
       Types.guestcaps_block_type * Types.guestcaps_net_type * bool * bool * bool * bool
 (** [install_drivers reg inspect]
     installs virtio drivers from the driver directory or driver
diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml
index 1c2d17f26543..7bdcaf52f33c 100644
--- a/convert/convert_windows.ml
+++ b/convert/convert_windows.ml
@@ -239,18 +239,38 @@ let convert (g : G.guestfs) _ inspect _ static_ips =
     );
 
     let machine, virtio_1_0 =
       match inspect.i_arch with
       | ("i386"|"x86_64") ->
         (try
+           (* Fall back to the decision that's based on the year that the OS
+            * was released in under three circumstances:
+            * - the user specified the location of the Windows virtio drivers
+            *   through an environment variable, or
+            * - "Libosinfo_utils.get_os_by_short_id" fails to look up the OS,
+            *   or
+            * - "Libosinfo_utils.best_driver" cannot find any matching driver.
+            * In each of these cases, a "Not_found" exception is raised.  This
+            * behavior exactly mirrors that of "Windows_virtio.copy_drivers".
+            *)
+           if Windows_virtio.virtio_win_from_env then
+             raise Not_found;
            let os = Libosinfo_utils.get_os_by_short_id inspect.i_osinfo in
-           let devices = os#get_devices () in
-           debug "libosinfo devices for OS \"%s\":\n%s" inspect.i_osinfo
+           let devices = os#get_devices ()
+           and drivers = os#get_device_drivers () in
+           let best_drv_devs =
+             (Libosinfo_utils.best_driver drivers inspect.i_arch).devices in
+           debug "libosinfo internal devices for OS \"%s\":\n%s"
+             inspect.i_osinfo
              (Libosinfo_utils.string_of_osinfo_device_list devices);
+           debug "libosinfo \"best driver\" devices for OS \"%s\":\n%s"
+             inspect.i_osinfo
+             (Libosinfo_utils.string_of_osinfo_device_list best_drv_devs);
            let { Libosinfo_utils.q35; vio10 } =
-             Libosinfo_utils.os_support_of_osinfo_device_list devices in
+             Libosinfo_utils.os_support_of_osinfo_device_list
+               (devices @ best_drv_devs) in
            (if q35 then Q35 else I440FX), vio10
          with
          | Not_found ->
            (* Pivot on the year 2007.  Any Windows version from earlier than
             * 2007 should use i440fx, anything 2007 or newer should use q35.
             * Luckily this coincides almost exactly with the release of NT 6.
diff --git a/tests/test-v2v-cdrom.expected b/tests/test-v2v-cdrom.expected
index b950492969c8..17bd152d8e64 100644
--- a/tests/test-v2v-cdrom.expected
+++ b/tests/test-v2v-cdrom.expected
@@ -1,7 +1,7 @@
-    <disk type='file' device='disk' model='virtio-transitional'>
+    <disk type='file' device='disk'>
       <driver name='qemu' type='raw'/>
       <target dev='vda' bus='virtio'/>
     </disk>
     <disk device='cdrom' type='file'>
       <driver name='qemu' type='raw'/>
       <target dev='sdc' bus='sata'/>
diff --git a/tests/test-v2v-floppy.expected b/tests/test-v2v-floppy.expected
index f4b679540c9d..a718c21f94dd 100644
--- a/tests/test-v2v-floppy.expected
+++ b/tests/test-v2v-floppy.expected
@@ -1,7 +1,7 @@
-    <disk type='file' device='disk' model='virtio-transitional'>
+    <disk type='file' device='disk'>
       <driver name='qemu' type='raw'/>
       <target dev='vda' bus='virtio'/>
     </disk>
     <disk device='floppy' type='file'>
       <driver name='qemu' type='raw'/>
       <target dev='fda'/>
diff --git a/tests/test-v2v-i-ova.xml b/tests/test-v2v-i-ova.xml
index 1915dd40aff0..6b8cda62f051 100644
--- a/tests/test-v2v-i-ova.xml
+++ b/tests/test-v2v-i-ova.xml
@@ -18,13 +18,13 @@
     <type arch='x86_64' machine='q35'>hvm</type>
   </os>
   <on_poweroff>destroy</on_poweroff>
   <on_reboot>restart</on_reboot>
   <on_crash>restart</on_crash>
   <devices>
-    <disk type='file' device='disk' model='virtio-transitional'>
+    <disk type='file' device='disk'>
       <driver name='qemu' type='raw'/>
       <source file='TestOva-sda'/>
       <target dev='vda' bus='virtio'/>
     </disk>
     <disk device='cdrom' type='file'>
       <driver name='qemu' type='raw'/>
@@ -33,21 +33,21 @@
     <disk device='floppy' type='file'>
       <driver name='qemu' type='raw'/>
       <target dev='fda'/>
     </disk>
     <interface type='bridge'>
       <source bridge='VM Network'/>
-      <model type='virtio-transitional'/>
+      <model type='virtio'/>
     </interface>
     <video>
       <model type='vga' vram='16384' heads='1'/>
     </video>
     <graphics type='vnc' autoport='yes'/>
-    <rng model='virtio-transitional'>
+    <rng model='virtio'>
       <backend model='random'>/dev/urandom</backend>
     </rng>
-    <memballoon model='virtio-transitional'/>
+    <memballoon model='virtio'/>
     <input type='tablet' bus='usb'/>
     <input type='mouse' bus='ps2'/>
     <console type='pty'/>
   </devices>
 </domain>
-- 
2.19.1.3.g30247aa5d201



More information about the Libguestfs mailing list