pacemaker 2.1.6-6fdc9deea29
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
cluster.h
Go to the documentation of this file.
1/*
2 * Copyright 2004-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 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
20extern "C" {
21#endif
22
23# if SUPPORT_COROSYNC
24# include <corosync/cpg.h>
25# endif
26
27extern gboolean crm_have_quorum;
28extern GHashTable *crm_peer_cache;
29extern GHashTable *crm_remote_peer_cache;
30extern unsigned long long crm_peer_seq;
31
32#define CRM_NODE_LOST "lost"
33#define CRM_NODE_MEMBER "member"
34
36 /* @COMPAT: crm_join_nack_quiet can be replaced by crm_node_t:user_data
37 * at a compatibility break.
38 */
41
48};
49
51 /* node is not a cluster node and should not be considered for cluster membership */
53
54 /* node's cache entry is dirty */
56};
57
58typedef struct crm_peer_node_s {
59 char *uname; // Node name as known to cluster
60 char *uuid; // Node UUID to ensure uniqueness
61 char *state; // @TODO change to enum
62 uint64_t flags; // Bitmask of crm_node_flags
63 uint64_t last_seen; // Only needed by cluster nodes
64 uint32_t processes; // @TODO most not needed, merge into flags
65
66 /* @TODO When we can break public API compatibility, we can make the rest of
67 * these members separate structs and use void *cluster_data and
68 * void *user_data here instead, to abstract the cluster layer further.
69 */
70
71 // Currently only needed by corosync stack
72 uint32_t id; // Node ID
73 time_t when_lost; // When CPG membership was last lost
74
75 // Only used by controller
77 char *expected;
78
79 time_t peer_lost;
80 char *conn_host;
82
83void crm_peer_init(void);
84void crm_peer_destroy(void);
85
86typedef struct crm_cluster_s {
87 char *uuid;
88 char *uname;
89 uint32_t nodeid;
90
91 void (*destroy) (gpointer);
92
93# if SUPPORT_COROSYNC
94 /* @TODO When we can break public API compatibility, make these members a
95 * separate struct and use void *cluster_data here instead, to abstract the
96 * cluster layer further.
97 */
98 struct cpg_name group;
99 cpg_callbacks_t cpg;
100 cpg_handle_t cpg_handle;
101# endif
102
104
105gboolean crm_cluster_connect(crm_cluster_t *cluster);
107
109void pcmk_cluster_free(crm_cluster_t *cluster);
110
114
127
128/* used with crm_get_peer_full */
134
135gboolean send_cluster_message(const crm_node_t *node,
136 enum crm_ais_msg_types service, xmlNode *data,
137 gboolean ordered);
138
140
141/* Initialize and refresh the remote peer cache from a cib config */
142void crm_remote_peer_cache_refresh(xmlNode *cib);
143crm_node_t *crm_remote_peer_get(const char *node_name);
144void crm_remote_peer_cache_remove(const char *node_name);
145
146/* allows filtering of remote and cluster nodes using crm_get_peer_flags */
147crm_node_t *crm_get_peer_full(unsigned int id, const char *uname, int flags);
148
149/* only searches cluster nodes */
150crm_node_t *crm_get_peer(unsigned int id, const char *uname);
151
152guint crm_active_peers(void);
153gboolean crm_is_peer_active(const crm_node_t * node);
154guint reap_crm_member(uint32_t id, const char *name);
155
156# if SUPPORT_COROSYNC
157uint32_t get_local_nodeid(cpg_handle_t handle);
158
159gboolean cluster_connect_cpg(crm_cluster_t *cluster);
161
162void pcmk_cpg_membership(cpg_handle_t handle,
163 const struct cpg_name *groupName,
164 const struct cpg_address *member_list, size_t member_list_entries,
165 const struct cpg_address *left_list, size_t left_list_entries,
166 const struct cpg_address *joined_list, size_t joined_list_entries);
167gboolean crm_is_corosync_peer_active(const crm_node_t * node);
168gboolean send_cluster_text(enum crm_ais_msg_class msg_class, const char *data,
169 gboolean local, const crm_node_t *node,
170 enum crm_ais_msg_types dest);
171char *pcmk_message_common_cs(cpg_handle_t handle, uint32_t nodeid, uint32_t pid, void *msg,
172 uint32_t *kind, const char **from);
173# endif
174
175const char *crm_peer_uuid(crm_node_t *node);
176const char *crm_peer_uname(const char *uuid);
177void set_uuid(xmlNode *xml, const char *attr, crm_node_t *node);
178
184
185enum crm_ais_msg_types text2msg_type(const char *text);
186void crm_set_status_callback(void (*dispatch) (enum crm_status_type, crm_node_t *, const void *));
187void crm_set_autoreap(gboolean autoreap);
188
192 // 0x0004 was heartbeat
193 // 0x0010 was corosync 1 with plugin
195 // 0x0040 was corosync 1 with CMAN
196};
197
200
201gboolean is_corosync_cluster(void);
202
203const char *get_local_node_name(void);
204char *get_node_name(uint32_t nodeid);
205
213static inline const char *
214crm_join_phase_str(enum crm_join_phase phase)
215{
216 switch (phase) {
217 case crm_join_nack_quiet: return "nack_quiet";
218 case crm_join_nack: return "nack";
219 case crm_join_none: return "none";
220 case crm_join_welcomed: return "welcomed";
221 case crm_join_integrated: return "integrated";
222 case crm_join_finalized: return "finalized";
223 case crm_join_confirmed: return "confirmed";
224 default: return "invalid";
225 }
226}
227
228#if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
229#include <crm/cluster/compat.h>
230#endif
231
232#ifdef __cplusplus
233}
234#endif
235
236#endif
const char * name
Definition cib.c:24
gboolean crm_have_quorum
Definition membership.c:64
crm_cluster_t * pcmk_cluster_new(void)
Allocate a new crm_cluster_t object.
Definition cluster.c:127
gboolean is_corosync_cluster(void)
Check whether the local cluster is a Corosync cluster.
Definition cluster.c:402
gboolean crm_cluster_connect(crm_cluster_t *cluster)
Connect to the cluster layer.
Definition cluster.c:75
int crm_remote_peer_cache_size(void)
Definition membership.c:87
GHashTable * crm_peer_cache
Definition membership.c:36
void set_uuid(xmlNode *xml, const char *attr, crm_node_t *node)
Add a node's UUID as an XML attribute.
Definition cluster.c:304
void crm_remote_peer_cache_refresh(xmlNode *cib)
Repopulate the remote peer cache based on CIB XML.
Definition membership.c:243
crm_ais_msg_types
Definition cluster.h:115
@ crm_msg_stonithd
Definition cluster.h:122
@ crm_msg_none
Definition cluster.h:116
@ crm_msg_cib
Definition cluster.h:119
@ crm_msg_pe
Definition cluster.h:124
@ crm_msg_attrd
Definition cluster.h:121
@ crm_msg_ais
Definition cluster.h:117
@ crm_msg_te
Definition cluster.h:123
@ crm_msg_stonith_ng
Definition cluster.h:125
@ crm_msg_crmd
Definition cluster.h:120
@ crm_msg_lrmd
Definition cluster.h:118
const char * get_local_node_name(void)
Get the local node's name.
Definition cluster.c:184
void crm_cluster_disconnect(crm_cluster_t *cluster)
Disconnect from the cluster layer.
Definition cluster.c:101
guint reap_crm_member(uint32_t id, const char *name)
Remove all peer cache entries matching a node ID and/or uname.
Definition membership.c:333
const char * crm_peer_uuid(crm_node_t *node)
Get (and set if needed) a node's UUID.
Definition cluster.c:38
crm_join_phase
Definition cluster.h:35
@ crm_join_nack_quiet
Not allowed to join, but don't send a nack message.
Definition cluster.h:40
@ crm_join_none
Definition cluster.h:43
@ crm_join_welcomed
Definition cluster.h:44
@ crm_join_nack
Definition cluster.h:42
@ crm_join_finalized
Definition cluster.h:46
@ crm_join_integrated
Definition cluster.h:45
@ crm_join_confirmed
Definition cluster.h:47
enum cluster_type_e get_cluster_type(void)
Get (and validate) the local cluster type.
Definition cluster.c:338
void crm_set_autoreap(gboolean autoreap)
Tell the library whether to automatically reap lost nodes.
Definition membership.c:470
void crm_set_status_callback(void(*dispatch)(enum crm_status_type, crm_node_t *, const void *))
Set a client function that will be called after peer status changes.
Definition membership.c:453
crm_node_t * crm_get_peer(unsigned int id, const char *uname)
Get a cluster node cache entry.
Definition membership.c:701
const char * crm_peer_uname(const char *uuid)
Get the node name corresponding to a node UUID.
Definition cluster.c:250
crm_node_t * crm_get_peer_full(unsigned int id, const char *uname, int flags)
Get a node cache entry (cluster or Pacemaker Remote)
Definition membership.c:533
char * get_node_name(uint32_t nodeid)
Get the node name corresponding to a cluster node ID.
Definition cluster.c:204
const char * name_for_cluster_type(enum cluster_type_e type)
Get a log-friendly string equivalent of a cluster type.
Definition cluster.c:317
GHashTable * crm_remote_peer_cache
Definition membership.c:53
void crm_remote_peer_cache_remove(const char *node_name)
Definition membership.c:147
cluster_type_e
Definition cluster.h:189
@ pcmk_cluster_unknown
Definition cluster.h:190
@ pcmk_cluster_invalid
Definition cluster.h:191
@ pcmk_cluster_corosync
Definition cluster.h:194
struct crm_cluster_s crm_cluster_t
struct crm_peer_node_s crm_node_t
crm_get_peer_flags
Definition cluster.h:129
@ CRM_GET_PEER_CLUSTER
Definition cluster.h:130
@ CRM_GET_PEER_ANY
Definition cluster.h:132
@ CRM_GET_PEER_REMOTE
Definition cluster.h:131
unsigned long long crm_peer_seq
Definition membership.c:63
enum crm_ais_msg_types text2msg_type(const char *text)
Get the message type equivalent of a string.
Definition cpg.c:1055
gboolean crm_is_peer_active(const crm_node_t *node)
Definition membership.c:281
crm_ais_msg_class
Definition cluster.h:111
@ crm_class_cluster
Definition cluster.h:112
void crm_peer_init(void)
Definition membership.c:400
crm_node_flags
Definition cluster.h:50
@ crm_remote_node
Definition cluster.h:52
@ crm_node_dirty
Definition cluster.h:55
void crm_peer_destroy(void)
Definition membership.c:416
gboolean send_cluster_message(const crm_node_t *node, enum crm_ais_msg_types service, xmlNode *data, gboolean ordered)
Send an XML message via the cluster messaging layer.
Definition cluster.c:162
guint crm_active_peers(void)
Definition membership.c:374
crm_node_t * crm_remote_peer_get(const char *node_name)
Get a remote node peer cache entry, creating it if necessary.
Definition membership.c:107
crm_status_type
Definition cluster.h:179
@ crm_status_processes
Definition cluster.h:182
@ crm_status_nstate
Definition cluster.h:181
@ crm_status_uname
Definition cluster.h:180
void pcmk_cluster_free(crm_cluster_t *cluster)
Free a crm_cluster_t object and its dynamically allocated members.
Definition cluster.c:141
uint64_t flags
Definition remote.c:3
Utility functions.
Deprecated Pacemaker cluster API.
gboolean crm_is_corosync_peer_active(const crm_node_t *node)
Check whether a Corosync cluster peer is active.
Definition corosync.c:531
gboolean send_cluster_text(enum crm_ais_msg_class msg_class, const char *data, gboolean local, const crm_node_t *node, enum crm_ais_msg_types dest)
Definition cpg.c:917
void pcmk_cpg_membership(cpg_handle_t handle, const struct cpg_name *groupName, const struct cpg_address *member_list, size_t member_list_entries, const struct cpg_address *left_list, size_t left_list_entries, const struct cpg_address *joined_list, size_t joined_list_entries)
Handle a CPG configuration change event.
Definition cpg.c:687
void cluster_disconnect_cpg(crm_cluster_t *cluster)
Disconnect from Corosync CPG.
Definition cpg.c:95
enum crm_ais_msg_types type
Definition cpg.c:3
char uname[MAX_NAME]
Definition cpg.c:5
char data[0]
Definition cpg.c:10
uint32_t get_local_nodeid(cpg_handle_t handle)
Get the local Corosync node ID (via CPG)
Definition cpg.c:117
gboolean local
Definition cpg.c:2
char * pcmk_message_common_cs(cpg_handle_t handle, uint32_t nodeid, uint32_t pid, void *content, uint32_t *kind, const char **from)
Extract text data from a Corosync CPG message.
Definition cpg.c:441
uint32_t pid
Definition cpg.c:1
gboolean cluster_connect_cpg(crm_cluster_t *cluster)
Connect to Corosync CPG.
Definition cpg.c:785
uint32_t nodeid
Definition cluster.h:89
char * uuid
Definition cluster.h:87
char * uname
Definition cluster.h:88
void(* destroy)(gpointer)
Definition cluster.h:91
uint32_t processes
Definition cluster.h:64
char * uname
Definition cluster.h:59
char * expected
Definition cluster.h:77
char * conn_host
Definition cluster.h:80
uint64_t last_seen
Definition cluster.h:63
time_t peer_lost
Definition cluster.h:79
uint32_t id
Definition cluster.h:72
char * state
Definition cluster.h:61
char * uuid
Definition cluster.h:60
time_t when_lost
Definition cluster.h:73
uint64_t flags
Definition cluster.h:62
enum crm_join_phase join
Definition cluster.h:76
Wrappers for and extensions to libxml2.