[pve-devel] [PATCH container] Fix pct skiplock

Alwin Antreich a.antreich at proxmox.com
Tue Mar 13 17:20:43 CET 2018


The method vm_start sets an environment variable that is not picked up
anymore by systemd. This patch keeps the environment variable and
introduces a skiplock file that is picked up by the
lxc-pve-prestart-hook.

Signed-off-by: Alwin Antreich <a.antreich at proxmox.com>
---
 src/PVE/LXC.pm            | 9 ++++++++-
 src/lxc-pve-prestart-hook | 5 ++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 7adbcd1..2e3e4ca 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -1545,7 +1545,14 @@ sub vm_start {
 
     update_lxc_config($vmid, $conf);
 
-    local $ENV{PVE_SKIPLOCK}=1 if $skiplock;
+    if ($skiplock) {
+	# to stay compatible with old behaviour
+	local $ENV{PVE_SKIPLOCK}=1;
+
+	my $file = "/var/lib/lxc/$vmid/skiplock";
+	open(my $fh, '>', $file) || die "failed to open $file for writing: $!\n";
+	close($fh);
+    }
 
     my $cmd = ['systemctl', 'start', "pve-container\@$vmid"];
 
diff --git a/src/lxc-pve-prestart-hook b/src/lxc-pve-prestart-hook
index fd29423..abe61aa 100755
--- a/src/lxc-pve-prestart-hook
+++ b/src/lxc-pve-prestart-hook
@@ -57,13 +57,16 @@ __PACKAGE__->register_method ({
 	return undef if $param->{name} !~ m/^\d+$/;
 
 	my $vmid = $param->{name};
+	my $file = "/var/lib/lxc/$vmid/skiplock";
+	my $skiplock = $ENV{PVE_SKIPLOCK} || 1 if -e $file;
+	unlink $file if -e $file;
 
 	PVE::Cluster::check_cfs_quorum(); # only start if we have quorum
 
 	return undef if ! -f PVE::LXC::Config->config_file($vmid);
 
 	my $conf = PVE::LXC::Config->load_config($vmid);
-	if (!$ENV{PVE_SKIPLOCK} && !PVE::LXC::Config->has_lock($conf, 'mounted')) {
+	if (!$skiplock && !PVE::LXC::Config->has_lock($conf, 'mounted')) {
 	    PVE::LXC::Config->check_lock($conf);
 	}
 
-- 
2.11.0





More information about the pve-devel mailing list