From b04ea5845346a8b13711abc03b58d86f2d6afb5f Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Fri, 8 Nov 2019 17:03:28 +0100 Subject: [PATCH] destroy_vm: allow to pass new config and lock instead This brings qemu more in line with containers, and it's nicer to allow passing the replacement config if we want to keep it, instead of setting a "memory: 128" config. Use that to lock it on removal before final deletion, and on legacy tar archive restore, in between old VM destruction and new restoration. Signed-off-by: Thomas Lamprecht --- PVE/API2/Qemu.pm | 2 +- PVE/CLI/qm.pm | 2 +- PVE/QemuServer.pm | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index da00676d..eef149b8 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -1448,7 +1448,7 @@ __PACKAGE__->register_method({ die "VM $vmid is running - destroy failed\n" if (PVE::QemuServer::check_running($vmid)); - PVE::QemuServer::destroy_vm($storecfg, $vmid, 1, $skiplock); + PVE::QemuServer::destroy_vm($storecfg, $vmid, $skiplock, { lock => 'destroyed' }); PVE::AccessControl::remove_vm_access($vmid); PVE::Firewall::remove_vmfw_conf($vmid); diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm index 59a38611..13615815 100755 --- a/PVE/CLI/qm.pm +++ b/PVE/CLI/qm.pm @@ -659,7 +659,7 @@ __PACKAGE__->register_method ({ if ($err) { my $skiplock = 1; # eval for additional safety in error path - eval { PVE::QemuServer::destroy_vm($storecfg, $vmid, undef, $skiplock) }; + eval { PVE::QemuServer::destroy_vm($storecfg, $vmid, $skiplock) }; warn "Could not destroy VM $vmid: $@" if "$@"; die "import failed - $err"; } diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index e1763478..a50b4e12 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -2550,7 +2550,7 @@ sub check_type { } sub destroy_vm { - my ($storecfg, $vmid, $keep_empty_config, $skiplock) = @_; + my ($storecfg, $vmid, $skiplock, $replacement_conf) = @_; my $conf = PVE::QemuConfig->load_config($vmid); @@ -2594,8 +2594,8 @@ sub destroy_vm { warn $@ if $@; }); - if ($keep_empty_config) { - PVE::QemuConfig->write_config($vmid, { memory => 128 }); + if (defined $replacement_conf) { + PVE::LXC::Config->write_config($vmid, $replacement_conf); } else { PVE::QemuConfig->destroy_config($vmid); } @@ -6595,7 +6595,7 @@ sub restore_tar_archive { # pass keep_empty_config=1 to keep the config (thus VMID) reserved for us # skiplock=1 because qmrestore has set the 'create' lock itself already my $vmcfgfn = PVE::QemuConfig->config_file($vmid); - destroy_vm($storecfg, $vmid, 1, 1) if -f $vmcfgfn; + destroy_vm($storecfg, $vmid, 1, { lock => 'restore' }) if -f $vmcfgfn; my $tocmd = "/usr/lib/qemu-server/qmextract"; -- 2.39.5