diff --git a/crm/tengine/callbacks.c b/crm/tengine/callbacks.c index 7a23e73916..9603bcf180 100644 --- a/crm/tengine/callbacks.c +++ b/crm/tengine/callbacks.c @@ -1,355 +1,461 @@ -/* $Id: callbacks.c,v 1.34 2005/06/14 11:38:26 davidlee Exp $ */ +/* $Id: callbacks.c,v 1.35 2005/06/15 10:47:45 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 te_update_confirm(const char *event, HA_Message *msg); +void te_update_diff(const char *event, HA_Message *msg); +crm_data_t *need_abort(crm_data_t *update); + +void +te_update_diff(const char *event, HA_Message *msg) +{ + int rc = -1; + const char *op = NULL; + crm_data_t *diff = NULL; + crm_data_t *aborted = NULL; + const char *set_name = NULL; + + if(msg == NULL) { + crm_err("NULL update"); + return; + } + + ha_msg_value_int(msg, F_CIB_RC, &rc); + op = cl_get_string(msg, F_CIB_OPERATION); + + if(rc < cib_ok) { + crm_debug_2("Ignoring failed %s operation: %s", + op, cib_error2string(rc)); + return; + } + + crm_debug("Processing diff from %s operation", op); + + diff = get_message_xml(msg, F_CIB_UPDATE_RESULT); + log_cib_diff(LOG_DEBUG, diff, op); + + set_name = "diff-added"; + if(diff != NULL && aborted == NULL) { + crm_data_t *section = NULL; + crm_data_t *change_set = find_xml_node(diff, set_name, FALSE); + change_set = find_xml_node(change_set, XML_TAG_CIB, FALSE); + + if(change_set != NULL) { + crm_debug("Checking status changes"); + section=get_object_root(XML_CIB_TAG_STATUS,change_set); + } + if(section != NULL && extract_event(section) == FALSE) { + send_complete("Unexpected status update", + section, te_update, i_cancel); + free_xml(diff); + return; + } + crm_debug("Checking change set: %s", set_name); + aborted = need_abort(change_set); + } + + set_name = "diff-removed"; + if(diff != NULL && aborted == NULL) { + crm_data_t *change_set = find_xml_node(diff, set_name, FALSE); + change_set = find_xml_node(change_set, XML_TAG_CIB, FALSE); + + crm_debug("Checking change set: %s", set_name); + aborted = need_abort(change_set); + } + + if(aborted != NULL) { + send_complete("Non-status change", diff, te_update, i_cancel); + free_xml(diff); + return; + } + + free_xml(diff); + return; +} + +crm_data_t * +need_abort(crm_data_t *update) +{ + crm_data_t *section_xml = NULL; + const char *section = NULL; + + if(update == NULL) { + return NULL; + } + + section = XML_CIB_TAG_NODES; + section_xml = get_object_root(section, update); + xml_child_iter(section_xml, child, NULL, + return section_xml; + ); + + section = XML_CIB_TAG_RESOURCES; + section_xml = get_object_root(section, update); + xml_child_iter(section_xml, child, NULL, + return section_xml; + ); + + section = XML_CIB_TAG_CONSTRAINTS; + section_xml = get_object_root(section, update); + xml_child_iter(section_xml, child, NULL, + return section_xml; + ); + + section = XML_CIB_TAG_CRMCONFIG; + section_xml = get_object_root(section, update); + xml_child_iter(section_xml, child, NULL, + return section_xml; + ); + return NULL; +} + void te_update_confirm(const char *event, HA_Message *msg) { int rc = -1; gboolean done = FALSE; const char *op = cl_get_string(msg, F_CIB_OPERATION); const char *type = cl_get_string(msg, F_CIB_OBJTYPE); crm_data_t *update = get_message_xml(msg, F_CIB_UPDATE); ha_msg_value_int(msg, F_CIB_RC, &rc); crm_debug("Processing %s...", event); crm_log_xml_debug_2(update, "Processing update"); if(op == NULL) { crm_err("Illegal CIB update, the operation must be specified"); send_complete("Illegal update", update, te_update, i_cancel); done = TRUE; } else if(te_fsa_state == s_abort_pending) { /* take no further actions if an abort is pending */ crm_debug("Ignoring CIB update while waiting for an abort"); done = TRUE; } else if(strcmp(op, CIB_OP_ERASE) == 0) { /* these are always unexpected, trigger the PE */ crm_err("Need to trigger an election here so that" " the current state of all nodes is obtained"); send_complete("Erase event", update, te_update, i_cancel); done = TRUE; } else if(strcmp(op, CIB_OP_CREATE) == 0 || strcmp(op, CIB_OP_DELETE) == 0 || strcmp(op, CIB_OP_REPLACE) == 0 || strcmp(op, CRM_OP_SHUTDOWN_REQ) == 0) { /* these are always unexpected, trigger the PE */ send_complete("Non-update change", update, te_update, i_cancel); done = TRUE; } else if(strcmp(op, CIB_OP_UPDATE) != 0) { crm_debug_2("Ignoring %s op confirmation", op); done = TRUE; } if(done) { free_xml(update); return; } if(safe_str_eq(type, XML_CIB_TAG_CRMCONFIG)) { /* ignore - for the moment */ crm_debug("Ignoring changes to the %s section", type); } else if(safe_str_eq(type, XML_CIB_TAG_NODES)) { /* ignore new nodes until they sign up */ crm_debug("Ignoring changes to the %s section", type); } else if(safe_str_eq(type, XML_CIB_TAG_STATUS)) { /* this _may_ not be un-expected */ if(extract_event(update) == FALSE) { send_complete("Unexpected status update", update, te_update, i_cancel); } } else if(safe_str_eq(type, XML_CIB_TAG_NODES) || safe_str_eq(type, XML_CIB_TAG_RESOURCES) || safe_str_eq(type, XML_CIB_TAG_CONSTRAINTS)) { /* these are never expected */ crm_debug("Aborting on changes to the %s section", type); send_complete("Non-status update", update, te_update, i_cancel); } else if(safe_str_eq(type, XML_TAG_CIB)) { crm_data_t *section_xml = NULL; const char *section = NULL; gboolean abort = FALSE; section = XML_CIB_TAG_NODES; if(abort == FALSE) { section_xml = get_object_root(section, update); xml_child_iter(section_xml, child, NULL, abort = TRUE; break; ); } section = XML_CIB_TAG_RESOURCES; if(abort == FALSE) { section_xml = get_object_root(section, update); xml_child_iter(section_xml, child, NULL, abort = TRUE; break; ); } section = XML_CIB_TAG_CONSTRAINTS; if(abort == FALSE) { section_xml = get_object_root(section, update); xml_child_iter(section_xml, child, NULL, abort = TRUE; break; ); } section = XML_CIB_TAG_CRMCONFIG; if(abort == FALSE) { section_xml = get_object_root(section, update); xml_child_iter(section_xml, child, NULL, abort = TRUE; break; ); } if(abort) { send_complete("Non-status update", update, te_update, i_cancel); } section = XML_CIB_TAG_STATUS; if(abort == FALSE) { section_xml = get_object_root(section, update); if(extract_event(section_xml) == FALSE) { send_complete("Unexpected global status update", section_xml, te_update, i_cancel); } } } else { crm_err("Ignoring update confirmation for %s object", type); crm_log_xml_debug(update, "Ignored update"); } free_xml(update); } gboolean process_te_message(HA_Message *msg, crm_data_t *xml_data, IPC_Channel *sender) { const char *sys_to = cl_get_string(msg, F_CRM_SYS_TO); const char *ref = cl_get_string(msg, XML_ATTR_REFERENCE); const char *op = cl_get_string(msg, F_CRM_TASK); crm_log_message(LOG_DEBUG_3, msg); if(safe_str_eq(cl_get_string(msg, F_CRM_MSG_TYPE), XML_ATTR_RESPONSE) && safe_str_neq(op, CRM_OP_EVENTCC)) { crm_info("Message was a response not a request. Discarding"); return TRUE; } crm_debug("Processing %s (%s) message", op, ref); if(op == NULL){ /* error */ } else if(strcmp(op, CRM_OP_HELLO) == 0) { /* ignore */ } else if(sys_to == NULL || strcmp(sys_to, CRM_SYSTEM_TENGINE) != 0) { crm_debug_2("Bad sys-to %s", crm_str(sys_to)); return FALSE; } else if(strcmp(op, CRM_OP_TRANSITION) == 0) { if(te_fsa_state != s_idle) { crm_debug("Attempt to start another transition"); send_complete(CRM_OP_TE_HALT, NULL, te_halt, i_cancel); } else { te_fsa_state = te_state_matrix[i_transition][te_fsa_state]; initialize_graph(); unpack_graph(xml_data); crm_debug("Initiating transition..."); if(initiate_transition() == FALSE) { /* nothing to be done.. means we're done. */ crm_info("No actions to be taken..." " transition compelte."); } } } else if(strcmp(op, CRM_OP_TE_HALT) == 0) { send_complete(CRM_OP_TE_HALT, NULL, te_halt, i_cancel); } else if(strcmp(op, CRM_OP_TEABORT) == 0) { send_complete(CRM_OP_TEABORTED, NULL, te_abort_confirmed, i_cancel); } else if(strcmp(op, CRM_OP_QUIT) == 0) { crm_info("Received quit message, terminating"); exit(0); #ifdef TESTING } else if(strcmp(op, CRM_OP_EVENTCC) == 0) { crm_debug_4("Processing %s...", CRM_OP_EVENTCC); if(extract_event(msg) == FALSE) { send_complete("ttest loopback", msg, te_failed, i_complete); } #endif } else { crm_err("Unknown command: %s", op); } crm_debug_3("finished processing message"); return TRUE; } void tengine_stonith_callback(stonith_ops_t * op, void * private_data) { int action_id = -1; if(op == NULL) { crm_err("Called with a NULL op!"); return; } crm_info("optype=%d, node_name=%s, result=%d, node_list=%s", op->optype, op->node_name, op->op_result, (char *)op->node_list); if(te_fsa_state == s_abort_pending) { /* take no further actions if an abort is pending */ crm_debug("Ignoring Stonith result while waiting for an abort"); return; } /* this will mark the event complete if a match is found */ action_id = match_down_event( op->node_name, CRM_OP_FENCE, op->op_result); if(op->op_result == STONITH_SUCCEEDED) { enum cib_errors rc = cib_ok; const char *target = op->node_name; const char *uuid = op->node_uuid; /* zero out the node-status & remove all LRM status info */ crm_data_t *update = NULL; crm_data_t *node_state = create_xml_node( NULL, XML_CIB_TAG_STATE); CRM_DEV_ASSERT(op->node_name != NULL); CRM_DEV_ASSERT(op->node_uuid != NULL); set_xml_property_copy(node_state, XML_ATTR_UUID, uuid); set_xml_property_copy(node_state, XML_ATTR_UNAME, target); set_xml_property_copy( node_state, XML_CIB_ATTR_HASTATE, DEADSTATUS); set_xml_property_copy( node_state, XML_CIB_ATTR_INCCM, XML_BOOLEAN_NO); set_xml_property_copy( node_state, XML_CIB_ATTR_CRMDSTATE, OFFLINESTATUS); set_xml_property_copy( node_state, XML_CIB_ATTR_JOINSTATE,CRMD_JOINSTATE_DOWN); set_xml_property_copy( node_state, XML_CIB_ATTR_EXPSTATE, CRMD_JOINSTATE_DOWN); set_xml_property_copy( node_state, XML_CIB_ATTR_REPLACE, XML_CIB_TAG_LRM); create_xml_node(node_state, XML_CIB_TAG_LRM); update = create_cib_fragment(node_state, NULL); free_xml(node_state); rc = te_cib_conn->cmds->modify( te_cib_conn, XML_CIB_TAG_STATUS, update, NULL, cib_quorum_override); if(action_id < 0) { send_complete("Stonith not matched", update, te_update, i_cancel); } else if(rc != cib_ok) { send_complete("Couldnt update CIB after stonith", update, te_failed, i_cancel); } else { process_trigger(action_id); check_for_completion(); } free_xml(update); } else { send_complete("Fencing op failed", NULL, te_failed, i_cancel); } } void tengine_stonith_connection_destroy(gpointer user_data) { #if 0 crm_err("Fencing daemon has left us: Shutting down...NOW"); /* shutdown properly later */ CRM_DEV_ASSERT(FALSE/* fencing daemon died */); #else crm_err("Fencing daemon has left us"); #endif return; } gboolean tengine_stonith_dispatch(IPC_Channel *sender, void *user_data) { int lpc = 0; while(stonithd_op_result_ready()) { if (sender->ch_status == IPC_DISCONNECT) { /* The message which was pending for us is that * the IPC status is now IPC_DISCONNECT */ break; } if(ST_FAIL == stonithd_receive_ops_result(FALSE)) { crm_err("stonithd_receive_ops_result() failed"); } else { lpc++; } } crm_debug_2("Processed %d messages", lpc); if (sender->ch_status == IPC_DISCONNECT) { return FALSE; } return TRUE; } diff --git a/crm/tengine/main.c b/crm/tengine/main.c index fb1146b230..bea8599d30 100644 --- a/crm/tengine/main.c +++ b/crm/tengine/main.c @@ -1,233 +1,233 @@ -/* $Id: main.c,v 1.25 2005/06/14 11:38:26 davidlee Exp $ */ +/* $Id: main.c,v 1.26 2005/06/15 10:47:45 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 #include #include #include #include #include #include #include #define SYS_NAME CRM_SYSTEM_TENGINE #define OPTARGS "hVc" GMainLoop* mainloop = NULL; const char* crm_system_name = SYS_NAME; extern cib_t *te_cib_conn; void usage(const char* cmd, int exit_status); int init_start(void); gboolean tengine_shutdown(int nsig, gpointer unused); extern void te_update_confirm(const char *event, HA_Message *msg); - +extern void te_update_diff(const char *event, HA_Message *msg); int main(int argc, char ** argv) { gboolean allow_cores = TRUE; int argerr = 0; int flag; crm_log_init(crm_system_name); G_main_add_SignalHandler( G_PRIORITY_HIGH, SIGTERM, tengine_shutdown, NULL, NULL); crm_debug_3("Begining option processing"); while ((flag = getopt(argc, argv, OPTARGS)) != EOF) { switch(flag) { case 'V': alter_debug(DEBUG_INC); break; case 'h': /* Help message */ usage(crm_system_name, LSB_EXIT_OK); break; case 'c': allow_cores = TRUE; break; default: ++argerr; break; } } crm_debug_3("Option processing complete"); if (optind > argc) { ++argerr; } if (argerr) { usage(crm_system_name,LSB_EXIT_GENERIC); } /* read local config file */ crm_debug_3("Starting..."); return init_start(); } int init_start(void) { int init_ok = TRUE; init_client_ipc_comms( CRM_SYSTEM_CRMD, subsystem_msg_dispatch, (void*)process_te_message, &crm_ch); if(crm_ch != NULL) { send_hello_message(crm_ch, "1234", CRM_SYSTEM_TENGINE, "0", "1"); } else { init_ok = FALSE; crm_err("Could not connect to the CRMd"); } if(init_ok) { crm_debug_4("Creating CIB connection"); te_cib_conn = cib_new(); if(te_cib_conn == NULL) { init_ok = FALSE; } } if(init_ok) { crm_debug_4("Connecting to the CIB"); if(cib_ok != te_cib_conn->cmds->signon( te_cib_conn, crm_system_name, cib_command)) { init_ok = FALSE; } } if(init_ok) { crm_debug_4("Setting CIB notification callback"); if(te_cib_conn->cmds->add_notify_callback( - te_cib_conn, T_CIB_UPDATE_CONFIRM, - te_update_confirm) != cib_ok) { + te_cib_conn, T_CIB_DIFF_NOTIFY, + te_update_diff) != cib_ok) { crm_err("Could not set CIB notification callback"); init_ok = FALSE; } } if(init_ok && ST_OK != stonithd_signon(crm_system_name)) { crm_err("Could not sign up to stonithd"); /* init_ok = FALSE; */ } if(init_ok && ST_OK != stonithd_set_stonith_ops_callback( tengine_stonith_callback, NULL)) { crm_err("Could not set stonith callback"); stonithd_signoff(); /* init_ok = FALSE; */ } if(init_ok) { IPC_Channel *fence_ch = stonithd_input_IPC_channel(); if(fence_ch == NULL) { } else if(NULL == G_main_add_IPC_Channel( G_PRIORITY_LOW, fence_ch, FALSE, tengine_stonith_dispatch, NULL, tengine_stonith_connection_destroy)) { crm_err("Failed to add Fencing channel to our mainloop"); init_ok = FALSE; } } if(init_ok) { /* Create the mainloop and run it... */ crm_info("Starting %s", crm_system_name); mainloop = g_main_new(FALSE); g_main_run(mainloop); return_to_orig_privs(); crm_info("Exiting %s", crm_system_name); } else { crm_warn("Initialization errors, %s not starting.", crm_system_name); } if(init_ok) { return 0; } return 1; } void usage(const char* cmd, int exit_status) { FILE* stream; stream = exit_status ? stderr : stdout; fprintf(stream, "usage: %s [-srkh]" "[-c configure file]\n", cmd); /* fprintf(stream, "\t-d\tsets debug level\n"); */ /* fprintf(stream, "\t-s\tgets daemon status\n"); */ /* fprintf(stream, "\t-r\trestarts daemon\n"); */ /* fprintf(stream, "\t-k\tstops daemon\n"); */ /* fprintf(stream, "\t-h\thelp message\n"); */ fflush(stream); exit(exit_status); } gboolean tengine_shutdown(int nsig, gpointer unused) { #if 0 static int shuttingdown = 0; if (!shuttingdown) { shuttingdown = 1; } if (mainloop != NULL && g_main_is_running(mainloop)) { g_main_quit(mainloop); }else{ exit(LSB_EXIT_OK); } return TRUE; #else return FALSE; #endif } diff --git a/crm/tengine/tengine.c b/crm/tengine/tengine.c index f2ac1b3ddf..b4157ea06b 100644 --- a/crm/tengine/tengine.c +++ b/crm/tengine/tengine.c @@ -1,954 +1,994 @@ -/* $Id: tengine.c,v 1.79 2005/06/14 11:38:26 davidlee Exp $ */ +/* $Id: tengine.c,v 1.80 2005/06/15 10:47:45 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 #include gboolean graph_complete = FALSE; GListPtr graph = NULL; IPC_Channel *crm_ch = NULL; uint transition_timeout = 30*1000; /* 30 seconds */ uint default_transition_timeout = 30*1000; /* 30 seconds */ uint next_transition_timeout = 30*1000; /* 30 seconds */ void fire_synapse(synapse_t *synapse); gboolean initiate_action(action_t *action); gboolean confirm_synapse(synapse_t *synapse, int action_id); void check_synapse_triggers(synapse_t *synapse, int action_id); void cib_action_updated( const HA_Message *msg, int call_id, int rc, crm_data_t *output, void *user_data); te_timer_t *transition_timer = NULL; int transition_counter = 1; const te_fsa_state_t te_state_matrix[i_invalid][s_invalid] = { /* s_idle, s_in_transition, s_abort_pending */ /* Got an i_transition */{ s_in_transition, s_abort_pending, s_abort_pending }, /* Got an i_cancel */{ s_idle, s_abort_pending, s_abort_pending }, /* Got an i_complete */{ s_idle, s_idle, s_abort_pending }, /* Got an i_cib_complete*/{ s_idle, s_in_transition, s_idle }, /* Got an i_cib_confirm */{ s_idle, s_in_transition, s_abort_pending }, /* Got an i_cib_notify */{ s_idle, s_in_transition, s_abort_pending } }; te_fsa_state_t te_fsa_state = s_idle; gboolean initialize_graph(void) { remove_cib_op_callback(-1, TRUE); if(transition_timer == NULL) { crm_malloc0(transition_timer, sizeof(te_timer_t)); transition_timer->timeout = 10; transition_timer->source_id = -1; transition_timer->reason = timeout_timeout; transition_timer->action = NULL; } else { stop_te_timer(transition_timer); } while(g_list_length(graph) > 0) { synapse_t *synapse = g_list_nth_data(graph, 0); while(g_list_length(synapse->actions) > 0) { action_t *action = g_list_nth_data(synapse->actions,0); synapse->actions = g_list_remove( synapse->actions, action); if(action->timer->source_id > 0) { crm_debug_3("Removing timer for action: %d", action->id); g_source_remove(action->timer->source_id); } free_xml(action->xml); crm_free(action->timer); crm_free(action); } while(g_list_length(synapse->inputs) > 0) { action_t *action = g_list_nth_data(synapse->inputs, 0); synapse->inputs = g_list_remove(synapse->inputs, action); free_xml(action->xml); crm_free(action); } graph = g_list_remove(graph, synapse); crm_free(synapse); } graph = NULL; return TRUE; } /* * returns the ID of the action if a match is found * returns -1 if a match was not found * returns -2 if a match was found but the action failed (and was * not allowed to) */ int match_graph_event(action_t *action, crm_data_t *event, const char *event_node) { const char *allow_fail = NULL; const char *this_action = NULL; const char *this_node = NULL; + const char *this_uname = NULL; const char *this_rsc = NULL; + const char *magic = NULL; + const char *transition = NULL; - const char *event_rsc; - const char *rsc_state; - const char *event_action; - const char *event_rc; + char *this_event; const char *op_status; + const char *update_event; action_t *match = NULL; int op_status_i = -3; + int transition_i = -1; if(event == NULL) { crm_debug_4("Ignoring NULL event"); return -1; } - event_action = crm_element_value(event, XML_LRM_ATTR_LASTOP); - event_rsc = crm_element_value(event, XML_ATTR_ID); - event_rc = crm_element_value(event, XML_LRM_ATTR_RC); - rsc_state = crm_element_value(event, XML_LRM_ATTR_RSCSTATE); + update_event = crm_element_value(event, XML_ATTR_ID); op_status = crm_element_value(event, XML_LRM_ATTR_OPSTATUS); - if(op_status != NULL) { - op_status_i = atoi(op_status); - } - this_action = crm_element_value(action->xml, XML_LRM_ATTR_TASK); - this_node = crm_element_value(action->xml, XML_LRM_ATTR_TARGET); + this_node = crm_element_value(action->xml, XML_LRM_ATTR_TARGET_UUID); + this_uname = crm_element_value(action->xml, XML_LRM_ATTR_TARGET); this_rsc = crm_element_value(action->xml, XML_LRM_ATTR_RSCID); - - crm_debug_2("matching against: <%s task=%s node=%s rsc_id=%s/>", - crm_element_name(action->xml), this_action, this_node, this_rsc); - if(safe_str_neq(this_action, event_action)) { - crm_debug_2("Action %d : Action mismatch %s", - action->id, event_action); - - } else if(safe_str_eq(crm_element_name(action->xml), XML_GRAPH_TAG_CRM_EVENT)) { - if(safe_str_eq(this_action, CRM_OP_FENCE)) { - - } else if(safe_str_neq(this_node, event_node)) { - crm_debug_2("node mismatch: %s", event_node); - } else { - crm_debug_3(XML_GRAPH_TAG_CRM_EVENT); - match = action; - } - - crm_debug_3(XML_GRAPH_TAG_CRM_EVENT); - match = action; - - } else if(safe_str_neq(this_node, event_node)) { - crm_debug_2("Action %d : Node mismatch %s", - action->id, event_node); + magic = crm_element_value(event, "transition_magic"); - } else if(safe_str_eq(crm_element_name(action->xml), XML_GRAPH_TAG_RSC_OP)) { - crm_debug_3(XML_GRAPH_TAG_RSC_OP); - if(safe_str_eq(this_rsc, event_rsc)) { - match = action; - } else { - crm_debug_2("Action %d : bad rsc (%s) != (%s)", - action->id, this_rsc, event_rsc); - } + this_event = generate_op_key(this_rsc, this_action, action->interval); + + if(safe_str_neq(this_event, update_event)) { + crm_debug_2("Action %d : Event mismatch %s vs. %s", + action->id, this_event, update_event); + + } else if(safe_str_neq(this_node, event_node)) { + crm_debug_2("Action %d : Node mismatch %s (%s) vs. %s", + action->id, this_node, this_uname, event_node); + } else { + match = action; } + crm_free(this_event); if(match == NULL) { - crm_debug_2("didnt match current action"); return -1; } + + crm_debug("Matched action %d", action->id); + if(transition != NULL) { + transition_i = atoi(transition); + } + if(op_status != NULL) { + op_status_i = atoi(op_status); + } - crm_debug_2("matched"); + if(magic != NULL && (op_status == NULL || transition == NULL)) { + char *alt_status = NULL; + char *alt_transition = NULL; + decodeNVpair(magic, ':', &alt_transition, &alt_status); + if(op_status == NULL && alt_status != NULL) { + op_status_i = atoi(alt_status); + } else if(op_status == NULL) { + crm_err("Status details not found"); + crm_log_message(LOG_ERR, event); + } + + if(transition == NULL && alt_transition != NULL) { + transition_i = atoi(alt_transition); + + } else if(transition == NULL) { + crm_err("Transition details not found"); + crm_log_message(LOG_ERR, event); + } + + } else if(magic == NULL) { + crm_err("magic not found"); + crm_log_message(LOG_ERR, event); + } + + if(transition_counter < transition_i) { + crm_err("Detected an action from a __future__ transition:" + " %d vs. %d", transition_i, transition_counter); + return -1; + + } else if(transition_counter > transition_i) { + crm_warn("Detected an action from a previous transition:" + " %d vs. %d", transition_i, transition_counter); + return -3; + } + + /* stop this event's timer if it had one */ stop_te_timer(match->timer); /* Process OP status */ allow_fail = crm_element_value(match->xml, "allow_fail"); switch(op_status_i) { + case -3: + crm_err("Action returned the same as last time..." + " whatever that was!"); + crm_log_message(LOG_ERR, event); + break; case LRM_OP_PENDING: - /* should never happen */ - CRM_DEV_ASSERT(op_status_i != LRM_OP_PENDING); + crm_debug("Ignoring pending operation"); + return -4; break; case LRM_OP_DONE: break; case LRM_OP_ERROR: case LRM_OP_TIMEOUT: case LRM_OP_NOTSUPPORTED: - crm_warn("Action %s for \"%s\" on %s failed: %s", - event_action, event_rsc, event_node, - op_status2text(op_status_i)); + crm_warn("Action %s on %s failed: %s", + update_event, event_node, + op_status2text(op_status_i)); if(FALSE == crm_is_true(allow_fail)) { send_complete("Action failed", event, te_failed, i_cancel); return -2; } break; case LRM_OP_CANCELLED: /* do nothing?? */ crm_err("Dont know what to do for cancelled ops yet"); break; default: crm_err("Unsupported action result: %d", op_status_i); send_complete("Unsupport action result", event, te_failed, i_cancel); return -2; } te_log_action(LOG_DEBUG, "Action %d confirmed", match->id); match->complete = TRUE; return match->id; } int match_down_event(const char *target, const char *filter, int rc) { const char *allow_fail = NULL; const char *this_action = NULL; const char *this_node = NULL; action_t *match = NULL; slist_iter( synapse, synapse_t, graph, lpc, /* lookup event */ slist_iter( action, action_t, synapse->actions, lpc2, crm_data_t *action_args = NULL; if(action->type != action_type_crm) { continue; } this_action = crm_element_value( action->xml, XML_LRM_ATTR_TASK); if(filter != NULL && safe_str_neq(this_action, filter)) { continue; } if(safe_str_eq(this_action, CRM_OP_FENCE)) { action_args = find_xml_node( action->xml, XML_TAG_ATTRS, TRUE); this_node = crm_element_value( action_args, XML_LRM_ATTR_TARGET); } else if(safe_str_eq(this_action, CRM_OP_SHUTDOWN)) { crm_element_value( action->xml, XML_LRM_ATTR_TASK); this_node = crm_element_value( action->xml, XML_LRM_ATTR_TARGET); } else { crm_info("Action %d : Bad action %s", action->id, this_action); continue; } if(safe_str_neq(this_node, target)) { crm_info("Action %d : Node mismatch: %s", action->id, this_node); continue; } match = action; ); if(match != NULL) { break; } ); if(match == NULL) { crm_debug_3("didnt match current action"); return -1; } crm_debug_3("matched"); /* stop this event's timer if it had one */ stop_te_timer(match->timer); /* Process OP status */ switch(rc) { case STONITH_SUCCEEDED: break; case STONITH_CANNOT: case STONITH_TIMEOUT: case STONITH_GENERIC: allow_fail = crm_element_value(match->xml, "allow_fail"); if(FALSE == crm_is_true(allow_fail)) { crm_err("Stonith of %s failed (%d)..." " aborting transition.", target, rc); send_complete("Stonith failed", match->xml, te_failed, i_cancel); return -2; } break; default: crm_err("Unsupported action result: %d", rc); send_complete("Unsupport Stonith result", match->xml, te_failed, i_cancel); return -2; } crm_debug_3("Action %d was successful, looking for next action", match->id); match->complete = TRUE; return match->id; } gboolean process_graph_event(crm_data_t *event, const char *event_node) { int rc = -1; int action_id = -1; int op_status_i = 0; const char *task = NULL; const char *rsc_id = NULL; const char *op_status = NULL; if(event == NULL) { crm_debug("a transition is starting"); process_trigger(action_id); check_for_completion(); return TRUE; } task = crm_element_value(event, XML_LRM_ATTR_LASTOP); rsc_id = crm_element_value(event, XML_ATTR_ID); op_status = crm_element_value(event, XML_LRM_ATTR_OPSTATUS); if(op_status != NULL) { op_status_i = atoi(op_status); if(op_status_i == -1) { /* just information that the action was sent */ crm_debug("Ignoring TE initiated updates"); return TRUE; } } - crm_debug("Processing CIB update: %s %s on %s: %s", - task, rsc_id, event_node, op_status2text(op_status_i)); + crm_debug("Processing CIB update: %s on %s: %s", + rsc_id, event_node, op_status2text(op_status_i)); next_transition_timeout = transition_timeout; slist_iter( synapse, synapse_t, graph, lpc, /* lookup event */ slist_iter( action, action_t, synapse->actions, lpc2, - rc = match_graph_event(action, event ,event_node); + rc = match_graph_event(action, event, event_node); if(action_id >= 0 && rc >= 0) { crm_err("Additional match found: %d [%d]", rc, action_id); } else if(rc != -1) { action_id = rc; } ); if(action_id != -1) { break; } ); if(action_id == -1) { /* didnt find a match... * now try any dangling inputs */ slist_iter( synapse, synapse_t, graph, lpc, slist_iter( action, action_t, synapse->inputs, lpc2, rc = match_graph_event(action,event,event_node); if(action_id >=0 && rc >=0 && rc != action_id) { crm_err("Additional match found:" " %d [%d]", rc, action_id); } else if(rc != -1) { action_id = rc; } ); if(action_id != -1) { break; } ); } if(action_id > -1) { crm_log_xml_debug_3(event, "Event found"); } else if(action_id == -2) { crm_log_xml_info(event, "Event failed"); + } else if(action_id == -3) { + crm_log_xml_info(event, "Old event found"); + + } else if(action_id == -4) { + crm_log_xml_debug(event, "Pending event found"); + } else { /* unexpected event, trigger a pe-recompute */ /* possibly do this only for certain types of actions */ send_complete("Event not matched", event, te_update, i_cancel); return FALSE; } process_trigger(action_id); check_for_completion(); return TRUE; } void check_for_completion(void) { if(graph_complete) { /* allow some slack until we are pretty sure nothing * else is happening */ crm_info("Transition complete"); send_complete("complete", NULL, te_done, i_complete); } else { /* restart the transition timer again */ crm_debug_3("Transition not yet complete"); transition_timer->timeout = next_transition_timeout; start_te_timer(transition_timer); } } gboolean initiate_action(action_t *action) { gboolean ret = FALSE; gboolean send_command = FALSE; const char *on_node = NULL; const char *id = NULL; const char *task = NULL; const char *timeout = NULL; const char *msg_task = XML_GRAPH_TAG_RSC_OP; on_node = crm_element_value(action->xml, XML_LRM_ATTR_TARGET); id = crm_element_value(action->xml, XML_ATTR_ID); task = crm_element_value(action->xml, XML_LRM_ATTR_TASK); timeout = crm_element_value(action->xml, XML_ATTR_TIMEOUT); if(id == NULL || strlen(id) == 0 || task == NULL || strlen(task) == 0) { /* error */ te_log_action(LOG_ERR, "Failed on corrupted command: %s (id=%s) %s", crm_element_name(action->xml), crm_str(id), crm_str(task)); } else if(action->type == action_type_pseudo){ te_log_action(LOG_INFO, "Executing pseudo-event (%d): " "%s on %s", action->id, task, on_node); action->complete = TRUE; process_trigger(action->id); ret = TRUE; } else if(action->type == action_type_crm && safe_str_eq(task, CRM_OP_FENCE)){ crm_data_t *action_args = find_xml_node( action->xml, XML_TAG_ATTRS, TRUE); const char *uuid = NULL; const char *target = NULL; const char *name = NULL; stonith_ops_t * st_op = NULL; xml_child_iter( action_args, nvpair, XML_CIB_TAG_NVPAIR, name = crm_element_value(nvpair, XML_NVPAIR_ATTR_NAME); if(safe_str_eq(name, XML_LRM_ATTR_TARGET)) { target = crm_element_value( nvpair, XML_NVPAIR_ATTR_VALUE); } else if(safe_str_eq(name, XML_LRM_ATTR_TARGET_UUID)) { uuid = crm_element_value( nvpair, XML_NVPAIR_ATTR_VALUE); } ); CRM_DEV_ASSERT(target != NULL); CRM_DEV_ASSERT(uuid != NULL); te_log_action(LOG_INFO,"Executing fencing operation (%s) on %s", id, target); #ifdef TESTING ret = TRUE; action->complete = TRUE; process_trigger(action->id); return TRUE; #endif crm_malloc0(st_op, sizeof(stonith_ops_t)); st_op->optype = RESET; st_op->timeout = crm_atoi(timeout, "10000"); /* ten seconds */ st_op->node_name = crm_strdup(target); st_op->node_uuid = crm_strdup(uuid); if(stonithd_input_IPC_channel() == NULL) { crm_err("Cannot fence %s - stonith not available", target); } else if (ST_OK == stonithd_node_fence( st_op )) { ret = TRUE; } } else if(on_node == NULL || strlen(on_node) == 0) { /* error */ te_log_action(LOG_ERR, "Failed on corrupted command: %s (id=%s) %s on %s", crm_element_name(action->xml), crm_str(id), crm_str(task), crm_str(on_node)); } else if(action->type == action_type_crm){ te_log_action(LOG_INFO, "Executing crm-event (%s): %s on %s", id, task, on_node); #ifdef TESTING action->complete = TRUE; process_trigger(action->id); return TRUE; #endif /* action->complete = TRUE; */ msg_task = task; send_command = TRUE; } else if(action->type == action_type_rsc){ /* never overwrite stop actions in the CIB with * anything other than completed results * * Writing pending stops makes it look like the * resource is running again */ #ifdef TESTING cib_action_update(action, LRM_OP_PENDING); return TRUE; #endif if(safe_str_neq(task, CRMD_ACTION_STOP)) { cib_action_update(action, LRM_OP_PENDING); } else { cib_action_updated(NULL, 0, cib_ok, NULL, action); } ret = TRUE; } else { te_log_action(LOG_ERR, "Failed on unsupported command type: " "%s, %s (id=%s) on %s", crm_element_name(action->xml), task, id, on_node); } if(send_command) { HA_Message *cmd = NULL; char *counter = crm_itoa(transition_counter); cmd = create_request(msg_task, NULL, on_node, CRM_SYSTEM_CRMD, CRM_SYSTEM_TENGINE, NULL); ha_msg_add(cmd, "transition_id", crm_str(counter)); ret = send_ipc_message(crm_ch, cmd); crm_free(counter); if(ret && action->timeout > 0) { crm_debug_3("Setting timer for action %d",action->id); action->timer->reason = timeout_action_warn; start_te_timer(action->timer); } } return ret; } gboolean cib_action_update(action_t *action, int status) { char *code = NULL; crm_data_t *fragment = NULL; crm_data_t *state = NULL; crm_data_t *rsc = NULL; crm_data_t *xml_op = NULL; + char *op_id = NULL; enum cib_errors rc = cib_ok; const char *task = crm_element_value(action->xml, XML_LRM_ATTR_TASK); const char *rsc_id = crm_element_value(action->xml, XML_LRM_ATTR_RSCID); const char *target = crm_element_value(action->xml, XML_LRM_ATTR_TARGET); const char *target_uuid = crm_element_value(action->xml, XML_LRM_ATTR_TARGET_UUID); int call_options = cib_quorum_override; if(status == LRM_OP_TIMEOUT) { if(crm_element_value(action->xml, XML_LRM_ATTR_RSCID) != NULL) { crm_warn("%s: %s %s on %s timed out", crm_element_name(action->xml), task, rsc_id, target); } else { crm_warn("%s: %s on %s timed out", crm_element_name(action->xml), task, target); } #ifdef TESTING /* turn the "pending" notification into a "op completed" notification * when testing... exercises more code this way. */ } else if(status == LRM_OP_PENDING) { status = LRM_OP_DONE; #endif } code = crm_itoa(status); /* update the CIB */ fragment = NULL; state = create_xml_node(NULL, XML_CIB_TAG_STATE); set_xml_property_copy(state, XML_ATTR_UUID, target_uuid); set_xml_property_copy(state, XML_ATTR_UNAME, target); rsc = create_xml_node(state, XML_CIB_TAG_LRM); rsc = create_xml_node(rsc, XML_LRM_TAG_RESOURCES); rsc = create_xml_node(rsc, XML_LRM_TAG_RESOURCE); xml_op = create_xml_node(rsc,XML_LRM_TAG_RSC_OP); set_xml_property_copy(rsc, XML_ATTR_ID, rsc_id); set_xml_property_copy(xml_op, XML_ATTR_ID, task); - if(action->interval > 0) { - char *op_id = generate_op_key(rsc_id, task, action->interval); - set_xml_property_copy(xml_op, XML_ATTR_ID, op_id); - crm_free(op_id); - } + op_id = generate_op_key(rsc_id, task, action->interval); + set_xml_property_copy(xml_op, XML_ATTR_ID, op_id); + crm_free(op_id); set_xml_property_copy(xml_op, XML_LRM_ATTR_TASK, task); set_xml_property_copy(rsc, XML_LRM_ATTR_RSCSTATE, get_rsc_state(task, status)); set_xml_property_copy(rsc, XML_LRM_ATTR_OPSTATUS, code); set_xml_property_copy(rsc, XML_LRM_ATTR_RC, code); set_xml_property_copy(rsc, XML_LRM_ATTR_LASTOP, task); set_xml_property_copy(xml_op, XML_LRM_ATTR_OPSTATUS, code); set_xml_property_copy(xml_op, XML_LRM_ATTR_RC, code); set_xml_property_copy(xml_op, "origin", __FUNCTION__); + + crm_free(code); + + ha_msg_add_int(xml_op, "transition_id", transition_counter); - set_node_tstamp(xml_op); - + crm_malloc0(code, sizeof(char)*37); + if(code != NULL) { + snprintf(code, 36, "%d:-1", transition_counter); + } + set_xml_property_copy(xml_op, "transition_magic", code); crm_free(code); + + set_node_tstamp(xml_op); fragment = create_cib_fragment(state, NULL); crm_debug_3("Updating CIB with \"%s\" (%s): %s %s on %s", status<0?"new action":XML_ATTR_TIMEOUT, crm_element_name(action->xml), crm_str(task), rsc_id, target); #ifndef TESTING rc = te_cib_conn->cmds->modify( te_cib_conn, XML_CIB_TAG_STATUS, fragment, NULL, call_options); crm_debug("Updating CIB with %s action %d: %s %s on %s (call_id=%d)", op_status2text(status), action->id, task, rsc_id, target, rc); if(status == LRM_OP_PENDING) { crm_debug_2("Waiting for callback id: %d", rc); add_cib_op_callback(rc, FALSE, action, cib_action_updated); } #else fprintf(stderr, "Initiating action %d: %s %s on %s\n", action->id, task, rsc_id, target); call_options = 0; { HA_Message *cmd = ha_msg_new(11); ha_msg_add(cmd, F_TYPE, T_CRM); ha_msg_add(cmd, F_CRM_VERSION, CRM_VERSION); ha_msg_add(cmd, F_CRM_MSG_TYPE, XML_ATTR_REQUEST); ha_msg_add(cmd, F_CRM_TASK, CRM_OP_EVENTCC); ha_msg_add(cmd, F_CRM_SYS_TO, CRM_SYSTEM_TENGINE); ha_msg_add(cmd, F_CRM_SYS_FROM, CRM_SYSTEM_TENGINE); ha_msg_addstruct(cmd, crm_element_name(state), state); send_ipc_message(crm_ch, cmd); } #endif free_xml(fragment); free_xml(state); if(rc < cib_ok) { return FALSE; } return TRUE; } void cib_action_updated( const HA_Message *msg, int call_id, int rc, crm_data_t *output, void *user_data) { HA_Message *cmd = NULL; crm_data_t *rsc_op = NULL; const char *task = NULL; const char *rsc_id = NULL; const char *on_node = NULL; action_t *action = user_data; char *counter = crm_itoa(transition_counter); CRM_DEV_ASSERT(action != NULL); if(crm_assert_failed) { return; } CRM_DEV_ASSERT(action->xml != NULL); if(crm_assert_failed) { return; } rsc_op = action->xml; task = crm_element_value(rsc_op, XML_LRM_ATTR_TASK); rsc_id = crm_element_value(rsc_op, XML_LRM_ATTR_RSCID); on_node = crm_element_value(rsc_op, XML_LRM_ATTR_TARGET); - + ha_msg_add_int(rsc_op, "transition_id", transition_counter); + if(rc < cib_ok) { crm_err("Update for action %d: %s %s on %s FAILED", action->id, task, rsc_id, on_node); send_complete(cib_error2string(rc), output, te_failed, i_cancel); return; } if(te_fsa_state != s_in_transition) { int pending_updates = num_cib_op_callbacks(); if(pending_updates == 0) { send_complete("CIB update queue empty", output, te_done, i_cib_complete); } else { crm_debug("Still waiting on %d callbacks", pending_updates); } crm_debug("Not executing action: Not in a transition: %d", te_fsa_state); return; } crm_info("Initiating action %d: %s %s on %s", action->id, task, rsc_id, on_node); if(rsc_op != NULL) { crm_log_xml_debug_2(rsc_op, "Performing"); } cmd = create_request( task, rsc_op, on_node, CRM_SYSTEM_LRMD,CRM_SYSTEM_TENGINE,NULL); ha_msg_add(cmd, "transition_id", counter); crm_free(counter); #ifndef TESTING send_ipc_message(crm_ch, cmd); #else crm_log_message(LOG_INFO, cmd); #endif if(action->timeout > 0) { crm_debug_3("Setting timer for action %d",action->id); action->timer->reason = timeout_action_warn; start_te_timer(action->timer); } } gboolean initiate_transition(void) { crm_info("Initating transition"); process_graph_event(NULL, NULL); return TRUE; } void check_synapse_triggers(synapse_t *synapse, int action_id) { synapse->triggers_complete = TRUE; if(synapse->confirmed) { crm_debug_3("Skipping confirmed synapse %d", synapse->id); return; } else if(synapse->complete == FALSE) { crm_debug_3("Checking pre-reqs for %d", synapse->id); /* lookup prereqs */ slist_iter( prereq, action_t, synapse->inputs, lpc, crm_debug_3("Processing input %d", prereq->id); if(prereq->id == action_id) { crm_debug_3("Marking input %d complete", action_id); prereq->complete = TRUE; } else if(prereq->complete == FALSE) { crm_debug_3("Inputs for synapse %d not satisfied", synapse->id); synapse->triggers_complete = FALSE; } ); } } void fire_synapse(synapse_t *synapse) { if(synapse == NULL) { crm_err("Synapse was NULL!"); return; } crm_debug_3("Checking if synapse %d needs to be fired", synapse->id); if(synapse->complete) { crm_debug_3("Skipping complete synapse %d", synapse->id); return; } else if(synapse->triggers_complete == FALSE) { crm_debug_3("Synapse %d not yet satisfied", synapse->id); return; } crm_debug("All inputs for synapse %d satisfied... invoking actions", synapse->id); synapse->complete = TRUE; slist_iter( action, action_t, synapse->actions, lpc, /* allow some leway */ unsigned tmp_time = 2 * action->timeout; gboolean passed = FALSE; action->invoked = TRUE; /* Invoke the action and start the timer */ passed = initiate_action(action); if(passed == FALSE) { crm_err("Failed initiating <%s id=%d> in synapse %d", crm_element_name(action->xml), action->id, synapse->id); send_complete("Action init failed", action->xml, te_failed, i_cancel); return; } if(tmp_time > next_transition_timeout) { next_transition_timeout = tmp_time; } ); crm_debug("Synapse %d complete", synapse->id); } gboolean confirm_synapse(synapse_t *synapse, int action_id) { gboolean complete = TRUE; synapse->confirmed = TRUE; slist_iter( action, action_t, synapse->actions, lpc, if(action->complete == FALSE) { complete = FALSE; synapse->confirmed = FALSE; crm_debug_3("Found an incomplete action" " - transition not complete"); break; } ); if(complete) { crm_debug("Synapse %d complete (action=%d)", synapse->id, action_id); } return complete; } void process_trigger(int action_id) { graph_complete = TRUE; crm_debug_3("Processing trigger from action %d", action_id); /* something happened, stop the timer and start it again at the end */ stop_te_timer(transition_timer); slist_iter( synapse, synapse_t, graph, lpc, if(synapse->confirmed) { crm_debug_3("Skipping confirmed synapse %d", synapse->id); continue; } check_synapse_triggers(synapse, action_id); fire_synapse(synapse); if(graph == NULL) { crm_err("Trigger processing aborted after failed synapse"); break; } crm_debug_3("Checking if %d is confirmed", synapse->id); if(synapse->complete == FALSE) { crm_debug_3("Found an incomplete synapse" " - transition not complete"); /* indicate that the transition is not yet complete */ graph_complete = FALSE; } else if(synapse->confirmed == FALSE) { gboolean confirmed = confirm_synapse(synapse,action_id); graph_complete = graph_complete && confirmed; } crm_debug_3("%d is %s", synapse->id, synapse->confirmed?"confirmed":synapse->complete?"complete":"pending"); ); } diff --git a/crm/tengine/unpack.c b/crm/tengine/unpack.c index 492d04c6d0..2a4b88d834 100644 --- a/crm/tengine/unpack.c +++ b/crm/tengine/unpack.c @@ -1,382 +1,381 @@ -/* $Id: unpack.c,v 1.37 2005/06/14 11:38:26 davidlee Exp $ */ +/* $Id: unpack.c,v 1.38 2005/06/15 10:47:45 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 #include #include cib_t *te_cib_conn = NULL; action_t* unpack_action(crm_data_t *xml_action); crm_data_t *create_shutdown_event(const char *node, int op_status); void set_timer_value(te_timer_t *timer, const char *time, int time_default); extern int transition_counter; void set_timer_value(te_timer_t *timer, const char *time, int time_default) { int tmp_time; if(timer == NULL) { return; } timer->timeout = time_default; tmp_time = crm_get_msec(time); if(tmp_time > 0) { timer->timeout = tmp_time; } } - gboolean unpack_graph(crm_data_t *xml_graph) { /* timeout = crm_get_msec(time); transition_timeout = transition_timer->timeout; time = crm_element_value(xml_graph, "transition_fuzz"); transition_counter = crm_atoi(t_id, "-1"); crm_info("Beginning transition %d : timeout set to %dms", transition_counter, transition_timer->timeout); xml_child_iter( xml_graph, synapse, "synapse", synapse_t *new_synapse = NULL; crm_debug_3("looking in synapse %s", crm_element_value(synapse, XML_ATTR_ID)); crm_malloc0(new_synapse, sizeof(synapse_t)); new_synapse->id = num_synapses++; new_synapse->complete = FALSE; new_synapse->confirmed = FALSE; new_synapse->actions = NULL; new_synapse->inputs = NULL; graph = g_list_append(graph, new_synapse); crm_debug_3("look for actions in synapse %s", crm_element_value(synapse, XML_ATTR_ID)); xml_child_iter( synapse, actions, "action_set", xml_child_iter( actions, action, NULL, action_t *new_action = unpack_action(action); num_actions++; if(new_action == NULL) { continue; } crm_debug_3("Adding action %d to synapse %d", new_action->id, new_synapse->id); new_synapse->actions = g_list_append( new_synapse->actions, new_action); ); ); crm_debug_3("look for inputs in synapse %s", crm_element_value(synapse, XML_ATTR_ID)); xml_child_iter( synapse, inputs, "inputs", xml_child_iter( inputs, trigger, NULL, xml_child_iter( trigger, input, NULL, action_t *new_input = unpack_action(input); if(new_input == NULL) { continue; } crm_debug_3("Adding input %d to synapse %d", new_input->id, new_synapse->id); new_synapse->inputs = g_list_append( new_synapse->inputs, new_input); ); ); ); ); crm_info("Unpacked %d actions in %d synapses", num_actions, num_synapses); if(num_actions > 0) { return TRUE; } else { /* indicate to caller that there's nothing to do */ return FALSE; } } action_t* unpack_action(crm_data_t *xml_action) { const char *tmp = crm_element_value(xml_action, XML_ATTR_ID); action_t *action = NULL; crm_data_t *action_copy = NULL; crm_data_t *nvpair_list = NULL; if(tmp == NULL) { crm_err("Actions must have an id!"); crm_log_xml_debug_3(xml_action, "Action with missing id"); return NULL; } action_copy = copy_xml(xml_action); crm_malloc0(action, sizeof(action_t)); if(action == NULL) { return NULL; } action->id = atoi(tmp); action->timeout = 0; action->interval = 0; action->timer = NULL; action->invoked = FALSE; action->complete = FALSE; action->can_fail = FALSE; action->type = action_type_rsc; action->xml = action_copy; if(safe_str_eq(crm_element_name(action_copy), XML_GRAPH_TAG_RSC_OP)) { action->type = action_type_rsc; } else if(safe_str_eq(crm_element_name(action_copy), XML_GRAPH_TAG_PSEUDO_EVENT)) { action->type = action_type_pseudo; } else if(safe_str_eq(crm_element_name(action_copy), XML_GRAPH_TAG_CRM_EVENT)) { action->type = action_type_crm; } nvpair_list = find_xml_node(action_copy, XML_TAG_ATTRS, FALSE); if(nvpair_list == NULL) { crm_debug_2("No attributes in %s", crm_element_name(action_copy)); } xml_child_iter( nvpair_list, node_iter, XML_CIB_TAG_NVPAIR, const char *key = crm_element_value( node_iter, XML_NVPAIR_ATTR_NAME); const char *value = crm_element_value( node_iter, XML_NVPAIR_ATTR_VALUE); if(safe_str_eq(key, "timeout")) { action->timeout = crm_get_msec(value); } else if(safe_str_eq(key, "interval")) { action->interval = crm_get_msec(value); } ); crm_debug_3("Action %d has timer set to %dms", action->id, action->timeout); crm_malloc0(action->timer, sizeof(te_timer_t)); action->timer->timeout = 2 * action->timeout; action->timer->source_id = -1; action->timer->reason = timeout_action; action->timer->action = action; tmp = crm_element_value(action_copy, "can_fail"); crm_str_to_boolean(tmp, &(action->can_fail)); return action; } gboolean extract_event(crm_data_t *msg) { const char *event_node = NULL; struct abort_blob_s { const char *text; crm_data_t *update; te_reason_t reason; }; struct abort_blob_s blob = { NULL, NULL, 0 }; blob.reason = te_update; /* [cib fragment] ... */ crm_debug_4("Extracting event from %s", crm_element_name(msg)); xml_child_iter( msg, node_state, XML_CIB_TAG_STATE, crm_data_t *resources = NULL; const char *ccm_state = crm_element_value( node_state, XML_CIB_ATTR_INCCM); const char *crmd_state = crm_element_value( node_state, XML_CIB_ATTR_CRMDSTATE); blob.update = node_state; - event_node = crm_element_value(node_state, XML_ATTR_UNAME); + event_node = crm_element_value(node_state, XML_ATTR_ID); crm_log_xml_debug_3(node_state,"Processing"); if(crm_element_value(node_state, XML_CIB_ATTR_SHUTDOWN) != NULL) { blob.text = "Aborting on "XML_CIB_ATTR_SHUTDOWN" attribute"; break; /* is this still required??? */ } else if(crm_element_value(node_state, CRM_OP_FENCE) != NULL) { /* node marked for STONITH * possibly by us when a shutdown timed out */ int action_id = -1; crm_debug_3("Checking for STONITH"); - event_node = crm_element_value(node_state, XML_ATTR_UNAME); action_id = match_down_event( event_node, CRM_OP_SHUTDOWN, LRM_OP_DONE); if(action_id < 0) { blob.text="Stonith/shutdown event not matched"; break; } else { process_trigger(action_id); check_for_completion(); } /* END: is this still required??? */ } resources = find_xml_node(node_state, XML_CIB_TAG_LRM, FALSE); resources = find_xml_node( resources, XML_LRM_TAG_RESOURCES, FALSE); /* * node state update... possibly from a shutdown we requested */ crm_debug_3("Processing state update"); if(safe_str_eq(ccm_state, XML_BOOLEAN_FALSE) || safe_str_eq(crmd_state, CRMD_JOINSTATE_DOWN)) { int action_id = -1; crm_debug_3("A shutdown we requested?"); action_id = match_down_event( event_node, NULL, LRM_OP_DONE); if(action_id >= 0) { process_trigger(action_id); check_for_completion(); } else { blob.text="Stonith/shutdown event not matched"; break; } } - if(resources != NULL) { - /* LRM resource update... - */ - xml_child_iter( - resources, child, NULL, + /* LRM resource update... */ + xml_child_iter( + resources, rsc, NULL, + xml_child_iter( + rsc, rsc_op, NULL, + crm_log_xml_debug_3( - child,"Processing LRM resource update"); - if(!process_graph_event(child, event_node)) { + rsc_op, "Processing resource update"); + if(!process_graph_event(rsc_op, event_node)) { /* the transition has already been * aborted and with better details */ return TRUE; } ); - } + ); ); if(blob.text != NULL) { send_complete(blob.text, blob.update, blob.reason, i_cancel); } return TRUE; } crm_data_t* create_shutdown_event(const char *node, int op_status) { crm_data_t *event = create_xml_node(NULL, XML_CIB_TAG_STATE); char *code = crm_itoa(op_status); set_xml_property_copy(event, XML_LRM_ATTR_TARGET, node); /* event_rsc = set_xml_property_copy(event, XML_ATTR_ID); */ set_xml_property_copy(event, XML_LRM_ATTR_RC, "0"); set_xml_property_copy( event, XML_LRM_ATTR_LASTOP, XML_CIB_ATTR_SHUTDOWN); set_xml_property_copy( event, XML_LRM_ATTR_RSCSTATE, CRMD_ACTION_GENERIC_OK); set_xml_property_copy(event, XML_LRM_ATTR_OPSTATUS, code); crm_free(code); return event; }