transition.c revision 99b44c3bba5a515aba1e56c2104f53af320a848d
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* transition.c - Graph State Machine
*
* The graph state machine is implemented here, with a typical approach
* of a function per state. Separating the implementation allows more
* clarity into the actions taken on notification of state change, as well
* as a place for future expansion including hooks for configurable actions.
* All functions are called with dgraph_lock held.
*
* The start action for this state machine is not explicit. The states
* (ONLINE and DEGRADED) which needs to know when they're entering the state
* due to a daemon restart implement this understanding by checking for
* transition from uninitialized. In the future, this would likely be better
* as an explicit start action instead of relying on an overloaded transition.
*
* All gt_enter functions use the same set of return codes.
* 0 success
* ECONNABORTED repository connection aborted
*/
#include "startd.h"
static int
{
if (state == RESTARTER_STATE_ONLINE ||
return (1);
return (0);
}
static int
{
int err;
/* Initialize instance by refreshing it. */
switch (err) {
case 0:
break;
case ECONNABORTED:
return (ECONNABORTED);
case ENOENT:
return (0);
case EINVAL:
case ENOTSUP:
default:
}
if (err == 0)
/* If the service was running, propagate a stop event. */
if (gt_running(old_state)) {
v->gv_name);
}
return (0);
}
static int
{
if (gt_running(old_state)) {
v->gv_name);
} else if (v->gv_state == RESTARTER_STATE_MAINT) {
v->gv_name);
}
return (0);
}
static int
{
/*
* If the instance should be enabled, see if we can start it.
* Otherwise send a disable command.
*/
if (v->gv_flags & GV_ENABLED) {
} else {
v->gv_post_disable_f();
}
if (gt_running(old_state)) {
v->gv_name);
}
return (0);
}
static int
{
/*
* If the instance should be disabled, no problem. Otherwise,
* send an enable command, which should result in the instance
* moving to OFFLINE.
*/
if (v->gv_flags & GV_ENABLED) {
v->gv_post_disable_f();
}
/*
* If the service was running, propagate this as a stop.
* Otherwise, we treat other transitions as a start propagate,
* since they can satisfy optional_all dependencies.
*/
if (gt_running(old_state)) {
v->gv_name);
} else if (v->gv_state == RESTARTER_STATE_DISABLED) {
v->gv_name);
}
return (0);
}
static int
{
int r;
/*
* If the instance has just come up, update the start
* snapshot.
*/
if (gt_running(old_state) == 0) {
/*
* Don't fire if we're just recovering state
* after a restart.
*/
if (old_state != RESTARTER_STATE_UNINIT &&
v->gv_post_online_f)
v->gv_post_online_f();
switch (r) {
case 0:
case ENOENT:
/*
* If ENOENT, the instance must have been
* deleted. Pretend we were successful since
* we should get a delete event later.
*/
break;
case ECONNABORTED:
return (ECONNABORTED);
case EACCES:
case ENOTSUP:
default:
bad_error("libscf_snapshots_poststart", r);
}
}
if (!(v->gv_flags & GV_ENABLED))
if (gt_running(old_state) == 0) {
v->gv_name);
} else if (rerr == RERR_REFRESH) {
/* For refresh we'll get a message sans state change */
v->gv_name);
}
return (0);
}
static int
{
int r;
if (r != 0)
return (r);
return (0);
}
static int
{
int r;
if (r != 0)
return (r);
return (0);
}
/*
* gt_transition() implements the state transition for the graph
* state machine. It can return:
* 0 success
* ECONNABORTED repository connection aborted
*/
int
{
int err = 0;
/*
* If there's a common set of work to be done on exit from the
* old_state, include it as a separate set of functions here. For
* now there's no such work, so there are no gt_exit functions.
*/
/*
* Now call the appropriate gt_enter function for the new state.
*/
switch (new_state) {
case RESTARTER_STATE_UNINIT:
break;
case RESTARTER_STATE_DISABLED:
break;
case RESTARTER_STATE_OFFLINE:
break;
case RESTARTER_STATE_ONLINE:
break;
case RESTARTER_STATE_DEGRADED:
break;
case RESTARTER_STATE_MAINT:
break;
default:
/* Shouldn't have been passed an invalid state. */
#ifndef NDEBUG
#endif
abort();
}
return (err);
}