pacemaker  1.1.18-7fdfbbe
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
internal.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 
19 #ifndef CRM_CLUSTER_INTERNAL__H
20 # define CRM_CLUSTER_INTERNAL__H
21 
22 # include <crm/cluster.h>
23 
24 # define AIS_IPC_MESSAGE_SIZE (8192 * 128)
25 # define CRM_MESSAGE_IPC_ACK 0
26 
27 # ifndef INTERFACE_MAX
28 # define INTERFACE_MAX 2 /* from the private coroapi.h header */
29 # endif
30 
31 typedef struct crm_ais_host_s AIS_Host;
32 typedef struct crm_ais_msg_s AIS_Message;
33 
37  gboolean local;
40  char uname[MAX_NAME];
41 
42 } __attribute__ ((packed));
43 
44 struct crm_ais_msg_s {
45  cs_ipc_header_response_t header __attribute__ ((aligned(8)));
47  gboolean is_compressed;
48 
51 
54  /* 584 bytes */
55  char data[0];
56 
57 } __attribute__ ((packed));
58 
60  cs_ipc_header_response_t header __attribute__ ((aligned(8)));
63  char uname[MAX_NAME];
64  char cname[MAX_NAME];
65 } __attribute__ ((packed));
66 
68  cs_ipc_header_response_t header __attribute__ ((aligned(8)));
69  uint64_t id;
73 } __attribute__ ((packed));
74 
75 /* *INDENT-OFF* */
77  crm_proc_none = 0x00000001,
78  /* @COMPAT These values are sent over the network by the legacy plugin.
79  * Therefore, changing any of these values is going to break compatibility.
80  * So don't.
81  */
82 
83  /* 3 messaging types */
84  crm_proc_heartbeat = 0x01000000,
85  crm_proc_plugin = 0x00000002,
86  crm_proc_cpg = 0x04000000,
87 
88  crm_proc_lrmd = 0x00000010,
89  crm_proc_cib = 0x00000100,
90  crm_proc_crmd = 0x00000200,
91  crm_proc_attrd = 0x00001000,
92 
93  crm_proc_stonithd = 0x00002000,
94  crm_proc_stonith_ng= 0x00100000,
95 
96  crm_proc_pe = 0x00010000,
97  crm_proc_te = 0x00020000,
98 
99  crm_proc_mgmtd = 0x00040000,
100 };
101 /* *INDENT-ON* */
102 
109 static inline uint32_t
110 crm_get_cluster_proc()
111 {
112  switch (get_cluster_type()) {
114  case pcmk_cluster_cman:
115  return crm_proc_cpg;
116 
118  return crm_proc_heartbeat;
119 
121  return crm_proc_plugin;
122 
123  default:
124  break;
125  }
126  return crm_proc_none;
127 }
128 
129 static inline const char *
130 peer2text(enum crm_proc_flag proc)
131 {
132  const char *text = "unknown";
133 
134  if (proc == (crm_proc_crmd | crm_get_cluster_proc())) {
135  return "peer";
136  }
137 
138  switch (proc) {
139  case crm_proc_none:
140  text = "none";
141  break;
142  case crm_proc_plugin:
143  text = "ais";
144  break;
145  case crm_proc_heartbeat:
146  text = "heartbeat";
147  break;
148  case crm_proc_cib:
149  text = "cib";
150  break;
151  case crm_proc_crmd:
152  text = "crmd";
153  break;
154  case crm_proc_pe:
155  text = "pengine";
156  break;
157  case crm_proc_te:
158  text = "tengine";
159  break;
160  case crm_proc_lrmd:
161  text = "lrmd";
162  break;
163  case crm_proc_attrd:
164  text = "attrd";
165  break;
166  case crm_proc_stonithd:
167  text = "stonithd";
168  break;
169  case crm_proc_stonith_ng:
170  text = "stonith-ng";
171  break;
172  case crm_proc_mgmtd:
173  text = "mgmtd";
174  break;
175  case crm_proc_cpg:
176  text = "corosync-cpg";
177  break;
178  }
179  return text;
180 }
181 
182 static inline enum crm_proc_flag
183 text2proc(const char *proc)
184 {
185  /* We only care about these two so far */
186 
187  if (proc && strcmp(proc, "cib") == 0) {
188  return crm_proc_cib;
189  } else if (proc && strcmp(proc, "crmd") == 0) {
190  return crm_proc_crmd;
191  }
192 
193  return crm_proc_none;
194 }
195 
196 static inline const char *
197 ais_dest(const struct crm_ais_host_s *host)
198 {
199  if (host->local) {
200  return "local";
201  } else if (host->size > 0) {
202  return host->uname;
203  } else {
204  return "<all>";
205  }
206 }
207 
208 # define ais_data_len(msg) (msg->is_compressed?msg->compressed_size:msg->size)
209 
210 static inline AIS_Message *
211 ais_msg_copy(const AIS_Message * source)
212 {
213  AIS_Message *target = malloc(sizeof(AIS_Message) + ais_data_len(source));
214 
215  if(target) {
216  memcpy(target, source, sizeof(AIS_Message));
217  memcpy(target->data, source->data, ais_data_len(target));
218  }
219  return target;
220 }
221 
222 /*
223 typedef enum {
224  CS_OK = 1,
225  CS_ERR_LIBRARY = 2,
226  CS_ERR_VERSION = 3,
227  CS_ERR_INIT = 4,
228  CS_ERR_TIMEOUT = 5,
229  CS_ERR_TRY_AGAIN = 6,
230  CS_ERR_INVALID_PARAM = 7,
231  CS_ERR_NO_MEMORY = 8,
232  CS_ERR_BAD_HANDLE = 9,
233  CS_ERR_BUSY = 10,
234  CS_ERR_ACCESS = 11,
235  CS_ERR_NOT_EXIST = 12,
236  CS_ERR_NAME_TOO_LONG = 13,
237  CS_ERR_EXIST = 14,
238  CS_ERR_NO_SPACE = 15,
239  CS_ERR_INTERRUPT = 16,
240  CS_ERR_NAME_NOT_FOUND = 17,
241  CS_ERR_NO_RESOURCES = 18,
242  CS_ERR_NOT_SUPPORTED = 19,
243  CS_ERR_BAD_OPERATION = 20,
244  CS_ERR_FAILED_OPERATION = 21,
245  CS_ERR_MESSAGE_ERROR = 22,
246  CS_ERR_QUEUE_FULL = 23,
247  CS_ERR_QUEUE_NOT_AVAILABLE = 24,
248  CS_ERR_BAD_FLAGS = 25,
249  CS_ERR_TOO_BIG = 26,
250  CS_ERR_NO_SECTIONS = 27,
251  CS_ERR_CONTEXT_NOT_FOUND = 28,
252  CS_ERR_TOO_MANY_GROUPS = 30,
253  CS_ERR_SECURITY = 100
254 } cs_error_t;
255  */
256 static inline const char *
257 ais_error2text(int error)
258 {
259  const char *text = "unknown";
260 
261 # if SUPPORT_COROSYNC
262  switch (error) {
263  case CS_OK:
264  text = "OK";
265  break;
266  case CS_ERR_LIBRARY:
267  text = "Library error";
268  break;
269  case CS_ERR_VERSION:
270  text = "Version error";
271  break;
272  case CS_ERR_INIT:
273  text = "Initialization error";
274  break;
275  case CS_ERR_TIMEOUT:
276  text = "Timeout";
277  break;
278  case CS_ERR_TRY_AGAIN:
279  text = "Try again";
280  break;
281  case CS_ERR_INVALID_PARAM:
282  text = "Invalid parameter";
283  break;
284  case CS_ERR_NO_MEMORY:
285  text = "No memory";
286  break;
287  case CS_ERR_BAD_HANDLE:
288  text = "Bad handle";
289  break;
290  case CS_ERR_BUSY:
291  text = "Busy";
292  break;
293  case CS_ERR_ACCESS:
294  text = "Access error";
295  break;
296  case CS_ERR_NOT_EXIST:
297  text = "Doesn't exist";
298  break;
299  case CS_ERR_NAME_TOO_LONG:
300  text = "Name too long";
301  break;
302  case CS_ERR_EXIST:
303  text = "Exists";
304  break;
305  case CS_ERR_NO_SPACE:
306  text = "No space";
307  break;
308  case CS_ERR_INTERRUPT:
309  text = "Interrupt";
310  break;
311  case CS_ERR_NAME_NOT_FOUND:
312  text = "Name not found";
313  break;
314  case CS_ERR_NO_RESOURCES:
315  text = "No resources";
316  break;
317  case CS_ERR_NOT_SUPPORTED:
318  text = "Not supported";
319  break;
320  case CS_ERR_BAD_OPERATION:
321  text = "Bad operation";
322  break;
323  case CS_ERR_FAILED_OPERATION:
324  text = "Failed operation";
325  break;
326  case CS_ERR_MESSAGE_ERROR:
327  text = "Message error";
328  break;
329  case CS_ERR_QUEUE_FULL:
330  text = "Queue full";
331  break;
332  case CS_ERR_QUEUE_NOT_AVAILABLE:
333  text = "Queue not available";
334  break;
335  case CS_ERR_BAD_FLAGS:
336  text = "Bad flags";
337  break;
338  case CS_ERR_TOO_BIG:
339  text = "Too big";
340  break;
341  case CS_ERR_NO_SECTIONS:
342  text = "No sections";
343  break;
344  }
345 # endif
346  return text;
347 }
348 
349 static inline const char *
350 msg_type2text(enum crm_ais_msg_types type)
351 {
352  const char *text = "unknown";
353 
354  switch (type) {
355  case crm_msg_none:
356  text = "unknown";
357  break;
358  case crm_msg_ais:
359  text = "ais";
360  break;
361  case crm_msg_cib:
362  text = "cib";
363  break;
364  case crm_msg_crmd:
365  text = "crmd";
366  break;
367  case crm_msg_pe:
368  text = "pengine";
369  break;
370  case crm_msg_te:
371  text = "tengine";
372  break;
373  case crm_msg_lrmd:
374  text = "lrmd";
375  break;
376  case crm_msg_attrd:
377  text = "attrd";
378  break;
379  case crm_msg_stonithd:
380  text = "stonithd";
381  break;
382  case crm_msg_stonith_ng:
383  text = "stonith-ng";
384  break;
385  }
386  return text;
387 }
388 
389 enum crm_ais_msg_types text2msg_type(const char *text);
390 char *get_ais_data(const AIS_Message * msg);
391 gboolean check_message_sanity(const AIS_Message * msg, const char *data);
392 
393 # if SUPPORT_HEARTBEAT
394 extern ll_cluster_t *heartbeat_cluster;
395 gboolean send_ha_message(ll_cluster_t * hb_conn, xmlNode * msg,
396  const char *node, gboolean force_ordered);
397 gboolean ha_msg_dispatch(ll_cluster_t * cluster_conn, gpointer user_data);
398 
399 gboolean register_heartbeat_conn(crm_cluster_t * cluster);
400 xmlNode *convert_ha_message(xmlNode * parent, HA_Message * msg, const char *field);
401 gboolean ccm_have_quorum(oc_ed_t event);
402 const char *ccm_event_name(oc_ed_t event);
403 crm_node_t *crm_update_ccm_node(const oc_ev_membership_t * oc, int offset, const char *state,
404  uint64_t seq);
405 
406 gboolean heartbeat_initialize_nodelist(void *cluster, gboolean force_member, xmlNode * xml_parent);
407 # endif
408 
409 # if SUPPORT_COROSYNC
410 
411 gboolean send_cpg_iov(struct iovec * iov);
412 
413 # if SUPPORT_PLUGIN
414 char *classic_node_name(uint32_t nodeid);
416 bool send_plugin_text(int class, struct iovec *iov);
417 # else
418 char *corosync_node_name(uint64_t /*cmap_handle_t */ cmap_handle, uint32_t nodeid);
419 char *corosync_cluster_name(void);
420 int corosync_cmap_has_config(const char *prefix);
421 # endif
422 
423 gboolean corosync_initialize_nodelist(void *cluster, gboolean force_member, xmlNode * xml_parent);
424 
425 gboolean send_cluster_message_cs(xmlNode * msg, gboolean local,
426  crm_node_t * node, enum crm_ais_msg_types dest);
427 
429 
430 void terminate_cs_connection(crm_cluster_t * cluster);
431 gboolean init_cs_connection(crm_cluster_t * cluster);
432 gboolean init_cs_connection_once(crm_cluster_t * cluster);
433 # endif
434 
435 # ifdef SUPPORT_CMAN
436 char *cman_node_name(uint32_t nodeid);
437 # endif
438 
443 };
444 
445 int get_corosync_id(int id, const char *uuid);
446 char *get_corosync_uuid(crm_node_t *peer);
448 
449 crm_node_t *crm_update_peer(const char *source, unsigned int id, uint64_t born,
450  uint64_t seen, int32_t votes, uint32_t children,
451  const char *uuid, const char *uname,
452  const char *addr, const char *state);
453 crm_node_t *crm_update_peer_proc(const char *source, crm_node_t * peer,
454  uint32_t flag, const char *status);
455 crm_node_t *crm_update_peer_state(const char *source, crm_node_t * node,
456  const char *state, int membership);
457 
458 void crm_update_peer_uname(crm_node_t *node, const char *uname);
459 void crm_update_peer_expected(const char *source, crm_node_t * node, const char *expected);
460 void crm_reap_unseen_nodes(uint64_t ring_id);
461 
462 gboolean init_cman_connection(gboolean(*dispatch) (unsigned long long, gboolean),
463  void (*destroy) (gpointer));
464 
465 gboolean cluster_connect_quorum(gboolean(*dispatch) (unsigned long long, gboolean),
466  void (*destroy) (gpointer));
467 
468 void set_node_uuid(const char *uname, const char *uuid);
469 
470 gboolean node_name_is_valid(const char *key, const char *name);
471 
472 crm_node_t * crm_find_peer_full(unsigned int id, const char *uname, int flags);
473 crm_node_t * crm_find_peer(unsigned int id, const char *uname);
474 
475 #endif
bool send_plugin_text(int class, struct iovec *iov)
Definition: legacy.c:135
uint32_t votes
Definition: internal.h:50
enum crm_ais_msg_types type
Definition: internal.h:38
char data[0]
Definition: internal.h:55
gboolean send_cpg_iov(struct iovec *iov)
Definition: cpg.c:201
gboolean is_compressed
Definition: internal.h:47
uint32_t size
Definition: internal.h:52
crm_ais_msg_types
Definition: cluster.h:128
void crm_reap_unseen_nodes(uint64_t ring_id)
Definition: membership.c:1089
char * corosync_node_name(uint64_tcmap_handle, uint32_t nodeid)
Definition: corosync.c:52
char * get_corosync_uuid(crm_node_t *peer)
Definition: cluster.c:106
void terminate_cs_connection(crm_cluster_t *cluster)
Definition: corosync.c:140
int get_corosync_id(int id, const char *uuid)
Definition: cluster.c:96
uint32_t id
Definition: internal.h:35
cs_ipc_header_response_t header __attribute__((aligned(8)))
AIS_Host host
Definition: internal.h:52
enum crm_ais_msg_types text2msg_type(const char *text)
Definition: cpg.c:652
gboolean cluster_connect_quorum(gboolean(*dispatch)(unsigned long long, gboolean), void(*destroy)(gpointer))
Definition: corosync.c:249
uint32_t expected_votes
Definition: internal.h:71
char uname[MAX_NAME]
Definition: internal.h:63
crm_node_t * crm_update_peer(const char *source, unsigned int id, uint64_t born, uint64_t seen, int32_t votes, uint32_t children, const char *uuid, const char *uname, const char *addr, const char *state)
Definition: membership.c:755
gboolean init_cs_connection(crm_cluster_t *cluster)
Definition: corosync.c:312
void plugin_handle_membership(AIS_Message *msg)
Definition: legacy.c:222
char uname[MAX_NAME]
Definition: internal.h:53
cs_ipc_header_response_t header __attribute__((aligned(8)))
char * corosync_cluster_name(void)
Definition: corosync.c:568
cluster_type_e
Definition: cluster.h:210
gboolean local
Definition: internal.h:37
crm_node_t * crm_update_peer_proc(const char *source, crm_node_t *peer, uint32_t flag, const char *status)
Definition: membership.c:891
enum crm_proc_flag __attribute__
AIS_Host sender
Definition: internal.h:50
uint32_t id
Definition: internal.h:46
gboolean check_message_sanity(const AIS_Message *msg, const char *data)
Definition: plugin.c:1356
enum crm_quorum_source get_quorum_source(void)
#define ais_data_len(msg)
Definition: internal.h:208
int corosync_cmap_has_config(const char *prefix)
Definition: corosync.c:594
uint32_t size
Definition: internal.h:39
struct qb_ipc_response_header cs_ipc_header_response_t
Definition: crm_internal.h:300
enum cluster_type_e find_corosync_variant(void)
Definition: corosync.c:440
uint32_t compressed_size
Definition: internal.h:53
#define MAX_NAME
Definition: crm.h:42
void crm_update_peer_expected(const char *source, crm_node_t *node, const char *expected)
Definition: membership.c:965
gboolean init_cs_connection_once(crm_cluster_t *cluster)
Definition: corosync.c:339
crm_node_t * crm_update_peer_state(const char *source, crm_node_t *node, const char *state, int membership)
Update a node&#39;s state and membership information.
Definition: membership.c:1077
char * get_ais_data(const AIS_Message *msg)
Definition: utils.c:454
char cname[MAX_NAME]
Definition: internal.h:64
gboolean node_name_is_valid(const char *key, const char *name)
Definition: cluster.c:651
char uname[MAX_NAME]
Definition: internal.h:40
crm_node_t * crm_find_peer_full(unsigned int id, const char *uname, int flags)
Definition: membership.c:502
gboolean send_cluster_message_cs(xmlNode *msg, gboolean local, crm_node_t *node, enum crm_ais_msg_types dest)
Definition: cpg.c:509
#define uint32_t
Definition: stdint.in.h:158
char data[0]
Definition: internal.h:58
void set_node_uuid(const char *uname, const char *uuid)
uint32_t pid
Definition: internal.h:36
cs_ipc_header_response_t header __attribute__((aligned(8)))
void crm_update_peer_uname(crm_node_t *node, const char *uname)
Definition: membership.c:838
AIS_Host host
Definition: internal.h:49
gboolean init_cman_connection(gboolean(*dispatch)(unsigned long long, gboolean), void(*destroy)(gpointer))
Definition: legacy.c:435
crm_node_t * crm_find_peer(unsigned int id, const char *uname)
Definition: membership.c:540
crm_quorum_source
Definition: internal.h:439
crm_proc_flag
Definition: internal.h:76
gboolean corosync_initialize_nodelist(void *cluster, gboolean force_member, xmlNode *xml_parent)
Definition: corosync.c:486
uint64_t flags
Definition: remote.c:156
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
gboolean local
Definition: internal.h:50