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
28 //! \deprecated Do not use (public access will be removed in a future release)
29 extern gboolean crm_have_quorum;
30
31 // @COMPAT Make this internal when we can break API backward compatibility
32 //! \deprecated Do not use (public access will be removed in a future release)
33 extern GHashTable *crm_peer_cache;
34
35 // @COMPAT Make this internal when we can break API backward compatibility
36 //! \deprecated Do not use (public access will be removed in a future release)
37 extern GHashTable *crm_remote_peer_cache;
38
39 // @COMPAT Make this internal when we can break API backward compatibility
40 //! \deprecated Do not use (public access will be removed in a future release)
41 extern unsigned long long crm_peer_seq;
42
43 // @COMPAT Make this internal when we can break API backward compatibility
44 //! \deprecated Do not use (public access will be removed in a future release)
45 #define CRM_NODE_LOST "lost"
46
47 // @COMPAT Make this internal when we can break API backward compatibility
48 //! \deprecated Do not use (public access will be removed in a future release)
49 #define CRM_NODE_MEMBER "member"
50
51 // @COMPAT Make this internal when we can break API backward compatibility
52 //!@{
53 //! \deprecated Do not use (public access will be removed in a future release)
54 enum crm_join_phase {
55 /* @COMPAT: crm_join_nack_quiet can be replaced by crm_node_t:user_data
56 * at a compatibility break.
57 */
58 //! Not allowed to join, but don't send a nack message
59 crm_join_nack_quiet = -2,
60
61 crm_join_nack = -1,
62 crm_join_none = 0,
63 crm_join_welcomed = 1,
64 crm_join_integrated = 2,
65 crm_join_finalized = 3,
66 crm_join_confirmed = 4,
67 };
68 //!@}
69
70 // @COMPAT Make this internal when we can break API backward compatibility
71 //!@{
72 //! \deprecated Do not use (public access will be removed in a future release)
73 enum crm_node_flags {
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 };
82 //!@}
83
84 // @COMPAT Make this internal when we can break API backward compatibility
85 //!@{
86 //! \deprecated Do not use (public access will be removed in a future release)
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 */
103 /*! Value of the PCMK_XA_ID XML attribute to use with the node's
104 * PCMK_XE_NODE, PCMK_XE_NODE_STATE, and PCMK_XE_TRANSIENT_ATTRIBUTES
105 * XML elements in the CIB
106 */
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
124 enum crm_join_phase join;
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;
133 //!@}
134
135 // Implementation of pcmk_cluster_t
136 // @COMPAT Make this internal when we can break API backward compatibility
137 //!@{
138 //! \deprecated Do not use (public access will be removed in a future release)
139 struct crm_cluster_s {
140 char *uuid;
141 char *uname;
142 uint32_t nodeid;
143
144 // NOTE: sbd (as of at least 1.5.2) uses this
145 //! \deprecated Call pcmk_cluster_set_destroy_fn() to set 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
156 /*!
157 * \deprecated Call pcmk_cpg_set_deliver_fn() and pcmk_cpg_set_confchg_fn()
158 * to set these
159 */
160 cpg_callbacks_t cpg;
161
162 cpg_handle_t cpg_handle;
163 # endif
164
165 };
166 //!@}
167
168 //! Connection to a cluster layer
169 typedef struct crm_cluster_s pcmk_cluster_t;
170
171 int pcmk_cluster_connect(pcmk_cluster_t *cluster);
172 int pcmk_cluster_disconnect(pcmk_cluster_t *cluster);
173
174 pcmk_cluster_t *pcmk_cluster_new(void);
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 */
187 //!@{
188 //! \deprecated Do not use (public access will be removed in a future release)
189 enum crm_ais_msg_class {
190 crm_class_cluster = 0,
191 };
192 //!@}
193
194 // @COMPAT Make this internal when we can break API backward compatibility
195 //!@{
196 //! \deprecated Do not use (public access will be removed in a future release)
197 enum crm_ais_msg_types {
198 crm_msg_none = 0,
199 crm_msg_ais = 1, // Unused
200 crm_msg_lrmd = 2,
201 crm_msg_cib = 3,
202 crm_msg_crmd = 4,
203 crm_msg_attrd = 5,
204 crm_msg_stonithd = 6, // Unused
205 crm_msg_te = 7, // Unused
206 crm_msg_pe = 8, // Unused
207 crm_msg_stonith_ng = 9,
208 };
209 //!@}
210
211 // @COMPAT Make this internal when we can break API backward compatibility
212 //!@{
213 //! \deprecated Do not use (public access will be removed in a future release)
214 enum crm_status_type {
215 crm_status_uname,
216 crm_status_nstate,
217 crm_status_processes,
218 };
219 //!@}
220
221 /*!
222 * \enum pcmk_cluster_layer
223 * \brief Types of cluster layer
224 */
225 enum pcmk_cluster_layer {
226 pcmk_cluster_layer_unknown = 1, //!< Unknown cluster layer
227 pcmk_cluster_layer_invalid = 2, //!< Invalid cluster layer
228 pcmk_cluster_layer_corosync = 32, //!< Corosync Cluster Engine
229 };
230
231 enum pcmk_cluster_layer pcmk_get_cluster_layer(void);
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 */
241 //! \deprecated Do not use (public access will be removed in a future release)
242 static inline const char *
243 crm_join_phase_str(enum crm_join_phase phase)
/* ![[previous]](../icons/n_left.png)
![[next]](../icons/n_right.png)
![[first]](../icons/n_first.png)
![[last]](../icons/n_last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
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