5
0
mirror of git://git.proxmox.com/git/qemu-server.git synced 2025-01-24 02:04:10 +03:00

destroy_vm: refactor+cleanup and continue on unused disk removal errors

it has some potential semantic change too, i.e., the Storage
vdisk_list call is not wrapped by eval anymore, put as
we did some (unguarded) storage things before that call I'd say that
that does not matters much..

We try to clean all unused disks too, even if one deletion fails

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2019-11-08 15:35:32 +01:00
parent 4b0269379b
commit a2f50f0172

View File

@ -2560,11 +2560,9 @@ sub destroy_vm {
# check if any base image is still used by a linked clone
foreach_drive($conf, sub {
my ($ds, $drive) = @_;
return if drive_is_cdrom($drive);
my $volid = $drive->{file};
return if !$volid || $volid =~ m|^/|;
die "base volume '$volid' is still in use by linked cloned\n"
@ -2576,37 +2574,25 @@ sub destroy_vm {
# only remove disks owned by this VM
foreach_drive($conf, sub {
my ($ds, $drive) = @_;
return if drive_is_cdrom($drive, 1);
my $volid = $drive->{file};
return if !$volid || $volid =~ m|^/|;
my ($path, $owner) = PVE::Storage::path($storecfg, $volid);
return if !$path || !$owner || ($owner != $vmid);
eval {
PVE::Storage::vdisk_free($storecfg, $volid);
};
eval { PVE::Storage::vdisk_free($storecfg, $volid) };
warn "Could not remove disk '$volid', check manually: $@" if $@;
});
# also remove unused disk
eval {
my $dl = PVE::Storage::vdisk_list($storecfg, undef, $vmid);
eval {
PVE::Storage::foreach_volid($dl, sub {
my ($volid, $sid, $volname, $d) = @_;
PVE::Storage::vdisk_free($storecfg, $volid);
});
};
my $vmdisks = PVE::Storage::vdisk_list($storecfg, undef, $vmid);
PVE::Storage::foreach_volid($vmdisks, sub {
my ($volid, $sid, $volname, $d) = @_;
eval { PVE::Storage::vdisk_free($storecfg, $volid) };
warn $@ if $@;
};
warn $@ if $@;
});
if ($keep_empty_config) {
PVE::QemuConfig->write_config($vmid, { memory => 128 });