1 /*
2 * Copyright (c) 2006-2015 Red Hat, Inc.
3 *
4 * All rights reserved.
5 *
6 * Author: Christine Caulfield (ccaulfie@redhat.com)
7 * Author: Jan Friesse (jfriesse@redhat.com)
8 *
9 * This software licensed under BSD license, the text of which follows:
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 *
14 * - Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 * - Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * and/or other materials provided with the distribution.
19 * - Neither the name of the MontaVista Software, Inc. nor the names of its
20 * contributors may be used to endorse or promote products derived from this
21 * software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33 * THE POSSIBILITY OF SUCH DAMAGE.
34 */
35 #ifndef IPC_CPG_H_DEFINED
36 #define IPC_CPG_H_DEFINED
37
38 #include <netinet/in.h>
39 #include <qb/qbipc_common.h>
40 #include <corosync/corotypes.h>
41 #include <corosync/mar_gen.h>
42
43 #define CPG_ZC_PATH_LEN 128
44
45 /**
46 * @brief The req_cpg_types enum
47 */
48 enum req_cpg_types {
49 MESSAGE_REQ_CPG_JOIN = 0,
50 MESSAGE_REQ_CPG_LEAVE = 1,
51 MESSAGE_REQ_CPG_MCAST = 2,
52 MESSAGE_REQ_CPG_MEMBERSHIP = 3,
53 MESSAGE_REQ_CPG_LOCAL_GET = 4,
54 MESSAGE_REQ_CPG_ITERATIONINITIALIZE = 5,
55 MESSAGE_REQ_CPG_ITERATIONNEXT = 6,
56 MESSAGE_REQ_CPG_ITERATIONFINALIZE = 7,
57 MESSAGE_REQ_CPG_FINALIZE = 8,
58 MESSAGE_REQ_CPG_ZC_ALLOC = 9,
59 MESSAGE_REQ_CPG_ZC_FREE = 10,
60 MESSAGE_REQ_CPG_ZC_EXECUTE = 11,
61 MESSAGE_REQ_CPG_PARTIAL_MCAST = 12,
62 };
63
64 /**
65 * @brief The res_cpg_types enum
66 */
67 enum res_cpg_types {
68 MESSAGE_RES_CPG_JOIN = 0,
69 MESSAGE_RES_CPG_LEAVE = 1,
70 MESSAGE_RES_CPG_MCAST = 2,
71 MESSAGE_RES_CPG_MEMBERSHIP = 3,
72 MESSAGE_RES_CPG_CONFCHG_CALLBACK = 4,
73 MESSAGE_RES_CPG_DELIVER_CALLBACK = 5,
74 MESSAGE_RES_CPG_FLOW_CONTROL_STATE_SET = 6,
75 MESSAGE_RES_CPG_LOCAL_GET = 7,
76 MESSAGE_RES_CPG_FLOWCONTROL_CALLBACK = 8,
77 MESSAGE_RES_CPG_ITERATIONINITIALIZE = 9,
78 MESSAGE_RES_CPG_ITERATIONNEXT = 10,
79 MESSAGE_RES_CPG_ITERATIONFINALIZE = 11,
80 MESSAGE_RES_CPG_FINALIZE = 12,
81 MESSAGE_RES_CPG_TOTEM_CONFCHG_CALLBACK = 13,
82 MESSAGE_RES_CPG_ZC_ALLOC = 14,
83 MESSAGE_RES_CPG_ZC_FREE = 15,
84 MESSAGE_RES_CPG_ZC_EXECUTE = 16,
85 MESSAGE_RES_CPG_PARTIAL_DELIVER_CALLBACK = 17,
86 MESSAGE_RES_CPG_PARTIAL_SEND = 18,
87 };
88
89 /**
90 * @brief The lib_cpg_confchg_reason enum
91 */
92 enum lib_cpg_confchg_reason {
93 CONFCHG_CPG_REASON_JOIN = 1,
94 CONFCHG_CPG_REASON_LEAVE = 2,
95 CONFCHG_CPG_REASON_NODEDOWN = 3,
96 CONFCHG_CPG_REASON_NODEUP = 4,
97 CONFCHG_CPG_REASON_PROCDOWN = 5
98 };
99
100 /**
101 * @brief The lib_cpg_partial_types enum
102 */
103 enum lib_cpg_partial_types {
104 LIBCPG_PARTIAL_FIRST = 1,
105 LIBCPG_PARTIAL_CONTINUED = 2,
106 LIBCPG_PARTIAL_LAST = 3,
107 };
108
109 /**
110 * @brief mar_cpg_name_t struct
111 */
112 typedef struct {
113 uint32_t length __attribute__((aligned(8)));
114 char value[CPG_MAX_NAME_LENGTH] __attribute__((aligned(8)));
115 } mar_cpg_name_t;
116
117 /**
118 * @brief swab_mar_cpg_name_t
119 * @param to_swab
120 */
swab_mar_cpg_name_t(mar_cpg_name_t * to_swab)121 static inline void swab_mar_cpg_name_t (mar_cpg_name_t *to_swab)
122 {
123 swab_mar_uint32_t (&to_swab->length);
124 }
125
126 /**
127 * @brief marshall_from_mar_cpg_name_t
128 * @param dest
129 * @param src
130 */
marshall_from_mar_cpg_name_t(struct cpg_name * dest,const mar_cpg_name_t * src)131 static inline void marshall_from_mar_cpg_name_t (
132 struct cpg_name *dest,
133 const mar_cpg_name_t *src)
134 {
135 dest->length = src->length;
136 memcpy (&dest->value, &src->value, CPG_MAX_NAME_LENGTH);
137 }
138
139 /**
140 * @brief marshall_to_mar_cpg_name_t
141 * @param dest
142 * @param src
143 */
marshall_to_mar_cpg_name_t(mar_cpg_name_t * dest,const struct cpg_name * src)144 static inline void marshall_to_mar_cpg_name_t (
145 mar_cpg_name_t *dest,
146 const struct cpg_name *src)
147 {
148 dest->length = src->length;
149 memcpy (&dest->value, &src->value, CPG_MAX_NAME_LENGTH);
150 }
151
152 /**
153 * @brief mar_cpg_address_t struct
154 */
155 typedef struct {
156 mar_uint32_t nodeid __attribute__((aligned(8)));
157 mar_uint32_t pid __attribute__((aligned(8)));
158 mar_uint32_t reason __attribute__((aligned(8)));
159 } mar_cpg_address_t;
160
161 /**
162 * @brief marshall_from_mar_cpg_address_t
163 * @param dest
164 * @param src
165 */
marshall_from_mar_cpg_address_t(struct cpg_address * dest,const mar_cpg_address_t * src)166 static inline void marshall_from_mar_cpg_address_t (
167 struct cpg_address *dest,
168 const mar_cpg_address_t *src)
169 {
170 dest->nodeid = src->nodeid;
171 dest->pid = src->pid;
172 dest->reason = src->reason;
173 }
174
175 /**
176 * @brief marshall_to_mar_cpg_address_t
177 * @param dest
178 * @param src
179 */
marshall_to_mar_cpg_address_t(mar_cpg_address_t * dest,const struct cpg_address * src)180 static inline void marshall_to_mar_cpg_address_t (
181 mar_cpg_address_t *dest,
182 const struct cpg_address *src)
183 {
184 dest->nodeid = src->nodeid;
185 dest->pid = src->pid;
186 dest->reason = src->reason;
187 }
188
189 /**
190 * @brief mar_name_compare
191 * @param g1
192 * @param g2
193 * @return
194 */
mar_name_compare(const mar_cpg_name_t * g1,const mar_cpg_name_t * g2)195 static inline int mar_name_compare (
196 const mar_cpg_name_t *g1,
197 const mar_cpg_name_t *g2)
198 {
199 return (g1->length == g2->length?
200 memcmp (g1->value, g2->value, g1->length):
201 g1->length - g2->length);
202 }
203
204 /**
205 * @brief mar_cpg_iteration_description_t struct
206 */
207 typedef struct {
208 mar_cpg_name_t group;
209 mar_uint32_t nodeid;
210 mar_uint32_t pid;
211 } mar_cpg_iteration_description_t;
212
213 /**
214 * @brief marshall_from_mar_cpg_iteration_description_t
215 * @param dest
216 * @param src
217 */
marshall_from_mar_cpg_iteration_description_t(struct cpg_iteration_description_t * dest,const mar_cpg_iteration_description_t * src)218 static inline void marshall_from_mar_cpg_iteration_description_t(
219 struct cpg_iteration_description_t *dest,
220 const mar_cpg_iteration_description_t *src)
221 {
222 dest->nodeid = src->nodeid;
223 dest->pid = src->pid;
224 marshall_from_mar_cpg_name_t (&dest->group, &src->group);
225 };
226
227 /**
228 * @brief mar_cpg_ring_id_t struct
229 */
230 typedef struct {
231 mar_uint32_t nodeid __attribute__((aligned(8)));
232 mar_uint64_t seq __attribute__((aligned(8)));
233 } mar_cpg_ring_id_t;
234
235 /**
236 * @brief marshall_from_mar_cpg_ring_id_t
237 * @param dest
238 * @param src
239 */
marshall_from_mar_cpg_ring_id_t(struct cpg_ring_id * dest,const mar_cpg_ring_id_t * src)240 static inline void marshall_from_mar_cpg_ring_id_t (
241 struct cpg_ring_id *dest,
242 const mar_cpg_ring_id_t *src)
243 {
244 dest->nodeid = src->nodeid;
245 dest->seq = src->seq;
246 }
247
248 /**
249 * @brief The req_lib_cpg_join struct
250 */
251 struct req_lib_cpg_join {
252 struct qb_ipc_request_header header __attribute__((aligned(8)));
253 mar_cpg_name_t group_name __attribute__((aligned(8)));
254 mar_uint32_t pid __attribute__((aligned(8)));
255 mar_uint32_t flags __attribute__((aligned(8)));
256 };
257
258 /**
259 * @brief The res_lib_cpg_join struct
260 */
261 struct res_lib_cpg_join {
262 struct qb_ipc_response_header header __attribute__((aligned(8)));
263 };
264
265 /**
266 * @brief The req_lib_cpg_finalize struct
267 */
268 struct req_lib_cpg_finalize {
269 struct qb_ipc_request_header header __attribute__((aligned(8)));
270 };
271
272 /**
273 * @brief The res_lib_cpg_finalize struct
274 */
275 struct res_lib_cpg_finalize {
276 struct qb_ipc_response_header header __attribute__((aligned(8)));
277 };
278
279 /**
280 * @brief The req_lib_cpg_local_get struct
281 */
282 struct req_lib_cpg_local_get {
283 struct qb_ipc_request_header header __attribute__((aligned(8)));
284 };
285
286 /**
287 * @brief The res_lib_cpg_local_get struct
288 */
289 struct res_lib_cpg_local_get {
290 struct qb_ipc_response_header header __attribute__((aligned(8)));
291 mar_uint32_t local_nodeid __attribute__((aligned(8)));
292 };
293
294 /**
295 * @brief The res_lib_cpg_partial_send struct
296 */
297 struct res_lib_cpg_partial_send {
298 struct qb_ipc_response_header header __attribute__((aligned(8)));
299 };
300
301 /**
302 * @brief The req_lib_cpg_mcast struct
303 */
304 struct req_lib_cpg_mcast {
305 struct qb_ipc_response_header header __attribute__((aligned(8)));
306 mar_uint32_t guarantee __attribute__((aligned(8)));
307 mar_uint32_t msglen __attribute__((aligned(8)));
308 mar_uint8_t message[] __attribute__((aligned(8)));
309 };
310
311 /**
312 * @brief The req_lib_cpg_partial_mcast struct
313 */
314 struct req_lib_cpg_partial_mcast {
315 struct qb_ipc_response_header header __attribute__((aligned(8)));
316 mar_uint32_t guarantee __attribute__((aligned(8)));
317 mar_uint32_t msglen __attribute__((aligned(8)));
318 mar_uint32_t fraglen __attribute__((aligned(8)));
319 mar_uint32_t type __attribute__((aligned(8)));
320 mar_uint8_t message[] __attribute__((aligned(8)));
321 };
322
323 /**
324 * @brief The res_lib_cpg_mcast struct
325 */
326 struct res_lib_cpg_mcast {
327 struct qb_ipc_response_header header __attribute__((aligned(8)));
328 };
329
330 /**
331 * Message from another node
332 */
333 struct res_lib_cpg_deliver_callback {
334 struct qb_ipc_response_header header __attribute__((aligned(8)));
335 mar_cpg_name_t group_name __attribute__((aligned(8)));
336 mar_uint32_t msglen __attribute__((aligned(8)));
337 mar_uint32_t nodeid __attribute__((aligned(8)));
338 mar_uint32_t pid __attribute__((aligned(8)));
339 mar_uint8_t message[] __attribute__((aligned(8)));
340 };
341
342 /**
343 * @brief The res_lib_cpg_partial_deliver_callback struct
344 */
345 struct res_lib_cpg_partial_deliver_callback {
346 struct qb_ipc_response_header header __attribute__((aligned(8)));
347 mar_cpg_name_t group_name __attribute__((aligned(8)));
348 mar_uint32_t msglen __attribute__((aligned(8)));
349 mar_uint32_t fraglen __attribute__((aligned(8)));
350 mar_uint32_t nodeid __attribute__((aligned(8)));
351 mar_uint32_t pid __attribute__((aligned(8)));
352 mar_uint32_t type __attribute__((aligned(8)));
353 mar_uint8_t message[] __attribute__((aligned(8)));
354 };
355
356 /**
357 * @brief The res_lib_cpg_flowcontrol_callback struct
358 */
359 struct res_lib_cpg_flowcontrol_callback {
360 struct qb_ipc_response_header header __attribute__((aligned(8)));
361 mar_uint32_t flow_control_state __attribute__((aligned(8)));
362 };
363
364 /**
365 * @brief The req_lib_cpg_membership_get struct
366 */
367 struct req_lib_cpg_membership_get {
368 struct qb_ipc_request_header header __attribute__((aligned(8)));
369 mar_cpg_name_t group_name __attribute__((aligned(8)));
370 };
371
372 /**
373 * @brief The res_lib_cpg_membership_get struct
374 */
375 struct res_lib_cpg_membership_get {
376 struct qb_ipc_response_header header __attribute__((aligned(8)));
377 mar_uint32_t member_count __attribute__((aligned(8)));
378 mar_cpg_address_t member_list[PROCESSOR_COUNT_MAX];
379 };
380
381 /**
382 * @brief The res_lib_cpg_confchg_callback struct
383 */
384 struct res_lib_cpg_confchg_callback {
385 struct qb_ipc_response_header header __attribute__((aligned(8)));
386 mar_cpg_name_t group_name __attribute__((aligned(8)));
387 mar_uint32_t member_list_entries __attribute__((aligned(8)));
388 mar_uint32_t joined_list_entries __attribute__((aligned(8)));
389 mar_uint32_t left_list_entries __attribute__((aligned(8)));
390 mar_cpg_address_t member_list[];
391 // struct cpg_address left_list[];
392 // struct cpg_address joined_list[];
393 };
394
395 /**
396 * @brief The res_lib_cpg_totem_confchg_callback struct
397 */
398 struct res_lib_cpg_totem_confchg_callback {
399 struct qb_ipc_response_header header __attribute__((aligned(8)));
400 mar_cpg_ring_id_t ring_id __attribute__((aligned(8)));
401 mar_uint32_t member_list_entries __attribute__((aligned(8)));
402 mar_uint32_t member_list[];
403 };
404
405 /**
406 * @brief The req_lib_cpg_leave struct
407 */
408 struct req_lib_cpg_leave {
409 struct qb_ipc_request_header header __attribute__((aligned(8)));
410 mar_cpg_name_t group_name __attribute__((aligned(8)));
411 mar_uint32_t pid __attribute__((aligned(8)));
412 };
413
414 /**
415 * @brief The res_lib_cpg_leave struct
416 */
417 struct res_lib_cpg_leave {
418 struct qb_ipc_response_header header __attribute__((aligned(8)));
419 };
420
421 /**
422 * @brief The req_lib_cpg_iterationinitialize struct
423 */
424 struct req_lib_cpg_iterationinitialize {
425 struct qb_ipc_request_header header __attribute__((aligned(8)));
426 mar_cpg_name_t group_name __attribute__((aligned(8)));
427 mar_uint32_t iteration_type __attribute__((aligned(8)));
428 };
429
430 /**
431 * @brief The res_lib_cpg_iterationinitialize struct
432 */
433 struct res_lib_cpg_iterationinitialize {
434 struct qb_ipc_response_header header __attribute__((aligned(8)));
435 hdb_handle_t iteration_handle __attribute__((aligned(8)));
436 };
437
438 /**
439 * @brief The req_lib_cpg_iterationnext struct
440 */
441 struct req_lib_cpg_iterationnext {
442 struct qb_ipc_request_header header __attribute__((aligned(8)));
443 hdb_handle_t iteration_handle __attribute__((aligned(8)));
444 };
445
446 /**
447 * @brief The res_lib_cpg_iterationnext struct
448 */
449 struct res_lib_cpg_iterationnext {
450 struct qb_ipc_response_header header __attribute__((aligned(8)));
451 mar_cpg_iteration_description_t description __attribute__((aligned(8)));
452 };
453
454 /**
455 * @brief The req_lib_cpg_iterationfinalize struct
456 */
457 struct req_lib_cpg_iterationfinalize {
458 struct qb_ipc_request_header header __attribute__((aligned(8)));
459 hdb_handle_t iteration_handle __attribute__((aligned(8)));
460 };
461
462 /**
463 * @brief The res_lib_cpg_iterationfinalize struct
464 */
465 struct res_lib_cpg_iterationfinalize {
466 struct qb_ipc_response_header header __attribute__((aligned(8)));
467 };
468
469 /**
470 * @brief mar_req_coroipcc_zc_alloc_t struct
471 */
472 typedef struct {
473 struct qb_ipc_request_header header __attribute__((aligned(8)));
474 size_t map_size __attribute__((aligned(8)));
475 char path_to_file[CPG_ZC_PATH_LEN] __attribute__((aligned(8)));
476 } mar_req_coroipcc_zc_alloc_t __attribute__((aligned(8)));
477
478 /**
479 * @brief mar_req_coroipcc_zc_free_t struct
480 */
481 typedef struct {
482 struct qb_ipc_request_header header __attribute__((aligned(8)));
483 size_t map_size __attribute__((aligned(8)));
484 uint64_t server_address __attribute__((aligned(8)));
485 } mar_req_coroipcc_zc_free_t __attribute__((aligned(8)));
486
487 /**
488 * @brief mar_req_coroipcc_zc_execute_t struct
489 */
490 typedef struct {
491 struct qb_ipc_request_header header __attribute__((aligned(8)));
492 uint64_t server_address __attribute__((aligned(8)));
493 } mar_req_coroipcc_zc_execute_t __attribute__((aligned(8)));
494
495 /**
496 * @brief coroipcs_zc_header struct
497 */
498 struct coroipcs_zc_header {
499 int map_size;
500 uint64_t server_address;
501 };
502 #endif /* IPC_CPG_H_DEFINED */
503