public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH qemu-server v2 7/9] tree-wide: use HardwareConfig for the machine version checks
Date: Thu, 15 Oct 2026 10:10:29 +0200	[thread overview]
Message-ID: <20261015081041.743422-8-d.csapak@proxmox.com> (raw)
In-Reply-To: <20261015081041.743422-1-d.csapak@proxmox.com>

The HardwareConfig object already contains the machine version, and
its version_at_least records the required +pveX revision like the
version guard does. So use it for the machine version checks in the
functions that get it anyway, instead of also passing the machine
version, the machine type or the version guard there.

The revisions recorded by the object are merged into the version
guard at the end of config_to_command. For hotplug, the object is
built from the running machine, so the stub version guard for NICs is
not needed anymore. Drive hotplug now also uses that version instead
of falling back to the installed QEMU version, which does not
necessarily match the running one anyway.

The windows version in config_to_command is now also taken from the
object.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/PVE/API2/Qemu.pm              |   9 +-
 src/PVE/QemuServer.pm             | 155 ++++++++++--------------------
 src/PVE/QemuServer/Drive.pm       |   7 +-
 src/PVE/QemuServer/DriveDevice.pm |   9 +-
 src/PVE/QemuServer/USB.pm         |  10 +-
 5 files changed, 67 insertions(+), 123 deletions(-)

diff --git a/src/PVE/API2/Qemu.pm b/src/PVE/API2/Qemu.pm
index cfbc1f51..c5fb78f3 100644
--- a/src/PVE/API2/Qemu.pm
+++ b/src/PVE/API2/Qemu.pm
@@ -1071,8 +1071,13 @@ sub assert_scsi_feature_compatibility {
         $machine_type,
         PVE::QemuServer::Helpers::kvm_user_version(),
     );
