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