public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH qemu-server 1/2] fix #4201: delete cloud-init disk on rollback
@ 2022-09-29 13:36 Mira Limbeck
  2022-09-29 13:36 ` [pve-devel] [PATCH qemu-server 2/2] reuse existing cloud-init disks Mira Limbeck
  2022-09-30  8:21 ` [pve-devel] [PATCH qemu-server 1/2] fix #4201: delete cloud-init disk on rollback Fiona Ebner
  0 siblings, 2 replies; 5+ messages in thread
From: Mira Limbeck @ 2022-09-29 13:36 UTC (permalink / raw)
  To: pve-devel

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 <m.limbeck@proxmox.com>
---
 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





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-09-30  9:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-29 13:36 [pve-devel] [PATCH qemu-server 1/2] fix #4201: delete cloud-init disk on rollback Mira Limbeck
2022-09-29 13:36 ` [pve-devel] [PATCH qemu-server 2/2] reuse existing cloud-init disks Mira Limbeck
2022-09-30  8:21   ` Fiona Ebner
2022-09-30  8:21 ` [pve-devel] [PATCH qemu-server 1/2] fix #4201: delete cloud-init disk on rollback Fiona Ebner
2022-09-30  9:19   ` Mira Limbeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal