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 175441FF0ED for ; Fri, 31 Jul 2026 12:22:24 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 9B4CA21598; Fri, 31 Jul 2026 12:22:03 +0200 (CEST) From: Dietmar Maurer To: pve-devel@lists.proxmox.com Subject: [RFC pve-storage 07/27] iscsi: factor out session device map from device list Date: Fri, 31 Jul 2026 12:21:36 +0200 Message-ID: <20260731102156.3947857-8-dietmar@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260731102156.3947857-1-dietmar@proxmox.com> References: <20260731102156.3947857-1-dietmar@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 2 AWL -0.356 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) KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods RDNS_NONE 1.274 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record Message-ID-Hash: L3MMAJMFE7FUPSGGGJFJNCDE2LGUZ6EX X-Message-ID-Hash: L3MMAJMFE7FUPSGGGJFJNCDE2LGUZ6EX X-MailFrom: dietmar@zilli.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: Walking the iSCSI sessions in sysfs to find the attached block devices and their target is useful on its own, for example to check whether a local disk belongs to a configured iSCSI storage. Split that part out of the device list helper into a reusable map of kernel device names to target and address. No functional change. Signed-off-by: Dietmar Maurer --- src/PVE/Storage/ISCSIPlugin.pm | 74 +++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 27 deletions(-) diff --git a/src/PVE/Storage/ISCSIPlugin.pm b/src/PVE/Storage/ISCSIPlugin.pm index 801b5d1..c18a4b6 100644 --- a/src/PVE/Storage/ISCSIPlugin.pm +++ b/src/PVE/Storage/ISCSIPlugin.pm @@ -251,14 +251,14 @@ sub load_stable_scsi_paths { return $stable_paths; } -sub iscsi_device_list { +# Maps kernel block device names (e.g. 'sda') of all disks attached through an +# iSCSI session to their target IQN and channel/id/lun address. +sub iscsi_session_device_map { my $res = {}; my $dirname = '/sys/class/iscsi_session'; - my $stable_paths = load_stable_scsi_paths(); - dir_glob_foreach( $dirname, 'session(\d+)', @@ -290,31 +290,12 @@ sub iscsi_device_list { } return if !$bdev; - #check multipath - if (-d "/sys/block/$bdev/holders") { - my $multipathdev = - dir_glob_regex("/sys/block/$bdev/holders", '[A-Za-z]\S*'); - $bdev = $multipathdev if $multipathdev; - } - - my $blockdev = $stable_paths->{$bdev}; - return if !$blockdev; - - my $size = file_read_firstline("/sys/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), }; - - #print "TEST: $target $session $host,$bus,$tg,$lun $blockdev\n"; }, ); @@ -324,6 +305,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 "/sys/block/$bdev/holders") { + my $multipathdev = dir_glob_regex("/sys/block/$bdev/holders", '[A-Za-z]\S*'); + $bdev = $multipathdev if $multipathdev; + } + + my $blockdev = $stable_paths->{$bdev}; + next if !$blockdev; + + my $size = file_read_firstline("/sys/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