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 024131FF0B4 for ; Fri, 27 Nov 2026 14:47:39 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 2C8B321830; Fri, 27 Nov 2026 14:46:48 +0100 (CET) From: Fiona Ebner To: pve-devel@lists.proxmox.com Subject: [PATCH qemu-server 09/10] restore: extract common helper for preparing new configuration Date: Fri, 27 Nov 2026 14:45:33 +0100 Message-ID: <20261127134637.140854-10-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: 1795787201056 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.243 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: GVPFJP3MBABVS76TON3OV6KVOWMR67WR X-Message-ID-Hash: GVPFJP3MBABVS76TON3OV6KVOWMR67WR 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: For restore_vma_archive(), the permission check and getting the virtdev hash is now done before restoring the firewall configuration. Note that having $options->{live} is only possible for PBS. Rejected for file-based archives in the create_vm API endpoint and for external archives in restore_external_archive(). Signed-off-by: Fiona Ebner --- src/PVE/QemuServer.pm | 110 +++++++++++++++--------------------------- 1 file changed, 40 insertions(+), 70 deletions(-) diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm index baaa6ef0..9bfb6906 100644 --- a/src/PVE/QemuServer.pm +++ b/src/PVE/QemuServer.pm @@ -6748,6 +6748,39 @@ sub restore_firewall_config { PVE::GuestHelpers::set_firewall_config_raw($vmid, PVE::Tools::file_get_contents($path)); } +my sub restore_prepare_new_config { + my ($rpcenv, $user, $vmid, $cfgfn, $storecfg, $devinfo, $options) = @_; + + my $fh = IO::File->new($cfgfn, "r") or die "unable to read qemu-server.conf - $!\n"; + + my $virtdev_hash = PVE::QemuServer::Restore::parse_backup_hints( + $rpcenv, $user, $storecfg, $fh, $devinfo, $options, + ); + + $fh->seek(0, 0) || die "seek failed - $!\n"; + + my $new_conf_raw = ''; + my $cookie = { netcount => 0 }; + while (defined(my $line = <$fh>)) { + $new_conf_raw .= restore_update_config_line( + $cookie, $virtdev_hash, $line, $options->{unique}, + ); + } + + $fh->close(); + + if ($options->{live}) { + # keep lock during live-restore + $new_conf_raw .= "\nlock: create"; + } + + my $conffile = PVE::QemuConfig->config_file($vmid); + my $new_conf = restore_merge_config($conffile, $new_conf_raw, $options->{override_conf}); + check_restore_permissions($rpcenv, $user, $new_conf); + + return ($new_conf, $virtdev_hash); +} + sub restore_proxmox_backup_archive { my ($archive, $vmid, $user, $options) = @_; @@ -6778,7 +6811,6 @@ sub restore_proxmox_backup_archive { rmtree $tmpdir; mkpath $tmpdir; - my $conffile = PVE::QemuConfig->config_file($vmid); # disable interrupts (always do cleanups) local $SIG{INT} = local $SIG{TERM} = local $SIG{QUIT} = local $SIG{HUP} = sub { print STDERR "got interrupt - ignored\n"; }; @@ -6844,33 +6876,10 @@ sub restore_proxmox_backup_archive { restore_firewall_config($vmid, $firewall_config_fn); } - my $fh = IO::File->new($cfgfn, "r") - || die "unable to read qemu-server.conf - $!\n"; - - $virtdev_hash = PVE::QemuServer::Restore::parse_backup_hints( - $rpcenv, $user, $storecfg, $fh, $devinfo, $options, + ($new_conf, $virtdev_hash) = restore_prepare_new_config( + $rpcenv, $user, $vmid, $cfgfn, $storecfg, $devinfo, $options, ); - $fh->seek(0, 0) || die "seek failed - $!\n"; - - my $new_conf_raw = ''; - my $cookie = { netcount => 0 }; - while (defined(my $line = <$fh>)) { - $new_conf_raw .= restore_update_config_line( - $cookie, $virtdev_hash, $line, $options->{unique}, - ); - } - - $fh->close(); - - if ($options->{live}) { - # keep lock during live-restore - $new_conf_raw .= "\nlock: create"; - } - - $new_conf = restore_merge_config($conffile, $new_conf_raw, $options->{override_conf}); - check_restore_permissions($rpcenv, $user, $new_conf); - # fixme: rate limit? # create empty/temp config @@ -6989,7 +6998,6 @@ sub restore_external_archive { rmtree($tmpdir); mkpath($tmpdir) or die "unable to create $tmpdir\n"; - my $conffile = PVE::QemuConfig->config_file($vmid); # disable interrupts (always do cleanups) local $SIG{INT} = local $SIG{TERM} = local $SIG{QUIT} = local $SIG{HUP} = sub { print STDERR "got interrupt - ignored\n"; }; @@ -7034,27 +7042,10 @@ sub restore_external_archive { restore_firewall_config($vmid, $firewall_config_fn); } - my $fh = IO::File->new($cfgfn, "r") or die "unable to read qemu-server.conf - $!\n"; - - $virtdev_hash = PVE::QemuServer::Restore::parse_backup_hints( - $rpcenv, $user, $storecfg, $fh, $devinfo, $options, + ($new_conf, $virtdev_hash) = restore_prepare_new_config( + $rpcenv, $user, $vmid, $cfgfn, $storecfg, $devinfo, $options, ); - $fh->seek(0, 0) || die "seek failed - $!\n"; - - my $new_conf_raw = ''; - my $cookie = { netcount => 0 }; - while (defined(my $line = <$fh>)) { - $new_conf_raw .= restore_update_config_line( - $cookie, $virtdev_hash, $line, $options->{unique}, - ); - } - - $fh->close(); - - $new_conf = restore_merge_config($conffile, $new_conf_raw, $options->{override_conf}); - check_restore_permissions($rpcenv, $user, $new_conf); - # create empty/temp config PVE::QemuServer::Restore::write_config( $vmid, { memory => 128, lock => 'create' }, $options, @@ -7434,8 +7425,6 @@ sub restore_vma_archive { my $rpcenv = PVE::RPCEnvironment::get(); - my $conffile = PVE::QemuConfig->config_file($vmid); - my $cfs_path = PVE::QemuConfig->cfs_config_path($vmid); my $oldconf = PVE::Cluster::cfs_read_file($cfs_path); my $new_conf; @@ -7452,32 +7441,13 @@ sub restore_vma_archive { $opts->{progress}->{'target-changed'} = 1; PVE::ReplicationState::delete_guest_states($vmid); - # we can read the config - that is already extracted - my $fh = IO::File->new($cfgfn, "r") - || die "unable to read qemu-server.conf - $!\n"; + ($new_conf, $virtdev_hash) = restore_prepare_new_config( + $rpcenv, $user, $vmid, $cfgfn, $storecfg, $devinfo, $opts, + ); my $fwcfgfn = "$tmpdir/qemu-server.fw"; restore_firewall_config($vmid, $fwcfgfn) if -f $fwcfgfn; - $virtdev_hash = PVE::QemuServer::Restore::parse_backup_hints( - $rpcenv, $user, $storecfg, $fh, $devinfo, $opts, - ); - - $fh->seek(0, 0) || die "seek failed - $!\n"; - - my $new_conf_raw = ''; - my $cookie = { netcount => 0 }; - while (defined(my $line = <$fh>)) { - $new_conf_raw .= restore_update_config_line( - $cookie, $virtdev_hash, $line, $opts->{unique}, - ); - } - - $fh->close(); - - $new_conf = restore_merge_config($conffile, $new_conf_raw, $opts->{override_conf}); - check_restore_permissions($rpcenv, $user, $new_conf); - foreach my $info (values %{$virtdev_hash}) { my $storeid = $info->{storeid}; next if defined($storage_limits{$storeid}); -- 2.47.3