[pve-devel] [PATCH container 2/2] vm_stop: add nokill-after-timeout parameter

Thomas Lamprecht t.lamprecht at proxmox.com
Wed May 8 13:58:22 CEST 2019


This allows to have the same semantics as qemu-server:
* immediate hard-kill
* shutdown with kill after timeout
* shutdown without kill after timeout

And thus we finally can move the vm_shutdown API call to a correct
semantic, i.e., do not immediate hard kill if forceStop is not passed
but rather see it as stop after timeout knob.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 src/PVE/API2/LXC/Status.pm |  2 +-
 src/PVE/LXC.pm             | 18 +++++++++++++-----
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/PVE/API2/LXC/Status.pm b/src/PVE/API2/LXC/Status.pm
index 95775fe..f6668e2 100644
--- a/src/PVE/API2/LXC/Status.pm
+++ b/src/PVE/API2/LXC/Status.pm
@@ -369,7 +369,7 @@ __PACKAGE__->register_method({
 
 		PVE::LXC::Config->check_lock($conf);
 
-		PVE::LXC::vm_stop($vmid, $param->{forceStop}, $timeout);
+		PVE::LXC::vm_stop($vmid, 0, $timeout, !$param->{forceStop});
 
 		return;
 	    };
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index f8fc37e..5d099ca 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -1938,8 +1938,11 @@ sub vm_start {
 # This is necessary because we want the post-stop hook to have completed its
 # unmount-all step, but post-stop happens after lxc puts the container into the
 # STOPPED state.
+# $kill - if true it will always do an immediate hard-stop
+# $shutdown_timeout - the timeout to wait for a gracefull shutdown
+# $nokill_after_timeout - if true, do not send a hardstop if shutdown timed out
 sub vm_stop {
-    my ($vmid, $kill, $shutdown_timeout) = @_;
+    my ($vmid, $kill, $shutdown_timeout, $nokill_after_timeout) = @_;
 
     # Open the container's command socket.
     my $path = "\0/var/lib/lxc/$vmid/command";
@@ -1961,10 +1964,15 @@ sub vm_stop {
 
     if ($kill) {
 	push @$cmd, '--kill'; # doesn't allow timeouts
-    } elsif (defined($shutdown_timeout)) {
-	push @$cmd, '--timeout', $shutdown_timeout;
-	# Give run_command 5 extra seconds
-	$shutdown_timeout += 5;
+    } else {
+	# lxc-stop uses a default timeout
+	push @$cmd, '--nokill' if $nokill_after_timeout;
+
+	if (defined($shutdown_timeout)) {
+	    push @$cmd, '--timeout', $shutdown_timeout;
+	    # Give run_command 5 extra seconds
+	    $shutdown_timeout += 5;
+	}
     }
 
     eval { PVE::Tools::run_command($cmd, timeout => $shutdown_timeout) };
-- 
2.20.1





More information about the pve-devel mailing list