root/daemons/attrd/pacemaker-attrd.h

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

INCLUDED FROM


   1 /*
   2  * Copyright 2013-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 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.1.5    Multiple attributes can be updated in a single IPC
  43  *                      message
  44  *     5       2.1.5    Peers can request confirmation of a sent message
  45  */
  46 #define ATTRD_PROTOCOL_VERSION "5"
  47 
  48 #define ATTRD_SUPPORTS_MULTI_MESSAGE(x) ((x) >= 4)
  49 #define ATTRD_SUPPORTS_CONFIRMATION(x)  ((x) >= 5)
  50 
  51 #define attrd_send_ack(client, id, flags) \
  52     pcmk__ipc_send_ack((client), (id), (flags), "ack", ATTRD_PROTOCOL_VERSION, CRM_EX_INDETERMINATE)
  53 
  54 void attrd_init_mainloop(void);
  55 void attrd_run_mainloop(void);
  56 
  57 void attrd_set_requesting_shutdown(void);
  58 void attrd_clear_requesting_shutdown(void);
  59 void attrd_free_waitlist(void);
  60 bool attrd_requesting_shutdown(void);
  61 bool attrd_shutting_down(void);
  62 void attrd_shutdown(int nsig);
  63 void attrd_init_ipc(void);
  64 void attrd_ipc_fini(void);
  65 
  66 void attrd_cib_disconnect(void);
  67 
  68 bool attrd_value_needs_expansion(const char *value);
  69 int attrd_expand_value(const char *value, const char *old_value);
  70 
  71 /* regular expression to clear failures of all resources */
  72 #define ATTRD_RE_CLEAR_ALL \
  73     "^(" PCMK__FAIL_COUNT_PREFIX "|" PCMK__LAST_FAILURE_PREFIX ")-"
  74 
  75 /* regular expression to clear failure of all operations for one resource
  76  * (format takes resource name)
  77  *
  78  * @COMPAT attributes set < 1.1.17:
  79  * also match older attributes that do not have the operation part
  80  */
  81 #define ATTRD_RE_CLEAR_ONE ATTRD_RE_CLEAR_ALL "%s(#.+_[0-9]+)?$"
  82 
  83 /* regular expression to clear failure of one operation for one resource
  84  * (format takes resource name, operation name, and interval)
  85  *
  86  * @COMPAT attributes set < 1.1.17:
  87  * also match older attributes that do not have the operation part
  88  */
  89 #define ATTRD_RE_CLEAR_OP ATTRD_RE_CLEAR_ALL "%s(#%s_%u)?$"
  90 
  91 int attrd_failure_regex(regex_t *regex, const char *rsc, const char *op,
  92                         guint interval_ms);
  93 
  94 extern cib_t *the_cib;
  95 
  96 /* Alerts */
  97 
  98 extern lrmd_t *the_lrmd;
  99 extern crm_trigger_t *attrd_config_read;
 100 
 101 void attrd_lrmd_disconnect(void);
 102 gboolean attrd_read_options(gpointer user_data);
 103 void attrd_cib_replaced_cb(const char *event, xmlNode * msg);
 104 void attrd_cib_updated_cb(const char *event, xmlNode *msg);
 105 int attrd_send_attribute_alert(const char *node, int nodeid,
 106                                const char *attr, const char *value);
 107 
 108 // Elections
 109 void attrd_election_init(void);
 110 void attrd_election_fini(void);
 111 void attrd_start_election_if_needed(void);
 112 bool attrd_election_won(void);
 113 void attrd_handle_election_op(const crm_node_t *peer, xmlNode *xml);
 114 bool attrd_check_for_new_writer(const crm_node_t *peer, const xmlNode *xml);
 115 void attrd_declare_winner(void);
 116 void attrd_remove_voter(const crm_node_t *peer);
 117 void attrd_xml_add_writer(xmlNode *xml);
 118 
 119 typedef struct attribute_s {
 120     char *uuid; /* TODO: Remove if at all possible */
 121     char *id;
 122     char *set_id;
 123     char *set_type;
 124     GHashTable *values;
 125     int update;
 126     int timeout_ms;
 127 
 128     /* TODO: refactor these three as a bitmask */
 129     bool changed; /* whether attribute value has changed since last write */
 130     bool unknown_peer_uuids; /* whether we know we're missing a peer uuid */
 131     gboolean is_private; /* whether to keep this attribute out of the CIB */
 132 
 133     mainloop_timer_t *timer;
 134 
 135     char *user;
 136 
 137     gboolean force_write; /* Flag for updating attribute by ignoring delay */
 138 
 139 } attribute_t;
 140 
 141 typedef struct attribute_value_s {
 142         uint32_t nodeid;
 143         gboolean is_remote;
 144         char *nodename;
 145         char *current;
 146         char *requested;
 147         gboolean seen;
 148 } attribute_value_t;
 149 
 150 extern crm_cluster_t *attrd_cluster;
 151 extern GHashTable *attributes;
 152 extern GHashTable *peer_protocol_vers;
 153 
 154 #define CIB_OP_TIMEOUT_S 120
 155 
 156 int attrd_cluster_connect(void);
 157 void attrd_peer_update(const crm_node_t *peer, xmlNode *xml, const char *host,
 158                        bool filter);
 159 void attrd_peer_sync(crm_node_t *peer, xmlNode *xml);
 160 void attrd_peer_remove(const char *host, bool uncache, const char *source);
 161 void attrd_peer_clear_failure(pcmk__request_t *request);
 162 void attrd_peer_sync_response(const crm_node_t *peer, bool peer_won,
 163                               xmlNode *xml);
 164 
 165 void attrd_broadcast_protocol(void);
 166 xmlNode *attrd_client_peer_remove(pcmk__request_t *request);
 167 xmlNode *attrd_client_clear_failure(pcmk__request_t *request);
 168 xmlNode *attrd_client_update(pcmk__request_t *request);
 169 xmlNode *attrd_client_refresh(pcmk__request_t *request);
 170 xmlNode *attrd_client_query(pcmk__request_t *request);
 171 gboolean attrd_send_message(crm_node_t *node, xmlNode *data, bool confirm);
 172 
 173 xmlNode *attrd_add_value_xml(xmlNode *parent, const attribute_t *a,
 174                              const attribute_value_t *v, bool force_write);
 175 void attrd_clear_value_seen(void);
 176 void attrd_free_attribute(gpointer data);
 177 void attrd_free_attribute_value(gpointer data);
 178 attribute_t *attrd_populate_attribute(xmlNode *xml, const char *attr);
 179 
 180 void attrd_write_attribute(attribute_t *a, bool ignore_delay);
 181 void attrd_write_attributes(bool all, bool ignore_delay);
 182 void attrd_write_or_elect_attribute(attribute_t *a);
 183 
 184 extern int minimum_protocol_version;
 185 void attrd_remove_peer_protocol_ver(const char *host);
 186 void attrd_update_minimum_protocol_ver(const char *host, const char *value);
 187 
 188 mainloop_timer_t *attrd_add_timer(const char *id, int timeout_ms, attribute_t *attr);
 189 
 190 void attrd_unregister_handlers(void);
 191 void attrd_handle_request(pcmk__request_t *request);
 192 
 193 enum attrd_sync_point {
 194     attrd_sync_point_local,
 195     attrd_sync_point_cluster,
 196 };
 197 
 198 typedef int (*attrd_confirmation_action_fn)(xmlNode *);
 199 
 200 void attrd_add_client_to_waitlist(pcmk__request_t *request);
 201 void attrd_ack_waitlist_clients(enum attrd_sync_point sync_point, const xmlNode *xml);
 202 int attrd_cluster_sync_point_update(xmlNode *xml);
 203 void attrd_do_not_expect_from_peer(const char *host);
 204 void attrd_do_not_wait_for_client(pcmk__client_t *client);
 205 void attrd_expect_confirmations(pcmk__request_t *request, attrd_confirmation_action_fn fn);
 206 void attrd_free_confirmations(void);
 207 void attrd_handle_confirmation(int callid, const char *host);
 208 void attrd_remove_client_from_waitlist(pcmk__client_t *client);
 209 const char *attrd_request_sync_point(xmlNode *xml);
 210 bool attrd_request_has_sync_point(xmlNode *xml);
 211 
 212 void attrd_copy_xml_attributes(xmlNode *src, xmlNode *dest);
 213 
 214 extern gboolean stand_alone;
 215 
 216 #endif /* PACEMAKER_ATTRD__H */

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