From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 68B021FF0AA for ; Tue, 22 Sep 2026 12:56:39 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id CD02121657; Tue, 22 Sep 2026 12:55:57 +0200 (CEST) From: Dominik Csapak To: pve-devel@lists.proxmox.com Subject: [PATCH qemu-server 9/9] pci: bridges: use the rust `Machine` struct to pass parameters Date: Tue, 22 Sep 2026 12:55:40 +0200 Message-ID: <20260922105550.2084078-10-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260922105550.2084078-1-d.csapak@proxmox.com> References: <20260922105550.2084078-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.459 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: CRH5XE63INCGYTRTCT5WEDCKZJQLQ5Y4 X-Message-ID-Hash: CRH5XE63INCGYTRTCT5WEDCKZJQLQ5Y4 X-MailFrom: d.csapak@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: This holds some general info about the guest config and is intended to be constructed once and passed to the individual functions that need to access them in rust, similar to the Cfg2Cmd class for perl. Signed-off-by: Dominik Csapak --- src/PVE/QemuServer.pm | 4 ++- src/PVE/QemuServer/PCI.pm | 32 ++++++++++++++++++------ src/test/TestsCommon/CommandLineMocks.pm | 3 +++ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm index c28668c1..0c2da1ab 100644 --- a/src/PVE/QemuServer.pm +++ b/src/PVE/QemuServer.pm @@ -3289,7 +3289,9 @@ sub config_to_command { } my $max_scsihw = PVE::QemuServer::DriveDevice::get_max_scsihw_index($conf); - if (my $bridges = get_pci_bridges($conf, $arch, $q35, $max_scsihw, $version_guard)) { + my $pci_machine = PVE::QemuServer::PCI::pci_machine($conf, $arch, $q35, $max_scsihw); + + if (my $bridges = get_pci_bridges($pci_machine)) { push @$devices, $bridges->@*; } diff --git a/src/PVE/QemuServer/PCI.pm b/src/PVE/QemuServer/PCI.pm index c3f4e918..19250d8a 100644 --- a/src/PVE/QemuServer/PCI.pm +++ b/src/PVE/QemuServer/PCI.pm @@ -8,6 +8,7 @@ use IO::File; use PVE::JSONSchema; use PVE::Mapping::PCI; use PVE::RS::PCI; +use PVE::RS::PCI::Machine; use PVE::SysFSTools; use PVE::Tools; @@ -649,15 +650,14 @@ sub reserve_pci_usage { # Returns a list of bridge devices which are necessary for the remaining # devices. sub get_pci_bridges { - my ($conf, $arch, $q35, $max_scsihw, $version_guard) = @_; + my ($pci_machine) = @_; - my $virtio_scsi_single = ($conf->{scsihw} // '') =~ m/^virtio-scsi-single/; + return PVE::RS::PCI::get_pci_bridges($pci_machine); +} - # some scsi controllers can only have 7 scsi disks per controller, - # so scsi14 and upwards need scsihw2,3,4 which live on bridge 4 - my $include_pci4 = $max_scsihw > 1 || $version_guard->(11, 1); +sub pci_machine { + my ($conf, $arch, $q35, $max_scsihw) = @_; - # use cheap legacy igd check instead of a full parse_hostpci my $legacy_igd = 0; for (my $i = 0; $i < $MAX_HOSTPCI_DEVICES; $i++) { next if !defined($conf->{"hostpci$i"}); @@ -669,8 +669,24 @@ sub get_pci_bridges { } } - return PVE::RS::PCI::get_pci_bridges($arch, $q35, $virtio_scsi_single, $legacy_igd, - $include_pci4); + my $machine_type = PVE::QemuServer::Machine::get_vm_machine($conf); + my $machine_version = PVE::QemuServer::Machine::extract_version( + $machine_type, + PVE::QemuServer::Helpers::kvm_user_version(), + ); + my ($major, $minor, $patch, $pve) = PVE::QemuServer::Helpers::version_parts($machine_version); + + return PVE::RS::PCI::Machine->new( + $arch // '', + $q35, + $conf->{scsihw}, + $max_scsihw + 0, + $legacy_igd, + $conf->{ostype}, + $major, + $minor, + $pve, + ); } 1; diff --git a/src/test/TestsCommon/CommandLineMocks.pm b/src/test/TestsCommon/CommandLineMocks.pm index 50540e8f..a4b91136 100644 --- a/src/test/TestsCommon/CommandLineMocks.pm +++ b/src/test/TestsCommon/CommandLineMocks.pm @@ -347,6 +347,9 @@ $qemu_server_helpers->mock( get_host_phys_address_bits => sub { return 46; }, + kvm_user_version => sub { + return get_test_qemu_version(); + }, ); our $qemu_server_memory; -- 2.47.3