diff --git a/crm/pengine/complex.c b/crm/pengine/complex.c index d25f59c1ab..e4416d72e5 100644 --- a/crm/pengine/complex.c +++ b/crm/pengine/complex.c @@ -1,335 +1,338 @@ -/* $Id: complex.c,v 1.7 2004/11/12 17:20:58 andrew Exp $ */ +/* $Id: complex.c,v 1.8 2004/11/23 20:43:08 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include gboolean update_node_weight(rsc_to_node_t *cons,const char *id,GListPtr nodes); gboolean is_active(rsc_to_node_t *cons); gboolean constraint_violated( resource_t *rsc_lh, resource_t *rsc_rh, rsc_dependancy_t *constraint); void order_actions(action_t *lh, action_t *rh, order_constraint_t *order); gboolean has_agent(node_t *a_node, lrm_agent_t *an_agent); resource_object_functions_t resource_class_functions[] = { { native_unpack, native_find_child, native_num_allowed_nodes, native_color, native_create_actions, native_internal_constraints, native_agent_constraints, native_rsc_dependancy_lh, native_rsc_dependancy_rh, native_rsc_order_lh, native_rsc_order_rh, native_rsc_location, native_expand, native_dump, native_free }, { group_unpack, group_find_child, group_num_allowed_nodes, group_color, group_create_actions, group_internal_constraints, group_agent_constraints, group_rsc_dependancy_lh, group_rsc_dependancy_rh, group_rsc_order_lh, group_rsc_order_rh, group_rsc_location, group_expand, group_dump, group_free }, { incarnation_unpack, incarnation_find_child, incarnation_num_allowed_nodes, incarnation_color, incarnation_create_actions, incarnation_internal_constraints, incarnation_agent_constraints, incarnation_rsc_dependancy_lh, incarnation_rsc_dependancy_rh, incarnation_rsc_order_lh, incarnation_rsc_order_rh, incarnation_rsc_location, incarnation_expand, incarnation_dump, incarnation_free } }; /* resource_object_functions_t resource_variants[] = resource_class_functions; */ int get_resource_type(const char *name) { if(safe_str_eq(name, "resource")) { return pe_native; } else if(safe_str_eq(name, "resource_group")) { return pe_group; } else if(safe_str_eq(name, "incarnation")) { return pe_incarnation; } return pe_unknown; } gboolean is_active(rsc_to_node_t *cons) { /* todo: check constraint lifetime */ return TRUE; } gboolean common_unpack(xmlNodePtr xml_obj, resource_t **rsc) { - const char *id = xmlGetProp(xml_obj, XML_ATTR_ID); - const char *stopfail = xmlGetProp(xml_obj, "on_stopfail"); - const char *restart = xmlGetProp(xml_obj, "restart_type"); - const char *timeout = xmlGetProp(xml_obj, "timeout"); - const char *priority = xmlGetProp(xml_obj, XML_CIB_ATTR_PRIORITY); + 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 *def_timeout = xmlGetProp(xml_obj, "def_timeout"); + const char *start_timeout = xmlGetProp(xml_obj, "start_timeout"); + const char *stop_timeout = xmlGetProp(xml_obj, "stop_timeout"); + const char *priority = xmlGetProp(xml_obj, XML_CIB_ATTR_PRIORITY); crm_verbose("Processing resource input..."); if(id == NULL) { crm_err("Must specify id tag in "); return FALSE; } else if(rsc == NULL) { crm_err("Nowhere to unpack resource into"); return FALSE; } crm_malloc(*rsc, sizeof(resource_t)); if(*rsc == NULL) { return FALSE; } (*rsc)->id = id; (*rsc)->xml = xml_obj; (*rsc)->variant = get_resource_type(xml_obj->name); if((*rsc)->variant == pe_unknown) { crm_err("Unknown resource type: %s", xml_obj->name); crm_free(*rsc); return FALSE; -/* } else if((*rsc)->variant == pe_native) { */ } (*rsc)->fns = &resource_class_functions[(*rsc)->variant]; crm_verbose("Unpacking resource..."); (*rsc)->priority = atoi(priority?priority:"0"); (*rsc)->effective_priority = (*rsc)->priority; (*rsc)->recovery_type = recovery_stop_start; (*rsc)->runnable = TRUE; (*rsc)->provisional = TRUE; (*rsc)->starting = FALSE; (*rsc)->stopping = FALSE; - (*rsc)->timeout = timeout; + (*rsc)->start_timeout = start_timeout; + (*rsc)->stop_timeout = stop_timeout; + (*rsc)->def_timeout = def_timeout; (*rsc)->candidate_colors = NULL; (*rsc)->rsc_cons = NULL; (*rsc)->actions = NULL; if(safe_str_eq(stopfail, "ignore")) { (*rsc)->stopfail_type = pesf_ignore; } else if(safe_str_eq(stopfail, "stonith")) { (*rsc)->stopfail_type = pesf_stonith; } else { (*rsc)->stopfail_type = pesf_block; } if(safe_str_eq(restart, "restart")) { (*rsc)->restart_type = pe_restart_restart; } else if(safe_str_eq(restart, "recover")) { (*rsc)->restart_type = pe_restart_recover; } else { (*rsc)->restart_type = pe_restart_ignore; } (*rsc)->fns->unpack(*rsc); return TRUE; } void order_actions(action_t *lh_action, action_t *rh_action, order_constraint_t *order) { action_wrapper_t *wrapper = NULL; GListPtr list = NULL; crm_verbose("%d Processing %d -> %d", order->id, lh_action->id, rh_action->id); crm_debug_action( print_action("LH (order_actions)", lh_action, FALSE)); crm_debug_action( print_action("RH (order_actions)", rh_action, FALSE)); crm_malloc(wrapper, sizeof(action_wrapper_t)); if(wrapper != NULL) { wrapper->action = rh_action; wrapper->strength = order->strength; list = lh_action->actions_after; list = g_list_append(list, wrapper); lh_action->actions_after = list; } crm_malloc(wrapper, sizeof(action_wrapper_t)); if(wrapper != NULL) { wrapper->action = lh_action; wrapper->strength = order->strength; list = rh_action->actions_before; list = g_list_append(list, wrapper); rh_action->actions_before = list; } } void common_dump(resource_t *rsc, const char *pre_text, gboolean details) { crm_debug("%s%s%s%sResource %s: (variant=%s, priority=%f)", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", rsc->provisional?"Provisional ":"", rsc->runnable?"":"(Non-Startable) ", rsc->id, rsc->xml->name, (double)rsc->priority); } void common_free(resource_t *rsc) { if(rsc == NULL) { return; } crm_trace("Freeing %s", rsc->id); while(rsc->rsc_cons) { pe_free_rsc_dependancy( (rsc_dependancy_t*)rsc->rsc_cons->data); rsc->rsc_cons = rsc->rsc_cons->next; } crm_trace("Freeing constraint list"); if(rsc->rsc_cons != NULL) { g_list_free(rsc->rsc_cons); } crm_trace("Freeing opaque data"); crm_free(rsc->variant_opaque); crm_trace("Freeing resource"); crm_free(rsc); crm_trace("Resource freed"); } void common_agent_constraints( GListPtr node_list, lrm_agent_t *agent, const char *id) { slist_iter( node, node_t, node_list, lpc, crm_trace("Checking if %s supports %s/%s (%s)", node->details->uname, agent->class, agent->type, agent->version); if(has_agent(node, agent) == FALSE) { /* remove node from contention */ crm_trace("Marking node %s unavailable for %s", node->details->uname, id); node->weight = -1.0; node->fixed = TRUE; } /* if(node->fixed && node->weight < 0) { */ /* /\* the structure of the list will have changed */ /* * lpc-- might be sufficient */ /* *\/ */ /* crm_debug("Removing node %s from %s", */ /* node->details->uname, rsc->id); */ /* lpc = -1; */ /* native_data->allowed_nodes = g_list_remove( */ /* native_data->allowed_nodes, node); */ /* crm_free(node); */ /* } */ ); } gboolean has_agent(node_t *a_node, lrm_agent_t *an_agent) { if(a_node == NULL || an_agent == NULL || an_agent->type == NULL) { crm_warn("Invalid inputs"); return FALSE; } crm_devel("Checking %d agents on %s", g_list_length(a_node->details->agents), a_node->details->uname); slist_iter( agent, lrm_agent_t, a_node->details->agents, lpc, crm_trace("Checking against %s/%s (%s)", agent->class, agent->type, agent->version); if(safe_str_eq(an_agent->type, agent->type)){ if(an_agent->class == NULL) { return TRUE; } else if(safe_str_eq(an_agent->class, agent->class)) { if(compare_version( an_agent->version, agent->version) <= 0) { return TRUE; } } } ); crm_verbose("%s doesnt support version %s of %s/%s", a_node->details->uname, an_agent->version, an_agent->class, an_agent->type); return FALSE; } diff --git a/crm/pengine/pengine.h b/crm/pengine/pengine.h index 07fea45d74..66e18060ad 100644 --- a/crm/pengine/pengine.h +++ b/crm/pengine/pengine.h @@ -1,336 +1,339 @@ -/* $Id: pengine.h,v 1.42 2004/11/12 17:20:58 andrew Exp $ */ +/* $Id: pengine.h,v 1.43 2004/11/23 20:43:08 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef PENGINE__H #define PENGINE__H #include typedef struct node_s node_t; typedef struct color_s color_t; typedef struct rsc_to_node_s rsc_to_node_t; typedef struct rsc_dependancy_s rsc_dependancy_t; typedef struct resource_s resource_t; typedef struct lrm_agent_s lrm_agent_t; typedef struct order_constraint_s order_constraint_t; typedef struct action_s action_t; typedef struct action_wrapper_s action_wrapper_t; #include #include #include enum con_type { type_none, rsc_dependancy, rsc_to_node, rsc_to_attr, base_weight }; enum node_type { node_ping, node_member }; enum con_strength { pecs_ignore, pecs_must, pecs_must_not, pecs_startstop }; enum action_tasks { no_action, stop_rsc, stopped_rsc, start_rsc, started_rsc, shutdown_crm, stonith_node }; enum rsc_recovery_type { recovery_stop_start, recovery_stop_only, recovery_block }; enum pe_stop_fail { pesf_block, pesf_stonith, pesf_ignore }; enum pe_restart { pe_restart_restart, pe_restart_recover, pe_restart_ignore }; struct node_shared_s { const char *id; const char *uname; gboolean online; gboolean unclean; gboolean shutdown; GListPtr running_rsc; /* resource_t* */ GListPtr agents; /* lrm_agent_t* */ GHashTable *attrs; /* char* => char* */ enum node_type type; }; struct node_s { float weight; gboolean fixed; struct node_shared_s *details; }; struct color_shared_s { int id; float highest_priority; GListPtr candidate_nodes; /* node_t* */ GListPtr allocated_resources; /* resources_t* */ node_t *chosen_node; gboolean pending; }; struct color_s { int id; struct color_shared_s *details; float local_weight; }; struct rsc_dependancy_s { const char *id; resource_t *rsc_lh; resource_t *rsc_rh; enum con_strength strength; }; struct rsc_to_node_s { const char *id; resource_t *rsc_lh; float weight; GListPtr node_list_rh; /* node_t* */ /* enum con_modifier modifier; */ gboolean can; }; struct lrm_agent_s { const char *class; const char *type; const char *version; }; struct resource_s { const char *id; xmlNodePtr xml; void *variant_opaque; enum pe_obj_types variant; resource_object_functions_t *fns; float priority; float effective_priority; - const char *timeout; + + const char *start_timeout; + const char *stop_timeout; + const char *def_timeout; gboolean starting; gboolean stopping; gboolean is_stonith; gboolean runnable; gboolean provisional; enum rsc_recovery_type recovery_type; enum pe_stop_fail stopfail_type; enum pe_restart restart_type; GListPtr candidate_colors; /* color_t* */ GListPtr rsc_cons; /* rsc_dependancy_t* */ GListPtr actions; /* action_t* */ /* (soon to be) variant specific */ int max_instances; int max_node_instances; int max_masters; int max_node_masters; }; struct action_wrapper_s { enum con_strength strength; action_t *action; }; struct action_s { int id; resource_t *rsc; void *rsc_opaque; node_t *node; enum action_tasks task; gboolean pseudo; gboolean runnable; gboolean dumped; gboolean processed; gboolean optional; gboolean discard; gboolean failure_is_fatal; int seen_count; const char *timeout; xmlNodePtr args; GListPtr actions_before; /* action_warpper_t* */ GListPtr actions_after; /* action_warpper_t* */ /* (soon to be) variant specific */ int incarnation; }; struct order_constraint_s { int id; enum con_strength strength; void *lh_opaque; resource_t *lh_rsc; action_t *lh_action; enum action_tasks lh_action_task; void *rh_opaque; resource_t *rh_rsc; action_t *rh_action; enum action_tasks rh_action_task; /* (soon to be) variant specific */ /* int lh_rsc_incarnation; */ /* int rh_rsc_incarnation; */ }; extern gboolean stage0(xmlNodePtr cib, GListPtr *nodes, GListPtr *rscs, GListPtr *cons, GListPtr *actions, GListPtr *ordering_constraints, GListPtr *stonith_list, GListPtr *shutdown_list); extern gboolean stage1(GListPtr placement_constraints, GListPtr nodes, GListPtr resources); extern gboolean stage2(GListPtr sorted_rscs, GListPtr sorted_nodes, GListPtr *colors); extern gboolean stage3(GListPtr colors); extern gboolean stage4(GListPtr colors); extern gboolean stage5(GListPtr resources, GListPtr *ordering_constraints); extern gboolean stage6( GListPtr *actions, GListPtr *ordering_constraints, GListPtr nodes, GListPtr resources); extern gboolean stage7( GListPtr resources, GListPtr actions, GListPtr ordering_constraints); extern gboolean stage8( GListPtr resources, GListPtr action_sets, xmlNodePtr *graph); extern gboolean summary(GListPtr resources); extern gboolean pe_msg_dispatch(IPC_Channel *sender, void *user_data); extern gboolean process_pe_message(xmlNodePtr msg, IPC_Channel *sender); extern gboolean unpack_constraints(xmlNodePtr xml_constraints, GListPtr nodes, GListPtr resources, GListPtr *placement_constraints, GListPtr *ordering_constraints); extern gboolean unpack_resources(xmlNodePtr xml_resources, GListPtr *resources, GListPtr *actions, GListPtr *ordering_constraints, GListPtr all_nodes); extern gboolean unpack_config(xmlNodePtr config); extern gboolean unpack_config(xmlNodePtr config); extern gboolean unpack_global_defaults(xmlNodePtr defaults); extern gboolean unpack_nodes(xmlNodePtr xml_nodes, GListPtr *nodes); extern gboolean unpack_status(xmlNodePtr status, GListPtr nodes, GListPtr rsc_list, GListPtr *actions, GListPtr *placement_constraints); extern gboolean apply_placement_constraints(GListPtr constraints, GListPtr nodes); extern gboolean apply_agent_constraints(GListPtr resources); extern void color_resource(resource_t *lh_resource, GListPtr *colors, GListPtr resources); extern gboolean choose_node_from_list(color_t *color); extern gboolean update_action_states(GListPtr actions); extern gboolean shutdown_constraints( node_t *node, action_t *shutdown_op, GListPtr *ordering_constraints); extern gboolean stonith_constraints( node_t *node, action_t *stonith_op, action_t *shutdown_op, GListPtr *ordering_constraints); extern gboolean order_new( resource_t *lh_rsc, enum action_tasks lh_task, action_t *lh_action, resource_t *rh_rsc, enum action_tasks rh_task, action_t *rh_action, enum con_strength strength, GListPtr *ordering_constraints); extern gboolean process_colored_constraints(resource_t *rsc); extern void graph_element_from_action(action_t *action, xmlNodePtr *graph); extern color_t *no_color; extern int max_valid_nodes; extern int order_id; extern int action_id; extern gboolean stonith_enabled; extern GListPtr agent_defaults; extern const char* transition_timeout; extern int num_synapse; #endif diff --git a/crm/pengine/utils.c b/crm/pengine/utils.c index bb903ab519..4e1a5ee64b 100644 --- a/crm/pengine/utils.c +++ b/crm/pengine/utils.c @@ -1,1118 +1,1121 @@ -/* $Id: utils.c,v 1.49 2004/11/12 17:20:58 andrew Exp $ */ +/* $Id: utils.c,v 1.50 2004/11/23 20:43:08 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include int action_id = 1; void print_str_str(gpointer key, gpointer value, gpointer user_data); gboolean ghash_free_str_str(gpointer key, gpointer value, gpointer user_data); gboolean node_merge_weights(node_t *node, node_t *with); /* only for rsc_dependancy constraints */ rsc_dependancy_t * invert_constraint(rsc_dependancy_t *constraint) { rsc_dependancy_t *inverted_con = NULL; crm_verbose("Inverting constraint"); if(constraint == NULL) { crm_err("Cannot invert NULL constraint"); return NULL; } crm_malloc(inverted_con, sizeof(rsc_dependancy_t)); if(inverted_con == NULL) { return NULL; } inverted_con->id = crm_strdup(constraint->id); inverted_con->strength = constraint->strength; /* swap the direction */ inverted_con->rsc_lh = constraint->rsc_rh; inverted_con->rsc_rh = constraint->rsc_lh; crm_debug_action( print_rsc_dependancy("Inverted constraint", inverted_con, FALSE)); return inverted_con; } /* are the contents of list1 and list2 equal * nodes with weight < 0 are ignored if filter == TRUE * * slow but linear * */ gboolean node_list_eq(GListPtr list1, GListPtr list2, gboolean filter) { node_t *other_node; GListPtr lhs = list1; GListPtr rhs = list2; slist_iter( node, node_t, lhs, lpc, if(node == NULL || (filter && node->weight < 0)) { continue; } other_node = (node_t*) pe_find_node(rhs, node->details->uname); if(other_node == NULL || other_node->weight < 0) { return FALSE; } ); lhs = list2; rhs = list1; slist_iter( node, node_t, lhs, lpc, if(node == NULL || (filter && node->weight < 0)) { continue; } other_node = (node_t*) pe_find_node(rhs, node->details->uname); if(other_node == NULL || other_node->weight < 0) { return FALSE; } ); return TRUE; } /* the intersection of list1 and list2 */ GListPtr node_list_and(GListPtr list1, GListPtr list2, gboolean filter) { GListPtr result = NULL; int lpc = 0; for(lpc = 0; lpc < g_list_length(list1); lpc++) { node_t *node = (node_t*)g_list_nth_data(list1, lpc); node_t *new_node = node_copy(node); node_t *other_node = pe_find_node(list2, node->details->uname); if(node_merge_weights(new_node, other_node) == FALSE) { crm_free(new_node); } else if(filter && new_node->weight < 0) { crm_free(new_node); } else { result = g_list_append(result, new_node); } } return result; } gboolean node_merge_weights(node_t *node, node_t *with) { if(node == NULL || with == NULL) { return FALSE; } else if(node->weight < 0 || with->weight < 0) { node->weight = -1; } else if(node->weight < with->weight) { node->weight = with->weight; } return TRUE; } /* list1 - list2 */ GListPtr node_list_minus(GListPtr list1, GListPtr list2, gboolean filter) { GListPtr result = NULL; slist_iter( node, node_t, list1, lpc, node_t *other_node = pe_find_node(list2, node->details->uname); node_t *new_node = NULL; if(node == NULL || other_node != NULL || (filter && node->weight < 0)) { continue; } new_node = node_copy(node); result = g_list_append(result, new_node); ); crm_verbose("Minus result len: %d", g_list_length(result)); return result; } /* list1 + list2 - (intersection of list1 and list2) */ GListPtr node_list_xor(GListPtr list1, GListPtr list2, gboolean filter) { GListPtr result = NULL; slist_iter( node, node_t, list1, lpc, node_t *new_node = NULL; node_t *other_node = (node_t*) pe_find_node(list2, node->details->uname); if(node == NULL || other_node != NULL || (filter && node->weight < 0)) { continue; } new_node = node_copy(node); result = g_list_append(result, new_node); ); slist_iter( node, node_t, list2, lpc, node_t *new_node = NULL; node_t *other_node = (node_t*) pe_find_node(list1, node->details->uname); if(node == NULL || other_node != NULL || (filter && node->weight < 0)) { continue; } new_node = node_copy(node); result = g_list_append(result, new_node); ); crm_verbose("Xor result len: %d", g_list_length(result)); return result; } GListPtr node_list_or(GListPtr list1, GListPtr list2, gboolean filter) { node_t *other_node = NULL; GListPtr result = NULL; result = node_list_dup(list1, filter); slist_iter( node, node_t, list2, lpc, if(node == NULL) { continue; } other_node = (node_t*)pe_find_node( result, node->details->uname); if(other_node != NULL) { node_merge_weights(other_node, node); if(filter && node->weight < 0) { /* TODO: remove and free other_node */ } } else if(filter && node->weight < 0) { } else { node_t *new_node = node_copy(node); result = g_list_append(result, new_node); } ); return result; } GListPtr node_list_dup(GListPtr list1, gboolean filter) { GListPtr result = NULL; slist_iter( this_node, node_t, list1, lpc, node_t *new_node = NULL; if(filter && this_node->weight < 0) { continue; } new_node = node_copy(this_node); if(new_node != NULL) { result = g_list_append(result, new_node); } ); return result; } node_t * node_copy(node_t *this_node) { node_t *new_node = NULL; if(this_node == NULL) { crm_err("Failed copy of node."); return NULL; } crm_malloc(new_node, sizeof(node_t)); if(new_node == NULL) { return NULL; } crm_trace("Copying %p (%s) to %p", this_node, this_node->details->uname, new_node); new_node->weight = this_node->weight; new_node->fixed = this_node->fixed; new_node->details = this_node->details; return new_node; } static int color_id = 0; /* * Create a new color with the contents of "nodes" as the list of * possible nodes that resources with this color can be run on. * * Typically, when creating a color you will provide the node list from * the resource you will first assign the color to. * * If "colors" != NULL, it will be added to that list * If "resources" != NULL, it will be added to every provisional resource * in that list */ color_t * create_color(GListPtr *colors, resource_t *resource, GListPtr node_list) { color_t *new_color = NULL; crm_trace("Creating color"); crm_malloc(new_color, sizeof(color_t)); if(new_color == NULL) { return NULL; } new_color->id = color_id++; new_color->local_weight = 1.0; crm_trace("Creating color details"); crm_malloc(new_color->details, sizeof(struct color_shared_s)); if(new_color->details == NULL) { crm_free(new_color); return NULL; } new_color->details->id = new_color->id; new_color->details->highest_priority = -1; new_color->details->chosen_node = NULL; new_color->details->candidate_nodes = NULL; new_color->details->allocated_resources = NULL; new_color->details->pending = TRUE; if(resource != NULL) { crm_trace("populating node list"); new_color->details->highest_priority = resource->priority; new_color->details->candidate_nodes = node_list_dup(node_list, TRUE); } crm_debug_action(print_color("Created color", new_color, TRUE)); if(colors != NULL) { *colors = g_list_append(*colors, new_color); } return new_color; } color_t * copy_color(color_t *a_color) { color_t *color_copy = NULL; if(a_color == NULL) { crm_err("Cannot copy NULL"); return NULL; } crm_malloc(color_copy, sizeof(color_t)); if(color_copy != NULL) { color_copy->id = a_color->id; color_copy->details = a_color->details; color_copy->local_weight = 1.0; } return color_copy; } resource_t * pe_find_resource(GListPtr rsc_list, const char *id) { int lpc = 0; resource_t *rsc = NULL; resource_t *child_rsc = NULL; for(lpc = 0; lpc < g_list_length(rsc_list); lpc++) { rsc = g_list_nth_data(rsc_list, lpc); if(rsc != NULL && safe_str_eq(rsc->id, id)){ crm_debug("Found a match for %s", id); return rsc; } } for(lpc = 0; lpc < g_list_length(rsc_list); lpc++) { rsc = g_list_nth_data(rsc_list, lpc); child_rsc = rsc->fns->find_child(rsc, id); if(child_rsc != NULL) { crm_debug("Found a match for %s in %s", id, rsc->id); return child_rsc; } } /* error */ return NULL; } node_t * pe_find_node(GListPtr nodes, const char *uname) { int lpc = 0; node_t *node = NULL; for(lpc = 0; lpc < g_list_length(nodes); lpc++) { node = g_list_nth_data(nodes, lpc); if(node != NULL && safe_str_eq(node->details->uname, uname)) { return node; } } /* error */ return NULL; } node_t * pe_find_node_id(GListPtr nodes, const char *id) { int lpc = 0; node_t *node = NULL; for(lpc = 0; lpc < g_list_length(nodes); lpc++) { node = g_list_nth_data(nodes, lpc); if(safe_str_eq(node->details->id, id)) { return node; } } /* error */ return NULL; } gint gslist_color_compare(gconstpointer a, gconstpointer b); color_t * find_color(GListPtr candidate_colors, color_t *other_color) { GListPtr tmp = g_list_find_custom(candidate_colors, other_color, gslist_color_compare); if(tmp != NULL) { return (color_t *)tmp->data; } return NULL; } gint gslist_color_compare(gconstpointer a, gconstpointer b) { const color_t *color_a = (const color_t*)a; const color_t *color_b = (const color_t*)b; /* crm_trace("%d vs. %d", a?color_a->id:-2, b?color_b->id:-2); */ if(a == b) { return 0; } else if(a == NULL || b == NULL) { return 1; } else if(color_a->id == color_b->id) { return 0; } return 1; } gint sort_rsc_priority(gconstpointer a, gconstpointer b) { const resource_t *resource1 = (const resource_t*)a; const resource_t *resource2 = (const resource_t*)b; if(a == NULL) return 1; if(b == NULL) return -1; if(resource1->priority > resource2->priority) return -1; if(resource1->priority < resource2->priority) return 1; return 0; } gint sort_cons_strength(gconstpointer a, gconstpointer b) { const rsc_dependancy_t *rsc_constraint1 = (const rsc_dependancy_t*)a; const rsc_dependancy_t *rsc_constraint2 = (const rsc_dependancy_t*)b; if(a == NULL) return 1; if(b == NULL) return -1; if(rsc_constraint1->strength > rsc_constraint2->strength) return 1; if(rsc_constraint1->strength < rsc_constraint2->strength) return -1; return 0; } gint sort_color_weight(gconstpointer a, gconstpointer b) { const color_t *color1 = (const color_t*)a; const color_t *color2 = (const color_t*)b; if(a == NULL) return 1; if(b == NULL) return -1; if(color1->local_weight > color2->local_weight) return -1; if(color1->local_weight < color2->local_weight) return 1; return 0; } gint sort_node_weight(gconstpointer a, gconstpointer b) { const node_t *node1 = (const node_t*)a; const node_t *node2 = (const node_t*)b; if(a == NULL) return 1; if(b == NULL) return -1; if(node1->weight > node2->weight) return -1; if(node1->weight < node2->weight) return 1; return 0; } action_t * action_new(resource_t *rsc, enum action_tasks task, node_t *on_node) { action_t *action = NULL; GListPtr possible_matches = NULL; if(rsc != NULL) { possible_matches = find_actions(rsc->actions, task, on_node); } if(on_node != NULL && on_node->details->unclean) { crm_warn("Not creating action %s for %s because %s is unclean", task2text(task), rsc?rsc->id:"", on_node->details->id); } if(on_node != NULL && on_node->details->unclean) { crm_warn("Not creating action %s for %s because %s is unclean", task2text(task), rsc?rsc->id:"", on_node->details->id); } if(possible_matches != NULL) { if(g_list_length(possible_matches) > 1) { crm_err("Action %s for %s on %s exists %d times", task2text(task), rsc?rsc->id:"", on_node?on_node->details->id:"", g_list_length(possible_matches)); } action = g_list_nth_data(possible_matches, 0); crm_debug("Returning existing action (%d) %s for %s on %s", action->id, task2text(task), rsc?rsc->id:"", on_node?on_node->details->id:""); /* todo: free possible_matches */ return action; } crm_debug("Creating action %s for %s on %s", task2text(task), rsc?rsc->id:"", on_node?on_node->details->id:""); crm_malloc(action, sizeof(action_t)); if(action != NULL) { action->id = action_id++; action->rsc = rsc; action->task = task; action->node = on_node; action->actions_before = NULL; action->actions_after = NULL; action->failure_is_fatal = TRUE; action->pseudo = FALSE; action->dumped = FALSE; action->discard = FALSE; action->runnable = TRUE; action->processed = FALSE; action->optional = FALSE; action->seen_count = 0; action->timeout = NULL; action->args = create_xml_node(NULL, "args"); if(rsc != NULL) { crm_debug("Adding created action to its resource"); rsc->actions = g_list_append(rsc->actions, action); - if(rsc->timeout != NULL) { - action->timeout = crm_strdup(rsc->timeout); - } if(task == start_rsc) { rsc->starting = TRUE; - } - if(task == stop_rsc) { + action->timeout = rsc->start_timeout; + + } else if(task == stop_rsc) { rsc->stopping = TRUE; + action->timeout = rsc->stop_timeout; + + } else { + action->timeout = rsc->def_timeout; } + } } crm_debug("Action %d created", action->id); return action; } const char * strength2text(enum con_strength strength) { const char *result = ""; switch(strength) { case pecs_ignore: result = "ignore"; break; case pecs_must: result = XML_STRENGTH_VAL_MUST; break; case pecs_must_not: result = XML_STRENGTH_VAL_MUSTNOT; break; case pecs_startstop: result = "start/stop"; break; } return result; } const char * task2text(enum action_tasks task) { const char *result = ""; switch(task) { case no_action: result = "no_action"; break; case stop_rsc: result = "stop"; break; case stopped_rsc: result = "stopped"; break; case start_rsc: result = "start"; break; case started_rsc: result = "started"; break; case shutdown_crm: result = "shutdown_crm"; break; case stonith_node: result = "stonith"; break; } return result; } void print_node(const char *pre_text, node_t *node, gboolean details) { if(node == NULL) { crm_debug("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug("%s%s%sNode %s: (weight=%f, fixed=%s)", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", node->details==NULL?"error ":node->details->online?"":"Unavailable/Unclean ", node->details->uname, node->weight, node->fixed?"True":"False"); if(details && node->details != NULL) { char *pe_mutable = crm_strdup("\t\t"); crm_debug("\t\t===Node Attributes"); g_hash_table_foreach(node->details->attrs, print_str_str, pe_mutable); crm_free(pe_mutable); } if(details) { crm_debug("\t\t===Node Attributes"); slist_iter( rsc, resource_t, node->details->running_rsc, lpc, print_resource("\t\t", rsc, FALSE); ); } } /* * Used by the HashTable for-loop */ void print_str_str(gpointer key, gpointer value, gpointer user_data) { crm_debug("%s%s %s ==> %s", user_data==NULL?"":(char*)user_data, user_data==NULL?"":": ", (char*)key, (char*)value); } void print_color_details(const char *pre_text, struct color_shared_s *color, gboolean details) { if(color == NULL) { crm_debug("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug("%s%sColor %d: node=%s (from %d candidates)", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", color->id, color->chosen_node==NULL?"":color->chosen_node->details->uname, g_list_length(color->candidate_nodes)); if(details) { slist_iter(node, node_t, color->candidate_nodes, lpc, print_node("\t", node, FALSE)); } } void print_color(const char *pre_text, color_t *color, gboolean details) { if(color == NULL) { crm_debug("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug("%s%sColor %d: (weight=%f, node=%s, possible=%d)", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", color->id, color->local_weight, safe_val5("",color,details,chosen_node,details,uname), g_list_length(color->details->candidate_nodes)); if(details) { print_color_details("\t", color->details, details); } } void print_rsc_to_node(const char *pre_text, rsc_to_node_t *cons, gboolean details) { if(cons == NULL) { crm_debug("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug("%s%s%s Constraint %s (%p) - %d nodes:", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", "rsc_to_node", cons->id, cons, g_list_length(cons->node_list_rh)); if(details == FALSE) { crm_debug("\t%s %s run (score=%f : node placement rule)", safe_val3(NULL, cons, rsc_lh, id), cons->can?"Can":"Cannot", cons->weight); slist_iter( node, node_t, cons->node_list_rh, lpc, print_node("\t\t-->", node, FALSE) ); } } void print_rsc_dependancy(const char *pre_text, rsc_dependancy_t *cons, gboolean details) { if(cons == NULL) { crm_debug("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug("%s%s%s Constraint %s (%p):", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", "rsc_dependancy", cons->id, cons); if(details == FALSE) { crm_debug("\t%s --> %s, %s", safe_val3(NULL, cons, rsc_lh, id), safe_val3(NULL, cons, rsc_rh, id), strength2text(cons->strength)); } } void print_resource(const char *pre_text, resource_t *rsc, gboolean details) { if(rsc == NULL) { crm_debug("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } rsc->fns->dump(rsc, pre_text, details); } void print_action(const char *pre_text, action_t *action, gboolean details) { if(action == NULL) { crm_debug("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } switch(action->task) { case stonith_node: case shutdown_crm: crm_debug("%s%s%sAction %d: %s @ %s", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", action->discard?"Discarded ":action->optional?"Optional ":action->runnable?action->processed?"":"(Provisional) ":"!!Non-Startable!! ", action->id, task2text(action->task), safe_val4(NULL, action, node, details, uname)); break; default: crm_debug("%s%s%sAction %d: %s %s @ %s", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", action->optional?"Optional ":action->runnable?action->processed?"":"(Provisional) ":"!!Non-Startable!! ", action->id, task2text(action->task), safe_val3(NULL, action, rsc, id), safe_val4(NULL, action, node, details, uname)); break; } if(details) { #if 1 crm_debug("\t\t====== Preceeding Actions"); slist_iter( other, action_wrapper_t, action->actions_before, lpc, print_action("\t\t", other->action, FALSE); ); crm_debug("\t\t====== Subsequent Actions"); slist_iter( other, action_wrapper_t, action->actions_after, lpc, print_action("\t\t", other->action, FALSE); ); #else crm_debug("\t\t====== Subsequent Actions"); slist_iter( other, action_wrapper_t, action->actions_after, lpc, print_action("\t\t", other->action, FALSE); ); #endif crm_debug("\t\t====== End"); } else { crm_debug("\t\t(seen=%d, before=%d, after=%d)", action->seen_count, g_list_length(action->actions_before), g_list_length(action->actions_after)); } } void pe_free_nodes(GListPtr nodes) { while(nodes != NULL) { GListPtr list_item = nodes; node_t *node = (node_t*)list_item->data; struct node_shared_s *details = node->details; nodes = nodes->next; crm_trace("deleting node"); crm_trace("%s is being deleted", details->uname); print_node("delete", node, FALSE); if(details != NULL) { if(details->attrs != NULL) { g_hash_table_foreach_remove(details->attrs, ghash_free_str_str, NULL); g_hash_table_destroy(details->attrs); } } } if(nodes != NULL) { g_list_free(nodes); } } gboolean ghash_free_str_str(gpointer key, gpointer value, gpointer user_data) { crm_free(key); crm_free(value); return TRUE; } void pe_free_colors(GListPtr colors) { while(colors != NULL) { GListPtr list_item = colors; color_t *color = (color_t *)list_item->data; struct color_shared_s *details = color->details; colors = colors->next; if(details != NULL) { pe_free_shallow(details->candidate_nodes); pe_free_shallow_adv(details->allocated_resources, FALSE); crm_free(details->chosen_node); crm_free(details); } crm_free(color); } if(colors != NULL) { g_list_free(colors); } } void pe_free_shallow(GListPtr alist) { pe_free_shallow_adv(alist, TRUE); } void pe_free_shallow_adv(GListPtr alist, gboolean with_data) { GListPtr item; GListPtr item_next = alist; while(item_next != NULL) { item = item_next; item_next = item_next->next; if(with_data) { /* crm_trace("freeing %p", item->data); */ crm_free(item->data); } item->data = NULL; item->next = NULL; g_list_free(item); } } void pe_free_resources(GListPtr resources) { volatile GListPtr list_item = NULL; resource_t *rsc = NULL; while(resources != NULL) { list_item = resources; rsc = (resource_t *)list_item->data; resources = resources->next; pe_free_shallow_adv(rsc->candidate_colors, TRUE); rsc->fns->free(rsc); } if(resources != NULL) { g_list_free(resources); } } void pe_free_actions(GListPtr actions) { while(actions != NULL) { GListPtr list_item = actions; action_t *action = (action_t *)list_item->data; actions = actions->next; pe_free_shallow(action->actions_before);/* action_warpper_t* */ pe_free_shallow(action->actions_after); /* action_warpper_t* */ action->actions_before = NULL; action->actions_after = NULL; free_xml(action->args); crm_free(action); } if(actions != NULL) { g_list_free(actions); } } void pe_free_rsc_dependancy(rsc_dependancy_t *cons) { if(cons != NULL) { crm_debug("Freeing constraint %s (%p)", cons->id, cons); crm_free(cons); } } void pe_free_rsc_to_node(rsc_to_node_t *cons) { if(cons != NULL) { /* right now we dont make copies so this isnt required */ /* pe_free_shallow(cons->node_list_rh); */ /* node_t* */ crm_free(cons); } } GListPtr find_actions(GListPtr input, enum action_tasks task, node_t *on_node) { GListPtr result = NULL; slist_iter( action, action_t, input, lpc, if(action->task == task && (on_node == NULL || safe_str_eq(on_node->details->id, action->node->details->id))) { result = g_list_append(result, action); } ); return result; } void set_id(xmlNodePtr xml_obj, const char *prefix, int child) { int id_len = 0; gboolean use_prefix = TRUE; gboolean use_child = TRUE; char *new_id = NULL; const char *id = xmlGetProp(xml_obj, "id"); id_len = 1 + strlen(id); if(child > 999) { crm_err("Are you insane?!?" " The CRM does not support > 1000 children per resource"); return; } else if(child < 0) { use_child = FALSE; } else { id_len += 4; /* child */ } if(prefix == NULL || safe_str_eq(id, prefix)) { use_prefix = FALSE; } else { id_len += (1 + strlen(prefix)); } crm_malloc(new_id, id_len); if(use_child) { snprintf(new_id, id_len, "%s%s%s:%d", use_prefix?prefix:"", use_prefix?":":"", id, child); } else { snprintf(new_id, id_len, "%s%s%s", use_prefix?prefix:"", use_prefix?":":"", id); } set_xml_property_copy(xml_obj, "id", new_id); crm_free(new_id); }