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 EB6CA1FF15C
	for <inbox@lore.proxmox.com>; Wed,  5 Mar 2025 13:50:05 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id B3FDF162CC;
	Wed,  5 Mar 2025 13:49:59 +0100 (CET)
Message-ID: <08e0af53-bdff-44c1-a5e5-7596cd561173@proxmox.com>
Date: Wed, 5 Mar 2025 13:49:56 +0100
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
 Markus Frank <m.frank@proxmox.com>
References: <20250212130229.249568-1-m.frank@proxmox.com>
 <20250212130229.249568-3-m.frank@proxmox.com>
Content-Language: en-US
From: Fiona Ebner <f.ebner@proxmox.com>
In-Reply-To: <20250212130229.249568-3-m.frank@proxmox.com>
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.043 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
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: Re: [pve-devel] [PATCH qemu-server v2 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>

Am 12.02.25 um 14:02 schrieb Markus Frank:
> 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>
> ---
>  PVE/API2/Qemu.pm     |  6 ++++++
>  PVE/CLI/qmrestore.pm |  4 ++++
>  PVE/QemuServer.pm    | 10 +++++++---
>  3 files changed, 17 insertions(+), 3 deletions(-)
> 
> diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
> index 295260e7..617dbe45 100644
> --- a/PVE/API2/Qemu.pm
> +++ b/PVE/API2/Qemu.pm
> @@ -1013,6 +1013,10 @@ __PACKAGE__->register_method({
>  		    default => 0,
>  		    description => "Start VM after it was created successfully.",
>  		},
> +		'disk-format' => get_standard_option('pve-storage-qm-image-format', {
> +		    optional => 1,

requires => 'archive',

> +		    description => "Image format used for all VM disks when restoring.",

I'd rather say "Preferred image format...", because if the storage
doesn't support it, it won't be used.

> +		}),
>  		'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 +1050,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 +1148,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..68c23db5 100755
> --- a/PVE/CLI/qmrestore.pm
> +++ b/PVE/CLI/qmrestore.pm
> @@ -64,6 +64,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-storage-qm-image-format', {

missing
use PVE::Storage; # for 'pve-storage-qm-image-format' standard option
which registers the option, at the beginning of the module

> +		optional => 1,
> +		description => "Restore all VM disks with the specified image format.",

I'd rather say "Preferred image format...", because if the storage
doesn't support it, it won't be used.

> +	    }),
>  	},
>      },
>      returns => {
> diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
> index 808c0e1c..63836399 100644
> --- a/PVE/QemuServer.pm
> +++ b/PVE/QemuServer.pm
> @@ -6660,7 +6660,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) {
> @@ -6670,6 +6670,10 @@ my $restore_allocate_devices = sub {
>  	my $storeid = $d->{storeid};
>  	my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
>  
> +	if ($disk_format) {
> +	    $d->{format} = $disk_format;

Rather than overriding the format hint, we could consider both:
check if $disk_format is supported, if yes, use that
else, check if $d->{format} is supported, if yes, use that
else, use default format

But arguably quite an edge case, I'm also fine with the behavior in this
patch.

> +	}
> +
>  	# test if requested format is supported
>  	my ($defFormat, $validFormats) = PVE::Storage::storage_default_format($storecfg, $storeid);
>  	my $supported = grep { $_ eq $d->{format} } @$validFormats;


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel