all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH storage v3] fix #957 iscsi: improve check_connection logic
@ 2025-03-11 17:59 Victor Seva via pve-devel
  2025-03-12 11:45 ` Friedrich Weber
  0 siblings, 1 reply; 2+ messages in thread
From: Victor Seva via pve-devel @ 2025-03-11 17:59 UTC (permalink / raw)
  To: pve-devel; +Cc: Victor Seva

[-- Attachment #1: Type: message/rfc822, Size: 5897 bytes --]

From: Victor Seva <linuxmaniac@torreviejawireless.org>
To: pve-devel@lists.proxmox.com
Subject: [PATCH storage v3] fix #957 iscsi: improve check_connection logic
Date: Tue, 11 Mar 2025 18:59:25 +0100
Message-ID: <20250311175925.26830-1-linuxmaniac@torreviejawireless.org>

don't check tcp connection directly if there are already
sessions. Use iscsiadm command to check the sessions
status instead.

pvestatd is calling check_connection every 10 seconds.
This check produces a lot of noise at the iscsi server logging.

Signed-off-by: Victor Seva <linuxmaniac@torreviejawireless.org>
---
 src/PVE/Storage/ISCSIPlugin.pm | 34 +++++++++++++++++++++++++++++++---
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/src/PVE/Storage/ISCSIPlugin.pm b/src/PVE/Storage/ISCSIPlugin.pm
index eb70453..89fc871 100644
--- a/src/PVE/Storage/ISCSIPlugin.pm
+++ b/src/PVE/Storage/ISCSIPlugin.pm
@@ -66,6 +66,23 @@ sub iscsi_test_portal {
     return PVE::Network::tcp_ping($server, $port || 3260, 2);
 }
 
+sub iscsi_test_session {
+    my ($sid) = @_;
+    my $cmd = [$ISCSIADM, '--mode', 'session', '--sid', $sid, '-P1'];
+
+    my $res = 0;
+    eval {
+        run_command($cmd, errmsg => 'iscsi session test failed', outfunc => sub {
+            my $line = shift;
+            if ($line =~ m/^\s+iSCSI Session State: LOGGED_IN\s*$/) {
+                $res = 1;
+            }
+        });
+    };
+    die "session check failed: $@\n" if $@;
+    return $res;
+}
+
 sub iscsi_portals {
     my ($target, $portal_in) = @_;
 
@@ -560,11 +577,22 @@ sub activate_volume {
 sub check_connection {
     my ($class, $storeid, $scfg) = @_;
 
+    my $cache = {};
+    my $sessions = iscsi_session($cache, $scfg->{target});
     my $portals = iscsi_portals($scfg->{target}, $scfg->{portal});
 
-    for my $portal (@$portals) {
-	my $result = iscsi_test_portal($portal);
-	return $result if $result;
+    for my $portal ($portals->@*) {
+        my $session_exists = 0;
+        for my $session ($sessions->@*) {
+            next if $session->{portal} ne $portal;
+            $session_exists = 1;
+            my $result = iscsi_test_session($session->{session_id});
+            return $result if $result;
+        }
+        next if $session_exists;
+        # no sessions, check portal via tcp
+        my $result = iscsi_test_portal($portal);
+        return $result if $result;
     }
 
     return 0;
-- 
2.43.0



[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-03-12 11:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-11 17:59 [pve-devel] [PATCH storage v3] fix #957 iscsi: improve check_connection logic Victor Seva via pve-devel
2025-03-12 11:45 ` Friedrich Weber

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal