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 v6 storage 04/42] diskmanage: optionally include iSCSI session devices in disk enumeration
Date: Wed, 18 Nov 2026 07:52:21 +0100	[thread overview]
Message-ID: <20261118065302.3033937-5-t.lamprecht@proxmox.com> (raw)
In-Reply-To: <20261118065302.3033937-1-t.lamprecht@proxmox.com>

From: Dietmar Maurer <dietmar@proxmox.com>

The disk enumeration skips iSCSI session devices, as its callers
manage local disks. The SAN LUN inventory needs them, so let a caller
ask for them. Such a listing also skips the usage probes that read
from the devices (pvs, ceph-volume), as they can block on a LUN whose
paths are down.

Callers that do not ask get the same list as before, so local disk
operations keep refusing iSCSI LUNs.

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
[TL: include the devices only on request instead of always, and skip
 the usage probes that read from devices then]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
 src/PVE/Diskmanage.pm                         | 61 +++++++++----------
 src/test/disk_tests/iscsi/disklist            |  1 +
 .../disk_tests/iscsi/disklist_expected.json   | 19 ++++++
 src/test/disk_tests/iscsi/lsblk               |  5 ++
 src/test/disk_tests/iscsi/sda/device/model    |  1 +
 src/test/disk_tests/iscsi/sda/device/vendor   |  1 +
 .../disk_tests/iscsi/sda/queue/rotational     |  1 +
 src/test/disk_tests/iscsi/sda/size            |  1 +
 src/test/disk_tests/iscsi/sda_udevadm         | 21 +++++++
 src/test/disklist_test.pm                     | 20 ++++--
 10 files changed, 94 insertions(+), 37 deletions(-)
 create mode 100644 src/test/disk_tests/iscsi/disklist
 create mode 100644 src/test/disk_tests/iscsi/disklist_expected.json
 create mode 100644 src/test/disk_tests/iscsi/lsblk
 create mode 100644 src/test/disk_tests/iscsi/sda/device/model
 create mode 100644 src/test/disk_tests/iscsi/sda/device/vendor
 create mode 100644 src/test/disk_tests/iscsi/sda/queue/rotational
 create mode 100644 src/test/disk_tests/iscsi/sda/size
 create mode 100644 src/test/disk_tests/iscsi/sda_udevadm

diff --git a/src/PVE/Diskmanage.pm b/src/PVE/Diskmanage.pm
index 7862bcd4..c342abcd 100644
--- a/src/PVE/Diskmanage.pm
+++ b/src/PVE/Diskmanage.pm
@@ -92,6 +92,13 @@ sub parse_wipefs_signatures {
     return $probe->{signatures};
 }
 
