From: Mira Limbeck <m.limbeck@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH v2 storage 13/15] api: add non-persistent iscsi discovery option
Date: Thu, 30 Apr 2026 19:27:11 +0200 [thread overview]
Message-ID: <20260430173220.441001-14-m.limbeck@proxmox.com> (raw)
In-Reply-To: <20260430173220.441001-1-m.limbeck@proxmox.com>
and return new portals list with reachability information for each
portal
Signed-off-by: Mira Limbeck <m.limbeck@proxmox.com>
---
src/PVE/API2/Storage/Scan.pm | 32 ++++++++++++++++++++++++++++++--
src/PVE/CLI/pvesm.pm | 3 ++-
src/PVE/Storage.pm | 2 +-
src/PVE/Storage/ISCSIPlugin.pm | 15 +++++++++++----
4 files changed, 44 insertions(+), 8 deletions(-)
diff --git a/src/PVE/API2/Storage/Scan.pm b/src/PVE/API2/Storage/Scan.pm
index a58bdd8..f272e3b 100644
--- a/src/PVE/API2/Storage/Scan.pm
+++ b/src/PVE/API2/Storage/Scan.pm
@@ -265,6 +265,12 @@ __PACKAGE__->register_method({
type => 'string',
format => 'pve-storage-portal-dns',
},
+ persist => {
+ description => 'Persist discovery results to discovery db.',
+ type => 'boolean',
+ optional => 1,
+ default => 1,
+ },
},
},
returns => {
@@ -280,17 +286,39 @@ __PACKAGE__->register_method({
description => "The iSCSI portal name.",
type => 'string',
},
+ portals => {
+ description => 'The iSCSI portals discovered, includes reachability.',
+ type => 'string',
+ },
},
},
},
code => sub {
my ($param) = @_;
- my $res = PVE::Storage::scan_iscsi($param->{portal});
+ my $persist = $param->{persist} // 1;
+ my $res = PVE::Storage::scan_iscsi($param->{portal}, $persist);
my $data = [];
foreach my $k (sort keys %$res) {
- push @$data, { target => $k, portal => join(',', @{ $res->{$k} }) };
+ my $portals = [];
+ my $portals_reachability = [];
+ for my $entry ($res->{$k}->@*) {
+ my $portal = $entry->{portal};
+ my $reachability = $entry->{reachable} ? '1' : '0';
+ push $portals->@*, $portal;
+ push $portals_reachability->@*, $portal . ':' . $reachability;
+ }
+ #my $portals = [ map { $_->{portal} } $res->{$k}->@* ];
+ #my $portals_reachability = [ map { $_->{portal} . ':' . ($_->{reachable} ? '1' : '0') } $res->{$k}->@* ];
+ my $entry = {
+ target => $k,
+ portal => join(',', $portals->@*),
+ portals => join(',', $portals_reachability->@*),
+ #portals => join(',', map { $_->{portal}.':'.($_->{reachable} // '0') } $res->{$k}->@*),
+ };
+ #push @$data, { target => $k, portal => join(',', $portals->@*) };
+ push $data->@*, $entry;
}
return $data;
diff --git a/src/PVE/CLI/pvesm.pm b/src/PVE/CLI/pvesm.pm
index 06bc4c9..6e88123 100755
--- a/src/PVE/CLI/pvesm.pm
+++ b/src/PVE/CLI/pvesm.pm
@@ -688,7 +688,8 @@ our $cmddef = {
$maxlen = $len if $len > $maxlen;
}
foreach my $rec (@$res) {
- printf "%-${maxlen}s %s\n", $rec->{target}, $rec->{portal};
+ printf "%-${maxlen}s %s %s\n", $rec->{target}, $rec->{portal},
+ $rec->{portals};
}
},
],
diff --git a/src/PVE/Storage.pm b/src/PVE/Storage.pm
index d783788..73546d2 100755
--- a/src/PVE/Storage.pm
+++ b/src/PVE/Storage.pm
@@ -1658,7 +1658,7 @@ sub scan_iscsi {
die "unable to parse/resolve portal address '${portal_in}'\n";
}
- return PVE::Storage::ISCSIPlugin::iscsi_discovery(undef, [$portal]);
+ return PVE::Storage::ISCSIPlugin::iscsi_discovery(undef, [$portal], undef, 0);
}
sub storage_default_format {
diff --git a/src/PVE/Storage/ISCSIPlugin.pm b/src/PVE/Storage/ISCSIPlugin.pm
index a95edf4..066d1ed 100644
--- a/src/PVE/Storage/ISCSIPlugin.pm
+++ b/src/PVE/Storage/ISCSIPlugin.pm
@@ -200,7 +200,7 @@ sub iscsi_portals {
}
sub iscsi_discovery {
- my ($target_in, $portals, $cache, $update_db) = @_;
+ my ($target_in, $portals, $cache, $persist) = @_;
assert_iscsi_support();
@@ -208,8 +208,9 @@ sub iscsi_discovery {
for my $portal ($portals->@*) {
next if !iscsi_test_portal($target_in, $portal, $cache); # fixme: raise exception here?
+ my $target_found = 0;
my $cmd = [$ISCSIADM, '--mode', 'discovery', '--type', 'sendtargets', '--portal', $portal];
- push $cmd->@*, '-o', 'nonpersistent' if !$update_db;
+ push $cmd->@*, '-o', 'nonpersistent' if !$persist;
eval {
run_command(
$cmd,
@@ -220,14 +221,20 @@ sub iscsi_discovery {
my ($portal, $target) = ($1, $2);
# one target can have more than one portal (multipath)
# and sendtargets should return all of them in single call
- push @{ $res->{$target} }, $portal;
+ my $entry = {
+ portal => $portal,
+ reachable => !!iscsi_test_portal($target, $portal, $cache),
+ };
+ push @{ $res->{$target} }, $entry;
+
+ $target_found = 1 if defined($target_in) && $target_in eq $target;
}
},
);
};
# In case of multipath we can stop after receiving targets from any available portal
- last if defined($target) && scalar(keys %$res) > 0;
+ last if $target_found && scalar(keys %$res) > 0;
}
return $res;
--
2.47.3
next prev parent reply other threads:[~2026-04-30 17:33 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-30 17:26 [PATCH v2 cluster/storage/manager 00/15] storage mapping Mira Limbeck
2026-04-30 17:26 ` [PATCH v2 cluster 01/15] mapping: add storage.cfg Mira Limbeck
2026-04-30 17:27 ` [PATCH v2 storage 02/15] mapping: add base plugin Mira Limbeck
2026-04-30 17:35 ` Mira Limbeck
2026-04-30 17:27 ` [PATCH v2 storage 03/15] mapping: add iSCSI plugin Mira Limbeck
2026-04-30 17:27 ` [PATCH v2 storage 04/15] iscsi: introduce mapping support Mira Limbeck
2026-04-30 17:27 ` [PATCH v2 storage 05/15] iscsi: add helper to get local config Mira Limbeck
2026-04-30 17:27 ` [PATCH v2 storage 06/15] iscsi: change functions to handle mappings Mira Limbeck
2026-04-30 17:27 ` [PATCH v2 storage 07/15] iscsi: introduce helper to update discovery db Mira Limbeck
2026-04-30 17:27 ` [PATCH v2 storage 08/15] iscsi: rework to update discovery db and simplify login Mira Limbeck
2026-04-30 17:27 ` [PATCH v2 storage 09/15] iscsi: remove stale sessions in non-mapping case Mira Limbeck
2026-04-30 17:27 ` [PATCH v2 storage 10/15] api: add mapping support Mira Limbeck
2026-04-30 17:27 ` [PATCH v2 storage 11/15] mapping: iscsi: add discovery-portal config option Mira Limbeck
2026-04-30 17:27 ` [PATCH v2 storage 12/15] iscsi: add support for non-persistent discovery Mira Limbeck
2026-04-30 17:38 ` Mira Limbeck
2026-04-30 17:27 ` Mira Limbeck [this message]
2026-04-30 17:27 ` [POC v2 storage 14/15] mapping: add zfspool plugin Mira Limbeck
2026-04-30 17:27 ` [PATCH v2 manager 15/15] api: mapping: add storage mapping path Mira Limbeck
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=20260430173220.441001-14-m.limbeck@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.