Adds some basic perl binding for the proxmox-ve-vfio, in particular to retrieve information about creatable vGPU typos for Nvidia host devices.
Signed-off-by: Christoph Heiss <[email protected]> --- pve-rs/Cargo.toml | 1 + pve-rs/Makefile | 3 +- pve-rs/debian/control | 1 + pve-rs/examples/nv-list-creatable-vgpus.pl | 20 ++++++++++++ pve-rs/src/lib.rs | 1 + pve-rs/src/vfio/mod.rs | 6 ++++ pve-rs/src/vfio/nvidia.rs | 38 ++++++++++++++++++++++ 7 files changed, 69 insertions(+), 1 deletion(-) create mode 100755 pve-rs/examples/nv-list-creatable-vgpus.pl create mode 100644 pve-rs/src/vfio/mod.rs create mode 100644 pve-rs/src/vfio/nvidia.rs diff --git a/pve-rs/Cargo.toml b/pve-rs/Cargo.toml index 527fcae..4e88942 100644 --- a/pve-rs/Cargo.toml +++ b/pve-rs/Cargo.toml @@ -49,6 +49,7 @@ proxmox-sys = "1" proxmox-tfa = { version = "6.0.3", features = ["api"] } proxmox-time = "2" proxmox-ve-config = { version = "0.4.5", features = [ "frr" ] } +proxmox-ve-vfio = { version = "0.1.0" } # [patch.crates-io] # pbs-api-types = { path = "../../proxmox/pbs-api-types" } diff --git a/pve-rs/Makefile b/pve-rs/Makefile index aa7181e..45ee12a 100644 --- a/pve-rs/Makefile +++ b/pve-rs/Makefile @@ -31,7 +31,8 @@ PERLMOD_PACKAGES := \ PVE::RS::OpenId \ PVE::RS::ResourceScheduling::Static \ PVE::RS::SDN::Fabrics \ - PVE::RS::TFA + PVE::RS::TFA \ + PVE::RS::VFIO::Nvidia PERLMOD_PACKAGE_FILES := $(addsuffix .pm,$(subst ::,/,$(PERLMOD_PACKAGES))) diff --git a/pve-rs/debian/control b/pve-rs/debian/control index 2743712..ec815f2 100644 --- a/pve-rs/debian/control +++ b/pve-rs/debian/control @@ -40,6 +40,7 @@ Build-Depends: cargo:native <!nocheck>, librust-proxmox-time-2+default-dev, librust-proxmox-ve-config-0.4+default-dev (>= 0.4.5-~~), librust-proxmox-ve-config-0.4+frr-dev (>= 0.4.5-~~), + librust-proxmox-ve-vfio-dev, librust-serde-1+default-dev, librust-serde-bytes-0.11+default-dev, librust-serde-json-1+default-dev, diff --git a/pve-rs/examples/nv-list-creatable-vgpus.pl b/pve-rs/examples/nv-list-creatable-vgpus.pl new file mode 100755 index 0000000..2814860 --- /dev/null +++ b/pve-rs/examples/nv-list-creatable-vgpus.pl @@ -0,0 +1,20 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use Data::Dumper; + +use PVE::RS::VFIO::Nvidia; + +my $bus_id = shift; + +die "vGPU bus id expected as first argument, e.g. 00:01.0\n" + if !defined($bus_id); + +my $creatable = + PVE::RS::VFIO::Nvidia::creatable_vgpu_types_for_dev($bus_id); + +foreach my $vgpu (@$creatable) { + print Dumper(\$vgpu); +} diff --git a/pve-rs/src/lib.rs b/pve-rs/src/lib.rs index b32b061..2e337da 100644 --- a/pve-rs/src/lib.rs +++ b/pve-rs/src/lib.rs @@ -14,6 +14,7 @@ use proxmox_notify::{Config, Notification, Severity}; mod common; mod sdn; +mod vfio; pub mod bindings; diff --git a/pve-rs/src/vfio/mod.rs b/pve-rs/src/vfio/mod.rs new file mode 100644 index 0000000..4c40a8d --- /dev/null +++ b/pve-rs/src/vfio/mod.rs @@ -0,0 +1,6 @@ +//! Exposes an interface for accessing and handling VFIO host devices such as NVIDIA vGPU devices, +//! to e.g. extract information about them for preparing passthrough. + +#![deny(missing_docs)] + +pub mod nvidia; diff --git a/pve-rs/src/vfio/nvidia.rs b/pve-rs/src/vfio/nvidia.rs new file mode 100644 index 0000000..5dc5730 --- /dev/null +++ b/pve-rs/src/vfio/nvidia.rs @@ -0,0 +1,38 @@ +//! Provides access to the state of NVIDIA (v)GPU devices connected to the system. + +#[perlmod::package(name = "PVE::RS::VFIO::Nvidia", lib = "pve_rs")] +mod export { + use anyhow::{Result, anyhow}; + use perlmod::Value; + use proxmox_ve_vfio::nvidia; + + /// Retrieves a list of *creatable* vGPU types for the specified GPU by bus id. + /// + /// The [`bus_id`] is of format "\<domain\>:\<bus\>:\<device\>.\<function\>", + /// e.g. "0000:01:01.0". + /// + /// # See also + /// + /// [`nvidia::creatable_vgpu_types_for_dev`] + /// [`nvmlDeviceGetHandleByPciBusId_v2`]: <https://docs.nvidia.com/deploy/nvml-api/group__nvmlDeviceQueries.html#group__nvmlDeviceQueries_1gea7484bb9eac412c28e8a73842254c05> + /// [`struct nvmlPciInto_t`]: <https://docs.nvidia.com/deploy/nvml-api/structnvmlPciInfo__t.html#structnvmlPciInfo__t_1a4d54ad9b596d7cab96ecc34613adbe4> + #[export] + fn creatable_vgpu_types_for_dev(bus_id: &str) -> Result<Vec<Value>> { + let vgpu_types = nvidia::creatable_vgpu_types_for_dev(bus_id)?; + + let mut result = Vec::with_capacity(vgpu_types.len()); + for vgpu in vgpu_types { + let mut value: Value = perlmod::to_value(&vgpu)? + .dereference() + .ok_or_else(|| anyhow!("expected reference"))?; + + if let Some(hash) = value.as_hash_mut() { + hash.insert("description", Value::new_string(&vgpu.description())); + } + + result.push(Value::new_ref(&value)); + } + + Ok(result) + } +} -- 2.52.0 _______________________________________________ pve-devel mailing list [email protected] https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
