This source file includes following definitions.
- crm_get_cluster_proc
- peer2text
- text2proc
- ais_dest
- ais_msg_copy
- ais_error2text
- msg_type2text
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
29 # endif
30
31 typedef struct crm_ais_host_s AIS_Host;
32 typedef struct crm_ais_msg_s AIS_Message;
33
34 struct crm_ais_host_s {
35 uint32_t id;
36 uint32_t pid;
37 gboolean local;
38 enum crm_ais_msg_types type;
39 uint32_t size;
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)));
46 uint32_t id;
47 gboolean is_compressed;
48
49 AIS_Host host;
50 AIS_Host sender;
51
52 uint32_t size;
53 uint32_t compressed_size;
54
55 char data[0];
56
57 } __attribute__ ((packed));
58
59 struct crm_ais_nodeid_resp_s {
60 cs_ipc_header_response_t header __attribute__ ((aligned(8)));
61 uint32_t id;
62 uint32_t counter;
63 char uname[MAX_NAME];
64 char cname[MAX_NAME];
65 } __attribute__ ((packed));
66
67 struct crm_ais_quorum_resp_s {
68 cs_ipc_header_response_t header __attribute__ ((aligned(8)));
69 uint64_t id;
70 uint32_t votes;
71 uint32_t expected_votes;
72 uint32_t quorate;
73 } __attribute__ ((packed));
74
75
76 enum crm_proc_flag {
77 crm_proc_none = 0x00000001,
78
79
80
81
82
83
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
102
103
104
105
106
107
108
109 static inline uint32_t
110 crm_get_cluster_proc()
111 {
112 switch (get_cluster_type()) {
113 case pcmk_cluster_corosync:
114 case pcmk_cluster_cman:
115 return crm_proc_cpg;
116
117 case pcmk_cluster_heartbeat:
118 return crm_proc_heartbeat;
119
120 case pcmk_cluster_classic_ais:
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
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
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);
415 void plugin_handle_membership(AIS_Message *msg);
416 bool send_plugin_text(int class, struct iovec *iov);
417 # else
418 char *corosync_node_name(uint64_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
428 enum cluster_type_e find_corosync_variant(void);
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
439 enum crm_quorum_source {
440 crm_quorum_cman,
441 crm_quorum_corosync,
442 crm_quorum_pacemaker,
443 };
444
445 int get_corosync_id(int id, const char *uuid);
446 char *get_corosync_uuid(crm_node_t *peer);
447 enum crm_quorum_source get_quorum_source(void);
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