public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Victor Seva via pve-devel <pve-devel@lists.proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: Victor Seva <linuxmaniac@torreviejawireless.org>
Subject: [pve-devel] [PATCH storage v2] fix #957 iscsi: improve check_connection logic
Date: Sat,  8 Mar 2025 16:52:29 +0100	[thread overview]
Message-ID: <mailman.909.1741449308.293.pve-devel@lists.proxmox.com> (raw)

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

From: Victor Seva <linuxmaniac@torreviejawireless.org>
To: pve-devel@lists.proxmox.com
Subject: [PATCH storage v2] fix #957 iscsi: improve check_connection logic
Date: Sat,  8 Mar 2025 16:52:29 +0100
Message-ID: <20250308155229.968380-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 | 42 ++++++++++++++++++++++++++++++----
 1 file changed, 37 insertions(+), 5 deletions(-)

diff --git a/src/PVE/Storage/ISCSIPlugin.pm b/src/PVE/Storage/ISCSIPlugin.pm
index eb70453..bcc281b 100644
--- a/src/PVE/Storage/ISCSIPlugin.pm
+++ b/src/PVE/Storage/ISCSIPlugin.pm
@@ -66,6 +66,25 @@ 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;
+            }
+        });
+    };
+    if (my $err = $@) {
+        die $err;
+    };
+    return $res;
+}
+
 sub iscsi_portals {
     my ($target, $portal_in) = @_;
 
@@ -560,11 +579,24 @@ sub activate_volume {
 sub check_connection {
     my ($class, $storeid, $scfg) = @_;
 
-    my $portals = iscsi_portals($scfg->{target}, $scfg->{portal});
-
-    for my $portal (@$portals) {
-	my $result = iscsi_test_portal($portal);
-	return $result if $result;
+    my $cache = {};
+    my $sessions = [];
+    eval {
+        $sessions = iscsi_session($cache, $scfg->{target});
+    };
+    if (my $err = $@) {
+        # no sessions, check portal via tcp
+        my $portals = iscsi_portals($scfg->{target}, $scfg->{portal});
+        for my $portal (@$portals) {
+            my $result = iscsi_test_portal($portal);
+            return $result if $result;
+        }
+        return 0;
+    }
+    # we have sessions, let's test them instead
+    for my $session (@$sessions) {
+        my $result = iscsi_test_session($session->{session_id});
+        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

             reply	other threads:[~2025-03-08 15:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-08 15:52 Victor Seva via pve-devel [this message]
2025-03-11 14:35 ` Mira Limbeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=mailman.909.1741449308.293.pve-devel@lists.proxmox.com \
    --to=pve-devel@lists.proxmox.com \
    --cc=linuxmaniac@torreviejawireless.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal