root/include/crm/cib/internal.h

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. cib__client_triggers_refresh

   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 #ifndef CIB_INTERNAL__H
  11 #  define CIB_INTERNAL__H
  12 #  include <crm/cib.h>
  13 #  include <crm/common/ipc_internal.h>
  14 #  include <crm/common/output_internal.h>
  15 
  16 // Request types for CIB manager IPC/CPG
  17 #define PCMK__CIB_REQUEST_SECONDARY     "cib_slave"
  18 #define PCMK__CIB_REQUEST_PRIMARY       "cib_master"
  19 #define PCMK__CIB_REQUEST_SYNC_TO_ALL   "cib_sync"
  20 #define PCMK__CIB_REQUEST_SYNC_TO_ONE   "cib_sync_one"
  21 #define PCMK__CIB_REQUEST_IS_PRIMARY    "cib_ismaster"
  22 #define PCMK__CIB_REQUEST_BUMP          "cib_bump"
  23 #define PCMK__CIB_REQUEST_QUERY         "cib_query"
  24 #define PCMK__CIB_REQUEST_CREATE        "cib_create"
  25 #define PCMK__CIB_REQUEST_MODIFY        "cib_modify"
  26 #define PCMK__CIB_REQUEST_DELETE        "cib_delete"
  27 #define PCMK__CIB_REQUEST_ERASE         "cib_erase"
  28 #define PCMK__CIB_REQUEST_REPLACE       "cib_replace"
  29 #define PCMK__CIB_REQUEST_APPLY_PATCH   "cib_apply_diff"
  30 #define PCMK__CIB_REQUEST_UPGRADE       "cib_upgrade"
  31 #define PCMK__CIB_REQUEST_ABS_DELETE    "cib_delete_alt"
  32 #define PCMK__CIB_REQUEST_NOOP          "noop"
  33 #define PCMK__CIB_REQUEST_SHUTDOWN      "cib_shutdown_req"
  34 #define PCMK__CIB_REQUEST_COMMIT_TRANSACT   "cib_commit_transact"
  35 #define PCMK__CIB_REQUEST_SCHEMAS       "cib_schemas"
  36 
  37 /*!
  38  * \internal
  39  * \enum cib__op_attr
  40  * \brief Flags for CIB operation attributes
  41  */
  42 enum cib__op_attr {
  43     cib__op_attr_none           = 0,        //!< No special attributes
  44     cib__op_attr_modifies       = (1 << 1), //!< Modifies CIB
  45     cib__op_attr_privileged     = (1 << 2), //!< Requires privileges
  46     cib__op_attr_local          = (1 << 3), //!< Must only be processed locally
  47     cib__op_attr_replaces       = (1 << 4), //!< Replaces CIB
  48     cib__op_attr_writes_through = (1 << 5), //!< Writes to disk on success
  49     cib__op_attr_transaction    = (1 << 6), //!< Supported in a transaction
  50 };
  51 
  52 /*!
  53  * \internal
  54  * \enum cib__op_type
  55  * \brief Types of CIB operations
  56  */
  57 enum cib__op_type {
  58     cib__op_abs_delete,
  59     cib__op_apply_patch,
  60     cib__op_bump,
  61     cib__op_commit_transact,
  62     cib__op_create,
  63     cib__op_delete,
  64     cib__op_erase,
  65     cib__op_is_primary,
  66     cib__op_modify,
  67     cib__op_noop,
  68     cib__op_ping,
  69     cib__op_primary,
  70     cib__op_query,
  71     cib__op_replace,
  72     cib__op_secondary,
  73     cib__op_shutdown,
  74     cib__op_sync_all,
  75     cib__op_sync_one,
  76     cib__op_upgrade,
  77     cib__op_schemas,
  78 };
  79 
  80 gboolean cib_diff_version_details(xmlNode * diff, int *admin_epoch, int *epoch, int *updates,
  81                                   int *_admin_epoch, int *_epoch, int *_updates);
  82 
  83 gboolean cib_read_config(GHashTable * options, xmlNode * current_cib);
  84 
  85 typedef int (*cib__op_fn_t)(const char *, int, const char *, xmlNode *,
  86                             xmlNode *, xmlNode *, xmlNode **, xmlNode **);
  87 
  88 typedef struct cib__operation_s {
  89     const char *name;
  90     enum cib__op_type type;
  91     uint32_t flags; //!< Group of <tt>enum cib__op_attr</tt> flags
  92 } cib__operation_t;
  93 
  94 typedef struct cib_notify_client_s {
  95     const char *event;
  96     const char *obj_id;         /* implement one day */
  97     const char *obj_type;       /* implement one day */
  98     void (*callback) (const char *event, xmlNode * msg);
  99 
 100 } cib_notify_client_t;
 101 
 102 typedef struct cib_callback_client_s {
 103     void (*callback) (xmlNode *, int, int, xmlNode *, void *);
 104     const char *id;
 105     void *user_data;
 106     gboolean only_success;
 107     struct timer_rec_s *timer;
 108     void (*free_func)(void *);
 109 } cib_callback_client_t;
 110 
 111 struct timer_rec_s {
 112     int call_id;
 113     int timeout;
 114     guint ref;
 115     cib_t *cib;
 116 };
 117 
 118 #define cib__set_call_options(cib_call_opts, call_for, flags_to_set) do {   \
 119         cib_call_opts = pcmk__set_flags_as(__func__, __LINE__,              \
 120             LOG_TRACE, "CIB call", (call_for), (cib_call_opts),             \
 121             (flags_to_set), #flags_to_set); \
 122     } while (0)
 123 
 124 #define cib__clear_call_options(cib_call_opts, call_for, flags_to_clear) do {  \
 125         cib_call_opts = pcmk__clear_flags_as(__func__, __LINE__,               \
 126             LOG_TRACE, "CIB call", (call_for), (cib_call_opts),                \
 127             (flags_to_clear), #flags_to_clear);                                \
 128     } while (0)
 129 
 130 cib_t *cib_new_variant(void);
 131 
 132 /*!
 133  * \internal
 134  * \brief Check whether a given CIB client's update should trigger a refresh
 135  *
 136  * Here, "refresh" means that Pacemaker daemons write out their current state.
 137  *
 138  * If a Pacemaker daemon or one of certain Pacemaker CLI tools modifies the CIB,
 139  * we can assume that the CIB hasn't diverged from the true cluster state. A
 140  * "safe" CLI tool requests that all relevant daemons update their state before
 141  * the tool requests any CIB modifications directly.
 142  *
 143  * In contrast, other "unsafe" tools (for example, \c cibadmin and external
 144  * tools) may request arbitrary CIB changes.
 145  *
 146  * A Pacemaker daemon can write out its current state to the CIB when it's
 147  * notified of an update from an unsafe client, to ensure the CIB still contains
 148  * the daemon's correct state.
 149  *
 150  * \param[in] name  CIB client name
 151  *
 152  * \return \c true if the CIB client should trigger a refresh, or \c false
 153  *         otherwise
 154  */
 155 static inline bool
 156 cib__client_triggers_refresh(const char *name)
     /* [previous][next][first][last][top][bottom][index][help] */
 157 {
 158     return !crm_is_daemon_name(name)
 159            && !pcmk__str_any_of(name,
 160                                 "attrd_updater",
 161                                 "crm_attribute",
 162                                 "crm_node",
 163                                 "crm_resource",
 164                                 "crm_ticket",
 165                                 NULL);
 166 }
 167 
 168 int cib__get_notify_patchset(const xmlNode *msg, const xmlNode **patchset);
 169 
 170 bool cib__element_in_patchset(const xmlNode *patchset, const char *element);
 171 
 172 int cib_perform_op(cib_t *cib, const char *op, uint32_t call_options,
 173                    cib__op_fn_t fn, bool is_query, const char *section,
 174                    xmlNode *req, xmlNode *input, bool manage_counters,
 175                    bool *config_changed, xmlNode **current_cib,
 176                    xmlNode **result_cib, xmlNode **diff, xmlNode **output);
 177 
 178 int cib__create_op(cib_t *cib, const char *op, const char *host,
 179                    const char *section, xmlNode *data, int call_options,
 180                    const char *user_name, const char *client_name,
 181                    xmlNode **op_msg);
 182 
 183 int cib__extend_transaction(cib_t *cib, xmlNode *request);
 184 
 185 void cib_native_callback(cib_t * cib, xmlNode * msg, int call_id, int rc);
 186 void cib_native_notify(gpointer data, gpointer user_data);
 187 
 188 int cib__get_operation(const char *op, const cib__operation_t **operation);
 189 
 190 int cib_process_query(const char *op, int options, const char *section, xmlNode * req,
 191                       xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 192                       xmlNode ** answer);
 193 
 194 int cib_process_erase(const char *op, int options, const char *section, xmlNode * req,
 195                       xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 196                       xmlNode ** answer);
 197 
 198 int cib_process_bump(const char *op, int options, const char *section, xmlNode * req,
 199                      xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 200                      xmlNode ** answer);
 201 
 202 int cib_process_replace(const char *op, int options, const char *section, xmlNode * req,
 203                         xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 204                         xmlNode ** answer);
 205 
 206 int cib_process_create(const char *op, int options, const char *section, xmlNode * req,
 207                        xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 208                        xmlNode ** answer);
 209 
 210 int cib_process_modify(const char *op, int options, const char *section, xmlNode * req,
 211                        xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 212                        xmlNode ** answer);
 213 
 214 int cib_process_delete(const char *op, int options, const char *section, xmlNode * req,
 215                        xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 216                        xmlNode ** answer);
 217 
 218 int cib_process_diff(const char *op, int options, const char *section, xmlNode * req,
 219                      xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 220                      xmlNode ** answer);
 221 
 222 int cib_process_upgrade(const char *op, int options, const char *section, xmlNode * req,
 223                         xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 224                         xmlNode ** answer);
 225 
 226 /*!
 227  * \internal
 228  * \brief Query or modify a CIB
 229  *
 230  * \param[in]     op            PCMK__CIB_REQUEST_* operation to be performed
 231  * \param[in]     options       Flag set of \c cib_call_options
 232  * \param[in]     section       XPath to query or modify
 233  * \param[in]     req           unused
 234  * \param[in]     input         Portion of CIB to modify (used with
 235  *                              PCMK__CIB_REQUEST_CREATE,
 236  *                              PCMK__CIB_REQUEST_MODIFY, and
 237  *                              PCMK__CIB_REQUEST_REPLACE)
 238  * \param[in,out] existing_cib  Input CIB (used with PCMK__CIB_REQUEST_QUERY)
 239  * \param[in,out] result_cib    CIB copy to make changes in (used with
 240  *                              PCMK__CIB_REQUEST_CREATE,
 241  *                              PCMK__CIB_REQUEST_MODIFY,
 242  *                              PCMK__CIB_REQUEST_DELETE, and
 243  *                              PCMK__CIB_REQUEST_REPLACE)
 244  * \param[out]    answer        Query result (used with PCMK__CIB_REQUEST_QUERY)
 245  *
 246  * \return Legacy Pacemaker return code
 247  */
 248 int cib_process_xpath(const char *op, int options, const char *section,
 249                       const xmlNode *req, xmlNode *input, xmlNode *existing_cib,
 250                       xmlNode **result_cib, xmlNode ** answer);
 251 
 252 bool cib__config_changed_v1(xmlNode *last, xmlNode *next, xmlNode **diff);
 253 
 254 int cib_internal_op(cib_t * cib, const char *op, const char *host,
 255                     const char *section, xmlNode * data,
 256                     xmlNode ** output_data, int call_options, const char *user_name);
 257 
 258 
 259 int cib_file_read_and_verify(const char *filename, const char *sigfile,
 260                              xmlNode **root);
 261 int cib_file_write_with_digest(xmlNode *cib_root, const char *cib_dirname,
 262                                const char *cib_filename);
 263 
 264 void cib__set_output(cib_t *cib, pcmk__output_t *out);
 265 
 266 cib_callback_client_t* cib__lookup_id (int call_id);
 267 
 268 /*!
 269  * \internal
 270  * \brief Connect to, query, and optionally disconnect from the CIB
 271  *
 272  * Open a read-write connection to the CIB manager if an already connected
 273  * client is not passed in. Then query the CIB and store the resulting XML.
 274  * Finally, disconnect if the CIB connection isn't being returned to the caller.
 275  *
 276  * \param[in,out] out         Output object (may be \p NULL)
 277  * \param[in,out] cib         If not \p NULL, where to store CIB connection
 278  * \param[out]    cib_object  Where to store query result
 279  *
 280  * \return Standard Pacemaker return code
 281  *
 282  * \note If \p cib is not \p NULL, the caller is responsible for freeing \p *cib
 283  *       using \p cib_delete().
 284  * \note If \p *cib points to an existing \p cib_t object, this function will
 285  *       reuse it instead of creating a new one. If the existing client is
 286  *       already connected, the connection will be reused, even if it's
 287  *       read-only.
 288  */
 289 int cib__signon_query(pcmk__output_t *out, cib_t **cib, xmlNode **cib_object);
 290 
 291 int cib__signon_attempts(cib_t *cib, const char *name, enum cib_conn_type type,
 292                          int attempts);
 293 
 294 int cib__clean_up_connection(cib_t **cib);
 295 
 296 int cib__update_node_attr(pcmk__output_t *out, cib_t *cib, int call_options,
 297                           const char *section, const char *node_uuid, const char *set_type,
 298                           const char *set_name, const char *attr_id, const char *attr_name,
 299                           const char *attr_value, const char *user_name,
 300                           const char *node_type);
 301 
 302 int cib__get_node_attrs(pcmk__output_t *out, cib_t *cib, const char *section,
 303                         const char *node_uuid, const char *set_type, const char *set_name,
 304                         const char *attr_id, const char *attr_name, const char *user_name,
 305                         xmlNode **result);
 306 
 307 int cib__delete_node_attr(pcmk__output_t *out, cib_t *cib, int options,
 308                           const char *section, const char *node_uuid, const char *set_type,
 309                           const char *set_name, const char *attr_id, const char *attr_name,
 310                           const char *attr_value, const char *user_name);
 311 
 312 #endif

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