pacemaker  2.0.5-ba59be712
Scalable High-Availability cluster resource manager
internal.h
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2020 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_CLUSTER_INTERNAL__H
11 # define CRM_CLUSTER_INTERNAL__H
12 
13 # include <crm/cluster.h>
14 
15 #define pcmk__set_peer_flags(peer, flags_to_set) do { \
16  (peer)->flags = pcmk__set_flags_as(__func__, __LINE__, LOG_TRACE, \
17  "Peer", (peer)->uname, \
18  (peer)->flags, (flags_to_set), \
19  #flags_to_set); \
20  } while (0)
21 
22 #define pcmk__clear_peer_flags(peer, flags_to_clear) do { \
23  (peer)->flags = pcmk__clear_flags_as(__func__, __LINE__, \
24  LOG_TRACE, \
25  "Peer", (peer)->uname, \
26  (peer)->flags, (flags_to_clear), \
27  #flags_to_clear); \
28  } while (0)
29 
30 typedef struct crm_ais_host_s AIS_Host;
31 typedef struct crm_ais_msg_s AIS_Message;
32 
34  uint32_t id;
35  uint32_t pid;
36  gboolean local;
38  uint32_t size;
39  char uname[MAX_NAME];
40 
41 } __attribute__ ((packed));
42 
43 #if SUPPORT_COROSYNC
44 # include <qb/qbipc_common.h>
45 # include <corosync/corotypes.h>
46 typedef struct qb_ipc_response_header cs_ipc_header_response_t;
47 #else
48 typedef struct {
49  int size __attribute__ ((aligned(8)));
50  int id __attribute__ ((aligned(8)));
51  int error __attribute__ ((aligned(8)));
52 } __attribute__ ((aligned(8))) cs_ipc_header_response_t;
53 #endif
54 
55 struct crm_ais_msg_s {
56  cs_ipc_header_response_t header __attribute__ ((aligned(8)));
57  uint32_t id;
58  gboolean is_compressed;
59 
62 
63  uint32_t size;
64  uint32_t compressed_size;
65  /* 584 bytes */
66  char data[0];
67 
68 } __attribute__ ((packed));
69 
70 /* *INDENT-OFF* */
72  crm_proc_none = 0x00000001,
73 
74  // Cluster layers
75  crm_proc_cpg = 0x04000000,
76 
77  // Daemons
78  crm_proc_execd = 0x00000010,
79  crm_proc_based = 0x00000100,
80  crm_proc_controld = 0x00000200,
81  crm_proc_attrd = 0x00001000,
82  crm_proc_schedulerd = 0x00010000,
83  crm_proc_fenced = 0x00100000,
84 };
85 /* *INDENT-ON* */
86 
93 static inline uint32_t
94 crm_get_cluster_proc(void)
95 {
96  switch (get_cluster_type()) {
98  return crm_proc_cpg;
99 
100  default:
101  break;
102  }
103  return crm_proc_none;
104 }
105 
106 static inline const char *
107 peer2text(enum crm_proc_flag proc)
108 {
109  const char *text = "unknown";
110 
111  switch (proc) {
112  case crm_proc_none:
113  text = "none";
114  break;
115  case crm_proc_based:
116  text = "pacemaker-based";
117  break;
118  case crm_proc_controld:
119  text = "pacemaker-controld";
120  break;
121  case crm_proc_schedulerd:
122  text = "pacemaker-schedulerd";
123  break;
124  case crm_proc_execd:
125  text = "pacemaker-execd";
126  break;
127  case crm_proc_attrd:
128  text = "pacemaker-attrd";
129  break;
130  case crm_proc_fenced:
131  text = "pacemaker-fenced";
132  break;
133  case crm_proc_cpg:
134  text = "corosync-cpg";
135  break;
136  }
137  return text;
138 }
139 
140 static inline const char *
141 ais_dest(const AIS_Host *host)
142 {
143  if (host->local) {
144  return "local";
145  } else if (host->size > 0) {
146  return host->uname;
147  } else {
148  return "<all>";
149  }
150 }
151 
152 # define ais_data_len(msg) (msg->is_compressed?msg->compressed_size:msg->size)
153 
154 /*
155 typedef enum {
156  CS_OK = 1,
157  CS_ERR_LIBRARY = 2,
158  CS_ERR_VERSION = 3,
159  CS_ERR_INIT = 4,
160  CS_ERR_TIMEOUT = 5,
161  CS_ERR_TRY_AGAIN = 6,
162  CS_ERR_INVALID_PARAM = 7,
163  CS_ERR_NO_MEMORY = 8,
164  CS_ERR_BAD_HANDLE = 9,
165  CS_ERR_BUSY = 10,
166  CS_ERR_ACCESS = 11,
167  CS_ERR_NOT_EXIST = 12,
168  CS_ERR_NAME_TOO_LONG = 13,
169  CS_ERR_EXIST = 14,
170  CS_ERR_NO_SPACE = 15,
171  CS_ERR_INTERRUPT = 16,
172  CS_ERR_NAME_NOT_FOUND = 17,
173  CS_ERR_NO_RESOURCES = 18,
174  CS_ERR_NOT_SUPPORTED = 19,
175  CS_ERR_BAD_OPERATION = 20,
176  CS_ERR_FAILED_OPERATION = 21,
177  CS_ERR_MESSAGE_ERROR = 22,
178  CS_ERR_QUEUE_FULL = 23,
179  CS_ERR_QUEUE_NOT_AVAILABLE = 24,
180  CS_ERR_BAD_FLAGS = 25,
181  CS_ERR_TOO_BIG = 26,
182  CS_ERR_NO_SECTIONS = 27,
183  CS_ERR_CONTEXT_NOT_FOUND = 28,
184  CS_ERR_TOO_MANY_GROUPS = 30,
185  CS_ERR_SECURITY = 100
186 } cs_error_t;
187  */
188 static inline const char *
189 ais_error2text(int error)
190 {
191  const char *text = "unknown";
192 
193 # if SUPPORT_COROSYNC
194  switch (error) {
195  case CS_OK:
196  text = "OK";
197  break;
198  case CS_ERR_LIBRARY:
199  text = "Library error";
200  break;
201  case CS_ERR_VERSION:
202  text = "Version error";
203  break;
204  case CS_ERR_INIT:
205  text = "Initialization error";
206  break;
207  case CS_ERR_TIMEOUT:
208  text = "Timeout";
209  break;
210  case CS_ERR_TRY_AGAIN:
211  text = "Try again";
212  break;
213  case CS_ERR_INVALID_PARAM:
214  text = "Invalid parameter";
215  break;
216  case CS_ERR_NO_MEMORY:
217  text = "No memory";
218  break;
219  case CS_ERR_BAD_HANDLE:
220  text = "Bad handle";
221  break;
222  case CS_ERR_BUSY:
223  text = "Busy";
224  break;
225  case CS_ERR_ACCESS:
226  text = "Access error";
227  break;
228  case CS_ERR_NOT_EXIST:
229  text = "Doesn't exist";
230  break;
231  case CS_ERR_NAME_TOO_LONG:
232  text = "Name too long";
233  break;
234  case CS_ERR_EXIST:
235  text = "Exists";
236  break;
237  case CS_ERR_NO_SPACE:
238  text = "No space";
239  break;
240  case CS_ERR_INTERRUPT:
241  text = "Interrupt";
242  break;
243  case CS_ERR_NAME_NOT_FOUND:
244  text = "Name not found";
245  break;
246  case CS_ERR_NO_RESOURCES:
247  text = "No resources";
248  break;
249  case CS_ERR_NOT_SUPPORTED:
250  text = "Not supported";
251  break;
252  case CS_ERR_BAD_OPERATION:
253  text = "Bad operation";
254  break;
255  case CS_ERR_FAILED_OPERATION:
256  text = "Failed operation";
257  break;
258  case CS_ERR_MESSAGE_ERROR:
259  text = "Message error";
260  break;
261  case CS_ERR_QUEUE_FULL:
262  text = "Queue full";
263  break;
264  case CS_ERR_QUEUE_NOT_AVAILABLE:
265  text = "Queue not available";
266  break;
267  case CS_ERR_BAD_FLAGS:
268  text = "Bad flags";
269  break;
270  case CS_ERR_TOO_BIG:
271  text = "Too big";
272  break;
273  case CS_ERR_NO_SECTIONS:
274  text = "No sections";
275  break;
276  }
277 # endif
278  return text;
279 }
280 
281 static inline const char *
282 msg_type2text(enum crm_ais_msg_types type)
283 {
284  const char *text = "unknown";
285 
286  switch (type) {
287  case crm_msg_none:
288  text = "unknown";
289  break;
290  case crm_msg_ais:
291  text = "ais";
292  break;
293  case crm_msg_cib:
294  text = "cib";
295  break;
296  case crm_msg_crmd:
297  text = "crmd";
298  break;
299  case crm_msg_pe:
300  text = "pengine";
301  break;
302  case crm_msg_te:
303  text = "tengine";
304  break;
305  case crm_msg_lrmd:
306  text = "lrmd";
307  break;
308  case crm_msg_attrd:
309  text = "attrd";
310  break;
311  case crm_msg_stonithd:
312  text = "stonithd";
313  break;
314  case crm_msg_stonith_ng:
315  text = "stonith-ng";
316  break;
317  }
318  return text;
319 }
320 
321 gboolean check_message_sanity(const AIS_Message * msg, const char *data);
322 
323 # if SUPPORT_COROSYNC
324 
325 gboolean send_cpg_iov(struct iovec * iov);
326 
327 char *get_corosync_uuid(crm_node_t *peer);
328 char *corosync_node_name(uint64_t /*cmap_handle_t */ cmap_handle, uint32_t nodeid);
329 char *corosync_cluster_name(void);
330 int corosync_cmap_has_config(const char *prefix);
331 
332 gboolean corosync_initialize_nodelist(void *cluster, gboolean force_member, xmlNode * xml_parent);
333 
334 gboolean send_cluster_message_cs(xmlNode * msg, gboolean local,
335  crm_node_t * node, enum crm_ais_msg_types dest);
336 
338 
339 void terminate_cs_connection(crm_cluster_t * cluster);
340 gboolean init_cs_connection(crm_cluster_t * cluster);
341 gboolean init_cs_connection_once(crm_cluster_t * cluster);
342 # endif
343 
344 crm_node_t *crm_update_peer_proc(const char *source, crm_node_t * peer,
345  uint32_t flag, const char *status);
346 crm_node_t *crm_update_peer_state(const char *source, crm_node_t * node,
347  const char *state, uint64_t membership);
348 
349 void crm_update_peer_uname(crm_node_t *node, const char *uname);
350 void crm_update_peer_expected(const char *source, crm_node_t * node, const char *expected);
351 void crm_reap_unseen_nodes(uint64_t ring_id);
352 
353 gboolean cluster_connect_quorum(gboolean(*dispatch) (unsigned long long, gboolean),
354  void (*destroy) (gpointer));
355 
356 gboolean node_name_is_valid(const char *key, const char *name);
357 
358 crm_node_t * crm_find_peer_full(unsigned int id, const char *uname, int flags);
359 crm_node_t * crm_find_peer(unsigned int id, const char *uname);
360 
361 void crm_peer_caches_refresh(xmlNode *cib);
362 crm_node_t *crm_find_known_peer_full(unsigned int id, const char *uname, int flags);
363 
364 #endif
enum crm_ais_msg_types type
Definition: internal.h:37
char uname[MAX_NAME]
Definition: internal.h:85
char data[0]
Definition: internal.h:66
gboolean send_cpg_iov(struct iovec *iov)
Definition: cpg.c:219
gboolean is_compressed
Definition: internal.h:58
uint32_t size
Definition: internal.h:63
crm_ais_msg_types
Definition: cluster.h:99
void crm_reap_unseen_nodes(uint64_t ring_id)
Definition: membership.c:990
void terminate_cs_connection(crm_cluster_t *cluster)
Definition: corosync.c:174
uint32_t size
Definition: internal.h:84
uint32_t id
Definition: internal.h:34
cs_ipc_header_response_t header __attribute__((aligned(8)))
AIS_Host host
Definition: internal.h:84
crm_node_t * crm_update_peer_state(const char *source, crm_node_t *node, const char *state, uint64_t membership)
Update a node's state and membership information.
Definition: membership.c:978
gboolean cluster_connect_quorum(gboolean(*dispatch)(unsigned long long, gboolean), void(*destroy)(gpointer))
Definition: corosync.c:272
gboolean init_cs_connection(crm_cluster_t *cluster)
Definition: corosync.c:357
char * corosync_cluster_name(void)
Definition: corosync.c:639
cluster_type_e
Definition: cluster.h:177
gboolean local
Definition: internal.h:36
crm_node_t * crm_update_peer_proc(const char *source, crm_node_t *peer, uint32_t flag, const char *status)
Definition: membership.c:786
AIS_Host sender
Definition: internal.h:61
uint32_t id
Definition: internal.h:57
gboolean check_message_sanity(const AIS_Message *msg, const char *data)
Definition: corosync.c:421
char * corosync_node_name(uint64_t cmap_handle, uint32_t nodeid)
Definition: corosync.c:61
int corosync_cmap_has_config(const char *prefix)
Definition: corosync.c:704
uint32_t size
Definition: internal.h:38
enum cluster_type_e find_corosync_variant(void)
Definition: corosync.c:484
uint32_t compressed_size
Definition: internal.h:64
#define MAX_NAME
Definition: crm.h:60
void crm_update_peer_expected(const char *source, crm_node_t *node, const char *expected)
Definition: membership.c:864
gboolean init_cs_connection_once(crm_cluster_t *cluster)
Definition: corosync.c:383
crm_node_t * crm_find_known_peer_full(unsigned int id, const char *uname, int flags)
Definition: membership.c:1170
gboolean node_name_is_valid(const char *key, const char *name)
Definition: cluster.c:336
char uname[MAX_NAME]
Definition: internal.h:39
crm_node_t * crm_find_peer_full(unsigned int id, const char *uname, int flags)
Definition: membership.c:484
gboolean send_cluster_message_cs(xmlNode *msg, gboolean local, crm_node_t *node, enum crm_ais_msg_types dest)
Definition: cpg.c:635
char data[0]
Definition: internal.h:90
typedef __attribute__
char * get_corosync_uuid(crm_node_t *node)
Definition: corosync.c:44
uint32_t pid
Definition: internal.h:35
void crm_update_peer_uname(crm_node_t *node, const char *uname)
Definition: membership.c:733
AIS_Host host
Definition: internal.h:60
void crm_peer_caches_refresh(xmlNode *cib)
Definition: membership.c:1163
char * name
Definition: pcmk_fence.c:31
crm_node_t * crm_find_peer(unsigned int id, const char *uname)
Definition: membership.c:522
crm_proc_flag
Definition: internal.h:71
gboolean corosync_initialize_nodelist(void *cluster, gboolean force_member, xmlNode *xml_parent)
Definition: corosync.c:530
uint64_t flags
Definition: remote.c:149
enum crm_ais_msg_types type
Definition: internal.h:83
enum cluster_type_e get_cluster_type(void)
Definition: cluster.c:275
gboolean local
Definition: internal.h:82