]> git.proxmox.com Git - qemu-server.git/commitdiff
vm_destroy: remove pending volumes as well
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Wed, 29 Sep 2021 09:45:07 +0000 (11:45 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 30 Sep 2021 15:37:27 +0000 (17:37 +0200)
if a volume is only referenced in the pending section of a config it was
previously not removed when removing the VM, 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>
PVE/QemuServer.pm

index 0fb86287285d94f0097208f16e490409ded1b38e..e8047e868efde728f1535311333ba7d549a58410 100644 (file)
@@ -2172,16 +2172,19 @@ sub destroy_vm {
        });
     }
 
+    my $volids = {};
     my $remove_owned_drive = sub {
        my ($ds, $drive) = @_;
        return if drive_is_cdrom($drive, 1);
 
        my $volid = $drive->{file};
        return if !$volid || $volid =~ m|^/|;
+       return if $volids->{$volid};
 
        my ($path, $owner) = PVE::Storage::path($storecfg, $volid);
        return if !$path || !$owner || ($owner != $vmid);
 
+       $volids->{$volid} = 1;
        eval { PVE::Storage::vdisk_free($storecfg, $volid) };
        warn "Could not remove disk '$volid', check manually: $@" if $@;
     };
@@ -2200,6 +2203,8 @@ sub destroy_vm {
        $remove_owned_drive->('vmstate', $drive);
     }
 
+    PVE::QemuConfig->foreach_volume_full($conf->{pending}, $include_opts, $remove_owned_drive);
+
     if ($purge_unreferenced) { # also remove unreferenced disk
        my $vmdisks = PVE::Storage::vdisk_list($storecfg, undef, $vmid, undef, 'images');
        PVE::Storage::foreach_volid($vmdisks, sub {