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 6AEA91FF0AF for ; Fri, 06 Nov 2026 14:26:17 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 4D4102169A; Fri, 06 Nov 2026 14:26:15 +0100 (CET) From: Dominik Csapak To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox-perl-rs v3 5/9] pve: add bindings for `pve-qemu-server-pci` crate Date: Fri, 6 Nov 2026 14:25:48 +0100 Message-ID: <20261106132604.2556840-6-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261106132604.2556840-1-d.csapak@proxmox.com> References: <20261106132604.2556840-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.315 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: YRUP5DLSFDWU6AMU3WD5WMK744HOXJN6 X-Message-ID-Hash: YRUP5DLSFDWU6AMU3WD5WMK744HOXJN6 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: These provide bindings for using the rust pci code in PVE's qemu-server perl code. This exposes 'PVE::RS::PCI::HardwareConfig' which provides an object that can be used to query the pci addresses of qemu vms. Signed-off-by: Dominik Csapak --- pve-rs/Cargo.toml | 1 + pve-rs/Makefile | 1 + pve-rs/src/bindings/mod.rs | 3 + pve-rs/src/bindings/pci/hardware_config.rs | 120 +++++++++++++++++++++ pve-rs/src/bindings/pci/mod.rs | 2 + 5 files changed, 127 insertions(+) create mode 100644 pve-rs/src/bindings/pci/hardware_config.rs create mode 100644 pve-rs/src/bindings/pci/mod.rs diff --git a/pve-rs/Cargo.toml b/pve-rs/Cargo.toml index ecedb1e..d728dcd 100644 --- a/pve-rs/Cargo.toml +++ b/pve-rs/Cargo.toml @@ -53,6 +53,7 @@ proxmox-tfa = { version = "6.0.3", features = ["api"] } proxmox-time = "2" proxmox-ve-config = { version = "0.11.0", features = [ "frr" ] } proxmox-wireguard = { version = "0.1.2" } +pve-qemu-server-pci = "0.1" # [patch.crates-io] # pbs-api-types = { path = "../../proxmox/pbs-api-types" } diff --git a/pve-rs/Makefile b/pve-rs/Makefile index 60f68c7..be0284d 100644 --- a/pve-rs/Makefile +++ b/pve-rs/Makefile @@ -31,6 +31,7 @@ PERLMOD_PACKAGES := \ PVE::RS::NVML \ PVE::RS::OCI \ PVE::RS::OpenId \ + PVE::RS::PCI::HardwareConfig \ PVE::RS::ResourceScheduling::Static \ PVE::RS::ResourceScheduling::Dynamic \ PVE::RS::SDN::Fabrics \ diff --git a/pve-rs/src/bindings/mod.rs b/pve-rs/src/bindings/mod.rs index 143a62b..9afcd4a 100644 --- a/pve-rs/src/bindings/mod.rs +++ b/pve-rs/src/bindings/mod.rs @@ -6,6 +6,9 @@ pub use nvml::pve_rs_nvml; mod oci; pub use oci::pve_rs_oci; +mod pci; +pub use pci::pve_rs_pci_hardware_config; + pub mod resource_scheduling; mod tfa; diff --git a/pve-rs/src/bindings/pci/hardware_config.rs b/pve-rs/src/bindings/pci/hardware_config.rs new file mode 100644 index 0000000..d00aea4 --- /dev/null +++ b/pve-rs/src/bindings/pci/hardware_config.rs @@ -0,0 +1,120 @@ +#[perlmod::package(name = "PVE::RS::PCI::HardwareConfig", lib = "pve_rs")] +pub mod pve_rs_pci_hardware_config { + //! The `PVE::RS::PCI::HardwareConfig` package. + //! + //! Provides bindings for the `HardwareConfig` struct of the `pve-qemu-server-pci` crate. + + use std::ops::Deref; + use std::rc::Rc; + + use anyhow::Error; + + use perlmod::Value; + + use pve_qemu_server_pci::{HardwareConfigParams, LayoutError, address}; + + perlmod::declare_magic!(Box: &HardwareConfig as "PVE::RS::PCI::HardwareConfig"); + + /// Wrapper for [`pve_qemu_server_pci::HardwareConfig`]. + pub struct HardwareConfig { + inner: Rc, + } + + impl Deref for HardwareConfig { + type Target = pve_qemu_server_pci::HardwareConfig; + + fn deref(&self) -> &Self::Target { + &self.inner + } + } + + #[export(raw_return)] + /// Class method: Create an instance of the `HardwareConfig` struct. + pub fn new(#[raw] class: Value, params: HardwareConfigParams) -> Result { + let hw_config = pve_qemu_server_pci::HardwareConfig::new(params); + Ok( + perlmod::instantiate_magic!(&class, MAGIC => Box::new(HardwareConfig { inner: Rc::new(hw_config) })), + ) + } + + #[export] + /// Method: Returns the PCI or PCIe address of the chosen device on the given machine if the + /// device exists on the layout. + pub fn addr( + #[try_from_ref] this: &HardwareConfig, + id: &str, + ) -> Result, LayoutError> { + match address(this, id) { + Ok(addr) => Ok(Some(addr.to_qemu_addr())), + Err(LayoutError::NoAddressFound(_)) => Ok(None), + Err(other) => Err(other), + } + } + + #[export] + /// Method: Get the `-device` arguments of all bridges, root ports and chipset devices forming + /// the buses of the guest, which have to come before any device on them. + pub fn pci_bus_devices( + #[try_from_ref] this: &HardwareConfig, + ) -> Result, LayoutError> { + pve_qemu_server_pci::pci_bus_devices(this) + } + + #[export] + /// Method: Whether the q35 chipset devices still have to be loaded from `pve-q35-4.0.cfg`. + pub fn uses_q35_config_file(#[try_from_ref] this: &HardwareConfig) -> bool { + this.uses_q35_config_file() + } + + #[export] + /// Method: Get the architecture of the machine + pub fn arch(#[try_from_ref] this: &HardwareConfig) -> String { + this.arch().to_string() + } + + #[export] + /// Method: Get the machines mainboard model + pub fn machine_type(#[try_from_ref] this: &HardwareConfig) -> String { + this.mainboard.to_string() + } + + #[export] + /// Method: Get the layout of the given machine. + pub fn layout(#[try_from_ref] this: &HardwareConfig) -> String { + this.layout.to_string() + } + + #[export] + /// Method: Checks if the given machine is at least the given version + /// Note: records the necessary PVE revision. + pub fn version_at_least( + #[try_from_ref] this: &HardwareConfig, + major: u16, + minor: u16, + pve: Option, + ) -> bool { + this.version_at_least(major, minor, pve) + } + + #[export] + /// Method: Returns the windows version (if any) + pub fn windows_version(#[try_from_ref] this: &HardwareConfig) -> u8 { + this.windows_version() + } + + #[export] + /// Method: Returns the bus the given device sits on, if it is a known device. + pub fn pci_bridge_for_device( + #[try_from_ref] this: &HardwareConfig, + device: &str, + ) -> Option { + let bus = pve_qemu_server_pci::pci_bridge_for_device(this, device)?; + Some(bus.to_string()) + } + + #[export] + /// Method: Returns the required '+pveX' version of the machine. + pub fn required_pve_version(#[try_from_ref] this: &HardwareConfig) -> u16 { + this.required_pve_version() + } +} diff --git a/pve-rs/src/bindings/pci/mod.rs b/pve-rs/src/bindings/pci/mod.rs new file mode 100644 index 0000000..d1b00dd --- /dev/null +++ b/pve-rs/src/bindings/pci/mod.rs @@ -0,0 +1,2 @@ +mod hardware_config; +pub use hardware_config::pve_rs_pci_hardware_config; -- 2.47.3