[pve-devel] [PATCH qemu-server 1/3] API/create: move locking inside worker

Thomas Lamprecht t.lamprecht at proxmox.com
Fri Jun 1 16:37:39 CEST 2018


Move the locking inside worker, so that the process doing the actual
work (create or restore) holds the lock, and can call functions which
do locking without deadlocking.

This mirrors the behaviour we use for containers, and allows to add
an 'autostart' parameter which starts the VM after successful
creation. vm_start needs the lock and as not the worker but it's
parents held it, it couldn't know that it was actually save to
continue...

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 PVE/API2/Qemu.pm | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 8d4b10d..c657245 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -462,6 +462,7 @@ __PACKAGE__->register_method({
 	my $vmid = extract_param($param, 'vmid');
 
 	my $archive = extract_param($param, 'archive');
+	my $is_restore = !!$archive;
 
 	my $storage = extract_param($param, 'storage');
 
@@ -569,7 +570,7 @@ __PACKAGE__->register_method({
 	    # ensure no old replication state are exists
 	    PVE::ReplicationState::delete_guest_states($vmid);
 
-	    return $rpcenv->fork_worker('qmrestore', $vmid, $authuser, $realcmd);
+	    return PVE::QemuConfig->lock_config_full($vmid, 1, $realcmd);
 	};
 
 	my $createfn = sub {
@@ -616,10 +617,13 @@ __PACKAGE__->register_method({
 		PVE::AccessControl::add_vm_to_pool($vmid, $pool) if $pool;
 	    };
 
-	    return $rpcenv->fork_worker('qmcreate', $vmid, $authuser, $realcmd);
+	    return PVE::QemuConfig->lock_config_full($vmid, 1, $realcmd);
 	};
 
-	return PVE::QemuConfig->lock_config_full($vmid, 1, $archive ? $restorefn : $createfn);
+	my $worker_name = $is_restore ? 'qmrestore' : 'qmcreate';
+	my $code = $is_restore ? $restorefn : $createfn;
+
+	return $rpcenv->fork_worker($worker_name, $vmid, $authuser, $code);
     }});
 
 __PACKAGE__->register_method({
-- 
2.17.1





More information about the pve-devel mailing list