[pve-devel] [PATCH qemu-server v2 1/3] Remove vm_destroy

Dominic Jäger d.jaeger at proxmox.com
Mon Oct 28 12:47:32 CET 2019


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 at proxmox.com>
---
v1->v2:
- Adapt commit message
- Keep $skiplock for readability
- Squash 3/7 "Remove redundant locks" into here
- Squash 5/7 "Remove useless eval" into here:
     Actually the eval is not removed anymore but I added a warning instead

 PVE/CLI/qm.pm     |  5 +++--
 PVE/QemuServer.pm | 15 ---------------
 2 files changed, 3 insertions(+), 17 deletions(-)

diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
index ea74ad5..acafdc0 100755
--- a/PVE/CLI/qm.pm
+++ b/PVE/CLI/qm.pm
@@ -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";
 	    }
 	};
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index b635760..af0e15a 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -5943,21 +5943,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 {
-- 
2.20.1




More information about the pve-devel mailing list