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

Michael Köppl m.koeppl at proxmox.com
Thu Jun 26 18:06:22 CEST 2025


This check 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. In case of a storage error (such as the underlying storage no
existing anymore), a warning will be printed and execution continues,
mimicking the handling of storage errors in later stages of
destroy_lxc_container().

Originally-by: Stefan Hrdlicka <s.hrdlicka at proxmox.com>
 [ MK: use classify_mountpoint instead of pattern matching
       display warning for storage errors during linked clone check
       resolve style nit ]
Signed-off-by: Michael Köppl <m.koeppl at proxmox.com>
---
 src/PVE/LXC.pm | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 2bb75dd8..977cf6c8 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -962,6 +962,25 @@ 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) };
+                PVE::RESTEnvironment::log_warn(
+                    "failed to check if volume '$volid' is used by linked clones: $@")
+                    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