From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <m.limbeck@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id A763B60DBD
 for <pve-devel@lists.proxmox.com>; Tue, 15 Dec 2020 15:44:34 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 971F413F67
 for <pve-devel@lists.proxmox.com>; Tue, 15 Dec 2020 15:44:34 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [212.186.127.180])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 71BFF13F58
 for <pve-devel@lists.proxmox.com>; Tue, 15 Dec 2020 15:44:33 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 360E44517F
 for <pve-devel@lists.proxmox.com>; Tue, 15 Dec 2020 15:44:33 +0100 (CET)
To: Thomas Lamprecht <t.lamprecht@proxmox.com>,
 Proxmox VE development discussion <pve-devel@lists.proxmox.com>
References: <20201202125025.27401-1-m.limbeck@proxmox.com>
 <a54eeb72-dada-3cab-a2a8-4c25da6bbfe6@proxmox.com>
From: Mira Limbeck <m.limbeck@proxmox.com>
Message-ID: <053f1991-d220-f6c0-15cc-1d23c2956857@proxmox.com>
Date: Tue, 15 Dec 2020 15:44:32 +0100
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
 Thunderbird/78.5.1
MIME-Version: 1.0
In-Reply-To: <a54eeb72-dada-3cab-a2a8-4c25da6bbfe6@proxmox.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Content-Language: en-US
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.463 Adjusted score from AWL reputation of From: address
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 NICE_REPLY_A           -0.001 Looks like a legit reply (A)
 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
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [qemuserver.pm]
Subject: Re: [pve-devel] [PATCH v2 qemu-server] fix cloning/restoring of
 cloudinit disks in raw format
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>
X-List-Received-Date: Tue, 15 Dec 2020 14:44:34 -0000

On 12/15/20 2:57 PM, Thomas Lamprecht wrote:
> On 02.12.20 13:50, Mira Limbeck wrote:
>> We only added the format extension when it was not 'raw'. But on file level
>> storages we always require it. To fix this, always add the format
>> extension if the storage provides the 'path' property.
>> This is the same logic we use in create_disks for cloudinit disks.
>>
>> Signed-off-by: Mira Limbeck <m.limbeck@proxmox.com>
>> ---
>> v2:
>>   - added the same fix when restoring from backup
>>
> clone seems to be fine, even if I slowly start to feel real hatred for those
> cloudinit disk edge cases, anyway, is there an actual reason why we need to
> restore that disk - isn't in gonna get regenerated on first start anyway?
We don't actually restore the disk, but we have to allocate it to 
account for a possibly new VMID as well as a different storage (e.g. 
directory storage with the VMID as part of the path).
>
>>   PVE/QemuServer.pm | 10 ++++++++--
>>   1 file changed, 8 insertions(+), 2 deletions(-)
>>
>> diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
>> index 4989938..412113e 100644
>> --- a/PVE/QemuServer.pm
>> +++ b/PVE/QemuServer.pm
>> @@ -5797,7 +5797,10 @@ my $restore_allocate_devices = sub {
>>   	my $name;
>>   	if ($d->{is_cloudinit}) {
>>   	    $name = "vm-$vmid-cloudinit";
>> -	    $name .= ".$d->{format}" if $d->{format} ne 'raw';
>> +	    my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
>> +	    if ($scfg->{path}) {
>> +		$name .= ".$d->{format}";
>> +	    }
>>   	}
>>   
>>   	my $volid = PVE::Storage::vdisk_alloc(
>> @@ -6945,7 +6948,10 @@ sub clone_disk {
>>   	my $size = undef;
>>   	if (drive_is_cloudinit($drive)) {
>>   	    $name = "vm-$newvmid-cloudinit";
>> -	    $name .= ".$dst_format" if $dst_format ne 'raw';
>> +	    my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
>> +	    if ($scfg->{path}) {
>> +		$name .= ".$dst_format";
>> +	    }
>>   	    $snapname = undef;
>>   	    $size = PVE::QemuServer::Cloudinit::CLOUDINIT_DISK_SIZE;
>>   	} elsif ($drivename eq 'efidisk0') {
>>
>