[pve-devel] [PATCH container 5/5] allow starting and stopping a mounted container

Wolfgang Bumiller w.bumiller at proxmox.com
Fri Feb 26 11:42:12 CET 2016


---
 src/PVE/API2/LXC/Status.pm | 8 ++++++--
 src/PVE/LXC.pm             | 5 +++++
 src/lxc-pve-prestart-hook  | 4 +++-
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/PVE/API2/LXC/Status.pm b/src/PVE/API2/LXC/Status.pm
index e91ac7c..a4498d1 100644
--- a/src/PVE/API2/LXC/Status.pm
+++ b/src/PVE/API2/LXC/Status.pm
@@ -168,7 +168,9 @@ __PACKAGE__->register_method({
 		    die "you can't start a CT if it's a template\n"
 			if PVE::LXC::is_template($conf);
 
-		    PVE::LXC::check_lock($conf) if !$skiplock;
+		    if (!$skiplock && !PVE::LXC::has_lock($conf, 'mounted')) {
+			PVE::LXC::check_lock($conf);
+		    }
 
 		    my $storage_cfg = cfs_read_file("storage.cfg");
 
@@ -256,7 +258,9 @@ __PACKAGE__->register_method({
 
 		    my $conf = PVE::LXC::load_config($vmid);
 
-		    PVE::LXC::check_lock($conf) if !$skiplock;
+		    if (!$skiplock && !PVE::LXC::has_lock($conf, 'mounted')) {
+			PVE::LXC::check_lock($conf);
+		    }
 
 		    my $cmd = ['lxc-stop', '-n', $vmid, '--kill'];
 
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 1ed3680..8ed2322 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -1098,6 +1098,11 @@ sub check_lock {
     die "VM is locked ($conf->{'lock'})\n" if $conf->{'lock'};
 }
 
+sub has_lock {
+    my ($conf, $lock) = @_;
+    return $conf->{lock} && (!defined($lock) || $lock eq $conf->{lock});
+}
+
 sub check_protection {
     my ($vm_conf, $err_msg) = @_;
 
diff --git a/src/lxc-pve-prestart-hook b/src/lxc-pve-prestart-hook
index 29e7808..28e1a36 100755
--- a/src/lxc-pve-prestart-hook
+++ b/src/lxc-pve-prestart-hook
@@ -63,7 +63,9 @@ __PACKAGE__->register_method ({
 	return undef if ! -f PVE::LXC::config_file($vmid);
 
 	my $conf = PVE::LXC::load_config($vmid);
-	PVE::LXC::check_lock($conf) if !$ENV{PVE_SKIPLOCK};
+	if (!$ENV{PVE_SKIPLOCK} && !PVE::LXC::has_lock($conf, 'mounted')) {
+	    PVE::LXC::check_lock($conf);
+	}
 
 	my $storage_cfg = PVE::Storage::config();
 
-- 
2.1.4





More information about the pve-devel mailing list