From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 864761FF13C for ; Thu, 30 Apr 2026 19:33:07 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 6118A156C4; Thu, 30 Apr 2026 19:32:37 +0200 (CEST) From: Mira Limbeck To: pve-devel@lists.proxmox.com Subject: [PATCH v2 storage 06/15] iscsi: change functions to handle mappings Date: Thu, 30 Apr 2026 19:27:04 +0200 Message-ID: <20260430173220.441001-7-m.limbeck@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260430173220.441001-1-m.limbeck@proxmox.com> References: <20260430173220.441001-1-m.limbeck@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.570 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods RDNS_NONE 0.793 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: JNNLTHGMAQREREGAEEI7YWBLXNGNOWFP X-Message-ID-Hash: JNNLTHGMAQREREGAEEI7YWBLXNGNOWFP X-MailFrom: mira@nena.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: change functions to use the new local config that unifies mapping and non-mapping configs into a similar structure Signed-off-by: Mira Limbeck --- src/PVE/Storage/ISCSIPlugin.pm | 105 ++++++++++++++++++++++----------- 1 file changed, 69 insertions(+), 36 deletions(-) diff --git a/src/PVE/Storage/ISCSIPlugin.pm b/src/PVE/Storage/ISCSIPlugin.pm index 8e5cbfb..8f2bdb5 100644 --- a/src/PVE/Storage/ISCSIPlugin.pm +++ b/src/PVE/Storage/ISCSIPlugin.pm @@ -479,26 +479,30 @@ sub list_images { # we have no owner for iscsi devices - my $target = $scfg->{target}; + my $local_cfg = $get_local_config->($scfg); + my $targets = $local_cfg->{targets}; - if (my $dat = $cache->{iscsi_devices}->{$target}) { + for my $target (keys $targets->%*) { + if (my $dat = $cache->{iscsi_devices}->{$target}) { - foreach my $volname (keys %$dat) { + foreach my $volname (keys %$dat) { - my $volid = "$storeid:$volname"; + my $volid = "$storeid:$volname"; - if ($vollist) { - my $found = grep { $_ eq $volid } @$vollist; - next if !$found; - } else { - # we have no owner for iscsi devices - next if defined($vmid); - } + if ($vollist) { + my $found = grep { $_ eq $volid } @$vollist; + next if !$found; + } else { + # we have no owner for iscsi devices + next if defined($vmid); + } - my $info = $dat->{$volname}; - $info->{volid} = $volid; + my $info = $dat->{$volname}; + $info->{volid} = $volid; - push @$res, $info; + push @$res, $info; + } + last; } } @@ -514,8 +518,13 @@ sub iscsi_session { sub status { my ($class, $storeid, $scfg, $cache) = @_; - my $session = iscsi_session($cache, $scfg->{target}); - my $active = defined($session) ? 1 : 0; + my $local_cfg = $get_local_config->($scfg); + my $active = 0; + for my $target (keys $local_cfg->{targets}->%*) { + my $session = iscsi_session($cache, $target); + $active = 1 if defined($session); + last if defined($session); + } return (0, 0, 0, $active); } @@ -525,28 +534,41 @@ sub activate_storage { return if !assert_iscsi_support(1); - my $sessions = iscsi_session($cache, $scfg->{target}); - my $portals = iscsi_portals($scfg->{target}, $scfg->{portal}); - my $do_login = !defined($sessions); + my $local_cfg = $get_local_config->($scfg); + my $targets = {}; + for my $target (keys $local_cfg->{targets}->%*) { + my $sessions = iscsi_session($cache, $target); + $targets->{$target}->{sessions} = $sessions; + $targets->{$target}->{portals} = $local_cfg->{targets}->{$target}; + } + my $do_login = 0; + for my $target (keys $targets->%*) { + $do_login = 1 if !defined($targets->{$target}->{sessions}); + } if (!$do_login) { # We should check that sessions for all portals are available - my $session_portals = [map { $_->{portal} } (@$sessions)]; - - for my $portal (@$portals) { - if (!grep(/^\Q$portal\E$/, @$session_portals)) { - $do_login = 1; - last; + for my $target (keys $targets->%*) { + my $session_portals = [map { $_->{portal} } ($targets->{$target}->{sessions}->@*)]; + for my $portal ($targets->{$target}->{portals}->@*) { + if (!grep(/^\Q$portal\E(?::3260)?$/, $session_portals->@*)) { + $do_login = 1; + last; + } } } } if ($do_login) { - eval { iscsi_login($scfg->{target}, $portals, $cache); }; - warn $@ if $@; + for my $target (keys $targets->%*) { + eval { iscsi_login($target, $targets->{$target}->{portals}, $cache); }; + warn $@ if $@; + } } else { # make sure we get all devices - iscsi_session_rescan($sessions); + for my $target (keys $targets->%*) { + iscsi_session_rescan($targets->{$target}->{sessions}); + } } } @@ -555,8 +577,11 @@ sub deactivate_storage { return if !assert_iscsi_support(1); - if (defined(iscsi_session($cache, $scfg->{target}))) { - iscsi_logout($scfg->{target}); + my $local_cfg = $get_local_config->($scfg); + for my $target (keys $local_cfg->{targets}->%*) { + if (defined(iscsi_session($cache, $target))) { + iscsi_logout($target); + } } } @@ -654,18 +679,26 @@ sub activate_volume { my $device_path = $udev_query_path->($real_path); my $resolved_paths = $resolve_virtual_devices->($device_path); - my $found = $check_devices_part_of_target->($resolved_paths, $scfg->{target}); - die "volume '$volname' not part of target '$scfg->{target}'\n" if !$found; + my $local_cfg = $get_local_config->($scfg); + my $found = 0; + for my $target ($local_cfg->{targets}->%*) { + $found ||= $check_devices_part_of_target->($resolved_paths, $target); + last if $found; + } + die "volume '$volname' not part of any matching target\n" if !$found; } sub check_connection { my ($class, $storeid, $scfg) = @_; + my $cache = {}; - my $portals = iscsi_portals($scfg->{target}, $scfg->{portal}); + my $local_cfg = $get_local_config->($scfg); - for my $portal (@$portals) { - my $result = iscsi_test_portal($scfg->{target}, $portal, $cache); - return $result if $result; + for my $target (keys $local_cfg->{targets}->%*) { + for my $portal ($local_cfg->{targets}->{$target}->@*) { + my $result = iscsi_test_portal($target, $portal, $cache); + return $result if $result; + } } return 0; -- 2.47.3