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