]> git.proxmox.com Git - pve-container.git/commitdiff
Prevent race conditions in snapshot mode backup
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Fri, 11 Mar 2016 10:44:47 +0000 (11:44 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 14 Mar 2016 07:50:57 +0000 (08:50 +0100)
Instead of dropping the 'backup' lock early on when doing
snapshot backups, drop it temporarily for snapshot
operations that set their own 'snapshot' lock, and protect
the "unlock_vm, snapshot_XX, lock_vm" sequence by holding an
flock for the config file.

Before this change it was possible to interfere with the
backup job by setting a different lock with another
operation inbetween the call to unlock_vm and
snapshot_create (or snapshot_delete).

The final lock_vm is re-introduced in order to be more
consistent with the other backup modes and to prevent
changes to the configuration file before assemble()
reloads the configuration that is included in the backup.

src/PVE/VZDump/LXC.pm

index 1bad3fd73a8f3991dc58f586b45d7a991376c685..e7a307f1e5c3528cf9d05b75ef84d39843e7b380 100644 (file)
@@ -134,11 +134,14 @@ sub prepare {
            die "mode failure - some volumes do not support snapshots\n";
        }
 
-       unlock_vm($self, $vmid);
 
        if ($conf->{snapshots} && $conf->{snapshots}->{vzdump}) {
            $self->loginfo("found old vzdump snapshot (force removal)");
-           PVE::LXC::Config->snapshot_delete($vmid, 'vzdump', 1);
+           PVE::LXC::Config->lock_config($vmid, sub {
+               $self->unlock_vm($vmid);
+               PVE::LXC::Config->snapshot_delete($vmid, 'vzdump', 1);
+               $self->lock_vm($vmid);
+           });
        }
 
        my $rootdir = $default_mount_point;
@@ -189,7 +192,11 @@ sub snapshot {
     $self->loginfo("create storage snapshot 'vzdump'");
 
     # todo: freeze/unfreeze if we have more than one volid
-    PVE::LXC::Config->snapshot_create($vmid, 'vzdump', 0, "vzdump backup snapshot");
+    PVE::LXC::Config->lock_config($vmid, sub {
+       $self->unlock_vm($vmid);
+       PVE::LXC::Config->snapshot_create($vmid, 'vzdump', 0, "vzdump backup snapshot");
+       $self->lock_vm($vmid);
+    });
     $task->{cleanup}->{remove_snapshot} = 1;
     
     # reload config