[pve-devel] [PATCH container v5 4/4] add linked clone check when destroying container

Michael Köppl m.koeppl at proxmox.com
Tue May 13 10:03:55 CEST 2025


This behavior matches the behavior already implemented for VMs and
prevents partial storage deletion if a container template has a linked
clone. In such cases, the destruction of the container template will
now fail, informing the user that the base volume is still in use by
the linked clone.

Co-authored-by: Stefan Hrdlicka
Signed-off-by: Michael Köppl <m.koeppl at proxmox.com>
---
 src/PVE/LXC.pm | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 6a1ce92..7bc566a 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -945,6 +945,18 @@ sub destroy_lxc_container {
     my ($storage_cfg, $vmid, $conf, $replacement_conf, $purge_unreferenced) = @_;
 
     my $volids = {};
+
+    if ($conf->{template}) {
+	PVE::LXC::Config->foreach_volume_full($conf, {include_unused => 1}, sub {
+	   my ($ms, $mountpoint) = @_;
+	   my $volid = $mountpoint->{volume};
+	   return if !$volid || PVE::LXC::Config->classify_mountpoint($volid) ne 'volume';
+	   my $result = eval { PVE::Storage::volume_is_base_and_used($storage_cfg, $volid) };
+	   die "failed to delete volume '$volid': $@\n" if $@;
+	   die "base volume '$volid' is still in use by linked clone\n" if $result;
+	});
+    }
+
     my $remove_volume = sub {
 	my ($ms, $mountpoint) = @_;
 
-- 
2.39.5





More information about the pve-devel mailing list