+sub is_iscsi_device {
+    my ($dev) = @_;
+
+    my $link = readlink("/sys/block/$dev");
+    return defined($link) && $link =~ m{/session\d+/} ? 1 : 0;
+}
+
 sub disk_is_used {
     my ($disk) = @_;
 
@@ -263,23 +270,25 @@ sub get_zfs_devices {
 }
 
 sub get_lvm_devices {
-    my ($lsblk_info) = @_;
+    my ($lsblk_info, $no_probe) = @_;
     my $res = {};
-    eval {
-        run_command(
-            [$PVS, '--noheadings', '--readonly', '-o', 'pv_name'],
-            outfunc => sub {
-                my ($line) = @_;
-                $line = trim($line);
-                if ($line =~ m|^/dev/|) {
-                    $res->{$line} = 1;
-                }
-            },
-        );
-    };
+    if (!$no_probe) {
+        eval {
+            run_command(
+                [$PVS, '--noheadings', '--readonly', '-o', 'pv_name'],
+                outfunc => sub {
+                    my ($line) = @_;
+                    $line = trim($line);
+                    if ($line =~ m|^/dev/|) {
+                        $res->{$line} = 1;
+                    }
+                },
+            );
+        };
 
-    # if something goes wrong, we do not want to give up, but indicate an error has occurred
-    warn "$@\n" if $@;
+        # if something goes wrong, we do not want to give up, but indicate an error has occurred
+        warn "$@\n" if $@;
+    }
 
     my $uuids = {
         "e6d6d379-f507-44c2-a23c-238f2a3df928" => 1,
@@ -495,16 +504,6 @@ sub dir_is_empty {
     return 1;
 }
 
-sub is_iscsi {
-    my ($sysdir) = @_;
-
-    if (-l $sysdir && readlink($sysdir) =~ m|host[^/]*/session[^/]*|) {
-        return 1;
-    }
-
-    return 0;
-}
-
 # Returns the NVMe transport (pcie, fc, tcp, rdma, loop) of a namespace, either directly from
 # its controller, or from any controller of its subsystem for native NVMe multipath setups.
 sub get_nvme_transport {
@@ -557,7 +556,8 @@ sub mounted_paths {
 }
 
 sub get_disks {
-    my ($disks, $nosmart, $include_partitions) = @_;
+    my ($disks, $nosmart, $include_partitions, $san_inventory) = @_;
+    # SAN inventory includes iSCSI session devices and skips usage probes that read devices.
     my $disklist = {};
 
     my $mounted = mounted_blockdevs();
@@ -565,11 +565,11 @@ sub get_disks {
     my $lsblk_info = get_lsblk_info();
 
     my $journalhash = get_ceph_journals($lsblk_info);
-    my $ceph_volume_infos = get_ceph_volume_infos();
+    my $ceph_volume_infos = $san_inventory ? {} : get_ceph_volume_infos();
 
     my $zfshash = get_zfs_devices($lsblk_info);
 
-    my $lvmhash = get_lvm_devices($lsblk_info);
+    my $lvmhash = get_lvm_devices($lsblk_info, $san_inventory);
 
     my $disk_regex = ".*";
     if (defined($disks)) {
@@ -609,14 +609,13 @@ sub get_disks {
                 && $dev !~ m/^nvme\d+n\d+$/
                 && $dev !~ m/^cciss\!c\d+d\d+$/;
 
+            return if !$san_inventory && is_iscsi_device($dev);
+
             my $data = get_udev_info("/sys/block/$dev") // return;
             my $devpath = $data->{devpath};
 
             my $sysdir = "/sys/block/$dev";
 
-            # we do not want iscsi devices
-            return if is_iscsi($sysdir);
-
             my $nvme_transport;
             $nvme_transport = get_nvme_transport($sysdir) if $dev =~ m/^nvme/;
 
diff --git a/src/test/disk_tests/iscsi/disklist b/src/test/disk_tests/iscsi/disklist
new file mode 100644
index 00000000..9191c61b
--- /dev/null
+++ b/src/test/disk_tests/iscsi/disklist
@@ -0,0 +1 @@
+sda
diff --git a/src/test/disk_tests/iscsi/disklist_expected.json b/src/test/disk_tests/iscsi/disklist_expected.json
new file mode 100644
index 00000000..ca334106
--- /dev/null
+++ b/src/test/disk_tests/iscsi/disklist_expected.json
@@ -0,0 +1,19 @@
+{
+    "sda": {
+        "devpath": "/dev/sda",
+        "size": 10737418240,
+        "vendor": "LIO-ORG",
+        "model": "vdisk1",
+        "serial": "ISER1",
+        "wwn": "0x60014051111111111",
+        "gpt": 0,
+        "rpm": -1,
+        "type": "unknown",
+        "health": "UNKNOWN",
+        "wearout": "N/A",
+        "osdid": -1,
+        "osdid-list": null,
+        "by_id_link": "/dev/disk/by-id/scsi-360014051111111111",
+        "transport": "iscsi"
+    }
+}
diff --git a/src/test/disk_tests/iscsi/lsblk b/src/test/disk_tests/iscsi/lsblk
new file mode 100644
index 00000000..526d27c5
--- /dev/null
+++ b/src/test/disk_tests/iscsi/lsblk
@@ -0,0 +1,5 @@
+{
+   "blockdevices": [
+      {"path":"/dev/sda", "parttype":null, "fstype":null, "tran":"iscsi"}
+   ]
+}
diff --git a/src/test/disk_tests/iscsi/sda/device/model b/src/test/disk_tests/iscsi/sda/device/model
new file mode 100644
index 00000000..b14d6fe7
--- /dev/null
+++ b/src/test/disk_tests/iscsi/sda/device/model
@@ -0,0 +1 @@
+vdisk1
diff --git a/src/test/disk_tests/iscsi/sda/device/vendor b/src/test/disk_tests/iscsi/sda/device/vendor
new file mode 100644
index 00000000..968831cd
--- /dev/null
+++ b/src/test/disk_tests/iscsi/sda/device/vendor
@@ -0,0 +1 @@
+LIO-ORG
diff --git a/src/test/disk_tests/iscsi/sda/queue/rotational b/src/test/disk_tests/iscsi/sda/queue/rotational
new file mode 100644
index 00000000..d00491fd
--- /dev/null
+++ b/src/test/disk_tests/iscsi/sda/queue/rotational
@@ -0,0 +1 @@
+1
diff --git a/src/test/disk_tests/iscsi/sda/size b/src/test/disk_tests/iscsi/sda/size
new file mode 100644
index 00000000..14faeece
--- /dev/null
+++ b/src/test/disk_tests/iscsi/sda/size
@@ -0,0 +1 @@
+20971520
diff --git a/src/test/disk_tests/iscsi/sda_udevadm b/src/test/disk_tests/iscsi/sda_udevadm
new file mode 100644
index 00000000..ca9f7815
--- /dev/null
+++ b/src/test/disk_tests/iscsi/sda_udevadm
@@ -0,0 +1,21 @@
+P: /devices/platform/host5/session1/target5:0:0/5:0:0:0/block/sda
+N: sda
+S: disk/by-id/scsi-360014051111111111
+S: disk/by-id/wwn-0x60014051111111111
+S: disk/by-path/ip-192.168.1.10:3260-iscsi-iqn.2003-01.org.linux-iscsi.storage:target1-lun-0
+E: DEVLINKS=/dev/disk/by-id/scsi-360014051111111111 /dev/disk/by-id/wwn-0x60014051111111111 /dev/disk/by-path/ip-192.168.1.10:3260-iscsi-iqn.2003-01.org.linux-iscsi.storage:target1-lun-0
+E: DEVNAME=/dev/sda
+E: DEVPATH=/devices/platform/host5/session1/target5:0:0/5:0:0:0/block/sda
+E: DEVTYPE=disk
+E: ID_BUS=scsi
+E: ID_MODEL=vdisk1
+E: ID_PATH=ip-192.168.1.10:3260-iscsi-iqn.2003-01.org.linux-iscsi.storage:target1-lun-0
+E: ID_SCSI=1
+E: ID_SERIAL=36001405111111111
+E: ID_SERIAL_SHORT=ISER1
+E: ID_TYPE=disk
+E: ID_VENDOR=LIO-ORG
+E: ID_WWN=0x60014051111111111
+E: MAJOR=8
+E: MINOR=0
+E: SUBSYSTEM=block
diff --git a/src/test/disklist_test.pm b/src/test/disklist_test.pm
index c7374fd5..4c85d9e9 100644
--- a/src/test/disklist_test.pm
+++ b/src/test/disklist_test.pm
@@ -97,10 +97,6 @@ sub mocked_get_sysdir_size {
     return &$originalsub($param);
 }
 
-sub mocked_is_iscsi {
-    return 0;
-}
-
 sub mocked_file_read_firstline {
     my ($path) = @_;
 
@@ -173,6 +169,7 @@ sub test_disk_list {
         eval { $disks = PVE::Diskmanage::get_disks(); };
         warn $@ if $@;
         $expected_disk_list = decode_json(read_test_file('disklist_expected.json'));
+        $expected_disk_list = {} if $testcasedir eq 'iscsi';
 
         print Dumper($disks) if $print;
         $testcount++;
@@ -223,6 +220,16 @@ sub test_disk_list {
         $testcount++;
         is_deeply($disks, $expected_disk_list, 'disk list should be the same');
 
+        if ($testcasedir eq 'iscsi') {
+            eval { PVE::Diskmanage::assert_disk_unused('/dev/sda'); };
+            $testcount++;
+            like($@, qr/not a valid local disk/, 'local disk operations reject an iSCSI LUN');
+
+            my $san_disks = PVE::Diskmanage::get_disks(undef, 1, 0, 1);
+            $testcount++;
+            ok($san_disks->{sda}, 'SAN inventory opts into iSCSI');
+        }
+
         done_testing($testcount);
     };
 }
@@ -243,8 +250,6 @@ $diskmanage_module->mock('get_sysdir_info' => \&mocked_get_sysdir_info);
 print("\tMocked get_sysdir_info\n");
 $diskmanage_module->mock('get_sysdir_size' => \&mocked_get_sysdir_size);
 print("\tMocked get_sysdir_size\n");
-$diskmanage_module->mock('is_iscsi' => \&mocked_is_iscsi);
-print("\tMocked is_iscsi\n");
 $diskmanage_module->mock('assert_blockdev' => sub { return 1; });
 print("\tMocked assert_blockdev\n");
 $diskmanage_module->mock(
@@ -262,6 +267,9 @@ $diskmanage_module->mock('file_read_firstline' => \&mocked_file_read_firstline);
 print("\tMocked file_read_firstline\n");
 $diskmanage_module->mock('check_bin' => sub { return 1; });
 print("\tMocked check_bin\n");
+# only the disks of the iscsi test case are session devices, the sysfs of the host must not count
+$diskmanage_module->mock('is_iscsi_device' => sub { return $testcasedir eq 'iscsi'; });
+print("\tMocked is_iscsi_device\n");
 my $tools_module = Test::MockModule->new('PVE::ProcFSTools', no_auto => 1);
 $tools_module->mock('parse_proc_mounts' => \&mocked_parse_proc_mounts);
 print("\tMocked parse_proc_mounts\n");




  parent reply	other threads:[~2026-11-18  6:53 UTC|newest]

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