all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH storage] fix #7295: lvm plugin: rollback: keep original volume when allocation fails and saferemove is used
Date: Mon,  9 Feb 2026 11:40:00 +0100	[thread overview]
Message-ID: <20260209104009.44272-1-f.ebner@proxmox.com> (raw)

When the 'saferemove' storage configuration option is used, the
'current' top volume of the backing chain is renamed and removal is
delegated to a worker task. Thus, the space for that volume is still
allocated and cannot be re-used for the new top volume (to be backed
by the snapshot volume). With a full enough pool, allocating the new
top volume fails. In this case, executing the saferemove worker and
removing the 'current' volume is bad, because there won't be any top
volume anymore. Fixing that situation would mean manually allocating a
new top volume backed by the snapshot afterwards.

Improve the situation by keeping the original top volume around and
renaming it back if allocating the new volume failed.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 src/PVE/Storage/LVMPlugin.pm | 41 ++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 21 deletions(-)

diff --git a/src/PVE/Storage/LVMPlugin.pm b/src/PVE/Storage/LVMPlugin.pm
index 32a8339..987e60b 100644
--- a/src/PVE/Storage/LVMPlugin.pm
+++ b/src/PVE/Storage/LVMPlugin.pm
@@ -1117,46 +1117,45 @@ sub volume_rollback_is_possible {
 }
 
 my sub volume_snapshot_rollback_locked {
-    my ($class, $scfg, $storeid, $volname, $snap, $cleanup_worker) = @_;
+    my ($class, $scfg, $storeid, $volname, $snap) = @_;
 
     my $format = ($class->parse_volname($volname))[6];
 
     die "can't rollback snapshot for '$format' volume\n" if $format ne 'qcow2';
 
-    $cleanup_worker->$* = eval { free_snap_image($class, $storeid, $scfg, $volname, 'current'); };
+    my $cleanup_worker = eval { free_snap_image($class, $storeid, $scfg, $volname, 'current'); };
     die "error deleting snapshot $snap $@\n" if $@;
 
     eval { alloc_snap_image($class, $storeid, $scfg, $volname, $snap) };
-    die "can't allocate new volume $volname: $@\n" if $@;
+    if (my $err = $@) {
+        if ($cleanup_worker) { # rename original image back
+            eval {
+                my $vg = $scfg->{vgname};
+                my $cmd = ['lvrename', $vg, "del-${volname}", $volname];
+                run_command($cmd, errmsg => "lvrename '${vg}/del-${volname}' error");
+            };
+            warn $@ if $@;
+        }
+        die "can't allocate new volume $volname: $err\n";
+    }
 
-    return undef;
+    return $cleanup_worker;
 }
 
 sub volume_snapshot_rollback {
     my ($class, $scfg, $storeid, $volname, $snap) = @_;
 
-    my $cleanup_worker;
-
-    eval {
-        $class->cluster_lock_storage(
-            $storeid,
-            $scfg->{shared},
-            undef,
-            sub {
-                volume_snapshot_rollback_locked(
-                    $class, $scfg, $storeid, $volname, $snap, \$cleanup_worker,
-                );
-            },
-        );
-    };
-    my $err = $@;
+    my $cleanup_worker = $class->cluster_lock_storage(
+        $storeid,
+        $scfg->{shared},
+        undef,
+        sub { volume_snapshot_rollback_locked($class, $scfg, $storeid, $volname, $snap); },
+    );
 
     # Spawn outside of the locked section, because with 'saferemove', the cleanup worker also needs
     # to obtain the lock, and in CLI context, it will be awaited synchronously, see fork_worker().
     fork_cleanup_worker($cleanup_worker);
 
-    die $err if $err;
-
     return;
 }
 
-- 
2.47.3





                 reply	other threads:[~2026-02-09 10:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260209104009.44272-1-f.ebner@proxmox.com \
    --to=f.ebner@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.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal