root/include/crm/cib/internal.h

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

INCLUDED FROM


   1 /*
   2  * Copyright 2004-2022 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_ALL_SECONDARY "cib_slave_all"
  19 #define PCMK__CIB_REQUEST_PRIMARY       "cib_master"
  20 #define PCMK__CIB_REQUEST_SYNC_TO_ALL   "cib_sync"
  21 #define PCMK__CIB_REQUEST_SYNC_TO_ONE   "cib_sync_one"
  22 #define PCMK__CIB_REQUEST_IS_PRIMARY    "cib_ismaster"
  23 #define PCMK__CIB_REQUEST_BUMP          "cib_bump"
  24 #define PCMK__CIB_REQUEST_QUERY         "cib_query"
  25 #define PCMK__CIB_REQUEST_CREATE        "cib_create"
  26 #define PCMK__CIB_REQUEST_MODIFY        "cib_modify"
  27 #define PCMK__CIB_REQUEST_DELETE        "cib_delete"
  28 #define PCMK__CIB_REQUEST_ERASE         "cib_erase"
  29 #define PCMK__CIB_REQUEST_REPLACE       "cib_replace"
  30 #define PCMK__CIB_REQUEST_APPLY_PATCH   "cib_apply_diff"
  31 #define PCMK__CIB_REQUEST_UPGRADE       "cib_upgrade"
  32 #define PCMK__CIB_REQUEST_ABS_DELETE    "cib_delete_alt"
  33 #define PCMK__CIB_REQUEST_NOOP          "noop"
  34 #define PCMK__CIB_REQUEST_SHUTDOWN      "cib_shutdown_req"
  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_CALLBACK_TOKEN  "cib_async_id"
  54 #  define F_CIB_GLOBAL_UPDATE   "cib_update"
  55 #  define F_CIB_UPDATE_RESULT   "cib_update_result"
  56 #  define F_CIB_CLIENTNAME      "cib_clientname"
  57 #  define F_CIB_NOTIFY_TYPE     "cib_notify_type"
  58 #  define F_CIB_NOTIFY_ACTIVATE "cib_notify_activate"
  59 #  define F_CIB_UPDATE_DIFF     "cib_update_diff"
  60 #  define F_CIB_USER            "cib_user"
  61 #  define F_CIB_LOCAL_NOTIFY_ID "cib_local_notify_id"
  62 #  define F_CIB_PING_ID         "cib_ping_id"
  63 #  define F_CIB_SCHEMA_MAX      "cib_schema_max"
  64 #  define F_CIB_CHANGE_SECTION  "cib_change_section"
  65 
  66 #  define T_CIB                 "cib"
  67 #  define T_CIB_NOTIFY          "cib_notify"
  68 /* notify sub-types */
  69 #  define T_CIB_PRE_NOTIFY      "cib_pre_notify"
  70 #  define T_CIB_POST_NOTIFY     "cib_post_notify"
  71 #  define T_CIB_UPDATE_CONFIRM  "cib_update_confirmation"
  72 #  define T_CIB_REPLACE_NOTIFY  "cib_refresh_notify"
  73 
  74 /*!
  75  * \internal
  76  * \enum cib_change_section_info
  77  * \brief Flags to indicate which sections of the CIB have changed
  78  */
  79 enum cib_change_section_info {
  80     cib_change_section_none     = 0,        //!< No sections have changed
  81     cib_change_section_nodes    = (1 << 0), //!< The nodes section has changed
  82     cib_change_section_alerts   = (1 << 1), //!< The alerts section has changed
  83     cib_change_section_status   = (1 << 2), //!< The status section has changed
  84 };
  85 
  86 
  87 gboolean cib_diff_version_details(xmlNode * diff, int *admin_epoch, int *epoch, int *updates,
  88                                   int *_admin_epoch, int *_epoch, int *_updates);
  89 
  90 gboolean cib_read_config(GHashTable * options, xmlNode * current_cib);
  91 void verify_cib_options(GHashTable * options);
  92 gboolean cib_internal_config_changed(xmlNode * diff);
  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 typedef int (*cib_op_t) (const char *, int, const char *, xmlNode *,
 131                          xmlNode *, xmlNode *, xmlNode **, xmlNode **);
 132 
 133 cib_t *cib_new_variant(void);
 134 
 135 int cib_perform_op(const char *op, int call_options, cib_op_t * fn, gboolean is_query,
 136                    const char *section, xmlNode * req, xmlNode * input,
 137                    gboolean manage_counters, gboolean * config_changed,
 138                    xmlNode * current_cib, xmlNode ** result_cib, xmlNode ** diff,
 139                    xmlNode ** output);
 140 
 141 xmlNode *cib_create_op(int call_id, const char *token, const char *op, const char *host,
 142                        const char *section, xmlNode * data, int call_options,
 143                        const char *user_name);
 144 
 145 void cib_native_callback(cib_t * cib, xmlNode * msg, int call_id, int rc);
 146 void cib_native_notify(gpointer data, gpointer user_data);
 147 int cib_native_register_notification(cib_t * cib, const char *callback, int enabled);
 148 gboolean cib_client_register_callback(cib_t * cib, int call_id, int timeout, gboolean only_success,
 149                                       void *user_data, const char *callback_name,
 150                                       void (*callback) (xmlNode *, int, int, xmlNode *, void *));
 151 gboolean cib_client_register_callback_full(cib_t *cib, int call_id,
 152                                            int timeout, gboolean only_success,
 153                                            void *user_data,
 154                                            const char *callback_name,
 155                                            void (*callback)(xmlNode *, int, int,
 156                                                             xmlNode *, void *),
 157                                            void (*free_func)(void *));
 158 
 159 int cib_process_query(const char *op, int options, const char *section, xmlNode * req,
 160                       xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 161                       xmlNode ** answer);
 162 
 163 int cib_process_erase(const char *op, int options, const char *section, xmlNode * req,
 164                       xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 165                       xmlNode ** answer);
 166 
 167 int cib_process_bump(const char *op, int options, const char *section, xmlNode * req,
 168                      xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 169                      xmlNode ** answer);
 170 
 171 int cib_process_replace(const char *op, int options, const char *section, xmlNode * req,
 172                         xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 173                         xmlNode ** answer);
 174 
 175 int cib_process_create(const char *op, int options, const char *section, xmlNode * req,
 176                        xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 177                        xmlNode ** answer);
 178 
 179 int cib_process_modify(const char *op, int options, const char *section, xmlNode * req,
 180                        xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 181                        xmlNode ** answer);
 182 
 183 int cib_process_delete(const char *op, int options, const char *section, xmlNode * req,
 184                        xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 185                        xmlNode ** answer);
 186 
 187 int cib_process_diff(const char *op, int options, const char *section, xmlNode * req,
 188                      xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 189                      xmlNode ** answer);
 190 
 191 int cib_process_upgrade(const char *op, int options, const char *section, xmlNode * req,
 192                         xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 193                         xmlNode ** answer);
 194 
 195 /*!
 196  * \internal
 197  * \brief Query or modify a CIB
 198  *
 199  * \param[in]     op            PCMK__CIB_REQUEST_* operation to be performed
 200  * \param[in]     options       Flag set of \c cib_call_options
 201  * \param[in]     section       XPath to query or modify
 202  * \param[in]     req           unused
 203  * \param[in]     input         Portion of CIB to modify (used with
 204  *                              PCMK__CIB_REQUEST_CREATE,
 205  *                              PCMK__CIB_REQUEST_MODIFY, and
 206  *                              PCMK__CIB_REQUEST_REPLACE)
 207  * \param[in,out] existing_cib  Input CIB (used with PCMK__CIB_REQUEST_QUERY)
 208  * \param[in,out] result_cib    CIB copy to make changes in (used with
 209  *                              PCMK__CIB_REQUEST_CREATE,
 210  *                              PCMK__CIB_REQUEST_MODIFY,
 211  *                              PCMK__CIB_REQUEST_DELETE, and
 212  *                              PCMK__CIB_REQUEST_REPLACE)
 213  * \param[out]    answer        Query result (used with PCMK__CIB_REQUEST_QUERY)
 214  *
 215  * \return Legacy Pacemaker return code
 216  */
 217 int cib_process_xpath(const char *op, int options, const char *section,
 218                       const xmlNode *req, xmlNode *input, xmlNode *existing_cib,
 219                       xmlNode **result_cib, xmlNode ** answer);
 220 
 221 gboolean cib_config_changed(xmlNode * last, xmlNode * next, xmlNode ** diff);
 222 gboolean update_results(xmlNode * failed, xmlNode * target, const char *operation, int return_code);
 223 int cib_update_counter(xmlNode * xml_obj, const char *field, gboolean reset);
 224 
 225 int cib_internal_op(cib_t * cib, const char *op, const char *host,
 226                     const char *section, xmlNode * data,
 227                     xmlNode ** output_data, int call_options, const char *user_name);
 228 
 229 
 230 int cib_file_read_and_verify(const char *filename, const char *sigfile,
 231                              xmlNode **root);
 232 int cib_file_write_with_digest(xmlNode *cib_root, const char *cib_dirname,
 233                                const char *cib_filename);
 234 
 235 void cib__set_output(cib_t *cib, pcmk__output_t *out);
 236 
 237 cib_callback_client_t* cib__lookup_id (int call_id);
 238 
 239 /*!
 240  * \internal
 241  * \brief Connect to, query, and optionally disconnect from the CIB, returning
 242  *        the resulting XML object.
 243  *
 244  * \param[out] cib        If non-NULL, a pointer to where to store the CIB
 245  *                        connection.  In this case, it is up to the caller to
 246  *                        disconnect from the CIB when finished.
 247  * \param[out] cib_object A pointer to where to store the XML query result.
 248  *
 249  * \return A standard Pacemaker return code
 250  */
 251 int cib__signon_query(cib_t **cib, xmlNode **cib_object);
 252 
 253 int cib__clean_up_connection(cib_t **cib);
 254 
 255 int cib__update_node_attr(pcmk__output_t *out, cib_t *cib, int call_options,
 256                           const char *section, const char *node_uuid, const char *set_type,
 257                           const char *set_name, const char *attr_id, const char *attr_name,
 258                           const char *attr_value, const char *user_name,
 259                           const char *node_type);
 260 
 261 int cib__get_node_attrs(pcmk__output_t *out, cib_t *cib, const char *section,
 262                         const char *node_uuid, const char *set_type, const char *set_name,
 263                         const char *attr_id, const char *attr_name, const char *user_name,
 264                         xmlNode **result);
 265 
 266 int cib__delete_node_attr(pcmk__output_t *out, cib_t *cib, int options,
 267                           const char *section, const char *node_uuid, const char *set_type,
 268                           const char *set_name, const char *attr_id, const char *attr_name,
 269                           const char *attr_value, const char *user_name);
 270 
 271 #endif

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