📄 fsa.c
字号:
/* * Copyright (C) 2004 Andrew Beekhof <andrew@beekhof.net> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include <sys/param.h>#include <stdio.h>#include <string.h>#include <time.h>#include <crm/crm.h>#include <crm/cib.h>#include <crm/msg_xml.h>#include <crm/common/xml.h>#include <crm/common/msg.h>#include <clplumbing/Gmain_timeout.h>#include <crmd_messages.h>#include <crmd_fsa.h>#include <fsa_proto.h>#include <fsa_matrix.h>#include <crm/dmalloc_wrapper.h>extern int num_join_invites;extern GHashTable *join_requests;extern GHashTable *confirmed_nodes;extern void initialize_join(gboolean before);long longdo_state_transition(long long actions, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_state next_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data);long long clear_flags(long long actions, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input cur_input);void dump_rsc_info(void);#define DOT_PREFIX "live.dot: "#ifdef DOT_FSA_ACTIONS# define IF_FSA_ACTION(x,y) \ if(is_set(fsa_actions,x)) { \ last_action = x; \ fsa_actions = clear_bit(fsa_actions, x); \ crm_verbose("Invoking action %s (%.16llx)", \ fsa_action2string(x), x); \ next_input = y(x, cause, fsa_state, last_input, fsa_data); \ crm_verbose("Action complete: %s (%.16llx)", \ fsa_action2string(x), x); \ CRM_DEV_ASSERT(next_input == I_NULL); \ crm_debug(DOT_PREFIX"\t// %s\n", fsa_action2string(x)); \ }#else# define IF_FSA_ACTION(x,y) \ if(is_set(fsa_actions,x)) { \ last_action = x; \ fsa_actions = clear_bit(fsa_actions, x); \ crm_verbose("Invoking action %s (%.16llx)", \ fsa_action2string(x), x); \ next_input = y(x, cause, fsa_state, last_input, fsa_data); \ crm_verbose("Action complete: %s (%.16llx)", \ fsa_action2string(x), x); \ CRM_DEV_ASSERT(next_input == I_NULL); \ }#endif/* #define ELSEIF_FSA_ACTION(x,y) else IF_FSA_ACTION(x,y) */void init_dotfile(void);voidinit_dotfile(void){ crm_debug(DOT_PREFIX"digraph \"g\" {"); crm_debug(DOT_PREFIX" size = \"30,30\""); crm_debug(DOT_PREFIX" graph ["); crm_debug(DOT_PREFIX" fontsize = \"12\""); crm_debug(DOT_PREFIX" fontname = \"Times-Roman\""); crm_debug(DOT_PREFIX" fontcolor = \"black\""); crm_debug(DOT_PREFIX" bb = \"0,0,398.922306,478.927856\""); crm_debug(DOT_PREFIX" color = \"black\""); crm_debug(DOT_PREFIX" ]"); crm_debug(DOT_PREFIX" node ["); crm_debug(DOT_PREFIX" fontsize = \"12\""); crm_debug(DOT_PREFIX" fontname = \"Times-Roman\""); crm_debug(DOT_PREFIX" fontcolor = \"black\""); crm_debug(DOT_PREFIX" shape = \"ellipse\""); crm_debug(DOT_PREFIX" color = \"black\""); crm_debug(DOT_PREFIX" ]"); crm_debug(DOT_PREFIX" edge ["); crm_debug(DOT_PREFIX" fontsize = \"12\""); crm_debug(DOT_PREFIX" fontname = \"Times-Roman\""); crm_debug(DOT_PREFIX" fontcolor = \"black\""); crm_debug(DOT_PREFIX" color = \"black\""); crm_debug(DOT_PREFIX" ]"); crm_debug(DOT_PREFIX"// special nodes"); crm_debug(DOT_PREFIX" \"S_PENDING\" "); crm_debug(DOT_PREFIX" ["); crm_debug(DOT_PREFIX" color = \"blue\""); crm_debug(DOT_PREFIX" fontcolor = \"blue\""); crm_debug(DOT_PREFIX" ]"); crm_debug(DOT_PREFIX" \"S_TERMINATE\" "); crm_debug(DOT_PREFIX" ["); crm_debug(DOT_PREFIX" color = \"red\""); crm_debug(DOT_PREFIX" fontcolor = \"red\""); crm_debug(DOT_PREFIX" ]"); crm_debug(DOT_PREFIX"// DC only nodes"); crm_debug(DOT_PREFIX" \"S_INTEGRATION\" [ fontcolor = \"green\" ]"); crm_debug(DOT_PREFIX" \"S_POLICY_ENGINE\" [ fontcolor = \"green\" ]"); crm_debug(DOT_PREFIX" \"S_TRANSITION_ENGINE\" [ fontcolor = \"green\" ]"); crm_debug(DOT_PREFIX" \"S_RELEASE_DC\" [ fontcolor = \"green\" ]"); crm_debug(DOT_PREFIX" \"S_IDLE\" [ fontcolor = \"green\" ]");}volatile enum crmd_fsa_state fsa_state = S_STARTING;oc_node_list_t *fsa_membership_copy;ll_cluster_t *fsa_cluster_conn;ll_lrm_t *fsa_lrm_conn;volatile long long fsa_input_register;volatile long long fsa_actions = A_NOTHING;const char *fsa_our_uname;char *fsa_our_dc;cib_t *fsa_cib_conn = NULL;fsa_timer_t *election_trigger = NULL; /* */fsa_timer_t *election_timeout = NULL; /* */fsa_timer_t *shutdown_escalation_timer = NULL; /* */fsa_timer_t *integration_timer = NULL;fsa_timer_t *finalization_timer = NULL;fsa_timer_t *dc_heartbeat = NULL;fsa_timer_t *wait_timer = NULL;int fsa_join_reannouce = 0;volatile gboolean do_fsa_stall = FALSE;enum crmd_fsa_states_crmd_fsa(enum crmd_fsa_cause cause){ time_t now; fsa_data_t *fsa_data = NULL; long long new_actions = A_NOTHING; long long last_action = A_NOTHING; enum crmd_fsa_input last_input = I_NULL; enum crmd_fsa_input cur_input = I_NULL; enum crmd_fsa_input next_input = I_NULL; enum crmd_fsa_state starting_state = fsa_state; enum crmd_fsa_state last_state = starting_state; enum crmd_fsa_state next_state = starting_state; crm_debug("FSA invoked with Cause: %s\tState: %s", fsa_cause2string(cause), fsa_state2string(fsa_state)); /* * Process actions in order of priority but do only one * action at a time to avoid complicating the ordering. * * Actions may result in a new I_ event, these are added to * (not replace) existing actions before the next iteration. * */ do_fsa_stall = FALSE; while(next_input != I_NULL || fsa_actions != A_NOTHING || is_message()) { if(do_fsa_stall) { /* we may be waiting for an a-sync task to "happen" * and until it does, we cant do anything else */ crm_info("Wait until something else happens"); break; } else if((is_message() && fsa_data == NULL) || (is_message() && fsa_actions == A_NOTHING && next_input == I_NULL)) { fsa_data_t *stored_msg = NULL; crm_devel("Finished with current input..." " Checking messages (%d remaining)", g_list_length(fsa_message_queue)); next_input = I_NULL; stored_msg = get_message(); if(stored_msg == NULL) { crm_crit("Invalid stored message"); exit(1); } delete_fsa_input(fsa_data); if(stored_msg->fsa_cause == C_CCM_CALLBACK) { crm_devel("FSA processing CCM callback from %s", stored_msg->origin); } else if(stored_msg->fsa_cause == C_LRM_OP_CALLBACK) { crm_devel("FSA processing LRM callback from %s", stored_msg->origin); } else if(stored_msg->data == NULL) { crm_devel("FSA processing input from %s", stored_msg->origin); } else { ha_msg_input_t *ha_input = fsa_typed_data_adv( stored_msg, fsa_dt_ha_msg, __FUNCTION__); crm_devel("FSA processing XML message from %s", stored_msg->origin); crm_log_message(LOG_MSG, ha_input->msg); crm_xml_devel(ha_input->xml, "FSA message data"); } fsa_data = stored_msg; /* set up the input */ next_input = fsa_data->fsa_input; /* add any actions back to the queue */ fsa_actions |= fsa_data->actions; /* update the cause */ cause = fsa_data->fsa_cause; fsa_dump_actions(fsa_data->actions, "\tadded back"); crm_debug(DOT_PREFIX"\t// FSA input: State=%s \tCause=%s" " \tInput=%s \tOrigin=%s()", fsa_state2string(fsa_state), fsa_cause2string(fsa_data->fsa_cause), fsa_input2string(fsa_data->fsa_input), fsa_data->origin); } else if(fsa_data == NULL) { crm_malloc(fsa_data, sizeof(fsa_data_t)); fsa_data->fsa_input = I_NULL; fsa_data->fsa_cause = cause; fsa_data->actions = A_NOTHING; fsa_data->origin = "s_crmd_fsa (enter)"; fsa_data->data = NULL; fsa_data->data_type = fsa_dt_none; if(fsa_data->origin == NULL) { crm_crit("Out of memory"); exit(1); } } /* update input variables */ cur_input = next_input; if(cur_input != I_NULL) { /* record the most recent non I_NULL input */ crm_devel("Updating last_input to %s", fsa_input2string(cur_input)); last_input = cur_input; } /* get the next batch of actions */ new_actions = crmd_fsa_actions[cur_input][fsa_state]; if(new_actions != A_NOTHING) {#ifdef FSA_TRACE crm_verbose("Adding actions %.16llx for %s/%s", new_actions, fsa_input2string(cur_input), fsa_state2string(fsa_state)); fsa_dump_actions(new_actions, "\tscheduled");#endif fsa_actions |= new_actions; } if(fsa_data == NULL) { crm_err("No input for FSA.... terminating"); exit(1); }#ifdef FSA_TRACE crm_verbose("FSA while loop:\tState: %s, Cause: %s," " Input: %s, Origin=%s", fsa_state2string(crmd_fsa_state[cur_input][fsa_state]), fsa_cause2string(fsa_data->fsa_cause), fsa_input2string(cur_input), fsa_data->origin);#endif /* logging : *before* the state is changed */ IF_FSA_ACTION(A_ERROR, do_log) else IF_FSA_ACTION(A_WARN, do_log) else IF_FSA_ACTION(A_LOG, do_log) /* this is always run, some inputs/states may make various * actions irrelevant/invalid */ fsa_actions = clear_flags(fsa_actions, cause, fsa_state, cur_input); /* update state variables */ next_state = crmd_fsa_state[cur_input][fsa_state]; last_state = fsa_state; fsa_state = next_state; /* start doing things... */ /* * Hook for change of state. * Allows actions to be added or removed when entering a state */ if(last_state != fsa_state){ fsa_actions = do_state_transition( fsa_actions, cause, last_state, fsa_state, cur_input, fsa_data); } /* regular action processing in order of action priority * * Make sure all actions that connect to required systems * are performed first */ /* get out of here NOW! before anything worse happens */ IF_FSA_ACTION(A_EXIT_1, do_exit) /* essential start tasks */ else IF_FSA_ACTION(A_HA_CONNECT, do_ha_control) else IF_FSA_ACTION(A_STARTUP, do_startup) else IF_FSA_ACTION(A_CIB_START, do_cib_control) else IF_FSA_ACTION(A_READCONFIG, do_read_config) /* sub-system start/connect */ else IF_FSA_ACTION(A_LRM_CONNECT, do_lrm_control) else IF_FSA_ACTION(A_CCM_CONNECT, do_ccm_control) else IF_FSA_ACTION(A_TE_START, do_te_control)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -