pacemaker  2.1.8-3980678f03
Scalable High-Availability cluster resource manager
cluster.h
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2024 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 PCMK__CRM_CLUSTER__H
11 # define PCMK__CRM_CLUSTER__H
12 
13 # include <stdint.h> // uint32_t, uint64_t
14 # include <glib.h> // gboolean, GHashTable
15 # include <libxml/tree.h> // xmlNode
16 # include <crm/common/xml.h>
17 # include <crm/common/util.h>
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 # if SUPPORT_COROSYNC
24 # include <corosync/cpg.h>
25 # endif
26 
27 // @COMPAT Make this internal when we can break API backward compatibility
29 extern gboolean crm_have_quorum;
30 
31 // @COMPAT Make this internal when we can break API backward compatibility
33 extern GHashTable *crm_peer_cache;
34 
35 // @COMPAT Make this internal when we can break API backward compatibility
37 extern GHashTable *crm_remote_peer_cache;
38 
39 // @COMPAT Make this internal when we can break API backward compatibility
41 extern unsigned long long crm_peer_seq;
42 
43 // @COMPAT Make this internal when we can break API backward compatibility
45 #define CRM_NODE_LOST "lost"
46 
47 // @COMPAT Make this internal when we can break API backward compatibility
49 #define CRM_NODE_MEMBER "member"
50 
51 // @COMPAT Make this internal when we can break API backward compatibility
55  /* @COMPAT: crm_join_nack_quiet can be replaced by crm_node_t:user_data
56  * at a compatibility break.
57  */
60 
67 };
69 
70 // @COMPAT Make this internal when we can break API backward compatibility
74  /* Node is not a cluster node and should not be considered for cluster
75  * membership
76  */
77  crm_remote_node = (1U << 0),
78 
79  // Node's cache entry is dirty
80  crm_node_dirty = (1U << 1),
81 };
83 
84 // @COMPAT Make this internal when we can break API backward compatibility
87 typedef struct crm_peer_node_s {
88  char *uname; // Node name as known to cluster
89 
90  /* @COMPAT This is less than ideal since the value is not a valid XML ID
91  * (for Corosync, it's the string equivalent of the node's numeric node ID,
92  * but XML IDs can't start with a number) and the three elements should have
93  * different IDs.
94  *
95  * Ideally, we would use something like node-NODEID, node_state-NODEID, and
96  * transient_attributes-NODEID as the element IDs. Unfortunately changing it
97  * would be impractical due to backward compatibility; older nodes in a
98  * rolling upgrade will always write and expect the value in the old format.
99  *
100  * This is also named poorly, since the value is not a UUID, but at least
101  * that can be changed at an API compatibility break.
102  */
107  char *uuid;
108 
109  char *state; // @TODO change to enum
110  uint64_t flags; // Bitmask of crm_node_flags
111  uint64_t last_seen; // Only needed by cluster nodes
112  uint32_t processes; // @TODO most not needed, merge into flags
113 
114  /* @TODO When we can break public API compatibility, we can make the rest of
115  * these members separate structs and use void *cluster_data and
116  * void *user_data here instead, to abstract the cluster layer further.
117  */
118 
119  // Currently only needed by corosync stack
120  uint32_t id; // Node ID
121  time_t when_lost; // When CPG membership was last lost
122 
123  // Only used by controller
125  char *expected;
126 
127  time_t peer_lost;
128  char *conn_host;
129 
130  time_t when_member; // Since when node has been a cluster member
131  time_t when_online; // Since when peer has been online in CPG
132 } crm_node_t;
134 
135 // Implementation of pcmk_cluster_t
136 // @COMPAT Make this internal when we can break API backward compatibility
140  char *uuid;
141  char *uname;
142  uint32_t nodeid;
143 
144  // NOTE: sbd (as of at least 1.5.2) uses this
146  void (*destroy) (gpointer);
147 
148 # if SUPPORT_COROSYNC
149  /* @TODO When we can break public API compatibility, make these members a
150  * separate struct and use void *cluster_data here instead, to abstract the
151  * cluster layer further.
152  */
153  struct cpg_name group;
154 
155  // NOTE: sbd (as of at least 1.5.2) uses this
160  cpg_callbacks_t cpg;
161 
162  cpg_handle_t cpg_handle;
163 # endif
164 
165 };
167 
170 
173 
175 void pcmk_cluster_free(pcmk_cluster_t *cluster);
176 
177 int pcmk_cluster_set_destroy_fn(pcmk_cluster_t *cluster, void (*fn)(gpointer));
178 #if SUPPORT_COROSYNC
179 int pcmk_cpg_set_deliver_fn(pcmk_cluster_t *cluster, cpg_deliver_fn_t fn);
180 int pcmk_cpg_set_confchg_fn(pcmk_cluster_t *cluster, cpg_confchg_fn_t fn);
181 #endif // SUPPORT_COROSYNC
182 
183 /* @COMPAT Make this internal when we can break API backward compatibility. Also
184  * evaluate whether we can drop this entirely. Since 2.0.0, we have sent only
185  * messages with crm_class_cluster.
186  */
191 };
193 
194 // @COMPAT Make this internal when we can break API backward compatibility
199  crm_msg_ais = 1, // Unused
204  crm_msg_stonithd = 6, // Unused
205  crm_msg_te = 7, // Unused
206  crm_msg_pe = 8, // Unused
208 };
210 
211 // @COMPAT Make this internal when we can break API backward compatibility
218 };
220 
229 };
230 
232 const char *pcmk_cluster_layer_text(enum pcmk_cluster_layer layer);
233 
234 /*
235  * \brief Get log-friendly string equivalent of a join phase
236  *
237  * \param[in] phase Join phase
238  *
239  * \return Log-friendly string equivalent of \p phase
240  */
242 static inline const char *
243 crm_join_phase_str(enum crm_join_phase phase)
244 {
245  switch (phase) {
246  case crm_join_nack_quiet: return "nack_quiet";
247  case crm_join_nack: return "nack";
248  case crm_join_none: return "none";
249  case crm_join_welcomed: return "welcomed";
250  case crm_join_integrated: return "integrated";
251  case crm_join_finalized: return "finalized";
252  case crm_join_confirmed: return "confirmed";
253  default: return "invalid";
254  }
255 }
256 
257 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
258 #include <crm/cluster/compat.h>
259 #endif
260 
261 #ifdef __cplusplus
262 }
263 #endif
264 
265 #endif
int pcmk_cluster_disconnect(pcmk_cluster_t *cluster)
Disconnect from the cluster layer.
Definition: cluster.c:154
struct crm_peer_node_s crm_node_t
pcmk_cluster_t * pcmk_cluster_new(void)
Allocate a new pcmk_cluster_t object.
Definition: cluster.c:186
crm_node_flags
Definition: cluster.h:73
crm_ais_msg_types
Definition: cluster.h:197
uint64_t flags
Definition: cluster.h:110
uint32_t nodeid
Definition: cluster.h:142
Corosync Cluster Engine.
Definition: cluster.h:228
enum crm_join_phase join
Definition: cluster.h:124
const char * pcmk_cluster_layer_text(enum pcmk_cluster_layer layer)
Get a log-friendly string equivalent of a cluster layer.
Definition: cluster.c:388
uint32_t id
Definition: cluster.h:120
gboolean crm_have_quorum
Definition: membership.c:68
char * uuid
Definition: cluster.h:107
crm_join_phase
Definition: cluster.h:54
void(* destroy)(gpointer)
Definition: cluster.h:146
GHashTable * crm_remote_peer_cache
Definition: membership.c:57
char * uuid
Definition: cluster.h:140
int pcmk_cluster_connect(pcmk_cluster_t *cluster)
Definition: cluster.c:123
void pcmk_cluster_free(pcmk_cluster_t *cluster)
Free a pcmk_cluster_t object and its dynamically allocated members.
Definition: cluster.c:197
uint32_t processes
Definition: cluster.h:112
Utility functions.
time_t when_lost
Definition: cluster.h:121
crm_status_type
Definition: cluster.h:214
int pcmk_cluster_set_destroy_fn(pcmk_cluster_t *cluster, void(*fn)(gpointer))
Set the destroy function for a cluster object.
Definition: cluster.c:216
time_t peer_lost
Definition: cluster.h:127
time_t when_member
Definition: cluster.h:130
int pcmk_cpg_set_deliver_fn(pcmk_cluster_t *cluster, cpg_deliver_fn_t fn)
Set the CPG deliver callback function for a cluster object.
Definition: cpg.c:794
Wrappers for and extensions to libxml2.
unsigned long long crm_peer_seq
Definition: membership.c:67
time_t when_online
Definition: cluster.h:131
int pcmk_cpg_set_confchg_fn(pcmk_cluster_t *cluster, cpg_confchg_fn_t fn)
Set the CPG config change callback function for a cluster object.
Definition: cpg.c:812
Deprecated Pacemaker cluster API.
char * expected
Definition: cluster.h:125
crm_ais_msg_class
Definition: cluster.h:189
char * uname
Definition: cluster.h:141
Invalid cluster layer.
Definition: cluster.h:227
char * conn_host
Definition: cluster.h:128
Not allowed to join, but don&#39;t send a nack message.
Definition: cluster.h:59
pcmk_cluster_layer
Types of cluster layer.
Definition: cluster.h:225
char * state
Definition: cluster.h:109
Unknown cluster layer.
Definition: cluster.h:226
char * uname
Definition: cluster.h:88
uint64_t last_seen
Definition: cluster.h:111
GHashTable * crm_peer_cache
Definition: membership.c:40
enum pcmk_cluster_layer pcmk_get_cluster_layer(void)
Get and validate the local cluster layer.
Definition: cluster.c:415