]> git.proxmox.com Git - pve-container.git/commitdiff
added set_lock and remove_lock
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 26 Feb 2016 10:42:09 +0000 (11:42 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Sat, 27 Feb 2016 13:22:17 +0000 (14:22 +0100)
Since set_lock does the implied lock_config() and
load_config() it also returns the loaded config afterwards
as there is no other meaningful return value defined for
this function since failure to apply the lock throws an
exception.

remove_lock() also takes a lock name in order to make sure
only the correct lock is being removed.

src/PVE/LXC.pm

index 503a57fb872ada093e83b101349afe851950baf3..8ebf3dbc49c6da52fba68560f23e557f19fc0279 100644 (file)
@@ -2772,4 +2772,30 @@ sub userns_command {
     return [];
 }
 
+sub set_lock {
+    my ($vmid, $lock) = @_;
+    my $conf;
+    lock_config($vmid, sub {
+       $conf = load_config($vmid);
+       check_lock($conf);
+       $conf->{lock} = $lock;
+       write_config($vmid, $conf);
+    });
+    return $conf;
+}
+
+sub remove_lock {
+    my ($vmid, $lock) = @_;
+    lock_config($vmid, sub {
+       my $conf = load_config($vmid);
+       if (!$conf->{lock}) {
+           die "no lock found trying to remove lock '$lock'\n";
+       } elsif (defined($lock) && $conf->{lock} ne $lock) {
+           die "found lock '$conf->{lock}' trying to remove lock '$lock'\n";
+       }
+       delete $conf->{lock};
+       write_config($vmid, $conf);
+    });
+}
+
 1;