public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Mira Limbeck <m.limbeck@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH v2 qemu-server] fix #4201: delete cloud-init disk on rollback
Date: Thu, 20 Oct 2022 17:22:36 +0200	[thread overview]
Message-ID: <20221020152236.371434-1-m.limbeck@proxmox.com> (raw)

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>
---
v2:
 - chose the add_unused_volume way as @fiona recommended, the
   implementation is a lot cleaner, but contains a cloudinit regex

 - removed the 2nd patch for reusing already existing disks when
   adding a cloudinit disk

 PVE/QemuConfig.pm | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/PVE/QemuConfig.pm b/PVE/QemuConfig.pm
index 482c7ab..9fb8e9f 100644
--- a/PVE/QemuConfig.pm
+++ b/PVE/QemuConfig.pm
@@ -498,7 +498,7 @@ sub __snapshot_rollback_get_unused {
     $class->foreach_volume($conf, sub {
 	my ($vs, $volume) = @_;
 
-	return if PVE::QemuServer::drive_is_cdrom($volume);
+	return if PVE::QemuServer::drive_is_cdrom($volume, 1);
 
 	my $found = 0;
 	my $volid = $volume->{file};
@@ -507,7 +507,7 @@ sub __snapshot_rollback_get_unused {
 	    my ($ds, $drive) = @_;
 
 	    return if $found;
-	    return if PVE::QemuServer::drive_is_cdrom($drive);
+	    return if PVE::QemuServer::drive_is_cdrom($drive, 1);
 
 	    $found = 1
 		if ($drive->{file} && $drive->{file} eq $volid);
@@ -519,6 +519,19 @@ sub __snapshot_rollback_get_unused {
     return $unused;
 }
 
+sub add_unused_volume {
+    my ($class, $config, $volid) = @_;
+
+    if ($volid =~ m/vm-\d+-cloudinit/) {
+	print "found unused cloudinit disk '$volid', removing it\n";
+	my $storecfg = PVE::Storage::config();
+	PVE::Storage::vdisk_free($storecfg, $volid);
+	return undef;
+    } else {
+        return $class->SUPER::add_unused_volume($config, $volid);
+    }
+}
+
 # END implemented abstract methods from PVE::AbstractConfig
 
 sub has_cloudinit {
-- 
2.30.2





             reply	other threads:[~2022-10-20 15:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-20 15:22 Mira Limbeck [this message]
2022-11-11 15:18 ` Stefan Hanreich
2022-11-11 15:24   ` Mira Limbeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221020152236.371434-1-m.limbeck@proxmox.com \
    --to=m.limbeck@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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