diff --git a/crm/pengine/Makefile.am b/crm/pengine/Makefile.am index 2b469afccf..50686c6b04 100644 --- a/crm/pengine/Makefile.am +++ b/crm/pengine/Makefile.am @@ -1,87 +1,87 @@ # # Copyright (C) 2004 Andrew Beekhof # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # MAINTAINERCLEANFILES = Makefile.in INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include \ -I$(top_builddir)/libltdl -I$(top_srcdir)/libltdl \ -I$(top_builddir)/linux-ha -I$(top_srcdir)/linux-ha \ -I$(top_builddir) -I$(top_srcdir) hadir = $(sysconfdir)/ha.d halibdir = $(libdir)/@HB_PKG@ commmoddir = $(halibdir)/modules/comm havarlibdir = $(localstatedir)/lib/@HB_PKG@ PIDFILE = $(localstatedir)/run/crmd.pid XML_FLAGS = `xml2-config --cflags` XML_LIBS = `xml2-config --libs` # sockets with path crmdir = $(havarlibdir)/crm apigid = @HA_APIGID@ crmuid = @HA_CCMUID@ COMMONLIBS = $(CRM_DEBUG_LIBS) \ $(top_builddir)/lib/clplumbing/libplumb.la \ $(top_builddir)/$(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 = color.c unpack.c graph.c \ - native.c group.c complex.c \ + native.c group.c incarnation.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 = unpack.c color.c graph.c \ - native.c group.c complex.c \ + native.c group.c incarnation.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 c3d66c9775..36da19dc93 100644 --- a/crm/pengine/color.c +++ b/crm/pengine/color.c @@ -1,147 +1,143 @@ -/* $Id: color.c,v 1.20 2004/11/09 14:49:14 andrew Exp $ */ +/* $Id: color.c,v 1.21 2004/11/11 14:51:26 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 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->rsc_lh, cons); ); return TRUE; } gboolean apply_agent_constraints(GListPtr resources) { int lpc; slist_iter( rsc, resource_t, resources, lpc, rsc->fns->agent_constraints(rsc); ); crm_trace("Finished applying RA restrictions"); return TRUE; } 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; } void -color_resource(resource_t *lh_resource, GListPtr *colors, GListPtr resources) +color_resource(resource_t *rsc, GListPtr *colors, GListPtr resources) { int lpc = 0; - crm_debug_action(print_resource("Coloring", lh_resource, FALSE)); + crm_debug_action(print_resource("Coloring", rsc, FALSE)); - if(lh_resource->provisional == FALSE) { + if(rsc->provisional == FALSE) { /* already processed this resource */ return; } - lh_resource->rsc_cons = g_list_sort( - lh_resource->rsc_cons, sort_cons_strength); + rsc->rsc_cons = g_list_sort( + rsc->rsc_cons, sort_cons_strength); crm_debug_action( - print_resource("Pre-processing", lh_resource, FALSE)); + print_resource("Pre-processing", rsc, FALSE)); /*------ Pre-processing */ slist_iter( - constraint, rsc_dependancy_t, lh_resource->rsc_cons, lpc, + constraint, rsc_dependancy_t, rsc->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); + rsc->fns->rsc_dependancy_lh(constraint); ); /* avoid looping through lists when we know this resource * cant be started */ - lh_resource->fns->color(lh_resource, colors); + rsc->fns->color(rsc, colors); crm_debug_action( - print_resource("Post-processing", lh_resource, TRUE)); + print_resource("Post-processing", rsc, TRUE)); /*------ Post-processing */ slist_iter( - constraint, rsc_dependancy_t, lh_resource->rsc_cons, lpc, + constraint, rsc_dependancy_t, rsc->rsc_cons, lpc, crm_debug_action( print_rsc_dependancy( "Post-Processing constraint",constraint,FALSE)); - lh_resource->fns->rsc_dependancy_lh(constraint); + rsc->fns->rsc_dependancy_lh(constraint); ); - crm_debug_action(print_resource("Colored", lh_resource, TRUE)); + crm_debug_action(print_resource("Colored", rsc, TRUE)); } diff --git a/crm/pengine/complex.c b/crm/pengine/complex.c index 2ced6ee49f..e73b62b3cc 100644 --- a/crm/pengine/complex.c +++ b/crm/pengine/complex.c @@ -1,242 +1,337 @@ -/* $Id: complex.c,v 1.5 2004/11/09 17:51:59 andrew Exp $ */ +/* $Id: complex.c,v 1.6 2004/11/11 14:51:26 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); +gboolean has_agent(node_t *a_node, lrm_agent_t *an_agent); + resource_object_functions_t resource_class_functions[] = { { native_unpack, native_find_child, + native_num_allowed_nodes, native_color, native_create_actions, native_internal_constraints, native_agent_constraints, native_rsc_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_find_child, + group_num_allowed_nodes, group_color, group_create_actions, 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 */ -/* }, */ - + { + incarnation_unpack, + incarnation_find_child, + incarnation_num_allowed_nodes, + incarnation_color, + incarnation_create_actions, + incarnation_internal_constraints, + incarnation_agent_constraints, + incarnation_rsc_dependancy_lh, + incarnation_rsc_dependancy_rh, + incarnation_rsc_order_lh, + incarnation_rsc_order_rh, + incarnation_rsc_location, + incarnation_expand, + incarnation_dump, + incarnation_free + } }; /* resource_object_functions_t resource_variants[] = resource_class_functions; */ int get_resource_type(const char *name) { if(safe_str_eq(name, "resource")) { return pe_native; } else if(safe_str_eq(name, "resource_group")) { return pe_group; + + } else if(safe_str_eq(name, "incarnation")) { + return pe_incarnation; } 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 *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..."); + crm_verbose("Processing resource input..."); 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; +/* } else if((*rsc)->variant == pe_native) { */ } (*rsc)->fns = &resource_class_functions[(*rsc)->variant]; - crm_verbose("Processing resource..."); + crm_verbose("Unpacking resource..."); (*rsc)->priority = atoi(priority?priority:"0"); (*rsc)->effective_priority = (*rsc)->priority; (*rsc)->recovery_type = recovery_stop_start; (*rsc)->runnable = TRUE; (*rsc)->provisional = TRUE; + (*rsc)->starting = FALSE; + (*rsc)->stopping = FALSE; (*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 { (*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; } (*rsc)->fns->unpack(*rsc); return TRUE; } void order_actions(action_t *lh_action, action_t *rh_action, order_constraint_t *order) { action_wrapper_t *wrapper = NULL; GListPtr list = NULL; crm_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_trace("Freeing %s", rsc->id); while(rsc->rsc_cons) { pe_free_rsc_dependancy( (rsc_dependancy_t*)rsc->rsc_cons->data); rsc->rsc_cons = rsc->rsc_cons->next; } crm_trace("Freeing constraint list"); if(rsc->rsc_cons != NULL) { g_list_free(rsc->rsc_cons); } crm_trace("Freeing opaque data"); crm_free(rsc->variant_opaque); crm_trace("Freeing resource"); crm_free(rsc); crm_trace("Resource freed"); } + +void +common_agent_constraints( + GListPtr node_list, lrm_agent_t *agent, const char *id) +{ + int lpc; + slist_iter( + node, node_t, node_list, lpc, + + crm_trace("Checking if %s supports %s/%s (%s)", + node->details->uname, + agent->class, agent->type, agent->version); + + if(has_agent(node, agent) == FALSE) { + /* remove node from contention */ + crm_trace("Marking node %s unavailable for %s", + node->details->uname, 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; +} diff --git a/crm/pengine/complex.h b/crm/pengine/complex.h index 0764b623ae..d69b7f0c2a 100644 --- a/crm/pengine/complex.h +++ b/crm/pengine/complex.h @@ -1,114 +1,139 @@ -/* $Id: complex.h,v 1.5 2004/11/10 16:41:46 msoffen Exp $ */ +/* $Id: complex.h,v 1.6 2004/11/11 14:51:26 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 *); resource_t *(*find_child)(resource_t *, const char *); + int (*num_allowed_nodes)(resource_t *); void (*color)(resource_t *, GListPtr *); void (*create_actions)(resource_t *); 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)(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 resource_t *native_find_child(resource_t *rsc, const char *id); +extern int native_num_allowed_nodes(resource_t *rsc); extern void native_color(resource_t *rsc, GListPtr *colors); extern void native_create_actions(resource_t *rsc); 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(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 resource_t *group_find_child(resource_t *rsc, const char *id); +extern int group_num_allowed_nodes(resource_t *rsc); extern void group_color(resource_t *rsc, GListPtr *colors); extern void group_create_actions(resource_t *rsc); 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(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 void incarnation_unpack(resource_t *rsc); +extern resource_t *incarnation_find_child(resource_t *rsc, const char *id); +extern int incarnation_num_allowed_nodes(resource_t *rsc); +extern void incarnation_color(resource_t *rsc, GListPtr *colors); +extern void incarnation_create_actions(resource_t *rsc); +extern void incarnation_internal_constraints( + resource_t *rsc, GListPtr *ordering_constraints); +extern void incarnation_agent_constraints(resource_t *rsc); +extern void incarnation_rsc_dependancy_lh(rsc_dependancy_t *constraint); +extern void incarnation_rsc_dependancy_rh( + resource_t *rsc, rsc_dependancy_t *constraint); +extern void incarnation_rsc_order_lh(resource_t *rsc, order_constraint_t *order); +extern void incarnation_rsc_order_rh( + action_t *lh_action, resource_t *rsc, order_constraint_t *order); +extern void incarnation_rsc_location(resource_t *rsc, rsc_to_node_t *constraint); +extern void incarnation_expand(resource_t *rsc, xmlNodePtr *graph); +extern void incarnation_dump(resource_t *rsc, const char *pre_text, gboolean details); +extern void incarnation_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); +extern void common_agent_constraints( + GListPtr node_list, lrm_agent_t *agent, const char *id); + diff --git a/crm/pengine/graph.c b/crm/pengine/graph.c index 9e10805104..b28cb5163a 100644 --- a/crm/pengine/graph.c +++ b/crm/pengine/graph.c @@ -1,357 +1,363 @@ -/* $Id: graph.c,v 1.20 2004/11/09 14:49:14 andrew Exp $ */ +/* $Id: graph.c,v 1.21 2004/11/11 14:51:26 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 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. */ stop_actions = find_actions(rsc->actions, stop_rsc, node); slist_iter( action, action_t, stop_actions, lpc2, 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); /* 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)); + set_xml_property_copy(action_xml, XML_LRM_ATTR_TASK, + task2text(action->task)); break; default: - action_xml = create_xml_node(NULL, "rsc_op"); + if(action->pseudo) { + action_xml = create_xml_node(NULL,"pseduo_op"); + } else { + 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)); + set_xml_property_copy(action_xml, XML_LRM_ATTR_TASK, + task2text(action->task)); break; } - if(action->task != stonith_node) { + if(action->task != stonith_node + && (action->pseudo == FALSE && action->node != NULL)) { 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 c5b717b477..c499287c72 100644 --- a/crm/pengine/group.c +++ b/crm/pengine/group.c @@ -1,320 +1,381 @@ -/* $Id: group.c,v 1.4 2004/11/09 17:51:59 andrew Exp $ */ +/* $Id: group.c,v 1.5 2004/11/11 14:51:26 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 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 *self; resource_t *first_child; resource_t *last_child; + } group_variant_data_t; #define get_group_variant_data(data, rsc) \ if(rsc->variant == pe_group) { \ data = (group_variant_data_t *)rsc->variant_opaque; \ } else { \ crm_err("Resource %s was not a \"group\" variant", \ rsc->id); \ return; \ } void group_unpack(resource_t *rsc) { xmlNodePtr xml_obj = rsc->xml; + xmlNodePtr xml_self = create_xml_node(NULL, XML_CIB_TAG_RESOURCE); group_variant_data_t *group_data = NULL; + resource_t *self = NULL; crm_verbose("Processing resource %s...", rsc->id); crm_malloc(group_data, sizeof(group_variant_data_t)); group_data->num_children = 0; + group_data->self = NULL; group_data->child_list = NULL; group_data->first_child = NULL; group_data->last_child = NULL; + + /* this is a bit of a hack - but simplifies everything else */ + copy_in_properties(xml_self, xml_obj); + if(common_unpack(xml_self, &self)) { + group_data->self = self; + self->restart_type = pe_restart_restart; + + } else { + crm_xml_err(xml_self, "Couldnt unpack dummy child"); + return; + } xml_child_iter( xml_obj, xml_native_rsc, XML_CIB_TAG_RESOURCE, resource_t *new_rsc = NULL; + set_id(xml_native_rsc, rsc->id, -1); + 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; } crm_debug_action( print_resource("Added", new_rsc, FALSE)); } else { crm_err("Failed unpacking resource %s", xmlGetProp(xml_obj, XML_ATTR_ID)); } ); crm_verbose("Added %d children to resource %s...", group_data->num_children, rsc->id); rsc->variant_opaque = group_data; } resource_t * group_find_child(resource_t *rsc, const char *id) { group_variant_data_t *group_data = NULL; if(rsc->variant == pe_group) { group_data = (group_variant_data_t *)rsc->variant_opaque; } else { crm_err("Resource %s was not a \"group\" variant", rsc->id); return NULL; } return pe_find_resource(group_data->child_list, id); } +int group_num_allowed_nodes(resource_t *rsc) +{ + group_variant_data_t *group_data = NULL; + if(rsc->variant == pe_native) { + group_data = (group_variant_data_t *)rsc->variant_opaque; + } else { + crm_err("Resource %s was not a \"native\" variant", + rsc->id); + return 0; + } + return group_data->self->fns->num_allowed_nodes(group_data->self); +} + void group_color(resource_t *rsc, GListPtr *colors) { int lpc; group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); -/* group_data->first_child->fns->color(group_data->first_child, colors); */ + group_data->self->fns->color(group_data->self, colors); slist_iter( child_rsc, resource_t, group_data->child_list, lpc, child_rsc->fns->color(child_rsc, colors); ); - - /* all others are supposed to be inferred by virtue of - * the must constraints - but this does not seem to happen (yet) - */ } void group_create_actions(resource_t *rsc) { int lpc; + gboolean child_starting = FALSE; + gboolean child_stopping = FALSE; group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); slist_iter( child_rsc, resource_t, group_data->child_list, lpc, child_rsc->fns->create_actions(child_rsc); + child_starting = child_starting || child_rsc->starting; + child_stopping = child_stopping || child_rsc->stopping; ); + if(child_starting) { + rsc->starting = TRUE; + action_new(group_data->self, start_rsc, NULL); + action_new(group_data->self, started_rsc, NULL); + + } + if(child_stopping) { + rsc->stopping = TRUE; + action_new(group_data->self, stop_rsc, NULL); + action_new(group_data->self, stopped_rsc, NULL); + } + + slist_iter( + action, action_t, group_data->self->actions, lpc, + action->pseudo = TRUE; + ); } void group_internal_constraints(resource_t *rsc, GListPtr *ordering_constraints) { int lpc; resource_t *last_rsc = NULL; group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); + order_new(group_data->self, stop_rsc, NULL, + group_data->self, start_rsc, NULL, + pecs_startstop, ordering_constraints); + slist_iter( child_rsc, resource_t, group_data->child_list, lpc, - order_new(child_rsc, stop_rsc, NULL, child_rsc, start_rsc, NULL, + order_new(child_rsc, stop_rsc, NULL, + child_rsc, start_rsc, NULL, pecs_startstop, ordering_constraints); if(last_rsc != NULL) { - order_new(last_rsc, start_rsc, NULL, + order_new(last_rsc, start_rsc, NULL, child_rsc, start_rsc, NULL, pecs_startstop, ordering_constraints); order_new(child_rsc, stop_rsc, NULL, - last_rsc, stop_rsc, NULL, + last_rsc, stop_rsc, NULL, + pecs_startstop, ordering_constraints); + + } else { + order_new(child_rsc, stop_rsc, NULL, + group_data->self, stopped_rsc, NULL, + pecs_startstop, ordering_constraints); + + order_new(group_data->self, 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); - } + rsc_dependancy_new("pe_group_internal", pecs_must, + group_data->self, child_rsc); last_rsc = child_rsc; ); + + if(last_rsc != NULL) { + order_new(last_rsc, start_rsc, NULL, + group_data->self, started_rsc, NULL, + pecs_startstop, ordering_constraints); + + order_new(group_data->self, stop_rsc, NULL, + last_rsc, stop_rsc, NULL, + pecs_startstop, ordering_constraints); + } + } 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"); + crm_err("rsc_lh was NULL for %s", constraint->id); + return; + + } else if(constraint->rsc_rh == NULL) { + crm_err("rsc_rh was NULL for %s", constraint->id); return; + } else { crm_debug("Processing constraints from %s", rsc->id); } get_group_variant_data(group_data, rsc); - - slist_iter( - child_rsc, resource_t, group_data->child_list, lpc, - - child_rsc->fns->rsc_dependancy_rh(child_rsc, constraint); - ); - + group_data->self->fns->rsc_dependancy_rh(group_data->self, 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 = NULL; get_group_variant_data(group_data, rsc); 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); - ); + group_data->self->fns->rsc_dependancy_rh(group_data->self, constraint); } void group_rsc_order_lh(resource_t *rsc, order_constraint_t *order) { group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); 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); + if(order->lh_action_task == start_rsc) { + order->lh_action_task = started_rsc; + + } else if(order->lh_action_task == stop_rsc) { + order->lh_action_task = stopped_rsc; } + + group_data->self->fns->rsc_order_lh(group_data->self, order); } void group_rsc_order_rh( action_t *lh_action, resource_t *rsc, order_constraint_t *order) { group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); 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); - } + group_data->self->fns->rsc_order_rh(lh_action, group_data->self, order); } void group_rsc_location(resource_t *rsc, rsc_to_node_t *constraint) { int lpc; group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); crm_verbose("Processing actions from %s", rsc->id); + group_data->self->fns->rsc_location(group_data->self, constraint); 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 = NULL; get_group_variant_data(group_data, rsc); crm_verbose("Processing actions from %s", rsc->id); + group_data->self->fns->expand(group_data->self, graph); + 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 = NULL; get_group_variant_data(group_data, rsc); common_dump(rsc, pre_text, details); + group_data->self->fns->dump(group_data->self, 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 = NULL; get_group_variant_data(group_data, rsc); crm_verbose("Freeing %s", rsc->id); slist_iter( child_rsc, resource_t, group_data->child_list, lpc, crm_verbose("Freeing child %s", child_rsc->id); child_rsc->fns->free(child_rsc); ); crm_verbose("Freeing child list"); pe_free_shallow_adv(group_data->child_list, FALSE); + group_data->self->fns->free(group_data->self); common_free(rsc); } void group_agent_constraints(resource_t *rsc) { int lpc; group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); slist_iter( child_rsc, resource_t, group_data->child_list, lpc, child_rsc->fns->agent_constraints(child_rsc); ); } diff --git a/crm/pengine/incarnation.c b/crm/pengine/incarnation.c new file mode 100644 index 0000000000..d5e5bd1413 --- /dev/null +++ b/crm/pengine/incarnation.c @@ -0,0 +1,542 @@ +/* $Id: incarnation.c,v 1.1 2004/11/11 14:51:26 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 rsc_dependancy_new( + const char *id, enum con_strength strength, + resource_t *rsc_lh, resource_t *rsc_rh); + +typedef struct incarnation_variant_data_s +{ + resource_t *self; + + int max_incarnation; + int max_incarnation_node; + +/* int max_master; */ +/* int max_master_node; */ + + int active_incarnation; + + gboolean interleave; + gboolean ordered; + + GListPtr child_list; /* resource_t* */ +} incarnation_variant_data_t; + +#define get_incarnation_variant_data(data, rsc) \ + if(rsc->variant == pe_incarnation) { \ + data = (incarnation_variant_data_t *)rsc->variant_opaque; \ + } else { \ + crm_err("Resource %s was not an \"incarnation\" variant", \ + rsc->id); \ + return; \ + } + +void incarnation_unpack(resource_t *rsc) +{ + int lpc = 0; + xmlNodePtr xml_obj = rsc->xml; + xmlNodePtr xml_self = create_xml_node(NULL, XML_CIB_TAG_RESOURCE); + incarnation_variant_data_t *incarnation_data = NULL; + resource_t *self = NULL; + + const char *ordered = xmlGetProp(xml_obj, "ordered"); + const char *interleave = xmlGetProp(xml_obj, "interleave"); + const char *max_incarn = xmlGetProp(xml_obj, "max_incarnations"); + const char *max_incarn_node = xmlGetProp(xml_obj, "max_per_node"); + + crm_verbose("Processing resource %s...", rsc->id); + + crm_malloc(incarnation_data, sizeof(incarnation_variant_data_t)); + incarnation_data->child_list = NULL; + incarnation_data->interleave = FALSE; + incarnation_data->active_incarnation = 0; + incarnation_data->max_incarnation = crm_atoi(max_incarn, "1"); + incarnation_data->max_incarnation_node = crm_atoi(max_incarn_node,"1"); + + /* this is a bit of a hack - but simplifies everything else */ + copy_in_properties(xml_self, xml_obj); + if(common_unpack(xml_self, &self)) { + incarnation_data->self = self; + self->restart_type = pe_restart_restart; + + } else { + crm_xml_err(xml_self, "Couldnt unpack dummy child"); + return; + } + + if(safe_str_eq(interleave, "true")) { + incarnation_data->interleave = TRUE; + } + if(safe_str_eq(ordered, "true")) { + incarnation_data->ordered = TRUE; + } + + xml_child_iter( + xml_obj, xml_obj_child, XML_CIB_TAG_RESOURCE, + + for(lpc = 0; lpc < incarnation_data->max_incarnation; lpc++) { + resource_t *child_rsc = NULL; + xmlNodePtr child_copy = copy_xml_node_recursive(xml_obj_child); + + set_id(child_copy, rsc->id, lpc); + + if(common_unpack(child_copy, &child_rsc)) { + incarnation_data->child_list = g_list_append( + incarnation_data->child_list, child_rsc); + + crm_debug_action( + print_resource("Added", child_rsc, FALSE)); + } else { + crm_err("Failed unpacking resource %s", + xmlGetProp(child_copy, XML_ATTR_ID)); + } + } + /* only count the first one */ + break; + ); + + crm_verbose("Added %d children to resource %s...", + incarnation_data->max_incarnation, rsc->id); + + rsc->variant_opaque = incarnation_data; +} + + + +resource_t * +incarnation_find_child(resource_t *rsc, const char *id) +{ + incarnation_variant_data_t *incarnation_data = NULL; + if(rsc->variant == pe_incarnation) { + incarnation_data = (incarnation_variant_data_t *)rsc->variant_opaque; + } else { + crm_err("Resource %s was not a \"incarnation\" variant", rsc->id); + return NULL; + } + return pe_find_resource(incarnation_data->child_list, id); +} + +int incarnation_num_allowed_nodes(resource_t *rsc) +{ + int lpc = 0, num_nodes = 0; + incarnation_variant_data_t *incarnation_data = NULL; + if(rsc->variant == pe_incarnation) { + incarnation_data = (incarnation_variant_data_t *)rsc->variant_opaque; + } else { + crm_err("Resource %s was not an \"incarnation\" variant", + rsc->id); + return 0; + } + + /* what *should* we return here? */ + slist_iter( + child_rsc, resource_t, incarnation_data->child_list, lpc, + int tmp_num_nodes = child_rsc->fns->num_allowed_nodes(child_rsc); + if(tmp_num_nodes > num_nodes) { + num_nodes = tmp_num_nodes; + } + ); + + return num_nodes; +} + +void incarnation_color(resource_t *rsc, GListPtr *colors) +{ + int lpc, lpc2, max_nodes = 0; + resource_t *child_0 = NULL; + resource_t *child_lh = NULL; + resource_t *child_rh = NULL; + incarnation_variant_data_t *incarnation_data = NULL; + get_incarnation_variant_data(incarnation_data, rsc); + + child_0 = g_list_nth_data(incarnation_data->child_list, 0); + + max_nodes = rsc->fns->num_allowed_nodes(rsc); + + /* generate up to max_nodes * incarnation_node_max constraints */ + lpc = 0; + crm_info("Distributing %d incarnations over %d nodes", + incarnation_data->max_incarnation, max_nodes); + + for(; lpc < max_nodes && lpc < incarnation_data->max_incarnation; lpc++) { + + child_lh = child_0; + incarnation_data->active_incarnation++; + + if(lpc != 0) { + child_rh = g_list_nth_data(incarnation_data->child_list, lpc); + + crm_info("Incarnation %d will run on a differnt node to 0", + lpc); + + rsc_dependancy_new("pe_incarnation_internal_must_not", + pecs_must_not, child_lh, child_rh); + } else { + child_rh = child_0; + } + + child_lh = child_rh; + + for(lpc2 = 1; lpc2 < incarnation_data->max_incarnation_node; lpc2++) { + int offset = lpc + (lpc2 * max_nodes); + if(offset >= incarnation_data->max_incarnation) { + break; + } + crm_info("Incarnation %d will run on the same node as %d", + offset, lpc); + + incarnation_data->active_incarnation++; + + child_rh = g_list_nth_data( + incarnation_data->child_list, offset); + + rsc_dependancy_new("pe_incarnation_internal_must", + pecs_must, child_lh, child_rh); + } + } + + slist_iter( + child_rsc, resource_t, incarnation_data->child_list, lpc, + if(lpc < incarnation_data->active_incarnation) { + crm_info("Coloring Incarnation %d", lpc); + child_rsc->fns->color(child_rsc, colors); + } else { + /* TODO: assign "no color"? Doesnt seem to need it */ + crm_info("Incarnation %d cannot be started", lpc); + } + ); + crm_info("%d Incarnations are active", incarnation_data->active_incarnation); +} + +void incarnation_create_actions(resource_t *rsc) +{ + int lpc; + gboolean child_starting = FALSE; + gboolean child_stopping = FALSE; + incarnation_variant_data_t *incarnation_data = NULL; + get_incarnation_variant_data(incarnation_data, rsc); + + slist_iter( + child_rsc, resource_t, incarnation_data->child_list, lpc, + child_rsc->fns->create_actions(child_rsc); + child_starting = child_starting || child_rsc->starting; + child_stopping = child_stopping || child_rsc->stopping; + ); + + if(child_starting) { + rsc->starting = TRUE; + action_new(incarnation_data->self, start_rsc, NULL); + action_new(incarnation_data->self, started_rsc, NULL); + + } + if(child_stopping) { + rsc->stopping = TRUE; + action_new(incarnation_data->self, stop_rsc, NULL); + action_new(incarnation_data->self, stopped_rsc, NULL); + } + + slist_iter( + action, action_t, incarnation_data->self->actions, lpc, + action->pseudo = TRUE; + ); +} + + +void incarnation_internal_constraints(resource_t *rsc, GListPtr *ordering_constraints) +{ + int lpc; + resource_t *last_rsc = NULL; + incarnation_variant_data_t *incarnation_data = NULL; + get_incarnation_variant_data(incarnation_data, rsc); + + /* global stop before start */ + order_new(incarnation_data->self, stop_rsc, NULL, + incarnation_data->self, start_rsc, NULL, + pecs_startstop, ordering_constraints); + + slist_iter( + child_rsc, resource_t, incarnation_data->child_list, lpc, + + /* child stop before start */ + order_new(child_rsc, stop_rsc, NULL, + child_rsc, start_rsc, NULL, + pecs_startstop, ordering_constraints); + + if(incarnation_data->ordered && last_rsc != NULL) { + if(lpc < incarnation_data->active_incarnation) { + /* child/child relative start */ + order_new(last_rsc, start_rsc, NULL, + child_rsc, start_rsc, NULL, + pecs_startstop, ordering_constraints); + } + + /* child/child relative stop */ + order_new(child_rsc, stop_rsc, NULL, + last_rsc, stop_rsc, NULL, + pecs_startstop, ordering_constraints); + + } else if(last_rsc != NULL) { + + if(lpc < incarnation_data->active_incarnation) { + /* child start before global started */ + order_new(child_rsc, start_rsc, NULL, + incarnation_data->self, started_rsc, NULL, + pecs_startstop, ordering_constraints); + } + + /* global start before child start */ + order_new(incarnation_data->self, start_rsc, NULL, + child_rsc, start_rsc, NULL, + pecs_startstop, ordering_constraints); + + /* child stop before global stopped */ + order_new(child_rsc, stop_rsc, NULL, + incarnation_data->self, stopped_rsc, NULL, + pecs_startstop, ordering_constraints); + + /* global stop before child stop */ + order_new(incarnation_data->self, stop_rsc, NULL, + child_rsc, stop_rsc, NULL, + pecs_startstop, ordering_constraints); + + } else { + /* child start before global started */ + order_new(child_rsc, start_rsc, NULL, + incarnation_data->self, started_rsc, NULL, + pecs_startstop, ordering_constraints); + + /* first child stop before global stopped */ + order_new(child_rsc, stop_rsc, NULL, + incarnation_data->self, stopped_rsc, NULL, + pecs_startstop, ordering_constraints); + + /* global start before first child start */ + order_new(incarnation_data->self, start_rsc, NULL, + child_rsc, start_rsc, NULL, + pecs_startstop, ordering_constraints); + } + + if(lpc < incarnation_data->active_incarnation) { + last_rsc = child_rsc; + } + + ); + + if(incarnation_data->ordered && last_rsc != NULL) { + /* last child start before global started */ + order_new(last_rsc, start_rsc, NULL, + incarnation_data->self, started_rsc, NULL, + pecs_startstop, ordering_constraints); + + /* global stop before first child stop */ + order_new(incarnation_data->self, stop_rsc, NULL, + last_rsc, stop_rsc, NULL, + pecs_startstop, ordering_constraints); + } + +} + +void incarnation_rsc_dependancy_lh(rsc_dependancy_t *constraint) +{ + int lpc; + resource_t *rsc = constraint->rsc_lh; + incarnation_variant_data_t *incarnation_data = NULL; + + if(rsc == NULL) { + crm_err("rsc_lh was NULL for %s", constraint->id); + return; + + } else if(constraint->rsc_rh == NULL) { + crm_err("rsc_rh was NULL for %s", constraint->id); + return; + + } else if(constraint->strength != pecs_must_not) { + crm_warn("rsc_dependancies other than \"must_not\" " + "are not supported for incarnation resources"); + return; + + } else { + crm_debug("Processing constraints from %s", rsc->id); + } + + get_incarnation_variant_data(incarnation_data, rsc); + + slist_iter( + child_rsc, resource_t, incarnation_data->child_list, lpc, + + crm_debug_action(print_resource("LHS", child_rsc, TRUE)); + child_rsc->fns->rsc_dependancy_rh(child_rsc, constraint); + ); +} + +void incarnation_rsc_dependancy_rh(resource_t *rsc, rsc_dependancy_t *constraint) +{ + int lpc; + incarnation_variant_data_t *incarnation_data = NULL; + + crm_verbose("Processing RH of constraint %s", constraint->id); + + if(rsc == NULL) { + crm_err("rsc_lh was NULL for %s", constraint->id); + return; + + } else if(constraint->rsc_rh == NULL) { + crm_err("rsc_rh was NULL for %s", constraint->id); + return; + + } else if(constraint->strength != pecs_must_not) { + crm_warn("rsc_dependancies other than \"must_not\" " + "are not supported for incarnation resources"); + return; + + } else { + crm_debug_action(print_resource("LHS", rsc, FALSE)); + } + + get_incarnation_variant_data(incarnation_data, rsc); + + slist_iter( + child_rsc, resource_t, incarnation_data->child_list, lpc, + + crm_debug_action(print_resource("RHS", child_rsc, FALSE)); + child_rsc->fns->rsc_dependancy_rh(child_rsc, constraint); + ); +} + + +void incarnation_rsc_order_lh(resource_t *rsc, order_constraint_t *order) +{ + incarnation_variant_data_t *incarnation_data = NULL; + get_incarnation_variant_data(incarnation_data, rsc); + + crm_verbose("Processing LH of ordering constraint %d", order->id); + + if(order->lh_action_task == start_rsc) { + order->lh_action_task = started_rsc; + + } else if(order->lh_action_task == stop_rsc) { + order->lh_action_task = stopped_rsc; + } + + incarnation_data->self->fns->rsc_order_lh(incarnation_data->self, order); +} + +void incarnation_rsc_order_rh( + action_t *lh_action, resource_t *rsc, order_constraint_t *order) +{ + incarnation_variant_data_t *incarnation_data = NULL; + get_incarnation_variant_data(incarnation_data, rsc); + + crm_verbose("Processing RH of ordering constraint %d", order->id); + + incarnation_data->self->fns->rsc_order_rh(lh_action, incarnation_data->self, order); +} + +void incarnation_rsc_location(resource_t *rsc, rsc_to_node_t *constraint) +{ + int lpc; + incarnation_variant_data_t *incarnation_data = NULL; + get_incarnation_variant_data(incarnation_data, rsc); + + crm_verbose("Processing actions from %s", rsc->id); + + incarnation_data->self->fns->rsc_location(incarnation_data->self, constraint); + slist_iter( + child_rsc, resource_t, incarnation_data->child_list, lpc, + + child_rsc->fns->rsc_location(child_rsc, constraint); + ); +} + +void incarnation_expand(resource_t *rsc, xmlNodePtr *graph) +{ + int lpc; + incarnation_variant_data_t *incarnation_data = NULL; + get_incarnation_variant_data(incarnation_data, rsc); + + crm_verbose("Processing actions from %s", rsc->id); + + incarnation_data->self->fns->expand(incarnation_data->self, graph); + + slist_iter( + child_rsc, resource_t, incarnation_data->child_list, lpc, + + child_rsc->fns->expand(child_rsc, graph); + ); + +} + +void incarnation_dump(resource_t *rsc, const char *pre_text, gboolean details) +{ + int lpc; + incarnation_variant_data_t *incarnation_data = NULL; + get_incarnation_variant_data(incarnation_data, rsc); + + common_dump(rsc, pre_text, details); + + incarnation_data->self->fns->dump(incarnation_data->self, pre_text, details); + + slist_iter( + child_rsc, resource_t, incarnation_data->child_list, lpc, + + child_rsc->fns->dump(child_rsc, pre_text, details); + ); +} + +void incarnation_free(resource_t *rsc) +{ + int lpc; + incarnation_variant_data_t *incarnation_data = NULL; + get_incarnation_variant_data(incarnation_data, rsc); + + crm_verbose("Freeing %s", rsc->id); + + slist_iter( + child_rsc, resource_t, incarnation_data->child_list, lpc, + + crm_verbose("Freeing child %s", child_rsc->id); + child_rsc->fns->free(child_rsc); + ); + + crm_verbose("Freeing child list"); + pe_free_shallow_adv(incarnation_data->child_list, FALSE); + incarnation_data->self->fns->free(incarnation_data->self); + + common_free(rsc); +} + + +void +incarnation_agent_constraints(resource_t *rsc) +{ + int lpc; + incarnation_variant_data_t *incarnation_data = NULL; + get_incarnation_variant_data(incarnation_data, rsc); + + slist_iter( + child_rsc, resource_t, incarnation_data->child_list, lpc, + + child_rsc->fns->agent_constraints(child_rsc); + ); +} diff --git a/crm/pengine/native.c b/crm/pengine/native.c index 9d899bee18..500bd62758 100644 --- a/crm/pengine/native.c +++ b/crm/pengine/native.c @@ -1,1092 +1,1119 @@ -/* $Id: native.c,v 1.5 2004/11/09 17:51:59 andrew Exp $ */ +/* $Id: native.c,v 1.6 2004/11/11 14:51:26 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include extern color_t *add_color(resource_t *rh_resource, color_t *color); -gboolean has_agent(node_t *a_node, lrm_agent_t *an_agent); - gboolean native_choose_color(resource_t *lh_resource); void native_assign_color(resource_t *rsc, color_t *color); void native_update_node_weight(resource_t *rsc, rsc_to_node_t *cons, const char *id, GListPtr nodes); void native_rsc_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); void filter_nodes(resource_t *rsc); +int num_allowed_nodes4color(color_t *color); + typedef struct native_variant_data_s { lrm_agent_t *agent; GListPtr running_on; /* node_t* */ color_t *color; GListPtr node_cons; /* rsc_to_node_t* */ GListPtr allowed_nodes; /* node_t* */ } native_variant_data_t; #define get_native_variant_data(data, rsc) \ if(rsc->variant == pe_native) { \ data = (native_variant_data_t *)rsc->variant_opaque; \ } else { \ crm_err("Resource %s was not a \"native\" variant", \ rsc->id); \ return; \ } \ #define get_native_variant_data_boolean(data, rsc) \ if(rsc->variant == pe_native) { \ data = (native_variant_data_t *)rsc->variant_opaque; \ } else { \ crm_err("Resource %s was not a \"native\" variant", \ rsc->id); \ return FALSE; \ } \ void native_add_running(resource_t *rsc, node_t *node) { native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); 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; native_variant_data_t *native_data = NULL; const char *version = xmlGetProp(xml_obj, XML_ATTR_VERSION); crm_verbose("Processing resource %s...", rsc->id); 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"; native_data->color = NULL; native_data->allowed_nodes = NULL; native_data->node_cons = NULL; native_data->running_on = NULL; rsc->variant_opaque = native_data; } resource_t * native_find_child(resource_t *rsc, const char *id) { return NULL; } +int native_num_allowed_nodes(resource_t *rsc) +{ + int lpc = 0, num_nodes = 0; + native_variant_data_t *native_data = NULL; + if(rsc->variant == pe_native) { + native_data = (native_variant_data_t *)rsc->variant_opaque; + } else { + crm_err("Resource %s was not a \"native\" variant", + rsc->id); + return 0; + } + + if(native_data->color) { + return num_allowed_nodes4color(native_data->color); + + } else if(rsc->candidate_colors) { + /* TODO: sort colors first */ + color_t *color = g_list_nth_data(rsc->candidate_colors, 0); + return num_allowed_nodes4color(color); + + } else { + slist_iter( + this_node, node_t, native_data->allowed_nodes, lpc, + if(this_node->weight < 0) { + continue; + } + num_nodes++; + ); + } + + return num_nodes; +} + +int num_allowed_nodes4color(color_t *color) +{ + int lpc = 0, num_nodes = 0; + + if(color->details->pending == FALSE) { + if(color->details->chosen_node) { + return 1; + } + return 0; + } + + slist_iter( + this_node, node_t, color->details->candidate_nodes, lpc, + if(this_node->weight < 0) { + continue; + } + num_nodes++; + ); + + return num_nodes; +} + void native_color(resource_t *rsc, GListPtr *colors) { color_t *new_color = NULL; native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); if( native_choose_color(rsc) ) { crm_verbose("Colored resource %s with color %d", rsc->id, native_data->color->id); } else { if(native_data->allowed_nodes != NULL) { /* filter out nodes with a negative weight */ filter_nodes(rsc); new_color = create_color( colors, rsc, native_data->allowed_nodes); native_assign_color(rsc, new_color); } if(new_color == NULL) { crm_err("Could not color resource %s", rsc->id); print_resource("ERROR: No color", rsc, FALSE); 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 = NULL; get_native_variant_data(native_data, rsc); if(native_data->color != NULL) { chosen = native_data->color->details->chosen_node; } if(chosen != NULL) { can_start = TRUE; } 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(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, native_data->running_on, lpc2, - crm_info("Stop resource %s (%s)", + 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, 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, + 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, + crm_info("Stop resource %s (%s)", rsc->id, safe_val3(NULL, node, details, uname)); action_new(rsc, stop_rsc, node); } ); } } 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"); + crm_err("rsc_lh was NULL for %s", constraint->id); + return; + + } else if(constraint->rsc_rh == NULL) { + crm_err("rsc_rh was NULL for %s", constraint->id); 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 = NULL; native_variant_data_t *native_data_rh = NULL; get_native_variant_data(native_data_lh, rsc_lh); get_native_variant_data(native_data_rh, rsc_rh); crm_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"); + if(constraint->strength == pecs_must) { + /* update effective_priorities */ + native_rsc_dependancy_rh_must( + rsc_lh, update_lh,rsc_rh, update_rh); + } else { + /* nothing */ + crm_debug( + "Skipping constraint, both sides provisional"); + } return; } else if( (!rsc_lh->provisional) && (!rsc_rh->provisional) && (!native_data_lh->color->details->pending) && (!native_data_rh->color->details->pending) ) { /* error check */ do_check = TRUE; if(rsc_lh->effective_priority < rsc_rh->effective_priority) { update_lh = TRUE; } else if(rsc_lh->effective_priority > rsc_rh->effective_priority) { update_rh = TRUE; } else { update_lh = TRUE; update_rh = TRUE; } } else if(rsc_lh->provisional == FALSE && native_data_lh->color->details->pending == FALSE) { /* update _us_ : postproc color version */ update_rh = TRUE; } else if(rsc_rh->provisional == 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(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; + switch(order->lh_action_task) { + case start_rsc: + case started_rsc: + case stop_rsc: + case stopped_rsc: + break; + default: + 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( 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)); + crm_debug("RH-Side was: (%s/%s)", + order->rh_rsc?order->rh_rsc->id:order->rh_action?order->rh_action->rsc->id:"", + task2text(order->rh_action_task)); return; } } else { crm_warn("No LH-Side (%s) specified for constraint", task2text(order->lh_action_task)); + crm_debug("RH-Side was: (%s/%s)", + order->rh_rsc?order->rh_rsc->id:order->rh_action?order->rh_action->rsc->id:"", + task2text(order->rh_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); + switch(order->rh_action_task) { + case start_rsc: + case started_rsc: + case stop_rsc: + case stopped_rsc: + break; + default: + crm_err("Task \"%s\" from ordering %d isnt a resource action", + task2text(order->rh_action_task), order->id); + return; + } + if(rh_action != NULL) { rh_actions = g_list_append(NULL, rh_action); } else if(rh_action == NULL && rsc != NULL) { rh_actions = find_actions( rsc->actions, order->rh_action_task, NULL); if(rh_actions == NULL) { crm_debug("No RH-Side (%s/%s) found for constraint..." " ignoring", rsc->id, task2text(order->rh_action_task)); + crm_debug("LH-Side was: (%s/%s)", + order->lh_rsc?order->lh_rsc->id:order->lh_action?order->lh_action->rsc->id:"", + task2text(order->lh_action_task)); return; } } else if(rh_action == NULL) { crm_debug("No RH-Side (%s) specified for constraint..." " ignoring", task2text(order->rh_action_task)); + crm_debug("LH-Side was: (%s/%s)", + order->lh_rsc?order->lh_rsc->id:order->lh_action?order->lh_action->rsc->id:"", + task2text(order->lh_action_task)); return; } slist_iter( rh_action_iter, action_t, rh_actions, lpc, order_actions(lh_action, rh_action_iter, order); ); pe_free_shallow_adv(rh_actions, FALSE); } void native_rsc_location(resource_t *rsc, rsc_to_node_t *constraint) { int lpc; GListPtr or_list; native_variant_data_t *native_data = NULL; 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; } else if(rsc == NULL) { crm_err("LHS of rsc_to_node (%s) is NULL", constraint->id); return; } get_native_variant_data(native_data, rsc); native_data->node_cons = g_list_append(native_data->node_cons, constraint); if(constraint->node_list_rh == NULL) { crm_err("RHS of constraint %s is NULL", constraint->id); return; } crm_debug_action(print_resource("before update", rsc,TRUE)); or_list = node_list_or( native_data->allowed_nodes, constraint->node_list_rh, FALSE); pe_free_shallow(native_data->allowed_nodes); native_data->allowed_nodes = or_list; slist_iter(node_rh, node_t, constraint->node_list_rh, lpc, native_update_node_weight( rsc, constraint, node_rh->details->uname, native_data->allowed_nodes)); crm_debug_action(print_resource("after update", rsc, 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) { native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); 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(native_data->allowed_nodes), g_list_length(rsc->rsc_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, 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(native_data->allowed_nodes); 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 = NULL; native_variant_data_t *native_data_rh = NULL; gboolean do_merge = FALSE; GListPtr old_list = NULL; GListPtr merged_node_list = NULL; float max_pri = rsc_lh->effective_priority; if(max_pri < rsc_rh->effective_priority) { max_pri = rsc_rh->effective_priority; } rsc_lh->effective_priority = max_pri; rsc_rh->effective_priority = max_pri; get_native_variant_data(native_data_lh, rsc_lh); get_native_variant_data(native_data_rh, rsc_rh); if(native_data_lh->color && native_data_rh->color) { do_merge = TRUE; merged_node_list = node_list_and( native_data_lh->color->details->candidate_nodes, native_data_rh->color->details->candidate_nodes, TRUE); } else if(native_data_lh->color) { do_merge = TRUE; merged_node_list = node_list_and( native_data_lh->color->details->candidate_nodes, native_data_rh->allowed_nodes, TRUE); } else if(native_data_rh->color) { do_merge = TRUE; merged_node_list = node_list_and( native_data_lh->allowed_nodes, native_data_rh->color->details->candidate_nodes, TRUE); } if(update_lh) { crm_free(native_data_lh->color); rsc_lh->runnable = rsc_rh->runnable; native_data_lh->color = copy_color(native_data_rh->color); } if(update_rh) { crm_free(native_data_rh->color); rsc_rh->runnable = rsc_lh->runnable; native_data_rh->color = copy_color(native_data_lh->color); } if(do_merge) { crm_debug("Merging candidate nodes"); old_list = native_data_rh->color->details->candidate_nodes; native_data_rh->color->details->candidate_nodes = merged_node_list; pe_free_shallow(old_list); } crm_debug("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 = NULL; native_variant_data_t *native_data_rh = NULL; get_native_variant_data(native_data_lh, rsc_lh); get_native_variant_data(native_data_rh, rsc_rh); crm_debug("Processing pecs_must_not constraint"); /* pecs_must_not */ if(update_lh) { color_rh = native_data_rh->color; if(rsc_lh->provisional) { color_lh = find_color( rsc_lh->candidate_colors, color_rh); rsc_lh->candidate_colors = g_list_remove( rsc_lh->candidate_colors, color_lh); crm_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(native_data_lh->color && native_data_lh->color->details->pending) { node_t *node_lh = NULL; color_lh = native_data_lh->color; node_lh = pe_find_node( color_lh->details->candidate_nodes, safe_val5(NULL, color_rh, details, chosen_node, details, uname)); color_lh->details->candidate_nodes = g_list_remove( color_lh->details->candidate_nodes, node_lh); crm_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 = 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(native_data_rh->color && native_data_rh->color->details->pending) { node_t *node_rh = NULL; color_rh = native_data_rh->color; node_rh = pe_find_node( color_rh->details->candidate_nodes, safe_val5(NULL, color_lh, details, chosen_node, details, uname)); color_rh->details->candidate_nodes = g_list_remove( color_rh->details->candidate_nodes, node_rh); crm_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 = NULL; get_native_variant_data(native_data, rsc); 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; + common_agent_constraints( + native_data->allowed_nodes, native_data->agent, rsc->id); } gboolean native_choose_color(resource_t *rsc) { int lpc = 0; GListPtr sorted_colors = NULL; native_variant_data_t *native_data = NULL; get_native_variant_data_boolean(native_data, rsc); if(rsc->runnable == FALSE) { native_assign_color(rsc, no_color); } if(rsc->provisional == FALSE) { return !rsc->provisional; } sorted_colors = g_list_sort( rsc->candidate_colors, sort_color_weight); rsc->candidate_colors = sorted_colors; crm_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; } void native_assign_color(resource_t *rsc, color_t *color) { color_t *local_color = add_color(rsc, color); GListPtr intersection = NULL; GListPtr old_list = NULL; native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); native_data->color = local_color; rsc->provisional = FALSE; if(local_color != NULL) { local_color->details->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)); } else { crm_err("local color was NULL"); } return; } void native_update_node_weight(resource_t *rsc, rsc_to_node_t *cons, const char *id, GListPtr nodes) { node_t *node_rh = NULL; native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); node_rh = pe_find_node(native_data->allowed_nodes, id); if(node_rh == NULL) { crm_err("Node not found - cant update"); return; } 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; } 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; } gboolean native_constraint_violated( resource_t *rsc_lh, resource_t *rsc_rh, rsc_dependancy_t *constraint) { native_variant_data_t *native_data_lh = NULL; native_variant_data_t *native_data_rh = NULL; GListPtr result = NULL; color_t *color_lh = NULL; color_t *color_rh = NULL; GListPtr candidate_nodes_lh = NULL; GListPtr candidate_nodes_rh = NULL; gboolean matched = FALSE; get_native_variant_data_boolean(native_data_lh, rsc_lh); get_native_variant_data_boolean(native_data_rh, rsc_rh); color_lh = native_data_lh->color; color_rh = native_data_rh->color; if(constraint->strength == pecs_must_not) { matched = TRUE; } if(rsc_lh->provisional || rsc_rh->provisional) { return FALSE; } if(color_lh->details->pending && color_rh->details->pending) { candidate_nodes_lh = color_lh->details->candidate_nodes; candidate_nodes_rh = color_rh->details->candidate_nodes; } else if(color_lh->details->pending == FALSE && color_rh->details->pending == FALSE) { if(color_lh == NULL && color_rh == NULL) { return matched; } else if(color_lh == NULL || color_rh == NULL) { return !matched; } else if(color_lh->details->chosen_node == NULL && color_rh->details->chosen_node == NULL) { return matched; } else if(color_lh->details->chosen_node == NULL || color_rh->details->chosen_node == NULL) { return !matched; } else if(safe_str_eq( color_lh->details->chosen_node->details->id, color_rh->details->chosen_node->details->id)) { return matched; } return !matched; } else if(color_lh->details->pending) { candidate_nodes_lh = color_lh->details->candidate_nodes; candidate_nodes_rh = g_list_append( NULL, color_rh->details->chosen_node); } else if(color_rh->details->pending) { candidate_nodes_rh = color_rh->details->candidate_nodes; candidate_nodes_lh = g_list_append( NULL, color_lh->details->chosen_node); } result = node_list_and(candidate_nodes_lh, candidate_nodes_rh, TRUE); if(g_list_length(result) == 0 && constraint->strength == pecs_must) { /* free result */ return TRUE; } return FALSE; } /* * Remove any nodes with a -ve weight */ void filter_nodes(resource_t *rsc) { int lpc2 = 0; native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); 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 */ } ); } diff --git a/crm/pengine/pe_utils.h b/crm/pengine/pe_utils.h index 52f725ca42..0777de7fe4 100644 --- a/crm/pengine/pe_utils.h +++ b/crm/pengine/pe_utils.h @@ -1,126 +1,129 @@ -/* $Id: pe_utils.h,v 1.16 2004/11/09 14:49:14 andrew Exp $ */ +/* $Id: pe_utils.h,v 1.17 2004/11/11 14:51:26 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 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( GListPtr input, enum action_tasks task, node_t *on_node); +extern void set_id(xmlNodePtr xml_obj, const char *prefix, int child); + + /* 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 40d7d437ab..517f32d33c 100644 --- a/crm/pengine/pengine.h +++ b/crm/pengine/pengine.h @@ -1,329 +1,334 @@ -/* $Id: pengine.h,v 1.40 2004/11/09 14:49:14 andrew Exp $ */ +/* $Id: pengine.h,v 1.41 2004/11/11 14:51:26 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, + stopped_rsc, start_rsc, + started_rsc, shutdown_crm, stonith_node }; enum rsc_recovery_type { recovery_stop_start, recovery_stop_only, recovery_block }; enum pe_stop_fail { pesf_block, pesf_stonith, pesf_ignore }; enum pe_restart { pe_restart_restart, pe_restart_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; + gboolean starting; + gboolean stopping; 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 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; }; 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 pseudo; 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/regression.sh b/crm/pengine/regression.sh index b7ee22ee5c..9b0c5835b8 100755 --- a/crm/pengine/regression.sh +++ b/crm/pengine/regression.sh @@ -1,122 +1,129 @@ #!/bin/bash # 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 # . regression.core.sh create_mode="true" echo Generating test outputs for these tests... -#do_test bad7 "Bad data" +#do_test bad7 +do_test inc3 echo "" echo Done. echo "" echo Performing the following tests... create_mode="false" do_test simple1 "Offline " do_test simple2 "Start " do_test simple3 "Start 2 " do_test simple4 "Start Failed" do_test simple6 "Stop Start " do_test simple7 "Shutdown " #do_test simple8 "Stonith " do_test simple9 "Lower version" do_test simple10 "Higher version" do_test simple11 "Priority (ne)" do_test simple12 "Priority (eq)" echo "" do_test rsc_dep1 "Must not " #do_test rsc_dep2 "Should not " do_test rsc_dep3 "Must " #do_test rsc_dep4 "Should " do_test rsc_dep5 "Must not 3 " #do_test rsc_dep6 "Should not 3" do_test rsc_dep7 "Must 3 " #do_test rsc_dep8 "Should 3 " do_test rsc_dep10 "Must (cant)" #do_test rsc_dep9 "2*MustNot 1*ShouldNot" echo "" do_test order1 "Order start 1" do_test order2 "Order start 2" do_test order3 "Order stop " +do_test order4 "Order (multiple)" echo "" do_test agent1 "version: lt (empty)" do_test agent2 "version: eq " do_test agent3 "version: gt " echo "" do_test attrs1 "string: eq (and) " do_test attrs2 "string: lt / gt (and)" do_test attrs3 "string: ne (or) " do_test attrs4 "string: exists " do_test attrs5 "string: notexists " echo "" do_test nodefail1 "Node Fail - Fence " do_test nodefail5 "Node Fail - Fence2Block" do_test nodefail4 "Node Fail - Block&Fence" do_test nodefail2 "Node Fail - Block " do_test nodefail3 "Node Fail - Ignore " echo "" do_test stopfail1 "Stop Fail - Disabled " do_test stopfail9 "Stop Fail - Enabled, 1 node" do_test stopfail2 "Stop Fail - Enabled, 2 node" do_test stopfail3 "Stop Fail - Ignore (1 node)" do_test stopfail4 "Stop Fail - Ignore (2 node)" #do_test stopfail5 "Stop Fail - STONITH (pass2) " #do_test stopfail6 "Stop Fail - STONITH (pass3) " #do_test stopfail7 "Stop Fail - STONITH (should fail)" echo "" do_test rsc_location1 "Score (not running) " do_test rsc_location2 "Score (running) " do_test rsc_location3 "Score (not running/no swap)" do_test rsc_location4 "Score (running/swap) " do_test rsc_location5 "Score (running/swap 2) " echo "" do_test multi1 "Multiple Active (stop/start)" #echo "" #do_test complex1 "Complex " echo "" -do_test group1 "Group " -do_test group2 "Group + Native" -do_test group3 "Group + Group" +do_test group1 "Group " +do_test group2 "Group + Native " +do_test group3 "Group + Group " do_test group4 "Group + Native (nothing)" -do_test group5 "Group + Native (stop)" +do_test group5 "Group + Native (move)" +do_test group6 "Group + Group (move)" +echo "" +do_test inc1 "Incarnation start " +do_test inc2 "Incarnation silent restart, stop, move " +do_test inc3 "Inter-incarnation ordering, silent restart, stop, move" echo "" do_test bad1 "Bad node " do_test bad2 "Bad rsc " do_test bad3 "No rsc class " do_test bad4 "Bad data " do_test bad5 "Bad data " do_test bad6 "Bad lrm_rsc " do_test bad7 "No lrm " echo "" test_results diff --git a/crm/pengine/testcases/group1.exp b/crm/pengine/testcases/group1.exp index b6ed07f949..cb776fd444 100644 --- a/crm/pengine/testcases/group1.exp +++ b/crm/pengine/testcases/group1.exp @@ -1,40 +1,66 @@ - - + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - + + - + diff --git a/crm/pengine/testcases/group2.exp b/crm/pengine/testcases/group2.exp index f7fb7cb2c4..6f333b62e0 100644 --- a/crm/pengine/testcases/group2.exp +++ b/crm/pengine/testcases/group2.exp @@ -1,66 +1,92 @@ - - + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - + + - + - + - + diff --git a/crm/pengine/testcases/group3.exp b/crm/pengine/testcases/group3.exp new file mode 100644 index 0000000000..499157c11b --- /dev/null +++ b/crm/pengine/testcases/group3.exp @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/crm/pengine/testcases/group4.xml b/crm/pengine/testcases/group4.xml index 48855b1195..e4bd31661f 100644 --- a/crm/pengine/testcases/group4.xml +++ b/crm/pengine/testcases/group4.xml @@ -1,62 +1,62 @@ - - - + + + diff --git a/crm/pengine/testcases/group5.exp b/crm/pengine/testcases/group5.exp index 26fb630ec0..5586beb1b5 100644 --- a/crm/pengine/testcases/group5.exp +++ b/crm/pengine/testcases/group5.exp @@ -1,143 +1,198 @@ - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - + + - + - + - - + + - + - - + + - + - + - - + + - + - - + + - + - + - + - + - + - + diff --git a/crm/pengine/testcases/group5.xml b/crm/pengine/testcases/group5.xml index de217ecadc..104727f9de 100644 --- a/crm/pengine/testcases/group5.xml +++ b/crm/pengine/testcases/group5.xml @@ -1,62 +1,62 @@ - - - + + + diff --git a/crm/pengine/testcases/group6.exp b/crm/pengine/testcases/group6.exp new file mode 100644 index 0000000000..899bb8eeb9 --- /dev/null +++ b/crm/pengine/testcases/group6.exp @@ -0,0 +1,282 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/crm/pengine/testcases/group4.xml b/crm/pengine/testcases/group6.xml similarity index 60% copy from crm/pengine/testcases/group4.xml copy to crm/pengine/testcases/group6.xml index 48855b1195..dedc519c9b 100644 --- a/crm/pengine/testcases/group4.xml +++ b/crm/pengine/testcases/group6.xml @@ -1,62 +1,60 @@ - - + - + + + + + - - - - - - - + + + + + + + + - - - - - - - + diff --git a/crm/pengine/testcases/inc1.exp b/crm/pengine/testcases/inc1.exp new file mode 100644 index 0000000000..b534e63ff7 --- /dev/null +++ b/crm/pengine/testcases/inc1.exp @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/crm/pengine/testcases/inc1.xml b/crm/pengine/testcases/inc1.xml new file mode 100644 index 0000000000..0585b1ca42 --- /dev/null +++ b/crm/pengine/testcases/inc1.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/crm/pengine/testcases/inc2.exp b/crm/pengine/testcases/inc2.exp new file mode 100644 index 0000000000..7d9bc41bf0 --- /dev/null +++ b/crm/pengine/testcases/inc2.exp @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/crm/pengine/testcases/inc2.xml b/crm/pengine/testcases/inc2.xml new file mode 100644 index 0000000000..fadde14243 --- /dev/null +++ b/crm/pengine/testcases/inc2.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/crm/pengine/testcases/inc3.exp b/crm/pengine/testcases/inc3.exp new file mode 100644 index 0000000000..3404e024e9 --- /dev/null +++ b/crm/pengine/testcases/inc3.exp @@ -0,0 +1,240 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/crm/pengine/testcases/inc3.xml b/crm/pengine/testcases/inc3.xml new file mode 100644 index 0000000000..60f9a5cd13 --- /dev/null +++ b/crm/pengine/testcases/inc3.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/crm/pengine/testcases/order4.exp b/crm/pengine/testcases/order4.exp new file mode 100644 index 0000000000..cd6d30204d --- /dev/null +++ b/crm/pengine/testcases/order4.exp @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/crm/pengine/testcases/order4.xml b/crm/pengine/testcases/order4.xml new file mode 100644 index 0000000000..9f274a65be --- /dev/null +++ b/crm/pengine/testcases/order4.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/crm/pengine/utils.c b/crm/pengine/utils.c index e7e8940e84..61fb6f46a5 100644 --- a/crm/pengine/utils.c +++ b/crm/pengine/utils.c @@ -1,1072 +1,1128 @@ -/* $Id: utils.c,v 1.47 2004/11/09 17:51:59 andrew Exp $ */ +/* $Id: utils.c,v 1.48 2004/11/11 14:51:26 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 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(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; } resource_t * pe_find_resource(GListPtr rsc_list, const char *id) { int lpc = 0; resource_t *rsc = NULL; resource_t *child_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)){ crm_debug("Found a match for %s", id); return rsc; } } for(lpc = 0; lpc < g_list_length(rsc_list); lpc++) { rsc = g_list_nth_data(rsc_list, lpc); child_rsc = rsc->fns->find_child(rsc, id); if(child_rsc != NULL) { crm_debug("Found a match for %s in %s", id, rsc->id); return child_rsc; } } /* error */ return NULL; } node_t * pe_find_node(GListPtr nodes, const char *uname) { 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(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->pseudo = FALSE; action->dumped = FALSE; action->discard = FALSE; action->runnable = TRUE; action->processed = FALSE; action->optional = FALSE; action->seen_count = 0; action->timeout = NULL; action->args = create_xml_node(NULL, "args"); if(rsc != NULL) { crm_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); } + if(task == start_rsc) { + rsc->starting = TRUE; + } + if(task == stop_rsc) { + rsc->stopping = TRUE; + } } } 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 stopped_rsc: + result = "stopped"; + break; case start_rsc: result = "start"; break; + case started_rsc: + result = "started"; + 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); } 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_debug("Freeing constraint %s (%p)", cons->id, cons); crm_free(cons); } } void pe_free_rsc_to_node(rsc_to_node_t *cons) { if(cons != NULL) { /* right now we dont make copies so this isnt required */ /* pe_free_shallow(cons->node_list_rh); */ /* node_t* */ crm_free(cons); } } GListPtr 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; } +void +set_id(xmlNodePtr xml_obj, const char *prefix, int child) +{ + int id_len = 0; + gboolean use_prefix = TRUE; + gboolean use_child = TRUE; + + char *new_id = NULL; + const char *id = xmlGetProp(xml_obj, "id"); + + id_len = 1 + strlen(id); + + if(child > 999) { + crm_err("Are you insane?!?" + " The CRM does not support > 1000 children per resource"); + return; + + } else if(child < 0) { + use_child = FALSE; + + } else { + id_len += 4; /* child */ + } + + if(prefix == NULL || safe_str_eq(id, prefix)) { + use_prefix = FALSE; + } else { + id_len += (1 + strlen(prefix)); + } + + crm_malloc(new_id, id_len); + + if(use_child) { + snprintf(new_id, id_len, "%s%s%s:%d", + use_prefix?prefix:"", use_prefix?":":"", id, child); + } else { + snprintf(new_id, id_len, "%s%s%s", + use_prefix?prefix:"", use_prefix?":":"", id); + } + + set_xml_property_copy(xml_obj, "id", new_id); + crm_free(new_id); +}