From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id D2F171FF162
	for <inbox@lore.proxmox.com>; Sat,  8 Mar 2025 16:55:17 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id F10C61B7A;
	Sat,  8 Mar 2025 16:55:08 +0100 (CET)
To: pve-devel@lists.proxmox.com
Date: Sat,  8 Mar 2025 16:52:29 +0100
MIME-Version: 1.0
Message-ID: <mailman.909.1741449308.293.pve-devel@lists.proxmox.com>
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Post: <mailto:pve-devel@lists.proxmox.com>
From: Victor Seva via pve-devel <pve-devel@lists.proxmox.com>
Precedence: list
Cc: Victor Seva <linuxmaniac@torreviejawireless.org>
X-Mailman-Version: 2.1.29
X-BeenThere: pve-devel@lists.proxmox.com
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
Subject: [pve-devel] [PATCH storage v2] fix #957 iscsi: improve
 check_connection logic
Content-Type: multipart/mixed; boundary="===============9021884083776254480=="
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

--===============9021884083776254480==
Content-Type: message/rfc822
Content-Disposition: inline

Return-Path: <linuxmaniac@torreviejawireless.org>
X-Original-To: pve-devel@lists.proxmox.com
Delivered-To: pve-devel@lists.proxmox.com
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
	(No client certificate requested)
	by lists.proxmox.com (Postfix) with ESMTPS id 96E57D508D
	for <pve-devel@lists.proxmox.com>; Sat,  8 Mar 2025 16:55:07 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 730CD1B57
	for <pve-devel@lists.proxmox.com>; Sat,  8 Mar 2025 16:55:07 +0100 (CET)
Received: from mail-106109.protonmail.ch (mail-106109.protonmail.ch [79.135.106.109])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
	(No client certificate requested)
	by firstgate.proxmox.com (Proxmox) with ESMTPS
	for <pve-devel@lists.proxmox.com>; Sat,  8 Mar 2025 16:55:05 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=torreviejawireless.org; s=protonmail; t=1741449284; x=1741708484;
	bh=WUapXu/fNmb5h0KFVXvfhoszh5SV+4PqFZUsg+72IEI=;
	h=From:To:Cc:Subject:Date:Message-ID:From:To:Cc:Date:Subject:
	 Reply-To:Feedback-ID:Message-ID:BIMI-Selector:List-Unsubscribe:
	 List-Unsubscribe-Post;
	b=NcJDt4CPFnOy3RjDbjWkkTfWmT3qBG8CRzIDRqrBoA9YnXoM5idSBmGNc/iTSeCNx
	 PXAscfAJzmomEnfaDgtn0eC5gNSW1JdLNNfJwks0E8ztM+EjaPaNQ5HWrJFgXwm09X
	 Ewr+aOioOftVK7ffCOqd/4pEqa6AKQ4ZAIPC2jjIuoN4SlvXcnyIHJtiVIEq51qsnu
	 6Re8OLIwX2gHuNHzPO85fqY6tDJbC7jSm6FGBmtotPixrVr7DUe6wz2gYrClVzc3LX
	 QiO65TUNFVVk6BE5e+s7o7/KrRcf3PK3rkhTssnabZQULhAEX2dcAcz4Ve87MLkBNM
	 Alisfi9IhgoGA==
X-Pm-Submission-Id: 4Z975H038jz4wwy6
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>
X-Mailer: git-send-email 2.43.0
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
	AWL                    -0.001 Adjusted score from AWL reputation of From: address
	BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
	DKIM_SIGNED               0.1 Message has a DKIM or DK signature, not necessarily valid
	DKIM_VALID               -0.1 Message has at least one valid DKIM or DK signature
	DKIM_VALID_AU            -0.1 Message has a valid DKIM or DK signature from author's domain
	DKIM_VALID_EF            -0.1 Message has a valid DKIM or DK signature from envelope-from domain
	DMARC_PASS               -0.1 DMARC pass policy
	RCVD_IN_DNSWL_NONE     -0.0001 Sender listed at https://www.dnswl.org/, no trust
	RCVD_IN_VALIDITY_CERTIFIED_BLOCKED  0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked.  See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information.
	RCVD_IN_VALIDITY_RPBL_BLOCKED  0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked.  See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information.
	RCVD_IN_VALIDITY_SAFE_BLOCKED  0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked.  See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information.
	SPF_HELO_PASS          -0.001 SPF: HELO matches SPF record
	SPF_PASS               -0.001 SPF: sender matches SPF record
	URIBL_BLOCKED           0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked.  See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [torreviejawireless.org,iscsiplugin.pm]

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



--===============9021884083776254480==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

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

--===============9021884083776254480==--