From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 33E201FF0B4 for ; Fri, 27 Nov 2026 14:47:47 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id AD2962184B; Fri, 27 Nov 2026 14:46:48 +0100 (CET) From: Fiona Ebner 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 Message-ID: <20261127134637.140854-6-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261127134637.140854-1-f.ebner@proxmox.com> References: <20261127134637.140854-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795787200816 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.242 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: SUZCTSC6N3ZAY3BDKF6BAF2QBCGYTMC6 X-Message-ID-Hash: SUZCTSC6N3ZAY3BDKF6BAF2QBCGYTMC6 X-MailFrom: f.ebner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: No functional change intended. Signed-off-by: Fiona Ebner --- 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