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

2018-03-13 Thread Thomas Lamprecht
On 03/13/2018 05:20 PM, Alwin Antreich wrote:
> 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 
> ---
>  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;

if it never gets passed along at all, no point in trying
to stay compatible, or?

> +
> + my $file = "/var/lib/lxc/$vmid/skiplock";

use /run/lxc/... or /run/pve-container (the former exists already)
those are guaranteed to be tmpfs and thus a reboot clears possible
left over flag files

> + 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";

$file is very ambiguous, maybe $skiplock_flag_fn?

> + my $skiplock = $ENV{PVE_SKIPLOCK} || 1 if -e $file;

don't do that, it's quite confusing, for what is the if?
the whole assign, then you could omit the $ENV{PVE_SKIPLOCK}
part...

Do either

my $skiplock = $ENV{PVE_SKIPLOCK} || -e $file;

or maybe even better:
my $skiplock = $ENV{PVE_SKIPLOCK}; # backwar copatibillity
$skiplock = 1 if -e $file;

Or if you say systemd does not picks this up just omit the $ENV
completely?


> + 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);
>   }
>  
> 


___
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


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

2018-03-13 Thread Alwin Antreich
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 
---
 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


___
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel