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 7/9] luncmd: lio: modernize sub `delete_lun()`
Date: Thu, 25 Jun 2026 18:40:59 +0200	[thread overview]
Message-ID: <20260625164110.706694-8-m.carrara@proxmox.com> (raw)
In-Reply-To: <20260625164110.706694-1-m.carrara@proxmox.com>

As before, make `delete_lun()` a "proper" private subroutine instead
of a lexically-scoped sub reference.

Use the new `run_remote_command()` helper for easier reading and
better error messages. Clean up the code style along the way a little.

Remove the old `$execute_remote_command` helper, as it is not used
anymore now.

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

diff --git a/src/PVE/Storage/LunCmd/LIO.pm b/src/PVE/Storage/LunCmd/LIO.pm
index 143b3fda..f4ad2ac8 100644
--- a/src/PVE/Storage/LunCmd/LIO.pm
+++ b/src/PVE/Storage/LunCmd/LIO.pm
@@ -166,47 +166,6 @@ my sub parse_remote_config {
     return $parsed_config;
 }
 
-my $execute_remote_command = sub {
-    my ($scfg, $timeout, $remote_command, @params) = @_;
-
-    my $msg = '';
-    my $err = undef;
-    my $target;
-    my $cmd;
-    my $res = ();
-
-    $timeout = 10 if !$timeout;
-
-    my $output = sub { $msg .= "$_[0]\n" };
-    my $errfunc = sub { $err .= "$_[0]\n" };
-
-    $target = 'root@' . $scfg->{portal};
-    $cmd = [
-        @ssh_cmd,
-        '-i',
-        "$id_rsa_path/$scfg->{portal}_id_rsa",
-        $target,
-        '--',
-        $remote_command,
-        @params,
-    ];
-
-    eval { run_command($cmd, outfunc => $output, errfunc => $errfunc, timeout => $timeout); };
-    if ($@) {
-        $res = {
-            result => 0,
-            msg => $err,
-        };
-    } else {
-        $res = {
-            result => 1,
-            msg => $msg,
-        };
-    }
-
-    return $res;
-};
-
 my sub get_backstore_prefix {
     my ($scfg) = @_;
     my $pool = $scfg->{pool};
@@ -357,10 +316,8 @@ my sub create_lun {
     return $register_res->{'merged-log'};
 }
 
-my $delete_lun = sub {
+my sub delete_lun {
     my ($scfg, $config, $timeout, $method, @params) = @_;
-    my $res = { msg => undef };
-
     my $tpg = $scfg->{lio_tpg} || die "Target Portal Group not set, aborting!\n";
 
     my $path = $params[0];
@@ -368,31 +325,48 @@ my $delete_lun = sub {
     my $id = "$scfg->{portal}.$scfg->{target}";
     my $target = $config->{$id};
 
-    foreach my $lun (@{ $target->{luns} }) {
+    for my $lun ($target->{luns}->@*) {
         next if $lun->{storage_object} ne "$BACKSTORE/$volname";
 
         # step 1: delete the lun
-        my @cliparams = ("/iscsi/$scfg->{target}/$tpg/luns/", 'delete', "lun$lun->{index}");
-        my $res = $execute_remote_command->($scfg, $timeout, $targetcli, @cliparams);
-        do {
-            die $res->{msg};
-        } unless $res->{result};
+        my $lun_path = "/iscsi/$scfg->{target}/$tpg/luns/";
+        my $lun_id = 'lun' . $lun->{index};
+        my $lun_delete_res = run_remote_command(
+            $scfg,
+            [$targetcli, $lun_path, 'delete', $lun_id],
+            timeout => $timeout,
+        );
+        if (!$lun_delete_res->{result}) {
+            my $err_msg = "Failed to delete LUN '$lun_id' in '$lun_path':\n"
+                . $lun_delete_res->{'merged-log'};
+            die $err_msg;
+        }
 
         # step 2: delete the backstore
-        @cliparams = ($BACKSTORE, 'delete', $volname);
-        $res = $execute_remote_command->($scfg, $timeout, $targetcli, @cliparams);
-        do {
-            die $res->{msg};
-        } unless $res->{result};
+        my $backstore_delete_res = run_remote_command(
+            $scfg,
+            [$targetcli, $BACKSTORE, 'delete', $volname],
+            timeout => $timeout,
+        );
+        if (!$backstore_delete_res->{result}) {
+            my $err_msg = "Failed to delete volume '$volname' from backstore '$BACKSTORE':\n"
+                . $backstore_delete_res->{'merged-log'};
+            die $err_msg;
+        }
 
-        # step 3: save to be safe ...
-        $execute_remote_command->($scfg, $timeout, $targetcli, 'saveconfig');
+        # step 3: unfortunately, targetcli doesn't always save changes, no matter
+        #         if auto_save_on_exit is true or not. So saving to be safe ...
+        my $saveconfig_res = run_remote_command(
+            $scfg, [$targetcli, 'saveconfig'], timeout => $timeout,
+        );
+        warn("Could not save LUN config: " . $saveconfig_res->{'merged-log'} . "\n")
+            if !$saveconfig_res->{result};
 
-        last;
+        return $backstore_delete_res->{'out-log'};
     }
 
-    return $res->{msg};
-};
+    die "Failed to delete LUN '$path'";
+}
 
 my $import_lun = sub {
     my ($scfg, $config, $timeout, $method, @params) = @_;
@@ -415,7 +389,7 @@ my $add_view = sub {
 
 my %lun_cmd_map = (
     create_lu => sub { create_lun(@_) },
-    delete_lu => $delete_lun,
+    delete_lu => sub { delete_lun(@_) },
     import_lu => $import_lun,
     modify_lu => $modify_lun,
     add_view => $add_view,
-- 
2.47.3





  parent reply	other threads:[~2026-06-25 16:42 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 ` [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 ` Max R. Carrara [this message]
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-8-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