public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: "Max R. Carrara" <m.carrara@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-storage 5/9] luncmd: lio: modernize & clean up `list_view()` and `list_lun()` subs
Date: Thu, 25 Jun 2026 18:40:57 +0200	[thread overview]
Message-ID: <20260625164110.706694-6-m.carrara@proxmox.com> (raw)
In-Reply-To: <20260625164110.706694-1-m.carrara@proxmox.com>

Make the `list_view()` and `list_lun()` subs "proper" private
subroutines instead of lexically-scoped sub references.

Also improve the code style along the way.

Signed-off-by: Max R. Carrara <m.carrara@proxmox.com>
---
 src/PVE/Storage/LunCmd/LIO.pm | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/src/PVE/Storage/LunCmd/LIO.pm b/src/PVE/Storage/LunCmd/LIO.pm
index abe0454b..483e2459 100644
--- a/src/PVE/Storage/LunCmd/LIO.pm
+++ b/src/PVE/Storage/LunCmd/LIO.pm
@@ -244,49 +244,49 @@ my sub extract_volname {
 }
 
 # retrieves the LUN index for a particular object
-my $list_view = sub {
+my sub list_view {
     my ($scfg, $config, $timeout, $method, @params) = @_;
-    my $lun = undef;
 
-    my $object = $params[0];
+    my $object = shift @params;
     my $volname = extract_volname($scfg, $config, $object);
+    return if !defined($volname); # nothing to search for..
+
     my $id = "$scfg->{portal}.$scfg->{target}";
     my $target = $config->{$id};
 
-    return undef if !defined($volname); # nothing to search for..
-
-    foreach my $lun (@{ $target->{luns} }) {
+    for my $lun ($target->{luns}->@*) {
         if ($lun->{storage_object} eq "$BACKSTORE/$volname") {
             return $lun->{index};
         }
     }
 
-    return $lun;
-};
+    return;
+}
 
-# determines, if the given object exists on the portal
-my $list_lun = sub {
+# determines if the given object exists on the portal
+my sub list_lun {
     my ($scfg, $config, $timeout, $method, @params) = @_;
 
-    my $object = $params[0];
+    my $object = shift @params;
     my $volname = extract_volname($scfg, $config, $object);
+
     my $id = "$scfg->{portal}.$scfg->{target}";
     my $target = $config->{$id};
 
-    foreach my $lun (@{ $target->{luns} }) {
+    for my $lun ($target->{luns}->@*) {
         if ($lun->{storage_object} eq "$BACKSTORE/$volname") {
             return $object;
         }
     }
 
-    return undef;
-};
+    return;
+}
 
 # adds a new LUN to the target
 my $create_lun = sub {
     my ($scfg, $config, $timeout, $method, @params) = @_;
 
-    if ($list_lun->($scfg, $config, $timeout, $method, @params)) {
+    if (list_lun($scfg, $config, $timeout, $method, @params)) {
         die "$params[0]: LUN already exists!";
     }
 
@@ -392,8 +392,8 @@ my %lun_cmd_map = (
     import_lu => $import_lun,
     modify_lu => $modify_lun,
     add_view => $add_view,
-    list_view => $list_view,
-    list_lu => $list_lun,
+    list_view => sub { list_view(@_) },
+    list_lu => sub { list_lun(@_) },
 );
 
 sub run_lun_command {
-- 
2.47.3





  parent reply	other threads:[~2026-06-25 16:41 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-25 16:40 [PATCH storage 0/9] Fix ZFS-over-iSCSI plugin w/ LIO Provider Issues Max R. Carrara
2026-06-25 16:40 ` [PATCH pve-storage 1/9] luncmd: lio: fix various errors by removing caching mechanism Max R. Carrara
2026-06-25 16:40 ` [PATCH pve-storage 2/9] luncmd: lio: fix LUN ops failing when passing nonstandard LUN path Max R. Carrara
2026-06-25 16:40 ` [PATCH pve-storage 3/9] luncmd: lio: remove rest of old parsing logic Max R. Carrara
2026-06-25 16:40 ` [PATCH pve-storage 4/9] luncmd: lio: modernize helpers Max R. Carrara
2026-06-25 16:40 ` Max R. Carrara [this message]
2026-06-25 16:40 ` [PATCH pve-storage 6/9] luncmd: lio: modernize sub `create_lun()` Max R. Carrara
2026-06-25 16:40 ` [PATCH pve-storage 7/9] luncmd: lio: modernize sub `delete_lun()` Max R. Carrara
2026-06-25 16:41 ` [PATCH pve-storage 8/9] luncmd: lio: modernize remaining LUN command subroutines Max R. Carrara
2026-06-25 16:41 ` [PATCH pve-storage 9/9] luncmd: lio: use v5.36 and use subroutine signatures Max R. Carrara

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=20260625164110.706694-6-m.carrara@proxmox.com \
    --to=m.carrara@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