diff --git a/crm/pengine/color.c b/crm/pengine/color.c index 36da19dc93..ca0fd995a5 100644 --- a/crm/pengine/color.c +++ b/crm/pengine/color.c @@ -1,143 +1,137 @@ -/* $Id: color.c,v 1.21 2004/11/11 14:51:26 andrew Exp $ */ +/* $Id: color.c,v 1.22 2004/11/12 17:20:58 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include color_t *no_color = NULL; color_t *add_color(resource_t *rh_resource, color_t *color); gboolean apply_placement_constraints(GListPtr constraints, GListPtr nodes) { - int lpc = 0; - crm_verbose("Applying constraints..."); slist_iter( cons, rsc_to_node_t, constraints, lpc, cons->rsc_lh->fns->rsc_location(cons->rsc_lh, cons); ); return TRUE; } gboolean apply_agent_constraints(GListPtr resources) { - int lpc; slist_iter( rsc, resource_t, resources, lpc, rsc->fns->agent_constraints(rsc); ); crm_trace("Finished applying RA restrictions"); return TRUE; } color_t * add_color(resource_t *resource, color_t *color) { - color_t *local_color = NULL; if(color == NULL) { crm_err("Cannot add NULL color"); return NULL; } local_color = find_color(resource->candidate_colors, color); if(local_color == NULL) { crm_debug("Adding color %d", color->id); local_color = copy_color(color); resource->candidate_colors = g_list_append(resource->candidate_colors, local_color); } else { crm_debug("Color %d already present", color->id); } return local_color; } void color_resource(resource_t *rsc, GListPtr *colors, GListPtr resources) { - int lpc = 0; - crm_debug_action(print_resource("Coloring", rsc, FALSE)); if(rsc->provisional == FALSE) { /* already processed this resource */ return; } rsc->rsc_cons = g_list_sort( rsc->rsc_cons, sort_cons_strength); crm_debug_action( print_resource("Pre-processing", rsc, FALSE)); /*------ Pre-processing */ slist_iter( constraint, rsc_dependancy_t, rsc->rsc_cons, lpc, crm_debug_action( print_rsc_dependancy( "Pre-Processing constraint", constraint,FALSE)); rsc->fns->rsc_dependancy_lh(constraint); ); /* avoid looping through lists when we know this resource * cant be started */ rsc->fns->color(rsc, colors); crm_debug_action( print_resource("Post-processing", rsc, TRUE)); /*------ Post-processing */ slist_iter( constraint, rsc_dependancy_t, rsc->rsc_cons, lpc, crm_debug_action( print_rsc_dependancy( "Post-Processing constraint",constraint,FALSE)); rsc->fns->rsc_dependancy_lh(constraint); ); crm_debug_action(print_resource("Colored", rsc, TRUE)); } diff --git a/crm/pengine/complex.c b/crm/pengine/complex.c index e73b62b3cc..d25f59c1ab 100644 --- a/crm/pengine/complex.c +++ b/crm/pengine/complex.c @@ -1,337 +1,335 @@ -/* $Id: complex.c,v 1.6 2004/11/11 14:51:26 andrew Exp $ */ +/* $Id: complex.c,v 1.7 2004/11/12 17:20:58 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); 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)->candidate_colors = NULL; (*rsc)->rsc_cons = NULL; (*rsc)->actions = NULL; if(safe_str_eq(stopfail, "ignore")) { (*rsc)->stopfail_type = pesf_ignore; } else if(safe_str_eq(stopfail, "stonith")) { (*rsc)->stopfail_type = pesf_stonith; } else { (*rsc)->stopfail_type = pesf_block; } if(safe_str_eq(restart, "restart")) { (*rsc)->restart_type = pe_restart_restart; } else if(safe_str_eq(restart, "recover")) { (*rsc)->restart_type = pe_restart_recover; } else { (*rsc)->restart_type = pe_restart_ignore; } (*rsc)->fns->unpack(*rsc); return TRUE; } void order_actions(action_t *lh_action, action_t *rh_action, order_constraint_t *order) { action_wrapper_t *wrapper = NULL; GListPtr list = NULL; crm_verbose("%d Processing %d -> %d", order->id, lh_action->id, rh_action->id); crm_debug_action( print_action("LH (order_actions)", lh_action, FALSE)); crm_debug_action( print_action("RH (order_actions)", rh_action, FALSE)); crm_malloc(wrapper, sizeof(action_wrapper_t)); if(wrapper != NULL) { wrapper->action = rh_action; wrapper->strength = order->strength; list = lh_action->actions_after; list = g_list_append(list, wrapper); lh_action->actions_after = list; } crm_malloc(wrapper, sizeof(action_wrapper_t)); if(wrapper != NULL) { wrapper->action = lh_action; wrapper->strength = order->strength; list = rh_action->actions_before; list = g_list_append(list, wrapper); rh_action->actions_before = list; } } void common_dump(resource_t *rsc, const char *pre_text, gboolean details) { crm_debug("%s%s%s%sResource %s: (variant=%s, priority=%f)", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", rsc->provisional?"Provisional ":"", rsc->runnable?"":"(Non-Startable) ", rsc->id, rsc->xml->name, (double)rsc->priority); } void common_free(resource_t *rsc) { if(rsc == NULL) { return; } crm_trace("Freeing %s", rsc->id); while(rsc->rsc_cons) { pe_free_rsc_dependancy( (rsc_dependancy_t*)rsc->rsc_cons->data); rsc->rsc_cons = rsc->rsc_cons->next; } crm_trace("Freeing constraint list"); if(rsc->rsc_cons != NULL) { g_list_free(rsc->rsc_cons); } crm_trace("Freeing opaque data"); crm_free(rsc->variant_opaque); crm_trace("Freeing resource"); crm_free(rsc); crm_trace("Resource freed"); } void common_agent_constraints( GListPtr node_list, lrm_agent_t *agent, const char *id) { - int lpc; slist_iter( node, node_t, node_list, lpc, crm_trace("Checking if %s supports %s/%s (%s)", node->details->uname, agent->class, agent->type, agent->version); if(has_agent(node, agent) == FALSE) { /* remove node from contention */ crm_trace("Marking node %s unavailable for %s", node->details->uname, id); node->weight = -1.0; node->fixed = TRUE; } /* if(node->fixed && node->weight < 0) { */ /* /\* the structure of the list will have changed */ /* * lpc-- might be sufficient */ /* *\/ */ /* crm_debug("Removing node %s from %s", */ /* node->details->uname, rsc->id); */ /* lpc = -1; */ /* native_data->allowed_nodes = g_list_remove( */ /* native_data->allowed_nodes, node); */ /* crm_free(node); */ /* } */ ); } gboolean has_agent(node_t *a_node, lrm_agent_t *an_agent) { - int lpc; if(a_node == NULL || an_agent == NULL || an_agent->type == NULL) { crm_warn("Invalid inputs"); return FALSE; } crm_devel("Checking %d agents on %s", g_list_length(a_node->details->agents), a_node->details->uname); slist_iter( agent, lrm_agent_t, a_node->details->agents, lpc, crm_trace("Checking against %s/%s (%s)", agent->class, agent->type, agent->version); if(safe_str_eq(an_agent->type, agent->type)){ if(an_agent->class == NULL) { return TRUE; } else if(safe_str_eq(an_agent->class, agent->class)) { if(compare_version( an_agent->version, agent->version) <= 0) { return TRUE; } } } ); crm_verbose("%s doesnt support version %s of %s/%s", a_node->details->uname, an_agent->version, an_agent->class, an_agent->type); return FALSE; } diff --git a/crm/pengine/group.c b/crm/pengine/group.c index c499287c72..9592c7309e 100644 --- a/crm/pengine/group.c +++ b/crm/pengine/group.c @@ -1,381 +1,373 @@ -/* $Id: group.c,v 1.5 2004/11/11 14:51:26 andrew Exp $ */ +/* $Id: group.c,v 1.6 2004/11/12 17:20:58 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include extern gboolean rsc_dependancy_new( const char *id, enum con_strength strength, resource_t *rsc_lh, resource_t *rsc_rh); typedef struct group_variant_data_s { int num_children; GListPtr child_list; /* resource_t* */ resource_t *self; resource_t *first_child; resource_t *last_child; } group_variant_data_t; #define get_group_variant_data(data, rsc) \ if(rsc->variant == pe_group) { \ data = (group_variant_data_t *)rsc->variant_opaque; \ } else { \ crm_err("Resource %s was not a \"group\" variant", \ rsc->id); \ return; \ } void group_unpack(resource_t *rsc) { xmlNodePtr xml_obj = rsc->xml; xmlNodePtr xml_self = create_xml_node(NULL, XML_CIB_TAG_RESOURCE); group_variant_data_t *group_data = NULL; resource_t *self = NULL; crm_verbose("Processing resource %s...", rsc->id); crm_malloc(group_data, sizeof(group_variant_data_t)); group_data->num_children = 0; group_data->self = NULL; group_data->child_list = NULL; group_data->first_child = NULL; group_data->last_child = NULL; /* this is a bit of a hack - but simplifies everything else */ copy_in_properties(xml_self, xml_obj); if(common_unpack(xml_self, &self)) { group_data->self = self; self->restart_type = pe_restart_restart; } else { crm_xml_err(xml_self, "Couldnt unpack dummy child"); return; } xml_child_iter( xml_obj, xml_native_rsc, XML_CIB_TAG_RESOURCE, resource_t *new_rsc = NULL; set_id(xml_native_rsc, rsc->id, -1); if(common_unpack(xml_native_rsc, &new_rsc)) { group_data->num_children++; group_data->child_list = g_list_append( group_data->child_list, new_rsc); group_data->last_child = new_rsc; if(group_data->first_child == NULL) { group_data->first_child = new_rsc; } crm_debug_action( print_resource("Added", new_rsc, FALSE)); } else { crm_err("Failed unpacking resource %s", xmlGetProp(xml_obj, XML_ATTR_ID)); } ); crm_verbose("Added %d children to resource %s...", group_data->num_children, rsc->id); rsc->variant_opaque = group_data; } resource_t * group_find_child(resource_t *rsc, const char *id) { group_variant_data_t *group_data = NULL; if(rsc->variant == pe_group) { group_data = (group_variant_data_t *)rsc->variant_opaque; } else { crm_err("Resource %s was not a \"group\" variant", rsc->id); return NULL; } return pe_find_resource(group_data->child_list, id); } int group_num_allowed_nodes(resource_t *rsc) { group_variant_data_t *group_data = NULL; if(rsc->variant == pe_native) { group_data = (group_variant_data_t *)rsc->variant_opaque; } else { crm_err("Resource %s was not a \"native\" variant", rsc->id); return 0; } return group_data->self->fns->num_allowed_nodes(group_data->self); } void group_color(resource_t *rsc, GListPtr *colors) { - int lpc; group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); group_data->self->fns->color(group_data->self, colors); slist_iter( child_rsc, resource_t, group_data->child_list, lpc, child_rsc->fns->color(child_rsc, colors); ); } void group_create_actions(resource_t *rsc) { - int lpc; gboolean child_starting = FALSE; gboolean child_stopping = FALSE; group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); slist_iter( child_rsc, resource_t, group_data->child_list, lpc, child_rsc->fns->create_actions(child_rsc); child_starting = child_starting || child_rsc->starting; child_stopping = child_stopping || child_rsc->stopping; ); if(child_starting) { rsc->starting = TRUE; action_new(group_data->self, start_rsc, NULL); action_new(group_data->self, started_rsc, NULL); } if(child_stopping) { rsc->stopping = TRUE; action_new(group_data->self, stop_rsc, NULL); action_new(group_data->self, stopped_rsc, NULL); } slist_iter( action, action_t, group_data->self->actions, lpc, action->pseudo = TRUE; ); } void group_internal_constraints(resource_t *rsc, GListPtr *ordering_constraints) { - int lpc; resource_t *last_rsc = NULL; group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); order_new(group_data->self, stop_rsc, NULL, group_data->self, start_rsc, NULL, pecs_startstop, ordering_constraints); slist_iter( child_rsc, resource_t, group_data->child_list, lpc, order_new(child_rsc, stop_rsc, NULL, child_rsc, start_rsc, NULL, pecs_startstop, ordering_constraints); if(last_rsc != NULL) { order_new(last_rsc, start_rsc, NULL, child_rsc, start_rsc, NULL, pecs_startstop, ordering_constraints); order_new(child_rsc, stop_rsc, NULL, last_rsc, stop_rsc, NULL, pecs_startstop, ordering_constraints); } else { order_new(child_rsc, stop_rsc, NULL, group_data->self, stopped_rsc, NULL, pecs_startstop, ordering_constraints); order_new(group_data->self, start_rsc, NULL, child_rsc, start_rsc, NULL, pecs_startstop, ordering_constraints); } rsc_dependancy_new("pe_group_internal", pecs_must, group_data->self, child_rsc); last_rsc = child_rsc; ); if(last_rsc != NULL) { order_new(last_rsc, start_rsc, NULL, group_data->self, started_rsc, NULL, pecs_startstop, ordering_constraints); order_new(group_data->self, stop_rsc, NULL, last_rsc, stop_rsc, NULL, pecs_startstop, ordering_constraints); } } void group_rsc_dependancy_lh(rsc_dependancy_t *constraint) { resource_t *rsc = constraint->rsc_lh; group_variant_data_t *group_data = NULL; if(rsc == NULL) { crm_err("rsc_lh was NULL for %s", constraint->id); return; } else if(constraint->rsc_rh == NULL) { crm_err("rsc_rh was NULL for %s", constraint->id); return; } else { crm_debug("Processing constraints from %s", rsc->id); } get_group_variant_data(group_data, rsc); group_data->self->fns->rsc_dependancy_rh(group_data->self, constraint); } void group_rsc_dependancy_rh(resource_t *rsc, rsc_dependancy_t *constraint) { resource_t *rsc_lh = rsc; group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); crm_verbose("Processing RH of constraint %s", constraint->id); crm_debug_action(print_resource("LHS", rsc_lh, TRUE)); group_data->self->fns->rsc_dependancy_rh(group_data->self, constraint); } void group_rsc_order_lh(resource_t *rsc, order_constraint_t *order) { group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); crm_verbose("Processing LH of ordering constraint %d", order->id); if(order->lh_action_task == start_rsc) { order->lh_action_task = started_rsc; } else if(order->lh_action_task == stop_rsc) { order->lh_action_task = stopped_rsc; } group_data->self->fns->rsc_order_lh(group_data->self, order); } void group_rsc_order_rh( action_t *lh_action, resource_t *rsc, order_constraint_t *order) { group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); crm_verbose("Processing RH of ordering constraint %d", order->id); group_data->self->fns->rsc_order_rh(lh_action, group_data->self, order); } void group_rsc_location(resource_t *rsc, rsc_to_node_t *constraint) { - int lpc; group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); crm_verbose("Processing actions from %s", rsc->id); group_data->self->fns->rsc_location(group_data->self, constraint); slist_iter( child_rsc, resource_t, group_data->child_list, lpc, child_rsc->fns->rsc_location(child_rsc, constraint); ); } void group_expand(resource_t *rsc, xmlNodePtr *graph) { - int lpc; group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); crm_verbose("Processing actions from %s", rsc->id); group_data->self->fns->expand(group_data->self, graph); slist_iter( child_rsc, resource_t, group_data->child_list, lpc, child_rsc->fns->expand(child_rsc, graph); ); } void group_dump(resource_t *rsc, const char *pre_text, gboolean details) { - int lpc; group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); common_dump(rsc, pre_text, details); group_data->self->fns->dump(group_data->self, pre_text, details); slist_iter( child_rsc, resource_t, group_data->child_list, lpc, child_rsc->fns->dump(child_rsc, pre_text, details); ); } void group_free(resource_t *rsc) { - int lpc; group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); crm_verbose("Freeing %s", rsc->id); slist_iter( child_rsc, resource_t, group_data->child_list, lpc, crm_verbose("Freeing child %s", child_rsc->id); child_rsc->fns->free(child_rsc); ); crm_verbose("Freeing child list"); pe_free_shallow_adv(group_data->child_list, FALSE); group_data->self->fns->free(group_data->self); common_free(rsc); } void group_agent_constraints(resource_t *rsc) { - int lpc; group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); slist_iter( child_rsc, resource_t, group_data->child_list, lpc, child_rsc->fns->agent_constraints(child_rsc); ); } diff --git a/crm/pengine/native.c b/crm/pengine/native.c index 500bd62758..1436f289c7 100644 --- a/crm/pengine/native.c +++ b/crm/pengine/native.c @@ -1,1119 +1,1110 @@ -/* $Id: native.c,v 1.6 2004/11/11 14:51:26 andrew Exp $ */ +/* $Id: native.c,v 1.7 2004/11/12 17:20:58 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include extern color_t *add_color(resource_t *rh_resource, color_t *color); gboolean native_choose_color(resource_t *lh_resource); void native_assign_color(resource_t *rsc, color_t *color); void native_update_node_weight(resource_t *rsc, rsc_to_node_t *cons, const char *id, GListPtr nodes); void native_rsc_dependancy_rh_must(resource_t *rsc_lh, gboolean update_lh, resource_t *rsc_rh, gboolean update_rh); void native_rsc_dependancy_rh_mustnot(resource_t *rsc_lh, gboolean update_lh, resource_t *rsc_rh, gboolean update_rh); void filter_nodes(resource_t *rsc); int num_allowed_nodes4color(color_t *color); typedef struct native_variant_data_s { lrm_agent_t *agent; GListPtr running_on; /* node_t* */ color_t *color; GListPtr node_cons; /* rsc_to_node_t* */ GListPtr allowed_nodes; /* node_t* */ } native_variant_data_t; #define get_native_variant_data(data, rsc) \ if(rsc->variant == pe_native) { \ data = (native_variant_data_t *)rsc->variant_opaque; \ } else { \ crm_err("Resource %s was not a \"native\" variant", \ rsc->id); \ return; \ } \ #define get_native_variant_data_boolean(data, rsc) \ if(rsc->variant == pe_native) { \ data = (native_variant_data_t *)rsc->variant_opaque; \ } else { \ crm_err("Resource %s was not a \"native\" variant", \ rsc->id); \ return FALSE; \ } \ void native_add_running(resource_t *rsc, node_t *node) { native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); native_data->running_on = g_list_append(native_data->running_on, node); if(g_list_length(native_data->running_on) > 1) { crm_warn("Resource %s is (potentially) active on %d nodes." " Latest: %s", rsc->id, g_list_length(native_data->running_on), node->details->id); } } void native_unpack(resource_t *rsc) { xmlNodePtr xml_obj = rsc->xml; native_variant_data_t *native_data = NULL; const char *version = xmlGetProp(xml_obj, XML_ATTR_VERSION); crm_verbose("Processing resource %s...", rsc->id); crm_malloc(native_data, sizeof(native_variant_data_t)); crm_malloc(native_data->agent, sizeof(lrm_agent_t)); native_data->agent->class = xmlGetProp(xml_obj, "class"); native_data->agent->type = xmlGetProp(xml_obj, "type"); native_data->agent->version = version?version:"0.0"; native_data->color = NULL; native_data->allowed_nodes = NULL; native_data->node_cons = NULL; native_data->running_on = NULL; rsc->variant_opaque = native_data; } resource_t * native_find_child(resource_t *rsc, const char *id) { return NULL; } int native_num_allowed_nodes(resource_t *rsc) { - int lpc = 0, num_nodes = 0; + int num_nodes = 0; native_variant_data_t *native_data = NULL; if(rsc->variant == pe_native) { native_data = (native_variant_data_t *)rsc->variant_opaque; } else { crm_err("Resource %s was not a \"native\" variant", rsc->id); return 0; } if(native_data->color) { return num_allowed_nodes4color(native_data->color); } else if(rsc->candidate_colors) { /* TODO: sort colors first */ color_t *color = g_list_nth_data(rsc->candidate_colors, 0); return num_allowed_nodes4color(color); } else { slist_iter( this_node, node_t, native_data->allowed_nodes, lpc, if(this_node->weight < 0) { continue; } num_nodes++; ); } return num_nodes; } int num_allowed_nodes4color(color_t *color) { - int lpc = 0, num_nodes = 0; + int num_nodes = 0; if(color->details->pending == FALSE) { if(color->details->chosen_node) { return 1; } return 0; } slist_iter( this_node, node_t, color->details->candidate_nodes, lpc, if(this_node->weight < 0) { continue; } num_nodes++; ); return num_nodes; } void native_color(resource_t *rsc, GListPtr *colors) { color_t *new_color = NULL; native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); if( native_choose_color(rsc) ) { crm_verbose("Colored resource %s with color %d", rsc->id, native_data->color->id); } else { if(native_data->allowed_nodes != NULL) { /* filter out nodes with a negative weight */ filter_nodes(rsc); new_color = create_color( colors, rsc, native_data->allowed_nodes); native_assign_color(rsc, new_color); } if(new_color == NULL) { crm_err("Could not color resource %s", rsc->id); print_resource("ERROR: No color", rsc, FALSE); native_assign_color(rsc, no_color); } } rsc->provisional = FALSE; } void native_create_actions(resource_t *rsc) { - int lpc2, lpc3; action_t *start_op = NULL; gboolean can_start = FALSE; node_t *chosen = NULL; native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); if(native_data->color != NULL) { chosen = native_data->color->details->chosen_node; } if(chosen != NULL) { can_start = TRUE; } if(can_start && g_list_length(native_data->running_on) == 0) { /* create start action */ crm_info("Start resource %s (%s)", rsc->id, safe_val3(NULL, chosen, details, uname)); start_op = action_new(rsc, start_rsc, chosen); } else if(g_list_length(native_data->running_on) > 1) { crm_info("Attempting recovery of resource %s", rsc->id); if(rsc->recovery_type == recovery_stop_start || rsc->recovery_type == recovery_stop_only) { slist_iter( node, node_t, - native_data->running_on, lpc2, + native_data->running_on, lpc, crm_info("Stop resource %s (%s)", rsc->id, safe_val3(NULL, node, details, uname)); action_new(rsc, stop_rsc, node); ); } if(rsc->recovery_type == recovery_stop_start && can_start) { crm_info("Start resource %s (%s)", rsc->id, safe_val3(NULL, chosen, details, uname)); start_op = action_new( rsc, start_rsc, chosen); } } else { /* stop and or possible restart */ crm_debug("Stop and possible restart of %s", rsc->id); slist_iter( - node, node_t, native_data->running_on, lpc2, + node, node_t, native_data->running_on, lpc, if(chosen != NULL && safe_str_eq( node->details->id, chosen->details->id)) { /* restart */ crm_info("Leave resource %s alone (%s)", rsc->id, safe_val3(NULL, chosen, details, uname)); /* in case the actions already exist */ slist_iter( - action, action_t, rsc->actions, lpc3, + action, action_t, rsc->actions, lpc2, if(action->task == start_rsc || action->task == stop_rsc){ action->optional = TRUE; } ); continue; } else if(chosen != NULL) { /* move */ crm_info("Move resource %s (%s -> %s)", rsc->id, safe_val3(NULL, node, details, uname), safe_val3(NULL, chosen, details, uname)); action_new(rsc, stop_rsc, node); action_new(rsc, start_rsc, chosen); } else { crm_info("Stop resource %s (%s)", rsc->id, safe_val3(NULL, node, details, uname)); action_new(rsc, stop_rsc, node); } ); } } void native_internal_constraints(resource_t *rsc, GListPtr *ordering_constraints) { order_new(rsc, stop_rsc, NULL, rsc, start_rsc, NULL, pecs_startstop, ordering_constraints); } void native_rsc_dependancy_lh(rsc_dependancy_t *constraint) { resource_t *rsc = constraint->rsc_lh; if(rsc == NULL) { crm_err("rsc_lh was NULL for %s", constraint->id); return; } else if(constraint->rsc_rh == NULL) { crm_err("rsc_rh was NULL for %s", constraint->id); return; } else { crm_debug("Processing constraints from %s", rsc->id); } constraint->rsc_rh->fns->rsc_dependancy_rh(rsc, constraint); } void native_rsc_dependancy_rh(resource_t *rsc, rsc_dependancy_t *constraint) { gboolean do_check = FALSE; gboolean update_lh = FALSE; gboolean update_rh = FALSE; resource_t *rsc_lh = rsc; resource_t *rsc_rh = constraint->rsc_rh; native_variant_data_t *native_data_lh = NULL; native_variant_data_t *native_data_rh = NULL; get_native_variant_data(native_data_lh, rsc_lh); get_native_variant_data(native_data_rh, rsc_rh); crm_verbose("Processing RH of constraint %s", constraint->id); crm_debug_action(print_resource("LHS", rsc_lh, TRUE)); crm_debug_action(print_resource("RHS", rsc_rh, TRUE)); if(constraint->strength == pecs_ignore || constraint->strength == pecs_startstop){ crm_debug("Skipping constraint type %d", constraint->strength); return; } if(rsc_lh->provisional && rsc_rh->provisional) { if(constraint->strength == pecs_must) { /* update effective_priorities */ native_rsc_dependancy_rh_must( rsc_lh, update_lh,rsc_rh, update_rh); } else { /* nothing */ crm_debug( "Skipping constraint, both sides provisional"); } return; } else if( (!rsc_lh->provisional) && (!rsc_rh->provisional) && (!native_data_lh->color->details->pending) && (!native_data_rh->color->details->pending) ) { /* error check */ do_check = TRUE; if(rsc_lh->effective_priority < rsc_rh->effective_priority) { update_lh = TRUE; } else if(rsc_lh->effective_priority > rsc_rh->effective_priority) { update_rh = TRUE; } else { update_lh = TRUE; update_rh = TRUE; } } else if(rsc_lh->provisional == FALSE && native_data_lh->color->details->pending == FALSE) { /* update _us_ : postproc color version */ update_rh = TRUE; } else if(rsc_rh->provisional == FALSE && native_data_rh->color->details->pending == FALSE) { /* update _them_ : postproc color alt version */ update_lh = TRUE; } else if(rsc_lh->provisional == FALSE) { /* update _us_ : preproc version */ update_rh = TRUE; } else if(rsc_rh->provisional == FALSE) { /* update _them_ : postproc version */ update_lh = TRUE; } else { crm_warn("Un-expected combination of inputs"); return; } if(update_lh) { crm_debug("Updating LHS"); } if(update_rh) { crm_debug("Updating RHS"); } if(do_check) { if(native_constraint_violated( rsc_lh, rsc_rh, constraint) == FALSE) { crm_debug("Constraint satisfied"); return; } /* else constraint cant be satisified */ crm_warn("Constraint %s could not be satisfied", constraint->id); if(update_lh) { crm_warn("Marking resource %s unrunnable as a result", rsc_lh->id); rsc_lh->runnable = FALSE; } if(update_rh) { crm_warn("Marking resource %s unrunnable as a result", rsc_rh->id); rsc_rh->runnable = FALSE; } } if(constraint->strength == pecs_must) { native_rsc_dependancy_rh_must( rsc_lh, update_lh,rsc_rh, update_rh); return; } else if(constraint->strength != pecs_must_not) { /* unknown type */ crm_err("Unknown constraint type %d", constraint->strength); return; } native_rsc_dependancy_rh_mustnot(rsc_lh, update_lh,rsc_rh, update_rh); } void native_rsc_order_lh(resource_t *lh_rsc, order_constraint_t *order) { - int lpc; GListPtr lh_actions = NULL; action_t *lh_action = order->lh_action; crm_verbose("Processing LH of ordering constraint %d", order->id); switch(order->lh_action_task) { case start_rsc: case started_rsc: case stop_rsc: case stopped_rsc: break; default: crm_err("Task \"%s\" from ordering %d isnt a resource action", task2text(order->lh_action_task), order->id); return; } if(lh_action != NULL) { lh_actions = g_list_append(NULL, lh_action); } else if(lh_action == NULL && lh_rsc != NULL) { if(order->strength == pecs_must) { crm_debug("No LH-Side (%s/%s) found for constraint..." " creating", lh_rsc->id, task2text(order->lh_action_task)); action_new(lh_rsc, order->lh_action_task, NULL); } lh_actions = find_actions( lh_rsc->actions, order->lh_action_task, NULL); if(lh_actions == NULL) { crm_debug("No LH-Side (%s/%s) found for constraint", lh_rsc->id, task2text(order->lh_action_task)); crm_debug("RH-Side was: (%s/%s)", order->rh_rsc?order->rh_rsc->id:order->rh_action?order->rh_action->rsc->id:"", task2text(order->rh_action_task)); return; } } else { crm_warn("No LH-Side (%s) specified for constraint", task2text(order->lh_action_task)); crm_debug("RH-Side was: (%s/%s)", order->rh_rsc?order->rh_rsc->id:order->rh_action?order->rh_action->rsc->id:"", task2text(order->rh_action_task)); return; } slist_iter( lh_action_iter, action_t, lh_actions, lpc, resource_t *rh_rsc = order->rh_rsc; if(rh_rsc == NULL && order->rh_action) { rh_rsc = order->rh_action->rsc; } if(rh_rsc) { rh_rsc->fns->rsc_order_rh( lh_action_iter, rh_rsc, order); } else if(order->rh_action) { order_actions(lh_action_iter, order->rh_action, order); } ); pe_free_shallow_adv(lh_actions, FALSE); } void native_rsc_order_rh( action_t *lh_action, resource_t *rsc, order_constraint_t *order) { - int lpc; GListPtr rh_actions = NULL; action_t *rh_action = order->rh_action; crm_verbose("Processing RH of ordering constraint %d", order->id); switch(order->rh_action_task) { case start_rsc: case started_rsc: case stop_rsc: case stopped_rsc: break; default: crm_err("Task \"%s\" from ordering %d isnt a resource action", task2text(order->rh_action_task), order->id); return; } if(rh_action != NULL) { rh_actions = g_list_append(NULL, rh_action); } else if(rh_action == NULL && rsc != NULL) { rh_actions = find_actions( rsc->actions, order->rh_action_task, NULL); if(rh_actions == NULL) { crm_debug("No RH-Side (%s/%s) found for constraint..." " ignoring", rsc->id, task2text(order->rh_action_task)); crm_debug("LH-Side was: (%s/%s)", order->lh_rsc?order->lh_rsc->id:order->lh_action?order->lh_action->rsc->id:"", task2text(order->lh_action_task)); return; } } else if(rh_action == NULL) { crm_debug("No RH-Side (%s) specified for constraint..." " ignoring", task2text(order->rh_action_task)); crm_debug("LH-Side was: (%s/%s)", order->lh_rsc?order->lh_rsc->id:order->lh_action?order->lh_action->rsc->id:"", task2text(order->lh_action_task)); return; } slist_iter( rh_action_iter, action_t, rh_actions, lpc, order_actions(lh_action, rh_action_iter, order); ); pe_free_shallow_adv(rh_actions, FALSE); } void native_rsc_location(resource_t *rsc, rsc_to_node_t *constraint) { - int lpc; GListPtr or_list; native_variant_data_t *native_data = NULL; crm_debug_action(print_rsc_to_node("Applying", constraint, FALSE)); /* take "lifetime" into account */ if(constraint == NULL) { crm_err("Constraint is NULL"); return; } else if(is_active(constraint) == FALSE) { crm_info("Constraint (%s) is not active", constraint->id); /* warning */ return; } else if(rsc == NULL) { crm_err("LHS of rsc_to_node (%s) is NULL", constraint->id); return; } get_native_variant_data(native_data, rsc); native_data->node_cons = g_list_append(native_data->node_cons, constraint); if(constraint->node_list_rh == NULL) { crm_err("RHS of constraint %s is NULL", constraint->id); return; } crm_debug_action(print_resource("before update", rsc,TRUE)); or_list = node_list_or( native_data->allowed_nodes, constraint->node_list_rh, FALSE); pe_free_shallow(native_data->allowed_nodes); native_data->allowed_nodes = or_list; slist_iter(node_rh, node_t, constraint->node_list_rh, lpc, native_update_node_weight( rsc, constraint, node_rh->details->uname, native_data->allowed_nodes)); crm_debug_action(print_resource("after update", rsc, TRUE)); } void native_expand(resource_t *rsc, xmlNodePtr *graph) { - int lpc; slist_iter( action, action_t, rsc->actions, lpc, crm_debug("processing action %d for rsc=%s", action->id, rsc->id); graph_element_from_action(action, graph); ); } void native_dump(resource_t *rsc, const char *pre_text, gboolean details) { native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); common_dump(rsc, pre_text, details); crm_debug("\t%d candidate colors, %d allowed nodes," " %d rsc_cons and %d node_cons", g_list_length(rsc->candidate_colors), g_list_length(native_data->allowed_nodes), g_list_length(rsc->rsc_cons), g_list_length(native_data->node_cons)); if(details) { - int lpc = 0; - crm_debug("\t=== Actions"); slist_iter( action, action_t, rsc->actions, lpc, print_action("\trsc action: ", action, FALSE); ); crm_debug("\t=== Colors"); slist_iter( color, color_t, rsc->candidate_colors, lpc, print_color("\t", color, FALSE) ); crm_debug("\t=== Allowed Nodes"); slist_iter( node, node_t, native_data->allowed_nodes, lpc, print_node("\t", node, FALSE); ); } } void native_free(resource_t *rsc) { native_variant_data_t *native_data = (native_variant_data_t *)rsc->variant_opaque; crm_debug("Freeing Allowed Nodes"); pe_free_shallow(native_data->allowed_nodes); common_free(rsc); } void native_rsc_dependancy_rh_must(resource_t *rsc_lh, gboolean update_lh, resource_t *rsc_rh, gboolean update_rh) { native_variant_data_t *native_data_lh = NULL; native_variant_data_t *native_data_rh = NULL; gboolean do_merge = FALSE; GListPtr old_list = NULL; GListPtr merged_node_list = NULL; float max_pri = rsc_lh->effective_priority; if(max_pri < rsc_rh->effective_priority) { max_pri = rsc_rh->effective_priority; } rsc_lh->effective_priority = max_pri; rsc_rh->effective_priority = max_pri; get_native_variant_data(native_data_lh, rsc_lh); get_native_variant_data(native_data_rh, rsc_rh); if(native_data_lh->color && native_data_rh->color) { do_merge = TRUE; merged_node_list = node_list_and( native_data_lh->color->details->candidate_nodes, native_data_rh->color->details->candidate_nodes, TRUE); } else if(native_data_lh->color) { do_merge = TRUE; merged_node_list = node_list_and( native_data_lh->color->details->candidate_nodes, native_data_rh->allowed_nodes, TRUE); } else if(native_data_rh->color) { do_merge = TRUE; merged_node_list = node_list_and( native_data_lh->allowed_nodes, native_data_rh->color->details->candidate_nodes, TRUE); } if(update_lh) { crm_free(native_data_lh->color); rsc_lh->runnable = rsc_rh->runnable; native_data_lh->color = copy_color(native_data_rh->color); } if(update_rh) { crm_free(native_data_rh->color); rsc_rh->runnable = rsc_lh->runnable; native_data_rh->color = copy_color(native_data_lh->color); } if(do_merge) { crm_debug("Merging candidate nodes"); old_list = native_data_rh->color->details->candidate_nodes; native_data_rh->color->details->candidate_nodes = merged_node_list; pe_free_shallow(old_list); } crm_debug("Finished processing pecs_must constraint"); } void native_rsc_dependancy_rh_mustnot(resource_t *rsc_lh, gboolean update_lh, resource_t *rsc_rh, gboolean update_rh) { color_t *color_lh = NULL; color_t *color_rh = NULL; native_variant_data_t *native_data_lh = NULL; native_variant_data_t *native_data_rh = NULL; get_native_variant_data(native_data_lh, rsc_lh); get_native_variant_data(native_data_rh, rsc_rh); crm_debug("Processing pecs_must_not constraint"); /* pecs_must_not */ if(update_lh) { color_rh = native_data_rh->color; if(rsc_lh->provisional) { color_lh = find_color( rsc_lh->candidate_colors, color_rh); rsc_lh->candidate_colors = g_list_remove( rsc_lh->candidate_colors, color_lh); crm_debug_action( print_color("Removed LH", color_lh, FALSE)); crm_debug_action( print_resource("Modified LH", rsc_lh, TRUE)); crm_free(color_lh); } else if(native_data_lh->color && native_data_lh->color->details->pending) { node_t *node_lh = NULL; color_lh = native_data_lh->color; node_lh = pe_find_node( color_lh->details->candidate_nodes, safe_val5(NULL, color_rh, details, chosen_node, details, uname)); color_lh->details->candidate_nodes = g_list_remove( color_lh->details->candidate_nodes, node_lh); crm_debug_action( print_node("Removed LH", node_lh, FALSE)); crm_debug_action( print_color("Modified LH", color_lh, FALSE)); crm_free(node_lh); } else { /* error, rsc marked as unrunnable above */ crm_warn("lh else"); } } if(update_rh) { color_lh = native_data_lh->color; if(rsc_rh->provisional) { color_rh = find_color( rsc_rh->candidate_colors, color_lh); rsc_rh->candidate_colors = g_list_remove( rsc_rh->candidate_colors, color_rh); crm_debug_action( print_color("Removed RH", color_rh, FALSE)); crm_debug_action( print_resource("Modified RH", rsc_rh, TRUE)); crm_free(color_rh); } else if(native_data_rh->color && native_data_rh->color->details->pending) { node_t *node_rh = NULL; color_rh = native_data_rh->color; node_rh = pe_find_node( color_rh->details->candidate_nodes, safe_val5(NULL, color_lh, details, chosen_node, details, uname)); color_rh->details->candidate_nodes = g_list_remove( color_rh->details->candidate_nodes, node_rh); crm_debug_action( print_node("Removed RH", node_rh, FALSE)); crm_debug_action( print_color("Modified RH", color_rh, FALSE)); crm_free(node_rh); } else { /* error, rsc marked as unrunnable above */ crm_warn("rh else"); } } } void native_agent_constraints(resource_t *rsc) { native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); crm_trace("Applying RA restrictions to %s", rsc->id); common_agent_constraints( native_data->allowed_nodes, native_data->agent, rsc->id); } gboolean native_choose_color(resource_t *rsc) { - int lpc = 0; GListPtr sorted_colors = NULL; native_variant_data_t *native_data = NULL; get_native_variant_data_boolean(native_data, rsc); if(rsc->runnable == FALSE) { native_assign_color(rsc, no_color); } if(rsc->provisional == FALSE) { return !rsc->provisional; } sorted_colors = g_list_sort( rsc->candidate_colors, sort_color_weight); rsc->candidate_colors = sorted_colors; crm_verbose("Choose a color from %d possibilities", g_list_length(sorted_colors)); slist_iter( this_color, color_t, rsc->candidate_colors, lpc, GListPtr intersection = NULL; GListPtr minus = NULL; int len = 0; if(this_color == NULL) { crm_err("color was NULL"); continue; } else if(rsc->effective_priority < this_color->details->highest_priority) { minus = node_list_minus( this_color->details->candidate_nodes, native_data->allowed_nodes, TRUE); len = g_list_length(minus); pe_free_shallow(minus); if(len > 0) { native_assign_color(rsc, this_color); break; } } else { intersection = node_list_and( this_color->details->candidate_nodes, native_data->allowed_nodes, TRUE); len = g_list_length(intersection); pe_free_shallow(intersection); if(len != 0) { native_assign_color(rsc, this_color); break; } } ); return !rsc->provisional; } void native_assign_color(resource_t *rsc, color_t *color) { color_t *local_color = add_color(rsc, color); GListPtr intersection = NULL; GListPtr old_list = NULL; native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); native_data->color = local_color; rsc->provisional = FALSE; if(local_color != NULL) { local_color->details->allocated_resources = g_list_append( local_color->details->allocated_resources,rsc); intersection = node_list_and( local_color->details->candidate_nodes, native_data->allowed_nodes, TRUE); old_list = local_color->details->candidate_nodes; pe_free_shallow(old_list); local_color->details->candidate_nodes = intersection; crm_verbose("Colored resource %s with new color %d", rsc->id, native_data->color->id); crm_debug_action( print_resource("Colored Resource", rsc, TRUE)); } else { crm_err("local color was NULL"); } return; } void native_update_node_weight(resource_t *rsc, rsc_to_node_t *cons, const char *id, GListPtr nodes) { node_t *node_rh = NULL; native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); node_rh = pe_find_node(native_data->allowed_nodes, id); if(node_rh == NULL) { crm_err("Node not found - cant update"); return; } if(node_rh->fixed) { /* warning */ crm_warn("Constraint %s is irrelevant as the" " weight of node %s is fixed as %f.", cons->id, node_rh->details->uname, node_rh->weight); return; } crm_verbose("Constraint %s (%s): node %s weight %f.", cons->id, cons->can?"can":"cannot", node_rh->details->uname, node_rh->weight); if(cons->can == FALSE) { node_rh->weight = -1; } else { node_rh->weight += cons->weight; } if(node_rh->weight < 0) { node_rh->fixed = TRUE; } crm_debug_action(print_node("Updated", node_rh, FALSE)); return; } gboolean native_constraint_violated( resource_t *rsc_lh, resource_t *rsc_rh, rsc_dependancy_t *constraint) { native_variant_data_t *native_data_lh = NULL; native_variant_data_t *native_data_rh = NULL; GListPtr result = NULL; color_t *color_lh = NULL; color_t *color_rh = NULL; GListPtr candidate_nodes_lh = NULL; GListPtr candidate_nodes_rh = NULL; gboolean matched = FALSE; get_native_variant_data_boolean(native_data_lh, rsc_lh); get_native_variant_data_boolean(native_data_rh, rsc_rh); color_lh = native_data_lh->color; color_rh = native_data_rh->color; if(constraint->strength == pecs_must_not) { matched = TRUE; } if(rsc_lh->provisional || rsc_rh->provisional) { return FALSE; } if(color_lh->details->pending && color_rh->details->pending) { candidate_nodes_lh = color_lh->details->candidate_nodes; candidate_nodes_rh = color_rh->details->candidate_nodes; } else if(color_lh->details->pending == FALSE && color_rh->details->pending == FALSE) { if(color_lh == NULL && color_rh == NULL) { return matched; } else if(color_lh == NULL || color_rh == NULL) { return !matched; } else if(color_lh->details->chosen_node == NULL && color_rh->details->chosen_node == NULL) { return matched; } else if(color_lh->details->chosen_node == NULL || color_rh->details->chosen_node == NULL) { return !matched; } else if(safe_str_eq( color_lh->details->chosen_node->details->id, color_rh->details->chosen_node->details->id)) { return matched; } return !matched; } else if(color_lh->details->pending) { candidate_nodes_lh = color_lh->details->candidate_nodes; candidate_nodes_rh = g_list_append( NULL, color_rh->details->chosen_node); } else if(color_rh->details->pending) { candidate_nodes_rh = color_rh->details->candidate_nodes; candidate_nodes_lh = g_list_append( NULL, color_lh->details->chosen_node); } result = node_list_and(candidate_nodes_lh, candidate_nodes_rh, TRUE); if(g_list_length(result) == 0 && constraint->strength == pecs_must) { /* free result */ return TRUE; } return FALSE; } /* * Remove any nodes with a -ve weight */ void filter_nodes(resource_t *rsc) { - int lpc2 = 0; native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); crm_debug_action(print_resource("Filtering nodes for", rsc, FALSE)); slist_iter( - node, node_t, native_data->allowed_nodes, lpc2, + node, node_t, native_data->allowed_nodes, lpc, if(node == NULL) { crm_err("Invalid NULL node"); } else if(node->weight < 0.0 || node->details->online == FALSE || node->details->type == node_ping) { crm_debug_action(print_node("Removing", node, FALSE)); native_data->allowed_nodes = g_list_remove(native_data->allowed_nodes, node); crm_free(node); - lpc2 = -1; /* restart the loop */ + lpc = -1; /* restart the loop */ } ); } diff --git a/crm/pengine/pengine.c b/crm/pengine/pengine.c index 36746ce624..fcecea76f8 100755 --- a/crm/pengine/pengine.c +++ b/crm/pengine/pengine.c @@ -1,255 +1,255 @@ -/* $Id: pengine.c,v 1.48 2004/11/09 09:32:14 andrew Exp $ */ +/* $Id: pengine.c,v 1.49 2004/11/12 17:20:58 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include FILE *pemsg_strm = NULL; xmlNodePtr do_calculations(xmlNodePtr cib_object); +int num_synapse = 0; + gboolean process_pe_message(xmlNodePtr msg, IPC_Channel *sender) { char *msg_buffer = NULL; const char *sys_to = NULL; const char *op = get_xml_attr (msg, XML_TAG_OPTIONS, XML_ATTR_OP, TRUE); const char *ref = xmlGetProp(msg, XML_ATTR_REFERENCE); if(safe_str_eq(xmlGetProp(msg, XML_ATTR_MSGTYPE), XML_ATTR_REQUEST)) { crm_info( "Message was a response not a request." " Discarding"); } crm_verbose("Processing %s op (ref=%s)...", op, ref); if(pemsg_strm == NULL) { pemsg_strm = fopen(DEVEL_DIR"/pe.log", "w"); } msg_buffer = dump_xml_formatted(msg); fprintf(pemsg_strm, "%s: %s\n", "[in ]", msg_buffer); fflush(pemsg_strm); crm_free(msg_buffer); sys_to = xmlGetProp(msg, XML_ATTR_SYSTO); if(op == NULL){ /* error */ } else if(strcmp(op, CRM_OP_HELLO) == 0) { /* ignore */ } else if(sys_to == NULL || strcmp(sys_to, CRM_SYSTEM_PENGINE) != 0) { crm_verbose("Bad sys-to %s", crm_str(sys_to)); return FALSE; } else if(strcmp(op, CRM_OP_PECALC) == 0) { xmlNodePtr input_cib = find_xml_node(msg, XML_TAG_CIB); xmlNodePtr output = do_calculations(input_cib); msg_buffer = dump_xml_formatted(output); fprintf(pemsg_strm, "%s: %s\n", "[out ]", msg_buffer); fflush(pemsg_strm); crm_free(msg_buffer); if (send_ipc_reply(sender, msg, output) ==FALSE) { crm_warn("Answer could not be sent"); } free_xml(output); } else if(strcmp(op, CRM_OP_QUIT) == 0) { crm_err("Received quit message, terminating"); exit(0); } return TRUE; } xmlNodePtr do_calculations(xmlNodePtr cib_object) { - int lpc, lpc2; - GListPtr resources = NULL; GListPtr nodes = NULL; GListPtr placement_constraints = NULL; GListPtr actions = NULL; GListPtr ordering_constraints = NULL; GListPtr stonith_list = NULL; GListPtr shutdown_list = NULL; GListPtr colors = NULL; GListPtr action_sets = NULL; xmlNodePtr graph = NULL; /* pe_debug_on(); */ crm_verbose("=#=#=#=#= Stage 0 =#=#=#=#="); stage0(cib_object, &resources, &nodes, &placement_constraints, &actions, &ordering_constraints, &stonith_list, &shutdown_list); crm_verbose("=#=#=#=#= Stage 1 =#=#=#=#="); stage1(placement_constraints, nodes, resources); crm_verbose("=#=#=#=#= Stage 2 =#=#=#=#="); stage2(resources, nodes, &colors); crm_verbose("========= Nodes ========="); crm_debug_action( slist_iter(node, node_t, nodes, lpc, print_node(NULL, node, TRUE) ) ); crm_verbose("========= Resources ========="); crm_debug_action( slist_iter(resource, resource_t, resources, lpc, print_resource(NULL, resource, TRUE) ) ); crm_verbose("=#=#=#=#= Stage 3 =#=#=#=#="); stage3(colors); crm_verbose("=#=#=#=#= Stage 4 =#=#=#=#="); stage4(colors); crm_verbose("========= Colors ========="); crm_debug_action( slist_iter(color, color_t, colors, lpc, print_color(NULL, color, FALSE) ) ); crm_verbose("=#=#=#=#= Stage 5 =#=#=#=#="); stage5(resources, &ordering_constraints); crm_verbose("=#=#=#=#= Stage 6 =#=#=#=#="); stage6(&actions, &ordering_constraints, nodes, resources); crm_verbose("========= Action List ========="); crm_debug_action( slist_iter(action, action_t, actions, lpc, print_action(NULL, action, TRUE) ) ); crm_verbose("=#=#=#=#= Stage 7 =#=#=#=#="); stage7(resources, actions, ordering_constraints); crm_verbose("=#=#=#=#= Summary =#=#=#=#="); summary(resources); crm_verbose("========= Action Sets ========="); crm_verbose("\t========= Set %d (Un-runnable) =========", -1); crm_debug_action( slist_iter(action, action_t, actions, lpc, if(action->optional == FALSE && action->runnable == FALSE) { print_action("\t", action, TRUE); } ) ); crm_debug_action( slist_iter(action_set, GList, action_sets, lpc, crm_verbose("\t========= Set %d =========", lpc); slist_iter(action, action_t, action_set, lpc2, print_action("\t", action, TRUE); ) ) ); crm_verbose("========= Stonith List ========="); crm_debug_action( slist_iter(node, node_t, stonith_list, lpc, print_node(NULL, node, FALSE); ) ); crm_verbose("========= Shutdown List ========="); crm_debug_action( slist_iter(node, node_t, shutdown_list, lpc, print_node(NULL, node, FALSE); ) ); crm_verbose("=#=#=#=#= Stage 8 =#=#=#=#="); stage8(resources, actions, &graph); crm_verbose("=#=#=#=#= Cleanup =#=#=#=#="); crm_verbose("deleting node cons"); while(placement_constraints) { pe_free_rsc_to_node((rsc_to_node_t*)placement_constraints->data); placement_constraints = placement_constraints->next; } if(placement_constraints != NULL) { g_list_free(placement_constraints); } crm_verbose("deleting order cons"); pe_free_shallow(ordering_constraints); crm_verbose("deleting action sets"); slist_iter(action_set, GList, action_sets, lpc, pe_free_shallow_adv(action_set, FALSE); ); pe_free_shallow_adv(action_sets, FALSE); crm_verbose("deleting actions"); pe_free_actions(actions); crm_verbose("deleting resources"); pe_free_resources(resources); crm_verbose("deleting colors"); pe_free_colors(colors); crm_verbose("deleting nodes"); pe_free_nodes(nodes); if(shutdown_list != NULL) { g_list_free(shutdown_list); } if(stonith_list != NULL) { g_list_free(stonith_list); } return graph; } diff --git a/crm/pengine/pengine.h b/crm/pengine/pengine.h index 517f32d33c..07fea45d74 100644 --- a/crm/pengine/pengine.h +++ b/crm/pengine/pengine.h @@ -1,334 +1,336 @@ -/* $Id: pengine.h,v 1.41 2004/11/11 14:51:26 andrew Exp $ */ +/* $Id: pengine.h,v 1.42 2004/11/12 17:20:58 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef PENGINE__H #define PENGINE__H #include typedef struct node_s node_t; typedef struct color_s color_t; typedef struct rsc_to_node_s rsc_to_node_t; typedef struct rsc_dependancy_s rsc_dependancy_t; typedef struct resource_s resource_t; typedef struct lrm_agent_s lrm_agent_t; typedef struct order_constraint_s order_constraint_t; typedef struct action_s action_t; typedef struct action_wrapper_s action_wrapper_t; #include #include #include enum con_type { type_none, rsc_dependancy, rsc_to_node, rsc_to_attr, base_weight }; enum node_type { node_ping, node_member }; enum con_strength { pecs_ignore, pecs_must, pecs_must_not, pecs_startstop }; enum action_tasks { no_action, stop_rsc, stopped_rsc, start_rsc, started_rsc, shutdown_crm, stonith_node }; enum rsc_recovery_type { recovery_stop_start, recovery_stop_only, recovery_block }; enum pe_stop_fail { pesf_block, pesf_stonith, pesf_ignore }; enum pe_restart { pe_restart_restart, pe_restart_recover, pe_restart_ignore }; struct node_shared_s { const char *id; const char *uname; gboolean online; gboolean unclean; gboolean shutdown; GListPtr running_rsc; /* resource_t* */ GListPtr agents; /* lrm_agent_t* */ GHashTable *attrs; /* char* => char* */ enum node_type type; }; struct node_s { float weight; gboolean fixed; struct node_shared_s *details; }; struct color_shared_s { int id; float highest_priority; GListPtr candidate_nodes; /* node_t* */ GListPtr allocated_resources; /* resources_t* */ node_t *chosen_node; gboolean pending; }; struct color_s { int id; struct color_shared_s *details; float local_weight; }; struct rsc_dependancy_s { const char *id; resource_t *rsc_lh; resource_t *rsc_rh; enum con_strength strength; }; struct rsc_to_node_s { const char *id; resource_t *rsc_lh; float weight; GListPtr node_list_rh; /* node_t* */ /* enum con_modifier modifier; */ gboolean can; }; struct lrm_agent_s { const char *class; const char *type; const char *version; }; struct resource_s { const char *id; xmlNodePtr xml; void *variant_opaque; enum pe_obj_types variant; resource_object_functions_t *fns; float priority; float effective_priority; const char *timeout; gboolean starting; gboolean stopping; gboolean is_stonith; gboolean runnable; gboolean provisional; enum rsc_recovery_type recovery_type; enum pe_stop_fail stopfail_type; enum pe_restart restart_type; GListPtr candidate_colors; /* color_t* */ GListPtr rsc_cons; /* rsc_dependancy_t* */ GListPtr actions; /* action_t* */ /* (soon to be) variant specific */ int max_instances; int max_node_instances; int max_masters; int max_node_masters; }; struct action_wrapper_s { enum con_strength strength; action_t *action; }; struct action_s { int id; resource_t *rsc; void *rsc_opaque; node_t *node; enum action_tasks task; gboolean pseudo; gboolean runnable; gboolean dumped; gboolean processed; gboolean optional; gboolean discard; gboolean failure_is_fatal; int seen_count; const char *timeout; xmlNodePtr args; GListPtr actions_before; /* action_warpper_t* */ GListPtr actions_after; /* action_warpper_t* */ /* (soon to be) variant specific */ int incarnation; }; struct order_constraint_s { int id; enum con_strength strength; void *lh_opaque; resource_t *lh_rsc; action_t *lh_action; enum action_tasks lh_action_task; void *rh_opaque; resource_t *rh_rsc; action_t *rh_action; enum action_tasks rh_action_task; /* (soon to be) variant specific */ /* int lh_rsc_incarnation; */ /* int rh_rsc_incarnation; */ }; extern gboolean stage0(xmlNodePtr cib, GListPtr *nodes, GListPtr *rscs, GListPtr *cons, GListPtr *actions, GListPtr *ordering_constraints, GListPtr *stonith_list, GListPtr *shutdown_list); extern gboolean stage1(GListPtr placement_constraints, GListPtr nodes, GListPtr resources); extern gboolean stage2(GListPtr sorted_rscs, GListPtr sorted_nodes, GListPtr *colors); extern gboolean stage3(GListPtr colors); extern gboolean stage4(GListPtr colors); extern gboolean stage5(GListPtr resources, GListPtr *ordering_constraints); extern gboolean stage6( GListPtr *actions, GListPtr *ordering_constraints, GListPtr nodes, GListPtr resources); extern gboolean stage7( GListPtr resources, GListPtr actions, GListPtr ordering_constraints); extern gboolean stage8( GListPtr resources, GListPtr action_sets, xmlNodePtr *graph); extern gboolean summary(GListPtr resources); extern gboolean pe_msg_dispatch(IPC_Channel *sender, void *user_data); extern gboolean process_pe_message(xmlNodePtr msg, IPC_Channel *sender); extern gboolean unpack_constraints(xmlNodePtr xml_constraints, GListPtr nodes, GListPtr resources, GListPtr *placement_constraints, GListPtr *ordering_constraints); extern gboolean unpack_resources(xmlNodePtr xml_resources, GListPtr *resources, GListPtr *actions, GListPtr *ordering_constraints, GListPtr all_nodes); extern gboolean unpack_config(xmlNodePtr config); extern gboolean unpack_config(xmlNodePtr config); extern gboolean unpack_global_defaults(xmlNodePtr defaults); extern gboolean unpack_nodes(xmlNodePtr xml_nodes, GListPtr *nodes); extern gboolean unpack_status(xmlNodePtr status, GListPtr nodes, GListPtr rsc_list, GListPtr *actions, GListPtr *placement_constraints); extern gboolean apply_placement_constraints(GListPtr constraints, GListPtr nodes); extern gboolean apply_agent_constraints(GListPtr resources); extern void color_resource(resource_t *lh_resource, GListPtr *colors, GListPtr resources); extern gboolean choose_node_from_list(color_t *color); extern gboolean update_action_states(GListPtr actions); extern gboolean shutdown_constraints( node_t *node, action_t *shutdown_op, GListPtr *ordering_constraints); extern gboolean stonith_constraints( node_t *node, action_t *stonith_op, action_t *shutdown_op, GListPtr *ordering_constraints); extern gboolean order_new( resource_t *lh_rsc, enum action_tasks lh_task, action_t *lh_action, resource_t *rh_rsc, enum action_tasks rh_task, action_t *rh_action, enum con_strength strength, GListPtr *ordering_constraints); extern gboolean process_colored_constraints(resource_t *rsc); extern void graph_element_from_action(action_t *action, xmlNodePtr *graph); extern color_t *no_color; extern int max_valid_nodes; extern int order_id; extern int action_id; extern gboolean stonith_enabled; extern GListPtr agent_defaults; extern const char* transition_timeout; +extern int num_synapse; + #endif diff --git a/crm/pengine/ptest.c b/crm/pengine/ptest.c index 8b5792399d..fb8d5a3b0e 100644 --- a/crm/pengine/ptest.c +++ b/crm/pengine/ptest.c @@ -1,302 +1,301 @@ -/* $Id: ptest.c,v 1.38 2004/11/09 09:32:14 andrew Exp $ */ +/* $Id: ptest.c,v 1.39 2004/11/12 17:20:58 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include #include #include #define OPTARGS "V?X:" #include #include #include #include int main(int argc, char **argv) { xmlNodePtr cib_object = NULL; - int lpc = 0; int argerr = 0; int flag; GListPtr resources = NULL; GListPtr nodes = NULL; GListPtr placement_constraints = NULL; GListPtr actions = NULL; GListPtr ordering_constraints = NULL; GListPtr stonith_list = NULL; GListPtr shutdown_list = NULL; GListPtr colors = NULL; GListPtr action_sets = NULL; xmlNodePtr graph = NULL; char *msg_buffer = NULL; const char *xml_file = NULL; cl_log_set_entity("ptest"); cl_log_set_facility(LOG_USER); while (1) { int option_index = 0; static struct option long_options[] = { /* Top-level Options */ {"xml", 1, 0, 'X'}, {"help", 0, 0, 0}, {0, 0, 0, 0} }; flag = getopt_long(argc, argv, OPTARGS, long_options, &option_index); if (flag == -1) break; switch(flag) { case 0: printf("option %s", long_options[option_index].name); if (optarg) printf(" with arg %s", optarg); printf("\n"); break; case 'X': xml_file = crm_strdup(optarg); break; case 'V': alter_debug(DEBUG_INC); break; default: printf("?? getopt returned character code 0%o ??\n", flag); ++argerr; break; } } if (optind < argc) { printf("non-option ARGV-elements: "); while (optind < argc) printf("%s ", argv[optind++]); printf("\n"); } if (optind > argc) { ++argerr; } if (argerr) { crm_err("%d errors in option parsing", argerr); } crm_info("=#=#=#=#= Getting XML =#=#=#=#="); if(xml_file != NULL) { FILE *xml_strm = fopen(xml_file, "r"); cib_object = file2xml(xml_strm); } else { cib_object = file2xml(stdin); } crm_info("=#=#=#=#= Stage 0 =#=#=#=#="); #ifdef MCHECK mtrace(); #endif stage0(cib_object, &resources, &nodes, &placement_constraints, &actions, &ordering_constraints, &stonith_list, &shutdown_list); crm_debug("========= Nodes ========="); slist_iter(node, node_t, nodes, lpc, print_node(NULL, node, TRUE)); crm_debug("========= Resources ========="); slist_iter(resource, resource_t, resources, lpc, print_resource(NULL, resource, TRUE)); crm_debug("========= Constraints ========="); slist_iter(constraint, rsc_to_node_t, placement_constraints, lpc, print_rsc_to_node(NULL, constraint, FALSE)); crm_debug("=#=#=#=#= Stage 1 =#=#=#=#="); stage1(placement_constraints, nodes, resources); crm_debug("========= Nodes ========="); slist_iter(node, node_t, nodes, lpc, print_node(NULL, node, TRUE)); crm_debug("========= Resources ========="); slist_iter(resource, resource_t, resources, lpc, print_resource(NULL, resource, TRUE)); crm_debug("=#=#=#=#= Stage 2 =#=#=#=#="); stage2(resources, nodes, &colors); crm_debug("========= Nodes ========="); slist_iter(node, node_t, nodes, lpc, print_node(NULL, node, TRUE)); crm_debug("========= Resources ========="); slist_iter(resource, resource_t, resources, lpc, print_resource(NULL, resource, TRUE)); crm_debug("========= Colors ========="); slist_iter(color, color_t, colors, lpc, print_color(NULL, color, FALSE)); crm_debug("========= Action List ========="); slist_iter(action, action_t, actions, lpc, print_action(NULL, action, FALSE)); crm_debug("=#=#=#=#= Stage 3 =#=#=#=#="); stage3(colors); crm_debug("========= Colors ========="); slist_iter(color, color_t, colors, lpc, print_color(NULL, color, FALSE)); crm_debug("========= Action List ========="); slist_iter(action, action_t, actions, lpc, print_action(NULL, action, TRUE)); crm_debug("=#=#=#=#= Stage 4 =#=#=#=#="); stage4(colors); crm_debug("========= Colors ========="); slist_iter(color, color_t, colors, lpc, print_color(NULL, color, FALSE)); crm_debug("=#=#=#=#= Summary =#=#=#=#="); summary(resources); crm_debug("========= Action List ========="); slist_iter(action, action_t, actions, lpc, print_action(NULL, action, TRUE)); crm_debug("=#=#=#=#= Stage 5 =#=#=#=#="); stage5(resources, &ordering_constraints); crm_debug("========= All Actions ========="); slist_iter(action, action_t, actions, lpc, print_action("\t", action, TRUE); ); crm_debug("=#=#=#=#= Stage 6 =#=#=#=#="); stage6(&actions, &ordering_constraints, nodes, resources); crm_debug("========= Action List ========="); slist_iter(action, action_t, actions, lpc, print_action(NULL, action, TRUE)); crm_debug("=#=#=#=#= Stage 7 =#=#=#=#="); stage7(resources, actions, ordering_constraints); crm_debug("=#=#=#=#= Summary =#=#=#=#="); summary(resources); crm_debug("========= All Actions ========="); slist_iter(action, action_t, actions, lpc, print_action("\t", action, TRUE); ); crm_debug("========= Stonith List ========="); slist_iter(node, node_t, stonith_list, lpc, print_node(NULL, node, FALSE)); crm_debug("========= Shutdown List ========="); slist_iter(node, node_t, shutdown_list, lpc, print_node(NULL, node, FALSE)); crm_debug("=#=#=#=#= Stage 8 =#=#=#=#="); stage8(resources, actions, &graph); crm_verbose("deleting node cons"); while(placement_constraints) { pe_free_rsc_to_node((rsc_to_node_t*)placement_constraints->data); placement_constraints = placement_constraints->next; } if(placement_constraints != NULL) { g_list_free(placement_constraints); } crm_verbose("deleting order cons"); pe_free_shallow(ordering_constraints); crm_verbose("deleting action sets"); slist_iter(action_set, GList, action_sets, lpc, pe_free_shallow_adv(action_set, FALSE); ); pe_free_shallow_adv(action_sets, FALSE); crm_verbose("deleting actions"); pe_free_actions(actions); /* GListPtr action_sets = NULL; */ crm_verbose("deleting resources"); pe_free_resources(resources); crm_verbose("deleting colors"); pe_free_colors(colors); crm_free(no_color->details); crm_free(no_color); crm_verbose("deleting nodes"); pe_free_nodes(nodes); if(shutdown_list != NULL) { g_list_free(shutdown_list); } if(stonith_list != NULL) { g_list_free(stonith_list); } #ifdef MCHECK muntrace(); #endif msg_buffer = dump_xml_formatted(graph); fprintf(stdout, "%s\n", msg_buffer); fflush(stdout); crm_free(msg_buffer); free_xml(graph); free_xml(cib_object); return 0; } diff --git a/crm/pengine/stages.c b/crm/pengine/stages.c index 2ed7d6f59b..854178a433 100644 --- a/crm/pengine/stages.c +++ b/crm/pengine/stages.c @@ -1,467 +1,459 @@ -/* $Id: stages.c,v 1.27 2004/11/09 14:49:14 andrew Exp $ */ +/* $Id: stages.c,v 1.28 2004/11/12 17:20:58 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include node_t *choose_fencer(action_t *stonith, node_t *node, GListPtr resources); void order_actions(action_t *lh, action_t *rh, order_constraint_t *order); /* * Unpack everything * At the end you'll have: * - A list of nodes * - A list of resources (each with any dependancies on other resources) * - A list of constraints between resources and nodes * - A list of constraints between start/stop actions * - A list of nodes that need to be stonith'd * - A list of nodes that need to be shutdown * - A list of the possible stop/start actions (without dependancies) */ gboolean stage0(xmlNodePtr cib, GListPtr *resources, GListPtr *nodes, GListPtr *placement_constraints, GListPtr *actions, GListPtr *ordering_constraints, GListPtr *stonith_list, GListPtr *shutdown_list) { /* int lpc; */ xmlNodePtr cib_nodes = get_object_root( XML_CIB_TAG_NODES, cib); xmlNodePtr cib_status = get_object_root( XML_CIB_TAG_STATUS, cib); xmlNodePtr cib_resources = get_object_root( XML_CIB_TAG_RESOURCES, cib); xmlNodePtr cib_constraints = get_object_root( XML_CIB_TAG_CONSTRAINTS, cib); xmlNodePtr config = get_object_root( XML_CIB_TAG_CRMCONFIG, cib); xmlNodePtr agent_defaults = NULL; /*get_object_root(XML_CIB_TAG_RA_DEFAULTS, cib); */ /* reset remaining global variables */ + num_synapse = 0; max_valid_nodes = 0; order_id = 1; action_id = 1; unpack_config(config); unpack_global_defaults(agent_defaults); unpack_nodes(cib_nodes, nodes); unpack_resources(cib_resources, resources, actions, ordering_constraints, *nodes); unpack_status(cib_status, *nodes, *resources, actions, placement_constraints); unpack_constraints(cib_constraints, *nodes, *resources, placement_constraints, ordering_constraints); return TRUE; } /* * Count how many valid nodes we have (so we know the maximum number of * colors we can resolve). * * Apply node constraints (ie. filter the "allowed_nodes" part of resources */ gboolean stage1(GListPtr placement_constraints, GListPtr nodes, GListPtr resources) { - int lpc = 0; crm_info("Processing stage 1"); slist_iter( node, node_t, nodes, lpc, if(node == NULL) { /* error */ } else if(node->weight >= 0.0 /* global weight */ && node->details->online && node->details->type == node_member) { max_valid_nodes++; } ); apply_placement_constraints(placement_constraints, nodes); /* will also filter -ve "final" weighted nodes from resources' * allowed lists while we are there */ apply_agent_constraints(resources); return TRUE; } /* * Choose a color for all resources from highest priority and XML_STRENGTH_VAL_MUST * dependancies to lowest, creating new colors as necessary (returned * as "colors"). * * Some nodes may be colored as a "no_color" meaning that it was unresolvable * given the current node stati and constraints. */ gboolean stage2(GListPtr sorted_rscs, GListPtr sorted_nodes, GListPtr *colors) { - int lpc; crm_info("Processing stage 2"); if(no_color != NULL) { crm_free(no_color->details); crm_free(no_color); } crm_trace("create \"no color\""); no_color = create_color(NULL, NULL, NULL); /* Take (next) highest resource */ slist_iter( lh_resource, resource_t, sorted_rscs, lpc, /* if resource.provisional == FALSE, repeat */ if(lh_resource->provisional == FALSE) { /* already processed this resource */ continue; } color_resource(lh_resource, colors, sorted_rscs); /* next resource */ ); return TRUE; } /* * not sure if this is a good idea or not, but eventually we might like * to utilize as many nodes as possible... and this might be a convienient * hook */ gboolean stage3(GListPtr colors) { crm_info("Processing stage 3"); /* not sure if this is a good idea or not */ if(g_list_length(colors) > max_valid_nodes) { /* we need to consolidate some */ } else if(g_list_length(colors) < max_valid_nodes) { /* we can create a few more */ } return TRUE; } /* * Choose a node for each (if possible) color */ gboolean stage4(GListPtr colors) { - - int lpc = 0, lpc2 = 0; crm_info("Processing stage 4"); slist_iter( color, color_t, colors, lpc, crm_debug("assigning node to color %d", color->id); if(color == NULL) { crm_err("NULL color detected"); continue; } else if(color->details->pending == FALSE) { continue; } choose_node_from_list(color); crm_debug("assigned %s to color %d", safe_val5(NULL, color, details, chosen_node, details, uname), color->id); slist_iter( rsc, resource_t, color->details->allocated_resources, lpc2, slist_iter( constraint, rsc_dependancy_t, rsc->rsc_cons, lpc, rsc->fns->rsc_dependancy_lh(constraint); ); ); ); crm_verbose("done"); return TRUE; } /* * Attach nodes to the actions that need to be taken * * Mark actions XML_LRM_ATTR_OPTIONAL if possible (Ie. if the start and stop are * for the same node) * * Mark unrunnable actions */ gboolean stage5(GListPtr resources, GListPtr *ordering_constraints) { - int lpc; slist_iter( rsc, resource_t, resources, lpc, rsc->fns->create_actions(rsc); rsc->fns->internal_constraints(rsc, ordering_constraints); ); return TRUE; } /* * Create dependacies for stonith and shutdown operations */ gboolean stage6(GListPtr *actions, GListPtr *ordering_constraints, GListPtr nodes, GListPtr resources) { - int lpc = 0; action_t *down_op = NULL; action_t *stonith_op = NULL; crm_info("Processing stage 6"); slist_iter( node, node_t, nodes, lpc, if(node->details->shutdown) { crm_warn("Scheduling Node %s for shutdown", node->details->uname); down_op = action_new(NULL, shutdown_crm, node); down_op->runnable = TRUE; *actions = g_list_append(*actions, down_op); shutdown_constraints( node, down_op, ordering_constraints); } if(node->details->unclean && stonith_enabled) { crm_warn("Scheduling Node %s for STONITH", node->details->uname); stonith_op = action_new(NULL, stonith_node, NULL); stonith_op->runnable = TRUE; set_xml_property_copy(stonith_op->args, "target", node->details->uname); if(down_op != NULL) { down_op->failure_is_fatal = FALSE; } *actions = g_list_append(*actions, stonith_op); stonith_constraints(node, stonith_op, down_op, ordering_constraints); } ); return TRUE; } /* * Determin the sets of independant actions and the correct order for the * actions in each set. * * Mark dependancies of un-runnable actions un-runnable * */ gboolean stage7(GListPtr resources, GListPtr actions, GListPtr ordering_constraints) { - int lpc; crm_info("Processing stage 7"); slist_iter( order, order_constraint_t, ordering_constraints, lpc, /* try rsc_action-to-rsc_action */ resource_t *rsc = order->lh_rsc; if(rsc == NULL && order->lh_action) { rsc = order->lh_action->rsc; } if(rsc != NULL) { rsc->fns->rsc_order_lh(rsc, order); continue; } /* try action-to-rsc_action */ /* que off the rh resource */ rsc = order->rh_rsc; if(rsc == NULL && order->rh_action) { rsc = order->rh_action->rsc; } if(rsc != NULL) { rsc->fns->rsc_order_rh(order->lh_action, rsc, order); } else { /* fall back to action-to-action */ order_actions( order->lh_action, order->rh_action, order); } ); update_action_states(actions); return TRUE; } /* * Create a dependancy graph to send to the transitioner (via the CRMd) */ gboolean stage8(GListPtr resources, GListPtr actions, xmlNodePtr *graph) { - int lpc = 0; - crm_info("Processing stage 8"); *graph = create_xml_node(NULL, "transition_graph"); set_xml_property_copy( *graph, "global_timeout", transition_timeout); /* errors... slist_iter(action, action_t, action_list, lpc, if(action->optional == FALSE && action->runnable == FALSE) { print_action("Ignoring", action, TRUE); } ); */ slist_iter( rsc, resource_t, resources, lpc, crm_debug("processing actions for rsc=%s", rsc->id); rsc->fns->expand(rsc, graph); ); crm_xml_devel(*graph, "created resource-driven action list"); /* catch any non-resource specific actions */ slist_iter( action, action_t, actions, lpc, graph_element_from_action(action, graph); ); crm_xml_devel(*graph, "created generic action list"); return TRUE; } /* * Print a nice human readable high-level summary of what we're going to do */ gboolean summary(GListPtr resources) { #if 0 int lpc = 0; const char *rsc_id = NULL; const char *node_id = NULL; const char *new_node_id = NULL; slist_iter( rsc, resource_t, resources, lpc, rsc_id = safe_val(NULL, rsc, id); node_id = safe_val4(NULL, rsc, cur_node, details, uname); new_node_id = safe_val6( NULL, rsc, color, details, chosen_node, details, uname); if(rsc->runnable == FALSE) { crm_err("Resource %s was not runnable", rsc_id); if(node_id != NULL) { crm_warn("Stopping Resource (%s) on node %s", rsc_id, node_id); } } else if(safe_val4(NULL, rsc, color, details, chosen_node) == NULL) { crm_err("Could not allocate Resource %s", rsc_id); crm_debug_action( print_resource("Could not allocate",rsc,TRUE)); if(node_id != NULL) { crm_warn("Stopping Resource (%s) on node %s", rsc_id, node_id); } } else if(safe_str_eq(node_id, new_node_id)){ crm_debug("No change for Resource %s (%s)", rsc_id, safe_val4(NULL, rsc, cur_node, details, uname)); } else if(node_id == NULL) { crm_info("Starting Resource %s on %s", rsc_id, new_node_id); } else { crm_info("Moving Resource %s from %s to %s", rsc_id, node_id, new_node_id); } ); #endif return TRUE; } gboolean choose_node_from_list(color_t *color) { /* 1. Sort by weight 2. color.chosen_node = highest wieghted node 3. remove color.chosen_node from all other colors */ GListPtr nodes = color->details->candidate_nodes; nodes = g_list_sort(nodes, sort_node_weight); color->details->chosen_node = node_copy((node_t*)g_list_nth_data(nodes, 0)); color->details->pending = FALSE; if(color->details->chosen_node == NULL) { crm_err("Could not allocate a node for color %d", color->id); return FALSE; } return TRUE; } diff --git a/crm/pengine/utils.c b/crm/pengine/utils.c index 61fb6f46a5..bb903ab519 100644 --- a/crm/pengine/utils.c +++ b/crm/pengine/utils.c @@ -1,1128 +1,1118 @@ -/* $Id: utils.c,v 1.48 2004/11/11 14:51:26 andrew Exp $ */ +/* $Id: utils.c,v 1.49 2004/11/12 17:20:58 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include int action_id = 1; void print_str_str(gpointer key, gpointer value, gpointer user_data); gboolean ghash_free_str_str(gpointer key, gpointer value, gpointer user_data); gboolean node_merge_weights(node_t *node, node_t *with); /* only for rsc_dependancy constraints */ rsc_dependancy_t * invert_constraint(rsc_dependancy_t *constraint) { rsc_dependancy_t *inverted_con = NULL; crm_verbose("Inverting constraint"); if(constraint == NULL) { crm_err("Cannot invert NULL constraint"); return NULL; } crm_malloc(inverted_con, sizeof(rsc_dependancy_t)); if(inverted_con == NULL) { return NULL; } inverted_con->id = crm_strdup(constraint->id); inverted_con->strength = constraint->strength; /* swap the direction */ inverted_con->rsc_lh = constraint->rsc_rh; inverted_con->rsc_rh = constraint->rsc_lh; crm_debug_action( print_rsc_dependancy("Inverted constraint", inverted_con, FALSE)); return inverted_con; } /* are the contents of list1 and list2 equal * nodes with weight < 0 are ignored if filter == TRUE * * slow but linear * */ gboolean node_list_eq(GListPtr list1, GListPtr list2, gboolean filter) { - int lpc; - node_t *other_node; GListPtr lhs = list1; GListPtr rhs = list2; slist_iter( node, node_t, lhs, lpc, if(node == NULL || (filter && node->weight < 0)) { continue; } other_node = (node_t*) pe_find_node(rhs, node->details->uname); if(other_node == NULL || other_node->weight < 0) { return FALSE; } ); lhs = list2; rhs = list1; slist_iter( node, node_t, lhs, lpc, if(node == NULL || (filter && node->weight < 0)) { continue; } other_node = (node_t*) pe_find_node(rhs, node->details->uname); if(other_node == NULL || other_node->weight < 0) { return FALSE; } ); return TRUE; } /* the intersection of list1 and list2 */ GListPtr node_list_and(GListPtr list1, GListPtr list2, gboolean filter) { GListPtr result = NULL; int lpc = 0; for(lpc = 0; lpc < g_list_length(list1); lpc++) { node_t *node = (node_t*)g_list_nth_data(list1, lpc); node_t *new_node = node_copy(node); node_t *other_node = pe_find_node(list2, node->details->uname); if(node_merge_weights(new_node, other_node) == FALSE) { crm_free(new_node); } else if(filter && new_node->weight < 0) { crm_free(new_node); } else { result = g_list_append(result, new_node); } } return result; } gboolean node_merge_weights(node_t *node, node_t *with) { if(node == NULL || with == NULL) { return FALSE; } else if(node->weight < 0 || with->weight < 0) { node->weight = -1; } else if(node->weight < with->weight) { node->weight = with->weight; } return TRUE; } /* list1 - list2 */ GListPtr node_list_minus(GListPtr list1, GListPtr list2, gboolean filter) { GListPtr result = NULL; - int lpc = 0; slist_iter( node, node_t, list1, lpc, node_t *other_node = pe_find_node(list2, node->details->uname); node_t *new_node = NULL; if(node == NULL || other_node != NULL || (filter && node->weight < 0)) { continue; } new_node = node_copy(node); result = g_list_append(result, new_node); ); crm_verbose("Minus result len: %d", g_list_length(result)); return result; } /* list1 + list2 - (intersection of list1 and list2) */ GListPtr node_list_xor(GListPtr list1, GListPtr list2, gboolean filter) { GListPtr result = NULL; - int lpc = 0; slist_iter( node, node_t, list1, lpc, node_t *new_node = NULL; node_t *other_node = (node_t*) pe_find_node(list2, node->details->uname); if(node == NULL || other_node != NULL || (filter && node->weight < 0)) { continue; } new_node = node_copy(node); result = g_list_append(result, new_node); ); slist_iter( node, node_t, list2, lpc, node_t *new_node = NULL; node_t *other_node = (node_t*) pe_find_node(list1, node->details->uname); if(node == NULL || other_node != NULL || (filter && node->weight < 0)) { continue; } new_node = node_copy(node); result = g_list_append(result, new_node); ); crm_verbose("Xor result len: %d", g_list_length(result)); return result; } GListPtr node_list_or(GListPtr list1, GListPtr list2, gboolean filter) { node_t *other_node = NULL; GListPtr result = NULL; - int lpc = 0; result = node_list_dup(list1, filter); slist_iter( node, node_t, list2, lpc, if(node == NULL) { continue; } other_node = (node_t*)pe_find_node( result, node->details->uname); if(other_node != NULL) { node_merge_weights(other_node, node); if(filter && node->weight < 0) { /* TODO: remove and free other_node */ } } else if(filter && node->weight < 0) { } else { node_t *new_node = node_copy(node); result = g_list_append(result, new_node); } ); return result; } GListPtr node_list_dup(GListPtr list1, gboolean filter) { GListPtr result = NULL; - int lpc = 0; + slist_iter( this_node, node_t, list1, lpc, node_t *new_node = NULL; if(filter && this_node->weight < 0) { continue; } new_node = node_copy(this_node); if(new_node != NULL) { result = g_list_append(result, new_node); } ); return result; } node_t * node_copy(node_t *this_node) { node_t *new_node = NULL; if(this_node == NULL) { crm_err("Failed copy of node."); return NULL; } crm_malloc(new_node, sizeof(node_t)); if(new_node == NULL) { return NULL; } crm_trace("Copying %p (%s) to %p", this_node, this_node->details->uname, new_node); new_node->weight = this_node->weight; new_node->fixed = this_node->fixed; new_node->details = this_node->details; return new_node; } static int color_id = 0; /* * Create a new color with the contents of "nodes" as the list of * possible nodes that resources with this color can be run on. * * Typically, when creating a color you will provide the node list from * the resource you will first assign the color to. * * If "colors" != NULL, it will be added to that list * If "resources" != NULL, it will be added to every provisional resource * in that list */ color_t * create_color(GListPtr *colors, resource_t *resource, GListPtr node_list) { color_t *new_color = NULL; crm_trace("Creating color"); crm_malloc(new_color, sizeof(color_t)); if(new_color == NULL) { return NULL; } new_color->id = color_id++; new_color->local_weight = 1.0; crm_trace("Creating color details"); crm_malloc(new_color->details, sizeof(struct color_shared_s)); if(new_color->details == NULL) { crm_free(new_color); return NULL; } new_color->details->id = new_color->id; new_color->details->highest_priority = -1; new_color->details->chosen_node = NULL; new_color->details->candidate_nodes = NULL; new_color->details->allocated_resources = NULL; new_color->details->pending = TRUE; if(resource != NULL) { crm_trace("populating node list"); new_color->details->highest_priority = resource->priority; new_color->details->candidate_nodes = node_list_dup(node_list, TRUE); } crm_debug_action(print_color("Created color", new_color, TRUE)); if(colors != NULL) { *colors = g_list_append(*colors, new_color); } return new_color; } color_t * copy_color(color_t *a_color) { color_t *color_copy = NULL; if(a_color == NULL) { crm_err("Cannot copy NULL"); return NULL; } crm_malloc(color_copy, sizeof(color_t)); if(color_copy != NULL) { color_copy->id = a_color->id; color_copy->details = a_color->details; color_copy->local_weight = 1.0; } return color_copy; } resource_t * pe_find_resource(GListPtr rsc_list, const char *id) { int lpc = 0; resource_t *rsc = NULL; resource_t *child_rsc = NULL; for(lpc = 0; lpc < g_list_length(rsc_list); lpc++) { rsc = g_list_nth_data(rsc_list, lpc); if(rsc != NULL && safe_str_eq(rsc->id, id)){ crm_debug("Found a match for %s", id); return rsc; } } for(lpc = 0; lpc < g_list_length(rsc_list); lpc++) { rsc = g_list_nth_data(rsc_list, lpc); child_rsc = rsc->fns->find_child(rsc, id); if(child_rsc != NULL) { crm_debug("Found a match for %s in %s", id, rsc->id); return child_rsc; } } /* error */ return NULL; } node_t * pe_find_node(GListPtr nodes, const char *uname) { int lpc = 0; node_t *node = NULL; for(lpc = 0; lpc < g_list_length(nodes); lpc++) { node = g_list_nth_data(nodes, lpc); if(node != NULL && safe_str_eq(node->details->uname, uname)) { return node; } } /* error */ return NULL; } node_t * pe_find_node_id(GListPtr nodes, const char *id) { int lpc = 0; node_t *node = NULL; for(lpc = 0; lpc < g_list_length(nodes); lpc++) { node = g_list_nth_data(nodes, lpc); if(safe_str_eq(node->details->id, id)) { return node; } } /* error */ return NULL; } gint gslist_color_compare(gconstpointer a, gconstpointer b); color_t * find_color(GListPtr candidate_colors, color_t *other_color) { GListPtr tmp = g_list_find_custom(candidate_colors, other_color, gslist_color_compare); if(tmp != NULL) { return (color_t *)tmp->data; } return NULL; } gint gslist_color_compare(gconstpointer a, gconstpointer b) { const color_t *color_a = (const color_t*)a; const color_t *color_b = (const color_t*)b; /* crm_trace("%d vs. %d", a?color_a->id:-2, b?color_b->id:-2); */ if(a == b) { return 0; } else if(a == NULL || b == NULL) { return 1; } else if(color_a->id == color_b->id) { return 0; } return 1; } gint sort_rsc_priority(gconstpointer a, gconstpointer b) { const resource_t *resource1 = (const resource_t*)a; const resource_t *resource2 = (const resource_t*)b; if(a == NULL) return 1; if(b == NULL) return -1; if(resource1->priority > resource2->priority) return -1; if(resource1->priority < resource2->priority) return 1; return 0; } gint sort_cons_strength(gconstpointer a, gconstpointer b) { const rsc_dependancy_t *rsc_constraint1 = (const rsc_dependancy_t*)a; const rsc_dependancy_t *rsc_constraint2 = (const rsc_dependancy_t*)b; if(a == NULL) return 1; if(b == NULL) return -1; if(rsc_constraint1->strength > rsc_constraint2->strength) return 1; if(rsc_constraint1->strength < rsc_constraint2->strength) return -1; return 0; } gint sort_color_weight(gconstpointer a, gconstpointer b) { const color_t *color1 = (const color_t*)a; const color_t *color2 = (const color_t*)b; if(a == NULL) return 1; if(b == NULL) return -1; if(color1->local_weight > color2->local_weight) return -1; if(color1->local_weight < color2->local_weight) return 1; return 0; } gint sort_node_weight(gconstpointer a, gconstpointer b) { const node_t *node1 = (const node_t*)a; const node_t *node2 = (const node_t*)b; if(a == NULL) return 1; if(b == NULL) return -1; if(node1->weight > node2->weight) return -1; if(node1->weight < node2->weight) return 1; return 0; } action_t * action_new(resource_t *rsc, enum action_tasks task, node_t *on_node) { action_t *action = NULL; GListPtr possible_matches = NULL; if(rsc != NULL) { possible_matches = find_actions(rsc->actions, task, on_node); } if(on_node != NULL && on_node->details->unclean) { crm_warn("Not creating action %s for %s because %s is unclean", task2text(task), rsc?rsc->id:"", on_node->details->id); } if(on_node != NULL && on_node->details->unclean) { crm_warn("Not creating action %s for %s because %s is unclean", task2text(task), rsc?rsc->id:"", on_node->details->id); } if(possible_matches != NULL) { if(g_list_length(possible_matches) > 1) { crm_err("Action %s for %s on %s exists %d times", task2text(task), rsc?rsc->id:"", on_node?on_node->details->id:"", g_list_length(possible_matches)); } action = g_list_nth_data(possible_matches, 0); crm_debug("Returning existing action (%d) %s for %s on %s", action->id, task2text(task), rsc?rsc->id:"", on_node?on_node->details->id:""); /* todo: free possible_matches */ return action; } crm_debug("Creating action %s for %s on %s", task2text(task), rsc?rsc->id:"", on_node?on_node->details->id:""); crm_malloc(action, sizeof(action_t)); if(action != NULL) { action->id = action_id++; action->rsc = rsc; action->task = task; action->node = on_node; action->actions_before = NULL; action->actions_after = NULL; action->failure_is_fatal = TRUE; action->pseudo = FALSE; action->dumped = FALSE; action->discard = FALSE; action->runnable = TRUE; action->processed = FALSE; action->optional = FALSE; action->seen_count = 0; action->timeout = NULL; action->args = create_xml_node(NULL, "args"); if(rsc != NULL) { crm_debug("Adding created action to its resource"); rsc->actions = g_list_append(rsc->actions, action); if(rsc->timeout != NULL) { action->timeout = crm_strdup(rsc->timeout); } if(task == start_rsc) { rsc->starting = TRUE; } if(task == stop_rsc) { rsc->stopping = TRUE; } } } crm_debug("Action %d created", action->id); return action; } const char * strength2text(enum con_strength strength) { const char *result = ""; switch(strength) { case pecs_ignore: result = "ignore"; break; case pecs_must: result = XML_STRENGTH_VAL_MUST; break; case pecs_must_not: result = XML_STRENGTH_VAL_MUSTNOT; break; case pecs_startstop: result = "start/stop"; break; } return result; } const char * task2text(enum action_tasks task) { const char *result = ""; switch(task) { case no_action: result = "no_action"; break; case stop_rsc: result = "stop"; break; case stopped_rsc: result = "stopped"; break; case start_rsc: result = "start"; break; case started_rsc: result = "started"; break; case shutdown_crm: result = "shutdown_crm"; break; case stonith_node: result = "stonith"; break; } return result; } void print_node(const char *pre_text, node_t *node, gboolean details) { if(node == NULL) { crm_debug("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug("%s%s%sNode %s: (weight=%f, fixed=%s)", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", node->details==NULL?"error ":node->details->online?"":"Unavailable/Unclean ", node->details->uname, node->weight, node->fixed?"True":"False"); if(details && node->details != NULL) { char *pe_mutable = crm_strdup("\t\t"); crm_debug("\t\t===Node Attributes"); g_hash_table_foreach(node->details->attrs, print_str_str, pe_mutable); crm_free(pe_mutable); } if(details) { - int lpc = 0; crm_debug("\t\t===Node Attributes"); slist_iter( rsc, resource_t, node->details->running_rsc, lpc, print_resource("\t\t", rsc, FALSE); ); } } /* * Used by the HashTable for-loop */ void print_str_str(gpointer key, gpointer value, gpointer user_data) { crm_debug("%s%s %s ==> %s", user_data==NULL?"":(char*)user_data, user_data==NULL?"":": ", (char*)key, (char*)value); } void print_color_details(const char *pre_text, struct color_shared_s *color, gboolean details) { if(color == NULL) { crm_debug("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug("%s%sColor %d: node=%s (from %d candidates)", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", color->id, color->chosen_node==NULL?"":color->chosen_node->details->uname, g_list_length(color->candidate_nodes)); if(details) { - int lpc = 0; slist_iter(node, node_t, color->candidate_nodes, lpc, print_node("\t", node, FALSE)); } } void print_color(const char *pre_text, color_t *color, gboolean details) { if(color == NULL) { crm_debug("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug("%s%sColor %d: (weight=%f, node=%s, possible=%d)", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", color->id, color->local_weight, safe_val5("",color,details,chosen_node,details,uname), g_list_length(color->details->candidate_nodes)); if(details) { print_color_details("\t", color->details, details); } } void print_rsc_to_node(const char *pre_text, rsc_to_node_t *cons, gboolean details) { - int lpc = 0; if(cons == NULL) { crm_debug("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug("%s%s%s Constraint %s (%p) - %d nodes:", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", "rsc_to_node", cons->id, cons, g_list_length(cons->node_list_rh)); if(details == FALSE) { crm_debug("\t%s %s run (score=%f : node placement rule)", safe_val3(NULL, cons, rsc_lh, id), cons->can?"Can":"Cannot", cons->weight); slist_iter( node, node_t, cons->node_list_rh, lpc, print_node("\t\t-->", node, FALSE) ); } } void print_rsc_dependancy(const char *pre_text, rsc_dependancy_t *cons, gboolean details) { if(cons == NULL) { crm_debug("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug("%s%s%s Constraint %s (%p):", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", "rsc_dependancy", cons->id, cons); if(details == FALSE) { crm_debug("\t%s --> %s, %s", safe_val3(NULL, cons, rsc_lh, id), safe_val3(NULL, cons, rsc_rh, id), strength2text(cons->strength)); } } void print_resource(const char *pre_text, resource_t *rsc, gboolean details) { if(rsc == NULL) { crm_debug("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } rsc->fns->dump(rsc, pre_text, details); } void print_action(const char *pre_text, action_t *action, gboolean details) { if(action == NULL) { crm_debug("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } switch(action->task) { case stonith_node: case shutdown_crm: crm_debug("%s%s%sAction %d: %s @ %s", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", action->discard?"Discarded ":action->optional?"Optional ":action->runnable?action->processed?"":"(Provisional) ":"!!Non-Startable!! ", action->id, task2text(action->task), safe_val4(NULL, action, node, details, uname)); break; default: crm_debug("%s%s%sAction %d: %s %s @ %s", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", action->optional?"Optional ":action->runnable?action->processed?"":"(Provisional) ":"!!Non-Startable!! ", action->id, task2text(action->task), safe_val3(NULL, action, rsc, id), safe_val4(NULL, action, node, details, uname)); break; } if(details) { - int lpc = 0; #if 1 crm_debug("\t\t====== Preceeding Actions"); slist_iter( other, action_wrapper_t, action->actions_before, lpc, print_action("\t\t", other->action, FALSE); ); crm_debug("\t\t====== Subsequent Actions"); slist_iter( other, action_wrapper_t, action->actions_after, lpc, print_action("\t\t", other->action, FALSE); ); #else crm_debug("\t\t====== Subsequent Actions"); slist_iter( other, action_wrapper_t, action->actions_after, lpc, print_action("\t\t", other->action, FALSE); ); #endif crm_debug("\t\t====== End"); } else { crm_debug("\t\t(seen=%d, before=%d, after=%d)", action->seen_count, g_list_length(action->actions_before), g_list_length(action->actions_after)); } } void pe_free_nodes(GListPtr nodes) { while(nodes != NULL) { GListPtr list_item = nodes; node_t *node = (node_t*)list_item->data; struct node_shared_s *details = node->details; nodes = nodes->next; crm_trace("deleting node"); crm_trace("%s is being deleted", details->uname); print_node("delete", node, FALSE); if(details != NULL) { if(details->attrs != NULL) { g_hash_table_foreach_remove(details->attrs, ghash_free_str_str, NULL); g_hash_table_destroy(details->attrs); } } } if(nodes != NULL) { g_list_free(nodes); } } gboolean ghash_free_str_str(gpointer key, gpointer value, gpointer user_data) { crm_free(key); crm_free(value); return TRUE; } void pe_free_colors(GListPtr colors) { while(colors != NULL) { GListPtr list_item = colors; color_t *color = (color_t *)list_item->data; struct color_shared_s *details = color->details; colors = colors->next; if(details != NULL) { pe_free_shallow(details->candidate_nodes); pe_free_shallow_adv(details->allocated_resources, FALSE); crm_free(details->chosen_node); crm_free(details); } crm_free(color); } if(colors != NULL) { g_list_free(colors); } } void pe_free_shallow(GListPtr alist) { pe_free_shallow_adv(alist, TRUE); } void pe_free_shallow_adv(GListPtr alist, gboolean with_data) { GListPtr item; GListPtr item_next = alist; while(item_next != NULL) { item = item_next; item_next = item_next->next; if(with_data) { /* crm_trace("freeing %p", item->data); */ crm_free(item->data); } item->data = NULL; item->next = NULL; g_list_free(item); } } void pe_free_resources(GListPtr resources) { volatile GListPtr list_item = NULL; resource_t *rsc = NULL; while(resources != NULL) { list_item = resources; rsc = (resource_t *)list_item->data; resources = resources->next; pe_free_shallow_adv(rsc->candidate_colors, TRUE); rsc->fns->free(rsc); } if(resources != NULL) { g_list_free(resources); } } void pe_free_actions(GListPtr actions) { while(actions != NULL) { GListPtr list_item = actions; action_t *action = (action_t *)list_item->data; actions = actions->next; pe_free_shallow(action->actions_before);/* action_warpper_t* */ pe_free_shallow(action->actions_after); /* action_warpper_t* */ action->actions_before = NULL; action->actions_after = NULL; free_xml(action->args); crm_free(action); } if(actions != NULL) { g_list_free(actions); } } void pe_free_rsc_dependancy(rsc_dependancy_t *cons) { if(cons != NULL) { crm_debug("Freeing constraint %s (%p)", cons->id, cons); crm_free(cons); } } void pe_free_rsc_to_node(rsc_to_node_t *cons) { if(cons != NULL) { /* right now we dont make copies so this isnt required */ /* pe_free_shallow(cons->node_list_rh); */ /* node_t* */ crm_free(cons); } } GListPtr find_actions(GListPtr input, enum action_tasks task, node_t *on_node) { - int lpc = 0; GListPtr result = NULL; slist_iter( action, action_t, input, lpc, if(action->task == task && (on_node == NULL || safe_str_eq(on_node->details->id, action->node->details->id))) { result = g_list_append(result, action); } ); return result; } void set_id(xmlNodePtr xml_obj, const char *prefix, int child) { int id_len = 0; gboolean use_prefix = TRUE; gboolean use_child = TRUE; char *new_id = NULL; const char *id = xmlGetProp(xml_obj, "id"); id_len = 1 + strlen(id); if(child > 999) { crm_err("Are you insane?!?" " The CRM does not support > 1000 children per resource"); return; } else if(child < 0) { use_child = FALSE; } else { id_len += 4; /* child */ } if(prefix == NULL || safe_str_eq(id, prefix)) { use_prefix = FALSE; } else { id_len += (1 + strlen(prefix)); } crm_malloc(new_id, id_len); if(use_child) { snprintf(new_id, id_len, "%s%s%s:%d", use_prefix?prefix:"", use_prefix?":":"", id, child); } else { snprintf(new_id, id_len, "%s%s%s", use_prefix?prefix:"", use_prefix?":":"", id); } set_xml_property_copy(xml_obj, "id", new_id); crm_free(new_id); }