[pve-devel] [PATCH container 1/2] Use set_lock and remove_lock

Fabian Grünbichler f.gruenbichler at proxmox.com
Fri Mar 11 11:37:33 CET 2016


instead of manually setting and removing the lock config
parameter.
---
 src/PVE/CLI/pct.pm    |  6 +-----
 src/PVE/VZDump/LXC.pm | 26 ++------------------------
 2 files changed, 3 insertions(+), 29 deletions(-)

diff --git a/src/PVE/CLI/pct.pm b/src/PVE/CLI/pct.pm
index 4376f8a..963015b 100755
--- a/src/PVE/CLI/pct.pm
+++ b/src/PVE/CLI/pct.pm
@@ -48,11 +48,7 @@ __PACKAGE__->register_method ({
 
 	my $vmid = $param->{vmid};
 
-	PVE::LXC::Config->lock_config($vmid, sub {
-	    my $conf = PVE::LXC::Config->load_config($vmid);
-	    delete $conf->{lock};
-	    PVE::LXC::Config->write_config($vmid, $conf);
-	});
+	PVE::LXC::Config->remove_lock($vmid);
 
 	return undef;
     }});
diff --git a/src/PVE/VZDump/LXC.pm b/src/PVE/VZDump/LXC.pm
index 33a0b55..1bad3fd 100644
--- a/src/PVE/VZDump/LXC.pm
+++ b/src/PVE/VZDump/LXC.pm
@@ -174,35 +174,13 @@ sub prepare {
 sub lock_vm {
     my ($self, $vmid) = @_;
 
-    my $lockconfig = sub {
-	my ($self, $vmid) = @_;
-
-	my $conf = PVE::LXC::Config->load_config($vmid);
-
-	PVE::LXC::Config->check_lock($conf);
-	$conf->{lock} = 'backup';
-
-	PVE::LXC::Config->write_config($vmid, $conf);
-    };
-
-    PVE::LXC::Config->lock_config($vmid, $lockconfig, ($self, $vmid));
+    PVE::LXC::Config->set_lock($vmid, 'backup');
 }
 
 sub unlock_vm {
     my ($self, $vmid) = @_;
 
-    my $unlockconfig = sub {
-	my ($self, $vmid) = @_;
-
-	my $conf = PVE::LXC::Config->load_config($vmid);
-
-	if ($conf->{lock} && $conf->{lock} eq 'backup') {
-	    delete $conf->{lock};
-	    PVE::LXC::Config->write_config($vmid, $conf);
-	}
-    };
-
-    PVE::LXC::Config->lock_config($vmid, $unlockconfig, ($self, $vmid));
+    PVE::LXC::Config->remove_lock($vmid, 'backup')
 }
 
 sub snapshot {
-- 
2.1.4





More information about the pve-devel mailing list