diff --git a/crm/pengine/graph.c b/crm/pengine/graph.c index ebe0ea6ef6..4a0d9eeb18 100644 --- a/crm/pengine/graph.c +++ b/crm/pengine/graph.c @@ -1,305 +1,307 @@ -/* $Id: graph.c,v 1.16 2004/09/20 12:31:07 andrew Exp $ */ +/* $Id: graph.c,v 1.17 2004/09/21 19:24:37 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include gboolean update_action(action_t *action); gboolean update_action_states(GListPtr actions) { int lpc = 0; slist_iter( action, action_t, actions, lpc, update_action(action); ); return TRUE; } gboolean update_action(action_t *action) { gboolean change = FALSE; int lpc = 0; if(action->optional && action->runnable) { return FALSE; } slist_iter( other, action_wrapper_t, action->actions_after, lpc, if(action->runnable == FALSE && action->optional == FALSE) { if(other->action->runnable == FALSE) { continue; } else if (other->strength == pecs_must) { change = TRUE; other->action->runnable =FALSE; crm_debug_action( print_action("Marking unrunnable", other->action, FALSE); print_action("Reason", action, FALSE); ); } } if(action->optional == FALSE && other->action->optional) { switch(action->rsc->restart_type) { case pe_restart_ignore: break; case pe_restart_recover: crm_err("Recover after dependancy " "restart not supported... " "forcing a restart"); /* keep going */ case pe_restart_restart: change = TRUE; other->action->optional = FALSE; crm_debug_action( print_action("Marking manditory", other->action, FALSE)); } } if(change) { update_action(other->action); } ); return change; } gboolean shutdown_constraints( node_t *node, action_t *shutdown_op, GListPtr *action_constraints) { int lpc = 0; action_wrapper_t *wrapper = NULL; /* add the stop to the before lists so it counts as a pre-req * for the shutdown */ slist_iter( rsc, resource_t, node->details->running_rsc, lpc, crm_malloc(wrapper, sizeof(action_wrapper_t)); if(wrapper != NULL) { wrapper->action = rsc->stop; wrapper->strength = pecs_must; shutdown_op->actions_before = g_list_append( shutdown_op->actions_before, wrapper); } /* order_new(rsc->stop, shutdown_op, pecs_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; action_wrapper_t *wrapper = NULL; if(shutdown_op != NULL) { /* shutdown before stonith */ /* add the shutdown OP to the before lists so it counts as a pre-req */ crm_debug("Adding shutdown (%d) as an input to stonith (%d)", shutdown_op->id, stonith_op->id); crm_malloc(wrapper, sizeof(action_wrapper_t)); if(wrapper != NULL) { wrapper->action = shutdown_op; wrapper->strength = pecs_must; stonith_op->actions_before = g_list_append( stonith_op->actions_before, wrapper); } } /* add the stonith OP to the before lists so it counts as a pre-req */ slist_iter( rsc, resource_t, node->details->running_rsc, lpc, /* make use of timeouts in the TE for cases such * as this. * ie. the node may be cactus and unable to receive the * stop let alone reply with failed. */ rsc->stop->failure_is_fatal = FALSE; if(rsc->stopfail_type == pesf_block) { /* depend on the stop action which will fail */ crm_warn("SHARED RESOURCE %s WILL REMAIN BLOCKED" " UNTIL CLEANED UP MANUALLY ON NODE %s", rsc->id, node->details->uname); continue; } else if(rsc->stopfail_type == pesf_ignore) { /* nothing to do here */ crm_warn("SHARED RESOURCE %s IS NOT PROTECTED", rsc->id); continue; } /* case pesf_stonith: */ /* remedial action: * shutdown (so all other resources are * stopped gracefully) and then STONITH node */ if(stonith_enabled == FALSE) { /* depend on an action that will never complete */ crm_err("STONITH is not enabled in this" " cluster but is required for " "resource %s after a failed stop", rsc->id); } crm_debug("Adding stonith (%d) as an input to start (%d)", stonith_op->id, rsc->start->id); /* stonith before start */ crm_malloc(wrapper, sizeof(action_wrapper_t)); if(wrapper != NULL) { wrapper->action = stonith_op; wrapper->strength = pecs_must; rsc->start->actions_before = g_list_append( rsc->start->actions_before, wrapper); } /* stop before stonith */ #if 0 a pointless optimization? probably if(shutdown_op != NULL) { /* the next rule is implied */ continue; } #endif crm_malloc(wrapper, sizeof(action_wrapper_t)); if(wrapper != NULL) { wrapper->action = rsc->stop; wrapper->strength = pecs_must; stonith_op->actions_before = g_list_append( stonith_op->actions_before, wrapper); } ); return TRUE; } xmlNodePtr action2xml(action_t *action, gboolean as_input) { xmlNodePtr action_xml = NULL; if(action == NULL) { return NULL; } switch(action->task) { case stonith_op: 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"); if(!as_input) { add_node_copy( action_xml, safe_val3(NULL, action, rsc, xml)); } set_xml_property_copy( action_xml, XML_ATTR_ID, crm_itoa(action->id)); set_xml_property_copy( action_xml, XML_LRM_ATTR_RSCID, safe_val3("__no_rsc__", action, rsc, id)); break; } if(action->task != stonith_op) { set_xml_property_copy( action_xml, XML_LRM_ATTR_TARGET, safe_val4("__no_node__", action, node, details,uname)); set_xml_property_copy( action_xml, XML_LRM_ATTR_TARGET_UUID, safe_val4("__no_uuid__", action, node, details, id)); } set_xml_property_copy( action_xml, XML_LRM_ATTR_TASK, task2text(action->task)); - set_xml_property_copy( action_xml, "allow_fail", action->failure_is_fatal?XML_BOOLEAN_FALSE:XML_BOOLEAN_TRUE); set_xml_property_copy( - action_xml, XML_LRM_ATTR_OPTIONAL, - action->optional?XML_BOOLEAN_TRUE:XML_BOOLEAN_FALSE); + action_xml, "timeout", action->timeout); - 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_RUNNABLE, */ +/* action->runnable?XML_BOOLEAN_TRUE:XML_BOOLEAN_FALSE); */ if(as_input) { return action_xml; } set_xml_property_copy( action_xml, XML_LRM_ATTR_DISCARD, action->discard?XML_BOOLEAN_TRUE:XML_BOOLEAN_FALSE); add_node_copy(action_xml, action->args); /* slist_iter( */ /* wrapper, action_wrapper_t, action->actions_before, lpc, */ /* xmlNodePtr prereq = create_xml_node(action_xml, "trigger"); */ /* set_xml_property_copy(prereq, "action_id", wrapper->action->id); */ /* ); */ return action_xml; } diff --git a/crm/pengine/pengine.h b/crm/pengine/pengine.h index d038bb450c..ac3641c8ee 100644 --- a/crm/pengine/pengine.h +++ b/crm/pengine/pengine.h @@ -1,310 +1,310 @@ -/* $Id: pengine.h,v 1.35 2004/09/14 05:54:43 andrew Exp $ */ +/* $Id: pengine.h,v 1.36 2004/09/21 19:24:37 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 { pecs_ignore, pecs_must, pecs_must_not, pecs_startstop }; enum action_tasks { no_action, stop_rsc, start_rsc, shutdown_crm, stonith_op }; enum rsc_con_type { start_before, start_after, same_node }; struct node_shared_s { const char *id; const char *uname; gboolean online; gboolean unclean; gboolean shutdown; GListPtr running_rsc; /* resource_t* */ GListPtr agents; /* lrm_agent_t* */ GHashTable *attrs; /* char* => char* */ enum node_type type; }; struct node_s { float weight; gboolean fixed; struct node_shared_s *details; }; struct color_shared_s { int id; float highest_priority; GListPtr candidate_nodes; /* node_t* */ GListPtr allocated_resources; /* resources_t* */ node_t *chosen_node; gboolean pending; }; struct color_s { int id; struct color_shared_s *details; float local_weight; }; struct rsc_to_rsc_s { const char *id; resource_t *rsc_lh; enum rsc_con_type variant; resource_t *rsc_rh; enum con_strength strength; }; struct rsc_to_node_s { const char *id; resource_t *rsc_lh; float weight; GListPtr node_list_rh; /* node_t* */ /* enum con_modifier modifier; */ gboolean can; }; struct lrm_agent_s { const char *class; const char *type; const char *version; }; enum pe_stop_fail { pesf_block, pesf_stonith, pesf_ignore }; enum pe_restart { pe_restart_restart, pe_restart_recover, pe_restart_ignore }; struct resource_s { const char *id; xmlNodePtr xml; float priority; float effective_priority; node_t *cur_node; lrm_agent_t *agent; gboolean is_stonith; gboolean runnable; gboolean provisional; enum pe_stop_fail stopfail_type; enum pe_restart restart_type; int max_instances; int max_node_instances; int max_masters; int max_node_masters; action_t *stop; action_t *start; GListPtr actions; /* action_t* */ GListPtr candidate_colors; /* color_t* */ GListPtr allowed_nodes; /* node_t* */ GListPtr node_cons; /* rsc_to_node_t* */ GListPtr rsc_cons; /* rsc_to_rsc_t* */ GListPtr fencable_nodes; /* node_t* */ 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; - int timeout; + const char *timeout; xmlNodePtr args; 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, GListPtr resources); 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(color_t *color); extern gboolean update_action_states(GListPtr actions); 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 gboolean process_colored_constraints(resource_t *rsc); extern color_t *no_color; extern int max_valid_nodes; extern int order_id; extern int action_id; extern gboolean stonith_enabled; extern GListPtr agent_defaults; - +extern const char* transition_timeout; #endif diff --git a/crm/pengine/stages.c b/crm/pengine/stages.c index bbe7718be0..16c58fe940 100644 --- a/crm/pengine/stages.c +++ b/crm/pengine/stages.c @@ -1,595 +1,603 @@ -/* $Id: stages.c,v 1.22 2004/09/20 12:31:07 andrew Exp $ */ +/* $Id: stages.c,v 1.23 2004/09/21 19:24:37 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include node_t *choose_fencer(action_t *stonith, node_t *node, GListPtr resources); /* * 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(cib_nodes, nodes); unpack_resources(cib_resources, resources, actions, action_constraints, *nodes); unpack_status(cib_status, *nodes, *resources, actions, node_constraints); unpack_constraints(cib_constraints, *nodes, *resources, node_constraints, action_constraints); return TRUE; } /* * Count how many valid nodes we have (so we know the maximum number of * colors we can resolve). * * Apply node constraints (ie. filter the "allowed_nodes" part of resources */ gboolean stage1(GListPtr node_constraints, GListPtr nodes, GListPtr resources) { int lpc = 0; + crm_info("Processing stage 1"); slist_iter( node, node_t, nodes, lpc, if(node == NULL) { /* error */ } else if(node->weight >= 0.0 /* global weight */ && node->details->online && node->details->type == node_member) { max_valid_nodes++; } ); apply_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; - - crm_trace("setup"); + crm_info("Processing stage 2"); if(no_color != NULL) { crm_free(no_color->details); crm_free(no_color); } crm_trace("create \"no color\""); no_color = create_color(NULL, NULL, NULL); /* Take (next) highest resource */ slist_iter( lh_resource, resource_t, sorted_rscs, lpc, /* if resource.provisional == FALSE, repeat */ if(lh_resource->provisional == FALSE) { /* already processed this resource */ continue; } color_resource(lh_resource, colors, sorted_rscs); /* next resource */ ); return TRUE; } /* * not sure if this is a good idea or not, but eventually we might like * to utilize as many nodes as possible... and this might be a convienient * hook */ gboolean stage3(GListPtr colors) { + crm_info("Processing stage 3"); /* not sure if this is a good idea or not */ if(g_list_length(colors) > max_valid_nodes) { /* we need to consolidate some */ } else if(g_list_length(colors) < max_valid_nodes) { /* we can create a few more */ } return TRUE; } /* * Choose a node for each (if possible) color */ gboolean stage4(GListPtr colors) { int lpc = 0, lpc2 = 0; + crm_info("Processing stage 4"); slist_iter( color, color_t, colors, lpc, crm_debug("assigning node to color %d", color->id); if(color == NULL) { crm_err("NULL color detected"); continue; } else if(color->details->pending == FALSE) { continue; } choose_node_from_list(color); crm_debug("assigned %s to color %d", safe_val5(NULL, color, details, chosen_node, details, uname), color->id); slist_iter( rsc, resource_t, color->details->allocated_resources, lpc2, process_colored_constraints(rsc); ); ); 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) { int lpc = 0; int lpc2 = 0; node_t *start_node = NULL; node_t *stop_node = NULL; node_t *default_node = NULL; + crm_info("Processing stage 5"); crm_verbose("filling in the nodes to perform the actions on"); slist_iter( rsc, resource_t, resources, lpc, crm_debug_action(print_resource("Processing", rsc, FALSE)); default_node = NULL; start_node = safe_val4( NULL, rsc, color, details, chosen_node); stop_node = safe_val(NULL, rsc, cur_node); if(stop_node == NULL && start_node == NULL) { /* it is not and will not run */ default_node = NULL; } else if(stop_node == NULL) { /* it is not running yet, all actions must take place * on the new node and if they fail, they fail */ default_node = start_node; rsc->start->optional = FALSE; crm_info("Starting resource %s (%s)", safe_val(NULL, rsc, id), safe_val3(NULL,start_node,details,uname)); } else if(start_node == NULL) { /* it is being stopped, all actions must take place * on the existing node and if they fail, they fail */ default_node = stop_node; rsc->stop->optional = FALSE; rsc->start->runnable = FALSE; crm_warn("Stop resource %s (%s)", safe_val(NULL, rsc, id), safe_val3(NULL, stop_node, details,uname)); } else if(safe_str_eq( safe_val3(NULL, stop_node, details, uname), safe_val3(NULL, start_node, details, uname))) { /* its not moving so choose either copy */ default_node = start_node; crm_verbose("No change (possible restart)" " for Resource %s (%s)", safe_val(NULL, rsc, id), safe_val3( NULL,default_node,details,uname)); } else { /* the resource is moving... * * the action was scheduled based on its current * location and or state, actions other than start * and stop *must* be run at the existing location * (ie. stop_node) * */ default_node = stop_node; rsc->stop->optional = FALSE; rsc->start->optional = FALSE; crm_debug("Move resource %s (%s -> %s)", safe_val(NULL, rsc, id), safe_val3(NULL, stop_node,details,uname), safe_val3(NULL, start_node,details,uname)); } slist_iter( action, action_t, rsc->actions, lpc2, switch(action->task) { case start_rsc: action->node = start_node; break; case stop_rsc: action->node = stop_node; break; default: action->node = default_node; break; } if(action->node == NULL) { crm_debug("Marking action %d as unrunnable", action->id); action->runnable = FALSE; } ); ); return TRUE; } /* * Create dependacies for stonith and shutdown operations */ gboolean stage6(GListPtr *actions, GListPtr *action_constraints, GListPtr nodes, GListPtr resources) { int lpc = 0; action_t *down_node = NULL; action_t *stonith_node = NULL; + crm_info("Processing stage 6"); slist_iter( node, node_t, nodes, lpc, if(node->details->shutdown) { crm_warn("Scheduling Node %s for shutdown", node->details->uname); down_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 && stonith_enabled) { crm_warn("Scheduling Node %s for STONITH", node->details->uname); stonith_node = action_new(NULL,stonith_op); stonith_node->runnable = TRUE; stonith_node->optional = FALSE; /* TODO: this needs to be our local node */ stonith_node->node = NULL; set_xml_property_copy(stonith_node->args, "target", node->details->uname); 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; + crm_info("Processing stage 7"); 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)); crm_malloc(wrapper, sizeof(action_wrapper_t)); if(wrapper != NULL) { 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; } crm_malloc(wrapper, sizeof(action_wrapper_t)); if(wrapper != NULL) { 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_action_states(actions); return TRUE; } /* * Create a dependancy graph to send to the transitioner (via the CRMd) */ gboolean stage8(GListPtr actions, xmlNodePtr *graph) { int lpc = 0; int lpc2 = 0; xmlNodePtr syn = NULL; xmlNodePtr set = NULL; xmlNodePtr in = NULL; xmlNodePtr input = NULL; xmlNodePtr xml_action = NULL; - + + crm_info("Processing stage 8"); *graph = create_xml_node(NULL, "transition_graph"); + set_xml_property_copy( + *graph, "global_timeout", transition_timeout); /* errors... slist_iter(action, action_t, action_list, lpc, if(action->optional == FALSE && action->runnable == FALSE) { print_action("Ignoring", action, TRUE); } ); */ slist_iter( action, action_t, actions, lpc, if(action->optional) { continue; } else if(action->runnable == FALSE) { continue; } syn = create_xml_node(*graph, "synapse"); set = create_xml_node(syn, "action_set"); in = create_xml_node(syn, "inputs"); xml_action = action2xml(action, FALSE); xmlAddChild(set, xml_action); slist_iter( wrapper,action_wrapper_t,action->actions_before,lpc2, if(wrapper->action->optional == TRUE) { continue; } switch(wrapper->strength) { case pecs_must_not: case pecs_ignore: /* ignore both */ break; case pecs_startstop: if(wrapper->action->runnable == FALSE){ break; } /* keep going */ case pecs_must: input = create_xml_node(in, "trigger"); xml_action = action2xml( wrapper->action, TRUE); xmlAddChild(input, xml_action); break; } ); ); crm_xml_devel(*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, uname); new_node_id = safe_val6( NULL, rsc, color, details, chosen_node, details, uname); if(rsc->runnable == FALSE) { crm_err("Resource %s was not runnable", rsc_id); if(node_id != NULL) { crm_warn("Stopping Resource (%s) on node %s", rsc_id, node_id); } } else if(safe_val4(NULL, rsc, color, details, chosen_node) == NULL) { crm_err("Could not allocate Resource %s", rsc_id); crm_debug_action( print_resource("Could not allocate",rsc,TRUE)); if(node_id != NULL) { crm_warn("Stopping Resource (%s) on node %s", rsc_id, node_id); } } else if(safe_str_eq(node_id, new_node_id)){ crm_debug("No change for Resource %s (%s)", rsc_id, safe_val4(NULL, rsc, cur_node, details, uname)); } else if(node_id == NULL) { crm_info("Starting Resource %s on %s", rsc_id, new_node_id); } else { crm_info("Moving Resource %s from %s to %s", rsc_id, node_id, new_node_id); } ); return TRUE; } gboolean choose_node_from_list(color_t *color) { /* 1. Sort by weight 2. color.chosen_node = highest wieghted node 3. remove color.chosen_node from all other colors */ GListPtr nodes = color->details->candidate_nodes; nodes = g_list_sort(nodes, sort_node_weight); color->details->chosen_node = node_copy((node_t*)g_list_nth_data(nodes, 0)); color->details->pending = FALSE; if(color->details->chosen_node == NULL) { crm_err("Could not allocate a node for color %d", color->id); return FALSE; } return TRUE; } diff --git a/crm/pengine/unpack.c b/crm/pengine/unpack.c index 3708c2858d..c5008e6836 100644 --- a/crm/pengine/unpack.c +++ b/crm/pengine/unpack.c @@ -1,1287 +1,1266 @@ -/* $Id: unpack.c,v 1.31 2004/09/20 12:31:07 andrew Exp $ */ +/* $Id: unpack.c,v 1.32 2004/09/21 19:24:37 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include /* for ONLINESTATUS */ #include #include int max_valid_nodes = 0; int order_id = 1; GListPtr agent_defaults = NULL; gboolean stonith_enabled = FALSE; +const char* transition_timeout = "60000"; /* 1 minute */ GListPtr match_attrs(const char *attr, const char *op, const char *value, const char *type, GListPtr node_list); gboolean unpack_rsc_to_attr(xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr node_list, GListPtr *node_constraints); gboolean unpack_rsc_to_node(xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr node_list, GListPtr *node_constraints); gboolean unpack_rsc_order( xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr *action_constraints); gboolean unpack_rsc_dependancy( 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 nodes, GListPtr *actions, GListPtr *node_constraints); gboolean add_node_attrs(xmlNodePtr attrs, node_t *node); 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, GListPtr *actions, xmlNodePtr rsc_entry, resource_t *rsc_lh, node_t *node); gboolean determine_online_status(xmlNodePtr node_state, node_t *this_node); gboolean unpack_lrm_agents(node_t *node, xmlNodePtr agent_list); gboolean is_node_unclean(xmlNodePtr node_state); gboolean rsc2rsc_new(const char *id, enum con_strength strength, enum rsc_con_type type, resource_t *rsc_lh, resource_t *rsc_rh); gboolean 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; } + + value = param_value(config, "transition_timeout"); + if(value != NULL) { + int tmp = atoi(value); + if(tmp > 0) { + transition_timeout = value; + } else { + crm_warn("Invalid value for %s: %s", + "transition_timeout", value); + } + } + crm_info("%s set to: %s", + "transition_timeout", transition_timeout); return TRUE; } const char * param_value(xmlNodePtr parent, const char *name) { xmlNodePtr a_default = find_entity( parent, XML_CIB_TAG_NVPAIR, name, FALSE); return xmlGetProp(a_default, XML_NVPAIR_ATTR_VALUE); } const char * get_agent_param(resource_t *rsc, const char *param) { const char *value = NULL; if(param == NULL) { return NULL; } value = get_agent_param_rsc(rsc, param); if(value == NULL) { value = get_agent_param_metadata(rsc, param); } if(value == NULL) { value = get_agent_param_global(rsc, param); } return value; } const char * get_agent_param_rsc(resource_t *rsc, const char *param) { xmlNodePtr xml_rsc = rsc->xml; return xmlGetProp(xml_rsc, param); } const void * get_agent_param_metadata(resource_t *rsc, const char *param) { return NULL; } const char * get_agent_param_global(resource_t *rsc, const char *param) { const char * value = NULL;/*g_hashtable_lookup(agent_global_defaults, param); */ if(value == NULL) { crm_err("No global value default for %s", param); } return value; } gboolean unpack_global_defaults(xmlNodePtr defaults) { return TRUE; } gboolean unpack_nodes(xmlNodePtr xml_nodes, GListPtr *nodes) { node_t *new_node = NULL; xmlNodePtr attrs = NULL; const char *id = NULL; const char *uname = NULL; const char *type = NULL; crm_verbose("Begining unpack..."); xml_child_iter( xml_nodes, xml_obj, XML_CIB_TAG_NODE, attrs = xml_obj->children; id = xmlGetProp(xml_obj, XML_ATTR_ID); uname = xmlGetProp(xml_obj, XML_ATTR_UNAME); type = xmlGetProp(xml_obj, XML_ATTR_TYPE); crm_verbose("Processing node %s/%s", uname, id); if(attrs != NULL) { attrs = attrs->children; } if(id == NULL) { crm_err("Must specify id tag in "); continue; } if(type == NULL) { crm_err("Must specify type tag in "); continue; } crm_malloc(new_node, sizeof(node_t)); if(new_node == NULL) { return FALSE; } new_node->weight = 1.0; new_node->fixed = FALSE; crm_malloc(new_node->details, sizeof(struct node_shared_s)); if(new_node->details == NULL) { crm_free(new_node); return FALSE; } crm_verbose("Creaing node for entry %s/%s", uname, id); new_node->details->id = id; new_node->details->uname = uname; new_node->details->type = node_ping; new_node->details->online = FALSE; new_node->details->unclean = FALSE; new_node->details->shutdown = FALSE; new_node->details->running_rsc = NULL; new_node->details->agents = NULL; new_node->details->attrs = g_hash_table_new( g_str_hash, g_str_equal); if(safe_str_eq(type, "member")) { new_node->details->type = node_member; } add_node_attrs(attrs, new_node); *nodes = g_list_append(*nodes, new_node); crm_verbose("Done with node %s", xmlGetProp(xml_obj, "uname")); crm_debug_action(print_node("Added", new_node, FALSE)); ); *nodes = g_list_sort(*nodes, sort_node_weight); return TRUE; } gboolean unpack_resources(xmlNodePtr xml_resources, GListPtr *resources, GListPtr *actions, GListPtr *action_cons, GListPtr all_nodes) { crm_verbose("Begining unpack..."); xml_child_iter( xml_resources, xml_obj, XML_CIB_TAG_RESOURCE, action_t *action_stop = NULL; action_t *action_start = NULL; const char *id = xmlGetProp(xml_obj, XML_ATTR_ID); const char *stopfail = xmlGetProp(xml_obj, "on_stopfail"); const char *restart = xmlGetProp(xml_obj, "restart_type"); + const char *timeout = xmlGetProp(xml_obj, "timeout"); const char *max_instances = xmlGetProp( xml_obj, "max_instances"); const char *max_node_instances = xmlGetProp( xml_obj, "max_node_instances"); const char *max_masters = xmlGetProp( xml_obj, "max_masters"); const char *max_node_masters = xmlGetProp( xml_obj, "max_node_masters"); const char *version = xmlGetProp(xml_obj, XML_ATTR_VERSION); resource_t *new_rsc = NULL; const char *priority = xmlGetProp( xml_obj, XML_CIB_ATTR_PRIORITY); crm_verbose("Processing resource..."); if(id == NULL) { crm_err("Must specify id tag in "); continue; } crm_malloc(new_rsc, sizeof(resource_t)); if(new_rsc == NULL) { return FALSE; } new_rsc->id = id; new_rsc->xml = xml_obj; crm_malloc(new_rsc->agent, sizeof(lrm_agent_t)); new_rsc->agent->class = xmlGetProp(xml_obj, "class"); new_rsc->agent->type = xmlGetProp(xml_obj, "type"); new_rsc->agent->version = version?version:"0.0"; new_rsc->priority = atoi(priority?priority:"0"); new_rsc->effective_priority = new_rsc->priority; new_rsc->max_instances = atoi( max_instances?max_instances:"1"); new_rsc->max_node_instances = atoi( max_node_instances?max_node_instances:"1"); new_rsc->max_masters = atoi( max_masters?max_masters:"0"); new_rsc->max_node_masters = atoi( max_node_masters?max_node_masters:"0"); new_rsc->candidate_colors = NULL; new_rsc->actions = NULL; new_rsc->color = NULL; new_rsc->runnable = TRUE; new_rsc->provisional = TRUE; new_rsc->allowed_nodes = NULL; new_rsc->rsc_cons = NULL; new_rsc->node_cons = NULL; new_rsc->cur_node = NULL; if(safe_str_eq(stopfail, "ignore")) { new_rsc->stopfail_type = pesf_ignore; } else if(safe_str_eq(stopfail, "stonith")) { new_rsc->stopfail_type = pesf_stonith; } else { new_rsc->stopfail_type = pesf_block; } if(safe_str_eq(restart, "restart")) { new_rsc->restart_type = pe_restart_restart; } else if(safe_str_eq(restart, "recover")) { new_rsc->restart_type = pe_restart_recover; } else { new_rsc->restart_type = pe_restart_ignore; } action_stop = action_new(new_rsc, stop_rsc); *actions = g_list_append(*actions, action_stop); new_rsc->stop = action_stop; new_rsc->actions = g_list_append(new_rsc->actions, action_stop); + action_stop->timeout = timeout; action_start = action_new(new_rsc, start_rsc); *actions = g_list_append(*actions, action_start); new_rsc->start = action_start; new_rsc->actions = g_list_append(new_rsc->actions, action_start); + action_start->timeout = timeout; order_new(action_stop,action_start,pecs_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..."); xml_child_iter( xml_constraints, xml_obj, NULL, const char *id = xmlGetProp(xml_obj, XML_ATTR_ID); if(id == NULL) { crm_err("Constraint <%s...> must have an id", xml_obj->name); continue; } crm_verbose("Processing constraint %s %s", xml_obj->name,id); if(safe_str_eq("rsc_order", xml_obj->name)) { unpack_rsc_order( xml_obj, resources, action_constraints); } else if(safe_str_eq("rsc_dependancy", xml_obj->name)) { unpack_rsc_dependancy( xml_obj, resources, action_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; } crm_malloc(new_con, sizeof(rsc_to_node_t)); if(new_con != NULL) { new_con->id = id; new_con->rsc_lh = rsc; new_con->node_list_rh = NULL; new_con->can = can; if(can) { new_con->weight = weight; } else { new_con->weight = -1; } if(node != NULL) { new_con->node_list_rh = g_list_append(NULL, node); } *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 *actions, GListPtr *node_constraints) { const char *uname = NULL; xmlNodePtr lrm_rsc = NULL; xmlNodePtr lrm_agents = NULL; xmlNodePtr attrs = NULL; node_t *this_node = NULL; crm_verbose("Begining unpack"); xml_child_iter( status, node_state, XML_CIB_TAG_STATE, /* id = xmlGetProp(node_state, XML_ATTR_ID); */ uname = xmlGetProp(node_state, XML_ATTR_UNAME); attrs = find_xml_node(node_state, "attributes"); lrm_rsc = find_xml_node(node_state, XML_CIB_TAG_LRM); lrm_agents = find_xml_node(lrm_rsc, "lrm_agents"); lrm_rsc = find_xml_node(lrm_rsc, XML_LRM_TAG_RESOURCES); lrm_rsc = find_xml_node(lrm_rsc, "lrm_resource"); crm_verbose("Processing node %s", uname); this_node = pe_find_node(nodes, uname); if(uname == NULL) { /* error */ continue; } else if(this_node == NULL) { crm_err("Node %s in status section no longer exists", uname); continue; } crm_verbose("Adding runtime node attrs"); add_node_attrs(attrs, this_node); crm_verbose("determining node state"); determine_online_status(node_state, this_node); crm_verbose("Processing lrm resource entries"); unpack_lrm_rsc_state(this_node, lrm_rsc, rsc_list, nodes, actions, 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 *uname = xmlGetProp(node_state,XML_ATTR_UNAME); /* const char *state = xmlGetProp(node_state,XML_NODE_ATTR_STATE); */ const char *exp_state = xmlGetProp(node_state,XML_CIB_ATTR_EXPSTATE); const char *join_state = xmlGetProp(node_state,XML_CIB_ATTR_JOINSTATE); const char *crm_state = xmlGetProp(node_state,XML_CIB_ATTR_CRMDSTATE); const char *ccm_state = xmlGetProp(node_state,XML_CIB_ATTR_INCCM); const char *shutdown = xmlGetProp(node_state,XML_CIB_ATTR_SHUTDOWN); const char *unclean = NULL;/*xmlGetProp(node_state,XML_CIB_ATTR_STONITH); */ if(safe_str_eq(join_state, CRMD_JOINSTATE_MEMBER) && safe_str_eq(ccm_state, XML_BOOLEAN_YES) && safe_str_eq(crm_state, ONLINESTATUS) && shutdown == NULL) { this_node->details->online = TRUE; crm_debug("Node %s is online", uname); } else { /* remove node from contention */ this_node->weight = -1; this_node->fixed = TRUE; crm_verbose("join_state %s, expected %s, shutdown %s", join_state, exp_state, shutdown); if(unclean != NULL) { this_node->details->unclean = TRUE; } else if(is_node_unclean(node_state)) { /* report and or take remedial action */ this_node->details->unclean = TRUE; } if(shutdown != NULL) { this_node->details->shutdown = TRUE; } if(this_node->details->unclean) { crm_warn("Node %s is due for STONITH", uname); } if(this_node->details->shutdown) { crm_info("Node %s is due for shutdown", uname); } } return 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(safe_str_neq(exp_state, CRMD_JOINSTATE_DOWN)) { if(safe_str_eq(crm_state, CRMD_STATE_INACTIVE) || safe_str_eq(join_state, CRMD_JOINSTATE_DOWN) || safe_str_eq(ccm_state, OFFLINESTATUS)) { return TRUE; } } return FALSE; } gboolean unpack_lrm_agents(node_t *node, xmlNodePtr agent_list) { /* if the agent is not listed, remove the node from * the resource's list of allowed_nodes */ lrm_agent_t *agent = NULL; const char *version = NULL; if(agent_list == NULL) { return FALSE; } xml_child_iter( agent_list, xml_agent, XML_LRM_TAG_AGENT, crm_malloc(agent, sizeof(lrm_agent_t)); if(agent == NULL) { continue; } agent->class = xmlGetProp(xml_agent, "class"); agent->type = xmlGetProp(xml_agent, "type"); version = xmlGetProp(xml_agent, "version"); agent->version = version?version:"0.0"; crm_trace("Adding agent %s/%s v%s to node %s", agent->class, agent->type, agent->version, node->details->uname); node->details->agents = g_list_append( node->details->agents, agent); ); return TRUE; } gboolean unpack_lrm_rsc_state(node_t *node, xmlNodePtr lrm_rsc, GListPtr rsc_list, GListPtr nodes, GListPtr *actions, GListPtr *node_constraints) { xmlNodePtr rsc_entry = NULL; const char *rsc_id = NULL; const char *node_id = NULL; const char *rsc_state = NULL; const char *op_status = NULL; const char *last_rc = NULL; const char *last_op = NULL; resource_t *rsc_lh = NULL; op_status_t action_status_i = LRM_OP_ERROR; while(lrm_rsc != NULL) { rsc_entry = lrm_rsc; lrm_rsc = lrm_rsc->next; rsc_id = xmlGetProp(rsc_entry, XML_ATTR_ID); node_id = xmlGetProp(rsc_entry, XML_LRM_ATTR_TARGET); rsc_state = xmlGetProp(rsc_entry, XML_LRM_ATTR_RSCSTATE); op_status = xmlGetProp(rsc_entry, XML_LRM_ATTR_OPSTATUS); last_rc = xmlGetProp(rsc_entry, XML_LRM_ATTR_RC); last_op = xmlGetProp(rsc_entry, XML_LRM_ATTR_LASTOP); rsc_lh = pe_find_resource(rsc_list, rsc_id); crm_verbose("[%s] Processing %s on %s (%s)", rsc_entry->name, rsc_id, node_id, rsc_state); if(rsc_lh == NULL) { crm_err("Could not find a match for resource" " %s in %s's status section", rsc_id, node_id); continue; } else if(op_status == NULL) { crm_err("Invalid resource status entry for %s in %s", rsc_id, node_id); continue; } action_status_i = atoi(op_status); if(node->details->unclean) { crm_info("Node %s (where %s is running) is unclean." "Further action depends on the value of on_stopfail", node->details->uname, rsc_lh->id); /* map the status to an error and then handle as a * failed resource. */ action_status_i = LRM_OP_ERROR; } else if(action_status_i == -1) { /* * TODO: this may need some more thought * Some cases: * - PE reinvoked with pending action that will succeed * - PE reinvoked with pending action that will fail * - After DC election * - After startup * * pending start - required start * pending stop - required stop * pending on unavailable node - stonith * * For now this should do */ if(safe_str_eq(last_op, "stop")) { /* map this to a timeout so it is re-issued */ action_status_i = LRM_OP_TIMEOUT; } else { /* map this to a "done" so it is not marked * as failed, then make sure it is re-issued */ action_status_i = LRM_OP_DONE; rsc_lh->start->optional = FALSE; } } switch(action_status_i) { case LRM_OP_DONE: 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, 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, GListPtr *actions, xmlNodePtr rsc_entry, resource_t *rsc_lh, node_t *node) { const char *last_op = xmlGetProp(rsc_entry, "last_op"); crm_debug("Unpacking failed action %s on %s", last_op, rsc_lh->id); /* make sure we dont allocate the resource here again*/ rsc2node_new("dont_run__generated", rsc_lh, -1.0, FALSE, node, node_constraints); if(safe_str_eq(last_op, "start")) { /* the resource is not actually running... nothing more to do*/ return TRUE; } switch(rsc_lh->stopfail_type) { case pesf_stonith: /* treat it as if it is still running * but also mark the node as unclean */ rsc_lh->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: /* let this depend on the stop action which will fail * but make sure the transition continues... */ rsc_lh->cur_node = node; node->details->running_rsc = g_list_append( node->details->running_rsc, rsc_lh); - rsc_lh->stop->timeout = -1; /* wait forever */ + rsc_lh->stop->timeout = NULL; /* wait forever */ break; case pesf_ignore: /* pretend nothing happened */ break; } return TRUE; } gboolean unpack_healthy_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 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->uname, node->details->uname); /* TODO: some recovery action!! */ /* like force a stop on the second node? */ return FALSE; } else { /* create the link between this node and the rsc */ crm_verbose("Setting cur_node = %s for rsc = %s", node->details->uname, rsc_lh->id); rsc_lh->cur_node = node; node->details->running_rsc = g_list_append( node->details->running_rsc, rsc_lh); } } return TRUE; } gboolean rsc2rsc_new(const char *id, enum con_strength strength, enum rsc_con_type type, resource_t *rsc_lh, resource_t *rsc_rh) { rsc_to_rsc_t *new_con = NULL; rsc_to_rsc_t *inverted_con = NULL; if(rsc_lh == NULL || rsc_rh == NULL){ /* error */ return FALSE; } crm_malloc(new_con, sizeof(rsc_to_rsc_t)); if(new_con != NULL) { new_con->id = id; new_con->rsc_lh = rsc_lh; new_con->rsc_rh = rsc_rh; new_con->strength = strength; new_con->variant = type; inverted_con = invert_constraint(new_con); rsc_lh->rsc_cons = g_list_insert_sorted( rsc_lh->rsc_cons, new_con, sort_cons_strength); rsc_rh->rsc_cons = g_list_insert_sorted( rsc_rh->rsc_cons, inverted_con, sort_cons_strength); } else { return FALSE; } return TRUE; } gboolean order_new(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; } crm_malloc(order, sizeof(order_constraint_t)); if(order != NULL) { 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_dependancy(xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr *action_constraints) { enum con_strength strength_e = pecs_ignore; const char *id_lh = xmlGetProp(xml_obj, "from"); const char *id = xmlGetProp(xml_obj, XML_ATTR_ID); const char *id_rh = xmlGetProp(xml_obj, "to"); - const char *type = xmlGetProp(xml_obj, XML_ATTR_TYPE); + 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 0 - /* relates to the ifdef below */ - action_t *before, *after; -#endif if(rsc_lh == NULL) { crm_err("No resource (con=%s, rsc=%s)", id, id_lh); return FALSE; } else if(rsc_rh == NULL) { crm_err("No resource (con=%s, rsc=%s)", id, id_rh); return FALSE; } if(safe_str_eq(type, XML_STRENGTH_VAL_MUST)) { strength_e = pecs_must; } else if(safe_str_eq(type, XML_STRENGTH_VAL_SHOULD)) { crm_err("Type %s is no longer supported", type); strength_e = pecs_must; } else if(safe_str_eq(type, XML_STRENGTH_VAL_SHOULDNOT)) { crm_err("Type %s is no longer supported", type); strength_e = pecs_must_not; } else if(safe_str_eq(type, XML_STRENGTH_VAL_MUSTNOT)) { strength_e = pecs_must_not; } else { crm_err("Unknown value for %s: %s", "type", type); return FALSE; } -#if 0 - if people want this behaviour, they should add an ordering constraint - /* 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 - */ - 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); -#endif return rsc2rsc_new(id, strength_e, same_node, rsc_lh, rsc_rh); } gboolean unpack_rsc_order(xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr *action_constraints) { enum con_strength strength_e = pecs_ignore; const char *id = xmlGetProp(xml_obj, XML_ATTR_ID); const char *id_lh = xmlGetProp(xml_obj, "from"); const char *id_rh = xmlGetProp(xml_obj, "to"); const char *type = xmlGetProp(xml_obj, XML_ATTR_TYPE); resource_t *rsc_lh = pe_find_resource(rsc_list, id_lh); resource_t *rsc_rh = pe_find_resource(rsc_list, id_rh); if(xml_obj == NULL) { crm_err("No constraint object to process."); return FALSE; } else if(id == NULL) { crm_err("%s constraint must have an id", xml_obj->name); return FALSE; } else if(rsc_lh == NULL || rsc_rh == NULL) { crm_err("Constraint %s needs two sides lh: %p rh: %p" " (NULL indicates missing side)", id, rsc_lh, rsc_rh); return FALSE; } else if(safe_str_eq(type, "after")) { rsc2rsc_new(id, strength_e, start_after, rsc_lh, rsc_rh); order_new(rsc_rh->stop, rsc_lh->stop, pecs_must, action_constraints); order_new(rsc_lh->start, rsc_rh->start, pecs_must, action_constraints); } else { rsc2rsc_new(id, strength_e, start_before, rsc_lh, rsc_rh); order_new(rsc_lh->stop, rsc_rh->stop, pecs_must, action_constraints); order_new(rsc_rh->start, rsc_lh->start, pecs_must, action_constraints); } return TRUE; } /* do NOT free the nodes returned here */ GListPtr match_attrs(const char *attr, const char *op, const char *value, const char *type, GListPtr node_list) { int lpc = 0, lpc2 = 0; GListPtr result = NULL; if(attr == NULL || op == NULL) { crm_err("Invlaid attribute or operation in expression" " (\'%s\' \'%s\' \'%s\')", crm_str(attr), crm_str(op), crm_str(value)); return NULL; } slist_iter( node, node_t, node_list, lpc, gboolean accept = FALSE; int cmp = 0; const char *h_val = (const char*)g_hash_table_lookup( node->details->attrs, attr); if(value != NULL && h_val != NULL) { if(type == NULL || (safe_str_eq(type, "string"))) { cmp = strcmp(h_val, value); } else if(safe_str_eq(type, "number")) { float h_val_f = atof(h_val); float value_f = atof(value); if(h_val_f < value_f) { cmp = -1; } else if(h_val_f > value_f) { cmp = 1; } else { cmp = 0; } } else if(safe_str_eq(type, "version")) { cmp = compare_version(h_val, value); } } else if(value == NULL && h_val == NULL) { cmp = 0; } else if(value == NULL) { cmp = 1; } else { cmp = -1; } if(safe_str_eq(op, "exists")) { if(h_val != NULL) accept = TRUE; } else if(safe_str_eq(op, "notexists")) { if(h_val == NULL) accept = TRUE; } else if(safe_str_eq(op, "running")) { GListPtr rsc_list = node->details->running_rsc; slist_iter( rsc, resource_t, rsc_list, lpc2, if(safe_str_eq(rsc->id, attr)) { accept = TRUE; } ); } else if(safe_str_eq(op, "not_running")) { GListPtr rsc_list = node->details->running_rsc; accept = TRUE; slist_iter( rsc, resource_t, rsc_list, lpc2, if(safe_str_eq(rsc->id, attr)) { accept = FALSE; break; } ); } else if(safe_str_eq(op, "eq")) { if((h_val == value) || cmp == 0) accept = TRUE; } else if(safe_str_eq(op, "ne")) { if((h_val == NULL && value != NULL) || (h_val != NULL && value == NULL) || cmp != 0) accept = TRUE; } else if(value == NULL || h_val == NULL) { /* the comparision is meaningless from this point on */ accept = FALSE; } else if(safe_str_eq(op, "lt")) { if(cmp < 0) accept = TRUE; } else if(safe_str_eq(op, "lte")) { if(cmp <= 0) accept = TRUE; } else if(safe_str_eq(op, "gt")) { if(cmp > 0) accept = TRUE; } else if(safe_str_eq(op, "gte")) { if(cmp >= 0) accept = TRUE; } if(accept) { crm_trace("node %s matched", node->details->uname); result = g_list_append(result, node); } else { crm_trace("node %s did not match", node->details->uname); } ); return result; } gboolean add_node_attrs(xmlNodePtr attrs, node_t *node) { const char *name = NULL; const char *value = NULL; while(attrs != NULL){ name = xmlGetProp(attrs, XML_NVPAIR_ATTR_NAME); value = xmlGetProp(attrs, XML_NVPAIR_ATTR_VALUE); if(name != NULL && value != NULL && safe_val(NULL, node, details) != NULL) { crm_verbose("Adding %s => %s", name, value); /* this is frustrating... no way to pass in const * keys or values yet docs say: * Note: If keys and/or values are dynamically * allocated, you should free them first. */ g_hash_table_insert(node->details->attrs, crm_strdup(name), crm_strdup(value)); } attrs = attrs->next; } g_hash_table_insert(node->details->attrs, crm_strdup("uname"), crm_strdup(node->details->uname)); g_hash_table_insert(node->details->attrs, crm_strdup("id"), crm_strdup(node->details->id)); return TRUE; } gboolean unpack_rsc_location( xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr node_list, GListPtr *node_constraints) { /* ... Translation: Further translation: */ gboolean were_rules = FALSE; const char *id_lh = xmlGetProp(xml_obj, "rsc"); const char *id = xmlGetProp(xml_obj, XML_ATTR_ID); resource_t *rsc_lh = pe_find_resource(rsc_list, id_lh); if(rsc_lh == NULL) { crm_err("No resource (con=%s, rsc=%s)", id, id_lh); return FALSE; } xml_child_iter( xml_obj, rule, "rule", gboolean first_expr = TRUE; gboolean can_run = FALSE; gboolean do_and = TRUE; const char *rule_id = xmlGetProp(rule, XML_ATTR_ID); const char *score = xmlGetProp(rule, "score"); const char *result = xmlGetProp(rule, "result"); const char *boolean = xmlGetProp(rule, "boolean_op"); GListPtr match_L = NULL; GListPtr old_list = NULL; float score_f = atof(score?score:"0.0"); rsc_to_node_t *new_con = NULL; were_rules = TRUE; if(safe_str_eq(boolean, "or")) { do_and = FALSE; } if(result == NULL || (safe_str_eq(result, "can"))) { can_run = TRUE; } new_con = rsc2node_new(rule_id, rsc_lh, score_f, can_run, NULL, node_constraints); if(new_con == NULL) { continue; } gboolean rule_has_expressions = FALSE; xml_child_iter( rule, expr, "expression", const char *attr = xmlGetProp(expr, "attribute"); const char *op = xmlGetProp(expr, "operation"); const char *value = xmlGetProp(expr, "value"); const char *type = xmlGetProp(expr, "type"); rule_has_expressions = TRUE; crm_trace("processing expression: %s", xmlGetProp(expr, "id")); match_L = match_attrs( attr, op, value, type, node_list); if(first_expr) { new_con->node_list_rh = node_list_dup( match_L, FALSE); first_expr = FALSE; continue; } old_list = new_con->node_list_rh; if(do_and) { crm_trace("do_and"); new_con->node_list_rh = node_list_and( old_list, match_L, FALSE); } else { crm_trace("do_or"); new_con->node_list_rh = node_list_or( old_list, match_L, FALSE); } pe_free_shallow_adv(match_L, FALSE); pe_free_shallow_adv(old_list, TRUE); ); if(rule_has_expressions == FALSE) { /* feels like a hack */ crm_debug("Rule %s had no expressions," " adding all nodes", xmlGetProp(rule, "id")); new_con->node_list_rh = node_list_dup(node_list,FALSE); } if(new_con->node_list_rh == NULL) { crm_warn("No matching nodes for constraint/rule %s/%s", id, xmlGetProp(rule, "id")); } crm_debug_action(print_rsc_to_node("Added", new_con, FALSE)); ); if(were_rules == FALSE) { crm_err("no rules for constraint %s", id); } - return TRUE; } -