From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH qemu-server 05/10] restore: move helper for parsing backup device hints to module
Date: Fri, 27 Nov 2026 14:45:29 +0100 [thread overview]
Message-ID: <20261127134637.140854-6-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 | 88 ++++-------------------------------
src/PVE/QemuServer/Restore.pm | 77 +++++++++++++++++++++++++++++-
2 files changed, 85 insertions(+), 80 deletions(-)
diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index da7e7d36..3194c677 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -6494,80 +6494,6 @@ sub restore_file_archive {
}
}
-# Helper to parse vzdump backup device hints
-#
-# $rpcenv: Environment, used to ckeck storage permissions
-# $user: User ID, to check storage permissions
-# $storecfg: Storage configuration
-# $fh: the file handle for reading the configuration
-# $devinfo: should contain device sizes for all backu-up'ed devices
-# $options: backup options (pool, default storage)
-#
-# Return: $virtdev_hash, updates $devinfo (add devname, virtdev, format, storeid)
-my $parse_backup_hints = sub {
- my ($rpcenv, $user, $storecfg, $fh, $devinfo, $options) = @_;
-
- my $check_storage = sub { # assert if an image can be allocate
- my ($storeid, $scfg) = @_;
- die "Content type 'images' is not available on storage '$storeid'\n"
- if !PVE::Storage::Common::content_allows($scfg->{content}, 'vm-vol');
- $rpcenv->check($user, "/storage/$storeid", ['Datastore.AllocateSpace'])
- if $user ne 'root@pam';
- };
-
- my $virtdev_hash = {};
- my $main_section_finished;
- while (defined(my $line = <$fh>)) {
- if ($line =~ m/^\#qmdump\#map:(\S+):(\S+):(\S*):(\S*):$/) {
- my ($virtdev, $devname, $storeid, $format) = ($1, $2, $3, $4);
- die "archive does not contain data for drive '$virtdev'\n"
- if !$devinfo->{$devname};
-
- if (defined($options->{storage})) {
- $storeid = $options->{storage} || 'local';
- } elsif (!$storeid) {
- $storeid = 'local';
- }
- $format = 'raw' if !$format;
- $devinfo->{$devname}->{devname} = $devname;
- $devinfo->{$devname}->{virtdev} = $virtdev;
- $devinfo->{$devname}->{format} = $format;
- $devinfo->{$devname}->{storeid} = $storeid;
-
- my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
- $check_storage->($storeid, $scfg); # permission and content type check
-
- $virtdev_hash->{$virtdev} = $devinfo->{$devname};
- } elsif ($main_section_finished) {
- next;
- } elsif ($line =~ m/^\[([^\]]*)\]\s*$/) {
- warn "detected backup configuration with unexpected $1 section - skipping it\n";
- $main_section_finished = 1;
- } elsif ($line =~ m/^((?:ide|sata|scsi)\d+):\s*(.*)\s*$/) {
- my $virtdev = $1;
- my $drive = parse_drive($virtdev, $2);
-
- if (drive_is_cloudinit($drive)) {
- my ($storeid, $volname) = PVE::Storage::parse_volume_id($drive->{file});
- $storeid = $options->{storage} if defined($options->{storage});
- my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
- my $format = eval { checked_volume_format($storecfg, $drive->{file}) } // 'raw';
-
- $check_storage->($storeid, $scfg); # permission and content type check
-
- $virtdev_hash->{$virtdev} = {
- format => $format,
- storeid => $storeid,
- size => PVE::QemuServer::Cloudinit::CLOUDINIT_DISK_SIZE,
- is_cloudinit => 1,
- };
- }
- }
- }
-
- return $virtdev_hash;
-};
-
sub restore_update_config_line {
my ($cookie, $map, $line, $unique) = @_;
@@ -6986,8 +6912,9 @@ sub restore_proxmox_backup_archive {
my $fh = IO::File->new($cfgfn, "r")
|| die "unable to read qemu-server.conf - $!\n";
- $virtdev_hash =
- $parse_backup_hints->($rpcenv, $user, $storecfg, $fh, $devinfo, $options);
+ $virtdev_hash = PVE::QemuServer::Restore::parse_backup_hints(
+ $rpcenv, $user, $storecfg, $fh, $devinfo, $options,
+ );
# fixme: rate limit?
@@ -7170,8 +7097,9 @@ sub restore_external_archive {
my $fh = IO::File->new($cfgfn, "r") or die "unable to read qemu-server.conf - $!\n";
- $virtdev_hash =
- $parse_backup_hints->($rpcenv, $user, $storecfg, $fh, $devinfo, $options);
+ $virtdev_hash = PVE::QemuServer::Restore::parse_backup_hints(
+ $rpcenv, $user, $storecfg, $fh, $devinfo, $options,
+ );
# create empty/temp config
restore_write_config($vmid, { memory => 128, lock => 'create' }, $options);
@@ -7586,7 +7514,9 @@ sub restore_vma_archive {
my $fwcfgfn = "$tmpdir/qemu-server.fw";
restore_firewall_config($vmid, $fwcfgfn) if -f $fwcfgfn;
- $virtdev_hash = $parse_backup_hints->($rpcenv, $user, $storecfg, $fh, $devinfo, $opts);
+ $virtdev_hash = PVE::QemuServer::Restore::parse_backup_hints(
+ $rpcenv, $user, $storecfg, $fh, $devinfo, $opts,
+ );
foreach my $info (values %{$virtdev_hash}) {
my $storeid = $info->{storeid};
diff --git a/src/PVE/QemuServer/Restore.pm b/src/PVE/QemuServer/Restore.pm
index a98d8d3b..80a7ddcd 100644
--- a/src/PVE/QemuServer/Restore.pm
+++ b/src/PVE/QemuServer/Restore.pm
@@ -3,9 +3,12 @@ package PVE::QemuServer::Restore;
use v5.36;
use PVE::Storage;
+use PVE::Storage::Common;
use PVE::QemuConfig;
-use PVE::QemuServer::Drive qw(drive_has_absolute_path drive_is_cdrom);
+use PVE::QemuServer::Cloudinit;
+use PVE::QemuServer::Drive
+ qw(checked_volume_format drive_has_absolute_path drive_is_cdrom drive_is_cloudinit parse_drive);
# Helper to allocate and activate all volumes required for a restore
#
@@ -93,4 +96,76 @@ sub cleanup_old_volumes($storecfg, $vmid, $oldconf, $virtdev_hash) {
}
}
+# Helper to parse vzdump backup device hints
+#
+# $rpcenv: Environment, used to ckeck storage permissions
+# $user: User ID, to check storage permissions
+# $storecfg: Storage configuration
+# $fh: the file handle for reading the configuration
+# $devinfo: should contain device sizes for all backu-up'ed devices
+# $options: backup options (pool, default storage)
+#
+# Return: $virtdev_hash, updates $devinfo (add devname, virtdev, format, storeid)
+sub parse_backup_hints($rpcenv, $user, $storecfg, $fh, $devinfo, $options) {
+ my $check_storage = sub { # assert if an image can be allocate
+ my ($storeid, $scfg) = @_;
+ die "Content type 'images' is not available on storage '$storeid'\n"
+ if !PVE::Storage::Common::content_allows($scfg->{content}, 'vm-vol');
+ $rpcenv->check($user, "/storage/$storeid", ['Datastore.AllocateSpace'])
+ if $user ne 'root@pam';
+ };
+
+ my $virtdev_hash = {};
+ my $main_section_finished;
+ while (defined(my $line = <$fh>)) {
+ if ($line =~ m/^\#qmdump\#map:(\S+):(\S+):(\S*):(\S*):$/) {
+ my ($virtdev, $devname, $storeid, $format) = ($1, $2, $3, $4);
+ die "archive does not contain data for drive '$virtdev'\n"
+ if !$devinfo->{$devname};
+
+ if (defined($options->{storage})) {
+ $storeid = $options->{storage} || 'local';
+ } elsif (!$storeid) {
+ $storeid = 'local';
+ }
+ $format = 'raw' if !$format;
+ $devinfo->{$devname}->{devname} = $devname;
+ $devinfo->{$devname}->{virtdev} = $virtdev;
+ $devinfo->{$devname}->{format} = $format;
+ $devinfo->{$devname}->{storeid} = $storeid;
+
+ my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
+ $check_storage->($storeid, $scfg); # permission and content type check
+
+ $virtdev_hash->{$virtdev} = $devinfo->{$devname};
+ } elsif ($main_section_finished) {
+ next;
+ } elsif ($line =~ m/^\[([^\]]*)\]\s*$/) {
+ warn "detected backup configuration with unexpected $1 section - skipping it\n";
+ $main_section_finished = 1;
+ } elsif ($line =~ m/^((?:ide|sata|scsi)\d+):\s*(.*)\s*$/) {
+ my $virtdev = $1;
+ my $drive = parse_drive($virtdev, $2);
+
+ if (drive_is_cloudinit($drive)) {
+ my ($storeid, $volname) = PVE::Storage::parse_volume_id($drive->{file});
+ $storeid = $options->{storage} if defined($options->{storage});
+ my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
+ my $format = eval { checked_volume_format($storecfg, $drive->{file}) } // 'raw';
+
+ $check_storage->($storeid, $scfg); # permission and content type check
+
+ $virtdev_hash->{$virtdev} = {
+ format => $format,
+ storeid => $storeid,
+ size => PVE::QemuServer::Cloudinit::CLOUDINIT_DISK_SIZE,
+ is_cloudinit => 1,
+ };
+ }
+ }
+ }
+
+ return $virtdev_hash;
+}
+
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 ` [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 ` Fiona Ebner [this message]
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-6-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox