From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH qemu-server 03/10] restore: introduce dedicated module
Date: Fri, 27 Nov 2026 14:45:27 +0100 [thread overview]
Message-ID: <20261127134637.140854-4-f.ebner@proxmox.com> (raw)
In-Reply-To: <20261127134637.140854-1-f.ebner@proxmox.com>
Initially, with the helper for allocating and activating the volumes
required for restore.
No functional change intended.
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
src/PVE/QemuServer.pm | 50 +++--------------------------------
src/PVE/QemuServer/Makefile | 1 +
src/PVE/QemuServer/Restore.pm | 48 +++++++++++++++++++++++++++++++++
3 files changed, 53 insertions(+), 46 deletions(-)
create mode 100644 src/PVE/QemuServer/Restore.pm
diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index 9af86902..87869e9d 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -97,6 +97,7 @@ use PVE::QemuServer::QemuImage;
use PVE::QemuServer::QMPHelpers
qw(get_running_qemu_version qemu_deviceadd qemu_devicedel qemu_objectadd qemu_objectdel);
use PVE::QemuServer::QSD;
+use PVE::QemuServer::Restore;
use PVE::QemuServer::RNG qw(parse_rng print_rng_device_commandline print_rng_object_commandline);
use PVE::QemuServer::RunState;
use PVE::QemuServer::StateFile;
@@ -6614,49 +6615,6 @@ my $parse_backup_hints = sub {
return $virtdev_hash;
};
-# Helper to allocate and activate all volumes required for a restore
-#
-# $storecfg: Storage configuration
-# $virtdev_hash: as returned by parse_backup_hints()
-#
-# Returns: { $virtdev => $volid }
-my $restore_allocate_devices = sub {
- my ($storecfg, $virtdev_hash, $vmid) = @_;
-
- my $map = {};
- foreach my $virtdev (sort keys %$virtdev_hash) {
- my $d = $virtdev_hash->{$virtdev};
- die "got no size for '$virtdev'\n" if !defined($d->{size});
- my $alloc_size = int(($d->{size} + 1024 - 1) / 1024);
- my $storeid = $d->{storeid};
- my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
-
- # falls back to default format if requested format is not supported
- $d->{format} = PVE::Storage::resolve_format_hint($storecfg, $storeid, $d->{format});
-
- my $name;
- if ($d->{is_cloudinit}) {
- $name = "vm-$vmid-cloudinit";
- my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
- if ($scfg->{path}) {
- $name .= ".$d->{format}";
- }
- }
-
- my $volid =
- PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $d->{format}, $name, $alloc_size);
-
- print STDERR "new volume ID is '$volid'\n";
- $d->{volid} = $volid;
-
- PVE::Storage::activate_volumes($storecfg, [$volid]);
-
- $map->{$virtdev} = $volid;
- }
-
- return $map;
-};
-
sub restore_update_config_line {
my ($cookie, $map, $line, $unique) = @_;
@@ -7086,7 +7044,7 @@ sub restore_proxmox_backup_archive {
$restore_cleanup_oldconf->($storecfg, $vmid, $oldconf, $virtdev_hash);
# allocate volumes
- my $map = $restore_allocate_devices->($storecfg, $virtdev_hash, $vmid);
+ my $map = PVE::QemuServer::Restore::allocate_volumes($storecfg, $virtdev_hash, $vmid);
foreach my $virtdev (sort keys %$virtdev_hash) {
my $d = $virtdev_hash->{$virtdev};
@@ -7267,7 +7225,7 @@ sub restore_external_archive {
$restore_cleanup_oldconf->($storecfg, $vmid, $oldconf, $virtdev_hash);
# allocate volumes
- my $map = $restore_allocate_devices->($storecfg, $virtdev_hash, $vmid);
+ my $map = PVE::QemuServer::Restore::allocate_volumes($storecfg, $virtdev_hash, $vmid);
for my $virtdev (sort keys $virtdev_hash->%*) {
my $d = $virtdev_hash->{$virtdev};
@@ -7694,7 +7652,7 @@ sub restore_vma_archive {
$restore_cleanup_oldconf->($storecfg, $vmid, $oldconf, $virtdev_hash);
# allocate volumes
- my $map = $restore_allocate_devices->($storecfg, $virtdev_hash, $vmid);
+ my $map = PVE::QemuServer::Restore::allocate_volumes($storecfg, $virtdev_hash, $vmid);
# print restore information to $fifofh
foreach my $virtdev (sort keys %$virtdev_hash) {
diff --git a/src/PVE/QemuServer/Makefile b/src/PVE/QemuServer/Makefile
index 61ed1a4e..62f69f29 100644
--- a/src/PVE/QemuServer/Makefile
+++ b/src/PVE/QemuServer/Makefile
@@ -25,6 +25,7 @@ SOURCES=Agent.pm \
QemuImage.pm \
QMPHelpers.pm \
QSD.pm \
+ Restore.pm \
RNG.pm \
RunState.pm \
Snapshot.pm \
diff --git a/src/PVE/QemuServer/Restore.pm b/src/PVE/QemuServer/Restore.pm
new file mode 100644
index 00000000..134c4766
--- /dev/null
+++ b/src/PVE/QemuServer/Restore.pm
@@ -0,0 +1,48 @@
+package PVE::QemuServer::Restore;
+
+use v5.36;
+
+use PVE::Storage;
+
+# Helper to allocate and activate all volumes required for a restore
+#
+# $storecfg: Storage configuration
+# $virtdev_hash: as returned by parse_backup_hints()
+#
+# Returns: { $virtdev => $volid }
+sub allocate_volumes($storecfg, $virtdev_hash, $vmid) {
+ my $map = {};
+ for my $virtdev (sort keys $virtdev_hash->%*) {
+ my $d = $virtdev_hash->{$virtdev};
+ die "got no size for '$virtdev'\n" if !defined($d->{size});
+ my $alloc_size = int(($d->{size} + 1024 - 1) / 1024);
+ my $storeid = $d->{storeid};
+ my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
+
+ # falls back to default format if requested format is not supported
+ $d->{format} = PVE::Storage::resolve_format_hint($storecfg, $storeid, $d->{format});
+
+ my $name;
+ if ($d->{is_cloudinit}) {
+ $name = "vm-$vmid-cloudinit";
+ my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
+ if ($scfg->{path}) {
+ $name .= ".$d->{format}";
+ }
+ }
+
+ my $volid =
+ PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $d->{format}, $name, $alloc_size);
+
+ print STDERR "new volume ID is '$volid'\n";
+ $d->{volid} = $volid;
+
+ PVE::Storage::activate_volumes($storecfg, [$volid]);
+
+ $map->{$virtdev} = $volid;
+ }
+
+ return $map;
+}
+
+1;
--
2.47.3
next prev 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 ` Fiona Ebner [this message]
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 ` [PATCH qemu-server 06/10] restore: move helpers to deactivate and destroy volumes " Fiona Ebner
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-4-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.