[pve-devel] [PATCH v3 ha-manager 4/9] Add timeout parameter for shutdown
Fabian Ebner
f.ebner at proxmox.com
Wed Oct 2 11:46:05 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>
---
src/PVE/HA/LRM.pm | 4 ++--
src/PVE/HA/Resources.pm | 2 +-
src/PVE/HA/Resources/PVECT.pm | 14 ++++++++++----
src/PVE/HA/Resources/PVEVM.pm | 16 +++++++++++-----
4 files changed, 24 insertions(+), 12 deletions(-)
diff --git a/src/PVE/HA/LRM.pm b/src/PVE/HA/LRM.pm
index 3b4a572..e5eee94 100644
--- a/src/PVE/HA/LRM.pm
+++ b/src/PVE/HA/LRM.pm
@@ -535,7 +535,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();
@@ -776,7 +776,7 @@ sub exec_resource_agent {
$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 9dcf558..45d87e8 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