From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 73BDB1FF0AF for ; Fri, 06 Nov 2026 01:51:07 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 6A82F216AC; Fri, 06 Nov 2026 01:50:36 +0100 (CET) From: Thomas Lamprecht To: pve-devel@lists.proxmox.com Subject: [PATCH v3 storage 18/76] iscsi: factor out session device map from device list Date: Fri, 6 Nov 2026 00:30:53 +0100 Message-ID: <20261105233336.2178064-19-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261105233336.2178064-1-t.lamprecht@proxmox.com> References: <20261105233336.2178064-1-t.lamprecht@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1793926178453 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.338 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: F4EATIAJONKZLV675IJD6TEINVLB7RMP X-Message-ID-Hash: F4EATIAJONKZLV675IJD6TEINVLB7RMP X-MailFrom: t.lamprecht@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Dietmar Maurer Checking whether a disk belongs to configured iSCSI storage needs the session-to-device information collected by device listing. Expose it separately as a map from kernel device names to targets and addresses. This does not change behavior. Signed-off-by: Dietmar Maurer [TL: drop redundant comments; keep the per-session LUN walk and read block devices below the sysfs root of the listing] Signed-off-by: Thomas Lamprecht --- src/PVE/Storage/ISCSIPlugin.pm | 70 ++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 25 deletions(-) diff --git a/src/PVE/Storage/ISCSIPlugin.pm b/src/PVE/Storage/ISCSIPlugin.pm index 81f06979..22f6c44f 100644 --- a/src/PVE/Storage/ISCSIPlugin.pm +++ b/src/PVE/Storage/ISCSIPlugin.pm @@ -306,14 +306,12 @@ my sub foreach_session_lun { ); } -sub iscsi_device_list { +sub iscsi_session_device_map { my $res = {}; my $dirname = "$SYSFS/class/iscsi_session"; - my $stable_paths = load_stable_scsi_paths(); - dir_glob_foreach( $dirname, 'session(\d+)', @@ -339,28 +337,11 @@ sub iscsi_device_list { } 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), + $res->{$bdev} = { + target => $target, + channel => int($channel), + id => int($id), + lun => int($lun), }; }, ); @@ -371,6 +352,45 @@ sub iscsi_device_list { return $res; } +sub iscsi_device_list { + + my $res = {}; + + my $stable_paths = load_stable_scsi_paths(); + + my $device_map = iscsi_session_device_map(); + + 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; +} + # Configuration sub type { -- 2.47.3