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

📄 utils.c

📁 linux集群服务器软件代码包
💻 C
📖 第 1 页 / 共 2 页
字号:
	if(on_node != NULL && on_node->details->unclean) {		crm_warn("Not creating action  %s for %s because %s is unclean",			 task2text(task), rsc?rsc->id:"<NULL>",			 on_node->details->id);	}		if(possible_matches != NULL) {		if(g_list_length(possible_matches) > 1) {			crm_warn("Action %s for %s on %s exists %d times",				task2text(task), rsc?rsc->id:"<NULL>",				on_node?on_node->details->id:"<NULL>",				g_list_length(possible_matches));		}				action = g_list_nth_data(possible_matches, 0);		crm_devel("Returning existing action (%d) %s for %s on %s",			  action->id,			  task2text(task), rsc?rsc->id:"<NULL>",			  on_node?on_node->details->id:"<NULL>");		/* todo: free possible_matches */		return action;	}		crm_devel("Creating action %s for %s on %s",		  task2text(task), rsc?rsc->id:"<NULL>",		  on_node?on_node->details->id:"<NULL>");	crm_malloc(action, sizeof(action_t));	if(action != NULL) {		action->id   = action_id++;		action->rsc  = rsc;		action->task = task;		action->node = on_node;		action->actions_before   = NULL;		action->actions_after    = NULL;		action->failure_is_fatal = TRUE;		action->pseudo = FALSE;		action->dumped     = FALSE;		action->discard    = FALSE;		action->runnable   = TRUE;		action->processed  = FALSE;		action->optional   = FALSE;		action->seen_count = 0;		action->timeout    = NULL;		action->args       = create_xml_node(NULL, "args");				if(rsc != NULL) {			crm_devel("Adding created action to its resource");			rsc->actions = g_list_append(rsc->actions, action);			if(task == start_rsc) {				rsc->starting = TRUE;				action->timeout = rsc->start_timeout;			} else if(task == stop_rsc) {				rsc->stopping = TRUE;				action->timeout = rsc->stop_timeout;			} else {				action->timeout = rsc->def_timeout;			}					}	}	crm_devel("Action %d created", action->id);	return action;}const char *strength2text(enum con_strength strength){	const char *result = "<unknown>";	switch(strength)	{		case pecs_ignore:			result = "ignore";			break;		case pecs_must:			result = XML_STRENGTH_VAL_MUST;			break;		case pecs_must_not:			result = XML_STRENGTH_VAL_MUSTNOT;			break;		case pecs_startstop:			result = "start/stop";			break;	}	return result;}const char *task2text(enum action_tasks task){	const char *result = "<unknown>";	switch(task)	{		case no_action:			result = "no_action";			break;		case stop_rsc:			result = CRMD_RSCSTATE_STOP;			break;		case stopped_rsc:			result = CRMD_RSCSTATE_STOP_OK;			break;		case start_rsc:			result = CRMD_RSCSTATE_START;			break;		case started_rsc:			result = CRMD_RSCSTATE_START_OK;			break;		case shutdown_crm:			result = CRM_OP_SHUTDOWN;			break;		case stonith_node:			result = XML_CIB_ATTR_STONITH;			break;	}		return result;}voidprint_node(const char *pre_text, node_t *node, gboolean details){ 	if(node == NULL) {		crm_devel("%s%s: <NULL>",		       pre_text==NULL?"":pre_text,		       pre_text==NULL?"":": ");		return;	}	crm_devel("%s%s%sNode %s: (weight=%f, fixed=%s)",	       pre_text==NULL?"":pre_text,	       pre_text==NULL?"":": ",	       node->details==NULL?"error ":node->details->online?"":"Unavailable/Unclean ",	       node->details->uname, 	       node->weight,	       node->fixed?"True":"False"); 	if(details && node->details != NULL) {		char *pe_mutable = crm_strdup("\t\t");		crm_devel("\t\t===Node Attributes");		g_hash_table_foreach(node->details->attrs,				     print_str_str, pe_mutable);		crm_free(pe_mutable);	}	if(details) {		crm_devel("\t\t===Node Attributes");		slist_iter(			rsc, resource_t, node->details->running_rsc, lpc,			print_resource("\t\t", rsc, FALSE);			);	}	}/* * Used by the HashTable for-loop */void print_str_str(gpointer key, gpointer value, gpointer user_data){	crm_devel("%s%s %s ==> %s",	       user_data==NULL?"":(char*)user_data,	       user_data==NULL?"":": ",	       (char*)key,	       (char*)value);}voidprint_color_details(const char *pre_text,		    struct color_shared_s *color,		    gboolean details){ 	if(color == NULL) {		crm_devel("%s%s: <NULL>",		       pre_text==NULL?"":pre_text,		       pre_text==NULL?"":": ");		return;	}	crm_devel("%s%sColor %d: node=%s (from %d candidates)",	       pre_text==NULL?"":pre_text,	       pre_text==NULL?"":": ",	       color->id, 	       color->chosen_node==NULL?"<unset>":color->chosen_node->details->uname,	       g_list_length(color->candidate_nodes)); 	if(details) {		slist_iter(node, node_t, color->candidate_nodes, lpc,			   print_node("\t", node, FALSE));	}}voidprint_color(const char *pre_text, color_t *color, gboolean details){ 	if(color == NULL) {		crm_devel("%s%s: <NULL>",		       pre_text==NULL?"":pre_text,		       pre_text==NULL?"":": ");		return;	}	crm_devel("%s%sColor %d: (weight=%f, node=%s, possible=%d)",	       pre_text==NULL?"":pre_text,	       pre_text==NULL?"":": ",	       color->id, 	       color->local_weight,		  safe_val5("<unset>",color,details,chosen_node,details,uname),	       g_list_length(color->details->candidate_nodes)); 	if(details) {		print_color_details("\t", color->details, details);	}}voidprint_rsc_to_node(const char *pre_text, rsc_to_node_t *cons, gboolean details){ 	if(cons == NULL) {		crm_devel("%s%s: <NULL>",		       pre_text==NULL?"":pre_text,		       pre_text==NULL?"":": ");		return;	}	crm_devel("%s%s%s Constraint %s (%p) - %d nodes:",	       pre_text==NULL?"":pre_text,	       pre_text==NULL?"":": ",	       "rsc_to_node",		  cons->id, cons,		  g_list_length(cons->node_list_rh));	if(details == FALSE) {		crm_devel("\t%s %s run (score=%f : node placement rule)",			  safe_val3(NULL, cons, rsc_lh, id), 			  cons->can?"Can":"Cannot",			  cons->weight);		slist_iter(			node, node_t, cons->node_list_rh, lpc,			print_node("\t\t-->", node, FALSE)			);	}}voidprint_rsc_dependancy(const char *pre_text, rsc_dependancy_t *cons, gboolean details){ 	if(cons == NULL) {		crm_devel("%s%s: <NULL>",		       pre_text==NULL?"":pre_text,		       pre_text==NULL?"":": ");		return;	}	crm_devel("%s%s%s Constraint %s (%p):",	       pre_text==NULL?"":pre_text,	       pre_text==NULL?"":": ",	       XML_CONS_TAG_RSC_DEPEND, cons->id, cons);	if(details == FALSE) {		crm_devel("\t%s --> %s, %s",			  safe_val3(NULL, cons, rsc_lh, id), 			  safe_val3(NULL, cons, rsc_rh, id), 			  strength2text(cons->strength));	}} voidprint_resource(const char *pre_text, resource_t *rsc, gboolean details){ 	if(rsc == NULL) {		crm_devel("%s%s: <NULL>",		       pre_text==NULL?"":pre_text,		       pre_text==NULL?"":": ");		return;	}	rsc->fns->dump(rsc, pre_text, details);}voidprint_action(const char *pre_text, action_t *action, gboolean details){ 	if(action == NULL) {		crm_devel("%s%s: <NULL>",		       pre_text==NULL?"":pre_text,		       pre_text==NULL?"":": ");		return;	}	switch(action->task) {		case stonith_node:		case shutdown_crm:			crm_devel("%s%s%sAction %d: %s @ %s",			       pre_text==NULL?"":pre_text,			       pre_text==NULL?"":": ",			       action->discard?"Discarded ":action->optional?"Optional ":action->runnable?action->processed?"":"(Provisional) ":"!!Non-Startable!! ",			       action->id,			       task2text(action->task),			       safe_val4(NULL, action, node, details, uname));			break;		default:			crm_devel("%s%s%sAction %d: %s %s @ %s",			       pre_text==NULL?"":pre_text,			       pre_text==NULL?"":": ",			       action->optional?"Optional ":action->runnable?action->processed?"":"(Provisional) ":"!!Non-Startable!! ",			       action->id,			       task2text(action->task),			       safe_val3(NULL, action, rsc, id),			       safe_val4(NULL, action, node, details, uname));						break;	}	if(details) {#if 1		crm_devel("\t\t====== Preceeding Actions");		slist_iter(			other, action_wrapper_t, action->actions_before, lpc,			print_action("\t\t", other->action, FALSE);			);		crm_devel("\t\t====== Subsequent Actions");		slist_iter(			other, action_wrapper_t, action->actions_after, lpc,			print_action("\t\t", other->action, FALSE);			);		#else		crm_devel("\t\t====== Subsequent Actions");		slist_iter(			other, action_wrapper_t, action->actions_after, lpc,			print_action("\t\t", other->action, FALSE);			);		#endif		crm_devel("\t\t====== End");	} else {		crm_devel("\t\t(seen=%d, before=%d, after=%d)",		       action->seen_count,		       g_list_length(action->actions_before),		       g_list_length(action->actions_after));	}}voidpe_free_nodes(GListPtr nodes){	while(nodes != NULL) {		GListPtr list_item = nodes;		node_t *node = (node_t*)list_item->data;		struct node_shared_s *details = node->details;		nodes = nodes->next;		crm_trace("deleting node");		crm_trace("%s is being deleted", details->uname);		print_node("delete", node, FALSE);				if(details != NULL) {			if(details->attrs != NULL) {				g_hash_table_foreach_remove(details->attrs,							    ghash_free_str_str,							    NULL);				g_hash_table_destroy(details->attrs);			}					}			}	if(nodes != NULL) {		g_list_free(nodes);	}}gboolean ghash_free_str_str(gpointer key, gpointer value, gpointer user_data){	crm_free(key);	crm_free(value);	return TRUE;}voidpe_free_colors(GListPtr colors){	while(colors != NULL) {		GListPtr list_item = colors;		color_t *color = (color_t *)list_item->data;		struct color_shared_s *details = color->details;		colors = colors->next;				if(details != NULL) {			pe_free_shallow(details->candidate_nodes);			pe_free_shallow_adv(details->allocated_resources, FALSE);			crm_free(details->chosen_node);			crm_free(details);		}		crm_free(color);	}	if(colors != NULL) {		g_list_free(colors);	}}voidpe_free_shallow(GListPtr alist){	pe_free_shallow_adv(alist, TRUE);}voidpe_free_shallow_adv(GListPtr alist, gboolean with_data){	GListPtr item;	GListPtr item_next = alist;	while(item_next != NULL) {		item = item_next;		item_next = item_next->next;				if(with_data) {/*			crm_trace("freeing %p", item->data); */			crm_free(item->data);		}				item->data = NULL;		item->next = NULL;		g_list_free(item);	}}voidpe_free_resources(GListPtr resources){ 	volatile GListPtr list_item = NULL;	resource_t *rsc = NULL;		while(resources != NULL) {		list_item = resources;		rsc = (resource_t *)list_item->data;		resources = resources->next;		pe_free_shallow_adv(rsc->candidate_colors, TRUE);		rsc->fns->free(rsc);	}	if(resources != NULL) {		g_list_free(resources);	}}voidpe_free_actions(GListPtr actions) {	while(actions != NULL) {		GListPtr list_item = actions;		action_t *action = (action_t *)list_item->data;		actions = actions->next;		pe_free_shallow(action->actions_before);/* action_warpper_t* */		pe_free_shallow(action->actions_after); /* action_warpper_t* */		action->actions_before = NULL;		action->actions_after  = NULL;		free_xml(action->args);		crm_free(action);	}	if(actions != NULL) {		g_list_free(actions);	}}voidpe_free_rsc_dependancy(rsc_dependancy_t *cons){ 	if(cons != NULL) {		crm_devel("Freeing constraint %s (%p)", cons->id, cons);		crm_free(cons);	}}voidpe_free_rsc_to_node(rsc_to_node_t *cons){	if(cons != NULL) {		/* right now we dont make copies so this isnt required *//*		pe_free_shallow(cons->node_list_rh); */ /* node_t* */		crm_free(cons);	}}GListPtrfind_actions(GListPtr input, enum action_tasks task, node_t *on_node){	GListPtr result = NULL;		slist_iter(		action, action_t, input, lpc,		if(action->task == task) {			if(on_node == NULL) {				result = g_list_append(result, action);			} else if(action->node == NULL) {				/* skip */				crm_warn("While looking for %s action on %s, "					  "found an unallocated one.  "					  "This could end up creating dups..",					  task2text(task),					  on_node->details->id);							} else if(safe_str_eq(on_node->details->id,					      action->node->details->id)) {				result = g_list_append(result, action);			}		}		);	return result;}voidset_id(crm_data_t * xml_obj, const char *prefix, int child) {	int id_len = 0;	gboolean use_prefix = TRUE;	gboolean use_child = TRUE;	char *new_id   = NULL;	const char *id = crm_element_value(xml_obj, XML_ATTR_ID);		id_len = 1 + strlen(id);	if(child > 999) {		crm_err("Are you insane?!?"			" The CRM does not support > 1000 children per resource");		return;			} else if(child < 0) {		use_child = FALSE;			} else {		id_len += 4; /* child */	}		if(prefix == NULL || safe_str_eq(id, prefix)) {		use_prefix = FALSE;	} else {		id_len += (1 + strlen(prefix));	}		crm_malloc(new_id, id_len);	if(use_child) {		snprintf(new_id, id_len, "%s%s%s:%d",			 use_prefix?prefix:"", use_prefix?":":"", id, child);	} else {		snprintf(new_id, id_len, "%s%s%s",			 use_prefix?prefix:"", use_prefix?":":"", id);	}		set_xml_property_copy(xml_obj, XML_ATTR_ID, new_id);	crm_free(new_id);}

⌨️ 快捷键说明

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