diff --git a/crm/pengine/Makefile.am b/crm/pengine/Makefile.am index ff82a2d5c4..db526cc383 100644 --- a/crm/pengine/Makefile.am +++ b/crm/pengine/Makefile.am @@ -1,83 +1,85 @@ # # 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 +noinst_HEADERS = pe_utils.h pengine.h complex.h -ptest_SOURCES = pengine.c stages.c unpack.c color.c graph.c utils.c ptest.c +ptest_SOURCES = pengine.c stages.c unpack.c color.c graph.c utils.c ptest.c \ + complex.c native.c ptest_CFLAGS = $(XML_FLAGS) -DHA_VARLIBDIR='"@HA_VARLIBDIR@"' ptest_LDFLAGS = $(XML_LIBS) ptest_LDADD = $(COMMONLIBS) -pengine_SOURCES = pengine.c stages.c unpack.c color.c graph.c utils.c main.c +pengine_SOURCES = pengine.c stages.c unpack.c color.c graph.c utils.c main.c \ + complex.c native.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 ec7bc3726d..8dfa037676 100644 --- a/crm/pengine/color.c +++ b/crm/pengine/color.c @@ -1,624 +1,380 @@ -/* $Id: color.c,v 1.18 2004/10/27 15:30:55 andrew Exp $ */ +/* $Id: color.c,v 1.19 2004/11/09 09:32:14 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include color_t *no_color = NULL; color_t *add_color(resource_t *rh_resource, color_t *color); gboolean has_agent(node_t *a_node, lrm_agent_t *agent); -gboolean update_node_weight(rsc_to_node_t *cons,const char *id,GListPtr nodes); - -gboolean rsc_preproc( - resource_t *lh_resource, GListPtr *colors, GListPtr resources); - -gboolean rsc_postproc( - resource_t *lh_resource, GListPtr *colors, GListPtr resources); - -gboolean strict_postproc(rsc_to_rsc_t *constraint, - GListPtr *colors, - GListPtr resources); - -gboolean strict_preproc(rsc_to_rsc_t *constraint, - GListPtr *colors, - GListPtr resources); - -gboolean is_active(rsc_to_node_t *cons); - gboolean choose_color(resource_t *lh_resource); gboolean assign_color(resource_t *rsc, color_t *color); gboolean apply_placement_constraints(GListPtr constraints, GListPtr nodes) { int lpc = 0; - int llpc = 0; - resource_t *rsc_lh = NULL; - GListPtr or_list = NULL; crm_verbose("Applying constraints..."); slist_iter( cons, rsc_to_node_t, constraints, lpc, - crm_debug_action(print_rsc_to_node("Applying", cons, FALSE)); - /* take "lifetime" into account */ - if(cons == NULL) { - crm_err("Constraint (%d) is NULL", lpc); - continue; - - } else if(is_active(cons) == FALSE) { - crm_info("Constraint (%d) is not active", lpc); - /* warning */ - continue; - } - - rsc_lh = cons->rsc_lh; - if(rsc_lh == NULL) { - crm_err("LHS of rsc_to_node (%s) is NULL", cons->id); - continue; - } - - cons->rsc_lh->node_cons = - g_list_append(cons->rsc_lh->node_cons, cons); - - if(cons->node_list_rh == NULL) { - crm_err("RHS of constraint %s is NULL", cons->id); - continue; - } - crm_debug_action(print_resource("before update", rsc_lh,TRUE)); - llpc = 0; - or_list = node_list_or( - rsc_lh->allowed_nodes, cons->node_list_rh, FALSE); - - pe_free_shallow(rsc_lh->allowed_nodes); - rsc_lh->allowed_nodes = or_list; - slist_iter(node_rh, node_t, cons->node_list_rh, llpc, - update_node_weight(cons, node_rh->details->uname, - rsc_lh->allowed_nodes)); - - crm_debug_action(print_resource("after update", rsc_lh, TRUE)); + cons->rsc_lh->fns->rsc_location(cons); ); return TRUE; } gboolean apply_agent_constraints(GListPtr resources) { int lpc; int lpc2; slist_iter( rsc, resource_t, resources, lpc, crm_trace("Applying RA restrictions to %s", rsc->id); slist_iter( node, node_t, rsc->allowed_nodes, lpc2, crm_trace("Checking if %s supports %s/%s (%s)", node->details->uname, rsc->agent->class, rsc->agent->type, rsc->agent->version); if(has_agent(node, rsc->agent) == FALSE) { /* remove node from contention */ crm_trace("Marking node %s unavailable for %s", node->details->uname, rsc->id); node->weight = -1.0; node->fixed = TRUE; } if(node->fixed && node->weight < 0) { /* the structure of the list will have changed * lpc2-- might be sufficient */ crm_debug("Removing node %s from %s", node->details->uname, rsc->id); lpc2 = -1; rsc->allowed_nodes = g_list_remove( rsc->allowed_nodes, node); crm_free(node); } ) ); crm_trace("Finished applying RA restrictions"); return TRUE; } gboolean has_agent(node_t *a_node, lrm_agent_t *an_agent) { int lpc; if(a_node == NULL || an_agent == NULL || an_agent->type == NULL) { crm_warn("Invalid inputs"); return FALSE; } crm_devel("Checking %d agents on %s", g_list_length(a_node->details->agents), a_node->details->uname); slist_iter( agent, lrm_agent_t, a_node->details->agents, lpc, crm_trace("Checking against %s/%s (%s)", agent->class, agent->type, agent->version); if(safe_str_eq(an_agent->type, agent->type)){ if(an_agent->class == NULL) { return TRUE; } else if(safe_str_eq(an_agent->class, agent->class)) { if(compare_version( an_agent->version, agent->version) <= 0) { return TRUE; } } } ); crm_verbose("%s doesnt support version %s of %s/%s", a_node->details->uname, an_agent->version, an_agent->class, an_agent->type); return FALSE; } -gboolean -is_active(rsc_to_node_t *cons) -{ - /* todo: check constraint lifetime */ - return TRUE; -} - - -gboolean -strict_preproc(rsc_to_rsc_t *constraint, GListPtr *colors, GListPtr resources) -{ - resource_t *lh_resource = constraint->rsc_lh; - resource_t *rh_resource = constraint->rsc_rh; - - color_t *local_color = NULL; - - float max_pri = lh_resource->effective_priority; - - switch(constraint->strength) { - case pecs_ignore: - break; - case pecs_startstop: - break; - case pecs_must: - if(max_pri < rh_resource->effective_priority) { - max_pri = rh_resource->effective_priority; - } - lh_resource->effective_priority = max_pri; - rh_resource->effective_priority = max_pri; - break; - - case pecs_must_not: - if(constraint->variant != same_node) { - break; - } else if(constraint->rsc_rh->provisional) { - break; - } else if(local_color != NULL) { - lh_resource->candidate_colors = g_list_remove( - lh_resource->candidate_colors, local_color); - - crm_debug_action( - print_color( - "Removed",local_color,FALSE)); - - crm_free(local_color); - } - break; - } - return TRUE; -} - -gboolean -strict_postproc(rsc_to_rsc_t *constraint, GListPtr *colors, GListPtr resources) -{ - print_rsc_to_rsc("Post processing", constraint, FALSE); - - switch(constraint->strength) { - case pecs_ignore: - case pecs_startstop: - break; - - case pecs_must: - if(constraint->rsc_lh->runnable == FALSE) { - crm_warn("Resource %s must run on the same" - " node as %s (cons %s), but %s is not" - " runnable.", - constraint->rsc_rh->id, - constraint->rsc_lh->id, - constraint->id, - constraint->rsc_lh->id); - constraint->rsc_rh->runnable = FALSE; - - } else if(constraint->variant != same_node) { - break; - - } else if(constraint->rsc_rh->provisional == TRUE) { - - - resource_t *rh_resource = constraint->rsc_rh; - assign_color(rh_resource, constraint->rsc_lh->color); - color_resource(rh_resource, colors, resources); - - } else if(constraint->rsc_rh->provisional == FALSE - && constraint->rsc_rh->color->id != - constraint->rsc_lh->color->id) { - crm_err("Resource %s must run on the same" - " node as %s (cons %s), but %s is already" - " assigned to another color.", - constraint->rsc_rh->id, - constraint->rsc_lh->id, - constraint->id, - constraint->rsc_lh->id); - constraint->rsc_lh->runnable = FALSE; - return FALSE; - } - break; - - case pecs_must_not: - if(constraint->rsc_rh->provisional == FALSE - && constraint->rsc_rh->color->id == - constraint->rsc_lh->color->id) { - crm_err("Resource %s must run on the same" - " node as %s (cons %s), but %s is already" - " assigned to another color.", - constraint->rsc_rh->id, - constraint->rsc_lh->id, - constraint->id, - constraint->rsc_lh->id); - constraint->rsc_lh->runnable = FALSE; - return FALSE; - } - break; - } - 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; } gboolean choose_color(resource_t *lh_resource) { int lpc = 0; GListPtr sorted_colors = NULL; if(lh_resource->runnable == FALSE) { assign_color(lh_resource, no_color); } if(lh_resource->provisional == FALSE) { return !lh_resource->provisional; } sorted_colors = g_list_sort( lh_resource->candidate_colors, sort_color_weight); lh_resource->candidate_colors = sorted_colors; crm_verbose("Choose a color from %d possibilities", g_list_length(sorted_colors)); slist_iter( this_color, color_t, lh_resource->candidate_colors, lpc, GListPtr intersection = NULL; GListPtr minus = NULL; int len = 0; if(this_color == NULL) { crm_err("color was NULL"); continue; } else if(lh_resource->effective_priority < this_color->details->highest_priority) { minus = node_list_minus( this_color->details->candidate_nodes, lh_resource->allowed_nodes, TRUE); len = g_list_length(minus); pe_free_shallow(minus); if(len > 0) { assign_color(lh_resource, this_color); break; } } else { intersection = node_list_and( this_color->details->candidate_nodes, lh_resource->allowed_nodes, TRUE); len = g_list_length(intersection); pe_free_shallow(intersection); if(len != 0) { assign_color(lh_resource, this_color); break; } } ); return !lh_resource->provisional; } -gboolean -rsc_preproc(resource_t *lh_resource, GListPtr *colors, GListPtr resources) -{ - int lpc = 0; - slist_iter( - constraint, rsc_to_rsc_t, lh_resource->rsc_cons, lpc, - - crm_debug_action( - print_rsc_to_rsc( - "Processing constraint",constraint,FALSE)); - - if(constraint->rsc_rh == NULL) { - crm_err("rsc_rh was NULL for %s", constraint->id); - continue; - } - - strict_preproc(constraint, colors, resources); - ); - - return TRUE; -} - -gboolean -rsc_postproc(resource_t *lh_resource, GListPtr *colors, GListPtr resources) -{ - int lpc = 0; - slist_iter( - constraint, rsc_to_rsc_t, lh_resource->rsc_cons, lpc, - strict_postproc(constraint, colors, resources); - ); - - return TRUE; -} - void color_resource(resource_t *lh_resource, GListPtr *colors, GListPtr resources) { - color_t *new_color = NULL; + int lpc = 0; crm_debug_action(print_resource("Coloring", lh_resource, FALSE)); if(lh_resource->provisional == FALSE) { /* already processed this resource */ return; } lh_resource->rsc_cons = g_list_sort( lh_resource->rsc_cons, sort_cons_strength); crm_debug_action( print_resource("Pre-processing", lh_resource, FALSE)); /*------ Pre-processing */ - rsc_preproc(lh_resource, colors, resources); + slist_iter( + constraint, rsc_dependancy_t, lh_resource->rsc_cons, lpc, + + crm_debug_action( + print_rsc_dependancy( + "Pre-Processing constraint", constraint,FALSE)); + + if(constraint->rsc_rh == NULL) { + crm_err("rsc_rh was NULL for %s", constraint->id); + continue; + } + lh_resource->fns->rsc_dependancy_lh(constraint); + ); /* avoid looping through lists when we know this resource * cant be started */ - if( choose_color(lh_resource) ) { - crm_verbose("Colored resource %s with color %d", - lh_resource->id, lh_resource->color->id); - - } else if(lh_resource->allowed_nodes != NULL) { - /* filter out nodes with a negative weight */ - filter_nodes(lh_resource); - new_color = create_color(colors, lh_resource, NULL); - assign_color(lh_resource, new_color); - } - - if(lh_resource->color == NULL) { - crm_err("Could not color resource %s", lh_resource->id); - print_resource("ERROR: No color", lh_resource, FALSE); - assign_color(lh_resource, no_color); - - } else { - - } - lh_resource->provisional = FALSE; + lh_resource->fns->color(lh_resource, colors); crm_debug_action( - print_resource("Post-processing", lh_resource, FALSE)); + print_resource("Post-processing", lh_resource, TRUE)); /*------ Post-processing */ - rsc_postproc(lh_resource, colors, resources); + slist_iter( + constraint, rsc_dependancy_t, lh_resource->rsc_cons, lpc, + crm_debug_action( + print_rsc_dependancy( + "Post-Processing constraint",constraint,FALSE)); + lh_resource->fns->rsc_dependancy_lh(constraint); + ); - crm_debug_action(print_resource("Colored", lh_resource, FALSE)); + crm_debug_action(print_resource("Colored", lh_resource, TRUE)); } -gboolean -update_node_weight(rsc_to_node_t *cons, const char *id, GListPtr nodes) -{ - node_t *node_rh = pe_find_node(cons->rsc_lh->allowed_nodes, id); - - if(node_rh == NULL) { - crm_err("Node not found - cant update"); - return FALSE; - } - - if(node_rh->fixed) { - /* warning */ - crm_warn("Constraint %s is irrelevant as the" - " weight of node %s is fixed as %f.", - cons->id, - node_rh->details->uname, - node_rh->weight); - return TRUE; - } - - crm_verbose("Constraint %s (%s): node %s weight %f.", - cons->id, - cons->can?"can":"cannot", - node_rh->details->uname, - node_rh->weight); - - if(cons->can == FALSE) { - node_rh->weight = -1; - } else { - node_rh->weight += cons->weight; - } - - if(node_rh->weight < 0) { - node_rh->fixed = TRUE; - } - - crm_debug_action(print_node("Updated", node_rh, FALSE)); - - return TRUE; -} gboolean assign_color(resource_t *rsc, color_t *color) { color_t *local_color = add_color(rsc, color); GListPtr intersection = NULL; GListPtr old_list = NULL; - rsc->color = local_color; rsc->provisional = FALSE; if(local_color != NULL) { local_color->details->allocated_resources = g_list_append( local_color->details->allocated_resources,rsc); intersection = node_list_and( local_color->details->candidate_nodes, rsc->allowed_nodes, TRUE); - old_list = - local_color->details->candidate_nodes; + old_list = local_color->details->candidate_nodes; pe_free_shallow(old_list); local_color->details->candidate_nodes = intersection; + crm_verbose("Colored resource %s with new color %d", + rsc->id, rsc->color->id); + + crm_debug_action( + print_resource("Colored Resource", rsc, TRUE)); + return TRUE; + } else { + crm_err("local color was NULL"); } + return FALSE; } gboolean process_colored_constraints(resource_t *rsc) { int lpc = 0; color_t *other_c = NULL; node_t *other_n = NULL; if(rsc == NULL) { crm_err("No constraints for NULL resource"); return FALSE; } else { crm_debug("Processing constraints from %s", rsc->id); } slist_iter( - constraint, rsc_to_rsc_t, rsc->rsc_cons, lpc, - - if(constraint->variant != same_node) { - continue; - } + constraint, rsc_dependancy_t, rsc->rsc_cons, lpc, /* remove the node from the other color */ other_c = constraint->rsc_rh->color; other_n = pe_find_node( other_c->details->candidate_nodes, safe_val6(NULL, rsc, color, details, chosen_node, details, uname)); if(other_c == NULL) { crm_err("No color associated with %s", constraint->id); continue; } else if(other_n == NULL) { crm_err("No node associated with rsc/color %s/%d", rsc->id, rsc->color->id); continue; } switch(constraint->strength) { case pecs_must_not: other_c->details->candidate_nodes = g_list_remove( other_c->details->candidate_nodes, other_n); crm_free(other_n); break; default: break; } ); return TRUE; } diff --git a/crm/pengine/complex.c b/crm/pengine/complex.c new file mode 100644 index 0000000000..41295d378c --- /dev/null +++ b/crm/pengine/complex.c @@ -0,0 +1,232 @@ +/* $Id: complex.c,v 1.1 2004/11/09 09:32:14 andrew Exp $ */ +/* + * Copyright (C) 2004 Andrew Beekhof + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +gboolean update_node_weight(rsc_to_node_t *cons,const char *id,GListPtr nodes); +gboolean is_active(rsc_to_node_t *cons); +gboolean constraint_violated( + resource_t *rsc_lh, resource_t *rsc_rh, rsc_dependancy_t *constraint); +void order_actions(action_t *lh, action_t *rh, order_constraint_t *order); + + +resource_object_functions_t resource_class_functions[] = { + { + native_unpack, + native_color, + native_create_actions, + native_internal_ordering, + native_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_expand, */ +/* group_n_colors, */ +/* group_assign, */ +/* group_expand, */ +/* group_internal_constraints, */ +/* group_rsc_dependancy, */ +/* group_rsc_order, */ +/* group_rsc_location, */ +/* group_dump */ +/* }, */ +/* { */ +/* incarnation_expand, */ +/* incarnation_n_colors, */ +/* incarnation_assign, */ +/* incarnation_expand, */ +/* incarnation_internal_constraints, */ +/* incarnation_rsc_dependancy, */ +/* incarnation_rsc_order, */ +/* incarnation_rsc_location, */ +/* incarnation_dump */ +/* }, */ + +}; + +/* resource_object_functions_t resource_variants[] = resource_class_functions; */ + + +int get_resource_type(const char *name) +{ + if(safe_str_eq(name, "resource")) { + return pe_native; + } + return pe_unknown; +} + +gboolean +is_active(rsc_to_node_t *cons) +{ + /* todo: check constraint lifetime */ + return TRUE; +} + + +gboolean +update_node_weight(rsc_to_node_t *cons, const char *id, GListPtr nodes) +{ + node_t *node_rh = pe_find_node(cons->rsc_lh->allowed_nodes, id); + + if(node_rh == NULL) { + crm_err("Node not found - cant update"); + return FALSE; + } + + if(node_rh->fixed) { + /* warning */ + crm_warn("Constraint %s is irrelevant as the" + " weight of node %s is fixed as %f.", + cons->id, + node_rh->details->uname, + node_rh->weight); + return TRUE; + } + + crm_verbose("Constraint %s (%s): node %s weight %f.", + cons->id, + cons->can?"can":"cannot", + node_rh->details->uname, + node_rh->weight); + + if(cons->can == FALSE) { + node_rh->weight = -1; + } else { + node_rh->weight += cons->weight; + } + + if(node_rh->weight < 0) { + node_rh->fixed = TRUE; + } + + crm_debug_action(print_node("Updated", node_rh, FALSE)); + + return TRUE; +} + +gboolean +constraint_violated( + resource_t *rsc_lh, resource_t *rsc_rh, rsc_dependancy_t *constraint) +{ + GListPtr result = NULL; + color_t *color_lh = rsc_lh->color; + color_t *color_rh = rsc_rh->color; + + GListPtr candidate_nodes_lh = NULL; + GListPtr candidate_nodes_rh = NULL; + + gboolean matched = FALSE; + if(constraint->strength == pecs_must_not) { + matched = TRUE; + } + + if(rsc_lh->provisional || rsc_rh->provisional) { + return FALSE; + } + + if(color_lh->details->pending + && color_rh->details->pending) { + candidate_nodes_lh = color_lh->details->candidate_nodes; + candidate_nodes_rh = color_rh->details->candidate_nodes; + + } else if(color_lh->details->pending == FALSE + && color_rh->details->pending == FALSE) { + + if(color_lh == NULL && color_rh == NULL) { + return matched; + + } else if(color_lh == NULL || color_rh == NULL) { + return !matched; + + } else if(color_lh->details->chosen_node == NULL + && color_rh->details->chosen_node == NULL) { + return matched; + + } else if(color_lh->details->chosen_node == NULL + || color_rh->details->chosen_node == NULL) { + return !matched; + + } else if(safe_str_eq( + color_lh->details->chosen_node->details->id, + color_rh->details->chosen_node->details->id)) { + return matched; + } + return !matched; + + } else if(color_lh->details->pending) { + candidate_nodes_lh = color_lh->details->candidate_nodes; + candidate_nodes_rh = g_list_append( + NULL, color_rh->details->chosen_node); + + } else if(color_rh->details->pending) { + candidate_nodes_rh = color_rh->details->candidate_nodes; + candidate_nodes_lh = g_list_append( + NULL, color_lh->details->chosen_node); + } + + result = node_list_and(candidate_nodes_lh, candidate_nodes_rh, TRUE); + + if(g_list_length(result) == 0 && constraint->strength == pecs_must) { + /* free result */ + return TRUE; + } + return FALSE; +} + +void +order_actions(action_t *lh_action, action_t *rh_action, order_constraint_t *order) +{ + action_wrapper_t *wrapper = NULL; + GListPtr list = NULL; + + crm_verbose("%d Processing %d -> %d", + order->id, lh_action->id, rh_action->id); + + crm_debug_action( + print_action("LH (order_actions)", lh_action, FALSE)); + + crm_debug_action( + print_action("RH (order_actions)", rh_action, FALSE)); + + crm_malloc(wrapper, sizeof(action_wrapper_t)); + if(wrapper != NULL) { + wrapper->action = rh_action; + wrapper->strength = order->strength; + + list = lh_action->actions_after; + list = g_list_append(list, wrapper); + lh_action->actions_after = list; + } + + crm_malloc(wrapper, sizeof(action_wrapper_t)); + if(wrapper != NULL) { + wrapper->action = lh_action; + wrapper->strength = order->strength; + + list = rh_action->actions_before; + list = g_list_append(list, wrapper); + rh_action->actions_before = list; + } +} diff --git a/crm/pengine/complex.h b/crm/pengine/complex.h new file mode 100644 index 0000000000..c1292939b0 --- /dev/null +++ b/crm/pengine/complex.h @@ -0,0 +1,78 @@ +/* $Id: complex.h,v 1.1 2004/11/09 09:32:14 andrew Exp $ */ +/* + * Copyright (C) 2004 Andrew Beekhof + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#define n_object_classes 3 + +//#define PE_OBJ_F_ "" + +#define PE_OBJ_T_NATIVE "native" +#define PE_OBJ_T_GROUP "group" +#define PE_OBJ_T_INCARNATION "incarnation" + +enum pe_obj_types +{ + pe_native = 0, + pe_group = 1, + pe_incarnation = 2, + pe_unknown = -1 +}; + +extern int get_resource_type(const char *name); + +typedef struct resource_object_functions_s +{ + void (*unpack)(resource_t *); + void (*color)(resource_t *, GListPtr *); + void (*create_actions)(resource_t *); + void (*internal_ordering)(resource_t *, GListPtr *); + + void (*rsc_dependancy_lh)(rsc_dependancy_t *); + void (*rsc_dependancy_rh)(resource_t *, rsc_dependancy_t *); + + void (*rsc_order_lh)(order_constraint_t *); + void (*rsc_order_rh)(action_t *, order_constraint_t *); + + void (*rsc_location)(rsc_to_node_t *); + + void (*expand)(resource_t *, xmlNodePtr *); + void (*dump)(resource_t *, const char *, gboolean); + void (*free)(resource_t *); + +} resource_object_functions_t; + +extern void native_unpack(resource_t *rsc); +extern void native_color(resource_t *rsc, GListPtr *colors); +extern void native_create_actions(resource_t *rsc); +extern void native_internal_ordering( + resource_t *rsc, GListPtr *ordering_constraints); +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(order_constraint_t *order); +extern void native_rsc_order_rh(action_t *lh_action, order_constraint_t *order); +extern void native_rsc_location(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 resource_object_functions_t resource_variants[]; */ +extern resource_object_functions_t resource_class_functions[]; + diff --git a/crm/pengine/native.c b/crm/pengine/native.c new file mode 100644 index 0000000000..e2cde9a859 --- /dev/null +++ b/crm/pengine/native.c @@ -0,0 +1,701 @@ +/* $Id: native.c,v 1.1 2004/11/09 09:32:14 andrew Exp $ */ +/* + * Copyright (C) 2004 Andrew Beekhof + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include + +extern gboolean choose_color(resource_t *lh_resource); +extern gboolean assign_color(resource_t *rsc, color_t *color); +extern gboolean update_node_weight( + rsc_to_node_t *cons,const char *id,GListPtr nodes); +extern gboolean is_active(rsc_to_node_t *cons); +extern gboolean constraint_violated( + resource_t *rsc_lh, resource_t *rsc_rh, rsc_dependancy_t *constraint); +extern void order_actions(action_t *lh, action_t *rh, order_constraint_t *order); + +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 native_unpack(resource_t *rsc) +{ + xmlNodePtr xml_obj = rsc->xml; + + const char *stopfail = xmlGetProp(xml_obj, "on_stopfail"); + const char *restart = xmlGetProp(xml_obj, "restart_type"); + const char *timeout = xmlGetProp(xml_obj, "timeout"); + const char *version = xmlGetProp(xml_obj, XML_ATTR_VERSION); + const char *priority = xmlGetProp(xml_obj, XML_CIB_ATTR_PRIORITY); + + const char *max_instances = xmlGetProp(xml_obj, "max_instances"); + const char *max_node_instances = xmlGetProp(xml_obj, "max_node_instances"); + const char *max_masters = xmlGetProp(xml_obj, "max_masters"); + const char *max_node_masters = xmlGetProp(xml_obj, "max_node_masters"); + + crm_verbose("Processing resource..."); + + crm_malloc(rsc->agent, sizeof(lrm_agent_t)); + rsc->agent->class = xmlGetProp(xml_obj, "class"); + rsc->agent->type = xmlGetProp(xml_obj, "type"); + rsc->agent->version = version?version:"0.0"; + + rsc->priority = atoi(priority?priority:"0"); + rsc->effective_priority = rsc->priority; + rsc->recovery_type = recovery_stop_start; + + rsc->max_instances = atoi(max_instances?max_instances:"1"); + rsc->max_node_instances = atoi(max_node_instances?max_node_instances:"1"); + rsc->max_masters = atoi(max_masters?max_masters:"0"); + rsc->max_node_masters = atoi(max_node_masters?max_node_masters:"0"); + + rsc->candidate_colors = NULL; + rsc->actions = NULL; + rsc->color = NULL; + rsc->runnable = TRUE; + rsc->provisional = TRUE; + rsc->allowed_nodes = NULL; + rsc->rsc_cons = NULL; + rsc->node_cons = NULL; + rsc->running_on = NULL; + rsc->timeout = timeout; + + if(safe_str_eq(stopfail, "ignore")) { + rsc->stopfail_type = pesf_ignore; + } else if(safe_str_eq(stopfail, "stonith")) { + rsc->stopfail_type = pesf_stonith; + } else { + rsc->stopfail_type = pesf_block; + } + + if(safe_str_eq(restart, "restart")) { + rsc->restart_type = pe_restart_restart; + } else if(safe_str_eq(restart, "recover")) { + rsc->restart_type = pe_restart_recover; + } else { + rsc->restart_type = pe_restart_ignore; + } + +} + +void native_color(resource_t *rsc, GListPtr *colors) +{ + color_t *new_color = NULL; + if( choose_color(rsc) ) { + crm_verbose("Colored resource %s with color %d", + rsc->id, rsc->color->id); + + } else { + if(rsc->allowed_nodes != NULL) { + /* filter out nodes with a negative weight */ + filter_nodes(rsc); + new_color = create_color(colors, rsc, NULL); + assign_color(rsc, new_color); + } + + if(new_color == NULL) { + crm_err("Could not color resource %s", rsc->id); + print_resource("ERROR: No color", rsc, FALSE); + assign_color(rsc, no_color); + } + } + 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; + + if(rsc->color != NULL) { + chosen = rsc->color->details->chosen_node; + } + + if(chosen != NULL) { + can_start = TRUE; + } + + if(can_start && g_list_length(rsc->running_on) == 0) { + /* create start action */ + crm_info("Start resource %s (%s)", + rsc->id, + safe_val3(NULL, chosen, details, uname)); + start_op = action_new(rsc, start_rsc, chosen); + + } else if(g_list_length(rsc->running_on) > 1) { + crm_info("Attempting recovery of resource %s", + rsc->id); + + if(rsc->recovery_type == recovery_stop_start + || rsc->recovery_type == recovery_stop_only) { + slist_iter( + node, node_t, + rsc->running_on, lpc2, + + crm_info("Stop resource %s (%s)", + rsc->id, + safe_val3(NULL, node, details, uname)); + action_new(rsc, stop_rsc, node); + ); + } + + if(rsc->recovery_type == recovery_stop_start && can_start) { + crm_info("Start resource %s (%s)", + rsc->id, + safe_val3(NULL, chosen, details, uname)); + start_op = action_new( + rsc, start_rsc, chosen); + } + + } else { + /* stop and or possible restart */ + crm_debug("Stop and possible restart of %s", rsc->id); + + slist_iter( + node, node_t, rsc->running_on, lpc2, + + if(chosen != NULL && safe_str_eq( + node->details->id, + chosen->details->id)) { + /* restart */ + crm_info("Leave resource %s alone (%s)", rsc->id, + safe_val3(NULL, chosen, details, uname)); + + + /* in case the actions already exist */ + slist_iter( + action, action_t, rsc->actions, lpc3, + + if(action->task == start_rsc + || action->task == stop_rsc){ + action->optional = TRUE; + } + ); + + continue; + } else if(chosen != NULL) { + /* move */ + crm_info("Move resource %s (%s -> %s)", rsc->id, + safe_val3(NULL, node, details, uname), + safe_val3(NULL, chosen, details, uname)); + action_new(rsc, stop_rsc, node); + action_new(rsc, start_rsc, chosen); + + } else { + crm_info("Stop resource %s (%s)", rsc->id, + safe_val3(NULL, node, details, uname)); + action_new(rsc, stop_rsc, node); + } + + ); + } + +} + +void native_internal_ordering(resource_t *rsc, GListPtr *ordering_constraints) +{ + order_new(rsc, stop_rsc, NULL, rsc, start_rsc, NULL, + pecs_startstop, ordering_constraints); +} + +void native_rsc_dependancy_lh(rsc_dependancy_t *constraint) +{ + resource_t *rsc = constraint->rsc_lh; + + if(rsc == NULL) { + crm_err("No constraints for NULL resource"); + return; + } else { + crm_debug("Processing constraints from %s", rsc->id); + } + + constraint->rsc_rh->fns->rsc_dependancy_rh(rsc, constraint); +} + +void native_rsc_dependancy_rh(resource_t *rsc, rsc_dependancy_t *constraint) +{ + gboolean do_check = FALSE; + gboolean update_lh = FALSE; + gboolean update_rh = FALSE; + + resource_t *rsc_lh = rsc; + resource_t *rsc_rh = constraint->rsc_rh; + + crm_verbose("Processing RH of constraint %s", constraint->id); + crm_debug_action(print_resource("LHS", rsc_lh, TRUE)); + crm_debug_action(print_resource("RHS", rsc_rh, TRUE)); + + if(constraint->strength == pecs_ignore + || constraint->strength == pecs_startstop){ + crm_debug("Skipping constraint type %d", constraint->strength); + return; + } + + if(rsc_lh->provisional && rsc_rh->provisional) { + /* nothing */ + crm_debug("Skipping constraint, both sides provisional"); + return; + + } else if( (!rsc_lh->provisional) && (!rsc_rh->provisional) + && (!rsc_lh->color->details->pending) + && (!rsc_rh->color->details->pending) ) { + /* error check */ + do_check = TRUE; + if(rsc_lh->effective_priority < rsc_rh->effective_priority) { + update_lh = TRUE; + + } else if(rsc_lh->effective_priority + > rsc_rh->effective_priority) { + update_rh = TRUE; + + } else { + update_lh = TRUE; + update_rh = TRUE; + } + + } else if(rsc_lh->provisional == FALSE + && rsc_lh->color->details->pending == FALSE) { + /* update _us_ : postproc color version */ + update_rh = TRUE; + + } else if(rsc_rh->provisional == FALSE + && rsc_rh->color->details->pending == FALSE) { + /* update _them_ : postproc color alt version */ + update_lh = TRUE; + + } else if(rsc_lh->provisional == FALSE) { + /* update _us_ : preproc version */ + update_rh = TRUE; + + } else if(rsc_rh->provisional == FALSE) { + /* update _them_ : postproc version */ + update_lh = TRUE; + + } else { + crm_warn("Un-expected combination of inputs"); + return; + } + + + if(update_lh) { + crm_debug("Updating LHS"); + } + if(update_rh) { + crm_debug("Updating RHS"); + } + + if(do_check) { + if(constraint_violated(rsc_lh, rsc_rh, constraint) == FALSE) { + 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(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(lh_action != NULL) { + lh_actions = g_list_append(NULL, lh_action); + + } else if(lh_action == NULL && order->lh_rsc != NULL) { + if(order->strength == pecs_must) { + crm_debug("No LH-Side (%s/%s) found for constraint..." + " creating", + order->lh_rsc->id, + task2text(order->lh_action_task)); + + action_new(order->lh_rsc, order->lh_action_task, NULL); + } + + lh_actions = find_actions_type( + order->lh_rsc->actions, order->lh_action_task, NULL); + + if(lh_actions == NULL) { + crm_debug("No LH-Side (%s/%s) found for constraint", + order->lh_rsc->id, + task2text(order->lh_action_task)); + return; + } + + } else { + crm_warn("No LH-Side (%s) specified for constraint", + task2text(order->lh_action_task)); + return; + } + + slist_iter( + lh_action_iter, action_t, lh_actions, lpc, + + if(order->rh_rsc) { + order->rh_rsc->fns->rsc_order_rh(lh_action_iter, 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, order_constraint_t *order) +{ + int lpc; + GListPtr rh_actions = NULL; + action_t *rh_action = order->rh_action; + + crm_verbose("Processing RH of ordering constraint %d", order->id); + + if(rh_action != NULL) { + rh_actions = g_list_append(NULL, rh_action); + + } else if(rh_action == NULL && order->rh_rsc != NULL) { + rh_actions = find_actions_type( + order->rh_rsc->actions, order->rh_action_task, NULL); + + if(rh_actions == NULL) { + crm_debug("No RH-Side (%s/%s) found for constraint..." + " ignoring", + order->rh_rsc->id, + task2text(order->rh_action_task)); + return; + } + + } else if(rh_action == NULL) { + crm_debug("No RH-Side (%s) specified for constraint..." + " ignoring", task2text(order->rh_action_task)); + return; + } + + slist_iter( + rh_action_iter, action_t, rh_actions, lpc, + + order_actions(lh_action, rh_action_iter, order); + ); + + pe_free_shallow_adv(rh_actions, FALSE); +} + +void native_rsc_location(rsc_to_node_t *constraint) +{ + int lpc; + GListPtr or_list; + resource_t *rsc_lh = constraint->rsc_lh; + + crm_debug_action(print_rsc_to_node("Applying", constraint, FALSE)); + /* take "lifetime" into account */ + if(constraint == NULL) { + crm_err("Constraint is NULL"); + return; + + } else if(is_active(constraint) == FALSE) { + crm_info("Constraint (%s) is not active", constraint->id); + /* warning */ + return; + } + + rsc_lh = constraint->rsc_lh; + if(rsc_lh == NULL) { + crm_err("LHS of rsc_to_node (%s) is NULL", constraint->id); + return; + } + + constraint->rsc_lh->node_cons = + g_list_append(constraint->rsc_lh->node_cons, constraint); + + if(constraint->node_list_rh == NULL) { + crm_err("RHS of constraint %s is NULL", constraint->id); + return; + } + crm_debug_action(print_resource("before update", rsc_lh,TRUE)); + + or_list = node_list_or( + rsc_lh->allowed_nodes, constraint->node_list_rh, FALSE); + + pe_free_shallow(rsc_lh->allowed_nodes); + rsc_lh->allowed_nodes = or_list; + slist_iter(node_rh, node_t, constraint->node_list_rh, lpc, + update_node_weight(constraint, node_rh->details->uname, + rsc_lh->allowed_nodes)); + + crm_debug_action(print_resource("after update", rsc_lh, TRUE)); + +} + +void native_expand(resource_t *rsc, xmlNodePtr *graph) +{ + int lpc; + slist_iter( + action, action_t, rsc->actions, lpc, + crm_debug("processing action %d for rsc=%s", + action->id, rsc->id); + graph_element_from_action(action, graph); + ); +} + +void native_dump(resource_t *rsc, const char *pre_text, gboolean details) +{ + + crm_debug("%s%s%s%sResource %s: (priority=%f, color=%d, now=%d)", + pre_text==NULL?"":pre_text, + pre_text==NULL?"":": ", + rsc->provisional?"Provisional ":"", + rsc->runnable?"":"(Non-Startable) ", + rsc->id, + (double)rsc->priority, + safe_val3(-1, rsc, color, id), + g_list_length(rsc->running_on)); + + crm_debug("\t%d candidate colors, %d allowed nodes," + " %d rsc_cons and %d node_cons", + g_list_length(rsc->candidate_colors), + g_list_length(rsc->allowed_nodes), + g_list_length(rsc->rsc_cons), + g_list_length(rsc->node_cons)); + + if(details) { + int lpc = 0; + + crm_debug("\t=== Actions"); + slist_iter( + action, action_t, rsc->actions, lpc, + print_action("\trsc action: ", action, FALSE); + ); + + crm_debug("\t=== Colors"); + slist_iter( + color, color_t, rsc->candidate_colors, lpc, + print_color("\t", color, FALSE) + ); + + crm_debug("\t=== Allowed Nodes"); + slist_iter( + node, node_t, rsc->allowed_nodes, lpc, + print_node("\t", node, FALSE); + ); + } +} + +void native_free(resource_t *rsc) +{ + crm_debug("Freeing Allowed Nodes"); + pe_free_shallow(rsc->allowed_nodes); + + while(rsc->rsc_cons) { + crm_debug("Freeing constraint"); + pe_free_rsc_dependancy((rsc_dependancy_t*)rsc->rsc_cons->data); + rsc->rsc_cons = rsc->rsc_cons->next; + } + crm_debug("Freeing constraint list"); + if(rsc->rsc_cons != NULL) { + g_list_free(rsc->rsc_cons); + } + /* free ourselves? */ +} + + +void native_rsc_dependancy_rh_must(resource_t *rsc_lh, gboolean update_lh, + resource_t *rsc_rh, gboolean update_rh) +{ + gboolean do_merge = FALSE; + GListPtr old_list = NULL; + GListPtr merged_node_list = NULL; + float max_pri = rsc_lh->effective_priority; + if(max_pri < rsc_rh->effective_priority) { + max_pri = rsc_rh->effective_priority; + } + rsc_lh->effective_priority = max_pri; + rsc_rh->effective_priority = max_pri; + + if(rsc_lh->color && rsc_rh->color) { + do_merge = TRUE; + merged_node_list = node_list_and( + rsc_lh->color->details->candidate_nodes, + rsc_rh->color->details->candidate_nodes, TRUE); + + } else if(rsc_lh->color) { + do_merge = TRUE; + merged_node_list = node_list_and( + rsc_lh->color->details->candidate_nodes, + rsc_rh->allowed_nodes, TRUE); + + } else if(rsc_rh->color) { + do_merge = TRUE; + merged_node_list = node_list_and( + rsc_lh->allowed_nodes, + rsc_rh->color->details->candidate_nodes, TRUE); + } + + if(update_lh) { + crm_free(rsc_lh->color); + rsc_lh->runnable = rsc_rh->runnable; + rsc_lh->color = copy_color(rsc_rh->color); + } + if(update_rh) { + crm_free(rsc_rh->color); + rsc_rh->runnable = rsc_lh->runnable; + rsc_rh->color = copy_color(rsc_lh->color); + } + + if(do_merge) { + crm_debug("Merging candidate nodes"); + old_list = rsc_rh->color->details->candidate_nodes; + rsc_rh->color->details->candidate_nodes = merged_node_list; + 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; + + crm_debug("Processing pecs_must_not constraint"); + /* pecs_must_not */ + if(update_lh) { + color_rh = rsc_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(rsc_lh->color && rsc_lh->color->details->pending) { + node_t *node_lh = NULL; + + color_lh = rsc_lh->color; + node_lh = pe_find_node( + color_lh->details->candidate_nodes, + safe_val5(NULL, color_rh, details, + chosen_node, details, uname)); + + color_lh->details->candidate_nodes = + g_list_remove( + color_lh->details->candidate_nodes, + node_lh); + + crm_debug_action( + print_node("Removed LH", node_lh, FALSE)); + + crm_debug_action( + print_color("Modified LH", color_lh, FALSE)); + + crm_free(node_lh); + } else { + /* error, rsc marked as unrunnable above */ + crm_warn("lh else"); + } + } + + if(update_rh) { + color_lh = rsc_lh->color; + if(rsc_rh->provisional) { + color_rh = find_color( + rsc_rh->candidate_colors, color_lh); + + rsc_rh->candidate_colors = g_list_remove( + rsc_rh->candidate_colors, color_rh); + + crm_debug_action( + print_color("Removed RH", color_rh, FALSE)); + + crm_debug_action( + print_resource("Modified RH", rsc_rh, TRUE)); + + crm_free(color_rh); + + } else if(rsc_rh->color && rsc_rh->color->details->pending) { + node_t *node_rh = NULL; + color_rh = rsc_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"); + } + } +} diff --git a/crm/pengine/pe_utils.h b/crm/pengine/pe_utils.h index 121a1486ca..ee48ad53ba 100644 --- a/crm/pengine/pe_utils.h +++ b/crm/pengine/pe_utils.h @@ -1,127 +1,128 @@ -/* $Id: pe_utils.h,v 1.14 2004/10/27 15:30:55 andrew Exp $ */ +/* $Id: pe_utils.h,v 1.15 2004/11/09 09:32:14 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef PE_UTILS__H #define PE_UTILS__H /* General utilities */ extern resource_t *pe_find_resource(GListPtr rsc_list, const char *id_rh); -extern action_t *action_new(resource_t *rsc, enum action_tasks task, node_t *on_node); +extern action_t *action_new( + resource_t *rsc, enum action_tasks task, node_t *on_node); /* Constraint helper functions */ -extern rsc_to_rsc_t *invert_constraint(rsc_to_rsc_t *constraint); +extern rsc_dependancy_t *invert_constraint(rsc_dependancy_t *constraint); extern rsc_to_node_t *copy_constraint(rsc_to_node_t *constraint); /* Color helper functions */ extern void add_color_to_rsc(resource_t *rsc, color_t *color); extern color_t *find_color(GListPtr candidate_colors, color_t *other_color); extern color_t *create_color( GListPtr *colors, resource_t *resource, GListPtr resources); extern color_t *copy_color(color_t *a_color); /* Node helper functions */ extern gboolean filter_nodes(resource_t *rsc); extern node_t *pe_find_node(GListPtr node_list, const char *uname); extern node_t *pe_find_node_id(GListPtr node_list, const char *id); extern node_t *node_copy(node_t *this_node) ; /* Binary like operators for lists of nodes */ extern GListPtr node_list_dup(GListPtr list1, gboolean filter); extern GListPtr node_list_and(GListPtr list1, GListPtr list2, gboolean filter); extern GListPtr node_list_xor(GListPtr list1, GListPtr list2, gboolean filter); extern GListPtr node_list_minus(GListPtr list1,GListPtr list2,gboolean filter); extern gboolean node_list_eq(GListPtr list1, GListPtr list2, gboolean filter); extern GListPtr node_list_or(GListPtr list1, GListPtr list2, gboolean filter); /* For creating the transition graph */ extern xmlNodePtr action2xml(action_t *action, gboolean as_input); /* Printing functions for debug */ extern void print_node( const char *pre_text, node_t *node, gboolean details); extern void print_resource( const char *pre_text, resource_t *rsc, gboolean details); extern void print_rsc_to_node( const char *pre_text, rsc_to_node_t *cons, gboolean details); -extern void print_rsc_to_rsc( - const char *pre_text, rsc_to_rsc_t *cons, gboolean details); +extern void print_rsc_dependancy( + const char *pre_text, rsc_dependancy_t *cons, gboolean details); extern void print_color( const char *pre_text, color_t *color, gboolean details); extern void print_color_details( const char *pre_text, struct color_shared_s *color, gboolean details); extern void print_action( const char *pre_text, action_t *action, gboolean details); /* Sorting functions */ extern gint sort_rsc_priority(gconstpointer a, gconstpointer b); extern gint sort_cons_strength(gconstpointer a, gconstpointer b); extern gint sort_color_weight(gconstpointer a, gconstpointer b); extern gint sort_node_weight(gconstpointer a, gconstpointer b); /* enum 2 text functions (mostly used by print_*) */ extern const char *contype2text(enum con_type type); extern const char *strength2text(enum con_strength strength); /*extern const char *modifier2text(enum con_modifier modifier); */ extern const char *task2text(enum action_tasks task); extern GListPtr find_actions_type( GListPtr input, enum action_tasks task, node_t *on_node); /* free the various structures */ extern void pe_free_nodes(GListPtr nodes); extern void pe_free_colors(GListPtr colors); -extern void pe_free_rsc_to_rsc(rsc_to_rsc_t *cons); +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.c b/crm/pengine/pengine.c index 5d21011bb4..36746ce624 100755 --- a/crm/pengine/pengine.c +++ b/crm/pengine/pengine.c @@ -1,255 +1,255 @@ -/* $Id: pengine.c,v 1.47 2004/10/27 15:30:55 andrew Exp $ */ +/* $Id: pengine.c,v 1.48 2004/11/09 09:32:14 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include FILE *pemsg_strm = NULL; xmlNodePtr do_calculations(xmlNodePtr cib_object); gboolean process_pe_message(xmlNodePtr msg, IPC_Channel *sender) { char *msg_buffer = NULL; const char *sys_to = NULL; const char *op = get_xml_attr (msg, XML_TAG_OPTIONS, XML_ATTR_OP, TRUE); const char *ref = xmlGetProp(msg, XML_ATTR_REFERENCE); if(safe_str_eq(xmlGetProp(msg, XML_ATTR_MSGTYPE), XML_ATTR_REQUEST)) { crm_info( "Message was a response not a request." " Discarding"); } crm_verbose("Processing %s op (ref=%s)...", op, ref); if(pemsg_strm == NULL) { pemsg_strm = fopen(DEVEL_DIR"/pe.log", "w"); } msg_buffer = dump_xml_formatted(msg); fprintf(pemsg_strm, "%s: %s\n", "[in ]", msg_buffer); fflush(pemsg_strm); crm_free(msg_buffer); sys_to = xmlGetProp(msg, XML_ATTR_SYSTO); if(op == NULL){ /* error */ } else if(strcmp(op, CRM_OP_HELLO) == 0) { /* ignore */ } else if(sys_to == NULL || strcmp(sys_to, CRM_SYSTEM_PENGINE) != 0) { crm_verbose("Bad sys-to %s", crm_str(sys_to)); return FALSE; } else if(strcmp(op, CRM_OP_PECALC) == 0) { xmlNodePtr input_cib = find_xml_node(msg, XML_TAG_CIB); xmlNodePtr output = do_calculations(input_cib); msg_buffer = dump_xml_formatted(output); fprintf(pemsg_strm, "%s: %s\n", "[out ]", msg_buffer); fflush(pemsg_strm); crm_free(msg_buffer); if (send_ipc_reply(sender, msg, output) ==FALSE) { crm_warn("Answer could not be sent"); } free_xml(output); } else if(strcmp(op, CRM_OP_QUIT) == 0) { crm_err("Received quit message, terminating"); exit(0); } return TRUE; } xmlNodePtr do_calculations(xmlNodePtr cib_object) { int lpc, lpc2; GListPtr resources = NULL; GListPtr nodes = NULL; GListPtr placement_constraints = NULL; GListPtr actions = NULL; GListPtr ordering_constraints = NULL; GListPtr stonith_list = NULL; GListPtr shutdown_list = NULL; GListPtr colors = NULL; GListPtr action_sets = NULL; xmlNodePtr graph = NULL; /* pe_debug_on(); */ crm_verbose("=#=#=#=#= Stage 0 =#=#=#=#="); stage0(cib_object, &resources, &nodes, &placement_constraints, &actions, &ordering_constraints, &stonith_list, &shutdown_list); crm_verbose("=#=#=#=#= Stage 1 =#=#=#=#="); stage1(placement_constraints, nodes, resources); crm_verbose("=#=#=#=#= Stage 2 =#=#=#=#="); stage2(resources, nodes, &colors); crm_verbose("========= Nodes ========="); crm_debug_action( slist_iter(node, node_t, nodes, lpc, print_node(NULL, node, TRUE) ) ); crm_verbose("========= Resources ========="); crm_debug_action( slist_iter(resource, resource_t, resources, lpc, print_resource(NULL, resource, TRUE) ) ); crm_verbose("=#=#=#=#= Stage 3 =#=#=#=#="); stage3(colors); crm_verbose("=#=#=#=#= Stage 4 =#=#=#=#="); stage4(colors); crm_verbose("========= Colors ========="); crm_debug_action( slist_iter(color, color_t, colors, lpc, print_color(NULL, color, FALSE) ) ); crm_verbose("=#=#=#=#= Stage 5 =#=#=#=#="); - stage5(resources); + stage5(resources, &ordering_constraints); crm_verbose("=#=#=#=#= Stage 6 =#=#=#=#="); stage6(&actions, &ordering_constraints, nodes, resources); crm_verbose("========= Action List ========="); crm_debug_action( slist_iter(action, action_t, actions, lpc, print_action(NULL, action, TRUE) ) ); crm_verbose("=#=#=#=#= Stage 7 =#=#=#=#="); - stage7(resources, actions, ordering_constraints, &action_sets); + stage7(resources, actions, ordering_constraints); crm_verbose("=#=#=#=#= Summary =#=#=#=#="); summary(resources); crm_verbose("========= Action Sets ========="); crm_verbose("\t========= Set %d (Un-runnable) =========", -1); crm_debug_action( slist_iter(action, action_t, actions, lpc, if(action->optional == FALSE && action->runnable == FALSE) { print_action("\t", action, TRUE); } ) ); crm_debug_action( slist_iter(action_set, GList, action_sets, lpc, crm_verbose("\t========= Set %d =========", lpc); slist_iter(action, action_t, action_set, lpc2, print_action("\t", action, TRUE); ) ) ); crm_verbose("========= Stonith List ========="); crm_debug_action( slist_iter(node, node_t, stonith_list, lpc, print_node(NULL, node, FALSE); ) ); crm_verbose("========= Shutdown List ========="); crm_debug_action( slist_iter(node, node_t, shutdown_list, lpc, print_node(NULL, node, FALSE); ) ); crm_verbose("=#=#=#=#= Stage 8 =#=#=#=#="); stage8(resources, actions, &graph); crm_verbose("=#=#=#=#= Cleanup =#=#=#=#="); crm_verbose("deleting node cons"); while(placement_constraints) { pe_free_rsc_to_node((rsc_to_node_t*)placement_constraints->data); placement_constraints = placement_constraints->next; } if(placement_constraints != NULL) { g_list_free(placement_constraints); } crm_verbose("deleting order cons"); pe_free_shallow(ordering_constraints); crm_verbose("deleting action sets"); slist_iter(action_set, GList, action_sets, lpc, pe_free_shallow_adv(action_set, FALSE); ); pe_free_shallow_adv(action_sets, FALSE); crm_verbose("deleting actions"); pe_free_actions(actions); crm_verbose("deleting resources"); pe_free_resources(resources); crm_verbose("deleting colors"); pe_free_colors(colors); crm_verbose("deleting nodes"); pe_free_nodes(nodes); if(shutdown_list != NULL) { g_list_free(shutdown_list); } if(stonith_list != NULL) { g_list_free(stonith_list); } return graph; } diff --git a/crm/pengine/pengine.h b/crm/pengine/pengine.h index a232be1931..ecbd5d9c8f 100644 --- a/crm/pengine/pengine.h +++ b/crm/pengine/pengine.h @@ -1,328 +1,334 @@ -/* $Id: pengine.h,v 1.38 2004/10/27 15:30:55 andrew Exp $ */ +/* $Id: pengine.h,v 1.39 2004/11/09 09:32:14 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef PENGINE__H #define PENGINE__H #include typedef struct node_s node_t; typedef struct color_s color_t; typedef struct rsc_to_node_s rsc_to_node_t; -typedef struct rsc_to_rsc_s rsc_to_rsc_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_to_rsc, + rsc_dependancy, rsc_to_node, rsc_to_attr, base_weight }; enum node_type { node_ping, node_member }; enum con_strength { pecs_ignore, pecs_must, pecs_must_not, pecs_startstop }; enum action_tasks { no_action, stop_rsc, start_rsc, shutdown_crm, stonith_node }; -enum rsc_con_type { - start_before, - start_after, - same_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_to_rsc_s { +struct rsc_dependancy_s { const char *id; resource_t *rsc_lh; - enum rsc_con_type variant; 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; }; -enum pe_stop_fail { - pesf_block, - pesf_stonith, - pesf_ignore -}; - -enum pe_restart { - pe_restart_restart, - pe_restart_recover, - pe_restart_ignore -}; - struct resource_s { - const char *id; - xmlNodePtr xml; - float priority; - float effective_priority; + const char *id; + xmlNodePtr xml; - const char *timeout; + void *variant_opaque; + enum pe_obj_types variant; + resource_object_functions_t *fns; - lrm_agent_t *agent; + float priority; + float effective_priority; + const char *timeout; + lrm_agent_t *agent; - gboolean is_stonith; - gboolean runnable; - gboolean provisional; + gboolean is_stonith; + gboolean runnable; + gboolean provisional; enum rsc_recovery_type recovery_type; enum pe_stop_fail stopfail_type; enum pe_restart restart_type; + GListPtr candidate_colors; /* color_t* */ + GListPtr allowed_nodes; /* node_t* */ + GListPtr actions; /* action_t* */ + + /* (soon to be) variant specific */ int max_instances; int max_node_instances; int max_masters; int max_node_masters; - - GListPtr actions; /* action_t* */ - GListPtr candidate_colors; /* color_t* */ - GListPtr allowed_nodes; /* node_t* */ - GListPtr node_cons; /* rsc_to_node_t* */ - GListPtr rsc_cons; /* rsc_to_rsc_t* */ - GListPtr fencable_nodes; /* node_t* */ - GListPtr running_on; /* node_t* */ - - color_t *color; + GListPtr node_cons; /* rsc_to_node_t* */ + GListPtr rsc_cons; /* rsc_dependancy_t* */ + GListPtr running_on; /* node_t* */ + color_t *color; }; struct action_wrapper_s { enum con_strength strength; action_t *action; }; struct action_s { - int id; + int id; resource_t *rsc; - node_t *node; + void *rsc_opaque; + node_t *node; enum action_tasks task; gboolean runnable; gboolean dumped; gboolean processed; gboolean optional; gboolean discard; gboolean failure_is_fatal; int seen_count; const char *timeout; xmlNodePtr args; GListPtr actions_before; /* action_warpper_t* */ GListPtr actions_after; /* action_warpper_t* */ + + /* (soon to be) variant specific */ + int incarnation; }; struct order_constraint_s { - int id; + int id; + enum con_strength strength; + void *lh_opaque; resource_t *lh_rsc; action_t *lh_action; enum action_tasks lh_action_task; -/* int lh_rsc_incarnation; */ + void *rh_opaque; resource_t *rh_rsc; action_t *rh_action; enum action_tasks rh_action_task; -/* int rh_rsc_incarnation; */ - enum con_strength strength; -/* enum action_order order; */ + /* (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); +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, - GListPtr *action_sets); +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 *action_cons, + 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/ptest.c b/crm/pengine/ptest.c index 34f4d9421c..8b5792399d 100644 --- a/crm/pengine/ptest.c +++ b/crm/pengine/ptest.c @@ -1,291 +1,302 @@ -/* $Id: ptest.c,v 1.37 2004/10/27 15:30:55 andrew Exp $ */ +/* $Id: ptest.c,v 1.38 2004/11/09 09:32:14 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include #include #include -#define OPTARGS "V?i:o:D:C:S:HA:U:M:I:EWRFt:m:a:d:w:c:r:p:s:" +#define OPTARGS "V?X:" #include #include #include #include int main(int argc, char **argv) { xmlNodePtr cib_object = NULL; int lpc = 0; int argerr = 0; int flag; GListPtr resources = NULL; GListPtr nodes = NULL; GListPtr placement_constraints = NULL; GListPtr actions = NULL; GListPtr ordering_constraints = NULL; GListPtr stonith_list = NULL; GListPtr shutdown_list = NULL; GListPtr colors = NULL; GListPtr action_sets = NULL; xmlNodePtr graph = NULL; char *msg_buffer = NULL; + const char *xml_file = NULL; + cl_log_set_entity("ptest"); cl_log_set_facility(LOG_USER); while (1) { int option_index = 0; static struct option long_options[] = { /* Top-level Options */ + {"xml", 1, 0, 'X'}, {"help", 0, 0, 0}, {0, 0, 0, 0} }; flag = getopt_long(argc, argv, OPTARGS, long_options, &option_index); if (flag == -1) break; switch(flag) { case 0: printf("option %s", long_options[option_index].name); if (optarg) printf(" with arg %s", optarg); printf("\n"); break; + case 'X': + xml_file = crm_strdup(optarg); + break; case 'V': alter_debug(DEBUG_INC); break; default: printf("?? getopt returned character code 0%o ??\n", flag); ++argerr; break; } } if (optind < argc) { printf("non-option ARGV-elements: "); while (optind < argc) printf("%s ", argv[optind++]); printf("\n"); } if (optind > argc) { ++argerr; } if (argerr) { crm_err("%d errors in option parsing", argerr); } crm_info("=#=#=#=#= Getting XML =#=#=#=#="); - cib_object = file2xml(stdin); - - crm_info("=#=#=#=#= Stage 0 =#=#=#=#="); + if(xml_file != NULL) { + FILE *xml_strm = fopen(xml_file, "r"); + cib_object = file2xml(xml_strm); + + } else { + cib_object = file2xml(stdin); + } + crm_info("=#=#=#=#= Stage 0 =#=#=#=#="); #ifdef MCHECK mtrace(); #endif stage0(cib_object, &resources, &nodes, &placement_constraints, &actions, &ordering_constraints, &stonith_list, &shutdown_list); crm_debug("========= Nodes ========="); slist_iter(node, node_t, nodes, lpc, print_node(NULL, node, TRUE)); crm_debug("========= Resources ========="); slist_iter(resource, resource_t, resources, lpc, print_resource(NULL, resource, TRUE)); crm_debug("========= Constraints ========="); slist_iter(constraint, rsc_to_node_t, placement_constraints, lpc, print_rsc_to_node(NULL, constraint, FALSE)); crm_debug("=#=#=#=#= Stage 1 =#=#=#=#="); stage1(placement_constraints, nodes, resources); crm_debug("========= Nodes ========="); slist_iter(node, node_t, nodes, lpc, print_node(NULL, node, TRUE)); crm_debug("========= Resources ========="); slist_iter(resource, resource_t, resources, lpc, print_resource(NULL, resource, TRUE)); crm_debug("=#=#=#=#= Stage 2 =#=#=#=#="); stage2(resources, nodes, &colors); crm_debug("========= Nodes ========="); slist_iter(node, node_t, nodes, lpc, print_node(NULL, node, TRUE)); crm_debug("========= Resources ========="); slist_iter(resource, resource_t, resources, lpc, print_resource(NULL, resource, TRUE)); crm_debug("========= Colors ========="); slist_iter(color, color_t, colors, lpc, print_color(NULL, color, FALSE)); crm_debug("========= Action List ========="); slist_iter(action, action_t, actions, lpc, print_action(NULL, action, FALSE)); crm_debug("=#=#=#=#= Stage 3 =#=#=#=#="); stage3(colors); crm_debug("========= Colors ========="); slist_iter(color, color_t, colors, lpc, print_color(NULL, color, FALSE)); crm_debug("========= Action List ========="); slist_iter(action, action_t, actions, lpc, print_action(NULL, action, TRUE)); crm_debug("=#=#=#=#= Stage 4 =#=#=#=#="); stage4(colors); crm_debug("========= Colors ========="); slist_iter(color, color_t, colors, lpc, print_color(NULL, color, FALSE)); crm_debug("=#=#=#=#= Summary =#=#=#=#="); summary(resources); crm_debug("========= Action List ========="); slist_iter(action, action_t, actions, lpc, print_action(NULL, action, TRUE)); crm_debug("=#=#=#=#= Stage 5 =#=#=#=#="); - stage5(resources); + stage5(resources, &ordering_constraints); crm_debug("========= All Actions ========="); slist_iter(action, action_t, actions, lpc, print_action("\t", action, TRUE); ); crm_debug("=#=#=#=#= Stage 6 =#=#=#=#="); stage6(&actions, &ordering_constraints, nodes, resources); crm_debug("========= Action List ========="); slist_iter(action, action_t, actions, lpc, print_action(NULL, action, TRUE)); crm_debug("=#=#=#=#= Stage 7 =#=#=#=#="); - stage7(resources, actions, ordering_constraints, &action_sets); + stage7(resources, actions, ordering_constraints); crm_debug("=#=#=#=#= Summary =#=#=#=#="); summary(resources); crm_debug("========= All Actions ========="); slist_iter(action, action_t, actions, lpc, print_action("\t", action, TRUE); ); crm_debug("========= Stonith List ========="); slist_iter(node, node_t, stonith_list, lpc, print_node(NULL, node, FALSE)); crm_debug("========= Shutdown List ========="); slist_iter(node, node_t, shutdown_list, lpc, print_node(NULL, node, FALSE)); crm_debug("=#=#=#=#= Stage 8 =#=#=#=#="); stage8(resources, actions, &graph); crm_verbose("deleting node cons"); while(placement_constraints) { pe_free_rsc_to_node((rsc_to_node_t*)placement_constraints->data); placement_constraints = placement_constraints->next; } if(placement_constraints != NULL) { g_list_free(placement_constraints); } crm_verbose("deleting order cons"); pe_free_shallow(ordering_constraints); crm_verbose("deleting action sets"); slist_iter(action_set, GList, action_sets, lpc, pe_free_shallow_adv(action_set, FALSE); ); pe_free_shallow_adv(action_sets, FALSE); crm_verbose("deleting actions"); pe_free_actions(actions); /* GListPtr action_sets = NULL; */ crm_verbose("deleting resources"); pe_free_resources(resources); crm_verbose("deleting colors"); pe_free_colors(colors); crm_free(no_color->details); crm_free(no_color); crm_verbose("deleting nodes"); pe_free_nodes(nodes); if(shutdown_list != NULL) { g_list_free(shutdown_list); } if(stonith_list != NULL) { g_list_free(stonith_list); } #ifdef MCHECK muntrace(); #endif msg_buffer = dump_xml_formatted(graph); fprintf(stdout, "%s\n", msg_buffer); fflush(stdout); crm_free(msg_buffer); free_xml(graph); free_xml(cib_object); return 0; } diff --git a/crm/pengine/stages.c b/crm/pengine/stages.c index 438bdfb6bb..e90dd65b37 100644 --- a/crm/pengine/stages.c +++ b/crm/pengine/stages.c @@ -1,628 +1,465 @@ -/* $Id: stages.c,v 1.24 2004/10/27 15:30:55 andrew Exp $ */ +/* $Id: stages.c,v 1.25 2004/11/09 09:32:14 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include node_t *choose_fencer(action_t *stonith, node_t *node, GListPtr resources); +void order_actions(action_t *lh, action_t *rh, order_constraint_t *order); /* * Unpack everything * At the end you'll have: * - A list of nodes * - A list of resources (each with any dependancies on other resources) * - A list of constraints between resources and nodes * - A list of constraints between start/stop actions * - A list of nodes that need to be stonith'd * - A list of nodes that need to be shutdown * - A list of the possible stop/start actions (without dependancies) */ gboolean stage0(xmlNodePtr cib, GListPtr *resources, GListPtr *nodes, GListPtr *placement_constraints, GListPtr *actions, GListPtr *ordering_constraints, GListPtr *stonith_list, GListPtr *shutdown_list) { /* int lpc; */ xmlNodePtr cib_nodes = get_object_root( XML_CIB_TAG_NODES, cib); xmlNodePtr cib_status = get_object_root( XML_CIB_TAG_STATUS, cib); xmlNodePtr cib_resources = get_object_root( XML_CIB_TAG_RESOURCES, cib); xmlNodePtr cib_constraints = get_object_root( XML_CIB_TAG_CONSTRAINTS, cib); xmlNodePtr config = get_object_root( XML_CIB_TAG_CRMCONFIG, cib); xmlNodePtr agent_defaults = NULL; /*get_object_root(XML_CIB_TAG_RA_DEFAULTS, cib); */ /* reset remaining global variables */ max_valid_nodes = 0; order_id = 1; action_id = 1; unpack_config(config); unpack_global_defaults(agent_defaults); unpack_nodes(cib_nodes, nodes); - unpack_resources(cib_resources, - resources, actions, ordering_constraints, *nodes); + unpack_resources(cib_resources, resources, actions, + ordering_constraints, *nodes); - unpack_status(cib_status, - *nodes, *resources, actions, placement_constraints); + unpack_status(cib_status, *nodes, *resources, actions, + placement_constraints); - unpack_constraints(cib_constraints, - *nodes, *resources, + unpack_constraints(cib_constraints, *nodes, *resources, placement_constraints, ordering_constraints); return TRUE; } /* * Count how many valid nodes we have (so we know the maximum number of * colors we can resolve). * * Apply node constraints (ie. filter the "allowed_nodes" part of resources */ gboolean stage1(GListPtr placement_constraints, GListPtr nodes, GListPtr resources) { int lpc = 0; crm_info("Processing stage 1"); slist_iter( node, node_t, nodes, lpc, if(node == NULL) { /* error */ } else if(node->weight >= 0.0 /* global weight */ && node->details->online && node->details->type == node_member) { max_valid_nodes++; } ); apply_placement_constraints(placement_constraints, nodes); /* will also filter -ve "final" weighted nodes from resources' * allowed lists while we are there */ apply_agent_constraints(resources); return TRUE; } /* * Choose a color for all resources from highest priority and XML_STRENGTH_VAL_MUST * dependancies to lowest, creating new colors as necessary (returned * as "colors"). * * Some nodes may be colored as a "no_color" meaning that it was unresolvable * given the current node stati and constraints. */ gboolean stage2(GListPtr sorted_rscs, GListPtr sorted_nodes, GListPtr *colors) { int lpc; crm_info("Processing stage 2"); if(no_color != NULL) { crm_free(no_color->details); crm_free(no_color); } crm_trace("create \"no color\""); no_color = create_color(NULL, NULL, NULL); /* Take (next) highest resource */ slist_iter( lh_resource, resource_t, sorted_rscs, lpc, /* if resource.provisional == FALSE, repeat */ if(lh_resource->provisional == FALSE) { /* already processed this resource */ continue; } color_resource(lh_resource, colors, sorted_rscs); /* next resource */ ); return TRUE; } /* * not sure if this is a good idea or not, but eventually we might like * to utilize as many nodes as possible... and this might be a convienient * hook */ gboolean stage3(GListPtr colors) { crm_info("Processing stage 3"); /* not sure if this is a good idea or not */ if(g_list_length(colors) > max_valid_nodes) { /* we need to consolidate some */ } else if(g_list_length(colors) < max_valid_nodes) { /* we can create a few more */ } return TRUE; } /* * Choose a node for each (if possible) color */ gboolean stage4(GListPtr colors) { int lpc = 0, lpc2 = 0; crm_info("Processing stage 4"); slist_iter( color, color_t, colors, lpc, crm_debug("assigning node to color %d", color->id); if(color == NULL) { crm_err("NULL color detected"); continue; } else if(color->details->pending == FALSE) { continue; } choose_node_from_list(color); crm_debug("assigned %s to color %d", safe_val5(NULL, color, details, chosen_node, details, uname), color->id); slist_iter( rsc, resource_t, color->details->allocated_resources, lpc2, - - process_colored_constraints(rsc); + slist_iter( + constraint, rsc_dependancy_t, rsc->rsc_cons, lpc, + rsc->fns->rsc_dependancy_lh(constraint); + ); ); ); crm_verbose("done"); return TRUE; } /* * Attach nodes to the actions that need to be taken * * Mark actions XML_LRM_ATTR_OPTIONAL if possible (Ie. if the start and stop are * for the same node) * * Mark unrunnable actions */ gboolean -stage5(GListPtr resources) +stage5(GListPtr resources, GListPtr *ordering_constraints) { - int lpc, lpc2, lpc3; + int lpc; slist_iter( rsc, resource_t, resources, lpc, - action_t *start_op = NULL; - gboolean can_start = FALSE; - node_t *chosen = rsc->color->details->chosen_node; - - if(rsc->color != NULL && chosen != NULL) { - can_start = TRUE; - } - - if(can_start && g_list_length(rsc->running_on) == 0) { - /* create start action */ - crm_info("Start resource %s (%s)", - rsc->id, - safe_val3(NULL, chosen, details, uname)); - start_op = action_new(rsc, start_rsc, chosen); - - } else if(g_list_length(rsc->running_on) > 1) { - crm_info("Attempting recovery of resource %s", - rsc->id); - - if(rsc->recovery_type == recovery_stop_start - || rsc->recovery_type == recovery_stop_only) { - slist_iter( - node, node_t, - rsc->running_on, lpc2, - - crm_info("Stop resource %s (%s)", - rsc->id, - safe_val3(NULL, node, details, uname)); - action_new(rsc, stop_rsc, node); - ); - } - - if(rsc->recovery_type == recovery_stop_start && can_start) { - crm_info("Start resource %s (%s)", - rsc->id, - safe_val3(NULL, chosen, details, uname)); - start_op = action_new( - rsc, start_rsc, chosen); - } - - } else { - /* stop and or possible restart */ - crm_debug("Stop and possible restart of %s", rsc->id); - - slist_iter( - node, node_t, rsc->running_on, lpc2, - - if(chosen != NULL && safe_str_eq( - node->details->id, - chosen->details->id)) { - /* restart */ - crm_info("Leave resource %s alone (%s)", - rsc->id, - safe_val3(NULL, chosen, details, uname)); - - - /* in case the actions already exist */ - slist_iter( - action, action_t, rsc->actions, lpc3, - - if(action->task == start_rsc - || action->task == stop_rsc){ - action->optional = TRUE; - } - ); - - continue; - } else if(chosen != NULL) { - /* move */ - crm_info("Move resource %s (%s -> %s)", - rsc->id, - safe_val3(NULL, node, details, uname), - safe_val3(NULL, chosen, details, uname)); - action_new(rsc, stop_rsc, node); - action_new(rsc, start_rsc, chosen); - - } else { - crm_info("Stop resource %s (%s)", - rsc->id, - safe_val3(NULL, node, details, uname)); - action_new(rsc, stop_rsc, node); - } - - ); - - } - + rsc->fns->create_actions(rsc); + rsc->fns->internal_ordering(rsc, ordering_constraints); ); return TRUE; } /* * Create dependacies for stonith and shutdown operations */ gboolean stage6(GListPtr *actions, GListPtr *ordering_constraints, GListPtr nodes, GListPtr resources) { int lpc = 0; action_t *down_op = NULL; action_t *stonith_op = NULL; crm_info("Processing stage 6"); slist_iter( node, node_t, nodes, lpc, if(node->details->shutdown) { crm_warn("Scheduling Node %s for shutdown", node->details->uname); down_op = action_new(NULL, shutdown_crm, node); down_op->runnable = TRUE; *actions = g_list_append(*actions, down_op); shutdown_constraints( node, down_op, ordering_constraints); } if(node->details->unclean && stonith_enabled) { crm_warn("Scheduling Node %s for STONITH", node->details->uname); stonith_op = action_new(NULL, stonith_node, NULL); stonith_op->runnable = TRUE; set_xml_property_copy(stonith_op->args, "target", node->details->uname); if(down_op != NULL) { down_op->failure_is_fatal = FALSE; } *actions = g_list_append(*actions, stonith_op); stonith_constraints(node, stonith_op, down_op, ordering_constraints); } ); return TRUE; } /* * Determin the sets of independant actions and the correct order for the * actions in each set. * * Mark dependancies of un-runnable actions un-runnable * */ gboolean -stage7(GListPtr resources, GListPtr actions, GListPtr ordering_constraints, - GListPtr *action_sets) +stage7(GListPtr resources, GListPtr actions, GListPtr ordering_constraints) { int lpc; - int lpc2; - int lpc3; - action_wrapper_t *wrapper = NULL; - GListPtr list = NULL; crm_info("Processing stage 7"); slist_iter( order, order_constraint_t, ordering_constraints, lpc, - action_t *lh_action = order->lh_action; - action_t *rh_action = order->rh_action; - GListPtr lh_actions = NULL; - GListPtr rh_actions = NULL; - - crm_verbose("Processing ordering constraint %d", order->id); - - if(lh_action != NULL) { - lh_actions = g_list_append(NULL, lh_action); - - } else if(lh_action == NULL && order->lh_rsc != NULL) { - if(order->strength == pecs_must) { - crm_debug("No RH-Side (%s/%s) found for constraint..." - " creating", - order->lh_rsc->id, task2text(order->lh_action_task)); - - action_new(order->lh_rsc, order->lh_action_task, NULL); - } - - - lh_actions = find_actions_type( - order->lh_rsc->actions, order->lh_action_task, NULL); - if(lh_actions == NULL) { - crm_debug("No LH-Side (%s/%s) found for constraint", - order->lh_rsc->id, - task2text(order->lh_action_task)); - continue; - } - - } else { - crm_warn("No LH-Side (%s) specified for constraint", - task2text(order->lh_action_task)); + /* try rsc_action-to-rsc_action */ + resource_t *rsc = order->lh_rsc; + if(rsc == NULL && order->lh_action) { + rsc = order->lh_action->rsc; + } + + if(rsc != NULL) { + rsc->fns->rsc_order_lh(order); continue; + } - if(rh_action != NULL) { - rh_actions = g_list_append(NULL, rh_action); - - } else if(rh_action == NULL && order->rh_rsc != NULL) { - rh_actions = find_actions_type( - order->rh_rsc->actions, order->rh_action_task, NULL); - - if(rh_actions == NULL) { - crm_debug("No RH-Side (%s/%s) found for constraint..." - " ignoring", - order->rh_rsc->id, task2text(order->rh_action_task)); - continue; - } - - } else if(rh_action == NULL) { - crm_debug("No RH-Side (%s) specified for constraint..." - " ignoring", task2text(order->rh_action_task)); - continue; - } + /* try action-to-rsc_action */ + /* que off the rh resource */ + rsc = order->rh_rsc; + if(rsc == NULL && order->rh_action) { + rsc = order->rh_action->rsc; + } + + if(rsc != NULL) { + rsc->fns->rsc_order_rh(order->lh_action, order); + } else { + /* fall back to action-to-action */ + order_actions( + order->lh_action, order->rh_action, order); + } - - slist_iter( - lh_action_iter, action_t, lh_actions, lpc2, - - slist_iter( - rh_action_iter, action_t, rh_actions, lpc3, - crm_verbose("%d Processing %d -> %d", - order->id, - lh_action_iter->id, - rh_action_iter->id); - - crm_debug_action( - print_action("LH (stage7)", - lh_action_iter, FALSE)); - crm_debug_action( - print_action("RH (stage7)", - rh_action_iter, FALSE)); - - crm_malloc(wrapper, sizeof(action_wrapper_t)); - if(wrapper != NULL) { - wrapper->action = rh_action_iter; - wrapper->strength = order->strength; - - list = lh_action_iter->actions_after; - list = g_list_append(list, wrapper); - lh_action_iter->actions_after = list; - } - - crm_malloc(wrapper, sizeof(action_wrapper_t)); - if(wrapper != NULL) { - wrapper->action = lh_action_iter; - wrapper->strength = order->strength; - - list = rh_action_iter->actions_before; - list = g_list_append(list, wrapper); - rh_action_iter->actions_before = list; - } - ); - ); - - pe_free_shallow_adv(lh_actions, FALSE); - pe_free_shallow_adv(rh_actions, FALSE); ); update_action_states(actions); return TRUE; } /* * Create a dependancy graph to send to the transitioner (via the CRMd) */ gboolean stage8(GListPtr resources, GListPtr actions, xmlNodePtr *graph) { - int lpc = 0, lpc2 = 0; + int lpc = 0; crm_info("Processing stage 8"); *graph = create_xml_node(NULL, "transition_graph"); set_xml_property_copy( *graph, "global_timeout", transition_timeout); /* errors... slist_iter(action, action_t, action_list, lpc, if(action->optional == FALSE && action->runnable == FALSE) { print_action("Ignoring", action, TRUE); } ); */ slist_iter( rsc, resource_t, resources, lpc, crm_debug("processing actions for rsc=%s", rsc->id); - slist_iter( - action, action_t, rsc->actions, lpc2, - crm_debug("processing action %d for rsc=%s", - action->id, rsc->id); - graph_element_from_action(action, graph); - ); + rsc->fns->expand(rsc, graph); ); crm_xml_devel(*graph, "created resource-driven action list"); /* catch any non-resource specific actions */ slist_iter( action, action_t, actions, lpc, graph_element_from_action(action, graph); ); crm_xml_devel(*graph, "created generic action list"); return TRUE; } /* * Print a nice human readable high-level summary of what we're going to do */ gboolean summary(GListPtr resources) { #if 0 int lpc = 0; const char *rsc_id = NULL; const char *node_id = NULL; const char *new_node_id = NULL; slist_iter( rsc, resource_t, resources, lpc, rsc_id = safe_val(NULL, rsc, id); node_id = safe_val4(NULL, rsc, cur_node, details, uname); new_node_id = safe_val6( NULL, rsc, color, details, chosen_node, details, uname); if(rsc->runnable == FALSE) { crm_err("Resource %s was not runnable", rsc_id); if(node_id != NULL) { crm_warn("Stopping Resource (%s) on node %s", rsc_id, node_id); } } else if(safe_val4(NULL, rsc, color, details, chosen_node) == NULL) { crm_err("Could not allocate Resource %s", rsc_id); crm_debug_action( print_resource("Could not allocate",rsc,TRUE)); if(node_id != NULL) { crm_warn("Stopping Resource (%s) on node %s", rsc_id, node_id); } } else if(safe_str_eq(node_id, new_node_id)){ crm_debug("No change for Resource %s (%s)", rsc_id, safe_val4(NULL, rsc, cur_node, details, uname)); } else if(node_id == NULL) { crm_info("Starting Resource %s on %s", rsc_id, new_node_id); } else { crm_info("Moving Resource %s from %s to %s", rsc_id, node_id, new_node_id); } ); #endif return TRUE; } gboolean choose_node_from_list(color_t *color) { /* 1. Sort by weight 2. color.chosen_node = highest wieghted node 3. remove color.chosen_node from all other colors */ GListPtr nodes = color->details->candidate_nodes; nodes = g_list_sort(nodes, sort_node_weight); color->details->chosen_node = node_copy((node_t*)g_list_nth_data(nodes, 0)); color->details->pending = FALSE; if(color->details->chosen_node == NULL) { crm_err("Could not allocate a node for color %d", color->id); return FALSE; } return TRUE; } diff --git a/crm/pengine/unpack.c b/crm/pengine/unpack.c index 6254748c56..b60597849e 100644 --- a/crm/pengine/unpack.c +++ b/crm/pengine/unpack.c @@ -1,1308 +1,1249 @@ -/* $Id: unpack.c,v 1.40 2004/11/08 13:22:05 andrew Exp $ */ +/* $Id: unpack.c,v 1.41 2004/11/09 09:32:14 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include /* for ONLINESTATUS */ #include #include int max_valid_nodes = 0; int order_id = 1; GListPtr agent_defaults = NULL; gboolean stonith_enabled = FALSE; const char* transition_timeout = "60000"; /* 1 minute */ GListPtr match_attrs(const char *attr, const char *op, const char *value, const char *type, GListPtr node_list); gboolean unpack_rsc_to_attr(xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr node_list, GListPtr *placement_constraints); gboolean unpack_rsc_to_node(xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr node_list, GListPtr *placement_constraints); gboolean unpack_rsc_order( xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr *ordering_constraints); gboolean unpack_rsc_dependancy( xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr *ordering_constraints); gboolean unpack_rsc_location( xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr node_list, GListPtr *ordering_constraints); gboolean unpack_lrm_rsc_state( node_t *node, xmlNodePtr lrm_state, GListPtr rsc_list, GListPtr nodes, GListPtr *actions, GListPtr *placement_constraints); gboolean add_node_attrs(xmlNodePtr attrs, node_t *node); gboolean unpack_healthy_resource(GListPtr *placement_constraints, GListPtr *actions, xmlNodePtr rsc_entry, resource_t *rsc_lh, node_t *node); gboolean unpack_failed_resource(GListPtr *placement_constraints, GListPtr *actions, xmlNodePtr rsc_entry, resource_t *rsc_lh, node_t *node); gboolean determine_online_status(xmlNodePtr node_state, node_t *this_node); gboolean unpack_lrm_agents(node_t *node, xmlNodePtr agent_list); gboolean is_node_unclean(xmlNodePtr node_state); -gboolean rsc2rsc_new(const char *id, enum con_strength strength, enum rsc_con_type type, - resource_t *rsc_lh, resource_t *rsc_rh); +gboolean rsc_dependancy_new( + const char *id, enum con_strength strength, + resource_t *rsc_lh, resource_t *rsc_rh); gboolean create_ordering( const char *id, enum con_strength strength, resource_t *rsc_lh, resource_t *rsc_rh, GListPtr *ordering_constraints); rsc_to_node_t *rsc2node_new( const char *id, resource_t *rsc, double weight, gboolean can_run, node_t *node, GListPtr *placement_constraints); const char *get_agent_param(resource_t *rsc, const char *param); const char *get_agent_param_rsc(resource_t *rsc, const char *param); const void *get_agent_param_metadata(resource_t *rsc, const char *param); const char *get_agent_param_global(resource_t *rsc, const char *param); const char *param_value(xmlNodePtr parent, const char *name); gboolean unpack_config(xmlNodePtr config) { const char *value = NULL; value = param_value(config, "failed_nodes"); if(safe_str_eq(value, "stonith")) { crm_debug("Enabling STONITH of failed nodes"); stonith_enabled = TRUE; } else { stonith_enabled = FALSE; } value = param_value(config, "transition_timeout"); if(value != NULL) { int tmp = atoi(value); if(tmp > 0) { transition_timeout = value; } else { crm_warn("Invalid value for %s: %s", "transition_timeout", value); } } crm_info("%s set to: %s", "transition_timeout", transition_timeout); return TRUE; } const char * param_value(xmlNodePtr parent, const char *name) { xmlNodePtr a_default = find_entity( parent, XML_CIB_TAG_NVPAIR, name, FALSE); return xmlGetProp(a_default, XML_NVPAIR_ATTR_VALUE); } const char * get_agent_param(resource_t *rsc, const char *param) { const char *value = NULL; if(param == NULL) { return NULL; } value = get_agent_param_rsc(rsc, param); if(value == NULL) { value = get_agent_param_metadata(rsc, param); } if(value == NULL) { value = get_agent_param_global(rsc, param); } return value; } const char * get_agent_param_rsc(resource_t *rsc, const char *param) { xmlNodePtr xml_rsc = rsc->xml; return xmlGetProp(xml_rsc, param); } const void * get_agent_param_metadata(resource_t *rsc, const char *param) { return NULL; } const char * get_agent_param_global(resource_t *rsc, const char *param) { const char * value = NULL;/*g_hashtable_lookup(agent_global_defaults, param); */ if(value == NULL) { crm_err("No global value default for %s", param); } return value; } gboolean unpack_global_defaults(xmlNodePtr defaults) { return TRUE; } gboolean unpack_nodes(xmlNodePtr xml_nodes, GListPtr *nodes) { node_t *new_node = NULL; xmlNodePtr attrs = NULL; const char *id = NULL; const char *uname = NULL; const char *type = NULL; crm_verbose("Begining unpack..."); xml_child_iter( xml_nodes, xml_obj, XML_CIB_TAG_NODE, attrs = xml_obj->children; id = xmlGetProp(xml_obj, XML_ATTR_ID); uname = xmlGetProp(xml_obj, XML_ATTR_UNAME); type = xmlGetProp(xml_obj, XML_ATTR_TYPE); crm_verbose("Processing node %s/%s", uname, id); if(attrs != NULL) { attrs = attrs->children; } if(id == NULL) { crm_err("Must specify id tag in "); continue; } if(type == NULL) { crm_err("Must specify type tag in "); continue; } crm_malloc(new_node, sizeof(node_t)); if(new_node == NULL) { return FALSE; } new_node->weight = 1.0; new_node->fixed = FALSE; crm_malloc(new_node->details, sizeof(struct node_shared_s)); if(new_node->details == NULL) { crm_free(new_node); return FALSE; } crm_verbose("Creaing node for entry %s/%s", uname, id); new_node->details->id = id; new_node->details->uname = uname; new_node->details->type = node_ping; new_node->details->online = FALSE; new_node->details->unclean = FALSE; new_node->details->shutdown = FALSE; new_node->details->running_rsc = NULL; new_node->details->agents = NULL; new_node->details->attrs = g_hash_table_new( g_str_hash, g_str_equal); if(safe_str_eq(type, "member")) { new_node->details->type = node_member; } add_node_attrs(attrs, new_node); *nodes = g_list_append(*nodes, new_node); crm_verbose("Done with node %s", xmlGetProp(xml_obj, "uname")); crm_debug_action(print_node("Added", new_node, FALSE)); ); *nodes = g_list_sort(*nodes, sort_node_weight); return TRUE; } gboolean unpack_resources(xmlNodePtr xml_resources, GListPtr *resources, GListPtr *actions, - GListPtr *action_cons, + GListPtr *ordering_constraints, GListPtr all_nodes) { crm_verbose("Begining unpack..."); xml_child_iter( xml_resources, xml_obj, XML_CIB_TAG_RESOURCE, 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 *max_instances = xmlGetProp( - xml_obj, "max_instances"); - const char *max_node_instances = xmlGetProp( - xml_obj, "max_node_instances"); - const char *max_masters = xmlGetProp( - xml_obj, "max_masters"); - const char *max_node_masters = xmlGetProp( - xml_obj, "max_node_masters"); - - const char *version = xmlGetProp(xml_obj, XML_ATTR_VERSION); resource_t *new_rsc = NULL; - const char *priority = xmlGetProp( - xml_obj, XML_CIB_ATTR_PRIORITY); crm_verbose("Processing resource..."); if(id == NULL) { crm_err("Must specify id tag in "); continue; } crm_malloc(new_rsc, sizeof(resource_t)); if(new_rsc == NULL) { return FALSE; } - new_rsc->id = id; - new_rsc->xml = xml_obj; - crm_malloc(new_rsc->agent, sizeof(lrm_agent_t)); - new_rsc->agent->class = xmlGetProp(xml_obj, "class"); - new_rsc->agent->type = xmlGetProp(xml_obj, "type"); - new_rsc->agent->version = version?version:"0.0"; - - new_rsc->priority = atoi(priority?priority:"0"); - new_rsc->effective_priority = new_rsc->priority; - new_rsc->recovery_type = recovery_stop_start; - - new_rsc->max_instances = atoi( - max_instances?max_instances:"1"); - new_rsc->max_node_instances = atoi( - max_node_instances?max_node_instances:"1"); - new_rsc->max_masters = atoi( - max_masters?max_masters:"0"); - new_rsc->max_node_masters = atoi( - max_node_masters?max_node_masters:"0"); - - new_rsc->candidate_colors = NULL; - new_rsc->actions = NULL; - new_rsc->color = NULL; - new_rsc->runnable = TRUE; - new_rsc->provisional = TRUE; - new_rsc->allowed_nodes = NULL; - new_rsc->rsc_cons = NULL; - new_rsc->node_cons = NULL; - new_rsc->running_on = NULL; - new_rsc->timeout = timeout; - - if(safe_str_eq(stopfail, "ignore")) { - new_rsc->stopfail_type = pesf_ignore; - } else if(safe_str_eq(stopfail, "stonith")) { - new_rsc->stopfail_type = pesf_stonith; - } else { - new_rsc->stopfail_type = pesf_block; - } - - if(safe_str_eq(restart, "restart")) { - new_rsc->restart_type = pe_restart_restart; - } else if(safe_str_eq(restart, "recover")) { - new_rsc->restart_type = pe_restart_recover; - } else { - new_rsc->restart_type = pe_restart_ignore; - } - - order_new(new_rsc, stop_rsc, NULL, new_rsc, start_rsc, NULL, - pecs_startstop, action_cons); + new_rsc->id = id; + new_rsc->xml = xml_obj; + new_rsc->variant = get_resource_type(xml_obj->name); + new_rsc->fns = &resource_class_functions[new_rsc->variant]; + new_rsc->fns->unpack(new_rsc); + *resources = g_list_append(*resources, new_rsc); crm_debug_action(print_resource("Added", new_rsc, FALSE)); ); *resources = g_list_sort(*resources, sort_rsc_priority); return TRUE; } gboolean unpack_constraints(xmlNodePtr xml_constraints, GListPtr nodes, GListPtr resources, GListPtr *placement_constraints, GListPtr *ordering_constraints) { crm_verbose("Begining unpack..."); xml_child_iter( xml_constraints, xml_obj, NULL, const char *id = xmlGetProp(xml_obj, XML_ATTR_ID); if(id == NULL) { crm_err("Constraint <%s...> must have an id", xml_obj->name); continue; } crm_verbose("Processing constraint %s %s", xml_obj->name,id); if(safe_str_eq("rsc_order", xml_obj->name)) { unpack_rsc_order( xml_obj, resources, ordering_constraints); } else if(safe_str_eq("rsc_dependancy", xml_obj->name)) { unpack_rsc_dependancy( xml_obj, resources, ordering_constraints); } else if(safe_str_eq("rsc_location", xml_obj->name)) { unpack_rsc_location( xml_obj, resources, nodes, placement_constraints); } else { crm_err("Unsupported constraint type: %s", xml_obj->name); } ); return TRUE; } rsc_to_node_t * rsc2node_new(const char *id, resource_t *rsc, double weight, gboolean can, node_t *node, GListPtr *placement_constraints) { rsc_to_node_t *new_con = NULL; if(rsc == NULL || id == NULL) { crm_err("Invalid constraint %s for rsc=%p", crm_str(id), rsc); return NULL; } crm_malloc(new_con, sizeof(rsc_to_node_t)); if(new_con != NULL) { new_con->id = id; new_con->rsc_lh = rsc; new_con->node_list_rh = NULL; new_con->can = can; if(can) { new_con->weight = weight; } else { new_con->weight = -1; } if(node != NULL) { new_con->node_list_rh = g_list_append(NULL, node); } *placement_constraints = g_list_append(*placement_constraints, new_con); } return new_con; } /* remove nodes that are down, stopping */ /* create +ve rsc_to_node constraints between resources and the nodes they are running on */ /* anything else? */ gboolean unpack_status(xmlNodePtr status, GListPtr nodes, GListPtr rsc_list, GListPtr *actions, GListPtr *placement_constraints) { const char *uname = NULL; xmlNodePtr lrm_rsc = NULL; xmlNodePtr lrm_agents = NULL; xmlNodePtr attrs = NULL; node_t *this_node = NULL; crm_verbose("Begining unpack"); xml_child_iter( status, node_state, XML_CIB_TAG_STATE, /* id = xmlGetProp(node_state, XML_ATTR_ID); */ uname = xmlGetProp(node_state, XML_ATTR_UNAME); attrs = find_xml_node(node_state, "attributes"); lrm_rsc = find_xml_node(node_state, XML_CIB_TAG_LRM); lrm_agents = find_xml_node(lrm_rsc, "lrm_agents"); lrm_rsc = find_xml_node(lrm_rsc, XML_LRM_TAG_RESOURCES); lrm_rsc = find_xml_node(lrm_rsc, "lrm_resource"); crm_verbose("Processing node %s", uname); this_node = pe_find_node(nodes, uname); if(uname == NULL) { /* error */ continue; } else if(this_node == NULL) { crm_err("Node %s in status section no longer exists", uname); continue; } crm_verbose("Adding runtime node attrs"); add_node_attrs(attrs, this_node); crm_verbose("determining node state"); determine_online_status(node_state, this_node); crm_verbose("Processing lrm resource entries"); unpack_lrm_rsc_state(this_node, lrm_rsc, rsc_list, nodes, actions, placement_constraints); crm_verbose("Processing lrm agents"); unpack_lrm_agents(this_node, lrm_agents); ); return TRUE; } gboolean determine_online_status(xmlNodePtr node_state, node_t *this_node) { gboolean online = FALSE; const char *uname = xmlGetProp(node_state,XML_ATTR_UNAME); /* const char *state = xmlGetProp(node_state,XML_NODE_ATTR_STATE); */ const char *exp_state = xmlGetProp(node_state,XML_CIB_ATTR_EXPSTATE); const char *join_state = xmlGetProp(node_state,XML_CIB_ATTR_JOINSTATE); const char *crm_state = xmlGetProp(node_state,XML_CIB_ATTR_CRMDSTATE); const char *ccm_state = xmlGetProp(node_state,XML_CIB_ATTR_INCCM); const char *ha_state = xmlGetProp(node_state,XML_CIB_ATTR_HASTATE); const char *shutdown = xmlGetProp(node_state,XML_CIB_ATTR_SHUTDOWN); const char *unclean = NULL;/*xmlGetProp(node_state,XML_CIB_ATTR_STONITH); */ if(safe_str_eq(join_state, CRMD_JOINSTATE_MEMBER) && safe_str_eq(ccm_state, XML_BOOLEAN_YES) && (ha_state == NULL || safe_str_eq(ha_state, ACTIVESTATUS)) && safe_str_eq(crm_state, ONLINESTATUS) && shutdown == NULL) { if(this_node != NULL) { this_node->details->online = TRUE; } crm_debug("Node %s is online", uname); online = TRUE; } else if(this_node != NULL) { /* remove node from contention */ this_node->weight = -1; this_node->fixed = TRUE; crm_verbose("join_state=%s, expected=%s, shutdown=%s", crm_str(join_state), crm_str(exp_state), crm_str(shutdown)); if(unclean != NULL) { this_node->details->unclean = TRUE; } else if(is_node_unclean(node_state)) { /* report and or take remedial action */ this_node->details->unclean = TRUE; } if(shutdown != NULL) { this_node->details->shutdown = TRUE; } if(this_node->details->unclean) { crm_warn("Node %s is due for STONITH", uname); } if(this_node->details->shutdown) { crm_info("Node %s is due for shutdown", uname); } } return online; } gboolean is_node_unclean(xmlNodePtr node_state) { /* const char *state = xmlGetProp(node_state,XML_NODE_ATTR_STATE); */ const char *uname = xmlGetProp(node_state,XML_ATTR_UNAME); const char *exp_state = xmlGetProp(node_state,XML_CIB_ATTR_EXPSTATE); const char *join_state = xmlGetProp(node_state,XML_CIB_ATTR_JOINSTATE); const char *crm_state = xmlGetProp(node_state,XML_CIB_ATTR_CRMDSTATE); const char *ha_state = xmlGetProp(node_state,XML_CIB_ATTR_HASTATE); const char *ccm_state = xmlGetProp(node_state,XML_CIB_ATTR_INCCM); if(safe_str_eq(exp_state, CRMD_STATE_INACTIVE)) { crm_debug("Node %s is safely inactive", uname); return FALSE; /* do an actual calculation once STONITH is available */ } else if(safe_str_neq(exp_state, CRMD_JOINSTATE_DOWN)) { if(safe_str_eq(crm_state, OFFLINESTATUS) || (ha_state != NULL && safe_str_eq(ha_state, DEADSTATUS)) || safe_str_eq(join_state, CRMD_JOINSTATE_DOWN) || safe_str_eq(ccm_state, XML_BOOLEAN_NO)) { crm_warn("Node %s is un-expectedly down", uname); return TRUE; } crm_debug("Node %s: ha=%s, join=%s, crm=%s, ccm=%s", uname, ha_state, join_state, crm_state, ccm_state); } else { crm_debug("Node %s was expected to be down", uname); } return FALSE; } gboolean unpack_lrm_agents(node_t *node, xmlNodePtr agent_list) { /* if the agent is not listed, remove the node from * the resource's list of allowed_nodes */ lrm_agent_t *agent = NULL; const char *version = NULL; if(agent_list == NULL) { return FALSE; } xml_child_iter( agent_list, xml_agent, XML_LRM_TAG_AGENT, crm_malloc(agent, sizeof(lrm_agent_t)); if(agent == NULL) { continue; } agent->class = xmlGetProp(xml_agent, "class"); agent->type = xmlGetProp(xml_agent, "type"); version = xmlGetProp(xml_agent, "version"); agent->version = version?version:"0.0"; crm_trace("Adding agent %s/%s v%s to node %s", agent->class, agent->type, agent->version, node->details->uname); node->details->agents = g_list_append( node->details->agents, agent); ); return TRUE; } gboolean unpack_lrm_rsc_state(node_t *node, xmlNodePtr lrm_rsc, GListPtr rsc_list, GListPtr nodes, GListPtr *actions, GListPtr *placement_constraints) { xmlNodePtr rsc_entry = NULL; const char *rsc_id = NULL; const char *node_id = NULL; const char *rsc_state = NULL; const char *op_status = NULL; const char *last_rc = NULL; const char *last_op = NULL; resource_t *rsc_lh = NULL; op_status_t action_status_i = LRM_OP_ERROR; while(lrm_rsc != NULL) { rsc_entry = lrm_rsc; lrm_rsc = lrm_rsc->next; rsc_id = xmlGetProp(rsc_entry, XML_ATTR_ID); node_id = xmlGetProp(rsc_entry, XML_LRM_ATTR_TARGET); rsc_state = xmlGetProp(rsc_entry, XML_LRM_ATTR_RSCSTATE); op_status = xmlGetProp(rsc_entry, XML_LRM_ATTR_OPSTATUS); last_rc = xmlGetProp(rsc_entry, XML_LRM_ATTR_RC); last_op = xmlGetProp(rsc_entry, XML_LRM_ATTR_LASTOP); rsc_lh = pe_find_resource(rsc_list, rsc_id); crm_verbose("[%s] Processing %s on %s (%s)", rsc_entry->name, rsc_id, node_id, rsc_state); if(rsc_lh == NULL) { crm_err("Could not find a match for resource" " %s in %s's status section", rsc_id, node_id); continue; } else if(op_status == NULL) { crm_err("Invalid resource status entry for %s in %s", rsc_id, node_id); continue; } action_status_i = atoi(op_status); if(node->details->unclean) { crm_info("Node %s (where %s is running) is unclean." "Further action depends on the value of on_stopfail", node->details->uname, rsc_lh->id); /* map the status to an error and then handle as a * failed resource. */ action_status_i = LRM_OP_ERROR; } else if(action_status_i == -1) { /* * TODO: this may need some more thought * Some cases: * - PE reinvoked with pending action that will succeed * - PE reinvoked with pending action that will fail * - After DC election * - After startup * * pending start - required start * pending stop - required stop * pending on unavailable node - stonith * * For now this should do */ if(safe_str_eq(last_op, "stop")) { /* map this to a timeout so it is re-issued */ action_status_i = LRM_OP_TIMEOUT; } else { /* map this to a "done" so it is not marked * as failed, then make sure it is re-issued */ action_new(rsc_lh, start_rsc, NULL); action_status_i = LRM_OP_DONE; } } switch(action_status_i) { case LRM_OP_DONE: unpack_healthy_resource( placement_constraints, actions, rsc_entry, rsc_lh,node); break; case LRM_OP_ERROR: case LRM_OP_TIMEOUT: case LRM_OP_NOTSUPPORTED: unpack_failed_resource( placement_constraints, actions, rsc_entry, rsc_lh,node); break; case LRM_OP_CANCELLED: /* do nothing?? */ crm_warn("Dont know what to do for cancelled ops yet"); break; } } return TRUE; } gboolean unpack_failed_resource(GListPtr *placement_constraints, GListPtr *actions, xmlNodePtr rsc_entry, resource_t *rsc_lh, node_t *node) { const char *last_op = xmlGetProp(rsc_entry, "last_op"); crm_debug("Unpacking failed action %s on %s", last_op, rsc_lh->id); /* make sure we dont allocate the resource here again*/ rsc2node_new("dont_run__generated", rsc_lh, -1.0, FALSE, node, placement_constraints); if(safe_str_eq(last_op, "start")) { /* the resource is not actually running... nothing more to do*/ return TRUE; } switch(rsc_lh->stopfail_type) { case pesf_stonith: /* treat it as if it is still running * but also mark the node as unclean */ rsc_lh->running_on = g_list_append( rsc_lh->running_on, node); node->details->running_rsc = g_list_append( node->details->running_rsc, rsc_lh); if(node->details->online) { node->details->shutdown = TRUE; } node->details->unclean = TRUE; break; case pesf_block: /* let this depend on the stop action which will fail * but make sure the transition continues... */ rsc_lh->running_on = g_list_append( rsc_lh->running_on, node); node->details->running_rsc = g_list_append( node->details->running_rsc, rsc_lh); /* rsc_lh->stop->timeout = NULL; /\* wait forever *\/ */ break; case pesf_ignore: /* pretend nothing happened */ break; } return TRUE; } gboolean unpack_healthy_resource(GListPtr *placement_constraints, GListPtr *actions, xmlNodePtr rsc_entry, resource_t *rsc_lh, node_t *node) { const char *last_op = xmlGetProp(rsc_entry, "last_op"); crm_debug("Unpacking healthy action %s on %s", last_op, rsc_lh->id); if(safe_str_neq(last_op, "stop")) { /* create the link between this node and the rsc */ crm_verbose("Setting cur_node = %s for rsc = %s", node->details->uname, rsc_lh->id); rsc_lh->running_on = g_list_append( rsc_lh->running_on, node); if(g_list_length(rsc_lh->running_on) > 1) { crm_warn("Resource %s active on %d nodes. Latest: %s (%s)", rsc_lh->id, g_list_length(rsc_lh->running_on), node->details->id, last_op); /* action_new(rsc_lh, stop_rsc, node); */ } node->details->running_rsc = g_list_append( node->details->running_rsc, rsc_lh); } return TRUE; } gboolean -rsc2rsc_new(const char *id, enum con_strength strength, enum rsc_con_type type, - resource_t *rsc_lh, resource_t *rsc_rh) +rsc_dependancy_new(const char *id, enum con_strength strength, + resource_t *rsc_lh, resource_t *rsc_rh) { - rsc_to_rsc_t *new_con = NULL; - rsc_to_rsc_t *inverted_con = NULL; + rsc_dependancy_t *new_con = NULL; + rsc_dependancy_t *inverted_con = NULL; if(rsc_lh == NULL || rsc_rh == NULL){ /* error */ return FALSE; } - crm_malloc(new_con, sizeof(rsc_to_rsc_t)); + crm_malloc(new_con, sizeof(rsc_dependancy_t)); if(new_con != NULL) { new_con->id = id; new_con->rsc_lh = rsc_lh; new_con->rsc_rh = rsc_rh; new_con->strength = strength; - new_con->variant = type; inverted_con = invert_constraint(new_con); rsc_lh->rsc_cons = g_list_insert_sorted( rsc_lh->rsc_cons, new_con, sort_cons_strength); rsc_rh->rsc_cons = g_list_insert_sorted( rsc_rh->rsc_cons, inverted_con, sort_cons_strength); } else { return FALSE; } return TRUE; } gboolean order_new(resource_t *lh_rsc, enum action_tasks lh_action_task, action_t *lh_action, resource_t *rh_rsc, enum action_tasks rh_action_task, action_t *rh_action, enum con_strength strength, GListPtr *ordering_constraints) { order_constraint_t *order = NULL; if((lh_action == NULL && lh_rsc == NULL) || (rh_action == NULL && rh_rsc == NULL) || ordering_constraints == NULL){ crm_err("Invalid inputs lh_rsc=%p, lh_a=%p," " rh_rsc=%p, rh_a=%p, l=%p", lh_rsc, lh_action, rh_rsc, rh_action, ordering_constraints); return FALSE; } crm_malloc(order, sizeof(order_constraint_t)); if(order != NULL) { order->id = order_id++; order->strength = strength; order->lh_rsc = lh_rsc; order->rh_rsc = rh_rsc; order->lh_action = lh_action; order->rh_action = rh_action; order->lh_action_task = lh_action_task; order->rh_action_task = rh_action_task; *ordering_constraints = g_list_append( *ordering_constraints, order); if(lh_rsc != NULL && rh_rsc != NULL) { crm_debug("Created ordering constraint %d (%s):" " %s/%s before %s/%s", order->id, strength2text(order->strength), lh_rsc->id, task2text(lh_action_task), rh_rsc->id, task2text(rh_action_task)); } else if(lh_rsc != NULL) { crm_debug("Created ordering constraint %d (%s):" " %s/%s before action %d (%s)", order->id, strength2text(order->strength), lh_rsc->id, task2text(lh_action_task), rh_action->id, task2text(rh_action_task)); } else if(rh_rsc != NULL) { crm_debug("Created ordering constraint %d (%s):" " action %d (%s) before %s/%s", order->id, strength2text(order->strength), lh_action->id, task2text(lh_action_task), rh_rsc->id, task2text(rh_action_task)); } else { crm_debug("Created ordering constraint %d (%s):" " action %d (%s) before action %d (%s)", order->id, strength2text(order->strength), lh_action->id, task2text(lh_action_task), rh_action->id, task2text(rh_action_task)); } } return TRUE; } gboolean unpack_rsc_dependancy(xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr *ordering_constraints) { enum con_strength strength_e = pecs_ignore; const char *id_lh = xmlGetProp(xml_obj, "from"); const char *id = xmlGetProp(xml_obj, XML_ATTR_ID); const char *id_rh = xmlGetProp(xml_obj, "to"); const char *type = xmlGetProp(xml_obj, XML_ATTR_TYPE); resource_t *rsc_lh = pe_find_resource(rsc_list, id_lh); resource_t *rsc_rh = pe_find_resource(rsc_list, id_rh); if(rsc_lh == NULL) { crm_err("No resource (con=%s, rsc=%s)", id, id_lh); return FALSE; } else if(rsc_rh == NULL) { crm_err("No resource (con=%s, rsc=%s)", id, id_rh); return FALSE; } if(safe_str_eq(type, XML_STRENGTH_VAL_MUST)) { strength_e = pecs_must; } else if(safe_str_eq(type, XML_STRENGTH_VAL_SHOULD)) { crm_err("Type %s is no longer supported", type); strength_e = pecs_must; } else if(safe_str_eq(type, XML_STRENGTH_VAL_SHOULDNOT)) { crm_err("Type %s is no longer supported", type); strength_e = pecs_must_not; } else if(safe_str_eq(type, XML_STRENGTH_VAL_MUSTNOT)) { strength_e = pecs_must_not; } else { crm_err("Unknown value for %s: %s", "type", type); return FALSE; } - return rsc2rsc_new(id, strength_e, same_node, rsc_lh, rsc_rh); + return rsc_dependancy_new(id, strength_e, rsc_lh, rsc_rh); } gboolean unpack_rsc_order(xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr *ordering_constraints) { const char *id = xmlGetProp(xml_obj, XML_ATTR_ID); const char *id_lh = xmlGetProp(xml_obj, "from"); const char *id_rh = xmlGetProp(xml_obj, "to"); const char *type = xmlGetProp(xml_obj, XML_ATTR_TYPE); resource_t *rsc_lh = pe_find_resource(rsc_list, id_lh); resource_t *rsc_rh = pe_find_resource(rsc_list, id_rh); if(xml_obj == NULL) { crm_err("No constraint object to process."); return FALSE; } else if(id == NULL) { crm_err("%s constraint must have an id", xml_obj->name); return FALSE; } else if(rsc_lh == NULL || rsc_rh == NULL) { crm_err("Constraint %s needs two sides lh: %p rh: %p" " (NULL indicates missing side)", id, rsc_lh, rsc_rh); return FALSE; } else if(safe_str_eq(type, "after")) { order_new(rsc_rh, stop_rsc, NULL, rsc_lh, stop_rsc, NULL, pecs_must, ordering_constraints); order_new(rsc_lh, start_rsc, NULL, rsc_rh, start_rsc, NULL, pecs_must, ordering_constraints); } else { order_new(rsc_lh, stop_rsc, NULL, rsc_rh, stop_rsc, NULL, pecs_must, ordering_constraints); order_new(rsc_rh, start_rsc, NULL, rsc_lh, start_rsc, NULL, pecs_must, ordering_constraints); } return TRUE; } /* do NOT free the nodes returned here */ GListPtr match_attrs(const char *attr, const char *op, const char *value, const char *type, GListPtr node_list) { int lpc = 0, lpc2 = 0; GListPtr result = NULL; if(attr == NULL || op == NULL) { crm_err("Invlaid attribute or operation in expression" " (\'%s\' \'%s\' \'%s\')", crm_str(attr), crm_str(op), crm_str(value)); return NULL; } slist_iter( node, node_t, node_list, lpc, gboolean accept = FALSE; int cmp = 0; const char *h_val = (const char*)g_hash_table_lookup( node->details->attrs, attr); if(value != NULL && h_val != NULL) { if(type == NULL || (safe_str_eq(type, "string"))) { cmp = strcmp(h_val, value); } else if(safe_str_eq(type, "number")) { float h_val_f = atof(h_val); float value_f = atof(value); if(h_val_f < value_f) { cmp = -1; } else if(h_val_f > value_f) { cmp = 1; } else { cmp = 0; } } else if(safe_str_eq(type, "version")) { cmp = compare_version(h_val, value); } } else if(value == NULL && h_val == NULL) { cmp = 0; } else if(value == NULL) { cmp = 1; } else { cmp = -1; } if(safe_str_eq(op, "exists")) { if(h_val != NULL) accept = TRUE; } else if(safe_str_eq(op, "notexists")) { if(h_val == NULL) accept = TRUE; } else if(safe_str_eq(op, "running")) { GListPtr rsc_list = node->details->running_rsc; slist_iter( rsc, resource_t, rsc_list, lpc2, if(safe_str_eq(rsc->id, attr)) { accept = TRUE; } ); } else if(safe_str_eq(op, "not_running")) { GListPtr rsc_list = node->details->running_rsc; accept = TRUE; slist_iter( rsc, resource_t, rsc_list, lpc2, if(safe_str_eq(rsc->id, attr)) { accept = FALSE; break; } ); } else if(safe_str_eq(op, "eq")) { if((h_val == value) || cmp == 0) accept = TRUE; } else if(safe_str_eq(op, "ne")) { if((h_val == NULL && value != NULL) || (h_val != NULL && value == NULL) || cmp != 0) accept = TRUE; } else if(value == NULL || h_val == NULL) { /* the comparision is meaningless from this point on */ accept = FALSE; } else if(safe_str_eq(op, "lt")) { if(cmp < 0) accept = TRUE; } else if(safe_str_eq(op, "lte")) { if(cmp <= 0) accept = TRUE; } else if(safe_str_eq(op, "gt")) { if(cmp > 0) accept = TRUE; } else if(safe_str_eq(op, "gte")) { if(cmp >= 0) accept = TRUE; } if(accept) { crm_trace("node %s matched", node->details->uname); result = g_list_append(result, node); } else { crm_trace("node %s did not match", node->details->uname); } ); return result; } gboolean add_node_attrs(xmlNodePtr attrs, node_t *node) { const char *name = NULL; const char *value = NULL; while(attrs != NULL){ name = xmlGetProp(attrs, XML_NVPAIR_ATTR_NAME); value = xmlGetProp(attrs, XML_NVPAIR_ATTR_VALUE); if(name != NULL && value != NULL && safe_val(NULL, node, details) != NULL) { crm_verbose("Adding %s => %s", name, value); /* this is frustrating... no way to pass in const * keys or values yet docs say: * Note: If keys and/or values are dynamically * allocated, you should free them first. */ g_hash_table_insert(node->details->attrs, crm_strdup(name), crm_strdup(value)); } attrs = attrs->next; } g_hash_table_insert(node->details->attrs, crm_strdup("uname"), crm_strdup(node->details->uname)); g_hash_table_insert(node->details->attrs, crm_strdup("id"), crm_strdup(node->details->id)); return TRUE; } gboolean unpack_rsc_location( xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr node_list, GListPtr *placement_constraints) { /* ... Translation: Further translation: */ gboolean were_rules = FALSE; const char *id_lh = xmlGetProp(xml_obj, "rsc"); const char *id = xmlGetProp(xml_obj, XML_ATTR_ID); resource_t *rsc_lh = pe_find_resource(rsc_list, id_lh); if(rsc_lh == NULL) { crm_err("No resource (con=%s, rsc=%s)", id, id_lh); return FALSE; } xml_child_iter( xml_obj, rule, "rule", gboolean first_expr = TRUE; gboolean can_run = FALSE; gboolean do_and = TRUE; gboolean rule_has_expressions; const char *rule_id = xmlGetProp(rule, XML_ATTR_ID); const char *score = xmlGetProp(rule, "score"); const char *result = xmlGetProp(rule, "result"); const char *boolean = xmlGetProp(rule, "boolean_op"); GListPtr match_L = NULL; GListPtr old_list = NULL; float score_f = atof(score?score:"0.0"); rsc_to_node_t *new_con = NULL; were_rules = TRUE; if(safe_str_eq(boolean, "or")) { do_and = FALSE; } if(result == NULL || (safe_str_eq(result, "can"))) { can_run = TRUE; } new_con = rsc2node_new(rule_id, rsc_lh, score_f, can_run, NULL, placement_constraints); if(new_con == NULL) { continue; } rule_has_expressions = FALSE; xml_child_iter( rule, expr, "expression", const char *attr = xmlGetProp(expr, "attribute"); const char *op = xmlGetProp(expr, "operation"); const char *value = xmlGetProp(expr, "value"); const char *type = xmlGetProp(expr, "type"); rule_has_expressions = TRUE; crm_trace("processing expression: %s", xmlGetProp(expr, "id")); match_L = match_attrs( attr, op, value, type, node_list); if(first_expr) { new_con->node_list_rh = node_list_dup( match_L, FALSE); first_expr = FALSE; continue; } old_list = new_con->node_list_rh; if(do_and) { crm_trace("do_and"); new_con->node_list_rh = node_list_and( old_list, match_L, FALSE); } else { crm_trace("do_or"); new_con->node_list_rh = node_list_or( old_list, match_L, FALSE); } pe_free_shallow_adv(match_L, FALSE); pe_free_shallow_adv(old_list, TRUE); ); if(rule_has_expressions == FALSE) { /* feels like a hack */ crm_debug("Rule %s had no expressions," " adding all nodes", xmlGetProp(rule, "id")); new_con->node_list_rh = node_list_dup(node_list,FALSE); } if(new_con->node_list_rh == NULL) { crm_warn("No matching nodes for constraint/rule %s/%s", id, xmlGetProp(rule, "id")); } crm_debug_action(print_rsc_to_node("Added", new_con, FALSE)); ); if(were_rules == FALSE) { crm_err("no rules for constraint %s", id); } return TRUE; } diff --git a/crm/pengine/utils.c b/crm/pengine/utils.c index de515f44ee..5664409cb8 100644 --- a/crm/pengine/utils.c +++ b/crm/pengine/utils.c @@ -1,1155 +1,1086 @@ -/* $Id: utils.c,v 1.43 2004/10/27 15:30:55 andrew Exp $ */ +/* $Id: utils.c,v 1.44 2004/11/09 09:32:14 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include int action_id = 1; void print_str_str(gpointer key, gpointer value, gpointer user_data); gboolean ghash_free_str_str(gpointer key, gpointer value, gpointer user_data); gboolean node_merge_weights(node_t *node, node_t *with); -/* only for rsc_to_rsc constraints */ -rsc_to_rsc_t * -invert_constraint(rsc_to_rsc_t *constraint) +/* only for rsc_dependancy constraints */ +rsc_dependancy_t * +invert_constraint(rsc_dependancy_t *constraint) { - rsc_to_rsc_t *inverted_con = NULL; + 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_to_rsc_t)); + 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; - switch(constraint->variant) { - case same_node: - inverted_con->variant = same_node; - break; - case start_before: - inverted_con->variant = start_after; - break; - case start_after: - inverted_con->variant = start_before; - break; - } - crm_debug_action( - print_rsc_to_rsc("Inverted constraint", inverted_con, FALSE)); + print_rsc_dependancy("Inverted constraint", inverted_con, FALSE)); return inverted_con; } /* are the contents of list1 and list2 equal * nodes with weight < 0 are ignored if filter == TRUE * * slow but linear * */ gboolean node_list_eq(GListPtr list1, GListPtr list2, gboolean filter) { int lpc; node_t *other_node; GListPtr lhs = list1; GListPtr rhs = list2; slist_iter( node, node_t, lhs, lpc, if(node == NULL || (filter && node->weight < 0)) { continue; } other_node = (node_t*) pe_find_node(rhs, node->details->uname); if(other_node == NULL || other_node->weight < 0) { return FALSE; } ); lhs = list2; rhs = list1; slist_iter( node, node_t, lhs, lpc, if(node == NULL || (filter && node->weight < 0)) { continue; } other_node = (node_t*) pe_find_node(rhs, node->details->uname); if(other_node == NULL || other_node->weight < 0) { return FALSE; } ); return TRUE; } /* the intersection of list1 and list2 */ GListPtr node_list_and(GListPtr list1, GListPtr list2, gboolean filter) { GListPtr result = NULL; int lpc = 0; for(lpc = 0; lpc < g_list_length(list1); lpc++) { node_t *node = (node_t*)g_list_nth_data(list1, lpc); node_t *new_node = node_copy(node); node_t *other_node = pe_find_node(list2, node->details->uname); if(node_merge_weights(new_node, other_node) == FALSE) { crm_free(new_node); } else if(filter && new_node->weight < 0) { crm_free(new_node); } else { result = g_list_append(result, new_node); } } return result; } gboolean node_merge_weights(node_t *node, node_t *with) { if(node == NULL || with == NULL) { return FALSE; } else if(node->weight < 0 || with->weight < 0) { node->weight = -1; } else if(node->weight < with->weight) { node->weight = with->weight; } return TRUE; } /* list1 - list2 */ GListPtr node_list_minus(GListPtr list1, GListPtr list2, gboolean filter) { GListPtr result = NULL; int lpc = 0; slist_iter( node, node_t, list1, lpc, node_t *other_node = pe_find_node(list2, node->details->uname); node_t *new_node = NULL; if(node == NULL || other_node != NULL || (filter && node->weight < 0)) { continue; } new_node = node_copy(node); result = g_list_append(result, new_node); ); crm_verbose("Minus result len: %d", g_list_length(result)); return result; } /* list1 + list2 - (intersection of list1 and list2) */ GListPtr node_list_xor(GListPtr list1, GListPtr list2, gboolean filter) { GListPtr result = NULL; int lpc = 0; slist_iter( node, node_t, list1, lpc, node_t *new_node = NULL; node_t *other_node = (node_t*) pe_find_node(list2, node->details->uname); if(node == NULL || other_node != NULL || (filter && node->weight < 0)) { continue; } new_node = node_copy(node); result = g_list_append(result, new_node); ); slist_iter( node, node_t, list2, lpc, node_t *new_node = NULL; node_t *other_node = (node_t*) pe_find_node(list1, node->details->uname); if(node == NULL || other_node != NULL || (filter && node->weight < 0)) { continue; } new_node = node_copy(node); result = g_list_append(result, new_node); ); crm_verbose("Xor result len: %d", g_list_length(result)); return result; } GListPtr node_list_or(GListPtr list1, GListPtr list2, gboolean filter) { node_t *other_node = NULL; GListPtr result = NULL; int lpc = 0; result = node_list_dup(list1, filter); slist_iter( node, node_t, list2, lpc, if(node == NULL) { continue; } other_node = (node_t*)pe_find_node( result, node->details->uname); if(other_node != NULL) { node_merge_weights(other_node, node); if(filter && node->weight < 0) { /* TODO: remove and free other_node */ } } else if(filter && node->weight < 0) { } else { node_t *new_node = node_copy(node); result = g_list_append(result, new_node); } ); return result; } GListPtr node_list_dup(GListPtr list1, gboolean filter) { GListPtr result = NULL; int lpc = 0; slist_iter( this_node, node_t, list1, lpc, node_t *new_node = NULL; if(filter && this_node->weight < 0) { continue; } new_node = node_copy(this_node); if(new_node != NULL) { result = g_list_append(result, new_node); } ); return result; } node_t * node_copy(node_t *this_node) { node_t *new_node = NULL; if(this_node == NULL) { crm_err("Failed copy of node."); return NULL; } crm_malloc(new_node, sizeof(node_t)); if(new_node == NULL) { return NULL; } crm_trace("Copying %p (%s) to %p", this_node, this_node->details->uname, new_node); new_node->weight = this_node->weight; new_node->fixed = this_node->fixed; new_node->details = this_node->details; return new_node; } static int color_id = 0; /* * Create a new color with the contents of "nodes" as the list of * possible nodes that resources with this color can be run on. * * Typically, when creating a color you will provide the node list from * the resource you will first assign the color to. * * If "colors" != NULL, it will be added to that list * If "resources" != NULL, it will be added to every provisional resource * in that list */ color_t * create_color(GListPtr *colors, resource_t *resource, GListPtr resources) { color_t *new_color = NULL; crm_trace("Creating color"); crm_malloc(new_color, sizeof(color_t)); if(new_color == NULL) { return NULL; } new_color->id = color_id++; new_color->local_weight = 1.0; crm_trace("Creating color details"); crm_malloc(new_color->details, sizeof(struct color_shared_s)); if(new_color->details == NULL) { crm_free(new_color); return NULL; } new_color->details->id = new_color->id; new_color->details->highest_priority = -1; new_color->details->chosen_node = NULL; new_color->details->candidate_nodes = NULL; new_color->details->allocated_resources = NULL; new_color->details->pending = TRUE; if(resource != NULL) { crm_trace("populating node list"); new_color->details->highest_priority = resource->priority; new_color->details->candidate_nodes = node_list_dup(resource->allowed_nodes, TRUE); } crm_debug_action(print_color("Created color", new_color, TRUE)); if(colors != NULL) { *colors = g_list_append(*colors, new_color); } return new_color; } color_t * copy_color(color_t *a_color) { color_t *color_copy = NULL; if(a_color == NULL) { crm_err("Cannot copy NULL"); return NULL; } crm_malloc(color_copy, sizeof(color_t)); if(color_copy != NULL) { color_copy->id = a_color->id; color_copy->details = a_color->details; color_copy->local_weight = 1.0; } return color_copy; } /* * Remove any nodes with a -ve weight */ gboolean filter_nodes(resource_t *rsc) { int lpc2 = 0; crm_debug_action(print_resource("Filtering nodes for", rsc, FALSE)); slist_iter( node, node_t, rsc->allowed_nodes, lpc2, if(node == NULL) { crm_err("Invalid NULL node"); } else if(node->weight < 0.0 || node->details->online == FALSE || node->details->type == node_ping) { crm_debug_action(print_node("Removing", node, FALSE)); rsc->allowed_nodes = g_list_remove(rsc->allowed_nodes,node); crm_free(node); lpc2 = -1; /* restart the loop */ } ); return TRUE; } resource_t * pe_find_resource(GListPtr rsc_list, const char *id_rh) { int lpc = 0; resource_t *rsc = NULL; for(lpc = 0; lpc < g_list_length(rsc_list); lpc++) { rsc = g_list_nth_data(rsc_list, lpc); if(rsc != NULL && safe_str_eq(rsc->id, id_rh)){ return rsc; } } /* error */ return NULL; } node_t * pe_find_node(GListPtr nodes, const char *uname) { int lpc = 0; node_t *node = NULL; for(lpc = 0; lpc < g_list_length(nodes); lpc++) { node = g_list_nth_data(nodes, lpc); if(node != NULL && safe_str_eq(node->details->uname, uname)) { return node; } } /* error */ return NULL; } node_t * pe_find_node_id(GListPtr nodes, const char *id) { int lpc = 0; node_t *node = NULL; for(lpc = 0; lpc < g_list_length(nodes); lpc++) { node = g_list_nth_data(nodes, lpc); if(safe_str_eq(node->details->id, id)) { return node; } } /* error */ return NULL; } gint gslist_color_compare(gconstpointer a, gconstpointer b); color_t * find_color(GListPtr candidate_colors, color_t *other_color) { GListPtr tmp = g_list_find_custom(candidate_colors, other_color, gslist_color_compare); if(tmp != NULL) { return (color_t *)tmp->data; } return NULL; } gint gslist_color_compare(gconstpointer a, gconstpointer b) { const color_t *color_a = (const color_t*)a; const color_t *color_b = (const color_t*)b; /* crm_trace("%d vs. %d", a?color_a->id:-2, b?color_b->id:-2); */ if(a == b) { return 0; } else if(a == NULL || b == NULL) { return 1; } else if(color_a->id == color_b->id) { return 0; } return 1; } gint sort_rsc_priority(gconstpointer a, gconstpointer b) { const resource_t *resource1 = (const resource_t*)a; const resource_t *resource2 = (const resource_t*)b; if(a == NULL) return 1; if(b == NULL) return -1; if(resource1->priority > resource2->priority) return -1; if(resource1->priority < resource2->priority) return 1; return 0; } gint sort_cons_strength(gconstpointer a, gconstpointer b) { - const rsc_to_rsc_t *rsc_constraint1 = (const rsc_to_rsc_t*)a; - const rsc_to_rsc_t *rsc_constraint2 = (const rsc_to_rsc_t*)b; + const rsc_dependancy_t *rsc_constraint1 = (const rsc_dependancy_t*)a; + const rsc_dependancy_t *rsc_constraint2 = (const rsc_dependancy_t*)b; if(a == NULL) return 1; if(b == NULL) return -1; if(rsc_constraint1->strength > rsc_constraint2->strength) return 1; if(rsc_constraint1->strength < rsc_constraint2->strength) return -1; return 0; } gint sort_color_weight(gconstpointer a, gconstpointer b) { const color_t *color1 = (const color_t*)a; const color_t *color2 = (const color_t*)b; if(a == NULL) return 1; if(b == NULL) return -1; if(color1->local_weight > color2->local_weight) return -1; if(color1->local_weight < color2->local_weight) return 1; return 0; } gint sort_node_weight(gconstpointer a, gconstpointer b) { const node_t *node1 = (const node_t*)a; const node_t *node2 = (const node_t*)b; if(a == NULL) return 1; if(b == NULL) return -1; if(node1->weight > node2->weight) return -1; if(node1->weight < node2->weight) return 1; return 0; } action_t * action_new(resource_t *rsc, enum action_tasks task, node_t *on_node) { action_t *action = NULL; GListPtr possible_matches = NULL; if(rsc != NULL) { - possible_matches = find_actions_type(rsc->actions, task, on_node); + possible_matches = + find_actions_type(rsc->actions, task, on_node); + } + + if(on_node != NULL && on_node->details->unclean) { + crm_warn("Not creating action %s for %s because %s is unclean", + task2text(task), rsc?rsc->id:"", + on_node->details->id); + } + + if(on_node != NULL && on_node->details->unclean) { + crm_warn("Not creating action %s for %s because %s is unclean", + task2text(task), rsc?rsc->id:"", + on_node->details->id); } if(possible_matches != NULL) { if(g_list_length(possible_matches) > 1) { crm_err("Action %s for %s on %s exists %d times", task2text(task), rsc?rsc->id:"", on_node?on_node->details->id:"", g_list_length(possible_matches)); } action = g_list_nth_data(possible_matches, 0); crm_debug("Returning existing action (%d) %s for %s on %s", action->id, task2text(task), rsc?rsc->id:"", on_node?on_node->details->id:""); /* todo: free possible_matches */ return action; } crm_debug("Creating action %s for %s on %s", task2text(task), rsc?rsc->id:"", on_node?on_node->details->id:""); crm_malloc(action, sizeof(action_t)); if(action != NULL) { action->id = action_id++; action->rsc = rsc; action->task = task; action->node = on_node; action->actions_before = NULL; action->actions_after = NULL; action->failure_is_fatal = TRUE; action->dumped = FALSE; action->discard = FALSE; action->runnable = TRUE; action->processed = FALSE; action->optional = FALSE; action->seen_count = 0; action->timeout = NULL; action->args = create_xml_node(NULL, "args"); if(rsc != NULL) { crm_debug("Adding created action to its resource"); rsc->actions = g_list_append(rsc->actions, action); if(rsc->timeout != NULL) { action->timeout = crm_strdup(rsc->timeout); } } } crm_debug("Action %d created", action->id); return action; } -const char * -contype2text(enum con_type type) -{ - const char *result = ""; - switch(type) - { - case type_none: - result = "none"; - break; - case rsc_to_rsc: - result = "rsc_to_rsc"; - break; - case rsc_to_node: - result = "rsc_to_node"; - break; - case rsc_to_attr: - result = "rsc_to_attr"; - break; - case base_weight: - result = "base_weight"; - break; - } - return result; -} - const char * strength2text(enum con_strength strength) { const char *result = ""; switch(strength) { case pecs_ignore: result = "ignore"; break; case pecs_must: result = XML_STRENGTH_VAL_MUST; break; case pecs_must_not: result = XML_STRENGTH_VAL_MUSTNOT; break; case pecs_startstop: result = "start/stop"; break; } return result; } const char * task2text(enum action_tasks task) { const char *result = ""; switch(task) { case no_action: result = "no_action"; break; case stop_rsc: result = "stop"; break; case start_rsc: result = "start"; break; case shutdown_crm: result = "shutdown_crm"; break; case stonith_node: result = "stonith"; break; } return result; } void print_node(const char *pre_text, node_t *node, gboolean details) { if(node == NULL) { crm_debug("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug("%s%s%sNode %s: (weight=%f, fixed=%s)", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", node->details==NULL?"error ":node->details->online?"":"Unavailable/Unclean ", node->details->uname, node->weight, node->fixed?"True":"False"); if(details && node->details != NULL) { char *pe_mutable = crm_strdup("\t\t"); crm_debug("\t\t===Node Attributes"); g_hash_table_foreach(node->details->attrs, print_str_str, pe_mutable); crm_free(pe_mutable); } if(details) { int lpc = 0; crm_debug("\t\t===Node Attributes"); slist_iter( rsc, resource_t, node->details->running_rsc, lpc, print_resource("\t\t", rsc, FALSE); ); } } /* * Used by the HashTable for-loop */ void print_str_str(gpointer key, gpointer value, gpointer user_data) { crm_debug("%s%s %s ==> %s", user_data==NULL?"":(char*)user_data, user_data==NULL?"":": ", (char*)key, (char*)value); } void print_color_details(const char *pre_text, struct color_shared_s *color, gboolean details) { if(color == NULL) { crm_debug("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug("%s%sColor %d: node=%s (from %d candidates)", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", color->id, color->chosen_node==NULL?"":color->chosen_node->details->uname, g_list_length(color->candidate_nodes)); if(details) { int lpc = 0; slist_iter(node, node_t, color->candidate_nodes, lpc, print_node("\t", node, FALSE)); } } void print_color(const char *pre_text, color_t *color, gboolean details) { if(color == NULL) { crm_debug("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug("%s%sColor %d: (weight=%f, node=%s, possible=%d)", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", color->id, color->local_weight, safe_val5("",color,details,chosen_node,details,uname), g_list_length(color->details->candidate_nodes)); if(details) { print_color_details("\t", color->details, details); } } void print_rsc_to_node(const char *pre_text, rsc_to_node_t *cons, gboolean details) { int lpc = 0; if(cons == NULL) { crm_debug("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug("%s%s%s Constraint %s (%p) - %d nodes:", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", "rsc_to_node", cons->id, cons, g_list_length(cons->node_list_rh)); if(details == FALSE) { crm_debug("\t%s %s run (score=%f : node placement rule)", safe_val3(NULL, cons, rsc_lh, id), cons->can?"Can":"Cannot", cons->weight); slist_iter( node, node_t, cons->node_list_rh, lpc, print_node("\t\t-->", node, FALSE) ); } } void -print_rsc_to_rsc(const char *pre_text, rsc_to_rsc_t *cons, gboolean details) +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_to_rsc", cons->id, cons); + "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; } - crm_debug("%s%s%s%sResource %s: (priority=%f, color=%d, now=%d)", - pre_text==NULL?"":pre_text, - pre_text==NULL?"":": ", - rsc->provisional?"Provisional ":"", - rsc->runnable?"":"(Non-Startable) ", - rsc->id, - (double)rsc->priority, - safe_val3(-1, rsc, color, id), - g_list_length(rsc->running_on)); - - crm_debug("\t%d candidate colors, %d allowed nodes," - " %d rsc_cons and %d node_cons", - g_list_length(rsc->candidate_colors), - g_list_length(rsc->allowed_nodes), - g_list_length(rsc->rsc_cons), - g_list_length(rsc->node_cons)); - - if(details) { - int lpc = 0; - - crm_debug("\t=== Actions"); - slist_iter( - action, action_t, rsc->actions, lpc, - print_action("\trsc action: ", action, FALSE); - ); - - crm_debug("\t=== Colors"); - slist_iter( - color, color_t, rsc->candidate_colors, lpc, - print_color("\t", color, FALSE) - ); - - crm_debug("\t=== Allowed Nodes"); - slist_iter( - node, node_t, rsc->allowed_nodes, lpc, - print_node("\t", node, FALSE); - ); - } + 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); - pe_free_shallow(rsc->allowed_nodes); - - while(rsc->rsc_cons) { - pe_free_rsc_to_rsc((rsc_to_rsc_t*)rsc->rsc_cons->data); - rsc->rsc_cons = rsc->rsc_cons->next; - } - if(rsc->rsc_cons != NULL) { - g_list_free(rsc->rsc_cons); - } + rsc->fns->free(rsc); crm_free(rsc); } if(resources != NULL) { g_list_free(resources); } } void pe_free_actions(GListPtr actions) { while(actions != NULL) { GListPtr list_item = actions; action_t *action = (action_t *)list_item->data; actions = actions->next; pe_free_shallow(action->actions_before);/* action_warpper_t* */ pe_free_shallow(action->actions_after); /* action_warpper_t* */ action->actions_before = NULL; action->actions_after = NULL; free_xml(action->args); crm_free(action); } if(actions != NULL) { g_list_free(actions); } } void -pe_free_rsc_to_rsc(rsc_to_rsc_t *cons) +pe_free_rsc_dependancy(rsc_dependancy_t *cons) { if(cons != NULL) { crm_free(cons); } } void pe_free_rsc_to_node(rsc_to_node_t *cons) { if(cons != NULL) { /* right now we dont make copies so this isnt required */ /* pe_free_shallow(cons->node_list_rh); */ /* node_t* */ crm_free(cons); } } GListPtr find_actions_type(GListPtr input, enum action_tasks task, node_t *on_node) { 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; }