[pve-devel] [PATCH V4 pve-container 3/7] add linked clone check for LXC container template deletion

Stefan Hrdlicka s.hrdlicka at proxmox.com
Fri Nov 25 15:40:04 CET 2022


prevent partial storage deletion if the template has a linked clone
container

Signed-off-by: Stefan Hrdlicka <s.hrdlicka 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 fe68f75..7164462 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -865,6 +865,18 @@ sub destroy_lxc_container {
 	$purge_unreferenced, $ignore_storage_errors) = @_;
 
     my $volids = {};
+
+    if ($conf->{template}) {
+	PVE::LXC::Config->foreach_volume_full($conf, {incldue_unused => 1}, sub {
+	    my ($ms, $mountpoint) = @_;
+	    my $volid = $mountpoint->{volume};
+	    return if !$volid || $volid =~ m|^/|;
+	    my $result;
+	    eval{ $result = PVE::Storage::volume_is_base_and_used($storage_cfg, $volid) };
+	    die "base volume '$volid' is still in use by linked cloned\n" if $result;
+	});
+    }
+
     my $remove_volume = sub {
 	my ($ms, $mountpoint) = @_;
 
-- 
2.30.2






More information about the pve-devel mailing list