all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH v8 storage 06/43] iscsi: factor out session device map from device list
Date: Thu, 19 Nov 2026 20:46:11 +0100	[thread overview]
Message-ID: <20261119194655.3163258-7-t.lamprecht@proxmox.com> (raw)
In-Reply-To: <20261119194655.3163258-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      |  69 +++++++++++++++++++++
 src/PVE/Makefile               |   1 +
 src/PVE/Storage/ISCSIPlugin.pm | 107 +++++++++------------------------
 3 files changed, 100 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..4ebfaccd
--- /dev/null
+++ b/src/PVE/ISCSI/Topology.pm
@@ -0,0 +1,69 @@
+package PVE::ISCSI::Topology;
+
+use v5.36;
+
+use PVE::Tools qw(dir_glob_foreach dir_glob_regex file_read_firstline);
+
+our $SYSFS = '/sys';
+
+# 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.
+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 1e349cde..cec58afb 100644
--- a/src/PVE/Storage/ISCSIPlugin.pm
+++ b/src/PVE/Storage/ISCSIPlugin.pm
@@ -8,6 +8,7 @@ use Fcntl qw(LOCK_EX LOCK_NB);
 use IO::Dir;
 use IO::File;
 
+use PVE::ISCSI::Topology;
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::Storage::Plugin;
 use PVE::Tools
@@ -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;
 }




  parent reply	other threads:[~2026-11-19 19:48 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 19:46 [PATCH v8 cluster,storage,docs,manager 00/43] SAN: cluster-wide multipath, SAN views and a guided setup for shared LVM Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 cluster 01/43] cfs: observe the multipath configuration files Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 storage 02/43] diskmanage: collect disk transport type from lsblk Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 storage 03/43] diskmanage: qualify NVMe over Fabrics transport Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 storage 04/43] diskmanage: optionally include iSCSI session devices in disk enumeration Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 storage 05/43] diskmanage: collect native NVMe multipath path state Thomas Lamprecht
2026-11-19 19:46 ` Thomas Lamprecht [this message]
2026-11-19 19:46 ` [PATCH v8 storage 07/43] multipath: add a library around multipathd Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 storage 08/43] diskmanage: add helper to list multipath devices Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 storage 09/43] multipath: add a cluster-wide configuration Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 storage 10/43] iscsi: add an option to manage storage LUNs with multipath Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 storage 11/43] lvm: activate a missing base volume before using the volume group Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 storage 12/43] multipath: apply the configuration on every node Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 storage 13/43] multipath: publish per-node status Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 storage 14/43] api: add endpoints for the cluster-wide multipath configuration Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 storage 15/43] api: multipath: add the cluster-wide health status Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 storage 16/43] diskmanage: look up the requested disks by name Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 storage 17/43] diskmanage: read the udev data of all disks with one call Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 storage 18/43] api: scan: add a SAN LUN inventory Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 storage 19/43] pvesm: expose the " Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 storage 20/43] api: add node-level iSCSI status Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 storage 21/43] api: scan: name the portal of an iSCSI path Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 storage 22/43] disks: lvm: drop unused imports Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 storage 23/43] disks: lvm: allow volume groups on SAN LUNs and multipath maps Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 storage 24/43] disks: lvm: refuse to destroy the volume group of a shared storage Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 storage 25/43] disks: allow wiping a SAN LUN that no storage uses Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 storage 26/43] api: scan: report the process that has a SAN LUN open Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 docs 27/43] storage: document the cluster-wide multipath management Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 docs 28/43] storage: multipath: describe the use shown for an open LUN Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 manager 29/43] pvestatd: apply the multipath configuration and report the node status Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 manager 30/43] report: add the managed multipath configuration Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 manager 31/43] api: cluster: add the multipath endpoints Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 manager 32/43] api: nodes: expose the iSCSI status Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 manager 33/43] ui: dc: add a SAN view Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 manager 34/43] ui: storage: iscsi: add the multipath option Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 manager 35/43] ui: lvm: enable shared when a base storage is selected Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 manager 36/43] ui: node: add SAN LUNs panel Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 manager 37/43] ui: node: san: wipe a LUN that no storage uses Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 manager 38/43] ui: node: san: show iSCSI targets and sessions Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 manager 39/43] ui: dc: san: add a guided setup for shared LVM on iSCSI Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 manager 40/43] ui: dc: san: add a guided setup for shared LVM on Fibre Channel Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 manager 41/43] ui: storage: point the iSCSI and LVM add dialogs to the SAN view Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 manager 42/43] ui: san: show the guest or process that has a LUN open Thomas Lamprecht
2026-11-19 19:46 ` [PATCH v8 manager 43/43] ui: node: san: add a column for the target or subsystem of 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=20261119194655.3163258-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 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.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal