From: Dominik Csapak <d.csapak@proxmox.com>
To: Elias Huhsovitz <e.huhsovitz@proxmox.com>,
pve-devel@lists.proxmox.com,
Wolfgang Bumiller <w.bumiller@proxmox.com>
Subject: Re: [PATCH qemu-server v5 04/13] pve-qemu-rs: build perlmod library with bindings for pve-qemu-pci
Date: Thu, 19 Nov 2026 15:51:52 +0100 [thread overview]
Message-ID: <97046dbe-c446-46f0-8be7-05287ca30f4f@proxmox.com> (raw)
In-Reply-To: <DMZ76BUNBSIN.3A5NBTFP4DSR1@proxmox.com>
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 <d.csapak@proxmox.com>
>> ---
>
> [...]
>
>> --- 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>: &HardwareConfig as "PVE::QemuServer::RS::PCI::HardwareConfig");
>> +
>> + /// Wrapper for [`pve_qemu_pci::HardwareConfig`].
>> + pub struct HardwareConfig {
>> + inner: Rc<pve_qemu_pci::HardwareConfig>,
>> + }
>> +
>> + 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<Value, Error> {
>> + 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<Option<String>, 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<Vec<String>, 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<u16>,
>> + ) -> 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<String> {
>> + 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
>
next prev parent reply other threads:[~2026-11-19 14:51 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 15:27 [PATCH manager/qemu-server v5 00/13] pci-handling rewrite Dominik Csapak
2026-11-18 15:27 ` [PATCH qemu-server v5 01/13] pve-qemu-rs: add pve-qemu-pci crate for guest PCI address generation Dominik Csapak
2026-11-18 15:27 ` [PATCH qemu-server v5 02/13] pve-qemu-pci: legacy: generate pci bridges Dominik Csapak
2026-11-18 15:27 ` [PATCH qemu-server v5 03/13] pve-qemu-pci: legacy: generate q35 chipset devices and hostpcie root ports Dominik Csapak
2026-11-18 15:27 ` [PATCH qemu-server v5 04/13] pve-qemu-rs: build perlmod library with bindings for pve-qemu-pci Dominik Csapak
2026-11-19 12:47 ` Elias Huhsovitz
2026-11-19 14:51 ` Dominik Csapak [this message]
2026-11-18 15:27 ` [PATCH qemu-server v5 05/13] pci: use PVE::QemuServer::RS::PCI bindings for addresses and bus devices Dominik Csapak
2026-11-18 15:27 ` [PATCH qemu-server v5 06/13] tree-wide: use HardwareConfig for the machine version checks Dominik Csapak
2026-11-18 15:27 ` [PATCH qemu-server v5 07/13] cfg2cmd: q35: generate chipset devices with machine version 11.1+pve1 Dominik Csapak
2026-11-18 15:27 ` [PATCH qemu-server v5 08/13] pve-qemu-pci: layout: add grouped PCI and PCIe layouts Dominik Csapak
2026-11-18 15:27 ` [PATCH qemu-server v5 09/13] machine: add 'pci-layout' option Dominik Csapak
2026-11-18 15:27 ` [PATCH qemu-server v5 10/13] pve-qemu-pci: bus: add buses for numa expander bridges and pcie switches Dominik Csapak
2026-11-18 15:27 ` [PATCH qemu-server v5 11/13] pve-qemu-pci: topology: place hostpcie devices like on the host Dominik Csapak
2026-11-19 13:43 ` Elias Huhsovitz
2026-11-19 15:10 ` Dominik Csapak
2026-11-18 15:27 ` [PATCH qemu-server v5 12/13] machine: add 'pci-topology' option Dominik Csapak
2026-11-19 12:42 ` Elias Huhsovitz
2026-11-19 15:12 ` Dominik Csapak
2026-11-18 15:27 ` [PATCH pve-manager v5 13/13] ui: qemu machine: don't lose pci options on edit cycle Dominik Csapak
2026-11-19 12:18 ` [PATCH manager/qemu-server v5 00/13] pci-handling rewrite Elias Huhsovitz
2026-11-19 12:33 ` 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=97046dbe-c446-46f0-8be7-05287ca30f4f@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=e.huhsovitz@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
--cc=w.bumiller@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.