From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 0AFD71FF0A5 for ; Thu, 19 Nov 2026 15:51:59 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 8B2182170E; Thu, 19 Nov 2026 15:51:57 +0100 (CET) Message-ID: <97046dbe-c446-46f0-8be7-05287ca30f4f@proxmox.com> Date: Thu, 19 Nov 2026 15:51:52 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Subject: Re: [PATCH qemu-server v5 04/13] pve-qemu-rs: build perlmod library with bindings for pve-qemu-pci To: Elias Huhsovitz , pve-devel@lists.proxmox.com, Wolfgang Bumiller References: <20261118152803.3843758-1-d.csapak@proxmox.com> <20261118152803.3843758-5-d.csapak@proxmox.com> Content-Language: en-US From: Dominik Csapak In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795099912353 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.149 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 SCC_5_SHORT_WORD_LINES 0.25 5 lines with many short words 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: TTDPHPLGC27NJTEU7I43NGMW5VBGC2BP X-Message-ID-Hash: TTDPHPLGC27NJTEU7I43NGMW5VBGC2BP 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: On 11/19/26 1:47 PM, Elias Huhsovitz wrote: > Comments inline. > > On Wed Nov 18, 2026 at 4:27 PM CET, Dominik Csapak wrote: >> These provide bindings for using the Rust PCI code in the Perl code of >> qemu-server. This exposes 'PVE::QemuServer::RS::PCI::HardwareConfig', >> which provides an object that can be used to query the PCI addresses >> of QEMU VMs. >> >> The library is built from the new 'pve-qemu-perl' crate and shipped >> with the qemu-server package, so the Rust code and its Perl users can >> change together, without going through libpve-rs-perl. >> >> It uses its own library tag, since libraries with the same tag share >> their loading state, which Proxmox::Lib::Common uses to find the >> library with the common bindings of libpve-rs-perl. >> >> The generated modules and the library are placed in >> pve-qemu-rs/build/perl, laid out like in @INC, so that the tests and >> the documentation generation can use them without installing them. >> >> Signed-off-by: Dominik Csapak >> --- > > [...] > >> --- a/pve-qemu-rs/Makefile >> +++ b/pve-qemu-rs/Makefile >> @@ -1,10 +1,62 @@ >> CARGO ?= cargo >> >> -all: >> +PERL_INSTALLVENDORARCH != perl -MConfig -e 'print $$Config{installvendorarch};' >> +PERL_INSTALLVENDORLIB != perl -MConfig -e 'print $$Config{installvendorlib};' >> + >> +ifeq ($(BUILD_MODE), release) >> +CARGO_BUILD_ARGS += --release >> +TARGET_DIR=release >> +else >> +TARGET_DIR=debug >> +endif >> + >> +LIBNAME := pve_qemu_perl >> +LIB := target/$(TARGET_DIR)/lib$(LIBNAME).so >> + >> +# The generated modules and the library, laid out like in @INC, so that the code in src/ can be >> +# used without installing them. >> +PERL_BUILDDIR := build/perl >> + >> +PERLMOD_GENPACKAGE ?= /usr/lib/perlmod/genpackage.pl >> + >> +# Libraries with the same tag share their loading state, so this must not use the 'proxmox' tag >> +# of libpve-rs-perl. >> +PERLMOD_GENPACKAGE_ARGS := \ >> + --lib=$(LIBNAME) \ >> + --lib-tag=pve-qemu \ >> + --lib-package=PVE::QemuServer::RS::Lib \ >> + --lib-prefix=PVE::QemuServer >> + >> +PERLMOD_PACKAGES := \ >> + PVE::QemuServer::RS::PCI::HardwareConfig >> + >> +PERLMOD_PACKAGE_FILES := \ >> + PVE/QemuServer/RS/Lib.pm \ >> + $(addsuffix .pm,$(subst ::,/,$(PERLMOD_PACKAGES))) >> + >> +.PHONY: all >> +all: $(addprefix $(PERL_BUILDDIR)/,$(PERLMOD_PACKAGE_FILES)) cargo-build >> + install -D -m644 $(LIB) $(PERL_BUILDDIR)/auto/lib$(LIBNAME).so >> + >> +.PHONY: cargo-build >> +cargo-build: >> + $(CARGO) build $(CARGO_BUILD_ARGS) >> + >> +$(addprefix $(PERL_BUILDDIR)/,$(PERLMOD_PACKAGE_FILES)) &: Makefile >> + rm -rf $(PERL_BUILDDIR)/PVE >> + mkdir -p $(PERL_BUILDDIR) >> + cd $(PERL_BUILDDIR) && $(PERLMOD_GENPACKAGE) $(PERLMOD_GENPACKAGE_ARGS) $(PERLMOD_PACKAGES) >> + >> +.PHONY: install >> +install: all >> + install -D -m644 $(LIB) $(DESTDIR)$(PERL_INSTALLVENDORARCH)/auto/lib$(LIBNAME).so > > This installs the shared library in the same path as the `proxmox-perl-rs` code. > e.g. on my system: > /usr/lib/x86_64-linux-gnu/perl5/5.40/auto/libpve_qemu_perl.so > /usr/lib/x86_64-linux-gnu/perl5/5.40/auto/libpve_rs.so > > AFAIK this breaks convention. IMO it should sit in path like this: > /usr/lib/x86_64-linux-gnu/perl5/5.40/auto/PVE/QemuServer/libpve_qemu_perl.so > > I am not sure if this intended for libpve_rs.so, but in case it is not, > we shouldn't follow this design pattern. (And probably fix this for > libpve_rs.so as well) > honestly i just copied this over, maybe @wolfgang has a stronger insight on this? >> + for f in $(PERLMOD_PACKAGE_FILES); do \ >> + install -D -m644 $(PERL_BUILDDIR)/$$f $(DESTDIR)$(PERL_INSTALLVENDORLIB)/$$f; \ >> + done >> >> .PHONY: test >> test: >> - $(CARGO) test >> + $(CARGO) test $(CARGO_BUILD_ARGS) >> >> # Prints a diff between the current code and the one rustfmt would produce >> .PHONY: fmt >> @@ -14,3 +66,4 @@ fmt: >> .PHONY: clean >> clean: >> $(CARGO) clean >> + rm -rf build >> diff --git a/pve-qemu-rs/pve-qemu-perl/Cargo.toml b/pve-qemu-rs/pve-qemu-perl/Cargo.toml >> new file mode 100644 >> index 00000000..48dc8e93 >> --- /dev/null >> +++ b/pve-qemu-rs/pve-qemu-perl/Cargo.toml >> @@ -0,0 +1,19 @@ >> +[package] >> +name = "pve-qemu-perl" >> +version = "0.1.0" >> +description = "Perl bindings for the Rust parts of qemu-server" >> +authors.workspace = true >> +edition.workspace = true >> +license.workspace = true >> +repository.workspace = true >> +homepage.workspace = true >> +rust-version.workspace = true >> + >> +[lib] >> +crate-type = ["cdylib"] >> + >> +[dependencies] >> +anyhow.workspace = true >> +perlmod = { workspace = true, features = ["exporter"] } >> + >> +pve-qemu-pci.workspace = true >> diff --git a/pve-qemu-rs/pve-qemu-perl/src/lib.rs b/pve-qemu-rs/pve-qemu-perl/src/lib.rs >> new file mode 100644 >> index 00000000..be545ef8 >> --- /dev/null >> +++ b/pve-qemu-rs/pve-qemu-perl/src/lib.rs >> @@ -0,0 +1,14 @@ >> +//! Perl bindings for the Rust parts of qemu-server. >> +//! >> +//! The packages are available below `PVE::QemuServer::RS`. >> + >> +#![deny(missing_docs)] >> + >> +pub mod pci; >> + >> +#[perlmod::package(name = "PVE::QemuServer::RS::Lib", lib = "pve_qemu_perl")] >> +pub mod pve_qemu_rs_lib { >> + //! The `PVE::QemuServer::RS::Lib` package. >> + //! >> + //! The base package of all other packages, which loads the library. >> +} >> diff --git a/pve-qemu-rs/pve-qemu-perl/src/pci/hardware_config.rs b/pve-qemu-rs/pve-qemu-perl/src/pci/hardware_config.rs >> new file mode 100644 >> index 00000000..53bb41bb >> --- /dev/null >> +++ b/pve-qemu-rs/pve-qemu-perl/src/pci/hardware_config.rs >> @@ -0,0 +1,117 @@ >> +#[perlmod::package( >> + name = "PVE::QemuServer::RS::PCI::HardwareConfig", >> + lib = "pve_qemu_perl" >> +)] >> +pub mod pve_qemu_rs_pci_hardware_config { >> + //! The `PVE::QemuServer::RS::PCI::HardwareConfig` package. >> + //! >> + //! Provides bindings for the `HardwareConfig` struct of the `pve-qemu-pci` crate. >> + >> + use std::ops::Deref; >> + use std::rc::Rc; >> + >> + use anyhow::Error; >> + >> + use perlmod::Value; >> + >> + use pve_qemu_pci::{HardwareConfigParams, LayoutError, address}; >> + >> + perlmod::declare_magic!(Box: &HardwareConfig as "PVE::QemuServer::RS::PCI::HardwareConfig"); >> + >> + /// Wrapper for [`pve_qemu_pci::HardwareConfig`]. >> + pub struct HardwareConfig { >> + inner: Rc, >> + } >> + >> + impl Deref for HardwareConfig { >> + type Target = pve_qemu_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_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_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.machine.mainboard.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_pci::pci_bridge_for_device(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-qemu-rs/pve-qemu-perl/src/pci/mod.rs b/pve-qemu-rs/pve-qemu-perl/src/pci/mod.rs >> new file mode 100644 >> index 00000000..1d2214a6 >> --- /dev/null >> +++ b/pve-qemu-rs/pve-qemu-perl/src/pci/mod.rs >> @@ -0,0 +1,4 @@ >> +//! Bindings for the `pve-qemu-pci` crate. >> + >> +mod hardware_config; >> +pub use hardware_config::pve_qemu_rs_pci_hardware_config; >> diff --git a/src/Makefile b/src/Makefile >> index f8e9a2d9..b0441252 100644 >> --- a/src/Makefile >> +++ b/src/Makefile >> @@ -1,7 +1,14 @@ >> +# The Rust workspace is next to src/ in git, the package build copies it into the build directory. >> +PVE_QEMU_RS ?= $(abspath ../pve-qemu-rs) >> +export PVE_QEMU_RS >> + >> +.PHONY: all >> all: >> + $(MAKE) -C $(PVE_QEMU_RS) >> >> .PHONY: install >> install: >> + $(MAKE) -C $(PVE_QEMU_RS) install >> $(MAKE) -C PVE install >> $(MAKE) -C bin install >> $(MAKE) -C qmeventd install >> @@ -9,12 +16,14 @@ install: >> $(MAKE) -C usr install >> >> .PHONY: test >> -test: >> +test: all >> + $(MAKE) -C $(PVE_QEMU_RS) test >> $(MAKE) -C test >> $(MAKE) -C bin $@ >> >> .PHONY: clean >> clean: >> + $(MAKE) -C $(PVE_QEMU_RS) clean >> $(MAKE) -C test $@ >> $(MAKE) -C bin $@ >> >> diff --git a/src/bin/Makefile b/src/bin/Makefile >> index 72763873..8e7aa309 100644 >> --- a/src/bin/Makefile >> +++ b/src/bin/Makefile >> @@ -10,26 +10,29 @@ MAN5DIR=$(MANDIR)/man5/ >> BASHCOMPLDIR=$(PREFIX)/share/bash-completion/completions/ >> ZSHCOMPLDIR=$(PREFIX)/share/zsh/vendor-completions/ >> >> -PERL_DOC_INC_DIRS=.. >> +PVE_QEMU_RS ?= $(abspath ../../pve-qemu-rs) >> +PVE_QEMU_RS_PERL = $(PVE_QEMU_RS)/build/perl >> + >> +PERL_DOC_INC_DIRS=.. $(PVE_QEMU_RS_PERL) >> -include /usr/share/pve-doc-generator/pve-doc-generator.mk >> >> all: >> >> >> qm.bash-completion: >> - PVE_GENERATING_DOCS=1 perl -I.. -T -e "use PVE::CLI::qm; PVE::CLI::qm->generate_bash_completions();" >$@.tmp >> + PVE_GENERATING_DOCS=1 perl -I.. -I$(PVE_QEMU_RS_PERL) -T -e "use PVE::CLI::qm; PVE::CLI::qm->generate_bash_completions();" >$@.tmp >> mv $@.tmp $@ >> >> qmrestore.bash-completion: >> - PVE_GENERATING_DOCS=1 perl -I.. -T -e "use PVE::CLI::qmrestore; PVE::CLI::qmrestore->generate_bash_completions();" >$@.tmp >> + PVE_GENERATING_DOCS=1 perl -I.. -I$(PVE_QEMU_RS_PERL) -T -e "use PVE::CLI::qmrestore; PVE::CLI::qmrestore->generate_bash_completions();" >$@.tmp >> mv $@.tmp $@ >> >> qm.zsh-completion: >> - PVE_GENERATING_DOCS=1 perl -I.. -T -e "use PVE::CLI::qm; PVE::CLI::qm->generate_zsh_completions();" >$@.tmp >> + PVE_GENERATING_DOCS=1 perl -I.. -I$(PVE_QEMU_RS_PERL) -T -e "use PVE::CLI::qm; PVE::CLI::qm->generate_zsh_completions();" >$@.tmp >> mv $@.tmp $@ >> >> qmrestore.zsh-completion: >> - PVE_GENERATING_DOCS=1 perl -I.. -T -e "use PVE::CLI::qmrestore; PVE::CLI::qmrestore->generate_zsh_completions();" >$@.tmp >> + PVE_GENERATING_DOCS=1 perl -I.. -I$(PVE_QEMU_RS_PERL) -T -e "use PVE::CLI::qmrestore; PVE::CLI::qmrestore->generate_zsh_completions();" >$@.tmp >> mv $@.tmp $@ >> >> PKGSOURCES=qm qm.1 qmrestore qmrestore.1 qmextract qm.conf.5 qm.bash-completion qmrestore.bash-completion \ >> @@ -57,7 +60,7 @@ install: $(PKGSOURCES) >> >> .PHONY: test >> test: >> - PVE_GENERATING_DOCS=1 perl -I.. ./qm verifyapi >> + PVE_GENERATING_DOCS=1 perl -I.. -I$(PVE_QEMU_RS_PERL) ./qm verifyapi >> >> .PHONY: clean >> clean: >> diff --git a/src/test/Makefile b/src/test/Makefile >> index fa14908e..825b3afa 100644 >> --- a/src/test/Makefile >> +++ b/src/test/Makefile >> @@ -1,3 +1,6 @@ >> +PVE_QEMU_RS ?= $(abspath ../../pve-qemu-rs) >> +export PERL5LIB := $(PVE_QEMU_RS)/build/perl$(if $(PERL5LIB),:$(PERL5LIB)) >> + >> all: test >> >> test: test_snapshot test_cfg_to_cmd test_cfg_to_cmd_aarch64 test_hotplug test_hotplug_aarch64 test_pci_addr_conflicts test_pci_reservation test_qemu_img_convert test_migration test_restore_config test_parse_config test_memory test_agent test_raw_config_write test_api test_api_cloudinit_dump >