⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utils.c

📁 linux集群服务器软件代码包
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  * 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 <crm/crm.h>#include <crm/cib.h>#include <crmd_fsa.h>#include <clplumbing/Gmain_timeout.h>#include <sys/types.h>#include <sys/wait.h>#include <signal.h>#include <heartbeat.h>#include <crm/msg_xml.h>#include <crm/common/xml.h>#include <crm/common/msg.h>#include <crmd_messages.h>#include <crmd_utils.h>#include <crm/dmalloc_wrapper.h>void copy_ccm_node(oc_node_t a_node, oc_node_t *a_node_copy);/*	A_DC_TIMER_STOP, A_DC_TIMER_START, *	A_FINALIZE_TIMER_STOP, A_FINALIZE_TIMER_START *	A_INTEGRATE_TIMER_STOP, A_INTEGRATE_TIMER_START */enum crmd_fsa_inputdo_timer_control(long long action,		   enum crmd_fsa_cause cause,		   enum crmd_fsa_state cur_state,		   enum crmd_fsa_input current_input,		   fsa_data_t *msg_data){	gboolean timer_op_ok = TRUE;	enum crmd_fsa_input result = I_NULL;		if(action & A_DC_TIMER_STOP) {		timer_op_ok = stopTimer(election_trigger);	} else if(action & A_FINALIZE_TIMER_STOP) {		timer_op_ok = stopTimer(finalization_timer);	} else if(action & A_INTEGRATE_TIMER_STOP) {		timer_op_ok = stopTimer(integration_timer);/* 	} else if(action & A_ELECTION_TIMEOUT_STOP) { *//* 		timer_op_ok = stopTimer(election_timeout); */	}	/* dont start a timer that wasnt already running */	if(action & A_DC_TIMER_START && timer_op_ok) {		startTimer(election_trigger);		if(AM_I_DC) {			/* there can be only one */			result = I_ELECTION;		}			} else if(action & A_FINALIZE_TIMER_START) {		startTimer(finalization_timer);	} else if(action & A_INTEGRATE_TIMER_START) {		startTimer(integration_timer);/* 	} else if(action & A_ELECTION_TIMEOUT_START) { *//* 		startTimer(election_timeout); */	}		return I_NULL;}gbooleantimer_popped(gpointer data){	fsa_timer_t *timer = (fsa_timer_t *)data;	if(timer == election_trigger) {		crm_info("Election Trigger (%s) just popped!",			 fsa_input2string(timer->fsa_input)); 	} else if(timer == election_timeout) {		crm_info("Election Timeout (%s) just popped!",			 fsa_input2string(timer->fsa_input));			} else {		crm_info("Timer %s just popped!",			 fsa_input2string(timer->fsa_input));	}		stopTimer(timer); /* make it _not_ go off again */	if(timer->fsa_input != I_NULL) {		register_fsa_input_before(			C_TIMER_POPPED, timer->fsa_input, NULL);	}	s_crmd_fsa(C_TIMER_POPPED);		return TRUE;}gbooleanstartTimer(fsa_timer_t *timer){	if((timer->source_id == (guint)-1 || timer->source_id == (guint)-2)	   && timer->period_ms > 0) {		timer->source_id = Gmain_timeout_add(			timer->period_ms, timer->callback, (void*)timer);		crm_devel("Started %s timer (%d), period=%dms",			  fsa_input2string(timer->fsa_input),			  timer->source_id, timer->period_ms);	} else if(timer->period_ms < 0) {		crm_err("Tried to start timer %s with -ve period",			fsa_input2string(timer->fsa_input));			} else {		crm_devel("Timer %s (period=%dms) already running (%d)",			  fsa_input2string(timer->fsa_input),			  timer->period_ms, timer->source_id);		return FALSE;			}	return TRUE;}gbooleanstopTimer(fsa_timer_t *timer){	if(timer == NULL) {		crm_err("Attempted to stop NULL timer");		return FALSE;			} else if(timer->source_id != (guint)-1 && timer->source_id != (guint)-2) {		crm_devel("Stopping %s timer (period=%dms, src=%d)",			  fsa_input2string(timer->fsa_input),			  timer->period_ms, timer->source_id);		g_source_remove(timer->source_id);		timer->source_id = -2;			} else {		crm_devel("Timer %s (period=%dms) already stopped (src=%d)",		       fsa_input2string(timer->fsa_input),			  timer->period_ms, timer->source_id);		timer->source_id = -2;		return FALSE;	}	return TRUE;}long longtoggle_bit(long long action_list, long long action){	crm_insane("Toggling bit %.16llx", action);	action_list ^= action;	crm_insane("Result %.16llx", action_list & action);	return action_list;}long longclear_bit(long long action_list, long long action){	crm_insane("Clearing bit\t%.16llx", action);	/* ensure its set */	action_list |= action;	/* then toggle */	action_list = action_list ^ action;	return action_list;}long longset_bit(long long action_list, long long action){	crm_insane("Setting bit\t%.16llx", action);	action_list |= action;	return action_list;}gbooleanis_set(long long action_list, long long action){	crm_insane("Checking bit\t%.16llx in %.16llx", action, action_list);	return ((action_list & action) == action);}gbooleanis_set_any(long long action_list, long long action){	crm_insane("Checking bit\t%.16llx in %.16llx", action, action_list);	return ((action_list & action) != 0);}const char *fsa_input2string(enum crmd_fsa_input input){	const char *inputAsText = NULL;		switch(input){		case I_NULL:			inputAsText = "I_NULL";			break;		case I_CCM_EVENT:			inputAsText = "I_CCM_EVENT";			break;		case I_CIB_OP:			inputAsText = "I_CIB_OP";			break;		case I_CIB_UPDATE:			inputAsText = "I_CIB_UPDATE";			break;		case I_DC_TIMEOUT:			inputAsText = "I_DC_TIMEOUT";			break;		case I_ELECTION:			inputAsText = "I_ELECTION";			break;		case I_PE_CALC:			inputAsText = "I_PE_CALC";			break;		case I_RELEASE_DC:			inputAsText = "I_RELEASE_DC";			break;		case I_ELECTION_DC:			inputAsText = "I_ELECTION_DC";			break;		case I_ERROR:			inputAsText = "I_ERROR";			break;		case I_FAIL:			inputAsText = "I_FAIL";			break;		case I_INTEGRATED:			inputAsText = "I_INTEGRATED";			break;		case I_FINALIZED:			inputAsText = "I_FINALIZED";			break;		case I_NODE_JOIN:			inputAsText = "I_NODE_JOIN";			break;		case I_JOIN_OFFER:			inputAsText = "I_JOIN_OFFER";			break;		case I_JOIN_REQUEST:			inputAsText = "I_JOIN_REQUEST";			break;		case I_JOIN_RESULT:			inputAsText = "I_JOIN_RESULT";			break;		case I_NOT_DC:			inputAsText = "I_NOT_DC";			break;		case I_RECOVERED:			inputAsText = "I_RECOVERED";			break;		case I_RELEASE_FAIL:			inputAsText = "I_RELEASE_FAIL";			break;		case I_RELEASE_SUCCESS:			inputAsText = "I_RELEASE_SUCCESS";			break;		case I_RESTART:			inputAsText = "I_RESTART";			break;		case I_PE_SUCCESS:			inputAsText = "I_PE_SUCCESS";			break;		case I_ROUTER:			inputAsText = "I_ROUTER";			break;		case I_SHUTDOWN:			inputAsText = "I_SHUTDOWN";			break;		case I_STARTUP:			inputAsText = "I_STARTUP";			break;		case I_TE_SUCCESS:			inputAsText = "I_TE_SUCCESS";			break;		case I_TERMINATE:			inputAsText = "I_TERMINATE";			break;		case I_DC_HEARTBEAT:			inputAsText = "I_DC_HEARTBEAT";			break;		case I_WAIT_FOR_EVENT:			inputAsText = "I_WAIT_FOR_EVENT";			break;		case I_LRM_EVENT:			inputAsText = "I_LRM_EVENT";			break;		case I_PENDING:			inputAsText = "I_PENDING";			break;		case I_HALT:			inputAsText = "I_HALT";			break;		case I_ILLEGAL:			inputAsText = "I_ILLEGAL";			break;	}	if(inputAsText == NULL) {		crm_err("Input %d is unknown", input);		inputAsText = "<UNKNOWN_INPUT>";	}		return inputAsText;}const char *fsa_state2string(enum crmd_fsa_state state){	const char *stateAsText = NULL;		switch(state){		case S_IDLE:			stateAsText = "S_IDLE";			break;		case S_ELECTION:			stateAsText = "S_ELECTION";			break;		case S_INTEGRATION:			stateAsText = "S_INTEGRATION";			break;		case S_FINALIZE_JOIN:			stateAsText = "S_FINALIZE_JOIN";			break;		case S_NOT_DC:			stateAsText = "S_NOT_DC";			break;		case S_POLICY_ENGINE:			stateAsText = "S_POLICY_ENGINE";			break;		case S_RECOVERY:			stateAsText = "S_RECOVERY";			break;		case S_RELEASE_DC:			stateAsText = "S_RELEASE_DC";			break;		case S_PENDING:			stateAsText = "S_PENDING";			break;		case S_STOPPING:			stateAsText = "S_STOPPING";			break;		case S_TERMINATE:			stateAsText = "S_TERMINATE";			break;		case S_TRANSITION_ENGINE:			stateAsText = "S_TRANSITION_ENGINE";			break;		case S_STARTING:			stateAsText = "S_STARTING";			break;		case S_HALT:			stateAsText = "S_HALT";			break;		case S_ILLEGAL:			stateAsText = "S_ILLEGAL";			break;	}	if(stateAsText == NULL) {		crm_err("State %d is unknown", state);		stateAsText = "<UNKNOWN_STATE>";	}		return stateAsText;}const char *fsa_cause2string(enum crmd_fsa_cause cause){	const char *causeAsText = NULL;		switch(cause){		case C_UNKNOWN:			causeAsText = "C_UNKNOWN";			break;		case C_STARTUP:			causeAsText = "C_STARTUP";			break;		case C_IPC_MESSAGE:			causeAsText = "C_IPC_MESSAGE";			break;		case C_HA_MESSAGE:			causeAsText = "C_HA_MESSAGE";			break;		case C_CCM_CALLBACK:			causeAsText = "C_CCM_CALLBACK";			break;		case C_TIMER_POPPED:			causeAsText = "C_TIMER_POPPED";			break;		case C_SHUTDOWN:			causeAsText = "C_SHUTDOWN";			break;		case C_HEARTBEAT_FAILED:			causeAsText = "C_HEARTBEAT_FAILED";			break;		case C_SUBSYSTEM_CONNECT:			causeAsText = "C_SUBSYSTEM_CONNECT";			break;		case C_LRM_OP_CALLBACK:			causeAsText = "C_LRM_OP_CALLBACK";			break;		case C_LRM_MONITOR_CALLBACK:			causeAsText = "C_LRM_MONITOR_CALLBACK";			break;		case C_CRMD_STATUS_CALLBACK:			causeAsText = "C_CRMD_STATUS_CALLBACK";			break;		case C_HA_DISCONNECT:			causeAsText = "C_HA_DISCONNECT";			break;		case C_FSA_INTERNAL:			causeAsText = "C_FSA_INTERNAL";			break;		case C_ILLEGAL:			causeAsText = "C_ILLEGAL";			break;	}	if(causeAsText == NULL) {		crm_err("Cause %d is unknown", cause);		causeAsText = "<UNKNOWN_CAUSE>";	}		return causeAsText;}const char *fsa_action2string(long long action){	const char *actionAsText = NULL;		switch(action){		case A_NOTHING:			actionAsText = "A_NOTHING";			break;		case A_ELECTION_START:			actionAsText = "A_ELECTION_START";			break;		case A_READCONFIG:			actionAsText = "A_READCONFIG";			break;		case O_SHUTDOWN:			actionAsText = "O_SHUTDOWN";			break;		case O_RELEASE:			actionAsText = "O_RELEASE";			break;		case A_STARTUP:			actionAsText = "A_STARTUP";			break;		case A_STARTED:			actionAsText = "A_STARTED";			break;		case A_HA_CONNECT:			actionAsText = "A_HA_CONNECT";			break;		case A_HA_DISCONNECT:			actionAsText = "A_HA_DISCONNECT";			break;		case A_LRM_CONNECT:			actionAsText = "A_LRM_CONNECT";			break;		case A_LRM_EVENT:			actionAsText = "A_LRM_EVENT";			break;		case A_LRM_INVOKE:			actionAsText = "A_LRM_INVOKE";			break;		case A_LRM_DISCONNECT:			actionAsText = "A_LRM_DISCONNECT";			break;		case A_CL_JOIN_QUERY:			actionAsText = "A_CL_JOIN_QUERY";			break;		case A_DC_TIMER_STOP:			actionAsText = "A_DC_TIMER_STOP";			break;		case A_DC_TIMER_START:			actionAsText = "A_DC_TIMER_START";			break;		case A_INTEGRATE_TIMER_START:			actionAsText = "A_INTEGRATE_TIMER_START";			break;		case A_INTEGRATE_TIMER_STOP:			actionAsText = "A_INTEGRATE_TIMER_STOP";			break;		case A_FINALIZE_TIMER_START:			actionAsText = "A_FINALIZE_TIMER_START";			break;		case A_FINALIZE_TIMER_STOP:			actionAsText = "A_FINALIZE_TIMER_STOP";			break;		case A_ELECTION_COUNT:			actionAsText = "A_ELECTION_COUNT";			break;		case A_ELECTION_VOTE:			actionAsText = "A_ELECTION_VOTE";			break;		case A_CL_JOIN_ANNOUNCE:			actionAsText = "A_CL_JOIN_ANNOUNCE";			break;		case A_CL_JOIN_REQUEST:			actionAsText = "A_CL_JOIN_REQUEST";			break;		case A_CL_JOIN_RESULT:			actionAsText = "A_CL_JOIN_RESULT";			break;		case A_DC_JOIN_OFFER_ALL:			actionAsText = "A_DC_JOIN_OFFER_ALL";			break;		case A_DC_JOIN_OFFER_ONE:			actionAsText = "A_DC_JOIN_OFFER_ONE";			break;		case A_DC_JOIN_PROCESS_REQ:			actionAsText = "A_DC_JOIN_PROCESS_REQ";			break;		case A_DC_JOIN_PROCESS_ACK:			actionAsText = "A_DC_JOIN_PROCESS_ACK";			break;		case A_DC_JOIN_FINALIZE:			actionAsText = "A_DC_JOIN_FINALIZE";			break;		case A_MSG_PROCESS:			actionAsText = "A_MSG_PROCESS";			break;		case A_MSG_ROUTE:			actionAsText = "A_MSG_ROUTE";			break;		case A_RECOVER:			actionAsText = "A_RECOVER";			break;		case A_DC_RELEASE:			actionAsText = "A_DC_RELEASE";			break;		case A_DC_RELEASED:			actionAsText = "A_DC_RELEASED";			break;		case A_DC_TAKEOVER:			actionAsText = "A_DC_TAKEOVER";			break;		case A_SHUTDOWN:			actionAsText = "A_SHUTDOWN";			break;		case A_SHUTDOWN_REQ:			actionAsText = "A_SHUTDOWN_REQ";			break;		case A_STOP:			actionAsText = "A_STOP  ";			break;		case A_EXIT_0:			actionAsText = "A_EXIT_0";			break;		case A_EXIT_1:			actionAsText = "A_EXIT_1";			break;		case A_CCM_CONNECT:			actionAsText = "A_CCM_CONNECT";			break;		case A_CCM_DISCONNECT:			actionAsText = "A_CCM_DISCONNECT";			break;		case A_CCM_EVENT:			actionAsText = "A_CCM_EVENT";			break;		case A_CCM_UPDATE_CACHE:			actionAsText = "A_CCM_UPDATE_CACHE";			break;		case A_CIB_BUMPGEN:			actionAsText = "A_CIB_BUMPGEN";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -