public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Mira Limbeck <m.limbeck@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH v2 storage 06/15] iscsi: change functions to handle mappings
Date: Thu, 30 Apr 2026 19:27:04 +0200	[thread overview]
Message-ID: <20260430173220.441001-7-m.limbeck@proxmox.com> (raw)
In-Reply-To: <20260430173220.441001-1-m.limbeck@proxmox.com>

change functions to use the new local config that unifies mapping and
non-mapping configs into a similar structure

Signed-off-by: Mira Limbeck <m.limbeck@proxmox.com>
---
 src/PVE/Storage/ISCSIPlugin.pm | 105 ++++++++++++++++++++++-----------
 1 file changed, 69 insertions(+), 36 deletions(-)

diff --git a/src/PVE/Storage/ISCSIPlugin.pm b/src/PVE/Storage/ISCSIPlugin.pm
index 8e5cbfb..8f2bdb5 100644
--- a/src/PVE/Storage/ISCSIPlugin.pm
+++ b/src/PVE/Storage/ISCSIPlugin.pm
@@ -479,26 +479,30 @@ sub list_images {
 
     # we have no owner for iscsi devices
 
-    my $target = $scfg->{target};
+    my $local_cfg = $get_local_config->($scfg);
+    my $targets = $local_cfg->{targets};
 
-    if (my $dat = $cache->{iscsi_devices}->{$target}) {
+    for my $target (keys $targets->%*) {
+        if (my $dat = $cache->{iscsi_devices}->{$target}) {
 
-        foreach my $volname (keys %$dat) {
+            foreach my $volname (keys %$dat) {
 
-            my $volid = "$storeid:$volname";
+                my $volid = "$storeid:$volname";
 
-            if ($vollist) {
-                my $found = grep { $_ eq $volid } @$vollist;
-                next if !$found;
-            } else {
-                # we have no owner for iscsi devices
-                next if defined($vmid);
-            }
+                if ($vollist) {
+                    my $found = grep { $_ eq $volid } @$vollist;
+                    next if !$found;
+                } else {
+                    # we have no owner for iscsi devices
+                    next if defined($vmid);
+                }
 
-            my $info = $dat->{$volname};
-            $info->{volid} = $volid;
+                my $info = $dat->{$volname};
+                $info->{volid} = $volid;
 
-            push @$res, $info;
+                push @$res, $info;
+            }
+            last;
         }
     }
 
@@ -514,8 +518,13 @@ sub iscsi_session {
 sub status {
     my ($class, $storeid, $scfg, $cache) = @_;
 
-    my $session = iscsi_session($cache, $scfg->{target});
-    my $active = defined($session) ? 1 : 0;
+    my $local_cfg = $get_local_config->($scfg);
+    my $active = 0;
+    for my $target (keys $local_cfg->{targets}->%*) {
+        my $session = iscsi_session($cache, $target);
+        $active = 1 if defined($session);
+        last if defined($session);
+    }
 
     return (0, 0, 0, $active);
 }
@@ -525,28 +534,41 @@ sub activate_storage {
 
     return if !assert_iscsi_support(1);
 
-    my $sessions = iscsi_session($cache, $scfg->{target});
-    my $portals = iscsi_portals($scfg->{target}, $scfg->{portal});
-    my $do_login = !defined($sessions);
+    my $local_cfg = $get_local_config->($scfg);
+    my $targets = {};
+    for my $target (keys $local_cfg->{targets}->%*) {
+        my $sessions = iscsi_session($cache, $target);
+        $targets->{$target}->{sessions} = $sessions;
+        $targets->{$target}->{portals} = $local_cfg->{targets}->{$target};
+    }
+    my $do_login = 0;
+    for my $target (keys $targets->%*) {
+        $do_login = 1 if !defined($targets->{$target}->{sessions});
+    }
 
     if (!$do_login) {
         # We should check that sessions for all portals are available
-        my $session_portals = [map { $_->{portal} } (@$sessions)];
-
-        for my $portal (@$portals) {
-            if (!grep(/^\Q$portal\E$/, @$session_portals)) {
-                $do_login = 1;
-                last;
+        for my $target (keys $targets->%*) {
+            my $session_portals = [map { $_->{portal} } ($targets->{$target}->{sessions}->@*)];
+            for my $portal ($targets->{$target}->{portals}->@*) {
+                if (!grep(/^\Q$portal\E(?::3260)?$/, $session_portals->@*)) {
+                    $do_login = 1;
+                    last;
+                }
             }
         }
     }
 
     if ($do_login) {
-        eval { iscsi_login($scfg->{target}, $portals, $cache); };
-        warn $@ if $@;
+        for my $target (keys $targets->%*) {
+            eval { iscsi_login($target, $targets->{$target}->{portals}, $cache); };
+            warn $@ if $@;
+        }
     } else {
         # make sure we get all devices
-        iscsi_session_rescan($sessions);
+        for my $target (keys $targets->%*) {
+            iscsi_session_rescan($targets->{$target}->{sessions});
+        }
     }
 }
 
@@ -555,8 +577,11 @@ sub deactivate_storage {
 
     return if !assert_iscsi_support(1);
 
-    if (defined(iscsi_session($cache, $scfg->{target}))) {
-        iscsi_logout($scfg->{target});
+    my $local_cfg = $get_local_config->($scfg);
+    for my $target (keys $local_cfg->{targets}->%*) {
+        if (defined(iscsi_session($cache, $target))) {
+            iscsi_logout($target);
+        }
     }
 }
 
@@ -654,18 +679,26 @@ sub activate_volume {
     my $device_path = $udev_query_path->($real_path);
     my $resolved_paths = $resolve_virtual_devices->($device_path);
 
-    my $found = $check_devices_part_of_target->($resolved_paths, $scfg->{target});
-    die "volume '$volname' not part of target '$scfg->{target}'\n" if !$found;
+    my $local_cfg = $get_local_config->($scfg);
+    my $found = 0;
+    for my $target ($local_cfg->{targets}->%*) {
+        $found ||= $check_devices_part_of_target->($resolved_paths, $target);
+        last if $found;
+    }
+    die "volume '$volname' not part of any matching target\n" if !$found;
 }
 
 sub check_connection {
     my ($class, $storeid, $scfg) = @_;
+
     my $cache = {};
-    my $portals = iscsi_portals($scfg->{target}, $scfg->{portal});
+    my $local_cfg = $get_local_config->($scfg);
 
-    for my $portal (@$portals) {
-        my $result = iscsi_test_portal($scfg->{target}, $portal, $cache);
-        return $result if $result;
+    for my $target (keys $local_cfg->{targets}->%*) {
+        for my $portal ($local_cfg->{targets}->{$target}->@*) {
+            my $result = iscsi_test_portal($target, $portal, $cache);
+            return $result if $result;
+        }
     }
 
     return 0;
-- 
2.47.3




  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 ` Mira Limbeck [this message]
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 ` [PATCH v2 storage 13/15] api: add non-persistent iscsi discovery option Mira Limbeck
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-7-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 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