[pve-devel] [PATCH container 2/5] added set_lock and remove_lock
Wolfgang Bumiller
w.bumiller at proxmox.com
Fri Feb 26 11:42:09 CET 2016
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 | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 5d9d082..a823062 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -2869,4 +2869,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;
--
2.1.4
More information about the pve-devel
mailing list