]> git.proxmox.com Git - qemu-server.git/commitdiff
copy_vm: use exclusive lock for running VM
authorDietmar Maurer <dietmar@proxmox.com>
Tue, 30 Apr 2013 05:40:43 +0000 (07:40 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 30 Apr 2013 05:40:43 +0000 (07:40 +0200)
Because we can only run one block job to copy data.

PVE/API2/Qemu.pm
PVE/QemuServer.pm

index 0fe0045b8fea874c579f266986da0a8ff6a5a674..e92a03e990d9fe299005c3f0b2613d4160698581 100644 (file)
@@ -1809,6 +1809,7 @@ __PACKAGE__->register_method({
            },
            storage => get_standard_option('pve-storage-id', {
                description => "Target storage for full copy.",
+               requires => 'full',
                optional => 1,
            }),
            full => {
@@ -1849,6 +1850,13 @@ __PACKAGE__->register_method({
 
        PVE::Cluster::check_cfs_quorum();
 
+       my $running = PVE::QemuServer::check_running($vmid) || 0;
+
+       die "Copy running VM $vmid not implemented\n" if $running; # fixme: implement this
+
+       # exclusive lock if VM is running - else shared lock is enough;
+       my $shared_lock = $running ? 0 : 1;
+
        # fixme: do early checks - re-check after lock 
 
        # fixme: impl. target node parameter (mv VM config if all storages are shared)
@@ -1860,9 +1868,9 @@ __PACKAGE__->register_method({
 
            PVE::QemuServer::check_lock($conf);
 
-           my $running = PVE::QemuServer::check_running($vmid);
+           my $verify_running = PVE::QemuServer::check_running($vmid) || 0;
 
-           die "Copy running VM $vmid not implemented\n" if $running;
+           die "unexpected state change\n" if $verify_running != $running;
 
            &$check_storage_access_copy($rpcenv, $authuser, $storecfg, $conf, $storage);
 
@@ -1967,8 +1975,7 @@ __PACKAGE__->register_method({
            return $rpcenv->fork_worker('qmcopy', $vmid, $authuser, $realcmd);
        };
 
-       # Aquire shared lock for $vmid
-       return PVE::QemuServer::lock_config_shared($vmid, 1, sub {
+       return PVE::QemuServer::lock_config_mode($vmid, 1, $shared_lock, sub {
            # Aquire exclusive lock lock for $newid
            return PVE::QemuServer::lock_config_full($newid, 1, $copyfn);
        });
index 3725807090bda0267b38481cf4f450ff0318235b..23f7c6c445203ab3e78b0adfcd238fab8736b2c3 100644 (file)
@@ -1483,12 +1483,12 @@ sub lock_config_full {
     return $res;
 }
 
-sub lock_config_shared {
-    my ($vmid, $timeout, $code, @param) = @_;
+sub lock_config_mode {
+    my ($vmid, $timeout, $shared, $code, @param) = @_;
 
     my $filename = config_file_lock($vmid);
 
-    my $res = lock_file_full($filename, $timeout, 1, $code, @param);
+    my $res = lock_file_full($filename, $timeout, $shared, $code, @param);
 
     die $@ if $@;