dhodovsk / source-git / pacemaker

Forked from source-git/pacemaker 3 years ago
Clone

Blame daemons/controld/controld_fsa.c

rpm-build 3ee90c
/*
rpm-build 3ee90c
 * Copyright 2004-2019 the Pacemaker project contributors
rpm-build 3ee90c
 *
rpm-build 3ee90c
 * The version control history for this file may have further details.
rpm-build 3ee90c
 *
rpm-build 3ee90c
 * This source code is licensed under the GNU General Public License version 2
rpm-build 3ee90c
 * or later (GPLv2+) WITHOUT ANY WARRANTY.
rpm-build 3ee90c
 */
rpm-build 3ee90c
rpm-build 3ee90c
#include <crm_internal.h>
rpm-build 3ee90c
rpm-build 3ee90c
#include <sys/param.h>
rpm-build 3ee90c
#include <stdio.h>
rpm-build 3ee90c
#include <string.h>
rpm-build 3ee90c
#include <time.h>
rpm-build 3ee90c
rpm-build 3ee90c
#include <crm/crm.h>
rpm-build 3ee90c
#include <crm/lrmd.h>
rpm-build 3ee90c
#include <crm/cib.h>
rpm-build 3ee90c
#include <crm/msg_xml.h>
rpm-build 3ee90c
#include <crm/common/xml.h>
rpm-build 3ee90c
#include <crm/cluster/election.h>
rpm-build 3ee90c
#include <crm/cluster.h>
rpm-build 3ee90c
rpm-build 3ee90c
#include <pacemaker-controld.h>
rpm-build 3ee90c
#include <controld_matrix.h>
rpm-build 3ee90c
rpm-build 3ee90c
char *fsa_our_dc = NULL;
rpm-build 3ee90c
cib_t *fsa_cib_conn = NULL;
rpm-build 3ee90c
char *fsa_our_dc_version = NULL;
rpm-build 3ee90c
rpm-build 3ee90c
char *fsa_our_uuid = NULL;
rpm-build 3ee90c
char *fsa_our_uname = NULL;
rpm-build 3ee90c
rpm-build 3ee90c
char *fsa_cluster_name = NULL;
rpm-build 3ee90c
rpm-build 3ee90c
gboolean do_fsa_stall = FALSE;
rpm-build 3ee90c
long long fsa_input_register = 0;
rpm-build 3ee90c
long long fsa_actions = A_NOTHING;
rpm-build 3ee90c
enum crmd_fsa_state fsa_state = S_STARTING;
rpm-build 3ee90c
rpm-build 3ee90c
extern uint highest_born_on;
rpm-build 3ee90c
extern uint num_join_invites;
rpm-build 3ee90c
extern void initialize_join(gboolean before);
rpm-build 3ee90c
rpm-build 3ee90c
#define DOT_PREFIX "actions:trace: "
rpm-build 3ee90c
#define do_dot_log(fmt, args...)     crm_trace( fmt, ##args)
rpm-build 3ee90c
rpm-build 3ee90c
long long do_state_transition(long long actions,
rpm-build 3ee90c
                              enum crmd_fsa_state cur_state,
rpm-build 3ee90c
                              enum crmd_fsa_state next_state, fsa_data_t * msg_data);
rpm-build 3ee90c
rpm-build 3ee90c
void s_crmd_fsa_actions(fsa_data_t * fsa_data);
rpm-build 3ee90c
void log_fsa_input(fsa_data_t * stored_msg);
rpm-build 3ee90c
void init_dotfile(void);
rpm-build 3ee90c
rpm-build 3ee90c
void
rpm-build 3ee90c
init_dotfile(void)
rpm-build 3ee90c
{
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "digraph \"g\" {");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "	size = \"30,30\"");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "	graph [");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "		fontsize = \"12\"");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "		fontname = \"Times-Roman\"");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "		fontcolor = \"black\"");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "		bb = \"0,0,398.922306,478.927856\"");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "		color = \"black\"");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "	]");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "	node [");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "		fontsize = \"12\"");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "		fontname = \"Times-Roman\"");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "		fontcolor = \"black\"");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "		shape = \"ellipse\"");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "		color = \"black\"");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "	]");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "	edge [");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "		fontsize = \"12\"");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "		fontname = \"Times-Roman\"");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "		fontcolor = \"black\"");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "		color = \"black\"");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "	]");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "// special nodes");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "	\"S_PENDING\" ");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "	[");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "	 color = \"blue\"");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "	 fontcolor = \"blue\"");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "	 ]");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "	\"S_TERMINATE\" ");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "	[");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "	 color = \"red\"");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "	 fontcolor = \"red\"");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "	 ]");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "// DC only nodes");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "	\"S_INTEGRATION\" [ fontcolor = \"green\" ]");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "	\"S_POLICY_ENGINE\" [ fontcolor = \"green\" ]");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "	\"S_TRANSITION_ENGINE\" [ fontcolor = \"green\" ]");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "	\"S_RELEASE_DC\" [ fontcolor = \"green\" ]");
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "	\"S_IDLE\" [ fontcolor = \"green\" ]");
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
static void
rpm-build 3ee90c
do_fsa_action(fsa_data_t * fsa_data, long long an_action,
rpm-build 3ee90c
              void (*function) (long long action,
rpm-build 3ee90c
                                enum crmd_fsa_cause cause,
rpm-build 3ee90c
                                enum crmd_fsa_state cur_state,
rpm-build 3ee90c
                                enum crmd_fsa_input cur_input, fsa_data_t * msg_data))
rpm-build 3ee90c
{
rpm-build 3ee90c
    fsa_actions &= ~an_action;
rpm-build 3ee90c
    crm_trace(DOT_PREFIX "\t// %s", fsa_action2string(an_action));
rpm-build 3ee90c
    function(an_action, fsa_data->fsa_cause, fsa_state, fsa_data->fsa_input, fsa_data);
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
static long long startup_actions =
rpm-build 3ee90c
    A_STARTUP | A_CIB_START | A_LRM_CONNECT | A_HA_CONNECT | A_READCONFIG |
rpm-build 3ee90c
    A_STARTED | A_CL_JOIN_QUERY;
rpm-build 3ee90c
rpm-build 3ee90c
// A_LOG, A_WARN, A_ERROR
rpm-build 3ee90c
void
rpm-build 3ee90c
do_log(long long action, enum crmd_fsa_cause cause,
rpm-build 3ee90c
       enum crmd_fsa_state cur_state,
rpm-build 3ee90c
       enum crmd_fsa_input current_input, fsa_data_t *msg_data)
rpm-build 3ee90c
{
rpm-build 3ee90c
    unsigned log_type = LOG_TRACE;
rpm-build 3ee90c
rpm-build 3ee90c
    if (action & A_LOG) {
rpm-build 3ee90c
        log_type = LOG_INFO;
rpm-build 3ee90c
    } else if (action & A_WARN) {
rpm-build 3ee90c
        log_type = LOG_WARNING;
rpm-build 3ee90c
    } else if (action & A_ERROR) {
rpm-build 3ee90c
        log_type = LOG_ERR;
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    do_crm_log(log_type, "Input %s received in state %s from %s",
rpm-build 3ee90c
               fsa_input2string(msg_data->fsa_input),
rpm-build 3ee90c
               fsa_state2string(cur_state), msg_data->origin);
rpm-build 3ee90c
rpm-build 3ee90c
    if (msg_data->data_type == fsa_dt_ha_msg) {
rpm-build 3ee90c
        ha_msg_input_t *input = fsa_typed_data(msg_data->data_type);
rpm-build 3ee90c
rpm-build 3ee90c
        crm_log_xml_debug(input->msg, __FUNCTION__);
rpm-build 3ee90c
rpm-build 3ee90c
    } else if (msg_data->data_type == fsa_dt_xml) {
rpm-build 3ee90c
        xmlNode *input = fsa_typed_data(msg_data->data_type);
rpm-build 3ee90c
rpm-build 3ee90c
        crm_log_xml_debug(input, __FUNCTION__);
rpm-build 3ee90c
rpm-build 3ee90c
    } else if (msg_data->data_type == fsa_dt_lrm) {
rpm-build 3ee90c
        lrmd_event_data_t *input = fsa_typed_data(msg_data->data_type);
rpm-build 3ee90c
rpm-build 3ee90c
        do_crm_log(log_type,
rpm-build 3ee90c
                   "Resource %s: Call ID %d returned %d (%d)."
rpm-build 3ee90c
                   "  New status if rc=0: %s",
rpm-build 3ee90c
                   input->rsc_id, input->call_id, input->rc,
rpm-build 3ee90c
                   input->op_status, (char *)input->user_data);
rpm-build 3ee90c
    }
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
enum crmd_fsa_state
rpm-build 3ee90c
s_crmd_fsa(enum crmd_fsa_cause cause)
rpm-build 3ee90c
{
rpm-build 3ee90c
    fsa_data_t *fsa_data = NULL;
rpm-build 3ee90c
    long long register_copy = fsa_input_register;
rpm-build 3ee90c
    long long new_actions = A_NOTHING;
rpm-build 3ee90c
    enum crmd_fsa_state last_state;
rpm-build 3ee90c
rpm-build 3ee90c
    crm_trace("FSA invoked with Cause: %s\tState: %s",
rpm-build 3ee90c
              fsa_cause2string(cause), fsa_state2string(fsa_state));
rpm-build 3ee90c
rpm-build 3ee90c
    fsa_dump_actions(fsa_actions, "Initial");
rpm-build 3ee90c
rpm-build 3ee90c
    do_fsa_stall = FALSE;
rpm-build 3ee90c
    if (is_message() == FALSE && fsa_actions != A_NOTHING) {
rpm-build 3ee90c
        /* fake the first message so we can get into the loop */
rpm-build 3ee90c
        fsa_data = calloc(1, sizeof(fsa_data_t));
rpm-build 3ee90c
        fsa_data->fsa_input = I_NULL;
rpm-build 3ee90c
        fsa_data->fsa_cause = C_FSA_INTERNAL;
rpm-build 3ee90c
        fsa_data->origin = __FUNCTION__;
rpm-build 3ee90c
        fsa_data->data_type = fsa_dt_none;
rpm-build 3ee90c
        fsa_message_queue = g_list_append(fsa_message_queue, fsa_data);
rpm-build 3ee90c
        fsa_data = NULL;
rpm-build 3ee90c
    }
rpm-build 3ee90c
    while (is_message() && do_fsa_stall == FALSE) {
rpm-build 3ee90c
        crm_trace("Checking messages (%d remaining)", g_list_length(fsa_message_queue));
rpm-build 3ee90c
rpm-build 3ee90c
        fsa_data = get_message();
rpm-build 3ee90c
        if(fsa_data == NULL) {
rpm-build 3ee90c
            continue;
rpm-build 3ee90c
        }
rpm-build 3ee90c
rpm-build 3ee90c
        log_fsa_input(fsa_data);
rpm-build 3ee90c
rpm-build 3ee90c
        /* add any actions back to the queue */
rpm-build 3ee90c
        fsa_actions |= fsa_data->actions;
rpm-build 3ee90c
        fsa_dump_actions(fsa_data->actions, "Restored actions");
rpm-build 3ee90c
rpm-build 3ee90c
        /* get the next batch of actions */
rpm-build 3ee90c
        new_actions = crmd_fsa_actions[fsa_data->fsa_input][fsa_state];
rpm-build 3ee90c
        fsa_actions |= new_actions;
rpm-build 3ee90c
        fsa_dump_actions(new_actions, "New actions");
rpm-build 3ee90c
rpm-build 3ee90c
        if (fsa_data->fsa_input != I_NULL && fsa_data->fsa_input != I_ROUTER) {
rpm-build 3ee90c
            crm_debug("Processing %s: [ state=%s cause=%s origin=%s ]",
rpm-build 3ee90c
                      fsa_input2string(fsa_data->fsa_input),
rpm-build 3ee90c
                      fsa_state2string(fsa_state),
rpm-build 3ee90c
                      fsa_cause2string(fsa_data->fsa_cause), fsa_data->origin);
rpm-build 3ee90c
        }
rpm-build 3ee90c
rpm-build 3ee90c
        /* logging : *before* the state is changed */
rpm-build 3ee90c
        if (is_set(fsa_actions, A_ERROR)) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_ERROR, do_log);
rpm-build 3ee90c
        }
rpm-build 3ee90c
        if (is_set(fsa_actions, A_WARN)) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_WARN, do_log);
rpm-build 3ee90c
        }
rpm-build 3ee90c
        if (is_set(fsa_actions, A_LOG)) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_LOG, do_log);
rpm-build 3ee90c
        }
rpm-build 3ee90c
rpm-build 3ee90c
        /* update state variables */
rpm-build 3ee90c
        last_state = fsa_state;
rpm-build 3ee90c
        fsa_state = crmd_fsa_state[fsa_data->fsa_input][fsa_state];
rpm-build 3ee90c
rpm-build 3ee90c
        /*
rpm-build 3ee90c
         * Remove certain actions during shutdown
rpm-build 3ee90c
         */
rpm-build 3ee90c
        if (fsa_state == S_STOPPING || ((fsa_input_register & R_SHUTDOWN) == R_SHUTDOWN)) {
rpm-build 3ee90c
            clear_bit(fsa_actions, startup_actions);
rpm-build 3ee90c
        }
rpm-build 3ee90c
rpm-build 3ee90c
        /*
rpm-build 3ee90c
         * Hook for change of state.
rpm-build 3ee90c
         * Allows actions to be added or removed when entering a state
rpm-build 3ee90c
         */
rpm-build 3ee90c
        if (last_state != fsa_state) {
rpm-build 3ee90c
            fsa_actions = do_state_transition(fsa_actions, last_state, fsa_state, fsa_data);
rpm-build 3ee90c
        } else {
rpm-build 3ee90c
            do_dot_log(DOT_PREFIX "\t// FSA input: State=%s \tCause=%s"
rpm-build 3ee90c
                       " \tInput=%s \tOrigin=%s() \tid=%d",
rpm-build 3ee90c
                       fsa_state2string(fsa_state),
rpm-build 3ee90c
                       fsa_cause2string(fsa_data->fsa_cause),
rpm-build 3ee90c
                       fsa_input2string(fsa_data->fsa_input), fsa_data->origin, fsa_data->id);
rpm-build 3ee90c
        }
rpm-build 3ee90c
rpm-build 3ee90c
        /* start doing things... */
rpm-build 3ee90c
        s_crmd_fsa_actions(fsa_data);
rpm-build 3ee90c
        delete_fsa_input(fsa_data);
rpm-build 3ee90c
        fsa_data = NULL;
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    if (g_list_length(fsa_message_queue) > 0 || fsa_actions != A_NOTHING || do_fsa_stall) {
rpm-build 3ee90c
        crm_debug("Exiting the FSA: queue=%d, fsa_actions=0x%llx, stalled=%s",
rpm-build 3ee90c
                  g_list_length(fsa_message_queue), fsa_actions, do_fsa_stall ? "true" : "false");
rpm-build 3ee90c
    } else {
rpm-build 3ee90c
        crm_trace("Exiting the FSA");
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    /* cleanup inputs? */
rpm-build 3ee90c
    if (register_copy != fsa_input_register) {
rpm-build 3ee90c
        long long same = register_copy & fsa_input_register;
rpm-build 3ee90c
rpm-build 3ee90c
        fsa_dump_inputs(LOG_DEBUG, "Added", fsa_input_register ^ same);
rpm-build 3ee90c
        fsa_dump_inputs(LOG_DEBUG, "Removed", register_copy ^ same);
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    fsa_dump_actions(fsa_actions, "Remaining");
rpm-build 3ee90c
    fsa_dump_queue(LOG_DEBUG);
rpm-build 3ee90c
rpm-build 3ee90c
    return fsa_state;
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
void
rpm-build 3ee90c
s_crmd_fsa_actions(fsa_data_t * fsa_data)
rpm-build 3ee90c
{
rpm-build 3ee90c
    /*
rpm-build 3ee90c
     * Process actions in order of priority but do only one
rpm-build 3ee90c
     * action at a time to avoid complicating the ordering.
rpm-build 3ee90c
     */
rpm-build 3ee90c
    CRM_CHECK(fsa_data != NULL, return);
rpm-build 3ee90c
    while (fsa_actions != A_NOTHING && do_fsa_stall == FALSE) {
rpm-build 3ee90c
rpm-build 3ee90c
        /* regular action processing in order of action priority
rpm-build 3ee90c
         *
rpm-build 3ee90c
         * Make sure all actions that connect to required systems
rpm-build 3ee90c
         * are performed first
rpm-build 3ee90c
         */
rpm-build 3ee90c
        if (fsa_actions & A_ERROR) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_ERROR, do_log);
rpm-build 3ee90c
        } else if (fsa_actions & A_WARN) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_WARN, do_log);
rpm-build 3ee90c
        } else if (fsa_actions & A_LOG) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_LOG, do_log);
rpm-build 3ee90c
rpm-build 3ee90c
            /* get out of here NOW! before anything worse happens */
rpm-build 3ee90c
        } else if (fsa_actions & A_EXIT_1) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_EXIT_1, do_exit);
rpm-build 3ee90c
rpm-build 3ee90c
            /* sub-system restart */
rpm-build 3ee90c
        } else if ((fsa_actions & O_LRM_RECONNECT) == O_LRM_RECONNECT) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, O_LRM_RECONNECT, do_lrm_control);
rpm-build 3ee90c
        } else if ((fsa_actions & O_CIB_RESTART) == O_CIB_RESTART) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, O_CIB_RESTART, do_cib_control);
rpm-build 3ee90c
        } else if ((fsa_actions & O_PE_RESTART) == O_PE_RESTART) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, O_PE_RESTART, do_pe_control);
rpm-build 3ee90c
        } else if ((fsa_actions & O_TE_RESTART) == O_TE_RESTART) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, O_TE_RESTART, do_te_control);
rpm-build 3ee90c
rpm-build 3ee90c
            /* essential start tasks */
rpm-build 3ee90c
        } else if (fsa_actions & A_STARTUP) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_STARTUP, do_startup);
rpm-build 3ee90c
        } else if (fsa_actions & A_CIB_START) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_CIB_START, do_cib_control);
rpm-build 3ee90c
        } else if (fsa_actions & A_HA_CONNECT) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_HA_CONNECT, do_ha_control);
rpm-build 3ee90c
        } else if (fsa_actions & A_READCONFIG) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_READCONFIG, do_read_config);
rpm-build 3ee90c
rpm-build 3ee90c
            /* sub-system start/connect */
rpm-build 3ee90c
        } else if (fsa_actions & A_LRM_CONNECT) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_LRM_CONNECT, do_lrm_control);
rpm-build 3ee90c
rpm-build 3ee90c
        } else if (fsa_actions & A_TE_START) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_TE_START, do_te_control);
rpm-build 3ee90c
        } else if (fsa_actions & A_PE_START) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_PE_START, do_pe_control);
rpm-build 3ee90c
rpm-build 3ee90c
            /* Timers */
rpm-build 3ee90c
/* 		else if(fsa_actions & O_DC_TIMER_RESTART) {
rpm-build 3ee90c
		do_fsa_action(fsa_data, O_DC_TIMER_RESTART,	     do_timer_control) */ ;
rpm-build 3ee90c
        } else if (fsa_actions & A_DC_TIMER_STOP) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_DC_TIMER_STOP, do_timer_control);
rpm-build 3ee90c
        } else if (fsa_actions & A_INTEGRATE_TIMER_STOP) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_INTEGRATE_TIMER_STOP, do_timer_control);
rpm-build 3ee90c
        } else if (fsa_actions & A_INTEGRATE_TIMER_START) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_INTEGRATE_TIMER_START, do_timer_control);
rpm-build 3ee90c
        } else if (fsa_actions & A_FINALIZE_TIMER_STOP) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_FINALIZE_TIMER_STOP, do_timer_control);
rpm-build 3ee90c
        } else if (fsa_actions & A_FINALIZE_TIMER_START) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_FINALIZE_TIMER_START, do_timer_control);
rpm-build 3ee90c
rpm-build 3ee90c
            /*
rpm-build 3ee90c
             * Highest priority actions
rpm-build 3ee90c
             */
rpm-build 3ee90c
        } else if (fsa_actions & A_MSG_ROUTE) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_MSG_ROUTE, do_msg_route);
rpm-build 3ee90c
        } else if (fsa_actions & A_RECOVER) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_RECOVER, do_recover);
rpm-build 3ee90c
        } else if (fsa_actions & A_CL_JOIN_RESULT) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_CL_JOIN_RESULT, do_cl_join_finalize_respond);
rpm-build 3ee90c
        } else if (fsa_actions & A_CL_JOIN_REQUEST) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_CL_JOIN_REQUEST, do_cl_join_offer_respond);
rpm-build 3ee90c
        } else if (fsa_actions & A_SHUTDOWN_REQ) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_SHUTDOWN_REQ, do_shutdown_req);
rpm-build 3ee90c
        } else if (fsa_actions & A_ELECTION_VOTE) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_ELECTION_VOTE, do_election_vote);
rpm-build 3ee90c
        } else if (fsa_actions & A_ELECTION_COUNT) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_ELECTION_COUNT, do_election_count_vote);
rpm-build 3ee90c
        } else if (fsa_actions & A_LRM_EVENT) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_LRM_EVENT, do_lrm_event);
rpm-build 3ee90c
rpm-build 3ee90c
            /*
rpm-build 3ee90c
             * High priority actions
rpm-build 3ee90c
             */
rpm-build 3ee90c
        } else if (fsa_actions & A_STARTED) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_STARTED, do_started);
rpm-build 3ee90c
        } else if (fsa_actions & A_CL_JOIN_QUERY) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_CL_JOIN_QUERY, do_cl_join_query);
rpm-build 3ee90c
        } else if (fsa_actions & A_DC_TIMER_START) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_DC_TIMER_START, do_timer_control);
rpm-build 3ee90c
rpm-build 3ee90c
            /*
rpm-build 3ee90c
             * Medium priority actions
rpm-build 3ee90c
             * - Membership
rpm-build 3ee90c
             */
rpm-build 3ee90c
        } else if (fsa_actions & A_DC_TAKEOVER) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_DC_TAKEOVER, do_dc_takeover);
rpm-build 3ee90c
        } else if (fsa_actions & A_DC_RELEASE) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_DC_RELEASE, do_dc_release);
rpm-build 3ee90c
        } else if (fsa_actions & A_DC_JOIN_FINAL) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_DC_JOIN_FINAL, do_dc_join_final);
rpm-build 3ee90c
        } else if (fsa_actions & A_ELECTION_CHECK) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_ELECTION_CHECK, do_election_check);
rpm-build 3ee90c
        } else if (fsa_actions & A_ELECTION_START) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_ELECTION_START, do_election_vote);
rpm-build 3ee90c
        } else if (fsa_actions & A_DC_JOIN_OFFER_ALL) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_DC_JOIN_OFFER_ALL, do_dc_join_offer_all);
rpm-build 3ee90c
        } else if (fsa_actions & A_DC_JOIN_OFFER_ONE) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_DC_JOIN_OFFER_ONE, do_dc_join_offer_one);
rpm-build 3ee90c
        } else if (fsa_actions & A_DC_JOIN_PROCESS_REQ) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_DC_JOIN_PROCESS_REQ, do_dc_join_filter_offer);
rpm-build 3ee90c
        } else if (fsa_actions & A_DC_JOIN_PROCESS_ACK) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_DC_JOIN_PROCESS_ACK, do_dc_join_ack);
rpm-build 3ee90c
        } else if (fsa_actions & A_DC_JOIN_FINALIZE) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_DC_JOIN_FINALIZE, do_dc_join_finalize);
rpm-build 3ee90c
        } else if (fsa_actions & A_CL_JOIN_ANNOUNCE) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_CL_JOIN_ANNOUNCE, do_cl_join_announce);
rpm-build 3ee90c
rpm-build 3ee90c
            /*
rpm-build 3ee90c
             * Low(er) priority actions
rpm-build 3ee90c
             * Make sure the CIB is always updated before invoking the
rpm-build 3ee90c
             * PE, and the PE before the TE
rpm-build 3ee90c
             */
rpm-build 3ee90c
        } else if (fsa_actions & A_TE_HALT) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_TE_HALT, do_te_invoke);
rpm-build 3ee90c
        } else if (fsa_actions & A_TE_CANCEL) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_TE_CANCEL, do_te_invoke);
rpm-build 3ee90c
        } else if (fsa_actions & A_LRM_INVOKE) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_LRM_INVOKE, do_lrm_invoke);
rpm-build 3ee90c
        } else if (fsa_actions & A_PE_INVOKE) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_PE_INVOKE, do_pe_invoke);
rpm-build 3ee90c
        } else if (fsa_actions & A_TE_INVOKE) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_TE_INVOKE, do_te_invoke);
rpm-build 3ee90c
rpm-build 3ee90c
            /* Shutdown actions */
rpm-build 3ee90c
        } else if (fsa_actions & A_DC_RELEASED) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_DC_RELEASED, do_dc_release);
rpm-build 3ee90c
        } else if (fsa_actions & A_PE_STOP) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_PE_STOP, do_pe_control);
rpm-build 3ee90c
        } else if (fsa_actions & A_TE_STOP) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_TE_STOP, do_te_control);
rpm-build 3ee90c
        } else if (fsa_actions & A_SHUTDOWN) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_SHUTDOWN, do_shutdown);
rpm-build 3ee90c
        } else if (fsa_actions & A_LRM_DISCONNECT) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_LRM_DISCONNECT, do_lrm_control);
rpm-build 3ee90c
        } else if (fsa_actions & A_HA_DISCONNECT) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_HA_DISCONNECT, do_ha_control);
rpm-build 3ee90c
        } else if (fsa_actions & A_CIB_STOP) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_CIB_STOP, do_cib_control);
rpm-build 3ee90c
        } else if (fsa_actions & A_STOP) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_STOP, do_stop);
rpm-build 3ee90c
rpm-build 3ee90c
            /* exit gracefully */
rpm-build 3ee90c
        } else if (fsa_actions & A_EXIT_0) {
rpm-build 3ee90c
            do_fsa_action(fsa_data, A_EXIT_0, do_exit);
rpm-build 3ee90c
rpm-build 3ee90c
            /* Error checking and reporting */
rpm-build 3ee90c
        } else {
rpm-build 3ee90c
            crm_err("Action %s not supported "CRM_XS" 0x%llx",
rpm-build 3ee90c
                    fsa_action2string(fsa_actions), fsa_actions);
rpm-build 3ee90c
            register_fsa_error_adv(C_FSA_INTERNAL, I_ERROR, fsa_data, NULL, __FUNCTION__);
rpm-build 3ee90c
        }
