diff --git a/crm/pengine/Makefile.am b/crm/pengine/Makefile.am index db526cc383..483cb12e6f 100644 --- a/crm/pengine/Makefile.am +++ b/crm/pengine/Makefile.am @@ -1,85 +1,85 @@ # # 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 # of the License, or (at your option) any later version. # # This program 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 program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # MAINTAINERCLEANFILES = Makefile.in INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include \ -I$(top_builddir)/libltdl -I$(top_srcdir)/libltdl \ -I$(top_builddir)/linux-ha -I$(top_srcdir)/linux-ha \ -I$(top_builddir) -I$(top_srcdir) hadir = $(sysconfdir)/ha.d halibdir = $(libdir)/@HB_PKG@ commmoddir = $(halibdir)/modules/comm havarlibdir = $(localstatedir)/lib/@HB_PKG@ PIDFILE = $(localstatedir)/run/crmd.pid XML_FLAGS = `xml2-config --cflags` XML_LIBS = `xml2-config --libs` # sockets with path crmdir = $(havarlibdir)/crm apigid = @HA_APIGID@ crmuid = @HA_CCMUID@ COMMONLIBS = $(CRM_DEBUG_LIBS) \ $(top_builddir)/lib/clplumbing/libplumb.la \ $(top_builddir)/$(CRM_DIR)/common/libcrmcommon.la \ $(top_builddir)/$(CRM_DIR)/cib/libcib.la \ $(top_builddir)/lib/apphb/libapphb.la \ $(GLIBLIB) \ $(LIBRT) LIBRT = @LIBRT@ AM_CFLAGS = @CFLAGS@ \ -DPIDFILE='"$(PIDFILE)"' \ $(CRM_DEBUG_FLAGS) ## libraries lib_LTLIBRARIES = ## binary progs halib_PROGRAMS = ptest pengine ## SOURCES noinst_HEADERS = pe_utils.h pengine.h complex.h ptest_SOURCES = pengine.c stages.c unpack.c color.c graph.c utils.c ptest.c \ - complex.c native.c + complex.c native.c group.c ptest_CFLAGS = $(XML_FLAGS) -DHA_VARLIBDIR='"@HA_VARLIBDIR@"' ptest_LDFLAGS = $(XML_LIBS) ptest_LDADD = $(COMMONLIBS) pengine_SOURCES = pengine.c stages.c unpack.c color.c graph.c utils.c main.c \ - complex.c native.c + complex.c native.c group.c pengine_CFLAGS = $(XML_FLAGS) -DHA_VARLIBDIR='"@HA_VARLIBDIR@"' pengine_LDFLAGS = $(XML_LIBS) pengine_LDADD = $(COMMONLIBS) \ $(top_builddir)/lib/hbclient/libhbclient.la # clean-generic: rm -f *.log *.debug *~ install-exec-local: uninstall-local: diff --git a/crm/pengine/complex.c b/crm/pengine/complex.c index 41295d378c..f37abf71c7 100644 --- a/crm/pengine/complex.c +++ b/crm/pengine/complex.c @@ -1,232 +1,273 @@ -/* $Id: complex.c,v 1.1 2004/11/09 09:32:14 andrew Exp $ */ +/* $Id: complex.c,v 1.2 2004/11/09 11:18:00 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include +#include + gboolean update_node_weight(rsc_to_node_t *cons,const char *id,GListPtr nodes); gboolean is_active(rsc_to_node_t *cons); gboolean constraint_violated( resource_t *rsc_lh, resource_t *rsc_rh, rsc_dependancy_t *constraint); void order_actions(action_t *lh, action_t *rh, order_constraint_t *order); resource_object_functions_t resource_class_functions[] = { { native_unpack, native_color, native_create_actions, native_internal_ordering, native_rsc_dependancy_lh, native_rsc_dependancy_rh, native_rsc_order_lh, native_rsc_order_rh, native_rsc_location, native_expand, native_dump, native_free - } -/* { */ -/* group_expand, */ -/* group_n_colors, */ -/* group_assign, */ -/* group_expand, */ -/* group_internal_constraints, */ -/* group_rsc_dependancy, */ -/* group_rsc_order, */ -/* group_rsc_location, */ -/* group_dump */ -/* }, */ + }, + { + group_unpack, + group_color, + group_create_actions, + group_internal_ordering, + group_rsc_dependancy_lh, + group_rsc_dependancy_rh, + group_rsc_order_lh, + group_rsc_order_rh, + group_rsc_location, + group_expand, + group_dump, + group_free + }, /* { */ /* incarnation_expand, */ /* incarnation_n_colors, */ /* incarnation_assign, */ /* incarnation_expand, */ /* incarnation_internal_constraints, */ /* incarnation_rsc_dependancy, */ /* incarnation_rsc_order, */ /* incarnation_rsc_location, */ /* incarnation_dump */ /* }, */ }; /* resource_object_functions_t resource_variants[] = resource_class_functions; */ int get_resource_type(const char *name) { if(safe_str_eq(name, "resource")) { return pe_native; } return pe_unknown; } gboolean is_active(rsc_to_node_t *cons) { /* todo: check constraint lifetime */ return TRUE; } +gboolean +common_unpack(xmlNodePtr xml_obj, resource_t **rsc) +{ + const char *id = xmlGetProp(xml_obj, XML_ATTR_ID); + + crm_verbose("Processing resource..."); + + if(id == NULL) { + crm_err("Must specify id tag in "); + return FALSE; + + } else if(rsc == NULL) { + crm_err("Nowhere to unpack resource into"); + return FALSE; + + } + crm_malloc(*rsc, sizeof(resource_t)); + + if(*rsc == NULL) { + return FALSE; + } + + (*rsc)->id = id; + (*rsc)->xml = xml_obj; + (*rsc)->variant = get_resource_type(xml_obj->name); + + if((*rsc)->variant == pe_unknown) { + crm_err("Unknown resource type: %s", xml_obj->name); + crm_free(*rsc); + return FALSE; + } + + (*rsc)->fns = &resource_class_functions[(*rsc)->variant]; + (*rsc)->fns->unpack(*rsc); + return TRUE; +} gboolean update_node_weight(rsc_to_node_t *cons, const char *id, GListPtr nodes) { node_t *node_rh = pe_find_node(cons->rsc_lh->allowed_nodes, id); if(node_rh == NULL) { crm_err("Node not found - cant update"); return FALSE; } if(node_rh->fixed) { /* warning */ crm_warn("Constraint %s is irrelevant as the" " weight of node %s is fixed as %f.", cons->id, node_rh->details->uname, node_rh->weight); return TRUE; } crm_verbose("Constraint %s (%s): node %s weight %f.", cons->id, cons->can?"can":"cannot", node_rh->details->uname, node_rh->weight); if(cons->can == FALSE) { node_rh->weight = -1; } else { node_rh->weight += cons->weight; } if(node_rh->weight < 0) { node_rh->fixed = TRUE; } crm_debug_action(print_node("Updated", node_rh, FALSE)); return TRUE; } gboolean constraint_violated( resource_t *rsc_lh, resource_t *rsc_rh, rsc_dependancy_t *constraint) { GListPtr result = NULL; color_t *color_lh = rsc_lh->color; color_t *color_rh = rsc_rh->color; GListPtr candidate_nodes_lh = NULL; GListPtr candidate_nodes_rh = NULL; gboolean matched = FALSE; 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; } void order_actions(action_t *lh_action, action_t *rh_action, order_constraint_t *order) { action_wrapper_t *wrapper = NULL; GListPtr list = NULL; crm_verbose("%d Processing %d -> %d", order->id, lh_action->id, rh_action->id); crm_debug_action( print_action("LH (order_actions)", lh_action, FALSE)); crm_debug_action( print_action("RH (order_actions)", rh_action, FALSE)); crm_malloc(wrapper, sizeof(action_wrapper_t)); if(wrapper != NULL) { wrapper->action = rh_action; wrapper->strength = order->strength; list = lh_action->actions_after; list = g_list_append(list, wrapper); lh_action->actions_after = list; } crm_malloc(wrapper, sizeof(action_wrapper_t)); if(wrapper != NULL) { wrapper->action = lh_action; wrapper->strength = order->strength; list = rh_action->actions_before; list = g_list_append(list, wrapper); rh_action->actions_before = list; } } diff --git a/crm/pengine/complex.h b/crm/pengine/complex.h index c1292939b0..b2ca5f02f3 100644 --- a/crm/pengine/complex.h +++ b/crm/pengine/complex.h @@ -1,78 +1,98 @@ -/* $Id: complex.h,v 1.1 2004/11/09 09:32:14 andrew Exp $ */ +/* $Id: complex.h,v 1.2 2004/11/09 11:18:00 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 #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_incarnation = 2, pe_unknown = -1 }; extern int get_resource_type(const char *name); typedef struct resource_object_functions_s { void (*unpack)(resource_t *); void (*color)(resource_t *, GListPtr *); void (*create_actions)(resource_t *); void (*internal_ordering)(resource_t *, GListPtr *); void (*rsc_dependancy_lh)(rsc_dependancy_t *); void (*rsc_dependancy_rh)(resource_t *, rsc_dependancy_t *); - void (*rsc_order_lh)(order_constraint_t *); - void (*rsc_order_rh)(action_t *, order_constraint_t *); + void (*rsc_order_lh)(resource_t *, order_constraint_t *); + void (*rsc_order_rh)( + action_t *, resource_t *, order_constraint_t *); void (*rsc_location)(rsc_to_node_t *); void (*expand)(resource_t *, xmlNodePtr *); void (*dump)(resource_t *, const char *, gboolean); void (*free)(resource_t *); } resource_object_functions_t; extern void native_unpack(resource_t *rsc); extern void native_color(resource_t *rsc, GListPtr *colors); extern void native_create_actions(resource_t *rsc); extern void native_internal_ordering( resource_t *rsc, GListPtr *ordering_constraints); extern void native_rsc_dependancy_lh(rsc_dependancy_t *constraint); extern void native_rsc_dependancy_rh( resource_t *rsc, rsc_dependancy_t *constraint); -extern void native_rsc_order_lh(order_constraint_t *order); -extern void native_rsc_order_rh(action_t *lh_action, order_constraint_t *order); +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(rsc_to_node_t *constraint); extern void native_expand(resource_t *rsc, xmlNodePtr *graph); extern void native_dump(resource_t *rsc, const char *pre_text, gboolean details); extern void native_free(resource_t *rsc); + +extern void group_unpack(resource_t *rsc); +extern void group_color(resource_t *rsc, GListPtr *colors); +extern void group_create_actions(resource_t *rsc); +extern void group_internal_ordering( + resource_t *rsc, GListPtr *ordering_constraints); +extern void group_rsc_dependancy_lh(rsc_dependancy_t *constraint); +extern void group_rsc_dependancy_rh( + resource_t *rsc, rsc_dependancy_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(rsc_to_node_t *constraint); +extern void group_expand(resource_t *rsc, xmlNodePtr *graph); +extern void group_dump(resource_t *rsc, const char *pre_text, gboolean details); +extern void group_free(resource_t *rsc); + + /* extern resource_object_functions_t resource_variants[]; */ extern resource_object_functions_t resource_class_functions[]; - +extern gboolean common_unpack(xmlNodePtr xml_obj, resource_t **rsc); diff --git a/crm/pengine/group.c b/crm/pengine/group.c new file mode 100644 index 0000000000..ea5199c4df --- /dev/null +++ b/crm/pengine/group.c @@ -0,0 +1,270 @@ +/* $Id: group.c,v 1.1 2004/11/09 11:18:00 andrew Exp $ */ +/* + * Copyright (C) 2004 Andrew Beekhof + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include + +extern gboolean choose_color(resource_t *lh_resource); +extern gboolean assign_color(resource_t *rsc, color_t *color); +extern gboolean update_node_weight( + rsc_to_node_t *cons,const char *id,GListPtr nodes); +extern gboolean is_active(rsc_to_node_t *cons); +extern gboolean constraint_violated( + resource_t *rsc_lh, resource_t *rsc_rh, rsc_dependancy_t *constraint); +extern void order_actions(action_t *lh, action_t *rh, order_constraint_t *order); + +typedef struct group_variant_data_s +{ + int num_children; + GListPtr child_list; /* resource_t* */ + resource_t *first_child; + resource_t *last_child; +} group_variant_data_t; + +void group_unpack(resource_t *rsc) +{ + xmlNodePtr xml_obj = rsc->xml; + group_variant_data_t *group_data = NULL; + + native_unpack(rsc); + + crm_malloc(group_data, sizeof(group_variant_data_t)); + group_data->num_children = 0; + group_data->child_list = NULL; + group_data->first_child = NULL; + group_data->last_child = NULL; + + xml_child_iter( + xml_obj, xml_native_rsc, XML_CIB_TAG_RESOURCE, + + resource_t *new_rsc = NULL; + if(common_unpack(xml_native_rsc, &new_rsc)) { + group_data->num_children++; + group_data->child_list = g_list_append( + group_data->child_list, new_rsc); + + if(group_data->first_child == NULL) { + group_data->first_child = new_rsc; + } + group_data->last_child = new_rsc; + +/* crm_debug("Merging node list with new child"); */ +/* old_list = rsc->allowed_nodes; */ +/* old_list = node_list_and(rsc->allowed_nodes, */ +/* new_rsc->allowed_nodes, FALSE); */ +/* pe_free_shallow(old_list); */ + + crm_debug_action( + print_resource("Added", new_rsc, FALSE)); + } else { + crm_err("Failed unpacking resource %s", + xmlGetProp(xml_obj, XML_ATTR_ID)); + } + ); + + rsc->variant_opaque = group_data; +} + +void group_color(resource_t *rsc, GListPtr *colors) +{ + int lpc; + group_variant_data_t *group_data = + (group_variant_data_t *)rsc->variant_opaque; + + native_color(rsc, colors); + + slist_iter( + child_rsc, resource_t, group_data->child_list, lpc, + child_rsc->color = rsc->color; + child_rsc->provisional = FALSE; + ); +} + +void group_create_actions(resource_t *rsc) +{ + int lpc; + group_variant_data_t *group_data = + (group_variant_data_t *)rsc->variant_opaque; + + slist_iter( + child_rsc, resource_t, group_data->child_list, lpc, + native_create_actions(child_rsc); + ); + +} + +void group_internal_ordering(resource_t *rsc, GListPtr *ordering_constraints) +{ + int lpc; + resource_t *last_rsc = NULL; + group_variant_data_t *group_data = + (group_variant_data_t *)rsc->variant_opaque; + + slist_iter( + child_rsc, resource_t, group_data->child_list, lpc, + + if(last_rsc != NULL) { + order_new(last_rsc, start_rsc, NULL, + child_rsc, start_rsc, NULL, + pecs_startstop, ordering_constraints); + } + last_rsc = child_rsc; + ); + + +} + +void group_rsc_dependancy_lh(rsc_dependancy_t *constraint) +{ + int lpc; + resource_t *rsc = constraint->rsc_lh; + group_variant_data_t *group_data = NULL; + + if(rsc == NULL) { + crm_err("No constraints for NULL resource"); + return; + } else { + crm_debug("Processing constraints from %s", rsc->id); + } + + group_data = (group_variant_data_t *)rsc->variant_opaque; + + slist_iter( + child_rsc, resource_t, group_data->child_list, lpc, + + child_rsc->fns->rsc_dependancy_rh(child_rsc, constraint); + ); + +} + +void group_rsc_dependancy_rh(resource_t *rsc, rsc_dependancy_t *constraint) +{ + int lpc; + resource_t *rsc_lh = rsc; + resource_t *rsc_rh = constraint->rsc_rh; + group_variant_data_t *group_data = + (group_variant_data_t *)rsc_rh->variant_opaque; + + crm_verbose("Processing RH of constraint %s", constraint->id); + crm_debug_action(print_resource("LHS", rsc_lh, TRUE)); + + + slist_iter( + child_rsc, resource_t, group_data->child_list, lpc, + + crm_debug_action(print_resource("RHS", rsc_rh, TRUE)); + child_rsc->fns->rsc_dependancy_rh(child_rsc, constraint); + ); +} + + +void group_rsc_order_lh(resource_t *rsc, order_constraint_t *order) +{ + group_variant_data_t *group_data = + (group_variant_data_t *)rsc->variant_opaque; + + crm_verbose("Processing LH of ordering constraint %d", order->id); + + if(order->lh_action_task == stop_rsc) { + group_data->first_child->fns->rsc_order_lh( + group_data->first_child, order); + + } else if(order->lh_action_task == start_rsc) { + group_data->last_child->fns->rsc_order_lh( + group_data->last_child, order); + } +} + +void group_rsc_order_rh( + action_t *lh_action, resource_t *rsc, order_constraint_t *order) +{ + group_variant_data_t *group_data = + (group_variant_data_t *)rsc->variant_opaque; + + crm_verbose("Processing RH of ordering constraint %d", order->id); + + if(order->lh_action_task == stop_rsc) { + group_data->last_child->fns->rsc_order_rh( + lh_action, group_data->last_child, order); + + } else if(order->lh_action_task == start_rsc) { + group_data->first_child->fns->rsc_order_rh( + lh_action, group_data->first_child, order); + } +} + +void group_rsc_location(rsc_to_node_t *constraint) +{ + native_rsc_location(constraint); +} + +void group_expand(resource_t *rsc, xmlNodePtr *graph) +{ + int lpc; + group_variant_data_t *group_data = + (group_variant_data_t *)rsc->variant_opaque; + + crm_verbose("Processing actions from %s", rsc->id); + + slist_iter( + child_rsc, resource_t, group_data->child_list, lpc, + + child_rsc->fns->expand(child_rsc, graph); + ); + +} + +void group_dump(resource_t *rsc, const char *pre_text, gboolean details) +{ + int lpc; + group_variant_data_t *group_data = + (group_variant_data_t *)rsc->variant_opaque; + + native_dump(rsc, pre_text, details); + + if(details) { + slist_iter( + child_rsc, resource_t, group_data->child_list, lpc, + + child_rsc->fns->dump(child_rsc, pre_text, details); + ); + } +} + +void group_free(resource_t *rsc) +{ + int lpc; + group_variant_data_t *group_data = + (group_variant_data_t *)rsc->variant_opaque; + + crm_verbose("Freeing %s", rsc->id); + + slist_iter( + child_rsc, resource_t, group_data->child_list, lpc, + + child_rsc->fns->free(child_rsc); + ); + + pe_free_shallow_adv(group_data->child_list, FALSE); + + native_free(rsc); +} + + diff --git a/crm/pengine/native.c b/crm/pengine/native.c index e2cde9a859..f5e534b5e3 100644 --- a/crm/pengine/native.c +++ b/crm/pengine/native.c @@ -1,701 +1,715 @@ -/* $Id: native.c,v 1.1 2004/11/09 09:32:14 andrew Exp $ */ +/* $Id: native.c,v 1.2 2004/11/09 11:18:00 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include extern gboolean choose_color(resource_t *lh_resource); extern gboolean assign_color(resource_t *rsc, color_t *color); extern gboolean update_node_weight( rsc_to_node_t *cons,const char *id,GListPtr nodes); extern gboolean is_active(rsc_to_node_t *cons); extern gboolean constraint_violated( resource_t *rsc_lh, resource_t *rsc_rh, rsc_dependancy_t *constraint); extern void order_actions(action_t *lh, action_t *rh, order_constraint_t *order); void native_rsc_dependancy_rh_must(resource_t *rsc_lh, gboolean update_lh, resource_t *rsc_rh, gboolean update_rh); void native_rsc_dependancy_rh_mustnot(resource_t *rsc_lh, gboolean update_lh, resource_t *rsc_rh, gboolean update_rh); void native_unpack(resource_t *rsc) { xmlNodePtr xml_obj = rsc->xml; const char *stopfail = xmlGetProp(xml_obj, "on_stopfail"); const char *restart = xmlGetProp(xml_obj, "restart_type"); const char *timeout = xmlGetProp(xml_obj, "timeout"); const char *version = xmlGetProp(xml_obj, XML_ATTR_VERSION); const char *priority = xmlGetProp(xml_obj, XML_CIB_ATTR_PRIORITY); const char *max_instances = xmlGetProp(xml_obj, "max_instances"); const char *max_node_instances = xmlGetProp(xml_obj, "max_node_instances"); const char *max_masters = xmlGetProp(xml_obj, "max_masters"); const char *max_node_masters = xmlGetProp(xml_obj, "max_node_masters"); crm_verbose("Processing resource..."); crm_malloc(rsc->agent, sizeof(lrm_agent_t)); rsc->agent->class = xmlGetProp(xml_obj, "class"); rsc->agent->type = xmlGetProp(xml_obj, "type"); rsc->agent->version = version?version:"0.0"; rsc->priority = atoi(priority?priority:"0"); rsc->effective_priority = rsc->priority; rsc->recovery_type = recovery_stop_start; rsc->max_instances = atoi(max_instances?max_instances:"1"); rsc->max_node_instances = atoi(max_node_instances?max_node_instances:"1"); rsc->max_masters = atoi(max_masters?max_masters:"0"); rsc->max_node_masters = atoi(max_node_masters?max_node_masters:"0"); rsc->candidate_colors = NULL; rsc->actions = NULL; rsc->color = NULL; rsc->runnable = TRUE; rsc->provisional = TRUE; rsc->allowed_nodes = NULL; rsc->rsc_cons = NULL; rsc->node_cons = NULL; rsc->running_on = NULL; rsc->timeout = timeout; if(safe_str_eq(stopfail, "ignore")) { rsc->stopfail_type = pesf_ignore; } else if(safe_str_eq(stopfail, "stonith")) { rsc->stopfail_type = pesf_stonith; } else { rsc->stopfail_type = pesf_block; } if(safe_str_eq(restart, "restart")) { rsc->restart_type = pe_restart_restart; } else if(safe_str_eq(restart, "recover")) { rsc->restart_type = pe_restart_recover; } else { rsc->restart_type = pe_restart_ignore; } } void native_color(resource_t *rsc, GListPtr *colors) { color_t *new_color = NULL; if( choose_color(rsc) ) { crm_verbose("Colored resource %s with color %d", rsc->id, rsc->color->id); } else { if(rsc->allowed_nodes != NULL) { /* filter out nodes with a negative weight */ filter_nodes(rsc); new_color = create_color(colors, rsc, NULL); assign_color(rsc, new_color); } if(new_color == NULL) { crm_err("Could not color resource %s", rsc->id); print_resource("ERROR: No color", rsc, FALSE); assign_color(rsc, no_color); } } rsc->provisional = FALSE; } void native_create_actions(resource_t *rsc) { int lpc2, lpc3; action_t *start_op = NULL; gboolean can_start = FALSE; node_t *chosen = NULL; if(rsc->color != NULL) { chosen = rsc->color->details->chosen_node; } if(chosen != NULL) { can_start = TRUE; } if(can_start && g_list_length(rsc->running_on) == 0) { /* create start action */ crm_info("Start resource %s (%s)", rsc->id, safe_val3(NULL, chosen, details, uname)); start_op = action_new(rsc, start_rsc, chosen); } else if(g_list_length(rsc->running_on) > 1) { crm_info("Attempting recovery of resource %s", rsc->id); if(rsc->recovery_type == recovery_stop_start || rsc->recovery_type == recovery_stop_only) { slist_iter( node, node_t, rsc->running_on, lpc2, crm_info("Stop resource %s (%s)", rsc->id, safe_val3(NULL, node, details, uname)); action_new(rsc, stop_rsc, node); ); } if(rsc->recovery_type == recovery_stop_start && can_start) { crm_info("Start resource %s (%s)", rsc->id, safe_val3(NULL, chosen, details, uname)); start_op = action_new( rsc, start_rsc, chosen); } } else { /* stop and or possible restart */ crm_debug("Stop and possible restart of %s", rsc->id); slist_iter( node, node_t, rsc->running_on, lpc2, if(chosen != NULL && safe_str_eq( node->details->id, chosen->details->id)) { /* restart */ crm_info("Leave resource %s alone (%s)", rsc->id, safe_val3(NULL, chosen, details, uname)); /* in case the actions already exist */ slist_iter( action, action_t, rsc->actions, lpc3, if(action->task == start_rsc || action->task == stop_rsc){ action->optional = TRUE; } ); continue; } else if(chosen != NULL) { /* move */ crm_info("Move resource %s (%s -> %s)", rsc->id, safe_val3(NULL, node, details, uname), safe_val3(NULL, chosen, details, uname)); action_new(rsc, stop_rsc, node); action_new(rsc, start_rsc, chosen); } else { crm_info("Stop resource %s (%s)", rsc->id, safe_val3(NULL, node, details, uname)); action_new(rsc, stop_rsc, node); } ); } } void native_internal_ordering(resource_t *rsc, GListPtr *ordering_constraints) { order_new(rsc, stop_rsc, NULL, rsc, start_rsc, NULL, pecs_startstop, ordering_constraints); } void native_rsc_dependancy_lh(rsc_dependancy_t *constraint) { resource_t *rsc = constraint->rsc_lh; if(rsc == NULL) { crm_err("No constraints for NULL resource"); return; } else { crm_debug("Processing constraints from %s", rsc->id); } constraint->rsc_rh->fns->rsc_dependancy_rh(rsc, constraint); } void native_rsc_dependancy_rh(resource_t *rsc, rsc_dependancy_t *constraint) { gboolean do_check = FALSE; gboolean update_lh = FALSE; gboolean update_rh = FALSE; resource_t *rsc_lh = rsc; resource_t *rsc_rh = constraint->rsc_rh; crm_verbose("Processing RH of constraint %s", constraint->id); crm_debug_action(print_resource("LHS", rsc_lh, TRUE)); crm_debug_action(print_resource("RHS", rsc_rh, TRUE)); if(constraint->strength == pecs_ignore || constraint->strength == pecs_startstop){ crm_debug("Skipping constraint type %d", constraint->strength); return; } if(rsc_lh->provisional && rsc_rh->provisional) { /* nothing */ crm_debug("Skipping constraint, both sides provisional"); return; } else if( (!rsc_lh->provisional) && (!rsc_rh->provisional) && (!rsc_lh->color->details->pending) && (!rsc_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 && rsc_lh->color->details->pending == FALSE) { /* update _us_ : postproc color version */ update_rh = TRUE; } else if(rsc_rh->provisional == FALSE && rsc_rh->color->details->pending == FALSE) { /* update _them_ : postproc color alt version */ update_lh = TRUE; } else if(rsc_lh->provisional == FALSE) { /* update _us_ : preproc version */ update_rh = TRUE; } else if(rsc_rh->provisional == FALSE) { /* update _them_ : postproc version */ update_lh = TRUE; } else { crm_warn("Un-expected combination of inputs"); return; } if(update_lh) { crm_debug("Updating LHS"); } if(update_rh) { crm_debug("Updating RHS"); } if(do_check) { if(constraint_violated(rsc_lh, rsc_rh, constraint) == FALSE) { crm_debug("Constraint satisfied"); return; } /* else constraint cant be satisified */ crm_warn("Constraint %s could not be satisfied", constraint->id); if(update_lh) { crm_warn("Marking resource %s unrunnable as a result", rsc_lh->id); rsc_lh->runnable = FALSE; } if(update_rh) { crm_warn("Marking resource %s unrunnable as a result", rsc_rh->id); rsc_rh->runnable = FALSE; } } if(constraint->strength == pecs_must) { native_rsc_dependancy_rh_must( rsc_lh, update_lh,rsc_rh, update_rh); return; } else if(constraint->strength != pecs_must_not) { /* unknown type */ crm_err("Unknown constraint type %d", constraint->strength); return; } native_rsc_dependancy_rh_mustnot(rsc_lh, update_lh,rsc_rh, update_rh); } -void native_rsc_order_lh(order_constraint_t *order) +void native_rsc_order_lh(resource_t *lh_rsc, order_constraint_t *order) { int lpc; GListPtr lh_actions = NULL; action_t *lh_action = order->lh_action; crm_verbose("Processing LH of ordering constraint %d", order->id); + if(order->lh_action_task != stop_rsc + && order->lh_action_task != start_rsc) { + crm_err("Task %s from ordering %d isnt a resource action", + task2text(order->lh_action_task), order->id); + return; + } + + if(lh_action != NULL) { lh_actions = g_list_append(NULL, lh_action); - } else if(lh_action == NULL && order->lh_rsc != NULL) { + } else if(lh_action == NULL && lh_rsc != NULL) { if(order->strength == pecs_must) { crm_debug("No LH-Side (%s/%s) found for constraint..." " creating", - order->lh_rsc->id, - task2text(order->lh_action_task)); + lh_rsc->id, task2text(order->lh_action_task)); - action_new(order->lh_rsc, order->lh_action_task, NULL); + action_new(lh_rsc, order->lh_action_task, NULL); } lh_actions = find_actions_type( - order->lh_rsc->actions, order->lh_action_task, NULL); + lh_rsc->actions, order->lh_action_task, NULL); if(lh_actions == NULL) { crm_debug("No LH-Side (%s/%s) found for constraint", - order->lh_rsc->id, - task2text(order->lh_action_task)); + lh_rsc->id, task2text(order->lh_action_task)); return; } } else { crm_warn("No LH-Side (%s) specified for constraint", task2text(order->lh_action_task)); return; } slist_iter( lh_action_iter, action_t, lh_actions, lpc, - if(order->rh_rsc) { - order->rh_rsc->fns->rsc_order_rh(lh_action_iter, order); + 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, order_constraint_t *order) +void native_rsc_order_rh( + action_t *lh_action, resource_t *rsc, order_constraint_t *order) { int lpc; GListPtr rh_actions = NULL; action_t *rh_action = order->rh_action; crm_verbose("Processing RH of ordering constraint %d", order->id); if(rh_action != NULL) { rh_actions = g_list_append(NULL, rh_action); - } else if(rh_action == NULL && order->rh_rsc != NULL) { + } else if(rh_action == NULL && rsc != NULL) { rh_actions = find_actions_type( - order->rh_rsc->actions, order->rh_action_task, NULL); + rsc->actions, order->rh_action_task, NULL); if(rh_actions == NULL) { crm_debug("No RH-Side (%s/%s) found for constraint..." " ignoring", - order->rh_rsc->id, - task2text(order->rh_action_task)); + rsc->id, task2text(order->rh_action_task)); return; } } else if(rh_action == NULL) { crm_debug("No RH-Side (%s) specified for constraint..." " ignoring", task2text(order->rh_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(rsc_to_node_t *constraint) { int lpc; GListPtr or_list; resource_t *rsc_lh = constraint->rsc_lh; crm_debug_action(print_rsc_to_node("Applying", constraint, FALSE)); /* take "lifetime" into account */ if(constraint == NULL) { crm_err("Constraint is NULL"); return; } else if(is_active(constraint) == FALSE) { crm_info("Constraint (%s) is not active", constraint->id); /* warning */ return; } rsc_lh = constraint->rsc_lh; if(rsc_lh == NULL) { crm_err("LHS of rsc_to_node (%s) is NULL", constraint->id); return; } constraint->rsc_lh->node_cons = g_list_append(constraint->rsc_lh->node_cons, constraint); if(constraint->node_list_rh == NULL) { crm_err("RHS of constraint %s is NULL", constraint->id); return; } crm_debug_action(print_resource("before update", rsc_lh,TRUE)); or_list = node_list_or( rsc_lh->allowed_nodes, constraint->node_list_rh, FALSE); pe_free_shallow(rsc_lh->allowed_nodes); rsc_lh->allowed_nodes = or_list; slist_iter(node_rh, node_t, constraint->node_list_rh, lpc, update_node_weight(constraint, node_rh->details->uname, rsc_lh->allowed_nodes)); crm_debug_action(print_resource("after update", rsc_lh, TRUE)); } void native_expand(resource_t *rsc, xmlNodePtr *graph) { int lpc; slist_iter( action, action_t, rsc->actions, lpc, crm_debug("processing action %d for rsc=%s", action->id, rsc->id); graph_element_from_action(action, graph); ); } void native_dump(resource_t *rsc, const char *pre_text, gboolean details) { crm_debug("%s%s%s%sResource %s: (priority=%f, color=%d, now=%d)", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", rsc->provisional?"Provisional ":"", rsc->runnable?"":"(Non-Startable) ", rsc->id, (double)rsc->priority, safe_val3(-1, rsc, color, id), g_list_length(rsc->running_on)); crm_debug("\t%d candidate colors, %d allowed nodes," " %d rsc_cons and %d node_cons", g_list_length(rsc->candidate_colors), g_list_length(rsc->allowed_nodes), g_list_length(rsc->rsc_cons), g_list_length(rsc->node_cons)); if(details) { int lpc = 0; crm_debug("\t=== Actions"); slist_iter( action, action_t, rsc->actions, lpc, print_action("\trsc action: ", action, FALSE); ); crm_debug("\t=== Colors"); slist_iter( color, color_t, rsc->candidate_colors, lpc, print_color("\t", color, FALSE) ); crm_debug("\t=== Allowed Nodes"); slist_iter( node, node_t, rsc->allowed_nodes, lpc, print_node("\t", node, FALSE); ); } } void native_free(resource_t *rsc) { crm_debug("Freeing Allowed Nodes"); pe_free_shallow(rsc->allowed_nodes); while(rsc->rsc_cons) { crm_debug("Freeing constraint"); pe_free_rsc_dependancy((rsc_dependancy_t*)rsc->rsc_cons->data); rsc->rsc_cons = rsc->rsc_cons->next; } crm_debug("Freeing constraint list"); if(rsc->rsc_cons != NULL) { g_list_free(rsc->rsc_cons); } - /* free ourselves? */ + + crm_free(rsc->variant_opaque); + crm_free(rsc); } void native_rsc_dependancy_rh_must(resource_t *rsc_lh, gboolean update_lh, resource_t *rsc_rh, gboolean update_rh) { 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; if(rsc_lh->color && rsc_rh->color) { do_merge = TRUE; merged_node_list = node_list_and( rsc_lh->color->details->candidate_nodes, rsc_rh->color->details->candidate_nodes, TRUE); } else if(rsc_lh->color) { do_merge = TRUE; merged_node_list = node_list_and( rsc_lh->color->details->candidate_nodes, rsc_rh->allowed_nodes, TRUE); } else if(rsc_rh->color) { do_merge = TRUE; merged_node_list = node_list_and( rsc_lh->allowed_nodes, rsc_rh->color->details->candidate_nodes, TRUE); } if(update_lh) { crm_free(rsc_lh->color); rsc_lh->runnable = rsc_rh->runnable; rsc_lh->color = copy_color(rsc_rh->color); } if(update_rh) { crm_free(rsc_rh->color); rsc_rh->runnable = rsc_lh->runnable; rsc_rh->color = copy_color(rsc_lh->color); } if(do_merge) { crm_debug("Merging candidate nodes"); old_list = rsc_rh->color->details->candidate_nodes; rsc_rh->color->details->candidate_nodes = merged_node_list; pe_free_shallow(old_list); } crm_debug("Finished processing pecs_must constraint"); } void native_rsc_dependancy_rh_mustnot(resource_t *rsc_lh, gboolean update_lh, resource_t *rsc_rh, gboolean update_rh) { color_t *color_lh = NULL; color_t *color_rh = NULL; crm_debug("Processing pecs_must_not constraint"); /* pecs_must_not */ if(update_lh) { color_rh = rsc_rh->color; if(rsc_lh->provisional) { color_lh = find_color( rsc_lh->candidate_colors,color_rh); rsc_lh->candidate_colors = g_list_remove( rsc_lh->candidate_colors, color_lh); crm_debug_action( print_color("Removed LH", color_lh, FALSE)); crm_debug_action( print_resource("Modified LH", rsc_lh, TRUE)); crm_free(color_lh); } else if(rsc_lh->color && rsc_lh->color->details->pending) { node_t *node_lh = NULL; color_lh = rsc_lh->color; node_lh = pe_find_node( color_lh->details->candidate_nodes, safe_val5(NULL, color_rh, details, chosen_node, details, uname)); color_lh->details->candidate_nodes = g_list_remove( color_lh->details->candidate_nodes, node_lh); crm_debug_action( print_node("Removed LH", node_lh, FALSE)); crm_debug_action( print_color("Modified LH", color_lh, FALSE)); crm_free(node_lh); } else { /* error, rsc marked as unrunnable above */ crm_warn("lh else"); } } if(update_rh) { color_lh = rsc_lh->color; if(rsc_rh->provisional) { color_rh = find_color( rsc_rh->candidate_colors, color_lh); rsc_rh->candidate_colors = g_list_remove( rsc_rh->candidate_colors, color_rh); crm_debug_action( print_color("Removed RH", color_rh, FALSE)); crm_debug_action( print_resource("Modified RH", rsc_rh, TRUE)); crm_free(color_rh); } else if(rsc_rh->color && rsc_rh->color->details->pending) { node_t *node_rh = NULL; color_rh = rsc_rh->color; node_rh = pe_find_node( color_rh->details->candidate_nodes, safe_val5(NULL, color_lh, details, chosen_node, details, uname)); color_rh->details->candidate_nodes = g_list_remove( color_rh->details->candidate_nodes, node_rh); crm_debug_action( print_node("Removed RH", node_rh, FALSE)); crm_debug_action( print_color("Modified RH", color_rh, FALSE)); crm_free(node_rh); } else { /* error, rsc marked as unrunnable above */ crm_warn("rh else"); } } } diff --git a/crm/pengine/stages.c b/crm/pengine/stages.c index e90dd65b37..d95e22c65f 100644 --- a/crm/pengine/stages.c +++ b/crm/pengine/stages.c @@ -1,465 +1,465 @@ -/* $Id: stages.c,v 1.25 2004/11/09 09:32:14 andrew Exp $ */ +/* $Id: stages.c,v 1.26 2004/11/09 11:18:00 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include node_t *choose_fencer(action_t *stonith, node_t *node, GListPtr resources); void order_actions(action_t *lh, action_t *rh, order_constraint_t *order); /* * Unpack everything * At the end you'll have: * - A list of nodes * - A list of resources (each with any dependancies on other resources) * - A list of constraints between resources and nodes * - A list of constraints between start/stop actions * - A list of nodes that need to be stonith'd * - A list of nodes that need to be shutdown * - A list of the possible stop/start actions (without dependancies) */ gboolean stage0(xmlNodePtr cib, GListPtr *resources, GListPtr *nodes, GListPtr *placement_constraints, GListPtr *actions, GListPtr *ordering_constraints, GListPtr *stonith_list, GListPtr *shutdown_list) { /* int lpc; */ xmlNodePtr cib_nodes = get_object_root( XML_CIB_TAG_NODES, cib); xmlNodePtr cib_status = get_object_root( XML_CIB_TAG_STATUS, cib); xmlNodePtr cib_resources = get_object_root( XML_CIB_TAG_RESOURCES, cib); xmlNodePtr cib_constraints = get_object_root( XML_CIB_TAG_CONSTRAINTS, cib); xmlNodePtr config = get_object_root( XML_CIB_TAG_CRMCONFIG, cib); xmlNodePtr agent_defaults = NULL; /*get_object_root(XML_CIB_TAG_RA_DEFAULTS, cib); */ /* reset remaining global variables */ max_valid_nodes = 0; order_id = 1; action_id = 1; unpack_config(config); unpack_global_defaults(agent_defaults); unpack_nodes(cib_nodes, nodes); unpack_resources(cib_resources, resources, actions, ordering_constraints, *nodes); unpack_status(cib_status, *nodes, *resources, actions, placement_constraints); unpack_constraints(cib_constraints, *nodes, *resources, placement_constraints, ordering_constraints); return TRUE; } /* * Count how many valid nodes we have (so we know the maximum number of * colors we can resolve). * * Apply node constraints (ie. filter the "allowed_nodes" part of resources */ gboolean stage1(GListPtr placement_constraints, GListPtr nodes, GListPtr resources) { int lpc = 0; crm_info("Processing stage 1"); slist_iter( node, node_t, nodes, lpc, if(node == NULL) { /* error */ } else if(node->weight >= 0.0 /* global weight */ && node->details->online && node->details->type == node_member) { max_valid_nodes++; } ); apply_placement_constraints(placement_constraints, nodes); /* will also filter -ve "final" weighted nodes from resources' * allowed lists while we are there */ apply_agent_constraints(resources); return TRUE; } /* * Choose a color for all resources from highest priority and XML_STRENGTH_VAL_MUST * dependancies to lowest, creating new colors as necessary (returned * as "colors"). * * Some nodes may be colored as a "no_color" meaning that it was unresolvable * given the current node stati and constraints. */ gboolean stage2(GListPtr sorted_rscs, GListPtr sorted_nodes, GListPtr *colors) { int lpc; crm_info("Processing stage 2"); if(no_color != NULL) { crm_free(no_color->details); crm_free(no_color); } crm_trace("create \"no color\""); no_color = create_color(NULL, NULL, NULL); /* Take (next) highest resource */ slist_iter( lh_resource, resource_t, sorted_rscs, lpc, /* if resource.provisional == FALSE, repeat */ if(lh_resource->provisional == FALSE) { /* already processed this resource */ continue; } color_resource(lh_resource, colors, sorted_rscs); /* next resource */ ); return TRUE; } /* * not sure if this is a good idea or not, but eventually we might like * to utilize as many nodes as possible... and this might be a convienient * hook */ gboolean stage3(GListPtr colors) { crm_info("Processing stage 3"); /* not sure if this is a good idea or not */ if(g_list_length(colors) > max_valid_nodes) { /* we need to consolidate some */ } else if(g_list_length(colors) < max_valid_nodes) { /* we can create a few more */ } return TRUE; } /* * Choose a node for each (if possible) color */ gboolean stage4(GListPtr colors) { int lpc = 0, lpc2 = 0; crm_info("Processing stage 4"); slist_iter( color, color_t, colors, lpc, crm_debug("assigning node to color %d", color->id); if(color == NULL) { crm_err("NULL color detected"); continue; } else if(color->details->pending == FALSE) { continue; } choose_node_from_list(color); crm_debug("assigned %s to color %d", safe_val5(NULL, color, details, chosen_node, details, uname), color->id); slist_iter( rsc, resource_t, color->details->allocated_resources, lpc2, slist_iter( constraint, rsc_dependancy_t, rsc->rsc_cons, lpc, rsc->fns->rsc_dependancy_lh(constraint); ); ); ); crm_verbose("done"); return TRUE; } /* * Attach nodes to the actions that need to be taken * * Mark actions XML_LRM_ATTR_OPTIONAL if possible (Ie. if the start and stop are * for the same node) * * Mark unrunnable actions */ gboolean stage5(GListPtr resources, GListPtr *ordering_constraints) { int lpc; slist_iter( rsc, resource_t, resources, lpc, rsc->fns->create_actions(rsc); rsc->fns->internal_ordering(rsc, ordering_constraints); ); return TRUE; } /* * Create dependacies for stonith and shutdown operations */ gboolean stage6(GListPtr *actions, GListPtr *ordering_constraints, GListPtr nodes, GListPtr resources) { int lpc = 0; action_t *down_op = NULL; action_t *stonith_op = NULL; crm_info("Processing stage 6"); slist_iter( node, node_t, nodes, lpc, if(node->details->shutdown) { crm_warn("Scheduling Node %s for shutdown", node->details->uname); down_op = action_new(NULL, shutdown_crm, node); down_op->runnable = TRUE; *actions = g_list_append(*actions, down_op); shutdown_constraints( node, down_op, ordering_constraints); } if(node->details->unclean && stonith_enabled) { crm_warn("Scheduling Node %s for STONITH", node->details->uname); stonith_op = action_new(NULL, stonith_node, NULL); stonith_op->runnable = TRUE; set_xml_property_copy(stonith_op->args, "target", node->details->uname); if(down_op != NULL) { down_op->failure_is_fatal = FALSE; } *actions = g_list_append(*actions, stonith_op); stonith_constraints(node, stonith_op, down_op, ordering_constraints); } ); return TRUE; } /* * Determin the sets of independant actions and the correct order for the * actions in each set. * * Mark dependancies of un-runnable actions un-runnable * */ gboolean stage7(GListPtr resources, GListPtr actions, GListPtr ordering_constraints) { int lpc; crm_info("Processing stage 7"); slist_iter( order, order_constraint_t, ordering_constraints, lpc, /* try rsc_action-to-rsc_action */ resource_t *rsc = order->lh_rsc; if(rsc == NULL && order->lh_action) { rsc = order->lh_action->rsc; } if(rsc != NULL) { - rsc->fns->rsc_order_lh(order); + rsc->fns->rsc_order_lh(rsc, order); continue; } /* try action-to-rsc_action */ /* que off the rh resource */ rsc = order->rh_rsc; if(rsc == NULL && order->rh_action) { rsc = order->rh_action->rsc; } if(rsc != NULL) { - rsc->fns->rsc_order_rh(order->lh_action, order); + rsc->fns->rsc_order_rh(order->lh_action, rsc, order); } else { /* fall back to action-to-action */ order_actions( order->lh_action, order->rh_action, order); } ); update_action_states(actions); return TRUE; } /* * Create a dependancy graph to send to the transitioner (via the CRMd) */ gboolean stage8(GListPtr resources, GListPtr actions, xmlNodePtr *graph) { int lpc = 0; crm_info("Processing stage 8"); *graph = create_xml_node(NULL, "transition_graph"); set_xml_property_copy( *graph, "global_timeout", transition_timeout); /* errors... slist_iter(action, action_t, action_list, lpc, if(action->optional == FALSE && action->runnable == FALSE) { print_action("Ignoring", action, TRUE); } ); */ slist_iter( rsc, resource_t, resources, lpc, crm_debug("processing actions for rsc=%s", rsc->id); rsc->fns->expand(rsc, graph); ); crm_xml_devel(*graph, "created resource-driven action list"); /* catch any non-resource specific actions */ slist_iter( action, action_t, actions, lpc, graph_element_from_action(action, graph); ); crm_xml_devel(*graph, "created generic action list"); return TRUE; } /* * Print a nice human readable high-level summary of what we're going to do */ gboolean summary(GListPtr resources) { #if 0 int lpc = 0; const char *rsc_id = NULL; const char *node_id = NULL; const char *new_node_id = NULL; slist_iter( rsc, resource_t, resources, lpc, rsc_id = safe_val(NULL, rsc, id); node_id = safe_val4(NULL, rsc, cur_node, details, uname); new_node_id = safe_val6( NULL, rsc, color, details, chosen_node, details, uname); if(rsc->runnable == FALSE) { crm_err("Resource %s was not runnable", rsc_id); if(node_id != NULL) { crm_warn("Stopping Resource (%s) on node %s", rsc_id, node_id); } } else if(safe_val4(NULL, rsc, color, details, chosen_node) == NULL) { crm_err("Could not allocate Resource %s", rsc_id); crm_debug_action( print_resource("Could not allocate",rsc,TRUE)); if(node_id != NULL) { crm_warn("Stopping Resource (%s) on node %s", rsc_id, node_id); } } else if(safe_str_eq(node_id, new_node_id)){ crm_debug("No change for Resource %s (%s)", rsc_id, safe_val4(NULL, rsc, cur_node, details, uname)); } else if(node_id == NULL) { crm_info("Starting Resource %s on %s", rsc_id, new_node_id); } else { crm_info("Moving Resource %s from %s to %s", rsc_id, node_id, new_node_id); } ); #endif return TRUE; } gboolean choose_node_from_list(color_t *color) { /* 1. Sort by weight 2. color.chosen_node = highest wieghted node 3. remove color.chosen_node from all other colors */ GListPtr nodes = color->details->candidate_nodes; nodes = g_list_sort(nodes, sort_node_weight); color->details->chosen_node = node_copy((node_t*)g_list_nth_data(nodes, 0)); color->details->pending = FALSE; if(color->details->chosen_node == NULL) { crm_err("Could not allocate a node for color %d", color->id); return FALSE; } return TRUE; } diff --git a/crm/pengine/unpack.c b/crm/pengine/unpack.c index b60597849e..8bf152ee99 100644 --- a/crm/pengine/unpack.c +++ b/crm/pengine/unpack.c @@ -1,1249 +1,1233 @@ -/* $Id: unpack.c,v 1.41 2004/11/09 09:32:14 andrew Exp $ */ +/* $Id: unpack.c,v 1.42 2004/11/09 11:18:00 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 int max_valid_nodes = 0; int order_id = 1; GListPtr agent_defaults = NULL; gboolean stonith_enabled = FALSE; const char* transition_timeout = "60000"; /* 1 minute */ + GListPtr match_attrs(const char *attr, const char *op, const char *value, const char *type, GListPtr node_list); gboolean unpack_rsc_to_attr(xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr node_list, GListPtr *placement_constraints); gboolean unpack_rsc_to_node(xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr node_list, GListPtr *placement_constraints); gboolean unpack_rsc_order( xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr *ordering_constraints); gboolean unpack_rsc_dependancy( xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr *ordering_constraints); gboolean unpack_rsc_location( xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr node_list, GListPtr *ordering_constraints); gboolean unpack_lrm_rsc_state( node_t *node, xmlNodePtr lrm_state, GListPtr rsc_list, GListPtr nodes, GListPtr *actions, GListPtr *placement_constraints); gboolean add_node_attrs(xmlNodePtr attrs, node_t *node); gboolean unpack_healthy_resource(GListPtr *placement_constraints, GListPtr *actions, xmlNodePtr rsc_entry, resource_t *rsc_lh, node_t *node); gboolean unpack_failed_resource(GListPtr *placement_constraints, GListPtr *actions, xmlNodePtr rsc_entry, resource_t *rsc_lh, node_t *node); gboolean determine_online_status(xmlNodePtr node_state, node_t *this_node); gboolean unpack_lrm_agents(node_t *node, xmlNodePtr agent_list); gboolean is_node_unclean(xmlNodePtr node_state); gboolean rsc_dependancy_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, GListPtr *ordering_constraints); rsc_to_node_t *rsc2node_new( const char *id, resource_t *rsc, double weight, gboolean can_run, node_t *node, GListPtr *placement_constraints); const char *get_agent_param(resource_t *rsc, const char *param); const char *get_agent_param_rsc(resource_t *rsc, const char *param); const void *get_agent_param_metadata(resource_t *rsc, const char *param); const char *get_agent_param_global(resource_t *rsc, const char *param); const char *param_value(xmlNodePtr parent, const char *name); gboolean unpack_config(xmlNodePtr config) { const char *value = NULL; value = param_value(config, "failed_nodes"); if(safe_str_eq(value, "stonith")) { crm_debug("Enabling STONITH of failed nodes"); stonith_enabled = TRUE; } else { stonith_enabled = FALSE; } value = param_value(config, "transition_timeout"); if(value != NULL) { int tmp = atoi(value); if(tmp > 0) { transition_timeout = value; } else { crm_warn("Invalid value for %s: %s", "transition_timeout", value); } } crm_info("%s set to: %s", "transition_timeout", transition_timeout); return TRUE; } const char * param_value(xmlNodePtr parent, const char *name) { xmlNodePtr a_default = find_entity( parent, XML_CIB_TAG_NVPAIR, name, FALSE); return xmlGetProp(a_default, XML_NVPAIR_ATTR_VALUE); } const char * get_agent_param(resource_t *rsc, const char *param) { const char *value = NULL; if(param == NULL) { return NULL; } value = get_agent_param_rsc(rsc, param); if(value == NULL) { value = get_agent_param_metadata(rsc, param); } if(value == NULL) { value = get_agent_param_global(rsc, param); } return value; } const char * get_agent_param_rsc(resource_t *rsc, const char *param) { xmlNodePtr xml_rsc = rsc->xml; return xmlGetProp(xml_rsc, param); } const void * get_agent_param_metadata(resource_t *rsc, const char *param) { return NULL; } const char * get_agent_param_global(resource_t *rsc, const char *param) { const char * value = NULL;/*g_hashtable_lookup(agent_global_defaults, param); */ if(value == NULL) { crm_err("No global value default for %s", param); } return value; } gboolean unpack_global_defaults(xmlNodePtr defaults) { return TRUE; } gboolean unpack_nodes(xmlNodePtr xml_nodes, GListPtr *nodes) { node_t *new_node = NULL; xmlNodePtr attrs = NULL; const char *id = NULL; const char *uname = NULL; const char *type = NULL; crm_verbose("Begining unpack..."); xml_child_iter( xml_nodes, xml_obj, XML_CIB_TAG_NODE, attrs = xml_obj->children; id = xmlGetProp(xml_obj, XML_ATTR_ID); uname = xmlGetProp(xml_obj, XML_ATTR_UNAME); type = xmlGetProp(xml_obj, XML_ATTR_TYPE); crm_verbose("Processing node %s/%s", uname, id); if(attrs != NULL) { attrs = attrs->children; } if(id == NULL) { crm_err("Must specify id tag in "); continue; } if(type == NULL) { crm_err("Must specify type tag in "); continue; } crm_malloc(new_node, sizeof(node_t)); if(new_node == NULL) { return FALSE; } new_node->weight = 1.0; new_node->fixed = FALSE; crm_malloc(new_node->details, sizeof(struct node_shared_s)); if(new_node->details == NULL) { crm_free(new_node); return FALSE; } crm_verbose("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->unclean = FALSE; new_node->details->shutdown = FALSE; new_node->details->running_rsc = NULL; new_node->details->agents = NULL; new_node->details->attrs = g_hash_table_new( g_str_hash, g_str_equal); if(safe_str_eq(type, "member")) { new_node->details->type = node_member; } add_node_attrs(attrs, new_node); *nodes = g_list_append(*nodes, new_node); crm_verbose("Done with node %s", xmlGetProp(xml_obj, "uname")); crm_debug_action(print_node("Added", new_node, FALSE)); ); *nodes = g_list_sort(*nodes, sort_node_weight); return TRUE; } gboolean unpack_resources(xmlNodePtr xml_resources, GListPtr *resources, GListPtr *actions, GListPtr *ordering_constraints, GListPtr all_nodes) { crm_verbose("Begining unpack..."); xml_child_iter( - xml_resources, xml_obj, XML_CIB_TAG_RESOURCE, - const char *id = xmlGetProp(xml_obj, XML_ATTR_ID); - resource_t *new_rsc = NULL; - - crm_verbose("Processing resource..."); - - if(id == NULL) { - crm_err("Must specify id tag in "); - continue; - } - crm_malloc(new_rsc, sizeof(resource_t)); + xml_resources, xml_obj, NULL, - if(new_rsc == NULL) { - return FALSE; + resource_t *new_rsc = NULL; + if(common_unpack(xml_obj, &new_rsc)) { + *resources = g_list_append(*resources, new_rsc); + crm_debug_action( + print_resource("Added", new_rsc, FALSE)); + } else { + crm_err("Failed unpacking resource %s", + xmlGetProp(xml_obj, XML_ATTR_ID)); } - - new_rsc->id = id; - new_rsc->xml = xml_obj; - new_rsc->variant = get_resource_type(xml_obj->name); - new_rsc->fns = &resource_class_functions[new_rsc->variant]; - - new_rsc->fns->unpack(new_rsc); - - *resources = g_list_append(*resources, new_rsc); - - crm_debug_action(print_resource("Added", new_rsc, FALSE)); ); *resources = g_list_sort(*resources, sort_rsc_priority); return TRUE; } - - gboolean unpack_constraints(xmlNodePtr xml_constraints, GListPtr nodes, GListPtr resources, GListPtr *placement_constraints, GListPtr *ordering_constraints) { crm_verbose("Begining unpack..."); xml_child_iter( xml_constraints, xml_obj, NULL, const char *id = xmlGetProp(xml_obj, XML_ATTR_ID); if(id == NULL) { crm_err("Constraint <%s...> must have an id", xml_obj->name); continue; } crm_verbose("Processing constraint %s %s", xml_obj->name,id); if(safe_str_eq("rsc_order", xml_obj->name)) { unpack_rsc_order( xml_obj, resources, ordering_constraints); } else if(safe_str_eq("rsc_dependancy", xml_obj->name)) { unpack_rsc_dependancy( xml_obj, resources, ordering_constraints); } else if(safe_str_eq("rsc_location", xml_obj->name)) { unpack_rsc_location( xml_obj, resources, nodes, placement_constraints); } else { crm_err("Unsupported constraint type: %s", xml_obj->name); } ); return TRUE; } rsc_to_node_t * rsc2node_new(const char *id, resource_t *rsc, double weight, gboolean can, node_t *node, GListPtr *placement_constraints) { rsc_to_node_t *new_con = NULL; if(rsc == NULL || id == NULL) { crm_err("Invalid constraint %s for rsc=%p", crm_str(id), rsc); return NULL; } crm_malloc(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->can = can; if(can) { new_con->weight = weight; } else { new_con->weight = -1; } if(node != NULL) { new_con->node_list_rh = g_list_append(NULL, node); } *placement_constraints = g_list_append(*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(xmlNodePtr status, GListPtr nodes, GListPtr rsc_list, GListPtr *actions, GListPtr *placement_constraints) { const char *uname = NULL; xmlNodePtr lrm_rsc = NULL; xmlNodePtr lrm_agents = NULL; xmlNodePtr attrs = NULL; node_t *this_node = NULL; crm_verbose("Begining unpack"); xml_child_iter( status, node_state, XML_CIB_TAG_STATE, /* id = xmlGetProp(node_state, XML_ATTR_ID); */ uname = xmlGetProp(node_state, XML_ATTR_UNAME); attrs = find_xml_node(node_state, "attributes"); lrm_rsc = find_xml_node(node_state, XML_CIB_TAG_LRM); lrm_agents = find_xml_node(lrm_rsc, "lrm_agents"); lrm_rsc = find_xml_node(lrm_rsc, XML_LRM_TAG_RESOURCES); lrm_rsc = find_xml_node(lrm_rsc, "lrm_resource"); crm_verbose("Processing node %s", uname); this_node = pe_find_node(nodes, uname); if(uname == NULL) { /* error */ continue; } else if(this_node == NULL) { crm_err("Node %s in status section no longer exists", uname); continue; } crm_verbose("Adding runtime node attrs"); add_node_attrs(attrs, this_node); crm_verbose("determining node state"); determine_online_status(node_state, this_node); crm_verbose("Processing lrm resource entries"); unpack_lrm_rsc_state(this_node, lrm_rsc, rsc_list, nodes, actions, placement_constraints); crm_verbose("Processing lrm agents"); unpack_lrm_agents(this_node, lrm_agents); ); return TRUE; } gboolean determine_online_status(xmlNodePtr node_state, node_t *this_node) { gboolean online = FALSE; const char *uname = xmlGetProp(node_state,XML_ATTR_UNAME); /* const char *state = xmlGetProp(node_state,XML_NODE_ATTR_STATE); */ const char *exp_state = xmlGetProp(node_state,XML_CIB_ATTR_EXPSTATE); const char *join_state = xmlGetProp(node_state,XML_CIB_ATTR_JOINSTATE); const char *crm_state = xmlGetProp(node_state,XML_CIB_ATTR_CRMDSTATE); const char *ccm_state = xmlGetProp(node_state,XML_CIB_ATTR_INCCM); const char *ha_state = xmlGetProp(node_state,XML_CIB_ATTR_HASTATE); const char *shutdown = xmlGetProp(node_state,XML_CIB_ATTR_SHUTDOWN); const char *unclean = NULL;/*xmlGetProp(node_state,XML_CIB_ATTR_STONITH); */ if(safe_str_eq(join_state, CRMD_JOINSTATE_MEMBER) && safe_str_eq(ccm_state, XML_BOOLEAN_YES) && (ha_state == NULL || safe_str_eq(ha_state, ACTIVESTATUS)) && safe_str_eq(crm_state, ONLINESTATUS) && shutdown == NULL) { if(this_node != NULL) { this_node->details->online = TRUE; } crm_debug("Node %s is online", uname); online = TRUE; } else if(this_node != NULL) { /* remove node from contention */ this_node->weight = -1; this_node->fixed = TRUE; crm_verbose("join_state=%s, expected=%s, shutdown=%s", crm_str(join_state), crm_str(exp_state), crm_str(shutdown)); if(unclean != NULL) { this_node->details->unclean = TRUE; } else if(is_node_unclean(node_state)) { /* report and or take remedial action */ this_node->details->unclean = TRUE; } if(shutdown != NULL) { this_node->details->shutdown = TRUE; } if(this_node->details->unclean) { crm_warn("Node %s is due for STONITH", uname); } if(this_node->details->shutdown) { crm_info("Node %s is due for shutdown", uname); } } return online; } gboolean is_node_unclean(xmlNodePtr node_state) { /* const char *state = xmlGetProp(node_state,XML_NODE_ATTR_STATE); */ const char *uname = xmlGetProp(node_state,XML_ATTR_UNAME); const char *exp_state = xmlGetProp(node_state,XML_CIB_ATTR_EXPSTATE); const char *join_state = xmlGetProp(node_state,XML_CIB_ATTR_JOINSTATE); const char *crm_state = xmlGetProp(node_state,XML_CIB_ATTR_CRMDSTATE); const char *ha_state = xmlGetProp(node_state,XML_CIB_ATTR_HASTATE); const char *ccm_state = xmlGetProp(node_state,XML_CIB_ATTR_INCCM); if(safe_str_eq(exp_state, CRMD_STATE_INACTIVE)) { crm_debug("Node %s is safely inactive", uname); return FALSE; /* do an actual calculation once STONITH is available */ } else if(safe_str_neq(exp_state, CRMD_JOINSTATE_DOWN)) { if(safe_str_eq(crm_state, OFFLINESTATUS) || (ha_state != NULL && safe_str_eq(ha_state, DEADSTATUS)) || safe_str_eq(join_state, CRMD_JOINSTATE_DOWN) || safe_str_eq(ccm_state, XML_BOOLEAN_NO)) { crm_warn("Node %s is un-expectedly down", uname); return TRUE; } crm_debug("Node %s: ha=%s, join=%s, crm=%s, ccm=%s", uname, ha_state, join_state, crm_state, ccm_state); } else { crm_debug("Node %s was expected to be down", uname); } return FALSE; } gboolean unpack_lrm_agents(node_t *node, xmlNodePtr agent_list) { /* if the agent is not listed, remove the node from * the resource's list of allowed_nodes */ lrm_agent_t *agent = NULL; const char *version = NULL; if(agent_list == NULL) { return FALSE; } xml_child_iter( agent_list, xml_agent, XML_LRM_TAG_AGENT, crm_malloc(agent, sizeof(lrm_agent_t)); if(agent == NULL) { continue; } agent->class = xmlGetProp(xml_agent, "class"); agent->type = xmlGetProp(xml_agent, "type"); version = xmlGetProp(xml_agent, "version"); agent->version = version?version:"0.0"; crm_trace("Adding agent %s/%s v%s to node %s", agent->class, agent->type, agent->version, node->details->uname); node->details->agents = g_list_append( node->details->agents, agent); ); return TRUE; } gboolean unpack_lrm_rsc_state(node_t *node, xmlNodePtr lrm_rsc, GListPtr rsc_list, GListPtr nodes, GListPtr *actions, GListPtr *placement_constraints) { xmlNodePtr rsc_entry = NULL; const char *rsc_id = NULL; const char *node_id = NULL; const char *rsc_state = NULL; const char *op_status = NULL; const char *last_rc = NULL; const char *last_op = NULL; resource_t *rsc_lh = NULL; op_status_t action_status_i = LRM_OP_ERROR; while(lrm_rsc != NULL) { rsc_entry = lrm_rsc; lrm_rsc = lrm_rsc->next; rsc_id = xmlGetProp(rsc_entry, XML_ATTR_ID); node_id = xmlGetProp(rsc_entry, XML_LRM_ATTR_TARGET); rsc_state = xmlGetProp(rsc_entry, XML_LRM_ATTR_RSCSTATE); op_status = xmlGetProp(rsc_entry, XML_LRM_ATTR_OPSTATUS); last_rc = xmlGetProp(rsc_entry, XML_LRM_ATTR_RC); last_op = xmlGetProp(rsc_entry, XML_LRM_ATTR_LASTOP); rsc_lh = pe_find_resource(rsc_list, rsc_id); crm_verbose("[%s] Processing %s on %s (%s)", rsc_entry->name, rsc_id, node_id, rsc_state); if(rsc_lh == NULL) { crm_err("Could not find a match for resource" " %s in %s's status section", rsc_id, node_id); continue; } else if(op_status == NULL) { crm_err("Invalid resource status entry for %s in %s", rsc_id, node_id); continue; } action_status_i = atoi(op_status); if(node->details->unclean) { crm_info("Node %s (where %s is running) is unclean." "Further action depends on the value of on_stopfail", node->details->uname, rsc_lh->id); /* map the status to an error and then handle as a * failed resource. */ action_status_i = LRM_OP_ERROR; } else if(action_status_i == -1) { /* * 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(safe_str_eq(last_op, "stop")) { /* map this to a timeout so it is re-issued */ action_status_i = LRM_OP_TIMEOUT; } else { /* map this to a "done" so it is not marked * as failed, then make sure it is re-issued */ action_new(rsc_lh, start_rsc, NULL); action_status_i = LRM_OP_DONE; } } switch(action_status_i) { case LRM_OP_DONE: unpack_healthy_resource( placement_constraints, actions, rsc_entry, rsc_lh,node); break; case LRM_OP_ERROR: case LRM_OP_TIMEOUT: case LRM_OP_NOTSUPPORTED: unpack_failed_resource( placement_constraints, actions, rsc_entry, rsc_lh,node); break; case LRM_OP_CANCELLED: /* do nothing?? */ crm_warn("Dont know what to do for cancelled ops yet"); break; } } return TRUE; } gboolean unpack_failed_resource(GListPtr *placement_constraints, GListPtr *actions, xmlNodePtr rsc_entry, resource_t *rsc_lh, node_t *node) { const char *last_op = xmlGetProp(rsc_entry, "last_op"); crm_debug("Unpacking failed action %s on %s", last_op, rsc_lh->id); /* make sure we dont allocate the resource here again*/ rsc2node_new("dont_run__generated", rsc_lh, -1.0, FALSE, node, placement_constraints); if(safe_str_eq(last_op, "start")) { /* the resource is not actually running... nothing more to do*/ return TRUE; } switch(rsc_lh->stopfail_type) { case pesf_stonith: /* treat it as if it is still running * but also mark the node as unclean */ rsc_lh->running_on = g_list_append( rsc_lh->running_on, node); node->details->running_rsc = g_list_append( node->details->running_rsc, rsc_lh); if(node->details->online) { node->details->shutdown = TRUE; } node->details->unclean = TRUE; break; case pesf_block: /* let this depend on the stop action which will fail * but make sure the transition continues... */ rsc_lh->running_on = g_list_append( rsc_lh->running_on, node); node->details->running_rsc = g_list_append( node->details->running_rsc, rsc_lh); /* rsc_lh->stop->timeout = NULL; /\* wait forever *\/ */ break; case pesf_ignore: /* pretend nothing happened */ break; } return TRUE; } gboolean unpack_healthy_resource(GListPtr *placement_constraints, GListPtr *actions, xmlNodePtr rsc_entry, resource_t *rsc_lh, node_t *node) { const char *last_op = xmlGetProp(rsc_entry, "last_op"); crm_debug("Unpacking healthy action %s on %s", last_op, rsc_lh->id); if(safe_str_neq(last_op, "stop")) { /* create the link between this node and the rsc */ crm_verbose("Setting cur_node = %s for rsc = %s", node->details->uname, rsc_lh->id); rsc_lh->running_on = g_list_append( rsc_lh->running_on, node); if(g_list_length(rsc_lh->running_on) > 1) { crm_warn("Resource %s active on %d nodes. Latest: %s (%s)", rsc_lh->id, g_list_length(rsc_lh->running_on), node->details->id, last_op); /* action_new(rsc_lh, stop_rsc, node); */ } node->details->running_rsc = g_list_append( node->details->running_rsc, rsc_lh); } return TRUE; } gboolean rsc_dependancy_new(const char *id, enum con_strength strength, resource_t *rsc_lh, resource_t *rsc_rh) { rsc_dependancy_t *new_con = NULL; rsc_dependancy_t *inverted_con = NULL; if(rsc_lh == NULL || rsc_rh == NULL){ /* error */ return FALSE; } crm_malloc(new_con, sizeof(rsc_dependancy_t)); if(new_con != NULL) { 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); rsc_lh->rsc_cons = g_list_insert_sorted( rsc_lh->rsc_cons, new_con, sort_cons_strength); rsc_rh->rsc_cons = g_list_insert_sorted( rsc_rh->rsc_cons, inverted_con, sort_cons_strength); } else { return FALSE; } return TRUE; } gboolean order_new(resource_t *lh_rsc, enum action_tasks lh_action_task, action_t *lh_action, resource_t *rh_rsc, enum action_tasks rh_action_task, action_t *rh_action, enum con_strength strength, GListPtr *ordering_constraints) { order_constraint_t *order = NULL; if((lh_action == NULL && lh_rsc == NULL) || (rh_action == NULL && rh_rsc == NULL) || ordering_constraints == NULL){ crm_err("Invalid inputs lh_rsc=%p, lh_a=%p," " rh_rsc=%p, rh_a=%p, l=%p", lh_rsc, lh_action, rh_rsc, rh_action, ordering_constraints); return FALSE; } crm_malloc(order, sizeof(order_constraint_t)); if(order != NULL) { order->id = order_id++; order->strength = strength; 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; *ordering_constraints = g_list_append( *ordering_constraints, order); if(lh_rsc != NULL && rh_rsc != NULL) { crm_debug("Created ordering constraint %d (%s):" " %s/%s before %s/%s", order->id, strength2text(order->strength), lh_rsc->id, task2text(lh_action_task), rh_rsc->id, task2text(rh_action_task)); } else if(lh_rsc != NULL) { crm_debug("Created ordering constraint %d (%s):" " %s/%s before action %d (%s)", order->id, strength2text(order->strength), lh_rsc->id, task2text(lh_action_task), rh_action->id, task2text(rh_action_task)); } else if(rh_rsc != NULL) { crm_debug("Created ordering constraint %d (%s):" " action %d (%s) before %s/%s", order->id, strength2text(order->strength), lh_action->id, task2text(lh_action_task), rh_rsc->id, task2text(rh_action_task)); } else { crm_debug("Created ordering constraint %d (%s):" " action %d (%s) before action %d (%s)", order->id, strength2text(order->strength), lh_action->id, task2text(lh_action_task), rh_action->id, task2text(rh_action_task)); } } return TRUE; } gboolean unpack_rsc_dependancy(xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr *ordering_constraints) { enum con_strength strength_e = pecs_ignore; const char *id_lh = xmlGetProp(xml_obj, "from"); const char *id = xmlGetProp(xml_obj, XML_ATTR_ID); const char *id_rh = xmlGetProp(xml_obj, "to"); const char *type = xmlGetProp(xml_obj, XML_ATTR_TYPE); resource_t *rsc_lh = pe_find_resource(rsc_list, id_lh); resource_t *rsc_rh = pe_find_resource(rsc_list, id_rh); if(rsc_lh == NULL) { crm_err("No resource (con=%s, rsc=%s)", id, id_lh); return FALSE; } else if(rsc_rh == NULL) { crm_err("No resource (con=%s, rsc=%s)", id, id_rh); return FALSE; } if(safe_str_eq(type, XML_STRENGTH_VAL_MUST)) { strength_e = pecs_must; } else if(safe_str_eq(type, XML_STRENGTH_VAL_SHOULD)) { crm_err("Type %s is no longer supported", type); strength_e = pecs_must; } else if(safe_str_eq(type, XML_STRENGTH_VAL_SHOULDNOT)) { crm_err("Type %s is no longer supported", type); strength_e = pecs_must_not; } else if(safe_str_eq(type, XML_STRENGTH_VAL_MUSTNOT)) { strength_e = pecs_must_not; } else { crm_err("Unknown value for %s: %s", "type", type); return FALSE; } return rsc_dependancy_new(id, strength_e, rsc_lh, rsc_rh); } gboolean unpack_rsc_order(xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr *ordering_constraints) { const char *id = xmlGetProp(xml_obj, XML_ATTR_ID); const char *id_lh = xmlGetProp(xml_obj, "from"); const char *id_rh = xmlGetProp(xml_obj, "to"); const char *type = xmlGetProp(xml_obj, XML_ATTR_TYPE); resource_t *rsc_lh = pe_find_resource(rsc_list, id_lh); resource_t *rsc_rh = pe_find_resource(rsc_list, id_rh); if(xml_obj == NULL) { crm_err("No constraint object to process."); return FALSE; } else if(id == NULL) { crm_err("%s constraint must have an id", xml_obj->name); return FALSE; } else if(rsc_lh == NULL || rsc_rh == NULL) { crm_err("Constraint %s needs two sides lh: %p rh: %p" " (NULL indicates missing side)", id, rsc_lh, rsc_rh); return FALSE; } else if(safe_str_eq(type, "after")) { order_new(rsc_rh, stop_rsc, NULL, rsc_lh, stop_rsc, NULL, pecs_must, ordering_constraints); order_new(rsc_lh, start_rsc, NULL, rsc_rh, start_rsc, NULL, pecs_must, ordering_constraints); } else { order_new(rsc_lh, stop_rsc, NULL, rsc_rh, stop_rsc, NULL, pecs_must, ordering_constraints); order_new(rsc_rh, start_rsc, NULL, rsc_lh, start_rsc, NULL, pecs_must, ordering_constraints); } return TRUE; } /* do NOT free the nodes returned here */ GListPtr match_attrs(const char *attr, const char *op, const char *value, const char *type, GListPtr node_list) { int lpc = 0, lpc2 = 0; GListPtr result = NULL; if(attr == NULL || op == NULL) { crm_err("Invlaid attribute or operation in expression" " (\'%s\' \'%s\' \'%s\')", crm_str(attr), crm_str(op), crm_str(value)); return NULL; } slist_iter( node, node_t, node_list, lpc, gboolean accept = FALSE; int cmp = 0; const char *h_val = (const char*)g_hash_table_lookup( node->details->attrs, attr); if(value != NULL && h_val != NULL) { if(type == NULL || (safe_str_eq(type, "string"))) { cmp = strcmp(h_val, value); } else if(safe_str_eq(type, "number")) { float h_val_f = atof(h_val); float value_f = atof(value); if(h_val_f < value_f) { cmp = -1; } else if(h_val_f > value_f) { cmp = 1; } else { cmp = 0; } } else if(safe_str_eq(type, "version")) { cmp = compare_version(h_val, value); } } else if(value == NULL && h_val == NULL) { cmp = 0; } else if(value == NULL) { cmp = 1; } else { cmp = -1; } if(safe_str_eq(op, "exists")) { if(h_val != NULL) accept = TRUE; } else if(safe_str_eq(op, "notexists")) { if(h_val == NULL) accept = TRUE; } else if(safe_str_eq(op, "running")) { GListPtr rsc_list = node->details->running_rsc; slist_iter( rsc, resource_t, rsc_list, lpc2, if(safe_str_eq(rsc->id, attr)) { accept = TRUE; } ); } else if(safe_str_eq(op, "not_running")) { GListPtr rsc_list = node->details->running_rsc; accept = TRUE; slist_iter( rsc, resource_t, rsc_list, lpc2, if(safe_str_eq(rsc->id, attr)) { accept = FALSE; break; } ); } else if(safe_str_eq(op, "eq")) { if((h_val == value) || cmp == 0) accept = TRUE; } else if(safe_str_eq(op, "ne")) { if((h_val == NULL && value != NULL) || (h_val != NULL && value == NULL) || cmp != 0) accept = TRUE; } else if(value == NULL || h_val == NULL) { /* the comparision is meaningless from this point on */ accept = FALSE; } else if(safe_str_eq(op, "lt")) { if(cmp < 0) accept = TRUE; } else if(safe_str_eq(op, "lte")) { if(cmp <= 0) accept = TRUE; } else if(safe_str_eq(op, "gt")) { if(cmp > 0) accept = TRUE; } else if(safe_str_eq(op, "gte")) { if(cmp >= 0) accept = TRUE; } if(accept) { crm_trace("node %s matched", node->details->uname); result = g_list_append(result, node); } else { crm_trace("node %s did not match", node->details->uname); } ); return result; } gboolean add_node_attrs(xmlNodePtr attrs, node_t *node) { const char *name = NULL; const char *value = NULL; while(attrs != NULL){ name = xmlGetProp(attrs, XML_NVPAIR_ATTR_NAME); value = xmlGetProp(attrs, XML_NVPAIR_ATTR_VALUE); if(name != NULL && value != NULL && safe_val(NULL, node, details) != NULL) { crm_verbose("Adding %s => %s", name, value); /* this is frustrating... no way to pass in const * keys or values yet docs say: * Note: If keys and/or values are dynamically * allocated, you should free them first. */ g_hash_table_insert(node->details->attrs, crm_strdup(name), crm_strdup(value)); } attrs = attrs->next; } g_hash_table_insert(node->details->attrs, crm_strdup("uname"), crm_strdup(node->details->uname)); g_hash_table_insert(node->details->attrs, crm_strdup("id"), crm_strdup(node->details->id)); return TRUE; } gboolean unpack_rsc_location( xmlNodePtr xml_obj, GListPtr rsc_list, GListPtr node_list, GListPtr *placement_constraints) { /* ... Translation: Further translation: */ gboolean were_rules = FALSE; const char *id_lh = xmlGetProp(xml_obj, "rsc"); const char *id = xmlGetProp(xml_obj, XML_ATTR_ID); resource_t *rsc_lh = pe_find_resource(rsc_list, id_lh); if(rsc_lh == NULL) { crm_err("No resource (con=%s, rsc=%s)", id, id_lh); return FALSE; } xml_child_iter( xml_obj, rule, "rule", gboolean first_expr = TRUE; gboolean can_run = FALSE; gboolean do_and = TRUE; gboolean rule_has_expressions; const char *rule_id = xmlGetProp(rule, XML_ATTR_ID); const char *score = xmlGetProp(rule, "score"); const char *result = xmlGetProp(rule, "result"); const char *boolean = xmlGetProp(rule, "boolean_op"); GListPtr match_L = NULL; GListPtr old_list = NULL; float score_f = atof(score?score:"0.0"); rsc_to_node_t *new_con = NULL; were_rules = TRUE; if(safe_str_eq(boolean, "or")) { do_and = FALSE; } if(result == NULL || (safe_str_eq(result, "can"))) { can_run = TRUE; } new_con = rsc2node_new(rule_id, rsc_lh, score_f, can_run, NULL, placement_constraints); if(new_con == NULL) { continue; } rule_has_expressions = FALSE; xml_child_iter( rule, expr, "expression", const char *attr = xmlGetProp(expr, "attribute"); const char *op = xmlGetProp(expr, "operation"); const char *value = xmlGetProp(expr, "value"); const char *type = xmlGetProp(expr, "type"); rule_has_expressions = TRUE; crm_trace("processing expression: %s", xmlGetProp(expr, "id")); match_L = match_attrs( attr, op, value, type, node_list); if(first_expr) { new_con->node_list_rh = node_list_dup( match_L, FALSE); first_expr = FALSE; continue; } old_list = new_con->node_list_rh; if(do_and) { crm_trace("do_and"); new_con->node_list_rh = node_list_and( old_list, match_L, FALSE); } else { crm_trace("do_or"); new_con->node_list_rh = node_list_or( old_list, match_L, FALSE); } pe_free_shallow_adv(match_L, FALSE); pe_free_shallow_adv(old_list, TRUE); ); if(rule_has_expressions == FALSE) { /* feels like a hack */ crm_debug("Rule %s had no expressions," " adding all nodes", xmlGetProp(rule, "id")); new_con->node_list_rh = node_list_dup(node_list,FALSE); } if(new_con->node_list_rh == NULL) { crm_warn("No matching nodes for constraint/rule %s/%s", id, xmlGetProp(rule, "id")); } crm_debug_action(print_rsc_to_node("Added", new_con, FALSE)); ); if(were_rules == FALSE) { crm_err("no rules for constraint %s", id); } return TRUE; }