From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH v5 storage 06/36] iscsi: factor out session device map from device list
Date: Mon, 16 Nov 2026 02:23:15 +0100 [thread overview]
Message-ID: <20261116012355.3187417-7-t.lamprecht@proxmox.com> (raw)
In-Reply-To: <20261116012355.3187417-1-t.lamprecht@proxmox.com>
From: Dietmar Maurer <dietmar@proxmox.com>
The SAN LUN inventory and the multipath handling need to know which
block devices belong to which iSCSI session, target and LUN. So far
only the device list of the plugin collects that. Provide it as a map
from kernel device names in a module of its own and build the device
list from it.
The device list stays the same. Only the fallback for the
'block:<name>' links that old kernels had instead of the 'block'
directory is gone.
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
[TL: put the session walk into the new PVE::ISCSI::Topology module,
with signatures, instead of the plugin; drop the fallback for old
kernels]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
src/PVE/ISCSI/Topology.pm | 67 +++++++++++++++++++++
src/PVE/Makefile | 1 +
src/PVE/Storage/ISCSIPlugin.pm | 107 +++++++++------------------------
3 files changed, 98 insertions(+), 77 deletions(-)
create mode 100644 src/PVE/ISCSI/Topology.pm
diff --git a/src/PVE/ISCSI/Topology.pm b/src/PVE/ISCSI/Topology.pm
new file mode 100644
index 00000000..52467864
--- /dev/null
+++ b/src/PVE/ISCSI/Topology.pm
@@ -0,0 +1,67 @@
+package PVE::ISCSI::Topology;
+
+use v5.36;
+
+use PVE::Tools qw(dir_glob_foreach dir_glob_regex file_read_firstline);
+
+our $SYSFS = '/sys';
+
+sub foreach_session_lun($sessiondir, $code) {
+ dir_glob_foreach(
+ $sessiondir,
+ 'target\d+:\d+:\d+',
+ sub($targetdir) {
+ dir_glob_foreach(
+ "$sessiondir/$targetdir",
+ '\d+:(\d+):(\d+):(\d+)',
+ sub($hctl, $channel, $id, $lun) {
+ $code->("$sessiondir/$targetdir/$hctl", $channel, $id, $lun);
+ },
+ );
+ },
+ );
+}
+
+sub sessions($sysfs = undef) {
+ $sysfs //= $SYSFS;
+ my $res = {};
+ dir_glob_foreach(
+ "$sysfs/class/iscsi_session",
+ 'session(\d+)',
+ sub($ent, $sid) {
+ my $dir = "$sysfs/class/iscsi_session/$ent";
+ my $target = file_read_firstline("$dir/targetname") // return;
+ my $session = {
+ target => $target,
+ devices => {},
+ };
+ foreach_session_lun(
+ "$dir/device",
+ sub($devdir, $channel, $id, $lun) {
+ return if (file_read_firstline("$devdir/type") // '') ne '0';
+ my (undef, $dev) = dir_glob_regex("$devdir/block/", '([A-Za-z]\S*)');
+ return if !defined($dev);
+ $session->{devices}->{$dev} = {
+ target => $target,
+ session => int($sid),
+ channel => int($channel),
+ id => int($id),
+ lun => int($lun),
+ };
+ },
+ );
+ $res->{$sid} = $session;
+ },
+ );
+ return $res;
+}
+
+sub device_map($sysfs = undef) {
+ my $res = {};
+ for my $session (values %{ sessions($sysfs) }) {
+ $res->{$_} = $session->{devices}->{$_} for keys $session->{devices}->%*;
+ }
+ return $res;
+}
+
+1;
diff --git a/src/PVE/Makefile b/src/PVE/Makefile
index 9e9f6aac..bd2ddfb9 100644
--- a/src/PVE/Makefile
+++ b/src/PVE/Makefile
@@ -4,6 +4,7 @@
install:
install -D -m 0644 Storage.pm ${DESTDIR}${PERLDIR}/PVE/Storage.pm
install -D -m 0644 Diskmanage.pm ${DESTDIR}${PERLDIR}/PVE/Diskmanage.pm
+ install -D -m 0644 ISCSI/Topology.pm ${DESTDIR}${PERLDIR}/PVE/ISCSI/Topology.pm
install -D -m 0644 CephConfig.pm ${DESTDIR}${PERLDIR}/PVE/CephConfig.pm
install -D -m 0644 GuestImport.pm ${DESTDIR}${PERLDIR}/PVE/GuestImport.pm
make -C Storage install
diff --git a/src/PVE/Storage/ISCSIPlugin.pm b/src/PVE/Storage/ISCSIPlugin.pm
index bb400fe6..373f9f84 100644
--- a/src/PVE/Storage/ISCSIPlugin.pm
+++ b/src/PVE/Storage/ISCSIPlugin.pm
@@ -10,6 +10,7 @@ use IO::File;
use PVE::JSONSchema qw(get_standard_option);
use PVE::Storage::Plugin;
+use PVE::ISCSI::Topology;
use PVE::Tools
qw(run_command file_read_firstline trim dir_glob_regex dir_glob_foreach $IPV4RE $IPV6RE);
@@ -290,89 +291,41 @@ sub load_stable_scsi_paths {
return $stable_paths;
}
-# Offload initiators can run several sessions on one SCSI host, so the LUNs of a session are the
-# ones below its own target, not all LUNs of its host.
-my sub foreach_session_lun {
- my ($sessiondir, $code) = @_;
-
- dir_glob_foreach(
- $sessiondir,
- 'target\d+:\d+:\d+',
- sub {
- my ($targetdir) = @_;
- dir_glob_foreach(
- "$sessiondir/$targetdir",
- '\d+:(\d+):(\d+):(\d+)',
- sub {
- my ($hctl, $channel, $id, $lun) = @_;
- $code->("$sessiondir/$targetdir/$hctl", $channel, $id, $lun);
- },
- );
- },
- );
-}
-
sub iscsi_device_list {
my $res = {};
- my $dirname = "$SYSFS/class/iscsi_session";
-
my $stable_paths = load_stable_scsi_paths();
- dir_glob_foreach(
- $dirname,
- 'session(\d+)',
- sub {
- my ($ent, $session) = @_;
-
- my $target = file_read_firstline("$dirname/$ent/targetname");
- return if !$target;
-
- foreach_session_lun(
- "$dirname/$ent/device",
- sub {
- my ($devdir, $channel, $id, $lun) = @_;
-
- my $type = file_read_firstline("$devdir/type");
- return if !defined($type) || $type ne '0'; # list disks only
-
- my $bdev;
- if (-d "$devdir/block") { # newer kernels
- (undef, $bdev) = dir_glob_regex("$devdir/block/", '([A-Za-z]\S*)');
- } else {
- (undef, $bdev) = dir_glob_regex($devdir, 'block:(\S+)');
- }
- return if !$bdev;
-
- #check multipath
- if (-d "$SYSFS/block/$bdev/holders") {
- my $multipathdev =
- dir_glob_regex("$SYSFS/block/$bdev/holders", '[A-Za-z]\S*');
- $bdev = $multipathdev if $multipathdev;
- }
-
- my $blockdev = $stable_paths->{$bdev};
- return if !$blockdev;
-
- my $size = file_read_firstline("$SYSFS/block/$bdev/size");
- return if !$size;
-
- my $volid = "$channel.$id.$lun.$blockdev";
-
- $res->{$target}->{$volid} = {
- 'format' => 'raw',
- 'size' => int($size * 512),
- 'vmid' => 0, # not assigned to any vm
- 'channel' => int($channel),
- 'id' => int($id),
- 'lun' => int($lun),
- };
- },
- );
-
- },
- );
+ my $device_map = PVE::ISCSI::Topology::device_map($SYSFS);
+
+ for my $bdev (sort keys %$device_map) {
+ my $info = $device_map->{$bdev};
+ my ($channel, $id, $lun) = $info->@{qw(channel id lun)};
+
+ #check multipath
+ if (-d "$SYSFS/block/$bdev/holders") {
+ my $multipathdev = dir_glob_regex("$SYSFS/block/$bdev/holders", '[A-Za-z]\S*');
+ $bdev = $multipathdev if $multipathdev;
+ }
+
+ my $blockdev = $stable_paths->{$bdev};
+ next if !$blockdev;
+
+ my $size = file_read_firstline("$SYSFS/block/$bdev/size");
+ next if !$size;
+
+ my $volid = "$channel.$id.$lun.$blockdev";
+
+ $res->{ $info->{target} }->{$volid} = {
+ 'format' => 'raw',
+ 'size' => int($size * 512),
+ 'vmid' => 0, # not assigned to any vm
+ 'channel' => $channel,
+ 'id' => $id,
+ 'lun' => $lun,
+ };
+ }
return $res;
}
next prev parent reply other threads:[~2026-11-16 1:24 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 1:23 [PATCH v5 cluster,storage,docs,manager 00/36] SAN: cluster-wide multipath, SAN views and a guided setup for shared LVM Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 cluster 01/36] cfs: observe the multipath configuration files Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 storage 02/36] diskmanage: collect disk transport type from lsblk Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 storage 03/36] diskmanage: qualify NVMe over fabrics transport Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 storage 04/36] diskmanage: optionally include iSCSI session devices in disk enumeration Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 storage 05/36] diskmanage: collect native NVMe multipath path state Thomas Lamprecht
2026-11-16 1:23 ` Thomas Lamprecht [this message]
2026-11-16 1:23 ` [PATCH v5 storage 07/36] multipath: add a library around multipathd Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 storage 08/36] diskmanage: add helper to list multipath devices Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 storage 09/36] multipath: add a cluster-wide configuration Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 storage 10/36] iscsi: add an option to manage storage LUNs with multipath Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 storage 11/36] lvm: activate a missing base volume before using the volume group Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 storage 12/36] multipath: apply the configuration on every node Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 storage 13/36] multipath: publish per-node status Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 storage 14/36] api: add endpoints for the cluster-wide multipath configuration Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 storage 15/36] api: multipath: add the cluster-wide health status Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 storage 16/36] api: scan: add a SAN LUN inventory Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 storage 17/36] pvesm: expose the " Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 storage 18/36] api: add node-level iSCSI status Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 storage 19/36] disks: lvm: drop unused imports Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 storage 20/36] disks: lvm: allow volume groups on SAN LUNs and multipath maps Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 storage 21/36] disks: lvm: refuse to destroy the volume group of a shared storage Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 storage 22/36] disks: allow wiping a SAN LUN that no storage uses Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 docs 23/36] storage: document the cluster-wide multipath management Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 manager 24/36] pvestatd: apply the multipath configuration and report the node status Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 manager 25/36] report: add the managed multipath configuration Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 manager 26/36] api: cluster: add the multipath endpoints Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 manager 27/36] api: nodes: expose the iSCSI status Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 manager 28/36] ui: dc: add a SAN view Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 manager 29/36] ui: storage: iscsi: add the multipath option Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 manager 30/36] ui: lvm: enable shared when a base storage is selected Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 manager 31/36] ui: node: add SAN LUNs panel Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 manager 32/36] ui: node: san: wipe a LUN that no storage uses Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 manager 33/36] ui: node: san: show iSCSI targets and sessions Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 manager 34/36] ui: dc: san: add a guided setup for shared LVM on iSCSI Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 manager 35/36] ui: dc: san: add a guided setup for shared LVM on Fibre Channel Thomas Lamprecht
2026-11-16 1:23 ` [PATCH v5 manager 36/36] ui: storage: point the iSCSI and LVM add dialogs to the SAN view Thomas Lamprecht
2026-11-18 8:11 ` superseded: [PATCH v5 cluster,storage,docs,manager 00/36] SAN: cluster-wide multipath, SAN views and a guided setup for shared LVM 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=20261116012355.3187417-7-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