[pve-devel] [PATCH v4 ha-manager 2/5] Add timeout parameter for shutdown

Fabian Ebner f.ebner at proxmox.com
Thu Oct 10 12:25:06 CEST 2019


Introduces a timeout parameter for shutting a resource down.
If the parameter is 0, we perform a hard stop instead of a shutdown.

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---

I did not find a way to pass along the parameters from change_service_state
without having an special handling for either target+timeout or node.

 src/PVE/HA/LRM.pm             | 10 +++++++---
 src/PVE/HA/Resources.pm       |  2 +-
 src/PVE/HA/Resources/PVECT.pm | 14 ++++++++++----
 src/PVE/HA/Resources/PVEVM.pm | 16 +++++++++++-----
 4 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/src/PVE/HA/LRM.pm b/src/PVE/HA/LRM.pm
index 5b986a4..b5ef8b8 100644
--- a/src/PVE/HA/LRM.pm
+++ b/src/PVE/HA/LRM.pm
@@ -532,7 +532,7 @@ sub manage_resources {
 	my $req_state = $sd->{state};
 	next if !defined($req_state);
 	next if $req_state eq 'freeze';
-	$self->queue_resource_command($sid, $sd->{uid}, $req_state, {'target' => $sd->{target}});
+	$self->queue_resource_command($sid, $sd->{uid}, $req_state, {'target' => $sd->{target}, 'timeout' => $sd->{timeout}});
     }
 
     return $self->run_workers();
@@ -771,9 +771,13 @@ sub exec_resource_agent {
 
 	return SUCCESS if !$running;
 
-	$haenv->log("info", "stopping service $sid");
+	if (defined($params->{timeout})) {
+	    $haenv->log("info", "stopping service $sid (timeout=$params->{timeout})");
+	} else {
+	    $haenv->log("info", "stopping service $sid");
+	}
 
-	$plugin->shutdown($haenv, $id);
+	$plugin->shutdown($haenv, $id, $params->{timeout});
 
 	$running = $plugin->check_running($haenv, $id);
 
diff --git a/src/PVE/HA/Resources.pm b/src/PVE/HA/Resources.pm
index 7c373bc..835c314 100644
--- a/src/PVE/HA/Resources.pm
+++ b/src/PVE/HA/Resources.pm
@@ -126,7 +126,7 @@ sub start {
 }
 
 sub shutdown {
-    my ($class, $haenv, $id) = @_;
+    my ($class, $haenv, $id, $timeout) = @_;
 
     die "implement in subclass";
 }
diff --git a/src/PVE/HA/Resources/PVECT.pm b/src/PVE/HA/Resources/PVECT.pm
index a0f05f4..282f4ef 100644
--- a/src/PVE/HA/Resources/PVECT.pm
+++ b/src/PVE/HA/Resources/PVECT.pm
@@ -74,18 +74,24 @@ sub start {
 }
 
 sub shutdown {
-    my ($class, $haenv, $id) = @_;
+    my ($class, $haenv, $id, $timeout) = @_;
 
     my $nodename = $haenv->nodename();
-    my $shutdown_timeout = 60; # fixme: make this configurable
+    my $shutdown_timeout = $timeout // 60;
 
+    my $upid;
     my $params = {
 	node => $nodename,
 	vmid => $id,
-	timeout => $shutdown_timeout,
     };
 
-    my $upid = PVE::API2::LXC::Status->vm_shutdown($params);
+    if ($shutdown_timeout) {
+	$params->{timeout} = $shutdown_timeout;
+	$upid = PVE::API2::LXC::Status->vm_shutdown($params);
+    } else {
+	$upid = PVE::API2::LXC::Status->vm_stop($params);
+    }
+
     PVE::HA::Tools::upid_wait($upid, $haenv);
 }
 
diff --git a/src/PVE/HA/Resources/PVEVM.pm b/src/PVE/HA/Resources/PVEVM.pm
index 0a37cf6..aad073d 100644
--- a/src/PVE/HA/Resources/PVEVM.pm
+++ b/src/PVE/HA/Resources/PVEVM.pm
@@ -72,19 +72,25 @@ sub start {
 }
 
 sub shutdown {
-    my ($class, $haenv, $id) = @_;
+    my ($class, $haenv, $id, $timeout) = @_;
 
     my $nodename = $haenv->nodename();
-    my $shutdown_timeout = 60; # fixme: make this configurable
+    my $shutdown_timeout = $timeout // 60;
 
+    my $upid;
     my $params = {
 	node => $nodename,
 	vmid => $id,
-	timeout => $shutdown_timeout,
-	forceStop => 1,
     };
 
-    my $upid = PVE::API2::Qemu->vm_shutdown($params);
+    if ($shutdown_timeout) {
+	$params->{timeout} = $shutdown_timeout;
+	$params->{forceStop} = 1;
+	$upid = PVE::API2::Qemu->vm_shutdown($params);
+    } else {
+	$upid = PVE::API2::Qemu->vm_stop($params);
+    }
+
     PVE::HA::Tools::upid_wait($upid, $haenv);
 }
 
-- 
2.20.1





More information about the pve-devel mailing list