From: Mira Limbeck <m.limbeck@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: Re: [pve-devel] [PATCH storage v2] fix #957 iscsi: improve check_connection logic
Date: Tue, 11 Mar 2025 15:35:34 +0100 [thread overview]
Message-ID: <52f12eb8-b235-4edc-a840-3c0e873a4103@proxmox.com> (raw)
In-Reply-To: <mailman.909.1741449308.293.pve-devel@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
prev parent reply other threads:[~2025-03-11 14:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-08 15:52 Victor Seva via pve-devel
2025-03-11 14:35 ` Mira Limbeck [this message]
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=52f12eb8-b235-4edc-a840-3c0e873a4103@proxmox.com \
--to=m.limbeck@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/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