From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH v3 proxmox-perl-rs 02/76] pve-rs: add PVE::RS::Multipath bindings for multipathd status parsing
Date: Fri, 6 Nov 2026 00:30:37 +0100 [thread overview]
Message-ID: <20261105233336.2178064-3-t.lamprecht@proxmox.com> (raw)
In-Reply-To: <20261105233336.2178064-1-t.lamprecht@proxmox.com>
Expose the multipathd map parser and the health derivation of the
proxmox-multipath crate to Perl. The managed dm-multipath support in
pve-storage then only runs the daemon command and passes its output
on, instead of keeping a parser of its own. The parser takes the raw
command output, so map aliases with non-ASCII characters keep their
names without a decoding step on the Perl side.
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
pve-rs/Cargo.toml | 1 +
pve-rs/Makefile | 2 +
pve-rs/debian/control | 1 +
pve-rs/src/bindings/mod.rs | 3 ++
pve-rs/src/bindings/multipath.rs | 40 +++++++++++++++++
pve-rs/test/Makefile | 1 +
pve-rs/test/multipath.pl | 74 ++++++++++++++++++++++++++++++++
7 files changed, 122 insertions(+)
create mode 100644 pve-rs/src/bindings/multipath.rs
create mode 100755 pve-rs/test/multipath.pl
diff --git a/pve-rs/Cargo.toml b/pve-rs/Cargo.toml
index ecedb1e..b89f91a 100644
--- a/pve-rs/Cargo.toml
+++ b/pve-rs/Cargo.toml
@@ -38,6 +38,7 @@ proxmox-frr = { version = "0.6.0" }
proxmox-http = { version = "1.0.2", features = ["client-sync", "client-trait"] }
proxmox-http-error = "1"
proxmox-log = "1"
+proxmox-multipath = "0.1"
proxmox-network-types = "1.1.2"
proxmox-notify = { version = "2", features = ["pve-context", "legacy-matchers"] }
proxmox-oci = "0.2.2"
diff --git a/pve-rs/Makefile b/pve-rs/Makefile
index 60f68c7..458ea68 100644
--- a/pve-rs/Makefile
+++ b/pve-rs/Makefile
@@ -27,6 +27,7 @@ PERLMOD_GENPACKAGE := /usr/lib/perlmod/genpackage.pl \
PERLMOD_PACKAGES := \
PVE::RS::Firewall::SDN \
+ PVE::RS::Multipath \
PVE::RS::Notify \
PVE::RS::NVML \
PVE::RS::OCI \
@@ -59,6 +60,7 @@ PROXMOX_DOC_CRATES := \
proxmox-http \
proxmox-http-error \
proxmox-log \
+ proxmox-multipath \
proxmox-notify \
proxmox-openid \
proxmox-resource-scheduling \
diff --git a/pve-rs/debian/control b/pve-rs/debian/control
index ad8611e..33a9bcb 100644
--- a/pve-rs/debian/control
+++ b/pve-rs/debian/control
@@ -26,6 +26,7 @@ Build-Depends: debhelper-compat (= 13),
librust-proxmox-http-1+default-dev (>= 1.0.2-~~),
librust-proxmox-http-error-1+default-dev,
librust-proxmox-log-1+default-dev,
+ librust-proxmox-multipath-0.1+default-dev,
librust-proxmox-network-types-1+default-dev (>= 1.1.2-~~),
librust-proxmox-notify-2+default-dev,
librust-proxmox-notify-2+legacy-matchers-dev,
diff --git a/pve-rs/src/bindings/mod.rs b/pve-rs/src/bindings/mod.rs
index 143a62b..c229327 100644
--- a/pve-rs/src/bindings/mod.rs
+++ b/pve-rs/src/bindings/mod.rs
@@ -1,5 +1,8 @@
//! This contains all the perl bindings.
+mod multipath;
+pub use multipath::pve_rs_multipath;
+
mod nvml;
pub use nvml::pve_rs_nvml;
diff --git a/pve-rs/src/bindings/multipath.rs b/pve-rs/src/bindings/multipath.rs
new file mode 100644
index 0000000..447c4aa
--- /dev/null
+++ b/pve-rs/src/bindings/multipath.rs
@@ -0,0 +1,40 @@
+//! Device-mapper multipath status parsing and health derivation.
+
+#[perlmod::package(name = "PVE::RS::Multipath", lib = "pve_rs")]
+pub mod pve_rs_multipath {
+ //! The `PVE::RS::Multipath` package.
+ //!
+ //! Pure helpers around device-mapper multipath state. The Perl side queries the daemon and
+ //! passes its output here.
+ //!
+ //! See [`proxmox_multipath`].
+
+ use anyhow::Error;
+
+ use proxmox_multipath::{Health, Map};
+
+ /// Parse the output of `multipathd show maps json` into normalized maps, each with its LUN
+ /// WWID, path groups, member paths and derived health.
+ ///
+ /// Takes the raw command output. `multipathd` prints map aliases as configured, so bytes that
+ /// are not valid UTF-8 are replaced rather than failing the status of every map.
+ ///
+ /// See [`proxmox_multipath::parse_maps_json`].
+ #[export]
+ pub fn parse_maps_json(json: &[u8]) -> Result<Vec<Map>, Error> {
+ proxmox_multipath::parse_maps_json(&String::from_utf8_lossy(json))
+ }
+
+ /// Derive the health of a map from its active and total path counts, and the number of paths
+ /// it is expected to have when the transport configuration knows that.
+ ///
+ /// See [`proxmox_multipath::derive_health`].
+ #[export]
+ pub fn derive_health(
+ paths_active: u64,
+ paths_total: u64,
+ paths_expected: Option<u64>,
+ ) -> Health {
+ proxmox_multipath::derive_health(paths_active, paths_total, paths_expected)
+ }
+}
diff --git a/pve-rs/test/Makefile b/pve-rs/test/Makefile
index 29dc955..1ed3210 100644
--- a/pve-rs/test/Makefile
+++ b/pve-rs/test/Makefile
@@ -2,6 +2,7 @@
test: Proxmox/Lib/PVE.pm
@echo "-- running pve-rs tests --"
perl -I. -I.. -I../.. ./resource_scheduling.pl
+ perl -I. -I.. -I../.. ./multipath.pl
# The test stub, we don't know where to look for the library from in here!
Proxmox/Lib/PVE.pm:
diff --git a/pve-rs/test/multipath.pl b/pve-rs/test/multipath.pl
new file mode 100755
index 0000000..2f30008
--- /dev/null
+++ b/pve-rs/test/multipath.pl
@@ -0,0 +1,74 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+
+use PVE::RS::Multipath;
+
+# a recorded `multipathd show maps json` reply: one healthy map, one with a failed path
+my $json = <<'JSON';
+{
+ "major_version": 0,
+ "minor_version": 1,
+ "maps": [
+ {
+ "name": "mpatha", "uuid": "3600140500a1b2c3d4e5f6a7b8c9d0e1f", "sysfs": "dm-0",
+ "dm_st": "active", "path_faults": 0,
+ "path_groups": [ { "group": 1, "dm_st": "active", "pri": 50, "paths": [
+ { "dev": "sdb", "dm_st": "active", "dev_st": "running", "chk_st": "ready", "pri": 50,
+ "host_wwpn": "0x21000024ff7d6a1c", "target_wwpn": "0x500a098000000001" },
+ { "dev": "sdc", "dm_st": "active", "dev_st": "running", "chk_st": "ready", "pri": 50,
+ "host_wwpn": "0x21000024ff7d6a1d", "target_wwpn": "0x500a098000000002" }
+ ] } ]
+ },
+ {
+ "name": "mpathb", "uuid": "360014050aabbccddeeff00112233445566", "sysfs": "dm-1",
+ "dm_st": "active", "path_faults": "3",
+ "path_groups": [
+ { "group": 1, "dm_st": "active", "pri": 10, "paths": [
+ { "dev": "sdd", "dm_st": "active", "chk_st": "ready", "pri": 10, "target_wwpn": "[undef]" } ] },
+ { "group": 2, "dm_st": "enabled", "pri": 0, "paths": [
+ { "dev": "sde", "dm_st": "failed", "chk_st": "faulty", "pri": 0 } ] }
+ ]
+ }
+ ]
+}
+JSON
+
+my $maps = PVE::RS::Multipath::parse_maps_json($json);
+is(scalar($maps->@*), 2, 'both maps parsed');
+
+my ($a, $b) = $maps->@*;
+is($a->{wwid}, '3600140500a1b2c3d4e5f6a7b8c9d0e1f', 'map keyed on the daemon uuid');
+is($a->{health}, 'optimal', 'all paths active is optimal');
+is($a->{'paths-active'}, 2, 'active path count');
+is($a->{'paths-total'}, 2, 'total path count');
+is($a->{'path-groups'}->[0]->{paths}->[0]->{transport}, 'fc', 'a target WWPN means FC');
+is($a->{'path-groups'}->[0]->{paths}->[0]->{'host-wwpn'}, '0x21000024ff7d6a1c', 'host WWPN kept');
+
+is($b->{health}, 'degraded', 'a failed path makes the map degraded');
+is($b->{'path-faults'}, 3, 'a string number is accepted');
+ok(!exists $b->{'path-groups'}->[0]->{paths}->[0]->{'target-wwpn'}, "'[undef]' is dropped");
+ok(!exists $b->{'path-groups'}->[0]->{paths}->[0]->{transport}, "'[undef]' does not imply FC");
+is($b->{'path-groups'}->[1]->{'dm-state'}, 'enabled', 'group state kept');
+
+is(PVE::RS::Multipath::derive_health(2, 2, undef), 'optimal', 'health without expectation');
+is(PVE::RS::Multipath::derive_health(1, 1, 2), 'degraded', 'a removed path counts against it');
+is(PVE::RS::Multipath::derive_health(0, 2, undef), 'failed', 'no active path is failed');
+
+# raw command output with a UTF-8 alias and one with an invalid byte, then the same reply decoded
+my $raw = qq({ "maps": [ { "name": "lun-\xc3\xa9", "uuid": "3600a", "path_groups": [] },
+ { "name": "bad-\xff", "uuid": "3600b", "path_groups": [] } ] });
+my $raw_maps = PVE::RS::Multipath::parse_maps_json($raw);
+is($raw_maps->[0]->{name}, "lun-\x{e9}", 'a UTF-8 alias in raw output is decoded');
+is($raw_maps->[1]->{name}, "bad-\x{fffd}", 'an invalid byte does not fail the reply');
+my $decoded = $raw =~ s/\xff//r;
+utf8::decode($decoded);
+is(PVE::RS::Multipath::parse_maps_json($decoded)->[0]->{name}, "lun-\x{e9}", 'decoded input');
+
+eval { PVE::RS::Multipath::parse_maps_json('not json') };
+like($@, qr/could not parse multipathd maps JSON/, 'invalid input dies with a clear error');
+
+done_testing();
--
2.47.3
next prev parent reply other threads:[~2026-11-06 0:50 UTC|newest]
Thread overview: 77+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 23:30 [PATCH v3 proxmox,proxmox-perl-rs,cluster,storage,docs,manager 00/76] SAN: cluster-wide multipath, SAN views and a guided storage setup Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 proxmox 01/76] add proxmox-multipath crate Thomas Lamprecht
2026-11-05 23:30 ` Thomas Lamprecht [this message]
2026-11-05 23:30 ` [PATCH v3 cluster 03/76] cfs: observe the multipath configuration files Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 04/76] storage: distinguish status-only activation in plugins Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 05/76] lvm: find a shared volume group created by another node Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 06/76] storage: bound LVM status commands Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 07/76] iscsi: rate-limit session rescans per target Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 08/76] iscsi: list the LUNs of each session, not of its SCSI host Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 09/76] lvm: refuse to create a volume group on a device that holds data Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 10/76] lvm: refuse a base volume of a target that serves disk images Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 11/76] iscsi: refuse virtual devices other than multipath maps as volumes Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 12/76] diskmanage: collect disk transport type from lsblk Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 13/76] diskmanage: add helper to list multipath devices Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 14/76] diskmanage: qualify NVMe over fabrics transport Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 15/76] disks: list: add include-remote parameter Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 16/76] diskmanage: include iSCSI session devices in disk enumeration Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 17/76] diskmanage: link multipath member disks to their map device Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 18/76] iscsi: factor out session device map from device list Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 19/76] api: scan: add a SAN LUN inventory Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 20/76] pvesm: expose the " Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 21/76] disks: lvm: allow volume groups on SAN LUNs and multipath maps Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 22/76] multipath: add a library around multipathd Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 23/76] diskmanage: collect native NVMe multipath path state Thomas Lamprecht
2026-11-05 23:30 ` [PATCH v3 storage 24/76] api: scan: san-luns: report " Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 25/76] diskmanage: collect local block device users Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 26/76] api: add node-level iSCSI status and maintenance Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 27/76] api: iscsi: add session logout with last-path protection Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 28/76] multipath: add a cluster-wide configuration Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 29/76] iscsi: add an option to manage storage LUNs with multipath Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 30/76] lvm: activate a missing base volume before using the volume group Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 31/76] multipath: apply the configuration on every node Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 32/76] iscsi: share the initiator identity reader Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 33/76] multipath: publish per-node status Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 34/76] api: add endpoints for the cluster-wide multipath configuration Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 35/76] api: multipath: add the cluster-wide health status Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 36/76] multipath: collect identities of non-iSCSI SCSI paths Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 37/76] api: scan: san-luns: report the multipath state of each LUN Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 38/76] api: scan: flag duplicate physical volumes on distinct LUNs Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 39/76] api: disks: recheck local users and retain wipe device references Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 40/76] iscsi: name plain LUNs after their identity link Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 41/76] api: disks: guard SAN wipes with stable identities and storage checks Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 storage 42/76] api: scan: refresh SAN usage with bounded probes Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 docs 43/76] storage: lvm: note the rescan after extending a shared volume group Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 docs 44/76] storage: document the cluster-wide multipath management Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 45/76] api: ceph: osd: keep iSCSI LUNs out of OSD creation Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 46/76] pvestatd: track pending storage status commands across re-exec Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 47/76] ui: storage: factor out the scan picker error mask Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 48/76] ui: storage: nfs: show scan errors and empty results Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 49/76] ui: storage: allow changing the node for NFS/CIFS scans Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 50/76] ui: storage: add guided remote storage wizard with NFS support Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 51/76] ui: storage wizard: add SMB/CIFS support Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 52/76] ui: storage wizard: preserve settings after partial setup Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 53/76] ui: storage wizard: add Fibre Channel shared LVM setup Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 54/76] ui: storage wizard: reconcile unanswered storage creation Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 55/76] ui: storage wizard: add ZFS over iSCSI support Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 56/76] ui: dc: storage: add remote storage wizard entry to the add menu Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 57/76] ui: node: add SAN LUNs panel Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 58/76] ui: san luns: show multipath path state Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 59/76] api: nodes: expose iSCSI status and maintenance Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 60/76] pvenode: add iscsi commands Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 61/76] ui: node: san: add iSCSI target and session management Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 62/76] pvestatd: apply the multipath configuration and report the node status Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 63/76] api: cluster: add the multipath endpoints Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 64/76] ui: dc: add a cluster-wide multipath view Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 65/76] ui: storage: iscsi: add the multipath option Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 66/76] ui: san luns: show multipath state and manage LUN entries Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 67/76] ui: storage wizard: add iSCSI support Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 68/76] ui: storage wizard: iscsi: show cluster initiator names Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 69/76] ui: storage wizard: iscsi: enable multipath for shared LVM Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 70/76] ui: node: san: wipe a LUN that no storage uses Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 71/76] ui: storage wizard: iscsi: reuse existing target connections Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 72/76] ui: storage wizard: fibre channel: enable multipath for a LUN Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 73/76] ui: storage wizard: let root@pam wipe a LUN with data Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 74/76] ui: storage wizard: do not offer LUNs in use for a new volume group Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 75/76] ui: san: show the local users of a LUN in its usage tooltip Thomas Lamprecht
2026-11-05 23:31 ` [PATCH v3 manager 76/76] ui: san: check the other nodes for users before wiping a LUN Thomas Lamprecht
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=20261105233336.2178064-3-t.lamprecht@proxmox.com \
--to=t.lamprecht@proxmox.com \
--cc=pve-devel@lists.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox