]> git.proxmox.com Git - qemu-server.git/commitdiff
clone: use new config_lock_shared
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Tue, 5 May 2020 08:27:23 +0000 (10:27 +0200)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Tue, 5 May 2020 09:41:55 +0000 (11:41 +0200)
and move the lock call and decision logic closer together

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Tested-by: Fabian Ebner <f.ebner@proxmox.com>
PVE/API2/Qemu.pm

index be5e2fc31e5239c3443b1c397e4ee17b3ecaa427..9fb886b4600eb367d49bee5a86c804476122d392 100644 (file)
@@ -2858,9 +2858,6 @@ __PACKAGE__->register_method({
 
        my $running = PVE::QemuServer::check_running($vmid) || 0;
 
-       # exclusive lock if VM is running - else shared lock is enough;
-       my $shared_lock = $running ? 0 : 1;
-
        my $clonefn = sub {
            # do all tests after lock but before forking worker - if possible
 
@@ -3048,11 +3045,17 @@ __PACKAGE__->register_method({
            return $rpcenv->fork_worker('qmclone', $vmid, $authuser, $realcmd);
        };
 
-       return PVE::QemuConfig->lock_config_mode($vmid, 1, $shared_lock, sub {
-           # Aquire exclusive lock lock for $newid
+       # Aquire exclusive lock lock for $newid
+       my $lock_target_vm = sub {
            return PVE::QemuConfig->lock_config_full($newid, 1, $clonefn);
-       });
+       };
 
+       # exclusive lock if VM is running - else shared lock is enough;
+       if ($running) {
+           return PVE::QemuConfig->lock_config_full($vmid, 1, $lock_target_vm);
+       } else {
+           return PVE::QemuConfig->lock_config_shared($vmid, 1, $lock_target_vm);
+       }
     }});
 
 __PACKAGE__->register_method({