root/daemons/attrd/pacemaker-attrd.h

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

INCLUDED FROM


   1 /*
   2  * Copyright 2013-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 General Public License version 2
   7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
   8  */
   9 
  10 #ifndef PACEMAKER_ATTRD__H
  11 #  define PACEMAKER_ATTRD__H
  12 
  13 #include <regex.h>
  14 #include <glib.h>
  15 #include <crm/crm.h>
  16 #include <crm/cluster.h>
  17 #include <crm/cluster/election_internal.h>
  18 #include <crm/common/messages_internal.h>
  19 #include <crm/cib/internal.h>
  20 
  21 /*
  22  * Legacy attrd (all pre-1.1.11 Pacemaker versions, plus all versions when used
  23  * with the no-longer-supported CMAN or corosync-plugin stacks) is unversioned.
  24  *
  25  * With atomic attrd, each attrd will send ATTRD_PROTOCOL_VERSION with every
  26  * peer request and reply. As of Pacemaker 2.0.0, at start-up each attrd will
  27  * also set a private attribute for itself with its version, so any attrd can
  28  * determine the minimum version supported by all peers.
  29  *
  30  * Protocol  Pacemaker  Significant changes
  31  * --------  ---------  -------------------
  32  *     1       1.1.11   PCMK__ATTRD_CMD_UPDATE (PCMK__XA_ATTR_NAME only),
  33  *                      PCMK__ATTRD_CMD_PEER_REMOVE, PCMK__ATTRD_CMD_REFRESH,
  34  *                      PCMK__ATTRD_CMD_FLUSH, PCMK__ATTRD_CMD_SYNC,
  35  *                      PCMK__ATTRD_CMD_SYNC_RESPONSE
  36  *     1       1.1.13   PCMK__ATTRD_CMD_UPDATE (with PCMK__XA_ATTR_PATTERN),
  37  *                      PCMK__ATTRD_CMD_QUERY
  38  *     1       1.1.15   PCMK__ATTRD_CMD_UPDATE_BOTH,
  39  *                      PCMK__ATTRD_CMD_UPDATE_DELAY
  40  *     2       1.1.17   PCMK__ATTRD_CMD_CLEAR_FAILURE
  41  *     3       2.1.1    PCMK__ATTRD_CMD_SYNC_RESPONSE indicates remote nodes
  42  *     4       2.2.0    Multiple attributes can be updated in a single IPC
  43  *                      message
  44  */
  45 #define ATTRD_PROTOCOL_VERSION "4"
  46 
  47 #define attrd_send_ack(client, id, flags) \
  48     pcmk__ipc_send_ack((client), (id), (flags), "ack", ATTRD_PROTOCOL_VERSION, CRM_EX_INDETERMINATE)
  49 
  50 void attrd_init_mainloop(void);
  51 void attrd_run_mainloop(void);
  52 
  53 void attrd_set_requesting_shutdown(void);
  54 void attrd_clear_requesting_shutdown(void);
  55 bool attrd_requesting_shutdown(void);
  56 bool attrd_shutting_down(void);
  57 void attrd_shutdown(int nsig);
  58 void attrd_init_ipc(void);
  59 void attrd_ipc_fini(void);
  60 
  61 void attrd_cib_disconnect(void);
  62 
  63 bool attrd_value_needs_expansion(const char *value);
  64 int attrd_expand_value(const char *value, const char *old_value);
  65 
  66 /* regular expression to clear failures of all resources */
  67 #define ATTRD_RE_CLEAR_ALL \
  68     "^(" PCMK__FAIL_COUNT_PREFIX "|" PCMK__LAST_FAILURE_PREFIX ")-"
  69 
  70 /* regular expression to clear failure of all operations for one resource
  71  * (format takes resource name)
  72  *
  73  * @COMPAT attributes set < 1.1.17:
  74  * also match older attributes that do not have the operation part
  75  */
  76 #define ATTRD_RE_CLEAR_ONE ATTRD_RE_CLEAR_ALL "%s(#.+_[0-9]+)?$"
  77 
  78 /* regular expression to clear failure of one operation for one resource
  79  * (format takes resource name, operation name, and interval)
  80  *
  81  * @COMPAT attributes set < 1.1.17:
  82  * also match older attributes that do not have the operation part
  83  */
  84 #define ATTRD_RE_CLEAR_OP ATTRD_RE_CLEAR_ALL "%s(#%s_%u)?$"
  85 
  86 int attrd_failure_regex(regex_t *regex, const char *rsc, const char *op,
  87                         guint interval_ms);
  88 
  89 extern cib_t *the_cib;
  90 
  91 /* Alerts */
  92 
  93 extern lrmd_t *the_lrmd;
  94 extern crm_trigger_t *attrd_config_read;
  95 
  96 void attrd_lrmd_disconnect(void);
  97 gboolean attrd_read_options(gpointer user_data);
  98 void attrd_cib_replaced_cb(const char *event, xmlNode * msg);
  99 void attrd_cib_updated_cb(const char *event, xmlNode *msg);
 100 int attrd_send_attribute_alert(const char *node, int nodeid,
 101                                const char *attr, const char *value);
 102 
 103 // Elections
 104 void attrd_election_init(void);
 105 void attrd_election_fini(void);
 106 void attrd_start_election_if_needed(void);
 107 bool attrd_election_won(void);
 108 void attrd_handle_election_op(const crm_node_t *peer, xmlNode *xml);
 109 bool attrd_check_for_new_writer(const crm_node_t *peer, const xmlNode *xml);
 110 void attrd_declare_winner(void);
 111 void attrd_remove_voter(const crm_node_t *peer);
 112 void attrd_xml_add_writer(xmlNode *xml);
 113 
 114 typedef struct attribute_s {
 115     char *uuid; /* TODO: Remove if at all possible */
 116     char *id;
 117     char *set;
 118     GHashTable *values;
 119     int update;
 120     int timeout_ms;
 121 
 122     /* TODO: refactor these three as a bitmask */
 123     bool changed; /* whether attribute value has changed since last write */
 124     bool unknown_peer_uuids; /* whether we know we're missing a peer uuid */
 125     gboolean is_private; /* whether to keep this attribute out of the CIB */
 126 
 127     mainloop_timer_t *timer;
 128 
 129     char *user;
 130 
 131     gboolean force_write; /* Flag for updating attribute by ignoring delay */
 132 
 133 } attribute_t;
 134 
 135 typedef struct attribute_value_s {
 136         uint32_t nodeid;
 137         gboolean is_remote;
 138         char *nodename;
 139         char *current;
 140         char *requested;
 141         gboolean seen;
 142 } attribute_value_t;
 143 
 144 extern crm_cluster_t *attrd_cluster;
 145 extern GHashTable *attributes;
 146 
 147 #define CIB_OP_TIMEOUT_S 120
 148 
 149 int attrd_cluster_connect(void);
 150 void attrd_peer_update(const crm_node_t *peer, xmlNode *xml, const char *host,
 151                        bool filter);
 152 void attrd_peer_sync(crm_node_t *peer, xmlNode *xml);
 153 void attrd_peer_remove(const char *host, bool uncache, const char *source);
 154 void attrd_peer_clear_failure(pcmk__request_t *request);
 155 void attrd_peer_sync_response(const crm_node_t *peer, bool peer_won,
 156                               xmlNode *xml);
 157 
 158 void attrd_broadcast_protocol(void);
 159 xmlNode *attrd_client_peer_remove(pcmk__request_t *request);
 160 xmlNode *attrd_client_clear_failure(pcmk__request_t *request);
 161 xmlNode *attrd_client_update(pcmk__request_t *request);
 162 xmlNode *attrd_client_refresh(pcmk__request_t *request);
 163 xmlNode *attrd_client_query(pcmk__request_t *request);
 164 gboolean attrd_send_message(crm_node_t * node, xmlNode * data);
 165 
 166 xmlNode *attrd_add_value_xml(xmlNode *parent, const attribute_t *a,
 167                              const attribute_value_t *v, bool force_write);
 168 void attrd_clear_value_seen(void);
 169 void attrd_free_attribute(gpointer data);
 170 void attrd_free_attribute_value(gpointer data);
 171 attribute_t *attrd_populate_attribute(xmlNode *xml, const char *attr);
 172 
 173 void attrd_write_attribute(attribute_t *a, bool ignore_delay);
 174 void attrd_write_attributes(bool all, bool ignore_delay);
 175 void attrd_write_or_elect_attribute(attribute_t *a);
 176 
 177 extern int minimum_protocol_version;
 178 void attrd_update_minimum_protocol_ver(const char *value);
 179 
 180 mainloop_timer_t *attrd_add_timer(const char *id, int timeout_ms, attribute_t *attr);
 181 
 182 void attrd_unregister_handlers(void);
 183 void attrd_handle_request(pcmk__request_t *request);
 184 
 185 #endif /* PACEMAKER_ATTRD__H */

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