diff --git a/crm/pengine/clone.c b/crm/pengine/clone.c index aeea85a234..4700d21c5f 100644 --- a/crm/pengine/clone.c +++ b/crm/pengine/clone.c @@ -1,1307 +1,1309 @@ /* $Id: clone.c,v 1.6 2006/07/18 06:19:33 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 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; void child_stopping_constraints( clone_variant_data_t *clone_data, enum pe_ordering type, resource_t *child, resource_t *last, pe_working_set_t *data_set); void child_starting_constraints( clone_variant_data_t *clone_data, enum pe_ordering type, resource_t *child, resource_t *last, pe_working_set_t *data_set); #define get_clone_variant_data(data, rsc) \ CRM_ASSERT(rsc->variant == pe_clone || rsc->variant == pe_master); \ data = (clone_variant_data_t *)rsc->variant_opaque; void clone_set_cmds(resource_t *rsc) { clone_variant_data_t *clone_data = NULL; get_clone_variant_data(clone_data, rsc); clone_data->self->cmds = &resource_class_alloc_functions[clone_data->self->variant]; slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, child_rsc->cmds = &resource_class_alloc_functions[child_rsc->variant]; child_rsc->cmds->set_cmds(child_rsc); ); } int clone_num_allowed_nodes(resource_t *rsc) { int num_nodes = 0; clone_variant_data_t *clone_data = NULL; get_clone_variant_data(clone_data, rsc); /* what *should* we return here? */ slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, int tmp_num_nodes = child_rsc->cmds->num_allowed_nodes(child_rsc); if(tmp_num_nodes > num_nodes) { num_nodes = tmp_num_nodes; } ); return num_nodes; } static gint sort_rsc_provisional(gconstpointer a, gconstpointer b) { const resource_t *resource1 = (const resource_t*)a; const resource_t *resource2 = (const resource_t*)b; CRM_ASSERT(resource1 != NULL); CRM_ASSERT(resource2 != NULL); if(resource1->provisional == resource2->provisional) { return 0; } else if(resource1->provisional) { return 1; } else if(resource2->provisional) { return -1; } CRM_CHECK(FALSE, return 0); return 0; } static resource_t * find_clone_child(resource_t *rsc, GListPtr resource_list) { crm_debug("foo"); slist_iter( child, resource_t, resource_list, lpc, if(child->parent) { crm_debug("%p / %p vs. %s / %s", rsc, child->parent, rsc->id, child->parent->id); if(child->parent == rsc) { return child; } } else { crm_debug("Child %s has no parent", child->id); } ); return NULL; } node_t * clone_color(resource_t *rsc, pe_working_set_t *data_set) { int local_node_max = 0; GListPtr node_list = NULL; int reverse_pointer = 0; int allocated = 0, pre_allocated = 0; /* int level = LOG_ERR; */ clone_variant_data_t *clone_data = NULL; get_clone_variant_data(clone_data, rsc); if(clone_data->self->provisional == FALSE) { return NULL; } local_node_max = clone_data->clone_node_max; clone_data->max_nodes = rsc->cmds->num_allowed_nodes(rsc); /* give already allocated resources every chance to run on the node * specified. other resources can be moved/started where we want * as required */ clone_data->child_list = g_list_sort( clone_data->child_list, sort_rsc_provisional); crm_debug_2("Coloring children of: %s", rsc->id); /* rsc->fns->print(rsc, "alloc: ", */ /* pe_print_details|pe_print_dev|pe_print_log, &level); */ clone_data->self->allowed_nodes = g_list_sort( clone_data->self->allowed_nodes, sort_node_weight); if(rsc->stickiness <= 0) { while(local_node_max > 1 && clone_data->max_nodes * (local_node_max -1) >= clone_data->clone_max) { local_node_max--; crm_debug("Dropped the effective value of" " clone_node_max to: %d", local_node_max); } } slist_iter(child, resource_t, clone_data->child_list, lpc2, node_t *current = NULL; node_t *chosen = NULL; if(child->running_on != NULL) { current = child->running_on->data; } if(current == NULL) { crm_debug_2("Not active: %s", child->id); continue; } else if(can_run_resources(current) == FALSE) { crm_debug_2("Node cant run resources: %s", current->details->uname); continue; } else if(g_list_length(child->running_on) != 1) { crm_debug("active != 1: %s", child->id); continue; } chosen = pe_find_node_id( clone_data->self->allowed_nodes, current->details->id); if(chosen == NULL) { /* unmanaged mode */ chosen = current; } if(chosen->count >= local_node_max) { crm_warn("Node %s too full for: %s", chosen->details->uname, child->id); continue; } else if(allocated >= clone_data->clone_max) { crm_debug_2("Reached maximum allocation: %s", child->id); break; } chosen->weight = merge_weights(chosen->weight, child->stickiness); if(native_assign_node(child, NULL, chosen)) { allocated++; } /* native_assign_node(clone_data->self, NULL, current); */ ); crm_debug("Running: Total=%d, New=%d, Max=%d", pre_allocated+allocated, allocated, clone_data->clone_max); if(clone_data->max_nodes) { local_node_max = (int) (clone_data->clone_max / clone_data->max_nodes); if(local_node_max < 1) { local_node_max = 1; } } if(local_node_max > clone_data->clone_node_max) { local_node_max = clone_data->clone_node_max; } pre_allocated = allocated; allocated = 0; if(rsc->stickiness != 0) { clone_data->self->allowed_nodes = g_list_sort( clone_data->self->allowed_nodes, sort_node_weight); } /* distribute a constant spread */ node_list = clone_data->self->allowed_nodes; slist_iter(child, resource_t, clone_data->child_list, lpc2, if(allocated+pre_allocated >= clone_data->clone_max) { break; } if(child->provisional == FALSE) { crm_debug_3("Spread: Skipping allocated resource: %s", child->id); continue; } while(node_list && local_node_max <= ((node_t*)node_list->data)->count) { node_list = node_list->next; } if(node_list) { allocated++; native_assign_node(child, NULL, node_list->data); } ); crm_debug("Spread: Total=%d, New=%d, Max=%d", pre_allocated+allocated, allocated, clone_data->clone_max); CRM_ASSERT(pre_allocated+allocated <= clone_data->clone_max); pre_allocated += allocated; allocated = 0; /* allocate the rest - if possible */ if(local_node_max < clone_data->clone_node_max) { local_node_max++; - node_list = clone_data->self->allowed_nodes; - - slist_iter(child, resource_t, clone_data->child_list, lpc2, - if(child->provisional == FALSE) { - crm_debug_3("Remainder: Skipping allocated resource: %s", child->id); - continue; - } - - if(node_list && (pre_allocated+allocated) >= clone_data->clone_max) { - crm_debug("Allocated maximum possible clone instances"); - node_list = NULL; - } - - while(node_list && local_node_max <= ((node_t*)node_list->data)->count) { - node_list = node_list->next; - } - - if(node_list) { - allocated++; - native_assign_node(child, NULL, node_list->data); + } + + node_list = clone_data->self->allowed_nodes; - } else { - crm_debug("Child %s not allocated", child->id); - native_assign_node(child, NULL, NULL); - } + slist_iter(child, resource_t, clone_data->child_list, lpc2, + if(child->provisional == FALSE) { + crm_debug("Remainder: Skipping allocated resource: %s", child->id); + continue; + } + + crm_debug("Remainder: Processing: %s", child->id); + if(node_list && (pre_allocated+allocated) >= clone_data->clone_max) { + crm_debug("Allocated maximum possible clone instances"); + node_list = NULL; + } + + while(node_list && local_node_max <= ((node_t*)node_list->data)->count) { + node_list = node_list->next; + } + + if(node_list) { + allocated++; + native_assign_node(child, NULL, node_list->data); - ); + } else { + crm_debug("Child %s not allocated", child->id); + native_assign_node(child, NULL, NULL); + } + + ); - crm_debug("Rest: Total=%d, New=%d, Max=%d", pre_allocated, allocated, clone_data->clone_max); - CRM_ASSERT(pre_allocated+allocated <= clone_data->clone_max); - } + crm_debug("Remainder: Total=%d, New=%d, Max=%d", pre_allocated, allocated, clone_data->clone_max); + CRM_ASSERT(pre_allocated+allocated <= clone_data->clone_max); clone_data->self->provisional = FALSE; if(rsc->stickiness >= INFINITY) { return NULL; } /* observe node preferences */ reverse_pointer = g_list_length(clone_data->self->allowed_nodes) - 1; slist_iter(a_node, node_t, clone_data->self->allowed_nodes, lpc, node_t *replace_node = NULL; resource_t *replace_rsc = NULL; CRM_ASSERT(a_node != NULL); if(a_node->count != 0) { crm_debug_4("Node %s has %d resources", a_node->details->uname, a_node->count); break; } else if(lpc >= reverse_pointer) { crm_debug_3("lpc %d, reverse lpc %d", lpc, reverse_pointer); break; } crm_debug_3("Node %s has %d resources, stealing one from...", a_node->details->uname, a_node->count); while(replace_rsc == NULL) { crm_debug_3("lpc %d, reverse lpc %d", lpc, reverse_pointer); if(lpc >= reverse_pointer) { return NULL; } replace_node = g_list_nth_data(clone_data->self->allowed_nodes, reverse_pointer); reverse_pointer--; crm_debug("Trying to reallocated an instance of %s to %s from %s", rsc->id, a_node->details->uname, replace_node->details->uname); replace_rsc = find_clone_child(rsc, replace_node->details->allocated_rsc); if(replace_rsc == NULL) { CRM_ASSERT(replace_node->count == 0); crm_debug("nothing on %s", replace_node->details->uname); } } crm_debug("Reallocating %s to %s from %s", replace_rsc->id, a_node->details->uname, replace_node->details->uname); native_assign_node(replace_rsc, NULL, a_node); ); return NULL; } static void clone_update_pseudo_status( resource_t *child, gboolean *stopping, gboolean *starting) { CRM_ASSERT(stopping != NULL); CRM_ASSERT(starting != NULL); slist_iter( action, action_t, child->actions, lpc, if(*starting && *stopping) { return; } else if(action->optional) { crm_debug_3("Skipping optional: %s", action->uuid); continue; } else if(action->pseudo == FALSE && action->runnable == FALSE){ crm_debug_3("Skipping unrunnable: %s", action->uuid); continue; } else if(safe_str_eq(CRMD_ACTION_STOP, action->task)) { crm_debug_2("Stopping due to: %s", action->uuid); *stopping = TRUE; } else if(safe_str_eq(CRMD_ACTION_START, action->task)) { if(action->runnable == FALSE) { crm_debug_3("Skipping pseduo-op: %s run=%d, pseudo=%d", action->uuid, action->runnable, action->pseudo); } else { crm_debug_2("Starting due to: %s", action->uuid); crm_debug_3("%s run=%d, pseudo=%d", action->uuid, action->runnable, action->pseudo); *starting = TRUE; } } ); } void clone_create_actions(resource_t *rsc, pe_working_set_t *data_set) { gboolean child_starting = FALSE; gboolean child_stopping = FALSE; action_t *stop = NULL; action_t *start = NULL; action_t *action_complete = NULL; resource_t *last_start_rsc = NULL; resource_t *last_stop_rsc = NULL; clone_variant_data_t *clone_data = NULL; get_clone_variant_data(clone_data, rsc); slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, child_rsc->cmds->create_actions(child_rsc, data_set); clone_update_pseudo_status( child_rsc, &child_stopping, &child_starting); if(child_rsc->starting) { last_start_rsc = child_rsc; } if(child_rsc->stopping) { last_stop_rsc = child_rsc; } ); /* start */ start = start_action(clone_data->self, NULL, !child_starting); action_complete = custom_action( clone_data->self, started_key(rsc), CRMD_ACTION_STARTED, NULL, !child_starting, TRUE, data_set); start->pseudo = TRUE; action_complete->pseudo = TRUE; action_complete->priority = INFINITY; child_starting_constraints(clone_data, pe_ordering_optional, NULL, last_start_rsc, data_set); clone_create_notifications( rsc, start, action_complete, data_set); /* stop */ stop = stop_action(clone_data->self, NULL, !child_stopping); action_complete = custom_action( clone_data->self, stopped_key(rsc), CRMD_ACTION_STOPPED, NULL, !child_stopping, TRUE, data_set); stop->pseudo = TRUE; action_complete->pseudo = TRUE; action_complete->priority = INFINITY; child_stopping_constraints(clone_data, pe_ordering_optional, NULL, last_stop_rsc, data_set); clone_create_notifications(rsc, stop, action_complete, data_set); rsc->actions = clone_data->self->actions; if(stop->post_notified != NULL && start->pre_notify != NULL) { order_actions(stop->post_notified, start->pre_notify, pe_ordering_optional); } } void clone_create_notifications( resource_t *rsc, action_t *action, action_t *action_complete, pe_working_set_t *data_set) { /* * pre_notify -> pre_notify_complete -> pseudo_action * -> (real actions) -> pseudo_action_complete * -> post_notify -> post_notify_complete * * if the pre_noitfy requires confirmation, * then a list of confirmations will be added as triggers * to pseudo_action in clone_expand() */ action_t *notify = NULL; action_t *notify_complete = NULL; enum action_tasks task; char *notify_key = NULL; clone_variant_data_t *clone_data = NULL; get_clone_variant_data(clone_data, rsc); if(rsc->notify == FALSE) { return; } task = text2task(action->task); /* create pre_notify */ notify_key = generate_notify_key( clone_data->self->id, "pre", action->task); notify = custom_action(clone_data->self, notify_key, CRMD_ACTION_NOTIFY, NULL, action->optional, TRUE, data_set); add_hash_param(notify->meta, "notify_type", "pre"); add_hash_param(notify->meta, "notify_operation", action->task); if(clone_data->notify_confirm) { add_hash_param(notify->meta, "notify_confirm", "yes"); } else { add_hash_param(notify->meta, "notify_confirm", "no"); } notify->pseudo = TRUE; /* create pre_notify_complete */ notify_key = generate_notify_key( clone_data->self->id, "confirmed-pre", action->task); notify_complete = custom_action(clone_data->self, notify_key, CRMD_ACTION_NOTIFIED, NULL, action->optional, TRUE, data_set); add_hash_param(notify_complete->meta, "notify_type", "pre"); add_hash_param(notify_complete->meta, "notify_operation", action->task); if(clone_data->notify_confirm) { add_hash_param(notify->meta, "notify_confirm", "yes"); } else { add_hash_param(notify->meta, "notify_confirm", "no"); } notify->pseudo = TRUE; notify_complete->pseudo = TRUE; /* pre_notify before pre_notify_complete */ custom_action_order( clone_data->self, NULL, notify, clone_data->self, NULL, notify_complete, pe_ordering_manditory, data_set); /* pre_notify_complete before action */ custom_action_order( clone_data->self, NULL, notify_complete, clone_data->self, NULL, action, pe_ordering_manditory, data_set); action->pre_notify = notify; action->pre_notified = notify_complete; /* create post_notify */ notify_key = generate_notify_key (clone_data->self->id, "post", action->task); notify = custom_action(clone_data->self, notify_key, CRMD_ACTION_NOTIFY, NULL, action_complete->optional, TRUE, data_set); add_hash_param(notify->meta, "notify_type", "post"); add_hash_param(notify->meta, "notify_operation", action->task); if(clone_data->notify_confirm) { add_hash_param(notify->meta, "notify_confirm", "yes"); } else { add_hash_param(notify->meta, "notify_confirm", "no"); } notify->pseudo = TRUE; /* action_complete before post_notify */ custom_action_order( clone_data->self, NULL, action_complete, clone_data->self, NULL, notify, pe_ordering_postnotify, data_set); /* create post_notify_complete */ notify_key = generate_notify_key( clone_data->self->id, "confirmed-post", action->task); notify_complete = custom_action(clone_data->self, notify_key, CRMD_ACTION_NOTIFIED, NULL, action->optional, TRUE, data_set); add_hash_param(notify_complete->meta, "notify_type", "pre"); add_hash_param(notify_complete->meta, "notify_operation", action->task); if(clone_data->notify_confirm) { add_hash_param(notify->meta, "notify_confirm", "yes"); } else { add_hash_param(notify->meta, "notify_confirm", "no"); } notify_complete->pseudo = TRUE; /* post_notify before post_notify_complete */ custom_action_order( clone_data->self, NULL, notify, clone_data->self, NULL, notify_complete, pe_ordering_manditory, data_set); action->post_notify = notify; action->post_notified = notify_complete; if(safe_str_eq(action->task, CRMD_ACTION_STOP)) { /* post_notify_complete before start */ custom_action_order( clone_data->self, NULL, notify_complete, clone_data->self, start_key(clone_data->self), NULL, pe_ordering_optional, data_set); } else if(safe_str_eq(action->task, CRMD_ACTION_START)) { /* post_notify_complete before promote */ custom_action_order( clone_data->self, NULL, notify_complete, clone_data->self, promote_key(clone_data->self), NULL, pe_ordering_optional, data_set); } else if(safe_str_eq(action->task, CRMD_ACTION_DEMOTE)) { /* post_notify_complete before promote */ custom_action_order( clone_data->self, NULL, notify_complete, clone_data->self, stop_key(clone_data->self), NULL, pe_ordering_optional, data_set); } } void child_starting_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 start before global started */ custom_action_order( last, start_key(last), NULL, clone_data->self, started_key(clone_data->self), NULL, type, data_set); } } else if(clone_data->ordered) { crm_debug_4("Ordered version"); if(last == NULL) { /* global start before first child start */ last = clone_data->self; } /* else: child/child relative start */ order_start_start(last, child, type); } else { crm_debug_4("Un-ordered version"); /* child start before global started */ custom_action_order( child, start_key(child), NULL, clone_data->self, started_key(clone_data->self), NULL, type, data_set); /* global start before child start */ /* order_start_start(clone_data->self, child, type); */ order_start_start( clone_data->self, child, pe_ordering_manditory); } } void child_stopping_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 stop before first child stop */ order_stop_stop(clone_data->self, last, pe_ordering_manditory); } } else if(clone_data->ordered && last != NULL) { crm_debug_4("Ordered version"); /* child/child relative stop */ order_stop_stop(child, last, type); } else if(clone_data->ordered) { crm_debug_4("Ordered version (1st node)"); /* first child stop before global stopped */ custom_action_order( child, stop_key(child), NULL, clone_data->self, stopped_key(clone_data->self), NULL, type, data_set); } else { crm_debug_4("Un-ordered version"); /* child stop before global stopped */ custom_action_order( child, stop_key(child), NULL, clone_data->self, stopped_key(clone_data->self), NULL, type, data_set); /* global stop before child stop */ order_stop_stop(clone_data->self, child, type); } } void clone_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_data->self->cmds->internal_constraints(clone_data->self, data_set); /* global stop before stopped */ custom_action_order( clone_data->self, stop_key(clone_data->self), NULL, clone_data->self, stopped_key(clone_data->self), NULL, pe_ordering_optional, data_set); /* global start before started */ custom_action_order( clone_data->self, start_key(clone_data->self), NULL, clone_data->self, started_key(clone_data->self), NULL, pe_ordering_optional, data_set); /* global stopped before start */ custom_action_order( clone_data->self, stopped_key(clone_data->self), NULL, clone_data->self, start_key(clone_data->self), NULL, pe_ordering_optional, data_set); slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, child_rsc->cmds->internal_constraints(child_rsc, data_set); child_starting_constraints( clone_data, pe_ordering_optional, child_rsc, last_rsc, data_set); child_stopping_constraints( clone_data, pe_ordering_optional, child_rsc, last_rsc, data_set); last_rsc = child_rsc; ); child_starting_constraints( clone_data, pe_ordering_optional, NULL, last_rsc, data_set); child_stopping_constraints( clone_data, pe_ordering_optional, NULL, last_rsc, data_set); } static resource_t* find_compatible_child(resource_t *local_child, resource_t *rsc) { node_t *local_node = NULL; node_t *node = NULL; clone_variant_data_t *clone_data = NULL; get_clone_variant_data(clone_data, rsc); local_node = local_child->allocated_to; if(local_node == NULL) { crm_debug("Can't colocate unrunnable child %s with %s", local_child->id, rsc->id); return NULL; } slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, node = child_rsc->allocated_to; if(node->details == local_node->details) { crm_info("Colocating %s with %s on %s", local_child->id, child_rsc->id, node->details->uname); return child_rsc; } ); crm_debug("Can't colocate child %s with %s", local_child->id, rsc->id); return NULL; } void clone_rsc_colocation_lh( resource_t *rsc_lh, resource_t *rsc_rh, rsc_colocation_t *constraint) { gboolean do_interleave = FALSE; resource_t *rsc = constraint->rsc_lh; clone_variant_data_t *clone_data = NULL; clone_variant_data_t *clone_data_rh = NULL; if(rsc == NULL) { pe_err("rsc_lh was NULL for %s", constraint->id); return; } else if(constraint->rsc_rh == NULL) { pe_err("rsc_rh was NULL for %s", constraint->id); return; } else { crm_debug_4("Processing constraints from %s", rsc->id); } get_clone_variant_data(clone_data, rsc); if(constraint->rsc_rh->variant == pe_clone) { get_clone_variant_data( clone_data_rh, constraint->rsc_rh); if(clone_data->clone_node_max != clone_data_rh->clone_node_max) { pe_err("Cannot interleave "XML_CIB_TAG_INCARNATION " %s and %s because" " they do not support the same number of" " resources per node", constraint->rsc_lh->id, constraint->rsc_rh->id); /* only the LHS side needs to be labeled as interleave */ } else if(clone_data->interleave) { do_interleave = TRUE; } else if(constraint->score != INFINITY) { pe_warn("rsc_colocations other than \"-INFINITY\"" " are not supported for non-interleaved " XML_CIB_TAG_INCARNATION" resources"); return; } } else if(constraint->score != -INFINITY) { pe_warn("Co-location scores other than \"-INFINITY\" are not " " allowed for non-"XML_CIB_TAG_INCARNATION" resources"); return; } if(do_interleave) { resource_t *rh_child = NULL; slist_iter(lh_child, resource_t, clone_data->child_list, lpc, CRM_ASSERT(lh_child != NULL); rh_child = find_compatible_child(lh_child, rsc_rh); if(rh_child == NULL) { continue; } lh_child->cmds->rsc_colocation_lh( lh_child, rh_child, constraint); ); return; } slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, child_rsc->cmds->rsc_colocation_lh(child_rsc, constraint->rsc_rh, constraint); ); } void clone_rsc_colocation_rh( resource_t *rsc_lh, resource_t *rsc_rh, rsc_colocation_t *constraint) { clone_variant_data_t *clone_data = NULL; CRM_CHECK(rsc_lh != NULL, return); CRM_CHECK(rsc_lh->variant == pe_native, return); crm_debug_3("Processing RH of constraint %s", constraint->id); if(rsc_rh == NULL) { pe_err("rsc_rh was NULL for %s", constraint->id); return; } else if(constraint->score != -INFINITY) { pe_warn("rsc_dependencies other than \"must_not\" " "are not supported for clone resources"); return; } else { print_resource(LOG_DEBUG_3, "LHS", rsc_lh, FALSE); } get_clone_variant_data(clone_data, rsc_rh); slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, print_resource(LOG_DEBUG_3, "RHS", child_rsc, FALSE); child_rsc->cmds->rsc_colocation_rh(rsc_lh, child_rsc, constraint); ); } void clone_rsc_order_lh(resource_t *rsc, order_constraint_t *order) { char *stop_id = NULL; char *start_id = NULL; clone_variant_data_t *clone_data = NULL; get_clone_variant_data(clone_data, rsc); crm_debug_3("Processing LH of ordering constraint %d", order->id); stop_id = stop_key(rsc); start_id = start_key(rsc); if(safe_str_eq(order->lh_action_task, start_id)) { crm_free(order->lh_action_task); order->lh_action_task = started_key(rsc); } else if(safe_str_eq(order->lh_action_task, stop_id)) { crm_free(order->lh_action_task); order->lh_action_task = stopped_key(rsc); } crm_free(start_id); crm_free(stop_id); clone_data->self->cmds->rsc_order_lh(clone_data->self, order); } void clone_rsc_order_rh( action_t *lh_action, resource_t *rsc, order_constraint_t *order) { clone_variant_data_t *clone_data = NULL; get_clone_variant_data(clone_data, rsc); crm_debug_3("Processing RH of ordering constraint %d", order->id); clone_data->self->cmds->rsc_order_rh(lh_action, clone_data->self, order); } void clone_rsc_location(resource_t *rsc, rsc_to_node_t *constraint) { clone_variant_data_t *clone_data = NULL; get_clone_variant_data(clone_data, rsc); crm_debug_3("Processing location constraint %s for %s", constraint->id, rsc->id); clone_data->self->cmds->rsc_location(clone_data->self, constraint); slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, child_rsc->cmds->rsc_location(child_rsc, constraint); ); } static gint sort_notify_entries(gconstpointer a, gconstpointer b) { int tmp; const notify_entry_t *entry_a = a; const notify_entry_t *entry_b = b; if(entry_a == NULL && entry_b == NULL) { return 0; } if(entry_a == NULL) { return 1; } if(entry_b == NULL) { return -1; } if(entry_a->rsc == NULL && entry_b->rsc == NULL) { return 0; } if(entry_a->rsc == NULL) { return 1; } if(entry_b->rsc == NULL) { return -1; } tmp = strcmp(entry_a->rsc->id, entry_b->rsc->id); if(tmp != 0) { return tmp; } if(entry_a->node == NULL && entry_b->node == NULL) { return 0; } if(entry_a->node == NULL) { return 1; } if(entry_b->node == NULL) { return -1; } return strcmp(entry_a->node->details->id, entry_b->node->details->id); } static void expand_list(GListPtr list, int clones, char **rsc_list, char **node_list, char **uuid_list) { const char *uname = NULL; const char *rsc_id = NULL; const char *last_rsc_id = NULL; CRM_CHECK(list != NULL, return); if(rsc_list) { CRM_CHECK(*rsc_list == NULL, *rsc_list = NULL); } if(node_list) { CRM_CHECK(*node_list == NULL, *node_list = NULL); } slist_iter(entry, notify_entry_t, list, lpc, CRM_CHECK(entry != NULL, continue); rsc_id = entry->rsc->id; CRM_CHECK(rsc_id != NULL, rsc_id = "__none__"); uname = NULL; if(entry->node) { uname = entry->node->details->uname; } CRM_CHECK(uname != NULL, uname = "__none__"); /* filter dups */ if(safe_str_eq(rsc_id, last_rsc_id)) { continue; } last_rsc_id = rsc_id; if(rsc_list != NULL) { int existing_len = 0; int len = 2 + strlen(rsc_id); /* +1 space, +1 EOS */ if(rsc_list && *rsc_list) { existing_len = strlen(*rsc_list); } crm_debug_5("Adding %s (%dc) at offset %d", rsc_id, len-2, existing_len); crm_realloc(*rsc_list, len + existing_len); sprintf(*rsc_list + existing_len, "%s ", rsc_id); } if(node_list != NULL) { int existing_len = 0; int len = 2 + strlen(uname); if(node_list && *node_list) { existing_len = strlen(*node_list); } crm_debug_5("Adding %s (%dc) at offset %d", uname, len-2, existing_len); crm_realloc(*node_list, len + existing_len); sprintf(*node_list + existing_len, "%s ", uname); } ); } void clone_expand(resource_t *rsc, pe_working_set_t *data_set) { char *rsc_list = NULL; char *node_list = NULL; char *uuid_list = NULL; notify_data_t *n_data = NULL; clone_variant_data_t *clone_data = NULL; get_clone_variant_data(clone_data, rsc); crm_malloc0(n_data, sizeof(notify_data_t)); n_data->keys = g_hash_table_new_full( g_str_hash, g_str_equal, g_hash_destroy_str, g_hash_destroy_str); crm_debug_2("Processing actions from %s", rsc->id); if(rsc->notify) { slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, slist_iter( op, action_t, clone_data->self->actions, lpc2, child_rsc->cmds->create_notify_element( child_rsc, op, n_data, data_set); ); ); } /* expand the notify data */ if(rsc->notify && n_data->stop) { n_data->stop = g_list_sort( n_data->stop, sort_notify_entries); rsc_list = NULL; node_list = NULL; expand_list(n_data->stop, clone_data->clone_max, &rsc_list, &node_list, &uuid_list); g_hash_table_insert( n_data->keys, crm_strdup("notify_stop_resource"), rsc_list); g_hash_table_insert( n_data->keys, crm_strdup("notify_stop_uname"), node_list); } if(rsc->notify && n_data->start) { n_data->start = g_list_sort( n_data->start, sort_notify_entries); rsc_list = NULL; node_list = NULL; expand_list(n_data->start, clone_data->clone_max, &rsc_list, &node_list, &uuid_list); g_hash_table_insert( n_data->keys, crm_strdup("notify_start_resource"), rsc_list); g_hash_table_insert( n_data->keys, crm_strdup("notify_start_uname"), node_list); } if(rsc->notify && n_data->demote) { n_data->demote = g_list_sort( n_data->demote, sort_notify_entries); rsc_list = NULL; node_list = NULL; expand_list(n_data->demote, clone_data->clone_max, &rsc_list, &node_list, &uuid_list); g_hash_table_insert( n_data->keys, crm_strdup("notify_demote_resource"), rsc_list); g_hash_table_insert( n_data->keys, crm_strdup("notify_demote_uname"), node_list); } if(rsc->notify && n_data->promote) { n_data->promote = g_list_sort( n_data->promote, sort_notify_entries); rsc_list = NULL; node_list = NULL; uuid_list = NULL; expand_list(n_data->promote, clone_data->clone_max, &rsc_list, &node_list, &uuid_list); g_hash_table_insert( n_data->keys, crm_strdup("notify_promote_resource"), rsc_list); g_hash_table_insert( n_data->keys, crm_strdup("notify_promote_uname"), node_list); } if(rsc->notify && n_data->active) { n_data->active = g_list_sort( n_data->active, sort_notify_entries); rsc_list = NULL; node_list = NULL; uuid_list = NULL; expand_list(n_data->active, clone_data->clone_max, &rsc_list, &node_list, &uuid_list); g_hash_table_insert( n_data->keys, crm_strdup("notify_active_resource"), rsc_list); g_hash_table_insert( n_data->keys, crm_strdup("notify_active_uname"), node_list); } if(rsc->notify && n_data->slave) { n_data->slave = g_list_sort( n_data->slave, sort_notify_entries); rsc_list = NULL; node_list = NULL; uuid_list = NULL; expand_list(n_data->slave, clone_data->clone_max, &rsc_list, &node_list, &uuid_list); g_hash_table_insert( n_data->keys, crm_strdup("notify_slave_resource"), rsc_list); g_hash_table_insert( n_data->keys, crm_strdup("notify_slave_uname"), node_list); } if(rsc->notify && n_data->master) { n_data->master = g_list_sort( n_data->master, sort_notify_entries); rsc_list = NULL; node_list = NULL; uuid_list = NULL; expand_list(n_data->master, clone_data->clone_max, &rsc_list, &node_list, &uuid_list); g_hash_table_insert( n_data->keys, crm_strdup("notify_master_resource"), rsc_list); g_hash_table_insert( n_data->keys, crm_strdup("notify_master_uname"), node_list); } if(rsc->notify && n_data->inactive) { n_data->inactive = g_list_sort( n_data->inactive, sort_notify_entries); rsc_list = NULL; node_list = NULL; uuid_list = NULL; expand_list(n_data->inactive, clone_data->clone_max, &rsc_list, &node_list, &uuid_list); g_hash_table_insert( n_data->keys, crm_strdup("notify_inactive_resource"), rsc_list); g_hash_table_insert( n_data->keys, crm_strdup("notify_inactive_uname"), node_list); } /* yes, we DO need this second loop */ slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, child_rsc->cmds->expand(child_rsc, data_set); ); /* slist_iter( */ /* action, action_t, clone_data->self->actions, lpc2, */ /* if(safe_str_eq(action->task, CRMD_ACTION_NOTIFY)) { */ /* action->meta_xml = notify_xml; */ /* } */ /* ); */ clone_data->self->cmds->expand(clone_data->self, data_set); /* destroy the notify_data */ pe_free_shallow(n_data->stop); pe_free_shallow(n_data->start); pe_free_shallow(n_data->demote); pe_free_shallow(n_data->promote); pe_free_shallow(n_data->master); pe_free_shallow(n_data->slave); pe_free_shallow(n_data->active); pe_free_shallow(n_data->inactive); g_hash_table_destroy(n_data->keys); crm_free(n_data); } void clone_agent_constraints(resource_t *rsc) { clone_variant_data_t *clone_data = NULL; get_clone_variant_data(clone_data, rsc); slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, child_rsc->cmds->agent_constraints(child_rsc); ); } void clone_create_notify_element(resource_t *rsc, action_t *op, notify_data_t *n_data, pe_working_set_t *data_set) { clone_variant_data_t *clone_data = NULL; get_clone_variant_data(clone_data, rsc); slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, child_rsc->cmds->create_notify_element( child_rsc, op, n_data, data_set); ); } static gint sort_rsc_id(gconstpointer a, gconstpointer b) { const resource_t *resource1 = (const resource_t*)a; const resource_t *resource2 = (const resource_t*)b; CRM_ASSERT(resource1 != NULL); CRM_ASSERT(resource2 != NULL); return strcmp(resource1->id, resource2->id); } gboolean clone_create_probe(resource_t *rsc, node_t *node, action_t *complete, gboolean force, pe_working_set_t *data_set) { gboolean any_created = FALSE; clone_variant_data_t *clone_data = NULL; get_clone_variant_data(clone_data, rsc); clone_data->child_list = g_list_sort( clone_data->child_list, sort_rsc_id); if(rsc->globally_unique == FALSE && clone_data->clone_node_max == 1) { /* only look for one copy */ slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, if(pe_find_node_id(child_rsc->running_on, node->details->id)) { return child_rsc->cmds->create_probe( child_rsc, node, complete, force, data_set); } ); } slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, if(child_rsc->cmds->create_probe( child_rsc, node, complete, force, data_set)) { any_created = TRUE; } if(any_created && rsc->globally_unique == FALSE && clone_data->clone_node_max == 1) { /* only look for one copy (clone :0) */ break; } ); return any_created; } void clone_stonith_ordering( resource_t *rsc, action_t *stonith_op, pe_working_set_t *data_set) { clone_variant_data_t *clone_data = NULL; get_clone_variant_data(clone_data, rsc); slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, child_rsc->cmds->stonith_ordering( child_rsc, stonith_op, data_set); ); } diff --git a/crm/pengine/testcases/inc0.exp b/crm/pengine/testcases/inc0.exp index b6842beffb..75474a74de 100644 --- a/crm/pengine/testcases/inc0.exp +++ b/crm/pengine/testcases/inc0.exp @@ -1,244 +1,244 @@ - + - + - + - + - + - + - + diff --git a/crm/pengine/testcases/inc1.exp b/crm/pengine/testcases/inc1.exp index 37ef789645..c4821bd7f9 100644 --- a/crm/pengine/testcases/inc1.exp +++ b/crm/pengine/testcases/inc1.exp @@ -1,324 +1,324 @@ - + - + - + - + - + - + - + - + - + diff --git a/crm/pengine/testcases/inc2.exp b/crm/pengine/testcases/inc2.exp index 8f60d957d1..bbea720215 100644 --- a/crm/pengine/testcases/inc2.exp +++ b/crm/pengine/testcases/inc2.exp @@ -1,220 +1,220 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/crm/pengine/testcases/inc3.exp b/crm/pengine/testcases/inc3.exp index 25fe1634e4..64af950353 100644 --- a/crm/pengine/testcases/inc3.exp +++ b/crm/pengine/testcases/inc3.exp @@ -1,419 +1,419 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/crm/pengine/testcases/inc7.dot b/crm/pengine/testcases/inc7.dot index 43bad9b793..53ef20080a 100644 --- a/crm/pengine/testcases/inc7.dot +++ b/crm/pengine/testcases/inc7.dot @@ -1,117 +1,117 @@ digraph "g" { size = "30,30" "probe_complete" [ style=bold color="green" fontcolor="orange" ] "probe_complete node1" [ style=bold color="green" fontcolor="black" ] "rsc0_monitor_0 node1" [ style=bold color="green" fontcolor="black" ] "child_rsc1:0_monitor_0 node1" [ style=bold color="green" fontcolor="black" ] "child_rsc1:1_monitor_0 node1" [ style=bold color="green" fontcolor="black" ] "child_rsc1:2_monitor_0 node1" [ style=bold color="green" fontcolor="black" ] "child_rsc1:3_monitor_0 node1" [ style=bold color="green" fontcolor="black" ] "child_rsc1:4_monitor_0 node1" [ style=bold color="green" fontcolor="black" ] "child_rsc2:0_monitor_0 node1" [ style=bold color="green" fontcolor="black" ] "child_rsc2:1_monitor_0 node1" [ style=bold color="green" fontcolor="black" ] "child_rsc2:2_monitor_0 node1" [ style=bold color="green" fontcolor="black" ] "child_rsc2:3_monitor_0 node1" [ style=bold color="green" fontcolor="black" ] "child_rsc2:4_monitor_0 node1" [ style=bold color="green" fontcolor="black" ] "probe_complete node2" [ style=bold color="green" fontcolor="black" ] "rsc0_monitor_0 node2" [ style=bold color="green" fontcolor="black" ] "child_rsc1:0_monitor_0 node2" [ style=bold color="green" fontcolor="black" ] "child_rsc1:1_monitor_0 node2" [ style=bold color="green" fontcolor="black" ] "child_rsc1:2_monitor_0 node2" [ style=bold color="green" fontcolor="black" ] "child_rsc1:3_monitor_0 node2" [ style=bold color="green" fontcolor="black" ] "child_rsc1:4_monitor_0 node2" [ style=bold color="green" fontcolor="black" ] "child_rsc2:0_monitor_0 node2" [ style=bold color="green" fontcolor="black" ] "child_rsc2:1_monitor_0 node2" [ style=bold color="green" fontcolor="black" ] "child_rsc2:2_monitor_0 node2" [ style=bold color="green" fontcolor="black" ] "child_rsc2:3_monitor_0 node2" [ style=bold color="green" fontcolor="black" ] "child_rsc2:4_monitor_0 node2" [ style=bold color="green" fontcolor="black" ] "probe_complete node3" [ style=bold color="green" fontcolor="black" ] "rsc0_monitor_0 node3" [ style=bold color="green" fontcolor="black" ] "child_rsc1:0_monitor_0 node3" [ style=bold color="green" fontcolor="black" ] "child_rsc1:1_monitor_0 node3" [ style=bold color="green" fontcolor="black" ] "child_rsc1:2_monitor_0 node3" [ style=bold color="green" fontcolor="black" ] "child_rsc1:3_monitor_0 node3" [ style=bold color="green" fontcolor="black" ] "child_rsc1:4_monitor_0 node3" [ style=bold color="green" fontcolor="black" ] "child_rsc2:0_monitor_0 node3" [ style=bold color="green" fontcolor="black" ] "child_rsc2:1_monitor_0 node3" [ style=bold color="green" fontcolor="black" ] "child_rsc2:2_monitor_0 node3" [ style=bold color="green" fontcolor="black" ] "child_rsc2:3_monitor_0 node3" [ style=bold color="green" fontcolor="black" ] "child_rsc2:4_monitor_0 node3" [ style=bold color="green" fontcolor="black" ] "rsc0_start_0 node1" [ style=bold color="green" fontcolor="black" ] -"child_rsc1:0_start_0 node1" [ style=bold color="green" fontcolor="black" ] -"child_rsc1:1_start_0 node2" [ style=bold color="green" fontcolor="black" ] -"child_rsc1:2_start_0 node3" [ style=bold color="green" fontcolor="black" ] -"child_rsc1:3_start_0 node1" [ style=bold color="green" fontcolor="black" ] -"child_rsc1:4_start_0 node2" [ style=bold color="green" fontcolor="black" ] +"child_rsc1:0_start_0 node2" [ style=bold color="green" fontcolor="black" ] +"child_rsc1:1_start_0 node3" [ style=bold color="green" fontcolor="black" ] +"child_rsc1:2_start_0 node1" [ style=bold color="green" fontcolor="black" ] +"child_rsc1:3_start_0 node2" [ style=bold color="green" fontcolor="black" ] +"child_rsc1:4_start_0 node3" [ style=bold color="green" fontcolor="black" ] "rsc1_start_0" [ style=bold color="green" fontcolor="orange" ] "rsc1_running_0" [ style=bold color="green" fontcolor="orange" ] "child_rsc2:0_start_0 node1" [ style=bold color="green" fontcolor="black" ] "child_rsc2:1_start_0 node2" [ style=bold color="green" fontcolor="black" ] "child_rsc2:2_start_0 node3" [ style=bold color="green" fontcolor="black" ] "child_rsc2:3_start_0 node1" [ style=bold color="green" fontcolor="black" ] "child_rsc2:4_start_0 node2" [ style=bold color="green" fontcolor="black" ] "rsc2_start_0" [ style=bold color="green" fontcolor="orange" ] "rsc2_running_0" [ style=bold color="green" fontcolor="orange" ] "probe_complete node1" -> "probe_complete" [ style = bold] "probe_complete node2" -> "probe_complete" [ style = bold] "probe_complete node3" -> "probe_complete" [ style = bold] "rsc0_monitor_0 node1" -> "probe_complete node1" [ style = bold] "child_rsc1:0_monitor_0 node1" -> "probe_complete node1" [ style = bold] "child_rsc1:1_monitor_0 node1" -> "probe_complete node1" [ style = bold] "child_rsc1:2_monitor_0 node1" -> "probe_complete node1" [ style = bold] "child_rsc1:3_monitor_0 node1" -> "probe_complete node1" [ style = bold] "child_rsc1:4_monitor_0 node1" -> "probe_complete node1" [ style = bold] "child_rsc2:0_monitor_0 node1" -> "probe_complete node1" [ style = bold] "child_rsc2:1_monitor_0 node1" -> "probe_complete node1" [ style = bold] "child_rsc2:2_monitor_0 node1" -> "probe_complete node1" [ style = bold] "child_rsc2:3_monitor_0 node1" -> "probe_complete node1" [ style = bold] "child_rsc2:4_monitor_0 node1" -> "probe_complete node1" [ style = bold] "rsc0_monitor_0 node2" -> "probe_complete node2" [ style = bold] "child_rsc1:0_monitor_0 node2" -> "probe_complete node2" [ style = bold] "child_rsc1:1_monitor_0 node2" -> "probe_complete node2" [ style = bold] "child_rsc1:2_monitor_0 node2" -> "probe_complete node2" [ style = bold] "child_rsc1:3_monitor_0 node2" -> "probe_complete node2" [ style = bold] "child_rsc1:4_monitor_0 node2" -> "probe_complete node2" [ style = bold] "child_rsc2:0_monitor_0 node2" -> "probe_complete node2" [ style = bold] "child_rsc2:1_monitor_0 node2" -> "probe_complete node2" [ style = bold] "child_rsc2:2_monitor_0 node2" -> "probe_complete node2" [ style = bold] "child_rsc2:3_monitor_0 node2" -> "probe_complete node2" [ style = bold] "child_rsc2:4_monitor_0 node2" -> "probe_complete node2" [ style = bold] "rsc0_monitor_0 node3" -> "probe_complete node3" [ style = bold] "child_rsc1:0_monitor_0 node3" -> "probe_complete node3" [ style = bold] "child_rsc1:1_monitor_0 node3" -> "probe_complete node3" [ style = bold] "child_rsc1:2_monitor_0 node3" -> "probe_complete node3" [ style = bold] "child_rsc1:3_monitor_0 node3" -> "probe_complete node3" [ style = bold] "child_rsc1:4_monitor_0 node3" -> "probe_complete node3" [ style = bold] "child_rsc2:0_monitor_0 node3" -> "probe_complete node3" [ style = bold] "child_rsc2:1_monitor_0 node3" -> "probe_complete node3" [ style = bold] "child_rsc2:2_monitor_0 node3" -> "probe_complete node3" [ style = bold] "child_rsc2:3_monitor_0 node3" -> "probe_complete node3" [ style = bold] "child_rsc2:4_monitor_0 node3" -> "probe_complete node3" [ style = bold] "probe_complete" -> "rsc0_start_0 node1" [ style = bold] -"rsc1_start_0" -> "child_rsc1:0_start_0 node1" [ style = bold] -"rsc1_start_0" -> "child_rsc1:1_start_0 node2" [ style = bold] -"rsc1_start_0" -> "child_rsc1:2_start_0 node3" [ style = bold] -"rsc1_start_0" -> "child_rsc1:3_start_0 node1" [ style = bold] -"rsc1_start_0" -> "child_rsc1:4_start_0 node2" [ style = bold] +"rsc1_start_0" -> "child_rsc1:0_start_0 node2" [ style = bold] +"rsc1_start_0" -> "child_rsc1:1_start_0 node3" [ style = bold] +"rsc1_start_0" -> "child_rsc1:2_start_0 node1" [ style = bold] +"rsc1_start_0" -> "child_rsc1:3_start_0 node2" [ style = bold] +"rsc1_start_0" -> "child_rsc1:4_start_0 node3" [ style = bold] "probe_complete" -> "rsc1_start_0" [ style = bold] -"child_rsc1:0_start_0 node1" -> "rsc1_running_0" [ style = bold] -"child_rsc1:1_start_0 node2" -> "rsc1_running_0" [ style = bold] -"child_rsc1:2_start_0 node3" -> "rsc1_running_0" [ style = bold] -"child_rsc1:3_start_0 node1" -> "rsc1_running_0" [ style = bold] -"child_rsc1:4_start_0 node2" -> "rsc1_running_0" [ style = bold] +"child_rsc1:0_start_0 node2" -> "rsc1_running_0" [ style = bold] +"child_rsc1:1_start_0 node3" -> "rsc1_running_0" [ style = bold] +"child_rsc1:2_start_0 node1" -> "rsc1_running_0" [ style = bold] +"child_rsc1:3_start_0 node2" -> "rsc1_running_0" [ style = bold] +"child_rsc1:4_start_0 node3" -> "rsc1_running_0" [ style = bold] "rsc1_start_0" -> "rsc1_running_0" [ style = bold] "rsc2_start_0" -> "child_rsc2:0_start_0 node1" [ style = bold] "rsc2_start_0" -> "child_rsc2:1_start_0 node2" [ style = bold] "rsc2_start_0" -> "child_rsc2:2_start_0 node3" [ style = bold] "rsc2_start_0" -> "child_rsc2:3_start_0 node1" [ style = bold] "rsc2_start_0" -> "child_rsc2:4_start_0 node2" [ style = bold] "probe_complete" -> "rsc2_start_0" [ style = bold] "rsc1_running_0" -> "rsc2_start_0" [ style = bold] "child_rsc2:0_start_0 node1" -> "rsc2_running_0" [ style = bold] "child_rsc2:1_start_0 node2" -> "rsc2_running_0" [ style = bold] "child_rsc2:2_start_0 node3" -> "rsc2_running_0" [ style = bold] "child_rsc2:3_start_0 node1" -> "rsc2_running_0" [ style = bold] "child_rsc2:4_start_0 node2" -> "rsc2_running_0" [ style = bold] "rsc2_start_0" -> "rsc2_running_0" [ style = bold] } diff --git a/crm/pengine/testcases/inc7.exp b/crm/pengine/testcases/inc7.exp index aec9569f16..1724842295 100644 --- a/crm/pengine/testcases/inc7.exp +++ b/crm/pengine/testcases/inc7.exp @@ -1,668 +1,668 @@ - + - + - + - + - + - + - + - + - + - + diff --git a/crm/pengine/testcases/inc8.dot b/crm/pengine/testcases/inc8.dot index 3914d6c7f2..03ad51ca86 100644 --- a/crm/pengine/testcases/inc8.dot +++ b/crm/pengine/testcases/inc8.dot @@ -1,64 +1,74 @@ digraph "g" { size = "30,30" "probe_complete" [ style=bold color="green" fontcolor="orange" ] "probe_complete node1" [ style=bold color="green" fontcolor="black" ] "rsc0_monitor_0 node1" [ style=bold color="green" fontcolor="black" ] "child_rsc1:0_monitor_0 node1" [ style=bold color="green" fontcolor="black" ] "child_rsc1:1_monitor_0 node1" [ style=bold color="green" fontcolor="black" ] "child_rsc1:2_monitor_0 node1" [ style=bold color="green" fontcolor="black" ] "child_rsc1:3_monitor_0 node1" [ style=bold color="green" fontcolor="black" ] "child_rsc1:4_monitor_0 node1" [ style=bold color="green" fontcolor="black" ] "child_rsc2:0_monitor_0 node1" [ style=bold color="green" fontcolor="black" ] "child_rsc2:1_monitor_0 node1" [ style=bold color="green" fontcolor="black" ] "child_rsc2:2_monitor_0 node1" [ style=bold color="green" fontcolor="black" ] "child_rsc2:3_monitor_0 node1" [ style=bold color="green" fontcolor="black" ] "child_rsc2:4_monitor_0 node1" [ style=bold color="green" fontcolor="black" ] "probe_complete node2" [ style=bold color="green" fontcolor="black" ] "rsc0_monitor_0 node2" [ style=bold color="green" fontcolor="black" ] "child_rsc1:0_monitor_0 node2" [ style=bold color="green" fontcolor="black" ] "child_rsc1:1_monitor_0 node2" [ style=bold color="green" fontcolor="black" ] "child_rsc1:2_monitor_0 node2" [ style=bold color="green" fontcolor="black" ] "child_rsc1:3_monitor_0 node2" [ style=bold color="green" fontcolor="black" ] "child_rsc1:4_monitor_0 node2" [ style=bold color="green" fontcolor="black" ] "child_rsc2:0_monitor_0 node2" [ style=bold color="green" fontcolor="black" ] "child_rsc2:1_monitor_0 node2" [ style=bold color="green" fontcolor="black" ] "child_rsc2:2_monitor_0 node2" [ style=bold color="green" fontcolor="black" ] "child_rsc2:3_monitor_0 node2" [ style=bold color="green" fontcolor="black" ] "child_rsc2:4_monitor_0 node2" [ style=bold color="green" fontcolor="black" ] "rsc0_start_0 node1" [ style=bold color="green" fontcolor="black" ] -"child_rsc1:0_start_0 node1" [ style=bold color="green" fontcolor="black" ] -"child_rsc1:1_start_0 node2" [ style=bold color="green" fontcolor="black" ] +"child_rsc1:0_start_0 node2" [ style=bold color="green" fontcolor="black" ] +"child_rsc1:1_start_0 node1" [ style=bold color="green" fontcolor="black" ] "rsc1_start_0" [ style=bold color="green" fontcolor="orange" ] "rsc1_running_0" [ style=bold color="green" fontcolor="orange" ] +"child_rsc2:0_start_0 node2" [ style=bold color="green" fontcolor="black" ] +"child_rsc2:1_start_0 node1" [ style=bold color="green" fontcolor="black" ] +"rsc2_start_0" [ style=bold color="green" fontcolor="orange" ] +"rsc2_running_0" [ style=bold color="green" fontcolor="orange" ] "probe_complete node1" -> "probe_complete" [ style = bold] "probe_complete node2" -> "probe_complete" [ style = bold] "rsc0_monitor_0 node1" -> "probe_complete node1" [ style = bold] "child_rsc1:0_monitor_0 node1" -> "probe_complete node1" [ style = bold] "child_rsc1:1_monitor_0 node1" -> "probe_complete node1" [ style = bold] "child_rsc1:2_monitor_0 node1" -> "probe_complete node1" [ style = bold] "child_rsc1:3_monitor_0 node1" -> "probe_complete node1" [ style = bold] "child_rsc1:4_monitor_0 node1" -> "probe_complete node1" [ style = bold] "child_rsc2:0_monitor_0 node1" -> "probe_complete node1" [ style = bold] "child_rsc2:1_monitor_0 node1" -> "probe_complete node1" [ style = bold] "child_rsc2:2_monitor_0 node1" -> "probe_complete node1" [ style = bold] "child_rsc2:3_monitor_0 node1" -> "probe_complete node1" [ style = bold] "child_rsc2:4_monitor_0 node1" -> "probe_complete node1" [ style = bold] "rsc0_monitor_0 node2" -> "probe_complete node2" [ style = bold] "child_rsc1:0_monitor_0 node2" -> "probe_complete node2" [ style = bold] "child_rsc1:1_monitor_0 node2" -> "probe_complete node2" [ style = bold] "child_rsc1:2_monitor_0 node2" -> "probe_complete node2" [ style = bold] "child_rsc1:3_monitor_0 node2" -> "probe_complete node2" [ style = bold] "child_rsc1:4_monitor_0 node2" -> "probe_complete node2" [ style = bold] "child_rsc2:0_monitor_0 node2" -> "probe_complete node2" [ style = bold] "child_rsc2:1_monitor_0 node2" -> "probe_complete node2" [ style = bold] "child_rsc2:2_monitor_0 node2" -> "probe_complete node2" [ style = bold] "child_rsc2:3_monitor_0 node2" -> "probe_complete node2" [ style = bold] "child_rsc2:4_monitor_0 node2" -> "probe_complete node2" [ style = bold] "probe_complete" -> "rsc0_start_0 node1" [ style = bold] -"rsc1_start_0" -> "child_rsc1:0_start_0 node1" [ style = bold] -"rsc1_start_0" -> "child_rsc1:1_start_0 node2" [ style = bold] +"rsc1_start_0" -> "child_rsc1:0_start_0 node2" [ style = bold] +"rsc1_start_0" -> "child_rsc1:1_start_0 node1" [ style = bold] "probe_complete" -> "rsc1_start_0" [ style = bold] -"child_rsc1:0_start_0 node1" -> "rsc1_running_0" [ style = bold] -"child_rsc1:1_start_0 node2" -> "rsc1_running_0" [ style = bold] +"child_rsc1:0_start_0 node2" -> "rsc1_running_0" [ style = bold] +"child_rsc1:1_start_0 node1" -> "rsc1_running_0" [ style = bold] "rsc1_start_0" -> "rsc1_running_0" [ style = bold] +"rsc2_start_0" -> "child_rsc2:0_start_0 node2" [ style = bold] +"rsc2_start_0" -> "child_rsc2:1_start_0 node1" [ style = bold] +"probe_complete" -> "rsc2_start_0" [ style = bold] +"child_rsc2:0_start_0 node2" -> "rsc2_running_0" [ style = bold] +"child_rsc2:1_start_0 node1" -> "rsc2_running_0" [ style = bold] +"rsc2_start_0" -> "rsc2_running_0" [ style = bold] } diff --git a/crm/pengine/testcases/inc8.exp b/crm/pengine/testcases/inc8.exp index 93522ede2e..563707e18c 100644 --- a/crm/pengine/testcases/inc8.exp +++ b/crm/pengine/testcases/inc8.exp @@ -1,369 +1,425 @@ - + - + - + - + - + + + + + + + + + + + + + + - + - + + + + + + + + + + + + + + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + diff --git a/crm/pengine/testcases/inc9.exp b/crm/pengine/testcases/inc9.exp index 6584512636..76c0636e7d 100644 --- a/crm/pengine/testcases/inc9.exp +++ b/crm/pengine/testcases/inc9.exp @@ -1,132 +1,132 @@ - + - + - + - + diff --git a/crm/pengine/testcases/master-0.dot b/crm/pengine/testcases/master-0.dot index 789b178c44..ac42e3f993 100644 --- a/crm/pengine/testcases/master-0.dot +++ b/crm/pengine/testcases/master-0.dot @@ -1,44 +1,44 @@ digraph "g" { size = "30,30" "probe_complete" [ style=bold color="green" fontcolor="orange" ] "probe_complete node1" [ style=bold color="green" fontcolor="black" ] "child_rsc1:0_monitor_0 node1" [ style=bold color="green" fontcolor="black" ] "child_rsc1:1_monitor_0 node1" [ style=bold color="green" fontcolor="black" ] "child_rsc1:2_monitor_0 node1" [ style=bold color="green" fontcolor="black" ] "child_rsc1:3_monitor_0 node1" [ style=bold color="green" fontcolor="black" ] "child_rsc1:4_monitor_0 node1" [ style=bold color="green" fontcolor="black" ] "probe_complete node2" [ style=bold color="green" fontcolor="black" ] "child_rsc1:0_monitor_0 node2" [ style=bold color="green" fontcolor="black" ] "child_rsc1:1_monitor_0 node2" [ style=bold color="green" fontcolor="black" ] "child_rsc1:2_monitor_0 node2" [ style=bold color="green" fontcolor="black" ] "child_rsc1:3_monitor_0 node2" [ style=bold color="green" fontcolor="black" ] "child_rsc1:4_monitor_0 node2" [ style=bold color="green" fontcolor="black" ] "child_rsc1:0_start_0 node1" [ style=bold color="green" fontcolor="black" ] -"child_rsc1:1_start_0 node2" [ style=bold color="green" fontcolor="black" ] -"child_rsc1:2_start_0 node1" [ style=bold color="green" fontcolor="black" ] +"child_rsc1:1_start_0 node1" [ style=bold color="green" fontcolor="black" ] +"child_rsc1:2_start_0 node2" [ style=bold color="green" fontcolor="black" ] "child_rsc1:3_start_0 node2" [ style=bold color="green" fontcolor="black" ] "rsc1_start_0" [ style=bold color="green" fontcolor="orange" ] "rsc1_running_0" [ style=bold color="green" fontcolor="orange" ] "probe_complete node1" -> "probe_complete" [ style = bold] "probe_complete node2" -> "probe_complete" [ style = bold] "child_rsc1:0_monitor_0 node1" -> "probe_complete node1" [ style = bold] "child_rsc1:1_monitor_0 node1" -> "probe_complete node1" [ style = bold] "child_rsc1:2_monitor_0 node1" -> "probe_complete node1" [ style = bold] "child_rsc1:3_monitor_0 node1" -> "probe_complete node1" [ style = bold] "child_rsc1:4_monitor_0 node1" -> "probe_complete node1" [ style = bold] "child_rsc1:0_monitor_0 node2" -> "probe_complete node2" [ style = bold] "child_rsc1:1_monitor_0 node2" -> "probe_complete node2" [ style = bold] "child_rsc1:2_monitor_0 node2" -> "probe_complete node2" [ style = bold] "child_rsc1:3_monitor_0 node2" -> "probe_complete node2" [ style = bold] "child_rsc1:4_monitor_0 node2" -> "probe_complete node2" [ style = bold] "rsc1_start_0" -> "child_rsc1:0_start_0 node1" [ style = bold] -"rsc1_start_0" -> "child_rsc1:1_start_0 node2" [ style = bold] -"rsc1_start_0" -> "child_rsc1:2_start_0 node1" [ style = bold] +"rsc1_start_0" -> "child_rsc1:1_start_0 node1" [ style = bold] +"rsc1_start_0" -> "child_rsc1:2_start_0 node2" [ style = bold] "rsc1_start_0" -> "child_rsc1:3_start_0 node2" [ style = bold] "probe_complete" -> "rsc1_start_0" [ style = bold] "child_rsc1:0_start_0 node1" -> "rsc1_running_0" [ style = bold] -"child_rsc1:1_start_0 node2" -> "rsc1_running_0" [ style = bold] -"child_rsc1:2_start_0 node1" -> "rsc1_running_0" [ style = bold] +"child_rsc1:1_start_0 node1" -> "rsc1_running_0" [ style = bold] +"child_rsc1:2_start_0 node2" -> "rsc1_running_0" [ style = bold] "child_rsc1:3_start_0 node2" -> "rsc1_running_0" [ style = bold] "rsc1_start_0" -> "rsc1_running_0" [ style = bold] } diff --git a/crm/pengine/testcases/master-0.exp b/crm/pengine/testcases/master-0.exp index d8473eefd8..114f4757e6 100644 --- a/crm/pengine/testcases/master-0.exp +++ b/crm/pengine/testcases/master-0.exp @@ -1,244 +1,244 @@ + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - + - + diff --git a/crm/pengine/utils.c b/crm/pengine/utils.c index a830d6e4ce..3fe0a3a088 100644 --- a/crm/pengine/utils.c +++ b/crm/pengine/utils.c @@ -1,378 +1,378 @@ /* $Id: utils.c,v 1.147 2006/07/05 14:20:02 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 /* only for rsc_colocation constraints */ rsc_colocation_t * invert_constraint(rsc_colocation_t *constraint) { rsc_colocation_t *inverted_con = NULL; crm_debug_3("Inverting constraint"); if(constraint == NULL) { pe_err("Cannot invert NULL constraint"); return NULL; } crm_malloc0(inverted_con, sizeof(rsc_colocation_t)); if(inverted_con == NULL) { return NULL; } inverted_con->id = constraint->id; inverted_con->score = constraint->score; /* swap the direction */ inverted_con->rsc_lh = constraint->rsc_rh; inverted_con->rsc_rh = constraint->rsc_lh; inverted_con->state_lh = constraint->state_rh; inverted_con->state_rh = constraint->state_lh; crm_action_debug_3( print_rsc_colocation("Inverted constraint", inverted_con, FALSE)); return inverted_con; } gint sort_cons_strength(gconstpointer a, gconstpointer b) { const rsc_colocation_t *rsc_constraint1 = (const rsc_colocation_t*)a; const rsc_colocation_t *rsc_constraint2 = (const rsc_colocation_t*)b; if(a == NULL) { return 1; } if(b == NULL) { return -1; } if(rsc_constraint1->score > rsc_constraint2->score) { return 1; } if(rsc_constraint1->score < rsc_constraint2->score) { return -1; } return 0; } void print_rsc_to_node(const char *pre_text, rsc_to_node_t *cons, gboolean details) { if(cons == NULL) { crm_debug_4("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug_4("%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_4("\t%s (node placement rule)", safe_val3(NULL, cons, rsc_lh, id)); slist_iter( node, node_t, cons->node_list_rh, lpc, print_node("\t\t-->", node, FALSE) ); } } void print_rsc_colocation(const char *pre_text, rsc_colocation_t *cons, gboolean details) { if(cons == NULL) { crm_debug_4("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug_4("%s%s%s Constraint %s (%p):", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", XML_CONS_TAG_RSC_DEPEND, cons->id, cons); if(details == FALSE) { crm_debug_4("\t%s --> %s, %d", safe_val3(NULL, cons, rsc_lh, id), safe_val3(NULL, cons, rsc_rh, id), cons->score); } } void pe_free_ordering(GListPtr constraints) { GListPtr iterator = constraints; while(iterator != NULL) { order_constraint_t *order = iterator->data; iterator = iterator->next; crm_free(order->lh_action_task); crm_free(order->rh_action_task); crm_free(order); } if(constraints != NULL) { g_list_free(constraints); } } void pe_free_rsc_to_node(GListPtr constraints) { GListPtr iterator = constraints; while(iterator != NULL) { rsc_to_node_t *cons = iterator->data; iterator = iterator->next; pe_free_shallow(cons->node_list_rh); crm_free(cons); } if(constraints != NULL) { g_list_free(constraints); } } rsc_to_node_t * rsc2node_new(const char *id, resource_t *rsc, int node_weight, node_t *foo_node, pe_working_set_t *data_set) { rsc_to_node_t *new_con = NULL; if(rsc == NULL || id == NULL) { pe_err("Invalid constraint %s for rsc=%p", crm_str(id), rsc); return NULL; } crm_malloc0(new_con, sizeof(rsc_to_node_t)); if(new_con != NULL) { new_con->id = id; new_con->rsc_lh = rsc; new_con->node_list_rh = NULL; new_con->role_filter = RSC_ROLE_UNKNOWN; if(foo_node != NULL) { node_t *copy = node_copy(foo_node); copy->weight = node_weight; new_con->node_list_rh = g_list_append(NULL, copy); } else { CRM_CHECK(node_weight == 0, return NULL); } data_set->placement_constraints = g_list_append( data_set->placement_constraints, new_con); rsc->rsc_location = g_list_append( rsc->rsc_location, new_con); } return new_con; } const char * ordering_type2text(enum pe_ordering type) { const char *result = ""; switch(type) { case pe_ordering_manditory: result = "manditory"; break; case pe_ordering_restart: result = "restart"; break; case pe_ordering_recover: result = "recover"; break; case pe_ordering_optional: result = "optional"; break; case pe_ordering_postnotify: result = "post_notify"; break; } return result; } gboolean can_run_resources(const node_t *node) { if(node->details->online == FALSE || node->details->shutdown || node->details->unclean || node->details->standby) { crm_debug_2("%s: online=%d, unclean=%d, standby=%d", node->details->uname, node->details->online, node->details->unclean, node->details->standby); return FALSE; } return TRUE; } /* return -1 if 'a' is more preferred * return 1 if 'b' is more preferred */ gint sort_node_weight(gconstpointer a, gconstpointer b) { const node_t *node1 = (const node_t*)a; const node_t *node2 = (const node_t*)b; int node1_weight = 0; int node2_weight = 0; if(a == NULL) { return 1; } if(b == NULL) { return -1; } node1_weight = node1->weight; node2_weight = node2->weight; if(can_run_resources(node1) == FALSE) { node1_weight = -INFINITY; } if(can_run_resources(node2) == FALSE) { node2_weight = -INFINITY; } if(node1_weight > node2_weight) { crm_debug_3("%s (%d) > %s (%d) : weight", node1->details->uname, node1_weight, node2->details->uname, node2_weight); return -1; } if(node1_weight < node2_weight) { crm_debug_3("%s (%d) < %s (%d) : weight", node1->details->uname, node1_weight, node2->details->uname, node2_weight); return 1; } crm_debug_3("%s (%d) == %s (%d) : weight", node1->details->uname, node1_weight, node2->details->uname, node2_weight); /* now try to balance resources across the cluster */ if(node1->details->num_resources < node2->details->num_resources) { crm_debug_3("%s (%d) < %s (%d) : resources", node1->details->uname, node1->details->num_resources, node2->details->uname, node2->details->num_resources); return -1; } else if(node1->details->num_resources > node2->details->num_resources) { crm_debug_3("%s (%d) > %s (%d) : resources", node1->details->uname, node1->details->num_resources, node2->details->uname, node2->details->num_resources); return 1; } crm_debug_4("%s = %s", node1->details->uname, node2->details->uname); return 0; } gboolean native_assign_node(resource_t *rsc, GListPtr nodes, node_t *chosen) { int multiple = 0; CRM_ASSERT(rsc->variant == pe_native); if(chosen == NULL) { crm_debug("Could not allocate a node for %s", rsc->id); rsc->next_role = RSC_ROLE_STOPPED; return FALSE; } else if(chosen->details->unclean || chosen->details->standby || chosen->details->shutdown) { crm_debug("All nodes for color %s are unavailable" ", unclean or shutting down", rsc->id); rsc->next_role = RSC_ROLE_STOPPED; return FALSE; } else if(chosen->weight < 0) { - crm_debug_2("Even highest ranked node for color %s, had weight %d", + crm_debug("Even highest ranked node for %s, had weight %d", rsc->id, chosen->weight); rsc->next_role = RSC_ROLE_STOPPED; return FALSE; } if(rsc->next_role == RSC_ROLE_UNKNOWN) { rsc->next_role = RSC_ROLE_STARTED; } slist_iter(candidate, node_t, nodes, lpc, crm_debug("Color %s, Node[%d] %s: %d", rsc->id, lpc, candidate->details->uname, candidate->weight); if(chosen->weight > 0 && candidate->details->unclean == FALSE && candidate->weight == chosen->weight) { multiple++; } else { break; } ); if(multiple > 1) { int log_level = LOG_INFO; char *score = score2char(chosen->weight); if(chosen->weight >= INFINITY) { log_level = LOG_WARNING; } crm_log_maybe(log_level, "%d nodes with equal score (%s) for" " running the listed resources (chose %s):", multiple, score, chosen->details->uname); crm_free(score); } /* todo: update the old node for each resource to reflect its * new resource count */ if(rsc->allocated_to) { node_t *old = rsc->allocated_to; old->details->allocated_rsc = g_list_remove(old->details->allocated_rsc, rsc); old->details->num_resources--; old->count--; } crm_debug("Assigning %s to %s", chosen->details->uname, rsc->id); rsc->provisional = FALSE; crm_free(rsc->allocated_to); rsc->allocated_to = node_copy(chosen); chosen->details->allocated_rsc = g_list_append(chosen->details->allocated_rsc, rsc); chosen->details->num_resources++; chosen->count++; return TRUE; }