pacemaker  1.1.18-7fdfbbe
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
cluster.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2004 Andrew Beekhof <andrew@beekhof.net>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This software is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 #ifndef CRM_COMMON_CLUSTER__H
19 # define CRM_COMMON_CLUSTER__H
20 
21 # include <crm/common/xml.h>
22 # include <crm/common/util.h>
23 
24 # if SUPPORT_HEARTBEAT
25 # include <heartbeat/hb_api.h>
26 # include <ocf/oc_event.h>
27 # endif
28 
29 # if SUPPORT_COROSYNC
30 # include <corosync/cpg.h>
31 # endif
32 
33 extern gboolean crm_have_quorum;
34 extern GHashTable *crm_peer_cache;
35 extern GHashTable *crm_remote_peer_cache;
36 extern unsigned long long crm_peer_seq;
37 
38 # ifndef CRM_SERVICE
39 # define CRM_SERVICE PCMK_SERVICE_ID
40 # endif
41 
42 /* *INDENT-OFF* */
43 #define CRM_NODE_LOST "lost"
44 #define CRM_NODE_MEMBER "member"
45 #define CRM_NODE_ACTIVE CRM_NODE_MEMBER
46 #define CRM_NODE_EVICTED "evicted"
47 
49 {
56 };
57 
59 {
60  /* node is not a cluster node and should not be considered for cluster membership */
61  crm_remote_node = 0x0001,
62 
63  /* deprecated (not used by cluster) */
66 
67  /* node's cache entry is dirty */
68  crm_node_dirty = 0x0010,
69 };
70 /* *INDENT-ON* */
71 
72 typedef struct crm_peer_node_s {
73  uint32_t id; /* Only used by corosync derivatives */
74  uint64_t born; /* Only used by heartbeat and the legacy plugin */
75  uint64_t last_seen;
76  uint64_t flags; /* Specified by crm_node_flags enum */
77 
78  int32_t votes; /* Only used by the legacy plugin */
81 
82  char *uname;
83  char *uuid;
84  char *state;
85  char *expected;
86 
87  char *addr; /* Only used by the legacy plugin */
88  char *version; /* Unused */
89 } crm_node_t;
90 
91 void crm_peer_init(void);
92 void crm_peer_destroy(void);
93 
94 typedef struct crm_cluster_s {
95  char *uuid;
96  char *uname;
98 
99  void (*destroy) (gpointer);
100 
101 # if SUPPORT_HEARTBEAT
102  ll_cluster_t *hb_conn;
103  void (*hb_dispatch) (HA_Message * msg, void *private);
104 # endif
105 
106 # if SUPPORT_COROSYNC
107  struct cpg_name group;
108  cpg_callbacks_t cpg;
109  cpg_handle_t cpg_handle;
110 # endif
111 
112 } crm_cluster_t;
113 
114 gboolean crm_cluster_connect(crm_cluster_t * cluster);
115 void crm_cluster_disconnect(crm_cluster_t * cluster);
116 
117 /* *INDENT-OFF* */
125 };
126 
127 /* order here matters - it's used to index into the crm_children array */
139 };
140 
141 /* used with crm_get_peer_full */
146 };
147 /* *INDENT-ON* */
148 
149 gboolean send_cluster_message(crm_node_t * node, enum crm_ais_msg_types service,
150  xmlNode * data, gboolean ordered);
151 
152 
154 
155 /* Initialize and refresh the remote peer cache from a cib config */
156 void crm_remote_peer_cache_refresh(xmlNode *cib);
157 void crm_remote_peer_cache_add(const char *node_name);
158 crm_node_t *crm_remote_peer_get(const char *node_name);
159 void crm_remote_peer_cache_remove(const char *node_name);
160 
161 /* allows filtering of remote and cluster nodes using crm_get_peer_flags */
162 crm_node_t *crm_get_peer_full(unsigned int id, const char *uname, int flags);
163 
164 /* only searches cluster nodes */
165 crm_node_t *crm_get_peer(unsigned int id, const char *uname);
166 
167 guint crm_active_peers(void);
168 gboolean crm_is_peer_active(const crm_node_t * node);
169 guint reap_crm_member(uint32_t id, const char *name);
170 int crm_terminate_member(int nodeid, const char *uname, void *unused);
171 int crm_terminate_member_no_mainloop(int nodeid, const char *uname, int *connection);
172 
173 # if SUPPORT_HEARTBEAT
174 gboolean crm_is_heartbeat_peer_active(const crm_node_t * node);
175 # endif
176 
177 # if SUPPORT_COROSYNC
178 extern int ais_fd_sync;
179 uint32_t get_local_nodeid(cpg_handle_t handle);
180 
181 gboolean cluster_connect_cpg(crm_cluster_t *cluster);
182 void cluster_disconnect_cpg(crm_cluster_t * cluster);
183 
184 void pcmk_cpg_membership(cpg_handle_t handle,
185  const struct cpg_name *groupName,
186  const struct cpg_address *member_list, size_t member_list_entries,
187  const struct cpg_address *left_list, size_t left_list_entries,
188  const struct cpg_address *joined_list, size_t joined_list_entries);
189 gboolean crm_is_corosync_peer_active(const crm_node_t * node);
190 gboolean send_cluster_text(int class, const char *data, gboolean local,
191  crm_node_t * node, enum crm_ais_msg_types dest);
192 # endif
193 
194 const char *crm_peer_uuid(crm_node_t *node);
195 const char *crm_peer_uname(const char *uuid);
196 void set_uuid(xmlNode *xml, const char *attr, crm_node_t *node);
197 
202  crm_status_rstate, /* remote node state */
203 };
204 
205 enum crm_ais_msg_types text2msg_type(const char *text);
206 void crm_set_status_callback(void (*dispatch) (enum crm_status_type, crm_node_t *, const void *));
207 void crm_set_autoreap(gboolean autoreap);
208 
209 /* *INDENT-OFF* */
211 {
218 };
219 /* *INDENT-ON* */
220 
222 const char *name_for_cluster_type(enum cluster_type_e type);
223 
224 gboolean is_corosync_cluster(void);
225 gboolean is_cman_cluster(void);
226 gboolean is_openais_cluster(void);
227 gboolean is_classic_ais_cluster(void);
228 gboolean is_heartbeat_cluster(void);
229 
230 const char *get_local_node_name(void);
231 char *get_node_name(uint32_t nodeid);
232 
233 # if SUPPORT_COROSYNC
234 char *pcmk_message_common_cs(cpg_handle_t handle, uint32_t nodeid, uint32_t pid, void *msg,
235  uint32_t *kind, const char **from);
236 # endif
237 
238 static inline const char *
239 crm_join_phase_str(enum crm_join_phase phase)
240 {
241  switch (phase) {
242  case crm_join_nack: return "nack";
243  case crm_join_none: return "none";
244  case crm_join_welcomed: return "welcomed";
245  case crm_join_integrated: return "integrated";
246  case crm_join_finalized: return "finalized";
247  case crm_join_confirmed: return "confirmed";
248  }
249  return "invalid";
250 }
251 
252 #endif
void crm_peer_destroy(void)
Definition: membership.c:431
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:459
gboolean is_openais_cluster(void)
Definition: cluster.c:630
crm_node_flags
Definition: cluster.h:58
crm_ais_msg_types
Definition: cluster.h:128
uint64_t flags
Definition: cluster.h:76
uint32_t nodeid
Definition: cluster.h:97
enum crm_join_phase join
Definition: cluster.h:80
uint32_t id
Definition: cluster.h:73
gboolean is_heartbeat_cluster(void)
Definition: cluster.c:645
gboolean crm_is_peer_active(const crm_node_t *node)
Definition: membership.c:295
gboolean crm_have_quorum
Definition: membership.c:65
uint64_t born
Definition: cluster.h:74
char * uuid
Definition: cluster.h:83
int crm_terminate_member(int nodeid, const char *uname, void *unused)
Definition: membership.c:1115
crm_join_phase
Definition: cluster.h:48
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:476
const char * get_local_node_name(void)
Definition: cluster.c:289
void crm_peer_init(void)
Definition: membership.c:419
void(* destroy)(gpointer)
Definition: cluster.h:99
GHashTable * crm_remote_peer_cache
Definition: membership.c:62
char * addr
Definition: cluster.h:87
void crm_remote_peer_cache_add(const char *node_name)
Add a node to the remote peer cache.
Definition: membership.c:137
crm_node_t * crm_get_peer(unsigned int id, const char *uname)
Definition: membership.c:676
char * uuid
Definition: cluster.h:95
guint crm_active_peers(void)
Definition: membership.c:393
uint32_t pid
Definition: internal.h:49
enum crm_ais_msg_types text2msg_type(const char *text)
Definition: cpg.c:652
char * get_node_name(uint32_t nodeid)
Definition: cluster.c:301
void crm_cluster_disconnect(crm_cluster_t *cluster)
Definition: cluster.c:234
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:233
crm_node_t * crm_get_peer_full(unsigned int id, const char *uname, int flags)
Definition: membership.c:521
gboolean crm_is_corosync_peer_active(const crm_node_t *node)
Definition: corosync.c:468
void cluster_disconnect_cpg(crm_cluster_t *cluster)
Definition: cpg.c:58
char uname[MAX_NAME]
Definition: internal.h:53
uint32_t processes
Definition: cluster.h:79
int ais_fd_sync
Definition: legacy.c:49
void crm_remote_peer_cache_remove(const char *node_name)
Definition: membership.c:143
Utility functions.
cluster_type_e
Definition: cluster.h:210
crm_status_type
Definition: cluster.h:198
Wrappers for and extensions to libxml2.
gboolean send_cluster_text(int class, const char *data, gboolean local, crm_node_t *node, enum crm_ais_msg_types dest)
Definition: cpg.c:521
unsigned long long crm_peer_seq
Definition: membership.c:64
gboolean is_cman_cluster(void)
Definition: cluster.c:612
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:352
const char * name_for_cluster_type(enum cluster_type_e type)
Definition: cluster.c:468
gboolean crm_cluster_connect(crm_cluster_t *cluster)
Definition: cluster.c:175
char * version
Definition: cluster.h:88
char * expected
Definition: cluster.h:85
gboolean is_corosync_cluster(void)
Definition: cluster.c:618
crm_ais_msg_class
Definition: cluster.h:118
char * uname
Definition: cluster.h:96
uint32_t get_local_nodeid(cpg_handle_t handle)
Definition: cpg.c:72
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:89
const char * crm_peer_uname(const char *uuid)
Get the node name corresponding to a node UUID.
Definition: cluster.c:375
#define uint32_t
Definition: stdint.in.h:158
char data[0]
Definition: internal.h:58
char * state
Definition: cluster.h:84
int32_t votes
Definition: cluster.h:78
char * uname
Definition: cluster.h:82
uint64_t last_seen
Definition: cluster.h:75
void set_uuid(xmlNode *xml, const char *attr, crm_node_t *node)
Definition: cluster.c:459
int crm_terminate_member_no_mainloop(int nodeid, const char *uname, int *connection)
Definition: membership.c:1122
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:363
gboolean send_cluster_message(crm_node_t *node, enum crm_ais_msg_types service, xmlNode *data, gboolean ordered)
Definition: cluster.c:271
void crm_remote_peer_cache_refresh(xmlNode *cib)
Repopulate the remote peer cache based on CIB XML.
Definition: membership.c:257
GHashTable * crm_peer_cache
Definition: membership.c:44
const char * crm_peer_uuid(crm_node_t *node)
Definition: cluster.c:135
uint64_t flags
Definition: remote.c:156
gboolean cluster_connect_cpg(crm_cluster_t *cluster)
Definition: cpg.c:436
gboolean is_classic_ais_cluster(void)
Definition: cluster.c:624
enum crm_ais_msg_types type
Definition: internal.h:51
#define int32_t
Definition: stdint.in.h:157
enum cluster_type_e get_cluster_type(void)
Definition: cluster.c:513
crm_get_peer_flags
Definition: cluster.h:142
int crm_remote_peer_cache_size(void)
Definition: membership.c:69
gboolean local
Definition: internal.h:50