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 949E41FF0DE for ; Thu, 19 Nov 2026 13:48:50 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 941782170B; Thu, 19 Nov 2026 13:48:42 +0100 (CET) Content-Type: text/plain; charset=UTF-8 Date: Thu, 19 Nov 2026 13:47:57 +0100 Message-Id: Subject: Re: [PATCH qemu-server v5 04/13] pve-qemu-rs: build perlmod library with bindings for pve-qemu-pci From: "Elias Huhsovitz" To: "Dominik Csapak" , Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: aerc 0.20.0 References: <20261118152803.3843758-1-d.csapak@proxmox.com> <20261118152803.3843758-5-d.csapak@proxmox.com> In-Reply-To: <20261118152803.3843758-5-d.csapak@proxmox.com> X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795092477965 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.281 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: GRC67KLDWBC2JA4T2KZP65C52TNHNPST X-Message-ID-Hash: GRC67KLDWBC2JA4T2KZP65C52TNHNPST X-MailFrom: e.huhsovitz@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: 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 ?=3D cargo > =20 > -all: > +PERL_INSTALLVENDORARCH !=3D perl -MConfig -e 'print $$Config{installvend= orarch};' > +PERL_INSTALLVENDORLIB !=3D perl -MConfig -e 'print $$Config{installvendo= rlib};' > + > +ifeq ($(BUILD_MODE), release) > +CARGO_BUILD_ARGS +=3D --release > +TARGET_DIR=3Drelease > +else > +TARGET_DIR=3Ddebug > +endif > + > +LIBNAME :=3D pve_qemu_perl > +LIB :=3D 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 :=3D build/perl > + > +PERLMOD_GENPACKAGE ?=3D /usr/lib/perlmod/genpackage.pl > + > +# Libraries with the same tag share their loading state, so this must no= t use the 'proxmox' tag > +# of libpve-rs-perl. > +PERLMOD_GENPACKAGE_ARGS :=3D \ > + --lib=3D$(LIBNAME) \ > + --lib-tag=3Dpve-qemu \ > + --lib-package=3DPVE::QemuServer::RS::Lib \ > + --lib-prefix=3DPVE::QemuServer > + > +PERLMOD_PACKAGES :=3D \ > + PVE::QemuServer::RS::PCI::HardwareConfig > + > +PERLMOD_PACKAGE_FILES :=3D \ > + 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$(L= IBNAME).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.s= o 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) > + for f in $(PERLMOD_PACKAGE_FILES); do \ > + install -D -m644 $(PERL_BUILDDIR)/$$f $(DESTDIR)$(PERL_INSTALLVENDO= RLIB)/$$f; \ > + done > =20 > .PHONY: test > test: > - $(CARGO) test > + $(CARGO) test $(CARGO_BUILD_ARGS) > =20 > # Prints a diff between the current code and the one rustfmt would produ= ce > .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 =3D "pve-qemu-perl" > +version =3D "0.1.0" > +description =3D "Perl bindings for the Rust parts of qemu-server" > +authors.workspace =3D true > +edition.workspace =3D true > +license.workspace =3D true > +repository.workspace =3D true > +homepage.workspace =3D true > +rust-version.workspace =3D true > + > +[lib] > +crate-type =3D ["cdylib"] > + > +[dependencies] > +anyhow.workspace =3D true > +perlmod =3D { workspace =3D true, features =3D ["exporter"] } > + > +pve-qemu-pci.workspace =3D 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 =3D "PVE::QemuServer::RS::Lib", lib =3D "pve_qem= u_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-q= emu-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 =3D "PVE::QemuServer::RS::PCI::HardwareConfig", > + lib =3D "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-qe= mu-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 =3D 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) -> Res= ult { > + let hw_config =3D pve_qemu_pci::HardwareConfig::new(params); > + Ok( > + perlmod::instantiate_magic!(&class, MAGIC =3D> Box::new(Hard= wareConfig { 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) =3D> Ok(Some(addr.to_qemu_addr())), > + Err(LayoutError::NoAddressFound(_)) =3D> Ok(None), > + Err(other) =3D> Err(other), > + } > + } > + > + #[export] > + /// Method: Get the `-device` arguments of all bridges, root ports a= nd 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 versio= n > + /// 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 kno= wn device. > + pub fn pci_bridge_for_device( > + #[try_from_ref] _this: &HardwareConfig, > + device: &str, > + ) -> Option { > + let bus =3D 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-q= emu-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 ?=3D $(abspath ../pve-qemu-rs) > +export PVE_QEMU_RS > + > +.PHONY: all > all: > + $(MAKE) -C $(PVE_QEMU_RS) > =20 > .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 > =20 > .PHONY: test > -test: > +test: all > + $(MAKE) -C $(PVE_QEMU_RS) test > $(MAKE) -C test > $(MAKE) -C bin $@ > =20 > .PHONY: clean > clean: > + $(MAKE) -C $(PVE_QEMU_RS) clean > $(MAKE) -C test $@ > $(MAKE) -C bin $@ > =20 > 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=3D$(MANDIR)/man5/ > BASHCOMPLDIR=3D$(PREFIX)/share/bash-completion/completions/ > ZSHCOMPLDIR=3D$(PREFIX)/share/zsh/vendor-completions/ > =20 > -PERL_DOC_INC_DIRS=3D.. > +PVE_QEMU_RS ?=3D $(abspath ../../pve-qemu-rs) > +PVE_QEMU_RS_PERL =3D $(PVE_QEMU_RS)/build/perl > + > +PERL_DOC_INC_DIRS=3D.. $(PVE_QEMU_RS_PERL) > -include /usr/share/pve-doc-generator/pve-doc-generator.mk > =20 > all: > =20 > =20 > qm.bash-completion: > - PVE_GENERATING_DOCS=3D1 perl -I.. -T -e "use PVE::CLI::qm; PVE::CLI::qm= ->generate_bash_completions();" >$@.tmp > + PVE_GENERATING_DOCS=3D1 perl -I.. -I$(PVE_QEMU_RS_PERL) -T -e "use PVE:= :CLI::qm; PVE::CLI::qm->generate_bash_completions();" >$@.tmp > mv $@.tmp $@ > =20 > qmrestore.bash-completion: > - PVE_GENERATING_DOCS=3D1 perl -I.. -T -e "use PVE::CLI::qmrestore; PVE::= CLI::qmrestore->generate_bash_completions();" >$@.tmp > + PVE_GENERATING_DOCS=3D1 perl -I.. -I$(PVE_QEMU_RS_PERL) -T -e "use PVE:= :CLI::qmrestore; PVE::CLI::qmrestore->generate_bash_completions();" >$@.tmp > mv $@.tmp $@ > =20 > qm.zsh-completion: > - PVE_GENERATING_DOCS=3D1 perl -I.. -T -e "use PVE::CLI::qm; PVE::CLI::qm= ->generate_zsh_completions();" >$@.tmp > + PVE_GENERATING_DOCS=3D1 perl -I.. -I$(PVE_QEMU_RS_PERL) -T -e "use PVE:= :CLI::qm; PVE::CLI::qm->generate_zsh_completions();" >$@.tmp > mv $@.tmp $@ > =20 > qmrestore.zsh-completion: > - PVE_GENERATING_DOCS=3D1 perl -I.. -T -e "use PVE::CLI::qmrestore; PVE::= CLI::qmrestore->generate_zsh_completions();" >$@.tmp > + PVE_GENERATING_DOCS=3D1 perl -I.. -I$(PVE_QEMU_RS_PERL) -T -e "use PVE:= :CLI::qmrestore; PVE::CLI::qmrestore->generate_zsh_completions();" >$@.tmp > mv $@.tmp $@ > =20 > PKGSOURCES=3Dqm qm.1 qmrestore qmrestore.1 qmextract qm.conf.5 qm.bash-c= ompletion qmrestore.bash-completion \ > @@ -57,7 +60,7 @@ install: $(PKGSOURCES) > =20 > .PHONY: test > test: > - PVE_GENERATING_DOCS=3D1 perl -I.. ./qm verifyapi > + PVE_GENERATING_DOCS=3D1 perl -I.. -I$(PVE_QEMU_RS_PERL) ./qm verifyapi > =20 > .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 ?=3D $(abspath ../../pve-qemu-rs) > +export PERL5LIB :=3D $(PVE_QEMU_RS)/build/perl$(if $(PERL5LIB),:$(PERL5L= IB)) > + > all: test > =20 > 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_qem= u_img_convert test_migration test_restore_config test_parse_config test_mem= ory test_agent test_raw_config_write test_api test_api_cloudinit_dump