root/lib/pacemaker/pcmk_graph_logging.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. pcmk__graph_status2text
  2. actiontype2text
  3. find_graph_action_by_id
  4. synapse_state_str
  5. synapse_pending_inputs
  6. log_unresolved_inputs
  7. log_synapse_action
  8. log_synapse
  9. pcmk__log_graph_action
  10. pcmk__log_graph

   1 /*
   2  * Copyright 2004-2023 the Pacemaker project contributors
   3  *
   4  * The version control history for this file may have further details.
   5  *
   6  * This source code is licensed under the GNU Lesser General Public License
   7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
   8  */
   9 
  10 #include <crm_internal.h>
  11 
  12 #include <crm/crm.h>
  13 #include <crm/msg_xml.h>
  14 #include <crm/common/xml.h>
  15 #include <pacemaker-internal.h>
  16 
  17 /*!
  18  * \internal
  19  * \brief Return text equivalent of an enum pcmk__graph_status for logging
  20  *
  21  * \param[in] state  Transition status
  22  *
  23  * \return Human-readable text equivalent of \p state
  24  */
  25 const char *
  26 pcmk__graph_status2text(enum pcmk__graph_status state)
     /* [previous][next][first][last][top][bottom][index][help] */
  27 {
  28     switch (state) {
  29         case pcmk__graph_active:
  30             return "active";
  31         case pcmk__graph_pending:
  32             return "pending";
  33         case pcmk__graph_complete:
  34             return "complete";
  35         case pcmk__graph_terminated:
  36             return "terminated";
  37     }
  38     return "unknown";
  39 }
  40 
  41 static const char *
  42 actiontype2text(enum pcmk__graph_action_type type)
     /* [previous][next][first][last][top][bottom][index][help] */
  43 {
  44     switch (type) {
  45         case pcmk__pseudo_graph_action:
  46             return "pseudo";
  47         case pcmk__rsc_graph_action:
  48             return "resource";
  49         case pcmk__cluster_graph_action:
  50             return "cluster";
  51     }
  52     return "invalid";
  53 }
  54 
  55 /*!
  56  * \internal
  57  * \brief Find a transition graph action by ID
  58  *
  59  * \param[in] graph  Transition graph to search
  60  * \param[in] id     Action ID to search for
  61  *
  62  * \return Transition graph action corresponding to \p id, or NULL if none
  63  */
  64 static const pcmk__graph_action_t *
  65 find_graph_action_by_id(const pcmk__graph_t *graph, int id)
     /* [previous][next][first][last][top][bottom][index][help] */
  66 {
  67     if (graph == NULL) {
  68         return NULL;
  69     }
  70 
  71     for (const GList *synapse_iter = graph->synapses;
  72          synapse_iter != NULL; synapse_iter = synapse_iter->next) {
  73 
  74         const pcmk__graph_synapse_t *synapse = synapse_iter->data;
  75 
  76         for (const GList *action_iter = synapse->actions;
  77              action_iter != NULL; action_iter = action_iter->next) {
  78 
  79             const pcmk__graph_action_t *action = action_iter->data;
  80             if (action->id == id) {
  81                 return action;
  82             }
  83         }
  84     }
  85     return NULL;
  86 }
  87 
  88 static const char *
  89 synapse_state_str(pcmk__graph_synapse_t *synapse)
     /* [previous][next][first][last][top][bottom][index][help] */
  90 {
  91     if (pcmk_is_set(synapse->flags, pcmk__synapse_failed)) {
  92         return "Failed";
  93 
  94     } else if (pcmk_is_set(synapse->flags, pcmk__synapse_confirmed)) {
  95         return "Completed";
  96 
  97     } else if (pcmk_is_set(synapse->flags, pcmk__synapse_executed)) {
  98         return "In-flight";
  99 
 100     } else if (pcmk_is_set(synapse->flags, pcmk__synapse_ready)) {
 101         return "Ready";
 102     }
 103     return "Pending";
 104 }
 105 
 106 /*!
 107  * \internal
 108  * \brief List the action IDs of pending inputs to a transition graph synapse
 109  *
 110  * \param[in] graph    Transition graph to which \p synapse belongs
 111  * \param[in] synapse  Synapse whose inputs to check
 112  *
 113  * \return A \p GString containing the space-delimited action IDs of inputs to
 114  *         \p synapse that haven't completed successfully
 115  *
 116  * \note The caller is responsible for freeing the return value using
 117  *       \p g_string_free().
 118  */
 119 static GString *
 120 synapse_pending_inputs(const pcmk__graph_t *graph,
     /* [previous][next][first][last][top][bottom][index][help] */
 121                        const pcmk__graph_synapse_t *synapse)
 122 {
 123     GString *pending = NULL;
 124 
 125     for (const GList *lpc = synapse->inputs; lpc != NULL; lpc = lpc->next) {
 126         const pcmk__graph_action_t *input = (pcmk__graph_action_t *) lpc->data;
 127 
 128         if (pcmk_is_set(input->flags, pcmk__graph_action_failed)) {
 129             pcmk__add_word(&pending, 1024, ID(input->xml));
 130 
 131         } else if (pcmk_is_set(input->flags, pcmk__graph_action_confirmed)) {
 132             // Confirmed successful inputs are not pending
 133 
 134         } else if (find_graph_action_by_id(graph, input->id) != NULL) {
 135             // In-flight or pending
 136             pcmk__add_word(&pending, 1024, ID(input->xml));
 137         }
 138     }
 139     return pending;
 140 }
 141 
 142 // Log synapse inputs that aren't in graph
 143 static void
 144 log_unresolved_inputs(unsigned int log_level, pcmk__graph_t *graph,
     /* [previous][next][first][last][top][bottom][index][help] */
 145                       pcmk__graph_synapse_t *synapse)
 146 {
 147     for (GList *lpc = synapse->inputs; lpc != NULL; lpc = lpc->next) {
 148         pcmk__graph_action_t *input = (pcmk__graph_action_t *) lpc->data;
 149         const char *key = crm_element_value(input->xml, XML_LRM_ATTR_TASK_KEY);
 150         const char *host = crm_element_value(input->xml, XML_LRM_ATTR_TARGET);
 151 
 152         if (find_graph_action_by_id(graph, input->id) == NULL) {
 153             do_crm_log(log_level,
 154                        " * [Input %2d]: Unresolved dependency %s op %s%s%s",
 155                        input->id, actiontype2text(input->type), key,
 156                        (host? " on " : ""), (host? host : ""));
 157         }
 158     }
 159 }
 160 
 161 static void
 162 log_synapse_action(unsigned int log_level, pcmk__graph_synapse_t *synapse,
     /* [previous][next][first][last][top][bottom][index][help] */
 163                    pcmk__graph_action_t *action, const char *pending_inputs)
 164 {
 165     const char *key = crm_element_value(action->xml, XML_LRM_ATTR_TASK_KEY);
 166     const char *host = crm_element_value(action->xml, XML_LRM_ATTR_TARGET);
 167     char *desc = crm_strdup_printf("%s %s op %s",
 168                                    synapse_state_str(synapse),
 169                                    actiontype2text(action->type), key);
 170 
 171     do_crm_log(log_level,
 172                "[Action %4d]: %-50s%s%s (priority: %d, waiting: %s)",
 173                action->id, desc, (host? " on " : ""), (host? host : ""),
 174                synapse->priority, pending_inputs);
 175     free(desc);
 176 }
 177 
 178 static void
 179 log_synapse(unsigned int log_level, pcmk__graph_t *graph,
     /* [previous][next][first][last][top][bottom][index][help] */
 180             pcmk__graph_synapse_t *synapse)
 181 {
 182     GString *g_pending = NULL;
 183     const char *pending = "none";
 184 
 185     if (!pcmk_is_set(synapse->flags, pcmk__synapse_executed)) {
 186         g_pending = synapse_pending_inputs(graph, synapse);
 187 
 188         if (g_pending != NULL) {
 189             pending = (const char *) g_pending->str;
 190         }
 191     }
 192 
 193     for (GList *lpc = synapse->actions; lpc != NULL; lpc = lpc->next) {
 194         log_synapse_action(log_level, synapse,
 195                            (pcmk__graph_action_t *) lpc->data, pending);
 196     }
 197 
 198     if (g_pending != NULL) {
 199         g_string_free(g_pending, TRUE);
 200     }
 201 
 202     if (!pcmk_is_set(synapse->flags, pcmk__synapse_executed)) {
 203         log_unresolved_inputs(log_level, graph, synapse);
 204     }
 205 }
 206 
 207 void
 208 pcmk__log_graph_action(int log_level, pcmk__graph_action_t *action)
     /* [previous][next][first][last][top][bottom][index][help] */
 209 {
 210     log_synapse(log_level, NULL, action->synapse);
 211 }
 212 
 213 void
 214 pcmk__log_graph(unsigned int log_level, pcmk__graph_t *graph)
     /* [previous][next][first][last][top][bottom][index][help] */
 215 {
 216     if ((graph == NULL) || (graph->num_actions == 0)) {
 217         if (log_level == LOG_TRACE) {
 218             crm_debug("Empty transition graph");
 219         }
 220         return;
 221     }
 222 
 223     do_crm_log(log_level, "Graph %d with %d actions:"
 224                " batch-limit=%d jobs, network-delay=%ums",
 225                graph->id, graph->num_actions,
 226                graph->batch_limit, graph->network_delay);
 227 
 228     for (GList *lpc = graph->synapses; lpc != NULL; lpc = lpc->next) {
 229         log_synapse(log_level, graph, (pcmk__graph_synapse_t *) lpc->data);
 230     }
 231 }

/* [previous][next][first][last][top][bottom][index][help] */