diff --git a/include/pcmki/pcmki_transition.h b/include/pcmki/pcmki_transition.h index c20cda4766..4e5578bf93 100644 --- a/include/pcmki/pcmki_transition.h +++ b/include/pcmki/pcmki_transition.h @@ -1,166 +1,164 @@ /* * Copyright 2004-2022 the Pacemaker project contributors * * The version control history for this file may have further details. * * This source code is licensed under the GNU Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #ifndef PCMK__PCMKI_PCMKI_TRANSITION__H # define PCMK__PCMKI_PCMKI_TRANSITION__H # include # include # include # include #ifdef __cplusplus extern "C" { #endif enum pcmk__graph_action_type { pcmk__pseudo_graph_action, pcmk__rsc_graph_action, pcmk__cluster_graph_action, }; enum pcmk__synapse_flags { pcmk__synapse_ready = (1 << 0), pcmk__synapse_failed = (1 << 1), pcmk__synapse_executed = (1 << 2), pcmk__synapse_confirmed = (1 << 3), }; typedef struct { int id; int priority; uint32_t flags; // Group of pcmk__synapse_flags GList *actions; /* pcmk__graph_action_t* */ GList *inputs; /* pcmk__graph_action_t* */ } pcmk__graph_synapse_t; -const char *synapse_state_str(pcmk__graph_synapse_t *synapse); - #define pcmk__set_synapse_flags(synapse, flags_to_set) do { \ (synapse)->flags = pcmk__set_flags_as(__func__, __LINE__, \ LOG_TRACE, \ "Synapse", "synapse", \ (synapse)->flags, (flags_to_set), #flags_to_set); \ } while (0) #define pcmk__clear_synapse_flags(synapse, flags_to_clear) do { \ (synapse)->flags = pcmk__clear_flags_as(__func__, __LINE__, \ LOG_TRACE, \ "Synapse", "synapse", \ (synapse)->flags, (flags_to_clear), #flags_to_clear); \ } while (0) enum pcmk__graph_action_flags { pcmk__graph_action_sent_update = (1 << 0), /* sent to the CIB */ pcmk__graph_action_executed = (1 << 1), /* sent to the CRM */ pcmk__graph_action_confirmed = (1 << 2), pcmk__graph_action_failed = (1 << 3), pcmk__graph_action_can_fail = (1 << 4), //! \deprecated Will be removed in a future release }; typedef struct { int id; int timeout; int timer; guint interval_ms; GHashTable *params; enum pcmk__graph_action_type type; pcmk__graph_synapse_t *synapse; uint32_t flags; // Group of pcmk__graph_action_flags xmlNode *xml; } pcmk__graph_action_t; #define crm__set_graph_action_flags(action, flags_to_set) do { \ (action)->flags = pcmk__set_flags_as(__func__, __LINE__, \ LOG_TRACE, \ "Action", "action", \ (action)->flags, (flags_to_set), #flags_to_set); \ } while (0) #define crm__clear_graph_action_flags(action, flags_to_clear) do { \ (action)->flags = pcmk__clear_flags_as(__func__, __LINE__, \ LOG_TRACE, \ "Action", "action", \ (action)->flags, (flags_to_clear), #flags_to_clear); \ } while (0) /* order matters here */ enum transition_action { tg_done, tg_stop, tg_restart, tg_shutdown, }; typedef struct { int id; char *source; int abort_priority; gboolean complete; const char *abort_reason; enum transition_action completion_action; int num_actions; int num_synapses; int batch_limit; guint network_delay; guint stonith_timeout; int fired; int pending; int skipped; int completed; int incomplete; GList *synapses; /* pcmk__graph_synapse_t* */ int migration_limit; } pcmk__graph_t; typedef struct crm_graph_functions_s { gboolean (*pseudo) (pcmk__graph_t *graph, pcmk__graph_action_t *action); gboolean (*rsc) (pcmk__graph_t *graph, pcmk__graph_action_t *action); gboolean (*crmd) (pcmk__graph_t *graph, pcmk__graph_action_t *action); gboolean (*stonith) (pcmk__graph_t *graph, pcmk__graph_action_t *action); gboolean (*allowed) (pcmk__graph_t *graph, pcmk__graph_action_t *action); } crm_graph_functions_t; enum transition_status { transition_active, transition_pending, /* active but no actions performed this time */ transition_complete, transition_terminated, }; void pcmk__set_graph_functions(crm_graph_functions_t *fns); pcmk__graph_t *pcmk__unpack_graph(xmlNode *xml_graph, const char *reference); enum transition_status pcmk__execute_graph(pcmk__graph_t *graph); void pcmk__update_graph(pcmk__graph_t *graph, pcmk__graph_action_t *action); void pcmk__free_graph(pcmk__graph_t *graph); const char *pcmk__graph_status2text(enum transition_status state); void pcmk__log_graph(unsigned int log_level, pcmk__graph_t *graph); void pcmk__log_graph_action(int log_level, pcmk__graph_action_t *action); lrmd_event_data_t *pcmk__event_from_graph_action(xmlNode *resource, pcmk__graph_action_t *action, int status, int rc, const char *exit_reason); #ifdef __cplusplus } #endif #endif diff --git a/lib/pacemaker/pcmk_graph_logging.c b/lib/pacemaker/pcmk_graph_logging.c index fedc9ead59..68f4df97cb 100644 --- a/lib/pacemaker/pcmk_graph_logging.c +++ b/lib/pacemaker/pcmk_graph_logging.c @@ -1,211 +1,211 @@ /* * Copyright 2004-2022 the Pacemaker project contributors * * The version control history for this file may have further details. * * This source code is licensed under the GNU Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include #include #include #include #include /*! * \internal * \brief Return text equivalent of an enum transition_status for logging * * \param[in] state Transition status * * \return Human-readable text equivalent of \p state */ const char * pcmk__graph_status2text(enum transition_status state) { switch (state) { case transition_active: return "active"; case transition_pending: return "pending"; case transition_complete: return "complete"; case transition_terminated: return "terminated"; } return "unknown"; } static const char * actiontype2text(enum pcmk__graph_action_type type) { switch (type) { case pcmk__pseudo_graph_action: return "pseudo"; case pcmk__rsc_graph_action: return "resource"; case pcmk__cluster_graph_action: return "cluster"; } return "invalid"; } /*! * \internal * \brief Find a transition graph action by ID * * \param[in] graph Transition graph to search * \param[in] id Action ID to search for * * \return Transition graph action corresponding to \p id, or NULL if none */ static pcmk__graph_action_t * find_graph_action_by_id(pcmk__graph_t *graph, int id) { if (graph == NULL) { return NULL; } for (GList *sIter = graph->synapses; sIter != NULL; sIter = sIter->next) { pcmk__graph_synapse_t *synapse = (pcmk__graph_synapse_t *) sIter->data; for (GList *aIter = synapse->actions; aIter != NULL; aIter = aIter->next) { pcmk__graph_action_t *action = (pcmk__graph_action_t *) aIter->data; if (action->id == id) { return action; } } } return NULL; } -const char * +static const char * synapse_state_str(pcmk__graph_synapse_t *synapse) { if (pcmk_is_set(synapse->flags, pcmk__synapse_failed)) { return "Failed"; } else if (pcmk_is_set(synapse->flags, pcmk__synapse_confirmed)) { return "Completed"; } else if (pcmk_is_set(synapse->flags, pcmk__synapse_executed)) { return "In-flight"; } else if (pcmk_is_set(synapse->flags, pcmk__synapse_ready)) { return "Ready"; } return "Pending"; } // List action IDs of inputs in graph that haven't completed successfully static char * synapse_pending_inputs(pcmk__graph_t *graph, pcmk__graph_synapse_t *synapse) { char *pending = NULL; size_t pending_len = 0; for (GList *lpc = synapse->inputs; lpc != NULL; lpc = lpc->next) { pcmk__graph_action_t *input = (pcmk__graph_action_t *) lpc->data; if (pcmk_is_set(input->flags, pcmk__graph_action_failed)) { pcmk__add_word(&pending, &pending_len, ID(input->xml)); } else if (pcmk_is_set(input->flags, pcmk__graph_action_confirmed)) { // Confirmed successful inputs are not pending } else if (find_graph_action_by_id(graph, input->id) != NULL) { // In-flight or pending pcmk__add_word(&pending, &pending_len, ID(input->xml)); } } if (pending == NULL) { pending = strdup("none"); } return pending; } // Log synapse inputs that aren't in graph static void log_unresolved_inputs(unsigned int log_level, pcmk__graph_t *graph, pcmk__graph_synapse_t *synapse) { for (GList *lpc = synapse->inputs; lpc != NULL; lpc = lpc->next) { pcmk__graph_action_t *input = (pcmk__graph_action_t *) lpc->data; const char *key = crm_element_value(input->xml, XML_LRM_ATTR_TASK_KEY); const char *host = crm_element_value(input->xml, XML_LRM_ATTR_TARGET); if (find_graph_action_by_id(graph, input->id) == NULL) { do_crm_log(log_level, " * [Input %2d]: Unresolved dependency %s op %s%s%s", input->id, actiontype2text(input->type), key, (host? " on " : ""), (host? host : "")); } } } static void log_synapse_action(unsigned int log_level, pcmk__graph_synapse_t *synapse, pcmk__graph_action_t *action, const char *pending_inputs) { const char *key = crm_element_value(action->xml, XML_LRM_ATTR_TASK_KEY); const char *host = crm_element_value(action->xml, XML_LRM_ATTR_TARGET); char *desc = crm_strdup_printf("%s %s op %s", synapse_state_str(synapse), actiontype2text(action->type), key); do_crm_log(log_level, "[Action %4d]: %-50s%s%s (priority: %d, waiting: %s)", action->id, desc, (host? " on " : ""), (host? host : ""), synapse->priority, pending_inputs); free(desc); } static void log_synapse(unsigned int log_level, pcmk__graph_t *graph, pcmk__graph_synapse_t *synapse) { char *pending = NULL; if (!pcmk_is_set(synapse->flags, pcmk__synapse_executed)) { pending = synapse_pending_inputs(graph, synapse); } for (GList *lpc = synapse->actions; lpc != NULL; lpc = lpc->next) { log_synapse_action(log_level, synapse, (pcmk__graph_action_t *) lpc->data, pending); } free(pending); if (!pcmk_is_set(synapse->flags, pcmk__synapse_executed)) { log_unresolved_inputs(log_level, graph, synapse); } } void pcmk__log_graph_action(int log_level, pcmk__graph_action_t *action) { log_synapse(log_level, NULL, action->synapse); } void pcmk__log_graph(unsigned int log_level, pcmk__graph_t *graph) { if ((graph == NULL) || (graph->num_actions == 0)) { if (log_level == LOG_TRACE) { crm_debug("Empty transition graph"); } return; } do_crm_log(log_level, "Graph %d with %d actions:" " batch-limit=%d jobs, network-delay=%ums", graph->id, graph->num_actions, graph->batch_limit, graph->network_delay); for (GList *lpc = graph->synapses; lpc != NULL; lpc = lpc->next) { log_synapse(log_level, graph, (pcmk__graph_synapse_t *) lpc->data); } }