root/daemons/attrd/pacemaker-attrd.h

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

INCLUDED FROM


   1 /*
   2  * Copyright 2013-2025 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/cib_types.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  *                      "flush", PCMK__ATTRD_CMD_SYNC_RESPONSE
  35  *     1       1.1.13   PCMK__ATTRD_CMD_UPDATE (with PCMK__XA_ATTR_REGEX),
  36  *                      PCMK__ATTRD_CMD_QUERY
  37  *     1       1.1.15   PCMK__ATTRD_CMD_UPDATE_BOTH,
  38  *                      PCMK__ATTRD_CMD_UPDATE_DELAY
  39  *     2       1.1.17   PCMK__ATTRD_CMD_CLEAR_FAILURE
  40  *     3       2.1.1    PCMK__ATTRD_CMD_SYNC_RESPONSE indicates remote nodes
  41  *     4       2.1.5    Multiple attributes can be updated in a single IPC
  42  *                      message
  43  *     5       2.1.5    Peers can request confirmation of a sent message
  44  *     6       2.1.7    PCMK__ATTRD_CMD_PEER_REMOVE supports PCMK__XA_REAP
  45  *     7       3.0.0    "flush" support dropped
  46  */
  47 #define ATTRD_PROTOCOL_VERSION "7"
  48 
  49 #define ATTRD_SUPPORTS_MULTI_MESSAGE(x) ((x) >= 4)
  50 #define ATTRD_SUPPORTS_CONFIRMATION(x)  ((x) >= 5)
  51 
  52 #define attrd_send_ack(client, id, flags)                       \
  53     pcmk__ipc_send_ack((client), (id), (flags), PCMK__XE_ACK,   \
  54                        ATTRD_PROTOCOL_VERSION, CRM_EX_INDETERMINATE)
  55 
  56 void attrd_init_mainloop(void);
  57 void attrd_run_mainloop(void);
  58 
  59 void attrd_set_requesting_shutdown(void);
  60 void attrd_clear_requesting_shutdown(void);
  61 void attrd_free_waitlist(void);
  62 bool attrd_shutting_down(bool if_requested);
  63 void attrd_shutdown(int nsig);
  64 void attrd_init_ipc(void);
  65 void attrd_ipc_fini(void);
  66 
  67 int attrd_cib_connect(int max_retry);
  68 void attrd_cib_disconnect(void);
  69 void attrd_cib_init(void);
  70 void attrd_cib_erase_transient_attrs(const char *node);
  71 
  72 bool attrd_value_needs_expansion(const char *value);
  73 int attrd_expand_value(const char *value, const char *old_value);
  74 
  75 /* regular expression to clear failures of all resources */
  76 #define ATTRD_RE_CLEAR_ALL \
  77     "^(" PCMK__FAIL_COUNT_PREFIX "|" PCMK__LAST_FAILURE_PREFIX ")-"
  78 
  79 /* regular expression to clear failure of all operations for one resource
  80  * (format takes resource name)
  81  */
  82 #define ATTRD_RE_CLEAR_ONE ATTRD_RE_CLEAR_ALL "%s#.+_[0-9]+$"
  83 
  84 /* regular expression to clear failure of one operation for one resource
  85  * (format takes resource name, operation name, and interval)
  86  */
  87 #define ATTRD_RE_CLEAR_OP ATTRD_RE_CLEAR_ALL "%s#%s_%u$"
  88 
  89 int attrd_failure_regex(regex_t *regex, const char *rsc, const char *op,
  90                         guint interval_ms);
  91 
  92 extern cib_t *the_cib;
  93 extern crm_exit_t attrd_exit_status;
  94 
  95 /* Alerts */
  96 
  97 extern lrmd_t *the_lrmd;
  98 extern crm_trigger_t *attrd_config_read;
  99 
 100 void attrd_lrmd_disconnect(void);
 101 gboolean attrd_read_options(gpointer user_data);
 102 int attrd_send_attribute_alert(const char *node, const char *node_xml_id,
 103                                const char *attr, const char *value);
 104 
 105 // Elections
 106 void attrd_election_init(void);
 107 void attrd_start_election_if_needed(void);
 108 bool attrd_election_won(void);
 109 void attrd_handle_election_op(const pcmk__node_status_t *peer, xmlNode *xml);
 110 bool attrd_check_for_new_writer(const pcmk__node_status_t *peer,
 111                                 const xmlNode *xml);
 112 void attrd_declare_winner(void);
 113 void attrd_remove_voter(const pcmk__node_status_t *peer);
 114 void attrd_xml_add_writer(xmlNode *xml);
 115 
 116 enum attrd_attr_flags {
 117     attrd_attr_none         = 0U,
 118 
 119     // At least one of attribute's values has changed since last write
 120     attrd_attr_changed      = (1U << 0),
 121 
 122     // At least one of attribute's values has an unknown node XML ID
 123     attrd_attr_node_unknown = (1U << 1),
 124 
 125     // This attribute should never be written to the CIB
 126     attrd_attr_is_private   = (1U << 2),
 127 
 128     // Ignore any configured delay for next write of this attribute
 129     attrd_attr_force_write  = (1U << 3),
 130 };
 131 
 132 typedef struct attribute_s {
 133     char *id;       // Attribute name
 134     char *set_type; // PCMK_XE_INSTANCE_ATTRIBUTES or PCMK_XE_UTILIZATION
 135     char *set_id;   // Set's XML ID to use when writing
 136     char *user;     // ACL user to use for CIB writes
 137     int update;     // Call ID of pending write
 138     int timeout_ms; // How long to wait for more changes before writing
 139     uint32_t flags; // Group of enum attrd_attr_flags
 140     GHashTable *values;         // Key: node name, value: attribute_value_t
 141     mainloop_timer_t *timer;    // Timer to use for timeout_ms
 142 } attribute_t;
 143 
 144 #define attrd_set_attr_flags(attr, flags_to_set) do {               \
 145         (attr)->flags = pcmk__set_flags_as(__func__, __LINE__,      \
 146             LOG_TRACE, "Value for attribute", (attr)->id,           \
 147             (attr)->flags, (flags_to_set), #flags_to_set);          \
 148     } while (0)
 149 
 150 #define attrd_clear_attr_flags(attr, flags_to_clear) do {           \
 151         (attr)->flags = pcmk__clear_flags_as(__func__, __LINE__,    \
 152             LOG_TRACE, "Value for attribute", (attr)->id,           \
 153             (attr)->flags, (flags_to_clear), #flags_to_clear);      \
 154     } while (0)
 155 
 156 enum attrd_value_flags {
 157     attrd_value_none        = 0U,
 158     attrd_value_remote      = (1U << 0),  // Value is for Pacemaker Remote node
 159     attrd_value_from_peer   = (1U << 1),  // Value is from peer sync response
 160 };
 161 
 162 typedef struct attribute_value_s {
 163     char *nodename;     // Node that this value is for
 164     char *current;      // Attribute value
 165     char *requested;    // Value specified in pending CIB write, if any
 166     uint32_t flags;     // Group of attrd_value_flags
 167 } attribute_value_t;
 168 
 169 #define attrd_set_value_flags(attr_value, flags_to_set) do {            \
 170         (attr_value)->flags = pcmk__set_flags_as(__func__, __LINE__,    \
 171             LOG_TRACE, "Value for node", (attr_value)->nodename,        \
 172             (attr_value)->flags, (flags_to_set), #flags_to_set);        \
 173     } while (0)
 174 
 175 #define attrd_clear_value_flags(attr_value, flags_to_clear) do {        \
 176         (attr_value)->flags = pcmk__clear_flags_as(__func__, __LINE__,  \
 177             LOG_TRACE, "Value for node", (attr_value)->nodename,        \
 178             (attr_value)->flags, (flags_to_clear), #flags_to_clear);    \
 179     } while (0)
 180 
 181 extern pcmk_cluster_t *attrd_cluster;
 182 extern GHashTable *attributes;
 183 extern GHashTable *peer_protocol_vers;
 184 
 185 #define CIB_OP_TIMEOUT_S 120
 186 
 187 int attrd_cluster_connect(void);
 188 void attrd_broadcast_value(const attribute_t *a, const attribute_value_t *v);
 189 void attrd_peer_update(const pcmk__node_status_t *peer, xmlNode *xml,
 190                        const char *host, bool filter);
 191 void attrd_peer_sync(pcmk__node_status_t *peer);
 192 void attrd_peer_remove(const char *host, bool uncache, const char *source);
 193 void attrd_peer_clear_failure(pcmk__request_t *request);
 194 void attrd_peer_sync_response(const pcmk__node_status_t *peer, bool peer_won,
 195                               xmlNode *xml);
 196 
 197 void attrd_send_protocol(const pcmk__node_status_t *peer);
 198 xmlNode *attrd_client_peer_remove(pcmk__request_t *request);
 199 xmlNode *attrd_client_clear_failure(pcmk__request_t *request);
 200 xmlNode *attrd_client_update(pcmk__request_t *request);
 201 xmlNode *attrd_client_refresh(pcmk__request_t *request);
 202 xmlNode *attrd_client_query(pcmk__request_t *request);
 203 gboolean attrd_send_message(const pcmk__node_status_t *node, xmlNode *data,
 204                             bool confirm);
 205 
 206 xmlNode *attrd_add_value_xml(xmlNode *parent, const attribute_t *a,
 207                              const attribute_value_t *v, bool force_write);
 208 void attrd_clear_value_seen(void);
 209 void attrd_free_attribute(gpointer data);
 210 void attrd_free_attribute_value(gpointer data);
 211 attribute_t *attrd_populate_attribute(xmlNode *xml, const char *attr);
 212 char *attrd_set_id(const attribute_t *attr, const char *node_state_id);
 213 char *attrd_nvpair_id(const attribute_t *attr, const char *node_state_id);
 214 
 215 enum attrd_write_options {
 216     attrd_write_changed         = 0,
 217     attrd_write_all             = (1 << 0),
 218     attrd_write_no_delay        = (1 << 1),
 219 };
 220 
 221 void attrd_write_attributes(uint32_t options);
 222 void attrd_write_or_elect_attribute(attribute_t *a);
 223 
 224 extern int minimum_protocol_version;
 225 void attrd_remove_peer_protocol_ver(const char *host);
 226 void attrd_update_minimum_protocol_ver(const char *host, const char *value);
 227 
 228 mainloop_timer_t *attrd_add_timer(const char *id, int timeout_ms, attribute_t *attr);
 229 
 230 void attrd_unregister_handlers(void);
 231 void attrd_handle_request(pcmk__request_t *request);
 232 
 233 enum attrd_sync_point {
 234     attrd_sync_point_local,
 235     attrd_sync_point_cluster,
 236 };
 237 
 238 typedef int (*attrd_confirmation_action_fn)(xmlNode *);
 239 
 240 void attrd_add_client_to_waitlist(pcmk__request_t *request);
 241 void attrd_ack_waitlist_clients(enum attrd_sync_point sync_point, const xmlNode *xml);
 242 int attrd_cluster_sync_point_update(xmlNode *xml);
 243 void attrd_do_not_expect_from_peer(const char *host);
 244 void attrd_do_not_wait_for_client(pcmk__client_t *client);
 245 void attrd_expect_confirmations(pcmk__request_t *request, attrd_confirmation_action_fn fn);
 246 void attrd_free_confirmations(void);
 247 void attrd_handle_confirmation(int callid, const char *host);
 248 void attrd_remove_client_from_waitlist(pcmk__client_t *client);
 249 const char *attrd_request_sync_point(xmlNode *xml);
 250 bool attrd_request_has_sync_point(xmlNode *xml);
 251 
 252 extern gboolean stand_alone;
 253 
 254 // Node utilities (from attrd_nodes.c)
 255 const char *attrd_get_node_xml_id(const char *node_name);
 256 void attrd_set_node_xml_id(const char *node_name, const char *node_xml_id);
 257 void attrd_forget_node_xml_id(const char *node_name);
 258 void attrd_cleanup_xml_ids(void);
 259 
 260 #endif /* PACEMAKER_ATTRD__H */

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