* [pve-devel] [PATCH storage v5] fix #957: iscsi: improve iscsi_test_portal logic
@ 2025-03-20 14:23 Victor Seva via pve-devel
2025-03-21 10:09 ` Mira Limbeck
2025-03-21 13:40 ` Friedrich Weber
0 siblings, 2 replies; 3+ messages in thread
From: Victor Seva via pve-devel @ 2025-03-20 14:23 UTC (permalink / raw)
To: pve-devel; +Cc: Victor Seva
[-- Attachment #1: Type: message/rfc822, Size: 7521 bytes --]
From: Victor Seva <linuxmaniac@torreviejawireless.org>
To: pve-devel@lists.proxmox.com
Subject: [PATCH storage v5] fix #957: iscsi: improve iscsi_test_portal logic
Date: Thu, 20 Mar 2025 15:23:20 +0100
Message-ID: <20250320142319.20411-2-linuxmaniac@torreviejawireless.org>
Check if there is already a logged session present and
fall back to previous TCP check port connection.
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 v4:
* rework commit message wording and subject in proper format
* iscsi_test_session():
use [0-9] instead of \d
simplify return logic checking $state is defined too
* iscsi_test_portal():
fallback to TCP check connection if session is not LOGGED_IN
* iscsi_discovery():
rename $target to $target_in to avoid variable shadowing
src/PVE/Storage.pm | 2 +-
src/PVE/Storage/ISCSIPlugin.pm | 39 ++++++++++++++++++++++++++--------
2 files changed, 31 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..2c608a4 100644
--- a/src/PVE/Storage/ISCSIPlugin.pm
+++ b/src/PVE/Storage/ISCSIPlugin.pm
@@ -58,9 +58,30 @@ sub iscsi_session_list {
return $res;
}
-sub iscsi_test_portal {
- my ($portal) = @_;
+sub iscsi_test_session {
+ my ($sid) = @_;
+ if ($sid !~ m/^[0-9]+$/) {
+ die "session_id: '$sid' is not a number\n";
+ }
+ my $state = file_read_firstline("/sys/class/iscsi_session/session${sid}/state");
+ return defined($state) && $state eq 'LOGGED_IN';
+}
+
+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;
+ my $state = iscsi_test_session($session->{session_id});
+ return $state if $state;
+ }
+ }
+ # 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 +118,13 @@ sub iscsi_portals {
}
sub iscsi_discovery {
- my ($portals) = @_;
+ my ($target_in, $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_in, $portal, $cache); # fixme: raise exception here?
my $cmd = [$ISCSIADM, '--mode', 'discovery', '--type', 'sendtargets', '--portal', $portal];
eval {
@@ -127,11 +148,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 +466,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 +580,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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [pve-devel] [PATCH storage v5] fix #957: iscsi: improve iscsi_test_portal logic
2025-03-20 14:23 [pve-devel] [PATCH storage v5] fix #957: iscsi: improve iscsi_test_portal logic Victor Seva via pve-devel
@ 2025-03-21 10:09 ` Mira Limbeck
2025-03-21 13:40 ` Friedrich Weber
1 sibling, 0 replies; 3+ messages in thread
From: Mira Limbeck @ 2025-03-21 10:09 UTC (permalink / raw)
To: pve-devel
The patch looks good to me. Thank you!
Consider this:
Tested-by: Mira Limbeck <m.limbeck@proxmox.com>
Reviewed-by: Mira Limbeck <m.limbeck@proxmox.com>
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [pve-devel] [PATCH storage v5] fix #957: iscsi: improve iscsi_test_portal logic
2025-03-20 14:23 [pve-devel] [PATCH storage v5] fix #957: iscsi: improve iscsi_test_portal logic Victor Seva via pve-devel
2025-03-21 10:09 ` Mira Limbeck
@ 2025-03-21 13:40 ` Friedrich Weber
1 sibling, 0 replies; 3+ messages in thread
From: Friedrich Weber @ 2025-03-21 13:40 UTC (permalink / raw)
To: Proxmox VE development discussion
Patch looks good to me too, ran a few tests and didn't see anything
unexpected, hence:
Tested-by: Friedrich Weber <f.weber@proxmox.com>
Reviewed-by: Friedrich Weber <f.weber@proxmox.com>
Thank you!
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-03-21 13:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-20 14:23 [pve-devel] [PATCH storage v5] fix #957: iscsi: improve iscsi_test_portal logic Victor Seva via pve-devel
2025-03-21 10:09 ` Mira Limbeck
2025-03-21 13:40 ` Friedrich Weber
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