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 A71861FF0AA for ; Tue, 22 Sep 2026 12:56:32 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 6D1DE2162F; Tue, 22 Sep 2026 12:55:57 +0200 (CEST) From: Dominik Csapak To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox-perl-rs 6/9] pve: pci bindings: add bindings for the `Machine` struct Date: Tue, 22 Sep 2026 12:55:37 +0200 Message-ID: <20260922105550.2084078-7-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.460 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: AIDKTK3SDC4LU5YD4TOSXN3L4LJ657EI X-Message-ID-Hash: AIDKTK3SDC4LU5YD4TOSXN3L4LJ657EI 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 is a better way to convey information necessary for some functions, so make use of it in the bindings. Signed-off-by: Dominik Csapak --- pve-rs/Makefile | 1 + pve-rs/src/bindings/pci/machine.rs | 45 ++++++++++++++++++++++++++++++ pve-rs/src/bindings/pci/mod.rs | 14 ++++------ 3 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 pve-rs/src/bindings/pci/machine.rs diff --git a/pve-rs/Makefile b/pve-rs/Makefile index dbffb38..20a7d24 100644 --- a/pve-rs/Makefile +++ b/pve-rs/Makefile @@ -30,6 +30,7 @@ PERLMOD_PACKAGES := \ PVE::RS::NVML \ PVE::RS::OCI \ PVE::RS::PCI \ + PVE::RS::PCI::Machine \ PVE::RS::OpenId \ PVE::RS::ResourceScheduling::Static \ PVE::RS::ResourceScheduling::Dynamic \ diff --git a/pve-rs/src/bindings/pci/machine.rs b/pve-rs/src/bindings/pci/machine.rs new file mode 100644 index 0000000..d9efc32 --- /dev/null +++ b/pve-rs/src/bindings/pci/machine.rs @@ -0,0 +1,45 @@ +#[perlmod::package(name = "PVE::RS::PCI::Machine", lib = "pve_rs")] +pub mod pve_rs_pci_machine { + //! The `PVE::RS::PCI::Machine` package. + //! + //! Provides bindings for the `Machine` struct of the [`pve-qemu-server-pci`] crate. + + use std::sync::RwLock; + + use anyhow::Error; + + use perlmod::Value; + + use pve_qemu_server_pci::Machine; + + perlmod::declare_magic!(Box: &MachineWrap as "PVE::RS::PCI::Machine"); + + /// Wraps the `Machine` struct behind an RwLock since most accesses are reads. + pub struct MachineWrap { + /// test + pub inner: RwLock, + } + + #[export(raw_return)] + #[allow(clippy::too_many_arguments)] + /// Create a instance of the `MachineWrap` struct + pub fn new( + #[raw] class: Value, + arch: String, + q35: bool, + scsihw: Option, + max_scsihw: u8, + legacy_igd: bool, + ostype: Option, + major: u16, + minor: u16, + pve: Option, + ) -> Result { + let machine = Machine::new( + &arch, q35, scsihw, max_scsihw, legacy_igd, ostype, major, minor, pve, + ); + Ok( + perlmod::instantiate_magic!(&class, MAGIC => Box::new(MachineWrap { inner: RwLock::new(machine) })), + ) + } +} diff --git a/pve-rs/src/bindings/pci/mod.rs b/pve-rs/src/bindings/pci/mod.rs index 9b3ad9d..a036704 100644 --- a/pve-rs/src/bindings/pci/mod.rs +++ b/pve-rs/src/bindings/pci/mod.rs @@ -1,3 +1,5 @@ +pub(crate) mod machine; + #[perlmod::package(name = "PVE::RS::PCI", lib = "pve_rs")] pub mod pve_rs_pci { //! The `PVE::RS::PCI` package. @@ -38,13 +40,9 @@ pub mod pve_rs_pci { } #[export] - /// Get the necessary PCI bridges for a guest from the given options. - pub fn get_pci_bridges( - arch: &str, - q35: bool, - virtio_scsi_single: bool, - legacy_igd: bool, - ) -> Vec { - pve_qemu_server_pci::get_pci_bridges(arch, q35, virtio_scsi_single, legacy_igd) + /// Get the necessary PCI bridges for a guest from the given config. + pub fn get_pci_bridges(#[try_from_ref] machine: &MachineWrap) -> Vec { + let machine = machine.inner.read().unwrap(); + pve_qemu_server_pci::get_pci_bridges(&machine) } } -- 2.47.3