From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <f.ebner@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 5C2E7638BF
 for <pve-devel@lists.proxmox.com>; Wed, 26 Jan 2022 12:40:40 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 5331E7437
 for <pve-devel@lists.proxmox.com>; Wed, 26 Jan 2022 12:40:40 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (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 C94BF742C
 for <pve-devel@lists.proxmox.com>; Wed, 26 Jan 2022 12:40:39 +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 9A84C416AA
 for <pve-devel@lists.proxmox.com>; Wed, 26 Jan 2022 12:40:39 +0100 (CET)
Message-ID: <a927af07-2f95-caa1-7ce6-f2b16b17dc11@proxmox.com>
Date: Wed, 26 Jan 2022 12:40:38 +0100
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
 Thunderbird/91.4.1
Content-Language: en-US
To: pve-devel@lists.proxmox.com,
 =?UTF-8?Q?Fabian_Gr=c3=bcnbichler?= <f.gruenbichler@proxmox.com>
References: <20220113100831.34113-1-f.ebner@proxmox.com>
 <20220113100831.34113-8-f.ebner@proxmox.com>
From: Fabian Ebner <f.ebner@proxmox.com>
In-Reply-To: <20220113100831.34113-8-f.ebner@proxmox.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.134 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 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)
 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] [RFC v10 qemu-server 6/7] api: support VM disk
 import
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: Wed, 26 Jan 2022 11:40:40 -0000

Am 13.01.22 um 11:08 schrieb Fabian Ebner:
> +
> +	    if (my $source = delete $disk->{'import-from'}) {

I'm adding a comment here in v11, because otherwise it's not clear where 
volume activation happens:
+               # abs_filesystem_path also calls activate_volume when 
$source is a volid

I'm also adding "The source should not be actively used by another 
process!" to the description of the import-from parameter in v11.

> +		$source = PVE::Storage::abs_filesystem_path($storecfg, $source, 1);

But there are a couple of issues here:

1. There's no protection against using a source volume that's actively 
used by a guest/other operation. While it's not possible to detect in 
general, I wonder if we should behave more like a full clone and lock 
the owning VM?

1a. we could check if the volume is referenced in the config/snapshots, 
but migration picks up everything, so it might be preferable not to.

1b. the volume might be configured in a VM that doesn't own it...

2. Related: avoiding concurrent activation of volumes on a shared LVM.

3. Related: cannot deactivate any volumes as the might be used by 
something else.

4. abs_filesystem_path does not work for RBD when krbd=0, because the 
plugin produces an "rbd:XYZ" path and the -f || -b check doesn't like 
that. But full clone does work, passing the volid to qemu_img_convert 
and that's likely what we should do here as well, when we are dealing 
with an existing volid rather than an absolute path.

5. Add your own ;)

TL;DR: I'd like to behave much more like full clone, when we are dealing 
with a volid rather than an absolute path.

> +		my $src_size = PVE::Storage::file_size_info($source);
> +		die "Could not get file size of $source" if !defined($src_size);
> +
> +		my (undef, $dst_volid) = PVE::QemuServer::ImportDisk::do_import(