pacemaker  2.0.5-ba59be712
Scalable High-Availability cluster resource manager
cluster.h
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2018 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 CRM_COMMON_CLUSTER__H
11 # define CRM_COMMON_CLUSTER__H
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 # include <stdint.h> // uint32_t, uint64_t
18 # include <glib.h> // gboolean, GHashTable
19 # include <libxml/tree.h> // xmlNode
20 # include <crm/common/xml.h>
21 # include <crm/common/util.h>
22 
23 # if SUPPORT_COROSYNC
24 # include <corosync/cpg.h>
25 # endif
26 
27 extern gboolean crm_have_quorum;
28 extern GHashTable *crm_peer_cache;
29 extern GHashTable *crm_remote_peer_cache;
30 extern unsigned long long crm_peer_seq;
31 
32 /* *INDENT-OFF* */
33 #define CRM_NODE_LOST "lost"
34 #define CRM_NODE_MEMBER "member"
35 
37 {
44 };
45 
47 {
48  /* node is not a cluster node and should not be considered for cluster membership */
49  crm_remote_node = 0x0001,
50 
51  /* node's cache entry is dirty */
52  crm_node_dirty = 0x0010,
53 };
54 /* *INDENT-ON* */
55 
56 typedef struct crm_peer_node_s {
57  char *uname; // Node name as known to cluster
58  char *uuid; // Node UUID to ensure uniqueness
59  char *state; // @TODO change to enum
60  uint64_t flags; // Bitmask of crm_node_flags
61  uint64_t last_seen; // Only needed by cluster nodes
62  uint32_t processes; // @TODO most not needed, merge into flags
63 
64  // Currently only needed by corosync stack
65  uint32_t id; // Node ID
66  time_t when_lost; // When CPG membership was last lost
67 
68  // Only used by controller
70  char *expected;
71 } crm_node_t;
72 
73 void crm_peer_init(void);
74 void crm_peer_destroy(void);
75 
76 typedef struct crm_cluster_s {
77  char *uuid;
78  char *uname;
79  uint32_t nodeid;
80 
81  void (*destroy) (gpointer);
82 
83 # if SUPPORT_COROSYNC
84  struct cpg_name group;
85  cpg_callbacks_t cpg;
86  cpg_handle_t cpg_handle;
87 # endif
88 
90 
91 gboolean crm_cluster_connect(crm_cluster_t * cluster);
93 
94 /* *INDENT-OFF* */
97 };
98 
110 };
111 
112 /* used with crm_get_peer_full */
117 };
118 /* *INDENT-ON* */
119 
120 gboolean send_cluster_message(crm_node_t * node, enum crm_ais_msg_types service,
121  xmlNode * data, gboolean ordered);
122 
123 
125 
126 /* Initialize and refresh the remote peer cache from a cib config */
127 void crm_remote_peer_cache_refresh(xmlNode *cib);
128 crm_node_t *crm_remote_peer_get(const char *node_name);
129 void crm_remote_peer_cache_remove(const char *node_name);
130 
131 /* allows filtering of remote and cluster nodes using crm_get_peer_flags */
132 crm_node_t *crm_get_peer_full(unsigned int id, const char *uname, int flags);
133 
134 /* only searches cluster nodes */
135 crm_node_t *crm_get_peer(unsigned int id, const char *uname);
136 
137 guint crm_active_peers(void);
138 gboolean crm_is_peer_active(const crm_node_t * node);
139 guint reap_crm_member(uint32_t id, const char *name);
140 int crm_terminate_member(int nodeid, const char *uname, void *unused);
141 int crm_terminate_member_no_mainloop(int nodeid, const char *uname, int *connection);
142 
143 # if SUPPORT_COROSYNC
144 uint32_t get_local_nodeid(cpg_handle_t handle);
145 
146 gboolean cluster_connect_cpg(crm_cluster_t *cluster);
147 void cluster_disconnect_cpg(crm_cluster_t * cluster);
148 
149 void pcmk_cpg_membership(cpg_handle_t handle,
150  const struct cpg_name *groupName,
151  const struct cpg_address *member_list, size_t member_list_entries,
152  const struct cpg_address *left_list, size_t left_list_entries,
153  const struct cpg_address *joined_list, size_t joined_list_entries);
154 gboolean crm_is_corosync_peer_active(const crm_node_t * node);
155 gboolean send_cluster_text(enum crm_ais_msg_class msg_class, const char *data,
156  gboolean local, crm_node_t * node,
157  enum crm_ais_msg_types dest);
158 char *pcmk_message_common_cs(cpg_handle_t handle, uint32_t nodeid, uint32_t pid, void *msg,
159  uint32_t *kind, const char **from);
160 # endif
161 
162 const char *crm_peer_uuid(crm_node_t *node);
163 const char *crm_peer_uname(const char *uuid);
164 void set_uuid(xmlNode *xml, const char *attr, crm_node_t *node);
165 
170 };
171 
172 enum crm_ais_msg_types text2msg_type(const char *text);
173 void crm_set_status_callback(void (*dispatch) (enum crm_status_type, crm_node_t *, const void *));
174 void crm_set_autoreap(gboolean autoreap);
175 
176 /* *INDENT-OFF* */
178 {
181  // 0x0004 was heartbeat
182  // 0x0010 was corosync 1 with plugin
184  // 0x0040 was corosync 1 with CMAN
185 };
186 /* *INDENT-ON* */
187 
189 const char *name_for_cluster_type(enum cluster_type_e type);
190 
191 gboolean is_corosync_cluster(void);
192 
193 const char *get_local_node_name(void);
194 char *get_node_name(uint32_t nodeid);
195 
196 static inline const char *
197 crm_join_phase_str(enum crm_join_phase phase)
198 {
199  switch (phase) {
200  case crm_join_nack: return "nack";
201  case crm_join_none: return "none";
202  case crm_join_welcomed: return "welcomed";
203  case crm_join_integrated: return "integrated";
204  case crm_join_finalized: return "finalized";
205  case crm_join_confirmed: return "confirmed";
206  }
207  return "invalid";
208 }
209 
210 #ifdef __cplusplus
211 }
212 #endif
213 
214 #endif
void crm_peer_destroy(void)
Definition: membership.c:406
char uname[MAX_NAME]
Definition: internal.h:85
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:46
crm_ais_msg_types
Definition: cluster.h:99
uint64_t flags
Definition: cluster.h:60
uint32_t nodeid
Definition: cluster.h:79
enum crm_join_phase join
Definition: cluster.h:69
uint32_t id
Definition: cluster.h:65
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:58
int crm_terminate_member(int nodeid, const char *uname, void *unused)
Definition: membership.c:1017
crm_join_phase
Definition: cluster.h:36
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:120
void crm_peer_init(void)
Definition: membership.c:390
void(* destroy)(gpointer)
Definition: cluster.h:81
GHashTable * crm_remote_peer_cache
Definition: membership.c:51
crm_node_t * crm_get_peer(unsigned int id, const char *uname)
Definition: membership.c:654
char * uuid
Definition: cluster.h:77
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:132
void crm_cluster_disconnect(crm_cluster_t *cluster)
Definition: cluster.c:83
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:647
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:252
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:512
void cluster_disconnect_cpg(crm_cluster_t *cluster)
Definition: cpg.c:51
uint32_t processes
Definition: cluster.h:62
enum crm_ais_msg_types text2msg_type(const char *text)
Definition: cpg.c:776
void crm_remote_peer_cache_remove(const char *node_name)
Definition: membership.c:120
Utility functions.
time_t when_lost
Definition: cluster.h:66
cluster_type_e
Definition: cluster.h:177
crm_status_type
Definition: cluster.h:166
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:236
gboolean crm_cluster_connect(crm_cluster_t *cluster)
Definition: cluster.c:61
char * expected
Definition: cluster.h:70
gboolean is_corosync_cluster(void)
Definition: cluster.c:330
crm_ais_msg_class
Definition: cluster.h:95
char * uname
Definition: cluster.h:78
uint32_t get_local_nodeid(cpg_handle_t handle)
Definition: cpg.c:65
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:178
char data[0]
Definition: internal.h:90
char * state
Definition: cluster.h:59
char * uname
Definition: cluster.h:57
uint64_t last_seen
Definition: cluster.h:61
void set_uuid(xmlNode *xml, const char *attr, crm_node_t *node)
Definition: cluster.c:227
char * name
Definition: pcmk_fence.c:31
int crm_terminate_member_no_mainloop(int nodeid, const char *uname, int *connection)
Definition: membership.c:1024
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:405
gboolean send_cluster_message(crm_node_t *node, enum crm_ais_msg_types service, xmlNode *data, gboolean ordered)
Definition: cluster.c:104
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:30
uint64_t flags
Definition: remote.c:149
gboolean cluster_connect_cpg(crm_cluster_t *cluster)
Definition: cpg.c:539
enum crm_ais_msg_types type
Definition: internal.h:83
enum cluster_type_e get_cluster_type(void)
Definition: cluster.c:275
crm_get_peer_flags
Definition: cluster.h:113
int crm_remote_peer_cache_size(void)
Definition: membership.c:60
gboolean local
Definition: internal.h:82