-    my $drivetype =
-        PVE::QemuServer::Drive::get_scsi_device_type($drive, $storecfg, $machine_version);
+    my $hw_config = PVE::QemuServer::PCI::hardware_config(
+        $conf,
+        PVE::QemuServer::Helpers::get_vm_arch($conf),
+        PVE::QemuServer::DriveDevice::get_max_scsihw_index($conf),
+        $machine_version,
+    );
+    my $drivetype = PVE::QemuServer::Drive::get_scsi_device_type($drive, $storecfg, $hw_config);
 
     if ($drivetype ne 'hd' && $drivetype ne 'cd') {
         if ($drive->{product}) {
diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index a393db78..d6a5ed6b 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -1319,7 +1319,6 @@ sub print_netdevice_full {
         $netid,
         $use_old_bios_files,
         $hw_config,
-        $version_guard, # checks the machine version and records the required +pveX revision
         $host_mtu_migration, # force this value for host_mtu, 0 means force absence of param
     ) = @_;
 
@@ -1335,12 +1334,12 @@ sub print_netdevice_full {
         # and out of each queue plus one config interrupt and control vector queue
         my $vectors = $net->{queues} * 2 + 2;
         $tmpstr .= ",vectors=$vectors,mq=on";
-        if ($version_guard->(7, 1)) {
+        if ($hw_config->version_at_least(7, 1)) {
             $tmpstr .= ",packed=on";
         }
     }
 
-    if ($version_guard->(7, 1) && $net->{model} eq 'virtio') {
+    if ($hw_config->version_at_least(7, 1) && $net->{model} eq 'virtio') {
         $tmpstr .= ",rx_queue_size=1024,tx_queue_size=256";
     }
 
@@ -1370,7 +1369,7 @@ sub print_netdevice_full {
                 . " that the bridge is configured as desired.\n";
         }
 
-        if ($version_guard->(10, 0, 1) || $host_mtu_migration) {
+        if ($hw_config->version_at_least(10, 0, 1) || $host_mtu_migration) {
             # Always add host_mtu for migration compatibility, because the presence of host_mtu
             # means that the virtual hardware is generated differently (at least for i440fx)
             $tmpstr .= ",host_mtu=$mtu";
@@ -1382,7 +1381,7 @@ sub print_netdevice_full {
         if ($migration_skip_host_mtu) {
             # When the machine version is less than 10.0+pve1 and the MTU is 1500, not having the
             # host_mtu parameter is fully expected. Only log when not expected to avoid confusion.
-            if ($version_guard->(10, 0, 1) || $mtu != 1500) {
+            if ($hw_config->version_at_least(10, 0, 1) || $mtu != 1500) {
                 log_warn(
                     "$msg_prefix, not used on the source side according to migration parameters");
             }
@@ -1415,10 +1414,10 @@ sub print_netdevice_full {
     # include the fix "virtio_net: do not allow tunnel csum offload for non GSO packets" with a
     # prominent notice in the upgrade guide.
     if ($net->{model} eq 'virtio') {
-        if ($version_guard->(11, 0, 1)) {
+        if ($hw_config->version_at_least(11, 0, 1)) {
             # Turn off if not explicitly enabled starting with 11.0+pve1
             $tmpstr .= ",host_tunnel=off" if !$net->{'host-tunnel'};
-        } elsif ($version_guard->(10, 2)) {
+        } elsif ($hw_config->version_at_least(10, 2)) {
             # The feature was introduced in QEMU 10.2. Turn off if explicitly disabled.
             $tmpstr .= ",host_tunnel=off"
                 if defined($net->{'host-tunnel'}) && !$net->{'host-tunnel'};
@@ -1488,7 +1487,7 @@ my sub map_vga_model {
 }
 
 sub print_vga_device {
-    my ($conf, $vga, $hw_config, $machine_version, $id, $qxlnum) = @_;
+    my ($conf, $vga, $hw_config, $id, $qxlnum) = @_;
 
     my $type = map_vga_model($vga->{type}, $hw_config->arch());
     my $vgamem_mb = $vga->{memory};
@@ -1499,7 +1498,7 @@ sub print_vga_device {
 
         if (!$conf->{ostype} || $conf->{ostype} =~ m/^(?:l\d\d)|(?:other)$/) {
             # set max outputs so linux can have up to 4 qxl displays with one device
-            if (min_version($machine_version, 4, 1)) {
+            if ($hw_config->version_at_least(4, 1)) {
                 $max_outputs = ",max_outputs=4";
             }
         }
@@ -1526,7 +1525,7 @@ sub print_vga_device {
     }
 
     my $edidoff = "";
-    if ($type eq 'VGA' && windows_version($conf->{ostype})) {
+    if ($type eq 'VGA' && $hw_config->windows_version()) {
         $edidoff = ",edid=off" if (!defined($conf->{bios}) || $conf->{bios} ne 'ovmf');
     }
 
@@ -2803,14 +2802,14 @@ sub conf_has_audio {
 }
 
 sub audio_devs {
-    my ($audio, $hw_config, $machine_version) = @_;
+    my ($audio, $hw_config) = @_;
 
     my $devs = [];
 
     my $audiopciaddr = $hw_config->addr("audio0");
     my $id = $audio->{dev_id};
     my $audiodev = "";
-    if (min_version($machine_version, 4, 2)) {
+    if ($hw_config->version_at_least(4, 2)) {
         $audiodev = ",audiodev=$audio->{backend_id}";
     }
 
@@ -3123,7 +3122,6 @@ sub config_to_command {
     my ($machineFlags, $rtcFlags) = ([], []);
     my $devices = [];
     my $ostype = $conf->{ostype};
-    my $winversion = windows_version($ostype);
     my $kvm = $conf->{kvm};
     my $nodename = nodename();
 
@@ -3283,13 +3281,14 @@ sub config_to_command {
         push @$devices, $bus_devices->@*;
     }
 
+    my $winversion = $hw_config->windows_version();
+
     if ($conf->{vmgenid}) {
         push @$devices, '-device', 'vmgenid,guid=' . $conf->{vmgenid};
     }
 
     # add usb controllers
-    my @usbcontrollers =
-        PVE::QemuServer::USB::get_usb_controllers($conf, $hw_config, $machine_version);
+    my @usbcontrollers = PVE::QemuServer::USB::get_usb_controllers($conf, $hw_config);
     push @$devices, @usbcontrollers if @usbcontrollers;
 
     my ($vga, $qxlnum) = get_vga_properties($conf, $arch, $machine_version, $winversion);
@@ -3316,7 +3315,7 @@ sub config_to_command {
             $vmid, $conf, $devices, $vga, $winversion, $hw_config, $bootorder, $dry_run,
         );
 
-    my @usbdevices = PVE::QemuServer::USB::get_usb_devices($conf, $bootorder, $machine_version);
+    my @usbdevices = PVE::QemuServer::USB::get_usb_devices($conf, $bootorder, $hw_config);
     push @$devices, @usbdevices if @usbdevices;
 
     # serial devices
@@ -3350,8 +3349,8 @@ sub config_to_command {
         }
     }
 
-    if (min_version($machine_version, 4, 0) && (my $audio = conf_has_audio($conf))) {
-        my $audio_devs = audio_devs($audio, $hw_config, $machine_version);
+    if ($hw_config->version_at_least(4, 0) && (my $audio = conf_has_audio($conf))) {
+        my $audio_devs = audio_devs($audio, $hw_config);
         push @$devices, @$audio_devs;
     }
 
@@ -3394,8 +3393,7 @@ sub config_to_command {
     push @$cmd, '-no-reboot' if defined($conf->{reboot}) && $conf->{reboot} == 0;
 
     if ($vga->{type} && $vga->{type} !~ m/^serial\d+$/ && $vga->{type} ne 'none') {
-        push @$devices, '-device',
-            print_vga_device($conf, $vga, $hw_config, $machine_version, undef, $qxlnum);
+        push @$devices, '-device', print_vga_device($conf, $vga, $hw_config, undef, $qxlnum);
 
         push @$cmd, '-display', 'egl-headless,gl=core' if $vga->{type} eq 'virtio-gl'; # VIRGL
 
@@ -3481,7 +3479,7 @@ sub config_to_command {
             if ($winversion) {
                 for (my $i = 1; $i < $qxlnum; $i++) {
                     push @$devices, '-device',
-                        print_vga_device($conf, $vga, $hw_config, $machine_version, $i, $qxlnum);
+                        print_vga_device($conf, $vga, $hw_config, $i, $qxlnum);
                 }
             } else {
                 # assume other OS works like Linux
@@ -3662,9 +3660,8 @@ sub config_to_command {
                 push @$devices, '-drive', $drive_cmd;
             }
 
-            push @$devices, '-device', print_drivedevice_full(
-                $storecfg, $conf, $vmid, $drive, $hw_config, $machine_type,
-            );
+            push @$devices, '-device',
+                print_drivedevice_full($storecfg, $conf, $vmid, $drive, $hw_config);
         },
     );
 
@@ -3694,7 +3691,6 @@ sub config_to_command {
             $netname,
             $use_old_bios_files,
             $hw_config,
-            $version_guard,
             $nets_host_mtu->{$netname},
         );
 
@@ -3723,6 +3719,9 @@ sub config_to_command {
 
     push @$machineFlags, 'smm=off' if should_disable_smm($conf, $vga, $machine_type);
 
+    # take pve versions from hw_config into account
+    $version_guard->($machine_major, $machine_minor, $hw_config->required_pve_version());
+
     my $machine_type_min = $machine_type;
     $machine_type_min =~ s/\+pve\d+$//;
     $machine_type_min .= "+pve$required_pve_version";
@@ -3851,7 +3850,7 @@ sub vm_devices_list {
 }
 
 sub vm_deviceplug {
-    my ($storecfg, $conf, $vmid, $deviceid, $device, $hw_config, $machine_type) = @_;
+    my ($storecfg, $conf, $vmid, $deviceid, $device, $hw_config) = @_;
 
     my $devices_list = vm_devices_list($vmid);
     return 1 if defined($devices_list->{$deviceid});
@@ -3876,8 +3875,7 @@ sub vm_deviceplug {
         qemu_iothread_add($vmid, $deviceid, $device);
 
         qemu_driveadd($storecfg, $vmid, $device);
-        my $devicefull =
-            print_drivedevice_full($storecfg, $conf, $vmid, $device, $hw_config, $machine_type);
+        my $devicefull = print_drivedevice_full($storecfg, $conf, $vmid, $device, $hw_config);
 
         qemu_deviceadd($vmid, $devicefull);
         eval { qemu_deviceaddverify($vmid, $deviceid); };
@@ -3914,11 +3912,12 @@ sub vm_deviceplug {
             die $err;
         }
     } elsif ($deviceid =~ m/^(scsi)(\d+)$/) {
-        qemu_findorcreatescsihw($storecfg, $conf, $vmid, $device, $hw_config, $machine_type);
+        qemu_findorcreatescsihw(
+            $storecfg, $conf, $vmid, $device, $hw_config,
+        );
         qemu_driveadd($storecfg, $vmid, $device);
 
-        my $devicefull =
-            print_drivedevice_full($storecfg, $conf, $vmid, $device, $hw_config, $machine_type);
+        my $devicefull = print_drivedevice_full($storecfg, $conf, $vmid, $device, $hw_config);
         eval { qemu_deviceadd($vmid, $devicefull); };
         if (my $err = $@) {
             eval { qemu_drivedel($vmid, $deviceid); };
@@ -3929,23 +3928,11 @@ sub vm_deviceplug {
         return if !qemu_netdevadd($vmid, $conf, $hw_config->arch(), $device, $deviceid);
 
         my $machine_type = PVE::QemuServer::Machine::qemu_machine_pxe($vmid, $conf);
-        my $machine_version = PVE::QemuServer::Machine::extract_version($machine_type);
         my $use_old_bios_files = undef;
         ($use_old_bios_files, $machine_type) = qemu_use_old_bios_files($machine_type);
 
-        # the machine is already running, so there is no required version to record
-        my $version_guard = sub {
-            my ($major, $minor, $pve) = @_;
-            return min_version($machine_version, $major, $minor, $pve);
-        };
         my $netdevicefull = print_netdevice_full(
-            $vmid,
-            $conf,
-            $device,
-            $deviceid,
-            $use_old_bios_files,
-            $hw_config,
-            $version_guard,
+            $vmid, $conf, $device, $deviceid, $use_old_bios_files, $hw_config,
         );
         qemu_deviceadd($vmid, $netdevicefull);
         eval {
@@ -4127,7 +4114,7 @@ sub qemu_devicedelverify {
 }
 
 sub qemu_findorcreatescsihw {
-    my ($storecfg, $conf, $vmid, $device, $hw_config, $machine_type) = @_;
+    my ($storecfg, $conf, $vmid, $device, $hw_config) = @_;
 
     my ($maxdev, $controller, $controller_prefix) = scsihw_infos($conf->{scsihw}, $device->{index});
 
@@ -4135,7 +4122,7 @@ sub qemu_findorcreatescsihw {
     my $devices_list = vm_devices_list($vmid);
 
     if (!defined($devices_list->{$scsihwid})) {
-        vm_deviceplug($storecfg, $conf, $vmid, $scsihwid, $device, $hw_config, $machine_type);
+        vm_deviceplug($storecfg, $conf, $vmid, $scsihwid, $device, $hw_config);
     }
 
     return 1;
@@ -4223,7 +4210,7 @@ sub qemu_netdevdel {
 }
 
 sub qemu_usb_hotplug {
-    my ($storecfg, $conf, $vmid, $deviceid, $device, $hw_config, $machine_type) = @_;
+    my ($storecfg, $conf, $vmid, $deviceid, $device, $hw_config) = @_;
 
     return if !$device;
 
@@ -4241,7 +4228,7 @@ sub qemu_usb_hotplug {
     }
 
     # add the new one
-    eval { vm_deviceplug($storecfg, $conf, $vmid, $deviceid, $device, $hw_config, $machine_type); };
+    eval { vm_deviceplug($storecfg, $conf, $vmid, $deviceid, $device, $hw_config); };
     if (my $err = $@) {
         if ($added_xhci) {
             eval { vm_deviceunplug($vmid, $conf, 'xhci'); };
@@ -4567,23 +4554,17 @@ sub vmconfig_hotplug_pending {
     my $defaults = load_defaults();
     my $arch = PVE::QemuServer::Helpers::get_vm_arch($conf);
 
-    my $_machine_type;
-    my $machine_type = sub {
-        return $_machine_type if defined($_machine_type);
-        $_machine_type = PVE::QemuServer::Machine::get_current_qemu_machine($vmid);
-        return $_machine_type;
-    };
-
     my $_hw_config;
     my $hw_config = sub {
         return $_hw_config if defined($_hw_config);
+        my $machine_type = PVE::QemuServer::Machine::get_current_qemu_machine($vmid);
 
         my $max_scsihw = PVE::QemuServer::DriveDevice::get_max_scsihw_index($conf);
         $_hw_config = PVE::QemuServer::PCI::hardware_config(
             $conf,
             $arch,
             $max_scsihw,
-            PVE::QemuServer::Machine::extract_version($machine_type->()),
+            PVE::QemuServer::Machine::extract_version($machine_type),
         );
 
         return $_hw_config;
@@ -4686,12 +4667,11 @@ sub vmconfig_hotplug_pending {
     my $is_usb_hotplug_supported = sub {
         return $usb_hotplug if defined($usb_hotplug);
         my $ostype = $conf->{ostype};
-        my $version = PVE::QemuServer::Machine::extract_version($machine_type->());
         $usb_hotplug =
             $hotplug_features->{usb}
-            && min_version($version, 7, 1)
+            && $hw_config->()->version_at_least(7, 1)
             && defined($ostype)
-            && ($ostype eq 'l26' || windows_version($ostype) > 7) ? 1 : 0;
+            && ($ostype eq 'l26' || $hw_config->()->windows_version() > 7) ? 1 : 0;
         return $usb_hotplug;
     };
 
@@ -4707,24 +4687,9 @@ sub vmconfig_hotplug_pending {
             } elsif ($opt eq 'tablet') {
                 die "skip\n" if !$hotplug_features->{usb};
                 if ($defaults->{tablet}) {
-                    vm_deviceplug(
-                        $storecfg,
-                        $conf,
-                        $vmid,
-                        'tablet',
-                        undef,
-                        $hw_config->(),
-                        $machine_type->(),
-                    );
-                    vm_deviceplug(
-                        $storecfg,
-                        $conf,
-                        $vmid,
-                        'keyboard',
-                        undef,
-                        $hw_config->(),
-                        $machine_type->(),
-                    ) if $arch eq 'aarch64';
+                    vm_deviceplug($storecfg, $conf, $vmid, 'tablet', undef, $hw_config->());
+                    vm_deviceplug($storecfg, $conf, $vmid, 'keyboard', undef, $hw_config->())
+                        if $arch eq 'aarch64';
                 } else {
                     vm_deviceunplug($vmid, $conf, 'tablet');
                     vm_deviceunplug($vmid, $conf, 'keyboard') if $arch eq 'aarch64';
@@ -4793,24 +4758,9 @@ sub vmconfig_hotplug_pending {
             } elsif ($opt eq 'tablet') {
                 die "skip\n" if !$hotplug_features->{usb};
                 if ($value == 1) {
-                    vm_deviceplug(
-                        $storecfg,
-                        $conf,
-                        $vmid,
-                        'tablet',
-                        undef,
-                        $hw_config->(),
-                        $machine_type->(),
-                    );
-                    vm_deviceplug(
-                        $storecfg,
-                        $conf,
-                        $vmid,
-                        'keyboard',
-                        undef,
-                        $hw_config->(),
-                        $machine_type->(),
-                    ) if $arch eq 'aarch64';
+                    vm_deviceplug($storecfg, $conf, $vmid, 'tablet', undef, $hw_config->());
+                    vm_deviceplug($storecfg, $conf, $vmid, 'keyboard', undef, $hw_config->())
+                        if $arch eq 'aarch64';
                 } elsif ($value == 0) {
                     vm_deviceunplug($vmid, $conf, 'tablet');
                     vm_deviceunplug($vmid, $conf, 'keyboard') if $arch eq 'aarch64';
@@ -4823,9 +4773,7 @@ sub vmconfig_hotplug_pending {
                 if ($d->{host} =~ m/^spice$/i) {
                     $id = "usbredirdev$index";
                 }
-                qemu_usb_hotplug(
-                    $storecfg, $conf, $vmid, $id, $d, $hw_config->(), $machine_type->(),
-                );
+                qemu_usb_hotplug($storecfg, $conf, $vmid, $id, $d, $hw_config->());
             } elsif ($opt eq 'vcpus') {
                 die "skip\n" if !$hotplug_features->{cpu};
                 qemu_cpu_hotplug($vmid, $conf, $value);
@@ -4852,7 +4800,6 @@ sub vmconfig_hotplug_pending {
                     $opt,
                     $value,
                     $hw_config->(),
-                    $machine_type->(),
                 );
             } elsif (is_valid_drivename($opt)) {
                 die "skip\n" if $opt eq 'efidisk0' || $opt eq 'tpmstate0';
@@ -4871,7 +4818,6 @@ sub vmconfig_hotplug_pending {
                     $opt,
                     $value,
                     $hw_config->(),
-                    $machine_type->(),
                 );
             } elsif ($opt =~ m/^memory$/) { #dimms
                 die "skip\n" if !$hotplug_features->{memory};
@@ -4912,7 +4858,6 @@ sub vmconfig_hotplug_pending {
                 $opt,
                 $value,
                 $hw_config->(),
-                $machine_type->(),
             );
         };
         if (my $err = $@) {
@@ -5106,7 +5051,7 @@ sub vmconfig_apply_pending {
 }
 
 sub vmconfig_update_net {
-    my ($storecfg, $conf, $hotplug, $vmid, $opt, $value, $hw_config, $machine_type) = @_;
+    my ($storecfg, $conf, $hotplug, $vmid, $opt, $value, $hw_config) = @_;
 
     my $newnet = PVE::QemuServer::Network::parse_net($value);
 
@@ -5198,7 +5143,7 @@ sub vmconfig_update_net {
         PVE::Network::SDN::Vnets::add_dhcp_mapping(
             $newnet->{bridge}, $newnet->{macaddr}, $vmid, $conf->{name},
         );
-        vm_deviceplug($storecfg, $conf, $vmid, $opt, $newnet, $hw_config, $machine_type);
+        vm_deviceplug($storecfg, $conf, $vmid, $opt, $newnet, $hw_config);
     } else {
         die "skip\n";
     }
@@ -5228,7 +5173,7 @@ sub vmconfig_update_agent {
 }
 
 sub vmconfig_update_disk {
-    my ($storecfg, $conf, $hotplug, $vmid, $opt, $value, $hw_config, $machine_type) = @_;
+    my ($storecfg, $conf, $hotplug, $vmid, $opt, $value, $hw_config) = @_;
 
     my $drive = parse_drive($opt, $value);
 
@@ -5334,7 +5279,7 @@ sub vmconfig_update_disk {
     die "skip\n" if !$hotplug || $opt =~ m/(ide|sata)(\d+)/;
     # hotplug new disks
     PVE::Storage::activate_volumes($storecfg, [$drive->{file}]) if $drive->{file} !~ m|^/dev/.+|;
-    vm_deviceplug($storecfg, $conf, $vmid, $opt, $drive, $hw_config, $machine_type);
+    vm_deviceplug($storecfg, $conf, $vmid, $opt, $drive, $hw_config);
 }
 
 sub vmconfig_update_cloudinit_drive {
diff --git a/src/PVE/QemuServer/Drive.pm b/src/PVE/QemuServer/Drive.pm
index 0b573717..769f2e0d 100644
--- a/src/PVE/QemuServer/Drive.pm
+++ b/src/PVE/QemuServer/Drive.pm
@@ -1115,7 +1115,7 @@ sub path_is_scsi {
 }
 
 sub get_scsi_device_type {
-    my ($drive, $storecfg, $machine_version) = @_;
+    my ($drive, $storecfg, $hw_config) = @_;
 
     my $devicetype = 'hd';
     my $path = '';
@@ -1139,10 +1139,7 @@ sub get_scsi_device_type {
         }
 
         # for compatibility only, we prefer scsi-hd (#2408, #2355, #2380)
-        if (
-            $path =~ m/^iscsi\:\/\//
-            && !PVE::QemuServer::Helpers::min_version($machine_version, 4, 1)
-        ) {
+        if ($path =~ m/^iscsi\:\/\// && !$hw_config->version_at_least(4, 1)) {
             $devicetype = 'generic';
         }
     }
diff --git a/src/PVE/QemuServer/DriveDevice.pm b/src/PVE/QemuServer/DriveDevice.pm
index 28588433..4303b664 100644
--- a/src/PVE/QemuServer/DriveDevice.pm
+++ b/src/PVE/QemuServer/DriveDevice.pm
@@ -6,7 +6,6 @@ use warnings;
 use URI::Escape;
 
 use PVE::QemuServer::Drive qw (drive_is_cdrom);
-use PVE::QemuServer::Helpers qw(kvm_user_version min_version);
 use PVE::QemuServer::Machine;
 
 use base qw(Exporter);
@@ -68,16 +67,14 @@ sub get_max_scsihw_index {
 }
 
 sub print_drivedevice_full {
-    my ($storecfg, $conf, $vmid, $drive, $hw_config, $machine_type) = @_;
+    my ($storecfg, $conf, $vmid, $drive, $hw_config) = @_;
 
     my $device = '';
     my $maxdev = 0;
 
-    my $machine_version =
-        PVE::QemuServer::Machine::extract_version($machine_type, kvm_user_version());
     my $has_write_cache = 1; # whether the device has a 'write-cache' option
 
-    my $use_blockdev = min_version($machine_version, 10, 0);
+    my $use_blockdev = $hw_config->version_at_least(10, 0);
 
     my $drive_id = PVE::QemuServer::Drive::get_drive_id($drive);
     if ($drive->{interface} eq 'virtio') {
@@ -96,7 +93,7 @@ sub print_drivedevice_full {
         my $unit = $drive->{index} % $maxdev;
 
         my $device_type =
-            PVE::QemuServer::Drive::get_scsi_device_type($drive, $storecfg, $machine_version);
+            PVE::QemuServer::Drive::get_scsi_device_type($drive, $storecfg, $hw_config);
 
         if (!$conf->{scsihw} || $conf->{scsihw} =~ m/^lsi/ || $conf->{scsihw} eq 'pvscsi') {
             $device = "scsi-$device_type,bus=$controller_prefix$controller.0,scsi-id=$unit";
diff --git a/src/PVE/QemuServer/USB.pm b/src/PVE/QemuServer/USB.pm
index f5e2e31f..42b4d3a3 100644
--- a/src/PVE/QemuServer/USB.pm
+++ b/src/PVE/QemuServer/USB.pm
@@ -3,7 +3,7 @@ package PVE::QemuServer::USB;
 use strict;
 use warnings;
 use PVE::QemuServer::Machine;
-use PVE::QemuServer::Helpers qw(min_version windows_version);
+use PVE::QemuServer::Helpers qw(windows_version);
 use PVE::JSONSchema;
 use PVE::Mapping::USB;
 use base 'Exporter';
@@ -126,7 +126,7 @@ sub get_default_usb_bus {
 }
 
 sub get_usb_controllers {
-    my ($conf, $hw_config, $machine_version) = @_;
+    my ($conf, $hw_config) = @_;
 
     my $devices = [];
     my $pciaddr = "";
@@ -134,7 +134,7 @@ sub get_usb_controllers {
     my $ostype = $conf->{ostype};
 
     my $use_qemu_xhci =
-        min_version($machine_version, 7, 1)
+        $hw_config->version_at_least(7, 1)
         && defined($ostype)
         && ($ostype eq 'l26' || windows_version($ostype) > 7);
 
@@ -175,13 +175,13 @@ sub get_usb_controllers {
 }
 
 sub get_usb_devices {
-    my ($conf, $bootorder, $machine_version) = @_;
+    my ($conf, $bootorder, $hw_config) = @_;
 
     my $devices = [];
 
     my $ostype = $conf->{ostype};
     my $use_qemu_xhci =
-        min_version($machine_version, 7, 1)
+        $hw_config->version_at_least(7, 1)
         && defined($ostype)
         && ($ostype eq 'l26' || windows_version($ostype) > 7);
 
-- 
2.47.3





  parent reply	other threads:[~2026-10-15  8:11 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15  8:10 [RFC proxmox-perl-rs/qemu-server/qemu-server-rs v2 0/9] pci-handling rewrite (part 1/2/3) Dominik Csapak
2026-10-15  8:10 ` [PATCH pve-qemu-server-rs v2 1/9] add pve-qemu-server-pci crate for guest PCI address generation Dominik Csapak
2026-10-15 12:16   ` Wolfgang Bumiller
2026-10-15  8:10 ` [PATCH pve-qemu-server-rs v2 2/9] pci: legacy: generate pci bridges Dominik Csapak
2026-10-15  8:10 ` [PATCH pve-qemu-server-rs v2 3/9] pci: legacy: generate q35 chipset devices and hostpcie root ports Dominik Csapak
2026-10-15  8:10 ` [PATCH pve-qemu-server-rs v2 4/9] pci: layout: add grouped PCI and PCIe layouts Dominik Csapak
2026-10-15  8:10 ` [PATCH proxmox-perl-rs v2 5/9] pve: add bindings for `pve-qemu-server-pci` crate Dominik Csapak
2026-10-15 11:47   ` Wolfgang Bumiller
2026-10-15  8:10 ` [PATCH qemu-server v2 6/9] pci: use PVE::RS::PCI bindings for addresses and bus devices Dominik Csapak
2026-10-15  8:10 ` Dominik Csapak [this message]
2026-10-15  8:10 ` [PATCH qemu-server v2 8/9] cfg2cmd: q35: generate chipset devices with machine version 11.1+pve1 Dominik Csapak
2026-10-15  8:10 ` [PATCH qemu-server v2 9/9] machine: add 'pci-layout' option Dominik Csapak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261015081041.743422-8-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal