[pve-devel] [PATCH V4 pve-container 3/7] add linked clone check for LXC container template deletion
Fiona Ebner
f.ebner at proxmox.com
Tue Dec 13 14:08:26 CET 2022
Am 25.11.22 um 15:40 schrieb Stefan Hrdlicka:
> prevent partial storage deletion if the template has a linked clone
> container
>
Nit: not too important, but you could mention that we already do the
same for VMs
> 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|^/|;
Could/should use
PVE::LXC::Config->classify_mountpoint($volume) ne 'volume';
rather than
$volid =~ m|^/|;
to be more future-proof.
> + my $result;
> + eval{ $result = PVE::Storage::volume_is_base_and_used($storage_cfg, $volid) };
Style nit: my $result = eval { PVE::... }; saves a line
> + die "base volume '$volid' is still in use by linked cloned\n" if $result;
If the check dies, we cannot tell if the volume is actually an in-use
base volume. So we shouldn't just move on with the removal. The error
should be propagated except if $ignore_storage_errors is true.
> + });
> + }
> +
> my $remove_volume = sub {
> my ($ms, $mountpoint) = @_;
>
More information about the pve-devel
mailing list