Laszlo Ersek
2022-Jan-06 14:09 UTC
[Libguestfs] [v2v PATCH 9/9] convert: determine machine type and virtio-1.0 from osinfo for x86 guests
Determine the machine type and virtio-1.0 support from osinfo, for x86 guests. This connects the previous two parts of this series. Keep the original logic from commit ac39fa292c31 ("v2v: Set machine type explicitly for outputs which support it (RHBZ#1581428).", 2020-12-04) for non-x86 guests, and for the case when libosinfo does not recognize the guest OS. Update the "cdrom", "floppy", and "i-ova" test cases, which all use a (phony) Windows 7 image -- Windows 7 does not support virtio-1.0-only devices, according to libosinfo. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1942325 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- Notes: (1) The patch duplicates the following control structure between "convert_linux.ml" and "convert_windows.ml": arch: i386 or x86_64 grab OS device list from libosinfo success: debug-log device list determine machine type (q35 vs. i440fx) from device list determine virtio-1.0 support from device list not found: FALL BACK TO PRE-EXISTENT LOGIC assume "virtio-1.0: yes" arch: something else machine type: pick Virt assume "virtio-1.0: yes" All of this could be factored out to another helper function (the only difference between the Linux and Windows conversion is the "PRE-EXISTENT LOGIC"). However, I couldn't find a good spot for this. "lib/utils.mli" is too low-level, I think, whereas "convert/libosinfo_utils.mli" is not appropriate: the control structure above does not use libosinfo at all if the architecture differs from x86. (2) When converting a RHEL-5.11 guest, the log contains the following: > libosinfo: loaded OS: http://redhat.com/rhel/5.11 > libosinfo devices for OS "rhel5.11": > http://pcisig.com/pci/8086/2668 | Intel Corporation | 8086 | 82801FB/FBM/FR/FW/FRW (ICH6 Family) High Definition Audio Controller | 2668 | ich6 | audio | pci | > http://pcisig.com/pci/1af4/1001 | Red Hat, Inc. | 1af4 | Virtio block device | 1001 | virtio-block | block | pci | > http://pcisig.com/pci/1af4/1000 | Red Hat, Inc. | 1af4 | Virtio network device | 1000 | virtio-net | net | pci | > gcaps_block_bus = virtio-blk > gcaps_net_bus = virtio-net > gcaps_virtio_rng = false > gcaps_virtio_balloon = true > gcaps_isa_pvpanic = false > gcaps_virtio_socket = false > gcaps_machine = i440fx > gcaps_arch = x86_64 > gcaps_acpi = true > gcaps_virtio_1_0 = false Note that the device list does *not* contain the Q35 chipset, therefore we can expect the machine type to flip from Q35 to I440FX, rather than just the virtio model flipping from virtio to virtio-transitional. (2.1) Accordingly, the JSON output changes as follows: > @@ -11,7 +11,7 @@ > "apic", > "vmport" > ], > - "machine": "q35", > + "machine": "pc", > "disks": [ > { > "dev": "vda", > @@ -39,14 +39,14 @@ > "block-bus": "virtio-blk", > "net-bus": "virtio-net", > "video": "vga", > - "machine": "q35", > + "machine": "i440fx", > "arch": "x86_64", > "virtio-rng": false, > "virtio-balloon": true, > "isa-pvpanic": false, > "virtio-socket": false, > "acpi": true, > - "virtio-1-0": true > + "virtio-1-0": false > }, > "sound": { > "model": "ich6" (2.2) The generated domain XML changes as follows: > @@ -15,7 +15,7 @@ > <apic/> > </features> > <os> > - <type arch='x86_64' machine='q35'>hvm</type> > + <type arch='x86_64' machine='pc'>hvm</type> > </os> > <on_poweroff>destroy</on_poweroff> > <on_reboot>restart</on_reboot> > @@ -28,7 +28,7 @@ > </disk> > <disk device='cdrom' type='file'> > <driver name='qemu' type='raw'/> > - <target dev='sda' bus='sata'/> > + <target dev='hda' bus='ide'/> > </disk> > <interface type='bridge'> > <source bridge='virbr0'/> (2.3) The domain XML, completed by libvirtd, changes as follows: > @@ -10,7 +10,7 @@ > <currentMemory unit='KiB'>1048576</currentMemory> > <vcpu placement='static'>1</vcpu> > <os> > - <type arch='x86_64' machine='pc-q35-6.1'>hvm</type> > + <type arch='x86_64' machine='pc-i440fx-6.1'>hvm</type> > <boot dev='hd'/> > </os> > <features> > @@ -30,60 +30,26 @@ > <driver name='qemu' type='raw'/> > <source pool='default' volume='converted-sda'/> > <target dev='vda' bus='virtio'/> > - <address type='pci' domain='0x0000' bus='0x05' slot='0x00' function='0x0'/> > + <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/> > </disk> > <disk type='file' device='cdrom'> > <driver name='qemu' type='raw'/> > - <target dev='sda' bus='sata'/> > + <target dev='hda' bus='ide'/> > <readonly/> > <address type='drive' controller='0' bus='0' target='0' unit='0'/> > </disk> > - <controller type='usb' index='0' model='qemu-xhci'> > - <address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/> > + <controller type='usb' index='0' model='piix3-uhci'> > + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> > </controller> > - <controller type='sata' index='0'> > - <address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/> > - </controller> > - <controller type='pci' index='0' model='pcie-root'/> > - <controller type='pci' index='1' model='pcie-root-port'> > - <model name='pcie-root-port'/> > - <target chassis='1' port='0x10'/> > - <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0' multifunction='on'/> > - </controller> > - <controller type='pci' index='2' model='pcie-root-port'> > - <model name='pcie-root-port'/> > - <target chassis='2' port='0x11'/> > - <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x1'/> > - </controller> > - <controller type='pci' index='3' model='pcie-to-pci-bridge'> > - <model name='pcie-pci-bridge'/> > - <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/> > - </controller> > - <controller type='pci' index='4' model='pcie-root-port'> > - <model name='pcie-root-port'/> > - <target chassis='4' port='0x12'/> > - <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x2'/> > - </controller> > - <controller type='pci' index='5' model='pcie-root-port'> > - <model name='pcie-root-port'/> > - <target chassis='5' port='0x13'/> > - <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x3'/> > - </controller> > - <controller type='pci' index='6' model='pcie-root-port'> > - <model name='pcie-root-port'/> > - <target chassis='6' port='0x14'/> > - <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x4'/> > - </controller> > - <controller type='pci' index='7' model='pcie-root-port'> > - <model name='pcie-root-port'/> > - <target chassis='7' port='0x15'/> > - <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x5'/> > + <controller type='pci' index='0' model='pci-root'/> > + <controller type='ide' index='0'> > + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> > </controller> > <interface type='bridge'> > <mac address='52:54:00:6c:97:64'/> > <source bridge='virbr0'/> > <model type='virtio'/> > - <address type='pci' domain='0x0000' bus='0x02' slot='0x00' function='0x0'/> > + <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> > </interface> > <serial type='pty'> > <target type='isa-serial' port='0'> > @@ -102,15 +68,15 @@ > <listen type='address'/> > </graphics> > <sound model='ich6'> > - <address type='pci' domain='0x0000' bus='0x03' slot='0x01' function='0x0'/> > + <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> > </sound> > <audio id='1' type='spice'/> > <video> > <model type='vga' vram='16384' heads='1' primary='yes'/> > - <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/> > + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> > </video> > <memballoon model='virtio'> > - <address type='pci' domain='0x0000' bus='0x06' slot='0x00' function='0x0'/> > + <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/> > </memballoon> > </devices> > </domain> (2.4) The converted RHEL-5.11 guest actually boots. (3) When converting a RHEL-6.10 guest, the log contains: > libosinfo: loaded OS: http://redhat.com/rhel/6.10 > libosinfo devices for OS "rhel6.10": > http://pcisig.com/pci/8086/2668 | Intel Corporation | 8086 | 82801FB/FBM/FR/FW/FRW (ICH6 Family) High Definition Audio Controller | 2668 | ich6 | audio | pci | > http://usb.org/usb/80ee/0021 | VirtualBox | 80ee | USB Tablet | 0021 | tablet | input | usb | > http://pcisig.com/pci/1af4/1003 | Red Hat, Inc. | 1af4 | Virtio console | 1003 | virtio-console | console | pci | > http://pcisig.com/pci/8086/293e | Intel Corporation | 8086 | 82801I (ICH9 Family) HD Audio Controller | 293e | ich9-hda | audio | pci | > http://qemu.org/chipset/x86/q35 | | | | | qemu-x86-q35 | chipset | | > http://pcisig.com/pci/1af4/1000 | Red Hat, Inc. | 1af4 | Virtio network device | 1000 | virtio-net | net | pci | > http://pcisig.com/pci/8086/10d3 | Intel Corporation | 8086 | 82574L Gigabit Network Connection | 10d3 | e1000e | net | pci | > http://pcisig.com/pci/1af4/1001 | Red Hat, Inc. | 1af4 | Virtio block device | 1001 | virtio-block | block | pci | > gcaps_block_bus = virtio-blk > gcaps_net_bus = virtio-net > gcaps_virtio_rng = true > gcaps_virtio_balloon = true > gcaps_isa_pvpanic = true > gcaps_virtio_socket = false > gcaps_machine = q35 > gcaps_arch = x86_64 > gcaps_acpi = true > gcaps_virtio_1_0 = false Refer to osinfo-db commit ae0add4d1b0f ("os: Add q35/ich9/e1000e to rhel6", 2018-10-11): https://gitlab.com/libosinfo/osinfo-db/-/commit/ae0add4d1b0f (3.1) The JSON output changes as follows (note the machine type in the context): > @@ -42,15 +42,15 @@ > "machine": "q35", > "arch": "x86_64", > "virtio-rng": true, > "virtio-balloon": true, > "isa-pvpanic": true, > "virtio-socket": false, > "acpi": true, > - "virtio-1-0": true > + "virtio-1-0": false > }, > "sound": { > "model": "ich6" > }, > "display": { > "type": "spice" > }, (3.2) The generated domain XML changes like this (note the machine type in the context): > @@ -18,35 +18,35 @@ > <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='volume' device='disk'> > + <disk type='volume' device='disk' model='virtio-transitional'> > <driver name='qemu' type='raw'/> > <source pool='default' volume='converted-sda'/> > <target dev='vda' bus='virtio'/> > </disk> > <disk device='cdrom' type='file'> > <driver name='qemu' type='raw'/> > <target dev='sda' bus='sata'/> > </disk> > <interface type='bridge'> > <source bridge='virbr0'/> > - <model type='virtio'/> > + <model type='virtio-transitional'/> > <mac address='52:54:00:3f:89:f8'/> > </interface> > <video> > <model type='vga' vram='16384' heads='1'/> > </video> > <graphics type='spice' autoport='yes' port='-1'/> > <sound model='ich6'/> > - <rng model='virtio'> > + <rng model='virtio-transitional'> > <backend model='random'>/dev/urandom</backend> > </rng> > - <memballoon model='virtio'/> > + <memballoon model='virtio-transitional'/> > <panic model='isa'> > <address type='isa' iobase='0x505'/> > </panic> > <viosock model='none'/> > <input type='tablet' bus='usb'/> > <input type='mouse' bus='ps2'/> (3.3) The domain XML, completed by libvirtd, changes as follows: > @@ -26,11 +26,11 @@ > <on_crash>restart</on_crash> > <devices> > <emulator>/usr/bin/qemu-system-x86_64</emulator> > - <disk type='volume' device='disk'> > + <disk type='volume' device='disk' model='virtio-transitional'> > <driver name='qemu' type='raw'/> > <source pool='default' volume='converted-sda'/> > <target dev='vda' bus='virtio'/> > - <address type='pci' domain='0x0000' bus='0x05' slot='0x00' function='0x0'/> > + <address type='pci' domain='0x0000' bus='0x02' slot='0x03' function='0x0'/> > </disk> > <disk type='file' device='cdrom'> > <driver name='qemu' type='raw'/> > @@ -39,7 +39,7 @@ > <address type='drive' controller='0' bus='0' target='0' unit='0'/> > </disk> > <controller type='usb' index='0' model='qemu-xhci'> > - <address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/> > + <address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/> > </controller> > <controller type='sata' index='0'> > <address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/> > @@ -50,45 +50,25 @@ > <target chassis='1' port='0x10'/> > <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0' multifunction='on'/> > </controller> > - <controller type='pci' index='2' model='pcie-root-port'> > - <model name='pcie-root-port'/> > - <target chassis='2' port='0x11'/> > - <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x1'/> > - </controller> > - <controller type='pci' index='3' model='pcie-to-pci-bridge'> > + <controller type='pci' index='2' model='pcie-to-pci-bridge'> > <model name='pcie-pci-bridge'/> > <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/> > </controller> > + <controller type='pci' index='3' model='pcie-root-port'> > + <model name='pcie-root-port'/> > + <target chassis='3' port='0x11'/> > + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x1'/> > + </controller> > <controller type='pci' index='4' model='pcie-root-port'> > <model name='pcie-root-port'/> > <target chassis='4' port='0x12'/> > <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x2'/> > </controller> > - <controller type='pci' index='5' model='pcie-root-port'> > - <model name='pcie-root-port'/> > - <target chassis='5' port='0x13'/> > - <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x3'/> > - </controller> > - <controller type='pci' index='6' model='pcie-root-port'> > - <model name='pcie-root-port'/> > - <target chassis='6' port='0x14'/> > - <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x4'/> > - </controller> > - <controller type='pci' index='7' model='pcie-root-port'> > - <model name='pcie-root-port'/> > - <target chassis='7' port='0x15'/> > - <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x5'/> > - </controller> > - <controller type='pci' index='8' model='pcie-root-port'> > - <model name='pcie-root-port'/> > - <target chassis='8' port='0x16'/> > - <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x6'/> > - </controller> > <interface type='bridge'> > <mac address='52:54:00:3f:89:f8'/> > <source bridge='virbr0'/> > - <model type='virtio'/> > - <address type='pci' domain='0x0000' bus='0x02' slot='0x00' function='0x0'/> > + <model type='virtio-transitional'/> > + <address type='pci' domain='0x0000' bus='0x02' slot='0x01' function='0x0'/> > </interface> > <serial type='pty'> > <target type='isa-serial' port='0'> > @@ -107,19 +87,19 @@ > <listen type='address'/> > </graphics> > <sound model='ich6'> > - <address type='pci' domain='0x0000' bus='0x03' slot='0x01' function='0x0'/> > + <address type='pci' domain='0x0000' bus='0x02' slot='0x02' function='0x0'/> > </sound> > <audio id='1' type='spice'/> > <video> > <model type='vga' vram='16384' heads='1' primary='yes'/> > <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/> > </video> > - <memballoon model='virtio'> > - <address type='pci' domain='0x0000' bus='0x06' slot='0x00' function='0x0'/> > + <memballoon model='virtio-transitional'> > + <address type='pci' domain='0x0000' bus='0x02' slot='0x04' function='0x0'/> > </memballoon> > - <rng model='virtio'> > + <rng model='virtio-transitional'> > <backend model='random'>/dev/urandom</backend> > - <address type='pci' domain='0x0000' bus='0x07' slot='0x00' function='0x0'/> > + <address type='pci' domain='0x0000' bus='0x02' slot='0x05' function='0x0'/> > </rng> > <panic model='isa'> > <address type='isa' iobase='0x505'/> Which can be summarized like below: - The model of all four virtio devices has changed from virtio to virtio-transitional (the fifth device, virtio-socket, is not supported at all). - The PCIe root ports providing bus numbers 2, 5, 6, 7, originally hosting the virtio devices, have been removed. The virtio devices have been moved to slots of "pcie-to-pci-bridge". - The (empty) PCIe root port providing bus number 8, has been removed. (This likely used to exist for hotplug purposes.) - "pcie-to-pci-bridge" now provides bus number 2, not 3. - The qemu-xhci device has been moved from the PCIe root port providing bus number 4 to a brand new port, providing bus number 3. The port providing bus number 4 is now empty (likely preserved for hotplug purposes). - The ich6 device has been kept on "pcie-to-pci-bridge", just relocated to a different slot. (3.4) The converted RHEL-6.10 guest actually boots. (4) When converting a RHEL-7.9 guest, the log contains: > libosinfo: loaded OS: http://redhat.com/rhel/7.9 > libosinfo devices for OS "rhel7.9": > http://pcisig.com/pci/1af4/1041 | Red Hat, Inc. | 1af4 | Virtio network device | 1041 | virtio1.0-net | net | pci | > http://pcisig.com/pci/8086/293e | Intel Corporation | 8086 | 82801I (ICH9 Family) HD Audio Controller | 293e | ich9-hda | audio | pci | > http://pcisig.com/pci/1033/0194 | NEC Corporation | 1033 | uPD720200 USB 3.0 Host Controller | 0194 | nec-xhci | controller.usb | pci | > http://pcisig.com/pci/1b36/0100 | Red Hat, Inc. | 1b36 | QXL paravirtual graphic card | 0100 | qxl | video | pci | > http://pcisig.com/pci/8086/2668 | Intel Corporation | 8086 | 82801FB/FBM/FR/FW/FRW (ICH6 Family) High Definition Audio Controller | 2668 | ich6 | audio | pci | > http://pcisig.com/pci/1af4/1003 | Red Hat, Inc. | 1af4 | Virtio console | 1003 | virtio-console | console | pci | > http://pcisig.com/pci/1af4/1049 | Red Hat, Inc. | 1af4 | Virtio filesystem | 1049 | virtio1.0-9p | filesystem | pci | > http://pcisig.com/pci/1af4/1000 | Red Hat, Inc. | 1af4 | Virtio network device | 1000 | virtio-net | net | pci | > http://pcisig.com/pci/1af4/1043 | Red Hat, Inc. | 1af4 | Virtio console | 1043 | virtio1.0-console | console | pci | > http://qemu.org/chipset/x86/q35 | | | | | qemu-x86-q35 | chipset | | > http://usb.org/usb/80ee/0021 | VirtualBox | 80ee | USB Tablet | 0021 | tablet | input | usb | > http://pcisig.com/pci/1af4/1005 | Red Hat, Inc. | 1af4 | Virtio RNG | 1005 | virtio-rng | rng | pci | > http://pcisig.com/pci/8086/10d3 | Intel Corporation | 8086 | 82574L Gigabit Network Connection | 10d3 | e1000e | net | pci | > http://pcisig.com/pci/1af4/1048 | Red Hat, Inc. | 1af4 | Virtio SCSI | 1048 | virtio1.0-scsi | block | pci | > http://pcisig.com/pci/8086/2415 | Intel Corporation | 8086 | 82801AA AC'97 Audio Controller | 2415 | ac97 | audio | pci | > http://pcisig.com/pci/1af4/1045 | Red Hat, Inc. | 1af4 | Virtio memory balloon | 1045 | virtio1.0-balloon | memory.balloon | pci | > http://pcisig.com/pci/1af4/1042 | Red Hat, Inc. | 1af4 | Virtio block device | 1042 | virtio1.0-block | block | pci | > http://pcisig.com/pci/1b36/0004 | Red Hat, Inc. | 1b36 | QEMU PCI Quad-port 16550A Adapter | 0004 | qemu-xhci | controller.usb | pci | > http://pcisig.com/pci/1af4/1001 | Red Hat, Inc. | 1af4 | Virtio block device | 1001 | virtio-block | block | pci | > http://pcisig.com/pci/1af4/1052 | Red Hat, Inc. | 1af4 | Virtio input | 1052 | virtio1.0-input | input | pci | > http://pcisig.com/pci/1af4/1044 | Red Hat, Inc. | 1af4 | Virtio RNG | 1044 | virtio1.0-rng | rng | pci | > gcaps_block_bus = virtio-blk > gcaps_net_bus = virtio-net > gcaps_virtio_rng = true > gcaps_virtio_balloon = true > gcaps_isa_pvpanic = true > gcaps_virtio_socket = false > gcaps_machine = q35 > gcaps_arch = x86_64 > gcaps_acpi = true > gcaps_virtio_1_0 = true Note the presence of both "qemu-x86-q35" ("http://qemu.org/chipset/x86/q35") and "virtio1.0-net" ("http://pcisig.com/pci/1af4/1041"). (4.1) None of the JSON output, the generated libvirt XML, and the completed (imported by libvirtd) domain XML change. (4.2) The converted RHEL-7.9 guest continues booting. convert/convert_linux.ml | 51 ++++++++++++-------- convert/convert_windows.ml | 32 ++++++++---- tests/test-v2v-cdrom.expected | 2 +- tests/test-v2v-floppy.expected | 2 +- tests/test-v2v-i-ova.xml | 8 +-- 5 files changed, 60 insertions(+), 35 deletions(-) diff --git a/convert/convert_linux.ml b/convert/convert_linux.ml index 3f1114ad155d..45ce069ad9bf 100644 --- a/convert/convert_linux.ml +++ b/convert/convert_linux.ml @@ -123,26 +123,39 @@ let convert (g : G.guestfs) source inspect keep_serial_console _ SELinux_relabel.relabel g; - (* Pivot on the year 2007. Any Linux distro from earlier than - * 2007 should use i440fx, anything 2007 or newer should use q35. - * XXX Look up this information in libosinfo in future. - *) - let machine - match inspect.i_arch, inspect.i_distro, inspect.i_major_version with - | ("i386"|"x86_64"), "fedora", _ -> Q35 - | ("i386"|"x86_64"), ("rhel"|"centos"|"scientificlinux"| - "redhat-based"|"oraclelinux"), major -> - if major <= 4 then I440FX else Q35 - | ("i386"|"x86_64"), ("sles"|"suse-based"|"opensuse"), major -> - if major < 10 then I440FX else Q35 - | ("i386"|"x86_64"), ("debian"|"ubuntu"|"linuxmint"| - "kalilinux"), major -> - if major < 4 then I440FX else Q35 + let machine, virtio_1_0 + match inspect.i_arch with + | ("i386"|"x86_64") -> + (try + 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 + (Libosinfo_utils.string_of_osinfo_device_list devices); + let { Libosinfo_utils.q35; vio10 } + Libosinfo_utils.os_support_of_osinfo_device_list devices in + (if q35 then Q35 else I440FX), vio10 + with + | Not_found -> + (* Pivot on the year 2007. Any Linux distro from earlier than 2007 + * should use i440fx, anything 2007 or newer should use q35. + *) + (match inspect.i_distro, inspect.i_major_version with + | "fedora", _ -> Q35 + | ("rhel"|"centos"|"scientificlinux"|"redhat-based"|"oraclelinux"), + major -> + if major <= 4 then I440FX else Q35 + | ("sles"|"suse-based"|"opensuse"), major -> + if major < 10 then I440FX else Q35 + | ("debian"|"ubuntu"|"linuxmint"|"kalilinux"), major -> + if major < 4 then I440FX else Q35 - (* reasonable default for all modern Linux kernels *) - | ("i386"|"x86_64"), _, _ -> Q35 + (* reasonable default for all modern Linux kernels *) + | _, _ -> Q35 + ), true + ) - | _ -> Virt in + | _ -> Virt, true + in (* Return guest capabilities from the convert () function. *) let guestcaps = { @@ -155,7 +168,7 @@ let convert (g : G.guestfs) source inspect keep_serial_console _ gcaps_machine = machine; gcaps_arch = Utils.kvm_arch inspect.i_arch; gcaps_acpi = acpi; - gcaps_virtio_1_0 = true; + gcaps_virtio_1_0 = virtio_1_0; } in guestcaps diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml index 30e494ea02cb..1c2d17f26543 100644 --- a/convert/convert_windows.ml +++ b/convert/convert_windows.ml @@ -238,15 +238,27 @@ let convert (g : G.guestfs) _ inspect _ static_ips 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."); ); - (* 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. - * XXX Look up this information in libosinfo in future. - *) - let machine - match inspect.i_arch, inspect.i_major_version with - | ("i386"|"x86_64"), major -> if major < 6 then I440FX else Q35 - | _ -> Virt in + let machine, virtio_1_0 + match inspect.i_arch with + | ("i386"|"x86_64") -> + (try + 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 + (Libosinfo_utils.string_of_osinfo_device_list devices); + let { Libosinfo_utils.q35; vio10 } + Libosinfo_utils.os_support_of_osinfo_device_list devices 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. + *) + (if inspect.i_major_version < 6 then I440FX else Q35), true + ) + | _ -> Virt, true + in (* Return guest capabilities from the convert () function. *) let guestcaps = { @@ -259,7 +271,7 @@ let convert (g : G.guestfs) _ inspect _ static_ips gcaps_machine = machine; gcaps_arch = Utils.kvm_arch inspect.i_arch; gcaps_acpi = true; - gcaps_virtio_1_0 = true; + gcaps_virtio_1_0 = virtio_1_0; } in guestcaps diff --git a/tests/test-v2v-cdrom.expected b/tests/test-v2v-cdrom.expected index 17bd152d8e64..b950492969c8 100644 --- a/tests/test-v2v-cdrom.expected +++ b/tests/test-v2v-cdrom.expected @@ -1,4 +1,4 @@ - <disk type='file' device='disk'> + <disk type='file' device='disk' model='virtio-transitional'> <driver name='qemu' type='raw'/> <target dev='vda' bus='virtio'/> </disk> diff --git a/tests/test-v2v-floppy.expected b/tests/test-v2v-floppy.expected index a718c21f94dd..f4b679540c9d 100644 --- a/tests/test-v2v-floppy.expected +++ b/tests/test-v2v-floppy.expected @@ -1,4 +1,4 @@ - <disk type='file' device='disk'> + <disk type='file' device='disk' model='virtio-transitional'> <driver name='qemu' type='raw'/> <target dev='vda' bus='virtio'/> </disk> diff --git a/tests/test-v2v-i-ova.xml b/tests/test-v2v-i-ova.xml index 9f3c1974243f..2b6a8de0f432 100644 --- a/tests/test-v2v-i-ova.xml +++ b/tests/test-v2v-i-ova.xml @@ -21,7 +21,7 @@ <on_reboot>restart</on_reboot> <on_crash>restart</on_crash> <devices> - <disk type='file' device='disk'> + <disk type='file' device='disk' model='virtio-transitional'> <driver name='qemu' type='raw'/> <source file='TestOva-sda'/> <target dev='vda' bus='virtio'/> @@ -36,16 +36,16 @@ </disk> <interface type='bridge'> <source bridge='VM Network'/> - <model type='virtio'/> + <model type='virtio-transitional'/> </interface> <video> <model type='vga' vram='16384' heads='1'/> </video> <graphics type='vnc' autoport='yes' port='-1'/> - <rng model='virtio'> + <rng model='virtio-transitional'> <backend model='random'>/dev/urandom</backend> </rng> - <memballoon model='virtio'/> + <memballoon model='virtio-transitional'/> <viosock model='none'/> <input type='tablet' bus='usb'/> <input type='mouse' bus='ps2'/> -- 2.19.1.3.g30247aa5d201
Richard W.M. Jones
2022-Jan-06 15:10 UTC
[Libguestfs] [v2v PATCH 9/9] convert: determine machine type and virtio-1.0 from osinfo for x86 guests
This one looks fine, ACK No need to post v2. Fix anything I noted if you want. It'd be nice to get this into RHEL 9 by the end of this week. If you can push it later today or tomorrow then I can add it. Coincidentally I was just doing a RHEL 9 release right this moment, but I won't continue with that for now. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org