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 BAE6F1FF15E
	for <inbox@lore.proxmox.com>; Tue, 11 Mar 2025 15:36:16 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 294B413C69;
	Tue, 11 Mar 2025 15:36:08 +0100 (CET)
Message-ID: <52f12eb8-b235-4edc-a840-3c0e873a4103@proxmox.com>
Date: Tue, 11 Mar 2025 15:35:34 +0100
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
To: pve-devel@lists.proxmox.com
References: <mailman.909.1741449308.293.pve-devel@lists.proxmox.com>
Content-Language: en-US
From: Mira Limbeck <m.limbeck@proxmox.com>
In-Reply-To: <mailman.909.1741449308.293.pve-devel@lists.proxmox.com>
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.296 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 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_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: Re: [pve-devel] [PATCH storage v2] fix #957 iscsi: improve
 check_connection logic
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
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/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

Thank you for the v2!

some comments inline
> +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;
> +    };
This can be written as just `die "$@\n" if $@` instead.
It should contain some additional info though, for example:
`die "session check failed: $@\n" if $@;`

> +    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});
> +    };
iscsi_session only dies if the `iscsiadm` command fails or prints
something other than `: No active sessions.`. See the `!~` check in
iscsi_session_list.

> +    if (my $err = $@) {
This will not be the case when there are no sessions, but when the
iscsiadm command fails. See above.

> +        # 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;
You could do something like this:
```
    my $cache = {};
    my $sessions = iscsi_session($cache, $scfg->{target});
    my $portals = iscsi_portals($scfg->{target}, $scfg->{portal});
    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;

	my $result = iscsi_test_portal($portal);
	return $result if $result;
    }
```
This goes through all portals, and if a session exists for the portal,
does a session test instead of the tcp_ping.
But if no session exists, it still checks with a tcp_ping to see if we
should login or not.


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