diff --git a/crm/pengine/color.c b/crm/pengine/color.c index 4f1d0a5b67..f309349240 100644 --- a/crm/pengine/color.c +++ b/crm/pengine/color.c @@ -1,489 +1,497 @@ -/* $Id: color.c,v 1.5 2004/06/16 11:12:34 andrew Exp $ */ +/* $Id: color.c,v 1.6 2004/06/28 08:29:20 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 color_t *no_color = NULL; -gboolean has_agent(node_t *a_node, const char *class, const char *type); +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, color_t *local_color, color_t *other_color, GListPtr *colors, GListPtr resources); gboolean strict_preproc(rsc_to_rsc_t *constraint, color_t *local_color, color_t *other_color, GListPtr *colors, GListPtr resources); gboolean is_active(rsc_to_node_t *cons); gboolean choose_color(resource_t *lh_resource); gboolean apply_node_constraints(GListPtr constraints, GListPtr nodes) { crm_verbose("Applying constraints..."); int lpc = 0; 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; } resource_t *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 rsc_to_node (%s) is NULL", cons->id); continue; } crm_debug_action(print_resource("before update", rsc_lh,TRUE)); int llpc = 0; GListPtr 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->id, rsc_lh->allowed_nodes)); crm_debug_action(print_resource("after update", rsc_lh, TRUE)); ); 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", - node->details->id, rsc->class, rsc->type); - if(has_agent(node, rsc->class, rsc->type) == FALSE) { + node->details->id, + rsc->agent->class, rsc->agent->type); + + if(has_agent(node, rsc->agent) == FALSE) { /* remove node from contention */ crm_trace("Marking node %s unavailable for %s", node->details->id, 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->id, 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, const char *class, const char *type) +has_agent(node_t *a_node, lrm_agent_t *an_agent) { int lpc; - if(a_node == NULL || type == NULL) { + if(a_node == NULL || an_agent == NULL || an_agent->type == NULL) { crm_warn("Invalid inputs"); return FALSE; } - slist_iter( agent, lrm_agent_t, a_node->details->agents, lpc, crm_trace("Checking against %s/%s",agent->class, agent->type); - if(safe_str_eq(type, agent->type)){ - if(class == NULL) { - return TRUE; - } else if(safe_str_eq(class, agent->class)) { + 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(an_agent->version <= agent->version) { + return TRUE; + } else { + return FALSE; + } } } ); - crm_verbose("%s doesnt support %s/%s",a_node->details->id,class,type); + crm_verbose("%s doesnt support version %f of %s/%s", + a_node->details->id, 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, color_t *local_color, color_t *other_color, GListPtr *colors, GListPtr resources) { resource_t * lh_resource = constraint->rsc_lh; switch(constraint->strength) { case must: if(constraint->rsc_rh->runnable == FALSE) { crm_warn("Resource %s must run on the same" " node as %s (cons %s), but %s is not" " runnable.", constraint->rsc_lh->id, constraint->rsc_rh->id, constraint->id, constraint->rsc_rh->id); constraint->rsc_lh->runnable = FALSE; } break; // x * should * should_not = x case should: if(constraint->rsc_rh->provisional == FALSE) { local_color->local_weight = local_color->local_weight * 2.0; } break; case should_not: if(constraint->rsc_rh->provisional == FALSE) { local_color->local_weight = local_color->local_weight * 0.5; } // if(g_list_length(lh_resource->candidate_colors)==1) create_color( colors, lh_resource->allowed_nodes, resources); break; case must_not: if(constraint->rsc_rh->provisional == FALSE && local_color->id != no_color->id) { lh_resource->candidate_colors = g_list_remove( lh_resource->candidate_colors, local_color); crm_debug_action( print_color( "Removed",local_color,FALSE)); // surely this is required... but mtrace says no... // crm_free(local_color); } break; default: // error break; } return TRUE; } gboolean strict_postproc(rsc_to_rsc_t *constraint, color_t *local_color, color_t *other_color, GListPtr *colors, GListPtr resources) { print_rsc_to_rsc("Post processing", constraint, FALSE); switch(constraint->strength) { case must: if(constraint->rsc_rh->provisional == TRUE) { constraint->rsc_rh->color = other_color; constraint->rsc_rh->provisional = FALSE; color_resource(constraint->rsc_rh, colors, resources); } // else check for error 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; } break; case should: break; case should_not: break; case must_not: if(constraint->rsc_rh->provisional == TRUE) { // check for error } break; default: // error break; } return TRUE; } gboolean choose_color(resource_t *lh_resource) { int lpc = 0; if(lh_resource->runnable == FALSE) { lh_resource->color = find_color( lh_resource->candidate_colors, no_color); lh_resource->provisional = FALSE; } if(lh_resource->provisional) { GListPtr 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 = node_list_and( this_color->details->candidate_nodes, lh_resource->allowed_nodes, TRUE); if(g_list_length(intersection) != 0) { // TODO: merge node weights GListPtr old_list = this_color->details->candidate_nodes; pe_free_shallow(old_list); this_color->details->candidate_nodes = intersection; lh_resource->color = this_color; lh_resource->provisional = FALSE; break; } else { pe_free_shallow(intersection); } ); } return !lh_resource->provisional; } gboolean rsc_preproc(resource_t *lh_resource, GListPtr *colors, GListPtr resources) { int lpc = 0; color_t *other_color = NULL; color_t *local_color = NULL; slist_iter( constraint, rsc_to_rsc_t, lh_resource->rsc_cons, lpc, if(lh_resource->runnable == FALSE) { return FALSE; } 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; } other_color = constraint->rsc_rh->color; local_color = find_color( lh_resource->candidate_colors, other_color); strict_preproc( constraint,local_color,other_color,colors,resources); ); return TRUE; } gboolean rsc_postproc(resource_t *lh_resource, GListPtr *colors, GListPtr resources) { int lpc = 0; color_t *local_color = lh_resource->color; slist_iter( constraint, rsc_to_rsc_t, lh_resource->rsc_cons, lpc, color_t *other_color = find_color( constraint->rsc_rh->candidate_colors, local_color); strict_postproc( constraint, local_color, other_color,colors,resources); ); return TRUE; } void color_resource(resource_t *lh_resource, GListPtr *colors, GListPtr resources) { 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); // filter out nodes with a negative weight filter_nodes(lh_resource); /* avoid looping through lists when we know this resource * cant be started */ if(lh_resource->allowed_nodes != NULL) { /* Choose a color from the candidates or, * create a new one if no color is suitable * (this may need modification pending further napkin drawings) */ choose_color(lh_resource); crm_verbose("* Colors %d, Nodes %d", g_list_length(*colors),max_valid_nodes); if(lh_resource->provisional) { lh_resource->color = create_color( colors, lh_resource->allowed_nodes, resources); } } if(lh_resource->color == NULL) { crm_err("Could not color resource %s", lh_resource->id); print_resource("ERROR: No color", lh_resource, FALSE); lh_resource->color = find_color( lh_resource->candidate_colors, no_color); } lh_resource->provisional = FALSE; crm_debug_action( print_resource("Post-processing", lh_resource, FALSE)); //------ Post-processing rsc_postproc(lh_resource, colors, resources); crm_debug_action(print_resource("Colored", lh_resource, FALSE)); } 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->id, node_rh->weight); return TRUE; } crm_verbose("Constraint %s (%s): node %s weight %f.", cons->id, cons->can?"can":"cannot", node_rh->details->id, 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; } diff --git a/crm/pengine/graph.c b/crm/pengine/graph.c index 4148364180..c2fd623897 100644 --- a/crm/pengine/graph.c +++ b/crm/pengine/graph.c @@ -1,289 +1,277 @@ -/* $Id: graph.c,v 1.6 2004/06/11 10:41:45 andrew Exp $ */ +/* $Id: graph.c,v 1.7 2004/06/28 08:29:20 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 GListPtr create_action_set(action_t *action) { int lpc; GListPtr tmp = NULL; GListPtr result = NULL; gboolean preceeding_complete = FALSE; if(action->processed) { return NULL; } crm_debug_action(print_action("Create action set for", action, FALSE)); // process actions_before if(action->seen_count == 0) { crm_verbose("Processing \"before\" for action %d", action->id); slist_iter( other, action_wrapper_t, action->actions_before, lpc, tmp = create_action_set(other->action); result = g_list_concat(result, tmp); preceeding_complete = TRUE; ); } else { crm_verbose("Already seen action %d", action->id); crm_verbose("Processing \"before\" for action %d", action->id); slist_iter( other, action_wrapper_t, action->actions_before, lpc, if(other->action->seen_count > action->seen_count && other->strength == must) { tmp = create_action_set(other->action); result = g_list_concat(result, tmp); } ); } // add ourselves if(action->runnable) { if(action->processed == FALSE) { crm_verbose("Adding self %d", action->id); result = g_list_append(result, action); } else { crm_verbose("Already added self %d", action->id); } } else { crm_verbose("Skipping ourselves, we're not runnable"); } action->processed = TRUE; if(preceeding_complete == FALSE) { /* add any "before" actions that arent already processed */ slist_iter( other, action_wrapper_t, action->actions_before, lpc, tmp = create_action_set(other->action); result = g_list_concat(result, tmp); ); } action->seen_count = action->seen_count + 1; /* process actions_after * * do this regardless of whether we are runnable. Any direct or * indirect hard/XML_STRENGTH_VAL_MUST dependancies on us will have * been picked up earlier on in stage 7 */ crm_verbose("Processing \"after\" for action %d", action->id); slist_iter( other, action_wrapper_t, action->actions_after, lpc, tmp = create_action_set(other->action); result = g_list_concat(result, tmp); ); return result; } gboolean update_runnable(GListPtr actions) { int lpc = 0, lpc2 = 0; gboolean change = TRUE; while(change) { change = FALSE; slist_iter( action, action_t, actions, lpc, if(action->runnable) { continue; } else if(action->optional) { continue; } slist_iter( other, action_wrapper_t, action->actions_after, lpc2, if(other->action->runnable == FALSE) { continue; } switch(other->strength) { case should: case should_not: case must_not: case startstop: case ignore: continue; break; case must: break; } change = TRUE; crm_debug_action( print_action("Marking unrunnable", other->action, FALSE)); other->action->runnable = FALSE; ); ); } return TRUE; } gboolean shutdown_constraints( node_t *node, action_t *shutdown_op, GListPtr *action_constraints) { int lpc = 0; slist_iter( rsc, resource_t, node->details->running_rsc, lpc, order_new(rsc->stop, shutdown_op, must, action_constraints); ); return TRUE; } gboolean stonith_constraints(node_t *node, action_t *stonith_op, action_t *shutdown_op, GListPtr *action_constraints) { int lpc = 0; if(shutdown_op != NULL) { order_new(shutdown_op, stonith_op, must, action_constraints); } slist_iter( rsc, resource_t, node->details->running_rsc, lpc, -#if 0 - /* - * Mark the stop as irrelevant - * - * Possibly one day failed actions wont terminate - * the transition, but not yet - */ - rsc->stop->discard = TRUE; -#else - /* need to add timeouts in the TE for actions such as this. - * ie. the node may be cactus and unable to receive the - * stop let alone reply with failed. - */ - rsc->stop->failure_is_fatal = FALSE; -#endif - -#if 0 - obsoleted by shutdown before stonith - - /* try stopping the resource before stonithing the node - * - * if the stop succeeds, the transitioner can then - * decided if stonith is needed - */ - order_new(rsc->stop, stonith_op, must, action_constraints); -#endif - /* stonith before start */ - order_new(stonith_op, rsc->start, must, action_constraints); + if(stonith_enabled) { + /* make use of timeouts in the TE for cases such + * as this. + * ie. the node may be cactus and unable to receive the + * stop let alone reply with failed. + */ + rsc->stop->failure_is_fatal = FALSE; + + /* stonith before start */ + order_new( + stonith_op,rsc->start,must,action_constraints); + } else { + // dont run this anywhere else + rsc->start->runnable = FALSE; + } + ); return TRUE; } xmlNodePtr action2xml(action_t *action) { xmlNodePtr action_xml = NULL; if(action == NULL) { return NULL; } switch(action->task) { case stonith_op: action_xml = create_xml_node(NULL, "pseduo_event"); set_xml_property_copy( action_xml, XML_ATTR_ID, crm_itoa(action->id)); break; case shutdown_crm: action_xml = create_xml_node(NULL, "crm_event"); set_xml_property_copy( action_xml, XML_ATTR_ID, crm_itoa(action->id)); break; default: action_xml = create_xml_node(NULL, "rsc_op"); add_node_copy(action_xml, action->rsc->xml); set_xml_property_copy( action_xml, XML_ATTR_ID, crm_itoa(action->id)); set_xml_property_copy( action_xml, "rsc_id", safe_val3(NULL, action, rsc, id)); break; } set_xml_property_copy( action_xml, XML_LRM_ATTR_TARGET, safe_val4(NULL, action, node, details, id)); set_xml_property_copy( action_xml, XML_LRM_ATTR_TASK, task2text(action->task)); set_xml_property_copy( action_xml, XML_LRM_ATTR_RUNNABLE, action->runnable?XML_BOOLEAN_TRUE:XML_BOOLEAN_FALSE); set_xml_property_copy( action_xml, XML_LRM_ATTR_OPTIONAL, action->optional?XML_BOOLEAN_TRUE:XML_BOOLEAN_FALSE); set_xml_property_copy( action_xml, XML_LRM_ATTR_DISCARD, action->discard?XML_BOOLEAN_TRUE:XML_BOOLEAN_FALSE); set_xml_property_copy( action_xml, "allow_fail", action->failure_is_fatal?XML_BOOLEAN_FALSE:XML_BOOLEAN_TRUE); return action_xml; } diff --git a/crm/pengine/pe_utils.h b/crm/pengine/pe_utils.h index 3e0f213547..b8194093e6 100644 --- a/crm/pengine/pe_utils.h +++ b/crm/pengine/pe_utils.h @@ -1,122 +1,122 @@ -/* $Id: pe_utils.h,v 1.7 2004/06/16 11:12:34 andrew Exp $ */ +/* $Id: pe_utils.h,v 1.8 2004/06/28 08:29:20 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(int id, resource_t *rsc, enum action_tasks task); +extern action_t *action_new(resource_t *rsc, enum action_tasks task); // Constraint helper functions extern rsc_to_rsc_t *invert_constraint(rsc_to_rsc_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, GListPtr nodes, GListPtr resources); // Node helper functions extern gboolean filter_nodes(resource_t *rsc); extern node_t *pe_find_node(GListPtr node_list, const char *id); extern node_t *node_copy(node_t *this_node) ; extern node_t *find_list_node(GListPtr list, const char *id); // 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); // 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_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); // 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_to_node(rsc_to_node_t *cons); extern void pe_free_shallow(GListPtr alist); extern void pe_free_shallow_adv(GListPtr alist, gboolean with_data); extern void pe_free_resources(GListPtr resources); extern void pe_free_actions(GListPtr actions); // Helper macros to avoid NULL pointers #define safe_val(def, x,y) (x?x->y:def) #define safe_val3(def, t,u,v) (t?t->u?t->u->v:def:def) #define safe_val4(def, t,u,v,w) (t?t->u?t->u->v?t->u->v->w:def:def:def) #define safe_val5(def, t,u,v,w,x) (t?t->u?t->u->v?t->u->v->w?t->u->v->w->x:def:def:def:def) #define safe_val6(def, t,u,v,w,x,y) (t?t->u?t->u->v?t->u->v->w?t->u->v->w->x?t->u->v->w->x->y:def:def:def:def:def) #define safe_val7(def, t,u,v,w,x,y,z) (t?t->u?t->u->v?t->u->v->w?t->u->v->w->x?t->u->v->w->x->y?t->u->v->w->x->y->z:def:def:def:def:def:def) #endif diff --git a/crm/pengine/pengine.h b/crm/pengine/pengine.h index 717154f6f7..6be0413a88 100644 --- a/crm/pengine/pengine.h +++ b/crm/pengine/pengine.h @@ -1,278 +1,296 @@ -/* $Id: pengine.h,v 1.25 2004/06/16 11:12:34 andrew Exp $ */ +/* $Id: pengine.h,v 1.26 2004/06/28 08:29:20 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 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; enum con_type { type_none, rsc_to_rsc, rsc_to_node, rsc_to_attr, base_weight }; enum node_type { node_ping, node_member }; enum con_strength { ignore, must, should, should_not, must_not, startstop }; enum con_modifier { modifier_none, set, inc, dec, only }; enum action_tasks { no_action, stop_rsc, start_rsc, shutdown_crm, stonith_op }; enum action_order { dontcare, before, after }; struct node_shared_s { const char *id; 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; GListPtr candidate_nodes; // node_t* node_t *chosen_node; }; struct color_s { int id; struct color_shared_s *details; float local_weight; }; struct rsc_to_rsc_s { const char *id; resource_t *rsc_lh; // gboolean is_placement; 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; + float version; }; +enum pe_stop_fail { + pesf_block, + pesf_stonith, + pesf_ignore +}; + + struct resource_s { - const char *id; - xmlNodePtr xml; - int priority; - node_t *cur_node; + const char *id; + xmlNodePtr xml; + float priority; + node_t *cur_node; - const char *class; - const char *type; + lrm_agent_t *agent; - gboolean runnable; - gboolean provisional; + gboolean runnable; + gboolean provisional; + + enum pe_stop_fail stopfail_type; - action_t *stop; - action_t *start; + action_t *stop; + action_t *start; - GListPtr candidate_colors; // color_t* - GListPtr allowed_nodes; // node_t* - GListPtr node_cons; // rsc_to_node_t* - GListPtr rsc_cons; // resource_t* + GListPtr candidate_colors; // color_t* + GListPtr allowed_nodes; // node_t* + GListPtr node_cons; // rsc_to_node_t* + GListPtr rsc_cons; // resource_t* - color_t *color; + color_t *color; }; struct action_wrapper_s { enum con_strength strength; action_t *action; }; struct action_s { int id; resource_t *rsc; node_t *node; enum action_tasks task; gboolean runnable; gboolean processed; gboolean optional; gboolean discard; gboolean failure_is_fatal; int seen_count; GListPtr actions_before; // action_warpper_t* GListPtr actions_after; // action_warpper_t* }; struct order_constraint_s { int id; action_t *lh_action; action_t *rh_action; enum con_strength strength; // enum action_order order; }; extern gboolean stage0(xmlNodePtr cib, GListPtr *nodes, GListPtr *rscs, GListPtr *cons, GListPtr *actions, GListPtr *action_constraints, GListPtr *stonith_list, GListPtr *shutdown_list); extern gboolean stage1(GListPtr node_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 stage6( GListPtr *actions, GListPtr *action_constraints, GListPtr nodes); extern gboolean stage7(GListPtr resources, GListPtr actions, GListPtr action_constraints, GListPtr *action_sets); extern gboolean stage8(GListPtr action_sets, xmlNodePtr *graph); extern gboolean summary(GListPtr resources); extern gboolean pe_input_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 *node_constraints, GListPtr *action_constraints); extern gboolean unpack_resources(xmlNodePtr xml_resources, GListPtr *resources, GListPtr *actions, GListPtr *action_cons, 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 *node_constraints); extern gboolean apply_node_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( GListPtr colors, color_t *color, GListPtr nodes); extern gboolean update_runnable(GListPtr actions); extern GListPtr create_action_set(action_t *action); extern gboolean shutdown_constraints( node_t *node, action_t *shutdown_op, GListPtr *action_constraints); extern gboolean stonith_constraints( node_t *node, action_t *stonith_op, action_t *shutdown_op, GListPtr *action_constraints); extern gboolean order_new( action_t *before, action_t *after, enum con_strength strength, GListPtr *action_constraints); 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; #endif diff --git a/crm/pengine/ptest.c b/crm/pengine/ptest.c index 4f08a6f462..3a0b9273b3 100644 --- a/crm/pengine/ptest.c +++ b/crm/pengine/ptest.c @@ -1,299 +1,310 @@ -/* $Id: ptest.c,v 1.22 2004/06/08 11:47:48 andrew Exp $ */ +/* $Id: ptest.c,v 1.23 2004/06/28 08:29:20 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 #define OPTARGS "V?i:o:D:C:S:HA:U:M:I:EWRFt:m:a:d:w:c:r:p:s:" #include #include #include #include int main(int argc, char **argv) { xmlNodePtr cib_object = NULL; int lpc = 0; int lpc2 = 0; int argerr = 0; int flag; GListPtr resources = NULL; GListPtr nodes = NULL; GListPtr node_constraints = NULL; GListPtr actions = NULL; GListPtr action_constraints = NULL; GListPtr stonith_list = NULL; GListPtr shutdown_list = NULL; GListPtr colors = NULL; GListPtr action_sets = NULL; xmlNodePtr graph = NULL; char *msg_buffer = NULL; cl_log_set_entity("ptest"); cl_log_enable_stderr(TRUE); cl_log_set_facility(LOG_USER); while (1) { int option_index = 0; static struct option long_options[] = { // Top-level Options {"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; /* a sample test for multiple instance if (digit_optind != 0 && digit_optind != this_option_optind) printf ("digits occur in two different argv-elements.\n"); digit_optind = this_option_optind; printf ("option %c\n", c); */ case 'V': printf("option %d", flag); 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 =#=#=#=#="); #ifdef MCHECK mtrace(); #endif - set_crm_log_level(LOG_VERBOSE); + set_crm_log_level(LOG_TRACE); + +/* crm_crit("crit %d", LOG_CRIT); */ +/* crm_err("err %d", LOG_ERR); */ +/* crm_warn("warn %d", LOG_WARNING); */ +/* crm_notice("notice %d", LOG_NOTICE); */ +/* crm_info("info %d", LOG_INFO); */ +/* crm_debug("debug %d", LOG_DEBUG); */ +/* crm_devel("devel %d", LOG_DEV); */ +/* crm_verbose("verbose %d", LOG_VERBOSE); */ +/* crm_trace("trace %d", LOG_TRACE); */ + stage0(cib_object, &resources, &nodes, &node_constraints, &actions, &action_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, node_constraints, lpc, print_rsc_to_node(NULL, constraint, FALSE)); crm_debug("=#=#=#=#= Stage 1 =#=#=#=#="); stage1(node_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 =#=#=#=#="); // pe_debug_on(); stage2(resources, nodes, &colors); // pe_debug_off(); 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("=#=#=#=#= Stage 3 =#=#=#=#="); stage3(colors); crm_debug("========= Colors ========="); slist_iter(color, color_t, colors, lpc, print_color(NULL, color, FALSE)); 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, FALSE)); crm_debug("=#=#=#=#= Stage 5 =#=#=#=#="); stage5(resources); crm_debug("=#=#=#=#= Stage 6 =#=#=#=#="); stage6(&actions, &action_constraints, nodes); crm_debug("========= Action List ========="); slist_iter(action, action_t, actions, lpc, print_action(NULL, action, TRUE)); crm_debug("=#=#=#=#= Stage 7 =#=#=#=#="); stage7(resources, actions, action_constraints, &action_sets); crm_debug("=#=#=#=#= Summary =#=#=#=#="); summary(resources); crm_debug("========= All Actions ========="); slist_iter(action, action_t, actions, lpc, print_action("\t", action, TRUE); ); crm_debug("========= Action Sets ========="); crm_debug("\t========= Set %d (Un-runnable) =========", -1); slist_iter(action, action_t, actions, lpc, if(action->optional == FALSE && action->runnable == FALSE) { print_action("\t", action, TRUE); } ); slist_iter(action_set, GList, action_sets, lpc, crm_debug("\t========= Set %d =========", lpc); slist_iter(action, action_t, action_set, lpc2, 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(action_sets, &graph); crm_verbose("deleting node cons"); while(node_constraints) { pe_free_rsc_to_node((rsc_to_node_t*)node_constraints->data); node_constraints = node_constraints->next; } g_list_free(node_constraints); crm_verbose("deleting order cons"); pe_free_shallow(action_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); g_list_free(shutdown_list); g_list_free(stonith_list); #ifdef MCHECK muntrace(); #endif set_crm_log_level(LOG_INFO); msg_buffer = dump_xml_node(graph, FALSE); 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/regression.sh b/crm/pengine/regression.sh index 144bcb4abf..3fdba5d0a5 100755 --- a/crm/pengine/regression.sh +++ b/crm/pengine/regression.sh @@ -1,147 +1,156 @@ #!/bin/bash # Copyright (C) 2004 Andrew Beekhof # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This software is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # verbose=$1 io_dir=testcases diff_opts="--ignore-all-space -1 -u" failed=.regression.failed # zero out the error log > $failed function do_test { base=$1; name=$2; input=$io_dir/${base}.xml output=$io_dir/${base}.out expected=$io_dir/${base}.exp if [ ! -f $input ]; then echo "Test $name ($base)... Error ($input)"; return; fi if [ "$create_mode" != "true" -a ! -f $expected ]; then echo "Test $name ($base)... Error ($expected)"; return; fi ./ptest < $input 2>/dev/null 2>/dev/null > $output if [ ! -s $output ]; then echo "Test $name ($base)... Error ($output)"; rm $output return; fi ./fix_xml.pl $output if [ ! -s $output ]; then echo "Test $name ($base)... Error (fixed $output)"; rm $output return; fi if [ "$create_mode" = "true" ]; then cp "$output" "$expected" fi diff $diff_opts -q $expected $output >/dev/null rc=$? if [ "$rc" = 0 ]; then echo "Test $name ($base)... Passed"; elif [ "$rc" = 1 ]; then echo "Test $name ($base)... * Failed"; diff $diff_opts $expected $output 2>/dev/null >> $failed else echo "Test $name ($base)... Error (diff: $rc)"; fi rm $output } create_mode="false" do_test simple1 "Offline " do_test simple2 "Start " do_test simple3 "Start 2 " do_test simple4 "Start Failed" -do_test simple5 "Stop Failed" do_test simple6 "Stop Start " do_test simple7 "Shutdown " do_test simple8 "Stonith " +do_test simple9 "Lower version" +do_test simple10 "Higher version" + +echo "" + +do_test stopfail1 "Stop Failed - STONITH " +do_test stopfail2 "Stop Failed - Block " +do_test stopfail3 "Stop Failed - Ignore (1 node)" +do_test stopfail4 "Stop Failed - Ignore (2 node)" echo "" do_test rsc_rsc1 "Must not " do_test rsc_rsc2 "Should not " do_test rsc_rsc3 "Must " do_test rsc_rsc4 "Should " do_test rsc_rsc5 "Must not 3 " do_test rsc_rsc6 "Should not 3" do_test rsc_rsc7 "Must 3 " do_test rsc_rsc8 "Should 3 " echo "" #do_test rsc_node1 "Rsc1 Node1 " #do_test rsc_node2 "Rsc1 Node2 " #do_test rsc_node3 "Node Only " echo "" #do_test rsc_attr1 "Attr inc " #do_test rsc_attr2 "Attr dec " #do_test rsc_attr3 "Attr set - " #do_test rsc_attr4 "Attr set + " #do_test rsc_attr5 "Attr only " #do_test rsc_attr6 "Attr multi " echo "" do_test complex1 "Complex " echo "" do_test bad1 "Bad node " do_test bad2 "Bad rsc " do_test bad3 "No rsc class" do_test bad4 "Bad data " do_test bad5 "Bad data " do_test bad6 "Bad lrm_rsc" do_test bad7 "No lrm " echo "" # Generate these test outputs create_mode="true" #do_test bad7 "Bad data" +do_test stopfail4 "Stop Failed - Ignore (2 node)" if [ -s $failed ]; then if [ "$verbose" = "-v" ]; then echo "Results of failed tests...." less $failed else echo "Results of failed tests are in $failed...." echo "Use $0 -v to display them automatically." fi else rm $failed fi diff --git a/crm/pengine/stages.c b/crm/pengine/stages.c index 4e953650eb..e36d1d4ac5 100644 --- a/crm/pengine/stages.c +++ b/crm/pengine/stages.c @@ -1,591 +1,617 @@ -/* $Id: stages.c,v 1.6 2004/06/21 10:14:00 andrew Exp $ */ +/* $Id: stages.c,v 1.7 2004/06/28 08:29:20 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 /* * 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 *node_constraints, GListPtr *actions, GListPtr *action_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(safe_val(NULL, cib_nodes, children), nodes); unpack_resources(safe_val(NULL, cib_resources, children), resources, actions, action_constraints, *nodes); int old_log = 0; old_log = set_crm_log_level(LOG_TRACE); unpack_status(safe_val(NULL, cib_status, children), - *nodes, *resources, node_constraints); + *nodes, *resources, actions, node_constraints); unpack_constraints(safe_val(NULL, cib_constraints, children), *nodes, *resources, node_constraints, action_constraints); // set_crm_log_level(old_log); 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 node_constraints, GListPtr nodes, GListPtr resources) { int lpc = 0; 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_node_constraints(node_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; color_t *current_color = NULL; crm_trace("setup"); // Set initial color // Set color.candidate_nodes = all active nodes if(no_color != NULL) { crm_free(no_color->details); crm_free(no_color); } crm_trace("create \"no color\""); no_color = create_color(NULL, NULL, sorted_rscs); crm_trace("create default color"); current_color = create_color(colors, sorted_nodes, sorted_rscs); // Set resource.color = color (all resources) // Set resource.provisional = TRUE (all resources) /* slist_iter( this_resource, resource_t, sorted_rscs, lpc, this_resource->color = NULL; this_resource->provisional = TRUE; ); */ crm_verbose("initialized resources to default color"); // Take (next) highest resource slist_iter( lh_resource, resource_t, sorted_rscs, lpc, // if resource.provisional == FALSE, repeat if(lh_resource->provisional == FALSE) { // already processed this resource continue; } color_resource(lh_resource, colors, sorted_rscs); // next resource ); return TRUE; } /* * not sure if this is a good idea or not, but eventually we might like * to utilize as many nodes as possible... and this might be a convienient * hook */ gboolean stage3(GListPtr colors) { // not sure if this is a good idea or not if(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; } #define color_n_nodes color_n->details->candidate_nodes #define color_n_plus_1_nodes color_n_plus_1->details->candidate_nodes /* * Choose a node for each (if possible) color */ gboolean stage4(GListPtr colors) { int lpc = 0; color_t *color_n = NULL; color_t *color_n_plus_1 = NULL; GListPtr minus = NULL; for(lpc = 0; lpc < g_list_length(colors); lpc++) { color_n = color_n_plus_1; color_n_plus_1 = (color_t*)g_list_nth_data(colors, lpc); crm_debug_action( print_color("Choose node for...", color_n, FALSE)); if(color_n == NULL) { continue; } minus = node_list_minus( color_n_nodes, color_n_plus_1_nodes, TRUE); if(0 && g_list_length(color_n_plus_1_nodes) == 1 && g_list_length(minus) > 0) { crm_warn("Dont choose the only node left for color n+1"); choose_node_from_list(colors, color_n, minus); } else { crm_verbose("Choose any node from our list"); choose_node_from_list(colors, color_n, color_n_nodes); } pe_free_shallow(minus); } // choose last color if(color_n_plus_1 != NULL) { crm_debug_action(print_color("Choose node for last color...", color_n_plus_1, FALSE)); choose_node_from_list(colors, color_n_plus_1, color_n_plus_1_nodes); } 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) { crm_verbose("filling in the nodes to perform the actions on"); int lpc = 0; slist_iter( rsc, resource_t, resources, lpc, crm_debug_action(print_resource("Processing", rsc, FALSE)); if(safe_val(NULL, rsc, stop) == NULL || safe_val(NULL, rsc, start) == NULL) { // error crm_err("Either start action (%p) or" " stop action (%p) were not defined", safe_val(NULL, rsc, stop), safe_val(NULL, rsc, start)); continue; } if(safe_val4(NULL, rsc, color, details, chosen_node) == NULL){ rsc->stop->node = safe_val(NULL, rsc, cur_node); rsc->start->node = NULL; rsc->stop->optional = FALSE; crm_warn("Stop resource %s (%s)", safe_val(NULL, rsc, id), safe_val5(NULL, rsc, stop, node,details,id)); crm_debug_action( print_action( CRMD_STATE_ACTIVE, rsc->stop, FALSE)); } else if(safe_str_eq(safe_val4(NULL, rsc,cur_node,details,id), safe_val6(NULL, rsc, color ,details, chosen_node, details, id))){ crm_verbose("No change for Resource %s (%s)", safe_val(NULL, rsc, id), safe_val4(NULL,rsc,cur_node,details,id)); rsc->stop->node = safe_val(NULL, rsc, cur_node); rsc->start->node = safe_val4(NULL, rsc, color, details, chosen_node); } else if(safe_val4(NULL, rsc,cur_node,details,id) == NULL) { rsc->start->node = safe_val4(NULL, rsc, color, details, chosen_node); crm_debug("Start resource %s (%s)", safe_val(NULL, rsc, id), safe_val5(NULL, rsc, start,node,details,id)); rsc->start->optional = FALSE; } else { rsc->stop->node = safe_val(NULL, rsc, cur_node); rsc->start->node = safe_val4(NULL, rsc, color, details, chosen_node); rsc->start->optional = FALSE; rsc->stop->optional = FALSE; crm_debug("Move resource %s (%s -> %s)", safe_val(NULL, rsc, id), safe_val5(NULL, rsc, stop, node,details,id), safe_val5(NULL, rsc, start,node,details,id)); } - if(rsc->stop->node != NULL) { - rsc->stop->runnable = TRUE; + if(rsc->stop->node == NULL) { + rsc->stop->runnable = FALSE; } - if(rsc->start->node != NULL) { - rsc->start->runnable = TRUE; + if(rsc->start->node == NULL) { + rsc->start->runnable = FALSE; } ); return TRUE; } /* * Create dependacies for stonith and shutdown operations */ gboolean stage6(GListPtr *actions, GListPtr *action_constraints, GListPtr nodes) { int lpc = 0; action_t *down_node = NULL; action_t *stonith_node = NULL; slist_iter( node, node_t, nodes, lpc, if(node->details->shutdown) { crm_warn("Scheduling Node %s for shutdown", node->details->id); - down_node = action_new(action_id++, NULL,shutdown_crm); + down_node = action_new(NULL,shutdown_crm); down_node->node = node; down_node->runnable = TRUE; down_node->optional = FALSE; *actions = g_list_append(*actions, down_node); shutdown_constraints( node, down_node, action_constraints); } if(node->details->unclean) { crm_warn("Scheduling Node %s for STONITH", node->details->id); - stonith_node = action_new(action_id++,NULL,stonith_op); + stonith_node = action_new(NULL,stonith_op); stonith_node->node = node; stonith_node->runnable = TRUE; stonith_node->optional = FALSE; if(down_node != NULL) { down_node->failure_is_fatal = FALSE; } *actions = g_list_append(*actions, stonith_node); stonith_constraints(node, stonith_node, down_node, action_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 action_constraints, GListPtr *action_sets) { int lpc; action_wrapper_t *wrapper = NULL; GListPtr list = NULL; + GListPtr action_set = NULL; /* for(lpc = 0; lpc < g_list_length(action_constraints); lpc++) { order_constraint_t *order = (order_constraint_t*) g_list_nth_data(action_constraints, lpc); */ slist_iter( order, order_constraint_t, action_constraints, lpc, crm_verbose("%d Processing %d -> %d", order->id, order->lh_action->id, order->rh_action->id); crm_debug_action( print_action("LH (stage7)", order->lh_action, FALSE)); crm_debug_action( print_action("RH (stage7)", order->rh_action, FALSE)); wrapper = (action_wrapper_t*) crm_malloc(sizeof(action_wrapper_t)); wrapper->action = order->rh_action; wrapper->strength = order->strength; list = order->lh_action->actions_after; list = g_list_append(list, wrapper); order->lh_action->actions_after = list; wrapper = (action_wrapper_t*) crm_malloc(sizeof(action_wrapper_t)); wrapper->action = order->lh_action; wrapper->strength = order->strength; list = order->rh_action->actions_before; list = g_list_append(list, wrapper); order->rh_action->actions_before = list; ); // } update_runnable(actions); slist_iter( rsc, resource_t, resources, lpc, - GListPtr action_set = NULL; + action_set = NULL; /* any non-essential stop actions will be marked redundant by * during stage6 */ action_set = create_action_set(rsc->start); if(action_set != NULL) { crm_verbose("Created action set for %s->start", rsc->id); *action_sets = g_list_append(*action_sets, action_set); } else { crm_verbose("No actions resulting from %s->start", rsc->id); } ); + + crm_verbose("Processing unconnected actions"); + action_set = NULL; + slist_iter( + action, action_t, actions, lpc, + + if(action->runnable && action->processed == FALSE) { + action_set = g_list_append(action_set, action); + } + ); + + if(action_set != NULL) { + crm_verbose("Created action set for unconnected actions"); + *action_sets = g_list_append(*action_sets, action_set); + } else { + crm_verbose("No unconnected actions"); + } return TRUE; } /* * Create a dependancy graph to send to the transitioner (via the CRMd) */ gboolean stage8(GListPtr action_sets, xmlNodePtr *graph) { int lpc = 0; xmlNodePtr xml_action_set = NULL; *graph = create_xml_node(NULL, "transition_graph"); /* errors... slist_iter(action, action_t, action_list, lpc, if(action->optional == FALSE && action->runnable == FALSE) { print_action("Ignoring", action, TRUE); } ); */ int lpc2; slist_iter(action_set, GList, action_sets, lpc, crm_verbose("Processing Action Set %d", lpc); xml_action_set = create_xml_node(NULL, "actions"); set_xml_property_copy( xml_action_set, XML_ATTR_ID, crm_itoa(lpc)); slist_iter(action, action_t, action_set, lpc2, xmlNodePtr xml_action = action2xml(action); xmlAddChild(xml_action_set, xml_action); ) xmlAddChild(*graph, xml_action_set); ); xml_message_debug(*graph, "created action list"); return TRUE; } /* * Print a nice human readable high-level summary of what we're going to do */ gboolean summary(GListPtr resources) { 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, id); new_node_id = safe_val6( NULL, rsc, color, details, chosen_node, details, id); 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, id)); } 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); } ); return TRUE; } gboolean choose_node_from_list(GListPtr colors, color_t *color, GListPtr nodes) { int lpc; /* 1. Sort by weight 2. color.chosen_node = highest wieghted node 3. remove color.chosen_node from all other colors */ nodes = g_list_sort(nodes, sort_node_weight); color->details->chosen_node = node_copy((node_t*)g_list_nth_data(nodes, 0)); if(color->details->chosen_node == NULL) { crm_err("Could not allocate a node for color %d", color->id); return FALSE; } slist_iter( color_n, color_t, colors, lpc, node_t *other_node = pe_find_node(color_n->details->candidate_nodes, color->details->chosen_node->details->id); if(color_n != color) { color_n->details->candidate_nodes = g_list_remove( color_n->details->candidate_nodes, other_node); // crm_free(other_node); } ); return TRUE; } diff --git a/crm/pengine/unpack.c b/crm/pengine/unpack.c index c9d78a18d1..96524962e8 100644 --- a/crm/pengine/unpack.c +++ b/crm/pengine/unpack.c @@ -1,997 +1,1128 @@ -/* $Id: unpack.c,v 1.11 2004/06/21 10:14:00 andrew Exp $ */ +/* $Id: unpack.c,v 1.12 2004/06/28 08:29:20 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; -int action_id = 1; +int max_valid_nodes = 0; +int order_id = 1; +GListPtr agent_defaults = NULL; +gboolean stonith_enabled = FALSE; GListPtr match_attrs( const char *attr_exp, GListPtr node_list, gboolean invert); gboolean unpack_rsc_to_attr(xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr node_list, GListPtr *node_constraints); gboolean unpack_rsc_to_node(xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr node_list, GListPtr *node_constraints); gboolean unpack_rsc_to_rsc( xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr *action_constraints); gboolean unpack_rsc_location( xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr node_list, GListPtr *action_constraints); -gboolean unpack_lrm_rsc_state(node_t *node, - xmlNodePtr lrm_state, - GListPtr rsc_list, - GListPtr *node_constraints); +gboolean unpack_lrm_rsc_state( + node_t *node, xmlNodePtr lrm_state, GListPtr rsc_list, + GListPtr *actions, GListPtr *node_constraints); gboolean add_node_attrs(xmlNodePtr attrs, node_t *node); -gboolean unpack_healthy_resource(GListPtr *node_constraints, +gboolean unpack_healthy_resource(GListPtr *node_constraints, GListPtr *actions, xmlNodePtr rsc_entry, resource_t *rsc_lh, node_t *node); -gboolean unpack_failed_resource(GListPtr *node_constraints, +gboolean unpack_failed_resource(GListPtr *node_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, 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 *action_constraints); +gboolean create_ordering( + const char *id, enum con_strength strength, + resource_t *rsc_lh, resource_t *rsc_rh, GListPtr *action_constraints); rsc_to_node_t *rsc2node_new( const char *id, resource_t *rsc, double weight, gboolean can_run, node_t *node, GListPtr *node_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"); + + crm_debug("config %p", config); + crm_debug("value %p", value); + + if(safe_str_eq(value, "stonith")) { + crm_debug("Enabling STONITH of failed nodes"); + stonith_enabled = TRUE; + } else { + stonith_enabled = FALSE; + } + + 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) { crm_verbose("Begining unpack..."); while(xml_nodes != NULL) { xmlNodePtr xml_obj = xml_nodes; xmlNodePtr attrs = xml_obj->children; const char *id = xmlGetProp(xml_obj, XML_ATTR_ID); const char *type = xmlGetProp(xml_obj, XML_ATTR_TYPE); crm_verbose("Processing node %s", id); if(attrs != NULL) { attrs = attrs->children; } xml_nodes = xml_nodes->next; if(id == NULL) { crm_err("Must specify id tag in "); continue; } if(type == NULL) { crm_err("Must specify type tag in "); continue; } node_t *new_node = crm_malloc(sizeof(node_t)); new_node->weight = 1.0; new_node->fixed = FALSE; new_node->details = (struct node_shared_s*) crm_malloc(sizeof(struct node_shared_s)); // new_node->details->id = crm_strdup(id); new_node->details->id = id; 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 all_nodes) { crm_verbose("Begining unpack..."); while(xml_resources != NULL) { action_t *action_stop = NULL; action_t *action_start = NULL; xmlNodePtr xml_obj = xml_resources; const char *id = xmlGetProp(xml_obj, XML_ATTR_ID); + const char *stopfail = xmlGetProp(xml_obj, "on_stopfail"); + const char *version = xmlGetProp(xml_obj, XML_ATTR_VERSION); const char *priority = xmlGetProp( xml_obj, XML_CIB_ATTR_PRIORITY); // todo: check for null - float priority_f = atof(priority); - xml_resources = xml_resources->next; crm_verbose("Processing resource..."); if(id == NULL) { crm_err("Must specify id tag in "); continue; } resource_t *new_rsc = crm_malloc(sizeof(resource_t)); new_rsc->id = id; - new_rsc->class = xmlGetProp(xml_obj, "class"); - new_rsc->type = xmlGetProp(xml_obj, "type"); new_rsc->xml = xml_obj; - new_rsc->priority = priority_f; + new_rsc->agent = crm_malloc(sizeof(lrm_agent_t)); + new_rsc->agent->class = xmlGetProp(xml_obj, "class"); + new_rsc->agent->type = xmlGetProp(xml_obj, "type"); + new_rsc->agent->version = atof(version?version:"0.0"); + new_rsc->priority = atof(priority?priority:"0.0"); new_rsc->candidate_colors = 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->cur_node = NULL; - - action_stop = action_new(action_id++, new_rsc, stop_rsc); - action_start = action_new(action_id++, new_rsc, start_rsc); + 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; + } - new_rsc->stop = action_stop; - *actions = g_list_append(*actions, action_stop); + action_stop = action_new(new_rsc, stop_rsc); + *actions = g_list_append(*actions, action_stop); + new_rsc->stop = action_stop; + action_start = action_new(new_rsc, start_rsc); + *actions = g_list_append(*actions, action_start); new_rsc->start = action_start; - *actions = g_list_append(*actions, action_start); order_new(action_stop, action_start, startstop, action_cons); *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 *node_constraints, GListPtr *action_constraints) { crm_verbose("Begining unpack..."); while(xml_constraints != NULL) { const char *id = xmlGetProp(xml_constraints, XML_ATTR_ID); xmlNodePtr xml_obj = xml_constraints; xml_constraints = xml_constraints->next; if(id == NULL) { crm_err("Constraint must have an id"); continue; } crm_verbose("Processing constraint %s %s", xml_obj->name,id); if(safe_str_eq("rsc_to_rsc", xml_obj->name)) { unpack_rsc_to_rsc(xml_obj, resources, action_constraints); /* } else if(safe_str_eq("rsc_to_node", xml_obj->name)) { unpack_rsc_to_node(xml_obj, resources, nodes, node_constraints); } else if(safe_str_eq("rsc_to_attr", xml_obj->name)) { unpack_rsc_to_attr(xml_obj, resources, nodes, node_constraints); */ } else if(safe_str_eq("rsc_location", xml_obj->name)) { unpack_rsc_location(xml_obj, resources, nodes, node_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 *node_constraints) { rsc_to_node_t *new_con = NULL; if(rsc == NULL || id == NULL) { crm_err("Invalid constraint %s for rsc=%p)", id, rsc); return NULL; } new_con = (rsc_to_node_t*)crm_malloc(sizeof(rsc_to_node_t)); 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); } *node_constraints = g_list_append(*node_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 *node_constraints) + GListPtr nodes, GListPtr rsc_list, + GListPtr *actions, GListPtr *node_constraints) { const char *id = NULL; xmlNodePtr node_state = NULL; xmlNodePtr lrm_rsc = NULL; xmlNodePtr lrm_agents = NULL; xmlNodePtr attrs = NULL; node_t *this_node = NULL; crm_verbose("Begining unpack"); while(status != NULL) { node_state = status; status = status->next; id = xmlGetProp(node_state, XML_ATTR_ID); 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", id); this_node = pe_find_node(nodes, id); if(id == NULL) { // error continue; } else if(this_node == NULL) { crm_err("Node %s in status section no longer exists", id); 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, node_constraints); + unpack_lrm_rsc_state(this_node, lrm_rsc, rsc_list, + actions, node_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) { const char *id = xmlGetProp(node_state,XML_ATTR_ID); 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 *shutdown = xmlGetProp(node_state,XML_CIB_ATTR_SHUTDOWN); const char *unclean = xmlGetProp(node_state,XML_CIB_ATTR_STONITH); if(safe_str_eq(join_state, CRMD_JOINSTATE_MEMBER) && safe_str_eq(ccm_state, XML_BOOLEAN_YES) && safe_str_eq(crm_state, ONLINESTATUS) && shutdown == NULL) { this_node->details->online = TRUE; } else { crm_verbose("remove"); // remove node from contention this_node->weight = -1; this_node->fixed = TRUE; crm_verbose("state %s, expected %s, shutdown %s", state, exp_state, shutdown); if(unclean != NULL) { this_node->details->unclean = TRUE; } else if(shutdown != NULL) { this_node->details->shutdown = TRUE; } else if(is_node_unclean(node_state)) { /* report and or take remedial action */ this_node->details->unclean = TRUE; } if(this_node->details->unclean) { crm_verbose("Node %s is due for STONITH", id); } if(this_node->details->shutdown) { crm_verbose("Node %s is due for shutdown", id); } } return TRUE; } gboolean is_node_unclean(xmlNodePtr node_state) { 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); if(safe_str_eq(exp_state, CRMD_STATE_INACTIVE)) { return FALSE; /* do an actual calculation once STONITH is available */ // } else if(...) { } // for now... if(0) { state = NULL; join_state = NULL; crm_state = NULL; ccm_state = NULL; } 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; + lrm_agent_t *agent = NULL; xmlNodePtr xml_agent = NULL; + const char *version = NULL; if(agent_list == NULL) { return FALSE; } xml_agent = agent_list->children; while(xml_agent != NULL){ agent = (lrm_agent_t*)crm_malloc(sizeof(lrm_agent_t)); agent->class = xmlGetProp(xml_agent, "class"); agent->type = xmlGetProp(xml_agent, "type"); + version = xmlGetProp(xml_agent, "version"); + agent->version = atof(version?version:"0.0"); + node->details->agents = g_list_append( node->details->agents, agent); xml_agent = xml_agent->next; } return TRUE; } gboolean -unpack_lrm_rsc_state(node_t *node, xmlNodePtr lrm_rsc, - GListPtr rsc_list, GListPtr *node_constraints) +unpack_lrm_rsc_state(node_t *node, xmlNodePtr lrm_rsc, GListPtr rsc_list, + GListPtr *actions, GListPtr *node_constraints) { xmlNodePtr rsc_entry = NULL; const char *rsc_id = NULL; const char *node_id = NULL; const char *rsc_state = NULL; const char *rsc_code = NULL; const char *last_op = NULL; resource_t *rsc_lh = NULL; op_status_t rsc_code_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_OPSTATE); rsc_code = xmlGetProp(rsc_entry, "op_code"); last_op = xmlGetProp(rsc_entry, "last_op"); 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(rsc_code == NULL) { crm_err("Invalid resource status entry for %s in %s", rsc_id, node_id); continue; } rsc_code_i = atoi(rsc_code); if(rsc_code_i == -1) { /* * TODO: this needs 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")) { - unpack_failed_resource(node_constraints, - rsc_entry,rsc_lh,node); + unpack_failed_resource( + node_constraints, actions, + rsc_entry,rsc_lh,node); } else { - unpack_healthy_resource(node_constraints, - rsc_entry,rsc_lh,node); + unpack_healthy_resource( + node_constraints, actions, + rsc_entry,rsc_lh,node); + rsc_lh->start->optional = FALSE; } continue; } switch(rsc_code_i) { case LRM_OP_DONE: - unpack_healthy_resource(node_constraints, - rsc_entry,rsc_lh,node); + unpack_healthy_resource( + node_constraints, actions, + rsc_entry, rsc_lh,node); break; case LRM_OP_ERROR: case LRM_OP_TIMEOUT: case LRM_OP_NOTSUPPORTED: - unpack_failed_resource(node_constraints, - rsc_entry,rsc_lh,node); + unpack_failed_resource( + node_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 *node_constraints, +unpack_failed_resource(GListPtr *node_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); - if(safe_str_eq(last_op, "start")) { + if(safe_str_neq(last_op, "stop")) { /* not running */ /* do not run the resource here again */ rsc2node_new("dont_run_generate", rsc_lh, -1.0, FALSE, node, node_constraints); - } else if(safe_str_eq(last_op, "stop")) { - /* must assume still running */ - rsc_lh->cur_node = node; - node->details->running_rsc = g_list_append( - node->details->running_rsc, rsc_lh); - - /* remedial action: - * shutdown (so all other resources are stopped gracefully) - * and then STONITH node - */ - if(node->details->online) { - node->details->shutdown = TRUE; - } - node->details->unclean = TRUE; + /* schedule a stop here just in case? */ + action_new(rsc_lh, stop_rsc); -// } else if(safe_str_eq(last_op, "???")) { + return TRUE; + + } - } else { - /* unknown action... */ - /* remedial action: ??? - * shutdown (so all other resources are stopped gracefully) - * and then STONITH node - */ + switch(rsc_lh->stopfail_type) { + case pesf_stonith: + /* remedial action: + * shutdown (so all other resources are + * stopped gracefully) and then STONITH node + */ + + if(stonith_enabled == FALSE) { + crm_err("STONITH is not enabled in this cluster but is required for resource %s after a failed stop", rsc_lh->id); + rsc_lh->start->runnable = FALSE; + break; + } + + /* treat it as if it is still running */ + rsc_lh->cur_node = 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: + crm_warn("SHARED RESOURCE %s WILL REMAIN BLOCKED" + " UNTIL CLEANED UP MANUALLY ON NODE %s", + rsc_lh->id, node->details->id); + rsc_lh->start->runnable = FALSE; + break; + + case pesf_ignore: + crm_warn("SHARED RESOURCE %s IS NOT PROTECTED", + rsc_lh->id); + /* do not run the resource here again */ + rsc2node_new( + "dont_run_generate", + rsc_lh, -1.0, FALSE, node, node_constraints); + + break; } - + return TRUE; } gboolean -unpack_healthy_resource(GListPtr *node_constraints, +unpack_healthy_resource(GListPtr *node_constraints, GListPtr *actions, xmlNodePtr rsc_entry, resource_t *rsc_lh, node_t *node) { double weight = 1.0; 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")) { if(rsc_lh->cur_node != NULL) { crm_err("Resource %s running on multiple nodes %s, %s", rsc_lh->id, rsc_lh->cur_node->details->id, node->details->id); // TODO: some recovery action!! // like force a stop on the second node? return FALSE; } else { /* we prefer to stay running here */ weight = 100.0; /* create the link between this node and the rsc */ crm_verbose("Setting cur_node = %s for rsc = %s", node->details->id, rsc_lh->id); rsc_lh->cur_node = node; node->details->running_rsc = g_list_append( node->details->running_rsc, rsc_lh); } } else { /* we prefer to start where we once ran successfully */ weight = 20.0; } rsc2node_new( "healthy_generate", rsc_lh, weight,TRUE,node,node_constraints); return TRUE; } gboolean rsc2rsc_new(const char *id, enum con_strength strength, resource_t *rsc_lh, resource_t *rsc_rh) { if(rsc_lh == NULL || rsc_rh == NULL){ // error return FALSE; } rsc_to_rsc_t *new_con = crm_malloc(sizeof(rsc_to_rsc_t)); rsc_to_rsc_t *inverted_con = NULL; new_con->id = id; new_con->rsc_lh = rsc_lh; new_con->rsc_rh = rsc_rh; new_con->strength = strength; inverted_con = invert_constraint(new_con); rsc_lh->rsc_cons = g_list_insert_sorted( rsc_lh->rsc_cons, new_con, sort_cons_strength); rsc_rh->rsc_cons = g_list_insert_sorted( rsc_rh->rsc_cons, inverted_con, sort_cons_strength); return TRUE; } gboolean create_ordering(const char *id, enum con_strength strength, resource_t *rsc_lh, resource_t *rsc_rh, GListPtr *action_constraints) { if(rsc_lh == NULL || rsc_rh == NULL){ // error return FALSE; } return TRUE; } gboolean order_new(action_t *before, action_t *after, enum con_strength strength, GListPtr *action_constraints) { order_constraint_t *order = NULL; if(before == NULL || after == NULL || action_constraints == NULL){ crm_err("Invalid inputs b=%p, a=%p l=%p", before, after, action_constraints); return FALSE; } order = (order_constraint_t*)crm_malloc(sizeof(order_constraint_t)); order->id = order_id++; order->strength = strength; order->lh_action = before; order->rh_action = after; *action_constraints = g_list_append(*action_constraints, order); return TRUE; } gboolean unpack_rsc_to_rsc(xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr *action_constraints) { enum con_strength strength_e = 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 *strength = xmlGetProp(xml_obj, "strength"); 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(strength, XML_STRENGTH_VAL_MUST)) { strength_e = must; } else if(safe_str_eq(strength, XML_STRENGTH_VAL_SHOULD)) { strength_e = should; } else if(safe_str_eq(strength, XML_STRENGTH_VAL_SHOULDNOT)) { strength_e = should_not; } else if(safe_str_eq(strength, XML_STRENGTH_VAL_MUSTNOT)) { strength_e = must_not; } else { crm_err("Unknown value for %s: %s", "strength", strength); return FALSE; } if(safe_str_eq(type, "ordering")) { // make an action_cons instead order_new(rsc_lh->stop, rsc_rh->stop, strength_e, action_constraints); order_new(rsc_rh->start, rsc_lh->start, strength_e, action_constraints); return TRUE; } /* make sure the lower priority resource stops before * the higher is started, otherwise they may be both running * on the same node when the higher is replacing the lower */ action_t *before, *after; if(rsc_lh->priority >= rsc_rh->priority) { before = rsc_rh->stop; after = rsc_lh->start; } else { before = rsc_lh->stop; after = rsc_rh->start; } order_new(before, after, strength_e, action_constraints); /* make sure the lower priority resource starts after * the higher is started */ if(rsc_lh->priority < rsc_rh->priority) { before = rsc_rh->start; after = rsc_lh->start; } else { before = rsc_lh->start; after = rsc_rh->start; } order_new(before, after, strength_e,action_constraints); return rsc2rsc_new(id, strength_e, rsc_lh, rsc_rh); } GListPtr match_attrs(const char *attr_exp, GListPtr node_list, gboolean invert) { int lpc = 0; GListPtr result = NULL; char *name = NULL, *value = NULL; if(decodeNVpair(attr_exp, ':', &name, &value) == FALSE) { return NULL; } else if(name == NULL) { crm_err("Attribute %s was invalid", name); return NULL; } slist_iter( node, node_t, node_list, lpc, gboolean accept = FALSE; const char *h_val = (const char*)g_hash_table_lookup( node->details->attrs, name); if(h_val != NULL && value == NULL && invert == FALSE) { accept = TRUE; } else if(h_val == NULL && value == NULL && invert) { accept = TRUE; } else if(h_val != NULL && value != NULL) { if(invert == FALSE && safe_str_eq(value, h_val)) { accept = TRUE; } else if(invert && safe_str_neq(value, h_val)) { accept = TRUE; } } if(accept) { result = g_list_append(result, node); } ); 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->id)); 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 *node_constraints) { /* ... Translation: Further translation: */ xmlNodePtr rules = xml_obj->children; 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; } if(rules == NULL) { crm_err("no rules for constraint %s", id); } while(rules != NULL) { gboolean first_expr = TRUE; gboolean can_run = FALSE; gboolean do_and = TRUE; xmlNodePtr rule = rules; xmlNodePtr expr = rule->children; 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"); float score_f = atof(score?score:"0.0"); rsc_to_node_t *new_con = NULL; if(safe_str_eq(boolean, "or")) { do_and = FALSE; } rules = rules->next; if(result == NULL || (safe_str_eq(result, "can"))) { can_run = TRUE; } new_con = rsc2node_new(rule_id, rsc_lh, score_f, can_run, NULL, node_constraints); if(new_con == NULL) { crm_err("couldnt create constraint %s", rule_id); continue; } /* feels like a hack */ if(expr == NULL && can_run) { new_con->node_list_rh = node_list_dup(node_list,FALSE); } while(expr != NULL) { const char *match = xmlGetProp(expr, "match"); const char *not_match = xmlGetProp(expr, "not_match"); expr = expr->next; if(match != NULL) { GListPtr match_L = match_attrs( match, node_list, FALSE); if(first_expr) { new_con->node_list_rh = match_L; first_expr = FALSE; continue; } if(do_and) { crm_trace("do_and"); new_con->node_list_rh = node_list_and( new_con->node_list_rh, match_L, FALSE); } else { crm_trace("do_or"); new_con->node_list_rh = node_list_or( new_con->node_list_rh, match_L, FALSE); } pe_free_shallow(match_L); } if(not_match != NULL) { GListPtr not_match_L = match_attrs( not_match, node_list, TRUE); if(first_expr) { new_con->node_list_rh = not_match_L; first_expr = FALSE; continue; } if(do_and) { new_con->node_list_rh = node_list_and( new_con->node_list_rh, not_match_L, FALSE); } else { new_con->node_list_rh = node_list_or( new_con->node_list_rh, not_match_L, FALSE); } pe_free_shallow(not_match_L); } } if(new_con->node_list_rh == NULL) { crm_warn("No matching nodes for constraint/rule %s/%s", id, rule->name); } crm_debug_action(print_rsc_to_node("Added", new_con, FALSE)); } return TRUE; } diff --git a/crm/pengine/utils.c b/crm/pengine/utils.c index fcf051ca69..295d9ec97c 100644 --- a/crm/pengine/utils.c +++ b/crm/pengine/utils.c @@ -1,1014 +1,1016 @@ -/* $Id: utils.c,v 1.31 2004/06/21 10:14:00 andrew Exp $ */ +/* $Id: utils.c,v 1.32 2004/06/28 08:29:20 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); /* only for rsc_to_rsc constraints */ rsc_to_rsc_t * invert_constraint(rsc_to_rsc_t *constraint) { rsc_to_rsc_t *inverted_con = NULL; crm_verbose("Inverting constraint"); inverted_con = crm_malloc(sizeof(rsc_to_rsc_t)); inverted_con->id = crm_strdup(constraint->id); inverted_con->strength = constraint->strength; // swap the direction inverted_con->rsc_lh = constraint->rsc_rh; inverted_con->rsc_rh = constraint->rsc_lh; crm_debug_action( print_rsc_to_rsc("Inverted constraint", inverted_con, FALSE)); return inverted_con; } /* are the contents of list1 and list2 equal */ /* nodes with weight < 0 are ignored */ gboolean node_list_eq(GListPtr list1, GListPtr list2, gboolean filter) { GListPtr result = NULL; if(g_list_length(list1) != g_list_length(list2)) { return FALSE; } // do stuff crm_err("Not yet implemented"); return g_list_length(result) != 0; } /* the intersection of list1 and list2 * when merging weights, nodes set to < 0 in either list will always * have their weight set to -1 in the result */ 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 = NULL; node_t *other_node = find_list_node(list2, node->details->id); if(node == NULL || other_node == NULL) { continue; // merge node weights } else if(node->weight < 0 || other_node->weight < 0) { new_node = node_copy(node); new_node->weight = -1; } else { new_node = node_copy(node); new_node->weight = node->weight + other_node->weight; if(new_node->weight != 0) { new_node->weight = new_node->weight /2.0; } } if(filter && new_node->weight < 0) { crm_free(new_node); continue; } result = g_list_append(result, new_node); } return result; } node_t * find_list_node(GListPtr list, const char *id) { int lpc = 0; slist_iter( thing, node_t, list, lpc, if(safe_str_eq(thing->details->id, id)) { crm_trace("found %s", id); return thing; } ); return NULL; } /* 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 = find_list_node(list2, node->details->id); if(node == NULL || other_node != NULL || (filter && node->weight < 0)) { continue; } node_t *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 *other_node = (node_t*)find_list_node(list2, node->details->id); if(node == NULL || other_node != NULL || (filter && node->weight < 0)) { continue; } node_t *new_node = node_copy(node); result = g_list_append(result, new_node); ); slist_iter( node, node_t, list2, lpc, node_t *other_node = (node_t*)find_list_node(list1, node->details->id); if(node == NULL || other_node != NULL || (filter && node->weight < 0)) { continue; } node_t *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 || (filter && node->weight < 0)) { continue; } other_node = (node_t*)find_list_node( result, node->details->id); if(other_node == NULL) { 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, if(filter && this_node->weight < 0) { continue; } node_t *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) { if(this_node == NULL) { print_node("Failed copy of", this_node, TRUE); return NULL; } node_t *new_node = crm_malloc(sizeof(node_t)); 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, GListPtr nodes, GListPtr resources) { color_t *new_color = NULL; crm_trace("Creating color"); if(colors != NULL && g_list_length(*colors) >= max_valid_nodes) { crm_warn("Created %d colors already", max_valid_nodes); return NULL; } new_color = crm_malloc(sizeof(color_t)); new_color->id = color_id++; new_color->local_weight = 1.0; crm_trace("Creating color details"); new_color->details = crm_malloc(sizeof(struct color_shared_s)); new_color->details->id = new_color->id; new_color->details->chosen_node = NULL; crm_trace("populating node list"); new_color->details->candidate_nodes = node_list_dup(nodes, TRUE); crm_debug_action(print_color("Created color", new_color, TRUE)); if(colors != NULL) { *colors = g_list_append(*colors, new_color); } if(resources != NULL) { /* Add any new color to the list of candidate_colors for * resources that havent been decided yet */ int lpc; slist_iter( rsc, resource_t, resources, lpc, if(rsc->provisional && rsc->runnable) { color_t *color_copy = (color_t *) cl_malloc(sizeof(color_t)); color_copy->id = new_color->id; color_copy->details = new_color->details; color_copy->local_weight = 1.0; rsc->candidate_colors = g_list_append(rsc->candidate_colors, color_copy); } ); } return new_color; } /* * 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; for(lpc = 0; lpc < g_list_length(rsc_list); lpc++) { resource_t *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 *id) { int lpc = 0; for(lpc = 0; lpc < g_list_length(nodes); lpc++) { node_t *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; 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; 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(int id, resource_t *rsc, enum action_tasks task) +action_new(resource_t *rsc, enum action_tasks task) { action_t *action = (action_t*)crm_malloc(sizeof(action_t)); - action->id = id; + action->id = action_id++; action->rsc = rsc; action->task = task; action->node = NULL; // fill node in later action->actions_before = NULL; action->actions_after = NULL; action->failure_is_fatal = TRUE; action->discard = FALSE; - action->runnable = FALSE; + action->runnable = TRUE; action->processed = FALSE; action->optional = TRUE; action->seen_count = 0; 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 ignore: result = "ignore"; break; case must: result = XML_STRENGTH_VAL_MUST; break; case should: result = XML_STRENGTH_VAL_SHOULD; break; case should_not: result = XML_STRENGTH_VAL_SHOULDNOT; break; case must_not: result = XML_STRENGTH_VAL_MUSTNOT; break; case startstop: result = "start/stop"; break; } return result; }; const char * modifier2text(enum con_modifier modifier) { const char *result = ""; switch(modifier) { case modifier_none: result = "modifier_none"; break; case set: result = "set"; break; case inc: result = "inc"; break; case dec: result = "dec"; break; case only: result = "only"; 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_op: 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->id, node->weight, node->fixed?"True":"False"); if(details && node->details != NULL) { char *mutable = crm_strdup("\t\t"); crm_debug("\t\t===Node Attributes"); g_hash_table_foreach(node->details->attrs, print_str_str, mutable); crm_free(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->id, 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,id), g_list_length(color->details->candidate_nodes)); if(details) { print_color_details("\t", color->details, details); } } void print_rsc_to_node(const char *pre_text, rsc_to_node_t *cons, gboolean details) { if(cons == NULL) { crm_debug("%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); int lpc = 0; 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) { 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); 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=%s)", 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), safe_val4(NULL, rsc, cur_node, details, id)); 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"); print_action("\tStop: ", rsc->stop, FALSE); print_action("\tStart: ", rsc->start, 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 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_op: 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, id)); 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, id)); 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->id); print_node("delete", node, FALSE); if(details != NULL) { // crm_free(details->id); if(details->attrs != NULL) { g_hash_table_foreach_remove(details->attrs, ghash_free_str_str, NULL); g_hash_table_destroy(details->attrs); } // crm_free(details); } // crm_free(node); } 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); crm_free(details->chosen_node); crm_free(details); } crm_free(color); } 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_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; // crm_free(rsc->id); // crm_verbose("color"); // crm_free(rsc->color); int lpc; slist_iter(clr, color_t, rsc->candidate_colors, lpc, print_color("deleting", clr, FALSE)); // pe_free_shallow(rsc->candidate_colors); 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; } g_list_free(rsc->rsc_cons); crm_free(rsc); } 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; crm_free(action); } g_list_free(actions); } void pe_free_rsc_to_rsc(rsc_to_rsc_t *cons) { if(cons != NULL) { // crm_free(cons->id); crm_free(cons); } } void pe_free_rsc_to_node(rsc_to_node_t *cons) { if(cons != NULL) { // crm_free(cons->id); // right now we dont make copies so this isnt required // pe_free_shallow(cons->node_list_rh); // node_t* crm_free(cons); } }