diff --git a/crm/pengine/complex.h b/crm/pengine/complex.h index c8bcc9ae1f..4b9ac3fda7 100644 --- a/crm/pengine/complex.h +++ b/crm/pengine/complex.h @@ -1,188 +1,203 @@ -/* $Id: complex.h,v 1.19 2005/08/10 08:55:04 andrew Exp $ */ +/* $Id: complex.h,v 1.20 2005/08/10 15:38:52 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 CRM_PENGINE_COMPLEX__H #define CRM_PENGINE_COMPLEX__H #include #include #include #define n_object_classes 3 /*#define PE_OBJ_F_ ""*/ #define PE_OBJ_T_NATIVE "native" #define PE_OBJ_T_GROUP "group" #define PE_OBJ_T_INCARNATION "incarnation" enum pe_obj_types { pe_native = 0, pe_group = 1, pe_clone = 2, pe_unknown = -1 }; extern int get_resource_type(const char *name); +typedef struct notify_entry_s { + resource_t *rsc; + node_t *node; +} notify_entry_t; + +typedef struct notify_data_s { + GHashTable *keys; + GListPtr active; /* notify_entry_t* */ + GListPtr inactive; /* notify_entry_t* */ + GListPtr start; /* notify_entry_t* */ + GListPtr stop; /* notify_entry_t* */ + +} notify_data_t; + + typedef struct resource_object_functions_s { void (*unpack)(resource_t *, pe_working_set_t *); resource_t *(*find_child)(resource_t *, const char *); int (*num_allowed_nodes)(resource_t *); void (*color)(resource_t *, pe_working_set_t *); void (*create_actions)(resource_t *, pe_working_set_t *); void (*internal_constraints)(resource_t *, pe_working_set_t *); void (*agent_constraints)(resource_t *); void (*rsc_colocation_lh)(rsc_colocation_t *); void (*rsc_colocation_rh)(resource_t *, rsc_colocation_t *); void (*rsc_order_lh)(resource_t *, order_constraint_t *); void (*rsc_order_rh)( action_t *, resource_t *, order_constraint_t *); void (*rsc_location)(resource_t *, rsc_to_node_t *); void (*expand)(resource_t *, pe_working_set_t *); void (*dump)(resource_t *, const char *, gboolean); void (*printw)(resource_t *, const char *, int*); void (*html)(resource_t *, const char *, FILE*); gboolean (*active)(resource_t *,gboolean); rsc_state_t (*state)(resource_t *); void (*create_notify_element)(resource_t*,action_t*, - crm_data_t*,pe_working_set_t*); + notify_data_t*,pe_working_set_t*); void (*free)(resource_t *); } resource_object_functions_t; extern void native_unpack(resource_t *rsc, pe_working_set_t *data_set); extern resource_t *native_find_child(resource_t *rsc, const char *id); extern int native_num_allowed_nodes(resource_t *rsc); extern void native_color(resource_t *rsc, pe_working_set_t *data_set); extern void native_create_actions( resource_t *rsc, pe_working_set_t *data_set); extern void native_internal_constraints( resource_t *rsc, pe_working_set_t *data_set); extern void native_agent_constraints(resource_t *rsc); extern void native_rsc_colocation_lh(rsc_colocation_t *constraint); extern void native_rsc_colocation_rh( resource_t *rsc, rsc_colocation_t *constraint); extern void native_rsc_order_lh(resource_t *rsc, order_constraint_t *order); extern void native_rsc_order_rh( action_t *lh_action, resource_t *rsc, order_constraint_t *order); extern void native_rsc_location(resource_t *rsc, rsc_to_node_t *constraint); extern void native_expand(resource_t *rsc, pe_working_set_t *data_set); extern void native_dump(resource_t *rsc, const char *pre_text, gboolean details); extern gboolean native_active(resource_t *rsc, gboolean all); extern void native_printw(resource_t *rsc, const char *pre_text, int *index); extern void native_html(resource_t *rsc, const char *pre_text, FILE *stream); extern void native_free(resource_t *rsc); extern rsc_state_t native_resource_state(resource_t *rsc); extern void native_create_notify_element( resource_t *rsc, action_t *op, - crm_data_t *parent, pe_working_set_t *data_set); + notify_data_t *n_data,pe_working_set_t *data_set); extern void group_unpack(resource_t *rsc, pe_working_set_t *data_set); extern resource_t *group_find_child(resource_t *rsc, const char *id); extern int group_num_allowed_nodes(resource_t *rsc); extern void group_color(resource_t *rsc, pe_working_set_t *data_set); extern void group_create_actions( resource_t *rsc, pe_working_set_t *data_set); extern void group_internal_constraints( resource_t *rsc, pe_working_set_t *data_set); extern void group_agent_constraints(resource_t *rsc); extern void group_rsc_colocation_lh(rsc_colocation_t *constraint); extern void group_rsc_colocation_rh( resource_t *rsc, rsc_colocation_t *constraint); extern void group_rsc_order_lh(resource_t *rsc, order_constraint_t *order); extern void group_rsc_order_rh( action_t *lh_action, resource_t *rsc, order_constraint_t *order); extern void group_rsc_location(resource_t *rsc, rsc_to_node_t *constraint); extern void group_expand(resource_t *rsc, pe_working_set_t *data_set); extern void group_dump(resource_t *rsc, const char *pre_text, gboolean details); extern gboolean group_active(resource_t *rsc, gboolean all); extern void group_printw(resource_t *rsc, const char *pre_text, int *index); extern void group_html(resource_t *rsc, const char *pre_text, FILE *stream); extern void group_free(resource_t *rsc); extern rsc_state_t group_resource_state(resource_t *rsc); extern void group_create_notify_element( resource_t *rsc, action_t *op, - crm_data_t *parent, pe_working_set_t *data_set); + notify_data_t *n_data,pe_working_set_t *data_set); extern void clone_unpack(resource_t *rsc, pe_working_set_t *data_set); extern resource_t *clone_find_child(resource_t *rsc, const char *id); extern int clone_num_allowed_nodes(resource_t *rsc); extern void clone_color(resource_t *rsc, pe_working_set_t *data_set); extern void clone_create_actions(resource_t *rsc, pe_working_set_t *data_set); extern void clone_internal_constraints( resource_t *rsc, pe_working_set_t *data_set); extern void clone_agent_constraints(resource_t *rsc); extern void clone_rsc_colocation_lh(rsc_colocation_t *constraint); extern void clone_rsc_colocation_rh( resource_t *rsc, rsc_colocation_t *constraint); extern void clone_rsc_order_lh(resource_t *rsc, order_constraint_t *order); extern void clone_rsc_order_rh( action_t *lh_action, resource_t *rsc, order_constraint_t *order); extern void clone_rsc_location(resource_t *rsc, rsc_to_node_t *constraint); extern void clone_expand(resource_t *rsc, pe_working_set_t *data_set); extern void clone_dump(resource_t *rsc, const char *pre_text, gboolean details); extern gboolean clone_active(resource_t *rsc, gboolean all); extern void clone_printw(resource_t *rsc, const char *pre_text, int *index); extern void clone_html(resource_t *rsc, const char *pre_text, FILE *stream); extern void clone_free(resource_t *rsc); extern rsc_state_t clone_resource_state(resource_t *rsc); extern void clone_create_notify_element( resource_t *rsc, action_t *op, - crm_data_t *parent, pe_working_set_t *data_set); + notify_data_t *n_data,pe_working_set_t *data_set); /* extern resource_object_functions_t resource_variants[]; */ extern resource_object_functions_t resource_class_functions[]; extern gboolean common_unpack( crm_data_t *xml_obj, resource_t **rsc, pe_working_set_t *data_set); extern void common_dump( resource_t *rsc, const char *pre_text, gboolean details); extern void common_printw(resource_t *rsc, const char *pre_text, int *index); extern void common_html(resource_t *rsc, const char *pre_text, FILE *stream); extern void common_free(resource_t *rsc); extern void native_add_running( resource_t *rsc, node_t *node, pe_working_set_t *data_set); extern gboolean is_active(rsc_to_node_t *cons); extern gboolean native_constraint_violated( resource_t *rsc_lh, resource_t *rsc_rh, rsc_colocation_t *constraint); extern void order_actions(action_t *lh, action_t *rh, order_constraint_t *order); extern void common_agent_constraints( GListPtr node_list, lrm_agent_t *agent, const char *id); extern void unpack_instance_attributes( crm_data_t *xml_obj, node_t *node, GHashTable *hash, const char **attr_filter, int attrs_length); extern const char *get_rsc_param(resource_t *rsc, const char *prop); extern void add_rsc_param(resource_t *rsc, const char *name, const char *value); extern void add_hash_param(GHashTable *hash, const char *name, const char *value); extern void hash2nvpair(gpointer key, gpointer value, gpointer user_data); extern void inherit_parent_attributes( crm_data_t *parent, crm_data_t *child, gboolean overwrite); #endif diff --git a/crm/pengine/graph.c b/crm/pengine/graph.c index 0699c4ccd4..50e5b77881 100644 --- a/crm/pengine/graph.c +++ b/crm/pengine/graph.c @@ -1,496 +1,501 @@ -/* $Id: graph.c,v 1.57 2005/08/10 08:55:03 andrew Exp $ */ +/* $Id: graph.c,v 1.58 2005/08/10 15:38:52 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include gboolean update_action(action_t *action); gboolean update_action_states(GListPtr actions) { crm_debug_2("Updating %d actions", g_list_length(actions)); slist_iter( action, action_t, actions, lpc, update_action(action); ); return TRUE; } #define UPDATE_THEM 1 gboolean update_action(action_t *action) { gboolean change = FALSE; enum action_tasks task = no_action; crm_debug_3("Processing action %d: %s", action->id, action->optional?"optional":"required"); slist_iter( other, action_wrapper_t, action->actions_before, lpc, crm_debug_3("\tChecking action %d: %s/%s", other->action->id, ordering_type2text(other->type), other->action->optional?"optional":"required"); if(other->type == pe_ordering_restart && action->rsc->start_pending == FALSE) { crm_debug_3("Upgrading %s constraint to %s", ordering_type2text(other->type), ordering_type2text(pe_ordering_manditory)); other->type = pe_ordering_manditory; } if(other->type != pe_ordering_manditory) { crm_debug_3("\t Ignoring: %s", ordering_type2text(other->type)); continue; } else if(action->optional || other->action->optional == FALSE){ crm_debug_3("\t Ignoring: %s/%s", other->action->optional?"-":"they are not optional", action->optional?"we are optional":"-"); continue; } else if(safe_str_eq(other->action->task, CRMD_ACTION_START)) { const char *interval = g_hash_table_lookup( action->extra, "interval"); int interval_i = 0; if(interval != NULL) { interval_i = atoi(interval); if(interval_i > 0) { crm_debug_3("Ignoring: start + recurring"); continue; } } } other->action->optional = FALSE; crm_debug_2("* Marking action %d manditory because of %d", other->action->id, action->id); update_action(other->action); ); slist_iter( other, action_wrapper_t, action->actions_after, lpc, if(action->pseudo == FALSE && action->runnable == FALSE) { if(other->action->runnable == FALSE) { crm_debug_2("Action %d already un-runnable", other->action->id); } else if(action->optional == FALSE) { other->action->runnable = FALSE; crm_debug_2("Marking action %d un-runnable" " because of %d", other->action->id, action->id); update_action(other->action); } } crm_debug_3("\t(Recover) Checking action %d: %s/%s", other->action->id, ordering_type2text(other->type), other->action->optional?"optional":"required"); if(other->action->rsc == NULL) { continue; } else if(other->type == pe_ordering_recover) { if(other->action->rsc->restart_type != pe_restart_restart) { crm_debug_3("\t Ignoring: restart type %d", other->action->rsc->restart_type); continue; } } else if(other->type == pe_ordering_restart) { } else if(other->type == pe_ordering_postnotify) { CRM_DEV_ASSERT(action->rsc == other->action->rsc); if(crm_assert_failed) { continue; } } else { crm_debug_3("\t Ignoring: ordering %s", ordering_type2text(other->type)); continue; } if(other->action->optional == FALSE || action->optional) { crm_debug_3("\t Ignoring: %s/%s", action->optional?"we are optional":"-", other->action->optional?"-":"they are not optional"); continue; } task = text2task(action->task); switch(task) { case stop_rsc: case stopped_rsc: crm_debug_3("\t Ignoring: action %s", action->task); break; case start_rsc: case started_rsc: crm_debug_2("* (Recover) Marking action %d" " manditory because of %d", other->action->id, action->id); other->action->optional = FALSE; update_action(other->action); break; default: crm_debug_3("\t Ignoring: action %s", action->task); break; } ); if(change) { update_action(action); } crm_debug_3("Action %d: %s", action->id, change?"update":"untouched"); return change; } gboolean shutdown_constraints( node_t *node, action_t *shutdown_op, pe_working_set_t *data_set) { /* add the stop to the before lists so it counts as a pre-req * for the shutdown */ slist_iter( rsc, resource_t, node->details->running_rsc, lpc, custom_action_order( rsc, stop_key(rsc), NULL, NULL, crm_strdup(CRM_OP_SHUTDOWN), shutdown_op, pe_ordering_manditory, data_set); ); return TRUE; } gboolean stonith_constraints(node_t *node, action_t *stonith_op, action_t *shutdown_op, pe_working_set_t *data_set) { GListPtr stop_actions = NULL; gboolean run_unprotected = TRUE; if(shutdown_op != NULL) { /* stop everything we can via shutdown_constraints() and then * shoot the node... the shutdown has been superceeded */ shutdown_op->pseudo = TRUE; shutdown_op->runnable = TRUE; /* shutdown before stonith */ /* Give any resources a chance to shutdown normally */ crm_debug_4("Adding shutdown (%d) as an input to stonith (%d)", shutdown_op->id, stonith_op->id); custom_action_order( NULL, crm_strdup(CRM_OP_SHUTDOWN), shutdown_op, NULL, crm_strdup(CRM_OP_FENCE), stonith_op, pe_ordering_manditory, data_set); } /* * Make sure the stonith OP occurs before we start any shared resources */ slist_iter( rsc, resource_t, data_set->resources, lpc, slist_iter(action, action_t, rsc->actions, lpc2, if(action->needs != rsc_req_stonith) { continue; } if(stonith_op != NULL) { custom_action_order( NULL, crm_strdup(CRM_OP_FENCE), stonith_op, rsc, NULL, action, pe_ordering_manditory, data_set); } else if(run_unprotected == FALSE) { /* mark the start unrunnable */ action->runnable = FALSE; } else { pe_err("SHARED RESOURCE %s IS NOT PROTECTED:" " Stonith disabled", rsc->id); } ); ); /* add the stonith OP as a stop pre-req and the mark the stop * as a pseudo op - since its now redundant */ slist_iter( rsc, resource_t, node->details->running_rsc, lpc, if(stonith_op != NULL) { char *key = stop_key(rsc); stop_actions = find_actions(rsc->actions, key, node); crm_free(key); slist_iter( action, action_t, stop_actions, lpc2, if(node->details->online == FALSE || rsc->unclean) { /* the stop would never complete and is * now implied by the stonith operation */ action->pseudo = TRUE; action->runnable = TRUE; custom_action_order( NULL, crm_strdup(CRM_OP_FENCE),stonith_op, rsc, stop_key(rsc), NULL, pe_ordering_manditory, data_set); } else { /* stop healthy resources before the * stonith op */ custom_action_order( rsc, stop_key(rsc), NULL, NULL,crm_strdup(CRM_OP_FENCE),stonith_op, pe_ordering_manditory, data_set); } ); crm_debug_4("Adding stonith (%d) as an input to stop", stonith_op->id); /* } else if((rsc->unclean || node->details->unclean) */ /* && rsc->stopfail_type == pesf_block) { */ /* /\* depend on the stop action which will fail *\/ */ /* pe_err("SHARED RESOURCE %s WILL REMAIN BLOCKED" */ /* " ON NODE %s UNTIL %s", */ /* rsc->id, node->details->uname, */ /* data_set->stonith_enabled?"QUORUM RETURNS":"CLEANED UP MANUALLY"); */ /* continue; */ /* } else if((rsc->unclean || node->details->unclean) */ /* && rsc->stopfail_type == pesf_ignore) { */ /* /\* nothing to do here *\/ */ /* pe_err("SHARED RESOURCE %s IS NOT PROTECTED", rsc->id); */ /* continue; */ } ); return TRUE; } +static void dup_attr(gpointer key, gpointer value, gpointer user_data) +{ + g_hash_table_replace(user_data, crm_strdup(key), crm_strdup(value)); +} + crm_data_t * action2xml(action_t *action, gboolean as_input) { gboolean needs_node_info = TRUE; crm_data_t * action_xml = NULL; crm_data_t * args_xml = NULL; char *action_id_s = NULL; if(action == NULL) { return NULL; } crm_debug_4("Dumping action %d as XML", action->id); if(safe_str_eq(action->task, CRM_OP_FENCE)) { action_xml = create_xml_node(NULL, XML_GRAPH_TAG_CRM_EVENT); needs_node_info = FALSE; } else if(safe_str_eq(action->task, CRM_OP_SHUTDOWN)) { action_xml = create_xml_node(NULL, XML_GRAPH_TAG_CRM_EVENT); } else if(action->pseudo) { action_xml = create_xml_node(NULL, XML_GRAPH_TAG_PSEUDO_EVENT); needs_node_info = FALSE; } else { action_xml = create_xml_node(NULL, XML_GRAPH_TAG_RSC_OP); } action_id_s = crm_itoa(action->id); crm_xml_add(action_xml, XML_ATTR_ID, action_id_s); crm_free(action_id_s); if(action->rsc != NULL) { crm_xml_add( action_xml, XML_LRM_ATTR_RSCID, action->rsc->id); } crm_xml_add(action_xml, XML_LRM_ATTR_TASK, action->task); crm_xml_add(action_xml, XML_LRM_ATTR_TASK_KEY, action->uuid); if(needs_node_info && action->node != NULL) { crm_xml_add(action_xml, XML_LRM_ATTR_TARGET, action->node->details->uname); crm_xml_add(action_xml, XML_LRM_ATTR_TARGET_UUID, action->node->details->id); CRM_DEV_ASSERT(NULL != crm_element_value( action_xml, XML_LRM_ATTR_TARGET)); CRM_DEV_ASSERT(NULL != crm_element_value( action_xml, XML_LRM_ATTR_TARGET_UUID)); } crm_xml_add(action_xml, "allow_fail", action->failure_is_fatal?XML_BOOLEAN_FALSE:XML_BOOLEAN_TRUE); if(as_input) { return action_xml; } + if(action->notify_keys != NULL) { + g_hash_table_foreach( + action->notify_keys, dup_attr, action->extra); + } if(action->rsc != NULL && action->pseudo == FALSE) { crm_data_t *rsc_xml = create_xml_node( action_xml, crm_element_name(action->rsc->xml)); copy_in_properties(rsc_xml, action->rsc->xml); args_xml = create_xml_node(action_xml, XML_TAG_ATTRS); g_hash_table_foreach(action->extra, hash2nvpair, args_xml); g_hash_table_foreach( action->rsc->parameters, hash2nvpair, args_xml); } else { args_xml = create_xml_node(action_xml, XML_TAG_ATTRS); g_hash_table_foreach(action->extra, hash2nvpair, args_xml); } - if(action->extra_xml != NULL) { - add_node_copy(action_xml, action->extra_xml); - } - crm_log_xml_debug_2(action_xml, "dumped action"); return action_xml; } void graph_element_from_action(action_t *action, pe_working_set_t *data_set) { int last_action = -1; char *syn_id = NULL; crm_data_t * syn = NULL; crm_data_t * set = NULL; crm_data_t * in = NULL; crm_data_t * input = NULL; crm_data_t * xml_action = NULL; if(action == NULL) { pe_err("Cannot dump NULL action"); return; } else if(action->optional) { crm_debug_5("action %d was optional", action->id); return; } else if(action->pseudo == FALSE && action->runnable == FALSE) { crm_debug_5("action %d was not runnable", action->id); return; } else if(action->dumped) { crm_debug_5("action %d was already dumped", action->id); return; } else if(action->pseudo || safe_str_eq(action->task, CRM_OP_FENCE) || safe_str_eq(action->task, CRM_OP_SHUTDOWN)) { /* skip the next two checks */ } else if(action->rsc != NULL && action->rsc->is_managed == FALSE) { pe_warn("action %d was for an unmanaged resource (%s)", action->id, action->rsc->id); return; } else { if(action->node == NULL) { pe_err("action %d was not allocated", action->id); log_action(LOG_DEBUG, "Unallocated action", action, FALSE); return; } else if(action->node->details->online == FALSE) { pe_err("action %d was scheduled for offline node", action->id); log_action(LOG_DEBUG, "Action for offline node", action, FALSE); return; } } action->dumped = TRUE; syn = create_xml_node(data_set->graph, "synapse"); set = create_xml_node(syn, "action_set"); in = create_xml_node(syn, "inputs"); syn_id = crm_itoa(data_set->num_synapse); crm_xml_add(syn, XML_ATTR_ID, syn_id); crm_free(syn_id); data_set->num_synapse++; xml_action = action2xml(action, FALSE); add_node_copy(set, xml_action); free_xml(xml_action); action->actions_before = g_list_sort( action->actions_before, sort_action_id); slist_iter(wrapper,action_wrapper_t,action->actions_before,lpc, if(last_action == wrapper->action->id) { crm_debug_2("Input (%d) %s duplicated", wrapper->action->id, wrapper->action->uuid); continue; } else if(wrapper->action->optional == TRUE) { crm_debug_2("Input (%d) %s optional", wrapper->action->id, wrapper->action->uuid); continue; } CRM_DEV_ASSERT(last_action < wrapper->action->id); last_action = wrapper->action->id; input = create_xml_node(in, "trigger"); xml_action = action2xml(wrapper->action, TRUE); add_node_copy(input, xml_action); free_xml(xml_action); ); } diff --git a/crm/pengine/group.c b/crm/pengine/group.c index ed60417934..b86738f81b 100644 --- a/crm/pengine/group.c +++ b/crm/pengine/group.c @@ -1,581 +1,581 @@ -/* $Id: group.c,v 1.32 2005/08/10 08:55:03 andrew Exp $ */ +/* $Id: group.c,v 1.33 2005/08/10 15:38:52 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 gboolean rsc_colocation_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; gboolean child_starting; gboolean child_stopping; } group_variant_data_t; #define get_group_variant_data(data, rsc) \ CRM_ASSERT(rsc->variant == pe_group); \ CRM_ASSERT(rsc->variant_opaque != NULL); \ data = (group_variant_data_t *)rsc->variant_opaque; \ void group_unpack(resource_t *rsc, pe_working_set_t *data_set) { crm_data_t *xml_obj = rsc->xml; crm_data_t *xml_self = create_xml_node(NULL, XML_CIB_TAG_RESOURCE); group_variant_data_t *group_data = NULL; resource_t *self = NULL; crm_debug_3("Processing resource %s...", rsc->id); crm_malloc0(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, data_set)) { group_data->self = self; self->restart_type = pe_restart_restart; } else { crm_log_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); inherit_parent_attributes(xml_self, xml_native_rsc, TRUE); if(common_unpack(xml_native_rsc, &new_rsc, data_set)) { 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; } rsc_colocation_new("pe_group_internal_colo", pecs_must, group_data->self, new_rsc); crm_action_debug_3( print_resource("Added", new_rsc, FALSE)); } else { pe_err("Failed unpacking resource %s", crm_element_value(xml_obj, XML_ATTR_ID)); } ); crm_debug_3("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 { pe_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 { pe_err("Resource %s was not a \"native\" variant", rsc->id); return 0; } if(group_data->self == NULL) { return 0; } return group_data->self->fns->num_allowed_nodes(group_data->self); } void group_color(resource_t *rsc, pe_working_set_t *data_set) { group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); if(group_data->self == NULL) { return; } group_data->self->fns->color(group_data->self, data_set); } void group_update_pseudo_status(resource_t *parent, resource_t *child); void group_create_actions(resource_t *rsc, pe_working_set_t *data_set) { action_t *op = NULL; 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, data_set); group_update_pseudo_status(rsc, child_rsc); ); op = start_action(group_data->self, NULL, !group_data->child_starting); op->pseudo = TRUE; op = custom_action(group_data->self, started_key(rsc), CRMD_ACTION_STARTED, NULL, !group_data->child_starting, data_set); op->pseudo = TRUE; op = stop_action(group_data->self, NULL, !group_data->child_stopping); op->pseudo = TRUE; op = custom_action(group_data->self, stopped_key(rsc), CRMD_ACTION_STOPPED, NULL, !group_data->child_stopping, data_set); op->pseudo = TRUE; } void group_update_pseudo_status(resource_t *parent, resource_t *child) { group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, parent); if(group_data->child_stopping && group_data->child_starting) { return; } slist_iter( action, action_t, child->actions, lpc, if(action->optional) { continue; } if(safe_str_eq(CRMD_ACTION_STOP, action->task)) { group_data->child_stopping = TRUE; } else if(safe_str_eq(CRMD_ACTION_START, action->task)) { group_data->child_starting = TRUE; } ); } void group_internal_constraints(resource_t *rsc, pe_working_set_t *data_set) { resource_t *last_rsc = NULL; group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); custom_action_order( group_data->self, stopped_key(group_data->self), NULL, group_data->self, start_key(group_data->self), NULL, pe_ordering_optional, data_set); slist_iter( child_rsc, resource_t, group_data->child_list, lpc, order_restart(child_rsc); if(last_rsc != NULL) { order_start_start( last_rsc, child_rsc, pe_ordering_optional); order_stop_stop( child_rsc, last_rsc, pe_ordering_optional); } else { custom_action_order( child_rsc, stop_key(child_rsc), NULL, group_data->self, stopped_key(group_data->self), NULL, pe_ordering_optional, data_set); order_start_start(group_data->self, child_rsc, pe_ordering_optional); } last_rsc = child_rsc; ); if(last_rsc != NULL) { custom_action_order( last_rsc, start_key(last_rsc), NULL, group_data->self, started_key(group_data->self), NULL, pe_ordering_optional, data_set); order_stop_stop( group_data->self, last_rsc, pe_ordering_optional); } } void group_rsc_colocation_lh(rsc_colocation_t *constraint) { resource_t *rsc = constraint->rsc_lh; group_variant_data_t *group_data = 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_group_variant_data(group_data, rsc); if(group_data->self == NULL) { return; } group_data->self->fns->rsc_colocation_rh(group_data->self, constraint); } void group_rsc_colocation_rh(resource_t *rsc, rsc_colocation_t *constraint) { resource_t *rsc_lh = rsc; group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); crm_debug_3("Processing RH of constraint %s", constraint->id); crm_action_debug_3(print_resource("LHS", rsc_lh, TRUE)); if(group_data->self == NULL) { return; } group_data->self->fns->rsc_colocation_rh(group_data->self, constraint); } void group_rsc_order_lh(resource_t *rsc, order_constraint_t *order) { char *stop_id = NULL; char *start_id = NULL; group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); crm_debug_3("Processing LH of ordering constraint %d", order->id); if(group_data->self == NULL) { return; } 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); 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_debug_3("Processing RH of ordering constraint %d", order->id); if(group_data->self == NULL) { return; } 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) { group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); crm_debug_3("Processing actions from %s", rsc->id); if(group_data->self != NULL) { 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, pe_working_set_t *data_set) { group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); crm_debug_3("Processing actions from %s", rsc->id); group_data->self->fns->expand(group_data->self, data_set); if(group_data->self == NULL) { return; } slist_iter( child_rsc, resource_t, group_data->child_list, lpc, child_rsc->fns->expand(child_rsc, data_set); ); } gboolean group_active(resource_t *rsc, gboolean all) { 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, gboolean child_active = child_rsc->fns->active(child_rsc, all); if(all == FALSE && child_active) { return TRUE; } else if(child_active == FALSE) { return FALSE; } ); if(all) { return TRUE; } else { return FALSE; } } void group_printw(resource_t *rsc, const char *pre_text, int *index) { #if CURSES_ENABLED const char *child_text = NULL; group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); if(pre_text != NULL) { child_text = " "; } else { child_text = " "; } move(*index, 0); printw("Resource Group: %s\n", rsc->id); slist_iter( child_rsc, resource_t, group_data->child_list, lpc, (*index)++; child_rsc->fns->printw(child_rsc, child_text, index); ); #else crm_err("printw support requires ncurses to be available during configure"); #endif } void group_html(resource_t *rsc, const char *pre_text, FILE *stream) { const char *child_text = NULL; group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); if(pre_text != NULL) { child_text = " "; } else { child_text = " "; } fprintf(stream, "Resource Group: %s\n", rsc->id); fprintf(stream, "
    \n"); slist_iter( child_rsc, resource_t, group_data->child_list, lpc, fprintf(stream, "
  • \n"); child_rsc->fns->html(child_rsc, child_text, stream); fprintf(stream, "
  • \n"); ); fprintf(stream, "
