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.hrdli...@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.koe...@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 4403701..fa762f5 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) }; + 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 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel