root/lib/common/probes.c

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

DEFINITIONS

This source file includes following definitions.
  1. pcmk_is_probe
  2. pcmk_xe_is_probe
  3. pcmk_xe_mask_probe_failure

   1 /*
   2  * Copyright 2004-2024 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>           // pcmk__str_eq(), etc.
  11 
  12 #include <stdio.h>                  // NULL
  13 #include <stdbool.h>                // bool, true, false
  14 #include <glib.h>                   // guint
  15 #include <libxml/tree.h>            // xmlNode
  16 
  17 #include <crm/common/options.h>     // PCMK_META_INTERVAL
  18 #include <crm/common/xml.h>         // PCMK_XA_OPERATION
  19 
  20 /*!
  21  * \brief Check whether an action name and interval represent a probe
  22  *
  23  * \param[in] task         Action name
  24  * \param[in] interval_ms  Action interval in milliseconds
  25  *
  26  * \return true if \p task is \c PCMK_ACTION_MONITOR and \p interval_ms is 0,
  27  *         otherwise false
  28  */
  29 bool
  30 pcmk_is_probe(const char *task, guint interval_ms)
     /* [previous][next][first][last][top][bottom][index][help] */
  31 {
  32     // @COMPAT This should be made inline at an API compatibility break
  33     return (interval_ms == 0)
  34            && pcmk__str_eq(task, PCMK_ACTION_MONITOR, pcmk__str_none);
  35 }
  36 
  37 /*!
  38  * \brief Check whether an action history entry represents a probe
  39  *
  40  * \param[in] xml  XML of action history entry
  41  *
  42  * \return true if \p xml is for a probe action, otherwise false
  43  */
  44 bool
  45 pcmk_xe_is_probe(const xmlNode *xml)
     /* [previous][next][first][last][top][bottom][index][help] */
  46 {
  47     int interval_ms = 0;
  48 
  49     if (xml == NULL) {
  50         return false;
  51     }
  52 
  53     pcmk__scan_min_int(crm_element_value(xml, PCMK_META_INTERVAL),
  54                        &interval_ms, 0);
  55 
  56     return pcmk_is_probe(crm_element_value(xml, PCMK_XA_OPERATION),
  57                          interval_ms);
  58 }
  59 
  60 /*!
  61  * \brief Check whether an action history entry represents a maskable probe
  62  *
  63  * \param[in] xml  XML of action history entry
  64  *
  65  * \return true if \p xml is for a failed probe action that should be treated as
  66  *         successful, otherwise false
  67  */
  68 bool
  69 pcmk_xe_mask_probe_failure(const xmlNode *xml)
     /* [previous][next][first][last][top][bottom][index][help] */
  70 {
  71     int exec_status = PCMK_EXEC_UNKNOWN;
  72     int exit_status = PCMK_OCF_OK;
  73 
  74     if (!pcmk_xe_is_probe(xml)) {
  75         return false;
  76     }
  77 
  78     crm_element_value_int(xml, PCMK__XA_OP_STATUS, &exec_status);
  79     crm_element_value_int(xml, PCMK__XA_RC_CODE, &exit_status);
  80 
  81     return (exit_status == PCMK_OCF_NOT_INSTALLED)
  82            || (exit_status == PCMK_OCF_INVALID_PARAM)
  83            || (exec_status == PCMK_EXEC_NOT_INSTALLED);
  84 }

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