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 2DA8491A05 for ; Thu, 29 Sep 2022 15:42:02 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0CD654D99 for ; Thu, 29 Sep 2022 15:41:32 +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)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Thu, 29 Sep 2022 15:41:30 +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 7C0654465D for ; Thu, 29 Sep 2022 15:36:17 +0200 (CEST) From: Mira Limbeck To: pve-devel@lists.proxmox.com Date: Thu, 29 Sep 2022 15:36:11 +0200 Message-Id: <20220929133612.388969-1-m.limbeck@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.198 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 KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods NO_DNS_FOR_FROM 0.001 Envelope sender has no MX or A DNS records SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an 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. [qemuconfig.pm] Subject: [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: Thu, 29 Sep 2022 13:42:02 -0000 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; + }); } 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; + } + }); + + # missing cloudinit disk after rollback + # clean up existing cloudinit disk + 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; -- 2.30.2