root/include/crm/cib/internal.h

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

INCLUDED FROM


   1 /*
   2  * Copyright 2004-2021 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 #  define CIB_OP_SLAVE  "cib_slave"
  17 #  define CIB_OP_SLAVEALL       "cib_slave_all"
  18 #  define CIB_OP_MASTER "cib_master"
  19 #  define CIB_OP_SYNC   "cib_sync"
  20 #  define CIB_OP_SYNC_ONE       "cib_sync_one"
  21 #  define CIB_OP_ISMASTER       "cib_ismaster"
  22 #  define CIB_OP_BUMP   "cib_bump"
  23 #  define CIB_OP_QUERY  "cib_query"
  24 #  define CIB_OP_CREATE "cib_create"
  25 #  define CIB_OP_MODIFY "cib_modify"
  26 #  define CIB_OP_DELETE "cib_delete"
  27 #  define CIB_OP_ERASE  "cib_erase"
  28 #  define CIB_OP_REPLACE        "cib_replace"
  29 #  define CIB_OP_APPLY_DIFF "cib_apply_diff"
  30 #  define CIB_OP_UPGRADE    "cib_upgrade"
  31 #  define CIB_OP_DELETE_ALT     "cib_delete_alt"
  32 
  33 #  define F_CIB_CLIENTID  "cib_clientid"
  34 #  define F_CIB_CALLOPTS  "cib_callopt"
  35 #  define F_CIB_CALLID    "cib_callid"
  36 #  define F_CIB_CALLDATA  "cib_calldata"
  37 #  define F_CIB_OPERATION "cib_op"
  38 #  define F_CIB_ISREPLY   "cib_isreplyto"
  39 #  define F_CIB_SECTION   "cib_section"
  40 #  define F_CIB_HOST    "cib_host"
  41 #  define F_CIB_RC      "cib_rc"
  42 #  define F_CIB_UPGRADE_RC      "cib_upgrade_rc"
  43 #  define F_CIB_DELEGATED       "cib_delegated_from"
  44 #  define F_CIB_OBJID   "cib_object"
  45 #  define F_CIB_OBJTYPE "cib_object_type"
  46 #  define F_CIB_EXISTING        "cib_existing_object"
  47 #  define F_CIB_SEENCOUNT       "cib_seen"
  48 #  define F_CIB_TIMEOUT "cib_timeout"
  49 #  define F_CIB_UPDATE  "cib_update"
  50 #  define F_CIB_CALLBACK_TOKEN  "cib_async_id"
  51 #  define F_CIB_GLOBAL_UPDATE   "cib_update"
  52 #  define F_CIB_UPDATE_RESULT   "cib_update_result"
  53 #  define F_CIB_CLIENTNAME      "cib_clientname"
  54 #  define F_CIB_NOTIFY_TYPE     "cib_notify_type"
  55 #  define F_CIB_NOTIFY_ACTIVATE "cib_notify_activate"
  56 #  define F_CIB_UPDATE_DIFF     "cib_update_diff"
  57 #  define F_CIB_USER            "cib_user"
  58 #  define F_CIB_LOCAL_NOTIFY_ID "cib_local_notify_id"
  59 #  define F_CIB_PING_ID         "cib_ping_id"
  60 #  define F_CIB_SCHEMA_MAX      "cib_schema_max"
  61 
  62 #  define T_CIB                 "cib"
  63 #  define T_CIB_NOTIFY          "cib_notify"
  64 /* notify sub-types */
  65 #  define T_CIB_PRE_NOTIFY      "cib_pre_notify"
  66 #  define T_CIB_POST_NOTIFY     "cib_post_notify"
  67 #  define T_CIB_UPDATE_CONFIRM  "cib_update_confirmation"
  68 #  define T_CIB_REPLACE_NOTIFY  "cib_refresh_notify"
  69 
  70 gboolean cib_diff_version_details(xmlNode * diff, int *admin_epoch, int *epoch, int *updates,
  71                                   int *_admin_epoch, int *_epoch, int *_updates);
  72 
  73 gboolean cib_read_config(GHashTable * options, xmlNode * current_cib);
  74 void verify_cib_options(GHashTable * options);
  75 gboolean cib_internal_config_changed(xmlNode * diff);
  76 
  77 typedef struct cib_notify_client_s {
  78     const char *event;
  79     const char *obj_id;         /* implement one day */
  80     const char *obj_type;       /* implement one day */
  81     void (*callback) (const char *event, xmlNode * msg);
  82 
  83 } cib_notify_client_t;
  84 
  85 typedef struct cib_callback_client_s {
  86     void (*callback) (xmlNode *, int, int, xmlNode *, void *);
  87     const char *id;
  88     void *user_data;
  89     gboolean only_success;
  90     struct timer_rec_s *timer;
  91     void (*free_func)(void *);
  92 } cib_callback_client_t;
  93 
  94 struct timer_rec_s {
  95     int call_id;
  96     int timeout;
  97     guint ref;
  98     cib_t *cib;
  99 };
 100 
 101 #define cib__set_call_options(cib_call_opts, call_for, flags_to_set) do {   \
 102         cib_call_opts = pcmk__set_flags_as(__func__, __LINE__,              \
 103             LOG_TRACE, "CIB call", (call_for), (cib_call_opts),             \
 104             (flags_to_set), #flags_to_set); \
 105     } while (0)
 106 
 107 #define cib__clear_call_options(cib_call_opts, call_for, flags_to_clear) do {  \
 108         cib_call_opts = pcmk__clear_flags_as(__func__, __LINE__,               \
 109             LOG_TRACE, "CIB call", (call_for), (cib_call_opts),                \
 110             (flags_to_clear), #flags_to_clear);                                \
 111     } while (0)
 112 
 113 typedef int (*cib_op_t) (const char *, int, const char *, xmlNode *,
 114                          xmlNode *, xmlNode *, xmlNode **, xmlNode **);
 115 
 116 cib_t *cib_new_variant(void);
 117 
 118 int cib_perform_op(const char *op, int call_options, cib_op_t * fn, gboolean is_query,
 119                    const char *section, xmlNode * req, xmlNode * input,
 120                    gboolean manage_counters, gboolean * config_changed,
 121                    xmlNode * current_cib, xmlNode ** result_cib, xmlNode ** diff,
 122                    xmlNode ** output);
 123 
 124 xmlNode *cib_create_op(int call_id, const char *token, const char *op, const char *host,
 125                        const char *section, xmlNode * data, int call_options,
 126                        const char *user_name);
 127 
 128 void cib_native_callback(cib_t * cib, xmlNode * msg, int call_id, int rc);
 129 void cib_native_notify(gpointer data, gpointer user_data);
 130 int cib_native_register_notification(cib_t * cib, const char *callback, int enabled);
 131 gboolean cib_client_register_callback(cib_t * cib, int call_id, int timeout, gboolean only_success,
 132                                       void *user_data, const char *callback_name,
 133                                       void (*callback) (xmlNode *, int, int, xmlNode *, void *));
 134 gboolean cib_client_register_callback_full(cib_t *cib, int call_id,
 135                                            int timeout, gboolean only_success,
 136                                            void *user_data,
 137                                            const char *callback_name,
 138                                            void (*callback)(xmlNode *, int, int,
 139                                                             xmlNode *, void *),
 140                                            void (*free_func)(void *));
 141 
 142 int cib_process_query(const char *op, int options, const char *section, xmlNode * req,
 143                       xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 144                       xmlNode ** answer);
 145 
 146 int cib_process_erase(const char *op, int options, const char *section, xmlNode * req,
 147                       xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 148                       xmlNode ** answer);
 149 
 150 int cib_process_bump(const char *op, int options, const char *section, xmlNode * req,
 151                      xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 152                      xmlNode ** answer);
 153 
 154 int cib_process_replace(const char *op, int options, const char *section, xmlNode * req,
 155                         xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 156                         xmlNode ** answer);
 157 
 158 int cib_process_create(const char *op, int options, const char *section, xmlNode * req,
 159                        xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 160                        xmlNode ** answer);
 161 
 162 int cib_process_modify(const char *op, int options, const char *section, xmlNode * req,
 163                        xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 164                        xmlNode ** answer);
 165 
 166 int cib_process_delete(const char *op, int options, const char *section, xmlNode * req,
 167                        xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 168                        xmlNode ** answer);
 169 
 170 int cib_process_diff(const char *op, int options, const char *section, xmlNode * req,
 171                      xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 172                      xmlNode ** answer);
 173 
 174 int cib_process_upgrade(const char *op, int options, const char *section, xmlNode * req,
 175                         xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 176                         xmlNode ** answer);
 177 
 178 /*!
 179  * \internal
 180  * \brief Query or modify a CIB
 181  *
 182  * \param[in]     op            CIB_OP_* operation to be performed
 183  * \param[in]     options       Flag set of \c cib_call_options
 184  * \param[in]     section       XPath to query or modify
 185  * \param[in]     req           unused
 186  * \param[in]     input         Portion of CIB to modify (used with
 187  *                              CIB_OP_CREATE, CIB_OP_MODIFY, and
 188  *                              CIB_OP_REPLACE)
 189  * \param[in]     existing_cib  Input CIB (used with CIB_OP_QUERY)
 190  * \param[in,out] result_cib    CIB copy to make changes in (used with
 191  *                              CIB_OP_CREATE, CIB_OP_MODIFY, CIB_OP_DELETE, and
 192  *                              CIB_OP_REPLACE)
 193  * \param[out]    answer        Query result (used with CIB_OP_QUERY)
 194  *
 195  * \return Legacy Pacemaker return code
 196  */
 197 int cib_process_xpath(const char *op, int options, const char *section, xmlNode * req,
 198                       xmlNode * input, xmlNode * existing_cib, xmlNode ** result_cib,
 199                       xmlNode ** answer);
 200 
 201 gboolean cib_config_changed(xmlNode * last, xmlNode * next, xmlNode ** diff);
 202 gboolean update_results(xmlNode * failed, xmlNode * target, const char *operation, int return_code);
 203 int cib_update_counter(xmlNode * xml_obj, const char *field, gboolean reset);
 204 
 205 int cib_internal_op(cib_t * cib, const char *op, const char *host,
 206                     const char *section, xmlNode * data,
 207                     xmlNode ** output_data, int call_options, const char *user_name);
 208 
 209 
 210 int cib_file_read_and_verify(const char *filename, const char *sigfile,
 211                              xmlNode **root);
 212 int cib_file_write_with_digest(xmlNode *cib_root, const char *cib_dirname,
 213                                const char *cib_filename);
 214 
 215 void cib__set_output(cib_t *cib, pcmk__output_t *out);
 216 
 217 cib_callback_client_t* cib__lookup_id (int call_id);
 218 
 219 /*!
 220  * \internal
 221  * \brief Connect to, query, and optionally disconnect from the CIB, returning
 222  *        the resulting XML object.
 223  *
 224  * \param[out] cib        If non-NULL, a pointer to where to store the CIB
 225  *                        connection.  In this case, it is up to the caller to
 226  *                        disconnect from the CIB when finished.
 227  * \param[out] cib_object A pointer to where to store the XML query result.
 228  *
 229  * \return A standard Pacemaker return code
 230  */
 231 int cib__signon_query(cib_t **cib, xmlNode **cib_object);
 232 
 233 #endif

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