From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 5540C1FF13C for ; Thu, 25 Jun 2026 18:41:34 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E3B434A4; Thu, 25 Jun 2026 18:41:28 +0200 (CEST) From: "Max R. Carrara" 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 Message-ID: <20260625164110.706694-5-m.carrara@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260625164110.706694-1-m.carrara@proxmox.com> References: <20260625164110.706694-1-m.carrara@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1782405674274 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.080 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: 65Y2IK5IXDJMTSQ5J6LNSLHPHSFMFSVE X-Message-ID-Hash: 65Y2IK5IXDJMTSQ5J6LNSLHPHSFMFSVE X-MailFrom: m.carrara@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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}\/(?[\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\/(?$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