]> git.proxmox.com Git - pve-container.git/commitdiff
destroy: remove pending volumes as well
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Wed, 29 Sep 2021 09:45:06 +0000 (11:45 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 30 Sep 2021 15:36:38 +0000 (17:36 +0200)
if a volume is only referenced in the pending section of a config it was
previously not removed when removing the CT, unless the non-default
'remove unreferenced disks' option was enabled.

keeping track of volume IDs which we attempt to remove gets rid of false
warnings in case a volume is referenced both in the config and the
pending section, or multiple times in the config for other reasons.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
src/PVE/LXC.pm

index dbdec2389b3d1ffd86e634e2c7b9eadef2d74139..b07d986087fa4037b2a2fa960bbde0a51c8c55ed 100644 (file)
@@ -864,10 +864,20 @@ sub delete_mountpoint_volume {
 sub destroy_lxc_container {
     my ($storage_cfg, $vmid, $conf, $replacement_conf, $purge_unreferenced) = @_;
 
-    PVE::LXC::Config->foreach_volume_full($conf, {include_unused => 1}, sub {
+    my $volids = {};
+    my $remove_volume = sub {
        my ($ms, $mountpoint) = @_;
-       delete_mountpoint_volume($storage_cfg, $vmid, $mountpoint->{volume});
-    });
+
+       my $volume = $mountpoint->{volume};
+
+       return if $volids->{$volume};
+       $volids->{$volume} = 1;
+
+       delete_mountpoint_volume($storage_cfg, $vmid, $volume);
+    };
+    PVE::LXC::Config->foreach_volume_full($conf, {include_unused => 1}, $remove_volume);
+
+    PVE::LXC::Config->foreach_volume_full($conf->{pending}, {include_unused => 1}, $remove_volume);
 
     if ($purge_unreferenced) { # also remove unreferenced disk
        my $vmdisks = PVE::Storage::vdisk_list($storage_cfg, undef, $vmid, undef, 'rootdir');