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 qemu-server 06/10] restore: move helpers to deactivate and destroy volumes to module
Date: Fri, 27 Nov 2026 14:45:30 +0100	[thread overview]
Message-ID: <20261127134637.140854-7-f.ebner@proxmox.com> (raw)
In-Reply-To: <20261127134637.140854-1-f.ebner@proxmox.com>

No functional change intended.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 src/PVE/QemuServer.pm         | 44 +++++------------------------------
 src/PVE/QemuServer/Restore.pm | 28 ++++++++++++++++++++++
 2 files changed, 34 insertions(+), 38 deletions(-)

diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index 3194c677..8415bb62 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -6575,38 +6575,6 @@ sub restore_update_config_line {
     return $res;
 }
 
-my $restore_deactivate_volumes = sub {
-    my ($storecfg, $virtdev_hash) = @_;
-
-    my $vollist = [];
-    for my $dev (values $virtdev_hash->%*) {
-        push $vollist->@*, $dev->{volid} if $dev->{volid};
-    }
-
-    eval { PVE::Storage::deactivate_volumes($storecfg, $vollist); };
-    print STDERR $@ if $@;
-};
-
-# Returns the number of volumes that could not be removed.
-my $restore_destroy_volumes = sub {
-    my ($storecfg, $virtdev_hash) = @_;
-
-    my $left = 0;
-    for my $dev (values $virtdev_hash->%*) {
-        my $volid = $dev->{volid} or next;
-        eval {
-            PVE::Storage::vdisk_free($storecfg, $volid);
-            print STDERR "temporary volume '$volid' successfully removed\n";
-        };
-        if (my $err = $@) {
-            print STDERR "unable to cleanup '$volid' - $err";
-            $left++;
-        }
-    }
-
-    return $left;
-};
-
 sub restore_merge_config {
     my ($filename, $backup_conf_raw, $override_conf) = @_;
 
@@ -6985,7 +6953,7 @@ sub restore_proxmox_backup_archive {
     my $err = $@;
 
     if ($err || !$options->{live}) {
-        $restore_deactivate_volumes->($storecfg, $virtdev_hash);
+        PVE::QemuServer::Restore::deactivate_volumes($storecfg, $virtdev_hash);
     }
 
     rmtree $tmpdir;
@@ -6993,7 +6961,7 @@ sub restore_proxmox_backup_archive {
     if ($err) {
         # what could not be removed keeps the VMID taken
         $options->{progress}->{'volumes-left'} = 1
-            if $restore_destroy_volumes->($storecfg, $virtdev_hash);
+            if PVE::QemuServer::Restore::destroy_volumes($storecfg, $virtdev_hash);
         die $err;
     }
     $options->{progress}->{'volumes-kept'} = 1;
@@ -7166,7 +7134,7 @@ sub restore_external_archive {
     warn "backup provider cleanup after restore failed - $@" if $@;
 
     if ($err) {
-        $restore_deactivate_volumes->($storecfg, $virtdev_hash);
+        PVE::QemuServer::Restore::deactivate_volumes($storecfg, $virtdev_hash);
     }
 
     rmtree($tmpdir);
@@ -7174,7 +7142,7 @@ sub restore_external_archive {
     if ($err) {
         # what could not be removed keeps the VMID taken
         $options->{progress}->{'volumes-left'} = 1
-            if $restore_destroy_volumes->($storecfg, $virtdev_hash);
+            if PVE::QemuServer::Restore::destroy_volumes($storecfg, $virtdev_hash);
         die $err;
     }
     $options->{progress}->{'volumes-kept'} = 1;
@@ -7637,7 +7605,7 @@ sub restore_vma_archive {
 
     alarm($oldtimeout) if $oldtimeout;
 
-    $restore_deactivate_volumes->($storecfg, $virtdev_hash);
+    PVE::QemuServer::Restore::deactivate_volumes($storecfg, $virtdev_hash);
 
     close($fifofh) if $fifofh;
     unlink $mapfifo;
@@ -7646,7 +7614,7 @@ sub restore_vma_archive {
     if ($err) {
         # what could not be removed keeps the VMID taken
         $opts->{progress}->{'volumes-left'} = 1
-            if $restore_destroy_volumes->($storecfg, $virtdev_hash);
+            if PVE::QemuServer::Restore::destroy_volumes($storecfg, $virtdev_hash);
         die $err;
     }
     $opts->{progress}->{'volumes-kept'} = 1;
diff --git a/src/PVE/QemuServer/Restore.pm b/src/PVE/QemuServer/Restore.pm
index 80a7ddcd..928fb811 100644
--- a/src/PVE/QemuServer/Restore.pm
+++ b/src/PVE/QemuServer/Restore.pm
@@ -168,4 +168,32 @@ sub parse_backup_hints($rpcenv, $user, $storecfg, $fh, $devinfo, $options) {
     return $virtdev_hash;
 }
 
+sub deactivate_volumes($storecfg, $virtdev_hash) {
+    my $vollist = [];
+    for my $dev (values $virtdev_hash->%*) {
+        push $vollist->@*, $dev->{volid} if $dev->{volid};
+    }
+
+    eval { PVE::Storage::deactivate_volumes($storecfg, $vollist); };
+    print STDERR $@ if $@;
+}
+
+# Returns the number of volumes that could not be removed.
+sub destroy_volumes($storecfg, $virtdev_hash) {
+    my $left = 0;
+    for my $dev (values $virtdev_hash->%*) {
+        my $volid = $dev->{volid} or next;
+        eval {
+            PVE::Storage::vdisk_free($storecfg, $volid);
+            print STDERR "temporary volume '$volid' successfully removed\n";
+        };
+        if (my $err = $@) {
+            print STDERR "unable to cleanup '$volid' - $err";
+            $left++;
+        }
+    }
+
+    return $left;
+}
+
 1;
-- 
2.47.3





  parent reply	other threads:[~2026-11-27 13:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 13:45 [PATCH-SERIES qemu-server 00/10] restore: check permissions up-front Fiona Ebner
2026-11-27 13:45 ` [PATCH qemu-server 01/10] restore: vma: rename variable for storage configuration Fiona Ebner
2026-11-27 13:45 ` [PATCH qemu-server 02/10] restore: skip non-main config sections Fiona Ebner
2026-11-27 13:45 ` [PATCH qemu-server 03/10] restore: introduce dedicated module Fiona Ebner
2026-11-27 13:45 ` [PATCH qemu-server 04/10] restore: move helper for cleaning up target to module Fiona Ebner
2026-11-27 13:45 ` [PATCH qemu-server 05/10] restore: move helper for parsing backup device hints " Fiona Ebner
2026-11-27 13:45 ` Fiona Ebner [this message]
2026-11-27 13:45 ` [PATCH qemu-server 07/10] restore: move helpers to check identity and write config " Fiona Ebner
2026-11-27 13:45 ` [PATCH qemu-server 08/10] restore: check permissions up-front Fiona Ebner
2026-11-27 13:45 ` [PATCH qemu-server 09/10] restore: extract common helper for preparing new configuration Fiona Ebner
2026-11-27 13:45 ` [PATCH qemu-server 10/10] restore: prepare new config before modifying the target Fiona Ebner

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=20261127134637.140854-7-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