[pve-devel] [PATCH qemu-server 4/7] Remove variable from lock

Dominic Jäger d.jaeger at proxmox.com
Fri Oct 25 11:24:04 CEST 2019


The variable was used in one place only. Nesting the code into the
lock_config_full makes clear what code is locked.

Signed-off-by: Dominic Jäger <d.jaeger at proxmox.com>
---
 PVE/CLI/qm.pm | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
index c93f78d..a378d3d 100755
--- a/PVE/CLI/qm.pm
+++ b/PVE/CLI/qm.pm
@@ -625,10 +625,9 @@ __PACKAGE__->register_method ({
 	$param->{memory} = $parsed->{qm}->{memory} if defined($parsed->{qm}->{memory});
 	$param->{cores} = $parsed->{qm}->{cores} if defined($parsed->{qm}->{cores});
 
-	my $importfn = sub {
-
+	# why is wait_for_lock exactly 1?
+	PVE::QemuConfig->lock_config_full($vmid, 1, sub {
 	    PVE::Cluster::check_vmid_unused($vmid);
-
 	    my $conf = $param;
 
 	    eval {
@@ -649,16 +648,12 @@ __PACKAGE__->register_method ({
 		$conf->{bootdisk} = $firstdisk if $firstdisk;
 		PVE::QemuConfig->write_config($vmid, $conf);
 	    };
-
 	    my $err = $@;
 	    if ($err) {
 		eval { PVE::QemuServer::destroy_vm($storecfg, $vmid, undef, 1); };
 		die "import failed - $err";
 	    }
-	};
-
-	my $wait_for_lock = 1;
-	PVE::QemuConfig->lock_config_full($vmid, $wait_for_lock, $importfn);
+	});
 
 	return undef;
 
-- 
2.20.1




More information about the pve-devel mailing list