]> git.proxmox.com Git - qemu-server.git/commitdiff
replace remaining vm_destroy call-sites with destroy_vm
authorDominic Jäger <d.jaeger@proxmox.com>
Mon, 28 Oct 2019 11:47:32 +0000 (12:47 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 29 Oct 2019 18:11:02 +0000 (19:11 +0100)
This function has been used in one place only into which we inlined its
functionality. Removing it avoids confusion between vm_destroy and vm_destroy.

The whole $importfn is executed in a lock_config_full.
As a consequence, for the inlined code:
1. lock_config is redundant
2. it is not possible that the VM has been started (check_running) in the
    meanwhile
Additionally, it is not possible that the "lock" property has been written into
the VM's config file (check_lock) in the meanwhile

Add warning after eval so that it does not go unnoticed if it ever comes into
action.

Signed-off-by: Dominic Jäger <d.jaeger@proxmox.com>
PVE/CLI/qm.pm
PVE/QemuServer.pm

index 2c363735f7fef2c7da2e01d3134dec43646c5ec1..235f6135a9abacef5f835627152a4fd52406b6b9 100755 (executable)
@@ -645,7 +645,6 @@ __PACKAGE__->register_method ({
 
                # reload after disks entries have been created
                $conf = PVE::QemuConfig->load_config($vmid);
-               PVE::QemuConfig->check_lock($conf);
                my $firstdisk = PVE::QemuServer::resolve_first_disk($conf);
                $conf->{bootdisk} = $firstdisk if $firstdisk;
                PVE::QemuConfig->write_config($vmid, $conf);
@@ -654,7 +653,9 @@ __PACKAGE__->register_method ({
            my $err = $@;
            if ($err) {
                my $skiplock = 1;
-               eval { PVE::QemuServer::vm_destroy($storecfg, $vmid, $skiplock); };
+               # eval for additional safety in error path
+               eval { PVE::QemuServer::destroy_vm($storecfg, $vmid, undef, $skiplock) };
+               warn "Could not destroy VM $vmid: $@" if "$@";
                die "import failed - $err";
            }
        };
index a11153ec75dd8e52d1f9fc08f261c32e1f7cb416..bfe6662dd18d57cdcc70486ebc59acfc89575f93 100644 (file)
@@ -5937,21 +5937,6 @@ sub vm_sendkey {
     });
 }
 
-sub vm_destroy {
-    my ($storecfg, $vmid, $skiplock) = @_;
-
-    PVE::QemuConfig->lock_config($vmid, sub {
-
-       my $conf = PVE::QemuConfig->load_config($vmid);
-
-       if (!check_running($vmid)) {
-           destroy_vm($storecfg, $vmid, undef, $skiplock);
-       } else {
-           die "VM $vmid is running - destroy failed\n";
-       }
-    });
-}
-
 # vzdump restore implementaion
 
 sub tar_archive_read_firstfile {