diff --git a/crm/pengine/complex.c b/crm/pengine/complex.c index c76756e452..bce0919a52 100644 --- a/crm/pengine/complex.c +++ b/crm/pengine/complex.c @@ -1,554 +1,549 @@ -/* $Id: complex.c,v 1.55 2005/08/11 08:58:40 andrew Exp $ */ +/* $Id: complex.c,v 1.56 2005/08/17 09:15:13 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 gboolean update_node_weight(rsc_to_node_t *cons,const char *id,GListPtr nodes); gboolean is_active(rsc_to_node_t *cons); gboolean constraint_violated( resource_t *rsc_lh, resource_t *rsc_rh, rsc_colocation_t *constraint); void order_actions(action_t *lh, action_t *rh, order_constraint_t *order); gboolean has_agent(node_t *a_node, lrm_agent_t *an_agent); extern gboolean rsc_colocation_new(const char *id, enum con_strength strength, resource_t *rsc_lh, resource_t *rsc_rh); extern rsc_to_node_t *rsc2node_new( const char *id, resource_t *rsc, double weight, node_t *node, pe_working_set_t *data_set); rsc_to_node_t *generate_location_rule( resource_t *rsc, crm_data_t *location_rule, pe_working_set_t *data_set); void populate_hash(crm_data_t *nvpair_list, GHashTable *hash, const char **attrs, int attrs_length); resource_object_functions_t resource_class_functions[] = { { native_unpack, native_find_child, native_num_allowed_nodes, native_color, native_create_actions, native_internal_constraints, native_agent_constraints, native_rsc_colocation_lh, native_rsc_colocation_rh, native_rsc_order_lh, native_rsc_order_rh, native_rsc_location, native_expand, native_dump, native_printw, native_html, native_active, native_resource_state, native_create_notify_element, native_free }, { group_unpack, group_find_child, group_num_allowed_nodes, group_color, group_create_actions, group_internal_constraints, group_agent_constraints, group_rsc_colocation_lh, group_rsc_colocation_rh, group_rsc_order_lh, group_rsc_order_rh, group_rsc_location, group_expand, group_dump, group_printw, group_html, group_active, group_resource_state, group_create_notify_element, group_free }, { clone_unpack, clone_find_child, clone_num_allowed_nodes, clone_color, clone_create_actions, clone_internal_constraints, clone_agent_constraints, clone_rsc_colocation_lh, clone_rsc_colocation_rh, clone_rsc_order_lh, clone_rsc_order_rh, clone_rsc_location, clone_expand, clone_dump, clone_printw, clone_html, clone_active, clone_resource_state, clone_create_notify_element, clone_free } }; /* resource_object_functions_t resource_variants[] = resource_class_functions; */ int get_resource_type(const char *name) { if(safe_str_eq(name, XML_CIB_TAG_RESOURCE)) { return pe_native; } else if(safe_str_eq(name, XML_CIB_TAG_GROUP)) { return pe_group; } else if(safe_str_eq(name, XML_CIB_TAG_INCARNATION)) { return pe_clone; } return pe_unknown; } gboolean is_active(rsc_to_node_t *cons) { /* todo: check constraint lifetime */ return TRUE; } - -void -inherit_parent_attributes( - crm_data_t *parent, crm_data_t *child, gboolean overwrite) +static void dup_attr(gpointer key, gpointer value, gpointer user_data) { - int lpc = 0; - const char *attributes[] = { - XML_RSC_ATTR_STOPFAIL, - XML_RSC_ATTR_RESTART, - "multiple_active", - "start_prereq", - "resource_stickiness", - "notify", - "is_managed" - }; - - for(lpc = 0; lpc < DIMOF(attributes); lpc++) { - const char *attr_p = crm_element_value(parent, attributes[lpc]); - const char *attr_c = crm_element_value(child, attributes[lpc]); - - if(attr_p == NULL) { - continue; - } else if(safe_str_eq(attr_p, attr_c)) { - continue; - } - - if(attr_c != NULL && overwrite == FALSE) { - crm_debug_2("Resource %s: ignoring parent value for %s", - ID(child), attributes[lpc]); - continue; - } else if(attr_c != NULL) { - pe_warn("Resource %s: Overwriting attribute %s: %s->%s", - ID(child), attributes[lpc], attr_c, attr_p); - } - crm_xml_add(child, attributes[lpc], attr_p); - } + add_hash_param(user_data, key, value); } gboolean -common_unpack( - crm_data_t * xml_obj, resource_t **rsc, pe_working_set_t *data_set) +common_unpack(crm_data_t * xml_obj, resource_t **rsc, + GHashTable *defaults, pe_working_set_t *data_set) { - const char *id = crm_element_value(xml_obj, XML_ATTR_ID); - const char *restart = crm_element_value(xml_obj, XML_RSC_ATTR_RESTART); - const char *multiple = crm_element_value(xml_obj, "multiple_active"); - const char *placement = crm_element_value(xml_obj, "resource_stickiness"); - const char *notify = crm_element_value(xml_obj, "notify"); - const char *priority = NULL; - const char *is_managed = NULL; + int lpc = 0; + const char *id = crm_element_value(xml_obj, XML_ATTR_ID); + const char *value = NULL; const char *allowed_attrs[] = { XML_CIB_ATTR_PRIORITY, XML_RSC_ATTR_INCARNATION_MAX, - XML_RSC_ATTR_INCARNATION_NODEMAX + XML_RSC_ATTR_INCARNATION_NODEMAX, + "resource_stickiness" }; + const char *rsc_attrs[] = { + XML_RSC_ATTR_STOPFAIL, + XML_RSC_ATTR_RESTART, + "resource_stickiness", + "multiple_active", + "start_prereq", + "is_managed", + "notify" + }; + crm_log_xml_debug_2(xml_obj, "Processing resource input..."); if(id == NULL) { pe_err("Must specify id tag in "); return FALSE; } else if(rsc == NULL) { pe_err("Nowhere to unpack resource into"); return FALSE; } crm_malloc0(*rsc, sizeof(resource_t)); if(*rsc == NULL) { return FALSE; } (*rsc)->id = id; (*rsc)->xml = xml_obj; (*rsc)->ops_xml = find_xml_node(xml_obj, "operations", FALSE); (*rsc)->variant = get_resource_type(crm_element_name(xml_obj)); if((*rsc)->variant == pe_unknown) { pe_err("Unknown resource type: %s", crm_element_name(xml_obj)); crm_free(*rsc); return FALSE; } (*rsc)->fns = &resource_class_functions[(*rsc)->variant]; crm_debug_3("Unpacking resource..."); (*rsc)->parameters = g_hash_table_new_full( g_str_hash,g_str_equal, g_hash_destroy_str,g_hash_destroy_str); - unpack_instance_attributes(xml_obj, NULL, (*rsc)->parameters, - allowed_attrs, DIMOF(allowed_attrs), data_set); - - priority = get_rsc_param(*rsc, XML_CIB_ATTR_PRIORITY); + for(lpc = 0; lpc < DIMOF(rsc_attrs); lpc++) { + value = crm_element_value(xml_obj, rsc_attrs[lpc]); + if(value != NULL) { + add_hash_param( + (*rsc)->parameters, rsc_attrs[lpc], value); + } + } + + unpack_instance_attributes( + xml_obj, XML_TAG_ATTR_SETS, NULL, (*rsc)->parameters, + allowed_attrs, DIMOF(allowed_attrs), data_set); - (*rsc)->priority = atoi(priority?priority:"0"); - (*rsc)->effective_priority = (*rsc)->priority; - (*rsc)->recovery_type = recovery_stop_start; + if(defaults != NULL) { + g_hash_table_foreach(defaults, dup_attr, (*rsc)->parameters); + } + (*rsc)->runnable = TRUE; (*rsc)->provisional = TRUE; (*rsc)->start_pending = FALSE; (*rsc)->starting = FALSE; (*rsc)->stopping = FALSE; - (*rsc)->notify = crm_is_true(notify); + (*rsc)->candidate_colors = NULL; (*rsc)->rsc_cons = NULL; (*rsc)->actions = NULL; (*rsc)->is_managed = TRUE; + + (*rsc)->recovery_type = recovery_stop_start; (*rsc)->stickiness = data_set->default_resource_stickiness; - is_managed = crm_element_value((*rsc)->xml, "is_managed"); - if(is_managed != NULL && crm_is_true(is_managed) == FALSE) { + value = g_hash_table_lookup((*rsc)->parameters, XML_CIB_ATTR_PRIORITY); + (*rsc)->priority = atoi(value?value:"0"); + (*rsc)->effective_priority = (*rsc)->priority; + + value = g_hash_table_lookup((*rsc)->parameters, "notify"); + (*rsc)->notify = crm_is_true(value); + + value = g_hash_table_lookup((*rsc)->parameters, "is_managed"); + if(value != NULL && crm_is_true(value) == FALSE) { (*rsc)->is_managed = FALSE; crm_warn("Resource %s is currently not managed", (*rsc)->id); #if 0 rsc_to_node_t *new_con = NULL; /* prevent this resource from running anywhere */ new_con = rsc2node_new( "is_managed_default", *rsc, -INFINITY, NULL, data_set); new_con->node_list_rh = node_list_dup(data_set->nodes, FALSE); #endif - } else if((*rsc)->is_managed && data_set->symmetric_cluster) { + } + if((*rsc)->is_managed && data_set->symmetric_cluster) { rsc_to_node_t *new_con = rsc2node_new( "symmetric_default", *rsc, 0, NULL, data_set); new_con->node_list_rh = node_list_dup(data_set->nodes, FALSE); } crm_debug_2("Options for %s", id); - if(safe_str_eq(restart, "restart")) { + value = g_hash_table_lookup((*rsc)->parameters, XML_RSC_ATTR_RESTART); + if(safe_str_eq(value, "restart")) { (*rsc)->restart_type = pe_restart_restart; crm_debug_2("\tDependancy restart handling: restart"); } else { (*rsc)->restart_type = pe_restart_ignore; crm_debug_2("\tDependancy restart handling: ignore"); } - if(safe_str_eq(multiple, "stop_only")) { + value = g_hash_table_lookup((*rsc)->parameters, "multiple_active"); + if(safe_str_eq(value, "stop_only")) { (*rsc)->recovery_type = recovery_stop_only; crm_debug_2("\tMultiple running resource recovery: stop only"); - } else if(safe_str_eq(multiple, "block")) { + } else if(safe_str_eq(value, "block")) { (*rsc)->recovery_type = recovery_block; crm_debug_2("\tMultiple running resource recovery: block"); } else { (*rsc)->recovery_type = recovery_stop_start; crm_debug_2("\tMultiple running resource recovery: stop/start"); } - if(placement != NULL) { - if(safe_str_eq(placement, INFINITY_S)) { + value = g_hash_table_lookup((*rsc)->parameters, "resource_stickiness"); + if(value != NULL) { + if(safe_str_eq(value, INFINITY_S)) { (*rsc)->stickiness = INFINITY; - } else if(safe_str_eq(placement, MINUS_INFINITY_S)) { + } else if(safe_str_eq(value, MINUS_INFINITY_S)) { (*rsc)->stickiness = -INFINITY; } else { - (*rsc)->stickiness = atoi(placement); + (*rsc)->stickiness = atoi(value); } } if((*rsc)->stickiness > 0) { crm_debug_2("\tPlacement: prefer current location%s", - placement == NULL?" (default)":""); + value == NULL?" (default)":""); } else if((*rsc)->stickiness < 0) { crm_warn("\tPlacement: always move from the current location%s", - placement == NULL?" (default)":""); + value == NULL?" (default)":""); } else { crm_debug_2("\tPlacement: optimal%s", - placement == NULL?" (default)":""); + value == NULL?" (default)":""); } crm_debug_2("\tNotification of start/stop actions: %s", (*rsc)->notify?"required":"not required"); (*rsc)->fns->unpack(*rsc, data_set); return TRUE; } void order_actions(action_t *lh_action, action_t *rh_action, order_constraint_t *order) { action_wrapper_t *wrapper = NULL; GListPtr list = NULL; crm_debug_2("Ordering %d: Action %d before %d", order?order->id:-1, lh_action->id, rh_action->id); log_action(LOG_DEBUG_4, "LH (order_actions)", lh_action, FALSE); log_action(LOG_DEBUG_4, "RH (order_actions)", rh_action, FALSE); crm_malloc0(wrapper, sizeof(action_wrapper_t)); if(wrapper != NULL) { wrapper->action = rh_action; wrapper->type = order->type; list = lh_action->actions_after; list = g_list_append(list, wrapper); lh_action->actions_after = list; wrapper = NULL; } if(order->type != pe_ordering_recover) { crm_malloc0(wrapper, sizeof(action_wrapper_t)); if(wrapper != NULL) { wrapper->action = lh_action; wrapper->type = order->type; list = rh_action->actions_before; list = g_list_append(list, wrapper); rh_action->actions_before = list; } } } void common_html(resource_t *rsc, const char *pre_text, FILE *stream) { const char *prov = crm_element_value(rsc->xml, XML_AGENT_ATTR_PROVIDER); fprintf(stream, "%s%s (%s%s%s:%s):\t", pre_text?pre_text:"", rsc->id, prov?prov:"", prov?"::":"", crm_element_value(rsc->xml, XML_AGENT_ATTR_CLASS), crm_element_value(rsc->xml, XML_ATTR_TYPE)); } void common_printw(resource_t *rsc, const char *pre_text, int *index) { #if CURSES_ENABLED const char *prov = crm_element_value(rsc->xml, XML_AGENT_ATTR_PROVIDER); move(*index, 0); printw("%s%s (%s%s%s:%s):\t", pre_text?pre_text:"", rsc->id, prov?prov:"", prov?"::":"", crm_element_value(rsc->xml, XML_AGENT_ATTR_CLASS), crm_element_value(rsc->xml, XML_ATTR_TYPE)); #else crm_err("printw support requires ncurses to be available during configure"); #endif } void common_dump(resource_t *rsc, const char *pre_text, gboolean details) { crm_debug_4("%s%s%s%sResource %s: (variant=%s, priority=%f)", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", rsc->provisional?"Provisional ":"", rsc->runnable?"":"(Non-Startable) ", rsc->id, crm_element_name(rsc->xml), (double)rsc->priority); } void common_free(resource_t *rsc) { if(rsc == NULL) { return; } crm_debug_5("Freeing %s", rsc->id); while(rsc->rsc_cons) { pe_free_rsc_colocation( (rsc_colocation_t*)rsc->rsc_cons->data); rsc->rsc_cons = rsc->rsc_cons->next; } if(rsc->rsc_cons != NULL) { g_list_free(rsc->rsc_cons); } if(rsc->parameters != NULL) { g_hash_table_destroy(rsc->parameters); } pe_free_shallow_adv(rsc->candidate_colors, TRUE); crm_free(rsc->variant_opaque); crm_free(rsc); crm_debug_5("Resource freed"); } void unpack_instance_attributes( - crm_data_t *xml_obj, node_t *node, GHashTable *hash, - const char **attrs, int attrs_length, pe_working_set_t *data_set) + crm_data_t *xml_obj, const char *set_name, node_t *node, + GHashTable *hash, const char **attrs, int attrs_length, + pe_working_set_t *data_set) { crm_data_t *attributes = NULL; if(xml_obj == NULL) { crm_debug_4("No instance attributes"); return; } if(attrs != NULL && attrs[0] == NULL) { /* none allowed */ crm_debug_2("No instance attributes allowed"); return; } crm_debug_2("Checking for attributes"); xml_child_iter( - xml_obj, attr_set, XML_TAG_ATTR_SETS, + xml_obj, attr_set, set_name, /* check any rules */ if(test_ruleset(attr_set, node, data_set) == FALSE) { continue; } crm_debug_2("Adding attributes"); attributes = cl_get_struct(attr_set, XML_TAG_ATTRS); if(attributes == NULL) { - pe_err("%s with no %s child", - XML_TAG_ATTR_SETS, XML_TAG_ATTRS); + pe_err("%s with no %s child", set_name, XML_TAG_ATTRS); } else { populate_hash(attributes, hash, attrs, attrs_length); } ); } void populate_hash(crm_data_t *nvpair_list, GHashTable *hash, const char **attrs, int attrs_length) { int lpc = 0; gboolean set_attr = FALSE; const char *name = NULL; const char *value = NULL; xml_child_iter( nvpair_list, an_attr, XML_CIB_TAG_NVPAIR, name = crm_element_value(an_attr, XML_NVPAIR_ATTR_NAME); set_attr = TRUE; if(attrs != NULL) { set_attr = FALSE; } for(lpc = 0; set_attr == FALSE && lpc < attrs_length && attrs[lpc] != NULL; lpc++) { if(safe_str_eq(name, attrs[lpc])) { set_attr = TRUE; } } if(set_attr) { crm_debug_4("Setting attribute: %s", name); value = crm_element_value( an_attr, XML_NVPAIR_ATTR_VALUE); add_hash_param(hash, name, value); } else { crm_debug_4("Skipping attribute: %s", name); } ); } void add_rsc_param(resource_t *rsc, const char *name, const char *value) { CRM_DEV_ASSERT(rsc != NULL); if(crm_assert_failed) { return; } add_hash_param(rsc->parameters, name, value); } void add_hash_param(GHashTable *hash, const char *name, const char *value) { CRM_DEV_ASSERT(hash != NULL); if(crm_assert_failed) { return; } crm_debug_3("adding: name=%s value=%s", crm_str(name), crm_str(value)); if(name == NULL || value == NULL) { return; } else if(g_hash_table_lookup(hash, name) == NULL) { g_hash_table_insert(hash, crm_strdup(name), crm_strdup(value)); } } const char * get_rsc_param(resource_t *rsc, const char *name) { CRM_DEV_ASSERT(rsc != NULL); if(crm_assert_failed) { return NULL; } return g_hash_table_lookup(rsc->parameters, name); } void hash2nvpair(gpointer key, gpointer value, gpointer user_data) { const char *name = key; const char *s_value = value; crm_data_t *xml_node = user_data; crm_data_t *xml_child = create_xml_node(xml_node, XML_CIB_TAG_NVPAIR); crm_xml_add(xml_child, XML_NVPAIR_ATTR_NAME, name); crm_xml_add(xml_child, XML_NVPAIR_ATTR_VALUE, s_value); crm_debug_3("dumped: name=%s value=%s", name, s_value); } diff --git a/crm/pengine/complex.h b/crm/pengine/complex.h index 4e88c918b1..2400351c94 100644 --- a/crm/pengine/complex.h +++ b/crm/pengine/complex.h @@ -1,203 +1,199 @@ -/* $Id: complex.h,v 1.21 2005/08/11 08:58:40 andrew Exp $ */ +/* $Id: complex.h,v 1.22 2005/08/17 09:15:13 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*, 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, 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, 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, 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 gboolean common_unpack(crm_data_t *xml_obj, resource_t **rsc, + GHashTable *defaults, 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, + crm_data_t *xml_obj, const char *set_name, node_t *node, GHashTable *hash, const char **attr_filter, int attrs_length, pe_working_set_t *data_set); 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/group.c b/crm/pengine/group.c index b86738f81b..80281463b2 100644 --- a/crm/pengine/group.c +++ b/crm/pengine/group.c @@ -1,581 +1,580 @@ -/* $Id: group.c,v 1.33 2005/08/10 15:38:52 andrew Exp $ */ +/* $Id: group.c,v 1.34 2005/08/17 09:15:13 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)) { + if(common_unpack(xml_self, &self, NULL, 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)) { + if(common_unpack(xml_native_rsc, &new_rsc, + group_data->self->parameters, 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, 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, n_data, data_set); ); } diff --git a/crm/pengine/incarnation.c b/crm/pengine/incarnation.c index 87acaa59b6..d35d9f615b 100644 --- a/crm/pengine/incarnation.c +++ b/crm/pengine/incarnation.c @@ -1,1193 +1,1193 @@ -/* $Id: incarnation.c,v 1.45 2005/08/10 15:38:52 andrew Exp $ */ +/* $Id: incarnation.c,v 1.46 2005/08/17 09:15:13 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)) { + if(common_unpack(xml_self, &self, NULL, 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)) { + if(common_unpack(child_copy, &child_rsc, + clone_data->self->parameters, 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); ); } 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); if(rsc->notify) { slist_iter( child_rsc, resource_t, clone_data->child_list, lpc, slist_iter( op, action_t, clone_data->self->actions, lpc2, child_rsc->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); } 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, */ /* if(safe_str_eq(action->task, CRMD_ACTION_NOTIFY)) { */ /* action->extra_xml = notify_xml; */ /* } */ /* ); */ clone_data->self->fns->expand(clone_data->self, data_set); /* destroy the notify_data */ pe_free_shallow(n_data->stop); pe_free_shallow(n_data->start); pe_free_shallow(n_data->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, 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, n_data, data_set); ); } diff --git a/crm/pengine/native.c b/crm/pengine/native.c index f91942e50e..5d57d4fc11 100644 --- a/crm/pengine/native.c +++ b/crm/pengine/native.c @@ -1,1661 +1,1660 @@ -/* $Id: native.c,v 1.72 2005/08/11 08:58:40 andrew Exp $ */ +/* $Id: native.c,v 1.73 2005/08/17 09:15:13 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, 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, notify_data_t *n_data, pe_working_set_t *data_set); void pe_post_notify( resource_t *rsc, node_t *node, action_t *op, 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); + } else if(rsc->stickiness != 0) { + rsc2node_new("stickiness", rsc, rsc->stickiness, 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, data_set); + unpack_instance_attributes( + rsc->xml, XML_TAG_ATTR_SETS, chosen, rsc->parameters, + NULL, 0, data_set); 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, 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, 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,n_data,data_set); register_activity(rsc, op, n_data); } else { 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, n_data); if(task == stop_rsc) { pe_pre_notify(rsc, current, op, n_data, data_set); } else { pe_post_notify(rsc, current,op,n_data,data_set); } break; case rsc_state_starting: if(task != stop_rsc) { 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, 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, notify_data_t *n_data) { 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, crm_malloc0(entry, sizeof(notify_entry_t)); entry->rsc = rsc; entry->node = node; n_data->stop=g_list_append(n_data->stop, entry); ); } } void register_state(resource_t *rsc, action_t *op, notify_data_t *n_data) { notify_entry_t *entry = NULL; native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); crm_malloc0(entry, sizeof(notify_entry_t)); entry->rsc = rsc; if(native_data->color != NULL) { entry->node = native_data->color->details->chosen_node; } 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); } } 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, 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); g_hash_table_foreach(op->extra, dup_attr, trigger->extra); 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); 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); 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, notify_data_t *n_data, pe_working_set_t *data_set) { pe_notify(rsc, node, op->pre_notify, op->pre_notified, n_data, data_set); } void pe_post_notify(resource_t *rsc, node_t *node, action_t *op, notify_data_t *n_data, pe_working_set_t *data_set) { pe_notify(rsc, node, op->post_notify, op->post_notified, n_data, data_set); } diff --git a/crm/pengine/testcases/696.exp b/crm/pengine/testcases/696.exp index c54525ae5f..be5664670f 100644 --- a/crm/pengine/testcases/696.exp +++ b/crm/pengine/testcases/696.exp @@ -1,269 +1,277 @@ + + + + + + + + diff --git a/crm/pengine/testcases/726.exp b/crm/pengine/testcases/726.exp index 490e982b74..efee2fa4ed 100644 --- a/crm/pengine/testcases/726.exp +++ b/crm/pengine/testcases/726.exp @@ -1,349 +1,358 @@ + + + + + + + + + diff --git a/crm/pengine/testcases/735.exp b/crm/pengine/testcases/735.exp index 95d105dc9a..01a4a8fa29 100644 --- a/crm/pengine/testcases/735.exp +++ b/crm/pengine/testcases/735.exp @@ -1,171 +1,176 @@ + + + + + diff --git a/crm/pengine/testcases/764.exp b/crm/pengine/testcases/764.exp index 0f1de2e66d..81651577ec 100644 --- a/crm/pengine/testcases/764.exp +++ b/crm/pengine/testcases/764.exp @@ -1,88 +1,93 @@ + + + + + diff --git a/crm/pengine/testcases/797.exp b/crm/pengine/testcases/797.exp index 8a344dfa0e..0ac35b4ab6 100644 --- a/crm/pengine/testcases/797.exp +++ b/crm/pengine/testcases/797.exp @@ -1,283 +1,288 @@ + + + + + diff --git a/crm/pengine/testcases/inc6.exp b/crm/pengine/testcases/inc6.exp index 80f6da3948..4f4851e26b 100644 --- a/crm/pengine/testcases/inc6.exp +++ b/crm/pengine/testcases/inc6.exp @@ -1,393 +1,421 @@ - - - + + + + + + + + - + - - - + + + + + + + + - + - - - - - - - - - - - - - - - - - - + - + - + - + + - + - + - + - + + - + - + - + - + - + - + - + - + + + + - + - + - + - + - + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + - + - + - + - + - + - + + + + + + + + + + - + - + - - + + + + + + + + + + + + + + + + + + + + - + + + + - + - - + + + + + + + + + + + + + + + + + + + + - + + + + - + - + - + - + + + + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + diff --git a/crm/pengine/testcases/managed-2.exp b/crm/pengine/testcases/managed-2.exp index 72fdacd066..8febb71c3b 100644 --- a/crm/pengine/testcases/managed-2.exp +++ b/crm/pengine/testcases/managed-2.exp @@ -1,91 +1,99 @@ + + + + + + + + diff --git a/crm/pengine/testcases/notify-1.exp b/crm/pengine/testcases/notify-1.exp index 3e01b8c6bf..761a511ad2 100644 --- a/crm/pengine/testcases/notify-1.exp +++ b/crm/pengine/testcases/notify-1.exp @@ -1,308 +1,314 @@ - + + - + + - + + - + + - + + - + + diff --git a/crm/pengine/testcases/notify-2.exp b/crm/pengine/testcases/notify-2.exp index 3e01b8c6bf..761a511ad2 100644 --- a/crm/pengine/testcases/notify-2.exp +++ b/crm/pengine/testcases/notify-2.exp @@ -1,308 +1,314 @@ - + + - + + - + + - + + - + + - + + diff --git a/crm/pengine/testcases/notify-3.exp b/crm/pengine/testcases/notify-3.exp index 5b8d536fa5..7dd02f9e7c 100644 --- a/crm/pengine/testcases/notify-3.exp +++ b/crm/pengine/testcases/notify-3.exp @@ -1,517 +1,527 @@ - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + diff --git a/crm/pengine/testcases/order6.exp b/crm/pengine/testcases/order6.exp index 48b84762f1..1bfec6ba6e 100644 --- a/crm/pengine/testcases/order6.exp +++ b/crm/pengine/testcases/order6.exp @@ -1,120 +1,132 @@ - + + + - + + + - + + + - + + + - + + + - + + + diff --git a/crm/pengine/testcases/quorum-1.exp b/crm/pengine/testcases/quorum-1.exp index d8cc7ec177..23471a77bc 100644 --- a/crm/pengine/testcases/quorum-1.exp +++ b/crm/pengine/testcases/quorum-1.exp @@ -1,34 +1,40 @@ - + + + - + + + - + + + diff --git a/crm/pengine/testcases/quorum-2.exp b/crm/pengine/testcases/quorum-2.exp index 06a4de42ee..0c9a9adb36 100644 --- a/crm/pengine/testcases/quorum-2.exp +++ b/crm/pengine/testcases/quorum-2.exp @@ -1,25 +1,29 @@ - + + + - + + + diff --git a/crm/pengine/testcases/quorum-3.exp b/crm/pengine/testcases/quorum-3.exp index 46b9266799..1fe26a0910 100644 --- a/crm/pengine/testcases/quorum-3.exp +++ b/crm/pengine/testcases/quorum-3.exp @@ -1,21 +1,25 @@ - + + + - + + + diff --git a/crm/pengine/testcases/quorum-5.exp b/crm/pengine/testcases/quorum-5.exp index bb53d74b8d..0183f7bb65 100644 --- a/crm/pengine/testcases/quorum-5.exp +++ b/crm/pengine/testcases/quorum-5.exp @@ -1,87 +1,91 @@ - + + - + + - + + - + + diff --git a/crm/pengine/testcases/rec-node-1.exp b/crm/pengine/testcases/rec-node-1.exp index 744d59a604..5721e255ab 100644 --- a/crm/pengine/testcases/rec-node-1.exp +++ b/crm/pengine/testcases/rec-node-1.exp @@ -1,21 +1,25 @@ - + + + - + + + diff --git a/crm/pengine/testcases/rec-node-2.exp b/crm/pengine/testcases/rec-node-2.exp index 54ac60b84d..179f4659f9 100644 --- a/crm/pengine/testcases/rec-node-2.exp +++ b/crm/pengine/testcases/rec-node-2.exp @@ -1,36 +1,42 @@ - + + + + - + + + + diff --git a/crm/pengine/testcases/rec-node-3.exp b/crm/pengine/testcases/rec-node-3.exp index 744d59a604..5721e255ab 100644 --- a/crm/pengine/testcases/rec-node-3.exp +++ b/crm/pengine/testcases/rec-node-3.exp @@ -1,21 +1,25 @@ - + + + - + + + diff --git a/crm/pengine/testcases/rec-node-4.exp b/crm/pengine/testcases/rec-node-4.exp index 22821e3b87..9b97e2089f 100644 --- a/crm/pengine/testcases/rec-node-4.exp +++ b/crm/pengine/testcases/rec-node-4.exp @@ -1,64 +1,68 @@ - + + + - + + + diff --git a/crm/pengine/testcases/rec-node-5.exp b/crm/pengine/testcases/rec-node-5.exp index 744d59a604..5721e255ab 100644 --- a/crm/pengine/testcases/rec-node-5.exp +++ b/crm/pengine/testcases/rec-node-5.exp @@ -1,21 +1,25 @@ - + + + - + + + diff --git a/crm/pengine/testcases/rec-node-6.exp b/crm/pengine/testcases/rec-node-6.exp index 22821e3b87..9b97e2089f 100644 --- a/crm/pengine/testcases/rec-node-6.exp +++ b/crm/pengine/testcases/rec-node-6.exp @@ -1,64 +1,68 @@ - + + + - + + + diff --git a/crm/pengine/testcases/rec-node-7.exp b/crm/pengine/testcases/rec-node-7.exp index 22821e3b87..9b97e2089f 100644 --- a/crm/pengine/testcases/rec-node-7.exp +++ b/crm/pengine/testcases/rec-node-7.exp @@ -1,64 +1,68 @@ - + + + - + + + diff --git a/crm/pengine/testcases/rec-rsc-3.exp b/crm/pengine/testcases/rec-rsc-3.exp index f92c9ed700..11c1466fca 100644 --- a/crm/pengine/testcases/rec-rsc-3.exp +++ b/crm/pengine/testcases/rec-rsc-3.exp @@ -1,12 +1,14 @@ - + + + diff --git a/crm/pengine/testcases/rec-rsc-4.exp b/crm/pengine/testcases/rec-rsc-4.exp index f81717dbac..bf97f572d8 100644 --- a/crm/pengine/testcases/rec-rsc-4.exp +++ b/crm/pengine/testcases/rec-rsc-4.exp @@ -1,25 +1,29 @@ - + + + - + + + diff --git a/crm/pengine/testcases/rec-rsc-5.exp b/crm/pengine/testcases/rec-rsc-5.exp index f790b933f4..6087fd048a 100644 --- a/crm/pengine/testcases/rec-rsc-5.exp +++ b/crm/pengine/testcases/rec-rsc-5.exp @@ -1,65 +1,71 @@ - + + + - + + + - + + + diff --git a/crm/pengine/testcases/rec-rsc-6.exp b/crm/pengine/testcases/rec-rsc-6.exp index 31bc996e00..6ad1d6145b 100644 --- a/crm/pengine/testcases/rec-rsc-6.exp +++ b/crm/pengine/testcases/rec-rsc-6.exp @@ -1,37 +1,43 @@ - + + + - + + + - + + + diff --git a/crm/pengine/testcases/rec-rsc-7.exp b/crm/pengine/testcases/rec-rsc-7.exp index b1d1d0423b..f287fd0b8c 100644 --- a/crm/pengine/testcases/rec-rsc-7.exp +++ b/crm/pengine/testcases/rec-rsc-7.exp @@ -1,21 +1,25 @@ - + + + - + + + diff --git a/crm/pengine/unpack.c b/crm/pengine/unpack.c index 340627bd93..a8b68cf125 100644 --- a/crm/pengine/unpack.c +++ b/crm/pengine/unpack.c @@ -1,1278 +1,1310 @@ -/* $Id: unpack.c,v 1.116 2005/08/11 08:58:40 andrew Exp $ */ +/* $Id: unpack.c,v 1.117 2005/08/17 09:15:13 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 /* for ONLINESTATUS */ #include #include #include gint sort_op_by_callid(gconstpointer a, gconstpointer b); gboolean unpack_rsc_to_attr(crm_data_t *xml_obj, pe_working_set_t *data_set); gboolean unpack_rsc_to_node(crm_data_t *xml_obj, pe_working_set_t *data_set); gboolean unpack_rsc_order(crm_data_t *xml_obj, pe_working_set_t *data_set); gboolean unpack_rsc_colocation(crm_data_t *xml_obj, pe_working_set_t *data_set); gboolean unpack_rsc_location(crm_data_t *xml_obj, pe_working_set_t *data_set); gboolean unpack_lrm_rsc_state( node_t *node, crm_data_t * lrm_state, pe_working_set_t *data_set); gboolean add_node_attrs( crm_data_t * attrs, node_t *node, pe_working_set_t *data_set); gboolean unpack_rsc_op( resource_t *rsc, node_t *node, crm_data_t *xml_op, gboolean *running, int *max_call_id, pe_working_set_t *data_set); gboolean determine_online_status( crm_data_t * node_state, node_t *this_node, pe_working_set_t *data_set); gboolean rsc_colocation_new( const char *id, enum con_strength strength, resource_t *rsc_lh, resource_t *rsc_rh); gboolean create_ordering( const char *id, enum con_strength strength, resource_t *rsc_lh, resource_t *rsc_rh, pe_working_set_t *data_set); rsc_to_node_t *rsc2node_new( const char *id, resource_t *rsc, double weight, node_t *node, pe_working_set_t *data_set); -const char *param_value(crm_data_t * parent, const char *name); +const char *param_value( + GHashTable *hash, crm_data_t * parent, const char *name); rsc_to_node_t *generate_location_rule( resource_t *rsc, crm_data_t *location_rule, pe_working_set_t *data_set); gboolean unpack_config(crm_data_t * config, pe_working_set_t *data_set) { - const char *value = NULL; +/* const char *attr_filter[] = { */ +/* "default_resource_stickiness", */ +/* "transition_idle_timeout", */ +/* "stonith_enabled", */ +/* "symmetric_cluster" */ +/* }; */ - value = param_value(config, "transition_idle_timeout"); + const char *value = NULL; + GHashTable *config_hash = g_hash_table_new_full( + g_str_hash,g_str_equal, g_hash_destroy_str,g_hash_destroy_str); + + unpack_instance_attributes( + config, "cluster_property_set", NULL, config_hash, + NULL, 0, data_set); + +#if CRM_DEPRECATED_SINCE_2_0_1 + param_value(config_hash, config, "transition_idle_timeout"); + param_value(config_hash, config, "default_resource_stickiness"); + param_value(config_hash, config, "stonith_enabled"); + param_value(config_hash, config, "symmetric_cluster"); + param_value(config_hash, config, "no_quorum_policy"); +#endif if(value != NULL) { long tmp = crm_get_msec(value); if(tmp > 0) { transition_idle_timeout = value; } else { crm_err("Invalid value for %s: %s", "transition_idle_timeout", value); } } crm_debug_4("%s set to: %s", "transition_idle_timeout", transition_idle_timeout); - value = param_value(config, "default_resource_stickiness"); + value = g_hash_table_lookup(config_hash, "default_resource_stickiness"); data_set->default_resource_stickiness = crm_atoi(value, "0"); - value = param_value(config, "stonith_enabled"); + value = g_hash_table_lookup(config_hash, "stonith_enabled"); if(value != NULL) { - crm_str_to_boolean(value, &data_set->stonith_enabled); + cl_str_to_boolean(value, &data_set->stonith_enabled); } crm_info("STONITH of failed nodes is %s", data_set->stonith_enabled?"enabled":"disabled"); + - value = param_value(config, "symmetric_cluster"); + value = g_hash_table_lookup(config_hash, "symmetric_cluster"); if(value != NULL) { - crm_str_to_boolean(value, &data_set->symmetric_cluster); + cl_str_to_boolean(value, &data_set->symmetric_cluster); } if(data_set->symmetric_cluster) { crm_info("Cluster is symmetric" " - resources can run anywhere by default"); } - value = param_value(config, "no_quorum_policy"); + value = g_hash_table_lookup(config_hash, "no_quorum_policy"); if(safe_str_eq(value, "ignore")) { data_set->no_quorum_policy = no_quorum_ignore; } else if(safe_str_eq(value, "freeze")) { data_set->no_quorum_policy = no_quorum_freeze; } else { data_set->no_quorum_policy = no_quorum_stop; } switch (data_set->no_quorum_policy) { case no_quorum_freeze: crm_info("On loss of CCM Quorum: Freeze resources"); break; case no_quorum_stop: crm_info("On loss of CCM Quorum: Stop ALL resources"); break; case no_quorum_ignore: crm_warn("On loss of CCM Quorum: Ignore"); break; } - + + g_hash_table_destroy(config_hash); return TRUE; } const char * -param_value(crm_data_t * parent, const char *name) +param_value(GHashTable *hash, crm_data_t * parent, const char *name) { + const char *value = NULL; crm_data_t * a_default = NULL; if(parent != NULL) { a_default = find_entity(parent, XML_CIB_TAG_NVPAIR, name); } if(a_default == NULL) { crm_warn("Option %s not set", name); return NULL; } - return crm_element_value(a_default, XML_NVPAIR_ATTR_VALUE); + value = crm_element_value(a_default, XML_NVPAIR_ATTR_VALUE); + if(value && hash) { + if(g_hash_table_lookup(hash, name) == NULL) { + g_hash_table_insert( + hash, crm_strdup(name), crm_strdup(value)); + } + } + return value; } gboolean unpack_nodes(crm_data_t * xml_nodes, pe_working_set_t *data_set) { node_t *new_node = NULL; const char *id = NULL; const char *uname = NULL; const char *type = NULL; crm_debug("Begining unpack... %s", xml_nodes?crm_element_name(xml_nodes):""); xml_child_iter( xml_nodes, xml_obj, XML_CIB_TAG_NODE, new_node = NULL; id = crm_element_value(xml_obj, XML_ATTR_ID); uname = crm_element_value(xml_obj, XML_ATTR_UNAME); type = crm_element_value(xml_obj, XML_ATTR_TYPE); crm_debug_3("Processing node %s/%s", uname, id); if(id == NULL) { pe_err("Must specify id tag in "); continue; } if(type == NULL) { pe_err("Must specify type tag in "); continue; } crm_malloc0(new_node, sizeof(node_t)); if(new_node == NULL) { return FALSE; } new_node->weight = 0; new_node->fixed = FALSE; crm_malloc0(new_node->details, sizeof(struct node_shared_s)); if(new_node->details == NULL) { crm_free(new_node); return FALSE; } crm_debug_3("Creaing node for entry %s/%s", uname, id); new_node->details->id = id; new_node->details->uname = uname; new_node->details->type = node_ping; new_node->details->online = FALSE; new_node->details->shutdown = FALSE; new_node->details->running_rsc = NULL; new_node->details->attrs = g_hash_table_new_full( g_str_hash, g_str_equal, g_hash_destroy_str, g_hash_destroy_str); /* if(data_set->have_quorum == FALSE */ /* && data_set->no_quorum_policy == no_quorum_stop) { */ /* /\* start shutting resources down *\/ */ /* new_node->weight = -INFINITY; */ /* } */ if(data_set->stonith_enabled) { /* all nodes are unclean until we've seen their * status entry */ new_node->details->unclean = TRUE; } else { /* blind faith... */ new_node->details->unclean = FALSE; } if(safe_str_eq(type, "member")) { new_node->details->type = node_member; } add_node_attrs(xml_obj, new_node, data_set); if(crm_is_true(g_hash_table_lookup( new_node->details->attrs, "standby"))) { crm_info("Node %s is in standby-mode", new_node->details->uname); new_node->weight = -INFINITY; } data_set->nodes = g_list_append(data_set->nodes, new_node); crm_debug_3("Done with node %s", crm_element_value(xml_obj, XML_ATTR_UNAME)); crm_action_debug_3(print_node("Added", new_node, FALSE)); ); data_set->nodes = g_list_sort(data_set->nodes, sort_node_weight); return TRUE; } gboolean unpack_resources(crm_data_t * xml_resources, pe_working_set_t *data_set) { crm_debug("Begining unpack... %s", xml_resources?crm_element_name(xml_resources):""); xml_child_iter( xml_resources, xml_obj, NULL, resource_t *new_rsc = NULL; crm_debug_2("Begining unpack... %s", xml_obj?crm_element_name(xml_obj):""); - if(common_unpack(xml_obj, &new_rsc, data_set)) { + if(common_unpack(xml_obj, &new_rsc, NULL, data_set)) { data_set->resources = g_list_append( data_set->resources, new_rsc); crm_action_debug_3( print_resource("Added", new_rsc, FALSE)); } else { pe_err("Failed unpacking %s %s", crm_element_name(xml_obj), crm_element_value(xml_obj, XML_ATTR_ID)); } ); data_set->resources = g_list_sort( data_set->resources, sort_rsc_priority); return TRUE; } gboolean unpack_constraints(crm_data_t * xml_constraints, pe_working_set_t *data_set) { crm_data_t *lifetime = NULL; crm_debug("Begining unpack... %s", xml_constraints?crm_element_name(xml_constraints):""); xml_child_iter( xml_constraints, xml_obj, NULL, const char *id = crm_element_value(xml_obj, XML_ATTR_ID); if(id == NULL) { pe_err("Constraint <%s...> must have an id", crm_element_name(xml_obj)); continue; } crm_debug_3("Processing constraint %s %s", crm_element_name(xml_obj),id); lifetime = cl_get_struct(xml_obj, "lifetime"); if(test_ruleset(lifetime, NULL, data_set) == FALSE) { crm_info("Constraint %s %s is not active", crm_element_name(xml_obj), id); } else if(safe_str_eq(XML_CONS_TAG_RSC_ORDER, crm_element_name(xml_obj))) { unpack_rsc_order(xml_obj, data_set); } else if(safe_str_eq(XML_CONS_TAG_RSC_DEPEND, crm_element_name(xml_obj))) { unpack_rsc_colocation(xml_obj, data_set); } else if(safe_str_eq(XML_CONS_TAG_RSC_LOCATION, crm_element_name(xml_obj))) { unpack_rsc_location(xml_obj, data_set); } else { pe_err("Unsupported constraint type: %s", crm_element_name(xml_obj)); } ); return TRUE; } rsc_to_node_t * rsc2node_new(const char *id, resource_t *rsc, double weight, node_t *node, pe_working_set_t *data_set) { rsc_to_node_t *new_con = NULL; if(rsc == NULL || id == NULL) { pe_err("Invalid constraint %s for rsc=%p", crm_str(id), rsc); return NULL; } crm_malloc0(new_con, sizeof(rsc_to_node_t)); if(new_con != NULL) { new_con->id = id; new_con->rsc_lh = rsc; new_con->node_list_rh = NULL; new_con->weight = weight; if(node != NULL) { node_t *copy = node_copy(node); new_con->node_list_rh = g_list_append(NULL, copy); } data_set->placement_constraints = g_list_append( data_set->placement_constraints, new_con); } return new_con; } /* remove nodes that are down, stopping */ /* create +ve rsc_to_node constraints between resources and the nodes they are running on */ /* anything else? */ gboolean unpack_status(crm_data_t * status, pe_working_set_t *data_set) { const char *uname = NULL; crm_data_t * lrm_rsc = NULL; crm_data_t * lrm_agents = NULL; crm_data_t * attrs = NULL; node_t *this_node = NULL; crm_debug_3("Begining unpack"); xml_child_iter( status, node_state, XML_CIB_TAG_STATE, /* id = crm_element_value(node_state, XML_ATTR_ID); */ uname = crm_element_value(node_state, XML_ATTR_UNAME); attrs = find_xml_node(node_state, XML_LRM_TAG_ATTRIBUTES,FALSE); lrm_rsc = find_xml_node(node_state, XML_CIB_TAG_LRM, FALSE); lrm_agents = find_xml_node(lrm_rsc, XML_LRM_TAG_AGENTS, FALSE); lrm_rsc = find_xml_node(lrm_rsc, XML_LRM_TAG_RESOURCES, FALSE); crm_debug_3("Processing node %s", uname); this_node = pe_find_node(data_set->nodes, uname); if(uname == NULL) { /* error */ continue; } else if(this_node == NULL) { pe_warn("Node %s in status section no longer exists", uname); continue; } /* Mark the node as provisionally clean * - at least we have seen it in the current cluster's lifetime */ this_node->details->unclean = FALSE; crm_debug_3("Adding runtime node attrs"); add_node_attrs(node_state, this_node, data_set); crm_debug_3("determining node state"); determine_online_status(node_state, this_node, data_set); if(this_node->details->online || data_set->stonith_enabled) { /* offline nodes run no resources... * unless stonith is enabled in which case we need to * make sure rsc start events happen after the stonith */ crm_debug_3("Processing lrm resource entries"); unpack_lrm_rsc_state(this_node, lrm_rsc, data_set); } ); return TRUE; } gboolean determine_online_status( crm_data_t * node_state, node_t *this_node, pe_working_set_t *data_set) { gboolean online = FALSE; const char *uname = crm_element_value(node_state,XML_ATTR_UNAME); const char *exp_state = crm_element_value(node_state, XML_CIB_ATTR_EXPSTATE); const char *join_state = crm_element_value(node_state, XML_CIB_ATTR_JOINSTATE); const char *crm_state = crm_element_value(node_state, XML_CIB_ATTR_CRMDSTATE); const char *ccm_state = crm_element_value(node_state, XML_CIB_ATTR_INCCM); const char *ha_state = crm_element_value(node_state, XML_CIB_ATTR_HASTATE); const char *shutdown = crm_element_value(node_state, XML_CIB_ATTR_SHUTDOWN); if(this_node == NULL) { return online; } if(shutdown != NULL) { this_node->details->shutdown = TRUE; } if(safe_str_eq(join_state, CRMD_JOINSTATE_MEMBER)) { this_node->details->expected_up = TRUE; } if(data_set->stonith_enabled == FALSE) { if(!crm_is_true(ccm_state) || safe_str_eq(ha_state,DEADSTATUS)){ crm_debug_2("Node is down: ha_state=%s, ccm_state=%s", crm_str(ha_state), crm_str(ccm_state)); } else if(!crm_is_true(ccm_state) || safe_str_eq(ha_state, DEADSTATUS)) { } else if(safe_str_neq(join_state, CRMD_JOINSTATE_DOWN) && safe_str_eq(crm_state, ONLINESTATUS)) { online = TRUE; } else if(this_node->details->expected_up == FALSE) { crm_debug_2("CRMd is down: ha_state=%s, ccm_state=%s", crm_str(ha_state), crm_str(ccm_state)); crm_debug_2("\tcrm_state=%s, join_state=%s, expected=%s", crm_str(crm_state), crm_str(join_state), crm_str(exp_state)); } else { /* mark it unclean */ this_node->details->unclean = TRUE; pe_err("Node %s is partially & un-expectedly down", uname); crm_debug_2("\tcrm_state=%s, join_state=%s, expected=%s", crm_str(crm_state), crm_str(join_state), crm_str(exp_state)); } } else { if(crm_is_true(ccm_state) && (ha_state == NULL || safe_str_eq(ha_state, ACTIVESTATUS)) && safe_str_eq(crm_state, ONLINESTATUS) && safe_str_neq(join_state, CRMD_JOINSTATE_DOWN)) { online = TRUE; } else if(this_node->details->expected_up == FALSE) { crm_debug_2("CRMd on %s is down: ha_state=%s, ccm_state=%s", uname, crm_str(ha_state), crm_str(ccm_state)); crm_debug_2("\tcrm_state=%s, join_state=%s, expected=%s", crm_str(crm_state), crm_str(join_state), crm_str(exp_state)); } else { /* mark it unclean */ this_node->details->unclean = TRUE; pe_err("Node %s is un-expectedly down", uname); crm_debug_2("\tha_state=%s, ccm_state=%s", crm_str(ha_state), crm_str(ccm_state)); crm_debug_2("\tcrm_state=%s, join_state=%s, expected=%s", crm_str(crm_state), crm_str(join_state), crm_str(exp_state)); } } if(online) { crm_debug_2("Node %s is online", uname); this_node->details->online = TRUE; } else { /* remove node from contention */ crm_debug_2("Node %s is down", uname); this_node->weight = -INFINITY; this_node->fixed = TRUE; } if(this_node->details->unclean) { pe_warn("Node %s is unclean", uname); } if(this_node->details->shutdown) { /* dont run resources here */ this_node->weight = -INFINITY; this_node->fixed = TRUE; crm_debug_2("Node %s is due for shutdown", uname); } return online; } gboolean unpack_lrm_rsc_state(node_t *node, crm_data_t * lrm_rsc_list, pe_working_set_t *data_set) { const char *rsc_id = NULL; const char *node_id = node->details->uname; const char *rsc_state = NULL; int max_call_id = -1; gboolean running = FALSE; resource_t *rsc = NULL; GListPtr op_list = NULL; GListPtr sorted_op_list = NULL; CRM_DEV_ASSERT(node != NULL); if(crm_assert_failed) { return FALSE; } xml_child_iter( lrm_rsc_list, rsc_entry, XML_LRM_TAG_RESOURCE, rsc_id = crm_element_value(rsc_entry, XML_ATTR_ID); rsc_state = crm_element_value(rsc_entry, XML_LRM_ATTR_RSCSTATE); rsc = pe_find_resource(data_set->resources, rsc_id); crm_debug_3("[%s] Processing %s on %s (%s)", crm_element_name(rsc_entry), rsc_id, node_id, rsc_state); if(rsc == NULL) { pe_err("Could not find a match for resource" " %s in %s's status section", rsc_id, node_id); crm_log_xml_debug(rsc_entry, "Invalid status entry"); continue; } running = FALSE; max_call_id = -1; op_list = NULL; sorted_op_list = NULL; xml_child_iter( rsc_entry, rsc_op, XML_LRM_TAG_RSC_OP, op_list = g_list_append(op_list, rsc_op); ); if(op_list == NULL) { continue; } sorted_op_list = g_list_sort(op_list, sort_op_by_callid); slist_iter( rsc_op, crm_data_t, sorted_op_list, lpc, unpack_rsc_op(rsc, node, rsc_op, &running, &max_call_id, data_set); ); /* no need to free the contents */ g_list_free(sorted_op_list); if(running) { native_add_running(rsc, node, data_set); } ); return TRUE; } #define sort_return(an_int) crm_free(a_uuid); crm_free(b_uuid); return an_int gint sort_op_by_callid(gconstpointer a, gconstpointer b) { char *a_uuid = NULL; char *b_uuid = NULL; const char *a_task_id = cl_get_string(a, XML_LRM_ATTR_CALLID); const char *b_task_id = cl_get_string(b, XML_LRM_ATTR_CALLID); const char *a_key = cl_get_string(a, XML_ATTR_TRANSITION_MAGIC); const char *b_key = cl_get_string(b, XML_ATTR_TRANSITION_MAGIC); int a_id = -1; int b_id = -1; int a_status = -1; int b_status = -1; int a_call_id = -1; int b_call_id = -1; CRM_DEV_ASSERT(a_task_id != NULL && b_task_id != NULL); a_call_id = atoi(a_task_id); b_call_id = atoi(b_task_id); if(a_call_id == -1 && b_call_id == -1) { /* both are pending ops so it doesnt matter since * stops are never pending */ sort_return(0); } else if(a_call_id >= 0 && a_call_id < b_call_id) { crm_debug_2("%s (%d) < %s (%d) : call id", ID(a), a_call_id, ID(b), b_call_id); sort_return(-1); } else if(b_call_id >= 0 && a_call_id > b_call_id) { crm_debug_2("%s (%d) > %s (%d) : call id", ID(a), a_call_id, ID(b), b_call_id); sort_return(1); } crm_debug_3("%s (%d) == %s (%d) : continuing", ID(a), a_call_id, ID(b), b_call_id); /* now process pending ops */ CRM_DEV_ASSERT(a_key != NULL && b_key != NULL); CRM_DEV_ASSERT(decode_transition_magic(a_key,&a_uuid,&a_id,&a_status)); CRM_DEV_ASSERT(decode_transition_magic(b_key,&b_uuid,&b_id,&b_status)); /* try and determin the relative age of the operation... * some pending operations (ie. a start) may have been supuerceeded * by a subsequent stop * * [a|b]_id == -1 means its a shutdown operation and _always_ comes last */ if(safe_str_neq(a_uuid, b_uuid) || a_id == b_id) { /* * some of the logic in here may be redundant... * * if the UUID from the TE doesnt match then one better * be a pending operation. * pending operations dont survive between elections and joins * because we query the LRM directly */ CRM_DEV_ASSERT(a_call_id == -1 || b_call_id == -1); CRM_DEV_ASSERT(a_call_id >= 0 || b_call_id >= 0); if(b_call_id == -1) { crm_debug_2("%s (%d) < %s (%d) : transition + call id", ID(a), a_call_id, ID(b), b_call_id); sort_return(-1); } if(a_call_id == -1) { crm_debug_2("%s (%d) > %s (%d) : transition + call id", ID(a), a_call_id, ID(b), b_call_id); sort_return(1); } } else if((a_id >= 0 && a_id < b_id) || b_id == -1) { crm_debug_2("%s (%d) < %s (%d) : transition", ID(a), a_id, ID(b), b_id); sort_return(-1); } else if((b_id >= 0 && a_id > b_id) || a_id == -1) { crm_debug_2("%s (%d) > %s (%d) : transition", ID(a), a_id, ID(b), b_id); sort_return(1); } /* we should never end up here */ crm_err("%s (%d:%d:%s) ?? %s (%d:%d:%s) : default", ID(a), a_call_id, a_id, a_uuid, ID(b), b_call_id, b_id, b_uuid); CRM_DEV_ASSERT(FALSE); sort_return(0); } gboolean unpack_rsc_op(resource_t *rsc, node_t *node, crm_data_t *xml_op, gboolean *running, int *max_call_id, pe_working_set_t *data_set) { const char *id = NULL; const char *task = NULL; const char *task_id = NULL; const char *task_status = NULL; int task_id_i = -1; int task_status_i = -2; action_t *action = NULL; gboolean is_stop_action = FALSE; CRM_DEV_ASSERT(rsc != NULL); if(crm_assert_failed) { return FALSE; } CRM_DEV_ASSERT(node != NULL); if(crm_assert_failed) { return FALSE; } CRM_DEV_ASSERT(xml_op != NULL); if(crm_assert_failed) { return FALSE; } id = ID(xml_op); task = crm_element_value(xml_op, XML_LRM_ATTR_TASK); task_id = crm_element_value(xml_op, XML_LRM_ATTR_CALLID); task_status = crm_element_value(xml_op, XML_LRM_ATTR_OPSTATUS); CRM_DEV_ASSERT(id != NULL); if(crm_assert_failed) { return FALSE; } CRM_DEV_ASSERT(task != NULL); if(crm_assert_failed) { return FALSE; } CRM_DEV_ASSERT(task_status != NULL); if(crm_assert_failed) { return FALSE; } task_status_i = atoi(task_status); CRM_DEV_ASSERT(task_status_i <= LRM_OP_ERROR); if(crm_assert_failed) {return FALSE;} CRM_DEV_ASSERT(task_status_i >= LRM_OP_PENDING); if(crm_assert_failed) {return FALSE;} if(safe_str_eq(task, CRMD_ACTION_NOTIFY)) { /* safe to ignore these */ return TRUE; } crm_debug_2("Unpacking task %s/%s (call_id=%s, status=%s) on %s", rsc->id, task, task_id, task_status, node->details->uname); if(safe_str_eq(task, CRMD_ACTION_STOP)) { is_stop_action = TRUE; } if(task_status_i != LRM_OP_PENDING) { task_id_i = crm_atoi(task_id, "-1"); CRM_DEV_ASSERT(task_id != NULL); if(crm_assert_failed) { return FALSE; } CRM_DEV_ASSERT(task_id_i >= 0); if(crm_assert_failed) { return FALSE; } if(task_id_i == *max_call_id) { crm_debug_2("Already processed this call"); return TRUE; } CRM_DEV_ASSERT(task_id_i > *max_call_id); if(crm_assert_failed) { return FALSE; } } if(*max_call_id < task_id_i) { *max_call_id = task_id_i; } if(node->details->unclean) { crm_debug_2("Node %s (where %s is running) is unclean." " Further action depends on the value of %s", node->details->uname, rsc->id, XML_RSC_ATTR_STOPFAIL); } switch(task_status_i) { case LRM_OP_PENDING: /* * TODO: this may need some more thought * Some cases: * - PE reinvoked with pending action that will succeed * - PE reinvoked with pending action that will fail * - After DC election * - After startup * * pending start - required start * pending stop - required stop * pending on unavailable node - stonith * * For now this should do */ if(is_stop_action) { /* re-issue the stop and return */ stop_action(rsc, node, FALSE); *running = TRUE; rsc->recover = TRUE; } else if(safe_str_eq(task, CRMD_ACTION_START)) { rsc->start_pending = TRUE; *running = TRUE; /* make sure it is re-issued but, * only if we have quorum */ if(data_set->have_quorum == TRUE || data_set->no_quorum_policy == no_quorum_ignore){ /* do not specify the node, we may want * to start it elsewhere */ start_action(rsc, NULL, FALSE); } } else if(*running == TRUE) { crm_debug_2("Re-issuing pending recurring task:" " %s for %s on %s", task, rsc->id, node->details->id); /* do not specify the node, we may want * to start it elsewhere */ custom_action(rsc, crm_strdup(id), task, NULL, FALSE, data_set); } break; case LRM_OP_DONE: crm_debug_3("%s/%s completed on %s", rsc->id, task, node->details->uname); if(is_stop_action) { *running = FALSE; } else if(safe_str_eq(task, CRMD_ACTION_START)) { crm_debug_3("%s active on %s", rsc->id, node->details->uname); *running = TRUE; } else if(*running) { /* make sure its already created and is optional * * creating it now tells create_recurring_actions() * that it can safely leave it optional */ custom_action(rsc, crm_strdup(id), task, NULL, TRUE, data_set); } break; case LRM_OP_ERROR: case LRM_OP_TIMEOUT: case LRM_OP_NOTSUPPORTED: crm_debug_2("Processing failed op (%s) for %s on %s", task, rsc->id, node->details->uname); action = custom_action( rsc, crm_strdup(id), task, NULL, TRUE, data_set); if(action->on_fail == action_fail_nothing) { /* pretend the op completed */ if(is_stop_action) { *running = FALSE; } else { *running = TRUE; } break; } if(task_status_i == LRM_OP_NOTSUPPORTED || is_stop_action || safe_str_eq(task, CRMD_ACTION_START) ) { crm_warn("Handling failed %s for %s on %s", task, rsc->id, node->details->uname); rsc2node_new("dont_run__failed_stopstart", rsc, -INFINITY, node, data_set); } if(action->on_fail == action_fail_fence) { /* treat it as if it is still running * but also mark the node as unclean */ rsc->unclean = TRUE; node->details->unclean = TRUE; stop_action(rsc, node, FALSE); *running = TRUE; } else if(action->on_fail == action_fail_block) { /* let this depend on the stop action * which will fail but make sure the * transition continues... */ rsc->unclean = TRUE; *running = TRUE; } else if(action->on_fail == action_fail_stop) { *running = TRUE; stop_action(rsc, node, FALSE); } break; case LRM_OP_CANCELLED: /* do nothing?? */ pe_err("Dont know what to do for cancelled ops yet"); break; } return TRUE; } gboolean rsc_colocation_new(const char *id, enum con_strength strength, resource_t *rsc_lh, resource_t *rsc_rh) { rsc_colocation_t *new_con = NULL; rsc_colocation_t *inverted_con = NULL; if(rsc_lh == NULL || rsc_rh == NULL){ /* error */ return FALSE; } crm_malloc0(new_con, sizeof(rsc_colocation_t)); if(new_con == NULL) { return FALSE; } new_con->id = id; new_con->rsc_lh = rsc_lh; new_con->rsc_rh = rsc_rh; new_con->strength = strength; inverted_con = invert_constraint(new_con); crm_debug_4("Adding constraint %s (%p) to %s", new_con->id, new_con, rsc_lh->id); rsc_lh->rsc_cons = g_list_insert_sorted( rsc_lh->rsc_cons, new_con, sort_cons_strength); crm_debug_4("Adding constraint %s (%p) to %s", inverted_con->id, inverted_con, rsc_rh->id); rsc_rh->rsc_cons = g_list_insert_sorted( rsc_rh->rsc_cons, inverted_con, sort_cons_strength); return TRUE; } /* LHS before RHS */ gboolean custom_action_order( resource_t *lh_rsc, char *lh_action_task, action_t *lh_action, resource_t *rh_rsc, char *rh_action_task, action_t *rh_action, enum pe_ordering type, pe_working_set_t *data_set) { order_constraint_t *order = NULL; if((lh_action == NULL && lh_rsc == NULL) || (rh_action == NULL && rh_rsc == NULL)){ pe_err("Invalid inputs lh_rsc=%p, lh_a=%p," " rh_rsc=%p, rh_a=%p", lh_rsc, lh_action, rh_rsc, rh_action); crm_free(lh_action_task); crm_free(rh_action_task); return FALSE; } crm_malloc0(order, sizeof(order_constraint_t)); if(order == NULL) { return FALSE; } order->id = data_set->order_id++; order->type = type; order->lh_rsc = lh_rsc; order->rh_rsc = rh_rsc; order->lh_action = lh_action; order->rh_action = rh_action; order->lh_action_task = lh_action_task; order->rh_action_task = rh_action_task; data_set->ordering_constraints = g_list_append( data_set->ordering_constraints, order); if(lh_rsc != NULL && rh_rsc != NULL) { crm_debug_4("Created ordering constraint %d (%s):" " %s/%s before %s/%s", order->id, ordering_type2text(order->type), lh_rsc->id, lh_action_task, rh_rsc->id, rh_action_task); } else if(lh_rsc != NULL) { crm_debug_4("Created ordering constraint %d (%s):" " %s/%s before action %d (%s)", order->id, ordering_type2text(order->type), lh_rsc->id, lh_action_task, rh_action->id, rh_action_task); } else if(rh_rsc != NULL) { crm_debug_4("Created ordering constraint %d (%s):" " action %d (%s) before %s/%s", order->id, ordering_type2text(order->type), lh_action->id, lh_action_task, rh_rsc->id, rh_action_task); } else { crm_debug_4("Created ordering constraint %d (%s):" " action %d (%s) before action %d (%s)", order->id, ordering_type2text(order->type), lh_action->id, lh_action_task, rh_action->id, rh_action_task); } return TRUE; } gboolean unpack_rsc_colocation(crm_data_t * xml_obj, pe_working_set_t *data_set) { enum con_strength strength_e = pecs_ignore; const char *id = crm_element_value(xml_obj, XML_ATTR_ID); const char *id_rh = crm_element_value(xml_obj, XML_CONS_ATTR_TO); const char *id_lh = crm_element_value(xml_obj, XML_CONS_ATTR_FROM); const char *score = crm_element_value(xml_obj, XML_RULE_ATTR_SCORE); resource_t *rsc_lh = pe_find_resource(data_set->resources, id_lh); resource_t *rsc_rh = pe_find_resource(data_set->resources, id_rh); if(rsc_lh == NULL) { pe_err("No resource (con=%s, rsc=%s)", id, id_lh); return FALSE; } else if(rsc_rh == NULL) { pe_err("No resource (con=%s, rsc=%s)", id, id_rh); return FALSE; } /* the docs indicate that only +/- INFINITY are allowed, * but no-one ever reads the docs so all positive values will * count as "must" and negative values as "must not" */ if(score == NULL || score[0] != '-') { strength_e = pecs_must; } else { strength_e = pecs_must_not; } return rsc_colocation_new(id, strength_e, rsc_lh, rsc_rh); } gboolean unpack_rsc_order(crm_data_t * xml_obj, pe_working_set_t *data_set) { gboolean type_is_after = TRUE; gboolean action_is_start = TRUE; gboolean symmetrical_bool = TRUE; const char *id = crm_element_value(xml_obj, XML_ATTR_ID); const char *type = crm_element_value(xml_obj, XML_ATTR_TYPE); const char *id_rh = crm_element_value(xml_obj, XML_CONS_ATTR_TO); const char *id_lh = crm_element_value(xml_obj, XML_CONS_ATTR_FROM); const char *action = crm_element_value(xml_obj, XML_CONS_ATTR_ACTION); const char *symmetrical = crm_element_value( xml_obj, XML_CONS_ATTR_SYMMETRICAL); resource_t *rsc_lh = pe_find_resource(data_set->resources, id_lh); resource_t *rsc_rh = pe_find_resource(data_set->resources, id_rh); if(xml_obj == NULL) { pe_err("No constraint object to process."); return FALSE; } else if(id == NULL) { pe_err("%s constraint must have an id", crm_element_name(xml_obj)); return FALSE; } else if(rsc_lh == NULL || rsc_rh == NULL) { pe_err("Constraint %s needs two sides lh: %p rh: %p" " (NULL indicates missing side)", id, rsc_lh, rsc_rh); return FALSE; } - crm_str_to_boolean(symmetrical, &symmetrical_bool); + cl_str_to_boolean(symmetrical, &symmetrical_bool); if(safe_str_eq(type, "before")) { type_is_after = FALSE; } if(safe_str_eq(action, task2text(stop_rsc))) { action_is_start = FALSE; } if((type_is_after && action_is_start) || (type_is_after == FALSE && action_is_start == FALSE)){ if(symmetrical_bool || action_is_start == FALSE) { if(rsc_lh->restart_type == pe_restart_restart){ order_stop_stop(rsc_lh, rsc_rh, pe_ordering_recover); } order_stop_stop(rsc_lh, rsc_rh, pe_ordering_optional); } if(symmetrical_bool || action_is_start) { if(rsc_lh->restart_type == pe_restart_restart){ order_start_start(rsc_rh, rsc_lh, pe_ordering_recover); } order_start_start(rsc_rh, rsc_lh, pe_ordering_optional); } } else { if(symmetrical_bool || action_is_start == FALSE) { if(rsc_rh->restart_type == pe_restart_restart){ order_stop_stop(rsc_rh, rsc_lh, pe_ordering_recover); } order_stop_stop(rsc_rh, rsc_lh, pe_ordering_optional); } if(symmetrical_bool || action_is_start) { if(rsc_rh->restart_type == pe_restart_restart){ order_start_start(rsc_lh, rsc_rh, pe_ordering_recover); } order_start_start(rsc_lh, rsc_rh, pe_ordering_optional); } } return TRUE; } gboolean add_node_attrs(crm_data_t *xml_obj, node_t *node, pe_working_set_t *data_set) { g_hash_table_insert(node->details->attrs, crm_strdup("#"XML_ATTR_UNAME), crm_strdup(node->details->uname)); g_hash_table_insert(node->details->attrs, crm_strdup("#"XML_ATTR_ID), crm_strdup(node->details->id)); if(safe_str_eq(node->details->id, data_set->dc_uuid)) { data_set->dc_node = node; node->details->is_dc = TRUE; g_hash_table_insert(node->details->attrs, crm_strdup("#"XML_ATTR_DC), crm_strdup(XML_BOOLEAN_TRUE)); } else { g_hash_table_insert(node->details->attrs, crm_strdup("#"XML_ATTR_DC), crm_strdup(XML_BOOLEAN_FALSE)); } unpack_instance_attributes( - xml_obj, node, node->details->attrs, NULL, 0, data_set); + xml_obj, XML_TAG_ATTR_SETS, node, node->details->attrs, + NULL, 0, data_set); return TRUE; } gboolean unpack_rsc_location(crm_data_t * xml_obj, pe_working_set_t *data_set) { const char *id_lh = crm_element_value(xml_obj, "rsc"); const char *id = crm_element_value(xml_obj, XML_ATTR_ID); resource_t *rsc_lh = pe_find_resource(data_set->resources, id_lh); if(rsc_lh == NULL) { pe_warn("No resource (con=%s, rsc=%s)", id, id_lh); return FALSE; } else if(rsc_lh->is_managed == FALSE) { crm_debug_2("Ignoring constraint %s: resource %s not managed", id, id_lh); return FALSE; } xml_child_iter( xml_obj, rule_xml, XML_TAG_RULE, crm_debug_2("Unpacking %s/%s", id, ID(rule_xml)); generate_location_rule(rsc_lh, rule_xml, data_set); ); return TRUE; } rsc_to_node_t * generate_location_rule( resource_t *rsc, crm_data_t *rule_xml, pe_working_set_t *data_set) { const char *rule_id = NULL; const char *score = NULL; const char *boolean = NULL; GListPtr match_L = NULL; float score_f = 0.0; gboolean do_and = TRUE; gboolean accept = TRUE; rsc_to_node_t *location_rule = NULL; rule_id = crm_element_value(rule_xml, XML_ATTR_ID); score = crm_element_value(rule_xml, XML_RULE_ATTR_SCORE); boolean = crm_element_value(rule_xml, XML_RULE_ATTR_BOOLEAN_OP); crm_debug("processing rule: %s", rule_id); score_f = char2score(score); if(safe_str_eq(boolean, "or")) { do_and = FALSE; } location_rule = rsc2node_new(rule_id, rsc, score_f, NULL, data_set); if(location_rule == NULL) { return NULL; } if(do_and) { match_L = node_list_dup(data_set->nodes, FALSE); } xml_child_iter( rule_xml, expr, XML_TAG_EXPRESSION, slist_iter( node, node_t, data_set->nodes, lpc, accept = test_expression(expr, node, data_set); if(!do_and && accept) { if(pe_find_node(match_L, node->details->uname) == NULL) { node_t *dup = node_copy(node); match_L = g_list_append(match_L, dup); crm_debug_5("node %s matched", node->details->uname); } crm_debug_5("node %s already matched", node->details->uname); } else if(do_and && !accept) { /* remove it */ node_t *delete = pe_find_node( match_L, node->details->uname); if(delete != NULL) { match_L = g_list_remove(match_L,delete); crm_debug_5("node %s did not match", node->details->uname); } crm_free(delete); } ); ); location_rule->node_list_rh = match_L; if(location_rule->node_list_rh == NULL) { crm_debug_2("No matching nodes for rule %s", rule_id); return NULL; } crm_debug_2("%s: %d nodes matched", rule_id, g_list_length(location_rule->node_list_rh)); crm_action_debug_3(print_rsc_to_node("Added", location_rule, FALSE)); return location_rule; } diff --git a/crm/pengine/utils.c b/crm/pengine/utils.c index a517119057..de84279815 100644 --- a/crm/pengine/utils.c +++ b/crm/pengine/utils.c @@ -1,1587 +1,1589 @@ -/* $Id: utils.c,v 1.100 2005/08/11 08:58:40 andrew Exp $ */ +/* $Id: utils.c,v 1.101 2005/08/17 09:15:14 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 void print_str_str(gpointer key, gpointer value, gpointer user_data); gboolean ghash_free_str_str(gpointer key, gpointer value, gpointer user_data); void unpack_operation( action_t *action, crm_data_t *xml_obj, pe_working_set_t* data_set); /* only for rsc_colocation constraints */ rsc_colocation_t * invert_constraint(rsc_colocation_t *constraint) { rsc_colocation_t *inverted_con = NULL; crm_debug_3("Inverting constraint"); if(constraint == NULL) { pe_err("Cannot invert NULL constraint"); return NULL; } crm_malloc0(inverted_con, sizeof(rsc_colocation_t)); if(inverted_con == NULL) { return NULL; } inverted_con->id = constraint->id; inverted_con->strength = constraint->strength; /* swap the direction */ inverted_con->rsc_lh = constraint->rsc_rh; inverted_con->rsc_rh = constraint->rsc_lh; crm_action_debug_3( print_rsc_colocation("Inverted constraint", inverted_con, FALSE)); return inverted_con; } /* are the contents of list1 and list2 equal * nodes with weight < 0 are ignored if filter == TRUE * * slow but linear * */ gboolean node_list_eq(GListPtr list1, GListPtr list2, gboolean filter) { node_t *other_node; GListPtr lhs = list1; GListPtr rhs = list2; slist_iter( node, node_t, lhs, lpc, if(node == NULL || (filter && node->weight < 0)) { continue; } other_node = (node_t*) pe_find_node(rhs, node->details->uname); if(other_node == NULL || other_node->weight < 0) { return FALSE; } ); lhs = list2; rhs = list1; slist_iter( node, node_t, lhs, lpc, if(node == NULL || (filter && node->weight < 0)) { continue; } other_node = (node_t*) pe_find_node(rhs, node->details->uname); if(other_node == NULL || other_node->weight < 0) { return FALSE; } ); return TRUE; } /* the intersection of list1 and list2 */ GListPtr node_list_and(GListPtr list1, GListPtr list2, gboolean filter) { GListPtr result = NULL; unsigned lpc = 0; for(lpc = 0; lpc < g_list_length(list1); lpc++) { node_t *node = (node_t*)g_list_nth_data(list1, lpc); node_t *other_node = pe_find_node(list2, node->details->uname); node_t *new_node = NULL; if(other_node != NULL) { new_node = node_copy(node); } if(new_node != NULL) { new_node->weight = merge_weights( new_node->weight, other_node->weight); if(filter && new_node->weight < 0) { crm_free(new_node); new_node = NULL; } } if(new_node != NULL) { result = g_list_append(result, new_node); } } return result; } /* list1 - list2 */ GListPtr node_list_minus(GListPtr list1, GListPtr list2, gboolean filter) { GListPtr result = NULL; slist_iter( node, node_t, list1, lpc, node_t *other_node = pe_find_node(list2, node->details->uname); node_t *new_node = NULL; if(node == NULL || other_node != NULL || (filter && node->weight < 0)) { continue; } new_node = node_copy(node); result = g_list_append(result, new_node); ); crm_debug_3("Minus result len: %d", g_list_length(result)); return result; } /* list1 + list2 - (intersection of list1 and list2) */ GListPtr node_list_xor(GListPtr list1, GListPtr list2, gboolean filter) { GListPtr result = NULL; slist_iter( node, node_t, list1, lpc, node_t *new_node = NULL; node_t *other_node = (node_t*) pe_find_node(list2, node->details->uname); if(node == NULL || other_node != NULL || (filter && node->weight < 0)) { continue; } new_node = node_copy(node); result = g_list_append(result, new_node); ); slist_iter( node, node_t, list2, lpc, node_t *new_node = NULL; node_t *other_node = (node_t*) pe_find_node(list1, node->details->uname); if(node == NULL || other_node != NULL || (filter && node->weight < 0)) { continue; } new_node = node_copy(node); result = g_list_append(result, new_node); ); crm_debug_3("Xor result len: %d", g_list_length(result)); return result; } GListPtr node_list_or(GListPtr list1, GListPtr list2, gboolean filter) { node_t *other_node = NULL; GListPtr result = NULL; gboolean needs_filter = FALSE; result = node_list_dup(list1, filter); slist_iter( node, node_t, list2, lpc, if(node == NULL) { continue; } other_node = (node_t*)pe_find_node( result, node->details->uname); if(other_node != NULL) { other_node->weight = merge_weights( other_node->weight, node->weight); if(filter && node->weight < 0) { needs_filter = TRUE; } } else if(filter == FALSE || node->weight >= 0) { node_t *new_node = node_copy(node); result = g_list_append(result, new_node); } ); /* not the neatest way, but the most expedient for now */ if(filter && needs_filter) { GListPtr old_result = result; result = node_list_dup(old_result, filter); pe_free_shallow_adv(old_result, TRUE); } return result; } GListPtr node_list_dup(GListPtr list1, gboolean filter) { GListPtr result = NULL; slist_iter( this_node, node_t, list1, lpc, node_t *new_node = NULL; if(filter && this_node->weight < 0) { continue; } new_node = node_copy(this_node); if(new_node != NULL) { result = g_list_append(result, new_node); } ); return result; } node_t * node_copy(node_t *this_node) { node_t *new_node = NULL; CRM_DEV_ASSERT(this_node != NULL); if(this_node == NULL) { pe_err("Failed copy of node."); return NULL; } crm_malloc0(new_node, sizeof(node_t)); CRM_DEV_ASSERT(new_node != NULL); if(new_node == NULL) { return NULL; } crm_debug_5("Copying %p (%s) to %p", this_node, this_node->details->uname, new_node); new_node->weight = this_node->weight; new_node->fixed = this_node->fixed; new_node->details = this_node->details; return new_node; } /* * Create a new color with the contents of "nodes" as the list of * possible nodes that resources with this color can be run on. * * Typically, when creating a color you will provide the node list from * the resource you will first assign the color to. * * If "colors" != NULL, it will be added to that list * If "resources" != NULL, it will be added to every provisional resource * in that list */ color_t * create_color( pe_working_set_t *data_set, resource_t *resource, GListPtr node_list) { color_t *new_color = NULL; crm_debug_5("Creating color"); crm_malloc0(new_color, sizeof(color_t)); if(new_color == NULL) { return NULL; } new_color->id = data_set->color_id++; new_color->local_weight = 1.0; crm_debug_5("Creating color details"); crm_malloc0(new_color->details, sizeof(struct color_shared_s)); if(new_color->details == NULL) { crm_free(new_color); return NULL; } new_color->details->id = new_color->id; new_color->details->highest_priority = -1; new_color->details->chosen_node = NULL; new_color->details->candidate_nodes = NULL; new_color->details->allocated_resources = NULL; new_color->details->pending = TRUE; if(resource != NULL) { crm_debug_5("populating node list"); new_color->details->highest_priority = resource->priority; new_color->details->candidate_nodes = node_list_dup(node_list, TRUE); } crm_action_debug_3(print_color("Created color", new_color, TRUE)); CRM_DEV_ASSERT(data_set != NULL); if(crm_assert_failed == FALSE) { data_set->colors = g_list_append(data_set->colors, new_color); } return new_color; } color_t * copy_color(color_t *a_color) { color_t *color_copy = NULL; if(a_color == NULL) { pe_err("Cannot copy NULL"); return NULL; } crm_malloc0(color_copy, sizeof(color_t)); if(color_copy != NULL) { color_copy->id = a_color->id; color_copy->details = a_color->details; color_copy->local_weight = 1.0; } return color_copy; } resource_t * pe_find_resource(GListPtr rsc_list, const char *id) { unsigned lpc = 0; resource_t *rsc = NULL; resource_t *child_rsc = NULL; crm_debug_4("Looking for %s in %d objects", id, g_list_length(rsc_list)); for(lpc = 0; lpc < g_list_length(rsc_list); lpc++) { rsc = g_list_nth_data(rsc_list, lpc); if(rsc != NULL && safe_str_eq(rsc->id, id)){ crm_debug_4("Found a match for %s", id); return rsc; } } for(lpc = 0; lpc < g_list_length(rsc_list); lpc++) { rsc = g_list_nth_data(rsc_list, lpc); child_rsc = rsc->fns->find_child(rsc, id); if(child_rsc != NULL) { crm_debug_4("Found a match for %s in %s", id, rsc->id); return child_rsc; } } /* error */ return NULL; } node_t * pe_find_node(GListPtr nodes, const char *uname) { unsigned lpc = 0; node_t *node = NULL; for(lpc = 0; lpc < g_list_length(nodes); lpc++) { node = g_list_nth_data(nodes, lpc); if(node != NULL && safe_str_eq(node->details->uname, uname)) { return node; } } /* error */ return NULL; } node_t * pe_find_node_id(GListPtr nodes, const char *id) { unsigned lpc = 0; node_t *node = NULL; for(lpc = 0; lpc < g_list_length(nodes); lpc++) { node = g_list_nth_data(nodes, lpc); if(safe_str_eq(node->details->id, id)) { return node; } } /* error */ return NULL; } gint gslist_color_compare(gconstpointer a, gconstpointer b); color_t * find_color(GListPtr candidate_colors, color_t *other_color) { GListPtr tmp = g_list_find_custom(candidate_colors, other_color, gslist_color_compare); if(tmp != NULL) { return (color_t *)tmp->data; } return NULL; } gint gslist_color_compare(gconstpointer a, gconstpointer b) { const color_t *color_a = (const color_t*)a; const color_t *color_b = (const color_t*)b; /* crm_debug_5("%d vs. %d", a?color_a->id:-2, b?color_b->id:-2); */ if(a == b) { return 0; } else if(a == NULL || b == NULL) { return 1; } else if(color_a->id == color_b->id) { return 0; } return 1; } gint sort_rsc_priority(gconstpointer a, gconstpointer b) { const resource_t *resource1 = (const resource_t*)a; const resource_t *resource2 = (const resource_t*)b; if(a == NULL && b == NULL) { return 0; } if(a == NULL) { return 1; } if(b == NULL) { return -1; } if(resource1->priority > resource2->priority) { return -1; } if(resource1->priority < resource2->priority) { return 1; } return 0; } /* lowest to highest */ gint sort_action_id(gconstpointer a, gconstpointer b) { const action_wrapper_t *action_wrapper2 = (const action_wrapper_t*)a; const action_wrapper_t *action_wrapper1 = (const action_wrapper_t*)b; if(a == NULL) { return 1; } if(b == NULL) { return -1; } if(action_wrapper1->action->id > action_wrapper2->action->id) { return -1; } if(action_wrapper1->action->id < action_wrapper2->action->id) { return 1; } return 0; } gint sort_cons_strength(gconstpointer a, gconstpointer b) { const rsc_colocation_t *rsc_constraint1 = (const rsc_colocation_t*)a; const rsc_colocation_t *rsc_constraint2 = (const rsc_colocation_t*)b; if(a == NULL) { return 1; } if(b == NULL) { return -1; } if(rsc_constraint1->strength > rsc_constraint2->strength) { return 1; } if(rsc_constraint1->strength < rsc_constraint2->strength) { return -1; } return 0; } gint sort_color_weight(gconstpointer a, gconstpointer b) { const color_t *color1 = (const color_t*)a; const color_t *color2 = (const color_t*)b; if(a == NULL) { return 1; } if(b == NULL) { return -1; } if(color1->local_weight > color2->local_weight) { return -1; } if(color1->local_weight < color2->local_weight) { return 1; } return 0; } /* return -1 if 'a' is more preferred * return 1 if 'b' is more preferred */ gint sort_node_weight(gconstpointer a, gconstpointer b) { const node_t *node1 = (const node_t*)a; const node_t *node2 = (const node_t*)b; float node1_weight = 0; float node2_weight = 0; if(a == NULL) { return 1; } if(b == NULL) { return -1; } node1_weight = node1->weight; node2_weight = node2->weight; if(node1->details->unclean || node1->details->shutdown) { node1_weight = -INFINITY; } if(node2->details->unclean || node2->details->shutdown) { node2_weight = -INFINITY; } if(node1_weight > node2_weight) { crm_debug_4("%s (%f) > %s (%f) : weight", node1->details->id, node1_weight, node2->details->id, node2_weight); return -1; } if(node1_weight < node2_weight) { crm_debug_4("%s (%f) < %s (%f) : weight", node1->details->id, node1_weight, node2->details->id, node2_weight); return 1; } /* now try to balance resources across the cluster */ if(node1->details->num_resources < node2->details->num_resources) { crm_debug_4("%s (%d) < %s (%d) : resources", node1->details->id, node1->details->num_resources, node2->details->id, node2->details->num_resources); return -1; } else if(node1->details->num_resources > node2->details->num_resources) { crm_debug_4("%s (%d) > %s (%d) : resources", node1->details->id, node1->details->num_resources, node2->details->id, node2->details->num_resources); return 1; } crm_debug_4("%s = %s", node1->details->id, node2->details->id); return 0; } action_t * custom_action(resource_t *rsc, char *key, const char *task, node_t *on_node, gboolean optional, pe_working_set_t *data_set) { action_t *action = NULL; GListPtr possible_matches = NULL; CRM_DEV_ASSERT(key != NULL); if(crm_assert_failed) { return NULL; } CRM_DEV_ASSERT(task != NULL); if(crm_assert_failed) { return NULL; } if(rsc != NULL) { possible_matches = find_actions(rsc->actions, key, on_node); } if(possible_matches != NULL) { crm_free(key); if(g_list_length(possible_matches) > 1) { pe_warn("Action %s for %s on %s exists %d times", task, rsc?rsc->id:"", on_node?on_node->details->uname:"", g_list_length(possible_matches)); } action = g_list_nth_data(possible_matches, 0); crm_debug_4("Found existing action (%d) %s for %s on %s", action->id, task, rsc?rsc->id:"", on_node?on_node->details->uname:""); } if(action == NULL) { crm_debug_2("Creating action %d: %s for %s on %s", data_set->action_id, task, rsc?rsc->id:"", on_node?on_node->details->uname:""); crm_malloc0(action, sizeof(action_t)); if(action != NULL) { action->id = data_set->action_id++; action->rsc = rsc; action->task = task; action->node = on_node; action->actions_before = NULL; action->actions_after = NULL; action->failure_is_fatal = TRUE; action->pseudo = FALSE; action->dumped = FALSE; action->runnable = TRUE; action->processed = FALSE; action->optional = TRUE; action->seen_count = 0; action->extra = g_hash_table_new_full( g_str_hash, g_str_equal, g_hash_destroy_str, g_hash_destroy_str); data_set->actions = g_list_append( data_set->actions, action); action->uuid = key; if(rsc != NULL) { action->op_entry = find_rsc_op_entry(rsc, key); unpack_operation( action, action->op_entry, data_set); rsc->actions = g_list_append( rsc->actions, action); } crm_debug_4("Action %d created", action->id); } } if(optional == FALSE) { crm_debug_2("Action %d marked manditory", action->id); action->optional = FALSE; } if(rsc != NULL) { if(action->node != NULL) { unpack_instance_attributes( - action->op_entry, action->node, action->extra, - NULL, 0, data_set); + action->op_entry, XML_TAG_ATTR_SETS, + action->node, action->extra, NULL,0, data_set); } if(action->node == NULL) { action->runnable = FALSE; } else if(action->node->details->online == FALSE) { pe_warn("Action %d %s for %s on %s is unrunnable", action->id, task, rsc?rsc->id:"", action->node?action->node->details->uname:""); action->runnable = FALSE; } else if(action->needs == rsc_req_nothing) { crm_debug_2("Action doesnt require anything"); action->runnable = TRUE; #if 0 /* * No point checking this * - if we dont have quorum we cant stonith anyway */ } else if(action->needs == rsc_req_stonith) { crm_debug_2("Action requires only stonith"); action->runnable = TRUE; #endif } else if(data_set->have_quorum == FALSE && data_set->no_quorum_policy == no_quorum_stop) { action->runnable = FALSE; crm_warn("%s resource %s\t(%s) (cancelled : quorum)", action->task, rsc->id, action->node->details->uname); } else if(data_set->have_quorum == FALSE && data_set->no_quorum_policy == no_quorum_freeze) { crm_debug_2("Check resource is already active"); if(rsc->fns->active(rsc, TRUE) == FALSE) { action->runnable = FALSE; crm_warn("%s resource %s\t(%s) (cancelled : quorum freeze)", action->task, rsc->id, action->node->details->uname); } } else { crm_debug_2("Action is runnable"); action->runnable = TRUE; } switch(text2task(action->task)) { case stop_rsc: rsc->stopping = TRUE; break; case start_rsc: rsc->starting = FALSE; if(action->runnable) { rsc->starting = TRUE; } break; default: break; } } return action; } void unpack_operation( action_t *action, crm_data_t *xml_obj, pe_working_set_t* data_set) { int lpc = 0; const char *value = NULL; const char *fields[] = { "interval", "timeout", "start_delay", }; CRM_DEV_ASSERT(action->rsc != NULL); if(xml_obj != NULL) { value = crm_element_value(xml_obj, "prereq"); } if(value == NULL && safe_str_eq(action->task, CRMD_ACTION_START)) { - value = crm_element_value(action->rsc->xml, "start_prereq"); + value = g_hash_table_lookup( + action->rsc->parameters, "start_prereq"); } if(value == NULL && safe_str_neq(action->task, CRMD_ACTION_START)) { /* todo: integrate stop as an option? */ action->needs = rsc_req_nothing; value = "nothing (default)"; } else if(safe_str_eq(value, "nothing")) { action->needs = rsc_req_nothing; } else if(safe_str_eq(value, "quorum")) { action->needs = rsc_req_quorum; } else if(safe_str_eq(value, "fencing")) { action->needs = rsc_req_stonith; } else if(data_set->no_quorum_policy == no_quorum_ignore) { action->needs = rsc_req_nothing; value = "nothing (default)"; } else if(data_set->no_quorum_policy == no_quorum_freeze && data_set->stonith_enabled) { action->needs = rsc_req_stonith; value = "fencing (default)"; } else { action->needs = rsc_req_quorum; value = "quorum (default)"; } crm_debug_2("\tAction %s requires: %s", action->task, value); value = NULL; if(xml_obj != NULL) { value = crm_element_value(xml_obj, "on_fail"); } if(value == NULL && safe_str_eq(action->task, CRMD_ACTION_STOP)) { - value = crm_element_value(action->rsc->xml, "on_stopfail"); + value = g_hash_table_lookup( + action->rsc->parameters, "on_stopfail"); } if(value == NULL) { } else if(safe_str_eq(value, "fence")) { action->on_fail = action_fail_fence; value = "node fencing"; } else if(safe_str_eq(value, "stop")) { action->on_fail = action_fail_stop; value = "resource stop"; } else if(safe_str_eq(value, "nothing")) { action->on_fail = action_fail_nothing; } else if(safe_str_eq(value, "block")) { action->on_fail = action_fail_block; } else if(safe_str_eq(value, "ignore")) { action->on_fail = action_fail_nothing; value = "nothing"; } else { pe_err("Resource %s: Unknown failure type (%s)", action->rsc->id, value); value = NULL; } /* defaults */ if(value == NULL && safe_str_eq(action->task, CRMD_ACTION_STOP)) { if(data_set->stonith_enabled) { action->on_fail = action_fail_fence; value = "resource fence (default)"; } else { action->on_fail = action_fail_block; value = "resource block (default)"; } } else if(value == NULL) { action->on_fail = action_fail_stop; value = "resource stop (default)"; } crm_debug_2("\t%s failure results in: %s", action->task, value); if(xml_obj == NULL) { return; } for(;lpc < DIMOF(fields); lpc++) { value = crm_element_value(xml_obj, fields[lpc]); add_hash_param(action->extra, fields[lpc], value); } /* if(safe_str_eq(native_data->agent->class, "stonith")) { */ /* if(rsc->start_needs == rsc_req_stonith) { */ /* pe_err("Stonith resources (eg. %s) cannot require" */ /* " fencing to start", rsc->id); */ /* } */ /* rsc->start_needs = rsc_req_quorum; */ /* } */ } crm_data_t * find_rsc_op_entry(resource_t *rsc, const char *key) { const char *name = NULL; const char *interval = NULL; char *match_key = NULL; crm_data_t *op = NULL; xml_child_iter( rsc->ops_xml, operation, "op", name = crm_element_value(operation, "name"); interval = crm_element_value(operation, "interval"); match_key = generate_op_key(rsc->id,name,crm_get_msec(interval)); crm_debug_2("Matching %s with %s", key, match_key); if(safe_str_eq(key, match_key)) { op = operation; } crm_free(match_key); if(op != NULL) { break; } ); crm_debug_2("No matching for %s", key); return op; } const char * strength2text(enum con_strength strength) { const char *result = ""; switch(strength) { case pecs_ignore: result = "ignore"; break; case pecs_must: result = XML_STRENGTH_VAL_MUST; break; case pecs_must_not: result = XML_STRENGTH_VAL_MUSTNOT; break; case pecs_startstop: result = "start/stop"; break; } return result; } const char * ordering_type2text(enum pe_ordering type) { const char *result = ""; switch(type) { case pe_ordering_manditory: result = "manditory"; break; case pe_ordering_restart: result = "restart"; break; case pe_ordering_recover: result = "recover"; break; case pe_ordering_optional: result = "optional"; break; case pe_ordering_postnotify: result = "post_notify"; break; } return result; } enum action_tasks text2task(const char *task) { if(safe_str_eq(task, CRMD_ACTION_STOP)) { return stop_rsc; } else if(safe_str_eq(task, CRMD_ACTION_STOPPED)) { return stopped_rsc; } else if(safe_str_eq(task, CRMD_ACTION_START)) { return start_rsc; } else if(safe_str_eq(task, CRMD_ACTION_STARTED)) { return started_rsc; } else if(safe_str_eq(task, CRM_OP_SHUTDOWN)) { return shutdown_crm; } else if(safe_str_eq(task, CRM_OP_FENCE)) { return stonith_node; } else if(safe_str_eq(task, CRMD_ACTION_MON)) { return monitor_rsc; } else if(safe_str_eq(task, CRMD_ACTION_NOTIFY)) { return action_notify; } else if(safe_str_eq(task, CRMD_ACTION_NOTIFIED)) { return action_notified; } pe_err("Unsupported action: %s", task); return no_action; } const char * task2text(enum action_tasks task) { const char *result = ""; switch(task) { case no_action: result = "no_action"; break; case stop_rsc: result = CRMD_ACTION_STOP; break; case stopped_rsc: result = CRMD_ACTION_STOPPED; break; case start_rsc: result = CRMD_ACTION_START; break; case started_rsc: result = CRMD_ACTION_STARTED; break; case shutdown_crm: result = CRM_OP_SHUTDOWN; break; case stonith_node: result = CRM_OP_FENCE; break; case monitor_rsc: result = CRMD_ACTION_MON; break; case action_notify: result = CRMD_ACTION_NOTIFY; break; case action_notified: result = CRMD_ACTION_NOTIFIED; break; } return result; } const char * rsc_state2text(rsc_state_t state) { const char *result = ""; switch(state) { case rsc_state_active: result = "active"; break; case rsc_state_restart: result = "restart"; break; case rsc_state_move: result = "move"; break; case rsc_state_starting: result = "starting"; break; case rsc_state_stopping: result = "stopping"; break; case rsc_state_stopped: result = "stopped"; break; case rsc_state_unknown: result = "unknown"; break; } return result; } void print_node(const char *pre_text, node_t *node, gboolean details) { if(node == NULL) { crm_debug_4("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug_4("%s%s%sNode %s: (weight=%f, fixed=%s)", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", node->details==NULL?"error ":node->details->online?"":"Unavailable/Unclean ", node->details->uname, node->weight, node->fixed?"True":"False"); if(details && node != NULL && node->details != NULL) { char *pe_mutable = crm_strdup("\t\t"); crm_debug_4("\t\t===Node Attributes"); g_hash_table_foreach(node->details->attrs, print_str_str, pe_mutable); crm_free(pe_mutable); crm_debug_4("\t\t=== Resources"); slist_iter( rsc, resource_t, node->details->running_rsc, lpc, print_resource("\t\t", rsc, FALSE); ); } } /* * Used by the HashTable for-loop */ void print_str_str(gpointer key, gpointer value, gpointer user_data) { crm_debug_4("%s%s %s ==> %s", user_data==NULL?"":(char*)user_data, user_data==NULL?"":": ", (char*)key, (char*)value); } void print_color_details(const char *pre_text, struct color_shared_s *color, gboolean details) { if(color == NULL) { crm_debug_4("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug_4("%s%sColor %d: node=%s (from %d candidates)", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", color->id, color->chosen_node==NULL?"":color->chosen_node->details->uname, g_list_length(color->candidate_nodes)); if(details) { slist_iter(node, node_t, color->candidate_nodes, lpc, print_node("\t", node, FALSE)); } } void print_color(const char *pre_text, color_t *color, gboolean details) { if(color == NULL) { crm_debug_4("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug_4("%s%sColor %d: (weight=%f, node=%s, possible=%d)", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", color->id, color->local_weight, safe_val5("",color,details,chosen_node,details,uname), g_list_length(color->details->candidate_nodes)); if(details) { print_color_details("\t", color->details, details); } } void print_rsc_to_node(const char *pre_text, rsc_to_node_t *cons, gboolean details) { if(cons == NULL) { crm_debug_4("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug_4("%s%s%s Constraint %s (%p) - %d nodes:", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", "rsc_to_node", cons->id, cons, g_list_length(cons->node_list_rh)); if(details == FALSE) { crm_debug_4("\t%s (score=%f : node placement rule)", safe_val3(NULL, cons, rsc_lh, id), cons->weight); slist_iter( node, node_t, cons->node_list_rh, lpc, print_node("\t\t-->", node, FALSE) ); } } void print_rsc_colocation(const char *pre_text, rsc_colocation_t *cons, gboolean details) { if(cons == NULL) { crm_debug_4("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } crm_debug_4("%s%s%s Constraint %s (%p):", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", XML_CONS_TAG_RSC_DEPEND, cons->id, cons); if(details == FALSE) { crm_debug_4("\t%s --> %s, %s", safe_val3(NULL, cons, rsc_lh, id), safe_val3(NULL, cons, rsc_rh, id), strength2text(cons->strength)); } } void print_resource(const char *pre_text, resource_t *rsc, gboolean details) { if(rsc == NULL) { crm_debug_4("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } rsc->fns->dump(rsc, pre_text, details); } void print_action(const char *pre_text, action_t *action, gboolean details) { log_action(LOG_DEBUG_3, pre_text, action, details); } #define util_log(fmt...) do_crm_log(log_level, __FILE__, __FUNCTION__, fmt) void log_action(unsigned int log_level, const char *pre_text, action_t *action, gboolean details) { const char *node_uname = NULL; const char *node_uuid = NULL; if(action == NULL) { util_log("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } if(action->pseudo) { node_uname = NULL; node_uuid = NULL; } else if(action->node != NULL) { node_uname = action->node->details->uname; node_uuid = action->node->details->id; } else { node_uname = ""; node_uuid = NULL; } switch(text2task(action->task)) { case stonith_node: case shutdown_crm: crm_log_maybe(log_level, "%s%s%sAction %d: %s%s%s%s%s%s", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", action->pseudo?"Pseduo ":action->optional?"Optional ":action->runnable?action->processed?"":"(Provisional) ":"!!Non-Startable!! ", action->id, action->task, node_uname?"\ton ":"", node_uname?node_uname:"", node_uuid?"\t\t(":"", node_uuid?node_uuid:"", node_uuid?")":""); break; default: crm_log_maybe(log_level, "%s%s%sAction %d: %s %s%s%s%s%s%s", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", action->optional?"Optional ":action->pseudo?"Pseduo ":action->runnable?action->processed?"":"(Provisional) ":"!!Non-Startable!! ", action->id, action->task, safe_val3("", action, rsc, id), node_uname?"\ton ":"", node_uname?node_uname:"", node_uuid?"\t\t(":"", node_uuid?node_uuid:"", node_uuid?")":""); break; } if(details) { crm_log_maybe(log_level+1, "\t\t====== Preceeding Actions"); slist_iter( other, action_wrapper_t, action->actions_before, lpc, log_action(log_level+1, "\t\t", other->action, FALSE); ); #if 1 crm_log_maybe(log_level+1, "\t\t====== Subsequent Actions"); slist_iter( other, action_wrapper_t, action->actions_after, lpc, log_action(log_level+1, "\t\t", other->action, FALSE); ); #endif crm_log_maybe(log_level+1, "\t\t====== End"); } else { crm_log_maybe(log_level, "\t\t(seen=%d, before=%d, after=%d)", action->seen_count, g_list_length(action->actions_before), g_list_length(action->actions_after)); } } void pe_free_nodes(GListPtr nodes) { GListPtr iterator = nodes; while(iterator != NULL) { node_t *node = (node_t*)iterator->data; struct node_shared_s *details = node->details; iterator = iterator->next; crm_debug_5("deleting node"); crm_debug_5("%s is being deleted", details->uname); print_node("delete", node, FALSE); if(details != NULL) { if(details->attrs != NULL) { g_hash_table_destroy(details->attrs); } pe_free_shallow_adv(details->running_rsc, FALSE); crm_free(details); } crm_free(node); } if(nodes != NULL) { g_list_free(nodes); } } void pe_free_colors(GListPtr colors) { GListPtr iterator = colors; while(iterator != NULL) { color_t *color = (color_t *)iterator->data; struct color_shared_s *details = color->details; iterator = iterator->next; if(details != NULL) { pe_free_shallow(details->candidate_nodes); pe_free_shallow_adv(details->allocated_resources, FALSE); crm_free(details->chosen_node); crm_free(details); } crm_free(color); } if(colors != NULL) { g_list_free(colors); } } void pe_free_shallow(GListPtr alist) { pe_free_shallow_adv(alist, TRUE); } void pe_free_shallow_adv(GListPtr alist, gboolean with_data) { GListPtr item; GListPtr item_next = alist; while(item_next != NULL) { item = item_next; item_next = item_next->next; if(with_data) { /* crm_debug_5("freeing %p", item->data); */ crm_free(item->data); } item->data = NULL; item->next = NULL; g_list_free(item); } } void pe_free_resources(GListPtr resources) { resource_t *rsc = NULL; GListPtr iterator = resources; while(iterator != NULL) { iterator = iterator; rsc = (resource_t *)iterator->data; iterator = iterator->next; rsc->fns->free(rsc); } if(resources != NULL) { g_list_free(resources); } } void pe_free_actions(GListPtr actions) { GListPtr iterator = actions; while(iterator != NULL) { action_t *action = (action_t *)iterator->data; iterator = iterator->next; pe_free_shallow(action->actions_before);/* action_warpper_t* */ pe_free_shallow(action->actions_after); /* action_warpper_t* */ g_hash_table_destroy(action->extra); crm_free(action->uuid); crm_free(action); } if(actions != NULL) { g_list_free(actions); } } void pe_free_ordering(GListPtr constraints) { GListPtr iterator = constraints; while(iterator != NULL) { order_constraint_t *order = iterator->data; iterator = iterator->next; crm_free(order->lh_action_task); crm_free(order->rh_action_task); crm_free(order); } if(constraints != NULL) { g_list_free(constraints); } } void pe_free_rsc_colocation(rsc_colocation_t *cons) { if(cons != NULL) { crm_debug_4("Freeing constraint %s (%p)", cons->id, cons); crm_free(cons); } } void pe_free_rsc_to_node(rsc_to_node_t *cons) { if(cons != NULL) { pe_free_shallow(cons->node_list_rh); crm_free(cons); } } GListPtr find_actions(GListPtr input, const char *key, node_t *on_node) { GListPtr result = NULL; CRM_DEV_ASSERT(key != NULL); slist_iter( action, action_t, input, lpc, crm_debug_5("Matching %s against %s", key, action->uuid); if(safe_str_neq(key, action->uuid)) { continue; } else if(on_node == NULL) { result = g_list_append(result, action); } else if(action->node == NULL) { /* skip */ crm_debug_2("While looking for %s action on %s, " "found an unallocated one. Assigning" " it to the requested node...", key, on_node->details->uname); action->node = on_node; result = g_list_append(result, action); } else if(safe_str_eq(on_node->details->id, action->node->details->id)) { result = g_list_append(result, action); } ); return result; } void set_id(crm_data_t * xml_obj, const char *prefix, int child) { int id_len = 0; gboolean use_prefix = TRUE; gboolean use_child = TRUE; char *new_id = NULL; const char *id = crm_element_value(xml_obj, XML_ATTR_ID); id_len = 1 + strlen(id); if(child > 999) { pe_err("Are you insane?!?" " The CRM does not support > 1000 children per resource"); return; } else if(child < 0) { use_child = FALSE; } else { id_len += 4; /* child */ } if(prefix == NULL || safe_str_eq(id, prefix)) { use_prefix = FALSE; } else { id_len += (1 + strlen(prefix)); } crm_malloc0(new_id, id_len); if(use_child) { snprintf(new_id, id_len, "%s%s%s:%d", use_prefix?prefix:"", use_prefix?":":"", id, child); } else { snprintf(new_id, id_len, "%s%s%s", use_prefix?prefix:"", use_prefix?":":"", id); } crm_xml_add(xml_obj, XML_ATTR_ID, new_id); crm_free(new_id); } float merge_weights(float w1, float w2) { float result = w1 + w2; if(w1 <= -INFINITY || w2 <= -INFINITY) { if(w1 >= INFINITY || w2 >= INFINITY) { pe_warn("-INFINITY + INFINITY == -INFINITY"); } return -INFINITY; } else if(w1 >= INFINITY || w2 >= INFINITY) { return INFINITY; } /* detect wrap-around */ if(result > 0) { if(w1 <= 0 && w2 < 0) { result = -INFINITY; } } else if(w1 > 0 && w2 > 0) { result = INFINITY; } /* detect +/- INFINITY */ if(result >= INFINITY) { result = INFINITY; } else if(result <= -INFINITY) { result = -INFINITY; } return result; } float char2score(const char *score) { float score_f = 0.0; if(score == NULL) { } else if(safe_str_eq(score, MINUS_INFINITY_S)) { score_f = -INFINITY; } else if(safe_str_eq(score, INFINITY_S)) { score_f = INFINITY; } else { score_f = atof(score); if(score_f > 0 && score_f > INFINITY) { score_f = INFINITY; } else if(score_f < 0 && score_f < -INFINITY) { score_f = -INFINITY; } } return score_f; }