diff --git a/crm/pengine/master.c b/crm/pengine/master.c index ebdceadb92..01817228e8 100644 --- a/crm/pengine/master.c +++ b/crm/pengine/master.c @@ -1,484 +1,485 @@ -/* $Id: master.c,v 1.11 2006/03/28 12:03:06 andrew Exp $ */ +/* $Id: master.c,v 1.12 2006/03/31 12:00:59 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 extern void clone_create_notifications( resource_t *rsc, action_t *action, action_t *action_complete, pe_working_set_t *data_set); typedef struct clone_variant_data_s { resource_t *self; int clone_max; int clone_node_max; int active_clones; int max_nodes; gboolean interleave; gboolean ordered; crm_data_t *xml_obj_child; gboolean notify_confirm; GListPtr child_list; /* resource_t* */ } clone_variant_data_t; #define NO_MASTER_PREFS 0 #define get_clone_variant_data(data, rsc) \ CRM_ASSERT(rsc->variant == pe_master); \ data = (clone_variant_data_t *)rsc->variant_opaque; void master_unpack(resource_t *rsc, pe_working_set_t *data_set) { add_hash_param(rsc->parameters, "stateful", XML_BOOLEAN_TRUE); clone_unpack(rsc, data_set); } static void child_promoting_constraints( clone_variant_data_t *clone_data, enum pe_ordering type, resource_t *child, resource_t *last, pe_working_set_t *data_set) { /* if(clone_data->ordered */ /* || clone_data->self->restart_type == pe_restart_restart) { */ /* type = pe_ordering_manditory; */ /* } */ if(child == NULL) { if(clone_data->ordered && last != NULL) { crm_debug_4("Ordered version (last node)"); /* last child promote before promoted started */ custom_action_order( last, promote_key(last), NULL, clone_data->self, promoted_key(clone_data->self), NULL, type, data_set); } } else if(clone_data->ordered) { crm_debug_4("Ordered version"); if(last == NULL) { /* global promote before first child promote */ last = clone_data->self; } /* else: child/child relative promote */ order_start_start(last, child, type); custom_action_order( last, promote_key(last), NULL, child, promote_key(child), NULL, type, data_set); } else { crm_debug_4("Un-ordered version"); /* child promote before global promoted */ custom_action_order( child, promote_key(child), NULL, clone_data->self, promoted_key(clone_data->self), NULL, type, data_set); /* global promote before child promote */ custom_action_order( clone_data->self, promote_key(clone_data->self), NULL, child, promote_key(child), NULL, type, data_set); } } static void child_demoting_constraints( clone_variant_data_t *clone_data, enum pe_ordering type, resource_t *child, resource_t *last, pe_working_set_t *data_set) { /* if(clone_data->ordered */ /* || clone_data->self->restart_type == pe_restart_restart) { */ /* type = pe_ordering_manditory; */ /* } */ if(child == NULL) { if(clone_data->ordered && last != NULL) { crm_debug_4("Ordered version (last node)"); /* global demote before first child demote */ custom_action_order( clone_data->self, demote_key(clone_data->self), NULL, last, demote_key(last), NULL, pe_ordering_manditory, data_set); } } else if(clone_data->ordered && last != NULL) { crm_debug_4("Ordered version"); /* child/child relative demote */ custom_action_order(child, demote_key(child), NULL, last, demote_key(last), NULL, type, data_set); } else if(clone_data->ordered) { crm_debug_4("Ordered version (1st node)"); /* first child stop before global stopped */ custom_action_order( child, demote_key(child), NULL, clone_data->self, demoted_key(clone_data->self), NULL, type, data_set); } else { crm_debug_4("Un-ordered version"); /* child demote before global demoted */ custom_action_order( child, demote_key(child), NULL, clone_data->self, demoted_key(clone_data->self), NULL, type, data_set); /* global demote before child demote */ custom_action_order( clone_data->self, demote_key(clone_data->self), NULL, child, demote_key(child), NULL, type, data_set); } } static void master_update_pseudo_status( resource_t *child, gboolean *demoting, gboolean *promoting) { CRM_ASSERT(demoting != NULL); CRM_ASSERT(promoting != NULL); slist_iter( action, action_t, child->actions, lpc, if(*promoting && *demoting) { return; } else if(action->optional) { continue; } else if(safe_str_eq(CRMD_ACTION_DEMOTE, action->task)) { *demoting = TRUE; } else if(safe_str_eq(CRMD_ACTION_PROMOTE, action->task)) { *promoting = TRUE; } ); } #define apply_master_location(list) \ slist_iter( \ cons, rsc_to_node_t, list, lpc2, \ cons_node = NULL; \ if(cons->role_filter == RSC_ROLE_MASTER) { \ crm_debug("Applying %s to %s", \ cons->id, child_rsc->id); \ cons_node = pe_find_node_id( \ cons->node_list_rh, chosen->details->id); \ } \ if(cons_node != NULL) { \ int new_priority = merge_weights( \ child_rsc->priority, cons_node->weight); \ crm_debug("\t%s: %d->%d", child_rsc->id, \ child_rsc->priority, new_priority); \ child_rsc->priority = new_priority; \ } \ ); struct masters_s { node_t *node; int num_masters; }; void master_create_actions(resource_t *rsc, pe_working_set_t *data_set) { int len = 0; node_t *chosen = NULL; char *attr_name = NULL; const char *attr_value = NULL; node_t *cons_node = NULL; action_t *action = NULL; action_t *action_complete = NULL; gboolean any_promoting = FALSE; gboolean any_demoting = FALSE; resource_t *last_promote_rsc = NULL; resource_t *last_demote_rsc = NULL; const char *master_max_s = g_hash_table_lookup( rsc->parameters, XML_RSC_ATTR_MASTER_MAX); const char *master_node_max_s = g_hash_table_lookup( rsc->parameters, XML_RSC_ATTR_MASTER_NODEMAX); int promoted = 0; int master_max = crm_parse_int(master_max_s, "1"); int master_node_max = crm_parse_int(master_node_max_s, "1"); struct masters_s *master_hash_obj = NULL; GHashTable *master_hash = g_hash_table_new_full( g_str_hash, g_str_equal, g_hash_destroy_str, g_hash_destroy_str); clone_variant_data_t *clone_data = NULL; get_clone_variant_data(clone_data, rsc); /* how many can we have? */ if(master_max > clone_data->max_nodes * clone_data->clone_node_max) { master_max = clone_data->max_nodes * clone_data->clone_node_max; crm_info("Limited to %d masters (potential slaves)",master_max); } if(master_max > clone_data->max_nodes * master_node_max) { master_max = clone_data->max_nodes * master_node_max; crm_info("Limited to %d masters (available nodes)", master_max); } /* * assign priority */ slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, crm_debug_2("Assigning priority for %s", child_rsc->id); CRM_CHECK(child_rsc->color != NULL, continue); chosen = child_rsc->color->details->chosen_node; switch(child_rsc->next_role) { case RSC_ROLE_STARTED: if(NO_MASTER_PREFS) { child_rsc->priority = clone_data->clone_max - lpc; break; } child_rsc->priority = -1; CRM_CHECK(chosen != NULL, break); len = 8 + strlen(child_rsc->id); crm_malloc0(attr_name, len); sprintf(attr_name, "master-%s", child_rsc->id); attr_value = g_hash_table_lookup( chosen->details->attrs, attr_name); - crm_info("%s=%s for %s", attr_name, - crm_str(attr_value), - chosen->details->uname); - if(attr_value != NULL) { + crm_debug("%s=%s for %s", attr_name, + crm_str(attr_value), + chosen->details->uname); + child_rsc->priority = char2score( attr_value); } + crm_free(attr_name); apply_master_location(child_rsc->rsc_location); apply_master_location(rsc->rsc_location); break; case RSC_ROLE_SLAVE: case RSC_ROLE_STOPPED: child_rsc->priority = -INFINITY; break; default: CRM_CHECK(FALSE/* unhandled */, ;); } ); /* sort based on the new "promote" priority */ clone_data->child_list = g_list_sort( clone_data->child_list, sort_rsc_priority); /* mark the first N as masters */ slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, CRM_CHECK(child_rsc->color != NULL, continue); chosen = child_rsc->color->details->chosen_node; switch(child_rsc->next_role) { case RSC_ROLE_STARTED: master_hash_obj = g_hash_table_lookup( master_hash, chosen->details->id); if(master_hash_obj == NULL) { crm_malloc0(master_hash_obj, sizeof(struct masters_s)); master_hash_obj->node = chosen; g_hash_table_insert( master_hash, crm_strdup(chosen->details->id), master_hash_obj); } if(master_hash_obj->num_masters >= master_node_max) { crm_info("Demoting %s (node master max)", child_rsc->id); child_rsc->next_role = RSC_ROLE_SLAVE; } else if(child_rsc->priority < 0) { crm_info("Demoting %s (priority)", child_rsc->id); child_rsc->next_role = RSC_ROLE_SLAVE; } else if(master_max <= promoted) { crm_info("Demoting %s (masters max)", child_rsc->id); child_rsc->next_role = RSC_ROLE_SLAVE; } else { crm_info("Promoting %s", child_rsc->id); child_rsc->next_role = RSC_ROLE_MASTER; promoted++; master_hash_obj->num_masters++; } break; case RSC_ROLE_SLAVE: if(child_rsc->priority < 0 ||master_max <= lpc){ pe_warn("Cannot promote %s (slave)", child_rsc->id); lpc--; } break; case RSC_ROLE_STOPPED: if(child_rsc->priority < 0 ||master_max <= lpc){ - pe_warn("Cannot promote %s (stopping)", - child_rsc->id); + crm_debug("Cannot promote %s (stopping)", + child_rsc->id); lpc--; } break; default: CRM_CHECK(FALSE/* unhandled */, ;); } add_hash_param(child_rsc->parameters, "crm_role", role2text(child_rsc->next_role)); ); crm_info("Promoted %d (of %d) slaves to master", promoted, master_max); g_hash_table_destroy(master_hash); /* create actions as normal */ clone_create_actions(rsc, data_set); slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, gboolean child_promoting = FALSE; gboolean child_demoting = FALSE; master_update_pseudo_status( child_rsc, &child_demoting, &child_promoting); any_demoting = any_demoting || child_demoting; any_promoting = any_promoting || child_promoting; ); /* promote */ action = promote_action(clone_data->self, NULL, !any_promoting); action_complete = custom_action( clone_data->self, promoted_key(rsc), CRMD_ACTION_PROMOTED, NULL, !any_promoting, TRUE, data_set); action->pseudo = TRUE; action_complete->pseudo = TRUE; child_promoting_constraints(clone_data, pe_ordering_optional, NULL, last_promote_rsc, data_set); clone_create_notifications(rsc, action, action_complete, data_set); /* demote */ action = demote_action(clone_data->self, NULL, !any_demoting); action_complete = custom_action( clone_data->self, demoted_key(rsc), CRMD_ACTION_DEMOTED, NULL, !any_demoting, TRUE, data_set); action->pseudo = TRUE; action_complete->pseudo = TRUE; child_demoting_constraints(clone_data, pe_ordering_optional, NULL, last_demote_rsc, data_set); clone_create_notifications(rsc, action, action_complete, data_set); } void master_internal_constraints(resource_t *rsc, pe_working_set_t *data_set) { resource_t *last_rsc = NULL; clone_variant_data_t *clone_data = NULL; get_clone_variant_data(clone_data, rsc); clone_internal_constraints(rsc, data_set); /* global demoted before start */ custom_action_order( clone_data->self, demoted_key(clone_data->self), NULL, clone_data->self, start_key(clone_data->self), NULL, pe_ordering_optional, data_set); /* global started before promote */ custom_action_order( clone_data->self, started_key(clone_data->self), NULL, clone_data->self, promote_key(clone_data->self), NULL, pe_ordering_optional, data_set); /* global demoted before stop */ custom_action_order( clone_data->self, demoted_key(clone_data->self), NULL, clone_data->self, stop_key(clone_data->self), NULL, pe_ordering_optional, data_set); /* global demote before demoted */ custom_action_order( clone_data->self, demote_key(clone_data->self), NULL, clone_data->self, demoted_key(clone_data->self), NULL, pe_ordering_optional, data_set); slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, /* child demote before promote */ custom_action_order( child_rsc, demote_key(child_rsc), NULL, child_rsc, promote_key(child_rsc), NULL, pe_ordering_restart, data_set); child_promoting_constraints(clone_data, pe_ordering_optional, child_rsc, last_rsc, data_set); child_demoting_constraints(clone_data, pe_ordering_optional, child_rsc, last_rsc, data_set); last_rsc = child_rsc; ); } diff --git a/crm/pengine/regression.core.sh b/crm/pengine/regression.core.sh index 14dc2f0ffa..0cc39e5a0a 100755 --- a/crm/pengine/regression.core.sh +++ b/crm/pengine/regression.core.sh @@ -1,184 +1,184 @@ #!/bin/bash # Copyright (C) 2004 Andrew Beekhof # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This software is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # verbose=$1 io_dir=testcases diff_opts="--ignore-all-space -U 1 -u" -failed=.regression.failed +failed=.regression.failed.diff # zero out the error log > $failed num_failed=0 function do_test { base=$1; name=$2; input=$io_dir/${base}.xml output=$io_dir/${base}.pe.out expected=$io_dir/${base}.exp te_output=$io_dir/${base}.te.out te_expected=$io_dir/${base}.te.exp dot_output=$io_dir/${base}.pe.dot dot_expected=$io_dir/${base}.dot dot_png=$io_dir/${base}.png if [ ! -f $input ]; then echo "Test $name ($base)... Error (PE : input)"; return; fi if [ "$create_mode" != "true" -a ! -f $expected ]; then echo "Test $name ($base)... Error (PE : expected)"; # return; fi # ../admin/crm_verify -X $input ./ptest -V -X $input -D $dot_output > $output if [ -s core ]; then echo "Test $name ($base)... Moved core to core.${base}"; rm -f core.$base mv core core.$base return; fi if [ ! -s $output ]; then echo "Test $name ($base)... Error (PE : raw output)"; rm $output return; fi if [ ! -s $dot_output ]; then echo "Test $name ($base)... Error (PE : dot output)"; rm $output return; fi if [ ! -s $output ]; then echo "Test $name ($base)... Error (PE : fixed output)"; rm $output return; fi if [ "$create_mode" = "true" ]; then cp "$output" "$expected" cp "$dot_output" "$dot_expected" fi rc=2 dot -Tpng $dot_output 2>/dev/null > $dot_png if [ -f $dot_expected ]; then diff $diff_opts -q $dot_expected $dot_output >/dev/null rc=$? if [ $rc != 0 ]; then echo "Test $name ($base)... * Failed (PE : dot)"; diff $diff_opts $dot_expected $dot_output 2>/dev/null >> $failed num_failed=`expr $num_failed + 1` else rm $dot_output fi else echo "Test $name ($base)... * No expected dot output"; echo "==== Raw results for PE test ($base) ====" >> $failed cat $dot_output 2>/dev/null >> $failed rm $dot_output fi rc2=2 if [ -f $expected ]; then diff $diff_opts -q $expected $output >/dev/null rc2=$? if [ $rc2 != 0 ]; then echo "Test $name ($base)... * Failed (PE : raw)"; diff $diff_opts $expected $output 2>/dev/null >> $failed num_failed=`expr $num_failed + 1` else rm $output fi else echo "Test $name ($base)... * No expected raw output"; echo "==== Raw results for PE test ($base) ====" >> $failed cat $output 2>/dev/null >> $failed rm $output fi if [ "$create_mode" = "true" ]; then echo "Test $name ($base)... Created expected output (PE)" elif [ "$rc" = 0 -a "$rc2" = 0 ]; then echo "Test $name ($base)... Passed (PE)"; fi if [ "$test_te" = "true" ]; then ../tengine/ttest -X $output 2> $te_output # if [ "$create_mode" = "true" ]; then if [ "$create_mode" = "true" -a ! -f $te_expected ]; then cp "$te_output" "$te_expected" fi if [ -f $te_expected ]; then diff $diff_opts -q $te_expected $te_output >/dev/null rc=$? fi if [ "$create_mode" = "true" ]; then echo "Test $name ($base)... Created expected output (PE)" elif [ ! -f $te_expected ]; then echo "==== Raw results for TE test ($base) ====" >> $failed cat $te_output 2>/dev/null >> $failed elif [ "$rc" = 0 ]; then echo "Test $name ($base)... Passed (TE)"; elif [ "$rc" = 1 ]; then echo "Test $name ($base)... * Failed (TE)"; diff $diff_opts $te_expected $te_output 2>/dev/null >> $failed diff $diff_opts $te_expected $te_output else echo "Test $name ($base)... Error TE (diff: $rc)"; echo "==== Raw results for test ($base) TE ====" >> $failed cat $te_output 2>/dev/null >> $failed fi fi rm -f $output $te_output } #function do_test { # base=$1; # input=$io_dir/${base}.xml # expected=$io_dir/${base}.exp # te_expected=$io_dir/${base}.te.exp # mv $input $expected $te_expected testcases.saved #} function test_results { if [ -s $failed ]; then if [ "$verbose" = "-v" ]; then echo "Results of $num_failed failed tests...." less $failed else echo "Results of $num_failed failed tests are in $failed...." echo "Use $0 -v to display them automatically." fi else rm $failed fi }