From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pve-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 303681FF176 for <inbox@lore.proxmox.com>; Fri, 7 Mar 2025 10:26:50 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 6D27016BBB; Fri, 7 Mar 2025 10:26:44 +0100 (CET) From: Markus Frank <m.frank@proxmox.com> To: pve-devel@lists.proxmox.com Date: Fri, 7 Mar 2025 10:25:44 +0100 Message-Id: <20250307092546.102655-3-m.frank@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250307092546.102655-1-m.frank@proxmox.com> References: <20250307092546.102655-1-m.frank@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.008 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [qmrestore.pm, qemuserver.pm, qemu.pm] Subject: [pve-devel] [PATCH qemu-server v3 2/4] fix 4888: qmrestore: add disk-format option X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/> List-Post: <mailto:pve-devel@lists.proxmox.com> List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com> Add an option to choose a file format (qcow2, raw, vmdk) when restoring a vm backup to file based storage. This options allows all disks to be recreated with the specified file format if supported by the target storage. Signed-off-by: Markus Frank <m.frank@proxmox.com> --- v3: * added requires => 'archive' to disk-format * changed descriptions * added missing imports/uses * check if disk_format is in validFormats PVE/API2/Qemu.pm | 7 +++++++ PVE/CLI/qmrestore.pm | 5 +++++ PVE/QemuServer.pm | 14 +++++++++----- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index 5ac61aa5..3f4d19cc 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -1013,6 +1013,11 @@ __PACKAGE__->register_method({ default => 0, description => "Start VM after it was created successfully.", }, + 'disk-format' => get_standard_option('pve-vm-image-format', { + optional => 1, + requires => 'archive', + description => "Preferred image format used for all VM disks when restoring.", + }), 'import-working-storage' => get_standard_option('pve-storage-id', { description => "A file-based storage with 'images' content-type enabled, which" ." is used as an intermediary extraction storage during import. Defaults to" @@ -1046,6 +1051,7 @@ __PACKAGE__->register_method({ my $storage = extract_param($param, 'storage'); my $unique = extract_param($param, 'unique'); my $live_restore = extract_param($param, 'live-restore'); + my $disk_format = extract_param($param, 'disk-format'); my $extraction_storage = extract_param($param, 'import-working-storage'); if (defined(my $ssh_keys = $param->{sshkeys})) { @@ -1143,6 +1149,7 @@ __PACKAGE__->register_method({ unique => $unique, bwlimit => $bwlimit, live => $live_restore, + disk_format => $disk_format, override_conf => $param, }; if (my $volid = $archive->{volid}) { diff --git a/PVE/CLI/qmrestore.pm b/PVE/CLI/qmrestore.pm index a47648bd..9910f30d 100755 --- a/PVE/CLI/qmrestore.pm +++ b/PVE/CLI/qmrestore.pm @@ -3,6 +3,7 @@ package PVE::CLI::qmrestore; use strict; use warnings; use PVE::SafeSyslog; +use PVE::Storage; use PVE::Tools qw(extract_param); use PVE::INotify; use PVE::RPCEnvironment; @@ -64,6 +65,10 @@ __PACKAGE__->register_method({ type => 'boolean', description => "Start the VM immediately from the backup and restore in background. PBS only.", }, + 'disk-format' => get_standard_option('pve-vm-image-format', { + optional => 1, + description => "Preferred image format used for all VM disks when restoring.", + }), }, }, returns => { diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index b6fc1f17..dbc7e6be 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -6677,7 +6677,7 @@ my $parse_backup_hints = sub { # # Returns: { $virtdev => $volid } my $restore_allocate_devices = sub { - my ($storecfg, $virtdev_hash, $vmid) = @_; + my ($storecfg, $virtdev_hash, $vmid, $disk_format) = @_; my $map = {}; foreach my $virtdev (sort keys %$virtdev_hash) { @@ -6689,8 +6689,12 @@ my $restore_allocate_devices = sub { # test if requested format is supported my ($defFormat, $validFormats) = PVE::Storage::storage_default_format($storecfg, $storeid); - my $supported = grep { $_ eq $d->{format} } @$validFormats; - $d->{format} = $defFormat if !$supported; + + if ($disk_format && grep { $_ eq $disk_format } @$validFormats) { + $d->{format} = $disk_format; + } elsif (!(grep { $_ eq $d->{format} } @$validFormats)) { + $d->{format} = $defFormat; + } my $name; if ($d->{is_cloudinit}) { @@ -7064,7 +7068,7 @@ sub restore_proxmox_backup_archive { $restore_cleanup_oldconf->($storecfg, $vmid, $oldconf, $virtdev_hash) if $oldconf; # allocate volumes - my $map = $restore_allocate_devices->($storecfg, $virtdev_hash, $vmid); + my $map = $restore_allocate_devices->($storecfg, $virtdev_hash, $vmid, $options->{disk_format}); foreach my $virtdev (sort keys %$virtdev_hash) { my $d = $virtdev_hash->{$virtdev}; @@ -7461,7 +7465,7 @@ sub restore_vma_archive { } # allocate volumes - my $map = $restore_allocate_devices->($cfg, $virtdev_hash, $vmid); + my $map = $restore_allocate_devices->($cfg, $virtdev_hash, $vmid, $opts->{disk_format}); # print restore information to $fifofh foreach my $virtdev (sort keys %$virtdev_hash) { -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel