[pve-devel] [PATCH RFC 2/3] implement start flag

Dietmar Maurer dietmar at proxmox.com
Mon Nov 14 12:23:58 CET 2016


Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
 src/PVE/HA/Manager.pm | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/src/PVE/HA/Manager.pm b/src/PVE/HA/Manager.pm
index e58fc0b..ab8e81d 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);
+	&$change_service_state($self, $sid, $cd->{start} ? 'started' : 'request_stop',
+			       node => $recovery_node);
     } else {
 	# no possible node found, cannot recover
 	$haenv->log('err', "recovering service '$sid' from fenced node " .
@@ -379,10 +380,12 @@ sub manage {
     # add new service
     foreach my $sid (sort keys %$sc) {
 	next if $ss->{$sid}; # already there
+	my $cd = $sc->{$sid};
 	$haenv->log('info', "adding new service '$sid' on node '$sc->{$sid}->{node}'");
 	# assume we are running to avoid relocate running service at add
-	$ss->{$sid} = { state => 'started', node => $sc->{$sid}->{node},
-			uid => compute_new_uuid('started') };
+	my $state = $cd->{start} ? 'started' : 'request_stop';
+	$ss->{$sid} = { state => $state, node => $cd->{node},
+			uid => compute_new_uuid($state) };
     }
 
     # remove stale service from manager state
@@ -432,7 +435,7 @@ sub manage {
 
 		my $lrm_mode = $sd->{node} ? $lrm_modes->{$sd->{node}} : undef;
 		# unfreeze
-		&$change_service_state($self, $sid, 'started') 
+		&$change_service_state($self, $sid, $cd->{start} ? 'started' : 'request_stop')
 		    if $lrm_mode && $lrm_mode eq 'active';
 
 	    } elsif ($last_state eq 'error') {
@@ -518,7 +521,8 @@ sub next_state_migrate_relocate {
     # check result from LRM daemon
     if ($lrm_res) {
 	my $exit_code = $lrm_res->{exit_code};
-	my $req_state = $cd->{state} eq 'enabled' ? 'started' : 'request_stop';
+	my $req_state = ($cd->{state} eq 'enabled' && $cd->{start}) ?
+	    'started' : 'request_stop';
 	if ($exit_code == SUCCESS) {
 	    &$change_service_state($self, $sid, $req_state, node => $sd->{target});
 	    return;
@@ -579,10 +583,17 @@ sub next_state_stopped {
 	return;
     }
 
+    if ($ns->node_is_offline_delayed($sd->{node})) {
+	&$change_service_state($self, $sid, 'fence');
+	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
-	&$change_service_state($self, $sid, 'started', node => $sd->{node});
+	if ($cd->{start}) {
+	    # simply mark it started, if it's on the wrong node
+	    # next_state_started will fix that for us
+	    &$change_service_state($self, $sid, 'started', node => $sd->{node});
+	}
 	return;
     }
 
@@ -613,7 +624,7 @@ sub next_state_started {
 	return;
     }
 	
-    if ($cd->{state} eq 'disabled') {
+    if ($cd->{state} eq 'disabled' || !$cd->{start} ) {
 	&$change_service_state($self, $sid, 'request_stop');
 	return;
     }
-- 
2.1.4




More information about the pve-devel mailing list