[pve-devel] [PATCH ha-manager v3 2/4] implement 'stopped' state
Thomas Lamprecht
t.lamprecht at proxmox.com
Tue Nov 15 12:11:21 CET 2016
In stopped state we do not start a service but we recover it on
fencing.
This can be practical for templates or cold standby guests.
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
changes since v2:
* split direct transition to request_stop state when adding a disabled or
stopped service in own patch
src/PVE/HA/Manager.pm | 18 +++++++++++++++---
src/PVE/HA/Sim/TestHardware.pm | 4 ++--
2 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/src/PVE/HA/Manager.pm b/src/PVE/HA/Manager.pm
index e58fc0b..c2fa2c3 100644
--- a/src/PVE/HA/Manager.pm
+++ b/src/PVE/HA/Manager.pm
@@ -290,7 +290,8 @@ my $recover_fenced_service = sub {
# $sd *is normally read-only*, fencing is the exception
$cd->{node} = $sd->{node} = $recovery_node;
- &$change_service_state($self, $sid, 'started', node => $recovery_node);
+ my $new_state = ($cd->{state} eq 'enabled') ? 'started' : 'request_stop';
+ &$change_service_state($self, $sid, $new_state, node => $recovery_node);
} else {
# no possible node found, cannot recover
$haenv->log('err', "recovering service '$sid' from fenced node " .
@@ -432,7 +433,8 @@ sub manage {
my $lrm_mode = $sd->{node} ? $lrm_modes->{$sd->{node}} : undef;
# unfreeze
- &$change_service_state($self, $sid, 'started')
+ my $state = ($cd->{state} eq 'enabled') ? 'started' : 'request_stop';
+ &$change_service_state($self, $sid, $state)
if $lrm_mode && $lrm_mode eq 'active';
} elsif ($last_state eq 'error') {
@@ -579,6 +581,16 @@ sub next_state_stopped {
return;
}
+ if ($ns->node_is_offline_delayed($sd->{node})) {
+ &$change_service_state($self, $sid, 'fence');
+ return;
+ }
+
+ if ($cd->{state} eq 'stopped') {
+ # almost the same as 'disabled' state but the service will also get recovered
+ return;
+ }
+
if ($cd->{state} eq 'enabled') {
# simply mark it started, if it's on the wrong node
# next_state_started will fix that for us
@@ -613,7 +625,7 @@ sub next_state_started {
return;
}
- if ($cd->{state} eq 'disabled') {
+ if ($cd->{state} eq 'disabled' || $cd->{state} eq 'stopped') {
&$change_service_state($self, $sid, 'request_stop');
return;
}
diff --git a/src/PVE/HA/Sim/TestHardware.pm b/src/PVE/HA/Sim/TestHardware.pm
index 0c7d6cd..c6ad238 100644
--- a/src/PVE/HA/Sim/TestHardware.pm
+++ b/src/PVE/HA/Sim/TestHardware.pm
@@ -87,7 +87,7 @@ sub log {
# reboot <node>
# shutdown <node>
# restart-lrm <node>
-# service <sid> <enabled|disabled>
+# service <sid> <enabled|disabled|stopped>
# service <sid> <migrate|relocate> <target>
# service <sid> lock/unlock [lockname]
@@ -175,7 +175,7 @@ sub sim_hardware_cmd {
}
} elsif ($cmd eq 'service') {
- if ($action eq 'enabled' || $action eq 'disabled') {
+ if ($action eq 'enabled' || $action eq 'disabled' || $action eq 'stopped') {
$self->set_service_state($sid, $action);
--
2.1.4
More information about the pve-devel
mailing list