xref: /titanic_50/usr/src/cmd/svc/startd/transition.c (revision aca380d78daaa1b42289bf234c6ab0bdd9afe538)
199b44c3bSlianep /*
299b44c3bSlianep  * CDDL HEADER START
399b44c3bSlianep  *
499b44c3bSlianep  * The contents of this file are subject to the terms of the
599b44c3bSlianep  * Common Development and Distribution License (the "License").
699b44c3bSlianep  * You may not use this file except in compliance with the License.
799b44c3bSlianep  *
899b44c3bSlianep  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
999b44c3bSlianep  * or http://www.opensolaris.org/os/licensing.
1099b44c3bSlianep  * See the License for the specific language governing permissions
1199b44c3bSlianep  * and limitations under the License.
1299b44c3bSlianep  *
1399b44c3bSlianep  * When distributing Covered Code, include this CDDL HEADER in each
1499b44c3bSlianep  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1599b44c3bSlianep  * If applicable, add the following below this CDDL HEADER, with the
1699b44c3bSlianep  * fields enclosed by brackets "[]" replaced with your own identifying
1799b44c3bSlianep  * information: Portions Copyright [yyyy] [name of copyright owner]
1899b44c3bSlianep  *
1999b44c3bSlianep  * CDDL HEADER END
2099b44c3bSlianep  */
2199b44c3bSlianep /*
22*aca380d7SRenaud Manus  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
2399b44c3bSlianep  * Use is subject to license terms.
2499b44c3bSlianep  */
2599b44c3bSlianep 
2699b44c3bSlianep 
2799b44c3bSlianep /*
2899b44c3bSlianep  * transition.c - Graph State Machine
2999b44c3bSlianep  *
3099b44c3bSlianep  * The graph state machine is implemented here, with a typical approach
3199b44c3bSlianep  * of a function per state.  Separating the implementation allows more
3299b44c3bSlianep  * clarity into the actions taken on notification of state change, as well
3399b44c3bSlianep  * as a place for future expansion including hooks for configurable actions.
3499b44c3bSlianep  * All functions are called with dgraph_lock held.
3599b44c3bSlianep  *
3699b44c3bSlianep  * The start action for this state machine is not explicit.  The states
3756e23938Sbustos  * (ONLINE and DEGRADED) which need to know when they're entering the state
3899b44c3bSlianep  * due to a daemon restart implement this understanding by checking for
3999b44c3bSlianep  * transition from uninitialized.  In the future, this would likely be better
4099b44c3bSlianep  * as an explicit start action instead of relying on an overloaded transition.
4199b44c3bSlianep  *
4299b44c3bSlianep  * All gt_enter functions use the same set of return codes.
4399b44c3bSlianep  *    0              success
4499b44c3bSlianep  *    ECONNABORTED   repository connection aborted
4599b44c3bSlianep  */
4699b44c3bSlianep 
4799b44c3bSlianep #include "startd.h"
4899b44c3bSlianep 
4999b44c3bSlianep static int
5099b44c3bSlianep gt_running(restarter_instance_state_t state)
5199b44c3bSlianep {
5299b44c3bSlianep 	if (state == RESTARTER_STATE_ONLINE ||
5399b44c3bSlianep 	    state == RESTARTER_STATE_DEGRADED)
5499b44c3bSlianep 		return (1);
5599b44c3bSlianep 
5699b44c3bSlianep 	return (0);
5799b44c3bSlianep }
5899b44c3bSlianep 
5999b44c3bSlianep static int
6099b44c3bSlianep gt_enter_uninit(scf_handle_t *h, graph_vertex_t *v,
6199b44c3bSlianep     restarter_instance_state_t old_state, restarter_error_t rerr)
6299b44c3bSlianep {
6399b44c3bSlianep 	int err;
6499b44c3bSlianep 	scf_instance_t *inst;
6599b44c3bSlianep 
6699b44c3bSlianep 	/* Initialize instance by refreshing it. */
6799b44c3bSlianep 
6899b44c3bSlianep 	err = libscf_fmri_get_instance(h, v->gv_name, &inst);
6999b44c3bSlianep 	switch (err) {
7099b44c3bSlianep 	case 0:
7199b44c3bSlianep 		break;
7299b44c3bSlianep 
7399b44c3bSlianep 	case ECONNABORTED:
7499b44c3bSlianep 		return (ECONNABORTED);
7599b44c3bSlianep 
7699b44c3bSlianep 	case ENOENT:
7799b44c3bSlianep 		return (0);
7899b44c3bSlianep 
7999b44c3bSlianep 	case EINVAL:
8099b44c3bSlianep 	case ENOTSUP:
8199b44c3bSlianep 	default:
8299b44c3bSlianep 		bad_error("libscf_fmri_get_instance", err);
8399b44c3bSlianep 	}
8499b44c3bSlianep 
8599b44c3bSlianep 	err = refresh_vertex(v, inst);
8699b44c3bSlianep 	if (err == 0)
8799b44c3bSlianep 		graph_enable_by_vertex(v, v->gv_flags & GV_ENABLED, 0);
8899b44c3bSlianep 
8999b44c3bSlianep 	scf_instance_destroy(inst);
9099b44c3bSlianep 
9199b44c3bSlianep 	/* If the service was running, propagate a stop event. */
9299b44c3bSlianep 	if (gt_running(old_state)) {
9399b44c3bSlianep 		log_framework(LOG_DEBUG, "Propagating stop of %s.\n",
9499b44c3bSlianep 		    v->gv_name);
9599b44c3bSlianep 
96cd3bce3eSlianep 		graph_transition_propagate(v, PROPAGATE_STOP, rerr);
9799b44c3bSlianep 	}
9899b44c3bSlianep 
9999b44c3bSlianep 	graph_transition_sulogin(RESTARTER_STATE_UNINIT, old_state);
10099b44c3bSlianep 	return (0);
10199b44c3bSlianep }
10299b44c3bSlianep 
10356e23938Sbustos /* ARGSUSED */
10499b44c3bSlianep static int
10599b44c3bSlianep gt_enter_maint(scf_handle_t *h, graph_vertex_t *v,
10699b44c3bSlianep     restarter_instance_state_t old_state, restarter_error_t rerr)
10799b44c3bSlianep {
108cd3bce3eSlianep 	/*
109cd3bce3eSlianep 	 * If the service was running, propagate a stop event.  If the
110cd3bce3eSlianep 	 * service was not running the maintenance transition may satisfy
111cd3bce3eSlianep 	 * optional dependencies and should be propagated to determine
112cd3bce3eSlianep 	 * whether new dependents are satisfiable.
113*aca380d7SRenaud Manus 	 * Instances that transition to maintenance and have the GV_TOOFFLINE
114*aca380d7SRenaud Manus 	 * flag are special because they can expose new subtree leaves so
115*aca380d7SRenaud Manus 	 * propagate the offline to the instance dependencies.
116cd3bce3eSlianep 	 */
11799b44c3bSlianep 	if (gt_running(old_state)) {
118*aca380d7SRenaud Manus 		/*
119*aca380d7SRenaud Manus 		 * Handle state change during instance disabling.
120*aca380d7SRenaud Manus 		 * Propagate offline to the new exposed leaves.
121*aca380d7SRenaud Manus 		 */
122*aca380d7SRenaud Manus 		if (v->gv_flags & GV_TOOFFLINE) {
123*aca380d7SRenaud Manus 			v->gv_flags &= ~GV_TOOFFLINE;
124*aca380d7SRenaud Manus 			log_framework(LOG_DEBUG, "%s removed from subtree\n",
125*aca380d7SRenaud Manus 			    v->gv_name);
126*aca380d7SRenaud Manus 			graph_offline_subtree_leaves(v, (void *)h);
127*aca380d7SRenaud Manus 		}
128*aca380d7SRenaud Manus 
129cd3bce3eSlianep 		log_framework(LOG_DEBUG, "Propagating maintenance (stop) of "
130cd3bce3eSlianep 		    "%s.\n", v->gv_name);
13199b44c3bSlianep 
132cd3bce3eSlianep 		graph_transition_propagate(v, PROPAGATE_STOP, rerr);
133cd3bce3eSlianep 	} else {
13499b44c3bSlianep 		log_framework(LOG_DEBUG, "Propagating maintenance of %s.\n",
13599b44c3bSlianep 		    v->gv_name);
13699b44c3bSlianep 
137cd3bce3eSlianep 		graph_transition_propagate(v, PROPAGATE_SAT, rerr);
13899b44c3bSlianep 	}
13999b44c3bSlianep 
14099b44c3bSlianep 	graph_transition_sulogin(RESTARTER_STATE_MAINT, old_state);
14199b44c3bSlianep 	return (0);
14299b44c3bSlianep }
14399b44c3bSlianep 
14456e23938Sbustos /* ARGSUSED */
14599b44c3bSlianep static int
14699b44c3bSlianep gt_enter_offline(scf_handle_t *h, graph_vertex_t *v,
14799b44c3bSlianep     restarter_instance_state_t old_state, restarter_error_t rerr)
14899b44c3bSlianep {
14999b44c3bSlianep 	/*
15099b44c3bSlianep 	 * If the instance should be enabled, see if we can start it.
15199b44c3bSlianep 	 * Otherwise send a disable command.
152*aca380d7SRenaud Manus 	 * If a instance has the GV_TOOFFLINE flag set then it must
153*aca380d7SRenaud Manus 	 * remains offline until the disable process completes.
15499b44c3bSlianep 	 */
15599b44c3bSlianep 	if (v->gv_flags & GV_ENABLED) {
156*aca380d7SRenaud Manus 		if (!(v->gv_flags & GV_TOOFFLINE))
15799b44c3bSlianep 			graph_start_if_satisfied(v);
15899b44c3bSlianep 	} else {
15999b44c3bSlianep 		if (gt_running(old_state) && v->gv_post_disable_f)
16099b44c3bSlianep 			v->gv_post_disable_f();
161*aca380d7SRenaud Manus 
16299b44c3bSlianep 		vertex_send_event(v, RESTARTER_EVENT_TYPE_DISABLE);
16399b44c3bSlianep 	}
16499b44c3bSlianep 
16573b709eaSrm88369 	/*
16673b709eaSrm88369 	 * If the service was running, propagate a stop event.  If the
16773b709eaSrm88369 	 * service was not running the offline transition may satisfy
16873b709eaSrm88369 	 * optional dependencies and should be propagated to determine
16973b709eaSrm88369 	 * whether new dependents are satisfiable.
170*aca380d7SRenaud Manus 	 * Instances that transition to offline and have the GV_TOOFFLINE flag
171*aca380d7SRenaud Manus 	 * are special because they can expose new subtree leaves so propagate
172*aca380d7SRenaud Manus 	 * the offline to the instance dependencies.
17373b709eaSrm88369 	 */
17499b44c3bSlianep 	if (gt_running(old_state)) {
175*aca380d7SRenaud Manus 		/*
176*aca380d7SRenaud Manus 		 * Handle state change during instance disabling.
177*aca380d7SRenaud Manus 		 * Propagate offline to the new exposed leaves.
178*aca380d7SRenaud Manus 		 */
179*aca380d7SRenaud Manus 		if (v->gv_flags & GV_TOOFFLINE) {
180*aca380d7SRenaud Manus 			v->gv_flags &= ~GV_TOOFFLINE;
181*aca380d7SRenaud Manus 			log_framework(LOG_DEBUG, "%s removed from subtree\n",
182*aca380d7SRenaud Manus 			    v->gv_name);
183*aca380d7SRenaud Manus 			graph_offline_subtree_leaves(v, (void *)h);
184*aca380d7SRenaud Manus 		}
185*aca380d7SRenaud Manus 
18699b44c3bSlianep 		log_framework(LOG_DEBUG, "Propagating stop of %s.\n",
18799b44c3bSlianep 		    v->gv_name);
18899b44c3bSlianep 
189cd3bce3eSlianep 		graph_transition_propagate(v, PROPAGATE_STOP, rerr);
19073b709eaSrm88369 	} else {
19173b709eaSrm88369 		log_framework(LOG_DEBUG, "Propagating offline of %s.\n",
19273b709eaSrm88369 		    v->gv_name);
19373b709eaSrm88369 
19473b709eaSrm88369 		graph_transition_propagate(v, PROPAGATE_SAT, rerr);
19599b44c3bSlianep 	}
19699b44c3bSlianep 
19799b44c3bSlianep 	graph_transition_sulogin(RESTARTER_STATE_OFFLINE, old_state);
19899b44c3bSlianep 	return (0);
19999b44c3bSlianep }
20099b44c3bSlianep 
20156e23938Sbustos /* ARGSUSED */
20299b44c3bSlianep static int
20399b44c3bSlianep gt_enter_disabled(scf_handle_t *h, graph_vertex_t *v,
20499b44c3bSlianep     restarter_instance_state_t old_state, restarter_error_t rerr)
20599b44c3bSlianep {
206*aca380d7SRenaud Manus 
20799b44c3bSlianep 	/*
20899b44c3bSlianep 	 * If the instance should be disabled, no problem.  Otherwise,
20999b44c3bSlianep 	 * send an enable command, which should result in the instance
210*aca380d7SRenaud Manus 	 * moving to OFFLINE unless the instance is part of a subtree
211*aca380d7SRenaud Manus 	 * (non root) and in this case the result is unpredictable.
21299b44c3bSlianep 	 */
21399b44c3bSlianep 	if (v->gv_flags & GV_ENABLED) {
21499b44c3bSlianep 		vertex_send_event(v, RESTARTER_EVENT_TYPE_ENABLE);
21599b44c3bSlianep 	} else if (gt_running(old_state) && v->gv_post_disable_f) {
21699b44c3bSlianep 		v->gv_post_disable_f();
21799b44c3bSlianep 	}
21899b44c3bSlianep 
21999b44c3bSlianep 	/*
220cd3bce3eSlianep 	 * If the service was running, propagate this as a stop.  If the
221cd3bce3eSlianep 	 * service was not running the disabled transition may satisfy
222cd3bce3eSlianep 	 * optional dependencies and should be propagated to determine
223cd3bce3eSlianep 	 * whether new dependents are satisfiable.
22499b44c3bSlianep 	 */
22599b44c3bSlianep 	if (gt_running(old_state)) {
226*aca380d7SRenaud Manus 		/*
227*aca380d7SRenaud Manus 		 * We need to propagate the offline to new exposed leaves in
228*aca380d7SRenaud Manus 		 * case we've just disabled an instance that was part of a
229*aca380d7SRenaud Manus 		 * subtree.
230*aca380d7SRenaud Manus 		 */
231*aca380d7SRenaud Manus 		if (v->gv_flags & GV_TOOFFLINE) {
232*aca380d7SRenaud Manus 			/*
233*aca380d7SRenaud Manus 			 * If the vertex is in the subtree and is transitionning
234*aca380d7SRenaud Manus 			 * to DISABLED then remove the GV_TODISABLE flag also.
235*aca380d7SRenaud Manus 			 */
236*aca380d7SRenaud Manus 			v->gv_flags &= ~GV_TODISABLE;
237*aca380d7SRenaud Manus 			v->gv_flags &= ~GV_TOOFFLINE;
238*aca380d7SRenaud Manus 
239*aca380d7SRenaud Manus 			log_framework(LOG_DEBUG, "%s removed from subtree\n",
240*aca380d7SRenaud Manus 			    v->gv_name);
241*aca380d7SRenaud Manus 
242*aca380d7SRenaud Manus 			/*
243*aca380d7SRenaud Manus 			 * Handle state change during instance disabling.
244*aca380d7SRenaud Manus 			 * Propagate offline to the new exposed leaves.
245*aca380d7SRenaud Manus 			 */
246*aca380d7SRenaud Manus 			graph_offline_subtree_leaves(v, (void *)h);
247*aca380d7SRenaud Manus 		}
248*aca380d7SRenaud Manus 
249*aca380d7SRenaud Manus 
25099b44c3bSlianep 		log_framework(LOG_DEBUG, "Propagating stop of %s.\n",
25199b44c3bSlianep 		    v->gv_name);
25299b44c3bSlianep 
253cd3bce3eSlianep 		graph_transition_propagate(v, PROPAGATE_STOP, rerr);
25499b44c3bSlianep 
255cd3bce3eSlianep 	} else {
25699b44c3bSlianep 		log_framework(LOG_DEBUG, "Propagating disable of %s.\n",
25799b44c3bSlianep 		    v->gv_name);
25899b44c3bSlianep 
259cd3bce3eSlianep 		graph_transition_propagate(v, PROPAGATE_SAT, rerr);
26099b44c3bSlianep 	}
26199b44c3bSlianep 
26299b44c3bSlianep 	graph_transition_sulogin(RESTARTER_STATE_DISABLED, old_state);
26399b44c3bSlianep 	return (0);
26499b44c3bSlianep }
26599b44c3bSlianep 
26699b44c3bSlianep static int
26799b44c3bSlianep gt_internal_online_or_degraded(scf_handle_t *h, graph_vertex_t *v,
26899b44c3bSlianep     restarter_instance_state_t old_state, restarter_error_t rerr)
26999b44c3bSlianep {
27099b44c3bSlianep 	int r;
27199b44c3bSlianep 
27299b44c3bSlianep 	/*
27399b44c3bSlianep 	 * If the instance has just come up, update the start
27499b44c3bSlianep 	 * snapshot.
27599b44c3bSlianep 	 */
27699b44c3bSlianep 	if (gt_running(old_state) == 0) {
27799b44c3bSlianep 		/*
27899b44c3bSlianep 		 * Don't fire if we're just recovering state
27999b44c3bSlianep 		 * after a restart.
28099b44c3bSlianep 		 */
28199b44c3bSlianep 		if (old_state != RESTARTER_STATE_UNINIT &&
28299b44c3bSlianep 		    v->gv_post_online_f)
28399b44c3bSlianep 			v->gv_post_online_f();
28499b44c3bSlianep 
28599b44c3bSlianep 		r = libscf_snapshots_poststart(h, v->gv_name, B_TRUE);
28699b44c3bSlianep 		switch (r) {
28799b44c3bSlianep 		case 0:
28899b44c3bSlianep 		case ENOENT:
28999b44c3bSlianep 			/*
29099b44c3bSlianep 			 * If ENOENT, the instance must have been
29199b44c3bSlianep 			 * deleted.  Pretend we were successful since
29299b44c3bSlianep 			 * we should get a delete event later.
29399b44c3bSlianep 			 */
29499b44c3bSlianep 			break;
29599b44c3bSlianep 
29699b44c3bSlianep 		case ECONNABORTED:
29799b44c3bSlianep 			return (ECONNABORTED);
29899b44c3bSlianep 
29999b44c3bSlianep 		case EACCES:
30099b44c3bSlianep 		case ENOTSUP:
30199b44c3bSlianep 		default:
30299b44c3bSlianep 			bad_error("libscf_snapshots_poststart", r);
30399b44c3bSlianep 		}
30499b44c3bSlianep 	}
30599b44c3bSlianep 	if (!(v->gv_flags & GV_ENABLED))
30699b44c3bSlianep 		vertex_send_event(v, RESTARTER_EVENT_TYPE_DISABLE);
30799b44c3bSlianep 
30899b44c3bSlianep 	if (gt_running(old_state) == 0) {
30999b44c3bSlianep 		log_framework(LOG_DEBUG, "Propagating start of %s.\n",
31099b44c3bSlianep 		    v->gv_name);
31199b44c3bSlianep 
312cd3bce3eSlianep 		graph_transition_propagate(v, PROPAGATE_START, rerr);
31399b44c3bSlianep 	} else if (rerr == RERR_REFRESH) {
31499b44c3bSlianep 		/* For refresh we'll get a message sans state change */
31599b44c3bSlianep 
31699b44c3bSlianep 		log_framework(LOG_DEBUG, "Propagating refresh of %s.\n",
31799b44c3bSlianep 		    v->gv_name);
31899b44c3bSlianep 
319cd3bce3eSlianep 		graph_transition_propagate(v, PROPAGATE_STOP, rerr);
32099b44c3bSlianep 	}
32199b44c3bSlianep 
32299b44c3bSlianep 	return (0);
32399b44c3bSlianep }
32499b44c3bSlianep 
32599b44c3bSlianep static int
32699b44c3bSlianep gt_enter_online(scf_handle_t *h, graph_vertex_t *v,
32799b44c3bSlianep     restarter_instance_state_t old_state, restarter_error_t rerr)
32899b44c3bSlianep {
32999b44c3bSlianep 	int r;
33099b44c3bSlianep 
33199b44c3bSlianep 	r = gt_internal_online_or_degraded(h, v, old_state, rerr);
33299b44c3bSlianep 	if (r != 0)
33399b44c3bSlianep 		return (r);
33499b44c3bSlianep 
33599b44c3bSlianep 	graph_transition_sulogin(RESTARTER_STATE_ONLINE, old_state);
33699b44c3bSlianep 	return (0);
33799b44c3bSlianep }
33899b44c3bSlianep 
33999b44c3bSlianep static int
34099b44c3bSlianep gt_enter_degraded(scf_handle_t *h, graph_vertex_t *v,
34199b44c3bSlianep     restarter_instance_state_t old_state, restarter_error_t rerr)
34299b44c3bSlianep {
34399b44c3bSlianep 	int r;
34499b44c3bSlianep 
34599b44c3bSlianep 	r = gt_internal_online_or_degraded(h, v, old_state, rerr);
34699b44c3bSlianep 	if (r != 0)
34799b44c3bSlianep 		return (r);
34899b44c3bSlianep 
34999b44c3bSlianep 	graph_transition_sulogin(RESTARTER_STATE_DEGRADED, old_state);
35099b44c3bSlianep 	return (0);
35199b44c3bSlianep }
35299b44c3bSlianep 
35399b44c3bSlianep /*
35499b44c3bSlianep  * gt_transition() implements the state transition for the graph
35599b44c3bSlianep  * state machine.  It can return:
35699b44c3bSlianep  *    0              success
35799b44c3bSlianep  *    ECONNABORTED   repository connection aborted
358cd3bce3eSlianep  *
359cd3bce3eSlianep  * v->gv_state should be set to the state we're transitioning to before
360cd3bce3eSlianep  * calling this function.
36199b44c3bSlianep  */
36299b44c3bSlianep int
36399b44c3bSlianep gt_transition(scf_handle_t *h, graph_vertex_t *v, restarter_error_t rerr,
364cd3bce3eSlianep     restarter_instance_state_t old_state)
36599b44c3bSlianep {
36656e23938Sbustos 	int err;
36756e23938Sbustos 	int lost_repository = 0;
36899b44c3bSlianep 
36999b44c3bSlianep 	/*
37099b44c3bSlianep 	 * If there's a common set of work to be done on exit from the
37199b44c3bSlianep 	 * old_state, include it as a separate set of functions here.  For
37299b44c3bSlianep 	 * now there's no such work, so there are no gt_exit functions.
37399b44c3bSlianep 	 */
37499b44c3bSlianep 
37556e23938Sbustos 	err = vertex_subgraph_dependencies_shutdown(h, v, old_state);
37656e23938Sbustos 	switch (err) {
37756e23938Sbustos 	case 0:
37856e23938Sbustos 		break;
37956e23938Sbustos 
38056e23938Sbustos 	case ECONNABORTED:
38156e23938Sbustos 		lost_repository = 1;
38256e23938Sbustos 		break;
38356e23938Sbustos 
38456e23938Sbustos 	default:
38556e23938Sbustos 		bad_error("vertex_subgraph_dependencies_shutdown", err);
38656e23938Sbustos 	}
38756e23938Sbustos 
38899b44c3bSlianep 	/*
38999b44c3bSlianep 	 * Now call the appropriate gt_enter function for the new state.
39099b44c3bSlianep 	 */
391cd3bce3eSlianep 	switch (v->gv_state) {
39299b44c3bSlianep 	case RESTARTER_STATE_UNINIT:
39399b44c3bSlianep 		err = gt_enter_uninit(h, v, old_state, rerr);
39499b44c3bSlianep 		break;
39599b44c3bSlianep 
39699b44c3bSlianep 	case RESTARTER_STATE_DISABLED:
39799b44c3bSlianep 		err = gt_enter_disabled(h, v, old_state, rerr);
39899b44c3bSlianep 		break;
39999b44c3bSlianep 
40099b44c3bSlianep 	case RESTARTER_STATE_OFFLINE:
40199b44c3bSlianep 		err = gt_enter_offline(h, v, old_state, rerr);
40299b44c3bSlianep 		break;
40399b44c3bSlianep 
40499b44c3bSlianep 	case RESTARTER_STATE_ONLINE:
40599b44c3bSlianep 		err = gt_enter_online(h, v, old_state, rerr);
40699b44c3bSlianep 		break;
40799b44c3bSlianep 
40899b44c3bSlianep 	case RESTARTER_STATE_DEGRADED:
40999b44c3bSlianep 		err = gt_enter_degraded(h, v, old_state, rerr);
41099b44c3bSlianep 		break;
41199b44c3bSlianep 
41299b44c3bSlianep 	case RESTARTER_STATE_MAINT:
41399b44c3bSlianep 		err = gt_enter_maint(h, v, old_state, rerr);
41499b44c3bSlianep 		break;
41599b44c3bSlianep 
41699b44c3bSlianep 	default:
417cd3bce3eSlianep 		/* Shouldn't be in an invalid state. */
41899b44c3bSlianep #ifndef NDEBUG
41956e23938Sbustos 		uu_warn("%s:%d: Invalid state %d.\n", __FILE__, __LINE__,
420cd3bce3eSlianep 		    v->gv_state);
42199b44c3bSlianep #endif
42299b44c3bSlianep 		abort();
42399b44c3bSlianep 	}
42499b44c3bSlianep 
42556e23938Sbustos 	switch (err) {
42656e23938Sbustos 	case 0:
42756e23938Sbustos 		break;
42856e23938Sbustos 
42956e23938Sbustos 	case ECONNABORTED:
43056e23938Sbustos 		lost_repository = 1;
43156e23938Sbustos 		break;
43256e23938Sbustos 
43356e23938Sbustos 	default:
43456e23938Sbustos #ifndef NDEBUG
43556e23938Sbustos 		uu_warn("%s:%d: "
43656e23938Sbustos 		    "gt_enter_%s() failed with unexpected error %d.\n",
43756e23938Sbustos 		    __FILE__, __LINE__, instance_state_str[v->gv_state], err);
43856e23938Sbustos #endif
43956e23938Sbustos 		abort();
44056e23938Sbustos 	}
44156e23938Sbustos 
44256e23938Sbustos 	return (lost_repository ? ECONNABORTED : 0);
44399b44c3bSlianep }
444