public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH container] destroy: remove pending volumes as well
@ 2021-09-29  9:45 Fabian Grünbichler
  2021-09-29  9:45 ` [pve-devel] [PATCH qemu-server] vm_destroy: " Fabian Grünbichler
  2021-09-30 15:40 ` [pve-devel] applied: [PATCH container] destroy: " Thomas Lamprecht
  0 siblings, 2 replies; 4+ messages in thread
From: Fabian Grünbichler @ 2021-09-29  9:45 UTC (permalink / raw)
  To: pve-devel

if a volume is only referenced in the pending section of a config it was
previously not removed when removing the CT, unless the non-default
'remove unreferenced disks' option was enabled.

keeping track of volume IDs which we attempt to remove gets rid of false
warnings in case a volume is referenced both in the config and the
pending section, or multiple times in the config for other reasons.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
 src/PVE/LXC.pm | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index dbdec23..b07d986 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -864,10 +864,20 @@ sub delete_mountpoint_volume {
 sub destroy_lxc_container {
     my ($storage_cfg, $vmid, $conf, $replacement_conf, $purge_unreferenced) = @_;
 
-    PVE::LXC::Config->foreach_volume_full($conf, {include_unused => 1}, sub {
+    my $volids = {};
+    my $remove_volume = sub {
 	my ($ms, $mountpoint) = @_;
-	delete_mountpoint_volume($storage_cfg, $vmid, $mountpoint->{volume});
-    });
+
+	my $volume = $mountpoint->{volume};
+
+	return if $volids->{$volume};
+	$volids->{$volume} = 1;
+
+	delete_mountpoint_volume($storage_cfg, $vmid, $volume);
+    };
+    PVE::LXC::Config->foreach_volume_full($conf, {include_unused => 1}, $remove_volume);
+
+    PVE::LXC::Config->foreach_volume_full($conf->{pending}, {include_unused => 1}, $remove_volume);
 
     if ($purge_unreferenced) { # also remove unreferenced disk
 	my $vmdisks = PVE::Storage::vdisk_list($storage_cfg, undef, $vmid, undef, 'rootdir');
-- 
2.30.2





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

* [pve-devel] [PATCH qemu-server] vm_destroy: remove pending volumes as well
  2021-09-29  9:45 [pve-devel] [PATCH container] destroy: remove pending volumes as well Fabian Grünbichler
@ 2021-09-29  9:45 ` Fabian Grünbichler
  2021-09-30 15:40   ` [pve-devel] applied: " Thomas Lamprecht
  2021-09-30 15:40 ` [pve-devel] applied: [PATCH container] destroy: " Thomas Lamprecht
  1 sibling, 1 reply; 4+ messages in thread
From: Fabian Grünbichler @ 2021-09-29  9:45 UTC (permalink / raw)
  To: pve-devel

if a volume is only referenced in the pending section of a config it was
previously not removed when removing the VM, unless the non-default
'remove unreferenced disks' option was enabled.

keeping track of volume IDs which we attempt to remove gets rid of false
warnings in case a volume is referenced both in the config and the
pending section, or multiple times in the config for other reasons.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
 PVE/QemuServer.pm | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 0fb8628..e8047e8 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -2172,16 +2172,19 @@ sub destroy_vm {
 	});
     }
 
+    my $volids = {};
     my $remove_owned_drive = sub {
 	my ($ds, $drive) = @_;
  	return if drive_is_cdrom($drive, 1);
 
 	my $volid = $drive->{file};
 	return if !$volid || $volid =~ m|^/|;
+	return if $volids->{$volid};
 
 	my ($path, $owner) = PVE::Storage::path($storecfg, $volid);
 	return if !$path || !$owner || ($owner != $vmid);
 
+	$volids->{$volid} = 1;
 	eval { PVE::Storage::vdisk_free($storecfg, $volid) };
 	warn "Could not remove disk '$volid', check manually: $@" if $@;
     };
@@ -2200,6 +2203,8 @@ sub destroy_vm {
 	$remove_owned_drive->('vmstate', $drive);
     }
 
+    PVE::QemuConfig->foreach_volume_full($conf->{pending}, $include_opts, $remove_owned_drive);
+
     if ($purge_unreferenced) { # also remove unreferenced disk
 	my $vmdisks = PVE::Storage::vdisk_list($storecfg, undef, $vmid, undef, 'images');
 	PVE::Storage::foreach_volid($vmdisks, sub {
-- 
2.30.2





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

* [pve-devel] applied: [PATCH container] destroy: remove pending volumes as well
  2021-09-29  9:45 [pve-devel] [PATCH container] destroy: remove pending volumes as well Fabian Grünbichler
  2021-09-29  9:45 ` [pve-devel] [PATCH qemu-server] vm_destroy: " Fabian Grünbichler
@ 2021-09-30 15:40 ` Thomas Lamprecht
  1 sibling, 0 replies; 4+ messages in thread
From: Thomas Lamprecht @ 2021-09-30 15:40 UTC (permalink / raw)
  To: Proxmox VE development discussion, Fabian Grünbichler

On 29.09.21 11:45, Fabian Grünbichler wrote:
> if a volume is only referenced in the pending section of a config it was
> previously not removed when removing the CT, unless the non-default
> 'remove unreferenced disks' option was enabled.
> 
> keeping track of volume IDs which we attempt to remove gets rid of false
> warnings in case a volume is referenced both in the config and the
> pending section, or multiple times in the config for other reasons.
> 
> Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
> ---
>  src/PVE/LXC.pm | 16 +++++++++++++---
>  1 file changed, 13 insertions(+), 3 deletions(-)
> 
>

applied, thanks!




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

* [pve-devel] applied: [PATCH qemu-server] vm_destroy: remove pending volumes as well
  2021-09-29  9:45 ` [pve-devel] [PATCH qemu-server] vm_destroy: " Fabian Grünbichler
@ 2021-09-30 15:40   ` Thomas Lamprecht
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Lamprecht @ 2021-09-30 15:40 UTC (permalink / raw)
  To: Proxmox VE development discussion, Fabian Grünbichler

On 29.09.21 11:45, Fabian Grünbichler wrote:
> if a volume is only referenced in the pending section of a config it was
> previously not removed when removing the VM, unless the non-default
> 'remove unreferenced disks' option was enabled.
> 
> keeping track of volume IDs which we attempt to remove gets rid of false
> warnings in case a volume is referenced both in the config and the
> pending section, or multiple times in the config for other reasons.
> 
> Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
> ---
>  PVE/QemuServer.pm | 5 +++++
>  1 file changed, 5 insertions(+)
> 
>

applied, thanks!




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

end of thread, other threads:[~2021-09-30 15:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-29  9:45 [pve-devel] [PATCH container] destroy: remove pending volumes as well Fabian Grünbichler
2021-09-29  9:45 ` [pve-devel] [PATCH qemu-server] vm_destroy: " Fabian Grünbichler
2021-09-30 15:40   ` [pve-devel] applied: " Thomas Lamprecht
2021-09-30 15:40 ` [pve-devel] applied: [PATCH container] destroy: " Thomas Lamprecht

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