rpm-build 3ee90c
    }
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
void
rpm-build 3ee90c
log_fsa_input(fsa_data_t * stored_msg)
rpm-build 3ee90c
{
rpm-build 3ee90c
    CRM_ASSERT(stored_msg);
rpm-build 3ee90c
    crm_trace("Processing queued input %d", stored_msg->id);
rpm-build 3ee90c
    if (stored_msg->fsa_cause == C_LRM_OP_CALLBACK) {
rpm-build 3ee90c
        crm_trace("FSA processing LRM callback from %s", stored_msg->origin);
rpm-build 3ee90c
rpm-build 3ee90c
    } else if (stored_msg->data == NULL) {
rpm-build 3ee90c
        crm_trace("FSA processing input from %s", stored_msg->origin);
rpm-build 3ee90c
rpm-build 3ee90c
    } else {
rpm-build 3ee90c
        ha_msg_input_t *ha_input = fsa_typed_data_adv(stored_msg, fsa_dt_ha_msg, __FUNCTION__);
rpm-build 3ee90c
rpm-build 3ee90c
        crm_trace("FSA processing XML message from %s", stored_msg->origin);
rpm-build 3ee90c
        crm_log_xml_trace(ha_input->xml, "FSA message data");
rpm-build 3ee90c
    }
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
long long
rpm-build 3ee90c
do_state_transition(long long actions,
rpm-build 3ee90c
                    enum crmd_fsa_state cur_state,
rpm-build 3ee90c
                    enum crmd_fsa_state next_state, fsa_data_t * msg_data)
rpm-build 3ee90c
{
rpm-build 3ee90c
    int level = LOG_INFO;
rpm-build 3ee90c
    long long tmp = actions;
rpm-build 3ee90c
    gboolean clear_recovery_bit = TRUE;
rpm-build 3ee90c
rpm-build 3ee90c
    enum crmd_fsa_cause cause = msg_data->fsa_cause;
rpm-build 3ee90c
    enum crmd_fsa_input current_input = msg_data->fsa_input;
rpm-build 3ee90c
rpm-build 3ee90c
    const char *state_from = fsa_state2string(cur_state);
rpm-build 3ee90c
    const char *state_to = fsa_state2string(next_state);
rpm-build 3ee90c
    const char *input = fsa_input2string(current_input);
rpm-build 3ee90c
rpm-build 3ee90c
    CRM_LOG_ASSERT(cur_state != next_state);
rpm-build 3ee90c
rpm-build 3ee90c
    do_dot_log(DOT_PREFIX "\t%s -> %s [ label=%s cause=%s origin=%s ]",
rpm-build 3ee90c
               state_from, state_to, input, fsa_cause2string(cause), msg_data->origin);
rpm-build 3ee90c
rpm-build 3ee90c
    if (cur_state == S_IDLE || next_state == S_IDLE) {
rpm-build 3ee90c
        level = LOG_NOTICE;
rpm-build 3ee90c
    } else if (cur_state == S_NOT_DC || next_state == S_NOT_DC) {
rpm-build 3ee90c
        level = LOG_NOTICE;
rpm-build 3ee90c
    } else if (cur_state == S_ELECTION) {
rpm-build 3ee90c
        level = LOG_NOTICE;
rpm-build 3ee90c
    } else if (cur_state == S_STARTING) {
rpm-build 3ee90c
        level = LOG_NOTICE;
rpm-build 3ee90c
    } else if (next_state == S_RECOVERY) {
rpm-build 3ee90c
        level = LOG_WARNING;
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    do_crm_log(level, "State transition %s -> %s "
rpm-build 3ee90c
               CRM_XS " input=%s cause=%s origin=%s",
rpm-build 3ee90c
               state_from, state_to, input, fsa_cause2string(cause),
rpm-build 3ee90c
               msg_data->origin);
rpm-build 3ee90c
rpm-build 3ee90c
    if (next_state != S_ELECTION && cur_state != S_RELEASE_DC) {
rpm-build 3ee90c
        controld_stop_election_timer();
rpm-build 3ee90c
    }
rpm-build 3ee90c
#if 0
rpm-build 3ee90c
    if ((fsa_input_register & R_SHUTDOWN)) {
rpm-build 3ee90c
        set_bit(tmp, A_DC_TIMER_STOP);
rpm-build 3ee90c
    }
rpm-build 3ee90c
#endif
rpm-build 3ee90c
    if (next_state == S_INTEGRATION) {
rpm-build 3ee90c
        set_bit(tmp, A_INTEGRATE_TIMER_START);
rpm-build 3ee90c
    } else {
rpm-build 3ee90c
        set_bit(tmp, A_INTEGRATE_TIMER_STOP);
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    if (next_state == S_FINALIZE_JOIN) {
rpm-build 3ee90c
        set_bit(tmp, A_FINALIZE_TIMER_START);
rpm-build 3ee90c
    } else {
rpm-build 3ee90c
        set_bit(tmp, A_FINALIZE_TIMER_STOP);
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    if (next_state != S_PENDING) {
rpm-build 3ee90c
        set_bit(tmp, A_DC_TIMER_STOP);
rpm-build 3ee90c
    }
rpm-build 3ee90c
    if (next_state != S_ELECTION) {
rpm-build 3ee90c
        highest_born_on = 0;
rpm-build 3ee90c
    }
rpm-build 3ee90c
    if (next_state != S_IDLE) {
rpm-build 3ee90c
        controld_stop_timer(recheck_timer);
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    if (cur_state == S_FINALIZE_JOIN && next_state == S_POLICY_ENGINE) {
rpm-build 3ee90c
        populate_cib_nodes(node_update_quick|node_update_all, __FUNCTION__);
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    switch (next_state) {
rpm-build 3ee90c
        case S_PENDING:
rpm-build 3ee90c
            fsa_cib_conn->cmds->set_slave(fsa_cib_conn, cib_scope_local);
rpm-build 3ee90c
            /* fall through */
rpm-build 3ee90c
        case S_ELECTION:
rpm-build 3ee90c
            crm_trace("Resetting our DC to NULL on transition to %s", fsa_state2string(next_state));
rpm-build 3ee90c
            update_dc(NULL);
rpm-build 3ee90c
            break;
rpm-build 3ee90c
        case S_NOT_DC:
rpm-build 3ee90c
            election_trigger->counter = 0;
rpm-build 3ee90c
            purge_stonith_cleanup();
rpm-build 3ee90c
rpm-build 3ee90c
            if (is_set(fsa_input_register, R_SHUTDOWN)) {
rpm-build 3ee90c
                crm_info("(Re)Issuing shutdown request now" " that we have a new DC");
rpm-build 3ee90c
                set_bit(tmp, A_SHUTDOWN_REQ);
rpm-build 3ee90c
            }
rpm-build 3ee90c
            CRM_LOG_ASSERT(fsa_our_dc != NULL);
rpm-build 3ee90c
            if (fsa_our_dc == NULL) {
rpm-build 3ee90c
                crm_err("Reached S_NOT_DC without a DC" " being recorded");
rpm-build 3ee90c
            }
rpm-build 3ee90c
            break;
rpm-build 3ee90c
        case S_RECOVERY:
rpm-build 3ee90c
            clear_recovery_bit = FALSE;
rpm-build 3ee90c
            break;
rpm-build 3ee90c
rpm-build 3ee90c
        case S_FINALIZE_JOIN:
rpm-build 3ee90c
            CRM_LOG_ASSERT(AM_I_DC);
rpm-build 3ee90c
            if (cause == C_TIMER_POPPED) {
rpm-build 3ee90c
                crm_warn("Progressed to state %s after %s",
rpm-build 3ee90c
                         fsa_state2string(next_state), fsa_cause2string(cause));
rpm-build 3ee90c
            }
rpm-build 3ee90c
            if (crmd_join_phase_count(crm_join_welcomed) > 0) {
rpm-build 3ee90c
                crm_warn("%u cluster nodes failed to respond"
rpm-build 3ee90c
                         " to the join offer.", crmd_join_phase_count(crm_join_welcomed));
rpm-build 3ee90c
                crmd_join_phase_log(LOG_NOTICE);
rpm-build 3ee90c
rpm-build 3ee90c
            } else {
rpm-build 3ee90c
                crm_debug("All %d cluster nodes responded to the join offer.",
rpm-build 3ee90c
                          crmd_join_phase_count(crm_join_integrated));
rpm-build 3ee90c
            }
rpm-build 3ee90c
            break;
rpm-build 3ee90c
rpm-build 3ee90c
        case S_POLICY_ENGINE:
rpm-build 3ee90c
            election_trigger->counter = 0;
rpm-build 3ee90c
            CRM_LOG_ASSERT(AM_I_DC);
rpm-build 3ee90c
            if (cause == C_TIMER_POPPED) {
rpm-build 3ee90c
                crm_info("Progressed to state %s after %s",
rpm-build 3ee90c
                         fsa_state2string(next_state), fsa_cause2string(cause));
rpm-build 3ee90c
            }
rpm-build 3ee90c
rpm-build 3ee90c
            if (crmd_join_phase_count(crm_join_finalized) > 0) {
rpm-build 3ee90c
                crm_err("%u cluster nodes failed to confirm their join.",
rpm-build 3ee90c
                        crmd_join_phase_count(crm_join_finalized));
rpm-build 3ee90c
                crmd_join_phase_log(LOG_NOTICE);
rpm-build 3ee90c
rpm-build 3ee90c
            } else if (crmd_join_phase_count(crm_join_confirmed)
rpm-build 3ee90c
                       == crm_active_peers()) {
rpm-build 3ee90c
                crm_debug("All %u cluster nodes are"
rpm-build 3ee90c
                          " eligible to run resources.", crm_active_peers());
rpm-build 3ee90c
rpm-build 3ee90c
            } else if (crmd_join_phase_count(crm_join_confirmed) > crm_active_peers()) {
rpm-build 3ee90c
                crm_err("We have more confirmed nodes than our membership does: %d vs. %d",
rpm-build 3ee90c
                        crmd_join_phase_count(crm_join_confirmed), crm_active_peers());
rpm-build 3ee90c
                register_fsa_input(C_FSA_INTERNAL, I_ELECTION, NULL);
rpm-build 3ee90c
rpm-build 3ee90c
            } else if (saved_ccm_membership_id != crm_peer_seq) {
rpm-build 3ee90c
                crm_info("Membership changed: %llu -> %llu - join restart",
rpm-build 3ee90c
                         saved_ccm_membership_id, crm_peer_seq);
rpm-build 3ee90c
                register_fsa_input_before(C_FSA_INTERNAL, I_NODE_JOIN, NULL);
rpm-build 3ee90c
rpm-build 3ee90c
            } else {
rpm-build 3ee90c
                crm_warn("Only %u of %u cluster "
rpm-build 3ee90c
                         "nodes are eligible to run resources - continue %d",
rpm-build 3ee90c
                         crmd_join_phase_count(crm_join_confirmed),
rpm-build 3ee90c
                         crm_active_peers(), crmd_join_phase_count(crm_join_welcomed));
rpm-build 3ee90c
            }
rpm-build 3ee90c
/* 			initialize_join(FALSE); */
rpm-build 3ee90c
            break;
rpm-build 3ee90c
rpm-build 3ee90c
        case S_STOPPING:
rpm-build 3ee90c
        case S_TERMINATE:
rpm-build 3ee90c
            /* possibly redundant */
rpm-build 3ee90c
            set_bit(fsa_input_register, R_SHUTDOWN);
rpm-build 3ee90c
            break;
rpm-build 3ee90c
rpm-build 3ee90c
        case S_IDLE:
rpm-build 3ee90c
            CRM_LOG_ASSERT(AM_I_DC);
rpm-build 3ee90c
            if (is_set(fsa_input_register, R_SHUTDOWN)) {
rpm-build 3ee90c
                crm_info("(Re)Issuing shutdown request now" " that we are the DC");
rpm-build 3ee90c
                set_bit(tmp, A_SHUTDOWN_REQ);
rpm-build 3ee90c
            }
rpm-build 3ee90c
            controld_start_recheck_timer();
rpm-build 3ee90c
            break;
rpm-build 3ee90c
rpm-build 3ee90c
        default:
rpm-build 3ee90c
            break;
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    if (clear_recovery_bit && next_state != S_PENDING) {
rpm-build 3ee90c
        tmp &= ~A_RECOVER;
rpm-build 3ee90c
    } else if (clear_recovery_bit == FALSE) {
rpm-build 3ee90c
        tmp |= A_RECOVER;
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    if (tmp != actions) {
rpm-build 3ee90c
        /* fsa_dump_actions(actions ^ tmp, "New actions"); */
rpm-build 3ee90c
        actions = tmp;
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    return actions;
rpm-build 3ee90c
}