pacemaker  2.0.1-9e909a5bdd
Scalable High-Availability cluster resource manager
cluster.h
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2018 Andrew Beekhof <andrew@beekhof.net>
3  *
4  * This source code is licensed under the GNU Lesser General Public License
5  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
6  */
7 
8 #ifndef CRM_COMMON_CLUSTER__H
9 # define CRM_COMMON_CLUSTER__H
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 # include <crm/common/xml.h>
16 # include <crm/common/util.h>
17 
18 # if SUPPORT_COROSYNC
19 # include <corosync/cpg.h>
20 # endif
21 
22 extern gboolean crm_have_quorum;
23 extern GHashTable *crm_peer_cache;
24 extern GHashTable *crm_remote_peer_cache;
25 extern unsigned long long crm_peer_seq;
26 
27 /* *INDENT-OFF* */
28 #define CRM_NODE_LOST "lost"
29 #define CRM_NODE_MEMBER "member"
30 
32 {
39 };
40 
42 {
43  /* node is not a cluster node and should not be considered for cluster membership */
44  crm_remote_node = 0x0001,
45 
46  /* node's cache entry is dirty */
47  crm_node_dirty = 0x0010,
48 };
49 /* *INDENT-ON* */
50 
51 typedef struct crm_peer_node_s {
52  char *uname; // Node name as known to cluster
53  char *uuid; // Node UUID to ensure uniqueness
54  char *state; // @TODO change to enum
55  uint64_t flags; // Bitmask of crm_node_flags
56  uint64_t last_seen; // Only needed by cluster nodes
57  uint32_t processes; // @TODO most not needed, merge into flags
58 
59  // Currently only needed by corosync stack
60  uint32_t id; // Node ID
61  time_t when_lost; // When CPG membership was last lost
62 
63  // Only used by controller
65  char *expected;
66 } crm_node_t;
67 
68 void crm_peer_init(void);
69 void crm_peer_destroy(void);
70 
71 typedef struct crm_cluster_s {
72  char *uuid;
73  char *uname;
75 
76  void (*destroy) (gpointer);
77 
78 # if SUPPORT_COROSYNC
79  struct cpg_name group;
80  cpg_callbacks_t cpg;
81  cpg_handle_t cpg_handle;
82 # endif
83 
85 
86 gboolean crm_cluster_connect(crm_cluster_t * cluster);
88 
89 /* *INDENT-OFF* */
92 };
93 
105 };
106 
107 /* used with crm_get_peer_full */
112 };
113 /* *INDENT-ON* */
114 
115 gboolean send_cluster_message(crm_node_t * node, enum crm_ais_msg_types service,
116  xmlNode * data, gboolean ordered);
117 
118 
120 
121 /* Initialize and refresh the remote peer cache from a cib config */
122 void crm_remote_peer_cache_refresh(xmlNode *cib);
123 crm_node_t *crm_remote_peer_get(const char *node_name);
124 void crm_remote_peer_cache_remove(const char *node_name);
125 
126 /* allows filtering of remote and cluster nodes using crm_get_peer_flags */
127 crm_node_t *crm_get_peer_full(unsigned int id, const char *uname, int flags);
128 
129 /* only searches cluster nodes */
130 crm_node_t *crm_get_peer(unsigned int id, const char *uname);
131 
132 guint crm_active_peers(void);
133 gboolean crm_is_peer_active(const crm_node_t * node);
134 guint reap_crm_member(uint32_t id, const char *name);
135 int crm_terminate_member(int nodeid, const char *uname, void *unused);
136 int crm_terminate_member_no_mainloop(int nodeid, const char *uname, int *connection);
137 
138 # if SUPPORT_COROSYNC
139 uint32_t get_local_nodeid(cpg_handle_t handle);
140 
141 gboolean cluster_connect_cpg(crm_cluster_t *cluster);
142 void cluster_disconnect_cpg(crm_cluster_t * cluster);
143 
144 void pcmk_cpg_membership(cpg_handle_t handle,
145  const struct cpg_name *groupName,
146  const struct cpg_address *member_list, size_t member_list_entries,
147  const struct cpg_address *left_list, size_t left_list_entries,
148  const struct cpg_address *joined_list, size_t joined_list_entries);
149 gboolean crm_is_corosync_peer_active(const crm_node_t * node);
150 gboolean send_cluster_text(enum crm_ais_msg_class msg_class, const char *data,
151  gboolean local, crm_node_t * node,
152  enum crm_ais_msg_types dest);
153 char *pcmk_message_common_cs(cpg_handle_t handle, uint32_t nodeid, uint32_t pid, void *msg,
154  uint32_t *kind, const char **from);
155 # endif
156 
157 const char *crm_peer_uuid(crm_node_t *node);
158 const char *crm_peer_uname(const char *uuid);
159 void set_uuid(xmlNode *xml, const char *attr, crm_node_t *node);
160 
165 };
166 
167 enum crm_ais_msg_types text2msg_type(const char *text);
168 void crm_set_status_callback(void (*dispatch) (enum crm_status_type, crm_node_t *, const void *));
169 void crm_set_autoreap(gboolean autoreap);
170 
171 /* *INDENT-OFF* */
173 {
176  // 0x0004 was heartbeat
177  // 0x0010 was corosync 1 with plugin
179  // 0x0040 was corosync 1 with CMAN
180 };
181 /* *INDENT-ON* */
182 
184 const char *name_for_cluster_type(enum cluster_type_e type);
185 
186 gboolean is_corosync_cluster(void);
187 
188 const char *get_local_node_name(void);
189 char *get_node_name(uint32_t nodeid);
190 
191 static inline const char *
192 crm_join_phase_str(enum crm_join_phase phase)
193 {
194  switch (phase) {
195  case crm_join_nack: return "nack";
196  case crm_join_none: return "none";
197  case crm_join_welcomed: return "welcomed";
198  case crm_join_integrated: return "integrated";
199  case crm_join_finalized: return "finalized";
200  case crm_join_confirmed: return "confirmed";
201  }
202  return "invalid";
203 }
204 
205 #ifdef __cplusplus
206 }
207 #endif
208 
209 #endif
void crm_peer_destroy(void)
Definition: membership.c:406
struct crm_peer_node_s crm_node_t
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:441
crm_node_flags
Definition: cluster.h:41
crm_ais_msg_types
Definition: cluster.h:94
uint64_t flags
Definition: cluster.h:55
uint32_t nodeid
Definition: cluster.h:74
enum crm_join_phase join
Definition: cluster.h:64
uint32_t id
Definition: cluster.h:60
gboolean crm_is_peer_active(const crm_node_t *node)
Definition: membership.c:272
gboolean crm_have_quorum
Definition: membership.c:56
char * uuid
Definition: cluster.h:53
int crm_terminate_member(int nodeid, const char *uname, void *unused)
Definition: membership.c:1003
crm_join_phase
Definition: cluster.h:31
struct crm_cluster_s crm_cluster_t
void crm_set_autoreap(gboolean autoreap)
Tell the library whether to automatically reap lost nodes.
Definition: membership.c:458
const char * get_local_node_name(void)
Definition: cluster.c:118
void crm_peer_init(void)
Definition: membership.c:390
GHashTable * crm_remote_peer_cache
Definition: membership.c:51
crm_node_t * crm_get_peer(unsigned int id, const char *uname)
Definition: membership.c:653
char * uuid
Definition: cluster.h:72
guint crm_active_peers(void)
Definition: membership.c:365
uint32_t pid
Definition: internal.h:81
char * get_node_name(uint32_t nodeid)
Definition: cluster.c:130
void crm_cluster_disconnect(crm_cluster_t *cluster)
Definition: cluster.c:81
gboolean send_cluster_text(enum crm_ais_msg_class msg_class, const char *data, gboolean local, crm_node_t *node, enum crm_ais_msg_types dest)
Definition: cpg.c:490
char * pcmk_message_common_cs(cpg_handle_t handle, uint32_t nodeid, uint32_t pid, void *content, uint32_t *kind, const char **from)
Definition: cpg.c:214
crm_node_t * crm_get_peer_full(unsigned int id, const char *uname, int flags)
Definition: membership.c:503
gboolean crm_is_corosync_peer_active(const crm_node_t *node)
Definition: corosync.c:470
void cluster_disconnect_cpg(crm_cluster_t *cluster)
Definition: cpg.c:47
uint32_t processes
Definition: cluster.h:57
enum crm_ais_msg_types text2msg_type(const char *text)
Definition: cpg.c:616
void crm_remote_peer_cache_remove(const char *node_name)
Definition: membership.c:120
Utility functions.
time_t when_lost
Definition: cluster.h:61
cluster_type_e
Definition: cluster.h:172
crm_status_type
Definition: cluster.h:161
Wrappers for and extensions to libxml2.
unsigned long long crm_peer_seq
Definition: membership.c:55
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:324
const char * name_for_cluster_type(enum cluster_type_e type)
Definition: cluster.c:234
gboolean crm_cluster_connect(crm_cluster_t *cluster)
Definition: cluster.c:59
char * expected
Definition: cluster.h:65
gboolean is_corosync_cluster(void)
Definition: cluster.c:328
crm_ais_msg_class
Definition: cluster.h:90
char * uname
Definition: cluster.h:73
uint32_t get_local_nodeid(cpg_handle_t handle)
Definition: cpg.c:61
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:80
const char * crm_peer_uname(const char *uuid)
Get the node name corresponding to a node UUID.
Definition: cluster.c:176
#define uint32_t
Definition: stdint.in.h:158
char data[0]
Definition: internal.h:90
char * state
Definition: cluster.h:54
char * uname
Definition: cluster.h:52
uint64_t last_seen
Definition: cluster.h:56
void set_uuid(xmlNode *xml, const char *attr, crm_node_t *node)
Definition: cluster.c:225
int crm_terminate_member_no_mainloop(int nodeid, const char *uname, int *connection)
Definition: membership.c:1010
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)
Definition: cpg.c:329
gboolean send_cluster_message(crm_node_t *node, enum crm_ais_msg_types service, xmlNode *data, gboolean ordered)
Definition: cluster.c:102
void crm_remote_peer_cache_refresh(xmlNode *cib)
Repopulate the remote peer cache based on CIB XML.
Definition: membership.c:234
GHashTable * crm_peer_cache
Definition: membership.c:34
const char * crm_peer_uuid(crm_node_t *node)
Definition: cluster.c:28
gboolean cluster_connect_cpg(crm_cluster_t *cluster)
Definition: cpg.c:404
enum crm_ais_msg_types type
Definition: internal.h:83
enum cluster_type_e get_cluster_type(void)
Definition: cluster.c:273
crm_get_peer_flags
Definition: cluster.h:108
int crm_remote_peer_cache_size(void)
Definition: membership.c:60
gboolean local
Definition: internal.h:82