root/include/crm/common/results.h

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. pcmk_exec_status_str

   1 /*
   2  * Copyright 2012-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 #ifndef PCMK__CRM_COMMON_RESULTS__H
  10 #define PCMK__CRM_COMMON_RESULTS__H
  11 
  12 #ifdef __cplusplus
  13 extern "C" {
  14 #endif
  15 
  16 /*!
  17  * \file
  18  * \brief Function and executable result codes
  19  * \ingroup core
  20  */
  21 
  22 // Lifted from config.h
  23 /* The _Noreturn keyword of C11.  */
  24 #ifndef _Noreturn
  25 # if (defined __cplusplus \
  26       && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \
  27           || (defined _MSC_VER && 1900 <= _MSC_VER)))
  28 #  define _Noreturn [[noreturn]]
  29 # elif ((!defined __cplusplus || defined __clang__) \
  30         && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0)  \
  31             || 4 < __GNUC__ + (7 <= __GNUC_MINOR__)))
  32    /* _Noreturn works as-is.  */
  33 # elif 2 < __GNUC__ + (8 <= __GNUC_MINOR__) || 0x5110 <= __SUNPRO_C
  34 #  define _Noreturn __attribute__ ((__noreturn__))
  35 # elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0)
  36 #  define _Noreturn __declspec (noreturn)
  37 # else
  38 #  define _Noreturn
  39 # endif
  40 #endif
  41 
  42 #define CRM_ASSERT(expr) do {                                                \
  43         if (!(expr)) {                                                       \
  44             crm_abort(__FILE__, __func__, __LINE__, #expr, TRUE, FALSE);     \
  45         }                                                                    \
  46     } while(0)
  47 
  48 /*
  49  * Function return codes
  50  *
  51  * Most Pacemaker API functions return an integer return code. There are two
  52  * alternative interpretations. The legacy interpration is that the absolute
  53  * value of the return code is either a system error number or a custom
  54  * pcmk_err_* number. This is less than ideal because system error numbers are
  55  * constrained only to the positive int range, so there's the possibility that
  56  * system errors and custom errors could collide (which did in fact happen
  57  * already on one architecture). The new intepretation is that negative values
  58  * are from the pcmk_rc_e enum, and positive values are system error numbers.
  59  * Both use 0 for success.
  60  *
  61  * For system error codes, see:
  62  * - /usr/include/asm-generic/errno.h
  63  * - /usr/include/asm-generic/errno-base.h
  64  */
  65 
  66 // Legacy custom return codes for Pacemaker API functions (deprecated)
  67 
  68 // NOTE: sbd (as of at least 1.5.2) uses this
  69 #define pcmk_ok                       0
  70 
  71 #define PCMK_ERROR_OFFSET             190    /* Replacements on non-linux systems, see include/portability.h */
  72 #define PCMK_CUSTOM_OFFSET            200    /* Purely custom codes */
  73 #define pcmk_err_generic              201
  74 #define pcmk_err_no_quorum            202
  75 #define pcmk_err_schema_validation    203
  76 #define pcmk_err_transform_failed     204
  77 #define pcmk_err_old_data             205
  78 
  79 // NOTE: sbd (as of at least 1.5.2) uses this
  80 #define pcmk_err_diff_failed          206
  81 
  82 // NOTE: sbd (as of at least 1.5.2) uses this
  83 #define pcmk_err_diff_resync          207
  84 
  85 #define pcmk_err_cib_modified         208
  86 #define pcmk_err_cib_backup           209
  87 #define pcmk_err_cib_save             210
  88 #define pcmk_err_schema_unchanged     211
  89 #define pcmk_err_cib_corrupt          212
  90 #define pcmk_err_multiple             213
  91 #define pcmk_err_node_unknown         214
  92 #define pcmk_err_already              215
  93 /* On HPPA 215 is ENOSYM (Unknown error 215), which hopefully never happens. */
  94 #ifdef __hppa__
  95 #define pcmk_err_bad_nvpair           250 /* 216 is ENOTSOCK */
  96 #define pcmk_err_unknown_format       252 /* 217 is EDESTADDRREQ */
  97 #else
  98 #define pcmk_err_bad_nvpair           216
  99 #define pcmk_err_unknown_format       217
 100 #endif
 101 
 102 /*!
 103  * \enum pcmk_rc_e
 104  * \brief Return codes for Pacemaker API functions
 105  *
 106  * Any Pacemaker API function documented as returning a "standard Pacemaker
 107  * return code" will return pcmk_rc_ok (0) on success, and one of this
 108  * enumeration's other (negative) values or a (positive) system error number
 109  * otherwise. The custom codes are at -1001 and lower, so that the caller may
 110  * use -1 through -1000 for their own custom values if desired. While generally
 111  * referred to as "errors", nonzero values simply indicate a result, which might
 112  * or might not be an error depending on the calling context.
 113  */
 114 enum pcmk_rc_e {
 115     /* When adding new values, use consecutively lower numbers, update the array
 116      * in lib/common/results.c, and test with crm_error.
 117      */
 118     pcmk_rc_compression         = -1039,
 119     pcmk_rc_ns_resolution       = -1038,
 120     pcmk_rc_no_transaction      = -1037,
 121     pcmk_rc_bad_xml_patch       = -1036,
 122     pcmk_rc_bad_input           = -1035,
 123     pcmk_rc_disabled            = -1034,
 124     pcmk_rc_duplicate_id        = -1033,
 125     pcmk_rc_unpack_error        = -1032,
 126     pcmk_rc_invalid_transition  = -1031,
 127     pcmk_rc_graph_error         = -1030,
 128     pcmk_rc_dot_error           = -1029,
 129     pcmk_rc_underflow           = -1028,
 130     pcmk_rc_no_input            = -1027,
 131     pcmk_rc_no_output           = -1026,
 132     pcmk_rc_after_range         = -1025,
 133     pcmk_rc_within_range        = -1024,
 134     pcmk_rc_before_range        = -1023,
 135     pcmk_rc_undetermined        = -1022,
 136     pcmk_rc_op_unsatisfied      = -1021,
 137     pcmk_rc_ipc_pid_only        = -1020,
 138     pcmk_rc_ipc_unresponsive    = -1019,
 139     pcmk_rc_ipc_unauthorized    = -1018,
 140     pcmk_rc_no_quorum           = -1017,
 141     pcmk_rc_schema_validation   = -1016,
 142     pcmk_rc_schema_unchanged    = -1015,
 143     pcmk_rc_transform_failed    = -1014,
 144     pcmk_rc_old_data            = -1013,
 145     pcmk_rc_diff_failed         = -1012,
 146     pcmk_rc_diff_resync         = -1011,
 147     pcmk_rc_cib_modified        = -1010,
 148     pcmk_rc_cib_backup          = -1009,
 149     pcmk_rc_cib_save            = -1008,
 150     pcmk_rc_cib_corrupt         = -1007,
 151     pcmk_rc_multiple            = -1006,
 152     pcmk_rc_node_unknown        = -1005,
 153     pcmk_rc_already             = -1004,
 154     pcmk_rc_bad_nvpair          = -1003,
 155     pcmk_rc_unknown_format      = -1002,
 156     // Developers: Use a more specific code than pcmk_rc_error whenever possible
 157     pcmk_rc_error               = -1001,
 158 
 159     // Values -1 through -1000 reserved for caller use
 160 
 161     // NOTE: sbd (as of at least 1.5.2) uses this
 162     pcmk_rc_ok                  =     0
 163 
 164     // Positive values reserved for system error numbers
 165 };
 166 
 167 
 168 /*!
 169  * \enum ocf_exitcode
 170  * \brief Exit status codes for resource agents
 171  *
 172  * The OCF Resource Agent API standard enumerates the possible exit status codes
 173  * that agents should return. Besides being used with OCF agents, these values
 174  * are also used by the executor as a universal status for all agent standards;
 175  * actual results are mapped to these before returning them to clients.
 176  */
 177 enum ocf_exitcode {
 178     PCMK_OCF_OK                   = 0,   //!< Success
 179 
 180     // NOTE: booth (as of at least 1.1) uses this value
 181     PCMK_OCF_UNKNOWN_ERROR        = 1,   //!< Unspecified error
 182 
 183     PCMK_OCF_INVALID_PARAM        = 2,   //!< Parameter invalid (in local context)
 184     PCMK_OCF_UNIMPLEMENT_FEATURE  = 3,   //!< Requested action not implemented
 185     PCMK_OCF_INSUFFICIENT_PRIV    = 4,   //!< Insufficient privileges
 186     PCMK_OCF_NOT_INSTALLED        = 5,   //!< Dependencies not available locally
 187     PCMK_OCF_NOT_CONFIGURED       = 6,   //!< Parameter invalid (inherently)
 188 
 189     // NOTE: booth (as of at least 1.1) uses this value
 190     PCMK_OCF_NOT_RUNNING          = 7,   //!< Service safely stopped
 191 
 192     PCMK_OCF_RUNNING_PROMOTED     = 8,   //!< Service active and promoted
 193     PCMK_OCF_FAILED_PROMOTED      = 9,   //!< Service failed and possibly in promoted role
 194     PCMK_OCF_DEGRADED             = 190, //!< Service active but more likely to fail soon
 195     PCMK_OCF_DEGRADED_PROMOTED    = 191, //!< Service promoted but more likely to fail soon
 196 
 197     /* These two are Pacemaker extensions, not in the OCF standard. The
 198      * controller records PCMK_OCF_UNKNOWN for pending actions.
 199      * PCMK_OCF_CONNECTION_DIED is used only with older DCs that don't support
 200      * PCMK_EXEC_NOT_CONNECTED.
 201      */
 202     PCMK_OCF_CONNECTION_DIED      = 189, //!< \deprecated See PCMK_EXEC_NOT_CONNECTED
 203     PCMK_OCF_UNKNOWN              = 193, //!< Action is pending
 204 
 205 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
 206     // Former Pacemaker extensions
 207     PCMK_OCF_EXEC_ERROR           = 192, //!< \deprecated (Unused)
 208     PCMK_OCF_SIGNAL               = 194, //!< \deprecated (Unused)
 209     PCMK_OCF_NOT_SUPPORTED        = 195, //!< \deprecated (Unused)
 210     PCMK_OCF_PENDING              = 196, //!< \deprecated (Unused)
 211     PCMK_OCF_CANCELLED            = 197, //!< \deprecated (Unused)
 212     PCMK_OCF_TIMEOUT              = 198, //!< \deprecated (Unused)
 213     PCMK_OCF_OTHER_ERROR          = 199, //!< \deprecated (Unused)
 214 
 215     //! \deprecated Use PCMK_OCF_RUNNING_PROMOTED instead
 216     PCMK_OCF_RUNNING_MASTER     = PCMK_OCF_RUNNING_PROMOTED,
 217 
 218     //! \deprecated Use PCMK_OCF_FAILED_PROMOTED instead
 219     PCMK_OCF_FAILED_MASTER      = PCMK_OCF_FAILED_PROMOTED,
 220 
 221     //! \deprecated Use PCMK_OCF_DEGRADED_PROMOTED instead
 222     PCMK_OCF_DEGRADED_MASTER    = PCMK_OCF_DEGRADED_PROMOTED,
 223 #endif
 224 };
 225 
 226 // NOTE: sbd (as of at least 1.5.2) uses this
 227 /*!
 228  * \enum crm_exit_e
 229  * \brief Exit status codes for tools and daemons
 230  *
 231  * We want well-specified (i.e. OS-invariant) exit status codes for our daemons
 232  * and applications so they can be relied on by callers. (Function return codes
 233  * and errno's do not make good exit statuses.)
 234  *
 235  * The only hard rule is that exit statuses must be between 0 and 255; all else
 236  * is convention. Universally, 0 is success, and 1 is generic error (excluding
 237  * OSes we don't support -- for example, OpenVMS considers 1 success!).
 238  *
 239  * For init scripts, the LSB gives meaning to 0-7, and sets aside 150-199 for
 240  * application use. OCF adds 8-9 and 190-191.
 241  *
 242  * sysexits.h was an attempt to give additional meanings, but never really
 243  * caught on. It uses 0 and 64-78.
 244  *
 245  * Bash reserves 2 ("incorrect builtin usage") and 126-255 (126 is "command
 246  * found but not executable", 127 is "command not found", 128 + n is
 247  * "interrupted by signal n").
 248  *
 249  * tldp.org recommends 64-113 for application use.
 250  *
 251  * We try to overlap with the above conventions when practical.
 252  */
 253 typedef enum crm_exit_e {
 254     // Common convention
 255     CRM_EX_OK                   =   0, //!< Success
 256     CRM_EX_ERROR                =   1, //!< Unspecified error
 257 
 258     // LSB + OCF
 259     CRM_EX_INVALID_PARAM        =   2, //!< Parameter invalid (in local context)
 260     CRM_EX_UNIMPLEMENT_FEATURE  =   3, //!< Requested action not implemented
 261     CRM_EX_INSUFFICIENT_PRIV    =   4, //!< Insufficient privileges
 262     CRM_EX_NOT_INSTALLED        =   5, //!< Dependencies not available locally
 263     CRM_EX_NOT_CONFIGURED       =   6, //!< Parameter invalid (inherently)
 264     CRM_EX_NOT_RUNNING          =   7, //!< Service safely stopped
 265     CRM_EX_PROMOTED             =   8, //!< Service active and promoted
 266     CRM_EX_FAILED_PROMOTED      =   9, //!< Service failed and possibly promoted
 267 
 268     // sysexits.h
 269     CRM_EX_USAGE                =  64, //!< Command line usage error
 270     CRM_EX_DATAERR              =  65, //!< User-supplied data incorrect
 271     CRM_EX_NOINPUT              =  66, //!< Input file not available
 272     CRM_EX_NOUSER               =  67, //!< User does not exist
 273     CRM_EX_NOHOST               =  68, //!< Host unknown
 274     CRM_EX_UNAVAILABLE          =  69, //!< Needed service unavailable
 275     CRM_EX_SOFTWARE             =  70, //!< Internal software bug
 276     CRM_EX_OSERR                =  71, //!< External (OS/environmental) problem
 277     CRM_EX_OSFILE               =  72, //!< System file not usable
 278     CRM_EX_CANTCREAT            =  73, //!< File couldn't be created
 279     CRM_EX_IOERR                =  74, //!< File I/O error
 280     CRM_EX_TEMPFAIL             =  75, //!< Try again
 281     CRM_EX_PROTOCOL             =  76, //!< Protocol violated
 282     CRM_EX_NOPERM               =  77, //!< Non-file permission issue
 283     CRM_EX_CONFIG               =  78, //!< Misconfiguration
 284 
 285     // Custom
 286     CRM_EX_FATAL                = 100, //!< Do not respawn
 287     CRM_EX_PANIC                = 101, //!< Panic the local host
 288     CRM_EX_DISCONNECT           = 102, //!< Lost connection to something
 289     CRM_EX_OLD                  = 103, //!< Update older than existing config
 290     CRM_EX_DIGEST               = 104, //!< Digest comparison failed
 291     CRM_EX_NOSUCH               = 105, //!< Requested item does not exist
 292     CRM_EX_QUORUM               = 106, //!< Local partition does not have quorum
 293     CRM_EX_UNSAFE               = 107, //!< Requires --force or new conditions
 294     CRM_EX_EXISTS               = 108, //!< Requested item already exists
 295     CRM_EX_MULTIPLE             = 109, //!< Requested item has multiple matches
 296     CRM_EX_EXPIRED              = 110, //!< Requested item has expired
 297     CRM_EX_NOT_YET_IN_EFFECT    = 111, //!< Requested item is not in effect
 298     CRM_EX_INDETERMINATE        = 112, //!< Could not determine status
 299     CRM_EX_UNSATISFIED          = 113, //!< Requested item does not satisfy constraints
 300 
 301     // Other
 302     CRM_EX_TIMEOUT              = 124, //!< Convention from timeout(1)
 303 
 304     /* Anything above 128 overlaps with some shells' use of these values for
 305      * "interrupted by signal N", and so may be unreliable when detected by
 306      * shell scripts.
 307      */
 308 
 309     // OCF Resource Agent API 1.1
 310     CRM_EX_DEGRADED             = 190, //!< Service active but more likely to fail soon
 311     CRM_EX_DEGRADED_PROMOTED    = 191, //!< Service promoted but more likely to fail soon
 312 
 313     /* Custom
 314      *
 315      * This can be used to initialize exit status variables or to indicate that
 316      * a command is pending (which is what the controller uses it for).
 317      */
 318     CRM_EX_NONE                 = 193, //!< No exit status available
 319 
 320     CRM_EX_MAX                  = 255, //!< Ensure crm_exit_t can hold this
 321 } crm_exit_t;
 322 
 323 /*!
 324  * \enum pcmk_exec_status
 325  * \brief Execution status
 326  *
 327  * These codes are used to specify the result of the attempt to execute an
 328  * agent, rather than the agent's result itself.
 329  */
 330 enum pcmk_exec_status {
 331     PCMK_EXEC_UNKNOWN = -2,     //!< Used only to initialize variables
 332     PCMK_EXEC_PENDING = -1,     //!< Action is in progress
 333     PCMK_EXEC_DONE,             //!< Action completed, result is known
 334     PCMK_EXEC_CANCELLED,        //!< Action was cancelled
 335     PCMK_EXEC_TIMEOUT,          //!< Action did not complete in time
 336     PCMK_EXEC_NOT_SUPPORTED,    //!< Agent does not implement requested action
 337     PCMK_EXEC_ERROR,            //!< Execution failed, may be retried
 338     PCMK_EXEC_ERROR_HARD,       //!< Execution failed, do not retry on node
 339     PCMK_EXEC_ERROR_FATAL,      //!< Execution failed, do not retry anywhere
 340     PCMK_EXEC_NOT_INSTALLED,    //!< Agent or dependency not available locally
 341     PCMK_EXEC_NOT_CONNECTED,    //!< No connection to executor
 342     PCMK_EXEC_INVALID,          //!< Action cannot be attempted (e.g. shutdown)
 343     PCMK_EXEC_NO_FENCE_DEVICE,  //!< No fence device is configured for target
 344     PCMK_EXEC_NO_SECRETS,       //!< Necessary CIB secrets are unavailable
 345 
 346     // Add new values above here then update this one below
 347     PCMK_EXEC_MAX = PCMK_EXEC_NO_SECRETS, //!< Maximum value for this enum
 348 };
 349 
 350 /*!
 351  * \enum pcmk_result_type
 352  * \brief Types of Pacemaker result codes
 353  *
 354  * A particular integer can have different meanings within different Pacemaker
 355  * result code families. It may be interpretable within zero, one, or multiple
 356  * families.
 357  *
 358  * These values are useful for specifying how an integer result code should be
 359  * interpreted in situations involving a generic integer value. For example, a
 360  * function that can process multiple types of result codes might accept an
 361  * arbitrary integer argument along with a \p pcmk_result_type argument that
 362  * specifies how to interpret the integer.
 363  */
 364 enum pcmk_result_type {
 365     pcmk_result_legacy      = 0,  //!< Legacy API function return code
 366     pcmk_result_rc          = 1,  //!< Standard Pacemaker return code
 367     pcmk_result_exitcode    = 2,  //!< Exit status code
 368     pcmk_result_exec_status = 3,  //!< Execution status
 369 };
 370 
 371 int pcmk_result_get_strings(int code, enum pcmk_result_type type,
 372                             const char **name, const char **desc);
 373 const char *pcmk_rc_name(int rc);
 374 
 375 // NOTE: sbd (as of at least 1.5.2) uses this
 376 const char *pcmk_rc_str(int rc);
 377 
 378 crm_exit_t pcmk_rc2exitc(int rc);
 379 enum ocf_exitcode pcmk_rc2ocf(int rc);
 380 int pcmk_rc2legacy(int rc);
 381 int pcmk_legacy2rc(int legacy_rc);
 382 
 383 // NOTE: sbd (as of at least 1.5.2) uses this
 384 const char *pcmk_strerror(int rc);
 385 
 386 const char *pcmk_errorname(int rc);
 387 const char *crm_exit_name(crm_exit_t exit_code);
 388 
 389 // NOTE: sbd (as of at least 1.5.2) uses this
 390 const char *crm_exit_str(crm_exit_t exit_code);
 391 
 392 _Noreturn crm_exit_t crm_exit(crm_exit_t rc);
 393 
 394 static inline const char *
 395 pcmk_exec_status_str(enum pcmk_exec_status status)
     /* [previous][next][first][last][top][bottom][index][help] */
 396 {
 397     switch (status) {
 398         case PCMK_EXEC_PENDING:         return "pending";
 399         case PCMK_EXEC_DONE:            return "complete";
 400         case PCMK_EXEC_CANCELLED:       return "Cancelled";
 401         case PCMK_EXEC_TIMEOUT:         return "Timed Out";
 402         case PCMK_EXEC_NOT_SUPPORTED:   return "NOT SUPPORTED";
 403         case PCMK_EXEC_ERROR:           return "Error";
 404         case PCMK_EXEC_ERROR_HARD:      return "Hard error";
 405         case PCMK_EXEC_ERROR_FATAL:     return "Fatal error";
 406         case PCMK_EXEC_NOT_INSTALLED:   return "Not installed";
 407         case PCMK_EXEC_NOT_CONNECTED:   return "Internal communication failure";
 408         case PCMK_EXEC_INVALID:         return "Cannot execute now";
 409         case PCMK_EXEC_NO_FENCE_DEVICE: return "No fence device";
 410         case PCMK_EXEC_NO_SECRETS:      return "CIB secrets unavailable";
 411         default:                        return "UNKNOWN!";
 412     }
 413 }
 414 
 415 #ifdef __cplusplus
 416 }
 417 #endif
 418 
 419 #endif

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