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

Alwin Antreich a.antreich at proxmox.com
Wed Mar 14 13:51:55 CET 2018


The method vm_start sets an environment variable that is not picked up
anymore by systemd. This patch removes 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>
---
note: made changes by Dietmar's comments

 src/PVE/LXC.pm            | 13 +++++++++++--
 src/lxc-pve-prestart-hook |  5 ++++-
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 7adbcd1..2a3950c 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -1545,11 +1545,20 @@ sub vm_start {

     update_lxc_config($vmid, $conf);

-    local $ENV{PVE_SKIPLOCK}=1 if $skiplock;
+    my $skiplock_flag_fn = "/run/lxc/skiplock-$vmid";
+
+    if ($skiplock) {
+	open(my $fh, '>', $skiplock_flag_fn) || die "failed to open $skiplock_flag_fn for writing: $!\n";
+	close($fh);
+    }

     my $cmd = ['systemctl', 'start', "pve-container\@$vmid"];

-    PVE::Tools::run_command($cmd);
+    eval { PVE::Tools::run_command($cmd); };
+    if (my $err = $@) {
+	unlink $skiplock_flag_fn;
+	die $err if $err;
+    }

     return;
 }
diff --git a/src/lxc-pve-prestart-hook b/src/lxc-pve-prestart-hook
index fd29423..61a8ef3 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 $skiplock_flag_fn = "/run/lxc/skiplock-$vmid";
+	my $skiplock = 1 if -e $skiplock_flag_fn;
+	unlink $skiplock_flag_fn if $skiplock;

 	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