all lists on 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 v4] fix #957 iscsi: improve iscsi_test_portal logic
Date: Sat, 15 Mar 2025 13:08:55 +0100	[thread overview]
Message-ID: <mailman.51.1742117805.416.pve-devel@lists.proxmox.com> (raw)

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

From: Victor Seva <linuxmaniac@torreviejawireless.org>
To: pve-devel@lists.proxmox.com
Subject: [PATCH storage v4] fix #957 iscsi: improve iscsi_test_portal logic
Date: Sat, 15 Mar 2025 13:08:55 +0100
Message-ID: <20250315120854.95412-2-linuxmaniac@torreviejawireless.org>

don't check tcp connection directly if there are already
sessions.

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>
---

changes since v3:

* iscsi_test_session():
  read /sys/class/iscsi_session/session${sid}/state instead of
  $ISCSIADM call

* iscsi_test_portal():
  add optional parameters target and cache. If target is defined,
  used it to check session status instead of check tcp port

* iscsi_discovery():
  add optional parameters target and cache and pass it to
  iscsi_test_portal call

* iscsi_login():
  add optional parameter cache and pass it to iscsi_discovery call

* activate_storage():
  pass cache parameter to iscsi_login call

* check_connection():
  add target and cache parameters to iscsi_test_portal call  

 src/PVE/Storage.pm             |  2 +-
 src/PVE/Storage/ISCSIPlugin.pm | 41 ++++++++++++++++++++++++++--------
 2 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/src/PVE/Storage.pm b/src/PVE/Storage.pm
index 3b4f041..c5d4ff8 100755
--- a/src/PVE/Storage.pm
+++ b/src/PVE/Storage.pm
@@ -1479,7 +1479,7 @@ sub scan_iscsi {
 	die "unable to parse/resolve portal address '${portal_in}'\n";
     }
 
-    return PVE::Storage::ISCSIPlugin::iscsi_discovery([ $portal ]);
+    return PVE::Storage::ISCSIPlugin::iscsi_discovery(undef, [ $portal ]);
 }
 
 sub storage_default_format {
diff --git a/src/PVE/Storage/ISCSIPlugin.pm b/src/PVE/Storage/ISCSIPlugin.pm
index eb70453..c7bacea 100644
--- a/src/PVE/Storage/ISCSIPlugin.pm
+++ b/src/PVE/Storage/ISCSIPlugin.pm
@@ -58,9 +58,32 @@ sub iscsi_session_list {
     return $res;
 }
 
-sub iscsi_test_portal {
-    my ($portal) = @_;
+sub iscsi_test_session {
+    my ($sid) = @_;
 
+    if ($sid !~ m/^\d+$/) {
+	die "session_id: '$sid' is not a number\n";
+    }
+    my $state = file_read_firstline("/sys/class/iscsi_session/session${sid}/state");
+    if ($state eq 'LOGGED_IN') {
+	return 1;
+    }
+    return 0;
+}
+
+sub iscsi_test_portal {
+    my ($target, $portal, $cache) = @_;
+    $cache //= {};
+
+    if (defined($target)) {
+	# check session state instead if available
+	my $sessions = iscsi_session($cache, $target);
+	for my $session ($sessions->@*) {
+	    next if $session->{portal} ne $portal;
+	    return iscsi_test_session($session->{session_id});
+	}
+    }
+    # check portal via tcp
     my ($server, $port) = PVE::Tools::parse_host_and_port($portal);
     return 0 if !$server;
     return PVE::Network::tcp_ping($server, $port || 3260, 2);
@@ -97,13 +120,13 @@ sub iscsi_portals {
 }
 
 sub iscsi_discovery {
-    my ($portals) = @_;
+    my ($target, $portals, $cache) = @_;
 
     assert_iscsi_support();
 
     my $res = {};
     for my $portal ($portals->@*) {
-	next if !iscsi_test_portal($portal); # fixme: raise exception here?
+	next if !iscsi_test_portal($target, $portal, $cache); # fixme: raise exception here?
 
 	my $cmd = [$ISCSIADM, '--mode', 'discovery', '--type', 'sendtargets', '--portal', $portal];
 	eval {
@@ -127,11 +150,11 @@ sub iscsi_discovery {
 }
 
 sub iscsi_login {
-    my ($target, $portals) = @_;
+    my ($target, $portals, $cache) = @_;
 
     assert_iscsi_support();
 
-    eval { iscsi_discovery($portals); };
+    eval { iscsi_discovery($target, $portals, $cache); };
     warn $@ if $@;
 
     # Disable retries to avoid blocking pvestatd for too long, next iteration will retry anyway
@@ -445,7 +468,7 @@ sub activate_storage {
     }
 
     if ($do_login) {
-	eval { iscsi_login($scfg->{target}, $portals); };
+	eval { iscsi_login($scfg->{target}, $portals, $cache); };
 	warn $@ if $@;
     } else {
 	# make sure we get all devices
@@ -559,11 +582,11 @@ sub activate_volume {
 
 sub check_connection {
     my ($class, $storeid, $scfg) = @_;
-
+    my $cache = {};
     my $portals = iscsi_portals($scfg->{target}, $scfg->{portal});
 
     for my $portal (@$portals) {
-	my $result = iscsi_test_portal($portal);
+	my $result = iscsi_test_portal($scfg->{target}, $portal, $cache);
 	return $result if $result;
     }
 
-- 
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-16  9:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-15 12:08 Victor Seva via pve-devel [this message]
2025-03-18 16:11 ` Friedrich Weber
2025-03-20 10:15   ` Mira Limbeck
2025-03-20 10:48     ` Friedrich Weber

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.51.1742117805.416.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 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