pacemaker  1.1.12-561c4cf
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 
36  uint32_t id;
37  uint32_t pid;
38  gboolean local;
40  uint32_t size;
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)));
47  uint32_t id;
48  gboolean is_compressed;
49 
52 
53  uint32_t size;
54  uint32_t compressed_size;
55  /* 584 bytes */
56  char data[0];
57 
58 } __attribute__ ((packed));
59 
61  cs_ipc_header_response_t header __attribute__ ((aligned(8)));
62  uint32_t id;
63  uint32_t counter;
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;
71  uint32_t votes;
72  uint32_t expected_votes;
73  uint32_t quorate;
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 
105 static inline const char *
106 peer2text(enum crm_proc_flag proc)
107 {
108  const char *text = "unknown";
109 
110  if (proc == (crm_proc_cpg | crm_proc_crmd)) {
111  return "peer";
112  }
113 
114  switch (proc) {
115  case crm_proc_none:
116  text = "none";
117  break;
118  case crm_proc_plugin:
119  text = "ais";
120  break;
121  case crm_proc_heartbeat:
122  text = "heartbeat";
123  break;
124  case crm_proc_cib:
125  text = "cib";
126  break;
127  case crm_proc_crmd:
128  text = "crmd";
129  break;
130  case crm_proc_pe:
131  text = "pengine";
132  break;
133  case crm_proc_te:
134  text = "tengine";
135  break;
136  case crm_proc_lrmd:
137  text = "lrmd";
138  break;
139  case crm_proc_attrd:
140  text = "attrd";
141  break;
142  case crm_proc_stonithd:
143  text = "stonithd";
144  break;
145  case crm_proc_stonith_ng:
146  text = "stonith-ng";
147  break;
148  case crm_proc_mgmtd:
149  text = "mgmtd";
150  break;
151  case crm_proc_cpg:
152  text = "corosync-cpg";
153  break;
154  }
155  return text;
156 }
157 
158 static inline enum crm_proc_flag
159 text2proc(const char *proc)
160 {
161  /* We only care about these two so far */
162 
163  if (proc && strcmp(proc, "cib") == 0) {
164  return crm_proc_cib;
165  } else if (proc && strcmp(proc, "crmd") == 0) {
166  return crm_proc_crmd;
167  }
168 
169  return crm_proc_none;
170 }
171 
172 static inline const char *
173 ais_dest(const struct crm_ais_host_s *host)
174 {
175  if (host->local) {
176  return "local";
177  } else if (host->size > 0) {
178  return host->uname;
179  } else {
180  return "<all>";
181  }
182 }
183 
184 # define ais_data_len(msg) (msg->is_compressed?msg->compressed_size:msg->size)
185 
186 static inline AIS_Message *
187 ais_msg_copy(const AIS_Message * source)
188 {
189  AIS_Message *target = malloc(sizeof(AIS_Message) + ais_data_len(source));
190 
191  if(target) {
192  memcpy(target, source, sizeof(AIS_Message));
193  memcpy(target->data, source->data, ais_data_len(target));
194  }
195  return target;
196 }
197 
198 /*
199 typedef enum {
200  CS_OK = 1,
201  CS_ERR_LIBRARY = 2,
202  CS_ERR_VERSION = 3,
203  CS_ERR_INIT = 4,
204  CS_ERR_TIMEOUT = 5,
205  CS_ERR_TRY_AGAIN = 6,
206  CS_ERR_INVALID_PARAM = 7,
207  CS_ERR_NO_MEMORY = 8,
208  CS_ERR_BAD_HANDLE = 9,
209  CS_ERR_BUSY = 10,
210  CS_ERR_ACCESS = 11,
211  CS_ERR_NOT_EXIST = 12,
212  CS_ERR_NAME_TOO_LONG = 13,
213  CS_ERR_EXIST = 14,
214  CS_ERR_NO_SPACE = 15,
215  CS_ERR_INTERRUPT = 16,
216  CS_ERR_NAME_NOT_FOUND = 17,
217  CS_ERR_NO_RESOURCES = 18,
218  CS_ERR_NOT_SUPPORTED = 19,
219  CS_ERR_BAD_OPERATION = 20,
220  CS_ERR_FAILED_OPERATION = 21,
221  CS_ERR_MESSAGE_ERROR = 22,
222  CS_ERR_QUEUE_FULL = 23,
223  CS_ERR_QUEUE_NOT_AVAILABLE = 24,
224  CS_ERR_BAD_FLAGS = 25,
225  CS_ERR_TOO_BIG = 26,
226  CS_ERR_NO_SECTIONS = 27,
227  CS_ERR_CONTEXT_NOT_FOUND = 28,
228  CS_ERR_TOO_MANY_GROUPS = 30,
229  CS_ERR_SECURITY = 100
230 } cs_error_t;
231  */
232 static inline const char *
233 ais_error2text(int error)
234 {
235  const char *text = "unknown";
236 
237 # if SUPPORT_COROSYNC
238  switch (error) {
239  case CS_OK:
240  text = "OK";
241  break;
242  case CS_ERR_LIBRARY:
243  text = "Library error";
244  break;
245  case CS_ERR_VERSION:
246  text = "Version error";
247  break;
248  case CS_ERR_INIT:
249  text = "Initialization error";
250  break;
251  case CS_ERR_TIMEOUT:
252  text = "Timeout";
253  break;
254  case CS_ERR_TRY_AGAIN:
255  text = "Try again";
256  break;
257  case CS_ERR_INVALID_PARAM:
258  text = "Invalid parameter";
259  break;
260  case CS_ERR_NO_MEMORY:
261  text = "No memory";
262  break;
263  case CS_ERR_BAD_HANDLE:
264  text = "Bad handle";
265  break;
266  case CS_ERR_BUSY:
267  text = "Busy";
268  break;
269  case CS_ERR_ACCESS:
270  text = "Access error";
271  break;
272  case CS_ERR_NOT_EXIST:
273  text = "Doesn't exist";
274  break;
275  case CS_ERR_NAME_TOO_LONG:
276  text = "Name too long";
277  break;
278  case CS_ERR_EXIST:
279  text = "Exists";
280  break;
281  case CS_ERR_NO_SPACE:
282  text = "No space";
283  break;
284  case CS_ERR_INTERRUPT:
285  text = "Interrupt";
286  break;
287  case CS_ERR_NAME_NOT_FOUND:
288  text = "Name not found";
289  break;
290  case CS_ERR_NO_RESOURCES:
291  text = "No resources";
292  break;
293  case CS_ERR_NOT_SUPPORTED:
294  text = "Not supported";
295  break;
296  case CS_ERR_BAD_OPERATION:
297  text = "Bad operation";
298  break;
299  case CS_ERR_FAILED_OPERATION:
300  text = "Failed operation";
301  break;
302  case CS_ERR_MESSAGE_ERROR:
303  text = "Message error";
304  break;
305  case CS_ERR_QUEUE_FULL:
306  text = "Queue full";
307  break;
308  case CS_ERR_QUEUE_NOT_AVAILABLE:
309  text = "Queue not available";
310  break;
311  case CS_ERR_BAD_FLAGS:
312  text = "Bad flags";
313  break;
314  case CS_ERR_TOO_BIG:
315  text = "To big";
316  break;
317  case CS_ERR_NO_SECTIONS:
318  text = "No sections";
319  break;
320  }
321 # endif
322  return text;
323 }
324 
325 static inline const char *
326 msg_type2text(enum crm_ais_msg_types type)
327 {
328  const char *text = "unknown";
329 
330  switch (type) {
331  case crm_msg_none:
332  text = "unknown";
333  break;
334  case crm_msg_ais:
335  text = "ais";
336  break;
337  case crm_msg_cib:
338  text = "cib";
339  break;
340  case crm_msg_crmd:
341  text = "crmd";
342  break;
343  case crm_msg_pe:
344  text = "pengine";
345  break;
346  case crm_msg_te:
347  text = "tengine";
348  break;
349  case crm_msg_lrmd:
350  text = "lrmd";
351  break;
352  case crm_msg_attrd:
353  text = "attrd";
354  break;
355  case crm_msg_stonithd:
356  text = "stonithd";
357  break;
358  case crm_msg_stonith_ng:
359  text = "stonith-ng";
360  break;
361  }
362  return text;
363 }
364 
365 enum crm_ais_msg_types text2msg_type(const char *text);
366 char *get_ais_data(const AIS_Message * msg);
367 gboolean check_message_sanity(const AIS_Message * msg, const char *data);
368 
369 # if SUPPORT_HEARTBEAT
370 extern ll_cluster_t *heartbeat_cluster;
371 gboolean send_ha_message(ll_cluster_t * hb_conn, xmlNode * msg,
372  const char *node, gboolean force_ordered);
373 gboolean ha_msg_dispatch(ll_cluster_t * cluster_conn, gpointer user_data);
374 
375 gboolean register_heartbeat_conn(crm_cluster_t * cluster);
376 xmlNode *convert_ha_message(xmlNode * parent, HA_Message * msg, const char *field);
377 gboolean ccm_have_quorum(oc_ed_t event);
378 const char *ccm_event_name(oc_ed_t event);
379 crm_node_t *crm_update_ccm_node(const oc_ev_membership_t * oc, int offset, const char *state,
380  uint64_t seq);
381 
382 gboolean heartbeat_initialize_nodelist(void *cluster, gboolean force_member, xmlNode * xml_parent);
383 # endif
384 
385 # if SUPPORT_COROSYNC
386 
387 gboolean send_cpg_iov(struct iovec * iov);
388 
389 # if SUPPORT_PLUGIN
390 char *classic_node_name(uint32_t nodeid);
391 void plugin_handle_membership(AIS_Message *msg);
392 bool send_plugin_text(int class, struct iovec *iov);
393 # else
394 char *corosync_node_name(uint64_t /*cmap_handle_t */ cmap_handle, uint32_t nodeid);
395 char *corosync_cluster_name(void);
396 int corosync_cmap_has_config(const char *prefix);
397 # endif
398 
399 gboolean corosync_initialize_nodelist(void *cluster, gboolean force_member, xmlNode * xml_parent);
400 
401 gboolean send_cluster_message_cs(xmlNode * msg, gboolean local,
402  crm_node_t * node, enum crm_ais_msg_types dest);
403 
404 enum cluster_type_e find_corosync_variant(void);
405 
406 void terminate_cs_connection(crm_cluster_t * cluster);
407 gboolean init_cs_connection(crm_cluster_t * cluster);
408 gboolean init_cs_connection_once(crm_cluster_t * cluster);
409 # endif
410 
411 # ifdef SUPPORT_CMAN
412 char *cman_node_name(uint32_t nodeid);
413 # endif
414 
419 };
420 
421 int get_corosync_id(int id, const char *uuid);
422 char *get_corosync_uuid(crm_node_t *peer);
424 
425 void crm_update_peer_proc(const char *source, crm_node_t * peer, uint32_t flag, const char *status);
426 
427 crm_node_t *crm_update_peer(const char *source, unsigned int id, uint64_t born, uint64_t seen,
428  int32_t votes, uint32_t children, const char *uuid, const char *uname,
429  const char *addr, const char *state);
430 
431 void crm_update_peer_expected(const char *source, crm_node_t * node, const char *expected);
432 void crm_update_peer_state(const char *source, crm_node_t * node, const char *state,
433  int membership);
434 
435 gboolean init_cman_connection(gboolean(*dispatch) (unsigned long long, gboolean),
436  void (*destroy) (gpointer));
437 
438 gboolean cluster_connect_quorum(gboolean(*dispatch) (unsigned long long, gboolean),
439  void (*destroy) (gpointer));
440 
441 void set_node_uuid(const char *uname, const char *uuid);
442 
443 gboolean node_name_is_valid(const char *key, const char *name);
444 
445 crm_node_t * crm_find_peer_full(unsigned int id, const char *uname, int flags);
446 crm_node_t * crm_find_peer(unsigned int id, const char *uname);
447 
448 #endif
uint32_t votes
Definition: internal.h:50
void crm_update_peer_state(const char *source, crm_node_t *node, const char *state, int membership)
enum crm_ais_msg_types type
Definition: internal.h:39
char data[0]
Definition: internal.h:56
gboolean is_compressed
Definition: internal.h:48
uint32_t size
Definition: internal.h:53
crm_ais_msg_types
Definition: cluster.h:125
char * get_corosync_uuid(crm_node_t *peer)
int get_corosync_id(int id, const char *uuid)
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)
gboolean cluster_connect_quorum(gboolean(*dispatch)(unsigned long long, gboolean), void(*destroy)(gpointer))
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)
char uname[MAX_NAME]
Definition: internal.h:53
cs_ipc_header_response_t header __attribute__((aligned(8)))
cluster_type_e
Definition: cluster.h:204
gboolean local
Definition: internal.h:38
enum crm_proc_flag __attribute__
void crm_update_peer_proc(const char *source, crm_node_t *peer, uint32_t flag, const char *status)
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)
enum crm_quorum_source get_quorum_source(void)
#define ais_data_len(msg)
Definition: internal.h:184
uint32_t size
Definition: internal.h:40
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)
char * get_ais_data(const AIS_Message *msg)
char cname[MAX_NAME]
Definition: internal.h:65
gboolean node_name_is_valid(const char *key, const char *name)
char uname[MAX_NAME]
Definition: internal.h:41
crm_node_t * crm_find_peer_full(unsigned int id, const char *uname, int flags)
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)))
AIS_Host host
Definition: internal.h:50
gboolean init_cman_connection(gboolean(*dispatch)(unsigned long long, gboolean), void(*destroy)(gpointer))
crm_node_t * crm_find_peer(unsigned int id, const char *uname)
crm_quorum_source
Definition: internal.h:415
crm_proc_flag
Definition: internal.h:77
enum crm_ais_msg_types type
Definition: internal.h:51
gboolean local
Definition: internal.h:50