From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id BED721FF13C for ; Thu, 30 Apr 2026 19:34:11 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 855301637E; Thu, 30 Apr 2026 19:33:11 +0200 (CEST) From: Mira Limbeck To: pve-devel@lists.proxmox.com Subject: [PATCH v2 storage 08/15] iscsi: rework to update discovery db and simplify login Date: Thu, 30 Apr 2026 19:27:06 +0200 Message-ID: <20260430173220.441001-9-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.564 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: IZUB3FI3ECTJYDFTGPROL3PE2EJWLVGK X-Message-ID-Hash: IZUB3FI3ECTJYDFTGPROL3PE2EJWLVGK 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: Manually updating the discovery db, and running a discovery for the non-mapping case, simplifies the tracking of sessions and node entries to decide if a login is necessary to a target. Logins are done on a node+target level, rather than on a portal level. This makes a single iscsiadm call per target instead of per portal. One downside is that warnings are logged if some sessions already exist, but not for all portals of a target. Signed-off-by: Mira Limbeck --- src/PVE/Storage/ISCSIPlugin.pm | 48 ++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/src/PVE/Storage/ISCSIPlugin.pm b/src/PVE/Storage/ISCSIPlugin.pm index 0f77f3f..b3f4e60 100644 --- a/src/PVE/Storage/ISCSIPlugin.pm +++ b/src/PVE/Storage/ISCSIPlugin.pm @@ -74,7 +74,7 @@ my $get_local_config = sub { return $res; } else { $res->{is_mapping} = 0; - $res->{targets}->{ $scfg->{target} } = iscsi_portals($scfg->{target}, $scfg->{portal}); + $res->{targets}->{ $scfg->{target} } = [$scfg->{portal}]; return $res; } }; @@ -237,9 +237,6 @@ sub iscsi_login { assert_iscsi_support(); - eval { iscsi_discovery($target, $portals, $cache); }; - warn $@ if $@; - # Disable retries to avoid blocking pvestatd for too long, next iteration will retry anyway eval { my $cmd = [ @@ -259,7 +256,14 @@ sub iscsi_login { }; warn $@ if $@; - run_command([$ISCSIADM, '--mode', 'node', '--targetname', $target, '--login']); + # iscsiadm warns if some target/portals are already logged in + # a workaround would be to check each of them and only log in on those + # that have no session yet, rather than just doing a log in per node + my $cmd = [ + $ISCSIADM, '--mode', 'node', '--targetname', $target, '--login', + ]; + eval { run_command($cmd); }; + warn $@ if $@; } sub iscsi_logout { @@ -699,32 +703,30 @@ sub activate_storage { return if !assert_iscsi_support(1); my $local_cfg = $get_local_config->($scfg); + + update_iscsi_discovery_db($local_cfg, $cache); + 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; + my $login_targets = {}; 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 - 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; - } + my $sessions = [map { $_->{portal} } ($targets->{$target}->{sessions}->@*)]; + for my $portal ($targets->{$target}->{portals}->@*) { + if (!grep(/\Q$portal\E$/, $sessions->@*)) { + push $login_targets->{$target}->@*, $portal; } } } + $do_login = keys $login_targets->%*; if ($do_login) { - for my $target (keys $targets->%*) { + for my $target (keys $login_targets->%*) { eval { iscsi_login($target, $targets->{$target}->{portals}, $cache); }; warn $@ if $@; } @@ -857,9 +859,17 @@ sub check_connection { my $cache = {}; my $local_cfg = $get_local_config->($scfg); + my $is_mapping = $local_cfg->{is_mapping}; for my $target (keys $local_cfg->{targets}->%*) { - for my $portal ($local_cfg->{targets}->{$target}->@*) { + my $portals; + if ($is_mapping) { + $portals = $local_cfg->{targets}->{$target}; + } else { + $portals = iscsi_portals($target, $local_cfg->{targets}->{$target}->[0]); + } + + for my $portal ($portals->@*) { my $result = iscsi_test_portal($target, $portal, $cache); return $result if $result; } -- 2.47.3