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

📄 messages.c

📁 linux集群服务器软件代码包
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $Id: messages.c,v 1.28 2005/02/20 14:36:56 andrew Exp $ *//*  * 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 <sys/types.h>#include <unistd.h>#include <stdlib.h>#include <errno.h>#include <fcntl.h>#include <heartbeat.h>#include <clplumbing/cl_log.h>#include <time.h>#include <crm/crm.h>#include <crm/cib.h>#include <crm/msg_xml.h>#include <crm/common/msg.h>#include <crm/common/xml.h>#include <cibio.h>#include <cibmessages.h>#include <cibprimatives.h>#include <notify.h>#include <callbacks.h>#include <crm/dmalloc_wrapper.h>extern const char *cib_our_uname;enum cib_errors revision_check(crm_data_t *cib_update, crm_data_t *cib_copy, int flags);int get_revision(crm_data_t *xml_obj, int cur_revision);enum cib_errors updateList(	crm_data_t *local_cib, crm_data_t *update_command, crm_data_t *failed,	int operation, const char *section);crm_data_t *createCibFragmentAnswer(const char *section, crm_data_t *failed);gboolean replace_section(	const char *section, crm_data_t *tmpCib, crm_data_t *command);gboolean check_generation(crm_data_t *newCib, crm_data_t *oldCib);gboolean update_results(	crm_data_t *failed, crm_data_t *target, int operation, int return_code);enum cib_errors cib_update_counter(	crm_data_t *xml_obj, const char *field, gboolean reset);int set_connected_peers(crm_data_t *xml_obj);void GHFunc_count_peers(gpointer key, gpointer value, gpointer user_data);intset_connected_peers(crm_data_t *xml_obj){	int active = 0;	char *peers_s = NULL;	g_hash_table_foreach(peer_hash, GHFunc_count_peers, &active);	peers_s = crm_itoa(active);	set_xml_property_copy(xml_obj, XML_ATTR_NUMPEERS, peers_s);	crm_free(peers_s);	return active;}void GHFunc_count_peers(gpointer key, gpointer value, gpointer user_data){	int *active = user_data;	if(safe_str_eq(value, ONLINESTATUS)) {		(*active)++;			} else if(safe_str_eq(value, JOINSTATUS)) {		(*active)++;	}}enum cib_errors cib_process_default(	const char *op, int options, const char *section, crm_data_t *input,	crm_data_t **answer){	enum cib_errors result = cib_ok;	crm_debug("Processing \"%s\" event", op);	if(answer != NULL) { *answer = NULL; }		if(op == NULL) {		result = cib_operation;		crm_err("No operation specified\n");			} else if(strcmp(CRM_OP_NOOP, op) == 0) {		;	} else {		result = cib_NOTSUPPORTED;		crm_err("Action [%s] is not supported by the CIB", op);	}	return result;}enum cib_errors cib_process_quit(	const char *op, int options, const char *section, crm_data_t *input,	crm_data_t **answer){	enum cib_errors result = cib_ok;	crm_debug("Processing \"%s\" event", op);	cib_pre_notify(op, get_the_CIB(), NULL);	crm_warn("The CRMd has asked us to exit... complying");	exit(0);	return result;}enum cib_errors cib_process_readwrite(	const char *op, int options, const char *section, crm_data_t *input,	crm_data_t **answer){	enum cib_errors result = cib_ok;	crm_debug("Processing \"%s\" event", op);	if(safe_str_eq(op, CRM_OP_CIB_ISMASTER)) {		if(cib_is_master == TRUE) {			result = cib_ok;		} else {			result = cib_not_master;		}		return result;	}	cib_pre_notify(op, get_the_CIB(), NULL);	if(safe_str_eq(op, CRM_OP_CIB_MASTER)) {		crm_info("We are now in R/W mode");		cib_is_master = TRUE;	} else {		crm_info("We are now in R/O mode");		cib_is_master = FALSE;	}	cib_post_notify(op, NULL, result, NULL);	return result;}enum cib_errors cib_process_ping(	const char *op, int options, const char *section, crm_data_t *input,	crm_data_t **answer){	enum cib_errors result = cib_ok;	crm_debug("Processing \"%s\" event", op);	if(answer != NULL) {		*answer = createPingAnswerFragment(CRM_SYSTEM_CIB, "ok");	}	return result;}enum cib_errors cib_process_query(	const char *op, int options, const char *section, crm_data_t *input,	crm_data_t **answer){	crm_data_t *obj_root = NULL;	enum cib_errors result = cib_ok;	crm_debug("Processing \"%s\" event for section=%s", op, crm_str(section));	if(answer != NULL) { *answer = NULL; }		else { return cib_ok; }	#if 0	if (safe_str_eq(XML_CIB_TAG_SECTION_ALL, section)) {		section = NULL;	}#else	if (section == NULL) {		section = XML_CIB_TAG_SECTION_ALL;	}#endif	*answer = create_xml_node(NULL, XML_TAG_FRAGMENT);/*  	set_xml_property_copy(*answer, XML_ATTR_SECTION, section); */	set_xml_property_copy(*answer, "generated_on", cib_our_uname);	obj_root = get_object_root(section, get_the_CIB());		if(obj_root == NULL) {		result = cib_NOTEXISTS;	} else if(obj_root == get_the_CIB()) {		add_node_copy(*answer, obj_root);	} else {		crm_data_t *cib = createEmptyCib();		crm_data_t *query_obj_root = get_object_root(section, cib);		copy_in_properties(cib, get_the_CIB());		xml_child_iter(			obj_root, an_obj, NULL,			add_node_copy(query_obj_root, an_obj);			);		add_node_copy(*answer, cib);		free_xml(cib);	}		return result;}enum cib_errors cib_process_erase(	const char *op, int options, const char *section, crm_data_t *input,	crm_data_t **answer){	crm_data_t *tmpCib = NULL;	enum cib_errors result = cib_ok;	crm_debug("Processing \"%s\" event", op);	if(answer != NULL) { *answer = NULL; }		tmpCib = createEmptyCib();	result = revision_check(get_the_CIB(), tmpCib, options);			copy_in_properties(tmpCib, get_the_CIB());		cib_pre_notify(op, the_cib, tmpCib);	cib_update_counter(tmpCib, XML_ATTR_NUMUPDATES, TRUE);			if(result == cib_ok && activateCibXml(tmpCib, CIB_FILENAME) < 0) {		result = cib_ACTIVATION;	}	cib_post_notify(op, NULL, result, the_cib);	if(answer != NULL) {		*answer = createCibFragmentAnswer(NULL, NULL);	}		return result;}enum cib_errors cib_process_bump(	const char *op, int options, const char *section, crm_data_t *input,	crm_data_t **answer){	crm_data_t *tmpCib = NULL;	enum cib_errors result = cib_ok;	crm_debug("Processing \"%s\" event for epoche=%s",		  op, crm_str(crm_element_value(the_cib, XML_ATTR_GENERATION)));		if(answer != NULL) { *answer = NULL; }		cib_pre_notify(op, get_the_CIB(), NULL);	tmpCib = copy_xml_node_recursive(the_cib);	cib_update_counter(tmpCib, XML_ATTR_GENERATION, FALSE);	cib_update_counter(tmpCib, XML_ATTR_NUMUPDATES, FALSE);		if(activateCibXml(tmpCib, CIB_FILENAME) < 0) {		result = cib_ACTIVATION;	}	cib_post_notify(op, NULL, result, get_the_CIB());	if(answer != NULL) {		*answer = createCibFragmentAnswer(NULL, NULL);	}		return result;}enum cib_errors cib_update_counter(crm_data_t *xml_obj, const char *field, gboolean reset){	char *new_value = NULL;	char *old_value = NULL;	int  int_value  = -1;	/* modify the timestamp */	set_node_tstamp(xml_obj);	if(reset == FALSE && crm_element_value(xml_obj, field) != NULL) {		old_value = crm_element_value_copy(xml_obj, field);	}	if(old_value != NULL) {		crm_malloc(new_value, 128*(sizeof(char)));		int_value = atoi(old_value);		sprintf(new_value, "%d", ++int_value);	} else {		new_value = crm_strdup("1");	}	crm_trace("%s %d(%s)->%s",		  field, int_value, crm_str(old_value), crm_str(new_value));	set_xml_property_copy(xml_obj, field, new_value);	crm_free(new_value);	if(safe_str_eq(field, XML_ATTR_NUMUPDATES)) {		set_connected_peers(xml_obj);		if(cib_have_quorum) {			set_xml_property_copy(				xml_obj, XML_ATTR_HAVE_QUORUM, XML_BOOLEAN_TRUE);		} else {			set_xml_property_copy(				xml_obj, XML_ATTR_HAVE_QUORUM, XML_BOOLEAN_FALSE);		}	}		crm_free(old_value);	return cib_ok;}enum cib_errors cib_process_replace(	const char *op, int options, const char *section, crm_data_t *input,	crm_data_t **answer){	gboolean verbose       = FALSE;	crm_data_t *tmpCib      = NULL;	crm_data_t *cib_update  = NULL;	crm_data_t *the_update  = NULL;	char *section_name = NULL;	enum cib_errors result = cib_ok;		crm_debug("Processing \"%s\" event for section=%s", op, crm_str(section));	if(answer != NULL) { *answer = NULL; }		if (options & cib_verbose) {		verbose = TRUE;	}	if(safe_str_eq(XML_CIB_TAG_SECTION_ALL, section)) {		section = NULL;	}		cib_update = find_xml_node(input, XML_TAG_CIB, TRUE);		if (cib_update == NULL) {		result = cib_NOOBJECT;			} else if (section == NULL) {		tmpCib = copy_xml_node_recursive(cib_update);		the_update = cib_update;		section_name = crm_strdup(crm_element_name(tmpCib));			} else {		tmpCib = copy_xml_node_recursive(get_the_CIB());		section_name = crm_strdup(section);		replace_section(section_name, tmpCib, input);		the_update = get_object_root(section_name, cib_update);	}	cib_pre_notify(		op, get_object_root(section_name, get_the_CIB()), the_update);	cib_update_counter(tmpCib, XML_ATTR_NUMUPDATES, FALSE);	result = revision_check(the_update, tmpCib, options);			copy_in_properties(tmpCib, cib_update);	if (result == cib_ok && activateCibXml(tmpCib, CIB_FILENAME) < 0) {		crm_warn("Replacment of section=%s failed", section);

⌨️ 快捷键说明

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