diff --git a/crm/pengine/Makefile.am b/crm/pengine/Makefile.am index 483cb12e6f..2b469afccf 100644 --- a/crm/pengine/Makefile.am +++ b/crm/pengine/Makefile.am @@ -1,85 +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)/$(CRM_DIR)/common/libcrmcommon.la \ $(top_builddir)/$(CRM_DIR)/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 -ptest_SOURCES = pengine.c stages.c unpack.c color.c graph.c utils.c ptest.c \ - complex.c native.c group.c +ptest_SOURCES = color.c unpack.c graph.c \ + native.c group.c complex.c \ + pengine.c stages.c utils.c ptest.c ptest_CFLAGS = $(XML_FLAGS) -DHA_VARLIBDIR='"@HA_VARLIBDIR@"' ptest_LDFLAGS = $(XML_LIBS) ptest_LDADD = $(COMMONLIBS) -pengine_SOURCES = pengine.c stages.c unpack.c color.c graph.c utils.c main.c \ - complex.c native.c group.c +pengine_SOURCES = unpack.c color.c graph.c \ + native.c group.c complex.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/color.c b/crm/pengine/color.c index 8dfa037676..c3d66c9775 100644 --- a/crm/pengine/color.c +++ b/crm/pengine/color.c @@ -1,380 +1,147 @@ -/* $Id: color.c,v 1.19 2004/11/09 09:32:14 andrew Exp $ */ +/* $Id: color.c,v 1.20 2004/11/09 14:49:14 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 color_t *no_color = NULL; color_t *add_color(resource_t *rh_resource, color_t *color); -gboolean has_agent(node_t *a_node, lrm_agent_t *agent); - -gboolean choose_color(resource_t *lh_resource); - -gboolean assign_color(resource_t *rsc, color_t *color); - gboolean apply_placement_constraints(GListPtr constraints, GListPtr nodes) { int lpc = 0; crm_verbose("Applying constraints..."); slist_iter( cons, rsc_to_node_t, constraints, lpc, - cons->rsc_lh->fns->rsc_location(cons); + cons->rsc_lh->fns->rsc_location(cons->rsc_lh, cons); ); return TRUE; } gboolean apply_agent_constraints(GListPtr resources) { int lpc; - int lpc2; slist_iter( rsc, resource_t, resources, lpc, - - crm_trace("Applying RA restrictions to %s", rsc->id); - slist_iter( - node, node_t, rsc->allowed_nodes, lpc2, - - crm_trace("Checking if %s supports %s/%s (%s)", - node->details->uname, - rsc->agent->class, rsc->agent->type, - rsc->agent->version); - - if(has_agent(node, rsc->agent) == FALSE) { - /* remove node from contention */ - crm_trace("Marking node %s unavailable for %s", - node->details->uname, rsc->id); - node->weight = -1.0; - node->fixed = TRUE; - } - if(node->fixed && node->weight < 0) { - /* the structure of the list will have changed - * lpc2-- might be sufficient - */ - crm_debug("Removing node %s from %s", - node->details->uname, rsc->id); - - lpc2 = -1; - rsc->allowed_nodes = g_list_remove( - rsc->allowed_nodes, node); - crm_free(node); - } - - ) + rsc->fns->agent_constraints(rsc); ); crm_trace("Finished applying RA restrictions"); return TRUE; } -gboolean -has_agent(node_t *a_node, lrm_agent_t *an_agent) -{ - int lpc; - if(a_node == NULL || an_agent == NULL || an_agent->type == NULL) { - crm_warn("Invalid inputs"); - return FALSE; - } - - crm_devel("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_trace("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_verbose("%s doesnt support version %s of %s/%s", - a_node->details->uname, an_agent->version, - an_agent->class, an_agent->type); - - return FALSE; -} - - color_t * add_color(resource_t *resource, color_t *color) { color_t *local_color = NULL; if(color == NULL) { crm_err("Cannot add NULL color"); return NULL; } local_color = find_color(resource->candidate_colors, color); if(local_color == NULL) { crm_debug("Adding color %d", color->id); local_color = copy_color(color); resource->candidate_colors = g_list_append(resource->candidate_colors, local_color); } else { crm_debug("Color %d already present", color->id); } return local_color; } -gboolean -choose_color(resource_t *lh_resource) -{ - int lpc = 0; - GListPtr sorted_colors = NULL; - - if(lh_resource->runnable == FALSE) { - assign_color(lh_resource, no_color); - } - - if(lh_resource->provisional == FALSE) { - return !lh_resource->provisional; - } - - sorted_colors = g_list_sort( - lh_resource->candidate_colors, sort_color_weight); - - lh_resource->candidate_colors = sorted_colors; - - crm_verbose("Choose a color from %d possibilities", - g_list_length(sorted_colors)); - - slist_iter( - this_color, color_t, lh_resource->candidate_colors, lpc, - GListPtr intersection = NULL; - GListPtr minus = NULL; - int len = 0; - - if(this_color == NULL) { - crm_err("color was NULL"); - continue; - - } else if(lh_resource->effective_priority - < this_color->details->highest_priority) { - - minus = node_list_minus( - this_color->details->candidate_nodes, - lh_resource->allowed_nodes, TRUE); - - len = g_list_length(minus); - pe_free_shallow(minus); - - if(len > 0) { - assign_color(lh_resource, this_color); - break; - } - - } else { - intersection = node_list_and( - this_color->details->candidate_nodes, - lh_resource->allowed_nodes, TRUE); - - len = g_list_length(intersection); - pe_free_shallow(intersection); - - if(len != 0) { - assign_color(lh_resource, this_color); - break; - } - } - ); - - return !lh_resource->provisional; -} - void color_resource(resource_t *lh_resource, GListPtr *colors, GListPtr resources) { int lpc = 0; crm_debug_action(print_resource("Coloring", lh_resource, FALSE)); if(lh_resource->provisional == FALSE) { /* already processed this resource */ return; } lh_resource->rsc_cons = g_list_sort( lh_resource->rsc_cons, sort_cons_strength); crm_debug_action( print_resource("Pre-processing", lh_resource, FALSE)); /*------ Pre-processing */ slist_iter( constraint, rsc_dependancy_t, lh_resource->rsc_cons, lpc, crm_debug_action( print_rsc_dependancy( "Pre-Processing constraint", constraint,FALSE)); if(constraint->rsc_rh == NULL) { crm_err("rsc_rh was NULL for %s", constraint->id); continue; } lh_resource->fns->rsc_dependancy_lh(constraint); ); /* avoid looping through lists when we know this resource * cant be started */ lh_resource->fns->color(lh_resource, colors); crm_debug_action( print_resource("Post-processing", lh_resource, TRUE)); /*------ Post-processing */ slist_iter( constraint, rsc_dependancy_t, lh_resource->rsc_cons, lpc, crm_debug_action( print_rsc_dependancy( "Post-Processing constraint",constraint,FALSE)); lh_resource->fns->rsc_dependancy_lh(constraint); ); crm_debug_action(print_resource("Colored", lh_resource, TRUE)); } -gboolean -assign_color(resource_t *rsc, color_t *color) -{ - color_t *local_color = add_color(rsc, color); - GListPtr intersection = NULL; - GListPtr old_list = NULL; - - rsc->color = local_color; - rsc->provisional = FALSE; - - if(local_color != NULL) { - local_color->details->allocated_resources = - g_list_append( - local_color->details->allocated_resources,rsc); - - intersection = node_list_and( - local_color->details->candidate_nodes, - rsc->allowed_nodes, TRUE); - - old_list = local_color->details->candidate_nodes; - - pe_free_shallow(old_list); - - local_color->details->candidate_nodes = intersection; - - crm_verbose("Colored resource %s with new color %d", - rsc->id, rsc->color->id); - - crm_debug_action( - print_resource("Colored Resource", rsc, TRUE)); - - return TRUE; - } else { - crm_err("local color was NULL"); - } - - return FALSE; -} - - -gboolean -process_colored_constraints(resource_t *rsc) -{ - int lpc = 0; - color_t *other_c = NULL; - node_t *other_n = NULL; - - - if(rsc == NULL) { - crm_err("No constraints for NULL resource"); - return FALSE; - } else { - crm_debug("Processing constraints from %s", rsc->id); - } - - slist_iter( - constraint, rsc_dependancy_t, rsc->rsc_cons, lpc, - - /* remove the node from the other color */ - other_c = constraint->rsc_rh->color; - other_n = pe_find_node( - other_c->details->candidate_nodes, - safe_val6(NULL, rsc, color, details, - chosen_node, details, uname)); - - if(other_c == NULL) { - crm_err("No color associated with %s", - constraint->id); - continue; - } else if(other_n == NULL) { - crm_err("No node associated with rsc/color %s/%d", - rsc->id, rsc->color->id); - continue; - } - - switch(constraint->strength) { - case pecs_must_not: - other_c->details->candidate_nodes = - g_list_remove( - other_c->details->candidate_nodes, - other_n); - - crm_free(other_n); - break; - default: - break; - } - ); - return TRUE; -} diff --git a/crm/pengine/complex.c b/crm/pengine/complex.c index f37abf71c7..e6d80daf96 100644 --- a/crm/pengine/complex.c +++ b/crm/pengine/complex.c @@ -1,273 +1,239 @@ -/* $Id: complex.c,v 1.2 2004/11/09 11:18:00 andrew Exp $ */ +/* $Id: complex.c,v 1.3 2004/11/09 14:49:14 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_dependancy_t *constraint); void order_actions(action_t *lh, action_t *rh, order_constraint_t *order); resource_object_functions_t resource_class_functions[] = { { native_unpack, native_color, native_create_actions, - native_internal_ordering, + native_internal_constraints, + native_agent_constraints, native_rsc_dependancy_lh, native_rsc_dependancy_rh, native_rsc_order_lh, native_rsc_order_rh, native_rsc_location, native_expand, native_dump, native_free }, { group_unpack, group_color, group_create_actions, - group_internal_ordering, + group_internal_constraints, + group_agent_constraints, group_rsc_dependancy_lh, group_rsc_dependancy_rh, group_rsc_order_lh, group_rsc_order_rh, group_rsc_location, group_expand, group_dump, group_free }, /* { */ /* incarnation_expand, */ /* incarnation_n_colors, */ /* incarnation_assign, */ /* incarnation_expand, */ /* incarnation_internal_constraints, */ /* incarnation_rsc_dependancy, */ /* incarnation_rsc_order, */ /* incarnation_rsc_location, */ /* incarnation_dump */ /* }, */ }; /* 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; } + return pe_unknown; } gboolean is_active(rsc_to_node_t *cons) { /* todo: check constraint lifetime */ return TRUE; } gboolean common_unpack(xmlNodePtr xml_obj, resource_t **rsc) { - const char *id = xmlGetProp(xml_obj, XML_ATTR_ID); + const char *id = xmlGetProp(xml_obj, XML_ATTR_ID); + const char *stopfail = xmlGetProp(xml_obj, "on_stopfail"); + const char *restart = xmlGetProp(xml_obj, "restart_type"); + const char *timeout = xmlGetProp(xml_obj, "timeout"); + const char *priority = xmlGetProp(xml_obj, XML_CIB_ATTR_PRIORITY); crm_verbose("Processing resource..."); if(id == NULL) { crm_err("Must specify id tag in "); return FALSE; } else if(rsc == NULL) { crm_err("Nowhere to unpack resource into"); return FALSE; } crm_malloc(*rsc, sizeof(resource_t)); if(*rsc == NULL) { return FALSE; } (*rsc)->id = id; (*rsc)->xml = xml_obj; (*rsc)->variant = get_resource_type(xml_obj->name); if((*rsc)->variant == pe_unknown) { crm_err("Unknown resource type: %s", xml_obj->name); crm_free(*rsc); return FALSE; } (*rsc)->fns = &resource_class_functions[(*rsc)->variant]; (*rsc)->fns->unpack(*rsc); - return TRUE; -} - -gboolean -update_node_weight(rsc_to_node_t *cons, const char *id, GListPtr nodes) -{ - node_t *node_rh = pe_find_node(cons->rsc_lh->allowed_nodes, id); - if(node_rh == NULL) { - crm_err("Node not found - cant update"); - return FALSE; - } - - if(node_rh->fixed) { - /* warning */ - crm_warn("Constraint %s is irrelevant as the" - " weight of node %s is fixed as %f.", - cons->id, - node_rh->details->uname, - node_rh->weight); - return TRUE; - } + crm_verbose("Processing resource..."); - crm_verbose("Constraint %s (%s): node %s weight %f.", - cons->id, - cons->can?"can":"cannot", - node_rh->details->uname, - node_rh->weight); - - if(cons->can == FALSE) { - node_rh->weight = -1; + (*rsc)->priority = atoi(priority?priority:"0"); + (*rsc)->effective_priority = (*rsc)->priority; + (*rsc)->recovery_type = recovery_stop_start; + (*rsc)->runnable = TRUE; + (*rsc)->provisional = TRUE; + (*rsc)->timeout = timeout; + (*rsc)->candidate_colors = NULL; + (*rsc)->rsc_cons = NULL; + (*rsc)->actions = NULL; + + if(safe_str_eq(stopfail, "ignore")) { + (*rsc)->stopfail_type = pesf_ignore; + } else if(safe_str_eq(stopfail, "stonith")) { + (*rsc)->stopfail_type = pesf_stonith; } else { - node_rh->weight += cons->weight; + (*rsc)->stopfail_type = pesf_block; } - - if(node_rh->weight < 0) { - node_rh->fixed = TRUE; + + if(safe_str_eq(restart, "restart")) { + (*rsc)->restart_type = pe_restart_restart; + } else if(safe_str_eq(restart, "recover")) { + (*rsc)->restart_type = pe_restart_recover; + } else { + (*rsc)->restart_type = pe_restart_ignore; } - crm_debug_action(print_node("Updated", node_rh, FALSE)); - return TRUE; } -gboolean -constraint_violated( - resource_t *rsc_lh, resource_t *rsc_rh, rsc_dependancy_t *constraint) -{ - GListPtr result = NULL; - color_t *color_lh = rsc_lh->color; - color_t *color_rh = rsc_rh->color; - - GListPtr candidate_nodes_lh = NULL; - GListPtr candidate_nodes_rh = NULL; - - gboolean matched = FALSE; - 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; -} void order_actions(action_t *lh_action, action_t *rh_action, order_constraint_t *order) { action_wrapper_t *wrapper = NULL; GListPtr list = NULL; crm_verbose("%d Processing %d -> %d", order->id, lh_action->id, rh_action->id); crm_debug_action( print_action("LH (order_actions)", lh_action, FALSE)); crm_debug_action( print_action("RH (order_actions)", rh_action, FALSE)); crm_malloc(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; } crm_malloc(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("%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, + rsc->xml->name, + (double)rsc->priority); +} + + +void common_free(resource_t *rsc) +{ + if(rsc == NULL) { + return; + } + + crm_debug("Freeing %s", rsc->id); + + while(rsc->rsc_cons) { + crm_debug("Freeing constraint"); + pe_free_rsc_dependancy( + (rsc_dependancy_t*)rsc->rsc_cons->data); + rsc->rsc_cons = rsc->rsc_cons->next; + } + crm_debug("Freeing constraint list"); + if(rsc->rsc_cons != NULL) { + g_list_free(rsc->rsc_cons); + } + + crm_free(rsc->variant_opaque); + crm_free(rsc); +} diff --git a/crm/pengine/complex.h b/crm/pengine/complex.h index b2ca5f02f3..15f978e774 100644 --- a/crm/pengine/complex.h +++ b/crm/pengine/complex.h @@ -1,98 +1,111 @@ -/* $Id: complex.h,v 1.2 2004/11/09 11:18:00 andrew Exp $ */ +/* $Id: complex.h,v 1.3 2004/11/09 14:49:14 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 #define n_object_classes 3 //#define PE_OBJ_F_ "" #define PE_OBJ_T_NATIVE "native" #define PE_OBJ_T_GROUP "group" #define PE_OBJ_T_INCARNATION "incarnation" enum pe_obj_types { pe_native = 0, pe_group = 1, pe_incarnation = 2, pe_unknown = -1 }; extern int get_resource_type(const char *name); typedef struct resource_object_functions_s { void (*unpack)(resource_t *); void (*color)(resource_t *, GListPtr *); void (*create_actions)(resource_t *); - void (*internal_ordering)(resource_t *, GListPtr *); + void (*internal_constraints)(resource_t *, GListPtr *); + void (*agent_constraints)(resource_t *); void (*rsc_dependancy_lh)(rsc_dependancy_t *); void (*rsc_dependancy_rh)(resource_t *, rsc_dependancy_t *); void (*rsc_order_lh)(resource_t *, order_constraint_t *); void (*rsc_order_rh)( action_t *, resource_t *, order_constraint_t *); - void (*rsc_location)(rsc_to_node_t *); + void (*rsc_location)(resource_t *, rsc_to_node_t *); void (*expand)(resource_t *, xmlNodePtr *); void (*dump)(resource_t *, const char *, gboolean); void (*free)(resource_t *); } resource_object_functions_t; extern void native_unpack(resource_t *rsc); extern void native_color(resource_t *rsc, GListPtr *colors); extern void native_create_actions(resource_t *rsc); -extern void native_internal_ordering( +extern void native_internal_constraints( resource_t *rsc, GListPtr *ordering_constraints); +extern void native_agent_constraints(resource_t *rsc); extern void native_rsc_dependancy_lh(rsc_dependancy_t *constraint); extern void native_rsc_dependancy_rh( resource_t *rsc, rsc_dependancy_t *constraint); extern void native_rsc_order_lh(resource_t *rsc, order_constraint_t *order); extern void native_rsc_order_rh( action_t *lh_action, resource_t *rsc, order_constraint_t *order); -extern void native_rsc_location(rsc_to_node_t *constraint); +extern void native_rsc_location(resource_t *rsc, rsc_to_node_t *constraint); extern void native_expand(resource_t *rsc, xmlNodePtr *graph); extern void native_dump(resource_t *rsc, const char *pre_text, gboolean details); extern void native_free(resource_t *rsc); extern void group_unpack(resource_t *rsc); extern void group_color(resource_t *rsc, GListPtr *colors); extern void group_create_actions(resource_t *rsc); -extern void group_internal_ordering( +extern void group_internal_constraints( resource_t *rsc, GListPtr *ordering_constraints); +extern void group_agent_constraints(resource_t *rsc); extern void group_rsc_dependancy_lh(rsc_dependancy_t *constraint); extern void group_rsc_dependancy_rh( resource_t *rsc, rsc_dependancy_t *constraint); extern void group_rsc_order_lh(resource_t *rsc, order_constraint_t *order); extern void group_rsc_order_rh( action_t *lh_action, resource_t *rsc, order_constraint_t *order); -extern void group_rsc_location(rsc_to_node_t *constraint); +extern void group_rsc_location(resource_t *rsc, rsc_to_node_t *constraint); extern void group_expand(resource_t *rsc, xmlNodePtr *graph); extern void group_dump(resource_t *rsc, const char *pre_text, gboolean details); extern void group_free(resource_t *rsc); /* extern resource_object_functions_t resource_variants[]; */ extern resource_object_functions_t resource_class_functions[]; extern gboolean common_unpack(xmlNodePtr xml_obj, resource_t **rsc); +extern void common_dump( + resource_t *rsc, const char *pre_text, gboolean details); +extern void common_free(resource_t *rsc); +extern void native_add_running(resource_t *rsc, node_t *node); +extern gboolean is_active(rsc_to_node_t *cons); + +extern gboolean native_constraint_violated( + resource_t *rsc_lh, resource_t *rsc_rh, rsc_dependancy_t *constraint); + +extern void order_actions(action_t *lh, action_t *rh, order_constraint_t *order); diff --git a/crm/pengine/graph.c b/crm/pengine/graph.c index 7b5612dd70..9e10805104 100644 --- a/crm/pengine/graph.c +++ b/crm/pengine/graph.c @@ -1,361 +1,357 @@ -/* $Id: graph.c,v 1.19 2004/10/27 15:30:55 andrew Exp $ */ +/* $Id: graph.c,v 1.20 2004/11/09 14:49:14 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 gboolean update_action(action_t *action); gboolean update_action_states(GListPtr actions) { int lpc = 0; slist_iter( action, action_t, actions, lpc, update_action(action); ); return TRUE; } gboolean update_action(action_t *action) { gboolean change = FALSE; int lpc = 0; if(action->optional && action->runnable) { return FALSE; } slist_iter( other, action_wrapper_t, action->actions_after, lpc, if(action->runnable == FALSE && action->optional == FALSE) { if(other->action->runnable == FALSE) { continue; } else if (other->strength == pecs_must) { change = TRUE; other->action->runnable =FALSE; crm_debug_action( print_action("Marking unrunnable", other->action, FALSE); print_action("Reason", action, FALSE); ); - } - + } } if(action->optional == FALSE && other->action->optional) { switch(action->rsc->restart_type) { case pe_restart_ignore: break; case pe_restart_recover: crm_err("Recover after dependancy " "restart not supported... " "forcing a restart"); /* keep going */ case pe_restart_restart: change = TRUE; other->action->optional = FALSE; crm_debug_action( print_action("Marking manditory", other->action, FALSE)); } } if(change) { update_action(other->action); } ); return change; } gboolean shutdown_constraints( node_t *node, action_t *shutdown_op, GListPtr *ordering_constraints) { int lpc = 0; /* 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, order_new(rsc, stop_rsc, NULL, NULL, shutdown_crm, 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) { int lpc = 0, lpc2 = 0; - GListPtr start_actions = NULL; GListPtr stop_actions = NULL; if(shutdown_op != NULL) { /* shutdown before stonith */ /* add the shutdown OP to the before lists so it counts as a pre-req */ crm_debug("Adding shutdown (%d) as an input to stonith (%d)", shutdown_op->id, stonith_op->id); order_new(NULL, shutdown_crm, shutdown_op, NULL, stonith_node, 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, /* make use of timeouts in the TE for cases such * as this. * ie. the node may be cactus and unable to receive the * stop let alone reply with failed. */ - /* TODO: this probably wont have any effect */ - stop_actions = find_actions_type(rsc->actions, stop_rsc, NULL); + stop_actions = find_actions(rsc->actions, stop_rsc, node); slist_iter( action, action_t, stop_actions, lpc2, - action->failure_is_fatal = FALSE; + action->discard = TRUE; ); - + if(rsc->stopfail_type == pesf_block) { /* depend on the stop action which will fail */ crm_warn("SHARED RESOURCE %s WILL REMAIN BLOCKED" " UNTIL CLEANED UP MANUALLY ON NODE %s", rsc->id, node->details->uname); continue; } else if(rsc->stopfail_type == pesf_ignore) { /* nothing to do here */ crm_warn("SHARED RESOURCE %s IS NOT PROTECTED", rsc->id); continue; } /* case pesf_stonith: */ /* remedial action: * shutdown (so all other resources are * stopped gracefully) and then STONITH node */ if(stonith_enabled == FALSE) { /* depend on an action that will never complete */ crm_err("STONITH is not enabled in this" " cluster but is required for " "resource %s after a failed stop", rsc->id); } crm_debug("Adding stonith (%d) as an input to start", stonith_op->id); /* stonith before start */ order_new(NULL, stonith_node, stonith_op, rsc, start_rsc, NULL, pecs_must, ordering_constraints); - /* TODO: this probably wont have any effect */ - start_actions = find_actions_type(rsc->actions, start_rsc, NULL); - slist_iter( - action, action_t, start_actions, lpc2, - action->failure_is_fatal = FALSE; - ); - - /* a pointless optimization? probably */ /* if(shutdown_op != NULL) { */ /* /\* the next rule is implied *\/ */ /* continue; */ /* } */ /* stop before stonith */ order_new(rsc, stop_rsc, NULL, NULL, stonith_node, stonith_op, pecs_must, ordering_constraints); ); return TRUE; } xmlNodePtr action2xml(action_t *action, gboolean as_input) { xmlNodePtr action_xml = NULL; if(action == NULL) { return NULL; } crm_debug("Dumping action%d as XML", action->id); switch(action->task) { case stonith_node: case shutdown_crm: action_xml = create_xml_node(NULL, "crm_event"); set_xml_property_copy( action_xml, XML_ATTR_ID, crm_itoa(action->id)); set_xml_property_copy( action_xml, XML_LRM_ATTR_TASK, task2text(action->task)); break; default: action_xml = create_xml_node(NULL, "rsc_op"); if(!as_input) { add_node_copy( action_xml, safe_val3(NULL, action, rsc, xml)); } set_xml_property_copy( action_xml, XML_ATTR_ID, crm_itoa(action->id)); set_xml_property_copy( action_xml, XML_LRM_ATTR_RSCID, safe_val3("__no_rsc__", action, rsc, id)); set_xml_property_copy( action_xml, XML_LRM_ATTR_TASK, task2text(action->task)); break; } if(action->task != stonith_node) { set_xml_property_copy( action_xml, XML_LRM_ATTR_TARGET, safe_val4("__no_node__", action, node, details,uname)); set_xml_property_copy( action_xml, XML_LRM_ATTR_TARGET_UUID, safe_val4("__no_uuid__", action, node, details, id)); } set_xml_property_copy( action_xml, "allow_fail", action->failure_is_fatal?XML_BOOLEAN_FALSE:XML_BOOLEAN_TRUE); set_xml_property_copy( action_xml, "timeout", action->timeout); /* set_xml_property_copy( */ /* action_xml, XML_LRM_ATTR_OPTIONAL, */ /* action->optional?XML_BOOLEAN_TRUE:XML_BOOLEAN_FALSE); */ /* set_xml_property_copy( */ /* action_xml, XML_LRM_ATTR_RUNNABLE, */ /* action->runnable?XML_BOOLEAN_TRUE:XML_BOOLEAN_FALSE); */ if(as_input) { return action_xml; } /* set_xml_property_copy( */ /* action_xml, XML_LRM_ATTR_DISCARD, */ /* action->discard?XML_BOOLEAN_TRUE:XML_BOOLEAN_FALSE); */ add_node_copy(action_xml, action->args); return action_xml; } void graph_element_from_action(action_t *action, xmlNodePtr *graph) { int lpc = 0; xmlNodePtr syn = NULL; xmlNodePtr set = NULL; xmlNodePtr in = NULL; xmlNodePtr input = NULL; xmlNodePtr xml_action = NULL; if(action == NULL) { crm_err("Cannot dump NULL action"); return; } else if(action->optional) { crm_trace("action %d was optional", action->id); return; } else if(action->runnable == FALSE) { crm_trace("action %d was not runnable", action->id); return; } else if(action->dumped) { crm_trace("action %d was already dumped", action->id); return; + + } else if(action->discard) { + crm_trace("action %d was discarded", action->id); + return; } action->dumped = TRUE; syn = create_xml_node(*graph, "synapse"); set = create_xml_node(syn, "action_set"); in = create_xml_node(syn, "inputs"); xml_action = action2xml(action, FALSE); xmlAddChild(set, xml_action); slist_iter(wrapper,action_wrapper_t,action->actions_before,lpc, if(wrapper->action->optional == TRUE) { continue; + + } else if(wrapper->action->discard == TRUE) { + continue; } switch(wrapper->strength) { case pecs_must_not: case pecs_ignore: /* ignore both */ break; case pecs_startstop: if(wrapper->action->runnable == FALSE){ break; } /* keep going */ case pecs_must: input = create_xml_node(in, "trigger"); xml_action = action2xml( wrapper->action, TRUE); xmlAddChild(input, xml_action); break; } ); } diff --git a/crm/pengine/group.c b/crm/pengine/group.c index ea5199c4df..c9709dbcc5 100644 --- a/crm/pengine/group.c +++ b/crm/pengine/group.c @@ -1,270 +1,277 @@ -/* $Id: group.c,v 1.1 2004/11/09 11:18:00 andrew Exp $ */ +/* $Id: group.c,v 1.2 2004/11/09 14:49:14 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 gboolean choose_color(resource_t *lh_resource); -extern gboolean assign_color(resource_t *rsc, color_t *color); -extern gboolean update_node_weight( - rsc_to_node_t *cons,const char *id,GListPtr nodes); -extern gboolean is_active(rsc_to_node_t *cons); -extern gboolean constraint_violated( - resource_t *rsc_lh, resource_t *rsc_rh, rsc_dependancy_t *constraint); -extern void order_actions(action_t *lh, action_t *rh, order_constraint_t *order); +extern gboolean rsc_dependancy_new( + const char *id, enum con_strength strength, + resource_t *rsc_lh, resource_t *rsc_rh); typedef struct group_variant_data_s { int num_children; GListPtr child_list; /* resource_t* */ resource_t *first_child; resource_t *last_child; } group_variant_data_t; void group_unpack(resource_t *rsc) { xmlNodePtr xml_obj = rsc->xml; group_variant_data_t *group_data = NULL; - native_unpack(rsc); - crm_malloc(group_data, sizeof(group_variant_data_t)); group_data->num_children = 0; group_data->child_list = NULL; group_data->first_child = NULL; group_data->last_child = NULL; xml_child_iter( xml_obj, xml_native_rsc, XML_CIB_TAG_RESOURCE, resource_t *new_rsc = NULL; if(common_unpack(xml_native_rsc, &new_rsc)) { group_data->num_children++; group_data->child_list = g_list_append( group_data->child_list, new_rsc); + group_data->last_child = new_rsc; + if(group_data->first_child == NULL) { group_data->first_child = new_rsc; } - group_data->last_child = new_rsc; - -/* crm_debug("Merging node list with new child"); */ -/* old_list = rsc->allowed_nodes; */ -/* old_list = node_list_and(rsc->allowed_nodes, */ -/* new_rsc->allowed_nodes, FALSE); */ -/* pe_free_shallow(old_list); */ crm_debug_action( print_resource("Added", new_rsc, FALSE)); } else { crm_err("Failed unpacking resource %s", xmlGetProp(xml_obj, XML_ATTR_ID)); } ); rsc->variant_opaque = group_data; } void group_color(resource_t *rsc, GListPtr *colors) { - int lpc; group_variant_data_t *group_data = (group_variant_data_t *)rsc->variant_opaque; - native_color(rsc, colors); + group_data->first_child->fns->color(group_data->first_child, colors); - slist_iter( - child_rsc, resource_t, group_data->child_list, lpc, - child_rsc->color = rsc->color; - child_rsc->provisional = FALSE; - ); + /* all others are inferred by vitue of the must constraints */ } void group_create_actions(resource_t *rsc) { int lpc; group_variant_data_t *group_data = (group_variant_data_t *)rsc->variant_opaque; slist_iter( child_rsc, resource_t, group_data->child_list, lpc, - native_create_actions(child_rsc); + child_rsc->fns->create_actions(child_rsc); ); } -void group_internal_ordering(resource_t *rsc, GListPtr *ordering_constraints) +void group_internal_constraints(resource_t *rsc, GListPtr *ordering_constraints) { int lpc; resource_t *last_rsc = NULL; group_variant_data_t *group_data = (group_variant_data_t *)rsc->variant_opaque; slist_iter( child_rsc, resource_t, group_data->child_list, lpc, if(last_rsc != NULL) { order_new(last_rsc, start_rsc, NULL, child_rsc, start_rsc, NULL, pecs_startstop, ordering_constraints); } + + if(child_rsc != group_data->first_child) { + rsc_dependancy_new("pe_group_internal", pecs_must, + group_data->first_child, child_rsc); + } + last_rsc = child_rsc; ); - - } void group_rsc_dependancy_lh(rsc_dependancy_t *constraint) { int lpc; resource_t *rsc = constraint->rsc_lh; group_variant_data_t *group_data = NULL; if(rsc == NULL) { crm_err("No constraints for NULL resource"); return; } else { crm_debug("Processing constraints from %s", rsc->id); } group_data = (group_variant_data_t *)rsc->variant_opaque; slist_iter( child_rsc, resource_t, group_data->child_list, lpc, child_rsc->fns->rsc_dependancy_rh(child_rsc, constraint); ); } void group_rsc_dependancy_rh(resource_t *rsc, rsc_dependancy_t *constraint) { int lpc; resource_t *rsc_lh = rsc; resource_t *rsc_rh = constraint->rsc_rh; group_variant_data_t *group_data = (group_variant_data_t *)rsc_rh->variant_opaque; crm_verbose("Processing RH of constraint %s", constraint->id); crm_debug_action(print_resource("LHS", rsc_lh, TRUE)); - slist_iter( child_rsc, resource_t, group_data->child_list, lpc, crm_debug_action(print_resource("RHS", rsc_rh, TRUE)); child_rsc->fns->rsc_dependancy_rh(child_rsc, constraint); ); } void group_rsc_order_lh(resource_t *rsc, order_constraint_t *order) { group_variant_data_t *group_data = (group_variant_data_t *)rsc->variant_opaque; crm_verbose("Processing LH of ordering constraint %d", order->id); if(order->lh_action_task == stop_rsc) { group_data->first_child->fns->rsc_order_lh( group_data->first_child, order); } else if(order->lh_action_task == start_rsc) { group_data->last_child->fns->rsc_order_lh( group_data->last_child, order); } } void group_rsc_order_rh( action_t *lh_action, resource_t *rsc, order_constraint_t *order) { group_variant_data_t *group_data = (group_variant_data_t *)rsc->variant_opaque; crm_verbose("Processing RH of ordering constraint %d", order->id); if(order->lh_action_task == stop_rsc) { group_data->last_child->fns->rsc_order_rh( lh_action, group_data->last_child, order); } else if(order->lh_action_task == start_rsc) { group_data->first_child->fns->rsc_order_rh( lh_action, group_data->first_child, order); } } -void group_rsc_location(rsc_to_node_t *constraint) +void group_rsc_location(resource_t *rsc, rsc_to_node_t *constraint) { - native_rsc_location(constraint); + int lpc; + group_variant_data_t *group_data = + (group_variant_data_t *)rsc->variant_opaque; + + crm_verbose("Processing actions from %s", rsc->id); + + slist_iter( + child_rsc, resource_t, group_data->child_list, lpc, + + child_rsc->fns->rsc_location(child_rsc, constraint); + ); } void group_expand(resource_t *rsc, xmlNodePtr *graph) { int lpc; group_variant_data_t *group_data = (group_variant_data_t *)rsc->variant_opaque; crm_verbose("Processing actions from %s", rsc->id); slist_iter( child_rsc, resource_t, group_data->child_list, lpc, child_rsc->fns->expand(child_rsc, graph); ); } void group_dump(resource_t *rsc, const char *pre_text, gboolean details) { int lpc; group_variant_data_t *group_data = (group_variant_data_t *)rsc->variant_opaque; - native_dump(rsc, pre_text, details); + common_dump(rsc, pre_text, details); - if(details) { - slist_iter( - child_rsc, resource_t, group_data->child_list, lpc, - - child_rsc->fns->dump(child_rsc, pre_text, details); - ); - } + slist_iter( + child_rsc, resource_t, group_data->child_list, lpc, + + child_rsc->fns->dump(child_rsc, pre_text, details); + ); } void group_free(resource_t *rsc) { int lpc; group_variant_data_t *group_data = (group_variant_data_t *)rsc->variant_opaque; crm_verbose("Freeing %s", rsc->id); slist_iter( child_rsc, resource_t, group_data->child_list, lpc, child_rsc->fns->free(child_rsc); ); pe_free_shallow_adv(group_data->child_list, FALSE); - native_free(rsc); + common_free(rsc); } +void +group_agent_constraints(resource_t *rsc) +{ + int lpc; + group_variant_data_t *group_data = + (group_variant_data_t *)rsc->variant_opaque; + + slist_iter( + child_rsc, resource_t, group_data->child_list, lpc, + + child_rsc->fns->agent_constraints(child_rsc); + ); +} diff --git a/crm/pengine/native.c b/crm/pengine/native.c index f5e534b5e3..f355ff48d2 100644 --- a/crm/pengine/native.c +++ b/crm/pengine/native.c @@ -1,715 +1,1067 @@ -/* $Id: native.c,v 1.2 2004/11/09 11:18:00 andrew Exp $ */ +/* $Id: native.c,v 1.3 2004/11/09 14:49:14 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 gboolean choose_color(resource_t *lh_resource); -extern gboolean assign_color(resource_t *rsc, color_t *color); -extern gboolean update_node_weight( - rsc_to_node_t *cons,const char *id,GListPtr nodes); -extern gboolean is_active(rsc_to_node_t *cons); -extern gboolean constraint_violated( - resource_t *rsc_lh, resource_t *rsc_rh, rsc_dependancy_t *constraint); -extern void order_actions(action_t *lh, action_t *rh, order_constraint_t *order); +extern color_t *add_color(resource_t *rh_resource, color_t *color); + +gboolean has_agent(node_t *a_node, lrm_agent_t *an_agent); + +gboolean native_choose_color(resource_t *lh_resource); + +gboolean native_assign_color(resource_t *rsc, color_t *color); + +gboolean native_update_node_weight( + rsc_to_node_t *cons, const char *id, GListPtr nodes); + + void native_rsc_dependancy_rh_must(resource_t *rsc_lh, gboolean update_lh, resource_t *rsc_rh, gboolean update_rh); void native_rsc_dependancy_rh_mustnot(resource_t *rsc_lh, gboolean update_lh, resource_t *rsc_rh, gboolean update_rh); +gboolean filter_nodes(resource_t *rsc); + + +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; + +void +native_add_running(resource_t *rsc, node_t *node) +{ + native_variant_data_t *native_data = + (native_variant_data_t *)rsc->variant_opaque; + + native_data->running_on = g_list_append(native_data->running_on, node); + + if(g_list_length(native_data->running_on) > 1) { + crm_warn("Resource %s is (potentially) active on %d nodes." + " Latest: %s", rsc->id, + g_list_length(native_data->running_on), + node->details->id); + } +} + + void native_unpack(resource_t *rsc) { xmlNodePtr xml_obj = rsc->xml; - - const char *stopfail = xmlGetProp(xml_obj, "on_stopfail"); - const char *restart = xmlGetProp(xml_obj, "restart_type"); - const char *timeout = xmlGetProp(xml_obj, "timeout"); - const char *version = xmlGetProp(xml_obj, XML_ATTR_VERSION); - const char *priority = xmlGetProp(xml_obj, XML_CIB_ATTR_PRIORITY); - - const char *max_instances = xmlGetProp(xml_obj, "max_instances"); - const char *max_node_instances = xmlGetProp(xml_obj, "max_node_instances"); - const char *max_masters = xmlGetProp(xml_obj, "max_masters"); - const char *max_node_masters = xmlGetProp(xml_obj, "max_node_masters"); + native_variant_data_t *native_data = NULL; + const char *version = xmlGetProp(xml_obj, XML_ATTR_VERSION); crm_verbose("Processing resource..."); + + crm_malloc(native_data, sizeof(native_variant_data_t)); + + crm_malloc(native_data->agent, sizeof(lrm_agent_t)); + native_data->agent->class = xmlGetProp(xml_obj, "class"); + native_data->agent->type = xmlGetProp(xml_obj, "type"); + native_data->agent->version = version?version:"0.0"; - crm_malloc(rsc->agent, sizeof(lrm_agent_t)); - rsc->agent->class = xmlGetProp(xml_obj, "class"); - rsc->agent->type = xmlGetProp(xml_obj, "type"); - rsc->agent->version = version?version:"0.0"; - - rsc->priority = atoi(priority?priority:"0"); - rsc->effective_priority = rsc->priority; - rsc->recovery_type = recovery_stop_start; - - rsc->max_instances = atoi(max_instances?max_instances:"1"); - rsc->max_node_instances = atoi(max_node_instances?max_node_instances:"1"); - rsc->max_masters = atoi(max_masters?max_masters:"0"); - rsc->max_node_masters = atoi(max_node_masters?max_node_masters:"0"); - - rsc->candidate_colors = NULL; - rsc->actions = NULL; - rsc->color = NULL; - rsc->runnable = TRUE; - rsc->provisional = TRUE; - rsc->allowed_nodes = NULL; - rsc->rsc_cons = NULL; - rsc->node_cons = NULL; - rsc->running_on = NULL; - rsc->timeout = timeout; - - if(safe_str_eq(stopfail, "ignore")) { - rsc->stopfail_type = pesf_ignore; - } else if(safe_str_eq(stopfail, "stonith")) { - rsc->stopfail_type = pesf_stonith; - } else { - rsc->stopfail_type = pesf_block; - } - - if(safe_str_eq(restart, "restart")) { - rsc->restart_type = pe_restart_restart; - } else if(safe_str_eq(restart, "recover")) { - rsc->restart_type = pe_restart_recover; - } else { - rsc->restart_type = pe_restart_ignore; - } + native_data->color = NULL; + native_data->allowed_nodes = NULL; + native_data->node_cons = NULL; + native_data->running_on = NULL; + rsc->variant_opaque = native_data; } void native_color(resource_t *rsc, GListPtr *colors) { color_t *new_color = NULL; - if( choose_color(rsc) ) { + native_variant_data_t *native_data = + (native_variant_data_t *)rsc->variant_opaque; + + if( native_choose_color(rsc) ) { crm_verbose("Colored resource %s with color %d", - rsc->id, rsc->color->id); + rsc->id, native_data->color->id); } else { - if(rsc->allowed_nodes != NULL) { + if(native_data->allowed_nodes != NULL) { /* filter out nodes with a negative weight */ filter_nodes(rsc); - new_color = create_color(colors, rsc, NULL); - assign_color(rsc, new_color); + new_color = create_color( + colors, rsc, native_data->allowed_nodes); + native_assign_color(rsc, new_color); } if(new_color == NULL) { crm_err("Could not color resource %s", rsc->id); print_resource("ERROR: No color", rsc, FALSE); - assign_color(rsc, no_color); + native_assign_color(rsc, no_color); } } rsc->provisional = FALSE; } void native_create_actions(resource_t *rsc) { int lpc2, lpc3; action_t *start_op = NULL; gboolean can_start = FALSE; node_t *chosen = NULL; + native_variant_data_t *native_data = + (native_variant_data_t *)rsc->variant_opaque; - if(rsc->color != NULL) { - chosen = rsc->color->details->chosen_node; + if(native_data->color != NULL) { + chosen = native_data->color->details->chosen_node; } if(chosen != NULL) { can_start = TRUE; } - if(can_start && g_list_length(rsc->running_on) == 0) { + if(can_start && g_list_length(native_data->running_on) == 0) { /* create start action */ crm_info("Start resource %s (%s)", rsc->id, safe_val3(NULL, chosen, details, uname)); start_op = action_new(rsc, start_rsc, chosen); - } else if(g_list_length(rsc->running_on) > 1) { + } else if(g_list_length(native_data->running_on) > 1) { crm_info("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, - rsc->running_on, lpc2, + native_data->running_on, lpc2, crm_info("Stop resource %s (%s)", rsc->id, safe_val3(NULL, node, details, uname)); action_new(rsc, stop_rsc, node); ); } if(rsc->recovery_type == recovery_stop_start && can_start) { crm_info("Start resource %s (%s)", rsc->id, safe_val3(NULL, chosen, details, uname)); start_op = action_new( rsc, start_rsc, chosen); } } else { /* stop and or possible restart */ crm_debug("Stop and possible restart of %s", rsc->id); slist_iter( - node, node_t, rsc->running_on, lpc2, + node, node_t, native_data->running_on, lpc2, if(chosen != NULL && safe_str_eq( node->details->id, chosen->details->id)) { /* restart */ crm_info("Leave resource %s alone (%s)", rsc->id, safe_val3(NULL, chosen, details, uname)); /* in case the actions already exist */ slist_iter( action, action_t, rsc->actions, lpc3, if(action->task == start_rsc || action->task == stop_rsc){ action->optional = TRUE; } ); continue; } else if(chosen != NULL) { /* move */ crm_info("Move resource %s (%s -> %s)", rsc->id, safe_val3(NULL, node, details, uname), safe_val3(NULL, chosen, details, uname)); action_new(rsc, stop_rsc, node); action_new(rsc, start_rsc, chosen); } else { crm_info("Stop resource %s (%s)", rsc->id, safe_val3(NULL, node, details, uname)); action_new(rsc, stop_rsc, node); } ); } } -void native_internal_ordering(resource_t *rsc, GListPtr *ordering_constraints) +void native_internal_constraints(resource_t *rsc, GListPtr *ordering_constraints) { order_new(rsc, stop_rsc, NULL, rsc, start_rsc, NULL, pecs_startstop, ordering_constraints); } void native_rsc_dependancy_lh(rsc_dependancy_t *constraint) { resource_t *rsc = constraint->rsc_lh; if(rsc == NULL) { crm_err("No constraints for NULL resource"); return; } else { crm_debug("Processing constraints from %s", rsc->id); } constraint->rsc_rh->fns->rsc_dependancy_rh(rsc, constraint); } void native_rsc_dependancy_rh(resource_t *rsc, rsc_dependancy_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 = + (native_variant_data_t *)rsc_lh->variant_opaque; + + native_variant_data_t *native_data_rh = + (native_variant_data_t *)rsc_rh->variant_opaque; + crm_verbose("Processing RH of constraint %s", constraint->id); crm_debug_action(print_resource("LHS", rsc_lh, TRUE)); crm_debug_action(print_resource("RHS", rsc_rh, TRUE)); if(constraint->strength == pecs_ignore || constraint->strength == pecs_startstop){ crm_debug("Skipping constraint type %d", constraint->strength); return; } if(rsc_lh->provisional && rsc_rh->provisional) { /* nothing */ crm_debug("Skipping constraint, both sides provisional"); return; } else if( (!rsc_lh->provisional) && (!rsc_rh->provisional) - && (!rsc_lh->color->details->pending) - && (!rsc_rh->color->details->pending) ) { + && (!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 - && rsc_lh->color->details->pending == FALSE) { + && native_data_lh->color->details->pending == FALSE) { /* update _us_ : postproc color version */ update_rh = TRUE; } else if(rsc_rh->provisional == FALSE - && rsc_rh->color->details->pending == FALSE) { + && native_data_rh->color->details->pending == FALSE) { /* update _them_ : postproc color alt version */ update_lh = TRUE; } else if(rsc_lh->provisional == FALSE) { /* update _us_ : preproc version */ update_rh = TRUE; } else if(rsc_rh->provisional == FALSE) { /* update _them_ : postproc version */ update_lh = TRUE; } else { crm_warn("Un-expected combination of inputs"); return; } if(update_lh) { crm_debug("Updating LHS"); } if(update_rh) { crm_debug("Updating RHS"); } if(do_check) { - if(constraint_violated(rsc_lh, rsc_rh, constraint) == FALSE) { + if(native_constraint_violated( + rsc_lh, rsc_rh, constraint) == FALSE) { + crm_debug("Constraint satisfied"); return; } /* else constraint cant be satisified */ crm_warn("Constraint %s could not be satisfied", constraint->id); if(update_lh) { crm_warn("Marking resource %s unrunnable as a result", rsc_lh->id); rsc_lh->runnable = FALSE; } if(update_rh) { crm_warn("Marking resource %s unrunnable as a result", rsc_rh->id); rsc_rh->runnable = FALSE; } } if(constraint->strength == pecs_must) { native_rsc_dependancy_rh_must( rsc_lh, update_lh,rsc_rh, update_rh); return; } else if(constraint->strength != pecs_must_not) { /* unknown type */ crm_err("Unknown constraint type %d", constraint->strength); return; } native_rsc_dependancy_rh_mustnot(rsc_lh, update_lh,rsc_rh, update_rh); } void native_rsc_order_lh(resource_t *lh_rsc, order_constraint_t *order) { int lpc; GListPtr lh_actions = NULL; action_t *lh_action = order->lh_action; crm_verbose("Processing LH of ordering constraint %d", order->id); if(order->lh_action_task != stop_rsc && order->lh_action_task != start_rsc) { crm_err("Task %s from ordering %d isnt a resource action", task2text(order->lh_action_task), order->id); return; } if(lh_action != NULL) { lh_actions = g_list_append(NULL, lh_action); } else if(lh_action == NULL && lh_rsc != NULL) { if(order->strength == pecs_must) { crm_debug("No LH-Side (%s/%s) found for constraint..." " creating", lh_rsc->id, task2text(order->lh_action_task)); action_new(lh_rsc, order->lh_action_task, NULL); } - lh_actions = find_actions_type( + lh_actions = find_actions( lh_rsc->actions, order->lh_action_task, NULL); if(lh_actions == NULL) { crm_debug("No LH-Side (%s/%s) found for constraint", lh_rsc->id, task2text(order->lh_action_task)); return; } } else { crm_warn("No LH-Side (%s) specified for constraint", task2text(order->lh_action_task)); 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) { int lpc; GListPtr rh_actions = NULL; action_t *rh_action = order->rh_action; crm_verbose("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_type( + rh_actions = find_actions( rsc->actions, order->rh_action_task, NULL); if(rh_actions == NULL) { crm_debug("No RH-Side (%s/%s) found for constraint..." " ignoring", rsc->id, task2text(order->rh_action_task)); return; } } else if(rh_action == NULL) { crm_debug("No RH-Side (%s) specified for constraint..." " ignoring", task2text(order->rh_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(rsc_to_node_t *constraint) +void native_rsc_location(resource_t *rsc, rsc_to_node_t *constraint) { int lpc; GListPtr or_list; - resource_t *rsc_lh = constraint->rsc_lh; + resource_t *rsc_lh = rsc; + native_variant_data_t *native_data = + (native_variant_data_t *)rsc_lh->variant_opaque; crm_debug_action(print_rsc_to_node("Applying", constraint, FALSE)); /* take "lifetime" into account */ if(constraint == NULL) { crm_err("Constraint is NULL"); return; } else if(is_active(constraint) == FALSE) { crm_info("Constraint (%s) is not active", constraint->id); /* warning */ return; } rsc_lh = constraint->rsc_lh; if(rsc_lh == NULL) { crm_err("LHS of rsc_to_node (%s) is NULL", constraint->id); return; } - constraint->rsc_lh->node_cons = - g_list_append(constraint->rsc_lh->node_cons, constraint); + native_data->node_cons = + g_list_append(native_data->node_cons, constraint); if(constraint->node_list_rh == NULL) { crm_err("RHS of constraint %s is NULL", constraint->id); return; } crm_debug_action(print_resource("before update", rsc_lh,TRUE)); or_list = node_list_or( - rsc_lh->allowed_nodes, constraint->node_list_rh, FALSE); + native_data->allowed_nodes, constraint->node_list_rh, FALSE); - pe_free_shallow(rsc_lh->allowed_nodes); - rsc_lh->allowed_nodes = or_list; + pe_free_shallow(native_data->allowed_nodes); + native_data->allowed_nodes = or_list; slist_iter(node_rh, node_t, constraint->node_list_rh, lpc, - update_node_weight(constraint, node_rh->details->uname, - rsc_lh->allowed_nodes)); + native_update_node_weight( + constraint, node_rh->details->uname, + native_data->allowed_nodes)); crm_debug_action(print_resource("after update", rsc_lh, TRUE)); } void native_expand(resource_t *rsc, xmlNodePtr *graph) { int lpc; slist_iter( action, action_t, rsc->actions, lpc, crm_debug("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) { - - crm_debug("%s%s%s%sResource %s: (priority=%f, color=%d, now=%d)", - pre_text==NULL?"":pre_text, - pre_text==NULL?"":": ", - rsc->provisional?"Provisional ":"", - rsc->runnable?"":"(Non-Startable) ", - rsc->id, - (double)rsc->priority, - safe_val3(-1, rsc, color, id), - g_list_length(rsc->running_on)); + native_variant_data_t *native_data = + (native_variant_data_t *)rsc->variant_opaque; + common_dump(rsc, pre_text, details); crm_debug("\t%d candidate colors, %d allowed nodes," " %d rsc_cons and %d node_cons", g_list_length(rsc->candidate_colors), - g_list_length(rsc->allowed_nodes), + g_list_length(native_data->allowed_nodes), g_list_length(rsc->rsc_cons), - g_list_length(rsc->node_cons)); + g_list_length(native_data->node_cons)); if(details) { int lpc = 0; crm_debug("\t=== Actions"); slist_iter( action, action_t, rsc->actions, lpc, print_action("\trsc action: ", action, FALSE); ); crm_debug("\t=== Colors"); slist_iter( color, color_t, rsc->candidate_colors, lpc, print_color("\t", color, FALSE) ); crm_debug("\t=== Allowed Nodes"); slist_iter( - node, node_t, rsc->allowed_nodes, lpc, + 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("Freeing Allowed Nodes"); - pe_free_shallow(rsc->allowed_nodes); + pe_free_shallow(native_data->allowed_nodes); - while(rsc->rsc_cons) { - crm_debug("Freeing constraint"); - pe_free_rsc_dependancy((rsc_dependancy_t*)rsc->rsc_cons->data); - rsc->rsc_cons = rsc->rsc_cons->next; - } - crm_debug("Freeing constraint list"); - if(rsc->rsc_cons != NULL) { - g_list_free(rsc->rsc_cons); - } - - crm_free(rsc->variant_opaque); - crm_free(rsc); + common_free(rsc); } void native_rsc_dependancy_rh_must(resource_t *rsc_lh, gboolean update_lh, resource_t *rsc_rh, gboolean update_rh) { + native_variant_data_t *native_data_lh = + (native_variant_data_t *)rsc_lh->variant_opaque; + + native_variant_data_t *native_data_rh = + (native_variant_data_t *)rsc_rh->variant_opaque; + 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; - if(rsc_lh->color && rsc_rh->color) { + if(native_data_lh->color && native_data_rh->color) { do_merge = TRUE; merged_node_list = node_list_and( - rsc_lh->color->details->candidate_nodes, - rsc_rh->color->details->candidate_nodes, TRUE); + native_data_lh->color->details->candidate_nodes, + native_data_rh->color->details->candidate_nodes, TRUE); - } else if(rsc_lh->color) { + } else if(native_data_lh->color) { do_merge = TRUE; merged_node_list = node_list_and( - rsc_lh->color->details->candidate_nodes, - rsc_rh->allowed_nodes, TRUE); + native_data_lh->color->details->candidate_nodes, + native_data_rh->allowed_nodes, TRUE); - } else if(rsc_rh->color) { + } else if(native_data_rh->color) { do_merge = TRUE; merged_node_list = node_list_and( - rsc_lh->allowed_nodes, - rsc_rh->color->details->candidate_nodes, TRUE); + native_data_lh->allowed_nodes, + native_data_rh->color->details->candidate_nodes, TRUE); } if(update_lh) { - crm_free(rsc_lh->color); + crm_free(native_data_lh->color); rsc_lh->runnable = rsc_rh->runnable; - rsc_lh->color = copy_color(rsc_rh->color); + native_data_lh->color = copy_color(native_data_rh->color); } if(update_rh) { - crm_free(rsc_rh->color); + crm_free(native_data_rh->color); rsc_rh->runnable = rsc_lh->runnable; - rsc_rh->color = copy_color(rsc_lh->color); + native_data_rh->color = copy_color(native_data_lh->color); } if(do_merge) { crm_debug("Merging candidate nodes"); - old_list = rsc_rh->color->details->candidate_nodes; - rsc_rh->color->details->candidate_nodes = merged_node_list; + 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("Finished processing pecs_must constraint"); } void native_rsc_dependancy_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 = + (native_variant_data_t *)rsc_lh->variant_opaque; + + native_variant_data_t *native_data_rh = + (native_variant_data_t *)rsc_rh->variant_opaque; crm_debug("Processing pecs_must_not constraint"); /* pecs_must_not */ if(update_lh) { - color_rh = rsc_rh->color; + color_rh = native_data_rh->color; if(rsc_lh->provisional) { color_lh = find_color( - rsc_lh->candidate_colors,color_rh); + rsc_lh->candidate_colors, color_rh); rsc_lh->candidate_colors = g_list_remove( rsc_lh->candidate_colors, color_lh); crm_debug_action( print_color("Removed LH", color_lh, FALSE)); crm_debug_action( print_resource("Modified LH", rsc_lh, TRUE)); crm_free(color_lh); - } else if(rsc_lh->color && rsc_lh->color->details->pending) { + } else if(native_data_lh->color + && native_data_lh->color->details->pending) { node_t *node_lh = NULL; - color_lh = rsc_lh->color; + 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_debug_action( print_node("Removed LH", node_lh, FALSE)); crm_debug_action( print_color("Modified LH", color_lh, FALSE)); crm_free(node_lh); } else { /* error, rsc marked as unrunnable above */ crm_warn("lh else"); } } if(update_rh) { - color_lh = rsc_lh->color; + 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_debug_action( print_color("Removed RH", color_rh, FALSE)); crm_debug_action( print_resource("Modified RH", rsc_rh, TRUE)); crm_free(color_rh); - } else if(rsc_rh->color && rsc_rh->color->details->pending) { + } else if(native_data_rh->color + && native_data_rh->color->details->pending) { node_t *node_rh = NULL; - color_rh = rsc_rh->color; + 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_debug_action( print_node("Removed RH", node_rh, FALSE)); crm_debug_action( print_color("Modified RH", color_rh, FALSE)); crm_free(node_rh); } else { /* error, rsc marked as unrunnable above */ crm_warn("rh else"); } } } + + +void +native_agent_constraints(resource_t *rsc) +{ + int lpc; + native_variant_data_t *native_data = + (native_variant_data_t *)rsc->variant_opaque; + + crm_trace("Applying RA restrictions to %s", rsc->id); + slist_iter( + node, node_t, native_data->allowed_nodes, lpc, + + crm_trace("Checking if %s supports %s/%s (%s)", + node->details->uname, + native_data->agent->class, + native_data->agent->type, + native_data->agent->version); + + if(has_agent(node, native_data->agent) == FALSE) { + /* remove node from contention */ + crm_trace("Marking node %s unavailable for %s", + node->details->uname, rsc->id); + node->weight = -1.0; + node->fixed = TRUE; + } + if(node->fixed && node->weight < 0) { + /* the structure of the list will have changed + * lpc-- might be sufficient + */ + crm_debug("Removing node %s from %s", + node->details->uname, rsc->id); + + lpc = -1; + native_data->allowed_nodes = g_list_remove( + native_data->allowed_nodes, node); + + crm_free(node); + } + ); +} + +gboolean +has_agent(node_t *a_node, lrm_agent_t *an_agent) +{ + int lpc; + if(a_node == NULL || an_agent == NULL || an_agent->type == NULL) { + crm_warn("Invalid inputs"); + return FALSE; + } + + crm_devel("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_trace("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_verbose("%s doesnt support version %s of %s/%s", + a_node->details->uname, an_agent->version, + an_agent->class, an_agent->type); + + return FALSE; +} +gboolean +native_choose_color(resource_t *rsc) +{ + int lpc = 0; + GListPtr sorted_colors = NULL; + native_variant_data_t *native_data = + (native_variant_data_t *)rsc->variant_opaque; + + 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_verbose("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) { + crm_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; +} + + +gboolean +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 = + (native_variant_data_t *)rsc->variant_opaque; + + native_data->color = local_color; + rsc->provisional = FALSE; + + if(local_color != NULL) { + 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_verbose("Colored resource %s with new color %d", + rsc->id, native_data->color->id); + + crm_debug_action( + print_resource("Colored Resource", rsc, TRUE)); + + return TRUE; + } else { + crm_err("local color was NULL"); + } + + return FALSE; +} + +gboolean +native_update_node_weight(rsc_to_node_t *cons, const char *id, GListPtr nodes) +{ + native_variant_data_t *native_data = + (native_variant_data_t *)cons->rsc_lh->variant_opaque; + + node_t *node_rh = pe_find_node(native_data->allowed_nodes, id); + + if(node_rh == NULL) { + crm_err("Node not found - cant update"); + return FALSE; + } + + if(node_rh->fixed) { + /* warning */ + crm_warn("Constraint %s is irrelevant as the" + " weight of node %s is fixed as %f.", + cons->id, + node_rh->details->uname, + node_rh->weight); + return TRUE; + } + + crm_verbose("Constraint %s (%s): node %s weight %f.", + cons->id, + cons->can?"can":"cannot", + node_rh->details->uname, + node_rh->weight); + + if(cons->can == FALSE) { + node_rh->weight = -1; + } else { + node_rh->weight += cons->weight; + } + + if(node_rh->weight < 0) { + node_rh->fixed = TRUE; + } + + crm_debug_action(print_node("Updated", node_rh, FALSE)); + + return TRUE; +} + +gboolean +native_constraint_violated( + resource_t *rsc_lh, resource_t *rsc_rh, rsc_dependancy_t *constraint) +{ + native_variant_data_t *native_data_lh = + (native_variant_data_t *)rsc_lh->variant_opaque; + + native_variant_data_t *native_data_rh = + (native_variant_data_t *)rsc_rh->variant_opaque; + + GListPtr result = NULL; + color_t *color_lh = native_data_lh->color; + color_t *color_rh = native_data_rh->color; + + GListPtr candidate_nodes_lh = NULL; + GListPtr candidate_nodes_rh = NULL; + + gboolean matched = FALSE; + 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 + */ +gboolean +filter_nodes(resource_t *rsc) +{ + int lpc2 = 0; + native_variant_data_t *native_data = + (native_variant_data_t *)rsc->variant_opaque; + + crm_debug_action(print_resource("Filtering nodes for", rsc, FALSE)); + slist_iter( + node, node_t, native_data->allowed_nodes, lpc2, + if(node == NULL) { + crm_err("Invalid NULL node"); + + } else if(node->weight < 0.0 + || node->details->online == FALSE + || node->details->type == node_ping) { + crm_debug_action(print_node("Removing", node, FALSE)); + native_data->allowed_nodes = + g_list_remove(native_data->allowed_nodes, node); + crm_free(node); + lpc2 = -1; /* restart the loop */ + } + ); + + return TRUE; +} diff --git a/crm/pengine/pe_utils.h b/crm/pengine/pe_utils.h index ee48ad53ba..52f725ca42 100644 --- a/crm/pengine/pe_utils.h +++ b/crm/pengine/pe_utils.h @@ -1,128 +1,126 @@ -/* $Id: pe_utils.h,v 1.15 2004/11/09 09:32:14 andrew Exp $ */ +/* $Id: pe_utils.h,v 1.16 2004/11/09 14:49:14 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 PE_UTILS__H #define PE_UTILS__H /* General utilities */ extern resource_t *pe_find_resource(GListPtr rsc_list, const char *id_rh); extern action_t *action_new( resource_t *rsc, enum action_tasks task, node_t *on_node); /* Constraint helper functions */ extern rsc_dependancy_t *invert_constraint(rsc_dependancy_t *constraint); extern rsc_to_node_t *copy_constraint(rsc_to_node_t *constraint); /* Color helper functions */ extern void add_color_to_rsc(resource_t *rsc, color_t *color); extern color_t *find_color(GListPtr candidate_colors, color_t *other_color); extern color_t *create_color( GListPtr *colors, resource_t *resource, GListPtr resources); extern color_t *copy_color(color_t *a_color); /* Node helper functions */ -extern gboolean filter_nodes(resource_t *rsc); - extern node_t *pe_find_node(GListPtr node_list, const char *uname); extern node_t *pe_find_node_id(GListPtr node_list, const char *id); extern node_t *node_copy(node_t *this_node) ; /* Binary like operators for lists of nodes */ extern GListPtr node_list_dup(GListPtr list1, gboolean filter); extern GListPtr node_list_and(GListPtr list1, GListPtr list2, gboolean filter); extern GListPtr node_list_xor(GListPtr list1, GListPtr list2, gboolean filter); extern GListPtr node_list_minus(GListPtr list1,GListPtr list2,gboolean filter); extern gboolean node_list_eq(GListPtr list1, GListPtr list2, gboolean filter); extern GListPtr node_list_or(GListPtr list1, GListPtr list2, gboolean filter); /* For creating the transition graph */ extern xmlNodePtr action2xml(action_t *action, gboolean as_input); /* Printing functions for debug */ extern void print_node( const char *pre_text, node_t *node, gboolean details); extern void print_resource( const char *pre_text, resource_t *rsc, gboolean details); extern void print_rsc_to_node( const char *pre_text, rsc_to_node_t *cons, gboolean details); extern void print_rsc_dependancy( const char *pre_text, rsc_dependancy_t *cons, gboolean details); extern void print_color( const char *pre_text, color_t *color, gboolean details); extern void print_color_details( const char *pre_text, struct color_shared_s *color, gboolean details); extern void print_action( const char *pre_text, action_t *action, gboolean details); /* Sorting functions */ extern gint sort_rsc_priority(gconstpointer a, gconstpointer b); extern gint sort_cons_strength(gconstpointer a, gconstpointer b); extern gint sort_color_weight(gconstpointer a, gconstpointer b); extern gint sort_node_weight(gconstpointer a, gconstpointer b); /* enum 2 text functions (mostly used by print_*) */ extern const char *contype2text(enum con_type type); extern const char *strength2text(enum con_strength strength); /*extern const char *modifier2text(enum con_modifier modifier); */ extern const char *task2text(enum action_tasks task); -extern GListPtr find_actions_type( +extern GListPtr find_actions( GListPtr input, enum action_tasks task, node_t *on_node); /* free the various structures */ extern void pe_free_nodes(GListPtr nodes); extern void pe_free_colors(GListPtr colors); extern void pe_free_rsc_dependancy(rsc_dependancy_t *cons); extern void pe_free_rsc_to_node(rsc_to_node_t *cons); extern void pe_free_shallow(GListPtr alist); extern void pe_free_shallow_adv(GListPtr alist, gboolean with_data); extern void pe_free_resources(GListPtr resources); extern void pe_free_actions(GListPtr actions); /* Helper macros to avoid NULL pointers */ #define safe_val(def, x,y) (x?x->y:def) #define safe_val3(def, t,u,v) (t?t->u?t->u->v:def:def) #define safe_val4(def, t,u,v,w) (t?t->u?t->u->v?t->u->v->w:def:def:def) #define safe_val5(def, t,u,v,w,x) (t?t->u?t->u->v?t->u->v->w?t->u->v->w->x:def:def:def:def) #define safe_val6(def, t,u,v,w,x,y) (t?t->u?t->u->v?t->u->v->w?t->u->v->w->x?t->u->v->w->x->y:def:def:def:def:def) #define safe_val7(def, t,u,v,w,x,y,z) (t?t->u?t->u->v?t->u->v->w?t->u->v->w->x?t->u->v->w->x->y?t->u->v->w->x->y->z:def:def:def:def:def:def) #endif diff --git a/crm/pengine/pengine.h b/crm/pengine/pengine.h index ecbd5d9c8f..40d7d437ab 100644 --- a/crm/pengine/pengine.h +++ b/crm/pengine/pengine.h @@ -1,334 +1,329 @@ -/* $Id: pengine.h,v 1.39 2004/11/09 09:32:14 andrew Exp $ */ +/* $Id: pengine.h,v 1.40 2004/11/09 14:49:14 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_dependancy_s rsc_dependancy_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 enum con_type { type_none, rsc_dependancy, 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, stop_rsc, start_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_recover, pe_restart_ignore }; struct node_shared_s { const char *id; const char *uname; gboolean online; gboolean unclean; gboolean shutdown; 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; }; struct color_s { int id; struct color_shared_s *details; float local_weight; }; struct rsc_dependancy_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; float weight; GListPtr node_list_rh; /* node_t* */ /* enum con_modifier modifier; */ gboolean can; }; struct lrm_agent_s { const char *class; const char *type; const char *version; }; struct resource_s { const char *id; xmlNodePtr xml; void *variant_opaque; enum pe_obj_types variant; resource_object_functions_t *fns; float priority; float effective_priority; const char *timeout; - lrm_agent_t *agent; gboolean is_stonith; gboolean runnable; gboolean provisional; enum rsc_recovery_type recovery_type; enum pe_stop_fail stopfail_type; enum pe_restart restart_type; GListPtr candidate_colors; /* color_t* */ - GListPtr allowed_nodes; /* node_t* */ - GListPtr actions; /* action_t* */ + GListPtr rsc_cons; /* rsc_dependancy_t* */ + GListPtr actions; /* action_t* */ /* (soon to be) variant specific */ int max_instances; int max_node_instances; int max_masters; int max_node_masters; - GListPtr node_cons; /* rsc_to_node_t* */ - GListPtr rsc_cons; /* rsc_dependancy_t* */ - GListPtr running_on; /* node_t* */ - color_t *color; }; 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; enum action_tasks task; gboolean runnable; gboolean dumped; gboolean processed; gboolean optional; gboolean discard; gboolean failure_is_fatal; int seen_count; const char *timeout; xmlNodePtr args; GListPtr actions_before; /* action_warpper_t* */ GListPtr actions_after; /* action_warpper_t* */ /* (soon to be) variant specific */ int incarnation; }; struct order_constraint_s { int id; enum con_strength strength; void *lh_opaque; resource_t *lh_rsc; action_t *lh_action; enum action_tasks lh_action_task; void *rh_opaque; resource_t *rh_rsc; action_t *rh_action; enum action_tasks rh_action_task; /* (soon to be) variant specific */ /* int lh_rsc_incarnation; */ /* int rh_rsc_incarnation; */ }; extern gboolean stage0(xmlNodePtr 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, xmlNodePtr *graph); extern gboolean summary(GListPtr resources); extern gboolean pe_msg_dispatch(IPC_Channel *sender, void *user_data); extern gboolean process_pe_message(xmlNodePtr msg, IPC_Channel *sender); extern gboolean unpack_constraints(xmlNodePtr xml_constraints, GListPtr nodes, GListPtr resources, GListPtr *placement_constraints, GListPtr *ordering_constraints); extern gboolean unpack_resources(xmlNodePtr xml_resources, GListPtr *resources, GListPtr *actions, GListPtr *ordering_constraints, GListPtr all_nodes); extern gboolean unpack_config(xmlNodePtr config); extern gboolean unpack_config(xmlNodePtr config); extern gboolean unpack_global_defaults(xmlNodePtr defaults); extern gboolean unpack_nodes(xmlNodePtr xml_nodes, GListPtr *nodes); extern gboolean unpack_status(xmlNodePtr 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 order_new( resource_t *lh_rsc, enum action_tasks lh_task, action_t *lh_action, resource_t *rh_rsc, enum action_tasks rh_task, action_t *rh_action, enum con_strength strength, GListPtr *ordering_constraints); extern gboolean process_colored_constraints(resource_t *rsc); extern void graph_element_from_action(action_t *action, xmlNodePtr *graph); extern color_t *no_color; extern int max_valid_nodes; extern int order_id; extern int action_id; extern gboolean stonith_enabled; extern GListPtr agent_defaults; extern const char* transition_timeout; #endif diff --git a/crm/pengine/stages.c b/crm/pengine/stages.c index d95e22c65f..2ed7d6f59b 100644 --- a/crm/pengine/stages.c +++ b/crm/pengine/stages.c @@ -1,465 +1,467 @@ -/* $Id: stages.c,v 1.26 2004/11/09 11:18:00 andrew Exp $ */ +/* $Id: stages.c,v 1.27 2004/11/09 14:49:14 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 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); /* * 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(xmlNodePtr cib, GListPtr *resources, GListPtr *nodes, GListPtr *placement_constraints, GListPtr *actions, GListPtr *ordering_constraints, GListPtr *stonith_list, GListPtr *shutdown_list) { /* int lpc; */ xmlNodePtr cib_nodes = get_object_root( XML_CIB_TAG_NODES, cib); xmlNodePtr cib_status = get_object_root( XML_CIB_TAG_STATUS, cib); xmlNodePtr cib_resources = get_object_root( XML_CIB_TAG_RESOURCES, cib); xmlNodePtr cib_constraints = get_object_root( XML_CIB_TAG_CONSTRAINTS, cib); xmlNodePtr config = get_object_root( XML_CIB_TAG_CRMCONFIG, cib); xmlNodePtr agent_defaults = NULL; /*get_object_root(XML_CIB_TAG_RA_DEFAULTS, cib); */ /* reset remaining global variables */ max_valid_nodes = 0; order_id = 1; action_id = 1; unpack_config(config); unpack_global_defaults(agent_defaults); unpack_nodes(cib_nodes, nodes); unpack_resources(cib_resources, resources, actions, ordering_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) { int lpc = 0; crm_info("Processing stage 1"); 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) { int lpc; crm_info("Processing stage 2"); if(no_color != NULL) { crm_free(no_color->details); crm_free(no_color); } crm_trace("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) { crm_info("Processing stage 3"); /* not sure if this is a good idea or not */ if(g_list_length(colors) > max_valid_nodes) { /* we need to consolidate some */ } else if(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) { + int lpc = 0, lpc2 = 0; crm_info("Processing stage 4"); slist_iter( color, color_t, colors, lpc, crm_debug("assigning node to color %d", color->id); if(color == NULL) { crm_err("NULL color detected"); continue; } else if(color->details->pending == FALSE) { continue; } choose_node_from_list(color); crm_debug("assigned %s to color %d", safe_val5(NULL, color, details, chosen_node, details, uname), color->id); slist_iter( rsc, resource_t, color->details->allocated_resources, lpc2, slist_iter( constraint, rsc_dependancy_t, rsc->rsc_cons, lpc, rsc->fns->rsc_dependancy_lh(constraint); ); ); ); + crm_verbose("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) { int lpc; slist_iter( rsc, resource_t, resources, lpc, rsc->fns->create_actions(rsc); - rsc->fns->internal_ordering(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) { int lpc = 0; action_t *down_op = NULL; action_t *stonith_op = NULL; crm_info("Processing stage 6"); slist_iter( node, node_t, nodes, lpc, if(node->details->shutdown) { crm_warn("Scheduling Node %s for shutdown", node->details->uname); down_op = action_new(NULL, shutdown_crm, 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) { crm_warn("Scheduling Node %s for STONITH", node->details->uname); stonith_op = action_new(NULL, stonith_node, NULL); stonith_op->runnable = TRUE; set_xml_property_copy(stonith_op->args, "target", node->details->uname); if(down_op != NULL) { down_op->failure_is_fatal = FALSE; } *actions = g_list_append(*actions, stonith_op); 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) { int lpc; crm_info("Processing stage 7"); 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(actions); return TRUE; } /* * Create a dependancy graph to send to the transitioner (via the CRMd) */ gboolean stage8(GListPtr resources, GListPtr actions, xmlNodePtr *graph) { int lpc = 0; crm_info("Processing stage 8"); *graph = create_xml_node(NULL, "transition_graph"); set_xml_property_copy( *graph, "global_timeout", transition_timeout); /* errors... slist_iter(action, action_t, action_list, lpc, if(action->optional == FALSE && action->runnable == FALSE) { print_action("Ignoring", action, TRUE); } ); */ slist_iter( rsc, resource_t, resources, lpc, crm_debug("processing actions for rsc=%s", rsc->id); rsc->fns->expand(rsc, graph); ); crm_xml_devel(*graph, "created resource-driven action list"); /* catch any non-resource specific actions */ slist_iter( action, action_t, actions, lpc, graph_element_from_action(action, graph); ); crm_xml_devel(*graph, "created generic action list"); return TRUE; } /* * Print a nice human readable high-level summary of what we're going to do */ gboolean summary(GListPtr resources) { #if 0 int lpc = 0; const char *rsc_id = NULL; const char *node_id = NULL; const char *new_node_id = NULL; slist_iter( rsc, resource_t, resources, lpc, rsc_id = safe_val(NULL, rsc, id); node_id = safe_val4(NULL, rsc, cur_node, details, uname); new_node_id = safe_val6( NULL, rsc, color, details, chosen_node, details, uname); if(rsc->runnable == FALSE) { crm_err("Resource %s was not runnable", rsc_id); if(node_id != NULL) { crm_warn("Stopping Resource (%s) on node %s", rsc_id, node_id); } } else if(safe_val4(NULL, rsc, color, details, chosen_node) == NULL) { crm_err("Could not allocate Resource %s", rsc_id); crm_debug_action( print_resource("Could not allocate",rsc,TRUE)); if(node_id != NULL) { crm_warn("Stopping Resource (%s) on node %s", rsc_id, node_id); } } else if(safe_str_eq(node_id, new_node_id)){ crm_debug("No change for Resource %s (%s)", rsc_id, safe_val4(NULL, rsc, cur_node, details, uname)); } else if(node_id == NULL) { crm_info("Starting Resource %s on %s", rsc_id, new_node_id); } else { crm_info("Moving Resource %s from %s to %s", rsc_id, node_id, new_node_id); } ); #endif return TRUE; } gboolean choose_node_from_list(color_t *color) { /* 1. Sort by weight 2. color.chosen_node = highest wieghted node 3. remove color.chosen_node from all other colors */ GListPtr nodes = color->details->candidate_nodes; nodes = g_list_sort(nodes, sort_node_weight); color->details->chosen_node = node_copy((node_t*)g_list_nth_data(nodes, 0)); color->details->pending = FALSE; if(color->details->chosen_node == NULL) { crm_err("Could not allocate a node for color %d", color->id); return FALSE; } return TRUE; } diff --git a/crm/pengine/testcases/nodefail1.exp b/crm/pengine/testcases/nodefail1.exp index 4ba02403ae..27930a048f 100644 --- a/crm/pengine/testcases/nodefail1.exp +++ b/crm/pengine/testcases/nodefail1.exp @@ -1,42 +1,26 @@ - - - - - - - - - - + - - - - - - - - + diff --git a/crm/pengine/testcases/nodefail4.exp b/crm/pengine/testcases/nodefail4.exp index f589b248e8..e3bd69d14c 100644 --- a/crm/pengine/testcases/nodefail4.exp +++ b/crm/pengine/testcases/nodefail4.exp @@ -1,35 +1,22 @@ - - - - - - - - - - - - - - + diff --git a/crm/pengine/unpack.c b/crm/pengine/unpack.c index 8bf152ee99..f9a94efed2 100644 --- a/crm/pengine/unpack.c +++ b/crm/pengine/unpack.c @@ -1,1233 +1,1221 @@ -/* $Id: unpack.c,v 1.42 2004/11/09 11:18:00 andrew Exp $ */ +/* $Id: unpack.c,v 1.43 2004/11/09 14:49:14 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 /* for ONLINESTATUS */ #include #include int max_valid_nodes = 0; int order_id = 1; GListPtr agent_defaults = NULL; gboolean stonith_enabled = FALSE; const char* transition_timeout = "60000"; /* 1 minute */ GListPtr match_attrs(const char *attr, const char *op, const char *value, const char *type, GListPtr node_list); gboolean unpack_rsc_to_attr(xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr node_list, GListPtr *placement_constraints); gboolean unpack_rsc_to_node(xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr node_list, GListPtr *placement_constraints); gboolean unpack_rsc_order( xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr *ordering_constraints); gboolean unpack_rsc_dependancy( xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr *ordering_constraints); gboolean unpack_rsc_location( xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr node_list, GListPtr *ordering_constraints); gboolean unpack_lrm_rsc_state( node_t *node, xmlNodePtr lrm_state, GListPtr rsc_list, GListPtr nodes, GListPtr *actions, GListPtr *placement_constraints); gboolean add_node_attrs(xmlNodePtr attrs, node_t *node); gboolean unpack_healthy_resource(GListPtr *placement_constraints, GListPtr *actions, xmlNodePtr rsc_entry, resource_t *rsc_lh, node_t *node); -gboolean unpack_failed_resource(GListPtr *placement_constraints, GListPtr *actions, +gboolean unpack_failed_resource(GListPtr *placement_constraints, xmlNodePtr rsc_entry, resource_t *rsc_lh, node_t *node); gboolean determine_online_status(xmlNodePtr node_state, node_t *this_node); gboolean unpack_lrm_agents(node_t *node, xmlNodePtr agent_list); gboolean is_node_unclean(xmlNodePtr node_state); gboolean rsc_dependancy_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 *get_agent_param(resource_t *rsc, const char *param); const char *get_agent_param_rsc(resource_t *rsc, const char *param); const void *get_agent_param_metadata(resource_t *rsc, const char *param); const char *get_agent_param_global(resource_t *rsc, const char *param); const char *param_value(xmlNodePtr parent, const char *name); gboolean unpack_config(xmlNodePtr config) { const char *value = NULL; value = param_value(config, "failed_nodes"); if(safe_str_eq(value, "stonith")) { crm_debug("Enabling STONITH of failed nodes"); stonith_enabled = TRUE; } else { stonith_enabled = FALSE; } value = param_value(config, "transition_timeout"); if(value != NULL) { int tmp = atoi(value); if(tmp > 0) { transition_timeout = value; } else { crm_warn("Invalid value for %s: %s", "transition_timeout", value); } } crm_info("%s set to: %s", "transition_timeout", transition_timeout); return TRUE; } const char * param_value(xmlNodePtr parent, const char *name) { xmlNodePtr a_default = find_entity( parent, XML_CIB_TAG_NVPAIR, name, FALSE); return xmlGetProp(a_default, XML_NVPAIR_ATTR_VALUE); } const char * get_agent_param(resource_t *rsc, const char *param) { const char *value = NULL; if(param == NULL) { return NULL; } value = get_agent_param_rsc(rsc, param); if(value == NULL) { value = get_agent_param_metadata(rsc, param); } if(value == NULL) { value = get_agent_param_global(rsc, param); } return value; } const char * get_agent_param_rsc(resource_t *rsc, const char *param) { xmlNodePtr xml_rsc = rsc->xml; return xmlGetProp(xml_rsc, param); } const void * get_agent_param_metadata(resource_t *rsc, const char *param) { return NULL; } const char * get_agent_param_global(resource_t *rsc, const char *param) { const char * value = NULL;/*g_hashtable_lookup(agent_global_defaults, param); */ if(value == NULL) { crm_err("No global value default for %s", param); } return value; } gboolean unpack_global_defaults(xmlNodePtr defaults) { return TRUE; } gboolean unpack_nodes(xmlNodePtr xml_nodes, GListPtr *nodes) { node_t *new_node = NULL; xmlNodePtr attrs = NULL; const char *id = NULL; const char *uname = NULL; const char *type = NULL; crm_verbose("Begining unpack..."); xml_child_iter( xml_nodes, xml_obj, XML_CIB_TAG_NODE, attrs = xml_obj->children; id = xmlGetProp(xml_obj, XML_ATTR_ID); uname = xmlGetProp(xml_obj, XML_ATTR_UNAME); type = xmlGetProp(xml_obj, XML_ATTR_TYPE); crm_verbose("Processing node %s/%s", uname, id); if(attrs != NULL) { attrs = attrs->children; } if(id == NULL) { crm_err("Must specify id tag in "); continue; } if(type == NULL) { crm_err("Must specify type tag in "); continue; } crm_malloc(new_node, sizeof(node_t)); if(new_node == NULL) { return FALSE; } new_node->weight = 1.0; new_node->fixed = FALSE; crm_malloc(new_node->details, sizeof(struct node_shared_s)); if(new_node->details == NULL) { crm_free(new_node); return FALSE; } crm_verbose("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->unclean = 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); if(safe_str_eq(type, "member")) { new_node->details->type = node_member; } add_node_attrs(attrs, new_node); *nodes = g_list_append(*nodes, new_node); crm_verbose("Done with node %s", xmlGetProp(xml_obj, "uname")); crm_debug_action(print_node("Added", new_node, FALSE)); ); *nodes = g_list_sort(*nodes, sort_node_weight); return TRUE; } gboolean unpack_resources(xmlNodePtr xml_resources, GListPtr *resources, GListPtr *actions, GListPtr *ordering_constraints, GListPtr all_nodes) { crm_verbose("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_debug_action( print_resource("Added", new_rsc, FALSE)); } else { crm_err("Failed unpacking resource %s", xmlGetProp(xml_obj, XML_ATTR_ID)); } ); *resources = g_list_sort(*resources, sort_rsc_priority); return TRUE; } gboolean unpack_constraints(xmlNodePtr xml_constraints, GListPtr nodes, GListPtr resources, GListPtr *placement_constraints, GListPtr *ordering_constraints) { crm_verbose("Begining unpack..."); xml_child_iter( xml_constraints, xml_obj, NULL, const char *id = xmlGetProp(xml_obj, XML_ATTR_ID); if(id == NULL) { crm_err("Constraint <%s...> must have an id", xml_obj->name); continue; } crm_verbose("Processing constraint %s %s", xml_obj->name,id); if(safe_str_eq("rsc_order", xml_obj->name)) { unpack_rsc_order( xml_obj, resources, ordering_constraints); } else if(safe_str_eq("rsc_dependancy", xml_obj->name)) { unpack_rsc_dependancy( xml_obj, resources, ordering_constraints); } else if(safe_str_eq("rsc_location", xml_obj->name)) { unpack_rsc_location( xml_obj, resources, nodes, placement_constraints); } else { crm_err("Unsupported constraint type: %s", xml_obj->name); } ); 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) { crm_err("Invalid constraint %s for rsc=%p", crm_str(id), rsc); return NULL; } crm_malloc(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->can = can; if(can) { new_con->weight = weight; } else { new_con->weight = -1; } 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(xmlNodePtr status, GListPtr nodes, GListPtr rsc_list, GListPtr *actions, GListPtr *placement_constraints) { const char *uname = NULL; xmlNodePtr lrm_rsc = NULL; xmlNodePtr lrm_agents = NULL; xmlNodePtr attrs = NULL; node_t *this_node = NULL; crm_verbose("Begining unpack"); xml_child_iter( status, node_state, XML_CIB_TAG_STATE, /* id = xmlGetProp(node_state, XML_ATTR_ID); */ uname = xmlGetProp(node_state, XML_ATTR_UNAME); attrs = find_xml_node(node_state, "attributes"); lrm_rsc = find_xml_node(node_state, XML_CIB_TAG_LRM); lrm_agents = find_xml_node(lrm_rsc, "lrm_agents"); lrm_rsc = find_xml_node(lrm_rsc, XML_LRM_TAG_RESOURCES); lrm_rsc = find_xml_node(lrm_rsc, "lrm_resource"); crm_verbose("Processing node %s", uname); this_node = pe_find_node(nodes, uname); if(uname == NULL) { /* error */ continue; } else if(this_node == NULL) { crm_err("Node %s in status section no longer exists", uname); continue; } crm_verbose("Adding runtime node attrs"); add_node_attrs(attrs, this_node); crm_verbose("determining node state"); determine_online_status(node_state, this_node); crm_verbose("Processing lrm resource entries"); unpack_lrm_rsc_state(this_node, lrm_rsc, rsc_list, nodes, actions, placement_constraints); crm_verbose("Processing lrm agents"); unpack_lrm_agents(this_node, lrm_agents); ); return TRUE; } gboolean determine_online_status(xmlNodePtr node_state, node_t *this_node) { gboolean online = FALSE; const char *uname = xmlGetProp(node_state,XML_ATTR_UNAME); /* const char *state = xmlGetProp(node_state,XML_NODE_ATTR_STATE); */ const char *exp_state = xmlGetProp(node_state,XML_CIB_ATTR_EXPSTATE); const char *join_state = xmlGetProp(node_state,XML_CIB_ATTR_JOINSTATE); const char *crm_state = xmlGetProp(node_state,XML_CIB_ATTR_CRMDSTATE); const char *ccm_state = xmlGetProp(node_state,XML_CIB_ATTR_INCCM); const char *ha_state = xmlGetProp(node_state,XML_CIB_ATTR_HASTATE); const char *shutdown = xmlGetProp(node_state,XML_CIB_ATTR_SHUTDOWN); const char *unclean = NULL;/*xmlGetProp(node_state,XML_CIB_ATTR_STONITH); */ if(safe_str_eq(join_state, CRMD_JOINSTATE_MEMBER) && safe_str_eq(ccm_state, XML_BOOLEAN_YES) && (ha_state == NULL || safe_str_eq(ha_state, ACTIVESTATUS)) && safe_str_eq(crm_state, ONLINESTATUS) && shutdown == NULL) { if(this_node != NULL) { this_node->details->online = TRUE; } crm_debug("Node %s is online", uname); online = TRUE; } else if(this_node != NULL) { /* remove node from contention */ this_node->weight = -1; this_node->fixed = TRUE; crm_verbose("join_state=%s, expected=%s, shutdown=%s", crm_str(join_state), crm_str(exp_state), crm_str(shutdown)); if(unclean != NULL) { this_node->details->unclean = TRUE; } else if(is_node_unclean(node_state)) { /* report and or take remedial action */ this_node->details->unclean = TRUE; } if(shutdown != NULL) { this_node->details->shutdown = TRUE; } if(this_node->details->unclean) { crm_warn("Node %s is due for STONITH", uname); } if(this_node->details->shutdown) { crm_info("Node %s is due for shutdown", uname); } } return online; } gboolean is_node_unclean(xmlNodePtr node_state) { /* const char *state = xmlGetProp(node_state,XML_NODE_ATTR_STATE); */ const char *uname = xmlGetProp(node_state,XML_ATTR_UNAME); const char *exp_state = xmlGetProp(node_state,XML_CIB_ATTR_EXPSTATE); const char *join_state = xmlGetProp(node_state,XML_CIB_ATTR_JOINSTATE); const char *crm_state = xmlGetProp(node_state,XML_CIB_ATTR_CRMDSTATE); const char *ha_state = xmlGetProp(node_state,XML_CIB_ATTR_HASTATE); const char *ccm_state = xmlGetProp(node_state,XML_CIB_ATTR_INCCM); if(safe_str_eq(exp_state, CRMD_STATE_INACTIVE)) { crm_debug("Node %s is safely inactive", uname); return FALSE; /* do an actual calculation once STONITH is available */ } else if(safe_str_neq(exp_state, CRMD_JOINSTATE_DOWN)) { if(safe_str_eq(crm_state, OFFLINESTATUS) || (ha_state != NULL && safe_str_eq(ha_state, DEADSTATUS)) || safe_str_eq(join_state, CRMD_JOINSTATE_DOWN) || safe_str_eq(ccm_state, XML_BOOLEAN_NO)) { crm_warn("Node %s is un-expectedly down", uname); return TRUE; } crm_debug("Node %s: ha=%s, join=%s, crm=%s, ccm=%s", uname, ha_state, join_state, crm_state, ccm_state); } else { crm_debug("Node %s was expected to be down", uname); } return FALSE; } gboolean unpack_lrm_agents(node_t *node, xmlNodePtr 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_malloc(agent, sizeof(lrm_agent_t)); if(agent == NULL) { continue; } agent->class = xmlGetProp(xml_agent, "class"); agent->type = xmlGetProp(xml_agent, "type"); version = xmlGetProp(xml_agent, "version"); agent->version = version?version:"0.0"; crm_trace("Adding agent %s/%s v%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, xmlNodePtr lrm_rsc, GListPtr rsc_list, GListPtr nodes, GListPtr *actions, GListPtr *placement_constraints) { xmlNodePtr rsc_entry = NULL; const char *rsc_id = NULL; const char *node_id = NULL; const char *rsc_state = NULL; const char *op_status = NULL; const char *last_rc = NULL; const char *last_op = NULL; resource_t *rsc_lh = NULL; op_status_t action_status_i = LRM_OP_ERROR; while(lrm_rsc != NULL) { rsc_entry = lrm_rsc; lrm_rsc = lrm_rsc->next; rsc_id = xmlGetProp(rsc_entry, XML_ATTR_ID); node_id = xmlGetProp(rsc_entry, XML_LRM_ATTR_TARGET); rsc_state = xmlGetProp(rsc_entry, XML_LRM_ATTR_RSCSTATE); op_status = xmlGetProp(rsc_entry, XML_LRM_ATTR_OPSTATUS); last_rc = xmlGetProp(rsc_entry, XML_LRM_ATTR_RC); last_op = xmlGetProp(rsc_entry, XML_LRM_ATTR_LASTOP); rsc_lh = pe_find_resource(rsc_list, rsc_id); crm_verbose("[%s] Processing %s on %s (%s)", rsc_entry->name, rsc_id, node_id, rsc_state); if(rsc_lh == NULL) { crm_err("Could not find a match for resource" " %s in %s's status section", rsc_id, node_id); continue; } else if(op_status == NULL) { crm_err("Invalid resource status entry for %s in %s", rsc_id, node_id); continue; } action_status_i = atoi(op_status); if(node->details->unclean) { crm_info("Node %s (where %s is running) is unclean." "Further action depends on the value of on_stopfail", node->details->uname, rsc_lh->id); /* map the status to an error and then handle as a * failed resource. */ action_status_i = LRM_OP_ERROR; } else if(action_status_i == -1) { /* * 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(last_op, "stop")) { /* map this to a timeout so it is re-issued */ action_status_i = LRM_OP_TIMEOUT; } else { /* map this to a "done" so it is not marked * as failed, then make sure it is re-issued */ action_new(rsc_lh, start_rsc, NULL); action_status_i = LRM_OP_DONE; } } switch(action_status_i) { case LRM_OP_DONE: unpack_healthy_resource( placement_constraints, actions, rsc_entry, rsc_lh,node); break; case LRM_OP_ERROR: case LRM_OP_TIMEOUT: case LRM_OP_NOTSUPPORTED: - unpack_failed_resource( - placement_constraints, actions, - rsc_entry, rsc_lh,node); + unpack_failed_resource(placement_constraints, + rsc_entry, rsc_lh,node); break; case LRM_OP_CANCELLED: /* do nothing?? */ crm_warn("Dont know what to do for cancelled ops yet"); break; } } return TRUE; } gboolean -unpack_failed_resource(GListPtr *placement_constraints, GListPtr *actions, +unpack_failed_resource(GListPtr *placement_constraints, xmlNodePtr rsc_entry, resource_t *rsc_lh, node_t *node) { const char *last_op = xmlGetProp(rsc_entry, "last_op"); crm_debug("Unpacking failed action %s on %s", last_op, rsc_lh->id); /* make sure we dont allocate the resource here again*/ rsc2node_new("dont_run__generated", rsc_lh, -1.0, FALSE, node, placement_constraints); if(safe_str_eq(last_op, "start")) { /* the resource is not actually running... nothing more to do*/ return TRUE; } switch(rsc_lh->stopfail_type) { case pesf_stonith: /* treat it as if it is still running * but also mark the node as unclean */ - rsc_lh->running_on = g_list_append( - rsc_lh->running_on, node); + native_add_running(rsc_lh, node); node->details->running_rsc = g_list_append( node->details->running_rsc, rsc_lh); if(node->details->online) { node->details->shutdown = TRUE; } node->details->unclean = TRUE; break; case pesf_block: /* let this depend on the stop action which will fail * but make sure the transition continues... */ - rsc_lh->running_on = g_list_append( - rsc_lh->running_on, node); + native_add_running(rsc_lh, node); node->details->running_rsc = g_list_append( node->details->running_rsc, rsc_lh); /* rsc_lh->stop->timeout = NULL; /\* wait forever *\/ */ break; case pesf_ignore: /* pretend nothing happened */ break; } return TRUE; } gboolean unpack_healthy_resource(GListPtr *placement_constraints, GListPtr *actions, xmlNodePtr rsc_entry, resource_t *rsc_lh, node_t *node) { const char *last_op = xmlGetProp(rsc_entry, "last_op"); crm_debug("Unpacking healthy action %s on %s", last_op, rsc_lh->id); if(safe_str_neq(last_op, "stop")) { /* create the link between this node and the rsc */ crm_verbose("Setting cur_node = %s for rsc = %s", node->details->uname, rsc_lh->id); - - rsc_lh->running_on = g_list_append( - rsc_lh->running_on, node); - if(g_list_length(rsc_lh->running_on) > 1) { - crm_warn("Resource %s active on %d nodes. Latest: %s (%s)", - rsc_lh->id, g_list_length(rsc_lh->running_on), - node->details->id, last_op); - -/* action_new(rsc_lh, stop_rsc, node); */ - } + native_add_running(rsc_lh, node); node->details->running_rsc = g_list_append( node->details->running_rsc, rsc_lh); } return TRUE; } gboolean rsc_dependancy_new(const char *id, enum con_strength strength, resource_t *rsc_lh, resource_t *rsc_rh) { rsc_dependancy_t *new_con = NULL; - rsc_dependancy_t *inverted_con = NULL; + rsc_dependancy_t *inverted_con = NULL; if(rsc_lh == NULL || rsc_rh == NULL){ /* error */ return FALSE; } crm_malloc(new_con, sizeof(rsc_dependancy_t)); if(new_con != NULL) { 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); rsc_lh->rsc_cons = g_list_insert_sorted( rsc_lh->rsc_cons, new_con, sort_cons_strength); rsc_rh->rsc_cons = g_list_insert_sorted( rsc_rh->rsc_cons, inverted_con, sort_cons_strength); } else { return FALSE; } return TRUE; } gboolean order_new(resource_t *lh_rsc, enum action_tasks lh_action_task, action_t *lh_action, resource_t *rh_rsc, enum action_tasks 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){ crm_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_malloc(order, sizeof(order_constraint_t)); if(order != NULL) { 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("Created ordering constraint %d (%s):" " %s/%s before %s/%s", order->id, strength2text(order->strength), lh_rsc->id, task2text(lh_action_task), rh_rsc->id, task2text(rh_action_task)); } else if(lh_rsc != NULL) { crm_debug("Created ordering constraint %d (%s):" " %s/%s before action %d (%s)", order->id, strength2text(order->strength), lh_rsc->id, task2text(lh_action_task), rh_action->id, task2text(rh_action_task)); } else if(rh_rsc != NULL) { crm_debug("Created ordering constraint %d (%s):" " action %d (%s) before %s/%s", order->id, strength2text(order->strength), lh_action->id, task2text(lh_action_task), rh_rsc->id, task2text(rh_action_task)); } else { crm_debug("Created ordering constraint %d (%s):" " action %d (%s) before action %d (%s)", order->id, strength2text(order->strength), lh_action->id, task2text(lh_action_task), rh_action->id, task2text(rh_action_task)); } } return TRUE; } gboolean unpack_rsc_dependancy(xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr *ordering_constraints) { enum con_strength strength_e = pecs_ignore; const char *id_lh = xmlGetProp(xml_obj, "from"); const char *id = xmlGetProp(xml_obj, XML_ATTR_ID); const char *id_rh = xmlGetProp(xml_obj, "to"); const char *type = xmlGetProp(xml_obj, XML_ATTR_TYPE); 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) { crm_err("No resource (con=%s, rsc=%s)", id, id_lh); return FALSE; } else if(rsc_rh == NULL) { crm_err("No resource (con=%s, rsc=%s)", id, id_rh); return FALSE; } if(safe_str_eq(type, XML_STRENGTH_VAL_MUST)) { strength_e = pecs_must; } else if(safe_str_eq(type, XML_STRENGTH_VAL_SHOULD)) { crm_err("Type %s is no longer supported", type); strength_e = pecs_must; } else if(safe_str_eq(type, XML_STRENGTH_VAL_SHOULDNOT)) { crm_err("Type %s is no longer supported", type); strength_e = pecs_must_not; } else if(safe_str_eq(type, XML_STRENGTH_VAL_MUSTNOT)) { strength_e = pecs_must_not; } else { crm_err("Unknown value for %s: %s", "type", type); return FALSE; } return rsc_dependancy_new(id, strength_e, rsc_lh, rsc_rh); } gboolean unpack_rsc_order(xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr *ordering_constraints) { const char *id = xmlGetProp(xml_obj, XML_ATTR_ID); const char *id_lh = xmlGetProp(xml_obj, "from"); const char *id_rh = xmlGetProp(xml_obj, "to"); const char *type = xmlGetProp(xml_obj, XML_ATTR_TYPE); 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) { crm_err("No constraint object to process."); return FALSE; } else if(id == NULL) { crm_err("%s constraint must have an id", xml_obj->name); return FALSE; } else if(rsc_lh == NULL || rsc_rh == NULL) { crm_err("Constraint %s needs two sides lh: %p rh: %p" " (NULL indicates missing side)", id, rsc_lh, rsc_rh); return FALSE; } else if(safe_str_eq(type, "after")) { order_new(rsc_rh, stop_rsc, NULL, rsc_lh, stop_rsc, NULL, pecs_must, ordering_constraints); order_new(rsc_lh, start_rsc, NULL, rsc_rh, start_rsc, NULL, pecs_must, ordering_constraints); } else { order_new(rsc_lh, stop_rsc, NULL, rsc_rh, stop_rsc, NULL, pecs_must, ordering_constraints); order_new(rsc_rh, start_rsc, NULL, rsc_lh, start_rsc, NULL, pecs_must, ordering_constraints); } return TRUE; } /* do NOT free the nodes returned here */ GListPtr match_attrs(const char *attr, const char *op, const char *value, const char *type, GListPtr node_list) { int lpc = 0, lpc2 = 0; GListPtr result = NULL; if(attr == NULL || op == NULL) { crm_err("Invlaid attribute or operation in expression" " (\'%s\' \'%s\' \'%s\')", crm_str(attr), crm_str(op), crm_str(value)); return NULL; } slist_iter( node, node_t, node_list, lpc, gboolean accept = FALSE; int cmp = 0; const char *h_val = (const char*)g_hash_table_lookup( node->details->attrs, attr); if(value != NULL && h_val != NULL) { if(type == NULL || (safe_str_eq(type, "string"))) { cmp = strcmp(h_val, value); } else if(safe_str_eq(type, "number")) { float h_val_f = atof(h_val); float value_f = atof(value); if(h_val_f < value_f) { cmp = -1; } else if(h_val_f > value_f) { cmp = 1; } else { cmp = 0; } } else if(safe_str_eq(type, "version")) { cmp = compare_version(h_val, value); } } else if(value == NULL && h_val == NULL) { cmp = 0; } else if(value == NULL) { cmp = 1; } else { cmp = -1; } if(safe_str_eq(op, "exists")) { if(h_val != NULL) accept = TRUE; } else if(safe_str_eq(op, "notexists")) { if(h_val == NULL) accept = TRUE; } else if(safe_str_eq(op, "running")) { GListPtr rsc_list = node->details->running_rsc; slist_iter( rsc, resource_t, rsc_list, lpc2, if(safe_str_eq(rsc->id, attr)) { accept = TRUE; } ); } else if(safe_str_eq(op, "not_running")) { GListPtr rsc_list = node->details->running_rsc; accept = TRUE; slist_iter( rsc, resource_t, rsc_list, lpc2, if(safe_str_eq(rsc->id, attr)) { accept = FALSE; break; } ); } else if(safe_str_eq(op, "eq")) { if((h_val == value) || cmp == 0) accept = TRUE; } else if(safe_str_eq(op, "ne")) { if((h_val == NULL && value != NULL) || (h_val != NULL && value == NULL) || cmp != 0) accept = TRUE; } else if(value == NULL || h_val == NULL) { /* the comparision is meaningless from this point on */ accept = FALSE; } else if(safe_str_eq(op, "lt")) { if(cmp < 0) accept = TRUE; } else if(safe_str_eq(op, "lte")) { if(cmp <= 0) accept = TRUE; } else if(safe_str_eq(op, "gt")) { if(cmp > 0) accept = TRUE; } else if(safe_str_eq(op, "gte")) { if(cmp >= 0) accept = TRUE; } if(accept) { crm_trace("node %s matched", node->details->uname); result = g_list_append(result, node); } else { crm_trace("node %s did not match", node->details->uname); } ); return result; } gboolean add_node_attrs(xmlNodePtr attrs, node_t *node) { const char *name = NULL; const char *value = NULL; while(attrs != NULL){ name = xmlGetProp(attrs, XML_NVPAIR_ATTR_NAME); value = xmlGetProp(attrs, XML_NVPAIR_ATTR_VALUE); if(name != NULL && value != NULL && safe_val(NULL, node, details) != NULL) { crm_verbose("Adding %s => %s", name, value); /* this is frustrating... no way to pass in const * keys or values yet docs say: * Note: If keys and/or values are dynamically * allocated, you should free them first. */ g_hash_table_insert(node->details->attrs, crm_strdup(name), crm_strdup(value)); } attrs = attrs->next; } g_hash_table_insert(node->details->attrs, crm_strdup("uname"), crm_strdup(node->details->uname)); g_hash_table_insert(node->details->attrs, crm_strdup("id"), crm_strdup(node->details->id)); return TRUE; } gboolean unpack_rsc_location( xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr node_list, GListPtr *placement_constraints) { /* ... Translation: Further translation: */ gboolean were_rules = FALSE; const char *id_lh = xmlGetProp(xml_obj, "rsc"); const char *id = xmlGetProp(xml_obj, XML_ATTR_ID); resource_t *rsc_lh = pe_find_resource(rsc_list, id_lh); if(rsc_lh == NULL) { crm_err("No resource (con=%s, rsc=%s)", id, id_lh); return FALSE; } xml_child_iter( xml_obj, rule, "rule", gboolean first_expr = TRUE; gboolean can_run = FALSE; gboolean do_and = TRUE; gboolean rule_has_expressions; const char *rule_id = xmlGetProp(rule, XML_ATTR_ID); const char *score = xmlGetProp(rule, "score"); const char *result = xmlGetProp(rule, "result"); const char *boolean = xmlGetProp(rule, "boolean_op"); GListPtr match_L = NULL; GListPtr old_list = NULL; float score_f = atof(score?score:"0.0"); rsc_to_node_t *new_con = NULL; were_rules = TRUE; if(safe_str_eq(boolean, "or")) { do_and = FALSE; } if(result == NULL || (safe_str_eq(result, "can"))) { can_run = TRUE; } new_con = rsc2node_new(rule_id, rsc_lh, score_f, can_run, NULL, placement_constraints); if(new_con == NULL) { continue; } rule_has_expressions = FALSE; xml_child_iter( rule, expr, "expression", const char *attr = xmlGetProp(expr, "attribute"); const char *op = xmlGetProp(expr, "operation"); const char *value = xmlGetProp(expr, "value"); const char *type = xmlGetProp(expr, "type"); rule_has_expressions = TRUE; crm_trace("processing expression: %s", xmlGetProp(expr, "id")); match_L = match_attrs( 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_trace("do_and"); new_con->node_list_rh = node_list_and( old_list, match_L, FALSE); } else { crm_trace("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) { /* feels like a hack */ crm_debug("Rule %s had no expressions," " adding all nodes", xmlGetProp(rule, "id")); new_con->node_list_rh = node_list_dup(node_list,FALSE); } if(new_con->node_list_rh == NULL) { crm_warn("No matching nodes for constraint/rule %s/%s", id, xmlGetProp(rule, "id")); } crm_debug_action(print_rsc_to_node("Added", new_con, FALSE)); ); if(were_rules == FALSE) { crm_err("no rules for constraint %s", id); } return TRUE; } diff --git a/crm/pengine/utils.c b/crm/pengine/utils.c index 5664409cb8..5149bc0e3c 100644 --- a/crm/pengine/utils.c +++ b/crm/pengine/utils.c @@ -1,1086 +1,1059 @@ -/* $Id: utils.c,v 1.44 2004/11/09 09:32:14 andrew Exp $ */ +/* $Id: utils.c,v 1.45 2004/11/09 14:49:14 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; void print_str_str(gpointer key, gpointer value, gpointer user_data); gboolean ghash_free_str_str(gpointer key, gpointer value, gpointer user_data); gboolean node_merge_weights(node_t *node, node_t *with); /* only for rsc_dependancy constraints */ rsc_dependancy_t * invert_constraint(rsc_dependancy_t *constraint) { rsc_dependancy_t *inverted_con = NULL; crm_verbose("Inverting constraint"); if(constraint == NULL) { crm_err("Cannot invert NULL constraint"); return NULL; } crm_malloc(inverted_con, sizeof(rsc_dependancy_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_debug_action( print_rsc_dependancy("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) { int lpc; 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; int lpc = 0; for(lpc = 0; lpc < g_list_length(list1); lpc++) { node_t *node = (node_t*)g_list_nth_data(list1, lpc); node_t *new_node = node_copy(node); node_t *other_node = pe_find_node(list2, node->details->uname); if(node_merge_weights(new_node, other_node) == FALSE) { crm_free(new_node); } else if(filter && new_node->weight < 0) { crm_free(new_node); } else { result = g_list_append(result, new_node); } } return result; } gboolean node_merge_weights(node_t *node, node_t *with) { if(node == NULL || with == NULL) { return FALSE; } else if(node->weight < 0 || with->weight < 0) { node->weight = -1; } else if(node->weight < with->weight) { node->weight = with->weight; } return TRUE; } /* list1 - list2 */ GListPtr node_list_minus(GListPtr list1, GListPtr list2, gboolean filter) { GListPtr result = NULL; int lpc = 0; 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_verbose("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; int lpc = 0; 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_verbose("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; int lpc = 0; 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) { node_merge_weights(other_node, node); if(filter && node->weight < 0) { /* TODO: remove and free other_node */ } } else if(filter && node->weight < 0) { } else { node_t *new_node = node_copy(node); result = g_list_append(result, new_node); } ); return result; } GListPtr node_list_dup(GListPtr list1, gboolean filter) { GListPtr result = NULL; int lpc = 0; 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; if(this_node == NULL) { crm_err("Failed copy of node."); return NULL; } crm_malloc(new_node, sizeof(node_t)); if(new_node == NULL) { return NULL; } crm_trace("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; } static int color_id = 0; /* * 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 resources) +create_color(GListPtr *colors, resource_t *resource, GListPtr node_list) { color_t *new_color = NULL; crm_trace("Creating color"); crm_malloc(new_color, sizeof(color_t)); if(new_color == NULL) { return NULL; } new_color->id = color_id++; new_color->local_weight = 1.0; crm_trace("Creating color details"); crm_malloc(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_trace("populating node list"); new_color->details->highest_priority = resource->priority; new_color->details->candidate_nodes = - node_list_dup(resource->allowed_nodes, TRUE); + node_list_dup(node_list, TRUE); } crm_debug_action(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) { crm_err("Cannot copy NULL"); return NULL; } crm_malloc(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; } -/* - * Remove any nodes with a -ve weight - */ -gboolean -filter_nodes(resource_t *rsc) -{ - int lpc2 = 0; - crm_debug_action(print_resource("Filtering nodes for", rsc, FALSE)); - slist_iter( - node, node_t, rsc->allowed_nodes, lpc2, - if(node == NULL) { - crm_err("Invalid NULL node"); - - } else if(node->weight < 0.0 - || node->details->online == FALSE - || node->details->type == node_ping) { - crm_debug_action(print_node("Removing", node, FALSE)); - rsc->allowed_nodes = - g_list_remove(rsc->allowed_nodes,node); - crm_free(node); - lpc2 = -1; /* restart the loop */ - } - ); - - return TRUE; -} - resource_t * pe_find_resource(GListPtr rsc_list, const char *id_rh) { int lpc = 0; resource_t *rsc = NULL; 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_rh)){ return rsc; } } /* error */ return NULL; } node_t * pe_find_node(GListPtr nodes, const char *uname) { int 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) { int 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_trace("%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) 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_dependancy_t *rsc_constraint1 = (const rsc_dependancy_t*)a; const rsc_dependancy_t *rsc_constraint2 = (const rsc_dependancy_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; } gint sort_node_weight(gconstpointer a, gconstpointer b) { const node_t *node1 = (const node_t*)a; const node_t *node2 = (const node_t*)b; if(a == NULL) return 1; if(b == NULL) return -1; if(node1->weight > node2->weight) return -1; if(node1->weight < node2->weight) return 1; return 0; } action_t * action_new(resource_t *rsc, enum action_tasks task, node_t *on_node) { action_t *action = NULL; GListPtr possible_matches = NULL; if(rsc != NULL) { possible_matches = - find_actions_type(rsc->actions, task, on_node); + find_actions(rsc->actions, task, on_node); } if(on_node != NULL && on_node->details->unclean) { crm_warn("Not creating action %s for %s because %s is unclean", task2text(task), rsc?rsc->id:"", on_node->details->id); } if(on_node != NULL && on_node->details->unclean) { crm_warn("Not creating action %s for %s because %s is unclean", task2text(task), rsc?rsc->id:"", on_node->details->id); } if(possible_matches != NULL) { if(g_list_length(possible_matches) > 1) { crm_err("Action %s for %s on %s exists %d times", task2text(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("Returning existing action (%d) %s for %s on %s", action->id, task2text(task), rsc?rsc->id:"", on_node?on_node->details->id:""); /* todo: free possible_matches */ return action; } crm_debug("Creating action %s for %s on %s", task2text(task), rsc?rsc->id:"", on_node?on_node->details->id:""); crm_malloc(action, sizeof(action_t)); if(action != NULL) { action->id = action_id++; action->rsc = rsc; action->task = task; action->node = on_node; action->actions_before = NULL; action->actions_after = NULL; action->failure_is_fatal = TRUE; action->dumped = FALSE; action->discard = FALSE; action->runnable = TRUE; action->processed = FALSE; action->optional = FALSE; action->seen_count = 0; action->timeout = NULL; action->args = create_xml_node(NULL, "args"); if(rsc != NULL) { crm_debug("Adding created action to its resource"); rsc->actions = g_list_append(rsc->actions, action); if(rsc->timeout != NULL) { action->timeout = crm_strdup(rsc->timeout); } } } crm_debug("Action %d created", action->id); return action; } 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; } const char * task2text(enum action_tasks task) { const char *result = ""; switch(task) { case no_action: result = "no_action"; break; case stop_rsc: result = "stop"; break; case start_rsc: result = "start"; break; case shutdown_crm: result = "shutdown_crm"; break; case stonith_node: result = "stonith"; break; } return result; } void print_node(const char *pre_text, node_t *node, gboolean details) { if(node == NULL) { crm_debug("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug("%s%s%sNode %s: (weight=%f, fixed=%s)", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", node->details==NULL?"error ":node->details->online?"":"Unavailable/Unclean ", node->details->uname, node->weight, node->fixed?"True":"False"); if(details && node->details != NULL) { char *pe_mutable = crm_strdup("\t\t"); crm_debug("\t\t===Node Attributes"); g_hash_table_foreach(node->details->attrs, print_str_str, pe_mutable); crm_free(pe_mutable); } if(details) { int lpc = 0; crm_debug("\t\t===Node Attributes"); slist_iter( rsc, resource_t, node->details->running_rsc, lpc, print_resource("\t\t", rsc, FALSE); ); } } /* * Used by the HashTable for-loop */ void print_str_str(gpointer key, gpointer value, gpointer user_data) { crm_debug("%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("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug("%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) { int lpc = 0; 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("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug("%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) { int lpc = 0; if(cons == NULL) { crm_debug("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug("%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("\t%s %s run (score=%f : node placement rule)", safe_val3(NULL, cons, rsc_lh, id), cons->can?"Can":"Cannot", cons->weight); slist_iter( node, node_t, cons->node_list_rh, lpc, print_node("\t\t-->", node, FALSE) ); } } void print_rsc_dependancy(const char *pre_text, rsc_dependancy_t *cons, gboolean details) { if(cons == NULL) { crm_debug("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug("%s%s%s Constraint %s (%p):", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", "rsc_dependancy", cons->id, cons); if(details == FALSE) { crm_debug("\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("%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) { if(action == NULL) { crm_debug("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } switch(action->task) { case stonith_node: case shutdown_crm: crm_debug("%s%s%sAction %d: %s @ %s", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", action->discard?"Discarded ":action->optional?"Optional ":action->runnable?action->processed?"":"(Provisional) ":"!!Non-Startable!! ", action->id, task2text(action->task), safe_val4(NULL, action, node, details, uname)); break; default: crm_debug("%s%s%sAction %d: %s %s @ %s", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", action->optional?"Optional ":action->runnable?action->processed?"":"(Provisional) ":"!!Non-Startable!! ", action->id, task2text(action->task), safe_val3(NULL, action, rsc, id), safe_val4(NULL, action, node, details, uname)); break; } if(details) { int lpc = 0; #if 1 crm_debug("\t\t====== Preceeding Actions"); slist_iter( other, action_wrapper_t, action->actions_before, lpc, print_action("\t\t", other->action, FALSE); ); crm_debug("\t\t====== Subsequent Actions"); slist_iter( other, action_wrapper_t, action->actions_after, lpc, print_action("\t\t", other->action, FALSE); ); #else crm_debug("\t\t====== Subsequent Actions"); slist_iter( other, action_wrapper_t, action->actions_after, lpc, print_action("\t\t", other->action, FALSE); ); #endif crm_debug("\t\t====== End"); } else { crm_debug("\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_trace("deleting node"); crm_trace("%s is being deleted", details->uname); print_node("delete", node, FALSE); if(details != NULL) { if(details->attrs != NULL) { g_hash_table_foreach_remove(details->attrs, ghash_free_str_str, NULL); g_hash_table_destroy(details->attrs); } } } if(nodes != NULL) { g_list_free(nodes); } } gboolean ghash_free_str_str(gpointer key, gpointer value, gpointer user_data) { crm_free(key); crm_free(value); return TRUE; } 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_trace("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); rsc->fns->free(rsc); crm_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; free_xml(action->args); crm_free(action); } if(actions != NULL) { g_list_free(actions); } } void pe_free_rsc_dependancy(rsc_dependancy_t *cons) { if(cons != NULL) { 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* */ crm_free(cons); } } GListPtr -find_actions_type(GListPtr input, enum action_tasks task, node_t *on_node) +find_actions(GListPtr input, enum action_tasks task, node_t *on_node) { int lpc = 0; GListPtr result = NULL; slist_iter( action, action_t, input, lpc, if(action->task == task && (on_node == NULL || safe_str_eq(on_node->details->id, action->node->details->id))) { result = g_list_append(result, action); } ); return result; }