root/lib/pacemaker/pcmk_setup.c

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

DEFINITIONS

This source file includes following definitions.
  1. pcmk__setup_output_cib_sched
  2. pcmk__setup_output_fencing

   1 /*
   2  * Copyright 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>
  11 #include <crm/cib/internal.h>
  12 #include <crm/common/output.h>
  13 #include <crm/common/results.h>
  14 #include <crm/common/scheduler.h>
  15 #include <crm/fencing/internal.h>
  16 #include <pacemaker-internal.h>
  17 #include <pacemaker.h>
  18 
  19 #include "libpacemaker_private.h"
  20 
  21 /*!
  22  * \internal
  23  * \brief Set up a pcmk__output_t, (optionally) cib_t, and
  24  *        (optionally) pcmk_scheduler_t for use in implementing
  25  *        public/private API function pairs
  26  *
  27  * \param[in,out] out       Where to store a \c pcmk__output_t object
  28  * \param[in,out] cib       Where to store a \c cib_t object
  29  *                          (may be \c NULL if a CIB is not needed)
  30  * \param[in,out] scheduler Where to store a \c pcmk_scheduler_t object
  31  *                          (may be \c NULL if a scheduler is not needed)
  32  * \param[in,out] xml       Where to write any result XML
  33  *
  34  * \note The \p cib and \p scheduler arguments will only be valid if there
  35  *       are no errors in this function.  However, \p out will always be
  36  *       valid unless there are errors setting it up so that other errors
  37  *       may still be reported.
  38  *
  39  * \return Standard Pacemaker return code
  40  */
  41 int
  42 pcmk__setup_output_cib_sched(pcmk__output_t **out, cib_t **cib,
     /* [previous][next][first][last][top][bottom][index][help] */
  43                              pcmk_scheduler_t **scheduler, xmlNode **xml)
  44 {
  45     int rc = pcmk_rc_ok;
  46 
  47     rc = pcmk__xml_output_new(out, xml);
  48     if (rc != pcmk_rc_ok) {
  49         return rc;
  50     }
  51 
  52     if (cib != NULL) {
  53         *cib = cib_new();
  54         if (*cib == NULL) {
  55             return pcmk_rc_cib_corrupt;
  56         }
  57 
  58         rc = (*cib)->cmds->signon(*cib, crm_system_name, cib_command);
  59         rc = pcmk_legacy2rc(rc);
  60 
  61         if (rc != pcmk_rc_ok) {
  62             cib__clean_up_connection(cib);
  63             return rc;
  64         }
  65     }
  66 
  67     if (scheduler != NULL) {
  68         rc = pcmk__init_scheduler(*out, NULL, NULL, scheduler);
  69         if (rc != pcmk_rc_ok && cib != NULL) {
  70             cib__clean_up_connection(cib);
  71             return rc;
  72         }
  73 
  74         pcmk__unpack_constraints(*scheduler);
  75     }
  76 
  77     pcmk__register_lib_messages(*out);
  78     return rc;
  79 }
  80 
  81 /*!
  82  * \internal
  83  * \brief Set up a pcmk__output_t and stonith_t for use in implementing
  84  *        public/private API function pairs
  85  *
  86  * \param[in,out] out       Where to store a \c pcmk__output_t object
  87  * \param[in,out] st        Where to store a \c stonith_t object
  88  * \param[in,out] xml       Where to write any result XML
  89  *
  90  * \note The \p st argument will only be valid if there are no errors in this
  91  *       function.  However, \p out will always be valid unless there are
  92  *       errors setting it up so that other errors may still be reported.
  93  *
  94  * \return Standard Pacemaker return code
  95  */
  96 int
  97 pcmk__setup_output_fencing(pcmk__output_t **out, stonith_t **st, xmlNode **xml)
     /* [previous][next][first][last][top][bottom][index][help] */
  98 {
  99     int rc = pcmk_rc_ok;
 100 
 101     rc = pcmk__xml_output_new(out, xml);
 102     if (rc != pcmk_rc_ok) {
 103         return rc;
 104     }
 105 
 106     *st = stonith_api_new();
 107     if (*st == NULL) {
 108         return ENOMEM;
 109     }
 110 
 111     rc = (*st)->cmds->connect(*st, crm_system_name, NULL);
 112     if (rc < 0) {
 113         rc = pcmk_legacy2rc(rc);
 114         stonith_api_delete(*st);
 115         return rc;
 116     }
 117 
 118     pcmk__register_lib_messages(*out);
 119     stonith__register_messages(*out);
 120     return rc;
 121 }

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