diff --git a/crm/pengine/Makefile.am b/crm/pengine/Makefile.am index 13fa0a3024..d4dd83eb90 100644 --- a/crm/pengine/Makefile.am +++ b/crm/pengine/Makefile.am @@ -1,87 +1,87 @@ # # Copyright (C) 2004 Andrew Beekhof # # 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 # of the License, or (at your option) any later version. # # This program 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 program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # MAINTAINERCLEANFILES = Makefile.in INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include \ -I$(top_builddir)/libltdl -I$(top_srcdir)/libltdl \ -I$(top_builddir)/linux-ha -I$(top_srcdir)/linux-ha \ -I$(top_builddir) -I$(top_srcdir) hadir = $(sysconfdir)/ha.d halibdir = $(libdir)/@HB_PKG@ commmoddir = $(halibdir)/modules/comm havarlibdir = $(localstatedir)/lib/@HB_PKG@ PIDFILE = $(localstatedir)/run/crmd.pid XML_FLAGS = `xml2-config --cflags` XML_LIBS = `xml2-config --libs` # sockets with path crmdir = $(havarlibdir)/crm apigid = @HA_APIGID@ crmuid = @HA_CCMUID@ COMMONLIBS = $(CRM_DEBUG_LIBS) \ $(top_builddir)/lib/clplumbing/libplumb.la \ $(top_builddir)/lib/crm/common/libcrmcommon.la \ $(top_builddir)/lib/crm/cib/libcib.la \ $(top_builddir)/lib/apphb/libapphb.la \ $(GLIBLIB) \ $(LIBRT) LIBRT = @LIBRT@ AM_CFLAGS = @CFLAGS@ \ -DPIDFILE='"$(PIDFILE)"' \ $(CRM_DEBUG_FLAGS) ## libraries lib_LTLIBRARIES = ## binary progs halib_PROGRAMS = ptest pengine ## SOURCES noinst_HEADERS = pe_utils.h pengine.h complex.h pe_rules.h ptest_SOURCES = color.c unpack.c graph.c \ native.c group.c incarnation.c complex.c \ rules.c pengine.c stages.c utils.c ptest.c -ptest_CFLAGS = $(XML_FLAGS) -DHA_VARLIBDIR='"@HA_VARLIBDIR@"' +ptest_CFLAGS = $(XML_FLAGS) -DTESTING=1 -DHA_VARLIBDIR='"@HA_VARLIBDIR@"' ptest_LDFLAGS = $(XML_LIBS) ptest_LDADD = $(COMMONLIBS) pengine_SOURCES = unpack.c color.c graph.c \ native.c group.c incarnation.c complex.c \ rules.c pengine.c stages.c utils.c main.c pengine_CFLAGS = $(XML_FLAGS) -DHA_VARLIBDIR='"@HA_VARLIBDIR@"' pengine_LDFLAGS = $(XML_LIBS) pengine_LDADD = $(COMMONLIBS) \ $(top_builddir)/lib/hbclient/libhbclient.la # clean-generic: rm -f *.log *.debug *~ install-exec-local: uninstall-local: diff --git a/crm/pengine/complex.c b/crm/pengine/complex.c index 025db6ee30..cf066ca15c 100644 --- a/crm/pengine/complex.c +++ b/crm/pengine/complex.c @@ -1,444 +1,404 @@ -/* $Id: complex.c,v 1.26 2005/05/18 20:15:57 andrew Exp $ */ +/* $Id: complex.c,v 1.27 2005/05/20 09:48:15 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * 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 #include #include gboolean update_node_weight(rsc_to_node_t *cons,const char *id,GListPtr nodes); gboolean is_active(rsc_to_node_t *cons); gboolean constraint_violated( resource_t *rsc_lh, resource_t *rsc_rh, rsc_colocation_t *constraint); void order_actions(action_t *lh, action_t *rh, order_constraint_t *order); gboolean has_agent(node_t *a_node, lrm_agent_t *an_agent); resource_object_functions_t resource_class_functions[] = { { native_unpack, native_find_child, native_num_allowed_nodes, native_color, native_create_actions, native_internal_constraints, native_agent_constraints, native_rsc_colocation_lh, native_rsc_colocation_rh, native_rsc_order_lh, native_rsc_order_rh, native_rsc_location, native_expand, native_dump, native_free }, { group_unpack, group_find_child, group_num_allowed_nodes, group_color, group_create_actions, group_internal_constraints, group_agent_constraints, group_rsc_colocation_lh, group_rsc_colocation_rh, group_rsc_order_lh, group_rsc_order_rh, group_rsc_location, group_expand, group_dump, group_free }, { incarnation_unpack, incarnation_find_child, incarnation_num_allowed_nodes, incarnation_color, incarnation_create_actions, incarnation_internal_constraints, incarnation_agent_constraints, incarnation_rsc_colocation_lh, incarnation_rsc_colocation_rh, incarnation_rsc_order_lh, incarnation_rsc_order_rh, incarnation_rsc_location, incarnation_expand, incarnation_dump, incarnation_free } }; /* resource_object_functions_t resource_variants[] = resource_class_functions; */ int get_resource_type(const char *name) { if(safe_str_eq(name, "resource")) { return pe_native; } else if(safe_str_eq(name, "resource_group")) { return pe_group; } else if(safe_str_eq(name, XML_RSC_ATTR_INCARNATION)) { return pe_incarnation; } return pe_unknown; } gboolean is_active(rsc_to_node_t *cons) { /* todo: check constraint lifetime */ return TRUE; } gboolean common_unpack(crm_data_t * xml_obj, resource_t **rsc) { const char *id = crm_element_value(xml_obj, XML_ATTR_ID); const char *stopfail = crm_element_value(xml_obj, XML_RSC_ATTR_STOPFAIL); const char *restart = crm_element_value(xml_obj, XML_RSC_ATTR_RESTART); const char *multiple = crm_element_value(xml_obj, "multiple_active"); const char *priority = NULL; crm_log_xml_debug_2(xml_obj, "Processing resource input..."); if(id == NULL) { pe_err("Must specify id tag in "); return FALSE; } else if(rsc == NULL) { pe_err("Nowhere to unpack resource into"); return FALSE; } crm_malloc0(*rsc, sizeof(resource_t)); if(*rsc == NULL) { return FALSE; } (*rsc)->id = id; (*rsc)->xml = xml_obj; (*rsc)->ops_xml = find_xml_node(xml_obj, "operations", FALSE); (*rsc)->variant = get_resource_type(crm_element_name(xml_obj)); if((*rsc)->variant == pe_unknown) { pe_err("Unknown resource type: %s", crm_element_name(xml_obj)); crm_free(*rsc); return FALSE; } (*rsc)->fns = &resource_class_functions[(*rsc)->variant]; crm_debug_2("Unpacking resource..."); (*rsc)->parameters = g_hash_table_new_full( g_str_hash,g_str_equal, g_hash_destroy_str,g_hash_destroy_str); unpack_instance_attributes(xml_obj, (*rsc)->parameters); priority = get_rsc_param(*rsc, XML_CIB_ATTR_PRIORITY); (*rsc)->priority = atoi(priority?priority:"0"); (*rsc)->effective_priority = (*rsc)->priority; (*rsc)->recovery_type = recovery_stop_start; (*rsc)->runnable = TRUE; (*rsc)->provisional = TRUE; (*rsc)->start_pending = FALSE; - (*rsc)->schedule_recurring = FALSE; + (*rsc)->schedule_recurring = FALSE; (*rsc)->starting = FALSE; (*rsc)->stopping = FALSE; (*rsc)->candidate_colors = NULL; (*rsc)->rsc_cons = NULL; (*rsc)->actions = NULL; crm_debug("Options for %s", id); if(stopfail == NULL && stonith_enabled) { (*rsc)->stopfail_type = pesf_stonith; crm_debug("\tFailed stop handling handling: fence (default)"); } else if(stopfail == NULL) { (*rsc)->stopfail_type = pesf_block; crm_debug("\tFailed stop handling handling: block (default)"); } else if(safe_str_eq(stopfail, "ignore")) { (*rsc)->stopfail_type = pesf_ignore; crm_debug("\tFailed stop handling handling: ignore"); } else if(safe_str_eq(stopfail, "fence")) { (*rsc)->stopfail_type = pesf_stonith; crm_debug("\tFailed stop handling handling: fence"); } else { (*rsc)->stopfail_type = pesf_block; crm_debug("\tFailed stop handling handling: block"); } if(safe_str_eq(restart, "restart")) { (*rsc)->restart_type = pe_restart_restart; crm_debug("\tDependancy restart handling: restart"); } else { (*rsc)->restart_type = pe_restart_ignore; crm_debug("\tDependancy restart handling: ignore"); } if(safe_str_eq(multiple, "stop_only")) { (*rsc)->recovery_type = recovery_stop_only; crm_debug("\tMultiple running resource recovery: stop only"); } else if(safe_str_eq(multiple, "block")) { (*rsc)->recovery_type = recovery_block; crm_debug("\tMultiple running resource recovery: block"); } else { (*rsc)->recovery_type = recovery_stop_start; crm_debug("\tMultiple running resource recovery: stop/start"); } (*rsc)->fns->unpack(*rsc); return TRUE; } - void order_actions(action_t *lh_action, action_t *rh_action, order_constraint_t *order) { action_wrapper_t *wrapper = NULL; GListPtr list = NULL; crm_debug("Ordering %d: Action %d before %d", order?order->id:-1, lh_action->id, rh_action->id); crm_action_debug_3( print_action("LH (order_actions)", lh_action, FALSE)); crm_action_debug_3( print_action("RH (order_actions)", rh_action, FALSE)); crm_malloc0(wrapper, sizeof(action_wrapper_t)); if(wrapper != NULL) { wrapper->action = rh_action; wrapper->strength = order->strength; list = lh_action->actions_after; list = g_list_append(list, wrapper); lh_action->actions_after = list; wrapper = NULL; } crm_malloc0(wrapper, sizeof(action_wrapper_t)); if(wrapper != NULL) { wrapper->action = lh_action; wrapper->strength = order->strength; list = rh_action->actions_before; list = g_list_append(list, wrapper); rh_action->actions_before = list; } } void common_dump(resource_t *rsc, const char *pre_text, gboolean details) { crm_debug_3("%s%s%s%sResource %s: (variant=%s, priority=%f)", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", rsc->provisional?"Provisional ":"", rsc->runnable?"":"(Non-Startable) ", rsc->id, crm_element_name(rsc->xml), (double)rsc->priority); } void common_free(resource_t *rsc) { if(rsc == NULL) { return; } crm_debug_4("Freeing %s", rsc->id); while(rsc->rsc_cons) { pe_free_rsc_colocation( (rsc_colocation_t*)rsc->rsc_cons->data); rsc->rsc_cons = rsc->rsc_cons->next; } - crm_debug_4("Freeing constraint list"); if(rsc->rsc_cons != NULL) { g_list_free(rsc->rsc_cons); } - - crm_debug_4("Freeing opaque data"); + if(rsc->parameters != NULL) { + g_hash_table_destroy(rsc->parameters); + } + pe_free_shallow_adv(rsc->candidate_colors, TRUE); crm_free(rsc->variant_opaque); - crm_debug_4("Freeing resource"); crm_free(rsc); crm_debug_4("Resource freed"); } void common_agent_constraints( GListPtr node_list, lrm_agent_t *agent, const char *id) { #if 0 slist_iter( node, node_t, node_list, lpc, crm_debug_4("Checking if %s supports %s/%s (%s)", node->details->uname, agent->class, agent->type, agent->version); if(has_agent(node, agent) == FALSE) { /* remove node from contention */ crm_debug_4("Marking node %s unavailable for %s", node->details->uname, id); node->weight = -1.0; node->fixed = TRUE; } ); #endif } -gboolean -has_agent(node_t *a_node, lrm_agent_t *an_agent) -{ - if(a_node == NULL || an_agent == NULL || an_agent->type == NULL) { - pe_warn("Invalid inputs"); - return FALSE; - } - - crm_debug_3("Checking %d agents on %s", - g_list_length(a_node->details->agents), - a_node->details->uname); - - slist_iter( - agent, lrm_agent_t, a_node->details->agents, lpc, - - crm_debug_4("Checking against %s/%s (%s)", - agent->class, agent->type, agent->version); - - if(safe_str_eq(an_agent->type, agent->type)){ - if(an_agent->class == NULL) { - return TRUE; - - } else if(safe_str_eq(an_agent->class, agent->class)) { - if(compare_version( - an_agent->version, agent->version) - <= 0) { - return TRUE; - } - } - } - ); - - crm_debug_2("%s doesnt support version %s of %s/%s", - a_node->details->uname, an_agent->version, - an_agent->class, an_agent->type); - - return FALSE; -} - void unpack_instance_attributes(crm_data_t *xml_obj, GHashTable *hash) { const char *name = NULL; const char *value = NULL; if(xml_obj == NULL) { crm_debug_3("No instance attributes"); return; } xml_child_iter( xml_obj, attr_set, XML_TAG_ATTR_SETS, xml_child_iter( attr_set, attrs, XML_TAG_ATTRS, /* todo: check any rules */ xml_child_iter( attrs, an_attr, XML_CIB_TAG_NVPAIR, name = crm_element_value( an_attr, XML_NVPAIR_ATTR_NAME); value = crm_element_value( an_attr, XML_NVPAIR_ATTR_VALUE); add_hash_param(hash, name, value); ); ); ); } void add_rsc_param(resource_t *rsc, const char *name, const char *value) { CRM_DEV_ASSERT(rsc != NULL); if(crm_assert_failed) { return; } add_hash_param(rsc->parameters, name, value); } void add_hash_param(GHashTable *hash, const char *name, const char *value) { CRM_DEV_ASSERT(hash != NULL); if(crm_assert_failed) { return; } crm_debug_2("adding: name=%s value=%s", crm_str(name), crm_str(value)); if(name == NULL || value == NULL) { return; } else if(g_hash_table_lookup(hash, name) == NULL) { g_hash_table_insert(hash, crm_strdup(name), crm_strdup(value)); } } const char * get_rsc_param(resource_t *rsc, const char *name) { CRM_DEV_ASSERT(rsc != NULL); if(crm_assert_failed) { return NULL; } return g_hash_table_lookup(rsc->parameters, name); } void hash2nvpair(gpointer key, gpointer value, gpointer user_data) { const char *name = key; const char *s_value = value; crm_data_t *xml_node = user_data; crm_data_t *xml_child = create_xml_node(xml_node, XML_CIB_TAG_NVPAIR); set_xml_property_copy(xml_child, XML_NVPAIR_ATTR_NAME, name); set_xml_property_copy(xml_child, XML_NVPAIR_ATTR_VALUE, s_value); crm_debug_2("dumped: name=%s value=%s", name, s_value); } diff --git a/crm/pengine/graph.c b/crm/pengine/graph.c index bd36b8e673..3cb2c31c92 100644 --- a/crm/pengine/graph.c +++ b/crm/pengine/graph.c @@ -1,366 +1,372 @@ -/* $Id: graph.c,v 1.43 2005/05/18 20:15:57 andrew Exp $ */ +/* $Id: graph.c,v 1.44 2005/05/20 09:48:15 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * 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 #include #include #include #include #include #include #include #include gboolean update_action(action_t *action); gboolean update_action_states(GListPtr actions) { crm_debug("Updating %d actions", g_list_length(actions)); slist_iter( action, action_t, actions, lpc, update_action(action); ); return TRUE; } gboolean update_action(action_t *action) { gboolean change = FALSE; crm_debug_2("Processing action %d", action->id); if(action->optional && action->runnable) { return FALSE; } slist_iter( other, action_wrapper_t, action->actions_before, lpc, if(action->optional && other->action->optional == FALSE) { change = TRUE; action->optional = FALSE; crm_debug("Marking action %d manditory because of %d", action->id, other->action->id); } ); slist_iter( other, action_wrapper_t, action->actions_after, lpc, if(action->pseudo == FALSE && action->runnable == FALSE && action->optional == FALSE) { if(other->action->runnable == FALSE) { crm_debug("Action %d already un-runnable", other->action->id); continue; } else { change = TRUE; other->action->runnable =FALSE; crm_debug("Marking action %d un-runnable" " because of %d", other->action->id, action->id); } } if(action->optional == FALSE && other->action->optional) { switch(action->rsc->restart_type) { case pe_restart_ignore: break; case pe_restart_restart: change = TRUE; other->action->optional = FALSE; crm_debug("(Restart) Marking action %d manditory because of %d", other->action->id, action->id); } } if(change) { update_action(other->action); } ); return change; } gboolean shutdown_constraints( node_t *node, action_t *shutdown_op, GListPtr *ordering_constraints) { /* add the stop to the before lists so it counts as a pre-req * for the shutdown */ slist_iter( rsc, resource_t, node->details->running_rsc, lpc, custom_action_order( rsc, stop_key(rsc), NULL, NULL, crm_strdup(CRM_OP_SHUTDOWN), shutdown_op, pecs_must, ordering_constraints); ); return TRUE; } gboolean stonith_constraints(node_t *node, action_t *stonith_op, action_t *shutdown_op, GListPtr *ordering_constraints) { GListPtr stop_actions = NULL; if(shutdown_op != NULL) { /* stop everything we can via shutdown_constraints() and then * shoot the node... the shutdown has been superceeded */ shutdown_op->pseudo = TRUE; shutdown_op->runnable = TRUE; /* shutdown before stonith */ /* Give any resources a chance to shutdown normally */ crm_debug_3("Adding shutdown (%d) as an input to stonith (%d)", shutdown_op->id, stonith_op->id); custom_action_order( NULL, crm_strdup(CRM_OP_SHUTDOWN), shutdown_op, NULL, crm_strdup(CRM_OP_FENCE), stonith_op, pecs_must, ordering_constraints); } /* add the stonith OP to the before lists so it counts as a pre-req */ slist_iter( rsc, resource_t, node->details->running_rsc, lpc, if(stonith_op != NULL) { char *key = stop_key(rsc); stop_actions = find_actions(rsc->actions, key, node); crm_free(key); slist_iter( action, action_t, stop_actions, lpc2, if(node->details->online == FALSE || rsc->unclean) { /* the stop would never complete and is * now implied by the stonith operation */ action->pseudo = TRUE; action->runnable = TRUE; custom_action_order( NULL, crm_strdup(CRM_OP_FENCE),stonith_op, rsc, stop_key(rsc), NULL, pecs_must, ordering_constraints); } else { /* stop healthy resources before the * stonith op */ custom_action_order( rsc, stop_key(rsc), NULL, NULL,crm_strdup(CRM_OP_FENCE),stonith_op, pecs_must, ordering_constraints); } ); crm_debug_3("Adding stonith (%d) as an input to stop", stonith_op->id); } else if((rsc->unclean || node->details->unclean) && rsc->stopfail_type == pesf_block) { /* depend on the stop action which will fail */ pe_err("SHARED RESOURCE %s WILL REMAIN BLOCKED" " ON NODE %s UNTIL %s", rsc->id, node->details->uname, stonith_enabled?"QUORUM RETURNS":"CLEANED UP MANUALLY"); continue; } else if((rsc->unclean || node->details->unclean) && rsc->stopfail_type == pesf_ignore) { /* nothing to do here */ pe_err("SHARED RESOURCE %s IS NOT PROTECTED", rsc->id); continue; } ); return TRUE; } crm_data_t * action2xml(action_t *action, gboolean as_input) { gboolean needs_node_info = TRUE; crm_data_t * action_xml = NULL; crm_data_t * args_xml = NULL; + char *action_id_s = NULL; if(action == NULL) { return NULL; } crm_debug_3("Dumping action %d as XML", action->id); if(safe_str_eq(action->task, CRM_OP_FENCE)) { action_xml = create_xml_node(NULL, XML_GRAPH_TAG_CRM_EVENT); needs_node_info = FALSE; } else if(safe_str_eq(action->task, CRM_OP_SHUTDOWN)) { action_xml = create_xml_node(NULL, XML_GRAPH_TAG_CRM_EVENT); } else if(action->pseudo) { action_xml = create_xml_node(NULL, XML_GRAPH_TAG_PSEUDO_EVENT); needs_node_info = FALSE; } else { action_xml = create_xml_node(NULL, XML_GRAPH_TAG_RSC_OP); } + + action_id_s = crm_itoa(action->id); + set_xml_property_copy(action_xml, XML_ATTR_ID, action_id_s); + crm_free(action_id_s); - set_xml_property_copy(action_xml, XML_ATTR_ID, crm_itoa(action->id)); if(action->rsc != NULL) { set_xml_property_copy( action_xml, XML_LRM_ATTR_RSCID, action->rsc->id); } set_xml_property_copy(action_xml, XML_LRM_ATTR_TASK, action->task); if(needs_node_info && action->node != NULL) { set_xml_property_copy( action_xml, XML_LRM_ATTR_TARGET, action->node->details->uname); set_xml_property_copy( action_xml, XML_LRM_ATTR_TARGET_UUID, action->node->details->id); CRM_DEV_ASSERT(NULL != crm_element_value( action_xml, XML_LRM_ATTR_TARGET)); CRM_DEV_ASSERT(NULL != crm_element_value( action_xml, XML_LRM_ATTR_TARGET_UUID)); } set_xml_property_copy( action_xml, "allow_fail", action->failure_is_fatal?XML_BOOLEAN_FALSE:XML_BOOLEAN_TRUE); if(as_input) { return action_xml; } if(action->rsc != NULL && action->pseudo == FALSE) { crm_data_t *rsc_xml = create_xml_node( action_xml, crm_element_name(action->rsc->xml)); copy_in_properties(rsc_xml, action->rsc->xml); args_xml = create_xml_node(action_xml, XML_TAG_ATTRS); g_hash_table_foreach(action->extra, hash2nvpair, args_xml); g_hash_table_foreach( action->rsc->parameters, hash2nvpair, args_xml); } else { args_xml = create_xml_node(action_xml, XML_TAG_ATTRS); g_hash_table_foreach(action->extra, hash2nvpair, args_xml); } crm_log_xml_debug_2(action_xml, "dumped action"); return action_xml; } void graph_element_from_action(action_t *action, crm_data_t * *graph) { char *syn_id = NULL; crm_data_t * syn = NULL; crm_data_t * set = NULL; crm_data_t * in = NULL; crm_data_t * input = NULL; crm_data_t * xml_action = NULL; if(action == NULL) { pe_err("Cannot dump NULL action"); return; } else if(action->optional) { crm_debug_4("action %d was optional", action->id); return; } else if(action->pseudo == FALSE && action->runnable == FALSE) { crm_debug_4("action %d was not runnable", action->id); return; } else if(action->dumped) { crm_debug_4("action %d was already dumped", action->id); return; } else if(action->pseudo || safe_str_eq(action->task, CRM_OP_FENCE) || safe_str_eq(action->task, CRM_OP_SHUTDOWN)) { /* skip the next check */ } else { if(action->node == NULL) { pe_err("action %d was not allocated", action->id); log_action(LOG_DEBUG, "Unallocated action", action, FALSE); return; } else if(action->node->details->online == FALSE) { pe_err("action %d was scheduled for offline node", action->id); log_action(LOG_DEBUG, "Action for offline node", action, FALSE); return; } } action->dumped = TRUE; syn = create_xml_node(*graph, "synapse"); set = create_xml_node(syn, "action_set"); in = create_xml_node(syn, "inputs"); - syn_id = crm_itoa(num_synapse++); + syn_id = crm_itoa(num_synapse); set_xml_property_copy(syn, XML_ATTR_ID, syn_id); crm_free(syn_id); + num_synapse++; xml_action = action2xml(action, FALSE); add_node_copy(set, xml_action); + free_xml(xml_action); slist_iter(wrapper,action_wrapper_t,action->actions_before,lpc, if(wrapper->action->optional == TRUE) { crm_debug("Input %d optional", wrapper->action->id); continue; } input = create_xml_node(in, "trigger"); xml_action = action2xml(wrapper->action, TRUE); add_node_copy(input, xml_action); + free_xml(xml_action); ); - free_xml(xml_action); } diff --git a/crm/pengine/native.c b/crm/pengine/native.c index 98dac534ad..22a1739d9b 100644 --- a/crm/pengine/native.c +++ b/crm/pengine/native.c @@ -1,1201 +1,1201 @@ -/* $Id: native.c,v 1.39 2005/05/19 10:54:32 andrew Exp $ */ +/* $Id: native.c,v 1.40 2005/05/20 09:48:15 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * 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 #include #include extern color_t *add_color(resource_t *rh_resource, color_t *color); gboolean native_choose_color(resource_t *lh_resource); void native_assign_color(resource_t *rsc, color_t *color); void native_update_node_weight(resource_t *rsc, rsc_to_node_t *cons, const char *id, GListPtr nodes); void native_rsc_colocation_rh_must(resource_t *rsc_lh, gboolean update_lh, resource_t *rsc_rh, gboolean update_rh); void native_rsc_colocation_rh_mustnot(resource_t *rsc_lh, gboolean update_lh, resource_t *rsc_rh, gboolean update_rh); void filter_nodes(resource_t *rsc); int num_allowed_nodes4color(color_t *color); void create_recurring_actions(resource_t *rsc, action_t *start, node_t *node, GListPtr *ordering_constraints); action_t *create_recurring_action(resource_t *rsc, node_t *node, const char *action, const char *key); typedef struct native_variant_data_s { lrm_agent_t *agent; GListPtr running_on; /* node_t* */ color_t *color; GListPtr node_cons; /* rsc_to_node_t* */ GListPtr allowed_nodes; /* node_t* */ } native_variant_data_t; #define get_native_variant_data(data, rsc) \ CRM_ASSERT(rsc->variant == pe_native); \ CRM_ASSERT(rsc->variant_opaque != NULL); \ data = (native_variant_data_t *)rsc->variant_opaque; void native_add_running(resource_t *rsc, node_t *node) { native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); CRM_DEV_ASSERT(node != NULL); if(crm_assert_failed) { return; } slist_iter( a_node, node_t, native_data->running_on, lpc, CRM_DEV_ASSERT(a_node != NULL); if(safe_str_eq(a_node->details->id, node->details->id)) { return; } ); native_data->running_on = g_list_append(native_data->running_on, node); node->details->running_rsc = g_list_append( node->details->running_rsc, rsc); if(g_list_length(native_data->running_on) > 1) { pe_warn("Resource %s is (potentially) active on %d nodes." " Latest: %s/%s", rsc->id, g_list_length(native_data->running_on), node->details->uname, node->details->id); } } void native_unpack(resource_t *rsc) { crm_data_t * xml_obj = rsc->xml; native_variant_data_t *native_data = NULL; const char *version = crm_element_value(xml_obj, XML_ATTR_VERSION); crm_debug_2("Processing resource %s...", rsc->id); crm_malloc0(native_data, sizeof(native_variant_data_t)); crm_malloc0(native_data->agent, sizeof(lrm_agent_t)); native_data->agent->class = crm_element_value(xml_obj, "class"); native_data->agent->type = crm_element_value(xml_obj, "type"); native_data->agent->version = version?version:"0.0"; native_data->color = NULL; native_data->allowed_nodes = NULL; native_data->node_cons = NULL; native_data->running_on = NULL; rsc->variant_opaque = native_data; } resource_t * native_find_child(resource_t *rsc, const char *id) { return NULL; } int native_num_allowed_nodes(resource_t *rsc) { int num_nodes = 0; native_variant_data_t *native_data = NULL; if(rsc->variant == pe_native) { native_data = (native_variant_data_t *)rsc->variant_opaque; } else { pe_err("Resource %s was not a \"native\" variant", rsc->id); return 0; } if(native_data->color) { return num_allowed_nodes4color(native_data->color); } else if(rsc->candidate_colors) { /* TODO: sort colors first */ color_t *color = g_list_nth_data(rsc->candidate_colors, 0); return num_allowed_nodes4color(color); } else { slist_iter( this_node, node_t, native_data->allowed_nodes, lpc, if(this_node->weight < 0) { continue; } num_nodes++; ); } return num_nodes; } int num_allowed_nodes4color(color_t *color) { int num_nodes = 0; if(color->details->pending == FALSE) { if(color->details->chosen_node) { return 1; } return 0; } slist_iter( this_node, node_t, color->details->candidate_nodes, lpc, if(this_node->weight < 0) { continue; } num_nodes++; ); return num_nodes; } void native_color(resource_t *rsc, GListPtr *colors) { color_t *new_color = NULL; native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); if( native_choose_color(rsc) ) { crm_debug_2("Colored resource %s with color %d", rsc->id, native_data->color->id); } else { if(native_data->allowed_nodes != NULL) { /* filter out nodes with a negative weight */ filter_nodes(rsc); new_color = create_color( colors, rsc, native_data->allowed_nodes); native_assign_color(rsc, new_color); } if(new_color == NULL) { pe_warn("Resource %s cannot run anywhere", rsc->id); print_resource("ERROR: No color", rsc, FALSE); native_assign_color(rsc, no_color); } } rsc->provisional = FALSE; } void create_recurring_actions(resource_t *rsc, action_t *start, node_t *node, GListPtr *ordering_constraints) { action_t *mon = NULL; char *key = NULL; const char *name = NULL; const char *value = NULL; if(node == NULL || !node->details->online || node->details->unclean) { crm_debug_2("Not creating recurring actions"); return; } xml_child_iter( rsc->ops_xml, operation, "op", name = crm_element_value(operation, "name"); value = crm_element_value(operation, "interval"); key = generate_op_key(rsc->id, name, crm_get_msec(value)); mon = custom_action(rsc, key, name, node); if(start != NULL) { custom_action_order( rsc, start_key(rsc), NULL, NULL, crm_strdup(key), mon, pecs_must, ordering_constraints); } ); } void native_create_actions(resource_t *rsc, GListPtr *ordering_constraints) { action_t *start = NULL; action_t *stop = NULL; node_t *chosen = NULL; native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); if(native_data->color != NULL) { chosen = native_data->color->details->chosen_node; } if(chosen != NULL && g_list_length(native_data->running_on) == 0) { /* create start action */ start = start_action(rsc, chosen); if( !have_quorum && no_quorum_policy != no_quorum_ignore) { start->runnable = FALSE; } else { crm_info("Start resource %s (%s)", rsc->id, chosen->details->uname); rsc->schedule_recurring = TRUE; } } else if(g_list_length(native_data->running_on) > 1) { pe_err("Attempting recovery of resource %s", rsc->id); if(rsc->recovery_type == recovery_stop_start || rsc->recovery_type == recovery_stop_only) { slist_iter( node, node_t, native_data->running_on, lpc, crm_info("Stop resource %s\t(%s) (recovery)", rsc->id, node->details->uname); stop = stop_action(rsc, node); ); } if(rsc->recovery_type == recovery_stop_start && chosen) { /* if one of the "stops" is for a node outside * our partition, then this will block anyway */ crm_info("Start resource %s (%s)\t(recovery)", rsc->id, chosen->details->uname); start = start_action(rsc, chosen); rsc->schedule_recurring = TRUE; } if(rsc->recovery_type == recovery_block) { pe_warn("RESOURCE %s WILL REMAIN ACTIVE ON MULTIPLE" " NODES PENDING MANUAL INTERVENTION", rsc->id); slist_iter( node, node_t, native_data->running_on, lpc, pe_warn("Resource %s active on %s", rsc->id, node->details->uname); ); } } else if(g_list_length(native_data->running_on) == 1) { node_t *node = native_data->running_on->data; crm_debug("Stop%s of %s", chosen?" and restart":"", rsc->id); CRM_DEV_ASSERT(node != NULL); if(have_quorum == FALSE && no_quorum_policy == no_quorum_stop){ start = start_action(rsc, chosen); stop = stop_action(rsc, node); start->runnable = FALSE; } else if(chosen != NULL && safe_str_eq( node->details->id, chosen->details->id)) { /* restart */ if(rsc->recover) { crm_info("Restart resource %s\t(%s)", rsc->id, chosen->details->uname); start = start_action(rsc, chosen); stop = stop_action(rsc, node); rsc->schedule_recurring = TRUE; } else { crm_info("Leave resource %s\t(%s)", rsc->id, chosen->details->uname); start = start_action(rsc, chosen); if(rsc->start_pending == FALSE) { start->optional = TRUE; } else { rsc->schedule_recurring = TRUE; } stop = stop_action(rsc, node); stop->optional = TRUE; } } else if(chosen != NULL) { /* move */ crm_info("Move resource %s\t(%s -> %s)", rsc->id, node->details->uname, chosen->details->uname); stop = stop_action(rsc, node); start = start_action(rsc, chosen); rsc->schedule_recurring = TRUE; } else { crm_info("Stop resource %s\t(%s)", rsc->id, node->details->uname); stop_action(rsc, node); } } if(start != NULL && start->runnable) { create_recurring_actions( rsc, start, chosen, ordering_constraints); } } void native_internal_constraints(resource_t *rsc,GListPtr *ordering_constraints) { native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); order_stop_start(rsc, rsc); } void native_rsc_colocation_lh(rsc_colocation_t *constraint) { resource_t *rsc = constraint->rsc_lh; if(rsc == NULL) { pe_err("rsc_lh was NULL for %s", constraint->id); return; } else if(constraint->rsc_rh == NULL) { pe_err("rsc_rh was NULL for %s", constraint->id); return; } else { crm_debug_3("Processing constraints from %s", rsc->id); } constraint->rsc_rh->fns->rsc_colocation_rh(rsc, constraint); } void native_rsc_colocation_rh(resource_t *rsc, rsc_colocation_t *constraint) { gboolean do_check = FALSE; gboolean update_lh = FALSE; gboolean update_rh = FALSE; resource_t *rsc_lh = rsc; resource_t *rsc_rh = constraint->rsc_rh; native_variant_data_t *native_data_lh = NULL; native_variant_data_t *native_data_rh = NULL; get_native_variant_data(native_data_lh, rsc_lh); get_native_variant_data(native_data_rh, rsc_rh); crm_debug_2("Processing RH of constraint %s", constraint->id); crm_action_debug_3(print_resource("LHS", rsc_lh, TRUE)); crm_action_debug_3(print_resource("RHS", rsc_rh, TRUE)); if(constraint->strength == pecs_ignore || constraint->strength == pecs_startstop){ crm_debug_3("Skipping constraint type %d", constraint->strength); return; } if(rsc_lh->provisional && rsc_rh->provisional) { if(constraint->strength == pecs_must) { /* update effective_priorities */ native_rsc_colocation_rh_must( rsc_lh, update_lh, rsc_rh, update_rh); } else { /* nothing */ crm_debug_3( "Skipping constraint, both sides provisional"); } return; } else if( (!rsc_lh->provisional) && (!rsc_rh->provisional) && (!native_data_lh->color->details->pending) && (!native_data_rh->color->details->pending) ) { /* error check */ do_check = TRUE; if(rsc_lh->effective_priority < rsc_rh->effective_priority) { update_lh = TRUE; } else if(rsc_lh->effective_priority > rsc_rh->effective_priority) { update_rh = TRUE; } else { update_lh = TRUE; update_rh = TRUE; } } else if(rsc_lh->provisional == FALSE && native_data_lh->color->details->pending == FALSE) { /* update _them_ : postproc color version */ update_rh = TRUE; } else if(rsc_rh->provisional == FALSE && native_data_rh->color->details->pending == FALSE) { /* update _us_ : postproc color alt version */ update_lh = TRUE; } else if(rsc_lh->provisional == FALSE) { /* update _them_ : preproc version */ update_rh = TRUE; } else if(rsc_rh->provisional == FALSE) { /* update _us_ : postproc version */ update_lh = TRUE; } else { pe_warn("Un-expected combination of inputs"); return; } if(update_lh) { crm_debug_3("Updating LHS"); } if(update_rh) { crm_debug_3("Updating RHS"); } if(do_check) { if(native_constraint_violated( rsc_lh, rsc_rh, constraint) == FALSE) { crm_debug_3("Constraint satisfied"); return; } /* else constraint cant be satisified */ pe_warn("Constraint %s could not be satisfied", constraint->id); if(update_lh) { pe_warn("Marking resource %s unrunnable as a result", rsc_lh->id); rsc_lh->runnable = FALSE; } if(update_rh) { pe_warn("Marking resource %s unrunnable as a result", rsc_rh->id); rsc_rh->runnable = FALSE; } } if(constraint->strength == pecs_must) { native_rsc_colocation_rh_must( rsc_lh, update_lh, rsc_rh, update_rh); return; } else if(constraint->strength != pecs_must_not) { /* unknown type */ pe_err("Unknown constraint type %d", constraint->strength); return; } native_rsc_colocation_rh_mustnot(rsc_lh, update_lh,rsc_rh, update_rh); } void native_rsc_order_lh(resource_t *lh_rsc, order_constraint_t *order) { GListPtr lh_actions = NULL; action_t *lh_action = order->lh_action; crm_debug_2("Processing LH of ordering constraint %d", order->id); if(lh_action != NULL) { lh_actions = g_list_append(NULL, lh_action); } else if(lh_action == NULL && lh_rsc != NULL) { #if 0 /* this should be safe to remove */ if(order->strength == pecs_must) { crm_debug_3("No LH-Side (%s/%s) found for constraint..." " creating", lh_rsc->id, order->lh_action_task); pe_err("BROKEN CODE"); custom_action( lh_rsc, order->lh_action_task, NULL, NULL); } #endif lh_actions = find_actions( lh_rsc->actions, order->lh_action_task, NULL); if(lh_actions == NULL) { crm_debug_3("No LH-Side (%s/%s) found for constraint", lh_rsc->id, order->lh_action_task); if(order->rh_rsc != NULL) { crm_debug_3("RH-Side was: (%s/%s)", order->rh_rsc->id, order->rh_action_task); } else if(order->rh_action != NULL && order->rh_action->rsc != NULL) { crm_debug_3("RH-Side was: (%s/%s)", order->rh_action->rsc->id, order->rh_action_task); } else if(order->rh_action != NULL) { crm_debug_3("RH-Side was: %s", order->rh_action_task); } else { crm_debug_3("RH-Side was NULL"); } return; } } else { pe_warn("No LH-Side (%s) specified for constraint", order->lh_action_task); if(order->rh_rsc != NULL) { crm_debug_3("RH-Side was: (%s/%s)", order->rh_rsc->id, order->rh_action_task); } else if(order->rh_action != NULL && order->rh_action->rsc != NULL) { crm_debug_3("RH-Side was: (%s/%s)", order->rh_action->rsc->id, order->rh_action_task); } else if(order->rh_action != NULL) { crm_debug_3("RH-Side was: %s", order->rh_action_task); } else { crm_debug_3("RH-Side was NULL"); } return; } slist_iter( lh_action_iter, action_t, lh_actions, lpc, resource_t *rh_rsc = order->rh_rsc; if(rh_rsc == NULL && order->rh_action) { rh_rsc = order->rh_action->rsc; } if(rh_rsc) { rh_rsc->fns->rsc_order_rh( lh_action_iter, rh_rsc, order); } else if(order->rh_action) { order_actions(lh_action_iter, order->rh_action, order); } ); pe_free_shallow_adv(lh_actions, FALSE); } void native_rsc_order_rh( action_t *lh_action, resource_t *rsc, order_constraint_t *order) { GListPtr rh_actions = NULL; action_t *rh_action = order->rh_action; crm_debug_2("Processing RH of ordering constraint %d", order->id); if(rh_action != NULL) { rh_actions = g_list_append(NULL, rh_action); } else if(rh_action == NULL && rsc != NULL) { rh_actions = find_actions( rsc->actions, order->rh_action_task, NULL); if(rh_actions == NULL) { crm_debug_3("No RH-Side (%s/%s) found for constraint..." " ignoring", rsc->id, order->rh_action_task); crm_debug_3("LH-Side was: (%s/%s)", order->lh_rsc?order->lh_rsc->id:order->lh_action?order->lh_action->rsc->id:"", order->lh_action_task); return; } } else if(rh_action == NULL) { crm_debug_3("No RH-Side (%s) specified for constraint..." " ignoring", order->rh_action_task); crm_debug_3("LH-Side was: (%s/%s)", order->lh_rsc?order->lh_rsc->id:order->lh_action?order->lh_action->rsc->id:"", order->lh_action_task); return; } slist_iter( rh_action_iter, action_t, rh_actions, lpc, order_actions(lh_action, rh_action_iter, order); ); pe_free_shallow_adv(rh_actions, FALSE); } void native_rsc_location(resource_t *rsc, rsc_to_node_t *constraint) { GListPtr or_list; native_variant_data_t *native_data = NULL; crm_action_debug_3(print_rsc_to_node("Applying", constraint, FALSE)); /* take "lifetime" into account */ if(constraint == NULL) { pe_err("Constraint is NULL"); return; } else if(is_active(constraint) == FALSE) { crm_debug("Constraint (%s) is not active", constraint->id); return; } else if(rsc == NULL) { pe_err("LHS of rsc_to_node (%s) is NULL", constraint->id); return; } get_native_variant_data(native_data, rsc); native_data->node_cons = g_list_append(native_data->node_cons, constraint); if(constraint->node_list_rh == NULL) { crm_debug("RHS of constraint %s is NULL", constraint->id); return; } crm_action_debug_3(print_resource("before update", rsc,TRUE)); or_list = node_list_or( native_data->allowed_nodes, constraint->node_list_rh, FALSE); pe_free_shallow(native_data->allowed_nodes); native_data->allowed_nodes = or_list; slist_iter(node_rh, node_t, constraint->node_list_rh, lpc, native_update_node_weight( rsc, constraint, node_rh->details->uname, native_data->allowed_nodes)); crm_action_debug_3(print_resource("after update", rsc, TRUE)); } void native_expand(resource_t *rsc, crm_data_t * *graph) { slist_iter( action, action_t, rsc->actions, lpc, crm_debug_3("processing action %d for rsc=%s", action->id, rsc->id); graph_element_from_action(action, graph); ); } void native_dump(resource_t *rsc, const char *pre_text, gboolean details) { native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); common_dump(rsc, pre_text, details); crm_debug_3("\t%d candidate colors, %d allowed nodes," " %d rsc_cons and %d node_cons", g_list_length(rsc->candidate_colors), g_list_length(native_data->allowed_nodes), g_list_length(rsc->rsc_cons), g_list_length(native_data->node_cons)); if(details) { crm_debug_3("\t=== Actions"); slist_iter( action, action_t, rsc->actions, lpc, print_action("\trsc action: ", action, FALSE); ); crm_debug_3("\t=== Colors"); slist_iter( color, color_t, rsc->candidate_colors, lpc, print_color("\t", color, FALSE) ); crm_debug_3("\t=== Allowed Nodes"); slist_iter( node, node_t, native_data->allowed_nodes, lpc, print_node("\t", node, FALSE); ); } } void native_free(resource_t *rsc) { native_variant_data_t *native_data = (native_variant_data_t *)rsc->variant_opaque; - crm_debug_3("Freeing Allowed Nodes"); + crm_debug_3("Freeing Allowed Nodes & Agent"); pe_free_shallow(native_data->allowed_nodes); crm_free(native_data->agent); common_free(rsc); } void native_rsc_colocation_rh_must(resource_t *rsc_lh, gboolean update_lh, resource_t *rsc_rh, gboolean update_rh) { native_variant_data_t *native_data_lh = NULL; native_variant_data_t *native_data_rh = NULL; gboolean do_merge = FALSE; GListPtr old_list = NULL; GListPtr merged_node_list = NULL; float max_pri = rsc_lh->effective_priority; if(max_pri < rsc_rh->effective_priority) { max_pri = rsc_rh->effective_priority; } rsc_lh->effective_priority = max_pri; rsc_rh->effective_priority = max_pri; get_native_variant_data(native_data_lh, rsc_lh); get_native_variant_data(native_data_rh, rsc_rh); if(native_data_lh->color && native_data_rh->color) { do_merge = TRUE; merged_node_list = node_list_and( native_data_lh->color->details->candidate_nodes, native_data_rh->color->details->candidate_nodes, TRUE); } else if(native_data_lh->color) { do_merge = TRUE; merged_node_list = node_list_and( native_data_lh->color->details->candidate_nodes, native_data_rh->allowed_nodes, TRUE); } else if(native_data_rh->color) { do_merge = TRUE; merged_node_list = node_list_and( native_data_lh->allowed_nodes, native_data_rh->color->details->candidate_nodes, TRUE); } if(update_lh) { crm_free(native_data_lh->color); rsc_lh->runnable = rsc_rh->runnable; rsc_lh->provisional = rsc_rh->provisional; native_data_lh->color = copy_color(native_data_rh->color); } if(update_rh) { crm_free(native_data_rh->color); rsc_rh->runnable = rsc_lh->runnable; rsc_rh->provisional = rsc_lh->provisional; native_data_rh->color = copy_color(native_data_lh->color); } if((update_rh || update_lh) && do_merge) { crm_debug_3("Merging candidate nodes"); old_list = native_data_rh->color->details->candidate_nodes; native_data_rh->color->details->candidate_nodes = merged_node_list; pe_free_shallow(old_list); } crm_debug_3("Finished processing pecs_must constraint"); } void native_rsc_colocation_rh_mustnot(resource_t *rsc_lh, gboolean update_lh, resource_t *rsc_rh, gboolean update_rh) { color_t *color_lh = NULL; color_t *color_rh = NULL; native_variant_data_t *native_data_lh = NULL; native_variant_data_t *native_data_rh = NULL; get_native_variant_data(native_data_lh, rsc_lh); get_native_variant_data(native_data_rh, rsc_rh); crm_debug_3("Processing pecs_must_not constraint"); /* pecs_must_not */ if(update_lh) { color_rh = native_data_rh->color; if(rsc_lh->provisional) { color_lh = find_color( rsc_lh->candidate_colors, color_rh); rsc_lh->candidate_colors = g_list_remove( rsc_lh->candidate_colors, color_lh); crm_action_debug_3( print_color("Removed LH", color_lh, FALSE)); crm_action_debug_3( print_resource("Modified LH", rsc_lh, TRUE)); crm_free(color_lh); } else if(native_data_lh->color && native_data_lh->color->details->pending) { node_t *node_lh = NULL; color_lh = native_data_lh->color; node_lh = pe_find_node( color_lh->details->candidate_nodes, safe_val5(NULL, color_rh, details, chosen_node, details, uname)); color_lh->details->candidate_nodes = g_list_remove( color_lh->details->candidate_nodes, node_lh); crm_action_debug_3( print_node("Removed LH", node_lh, FALSE)); crm_action_debug_3( print_color("Modified LH", color_lh, FALSE)); crm_free(node_lh); } else { /* error, rsc marked as unrunnable above */ pe_warn("lh else"); } } if(update_rh) { color_lh = native_data_lh->color; if(rsc_rh->provisional) { color_rh = find_color( rsc_rh->candidate_colors, color_lh); rsc_rh->candidate_colors = g_list_remove( rsc_rh->candidate_colors, color_rh); crm_action_debug_3( print_color("Removed RH", color_rh, FALSE)); crm_action_debug_3( print_resource("Modified RH", rsc_rh, TRUE)); crm_free(color_rh); } else if(native_data_rh->color && native_data_rh->color->details->pending) { node_t *node_rh = NULL; color_rh = native_data_rh->color; node_rh = pe_find_node( color_rh->details->candidate_nodes, safe_val5(NULL, color_lh, details, chosen_node, details, uname)); color_rh->details->candidate_nodes = g_list_remove( color_rh->details->candidate_nodes, node_rh); crm_action_debug_3( print_node("Removed RH", node_rh, FALSE)); crm_action_debug_3( print_color("Modified RH", color_rh, FALSE)); crm_free(node_rh); } else { /* error, rsc marked as unrunnable above */ pe_warn("rh else"); } } } void native_agent_constraints(resource_t *rsc) { native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); crm_debug_4("Applying RA restrictions to %s", rsc->id); common_agent_constraints( native_data->allowed_nodes, native_data->agent, rsc->id); } gboolean native_choose_color(resource_t *rsc) { GListPtr sorted_colors = NULL; native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); if(rsc->runnable == FALSE) { native_assign_color(rsc, no_color); } if(rsc->provisional == FALSE) { return !rsc->provisional; } sorted_colors = g_list_sort( rsc->candidate_colors, sort_color_weight); rsc->candidate_colors = sorted_colors; crm_debug_2("Choose a color from %d possibilities", g_list_length(sorted_colors)); slist_iter( this_color, color_t, rsc->candidate_colors, lpc, GListPtr intersection = NULL; GListPtr minus = NULL; int len = 0; if(this_color == NULL) { pe_err("color was NULL"); continue; } else if(rsc->effective_priority < this_color->details->highest_priority) { minus = node_list_minus( this_color->details->candidate_nodes, native_data->allowed_nodes, TRUE); len = g_list_length(minus); pe_free_shallow(minus); if(len > 0) { native_assign_color(rsc, this_color); break; } } else { intersection = node_list_and( this_color->details->candidate_nodes, native_data->allowed_nodes, TRUE); len = g_list_length(intersection); pe_free_shallow(intersection); if(len != 0) { native_assign_color(rsc, this_color); break; } } ); return !rsc->provisional; } void native_assign_color(resource_t *rsc, color_t *color) { color_t *local_color = add_color(rsc, color); GListPtr intersection = NULL; GListPtr old_list = NULL; native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); native_data->color = local_color; rsc->provisional = FALSE; if(local_color != NULL) { (local_color->details->num_resources)++; local_color->details->allocated_resources = g_list_append( local_color->details->allocated_resources,rsc); intersection = node_list_and( local_color->details->candidate_nodes, native_data->allowed_nodes, TRUE); old_list = local_color->details->candidate_nodes; pe_free_shallow(old_list); local_color->details->candidate_nodes = intersection; crm_debug_2("Colored resource %s with new color %d", rsc->id, native_data->color->id); crm_action_debug_3( print_resource("Colored Resource", rsc, TRUE)); } else { pe_err("local color was NULL"); } return; } void native_update_node_weight(resource_t *rsc, rsc_to_node_t *cons, const char *id, GListPtr nodes) { node_t *node_rh = NULL; native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); node_rh = pe_find_node(native_data->allowed_nodes, id); if(node_rh == NULL) { pe_err("Node not found - cant update"); return; } if(node_rh->weight >= INFINITY && cons->weight == -INFINITY) { pe_err("Constraint %s mixes +/- INFINITY", cons->id); } else if(node_rh->weight <= -INFINITY && cons->weight == INFINITY) { pe_err("Constraint %s mixes +/- INFINITY", cons->id); } if(node_rh->fixed) { /* warning */ crm_debug("Constraint %s is irrelevant as the" " weight of node %s is fixed as %f.", cons->id, node_rh->details->uname, node_rh->weight); return; } if(cons->weight != INFINITY && cons->weight != -INFINITY) { crm_debug_2("Constraint %s (%f): node %s weight %f.", cons->id, cons->weight, node_rh->details->uname, node_rh->weight); } else if(cons->weight == -INFINITY) { crm_debug_2("Constraint %s (-INFINITY): node %s weight %f.", cons->id, node_rh->details->uname, node_rh->weight); } else { crm_debug_2("Constraint %s (+INFINITY): node %s weight %f.", cons->id, node_rh->details->uname, node_rh->weight); } node_rh->weight = merge_weights(node_rh->weight, cons->weight); if(node_rh->weight < 0) { node_rh->fixed = TRUE; } crm_action_debug_3(print_node("Updated", node_rh, FALSE)); return; } gboolean native_constraint_violated( resource_t *rsc_lh, resource_t *rsc_rh, rsc_colocation_t *constraint) { native_variant_data_t *native_data_lh = NULL; native_variant_data_t *native_data_rh = NULL; GListPtr result = NULL; color_t *color_lh = NULL; color_t *color_rh = NULL; GListPtr candidate_nodes_lh = NULL; GListPtr candidate_nodes_rh = NULL; gboolean matched = FALSE; get_native_variant_data(native_data_lh, rsc_lh); get_native_variant_data(native_data_rh, rsc_rh); color_lh = native_data_lh->color; color_rh = native_data_rh->color; if(constraint->strength == pecs_must_not) { matched = TRUE; } if(rsc_lh->provisional || rsc_rh->provisional) { return FALSE; } if(color_lh->details->pending && color_rh->details->pending) { candidate_nodes_lh = color_lh->details->candidate_nodes; candidate_nodes_rh = color_rh->details->candidate_nodes; } else if(color_lh->details->pending == FALSE && color_rh->details->pending == FALSE) { if(color_lh == NULL && color_rh == NULL) { return matched; } else if(color_lh == NULL || color_rh == NULL) { return !matched; } else if(color_lh->details->chosen_node == NULL && color_rh->details->chosen_node == NULL) { return matched; } else if(color_lh->details->chosen_node == NULL || color_rh->details->chosen_node == NULL) { return !matched; } else if(safe_str_eq( color_lh->details->chosen_node->details->id, color_rh->details->chosen_node->details->id)) { return matched; } return !matched; } else if(color_lh->details->pending) { candidate_nodes_lh = color_lh->details->candidate_nodes; candidate_nodes_rh = g_list_append( NULL, color_rh->details->chosen_node); } else if(color_rh->details->pending) { candidate_nodes_rh = color_rh->details->candidate_nodes; candidate_nodes_lh = g_list_append( NULL, color_lh->details->chosen_node); } result = node_list_and(candidate_nodes_lh, candidate_nodes_rh, TRUE); if(g_list_length(result) == 0 && constraint->strength == pecs_must) { /* free result */ return TRUE; } return FALSE; } /* * Remove any nodes with a -ve weight */ void filter_nodes(resource_t *rsc) { native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); crm_action_debug_3(print_resource("Filtering nodes for", rsc, FALSE)); slist_iter( node, node_t, native_data->allowed_nodes, lpc, if(node == NULL) { pe_err("Invalid NULL node"); } else if(node->weight < 0.0 || node->details->online == FALSE || node->details->type == node_ping) { crm_action_debug_3(print_node("Removing", node, FALSE)); native_data->allowed_nodes = g_list_remove(native_data->allowed_nodes, node); crm_free(node); lpc = -1; /* restart the loop */ } ); } diff --git a/crm/pengine/pengine.c b/crm/pengine/pengine.c index 15c469e435..75757a4f8b 100755 --- a/crm/pengine/pengine.c +++ b/crm/pengine/pengine.c @@ -1,229 +1,310 @@ -/* $Id: pengine.c,v 1.66 2005/05/18 20:15:58 andrew Exp $ */ +/* $Id: pengine.c,v 1.67 2005/05/20 09:48:15 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * 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 #include #include #include #include #include #include #include #include +extern GListPtr global_action_list; + crm_data_t * do_calculations(crm_data_t *cib_object); +void cleanup_calculations( + GListPtr resources, GListPtr nodes, GListPtr placement_constraints, + GListPtr actions, GListPtr ordering_constraints, GListPtr stonith_list, + GListPtr shutdown_list, GListPtr colors, GListPtr action_sets); + int num_synapse = 0; gboolean was_processing_error = FALSE; gboolean was_processing_warning = FALSE; +cl_mem_stats_t *mem_stats = NULL; gboolean process_pe_message(HA_Message *msg, crm_data_t * xml_data, IPC_Channel *sender) { const char *sys_to = cl_get_string(msg, F_CRM_SYS_TO); const char *op = cl_get_string(msg, F_CRM_TASK); const char *ref = cl_get_string(msg, XML_ATTR_REFERENCE); crm_debug_2("Processing %s op (ref=%s)...", op, ref); if(op == NULL){ /* error */ } else if(strcmp(op, CRM_OP_HELLO) == 0) { /* ignore */ } else if(safe_str_eq(cl_get_string(msg, F_CRM_MSG_TYPE), XML_ATTR_RESPONSE)) { /* ignore */ } else if(sys_to == NULL || strcmp(sys_to, CRM_SYSTEM_PENGINE) != 0) { crm_debug_2("Bad sys-to %s", crm_str(sys_to)); return FALSE; } else if(strcmp(op, CRM_OP_PECALC) == 0) { crm_data_t *generation = create_xml_node(NULL, XML_TAG_CIB); crm_data_t *status = get_object_root( XML_CIB_TAG_STATUS, xml_data); crm_data_t *log_input = status; crm_data_t *output = NULL; + log_input = xml_data; + copy_in_properties(generation, xml_data); crm_log_xml_info(generation, "[generation]"); #if 0 char *xml_buffer = NULL; char *xml_buffer_ptr = NULL; int max_xml = MAXLINE - 8; xml_buffer = dump_xml_unformatted(generation); LogToCircularBuffer(input_buffer, LOG_INFO, "Generation: %s", xml_buffer); crm_free(xml_buffer); xml_buffer = dump_xml_unformatted(status); xml_buffer_ptr = xml_buffer; while(xml_buffer_ptr != NULL) { LogToCircularBuffer(input_buffer, LOG_INFO, "PE xml: %s", xml_buffer_ptr); if(strlen(xml_buffer_ptr) > max_xml) { xml_buffer_ptr = xml_buffer_ptr + max_xml; } else { xml_buffer_ptr = NULL;; } } crm_free(xml_buffer); #endif was_processing_error = FALSE; was_processing_warning = FALSE; +#ifndef CRM_USE_MALLOC + crm_malloc0(mem_stats, sizeof(cl_mem_stats_t)); + cl_malloc_setstats(mem_stats); +#endif output = do_calculations(xml_data); + +#ifndef CRM_USE_MALLOC + crm_mem_stats(mem_stats); + if(mem_stats->nbytes_alloc != 0) { + pe_err("Unfree'd memory"); + } else { + crm_info("All memory was free'd"); + } + cl_malloc_setstats(NULL); +#endif if(was_processing_error) { crm_err("ERRORs found during PE processing." " Input follows:"); crm_log_xml_info(log_input, "[input]"); } else if(was_processing_warning) { crm_warn("WARNINGs found during PE processing." " Input follows:"); crm_log_xml_debug(log_input, "[input]"); } else { crm_log_xml_debug_2(log_input, "[input]"); } crm_log_xml_debug_3(output, "[out]"); if (send_ipc_reply(sender, msg, output) ==FALSE) { - crm_warn("Answer could not be sent"); + crm_err("Answer could not be sent"); } free_xml(output); free_xml(generation); + } else if(strcmp(op, CRM_OP_QUIT) == 0) { crm_warn("Received quit message, terminating"); exit(0); } return TRUE; } crm_data_t * do_calculations(crm_data_t * cib_object) { GListPtr resources = NULL; GListPtr nodes = NULL; GListPtr placement_constraints = NULL; GListPtr actions = NULL; GListPtr ordering_constraints = NULL; GListPtr stonith_list = NULL; GListPtr shutdown_list = NULL; GListPtr colors = NULL; GListPtr action_sets = NULL; crm_data_t * graph = NULL; /* pe_debug_on(); */ crm_debug_4("unpack"); stage0(cib_object, &resources, &nodes, &placement_constraints, &actions, &ordering_constraints, &stonith_list, &shutdown_list); - + crm_debug_4("apply placement constraints"); stage1(placement_constraints, nodes, resources); crm_debug_4("color resources"); stage2(resources, nodes, &colors); /* unused */ stage3(colors); crm_debug_4("assign nodes to colors"); - stage4(colors); + stage4(colors); crm_debug_4("creating actions and internal ording constraints"); stage5(resources, &ordering_constraints); - + crm_debug_4("processing fencing and shutdown cases"); stage6(&actions, &ordering_constraints, nodes, resources); crm_debug_4("applying ordering constraints"); stage7(resources, actions, ordering_constraints); + + crm_debug("=#=#=#=#= Summary =#=#=#=#="); + crm_debug("========= All Actions ========="); + slist_iter(action, action_t, actions, lpc, + print_action("\t", action, TRUE); + ); - crm_debug_2("\t========= Set %d (Un-runnable) =========", -1); + crm_debug("\t========= Set %d (Un-runnable) =========", -1); crm_action_debug_2( slist_iter(action, action_t, actions, lpc, if(action->optional == FALSE && action->runnable == FALSE) { log_action(LOG_DEBUG_2, "\t", action, TRUE); } ) ); - crm_debug_2("========= Stonith List ========="); + crm_debug("========= Stonith List ========="); crm_action_debug_3( slist_iter(node, node_t, stonith_list, lpc, print_node(NULL, node, FALSE); ) ); - crm_debug_2("========= Shutdown List ========="); + crm_debug("========= Shutdown List ========="); crm_action_debug_3( slist_iter(node, node_t, shutdown_list, lpc, print_node(NULL, node, FALSE); ) ); crm_debug_4("creating transition graph"); stage8(resources, actions, &graph); + +#if 0 + cleanup_calculations( + resources, nodes, placement_constraints, actions, + ordering_constraints, stonith_list, shutdown_list, + colors, action_sets); + free_xml(cib_object); + free_xml(graph); + crm_mem_stats(mem_stats); + crm_err("Exiting"); + exit(1); +#endif - crm_debug_2("Cleaning up"); + cleanup_calculations( + resources, nodes, placement_constraints, actions, + ordering_constraints, stonith_list, shutdown_list, + colors, action_sets); + + return graph; +} +void +cleanup_calculations(GListPtr resources, + GListPtr nodes, + GListPtr placement_constraints, + GListPtr actions, + GListPtr ordering_constraints, + GListPtr stonith_list, + GListPtr shutdown_list, + GListPtr colors, + GListPtr action_sets) +{ + crm_free(dc_uuid); + dc_uuid = NULL; + + crm_debug_2("deleting node cons"); while(placement_constraints) { pe_free_rsc_to_node((rsc_to_node_t*)placement_constraints->data); placement_constraints = placement_constraints->next; } if(placement_constraints != NULL) { g_list_free(placement_constraints); } - + + crm_debug_2("deleting order cons"); pe_free_ordering(ordering_constraints); + + crm_debug_2("deleting action sets"); slist_iter(action_set, GList, action_sets, lpc, pe_free_shallow_adv(action_set, FALSE); ); pe_free_shallow_adv(action_sets, FALSE); + + crm_debug_2("deleting global actions"); + pe_free_actions(global_action_list); + global_action_list = NULL; +/* crm_debug_2("deleting actions"); */ /* pe_free_actions(actions); */ + + crm_debug_2("deleting resources"); pe_free_resources(resources); + + crm_debug_2("deleting colors"); pe_free_colors(colors); - pe_free_nodes(nodes); + if(no_color != NULL) { + crm_free(no_color->details); + crm_free(no_color); + } + + crm_debug_2("deleting nodes"); + pe_free_nodes(nodes); + if(shutdown_list != NULL) { g_list_free(shutdown_list); } if(stonith_list != NULL) { g_list_free(stonith_list); } - - return graph; } diff --git a/crm/pengine/pengine.h b/crm/pengine/pengine.h index 14172883eb..d33ec100de 100644 --- a/crm/pengine/pengine.h +++ b/crm/pengine/pengine.h @@ -1,371 +1,386 @@ -/* $Id: pengine.h,v 1.63 2005/05/17 14:33:39 andrew Exp $ */ +/* $Id: pengine.h,v 1.64 2005/05/20 09:48:15 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * 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 */ #ifndef PENGINE__H #define PENGINE__H #include typedef struct node_s node_t; typedef struct color_s color_t; typedef struct rsc_to_node_s rsc_to_node_t; typedef struct rsc_colocation_s rsc_colocation_t; typedef struct resource_s resource_t; typedef struct lrm_agent_s lrm_agent_t; typedef struct order_constraint_s order_constraint_t; typedef struct action_s action_t; typedef struct action_wrapper_s action_wrapper_t; #include #include #include #include typedef enum no_quorum_policy_e { no_quorum_freeze, no_quorum_stop, no_quorum_ignore } no_quorum_policy_t; enum con_type { type_none, rsc_colocation, rsc_to_node, rsc_to_attr, base_weight }; enum node_type { node_ping, node_member }; enum con_strength { pecs_ignore, pecs_must, pecs_must_not, pecs_startstop }; enum action_tasks { no_action, monitor_rsc, stop_rsc, stopped_rsc, start_rsc, started_rsc, shutdown_crm, stonith_node }; enum rsc_recovery_type { recovery_stop_start, recovery_stop_only, recovery_block }; enum pe_stop_fail { pesf_block, pesf_stonith, pesf_ignore }; enum pe_restart { pe_restart_restart, pe_restart_ignore }; +typedef struct pe_working_set_s +{ + crm_data_t *input; + + GListPtr nodes; + GListPtr resources; + GListPtr placement_constraints; + GListPtr ordering_constraints; + + GListPtr colors; + GListPtr actions; + GListPtr action_sets; + GListPtr stonith_list; + GListPtr shutdown_list; +} pe_working_set_t; + struct node_shared_s { const char *id; const char *uname; gboolean online; gboolean unclean; gboolean shutdown; gboolean expected_up; gboolean is_dc; int num_resources; GListPtr running_rsc; /* resource_t* */ - GListPtr agents; /* lrm_agent_t* */ GHashTable *attrs; /* char* => char* */ enum node_type type; }; struct node_s { float weight; gboolean fixed; struct node_shared_s *details; }; struct color_shared_s { int id; float highest_priority; GListPtr candidate_nodes; /* node_t* */ GListPtr allocated_resources; /* resources_t* */ node_t *chosen_node; gboolean pending; int num_resources; }; struct color_s { int id; struct color_shared_s *details; float local_weight; }; struct rsc_colocation_s { const char *id; resource_t *rsc_lh; resource_t *rsc_rh; enum con_strength strength; }; struct rsc_to_node_s { - const char *id; - resource_t *rsc_lh; + const char *id; + resource_t *rsc_lh; - float weight; - GListPtr node_list_rh; /* node_t* */ + float weight; + GListPtr node_list_rh; /* node_t* */ }; struct lrm_agent_s { const char *class; const char *type; const char *version; }; struct resource_s { const char *id; - crm_data_t * xml; - crm_data_t * ops_xml; + crm_data_t *xml; + crm_data_t *ops_xml; void *variant_opaque; enum pe_obj_types variant; resource_object_functions_t *fns; enum rsc_recovery_type recovery_type; enum pe_stop_fail stopfail_type; enum pe_restart restart_type; float priority; float effective_priority; gboolean start_pending; gboolean schedule_recurring; gboolean recover; gboolean starting; gboolean stopping; gboolean is_stonith; gboolean runnable; gboolean provisional; gboolean unclean; GListPtr candidate_colors; /* color_t* */ GListPtr rsc_cons; /* rsc_colocation_t* */ GListPtr actions; /* action_t* */ GHashTable * parameters; }; struct action_wrapper_s { enum con_strength strength; action_t *action; }; struct action_s { int id; resource_t *rsc; void *rsc_opaque; node_t *node; const char *task; char *uuid; crm_data_t *op_entry; gboolean pseudo; gboolean runnable; gboolean optional; gboolean failure_is_fatal; gboolean dumped; gboolean processed; int seen_count; /* crm_data_t *args; */ GHashTable *extra; GListPtr actions_before; /* action_warpper_t* */ GListPtr actions_after; /* action_warpper_t* */ }; struct order_constraint_s { int id; enum con_strength strength; void *lh_opaque; resource_t *lh_rsc; action_t *lh_action; char *lh_action_task; void *rh_opaque; resource_t *rh_rsc; action_t *rh_action; char *rh_action_task; /* (soon to be) variant specific */ /* int lh_rsc_incarnation; */ /* int rh_rsc_incarnation; */ }; extern gboolean stage0(crm_data_t *cib, GListPtr *nodes, GListPtr *rscs, GListPtr *cons, GListPtr *actions, GListPtr *ordering_constraints, GListPtr *stonith_list, GListPtr *shutdown_list); extern gboolean stage1(GListPtr placement_constraints, GListPtr nodes, GListPtr resources); extern gboolean stage2(GListPtr sorted_rscs, GListPtr sorted_nodes, GListPtr *colors); extern gboolean stage3(GListPtr colors); extern gboolean stage4(GListPtr colors); extern gboolean stage5(GListPtr resources, GListPtr *ordering_constraints); extern gboolean stage6( GListPtr *actions, GListPtr *ordering_constraints, GListPtr nodes, GListPtr resources); extern gboolean stage7( GListPtr resources, GListPtr actions, GListPtr ordering_constraints); extern gboolean stage8( GListPtr resources, GListPtr action_sets, crm_data_t **graph); extern gboolean summary(GListPtr resources); extern gboolean pe_msg_dispatch(IPC_Channel *sender, void *user_data); extern gboolean process_pe_message( HA_Message *msg, crm_data_t *xml_data, IPC_Channel *sender); extern gboolean unpack_constraints(crm_data_t *xml_constraints, GListPtr nodes, GListPtr resources, GListPtr *placement_constraints, GListPtr *ordering_constraints); extern gboolean unpack_resources(crm_data_t *xml_resources, GListPtr *resources, GListPtr *actions, GListPtr *ordering_constraints, GListPtr *placement_constraints, GListPtr all_nodes); extern gboolean unpack_config(crm_data_t *config); extern gboolean unpack_config(crm_data_t *config); extern gboolean unpack_nodes(crm_data_t *xml_nodes, GListPtr *nodes); extern gboolean unpack_status(crm_data_t *status, GListPtr nodes, GListPtr rsc_list, GListPtr *actions, GListPtr *placement_constraints); extern gboolean apply_placement_constraints(GListPtr constraints, GListPtr nodes); extern gboolean apply_agent_constraints(GListPtr resources); extern void color_resource(resource_t *lh_resource, GListPtr *colors, GListPtr resources); extern gboolean choose_node_from_list(color_t *color); extern gboolean update_action_states(GListPtr actions); extern gboolean shutdown_constraints( node_t *node, action_t *shutdown_op, GListPtr *ordering_constraints); extern gboolean stonith_constraints( node_t *node, action_t *stonith_op, action_t *shutdown_op, GListPtr *ordering_constraints); extern gboolean custom_action_order( resource_t *lh_rsc, char *lh_task, action_t *lh_action, resource_t *rh_rsc, char *rh_task, action_t *rh_action, enum con_strength strength, GListPtr *ordering_constraints); #define order_start_start(rsc1,rsc2) \ custom_action_order(rsc1, start_key(rsc1), NULL, \ rsc2, start_key(rsc2) ,NULL, \ pecs_startstop, ordering_constraints) #define order_stop_stop(rsc1, rsc2) \ custom_action_order(rsc1, stop_key(rsc1), NULL, \ rsc2, stop_key(rsc2) ,NULL, \ pecs_startstop, ordering_constraints) #define order_stop_start(rsc1, rsc2) \ custom_action_order(rsc1, stop_key(rsc1), NULL, \ rsc2, start_key(rsc2) ,NULL, \ pecs_startstop, ordering_constraints) #define order_start_stop(rsc1, rsc2) \ custom_action_order(rsc1, start_key(rsc1), NULL, \ rsc2, stop_key(rsc2) ,NULL, \ pecs_startstop, ordering_constraints) #define pe_err(fmt...) { was_processing_error = TRUE; crm_err(fmt); } #define pe_warn(fmt...) { was_processing_warning = TRUE; crm_warn(fmt); } extern gboolean process_colored_constraints(resource_t *rsc); extern void graph_element_from_action(action_t *action, crm_data_t **graph); extern color_t *no_color; extern int max_valid_nodes; extern int order_id; extern int action_id; extern gboolean stonith_enabled; extern gboolean have_quorum; extern no_quorum_policy_t no_quorum_policy; extern gboolean symmetric_cluster; extern GListPtr agent_defaults; extern const char* transition_timeout; extern int num_synapse; extern int color_id; extern char *dc_uuid; extern gboolean was_processing_error; extern gboolean was_processing_warning; #endif diff --git a/crm/pengine/ptest.c b/crm/pengine/ptest.c index 1644564693..afacef78d7 100644 --- a/crm/pengine/ptest.c +++ b/crm/pengine/ptest.c @@ -1,248 +1,165 @@ -/* $Id: ptest.c,v 1.48 2005/05/19 10:53:44 andrew Exp $ */ +/* $Id: ptest.c,v 1.49 2005/05/20 09:48:15 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * 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 #include #include #include #include #include #include #include #include #include #include #include #define OPTARGS "V?X:w" #include #include #include #include gboolean inhibit_exit = FALSE; +extern crm_data_t * do_calculations(crm_data_t *cib_object); +extern cl_mem_stats_t *mem_stats; int main(int argc, char **argv) { crm_data_t * cib_object = NULL; int argerr = 0; int flag; - GListPtr resources = NULL; - GListPtr nodes = NULL; - GListPtr placement_constraints = NULL; - GListPtr actions = NULL; - GListPtr ordering_constraints = NULL; - GListPtr stonith_list = NULL; - GListPtr shutdown_list = NULL; - GListPtr colors = NULL; - GListPtr action_sets = NULL; crm_data_t * graph = NULL; char *msg_buffer = NULL; const char *xml_file = NULL; cl_log_set_entity("ptest"); cl_log_set_facility(LOG_USER); set_crm_log_level(LOG_WARNING); while (1) { int option_index = 0; static struct option long_options[] = { /* Top-level Options */ {F_CRM_DATA, 1, 0, 'X'}, {"help", 0, 0, 0}, {0, 0, 0, 0} }; flag = getopt_long(argc, argv, OPTARGS, long_options, &option_index); if (flag == -1) break; switch(flag) { case 0: printf("option %s", long_options[option_index].name); if (optarg) printf(" with arg %s", optarg); printf("\n"); break; case 'w': inhibit_exit = TRUE; break; case 'X': xml_file = crm_strdup(optarg); break; case 'V': cl_log_enable_stderr(TRUE); alter_debug(DEBUG_INC); break; default: printf("?? getopt returned character code 0%o ??\n", flag); ++argerr; break; } } if (optind < argc) { printf("non-option ARGV-elements: "); while (optind < argc) { printf("%s ", argv[optind++]); } printf("\n"); } if (optind > argc) { ++argerr; } if (argerr) { crm_err("%d errors in option parsing", argerr); } crm_info("=#=#=#=#= Getting XML =#=#=#=#="); - +#ifndef CRM_USE_MALLOC + crm_malloc0(mem_stats, sizeof(cl_mem_stats_t)); + cl_malloc_setstats(mem_stats); +#endif + if(xml_file != NULL) { FILE *xml_strm = fopen(xml_file, "r"); cib_object = file2xml(xml_strm); } else { cib_object = stdin2xml(); } + #ifdef MCHECK mtrace(); -#endif - crm_debug("unpack"); - stage0(cib_object, - &resources, - &nodes, &placement_constraints, - &actions, &ordering_constraints, - &stonith_list, &shutdown_list); - - crm_debug("apply placement constraints"); - stage1(placement_constraints, nodes, resources); - - crm_debug("color resources"); - stage2(resources, nodes, &colors); - - /* unused */ - stage3(colors); - - crm_debug("assign nodes to colors"); - stage4(colors); - - crm_debug("creating actions and internal ording constraints"); - stage5(resources, &ordering_constraints); - - crm_debug("processing fencing and shutdown cases"); - stage6(&actions, &ordering_constraints, nodes, resources); - - crm_debug("applying ordering constraints"); - stage7(resources, actions, ordering_constraints); - - crm_debug("=#=#=#=#= Summary =#=#=#=#="); - crm_debug("========= All Actions ========="); - slist_iter(action, action_t, actions, lpc, - print_action("\t", action, TRUE); - ); - - crm_debug("========= Stonith List ========="); - slist_iter(node, node_t, stonith_list, lpc, - print_node(NULL, node, FALSE)); - - crm_debug("========= Shutdown List ========="); - slist_iter(node, node_t, shutdown_list, lpc, - print_node(NULL, node, FALSE)); - - crm_debug("creating transition graph"); - stage8(resources, actions, &graph); - - - crm_debug_2("deleting node cons"); - while(placement_constraints) { - pe_free_rsc_to_node((rsc_to_node_t*)placement_constraints->data); - placement_constraints = placement_constraints->next; - } - if(placement_constraints != NULL) { - g_list_free(placement_constraints); - } - - crm_debug_2("deleting order cons"); - pe_free_ordering(ordering_constraints); - - crm_debug_2("deleting action sets"); - slist_iter(action_set, GList, action_sets, lpc, - pe_free_shallow_adv(action_set, FALSE); - ); - pe_free_shallow_adv(action_sets, FALSE); - - crm_debug_2("deleting actions"); - pe_free_actions(actions); - -/* GListPtr action_sets = NULL; */ - - crm_debug_2("deleting resources"); - pe_free_resources(resources); - - crm_debug_2("deleting colors"); - pe_free_colors(colors); - - crm_free(no_color->details); - crm_free(no_color); - - crm_debug_2("deleting nodes"); - pe_free_nodes(nodes); - - if(shutdown_list != NULL) { - g_list_free(shutdown_list); - } - if(stonith_list != NULL) { - g_list_free(stonith_list); - } +#endif + graph = do_calculations(cib_object); #ifdef MCHECK muntrace(); #endif msg_buffer = dump_xml_formatted(graph); fprintf(stdout, "%s\n", msg_buffer); fflush(stdout); crm_free(msg_buffer); free_xml(graph); free_xml(cib_object); +#ifndef CRM_USE_MALLOC + crm_mem_stats(mem_stats); + cl_malloc_setstats(NULL); +#endif + /* required for MallocDebug.app */ if(inhibit_exit) { GMainLoop* mainloop = g_main_new(FALSE); g_main_run(mainloop); } return 0; } diff --git a/crm/pengine/stages.c b/crm/pengine/stages.c index 049c9e3998..382cea83ef 100644 --- a/crm/pengine/stages.c +++ b/crm/pengine/stages.c @@ -1,509 +1,505 @@ -/* $Id: stages.c,v 1.59 2005/05/19 10:54:32 andrew Exp $ */ +/* $Id: stages.c,v 1.60 2005/05/20 09:48:15 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * 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 #include #include #include #include #include #include #include #include node_t *choose_fencer(action_t *stonith, node_t *node, GListPtr resources); void order_actions(action_t *lh, action_t *rh, order_constraint_t *order); int order_id = 1; int max_valid_nodes = 0; GListPtr agent_defaults = NULL; GListPtr global_action_list = NULL; gboolean have_quorum = FALSE; gboolean stonith_enabled = FALSE; gboolean symmetric_cluster = TRUE; no_quorum_policy_t no_quorum_policy = no_quorum_freeze; char *dc_uuid = NULL; const char* transition_timeout = NULL; /* * Unpack everything * At the end you'll have: * - A list of nodes * - A list of resources (each with any dependancies on other resources) * - A list of constraints between resources and nodes * - A list of constraints between start/stop actions * - A list of nodes that need to be stonith'd * - A list of nodes that need to be shutdown * - A list of the possible stop/start actions (without dependancies) */ gboolean stage0(crm_data_t * cib, GListPtr *resources, GListPtr *nodes, GListPtr *placement_constraints, GListPtr *actions, GListPtr *ordering_constraints, GListPtr *stonith_list, GListPtr *shutdown_list) { /* int lpc; */ + crm_data_t * config = get_object_root( + XML_CIB_TAG_CRMCONFIG, cib); crm_data_t * cib_nodes = get_object_root( XML_CIB_TAG_NODES, cib); - crm_data_t * cib_status = get_object_root( - XML_CIB_TAG_STATUS, cib); crm_data_t * cib_resources = get_object_root( XML_CIB_TAG_RESOURCES, cib); + crm_data_t * cib_status = get_object_root( + XML_CIB_TAG_STATUS, cib); crm_data_t * cib_constraints = get_object_root( XML_CIB_TAG_CONSTRAINTS, cib); - crm_data_t * config = get_object_root( - XML_CIB_TAG_CRMCONFIG, cib); crm_debug_2("Beginning unpack"); /* reset remaining global variables */ num_synapse = 0; max_valid_nodes = 0; order_id = 1; action_id = 1; color_id = 0; have_quorum = TRUE; stonith_enabled = FALSE; - if(global_action_list != NULL) { - crm_debug_2("deleting actions"); - pe_free_actions(global_action_list); - global_action_list = NULL; - } - - - crm_free(dc_uuid); dc_uuid = NULL; + CRM_DEV_ASSERT(dc_uuid == NULL); + CRM_DEV_ASSERT(global_action_list == NULL); if(cib == NULL) { return FALSE; } if(cib != NULL && crm_element_value(cib, XML_ATTR_DC_UUID) != NULL) { /* this should always be present */ dc_uuid = crm_element_value_copy(cib, XML_ATTR_DC_UUID); } transition_timeout = "60s"; /* 1 minute */ unpack_config(config); if(no_quorum_policy != no_quorum_ignore) { const char *value = crm_element_value( cib, XML_ATTR_HAVE_QUORUM); have_quorum = FALSE; if(value != NULL) { crm_str_to_boolean(value, &have_quorum); } if(have_quorum == FALSE) { crm_warn("We do not have quorum" " - fencing and resource management disabled"); } } unpack_nodes(cib_nodes, nodes); unpack_resources(cib_resources, resources, actions, ordering_constraints, placement_constraints, *nodes); unpack_status(cib_status, *nodes, *resources, actions, placement_constraints); unpack_constraints(cib_constraints, *nodes, *resources, placement_constraints, ordering_constraints); return TRUE; } /* * Count how many valid nodes we have (so we know the maximum number of * colors we can resolve). * * Apply node constraints (ie. filter the "allowed_nodes" part of resources */ gboolean stage1(GListPtr placement_constraints, GListPtr nodes, GListPtr resources) { crm_debug_2("Applying placement constraints"); slist_iter( node, node_t, nodes, lpc, if(node == NULL) { /* error */ } else if(node->weight >= 0.0 /* global weight */ && node->details->online && node->details->type == node_member) { max_valid_nodes++; } ); apply_placement_constraints(placement_constraints, nodes); /* will also filter -ve "final" weighted nodes from resources' * allowed lists while we are there */ apply_agent_constraints(resources); return TRUE; } /* * Choose a color for all resources from highest priority and XML_STRENGTH_VAL_MUST * dependancies to lowest, creating new colors as necessary (returned * as "colors"). * * Some nodes may be colored as a "no_color" meaning that it was unresolvable * given the current node stati and constraints. */ gboolean stage2(GListPtr sorted_rscs, GListPtr sorted_nodes, GListPtr *colors) { crm_debug_2("Coloring resources"); if(no_color != NULL) { crm_free(no_color->details); crm_free(no_color); } crm_debug_4("create \"no color\""); no_color = create_color(NULL, NULL, NULL); /* Take (next) highest resource */ slist_iter( lh_resource, resource_t, sorted_rscs, lpc, /* if resource.provisional == FALSE, repeat */ if(lh_resource->provisional == FALSE) { /* already processed this resource */ continue; } color_resource(lh_resource, colors, sorted_rscs); /* next resource */ ); return TRUE; } /* * not sure if this is a good idea or not, but eventually we might like * to utilize as many nodes as possible... and this might be a convienient * hook */ gboolean stage3(GListPtr colors) { /* not sure if this is a good idea or not */ if((ssize_t)g_list_length(colors) > max_valid_nodes) { /* we need to consolidate some */ } else if((ssize_t)g_list_length(colors) < max_valid_nodes) { /* we can create a few more */ } return TRUE; } /* * Choose a node for each (if possible) color */ gboolean stage4(GListPtr colors) { crm_debug_2("Assigning nodes to colors"); slist_iter( color, color_t, colors, lpc, crm_debug_3("assigning node to color %d", color->id); if(color == NULL) { pe_err("NULL color detected"); continue; } else if(color->details->pending == FALSE) { continue; } choose_node_from_list(color); if(color->details->chosen_node == NULL) { crm_debug("No node available for color %d", color->id); } else { crm_debug_3("assigned %s to color %d", color->details->chosen_node->details->uname, color->id); } slist_iter( rsc, resource_t, color->details->allocated_resources, lpc2, slist_iter( constraint, rsc_colocation_t, rsc->rsc_cons, lpc, rsc->fns->rsc_colocation_lh(constraint); ); ); ); crm_debug_2("done"); return TRUE; } /* * Attach nodes to the actions that need to be taken * * Mark actions XML_LRM_ATTR_OPTIONAL if possible (Ie. if the start and stop are * for the same node) * * Mark unrunnable actions */ gboolean stage5(GListPtr resources, GListPtr *ordering_constraints) { crm_debug_2("Creating actions and internal ording constraints"); slist_iter( rsc, resource_t, resources, lpc, rsc->fns->create_actions(rsc, ordering_constraints); rsc->fns->internal_constraints(rsc, ordering_constraints); ); return TRUE; } /* * Create dependacies for stonith and shutdown operations */ gboolean stage6(GListPtr *actions, GListPtr *ordering_constraints, GListPtr nodes, GListPtr resources) { action_t *down_op = NULL; action_t *stonith_op = NULL; crm_debug_2("Processing fencing and shutdown cases"); slist_iter( node, node_t, nodes, lpc, if(node->details->online && node->details->shutdown) { crm_info("Scheduling Node %s for shutdown", node->details->uname); down_op = custom_action( NULL, crm_strdup(CRM_OP_SHUTDOWN), CRM_OP_SHUTDOWN, node); down_op->runnable = TRUE; *actions = g_list_append(*actions, down_op); shutdown_constraints( node, down_op, ordering_constraints); } if(node->details->unclean && stonith_enabled == FALSE) { pe_err("Node %s is unclean!", node->details->uname); pe_warn("YOUR RESOURCES ARE NOW LIKELY COMPROMISED"); pe_warn("ENABLE STONITH TO KEEP YOUR RESOURCES SAFE"); } else if(node->details->unclean && stonith_enabled && (have_quorum || no_quorum_policy == no_quorum_ignore)) { pe_warn("Scheduling Node %s for STONITH", node->details->uname); stonith_op = custom_action( NULL, crm_strdup(CRM_OP_FENCE), CRM_OP_FENCE, node); stonith_op->runnable = TRUE; add_hash_param( stonith_op->extra, XML_LRM_ATTR_TARGET, node->details->uname); add_hash_param( stonith_op->extra, XML_LRM_ATTR_TARGET_UUID, node->details->id); if(down_op != NULL) { down_op->failure_is_fatal = FALSE; } *actions = g_list_append(*actions, stonith_op); } if(node->details->unclean) { stonith_constraints( node, stonith_op, down_op, ordering_constraints); } ); return TRUE; } /* * Determin the sets of independant actions and the correct order for the * actions in each set. * * Mark dependancies of un-runnable actions un-runnable * */ gboolean stage7(GListPtr resources, GListPtr actions, GListPtr ordering_constraints) { crm_debug_2("Applying ordering constraints"); slist_iter( order, order_constraint_t, ordering_constraints, lpc, /* try rsc_action-to-rsc_action */ resource_t *rsc = order->lh_rsc; if(rsc == NULL && order->lh_action) { rsc = order->lh_action->rsc; } if(rsc != NULL) { rsc->fns->rsc_order_lh(rsc, order); continue; } /* try action-to-rsc_action */ /* que off the rh resource */ rsc = order->rh_rsc; if(rsc == NULL && order->rh_action) { rsc = order->rh_action->rsc; } if(rsc != NULL) { rsc->fns->rsc_order_rh(order->lh_action, rsc, order); } else { /* fall back to action-to-action */ order_actions( order->lh_action, order->rh_action, order); } ); update_action_states(global_action_list); return TRUE; } static int transition_id = 0; /* * Create a dependancy graph to send to the transitioner (via the CRMd) */ gboolean stage8(GListPtr resources, GListPtr actions, crm_data_t * *graph) { char *transition_id_s = NULL; - crm_info("Creating transition graph %d.", transition_id); - transition_id_s = crm_itoa(transition_id++); + transition_id++; + transition_id_s = crm_itoa(transition_id); + crm_info("Creating transition graph %d.", transition_id); + *graph = create_xml_node(NULL, XML_TAG_GRAPH); set_xml_property_copy(*graph, "global_timeout", transition_timeout); set_xml_property_copy(*graph, "transition_id", transition_id_s); crm_free(transition_id_s); /* errors... slist_iter(action, action_t, action_list, lpc, if(action->optional == FALSE && action->runnable == FALSE) { print_action("Ignoring", action, TRUE); } ); */ crm_debug_2("========= Complete Action List ========="); crm_debug("%d actions created", g_list_length(global_action_list)); slist_iter(action, action_t, global_action_list, lpc, print_action(NULL, action, FALSE)); slist_iter( rsc, resource_t, resources, lpc, crm_debug_3("processing actions for rsc=%s", rsc->id); rsc->fns->expand(rsc, graph); ); crm_log_xml_debug_3(*graph, "created resource-driven action list"); /* catch any non-resource specific actions */ crm_debug_3("processing non-resource actions"); slist_iter( action, action_t, global_action_list, lpc, graph_element_from_action(action, graph); ); crm_log_xml_debug_3(*graph, "created generic action list"); return TRUE; } gboolean choose_node_from_list(color_t *color) { /* 1. Sort by weight 2. color.chosen_node = the node (of those with the highest wieght) with the fewest resources 3. remove color.chosen_node from all other colors */ GListPtr nodes = color->details->candidate_nodes; node_t *chosen = NULL; crm_debug_3("Choosing node for color %d", color->id); nodes = g_list_sort(nodes, sort_node_weight); chosen = g_list_nth_data(nodes, 0); color->details->chosen_node = NULL; color->details->pending = FALSE; if(chosen == NULL) { crm_debug("Could not allocate a node for color %d", color->id); return FALSE; } else if(chosen->details->unclean || chosen->details->shutdown) { crm_debug("Even highest ranked node for color %d" " is unclean or shutting down", color->id); return FALSE; } else if(chosen->weight < 0) { crm_debug("Even highest ranked node for color %d, had weight %f", color->id, chosen->weight); return FALSE; } /* todo: update the old node for each resource to reflect its * new resource count */ chosen->details->num_resources += color->details->num_resources; color->details->chosen_node = node_copy(chosen); return TRUE; } diff --git a/crm/pengine/unpack.c b/crm/pengine/unpack.c index 18e24d410c..123523b25a 100644 --- a/crm/pengine/unpack.c +++ b/crm/pengine/unpack.c @@ -1,1279 +1,1239 @@ -/* $Id: unpack.c,v 1.90 2005/05/18 20:15:58 andrew Exp $ */ +/* $Id: unpack.c,v 1.91 2005/05/20 09:48:15 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * 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 #include #include #include #include #include #include #include #include /* for ONLINESTATUS */ #include #include #include gint sort_op_by_callid(gconstpointer a, gconstpointer b); gboolean unpack_rsc_to_attr(crm_data_t * xml_obj, GListPtr rsc_list, GListPtr node_list, GListPtr *placement_constraints); gboolean unpack_rsc_to_node(crm_data_t * xml_obj, GListPtr rsc_list, GListPtr node_list, GListPtr *placement_constraints); gboolean unpack_rsc_order( crm_data_t * xml_obj, GListPtr rsc_list, GListPtr *ordering_constraints); gboolean unpack_rsc_colocation( crm_data_t * xml_obj, GListPtr rsc_list, GListPtr *ordering_constraints); gboolean unpack_rsc_location( crm_data_t * xml_obj, GListPtr rsc_list, GListPtr node_list, GListPtr *ordering_constraints); gboolean unpack_lrm_rsc_state( node_t *node, crm_data_t * lrm_state, GListPtr rsc_list, GListPtr nodes, GListPtr *actions, GListPtr *placement_constraints); gboolean add_node_attrs(crm_data_t * attrs, node_t *node); gboolean unpack_rsc_op(resource_t *rsc, node_t *node, crm_data_t *xml_op, gboolean *running, gboolean *failed, int *max_call_id, GListPtr *placement_constraints); gboolean determine_online_status(crm_data_t * node_state, node_t *this_node); gboolean unpack_lrm_agents(node_t *node, crm_data_t * agent_list); gboolean rsc_colocation_new( const char *id, enum con_strength strength, resource_t *rsc_lh, resource_t *rsc_rh); gboolean create_ordering( const char *id, enum con_strength strength, resource_t *rsc_lh, resource_t *rsc_rh, GListPtr *ordering_constraints); rsc_to_node_t *rsc2node_new( const char *id, resource_t *rsc, double weight, gboolean can_run, node_t *node, GListPtr *placement_constraints); const char *param_value(crm_data_t * parent, const char *name); gboolean unpack_config(crm_data_t * config) { const char *value = NULL; value = param_value(config, "transition_timeout"); if(value != NULL) { long tmp = crm_get_msec(value); if(tmp > 0) { transition_timeout = value; } else { crm_err("Invalid value for %s: %s", "transition_timeout", value); } } crm_debug_3("%s set to: %s", "transition_timeout", transition_timeout); value = param_value(config, "stonith_enabled"); if(value != NULL) { crm_str_to_boolean(value, &stonith_enabled); } crm_info("STONITH of failed nodes is %s", stonith_enabled?"enabled":"disabled"); value = param_value(config, "symmetric_cluster"); if(value != NULL) { crm_str_to_boolean(value, &symmetric_cluster); } if(symmetric_cluster) { crm_info("Cluster is symmetric" " - resources can run anywhere by default"); } value = param_value(config, "no_quorum_policy"); if(safe_str_eq(value, "ignore")) { no_quorum_policy = no_quorum_ignore; } else if(safe_str_eq(value, "freeze")) { no_quorum_policy = no_quorum_freeze; } else { no_quorum_policy = no_quorum_stop; } switch (no_quorum_policy) { case no_quorum_freeze: crm_info("On loss of CCM Quorum: Freeze resources"); break; case no_quorum_stop: crm_info("On loss of CCM Quorum: Stop ALL resources"); break; case no_quorum_ignore: crm_warn("On loss of CCM Quorum: Ignore"); break; } return TRUE; } const char * param_value(crm_data_t * parent, const char *name) { crm_data_t * a_default = NULL; if(parent != NULL) { a_default = find_entity( parent, XML_CIB_TAG_NVPAIR, name, FALSE); } if(a_default == NULL) { crm_warn("Option %s not set", name); return NULL; } return crm_element_value(a_default, XML_NVPAIR_ATTR_VALUE); } gboolean unpack_nodes(crm_data_t * xml_nodes, GListPtr *nodes) { node_t *new_node = NULL; crm_data_t * attrs = NULL; const char *id = NULL; const char *uname = NULL; const char *type = NULL; crm_debug_2("Begining unpack..."); xml_child_iter( xml_nodes, xml_obj, XML_CIB_TAG_NODE, new_node = NULL; id = crm_element_value(xml_obj, XML_ATTR_ID); uname = crm_element_value(xml_obj, XML_ATTR_UNAME); type = crm_element_value(xml_obj, XML_ATTR_TYPE); crm_debug_2("Processing node %s/%s", uname, id); attrs = find_xml_node(xml_obj, "attributes", FALSE); if(id == NULL) { pe_err("Must specify id tag in "); continue; } if(type == NULL) { pe_err("Must specify type tag in "); continue; } crm_malloc0(new_node, sizeof(node_t)); if(new_node == NULL) { return FALSE; } new_node->weight = 0; new_node->fixed = FALSE; crm_malloc0(new_node->details, sizeof(struct node_shared_s)); if(new_node->details == NULL) { crm_free(new_node); return FALSE; } crm_debug_2("Creaing node for entry %s/%s", uname, id); new_node->details->id = id; new_node->details->uname = uname; new_node->details->type = node_ping; new_node->details->online = FALSE; new_node->details->shutdown = FALSE; new_node->details->running_rsc = NULL; - new_node->details->agents = NULL; - new_node->details->attrs = g_hash_table_new( - g_str_hash, g_str_equal); + new_node->details->attrs = g_hash_table_new_full( + g_str_hash, g_str_equal, + g_hash_destroy_str, g_hash_destroy_str); if(have_quorum == FALSE && no_quorum_policy == no_quorum_stop) { /* start shutting resources down */ new_node->weight = -INFINITY; } if(stonith_enabled) { /* all nodes are unclean until we've seen their * status entry */ new_node->details->unclean = TRUE; } else { /* blind faith... */ new_node->details->unclean = FALSE; } if(safe_str_eq(type, "member")) { new_node->details->type = node_member; } add_node_attrs(xml_obj, new_node); if(crm_is_true(g_hash_table_lookup( new_node->details->attrs, "standby"))) { crm_info("Node %s is in standby-mode", new_node->details->uname); new_node->weight = -INFINITY; } *nodes = g_list_append(*nodes, new_node); crm_debug_2("Done with node %s", crm_element_value(xml_obj, XML_ATTR_UNAME)); crm_action_debug_3(print_node("Added", new_node, FALSE)); ); *nodes = g_list_sort(*nodes, sort_node_weight); return TRUE; } gboolean unpack_resources(crm_data_t * xml_resources, GListPtr *resources, GListPtr *actions, GListPtr *ordering_constraints, GListPtr *placement_constraints, GListPtr all_nodes) { crm_debug_2("Begining unpack..."); xml_child_iter( xml_resources, xml_obj, NULL, resource_t *new_rsc = NULL; if(common_unpack(xml_obj, &new_rsc)) { *resources = g_list_append(*resources, new_rsc); crm_action_debug_3( print_resource("Added", new_rsc, FALSE)); if(symmetric_cluster) { rsc_to_node_t *new_con = rsc2node_new( "symmetric_default", new_rsc, 0, TRUE, NULL, placement_constraints); new_con->node_list_rh = node_list_dup( all_nodes, FALSE); } } else { pe_err("Failed unpacking resource %s", crm_element_value(xml_obj, XML_ATTR_ID)); } ); *resources = g_list_sort(*resources, sort_rsc_priority); return TRUE; } gboolean unpack_constraints(crm_data_t * xml_constraints, GListPtr nodes, GListPtr resources, GListPtr *placement_constraints, GListPtr *ordering_constraints) { crm_debug_2("Begining unpack..."); xml_child_iter( xml_constraints, xml_obj, NULL, const char *id = crm_element_value(xml_obj, XML_ATTR_ID); if(id == NULL) { pe_err("Constraint <%s...> must have an id", crm_element_name(xml_obj)); continue; } crm_debug_2("Processing constraint %s %s", crm_element_name(xml_obj),id); if(safe_str_eq(XML_CONS_TAG_RSC_ORDER, crm_element_name(xml_obj))) { unpack_rsc_order( xml_obj, resources, ordering_constraints); } else if(safe_str_eq(XML_CONS_TAG_RSC_DEPEND, crm_element_name(xml_obj))) { unpack_rsc_colocation( xml_obj, resources, ordering_constraints); } else if(safe_str_eq(XML_CONS_TAG_RSC_LOCATION, crm_element_name(xml_obj))) { unpack_rsc_location( xml_obj, resources,nodes,placement_constraints); } else { pe_err("Unsupported constraint type: %s", crm_element_name(xml_obj)); } ); return TRUE; } rsc_to_node_t * rsc2node_new(const char *id, resource_t *rsc, double weight, gboolean can, node_t *node, GListPtr *placement_constraints) { rsc_to_node_t *new_con = NULL; if(rsc == NULL || id == NULL) { pe_err("Invalid constraint %s for rsc=%p", crm_str(id), rsc); return NULL; } crm_malloc0(new_con, sizeof(rsc_to_node_t)); if(new_con != NULL) { new_con->id = id; new_con->rsc_lh = rsc; new_con->node_list_rh = NULL; new_con->weight = weight; if(node != NULL) { new_con->node_list_rh = g_list_append(NULL, node); } *placement_constraints = g_list_append( *placement_constraints, new_con); } return new_con; } /* remove nodes that are down, stopping */ /* create +ve rsc_to_node constraints between resources and the nodes they are running on */ /* anything else? */ gboolean unpack_status(crm_data_t * status, GListPtr nodes, GListPtr rsc_list, GListPtr *actions, GListPtr *placement_constraints) { const char *uname = NULL; crm_data_t * lrm_rsc = NULL; crm_data_t * lrm_agents = NULL; crm_data_t * attrs = NULL; node_t *this_node = NULL; crm_debug_2("Begining unpack"); xml_child_iter( status, node_state, XML_CIB_TAG_STATE, /* id = crm_element_value(node_state, XML_ATTR_ID); */ uname = crm_element_value(node_state, XML_ATTR_UNAME); attrs = find_xml_node(node_state, XML_LRM_TAG_ATTRIBUTES,FALSE); lrm_rsc = find_xml_node(node_state, XML_CIB_TAG_LRM, FALSE); lrm_agents = find_xml_node(lrm_rsc, XML_LRM_TAG_AGENTS, FALSE); lrm_rsc = find_xml_node(lrm_rsc, XML_LRM_TAG_RESOURCES, FALSE); crm_debug_2("Processing node %s", uname); this_node = pe_find_node(nodes, uname); if(uname == NULL) { /* error */ continue; } else if(this_node == NULL) { pe_warn("Node %s in status section no longer exists", uname); continue; } /* Mark the node as provisionally clean * - at least we have seen it in the current cluster's lifetime */ this_node->details->unclean = FALSE; crm_debug_2("Adding runtime node attrs"); add_node_attrs(node_state, this_node); crm_debug_2("determining node state"); determine_online_status(node_state, this_node); if(this_node->details->online || stonith_enabled) { /* offline nodes run no resources... * unless stonith is enabled in which case we need to * make sure rsc start events happen after the stonith */ crm_debug_2("Processing lrm resource entries"); unpack_lrm_rsc_state( this_node, lrm_rsc, rsc_list, nodes, actions, placement_constraints); } ); return TRUE; } gboolean determine_online_status(crm_data_t * node_state, node_t *this_node) { gboolean online = FALSE; const char *uname = crm_element_value(node_state,XML_ATTR_UNAME); const char *exp_state = crm_element_value(node_state, XML_CIB_ATTR_EXPSTATE); const char *join_state = crm_element_value(node_state, XML_CIB_ATTR_JOINSTATE); const char *crm_state = crm_element_value(node_state, XML_CIB_ATTR_CRMDSTATE); const char *ccm_state = crm_element_value(node_state, XML_CIB_ATTR_INCCM); const char *ha_state = crm_element_value(node_state, XML_CIB_ATTR_HASTATE); const char *shutdown = crm_element_value(node_state, XML_CIB_ATTR_SHUTDOWN); if(this_node == NULL) { return online; } if(shutdown != NULL) { this_node->details->shutdown = TRUE; } if(safe_str_eq(join_state, CRMD_JOINSTATE_MEMBER)) { this_node->details->expected_up = TRUE; } if(stonith_enabled == FALSE) { if(!crm_is_true(ccm_state) || safe_str_eq(ha_state,DEADSTATUS)){ crm_debug("Node is down: ha_state=%s, ccm_state=%s", crm_str(ha_state), crm_str(ccm_state)); } else if(!crm_is_true(ccm_state) || safe_str_eq(ha_state, DEADSTATUS)) { } else if(safe_str_neq(join_state, CRMD_JOINSTATE_DOWN) && safe_str_eq(crm_state, ONLINESTATUS)) { online = TRUE; } else if(this_node->details->expected_up == FALSE) { crm_debug("CRMd is down: ha_state=%s, ccm_state=%s", crm_str(ha_state), crm_str(ccm_state)); crm_debug("\tcrm_state=%s, join_state=%s, expected=%s", crm_str(crm_state), crm_str(join_state), crm_str(exp_state)); } else { /* mark it unclean */ this_node->details->unclean = TRUE; pe_err("Node %s is partially & un-expectedly down", uname); crm_debug("\tcrm_state=%s, join_state=%s, expected=%s", crm_str(crm_state), crm_str(join_state), crm_str(exp_state)); } } else { if(crm_is_true(ccm_state) && (ha_state == NULL || safe_str_eq(ha_state, ACTIVESTATUS)) && safe_str_eq(crm_state, ONLINESTATUS) && safe_str_neq(join_state, CRMD_JOINSTATE_DOWN)) { online = TRUE; } else if(this_node->details->expected_up == FALSE) { crm_debug("CRMd on %s is down: ha_state=%s, ccm_state=%s", uname, crm_str(ha_state), crm_str(ccm_state)); crm_debug("\tcrm_state=%s, join_state=%s, expected=%s", crm_str(crm_state), crm_str(join_state), crm_str(exp_state)); } else { /* mark it unclean */ this_node->details->unclean = TRUE; pe_err("Node %s is un-expectedly down", uname); crm_debug("\tha_state=%s, ccm_state=%s", crm_str(ha_state), crm_str(ccm_state)); crm_debug("\tcrm_state=%s, join_state=%s, expected=%s", crm_str(crm_state), crm_str(join_state), crm_str(exp_state)); } } if(online) { crm_debug("Node %s is online", uname); this_node->details->online = TRUE; } else { /* remove node from contention */ crm_debug("Node %s is down", uname); this_node->weight = -INFINITY; this_node->fixed = TRUE; } if(this_node->details->unclean) { pe_warn("Node %s is unclean", uname); } if(this_node->details->shutdown) { /* dont run resources here */ this_node->weight = -INFINITY; this_node->fixed = TRUE; crm_debug("Node %s is due for shutdown", uname); } return online; } -gboolean -unpack_lrm_agents(node_t *node, crm_data_t * agent_list) -{ - /* if the agent is not listed, remove the node from - * the resource's list of allowed_nodes - */ - lrm_agent_t *agent = NULL; - const char *version = NULL; - - if(agent_list == NULL) { - return FALSE; - } - - xml_child_iter( - agent_list, xml_agent, XML_LRM_TAG_AGENT, - - crm_malloc0(agent, sizeof(lrm_agent_t)); - if(agent == NULL) { - continue; - } - - agent->class = crm_element_value(xml_agent, XML_AGENT_ATTR_CLASS); - agent->type = crm_element_value(xml_agent, XML_ATTR_TYPE); - version = crm_element_value(xml_agent, XML_ATTR_VERSION); - agent->version = version?version:"0.0"; - - crm_debug_4("Adding agent %s/%s %s to node %s", - agent->class, - agent->type, - agent->version, - node->details->uname); - - node->details->agents = g_list_append( - node->details->agents, agent); - ); - - return TRUE; -} - - gboolean unpack_lrm_rsc_state(node_t *node, crm_data_t * lrm_rsc_list, GListPtr rsc_list, GListPtr nodes, GListPtr *actions, GListPtr *placement_constraints) { const char *rsc_id = NULL; const char *node_id = node->details->uname; const char *rsc_state = NULL; int max_call_id = -1; gboolean failed = FALSE; gboolean running = FALSE; resource_t *rsc = NULL; GListPtr op_list = NULL; GListPtr sorted_op_list = NULL; CRM_DEV_ASSERT(node != NULL); if(crm_assert_failed) { return FALSE; } xml_child_iter( lrm_rsc_list, rsc_entry, XML_LRM_TAG_RESOURCE, rsc_id = crm_element_value(rsc_entry, XML_ATTR_ID); rsc_state = crm_element_value(rsc_entry, XML_LRM_ATTR_RSCSTATE); rsc = pe_find_resource(rsc_list, rsc_id); crm_debug_2("[%s] Processing %s on %s (%s)", crm_element_name(rsc_entry), rsc_id, node_id, rsc_state); if(rsc == NULL) { pe_err("Could not find a match for resource" " %s in %s's status section", rsc_id, node_id); crm_log_xml_debug(rsc_entry, "Invalid status entry"); continue; } failed = FALSE; running = FALSE; max_call_id = -1; op_list = NULL; sorted_op_list = NULL; xml_child_iter( rsc_entry, rsc_op, XML_LRM_TAG_RSC_OP, op_list = g_list_append(op_list, rsc_op); ); if(op_list == NULL) { continue; } sorted_op_list = g_list_sort(op_list, sort_op_by_callid); slist_iter( rsc_op, crm_data_t, sorted_op_list, lpc, unpack_rsc_op(rsc, node, rsc_op, &running, &failed, &max_call_id, placement_constraints); ); /* no need to free the contents */ g_list_free(sorted_op_list); if(running) { native_add_running(rsc, node); if(failed) { action_t *stop = stop_action(rsc, node); stop->optional = FALSE; rsc->recover = TRUE; } } ); return TRUE; } gint sort_op_by_callid(gconstpointer a, gconstpointer b) { const char *a_task_id = cl_get_string(a, XML_LRM_ATTR_CALLID); const char *b_task_id = cl_get_string(b, XML_LRM_ATTR_CALLID); /* if task id is NULL, then its a pending op * put pending ops last */ int a_id = -1; int b_id = -1; if(a_task_id == NULL && b_task_id == NULL) { return 0; } /* the reverse from normal so that NULLs appear last */ if(a_task_id == NULL) { return -1; } if(b_task_id == NULL) { return 1; } a_id = atoi(a_task_id); b_id = atoi(b_task_id); if(a_id < b_id) { return -1; } else if(a_id > b_id) { return 1; } return 0; } gboolean unpack_rsc_op(resource_t *rsc, node_t *node, crm_data_t *xml_op, gboolean *running, gboolean *failed, int *max_call_id, GListPtr *placement_constraints) { const char *task = NULL; const char *task_id = NULL; const char *task_status = NULL; int task_status_i = -2; int task_id_i = -1; CRM_DEV_ASSERT(rsc != NULL); if(crm_assert_failed) { return FALSE; } CRM_DEV_ASSERT(node != NULL); if(crm_assert_failed) { return FALSE; } CRM_DEV_ASSERT(xml_op != NULL); if(crm_assert_failed) { return FALSE; } task = crm_element_value(xml_op, XML_LRM_ATTR_TASK); task_id = crm_element_value(xml_op, XML_LRM_ATTR_CALLID); task_status = crm_element_value(xml_op, XML_LRM_ATTR_OPSTATUS); CRM_DEV_ASSERT(task != NULL); if(crm_assert_failed) { return FALSE; } CRM_DEV_ASSERT(task_status != NULL); if(crm_assert_failed) { return FALSE; } task_status_i = atoi(task_status); CRM_DEV_ASSERT(task_status_i <= LRM_OP_ERROR); if(crm_assert_failed) {return FALSE;} CRM_DEV_ASSERT(task_status_i >= LRM_OP_PENDING); if(crm_assert_failed) {return FALSE;} if(task_status_i != LRM_OP_PENDING) { task_id_i = crm_atoi(task_id, "-1"); CRM_DEV_ASSERT(task_id != NULL); if(crm_assert_failed) { return FALSE; } CRM_DEV_ASSERT(task_id_i >= 0); if(crm_assert_failed) { return FALSE; } if(task_id_i == *max_call_id) { crm_debug("Already processed this call"); return TRUE; } CRM_DEV_ASSERT(task_id_i > *max_call_id); if(crm_assert_failed) { return FALSE; } } if(*max_call_id < task_id_i) { *max_call_id = task_id_i; } if(node->details->unclean) { crm_debug("Node %s (where %s is running) is unclean." " Further action depends on the value of %s", node->details->uname, rsc->id, XML_RSC_ATTR_STOPFAIL); } switch(task_status_i) { case LRM_OP_PENDING: /* * TODO: this may need some more thought * Some cases: * - PE reinvoked with pending action that will succeed * - PE reinvoked with pending action that will fail * - After DC election * - After startup * * pending start - required start * pending stop - required stop * pending on unavailable node - stonith * * For now this should do */ if(safe_str_eq(task, CRMD_ACTION_STOP)) { /* re-issue the stop and return */ stop_action(rsc, node); *running = TRUE; rsc->recover = TRUE; } else if(safe_str_eq(task, CRMD_ACTION_START)) { rsc->start_pending = TRUE; rsc->schedule_recurring = TRUE; *running = TRUE; /* make sure it is re-issued but, * only if we have quorum */ if(have_quorum == TRUE || no_quorum_policy == no_quorum_ignore){ /* do not specify the node, we may want * to start it elsewhere */ start_action(rsc, NULL); } } else if(*running == TRUE) { crm_debug_3("Re-issuing pending recurring task:" " %s for %s on %s", task, rsc->id, node->details->id); rsc->schedule_recurring = TRUE; } break; case LRM_OP_DONE: crm_debug_2("%s/%s completed on %s", rsc->id, task, node->details->uname); if(safe_str_eq(task, CRMD_ACTION_STOP)) { *failed = FALSE; *running = FALSE; rsc->schedule_recurring = FALSE; } else if(safe_str_eq(task, CRMD_ACTION_START)) { crm_debug_2("%s active on %s", rsc->id, node->details->uname); *running = TRUE; rsc->schedule_recurring = FALSE; } else if(*running) { /* assume its a recurring action */ action_t *mon = NULL; const char *id = crm_element_value( xml_op, XML_ATTR_ID); CRM_DEV_ASSERT(id != NULL); if(crm_assert_failed) { break; } mon = custom_action( rsc, crm_strdup(id), task, node); if(mon != NULL) { mon->optional = TRUE; } } break; case LRM_OP_ERROR: case LRM_OP_TIMEOUT: case LRM_OP_NOTSUPPORTED: if(task_status_i == LRM_OP_NOTSUPPORTED || safe_str_eq(task, CRMD_ACTION_STOP) || safe_str_eq(task, CRMD_ACTION_START) ) { pe_warn("Handling failed %s for %s on %s", task, rsc->id, node->details->uname); rsc2node_new("dont_run__failed_stopstart", rsc, -INFINITY, FALSE, node, placement_constraints); } crm_debug("Processing last op (%s) for %s on %s", task, rsc->id, node->details->uname); if(safe_str_neq(task, CRMD_ACTION_STOP)) { *failed = TRUE; *running = TRUE; } else if(rsc->stopfail_type == pesf_stonith) { /* treat it as if it is still running * but also mark the node as unclean */ rsc->unclean = TRUE; node->details->unclean = TRUE; *running = TRUE; } else if(rsc->stopfail_type == pesf_block) { /* let this depend on the stop action * which will fail but make sure the * transition continues... */ *running = TRUE; rsc->unclean = TRUE; } else { /* pretend the stop completed */ *running = FALSE; rsc->schedule_recurring = FALSE; } break; case LRM_OP_CANCELLED: /* do nothing?? */ pe_err("Dont know what to do for cancelled ops yet"); break; } return TRUE; } gboolean rsc_colocation_new(const char *id, enum con_strength strength, resource_t *rsc_lh, resource_t *rsc_rh) { rsc_colocation_t *new_con = NULL; rsc_colocation_t *inverted_con = NULL; if(rsc_lh == NULL || rsc_rh == NULL){ /* error */ return FALSE; } crm_malloc0(new_con, sizeof(rsc_colocation_t)); if(new_con == NULL) { return FALSE; } new_con->id = id; new_con->rsc_lh = rsc_lh; new_con->rsc_rh = rsc_rh; new_con->strength = strength; inverted_con = invert_constraint(new_con); crm_debug_3("Adding constraint %s (%p) to %s", new_con->id, new_con, rsc_lh->id); rsc_lh->rsc_cons = g_list_insert_sorted( rsc_lh->rsc_cons, new_con, sort_cons_strength); crm_debug_3("Adding constraint %s (%p) to %s", inverted_con->id, inverted_con, rsc_rh->id); rsc_rh->rsc_cons = g_list_insert_sorted( rsc_rh->rsc_cons, inverted_con, sort_cons_strength); return TRUE; } gboolean custom_action_order( resource_t *lh_rsc, char *lh_action_task, action_t *lh_action, resource_t *rh_rsc, char *rh_action_task, action_t *rh_action, enum con_strength strength, GListPtr *ordering_constraints) { order_constraint_t *order = NULL; if((lh_action == NULL && lh_rsc == NULL) || (rh_action == NULL && rh_rsc == NULL) || ordering_constraints == NULL){ pe_err("Invalid inputs lh_rsc=%p, lh_a=%p," " rh_rsc=%p, rh_a=%p, l=%p", lh_rsc, lh_action, rh_rsc, rh_action, ordering_constraints); return FALSE; } crm_malloc0(order, sizeof(order_constraint_t)); if(order == NULL) { return FALSE; } order->id = order_id++; order->strength = strength; order->lh_rsc = lh_rsc; order->rh_rsc = rh_rsc; order->lh_action = lh_action; order->rh_action = rh_action; order->lh_action_task = lh_action_task; order->rh_action_task = rh_action_task; *ordering_constraints = g_list_append( *ordering_constraints, order); if(lh_rsc != NULL && rh_rsc != NULL) { crm_debug_3("Created ordering constraint %d (%s):" " %s/%s before %s/%s", order->id, strength2text(order->strength), lh_rsc->id, lh_action_task, rh_rsc->id, rh_action_task); } else if(lh_rsc != NULL) { crm_debug_3("Created ordering constraint %d (%s):" " %s/%s before action %d (%s)", order->id, strength2text(order->strength), lh_rsc->id, lh_action_task, rh_action->id, rh_action_task); } else if(rh_rsc != NULL) { crm_debug_3("Created ordering constraint %d (%s):" " action %d (%s) before %s/%s", order->id, strength2text(order->strength), lh_action->id, lh_action_task, rh_rsc->id, rh_action_task); } else { crm_debug_3("Created ordering constraint %d (%s):" " action %d (%s) before action %d (%s)", order->id, strength2text(order->strength), lh_action->id, lh_action_task, rh_action->id, rh_action_task); } return TRUE; } gboolean unpack_rsc_colocation(crm_data_t * xml_obj, GListPtr rsc_list, GListPtr *ordering_constraints) { enum con_strength strength_e = pecs_ignore; const char *id = crm_element_value(xml_obj, XML_ATTR_ID); const char *id_rh = crm_element_value(xml_obj, XML_CONS_ATTR_TO); const char *id_lh = crm_element_value(xml_obj, XML_CONS_ATTR_FROM); const char *score = crm_element_value(xml_obj, XML_RULE_ATTR_SCORE); resource_t *rsc_lh = pe_find_resource(rsc_list, id_lh); resource_t *rsc_rh = pe_find_resource(rsc_list, id_rh); if(rsc_lh == NULL) { pe_err("No resource (con=%s, rsc=%s)", id, id_lh); return FALSE; } else if(rsc_rh == NULL) { pe_err("No resource (con=%s, rsc=%s)", id, id_rh); return FALSE; } /* the docs indicate that only +/- INFINITY are allowed, * but no-one ever reads the docs so all positive values will * count as "must" and negative values as "must not" */ if(score == NULL || score[0] != '-') { strength_e = pecs_must; } else { strength_e = pecs_must_not; } return rsc_colocation_new(id, strength_e, rsc_lh, rsc_rh); } gboolean unpack_rsc_order( crm_data_t * xml_obj, GListPtr rsc_list, GListPtr *ordering_constraints) { gboolean type_is_after = TRUE; gboolean action_is_start = TRUE; gboolean symmetrical_bool = TRUE; const char *id = crm_element_value(xml_obj, XML_ATTR_ID); const char *type = crm_element_value(xml_obj, XML_ATTR_TYPE); const char *id_rh = crm_element_value(xml_obj, XML_CONS_ATTR_TO); const char *id_lh = crm_element_value(xml_obj, XML_CONS_ATTR_FROM); const char *action = crm_element_value(xml_obj, XML_CONS_ATTR_ACTION); const char *symmetrical = crm_element_value( xml_obj, XML_CONS_ATTR_SYMMETRICAL); resource_t *rsc_lh = pe_find_resource(rsc_list, id_lh); resource_t *rsc_rh = pe_find_resource(rsc_list, id_rh); if(xml_obj == NULL) { pe_err("No constraint object to process."); return FALSE; } else if(id == NULL) { pe_err("%s constraint must have an id", crm_element_name(xml_obj)); return FALSE; } else if(rsc_lh == NULL || rsc_rh == NULL) { pe_err("Constraint %s needs two sides lh: %p rh: %p" " (NULL indicates missing side)", id, rsc_lh, rsc_rh); return FALSE; } crm_str_to_boolean(symmetrical, &symmetrical_bool); if(safe_str_eq(type, "before")) { type_is_after = FALSE; } if(safe_str_eq(action, task2text(stop_rsc))) { action_is_start = FALSE; } #if 1 if((type_is_after && action_is_start) || (type_is_after == FALSE && action_is_start == FALSE)){ if(symmetrical_bool || action_is_start == FALSE) { order_stop_stop(rsc_lh, rsc_rh); } if(symmetrical_bool || action_is_start) { order_start_start(rsc_rh, rsc_lh); } } else { if(symmetrical_bool || action_is_start == FALSE) { order_stop_stop(rsc_rh, rsc_lh); } if(symmetrical_bool || action_is_start) { order_start_start(rsc_lh, rsc_rh); } } #else if(type_is_after) { order_stop_stop(rsc_lh, rsc_rh); order_start_start(rsc_rh, rsc_lh); } else { order_stop_stop(rsc_rh, rsc_lh); order_start_start(rsc_lh, rsc_rh); } #endif return TRUE; } gboolean add_node_attrs(crm_data_t *xml_obj, node_t *node) { g_hash_table_insert(node->details->attrs, crm_strdup("#"XML_ATTR_UNAME), crm_strdup(node->details->uname)); g_hash_table_insert(node->details->attrs, crm_strdup("#"XML_ATTR_ID), crm_strdup(node->details->id)); if(safe_str_eq(node->details->id, dc_uuid)) { node->details->is_dc = TRUE; g_hash_table_insert(node->details->attrs, crm_strdup("#"XML_ATTR_DC), crm_strdup(XML_BOOLEAN_TRUE)); } else { g_hash_table_insert(node->details->attrs, crm_strdup("#"XML_ATTR_DC), crm_strdup(XML_BOOLEAN_FALSE)); } unpack_instance_attributes(xml_obj, node->details->attrs); return TRUE; } gboolean unpack_rsc_location( crm_data_t * xml_obj, GListPtr rsc_list, GListPtr node_list, GListPtr *placement_constraints) { gboolean were_rules = FALSE; const char *id_lh = crm_element_value(xml_obj, "rsc"); const char *id = crm_element_value(xml_obj, XML_ATTR_ID); resource_t *rsc_lh = pe_find_resource(rsc_list, id_lh); if(rsc_lh == NULL) { pe_warn("No resource (con=%s, rsc=%s)", id, id_lh); return FALSE; } xml_child_iter( xml_obj, rule, XML_TAG_RULE, gboolean first_expr = TRUE; gboolean can_run = FALSE; gboolean do_and = TRUE; gboolean rule_has_expressions; const char *rule_id = crm_element_value(rule, XML_ATTR_ID); const char *score = crm_element_value(rule, XML_RULE_ATTR_SCORE); const char *boolean = crm_element_value(rule, XML_RULE_ATTR_BOOLEAN_OP); GListPtr match_L = NULL; GListPtr old_list = NULL; float score_f = 0.0; rsc_to_node_t *new_con = NULL; were_rules = TRUE; if(score == NULL) { score_f = 0.0; } else if(safe_str_eq(score, MINUS_INFINITY_S)) { score_f = -INFINITY; } else if(safe_str_eq(score, INFINITY_S)) { score_f = INFINITY; } else { score_f = atof(score); } if(safe_str_eq(boolean, "or")) { do_and = FALSE; } if(score_f >= 0.0) { can_run = TRUE; } new_con = rsc2node_new(rule_id, rsc_lh, score_f, can_run, NULL, placement_constraints); if(new_con == NULL) { continue; } crm_debug_4("processing rule: %s", crm_element_value(rule, XML_ATTR_ID)); rule_has_expressions = FALSE; xml_child_iter( rule, expr, XML_TAG_EXPRESSION, const char *attr = crm_element_value( expr, XML_EXPR_ATTR_ATTRIBUTE); const char *op = crm_element_value( expr, XML_EXPR_ATTR_OPERATION); const char *value = crm_element_value( expr, XML_EXPR_ATTR_VALUE); const char *type = crm_element_value( expr, XML_EXPR_ATTR_TYPE); rule_has_expressions = TRUE; crm_debug_4("processing expression: %s", crm_element_value(expr, XML_ATTR_ID)); match_L = apply_node_expression( attr, op, value, type, node_list); if(first_expr) { new_con->node_list_rh = node_list_dup( match_L, FALSE); first_expr = FALSE; continue; } old_list = new_con->node_list_rh; if(do_and) { crm_debug_4("do_and"); new_con->node_list_rh = node_list_and( old_list, match_L, FALSE); } else { crm_debug_4("do_or"); new_con->node_list_rh = node_list_or( old_list, match_L, FALSE); } pe_free_shallow_adv(match_L, FALSE); pe_free_shallow_adv(old_list, TRUE); ); if(rule_has_expressions == FALSE && symmetric_cluster == FALSE) { /* feels like a hack */ crm_debug_3("Rule %s had no expressions," " adding all nodes", crm_element_value(rule, XML_ATTR_ID)); new_con->node_list_rh = node_list_dup(node_list,FALSE); } if(new_con->node_list_rh == NULL) { crm_debug("No matching nodes for constraint/rule %s/%s", id, crm_element_value(rule, XML_ATTR_ID)); } crm_action_debug_3(print_rsc_to_node("Added", new_con, FALSE)); ); if(were_rules == FALSE) { crm_debug("no rules for constraint %s", id); } return TRUE; } diff --git a/crm/pengine/utils.c b/crm/pengine/utils.c index ac89167cb6..da8fa420ba 100644 --- a/crm/pengine/utils.c +++ b/crm/pengine/utils.c @@ -1,1342 +1,1322 @@ -/* $Id: utils.c,v 1.76 2005/05/19 06:49:52 andrew Exp $ */ +/* $Id: utils.c,v 1.77 2005/05/20 09:48:15 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * 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 #include #include #include #include #include #include #include #include int action_id = 1; int color_id = 0; extern GListPtr global_action_list; void print_str_str(gpointer key, gpointer value, gpointer user_data); gboolean ghash_free_str_str(gpointer key, gpointer value, gpointer user_data); void unpack_operation(crm_data_t *xml_obj, GHashTable *hash); /* only for rsc_colocation constraints */ rsc_colocation_t * invert_constraint(rsc_colocation_t *constraint) { rsc_colocation_t *inverted_con = NULL; crm_debug_2("Inverting constraint"); if(constraint == NULL) { pe_err("Cannot invert NULL constraint"); return NULL; } crm_malloc0(inverted_con, sizeof(rsc_colocation_t)); if(inverted_con == NULL) { return NULL; } inverted_con->id = crm_strdup(constraint->id); inverted_con->strength = constraint->strength; /* swap the direction */ inverted_con->rsc_lh = constraint->rsc_rh; inverted_con->rsc_rh = constraint->rsc_lh; crm_action_debug_3( print_rsc_colocation("Inverted constraint", inverted_con, FALSE)); return inverted_con; } /* are the contents of list1 and list2 equal * nodes with weight < 0 are ignored if filter == TRUE * * slow but linear * */ gboolean node_list_eq(GListPtr list1, GListPtr list2, gboolean filter) { node_t *other_node; GListPtr lhs = list1; GListPtr rhs = list2; slist_iter( node, node_t, lhs, lpc, if(node == NULL || (filter && node->weight < 0)) { continue; } other_node = (node_t*) pe_find_node(rhs, node->details->uname); if(other_node == NULL || other_node->weight < 0) { return FALSE; } ); lhs = list2; rhs = list1; slist_iter( node, node_t, lhs, lpc, if(node == NULL || (filter && node->weight < 0)) { continue; } other_node = (node_t*) pe_find_node(rhs, node->details->uname); if(other_node == NULL || other_node->weight < 0) { return FALSE; } ); return TRUE; } /* the intersection of list1 and list2 */ GListPtr node_list_and(GListPtr list1, GListPtr list2, gboolean filter) { GListPtr result = NULL; unsigned lpc = 0; for(lpc = 0; lpc < g_list_length(list1); lpc++) { node_t *node = (node_t*)g_list_nth_data(list1, lpc); node_t *other_node = pe_find_node(list2, node->details->uname); node_t *new_node = NULL; if(other_node != NULL) { new_node = node_copy(node); } if(new_node != NULL) { new_node->weight = merge_weights( new_node->weight, other_node->weight); if(filter && new_node->weight < 0) { crm_free(new_node); new_node = NULL; } } if(new_node != NULL) { result = g_list_append(result, new_node); } } return result; } /* list1 - list2 */ GListPtr node_list_minus(GListPtr list1, GListPtr list2, gboolean filter) { GListPtr result = NULL; slist_iter( node, node_t, list1, lpc, node_t *other_node = pe_find_node(list2, node->details->uname); node_t *new_node = NULL; if(node == NULL || other_node != NULL || (filter && node->weight < 0)) { continue; } new_node = node_copy(node); result = g_list_append(result, new_node); ); crm_debug_2("Minus result len: %d", g_list_length(result)); return result; } /* list1 + list2 - (intersection of list1 and list2) */ GListPtr node_list_xor(GListPtr list1, GListPtr list2, gboolean filter) { GListPtr result = NULL; slist_iter( node, node_t, list1, lpc, node_t *new_node = NULL; node_t *other_node = (node_t*) pe_find_node(list2, node->details->uname); if(node == NULL || other_node != NULL || (filter && node->weight < 0)) { continue; } new_node = node_copy(node); result = g_list_append(result, new_node); ); slist_iter( node, node_t, list2, lpc, node_t *new_node = NULL; node_t *other_node = (node_t*) pe_find_node(list1, node->details->uname); if(node == NULL || other_node != NULL || (filter && node->weight < 0)) { continue; } new_node = node_copy(node); result = g_list_append(result, new_node); ); crm_debug_2("Xor result len: %d", g_list_length(result)); return result; } GListPtr node_list_or(GListPtr list1, GListPtr list2, gboolean filter) { node_t *other_node = NULL; GListPtr result = NULL; gboolean needs_filter = FALSE; result = node_list_dup(list1, filter); slist_iter( node, node_t, list2, lpc, if(node == NULL) { continue; } other_node = (node_t*)pe_find_node( result, node->details->uname); if(other_node != NULL) { other_node->weight = merge_weights( other_node->weight, node->weight); if(filter && node->weight < 0) { needs_filter = TRUE; } } else { node_t *new_node = node_copy(node); result = g_list_append(result, new_node); } ); /* not the neatest way, but the most expedient for now */ if(filter && needs_filter) { GListPtr old_result = result; result = node_list_dup(old_result, filter); pe_free_shallow_adv(old_result, TRUE); } return result; } GListPtr node_list_dup(GListPtr list1, gboolean filter) { GListPtr result = NULL; slist_iter( this_node, node_t, list1, lpc, node_t *new_node = NULL; if(filter && this_node->weight < 0) { continue; } new_node = node_copy(this_node); if(new_node != NULL) { result = g_list_append(result, new_node); } ); return result; } node_t * node_copy(node_t *this_node) { node_t *new_node = NULL; CRM_DEV_ASSERT(this_node != NULL); if(this_node == NULL) { pe_err("Failed copy of node."); return NULL; } crm_malloc0(new_node, sizeof(node_t)); CRM_DEV_ASSERT(new_node != NULL); if(new_node == NULL) { return NULL; } crm_debug_4("Copying %p (%s) to %p", this_node, this_node->details->uname, new_node); new_node->weight = this_node->weight; new_node->fixed = this_node->fixed; new_node->details = this_node->details; return new_node; } /* * Create a new color with the contents of "nodes" as the list of * possible nodes that resources with this color can be run on. * * Typically, when creating a color you will provide the node list from * the resource you will first assign the color to. * * If "colors" != NULL, it will be added to that list * If "resources" != NULL, it will be added to every provisional resource * in that list */ color_t * create_color(GListPtr *colors, resource_t *resource, GListPtr node_list) { color_t *new_color = NULL; crm_debug_4("Creating color"); crm_malloc0(new_color, sizeof(color_t)); if(new_color == NULL) { return NULL; } new_color->id = color_id++; new_color->local_weight = 1.0; crm_debug_4("Creating color details"); crm_malloc0(new_color->details, sizeof(struct color_shared_s)); if(new_color->details == NULL) { crm_free(new_color); return NULL; } new_color->details->id = new_color->id; new_color->details->highest_priority = -1; new_color->details->chosen_node = NULL; new_color->details->candidate_nodes = NULL; new_color->details->allocated_resources = NULL; new_color->details->pending = TRUE; if(resource != NULL) { crm_debug_4("populating node list"); new_color->details->highest_priority = resource->priority; new_color->details->candidate_nodes = node_list_dup(node_list, TRUE); } crm_action_debug_3(print_color("Created color", new_color, TRUE)); if(colors != NULL) { *colors = g_list_append(*colors, new_color); } return new_color; } color_t * copy_color(color_t *a_color) { color_t *color_copy = NULL; if(a_color == NULL) { pe_err("Cannot copy NULL"); return NULL; } crm_malloc0(color_copy, sizeof(color_t)); if(color_copy != NULL) { color_copy->id = a_color->id; color_copy->details = a_color->details; color_copy->local_weight = 1.0; } return color_copy; } resource_t * pe_find_resource(GListPtr rsc_list, const char *id) { unsigned lpc = 0; resource_t *rsc = NULL; resource_t *child_rsc = NULL; crm_debug_3("Looking for %s in %d objects", id, g_list_length(rsc_list)); for(lpc = 0; lpc < g_list_length(rsc_list); lpc++) { rsc = g_list_nth_data(rsc_list, lpc); if(rsc != NULL && safe_str_eq(rsc->id, id)){ crm_debug_3("Found a match for %s", id); return rsc; } } for(lpc = 0; lpc < g_list_length(rsc_list); lpc++) { rsc = g_list_nth_data(rsc_list, lpc); child_rsc = rsc->fns->find_child(rsc, id); if(child_rsc != NULL) { crm_debug_3("Found a match for %s in %s", id, rsc->id); return child_rsc; } } /* error */ return NULL; } node_t * pe_find_node(GListPtr nodes, const char *uname) { unsigned lpc = 0; node_t *node = NULL; for(lpc = 0; lpc < g_list_length(nodes); lpc++) { node = g_list_nth_data(nodes, lpc); if(node != NULL && safe_str_eq(node->details->uname, uname)) { return node; } } /* error */ return NULL; } node_t * pe_find_node_id(GListPtr nodes, const char *id) { unsigned lpc = 0; node_t *node = NULL; for(lpc = 0; lpc < g_list_length(nodes); lpc++) { node = g_list_nth_data(nodes, lpc); if(safe_str_eq(node->details->id, id)) { return node; } } /* error */ return NULL; } gint gslist_color_compare(gconstpointer a, gconstpointer b); color_t * find_color(GListPtr candidate_colors, color_t *other_color) { GListPtr tmp = g_list_find_custom(candidate_colors, other_color, gslist_color_compare); if(tmp != NULL) { return (color_t *)tmp->data; } return NULL; } gint gslist_color_compare(gconstpointer a, gconstpointer b) { const color_t *color_a = (const color_t*)a; const color_t *color_b = (const color_t*)b; /* crm_debug_4("%d vs. %d", a?color_a->id:-2, b?color_b->id:-2); */ if(a == b) { return 0; } else if(a == NULL || b == NULL) { return 1; } else if(color_a->id == color_b->id) { return 0; } return 1; } gint sort_rsc_priority(gconstpointer a, gconstpointer b) { const resource_t *resource1 = (const resource_t*)a; const resource_t *resource2 = (const resource_t*)b; if(a == NULL && b == NULL) { return 0; } if(a == NULL) { return 1; } if(b == NULL) { return -1; } if(resource1->priority > resource2->priority) { return -1; } if(resource1->priority < resource2->priority) { return 1; } return 0; } gint sort_cons_strength(gconstpointer a, gconstpointer b) { const rsc_colocation_t *rsc_constraint1 = (const rsc_colocation_t*)a; const rsc_colocation_t *rsc_constraint2 = (const rsc_colocation_t*)b; if(a == NULL) { return 1; } if(b == NULL) { return -1; } if(rsc_constraint1->strength > rsc_constraint2->strength) { return 1; } if(rsc_constraint1->strength < rsc_constraint2->strength) { return -1; } return 0; } gint sort_color_weight(gconstpointer a, gconstpointer b) { const color_t *color1 = (const color_t*)a; const color_t *color2 = (const color_t*)b; if(a == NULL) { return 1; } if(b == NULL) { return -1; } if(color1->local_weight > color2->local_weight) { return -1; } if(color1->local_weight < color2->local_weight) { return 1; } return 0; } /* return -1 if 'a' is more preferred * return 1 if 'b' is more preferred */ gint sort_node_weight(gconstpointer a, gconstpointer b) { const node_t *node1 = (const node_t*)a; const node_t *node2 = (const node_t*)b; float node1_weight = 0; float node2_weight = 0; if(a == NULL) { return 1; } if(b == NULL) { return -1; } node1_weight = node1->weight; node2_weight = node2->weight; if(node1->details->unclean || node1->details->shutdown) { node1_weight = -INFINITY; } if(node2->details->unclean || node2->details->shutdown) { node2_weight = -INFINITY; } if(node1_weight > node2_weight) { crm_debug_3("%s (%f) > %s (%f) : weight", node1->details->id, node1_weight, node2->details->id, node2_weight); return -1; } if(node1_weight < node2_weight) { crm_debug_3("%s (%f) < %s (%f) : weight", node1->details->id, node1_weight, node2->details->id, node2_weight); return 1; } /* now try to balance resources across the cluster */ if(node1->details->num_resources < node2->details->num_resources) { crm_debug_3("%s (%d) < %s (%d) : resources", node1->details->id, node1->details->num_resources, node2->details->id, node2->details->num_resources); return -1; } else if(node1->details->num_resources > node2->details->num_resources) { crm_debug_3("%s (%d) > %s (%d) : resources", node1->details->id, node1->details->num_resources, node2->details->id, node2->details->num_resources); return 1; } crm_debug_3("%s = %s", node1->details->id, node2->details->id); return 0; } action_t * custom_action( resource_t *rsc, char *key, const char *task, node_t *on_node) { action_t *action = NULL; GListPtr possible_matches = NULL; CRM_DEV_ASSERT(key != NULL); if(crm_assert_failed) { return NULL; } CRM_DEV_ASSERT(task != NULL); if(crm_assert_failed) { return NULL; } if(rsc != NULL) { possible_matches = find_actions(rsc->actions, key, on_node); } if(possible_matches != NULL) { if(g_list_length(possible_matches) > 1) { pe_warn("Action %s for %s on %s exists %d times", task, rsc?rsc->id:"", on_node?on_node->details->id:"", g_list_length(possible_matches)); } action = g_list_nth_data(possible_matches, 0); crm_debug_3("Found existing action (%d) %s for %s on %s", action->id, task, rsc?rsc->id:"", on_node?on_node->details->id:""); } if(action == NULL) { crm_debug_3("Creating action %s for %s on %s", task, rsc?rsc->id:"", on_node?on_node->details->id:""); crm_malloc0(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->runnable = TRUE; action->processed = FALSE; action->optional = FALSE; action->seen_count = 0; action->extra = g_hash_table_new_full( g_str_hash, g_str_equal, g_hash_destroy_str, g_hash_destroy_str); global_action_list = g_list_append( global_action_list, action); action->uuid = key; if(rsc != NULL) { action->op_entry = find_rsc_op_entry(rsc, key); unpack_operation(action->op_entry,action->extra); rsc->actions = g_list_append( rsc->actions, action); } crm_debug_3("Action %d created", action->id); } } if(rsc != NULL) { if(action->node == NULL) { action->runnable = FALSE; } else if(action->node->details->online == FALSE) { pe_warn("Action %d %s for %s on %s is unrunnable", action->id, task, rsc?rsc->id:"", action->node?action->node->details->id:""); action->runnable = FALSE; } else { action->runnable = TRUE; } switch(text2task(action->task)) { case stop_rsc: rsc->stopping = TRUE; break; case start_rsc: rsc->starting = FALSE; if(action->runnable) { rsc->starting = TRUE; } break; default: break; } } return action; } void unpack_operation(crm_data_t *xml_obj, GHashTable *hash) { int lpc = 0; const char *value = NULL; const char *fields[] = { "interval", "timeout", "start_delay" }; if(xml_obj == NULL) { return; } for(;lpc < DIMOF(fields); lpc++) { value = crm_element_value(xml_obj, fields[lpc]); add_hash_param(hash, fields[lpc], value); } unpack_instance_attributes(xml_obj, hash); } crm_data_t * find_rsc_op_entry(resource_t *rsc, const char *key) { const char *name = NULL; const char *interval = NULL; char *match_key = NULL; xml_child_iter( rsc->ops_xml, operation, "op", name = crm_element_value(operation, "name"); interval = crm_element_value(operation, "interval"); match_key = generate_op_key(rsc->id,name,crm_get_msec(interval)); crm_debug("Matching %s with %s", key, match_key); if(safe_str_eq(key, match_key)) { crm_free(match_key); return operation; } crm_free(match_key); ); crm_debug("No matching for %s", key); return NULL; } const char * strength2text(enum con_strength strength) { const char *result = ""; 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; } enum action_tasks text2task(const char *task) { if(safe_str_eq(task, CRMD_ACTION_STOP)) { return stop_rsc; } else if(safe_str_eq(task, CRMD_ACTION_STOPPED)) { return stopped_rsc; } else if(safe_str_eq(task, CRMD_ACTION_START)) { return start_rsc; } else if(safe_str_eq(task, CRMD_ACTION_STARTED)) { return started_rsc; } else if(safe_str_eq(task, CRM_OP_SHUTDOWN)) { return shutdown_crm; } else if(safe_str_eq(task, CRM_OP_FENCE)) { return stonith_node; } else if(safe_str_eq(task, CRMD_ACTION_MON)) { return monitor_rsc; } pe_err("Unsupported action: %s", task); return no_action; } const char * task2text(enum action_tasks task) { const char *result = ""; switch(task) { case no_action: result = "no_action"; break; case stop_rsc: result = CRMD_ACTION_STOP; break; case stopped_rsc: result = CRMD_ACTION_STOPPED; break; case start_rsc: result = CRMD_ACTION_START; break; case started_rsc: result = CRMD_ACTION_STARTED; break; case shutdown_crm: result = CRM_OP_SHUTDOWN; break; case stonith_node: result = CRM_OP_FENCE; break; case monitor_rsc: result = CRMD_ACTION_MON; break; } return result; } void print_node(const char *pre_text, node_t *node, gboolean details) { if(node == NULL) { crm_debug_3("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug_3("%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) { + if(details && node != NULL && node->details != NULL) { char *pe_mutable = crm_strdup("\t\t"); crm_debug_3("\t\t===Node Attributes"); g_hash_table_foreach(node->details->attrs, print_str_str, pe_mutable); crm_free(pe_mutable); - } - if(details && node != NULL) { - crm_debug_3("\t\t===Node Attributes"); + crm_debug_3("\t\t=== Resources"); 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_debug_3("%s%s %s ==> %s", user_data==NULL?"":(char*)user_data, user_data==NULL?"":": ", (char*)key, (char*)value); } void print_color_details(const char *pre_text, struct color_shared_s *color, gboolean details) { if(color == NULL) { crm_debug_3("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug_3("%s%sColor %d: node=%s (from %d candidates)", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", color->id, color->chosen_node==NULL?"":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)); } } void print_color(const char *pre_text, color_t *color, gboolean details) { if(color == NULL) { crm_debug_3("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug_3("%s%sColor %d: (weight=%f, node=%s, possible=%d)", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", color->id, color->local_weight, safe_val5("",color,details,chosen_node,details,uname), g_list_length(color->details->candidate_nodes)); if(details) { print_color_details("\t", color->details, details); } } void print_rsc_to_node(const char *pre_text, rsc_to_node_t *cons, gboolean details) { if(cons == NULL) { crm_debug_3("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug_3("%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_debug_3("\t%s (score=%f : node placement rule)", safe_val3(NULL, cons, rsc_lh, id), cons->weight); slist_iter( node, node_t, cons->node_list_rh, lpc, print_node("\t\t-->", node, FALSE) ); } } void print_rsc_colocation(const char *pre_text, rsc_colocation_t *cons, gboolean details) { if(cons == NULL) { crm_debug_3("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug_3("%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_debug_3("\t%s --> %s, %s", safe_val3(NULL, cons, rsc_lh, id), safe_val3(NULL, cons, rsc_rh, id), strength2text(cons->strength)); } } void print_resource(const char *pre_text, resource_t *rsc, gboolean details) { if(rsc == NULL) { crm_debug_3("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } rsc->fns->dump(rsc, pre_text, details); } void print_action(const char *pre_text, action_t *action, gboolean details) { log_action(LOG_DEBUG_3, pre_text, action, details); } #define util_log(fmt...) do_crm_log(log_level, __FILE__, __FUNCTION__, fmt) void log_action(int log_level, const char *pre_text, action_t *action, gboolean details) { if(action == NULL) { util_log("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } switch(text2task(action->task)) { case stonith_node: case shutdown_crm: util_log("%s%s%sAction %d: %s @ %s", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", action->pseudo?"Pseduo ":action->optional?"Optional ":action->runnable?action->processed?"":"(Provisional) ":"!!Non-Startable!! ", action->id, action->task, safe_val4(NULL, action, node, details, uname)); break; default: util_log("%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, action->task, safe_val3(NULL, action, rsc, id), safe_val4(NULL, action, node, details, uname)); break; } if(details) { #if 1 util_log("\t\t====== Preceeding Actions"); slist_iter( other, action_wrapper_t, action->actions_before, lpc, log_action(log_level-1, "\t\t", other->action, FALSE); ); util_log("\t\t====== Subsequent Actions"); slist_iter( other, action_wrapper_t, action->actions_after, lpc, log_action(log_level-1, "\t\t", other->action, FALSE); ); #else util_log("\t\t====== Subsequent Actions"); slist_iter( other, action_wrapper_t, action->actions_after, lpc, log_action(log_level-1, "\t\t", other->action, FALSE); ); #endif util_log("\t\t====== End"); } else { util_log("\t\t(seen=%d, before=%d, after=%d)", action->seen_count, g_list_length(action->actions_before), g_list_length(action->actions_after)); } } void pe_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_debug_4("deleting node"); crm_debug_4("%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); } - + pe_free_shallow_adv(details->running_rsc, FALSE); } - + crm_free(details); + crm_free(node); } 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; -} - - void pe_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); } } void pe_free_shallow(GListPtr alist) { pe_free_shallow_adv(alist, TRUE); } void pe_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_debug_4("freeing %p", item->data); */ crm_free(item->data); } item->data = NULL; item->next = NULL; g_list_free(item); } } void pe_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); - - g_hash_table_destroy(rsc->parameters); - rsc->fns->free(rsc); } if(resources != NULL) { g_list_free(resources); } } void pe_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; g_hash_table_destroy(action->extra); crm_free(action->uuid); crm_free(action); } if(actions != NULL) { g_list_free(actions); } } void pe_free_ordering(GListPtr constraints) { while(constraints != NULL) { GListPtr list_item = constraints; order_constraint_t *order = list_item->data; constraints = constraints->next; crm_free(order->lh_action_task); crm_free(order->rh_action_task); crm_free(order); } if(constraints != NULL) { g_list_free(constraints); } } void pe_free_rsc_colocation(rsc_colocation_t *cons) { if(cons != NULL) { crm_debug_3("Freeing constraint %s (%p)", cons->id, cons); crm_free(cons); } } void pe_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* */ + pe_free_shallow(cons->node_list_rh); crm_free(cons); } } GListPtr find_actions(GListPtr input, const char *key, node_t *on_node) { GListPtr result = NULL; CRM_DEV_ASSERT(key != NULL); slist_iter( action, action_t, input, lpc, crm_debug_4("Matching %s against %s", key, action->uuid); if(safe_str_neq(key, action->uuid)) { continue; } else if(on_node == NULL) { result = g_list_append(result, action); } else if(action->node == NULL) { /* skip */ crm_debug("While looking for %s action on %s, " "found an unallocated one. Assigning" " it to the requested node...", key, on_node->details->uname); action->node = on_node; result = g_list_append(result, action); } else if(safe_str_eq(on_node->details->id, action->node->details->id)) { result = g_list_append(result, action); } ); return result; } void set_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) { pe_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_malloc0(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); } float merge_weights(float w1, float w2) { float result = w1 + w2; if(w1 <= -INFINITY || w2 <= -INFINITY) { if(w1 == INFINITY || w2 == INFINITY) { pe_warn("-INFINITY + INFINITY == -INFINITY"); } return -INFINITY; } else if(w1 >= INFINITY || w2 >= INFINITY) { return INFINITY; } /* detect wrap-around */ if(result > 0) { if(w1 <= 0 && w2 < 0) { result = -INFINITY; } } else if(w1 > 0 && w2 > 0) { result = INFINITY; } /* detect +/- INFINITY */ if(result >= INFINITY) { result = INFINITY; } else if(result <= -INFINITY) { result = -INFINITY; } return result; } +