From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id BD3FB91B41 for ; Fri, 30 Sep 2022 11:27:05 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A03D21BB05 for ; Fri, 30 Sep 2022 11:26:35 +0200 (CEST) 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 ; Fri, 30 Sep 2022 11:26:34 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id E4843446CC for ; Fri, 30 Sep 2022 11:19:16 +0200 (CEST) Message-ID: <3a783bb7-2120-a980-375a-538ebba88e23@proxmox.com> Date: Fri, 30 Sep 2022 11:19:15 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.0 To: Fiona Ebner , pve-devel@lists.proxmox.com References: <20220929133612.388969-1-m.limbeck@proxmox.com> Content-Language: en-US From: Mira Limbeck In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 2.361 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 -4.099 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] [PATCH qemu-server 1/2] fix #4201: delete cloud-init disk on rollback X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Sep 2022 09:27:05 -0000 On 9/30/22 10:21, Fiona Ebner wrote: > Am 29.09.22 um 15:36 schrieb Mira Limbeck: >> If the config doesn't contain the cloud-init disk anymore after the >> rollback, we have to clean it up since otherwise no further disk can be >> attached unless the one still existing on the storage is deleted. >> >> Signed-off-by: Mira Limbeck >> --- >> PVE/QemuConfig.pm | 34 ++++++++++++++++++++++++++++++++++ >> 1 file changed, 34 insertions(+) >> >> diff --git a/PVE/QemuConfig.pm b/PVE/QemuConfig.pm >> index 482c7ab..4a744cc 100644 >> --- a/PVE/QemuConfig.pm >> +++ b/PVE/QemuConfig.pm >> @@ -419,6 +419,17 @@ sub __snapshot_rollback_hook { >> if ($prepare) { >> # we save the machine of the current config >> $data->{oldmachine} = $conf->{machine}; >> + >> + # keep info about cloudinit disk in the config before the rollback >> + # will be used to later keep or delete possible leftover cloudinit disks >> + # since cloudinit disks are not part of the snapshots >> + $class->foreach_volume($conf, sub { >> + my ($ds, $drive) = @_; >> + >> + return if !PVE::QemuServer::drive_is_cloudinit($drive); >> + >> + $data->{cloudinit} = $drive; >> + }); > You could re-use the has_cloudinit() helper here (not passing any $skip > parameter) ;) Ah yes, I didn't revisit this patch after talking to you about that. Thanks for the suggestion! >> } else { >> # if we have a 'runningmachine' entry in the snapshot we use that >> # for the forcemachine parameter, else we use the old logic >> @@ -446,6 +457,29 @@ sub __snapshot_rollback_hook { >> # re-initializing its random number generator >> $conf->{vmgenid} = PVE::QemuServer::generate_uuid(); >> } >> + >> + # config before rollback contained a cloudinit disk >> + # check if that is still the case after the rollback >> + if ($data->{cloudinit}) { >> + my $found = 0; >> + $class->foreach_volume($conf, sub { >> + my ($ds, $drive) = @_; >> + >> + if (PVE::QemuServer::drive_is_cloudinit($drive)) { >> + $found = 1; >> + last; > We're not in a loop here (at least not a native Perl loop), but in a > 'sub', so 'last' is out of place and results in a warning: > Exiting subroutine via last at /usr/share/perl5/PVE/QemuConfig.pm line 470. > > Could also re-use the helper. Yes, will definitely use the helper. >> + } >> + }); >> + >> + # missing cloudinit disk after rollback >> + # clean up existing cloudinit disk > This is missing the case where the storage of the cloud-init disk > changed. It still needs to be freed then. > > If you wanted, you could also leverage the existing logic for > unreferenced disks upon rollback: > Namely, change __snapshot_rollback_get_unused() to also return the > cloudinit disk (if it is unused), and overwrite the add_unused_volume() > implementation here, freeing any cloud-init disk that comes along and > calling the parent implementation for all other disks. > > Might be a bit more future-proof, but your approach is also fine. I'll take a look at doing it that way. >> + if (!$found) { >> + print "removing unreferenced cloud-init disk $data->{cloudinit}->{file}\n"; >> + >> + my $storecfg = PVE::Storage::config(); >> + PVE::Storage::vdisk_free($storecfg, $data->{cloudinit}->{file}); >> + } >> + } >> } >> >> return;