From: Dominik Csapak <d.csapak@proxmox.com>
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 [thread overview]
Message-ID: <20260922105550.2084078-10-d.csapak@proxmox.com> (raw)
In-Reply-To: <20260922105550.2084078-1-d.csapak@proxmox.com>
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 <d.csapak@proxmox.com>
---
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
next prev parent reply other threads:[~2026-09-22 10:56 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-22 10:55 [RFC proxmox-perl-rs/qemu-server/qemu-server-rs 0/9] pci-handling rewrite (part 1) Dominik Csapak
2026-09-22 10:55 ` [PATCH pve-qemu-server-rs 1/9] add pve-qemu-server-pci crate for guest PCI address generation Dominik Csapak
2026-09-22 10:55 ` [PATCH pve-qemu-server-rs 2/9] pci: add machine abstraction and PCI bridge generation Dominik Csapak
2026-09-22 10:55 ` [PATCH pve-qemu-server-rs 3/9] pci: layout: add v2 PCI and PCIe layouts Dominik Csapak
2026-09-22 10:55 ` [PATCH pve-qemu-server-rs 4/9] fixup! add pve-qemu-server-pci crate for guest PCI address generation Dominik Csapak
2026-09-22 10:55 ` [PATCH proxmox-perl-rs 5/9] pve: add bindings for `pve-qemu-server-pci` crate Dominik Csapak
2026-09-22 10:55 ` [PATCH proxmox-perl-rs 6/9] pve: pci bindings: add bindings for the `Machine` struct Dominik Csapak
2026-09-22 10:55 ` [PATCH qemu-server 7/9] pci: use PVE::RS::PCI bindings Dominik Csapak
2026-09-22 10:55 ` [PATCH qemu-server 8/9] helpers: factor out the version parts parsing Dominik Csapak
2026-09-22 10:55 ` Dominik Csapak [this message]
2026-09-22 11:06 ` [RFC proxmox-perl-rs/qemu-server/qemu-server-rs 0/9] pci-handling rewrite (part 1) 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=20260922105550.2084078-10-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