From: "Max R. Carrara" <m.carrara@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-storage 4/9] luncmd: lio: modernize helpers
Date: Thu, 25 Jun 2026 18:40:56 +0200 [thread overview]
Message-ID: <20260625164110.706694-5-m.carrara@proxmox.com> (raw)
In-Reply-To: <20260625164110.706694-1-m.carrara@proxmox.com>
Modernize the `get_backstore_prefix()` and `extract_volname()` helpers
by making them "proper" private subs instead of lexically-scoped sub
references.
Refactor the body of `extract_volname()` by reducing nesting, more
modern syntax, and a little guard clause.
Signed-off-by: Max R. Carrara <m.carrara@proxmox.com>
---
src/PVE/Storage/LunCmd/LIO.pm | 50 +++++++++++++++++++----------------
1 file changed, 27 insertions(+), 23 deletions(-)
diff --git a/src/PVE/Storage/LunCmd/LIO.pm b/src/PVE/Storage/LunCmd/LIO.pm
index ae5f3188..abe0454b 100644
--- a/src/PVE/Storage/LunCmd/LIO.pm
+++ b/src/PVE/Storage/LunCmd/LIO.pm
@@ -207,37 +207,41 @@ my $execute_remote_command = sub {
return $res;
};
-# Get prefix for backstores
-my $get_backstore_prefix = sub {
+my sub get_backstore_prefix {
my ($scfg) = @_;
my $pool = $scfg->{pool};
$pool =~ s/\//-/g;
return $pool . '-';
-};
+}
# extracts the ZFS volume name from a device path
-my $extract_volname = sub {
+my sub extract_volname {
my ($scfg, $config, $lunpath) = @_;
- my $volname = undef;
my $base = get_base($scfg);
- if ($lunpath =~ /^$base\/$scfg->{pool}\/([\w\-\.]+)$/) {
- $volname = $1;
- my $prefix = $get_backstore_prefix->($scfg);
- my $id = "$scfg->{portal}.$scfg->{target}";
- my $target = $config->{$id};
- foreach my $lun (@{ $target->{luns} }) {
- # If we have a lun with the pool prefix matching this vol, then return this one
- # like pool-pve-vm-100-disk-0
- # Else, just fallback to the old name scheme which is vm-100-disk-0
- if ($lun->{storage_object} =~ /^$BACKSTORE\/($prefix$volname)$/) {
- return $1;
- }
+
+ $lunpath =~ m/^$base\/$scfg->{pool}\/(?<volname>[\w\-\.]+)$/;
+ my $volname = $+{volname};
+
+ if (!defined($volname)) {
+ return;
+ }
+
+ my $prefix = get_backstore_prefix($scfg);
+ my $id = "$scfg->{portal}.$scfg->{target}";
+ my $target = $config->{$id};
+
+ for my $lun ($target->{luns}->@*) {
+ # If we have a lun with the pool prefix matching this vol, then return this one
+ # like pool-pve-vm-100-disk-0
+ # Else, just fallback to the old name scheme which is vm-100-disk-0
+ if ($lun->{storage_object} =~ /^$BACKSTORE\/(?<volname>$prefix$volname)$/) {
+ return $+{volname};
}
}
return $volname;
-};
+}
# retrieves the LUN index for a particular object
my $list_view = sub {
@@ -245,7 +249,7 @@ my $list_view = sub {
my $lun = undef;
my $object = $params[0];
- my $volname = $extract_volname->($scfg, $config, $object);
+ my $volname = extract_volname($scfg, $config, $object);
my $id = "$scfg->{portal}.$scfg->{target}";
my $target = $config->{$id};
@@ -265,7 +269,7 @@ my $list_lun = sub {
my ($scfg, $config, $timeout, $method, @params) = @_;
my $object = $params[0];
- my $volname = $extract_volname->($scfg, $config, $object);
+ my $volname = extract_volname($scfg, $config, $object);
my $id = "$scfg->{portal}.$scfg->{target}";
my $target = $config->{$id};
@@ -287,10 +291,10 @@ my $create_lun = sub {
}
my $device = $params[0];
- my $volname = $extract_volname->($scfg, $config, $device);
+ my $volname = extract_volname($scfg, $config, $device);
# Here we create a new device, so we didn't get the volname prefixed with the pool name
# as extract_volname couldn't find a matching vol yet
- $volname = $get_backstore_prefix->($scfg) . $volname;
+ $volname = get_backstore_prefix($scfg) . $volname;
my $tpg = $scfg->{lio_tpg} || die "Target Portal Group not set, aborting!\n";
# step 1: create backstore for device
@@ -333,7 +337,7 @@ my $delete_lun = sub {
my $tpg = $scfg->{lio_tpg} || die "Target Portal Group not set, aborting!\n";
my $path = $params[0];
- my $volname = $extract_volname->($scfg, $config, $path);
+ my $volname = extract_volname($scfg, $config, $path);
my $id = "$scfg->{portal}.$scfg->{target}";
my $target = $config->{$id};
--
2.47.3
next prev 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 ` Max R. Carrara [this message]
2026-06-25 16:40 ` [PATCH pve-storage 5/9] luncmd: lio: modernize & clean up `list_view()` and `list_lun()` subs Max R. Carrara
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-5-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 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.