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 1983E82F3
 for <pve-devel@lists.proxmox.com>; Tue, 15 Nov 2022 13:17:44 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id E4F5B244F
 for <pve-devel@lists.proxmox.com>; Tue, 15 Nov 2022 13:17:13 +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) server-digest SHA256)
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS
 for <pve-devel@lists.proxmox.com>; Tue, 15 Nov 2022 13:17:10 +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 46C8A43DB1
 for <pve-devel@lists.proxmox.com>; Tue, 15 Nov 2022 13:17:10 +0100 (CET)
Message-ID: <94fa3244-7649-aa49-534b-0f1eebb5fab0@proxmox.com>
Date: Tue, 15 Nov 2022 13:17:09 +0100
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
 Thunderbird/102.3.0
Content-Language: en-US
To: pve-devel@lists.proxmox.com, Stefan Hrdlicka <s.hrdlicka@proxmox.com>
References: <20221115105526.3428334-1-s.hrdlicka@proxmox.com>
 <20221115105526.3428334-5-s.hrdlicka@proxmox.com>
From: Fiona Ebner <f.ebner@proxmox.com>
In-Reply-To: <20221115105526.3428334-5-s.hrdlicka@proxmox.com>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-SPAM-LEVEL: Spam detection results: =?UTF-8?Q?0=0A=09?=AWL 0.028 Adjusted
 score from AWL reputation of From: =?UTF-8?Q?address=0A=09?=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
 =?UTF-8?Q?Alignment=0A=09?=NICE_REPLY_A -0.001 Looks like a legit reply (A)
 SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF
 =?UTF-8?Q?Record=0A=09?=SPF_PASS -0.001 SPF: sender matches SPF record
Subject: Re: [pve-devel] [PATCH V3 qemu-server 4/6] add
 ignore-storage-errors for removing VM with missing storage
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 Nov 2022 12:17:44 -0000

Am 15.11.22 um 11:55 schrieb Stefan Hrdlicka:
> @@ -2341,10 +2346,10 @@ sub destroy_vm {
>  
>  		my $volid = $drive->{file};
>  		return if !$volid || $volid =~ m|^/|;
> -
> -		die "base volume '$volid' is still in use by linked cloned\n"
> -		    if PVE::Storage::volume_is_base_and_used($storecfg, $volid);
> -
> +		my $result;
> +		eval { $result = PVE::Storage::volume_is_base_and_used($storecfg, $volid) };
> +		die "Couldn't remove one or more disks: $@\n" if $@ && !$ignore_storage_errors;

This error message is wrong. The check failed, not the removal. The
check should be repeated in vdisk_free anyways and you should get the
appropriate error then below :)

AFAIU base volumes should still survive if they are still referenced by
linked clones, even when ignore-storage-errors is used (IMHO good). Is
that correct?

Nothing new and not directly related:
I noticed that for containers, we don't have this heads-up check. Maybe
worth adding there too? Arguably minor issue is that I can have a
container template with a disk on lvm-thin and a second disk on
non-lvm-thin. Even if there is a linked clone, removing the template
might remove the lvm-thin disk, and then fail, because the second disk
is referenced.

> +		die "base volume '$volid' is still in use by linked cloned\n" if $result;
>  	});
>      }
>  
> @@ -2370,7 +2375,8 @@ sub destroy_vm {
>  	include_unused => 1,
>  	extra_keys => ['vmstate'],
>      };
> -    PVE::QemuConfig->foreach_volume_full($conf, $include_opts, $remove_owned_drive);
> +    eval { PVE::QemuConfig->foreach_volume_full($conf, $include_opts, $remove_owned_drive); };
> +    die "Couldn't remove one or more disks: $@\n" if $@ && !$ignore_storage_errors;

So, $removed_owned_drive already ignores all storage errors beside if
PVE::Storage::path() fails right? Can't we just add an eval around that
and be done? No need for a new ignore-storage-errors parameter. Most
storage errors are already ignored even without that parameter right
now! I don't think it's a big issue to start ignoring the few missing
ones as well?

>  
>      for my $snap (values %{$conf->{snapshots}}) {
>  	next if !defined($snap->{vmstate});