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

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 <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2019-11-08 17:03:28 +01:00
parent 7dc7f315f3
commit b04ea58453
3 changed files with 6 additions and 6 deletions

View File

@ -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);

View File

@ -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";
}

View File

@ -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";