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-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 #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 
  36 #  define F_CIB_CLIENTID  "cib_clientid"
  37 #  define F_CIB_CALLOPTS  "cib_callopt"
  38 #  define F_CIB_CALLID    "cib_callid"
  39 #  define F_CIB_CALLDATA  "cib_calldata"
  40 #  define F_CIB_OPERATION "cib_op"
  41 #  define F_CIB_ISREPLY   "cib_isreplyto"
  42 #  define F_CIB_SECTION   "cib_section"
  43 #  define F_CIB_HOST    "cib_host"
  44 #  define F_CIB_RC      "cib_rc"
  45 #  define F_CIB_UPGRADE_RC      "cib_upgrade_rc"
  46 #  define F_CIB_DELEGATED       "cib_delegated_from"
  47 #  define F_CIB_OBJID   "cib_object"
  48 #  define F_CIB_OBJTYPE "cib_object_type"
  49 #  define F_CIB_EXISTING        "cib_existing_object"
  50 #  define F_CIB_SEENCOUNT       "cib_seen"
  51 #  define F_CIB_TIMEOUT "cib_timeout"
  52 #  define F_CIB_UPDATE  "cib_update"
  53 #  define F_CIB_GLOBAL_UPDATE   "cib_update"
  54 #  define F_CIB_UPDATE_RESULT   "cib_update_result"
  55 #  define F_CIB_CLIENTNAME      "cib_clientname"
  56 #  define F_CIB_NOTIFY_TYPE     "cib_notify_type"
  57 #  define F_CIB_NOTIFY_ACTIVATE "cib_notify_activate"
  58 #  define F_CIB_UPDATE_DIFF     "cib_update_diff"
  59 #  define F_CIB_USER            "cib_user"
  60 #  define F_CIB_LOCAL_NOTIFY_ID "cib_local_notify_id"
  61 #  define F_CIB_PING_ID         "cib_ping_id"
  62 #  define F_CIB_SCHEMA_MAX      "cib_schema_max"
  63 
  64 #  define T_CIB                 "cib"
  65 #  define T_CIB_COMMAND         "cib_command"
  66 #  define T_CIB_NOTIFY          "cib_notify"
  67 /* notify sub-types */
  68 #  define T_CIB_PRE_NOTIFY      "cib_pre_notify"
  69 #  define T_CIB_POST_NOTIFY     "cib_post_notify"
  70 #  define T_CIB_TRANSACTION     "cib_transaction"
  71 #  define T_CIB_UPDATE_CONFIRM  "cib_update_confirmation"
  72 
  73 /*!
  74  * \internal
  75  * \enum cib__op_attr
  76  * \brief Flags for CIB operation attributes
  77  */
  78 enum cib__op_attr {
  79     cib__op_attr_none           = 0,        //!< No special attributes
  80     cib__op_attr_modifies       = (1 << 1), //!< Modifies CIB
  81     cib__op_attr_privileged     = (1 << 2), //!< Requires privileges
  82     cib__op_attr_local          = (1 << 3), //!< Must only be processed locally
  83     cib__op_attr_replaces       = (1 << 4), //!< Replaces CIB
  84     cib__op_attr_writes_through = (1 << 5), //!< Writes to disk on success
  85     cib__op_attr_transaction    = (1 << 6), //!< Supported in a transaction
  86 };
  87 
  88 /*!
  89  * \internal
  90  * \enum cib__op_type
  91  * \brief Types of CIB operations
  92  */
  93 enum cib__op_type {
  94     cib__op_abs_delete,
  95     cib__op_apply_patch,
  96     cib__op_bump,
  97     cib__op_commit_transact,
  98     cib__op_create,
  99     cib__op_delete,
 100     cib__op_erase,
 101     cib__op_is_primary,
 102     cib__op_modify,
 103     cib__op_noop,
 104     cib__op_ping,
 105     cib__op_primary,
 106     cib__op_query,
 107     cib__op_replace,
 108     cib__op_secondary,
 109     cib__op_shutdown,
 110     cib__op_sync_all,
 111     cib__op_sync_one,
 112     cib__op_upgrade,
 113 };
 114 
 115 gboolean cib_diff_version_details(xmlNode * diff, int *admin_epoch, int *epoch, int *updates,
 116                                   int *_admin_epoch, int *_epoch, int *_updates);
 117 
 118 gboolean cib_read_config(GHashTable * options, xmlNode * current_cib);
 119 
 120 typedef int (*cib__op_fn_t)(const char *, int, const char *, xmlNode *,
 121                             xmlNode *, xmlNode *, xmlNode **, xmlNode **);
 122 
 123 typedef struct cib__operation_s {
 124     const char *name;
 125     enum cib__op_type type;
 126     uint32_t flags; //!< Group of <tt>enum cib__op_attr</tt> flags
 127 } cib__operation_t;
 128 
 129 typedef struct cib_notify_client_s {
 130     const char *event;
 131     const char *obj_id;         /* implement one day */
 132     const char *obj_type;       /* implement one day */
 133     void (*callback) (const char *event, xmlNode * msg);
 134 
 135 } cib_notify_client_t;
 136 
 137 typedef struct cib_callback_client_s {
 138     void (*callback) (xmlNode *, int, int, xmlNode *, void *);
 139     const char *id;
 140     void *user_data;
 141     gboolean only_success;
 142     struct timer_rec_s *timer;
 143     void (*free_func)(void *);
 144 } cib_callback_client_t;
 145 
 146 struct timer_rec_s {
 147     int call_id;
 148     int timeout;
 149     guint ref;
 150     cib_t *cib;
 151 };
 152 
 153 #define cib__set_call_options(cib_call_opts, call_for, flags_to_set) do {   \
 154         cib_call_opts = pcmk__set_flags_as(__func__, __LINE__,              \
 155             LOG_TRACE, "CIB call", (call_for), (cib_call_opts),             \
 156             (flags_to_set), #flags_to_set); \
 157     } while (0)
 158 
 159 #define cib__clear_call_options(cib_call_opts, call_for, flags_to_clear) do {  \
 160         cib_call_opts = pcmk__clear_flags_as(__func__, __LINE__,               \
 161             LOG_TRACE, "CIB call", (call_for), (cib_call_opts),                \
 162             (flags_to_clear), #flags_to_clear);                                \
 163     } while (0)
 164 
 165 cib_t *cib_new_variant(void);
 166 
 167 /*!
 168  * \internal
 169  * \brief Check whether a given CIB client's update should trigger a refresh
 170  *
 171  * Here, "refresh" means that Pacemaker daemons write out their current state.
 172  *
 173  * If a Pacemaker daemon or one of certain Pacemaker CLI tools modifies the CIB,
 174  * we can assume that the CIB hasn't diverged from the true cluster state. A
 175  * "safe" CLI tool requests that all relevant daemons update their state before
 176  * the tool requests any CIB modifications directly.
 177  *
 178  * In contrast, other "unsafe" tools (for example, \c cibadmin and external
 179  * tools) may request arbitrary CIB changes.
 180  *
 181  * A Pacemaker daemon can write out its current state to the CIB when it's
 182  * notified of an update from an unsafe client, to ensure the CIB still contains
 183  * the daemon's correct state.
 184  *
 185  * \param[in] name  CIB client name
 186  *
 187  * \return \c true if the CIB client should trigger a refresh, or \c false
 188  *         otherwise
 189  */
 190 static inline bool
 191 cib__client_triggers_refresh(const char *name)
     /* [previous][next][first][last][top][bottom][index][help] */
 192 {
 193     return !crm_is_daemon_name(name)
 194            && !pcmk__str_any_of(name,
 195                                 "attrd_updater",
 196                                 "crm_attribute",
 197                                 "crm_node",
 198                                 "crm_resource",
 199                                 "crm_ticket",
 200                                 NULL);
 201 }
 202 
 203 int cib__get_notify_patchset(const xmlNode *msg, const xmlNode **patchset);
 204 
 205 bool cib__element_in_patchset(const xmlNode *patchset, const char *element);
 206 
 207 int cib_perform_op(const char *op, int call_options, cib__op_fn_t fn,
 208                    bool is_query, const char *section, xmlNode *req,
 209                    xmlNode *input, bool manage_counters, bool *config_changed,
 210                    xmlNode **current_cib, xmlNode **result_cib, xmlNode **diff,
 211                    xmlNode **output);
 212 
 213 int cib__create_op(cib_t *cib, const char *op, const char *host,
 214                    const char *section, xmlNode *data, int call_options,
 215                    const char *user_name, const char *client_name,
 216                    xmlNode **op_msg);
 217 
 218 int cib__extend_transaction(cib_t *cib, xmlNode *request);
 219 
 220 void cib_native_callback(cib_t * cib, xmlNode * msg, int call_id, int rc);
 221 void cib_native_notify(gpointer data, gpointer user_data);
 222 
 223 int cib__get_operation(const char *op, const cib__operation_t **operation);
 224 
 225 int cib_process_query(const char *op, int options, const char *section, xmlNode * req,
 226                       xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 227                       xmlNode ** answer);
 228 
 229 int cib_process_erase(const char *op, int options, const char *section, xmlNode * req,
 230                       xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 231                       xmlNode ** answer);
 232 
 233 int cib_process_bump(const char *op, int options, const char *section, xmlNode * req,
 234                      xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 235                      xmlNode ** answer);
 236 
 237 int cib_process_replace(const char *op, int options, const char *section, xmlNode * req,
 238                         xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 239                         xmlNode ** answer);
 240 
 241 int cib_process_create(const char *op, int options, const char *section, xmlNode * req,
 242                        xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 243                        xmlNode ** answer);
 244 
 245 int cib_process_modify(const char *op, int options, const char *section, xmlNode * req,
 246                        xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 247                        xmlNode ** answer);
 248 
 249 int cib_process_delete(const char *op, int options, const char *section, xmlNode * req,
 250                        xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 251                        xmlNode ** answer);
 252 
 253 int cib_process_diff(const char *op, int options, const char *section, xmlNode * req,
 254                      xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 255                      xmlNode ** answer);
 256 
 257 int cib_process_upgrade(const char *op, int options, const char *section, xmlNode * req,
 258                         xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 259                         xmlNode ** answer);
 260 
 261 /*!
 262  * \internal
 263  * \brief Query or modify a CIB
 264  *
 265  * \param[in]     op            PCMK__CIB_REQUEST_* operation to be performed
 266  * \param[in]     options       Flag set of \c cib_call_options
 267  * \param[in]     section       XPath to query or modify
 268  * \param[in]     req           unused
 269  * \param[in]     input         Portion of CIB to modify (used with
 270  *                              PCMK__CIB_REQUEST_CREATE,
 271  *                              PCMK__CIB_REQUEST_MODIFY, and
 272  *                              PCMK__CIB_REQUEST_REPLACE)
 273  * \param[in,out] existing_cib  Input CIB (used with PCMK__CIB_REQUEST_QUERY)
 274  * \param[in,out] result_cib    CIB copy to make changes in (used with
 275  *                              PCMK__CIB_REQUEST_CREATE,
 276  *                              PCMK__CIB_REQUEST_MODIFY,
 277  *                              PCMK__CIB_REQUEST_DELETE, and
 278  *                              PCMK__CIB_REQUEST_REPLACE)
 279  * \param[out]    answer        Query result (used with PCMK__CIB_REQUEST_QUERY)
 280  *
 281  * \return Legacy Pacemaker return code
 282  */
 283 int cib_process_xpath(const char *op, int options, const char *section,
 284                       const xmlNode *req, xmlNode *input, xmlNode *existing_cib,
 285                       xmlNode **result_cib, xmlNode ** answer);
 286 
 287 bool cib__config_changed_v1(xmlNode *last, xmlNode *next, xmlNode **diff);
 288 
 289 int cib_internal_op(cib_t * cib, const char *op, const char *host,
 290                     const char *section, xmlNode * data,
 291                     xmlNode ** output_data, int call_options, const char *user_name);
 292 
 293 
 294 int cib_file_read_and_verify(const char *filename, const char *sigfile,
 295                              xmlNode **root);
 296 int cib_file_write_with_digest(xmlNode *cib_root, const char *cib_dirname,
 297                                const char *cib_filename);
 298 
 299 void cib__set_output(cib_t *cib, pcmk__output_t *out);
 300 
 301 cib_callback_client_t* cib__lookup_id (int call_id);
 302 
 303 /*!
 304  * \internal
 305  * \brief Connect to, query, and optionally disconnect from the CIB
 306  *
 307  * Open a read-write connection to the CIB manager if an already connected
 308  * client is not passed in. Then query the CIB and store the resulting XML.
 309  * Finally, disconnect if the CIB connection isn't being returned to the caller.
 310  *
 311  * \param[in,out] out         Output object (may be \p NULL)
 312  * \param[in,out] cib         If not \p NULL, where to store CIB connection
 313  * \param[out]    cib_object  Where to store query result
 314  *
 315  * \return Standard Pacemaker return code
 316  *
 317  * \note If \p cib is not \p NULL, the caller is responsible for freeing \p *cib
 318  *       using \p cib_delete().
 319  * \note If \p *cib points to an existing \p cib_t object, this function will
 320  *       reuse it instead of creating a new one. If the existing client is
 321  *       already connected, the connection will be reused, even if it's
 322  *       read-only.
 323  */
 324 int cib__signon_query(pcmk__output_t *out, cib_t **cib, xmlNode **cib_object);
 325 
 326 int cib__clean_up_connection(cib_t **cib);
 327 
 328 int cib__update_node_attr(pcmk__output_t *out, cib_t *cib, int call_options,
 329                           const char *section, const char *node_uuid, const char *set_type,
 330                           const char *set_name, const char *attr_id, const char *attr_name,
 331                           const char *attr_value, const char *user_name,
 332                           const char *node_type);
 333 
 334 int cib__get_node_attrs(pcmk__output_t *out, cib_t *cib, const char *section,
 335                         const char *node_uuid, const char *set_type, const char *set_name,
 336                         const char *attr_id, const char *attr_name, const char *user_name,
 337                         xmlNode **result);
 338 
 339 int cib__delete_node_attr(pcmk__output_t *out, cib_t *cib, int options,
 340                           const char *section, const char *node_uuid, const char *set_type,
 341                           const char *set_name, const char *attr_id, const char *attr_name,
 342                           const char *attr_value, const char *user_name);
 343 
 344 #endif

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