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 460541FF13C for ; Thu, 30 Apr 2026 19:33:00 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 5ADA215593; Thu, 30 Apr 2026 19:32:34 +0200 (CEST) From: Mira Limbeck To: pve-devel@lists.proxmox.com Subject: [PATCH v2 storage 09/15] iscsi: remove stale sessions in non-mapping case Date: Thu, 30 Apr 2026 19:27:07 +0200 Message-ID: <20260430173220.441001-10-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.576 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: L4H4IH2S6Z4FSET2HGPZYLYLLKLTQZMW X-Message-ID-Hash: L4H4IH2S6Z4FSET2HGPZYLYLLKLTQZMW 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: So far there was no cleanup for sessions of target/portal combinations that are no longer exported. Adds a cleanup after all logins are done or sessions are rescanned. Signed-off-by: Mira Limbeck --- This patch is optional and may be a bit controversial since it changes the current behavior. This patch should be discussed in-depth before it is applied. src/PVE/Storage/ISCSIPlugin.pm | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/PVE/Storage/ISCSIPlugin.pm b/src/PVE/Storage/ISCSIPlugin.pm index b3f4e60..5b636a8 100644 --- a/src/PVE/Storage/ISCSIPlugin.pm +++ b/src/PVE/Storage/ISCSIPlugin.pm @@ -736,6 +736,41 @@ sub activate_storage { iscsi_session_rescan($targets->{$target}->{sessions}); } } + + # log out of stale sessions + # should only be needed for the non-mapping case + if (!$local_cfg->{is_mapping}) { + for my $target (keys $targets->%*) { + for my $session ($targets->{$target}->{sessions}->@*) { + my $portals = $targets->{$target}->{portals}; + if (!grep(/^\Q$session->{portal}\E$/, $portals->@*)) { + my $sid = $session->{session_id}; + my $portal = $session->{portal}; + print "logging out of stale iscsi session: $sid for $target via $portal\n"; + my $cmd = [ + $ISCSIADM, '--mode', 'session', '--sid', $sid, '--logout', + ]; + eval { run_command($cmd); }; + warn "failed to log out of stale session: $@\n" if $@; + + print "removing stale node entry: $target via $portal\n"; + $cmd = [ + $ISCSIADM, + '--mode', + 'node', + '--target', + $target, + '--portal', + $portal, + '-o', + 'delete', + ]; + eval { run_command($cmd); }; + warn "failed to remove stale node entry: $@\n" if $@; + } + } + } + } } sub deactivate_storage { -- 2.47.3