\n"); } void group_dump(resource_t *rsc, const char *pre_text, gboolean details) { group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); if(group_data->self == NULL) { return; } 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) { group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); crm_debug_3("Freeing %s", rsc->id); slist_iter( child_rsc, resource_t, group_data->child_list, lpc, crm_debug_3("Freeing child %s", child_rsc->id); child_rsc->fns->free(child_rsc); ); crm_debug_3("Freeing child list"); pe_free_shallow_adv(group_data->child_list, FALSE); free_xml(group_data->self->xml); if(group_data->self != NULL) { group_data->self->fns->free(group_data->self); } common_free(rsc); } void group_agent_constraints(resource_t *rsc) { 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); ); } rsc_state_t group_resource_state(resource_t *rsc) { rsc_state_t state = rsc_state_unknown; rsc_state_t last_state = rsc_state_unknown; 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, last_state = child_rsc->fns->state(child_rsc); switch(last_state) { case rsc_state_unknown: case rsc_state_move: return last_state; break; case rsc_state_restart: CRM_DEV_ASSERT(state != rsc_state_stopping); CRM_DEV_ASSERT(state != rsc_state_stopped); /* CRM_DEV_ASSERT(state != rsc_state_active); */ state = last_state; break; case rsc_state_active: /* CRM_DEV_ASSERT(state != rsc_state_restart); */ CRM_DEV_ASSERT(state != rsc_state_stopping); if(last_state == rsc_state_unknown) { state = last_state; } break; case rsc_state_stopped: CRM_DEV_ASSERT(state != rsc_state_restart); CRM_DEV_ASSERT(state != rsc_state_starting); if(last_state == rsc_state_unknown) { state = last_state; } break; case rsc_state_starting: CRM_DEV_ASSERT(state != rsc_state_stopped); if(state != rsc_state_restart) { state = last_state; } break; case rsc_state_stopping: CRM_DEV_ASSERT(state != rsc_state_active); if(state != rsc_state_restart) { state = last_state; } break; } ); return state; } void -group_create_notify_element(resource_t *rsc, action_t *op, crm_data_t *parent, - pe_working_set_t *data_set) +group_create_notify_element(resource_t *rsc, action_t *op, + notify_data_t *n_data, pe_working_set_t *data_set) { 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_notify_element( - child_rsc, op, parent, data_set); + child_rsc, op, n_data, data_set); ); } diff --git a/crm/pengine/incarnation.c b/crm/pengine/incarnation.c index 91d333613e..87acaa59b6 100644 --- a/crm/pengine/incarnation.c +++ b/crm/pengine/incarnation.c @@ -1,973 +1,1193 @@ -/* $Id: incarnation.c,v 1.44 2005/08/10 12:58:36 andrew Exp $ */ +/* $Id: incarnation.c,v 1.45 2005/08/10 15:38:52 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); extern gboolean rsc_colocation_new( const char *id, enum con_strength strength, resource_t *rsc_lh, resource_t *rsc_rh); typedef struct clone_variant_data_s { resource_t *self; int clone_max; int clone_max_node; int active_clones; gboolean interleave; gboolean ordered; gboolean notify_confirm; GListPtr child_list; /* resource_t* */ gboolean child_starting; gboolean child_stopping; } 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); \ data = (clone_variant_data_t *)rsc->variant_opaque; void clone_unpack(resource_t *rsc, pe_working_set_t *data_set) { int lpc = 0; crm_data_t * xml_obj_child = NULL; crm_data_t * xml_obj = rsc->xml; crm_data_t * xml_self = create_xml_node(NULL, XML_CIB_TAG_RESOURCE); clone_variant_data_t *clone_data = NULL; resource_t *self = NULL; char *inc_max = NULL; const char *ordered = crm_element_value(xml_obj, XML_RSC_ATTR_ORDERED); const char *interleave = crm_element_value(xml_obj, XML_RSC_ATTR_INTERLEAVE); const char *max_clones = get_rsc_param(rsc, XML_RSC_ATTR_INCARNATION_MAX); const char *max_clones_node = get_rsc_param(rsc, XML_RSC_ATTR_INCARNATION_NODEMAX); crm_debug_3("Processing resource %s...", rsc->id); crm_malloc0(clone_data, sizeof(clone_variant_data_t)); clone_data->child_list = NULL; clone_data->interleave = FALSE; clone_data->ordered = FALSE; clone_data->active_clones = 0; clone_data->clone_max = crm_atoi(max_clones, "1"); clone_data->clone_max_node = crm_atoi(max_clones_node,"1"); /* this is a bit of a hack - but simplifies everything else */ copy_in_properties(xml_self, xml_obj); xml_obj_child = find_xml_node(xml_obj, "operations", FALSE); if(xml_obj_child != NULL) { add_node_copy(xml_self, xml_obj_child); } xml_obj_child = find_xml_node(xml_obj, XML_CIB_TAG_GROUP, FALSE); if(xml_obj_child == NULL) { xml_obj_child = find_xml_node( xml_obj, XML_CIB_TAG_RESOURCE, TRUE); } CRM_DEV_ASSERT(xml_obj_child != NULL); if(crm_assert_failed) { return; } if(common_unpack(xml_self, &self, data_set)) { clone_data->self = self; } else { crm_log_xml_err(xml_self, "Couldnt unpack dummy child"); return; } if(crm_is_true(interleave)) { clone_data->interleave = TRUE; } if(crm_is_true(ordered)) { clone_data->ordered = TRUE; } #if 0 { const char *confirm = crm_element_value( xml_obj, "notify_confirm"); clone_data->notify_confirm = crm_is_true(confirm); } #else clone_data->notify_confirm = clone_data->self->notify; #endif inherit_parent_attributes(xml_self, xml_obj_child, FALSE); inc_max = crm_itoa(clone_data->clone_max); for(lpc = 0; lpc < clone_data->clone_max; lpc++) { resource_t *child_rsc = NULL; crm_data_t * child_copy = copy_xml(xml_obj_child); set_id(child_copy, rsc->id, lpc); if(common_unpack(child_copy, &child_rsc, data_set)) { char *inc_num = crm_itoa(lpc); clone_data->child_list = g_list_append( clone_data->child_list, child_rsc); add_rsc_param( child_rsc, XML_RSC_ATTR_INCARNATION, inc_num); add_rsc_param( child_rsc, XML_RSC_ATTR_INCARNATION_MAX, inc_max); crm_action_debug_3( print_resource("Added", child_rsc, FALSE)); crm_free(inc_num); } else { pe_err("Failed unpacking resource %s", crm_element_value(child_copy, XML_ATTR_ID)); } } crm_free(inc_max); crm_debug_3("Added %d children to resource %s...", clone_data->clone_max, rsc->id); rsc->variant_opaque = clone_data; } resource_t * clone_find_child(resource_t *rsc, const char *id) { clone_variant_data_t *clone_data = NULL; if(rsc->variant == pe_clone) { clone_data = (clone_variant_data_t *)rsc->variant_opaque; } else { pe_err("Resource %s was not a \"" XML_CIB_TAG_INCARNATION "\" variant", rsc->id); return NULL; } return pe_find_resource(clone_data->child_list, id); } int clone_num_allowed_nodes(resource_t *rsc) { int num_nodes = 0; clone_variant_data_t *clone_data = NULL; if(rsc->variant == pe_clone) { clone_data = (clone_variant_data_t *)rsc->variant_opaque; } else { pe_err("Resource %s was not an \"" XML_CIB_TAG_INCARNATION "\" variant", rsc->id); return 0; } /* what *should* we return here? */ slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, int tmp_num_nodes = child_rsc->fns->num_allowed_nodes(child_rsc); if(tmp_num_nodes > num_nodes) { num_nodes = tmp_num_nodes; } ); return num_nodes; } void clone_color(resource_t *rsc, pe_working_set_t *data_set) { int lpc = 0, lpc2 = 0, max_nodes = 0; resource_t *child_0 = NULL; resource_t *child_lh = NULL; resource_t *child_rh = NULL; clone_variant_data_t *clone_data = NULL; get_clone_variant_data(clone_data, rsc); if(clone_data->self->is_managed == FALSE) { return; } child_0 = g_list_nth_data(clone_data->child_list, 0); max_nodes = rsc->fns->num_allowed_nodes(rsc); /* generate up to max_nodes * clone_node_max constraints */ lpc = 0; clone_data->active_clones = max_nodes * clone_data->clone_max_node; if(clone_data->active_clones > clone_data->clone_max) { clone_data->active_clones = clone_data->clone_max; } crm_info("Distributing %d (of %d) %s clones over %d nodes", clone_data->active_clones, clone_data->clone_max, rsc->id, max_nodes); for(; lpc < clone_data->active_clones && lpc < max_nodes; lpc++) { child_lh = g_list_nth_data(clone_data->child_list, lpc); for(lpc2 = lpc + 1; lpc2 < clone_data->active_clones; lpc2++) { child_rh = g_list_nth_data(clone_data->child_list,lpc2); if(lpc2 < max_nodes) { crm_debug_2("Clone %d will not run with %d", lpc, lpc2); rsc_colocation_new( "__clone_internal_must_not__", pecs_must_not, child_lh, child_rh); } else if((lpc2 % max_nodes) == lpc) { crm_debug_2("Clone %d can run with %d", lpc, lpc2); rsc_colocation_new( "__clone_internal_must__", pecs_must, child_lh, child_rh); } } for(; lpc2 < clone_data->clone_max; lpc2++) { child_rh = g_list_nth_data(clone_data->child_list,lpc2); crm_debug_2("Unrunnable: Clone %d will not run with %d", lpc2, lpc); rsc_colocation_new("__clone_internal_must_not__", pecs_must_not, child_lh, child_rh); } } slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, if(lpc >= clone_data->active_clones) { crm_warn("Clone %s cannot be started", child_rsc->id); } child_rsc->fns->color(child_rsc, data_set); ); } void clone_update_pseudo_status(resource_t *parent, resource_t *child); void clone_create_actions(resource_t *rsc, pe_working_set_t *data_set) { action_t *action = 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->fns->create_actions(child_rsc, data_set); clone_update_pseudo_status(rsc, child_rsc); if(child_rsc->starting) { last_start_rsc = child_rsc; } if(child_rsc->stopping) { last_stop_rsc = child_rsc; } ); /* start */ action = start_action(clone_data->self, NULL, !clone_data->child_starting); action_complete = custom_action(clone_data->self, started_key(rsc), CRMD_ACTION_STARTED, NULL, !clone_data->child_starting, data_set); action->pseudo = TRUE; action_complete->pseudo = TRUE; child_starting_constraints( clone_data, pe_ordering_optional, NULL, last_start_rsc, data_set); clone_create_notifications( rsc, action, action_complete, data_set); /* stop */ action = stop_action(clone_data->self, NULL, !clone_data->child_stopping); action_complete = custom_action(clone_data->self, stopped_key(rsc), CRMD_ACTION_STOPPED, NULL, !clone_data->child_stopping, data_set); action->pseudo = TRUE; action_complete->pseudo = TRUE; child_stopping_constraints( clone_data, pe_ordering_optional, NULL, last_stop_rsc, data_set); clone_create_notifications( rsc, action, action_complete, data_set); } 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, data_set); add_hash_param(notify->extra, "notify_type", "pre"); add_hash_param(notify->extra, "notify_operation", action->task); if(clone_data->notify_confirm) { add_hash_param(notify->extra, "notify_confirm", "yes"); } else { add_hash_param(notify->extra, "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, data_set); add_hash_param(notify_complete->extra, "notify_type", "pre"); add_hash_param(notify_complete->extra, "notify_operation", action->task); if(clone_data->notify_confirm) { add_hash_param(notify->extra, "notify_confirm", "yes"); } else { add_hash_param(notify->extra, "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, data_set); add_hash_param(notify->extra, "notify_type", "post"); add_hash_param(notify->extra, "notify_operation", action->task); if(clone_data->notify_confirm) { add_hash_param(notify->extra, "notify_confirm", "yes"); } else { add_hash_param(notify->extra, "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, data_set); add_hash_param(notify_complete->extra, "notify_type", "pre"); add_hash_param(notify_complete->extra, "notify_operation", action->task); if(clone_data->notify_confirm) { add_hash_param(notify->extra, "notify_confirm", "yes"); } else { add_hash_param(notify->extra, "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); } } void clone_update_pseudo_status(resource_t *parent, resource_t *child) { clone_variant_data_t *clone_data = NULL; get_clone_variant_data(clone_data, parent); if(clone_data->child_stopping && clone_data->child_starting) { return; } slist_iter( action, action_t, child->actions, lpc, if(action->optional) { continue; } if(safe_str_eq(CRMD_ACTION_STOP, action->task)) { clone_data->child_stopping = TRUE; } else if(safe_str_eq(CRMD_ACTION_START, action->task)) { clone_data->child_starting = TRUE; } ); } 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); /* 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 stop before start */ order_restart(child_rsc); 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; ); } void clone_rsc_colocation_lh(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_max_node != clone_data_rh->clone_max_node) { 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; } } if(do_interleave) { resource_t *child_lh = NULL; resource_t *child_rh = NULL; resource_t *parent_rh = constraint->rsc_rh; GListPtr iter_lh = clone_data->child_list; GListPtr iter_rh = clone_data_rh->child_list; crm_debug_2("Interleaving %s with %s", constraint->rsc_lh->id, constraint->rsc_rh->id); /* If the resource have different numbers of incarnations, * then just do as many as are available */ while(iter_lh != NULL && iter_rh != NULL) { child_lh = iter_lh->data; child_rh = iter_rh->data; iter_lh = iter_lh->next; iter_rh = iter_rh->next; constraint->rsc_rh = child_rh; crm_debug_3("Colocating %s with %s", child_lh->id, child_rh->id); child_rh->fns->rsc_colocation_rh(child_lh, constraint); } /* restore the original RHS of the constraint */ constraint->rsc_rh = parent_rh; return; } else if(constraint->strength != pecs_must_not) { pe_warn("rsc_colocations other than \"-INFINITY\"" " are not supported for non-interleaved" " "XML_CIB_TAG_INCARNATION" resources"); return; } slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, crm_action_debug_3(print_resource("LHS", child_rsc, TRUE)); child_rsc->fns->rsc_colocation_rh(child_rsc, constraint); ); } void clone_rsc_colocation_rh(resource_t *rsc, rsc_colocation_t *constraint) { clone_variant_data_t *clone_data = NULL; crm_debug_3("Processing RH of constraint %s", constraint->id); 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 if(constraint->strength != pecs_must_not) { pe_warn("rsc_dependencies other than \"must_not\" " "are not supported for incarnation resources"); return; } else { crm_action_debug_3(print_resource("LHS", rsc, FALSE)); } get_clone_variant_data(clone_data, rsc); slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, crm_action_debug_3(print_resource("RHS", child_rsc, FALSE)); child_rsc->fns->rsc_colocation_rh(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->fns->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->fns->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 actions from %s", rsc->id); clone_data->self->fns->rsc_location(clone_data->self, constraint); slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, child_rsc->fns->rsc_location(child_rsc, constraint); ); } -void clone_expand(resource_t *rsc, pe_working_set_t *data_set) -{ - crm_data_t *notify_xml = create_xml_node(NULL, "notify"); +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) +{ + int rsc_len = 0; + int node_len = 0; + int uuid_len = 0; + int list_len = 100 * clones; + + char *rsc_list_s = NULL; + char *node_list_s = NULL; + char *uuid_list_s = NULL; + + const char *uuid = NULL; + const char *uname = NULL; + const char *rsc_id = NULL; + + const char *last_uuid = NULL; + const char *last_rsc_id = NULL; + clone_expand_reallocate: + if(rsc_list != NULL) { + crm_malloc0(*rsc_list, sizeof(char)*list_len); + rsc_list_s = *rsc_list; + rsc_len = 0; + } + if(node_list != NULL) { + crm_malloc0(*node_list, sizeof(char)*list_len); + node_list_s = *node_list; + node_len = 0; + } + if(uuid_list != NULL) { + crm_malloc0(*uuid_list, sizeof(char)*list_len); + uuid_list_s = *uuid_list; + uuid_len = 0; + } + + slist_iter(entry, notify_entry_t, list, lpc, + + rsc_id = entry->rsc->id; + CRM_DEV_ASSERT(rsc_id != NULL); + if(crm_assert_failed) { + rsc_id = "__none__"; + } + + uuid = NULL; + if(entry->node) { + uuid = entry->node->details->id; + } + CRM_DEV_ASSERT(uuid != NULL); + if(crm_assert_failed) { + uuid = "__none__"; + } + + uname = NULL; + if(entry->node) { + uname = entry->node->details->uname; + } + CRM_DEV_ASSERT(uname != NULL); + if(crm_assert_failed) { + uname = "__none__"; + } + + /* filter dups */ + if(safe_str_eq(rsc_id, last_rsc_id) + && safe_str_eq(uuid, last_uuid)) { + continue; + } + last_rsc_id = rsc_id; + last_uuid = uuid; + + if(rsc_len + 1 + strlen(rsc_id) >= list_len) { + crm_free(*rsc_list); + crm_free(*node_list); + crm_free(*uuid_list); + list_len *= 2; + goto clone_expand_reallocate; + } + sprintf(rsc_list_s, "%s ", rsc_id); + rsc_list_s += 1 + strlen(rsc_id); + rsc_len += 1 + strlen(rsc_id); + + + if(node_len + 1 + strlen(uname) >= list_len) { + crm_free(*rsc_list); + crm_free(*node_list); + crm_free(*uuid_list); + list_len *= 2; + goto clone_expand_reallocate; + } + sprintf(node_list_s, "%s ", uname); + node_list_s += 1 + strlen(uname); + node_len += 1 + strlen(uname); + + + if(uuid_len + 1 + strlen(uuid) >= list_len) { + crm_free(*rsc_list); + crm_free(*node_list); + crm_free(*uuid_list); + list_len *= 2; + goto clone_expand_reallocate; + } + sprintf(uuid_list_s, "%s ", uuid); + uuid_list_s += 1 + strlen(uuid); + uuid_len += 1 + strlen(uuid); + ); +} + +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); - slist_iter( - child_rsc, resource_t, clone_data->child_list, lpc, - + if(rsc->notify) { slist_iter( - op, action_t, clone_data->self->actions, lpc2, - - child_rsc->fns->create_notify_element( - child_rsc, op, notify_xml, data_set); + child_rsc, resource_t, clone_data->child_list, lpc, + + slist_iter( + op, action_t, clone_data->self->actions, lpc2, + + child_rsc->fns->create_notify_element( + child_rsc, op, n_data, data_set); + ); ); - ); + } + + /* expand the notify data */ + if(rsc->notify && n_data->start) { + n_data->start = g_list_sort( + n_data->start, sort_notify_entries); + rsc_list = NULL; node_list = NULL; uuid_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); + g_hash_table_insert( + n_data->keys, + crm_strdup("notify_start_uuid"), uuid_list); + } + + if(rsc->notify && n_data->stop) { + n_data->stop = g_list_sort( + n_data->stop, sort_notify_entries); + rsc_list = NULL; node_list = NULL; uuid_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); + g_hash_table_insert( + n_data->keys, + crm_strdup("notify_stop_uuid"), uuid_list); + } - /* yes we DO need the second loop */ + 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); + g_hash_table_insert( + n_data->keys, + crm_strdup("notify_active_uuid"), uuid_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); + g_hash_table_insert( + n_data->keys, + crm_strdup("notify_inactive_uuid"), uuid_list); + } + + /* yes, we DO need this second loop */ slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, child_rsc->fns->expand(child_rsc, data_set); ); - slist_iter( - action, action_t, clone_data->self->actions, lpc2, +/* slist_iter( */ +/* action, action_t, clone_data->self->actions, lpc2, */ - if(safe_str_eq(action->task, CRMD_ACTION_NOTIFY)) { - action->extra_xml = notify_xml; - } - ); +/* if(safe_str_eq(action->task, CRMD_ACTION_NOTIFY)) { */ +/* action->extra_xml = notify_xml; */ +/* } */ +/* ); */ clone_data->self->fns->expand(clone_data->self, data_set); - free_xml(notify_xml); + + /* destroy the notify_data */ + pe_free_shallow(n_data->stop); + pe_free_shallow(n_data->start); + pe_free_shallow(n_data->active); + pe_free_shallow(n_data->inactive); + g_hash_table_destroy(n_data->keys); + crm_free(n_data); } gboolean clone_active(resource_t *rsc, gboolean all) { 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, gboolean child_active = child_rsc->fns->active(child_rsc, all); if(all == FALSE && child_active) { return TRUE; } else if(all && child_active == FALSE) { return FALSE; } ); if(all) { return TRUE; } else { return FALSE; } } void clone_printw(resource_t *rsc, const char *pre_text, int *index) { #if CURSES_ENABLED const char *child_text = NULL; clone_variant_data_t *clone_data = NULL; get_clone_variant_data(clone_data, rsc); if(pre_text != NULL) { child_text = " "; } else { child_text = " "; } move(*index, 0); printw("Clone: %s\n", rsc->id); slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, (*index)++; child_rsc->fns->printw(child_rsc, child_text, index); ); #else crm_err("printw support requires ncurses to be available during configure"); #endif } void clone_html(resource_t *rsc, const char *pre_text, FILE *stream) { const char *child_text = NULL; clone_variant_data_t *clone_data = NULL; get_clone_variant_data(clone_data, rsc); if(pre_text != NULL) { child_text = " "; } else { child_text = " "; } fprintf(stream, "Clone: %s\n", rsc->id); fprintf(stream, "
    \n"); slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, fprintf(stream, "
  • \n"); child_rsc->fns->html(child_rsc, child_text, stream); fprintf(stream, "
  • \n"); ); fprintf(stream, "
\n"); } void clone_dump(resource_t *rsc, const char *pre_text, gboolean details) { clone_variant_data_t *clone_data = NULL; get_clone_variant_data(clone_data, rsc); common_dump(rsc, pre_text, details); clone_data->self->fns->dump( clone_data->self, pre_text, details); slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, child_rsc->fns->dump(child_rsc, pre_text, details); ); } void clone_free(resource_t *rsc) { clone_variant_data_t *clone_data = NULL; get_clone_variant_data(clone_data, rsc); crm_debug_3("Freeing %s", rsc->id); slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, crm_debug_3("Freeing child %s", child_rsc->id); free_xml(child_rsc->xml); child_rsc->fns->free(child_rsc); ); crm_debug_3("Freeing child list"); pe_free_shallow_adv(clone_data->child_list, FALSE); free_xml(clone_data->self->xml); clone_data->self->fns->free(clone_data->self); common_free(rsc); } 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->fns->agent_constraints(child_rsc); ); } rsc_state_t clone_resource_state(resource_t *rsc) { return rsc_state_unknown; } void -clone_create_notify_element(resource_t *rsc, action_t *op, crm_data_t *parent, - pe_working_set_t *data_set) +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->fns->create_notify_element( - child_rsc, op, parent, data_set); + child_rsc, op, n_data, data_set); ); } diff --git a/crm/pengine/native.c b/crm/pengine/native.c index 606d8bce11..b557117192 100644 --- a/crm/pengine/native.c +++ b/crm/pengine/native.c @@ -1,1673 +1,1661 @@ -/* $Id: native.c,v 1.70 2005/08/10 08:55:03 andrew Exp $ */ +/* $Id: native.c,v 1.71 2005/08/10 15:38:52 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 color_t *add_color(resource_t *rh_resource, color_t *color); gboolean native_choose_color(resource_t *lh_resource, color_t *no_color); 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_colocation_rh_must(resource_t *rsc_lh, gboolean update_lh, resource_t *rsc_rh, gboolean update_rh); void native_rsc_colocation_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); void create_recurring_actions(resource_t *rsc, action_t *start, node_t *node, pe_working_set_t *data_set); action_t *create_recurring_action(resource_t *rsc, node_t *node, const char *action, const char *key); -void register_state( - resource_t *rsc, action_t *op, node_t *node, crm_data_t *parent); -void register_activity( - resource_t *rsc, action_t *op, node_t *node, crm_data_t *parent); +void register_state(resource_t *rsc, action_t *op, notify_data_t *n_data); +void register_activity(resource_t *rsc, action_t *op, notify_data_t *n_data); void pe_pre_notify( resource_t *rsc, node_t *node, action_t *op, - crm_data_t *parent, pe_working_set_t *data_set); + notify_data_t *n_data, pe_working_set_t *data_set); void pe_post_notify( resource_t *rsc, node_t *node, action_t *op, - crm_data_t *parent, pe_working_set_t *data_set); + notify_data_t *n_data, pe_working_set_t *data_set); extern rsc_to_node_t * rsc2node_new(const char *id, resource_t *rsc, double weight, node_t *node, pe_working_set_t *data_set); 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) \ CRM_ASSERT(rsc->variant == pe_native); \ CRM_ASSERT(rsc->variant_opaque != NULL); \ data = (native_variant_data_t *)rsc->variant_opaque; void native_add_running(resource_t *rsc, node_t *node, pe_working_set_t *data_set) { native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); CRM_DEV_ASSERT(node != NULL); if(crm_assert_failed) { return; } slist_iter( a_node, node_t, native_data->running_on, lpc, CRM_DEV_ASSERT(a_node != NULL); if(safe_str_eq(a_node->details->id, node->details->id)) { return; } ); native_data->running_on = g_list_append(native_data->running_on, node); node->details->running_rsc = g_list_append( node->details->running_rsc, rsc); if(rsc->is_managed == FALSE) { rsc2node_new( "not_managed_default", rsc, INFINITY, node, data_set); return; } else if(rsc->stickiness > 0) { rsc2node_new("stickiness", rsc, INFINITY, node, data_set); } else if(rsc->stickiness < 0) { rsc2node_new("stickiness", rsc, -INFINITY, node, data_set); } if(g_list_length(native_data->running_on) > 1) { pe_warn("Resource %s is (potentially) active on %d nodes." " Latest: %s/%s", rsc->id, g_list_length(native_data->running_on), node->details->uname, node->details->id); } } void native_unpack(resource_t *rsc, pe_working_set_t *data_set) { crm_data_t * xml_obj = rsc->xml; native_variant_data_t *native_data = NULL; const char *version = crm_element_value(xml_obj, XML_ATTR_VERSION); crm_debug_3("Processing resource %s...", rsc->id); crm_malloc0(native_data, sizeof(native_variant_data_t)); crm_malloc0(native_data->agent, sizeof(lrm_agent_t)); native_data->agent->class = crm_element_value(xml_obj, "class"); native_data->agent->type = crm_element_value(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 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 { pe_err("Resource %s was not a \"native\" variant", rsc->id); return 0; } if(native_data->color) { crm_debug_4("Colored case"); num_nodes = 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); crm_debug_4("Candidate colors case"); num_nodes = num_allowed_nodes4color(color); } else { crm_debug_4("Default case"); slist_iter( this_node, node_t, native_data->allowed_nodes, lpc, crm_debug_3("Rsc %s Checking %s: %f", rsc->id, this_node->details->uname, this_node->weight); if(this_node->details->shutdown || this_node->details->online == FALSE) { this_node->weight = -INFINITY; } if(this_node->weight < 0) { continue; /* } else if(this_node->details->unclean) { */ /* continue; */ } num_nodes++; ); } crm_debug_2("Resource %s can run on %d nodes", rsc->id, num_nodes); return num_nodes; } int num_allowed_nodes4color(color_t *color) { 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, crm_debug_3("Checking %s: %f", this_node->details->uname, this_node->weight); if(this_node->details->shutdown || this_node->details->online == FALSE) { this_node->weight = -INFINITY; } if(this_node->weight < 0) { continue; /* } else if(this_node->details->unclean) { */ /* continue; */ } num_nodes++; ); return num_nodes; } void native_color(resource_t *rsc, pe_working_set_t *data_set) { color_t *new_color = NULL; native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); if( native_choose_color(rsc, data_set->no_color) ) { crm_debug_3("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(data_set, rsc, native_data->allowed_nodes); native_assign_color(rsc, new_color); } if(new_color == NULL) { pe_warn("Resource %s cannot run anywhere", rsc->id); print_resource("ERROR: No color", rsc, FALSE); native_assign_color(rsc, data_set->no_color); } } rsc->provisional = FALSE; } void create_recurring_actions(resource_t *rsc, action_t *start, node_t *node, pe_working_set_t *data_set) { action_t *mon = NULL; char *key = NULL; const char *node_uname = NULL; const char *name = NULL; const char *value = NULL; int interval_ms = 0; gboolean is_optional = TRUE; GListPtr possible_matches = NULL; crm_debug_2("Creating recurring actions for %s", rsc->id); if(node != NULL) { node_uname = node->details->uname; } xml_child_iter( rsc->ops_xml, operation, "op", name = crm_element_value(operation, "name"); value = crm_element_value(operation, "interval"); interval_ms = crm_get_msec(value); if(interval_ms <= 0) { continue; } key = generate_op_key(rsc->id, name, interval_ms); possible_matches = find_actions(rsc->actions, key, node); if(start != NULL) { is_optional = start->optional; } else { is_optional = TRUE; } /* start a monitor for an already active resource */ if(possible_matches == NULL) { is_optional = FALSE; } mon = custom_action(rsc, key, name, node, is_optional,data_set); if(start == NULL || start->runnable == FALSE) { crm_warn(" %s:\t(%s) (cancelled : start un-runnable)", mon->uuid, crm_str(node_uname)); mon->runnable = FALSE; } else if(node == NULL || node->details->online == FALSE || node->details->unclean) { crm_warn(" %s:\t(%s) (cancelled : no node available)", mon->uuid, crm_str(node_uname)); mon->runnable = FALSE; } else if(mon->optional == FALSE) { crm_info(" %s:\t(%s)", mon->uuid, crm_str(node_uname)); } custom_action_order(rsc, start_key(rsc), NULL, NULL, crm_strdup(key), mon, pe_ordering_manditory, data_set); ); } void native_create_actions(resource_t *rsc, pe_working_set_t *data_set) { action_t *start = NULL; action_t *stop = NULL; 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; } unpack_instance_attributes(rsc->xml, chosen, rsc->parameters, NULL, 0); if(chosen != NULL && g_list_length(native_data->running_on) == 0) { start = start_action(rsc, chosen, TRUE); if(start->runnable) { crm_info("Start resource %s\t(%s)", rsc->id, chosen->details->uname); start->optional = FALSE; start->rsc->start_pending = TRUE; } } else if(g_list_length(native_data->running_on) > 1) { pe_err("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, lpc, pe_warn("Stop resource %s\t(%s) (recovery)", rsc->id, node->details->uname); stop = stop_action(rsc, node, FALSE); ); } if(rsc->recovery_type == recovery_stop_start && chosen) { /* if one of the "stops" is for a node outside * our partition, then this will block anyway */ start = start_action(rsc, chosen, FALSE); if(start->runnable) { pe_warn("Recover resource %s\t(%s)", rsc->id, chosen->details->uname); } /* make the restart required */ order_stop_start(rsc, rsc, pe_ordering_manditory); } if(rsc->recovery_type == recovery_block) { pe_warn("RESOURCE %s WILL REMAIN ACTIVE ON MULTIPLE" " NODES PENDING MANUAL INTERVENTION", rsc->id); slist_iter( node, node_t, native_data->running_on, lpc, pe_warn("Resource %s active on %s", rsc->id, node->details->uname); ); } } else if(g_list_length(native_data->running_on) == 1) { node_t *node = native_data->running_on->data; crm_debug_2("Stop%s of %s", chosen?" and restart":"", rsc->id); CRM_DEV_ASSERT(node != NULL); if(chosen == NULL) { crm_info("Stop resource %s\t(%s)", rsc->id, node->details->uname); stop_action(rsc, node, FALSE); } else if(safe_str_eq(node->details->id, chosen->details->id)) { stop = stop_action(rsc, node, TRUE); start = start_action(rsc, chosen, TRUE); if(start->runnable == FALSE) { crm_info("Stop resource %s\t(%s)", rsc->id, node->details->uname); stop->optional = FALSE; } else if(rsc->recover) { crm_info("Restart resource %s\t(%s)", rsc->id, node->details->uname); /* make the restart required */ order_stop_start(rsc, rsc, pe_ordering_manditory); start->optional = FALSE; stop->optional = FALSE; } else { crm_info("Leave resource %s\t(%s)", rsc->id, node->details->uname); if(stop->optional == FALSE) { start->optional = FALSE; } else if(rsc->start_pending) { start->optional = FALSE; } } } else { /* move */ stop = stop_action(rsc, node, FALSE); start = start_action(rsc, chosen, FALSE); if(start->runnable) { crm_info("Move resource %s\t(%s -> %s)", rsc->id, node->details->uname, chosen->details->uname); } else { crm_info("Stop resource %s\t(%s)", rsc->id, node->details->uname); } /* make the restart required */ order_stop_start(rsc, rsc, pe_ordering_manditory); } } create_recurring_actions(rsc, start, chosen, data_set); } void native_internal_constraints(resource_t *rsc, pe_working_set_t *data_set) { native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); order_restart(rsc); } void native_rsc_colocation_lh(rsc_colocation_t *constraint) { resource_t *rsc = constraint->rsc_lh; 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); } constraint->rsc_rh->fns->rsc_colocation_rh(rsc, constraint); } void native_rsc_colocation_rh(resource_t *rsc, rsc_colocation_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_debug_2("%sColocating %s with %s", constraint->strength == pecs_must?"":"Anti-", rsc_lh->id, rsc_rh->id); if(constraint->strength == pecs_ignore || constraint->strength == pecs_startstop){ crm_debug_4("Skipping constraint type %d", constraint->strength); return; } if(rsc_lh->provisional && rsc_rh->provisional) { if(constraint->strength == pecs_must) { /* update effective_priorities */ native_rsc_colocation_rh_must( rsc_lh, update_lh, rsc_rh, update_rh); } else { /* nothing */ crm_debug_4( "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 _them_ : postproc color version */ update_rh = TRUE; } else if(rsc_rh->provisional == FALSE && native_data_rh->color->details->pending == FALSE) { /* update _us_ : postproc color alt version */ update_lh = TRUE; } else if(rsc_lh->provisional == FALSE) { /* update _them_ : preproc version */ update_rh = TRUE; } else if(rsc_rh->provisional == FALSE) { /* update _us_ : postproc version */ update_lh = TRUE; } else { pe_warn("Un-expected combination of inputs"); return; } if(update_lh) { crm_debug_4("Updating LHS"); } if(update_rh) { crm_debug_4("Updating RHS"); } if(do_check) { if(native_constraint_violated( rsc_lh, rsc_rh, constraint) == FALSE) { crm_debug_4("Constraint satisfied"); return; } /* else constraint cant be satisified */ pe_warn("Constraint %s could not be satisfied", constraint->id); if(update_lh) { pe_warn("Marking resource %s unrunnable as a result", rsc_lh->id); rsc_lh->runnable = FALSE; } if(update_rh) { pe_warn("Marking resource %s unrunnable as a result", rsc_rh->id); rsc_rh->runnable = FALSE; } } if(constraint->strength == pecs_must) { native_rsc_colocation_rh_must( rsc_lh, update_lh, rsc_rh, update_rh); return; } else if(constraint->strength != pecs_must_not) { /* unknown type */ pe_err("Unknown constraint type %d", constraint->strength); return; } native_rsc_colocation_rh_mustnot(rsc_lh, update_lh,rsc_rh, update_rh); } void native_rsc_order_lh(resource_t *lh_rsc, order_constraint_t *order) { GListPtr lh_actions = NULL; action_t *lh_action = order->lh_action; crm_debug_3("Processing LH of ordering constraint %d", order->id); if(lh_action != NULL) { lh_actions = g_list_append(NULL, lh_action); } else if(lh_action == NULL && lh_rsc != NULL) { #if 0 /* this should be safe to remove */ if(order->strength == pecs_must) { crm_debug_4("No LH-Side (%s/%s) found for constraint..." " creating", lh_rsc->id, order->lh_action_task); pe_err("BROKEN CODE"); custom_action( lh_rsc, order->lh_action_task, NULL, NULL); } #endif lh_actions = find_actions( lh_rsc->actions, order->lh_action_task, NULL); if(lh_actions == NULL) { crm_debug_4("No LH-Side (%s/%s) found for constraint", lh_rsc->id, order->lh_action_task); if(order->rh_rsc != NULL) { crm_debug_4("RH-Side was: (%s/%s)", order->rh_rsc->id, order->rh_action_task); } else if(order->rh_action != NULL && order->rh_action->rsc != NULL) { crm_debug_4("RH-Side was: (%s/%s)", order->rh_action->rsc->id, order->rh_action_task); } else if(order->rh_action != NULL) { crm_debug_4("RH-Side was: %s", order->rh_action_task); } else { crm_debug_4("RH-Side was NULL"); } return; } } else { pe_warn("No LH-Side (%s) specified for constraint", order->lh_action_task); if(order->rh_rsc != NULL) { crm_debug_4("RH-Side was: (%s/%s)", order->rh_rsc->id, order->rh_action_task); } else if(order->rh_action != NULL && order->rh_action->rsc != NULL) { crm_debug_4("RH-Side was: (%s/%s)", order->rh_action->rsc->id, order->rh_action_task); } else if(order->rh_action != NULL) { crm_debug_4("RH-Side was: %s", order->rh_action_task); } else { crm_debug_4("RH-Side was NULL"); } 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) { GListPtr rh_actions = NULL; action_t *rh_action = order->rh_action; crm_debug_3("Processing RH of ordering constraint %d", order->id); 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_4("No RH-Side (%s/%s) found for constraint..." " ignoring", rsc->id, order->rh_action_task); crm_debug_4("LH-Side was: (%s/%s)", order->lh_rsc?order->lh_rsc->id:order->lh_action?order->lh_action->rsc->id:"", order->lh_action_task); return; } } else if(rh_action == NULL) { crm_debug_4("No RH-Side (%s) specified for constraint..." " ignoring", order->rh_action_task); crm_debug_4("LH-Side was: (%s/%s)", order->lh_rsc?order->lh_rsc->id:order->lh_action?order->lh_action->rsc->id:"", 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) { GListPtr or_list; native_variant_data_t *native_data = NULL; crm_action_debug_3(print_rsc_to_node("Applying", constraint, FALSE)); /* take "lifetime" into account */ if(constraint == NULL) { pe_err("Constraint is NULL"); return; } else if(is_active(constraint) == FALSE) { crm_debug_2("Constraint (%s) is not active", constraint->id); return; } else if(rsc == NULL) { pe_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_debug_2("RHS of constraint %s is NULL", constraint->id); return; } crm_action_debug_3(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_action_debug_3(print_resource("after update", rsc, TRUE)); } void native_expand(resource_t *rsc, pe_working_set_t *data_set) { slist_iter( action, action_t, rsc->actions, lpc, crm_debug_4("processing action %d for rsc=%s", action->id, rsc->id); graph_element_from_action(action, data_set); ); } gboolean native_active(resource_t *rsc, gboolean all) { native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); slist_iter( a_node, node_t, native_data->running_on, lpc, if(a_node->details->online == FALSE) { crm_debug("Resource %s: node %s is offline", rsc->id, a_node->details->uname); } else if(a_node->details->unclean) { crm_debug("Resource %s: node %s is unclean", rsc->id, a_node->details->uname); } else { crm_debug("Resource %s active on %s", rsc->id, a_node->details->uname); return TRUE; } ); return FALSE; } void native_printw(resource_t *rsc, const char *pre_text, int *index) { #if CURSES_ENABLED native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); common_printw(rsc, pre_text, index); if(rsc->is_managed == FALSE) { printw(" (unmanaged) "); } if(g_list_length(native_data->running_on) == 0) { printw("NOT ACTIVE"); } else if(g_list_length(native_data->running_on) == 1) { node_t *node = native_data->running_on->data; printw("%s (%s)", node->details->uname, node->details->id); if(rsc->unclean) { printw(" FAILED"); } } else if(g_list_length(native_data->running_on) == 1) { printw("["); slist_iter(node, node_t, native_data->running_on, lpc, if(lpc > 0) { printw(", "); } printw("%s (%s)", node->details->uname, node->details->id); ); printw("]"); } printw("\n"); #else crm_err("printw support requires ncurses to be available during configure"); #endif } void native_html(resource_t *rsc, const char *pre_text, FILE *stream) { native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); if(rsc->is_managed == FALSE) { fprintf(stream, ""); } common_html(rsc, pre_text, stream); if(rsc->is_managed == FALSE) { fprintf(stream, " (unmanaged) "); } if(rsc->unclean) { fprintf(stream, ""); } else if(g_list_length(native_data->running_on) == 0) { fprintf(stream, ""); } else if(g_list_length(native_data->running_on) > 1) { fprintf(stream, ""); } else { fprintf(stream, ""); } if(g_list_length(native_data->running_on) == 0) { fprintf(stream, "NOT ACTIVE"); } else if(g_list_length(native_data->running_on) == 1) { node_t *node = native_data->running_on->data; fprintf(stream, "%s (%s)", node->details->uname, node->details->id); } else if(g_list_length(native_data->running_on) > 1) { fprintf(stream, "
    \n"); slist_iter(node, node_t, native_data->running_on, lpc, fprintf(stream, "
  • %s (%s)
  • \n", node->details->uname, node->details->id); ); fprintf(stream, "
\n"); } fprintf(stream, "

\n"); } 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_4("\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) { crm_debug_4("\t=== Actions"); slist_iter( action, action_t, rsc->actions, lpc, print_action("\trsc action: ", action, FALSE); ); crm_debug_4("\t=== Colors"); slist_iter( color, color_t, rsc->candidate_colors, lpc, print_color("\t", color, FALSE) ); crm_debug_4("\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_4("Freeing Allowed Nodes & Agent"); crm_free(native_data->color); pe_free_shallow(native_data->allowed_nodes); crm_free(native_data->agent); common_free(rsc); } void native_rsc_colocation_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 && rsc_rh != rsc_lh) { CRM_DEV_ASSERT(native_data_lh->color != native_data_rh->color); crm_free(native_data_lh->color); rsc_lh->runnable = rsc_rh->runnable; rsc_lh->provisional = rsc_rh->provisional; native_data_lh->color = copy_color(native_data_rh->color); } if(update_rh && rsc_rh != rsc_lh) { CRM_DEV_ASSERT(native_data_lh->color != native_data_rh->color); crm_free(native_data_rh->color); rsc_rh->runnable = rsc_lh->runnable; rsc_rh->provisional = rsc_lh->provisional; native_data_rh->color = copy_color(native_data_lh->color); } if((update_rh || update_lh) && do_merge) { crm_debug_4("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_4("Finished processing pecs_must constraint"); } void native_rsc_colocation_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_4("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_action_debug_3( print_color("Removed LH", color_lh, FALSE)); crm_action_debug_3( 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_action_debug_3( print_node("Removed LH", node_lh, FALSE)); crm_action_debug_3( print_color("Modified LH", color_lh, FALSE)); crm_free(node_lh); } else { /* error, rsc marked as unrunnable above */ pe_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_action_debug_3( print_color("Removed RH", color_rh, FALSE)); crm_action_debug_3( 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_action_debug_3( print_node("Removed RH", node_rh, FALSE)); crm_action_debug_3( print_color("Modified RH", color_rh, FALSE)); crm_free(node_rh); } else { /* error, rsc marked as unrunnable above */ pe_warn("rh else"); } } } void native_agent_constraints(resource_t *rsc) { } gboolean native_choose_color(resource_t *rsc, color_t *no_color) { GListPtr sorted_colors = NULL; native_variant_data_t *native_data = NULL; get_native_variant_data(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_debug_3("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) { pe_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 = copy_color(local_color); rsc->provisional = FALSE; if(local_color != NULL) { (local_color->details->num_resources)++; 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_debug_3("Colored resource %s with new color %d", rsc->id, native_data->color->id); crm_action_debug_3( print_resource("Colored Resource", rsc, TRUE)); } else { pe_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) { pe_err("Node not found - cant update"); return; } if(node_rh->weight >= INFINITY && cons->weight <= -INFINITY) { pe_err("Constraint %s mixes +/- INFINITY", cons->id); } else if(node_rh->weight <= -INFINITY && cons->weight >= INFINITY) { pe_err("Constraint %s mixes +/- INFINITY", cons->id); } if(node_rh->fixed) { /* warning */ crm_debug_2("Constraint %s is irrelevant as the" " weight of node %s is fixed as %f.", cons->id, node_rh->details->uname, node_rh->weight); return; } if(cons->weight >= INFINITY && cons->weight <= -INFINITY) { crm_debug_3("Constraint %s (%f): node %s weight %f.", cons->id, cons->weight, node_rh->details->uname, node_rh->weight); } else if(cons->weight <= -INFINITY) { crm_debug_3("Constraint %s (-INFINITY): node %s weight %f.", cons->id, node_rh->details->uname, node_rh->weight); } else { crm_debug_3("Constraint %s (+INFINITY): node %s weight %f.", cons->id, node_rh->details->uname, node_rh->weight); } node_rh->weight = merge_weights(node_rh->weight, cons->weight); if(node_rh->weight < 0) { node_rh->fixed = TRUE; } crm_action_debug_3(print_node("Updated", node_rh, FALSE)); return; } gboolean native_constraint_violated( resource_t *rsc_lh, resource_t *rsc_rh, rsc_colocation_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(native_data_lh, rsc_lh); get_native_variant_data(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) { native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); crm_action_debug_3(print_resource("Filtering nodes for", rsc, FALSE)); slist_iter( node, node_t, native_data->allowed_nodes, lpc, if(node == NULL) { pe_err("Invalid NULL node"); } else if(node->weight < 0.0 || node->details->shutdown || node->details->online == FALSE || node->details->type == node_ping) { crm_action_debug_3(print_node("Removing", node, FALSE)); native_data->allowed_nodes = g_list_remove(native_data->allowed_nodes, node); crm_free(node); lpc = -1; /* restart the loop */ } ); } rsc_state_t native_resource_state(resource_t *rsc) { enum action_tasks task = no_action; rsc_state_t state = rsc_state_unknown; native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); slist_iter( action, action_t, rsc->actions, lpc, crm_debug_4("processing action %d for rsc=%s", action->id, rsc->id); task = text2task(action->task); if(action->optional) { continue; } if(task == stop_rsc) { if(state == rsc_state_starting) { state = rsc_state_restart; break; } else { state = rsc_state_stopping; } } else if(task == start_rsc) { if(state == rsc_state_stopping) { state = rsc_state_restart; break; } else { state = rsc_state_starting; } } ); if(native_data->running_on != NULL) { node_t *chosen = NULL; node_t *node = native_data->running_on->data; if(native_data->color != NULL) { chosen = native_data->color->details->chosen_node; } if(state == rsc_state_unknown) { state = rsc_state_active; } else if(state == rsc_state_restart) { CRM_DEV_ASSERT(chosen != NULL && node != NULL); if(crm_assert_failed) { crm_err("State for %s is unreliable", rsc->id); } else if(safe_str_neq(node->details->id, chosen->details->id)) { state = rsc_state_move; } } } else if(state == rsc_state_unknown) { state = rsc_state_stopped; } return state; } void -native_create_notify_element(resource_t *rsc, action_t *op, crm_data_t *parent, - pe_working_set_t *data_set) +native_create_notify_element(resource_t *rsc, action_t *op, + notify_data_t *n_data, pe_working_set_t *data_set) { node_t *next = NULL; node_t *current = NULL; enum action_tasks task; rsc_state_t state = rsc->fns->state(rsc); native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); if(native_data->color != NULL) { next = native_data->color->details->chosen_node; } if(native_data->running_on != NULL) { current = native_data->running_on->data; } if(op->pre_notify == NULL || op->post_notify == NULL) { /* no notifications required */ crm_debug_4("No notificaitons required for %s", op->task); return; } crm_debug_2("Notificaitons required for %s", op->task); task = text2task(op->task); switch(state) { case rsc_state_active: - pe_pre_notify(rsc, current, op, parent, data_set); - pe_post_notify(rsc, current, op, parent, data_set); - register_state(rsc, op, current, parent); + pe_pre_notify(rsc, current, op, n_data, data_set); + pe_post_notify(rsc, current, op, n_data, data_set); + register_state(rsc, op, n_data); break; case rsc_state_move: if(task == stop_rsc) { - pe_pre_notify(rsc, current, op,parent,data_set); - register_activity(rsc, op, current, parent); + pe_pre_notify(rsc, current, op,n_data,data_set); + register_activity(rsc, op, n_data); } else { - pe_post_notify(rsc, next, op, parent, data_set); - register_activity(rsc, op, next, parent); + pe_post_notify(rsc, next, op, n_data, data_set); + register_activity(rsc, op, n_data); } break; case rsc_state_restart: - register_activity(rsc, op, current, parent); + register_activity(rsc, op, n_data); if(task == stop_rsc) { - pe_pre_notify(rsc, current, op, parent, data_set); + pe_pre_notify(rsc, current, op, n_data, data_set); } else { - pe_post_notify(rsc, current,op,parent,data_set); + pe_post_notify(rsc, current,op,n_data,data_set); } break; case rsc_state_starting: if(task != stop_rsc) { - register_activity(rsc, op, next, parent); - pe_post_notify(rsc, next, op, parent, data_set); + register_activity(rsc, op, n_data); + pe_post_notify(rsc, next, op, n_data, data_set); } break; case rsc_state_stopping: if(task == stop_rsc) { - register_activity(rsc, op, current, parent); - pe_pre_notify(rsc, current, op,parent,data_set); + register_activity(rsc, op, n_data); + pe_pre_notify(rsc, current, op,n_data,data_set); } break; case rsc_state_stopped: case rsc_state_unknown: return; break; } } void -register_activity( - resource_t *rsc, action_t *op, node_t *node, crm_data_t *parent) +register_activity(resource_t *rsc, action_t *op, notify_data_t *n_data) { - crm_data_t *target = NULL; -/* const char *value = NULL; */ - -/* value = g_hash_table_lookup(op->extra, "notify_type"); */ -/* if(safe_str_neq(value, "pre")) { */ -/* /\* only add once *\/ */ -/* return; */ -/* } */ - - CRM_DEV_ASSERT(node != NULL); + notify_entry_t *entry = NULL; + native_variant_data_t *native_data = NULL; + get_native_variant_data(native_data, rsc); + + if(safe_str_eq(op->task, CRMD_ACTION_START)) { + crm_malloc0(entry, sizeof(notify_entry_t)); + entry->rsc = rsc; + if(native_data->color != NULL) { + entry->node = native_data->color->details->chosen_node; + } + n_data->start = g_list_append(n_data->start, entry); + + } else { + slist_iter( + node, node_t, native_data->running_on, lpc, - if(find_entity(parent, op->task, rsc->id) != NULL) { - /* only add once */ - return; + crm_malloc0(entry, sizeof(notify_entry_t)); + entry->rsc = rsc; + entry->node = node; + n_data->stop=g_list_append(n_data->stop, entry); + ); } - - crm_debug_3("Creating entry for %s: %s (%s)",op->uuid,rsc->id,op->task); - - target = create_xml_node(parent, op->task); - crm_xml_add(target, XML_ATTR_ID, rsc->id); - crm_xml_add(target, XML_LRM_ATTR_TARGET, node->details->uname); - crm_xml_add(target, XML_LRM_ATTR_TARGET_UUID, node->details->id); } void -register_state( - resource_t *rsc, action_t *op, node_t *node, crm_data_t *parent) +register_state(resource_t *rsc, action_t *op, notify_data_t *n_data) { - crm_data_t *target = NULL; -/* const char *value = NULL; */ - -/* value = g_hash_table_lookup(op->extra, "notify_type"); */ -/* if(safe_str_neq(value, "pre")) { */ -/* /\* only add once *\/ */ -/* return; */ -/* } */ + notify_entry_t *entry = NULL; + native_variant_data_t *native_data = NULL; + get_native_variant_data(native_data, rsc); - CRM_DEV_ASSERT(node != NULL); + crm_malloc0(entry, sizeof(notify_entry_t)); + entry->rsc = rsc; + if(native_data->color != NULL) { + entry->node = native_data->color->details->chosen_node; + } - if(find_entity(parent, "peer", rsc->id) != NULL) { - /* only add once */ - return; + if(entry->node != NULL) { + n_data->active = g_list_append(n_data->active, entry); + } else { + n_data->inactive = g_list_append(n_data->inactive, entry); } - - crm_debug_3("Creating peer entry for %s: %s (%s)", - op->uuid, rsc->id, op->task); - - target = create_xml_node(parent, "peer"); - crm_xml_add(target, XML_ATTR_ID, rsc->id); - crm_xml_add(target, XML_LRM_ATTR_TARGET, node->details->uname); - crm_xml_add(target, XML_LRM_ATTR_TARGET_UUID, node->details->id); } static void dup_attr(gpointer key, gpointer value, gpointer user_data) { g_hash_table_replace(user_data, crm_strdup(key), crm_strdup(value)); } static void pe_notify(resource_t *rsc, node_t *node, action_t *op, action_t *confirm, - crm_data_t *parent, pe_working_set_t *data_set) + notify_data_t *n_data, pe_working_set_t *data_set) { char *key = NULL; action_t *trigger = NULL; action_wrapper_t *wrapper = NULL; const char *value = NULL; const char *task = NULL; if(op == NULL || confirm == NULL) { return; } CRM_DEV_ASSERT(node != NULL); value = g_hash_table_lookup(op->extra, "notify_type"); task = g_hash_table_lookup(op->extra, "notify_operation"); crm_debug_2("Creating actions for %s: %s (%s-%s)", op->uuid, rsc->id, value, task); key = generate_notify_key(rsc->id, value, task); - - trigger = custom_action( - rsc, key, op->task, node, op->optional, data_set); + trigger = custom_action(rsc, key, op->task, node,op->optional,data_set); g_hash_table_foreach(op->extra, dup_attr, trigger->extra); - trigger->extra_xml = parent; + trigger->notify_keys = n_data->keys; /* pseudo_notify before notify */ crm_debug_3("Ordering %s before %s (%d->%d)", op->uuid, trigger->uuid, trigger->id, op->id); + crm_malloc0(wrapper, sizeof(action_wrapper_t)); wrapper->action = op; wrapper->type = pe_ordering_manditory; - - trigger->actions_before = g_list_append( - trigger->actions_before, wrapper); + trigger->actions_before=g_list_append(trigger->actions_before, wrapper); wrapper = NULL; crm_malloc0(wrapper, sizeof(action_wrapper_t)); wrapper->action = trigger; wrapper->type = pe_ordering_manditory; - op->actions_after = g_list_append( - op->actions_after, wrapper); + op->actions_after = g_list_append(op->actions_after, wrapper); - /* notify before pseudo_notified */ - crm_debug_3("Ordering %s before %s (%d->%d)", - trigger->uuid, confirm->uuid, confirm->id, trigger->id); + + value = g_hash_table_lookup(op->extra, "notify_confirm"); if(crm_is_true(value)) { + /* notify before pseudo_notified */ + crm_debug_3("Ordering %s before %s (%d->%d)", + trigger->uuid, confirm->uuid, + confirm->id, trigger->id); + wrapper = NULL; crm_malloc0(wrapper, sizeof(action_wrapper_t)); wrapper->action = trigger; wrapper->type = pe_ordering_manditory; confirm->actions_before = g_list_append( confirm->actions_before, wrapper); wrapper = NULL; crm_malloc0(wrapper, sizeof(action_wrapper_t)); wrapper->action = confirm; wrapper->type = pe_ordering_manditory; trigger->actions_after = g_list_append( trigger->actions_after, wrapper); } } void pe_pre_notify(resource_t *rsc, node_t *node, action_t *op, - crm_data_t *parent, pe_working_set_t *data_set) + notify_data_t *n_data, pe_working_set_t *data_set) { pe_notify(rsc, node, op->pre_notify, op->pre_notified, - parent, data_set); + n_data, data_set); } void pe_post_notify(resource_t *rsc, node_t *node, action_t *op, - crm_data_t *parent, pe_working_set_t *data_set) + notify_data_t *n_data, pe_working_set_t *data_set) { pe_notify(rsc, node, op->post_notify, op->post_notified, - parent, data_set); + n_data, data_set); } diff --git a/crm/pengine/pengine.h b/crm/pengine/pengine.h index 1f0891c907..fef37e8b22 100644 --- a/crm/pengine/pengine.h +++ b/crm/pengine/pengine.h @@ -1,427 +1,426 @@ -/* $Id: pengine.h,v 1.80 2005/08/10 08:55:04 andrew Exp $ */ +/* $Id: pengine.h,v 1.81 2005/08/10 15:38:52 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_colocation_s rsc_colocation_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 #include /* * The man pages for both curses and ncurses suggest inclusion of "curses.h". * We believe the following to be acceptable and portable. */ #if defined(HAVE_NCURSES_H) # include # define CURSES_ENABLED 1 #elif defined(HAVE_CURSES_H) # include # define CURSES_ENABLED 1 #else # define CURSES_ENABLED 0 #endif typedef enum no_quorum_policy_e { no_quorum_freeze, no_quorum_stop, no_quorum_ignore } no_quorum_policy_t; typedef enum rsc_state_e { rsc_state_unknown, rsc_state_active, rsc_state_stopped, rsc_state_starting, rsc_state_stopping, rsc_state_restart, rsc_state_move } rsc_state_t; typedef struct pe_working_set_s { crm_data_t *input; /* options extracted from the input */ char *dc_uuid; node_t *dc_node; gboolean have_quorum; gboolean stonith_enabled; gboolean symmetric_cluster; int default_resource_stickiness; no_quorum_policy_t no_quorum_policy; /* intermediate steps */ color_t *no_color; GListPtr nodes; GListPtr resources; GListPtr placement_constraints; GListPtr ordering_constraints; GListPtr colors; GListPtr actions; /* stats */ int num_synapse; int max_valid_nodes; int order_id; int action_id; int color_id; /* final output */ crm_data_t *graph; } pe_working_set_t; #include enum con_type { type_none, rsc_colocation, 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, monitor_rsc, stop_rsc, stopped_rsc, start_rsc, started_rsc, action_notify, action_notified, shutdown_crm, stonith_node }; enum rsc_recovery_type { recovery_stop_start, recovery_stop_only, recovery_block }; enum rsc_start_requirement { rsc_req_nothing, rsc_req_quorum, rsc_req_stonith }; enum pe_stop_fail { pesf_block, pesf_stonith, pesf_ignore }; enum pe_restart { pe_restart_restart, pe_restart_ignore }; enum pe_ordering { pe_ordering_manditory, pe_ordering_restart, pe_ordering_recover, pe_ordering_postnotify, pe_ordering_optional }; struct node_shared_s { const char *id; const char *uname; gboolean online; gboolean unclean; gboolean shutdown; gboolean expected_up; gboolean is_dc; int num_resources; GListPtr running_rsc; /* resource_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; int num_resources; }; struct color_s { int id; struct color_shared_s *details; float local_weight; }; struct rsc_colocation_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* */ }; struct lrm_agent_s { const char *class; const char *type; const char *version; }; struct resource_s { const char *id; crm_data_t *xml; crm_data_t *ops_xml; void *variant_opaque; enum pe_obj_types variant; resource_object_functions_t *fns; enum rsc_recovery_type recovery_type; enum pe_restart restart_type; float priority; float stickiness; float effective_priority; gboolean notify; gboolean is_managed; gboolean start_pending; gboolean recover; gboolean starting; gboolean stopping; gboolean runnable; gboolean provisional; gboolean unclean; GListPtr candidate_colors; /* color_t* */ GListPtr rsc_cons; /* rsc_colocation_t* */ GListPtr actions; /* action_t* */ GHashTable * parameters; }; struct action_wrapper_s { enum pe_ordering type; action_t *action; }; enum action_fail_response { action_fail_nothing, action_fail_block, action_fail_stop, action_fail_fence }; struct action_s { int id; resource_t *rsc; void *rsc_opaque; node_t *node; const char *task; char *uuid; crm_data_t *op_entry; gboolean pseudo; gboolean runnable; gboolean optional; gboolean failure_is_fatal; enum rsc_start_requirement needs; enum action_fail_response on_fail; gboolean dumped; gboolean processed; action_t *pre_notify; action_t *pre_notified; action_t *post_notify; action_t *post_notified; int seen_count; GHashTable *extra; - crm_data_t *extra_xml; + GHashTable *notify_keys; /* do NOT free */ GListPtr actions_before; /* action_warpper_t* */ GListPtr actions_after; /* action_warpper_t* */ }; struct order_constraint_s { int id; enum pe_ordering type; void *lh_opaque; resource_t *lh_rsc; action_t *lh_action; char *lh_action_task; void *rh_opaque; resource_t *rh_rsc; action_t *rh_action; char *rh_action_task; /* (soon to be) variant specific */ /* int lh_rsc_incarnation; */ /* int rh_rsc_incarnation; */ }; - extern gboolean stage0(pe_working_set_t *data_set); extern gboolean stage1(pe_working_set_t *data_set); extern gboolean stage2(pe_working_set_t *data_set); extern gboolean stage3(pe_working_set_t *data_set); extern gboolean stage4(pe_working_set_t *data_set); extern gboolean stage5(pe_working_set_t *data_set); extern gboolean stage6(pe_working_set_t *data_set); extern gboolean stage7(pe_working_set_t *data_set); extern gboolean stage8(pe_working_set_t *data_set); extern gboolean summary(GListPtr resources); extern gboolean pe_msg_dispatch(IPC_Channel *sender, void *user_data); extern gboolean process_pe_message( HA_Message *msg, crm_data_t *xml_data, IPC_Channel *sender); extern gboolean unpack_constraints( crm_data_t *xml_constraints, pe_working_set_t *data_set); extern gboolean unpack_resources( crm_data_t *xml_resources, pe_working_set_t *data_set); extern gboolean unpack_config(crm_data_t *config, pe_working_set_t *data_set); extern gboolean unpack_nodes(crm_data_t *xml_nodes, pe_working_set_t *data_set); extern gboolean unpack_status(crm_data_t *status, pe_working_set_t *data_set); extern gboolean apply_placement_constraints(pe_working_set_t *data_set); extern void color_resource(resource_t *lh_resource, pe_working_set_t *data_set); 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, pe_working_set_t *data_set); extern gboolean stonith_constraints( node_t *node, action_t *stonith_op, action_t *shutdown_op, pe_working_set_t *data_set); extern gboolean custom_action_order( resource_t *lh_rsc, char *lh_task, action_t *lh_action, resource_t *rh_rsc, char *rh_task, action_t *rh_action, enum pe_ordering type, pe_working_set_t *data_set); #define order_start_start(rsc1,rsc2, type) \ custom_action_order(rsc1, start_key(rsc1), NULL, \ rsc2, start_key(rsc2) ,NULL, \ type, data_set) #define order_stop_stop(rsc1, rsc2, type) \ custom_action_order(rsc1, stop_key(rsc1), NULL, \ rsc2, stop_key(rsc2) ,NULL, \ type, data_set) #define order_restart(rsc1) \ custom_action_order(rsc1, stop_key(rsc1), NULL, \ rsc1, start_key(rsc1), NULL, \ pe_ordering_restart, data_set) #define order_stop_start(rsc1, rsc2, type) \ custom_action_order(rsc1, stop_key(rsc1), NULL, \ rsc2, start_key(rsc2) ,NULL, \ type, data_set) #define order_start_stop(rsc1, rsc2, type) \ custom_action_order(rsc1, start_key(rsc1), NULL, \ rsc2, stop_key(rsc2) ,NULL, \ type, data_set) #define pe_err(fmt...) { was_processing_error = TRUE; crm_err(fmt); } #define pe_warn(fmt...) { was_processing_warning = TRUE; crm_warn(fmt); } #define check_and_exit(stage) cleanup_calculations(data_set); \ crm_mem_stats(NULL); \ crm_err("Exiting: stage %d", stage); \ exit(1); extern gboolean process_colored_constraints(resource_t *rsc); extern void graph_element_from_action( action_t *action, pe_working_set_t *data_set); extern void set_working_set_defaults(pe_working_set_t *data_set); extern void cleanup_calculations(pe_working_set_t *data_set); extern const char* transition_idle_timeout; extern gboolean was_processing_error; extern gboolean was_processing_warning; #endif diff --git a/crm/pengine/testcases/notify-1.exp b/crm/pengine/testcases/notify-1.exp index 51f03ff1aa..3e01b8c6bf 100644 --- a/crm/pengine/testcases/notify-1.exp +++ b/crm/pengine/testcases/notify-1.exp @@ -1,316 +1,308 @@ + + + + + + - - - - + + + + + + - - - - + + + + + + - - - - - - - - - - - - + + + - - - - - - - - - diff --git a/crm/pengine/testcases/notify-2.exp b/crm/pengine/testcases/notify-2.exp index 51f03ff1aa..3e01b8c6bf 100644 --- a/crm/pengine/testcases/notify-2.exp +++ b/crm/pengine/testcases/notify-2.exp @@ -1,316 +1,308 @@ + + + + + + - - - - + + + + + + - - - - + + + + + + - - - - - - - - - - - - + + + - - - - - - - - - diff --git a/crm/pengine/testcases/notify-3.exp b/crm/pengine/testcases/notify-3.exp index 36713fef5f..5b8d536fa5 100644 --- a/crm/pengine/testcases/notify-3.exp +++ b/crm/pengine/testcases/notify-3.exp @@ -1,519 +1,517 @@ + + + + + + + + + - - - - - + + + + + + + + + - - - - - + + + + + + + + + - - - - - + + + + + + + + + - - - - - + + + + + + + + + - - - - - + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - - - - - - -