41 #include <sys/types.h> 42 #include <sys/socket.h> 44 #include <sys/ioctl.h> 45 #include <netinet/in.h> 55 #include <netinet/in.h> 56 #include <arpa/inet.h> 61 #include <qb/qbipc_common.h> 71 #define MAP_ANONYMOUS MAP_ANON 78 #define GROUP_HASH_SIZE 32 144 static struct list_head joinlist_messages_head;
173 static unsigned int my_member_list_entries;
177 static unsigned int my_old_member_list_entries = 0;
203 static int cpg_lib_init_fn (
void *conn);
205 static int cpg_lib_exit_fn (
void *conn);
207 static void message_handler_req_exec_cpg_procjoin (
211 static void message_handler_req_exec_cpg_procleave (
215 static void message_handler_req_exec_cpg_joinlist (
219 static void message_handler_req_exec_cpg_mcast (
223 static void message_handler_req_exec_cpg_partial_mcast (
227 static void message_handler_req_exec_cpg_downlist_old (
231 static void message_handler_req_exec_cpg_downlist (
235 static void exec_cpg_procjoin_endian_convert (
void *msg);
237 static void exec_cpg_joinlist_endian_convert (
void *msg);
239 static void exec_cpg_mcast_endian_convert (
void *msg);
241 static void exec_cpg_partial_mcast_endian_convert (
void *msg);
243 static void exec_cpg_downlist_endian_convert_old (
void *msg);
245 static void exec_cpg_downlist_endian_convert (
void *msg);
247 static void message_handler_req_lib_cpg_join (
void *conn,
const void *message);
249 static void message_handler_req_lib_cpg_leave (
void *conn,
const void *message);
251 static void message_handler_req_lib_cpg_finalize (
void *conn,
const void *message);
253 static void message_handler_req_lib_cpg_mcast (
void *conn,
const void *message);
255 static void message_handler_req_lib_cpg_partial_mcast (
void *conn,
const void *message);
257 static void message_handler_req_lib_cpg_membership (
void *conn,
258 const void *message);
260 static void message_handler_req_lib_cpg_local_get (
void *conn,
261 const void *message);
263 static void message_handler_req_lib_cpg_iteration_initialize (
265 const void *message);
267 static void message_handler_req_lib_cpg_iteration_next (
269 const void *message);
271 static void message_handler_req_lib_cpg_iteration_finalize (
273 const void *message);
275 static void message_handler_req_lib_cpg_zc_alloc (
277 const void *message);
279 static void message_handler_req_lib_cpg_zc_free (
281 const void *message);
283 static void message_handler_req_lib_cpg_zc_execute (
285 const void *message);
287 static int cpg_node_joinleave_send (
unsigned int pid,
const mar_cpg_name_t *group_name,
int fn,
int reason);
289 static int cpg_exec_send_downlist(
void);
291 static int cpg_exec_send_joinlist(
void);
293 static void downlist_inform_clients (
void);
295 static void joinlist_inform_clients (
void);
297 static void joinlist_messages_delete (
void);
299 static void cpg_sync_init (
300 const unsigned int *trans_list,
301 size_t trans_list_entries,
302 const unsigned int *member_list,
303 size_t member_list_entries,
306 static int cpg_sync_process (
void);
308 static void cpg_sync_activate (
void);
310 static void cpg_sync_abort (
void);
312 static void do_proc_join(
318 static void do_proc_leave(
324 static int notify_lib_totem_membership (
326 int member_list_entries,
327 const unsigned int *member_list);
329 static inline int zcb_all_free (
332 static char *cpg_print_group_name (
345 .lib_handler_fn = message_handler_req_lib_cpg_leave,
349 .lib_handler_fn = message_handler_req_lib_cpg_mcast,
353 .lib_handler_fn = message_handler_req_lib_cpg_membership,
357 .lib_handler_fn = message_handler_req_lib_cpg_local_get,
361 .lib_handler_fn = message_handler_req_lib_cpg_iteration_initialize,
365 .lib_handler_fn = message_handler_req_lib_cpg_iteration_next,
369 .lib_handler_fn = message_handler_req_lib_cpg_iteration_finalize,
373 .lib_handler_fn = message_handler_req_lib_cpg_finalize,
377 .lib_handler_fn = message_handler_req_lib_cpg_zc_alloc,
381 .lib_handler_fn = message_handler_req_lib_cpg_zc_free,
385 .lib_handler_fn = message_handler_req_lib_cpg_zc_execute,
389 .lib_handler_fn = message_handler_req_lib_cpg_partial_mcast,
399 .exec_endian_convert_fn = exec_cpg_procjoin_endian_convert
402 .exec_handler_fn = message_handler_req_exec_cpg_procleave,
403 .exec_endian_convert_fn = exec_cpg_procjoin_endian_convert
406 .exec_handler_fn = message_handler_req_exec_cpg_joinlist,
407 .exec_endian_convert_fn = exec_cpg_joinlist_endian_convert
410 .exec_handler_fn = message_handler_req_exec_cpg_mcast,
411 .exec_endian_convert_fn = exec_cpg_mcast_endian_convert
414 .exec_handler_fn = message_handler_req_exec_cpg_downlist_old,
415 .exec_endian_convert_fn = exec_cpg_downlist_endian_convert_old
418 .exec_handler_fn = message_handler_req_exec_cpg_downlist,
419 .exec_endian_convert_fn = exec_cpg_downlist_endian_convert
422 .exec_handler_fn = message_handler_req_exec_cpg_partial_mcast,
423 .exec_endian_convert_fn = exec_cpg_partial_mcast_endian_convert
428 .
name =
"corosync cluster closed process group service v1.01",
431 .private_data_size =
sizeof (
struct cpg_pd),
434 .lib_init_fn = cpg_lib_init_fn,
435 .lib_exit_fn = cpg_lib_exit_fn,
436 .lib_engine = cpg_lib_engine,
438 .exec_init_fn = cpg_exec_init_fn,
439 .exec_dump_fn = NULL,
440 .exec_engine = cpg_exec_engine,
442 .sync_init = cpg_sync_init,
443 .sync_process = cpg_sync_process,
444 .sync_activate = cpg_sync_activate,
445 .sync_abort = cpg_sync_abort
450 return (&cpg_service_engine);
454 struct qb_ipc_request_header header __attribute__((aligned(8)));
461 struct qb_ipc_request_header header __attribute__((aligned(8)));
470 struct qb_ipc_request_header header __attribute__((aligned(8)));
481 struct qb_ipc_request_header header __attribute__((aligned(8)));
487 struct qb_ipc_request_header header __attribute__((aligned(8)));
514 for (i = 0; i < group->length; i++) {
517 if (c >=
' ' && c < 0x7f && c !=
'\\') {
521 res[dest_pos++] =
'\\';
522 res[dest_pos++] =
'\\';
524 snprintf(res + dest_pos,
sizeof(res) - dest_pos,
"\\x%02X", c);
534 static void cpg_sync_init (
535 const unsigned int *trans_list,
536 size_t trans_list_entries,
537 const unsigned int *member_list,
538 size_t member_list_entries,
547 memcpy (my_member_list, member_list, member_list_entries *
548 sizeof (
unsigned int));
549 my_member_list_entries = member_list_entries;
551 last_sync_ring_id.nodeid = ring_id->
rep.
nodeid;
552 last_sync_ring_id.seq = ring_id->
seq;
558 for (i = 0; i < my_old_member_list_entries; i++) {
560 for (j = 0; j < trans_list_entries; j++) {
561 if (my_old_member_list[i] == trans_list[j]) {
567 g_req_exec_cpg_downlist.nodeids[entries++] =
568 my_old_member_list[i];
571 g_req_exec_cpg_downlist.left_nodes = entries;
574 static int cpg_sync_process (
void)
579 res = cpg_exec_send_downlist();
586 res = cpg_exec_send_joinlist();
591 static void cpg_sync_activate (
void)
593 memcpy (my_old_member_list, my_member_list,
594 my_member_list_entries *
sizeof (
unsigned int));
595 my_old_member_list_entries = my_member_list_entries;
597 downlist_inform_clients ();
599 joinlist_inform_clients ();
601 joinlist_messages_delete ();
603 notify_lib_totem_membership (NULL, my_member_list_entries, my_member_list);
606 static void cpg_sync_abort (
void)
609 joinlist_messages_delete ();
612 static int notify_lib_totem_membership (
614 int member_list_entries,
615 const unsigned int *member_list)
629 res->member_list_entries = member_list_entries;
630 res->header.size =
size;
632 res->header.error =
CS_OK;
638 for (iter = cpg_pd_list_head.
next; iter != &cpg_pd_list_head; iter = iter->
next) {
649 static int notify_lib_joinlist(
652 int joined_list_entries,
654 int left_list_entries,
667 for (iter = process_info_list_head.
next; iter != &process_info_list_head; iter = iter->
next) {
669 if (mar_name_compare (&pi->
group, group_name) == 0) {
673 for (i = 0; i < left_list_entries; i++) {
674 if (left_list[i].
nodeid == pi->
nodeid && left_list[i].pid == pi->
pid) {
691 res->joined_list_entries = joined_list_entries;
692 res->left_list_entries = left_list_entries;
693 res->member_list_entries = count;
695 res->header.size =
size;
697 res->header.error =
CS_OK;
700 for (iter = process_info_list_head.
next; iter != &process_info_list_head; iter = iter->
next) {
703 if (mar_name_compare (&pi->
group, group_name) == 0) {
707 for (i = 0;i < left_list_entries; i++) {
708 if (left_list[i].
nodeid == pi->
nodeid && left_list[i].pid == pi->
pid) {
714 retgi->nodeid = pi->
nodeid;
715 retgi->pid = pi->
pid;
721 if (left_list_entries) {
723 retgi += left_list_entries;
726 if (joined_list_entries) {
728 retgi += joined_list_entries;
734 for (iter = cpg_pd_list_head.
next; iter != &cpg_pd_list_head; iter = iter->
next) {
736 if (mar_name_compare (&cpd->
group_name, group_name) == 0) {
737 assert (joined_list_entries <= 1);
738 if (joined_list_entries) {
739 if (joined_list[0].
pid == cpd->
pid &&
750 if (left_list_entries) {
751 if (left_list[0].
pid == cpd->
pid &&
768 for (iter = cpg_pd_list_head.
next; iter != &cpg_pd_list_head; iter = iter->
next) {
774 notify_lib_totem_membership (cpd->
conn, my_old_member_list_entries, my_old_member_list);
784 "%s: members(old:%d left:%d)",
790 static void downlist_inform_clients (
void)
800 int left_list_entries;
803 qb_map_iter_t *miter;
806 downlist_log(
"my downlist", &g_req_exec_cpg_downlist);
808 group_map = qb_skiplist_create();
815 for (iter = process_info_list_head.
next; iter != &process_info_list_head; ) {
820 for (i = 0; i < g_req_exec_cpg_downlist.left_nodes; i++) {
822 if (pi->
nodeid == g_req_exec_cpg_downlist.nodeids[i]) {
829 marshall_from_mar_cpg_name_t(&cpg_group, &left_pi->
group);
830 cpg_group.value[cpg_group.length] = 0;
832 pcd = (
struct confchg_data *)qb_map_get(group_map, cpg_group.value);
834 pcd = (
struct confchg_data *)calloc(1,
sizeof(
struct confchg_data));
835 memcpy(&pcd->cpg_group, &cpg_group,
sizeof(
struct cpg_name));
836 qb_map_put(group_map, pcd->cpg_group.value, pcd);
838 size = pcd->left_list_entries;
839 pcd->left_list[
size].nodeid = left_pi->
nodeid;
840 pcd->left_list[
size].pid = left_pi->
pid;
842 pcd->left_list_entries++;
843 list_del (&left_pi->
list);
849 miter = qb_map_iter_create(group_map);
850 while (qb_map_iter_next(miter, (
void **)&pcd)) {
851 marshall_to_mar_cpg_name_t(&group, &pcd->cpg_group);
853 log_printf (LOG_DEBUG,
"left_list_entries:%d", pcd->left_list_entries);
854 for (i=0; i<pcd->left_list_entries; i++) {
855 log_printf (LOG_DEBUG,
"left_list[%d] group:%s, ip:%s, pid:%d",
856 i, cpg_print_group_name(&group),
858 pcd->left_list[i].pid);
862 notify_lib_joinlist(&group, NULL,
864 pcd->left_list_entries,
870 qb_map_iter_free(miter);
871 qb_map_destroy(group_map);
877 static void joinlist_remove_zombie_pi_entries (
void)
885 for (pi_iter = process_info_list_head.
next; pi_iter != &process_info_list_head; ) {
887 pi_iter = pi_iter->
next;
900 for (jl_iter = joinlist_messages_head.
next;
901 jl_iter != &joinlist_messages_head;
902 jl_iter = jl_iter->
next) {
911 pi->
pid == stored_msg->
pid &&
924 static void joinlist_inform_clients (
void)
931 for (iter = joinlist_messages_head.
next;
932 iter != &joinlist_messages_head;
937 log_printf (LOG_DEBUG,
"joinlist_messages[%u] group:%s, ip:%s, pid:%d",
938 i++, cpg_print_group_name(&stored_msg->
group_name),
951 joinlist_remove_zombie_pi_entries ();
954 static void joinlist_messages_delete (
void)
959 for (iter = joinlist_messages_head.
next;
960 iter != &joinlist_messages_head;
963 iter_next = iter->
next;
966 list_del (&stored_msg->
list);
969 list_init (&joinlist_messages_head);
974 list_init (&joinlist_messages_head);
988 iter_next = iter->
next;
991 list_del (&pi->
list);
995 list_del (&cpg_iteration_instance->
list);
996 hdb_handle_destroy (&cpg_iteration_handle_t_db, cpg_iteration_instance->
handle);
999 static void cpg_pd_finalize (
struct cpg_pd *cpd)
1002 struct cpg_iteration_instance *cpii;
1009 iter_next = iter->
next;
1011 cpii =
list_entry (iter,
struct cpg_iteration_instance, list);
1013 cpg_iteration_instance_finalize (cpii);
1016 list_del (&cpd->
list);
1019 static int cpg_lib_exit_fn (
void *conn)
1030 cpg_pd_finalize (cpd);
1036 static int cpg_node_joinleave_send (
unsigned int pid,
const mar_cpg_name_t *group_name,
int fn,
int reason)
1039 struct iovec req_exec_cpg_iovec;
1058 static void exec_cpg_procjoin_endian_convert (
void *msg)
1062 req_exec_cpg_procjoin->pid =
swab32(req_exec_cpg_procjoin->pid);
1063 swab_mar_cpg_name_t (&req_exec_cpg_procjoin->group_name);
1064 req_exec_cpg_procjoin->reason =
swab32(req_exec_cpg_procjoin->reason);
1067 static void exec_cpg_joinlist_endian_convert (
void *msg_v)
1070 struct qb_ipc_response_header *res = (
struct qb_ipc_response_header *)msg;
1073 swab_mar_int32_t (&res->size);
1075 while ((
const char*)jle < msg + res->size) {
1082 static void exec_cpg_downlist_endian_convert_old (
void *msg)
1086 static void exec_cpg_downlist_endian_convert (
void *msg)
1091 req_exec_cpg_downlist->left_nodes =
swab32(req_exec_cpg_downlist->left_nodes);
1092 req_exec_cpg_downlist->old_members =
swab32(req_exec_cpg_downlist->old_members);
1094 for (i = 0; i < req_exec_cpg_downlist->left_nodes; i++) {
1095 req_exec_cpg_downlist->nodeids[i] =
swab32(req_exec_cpg_downlist->nodeids[i]);
1100 static void exec_cpg_mcast_endian_convert (
void *msg)
1104 swab_coroipc_request_header_t (&req_exec_cpg_mcast->header);
1105 swab_mar_cpg_name_t (&req_exec_cpg_mcast->group_name);
1106 req_exec_cpg_mcast->pid =
swab32(req_exec_cpg_mcast->pid);
1107 req_exec_cpg_mcast->msglen =
swab32(req_exec_cpg_mcast->msglen);
1108 swab_mar_message_source_t (&req_exec_cpg_mcast->source);
1111 static void exec_cpg_partial_mcast_endian_convert (
void *msg)
1115 swab_coroipc_request_header_t (&req_exec_cpg_mcast->header);
1116 swab_mar_cpg_name_t (&req_exec_cpg_mcast->group_name);
1117 req_exec_cpg_mcast->pid =
swab32(req_exec_cpg_mcast->pid);
1118 req_exec_cpg_mcast->msglen =
swab32(req_exec_cpg_mcast->msglen);
1119 req_exec_cpg_mcast->fraglen =
swab32(req_exec_cpg_mcast->fraglen);
1120 req_exec_cpg_mcast->type =
swab32(req_exec_cpg_mcast->type);
1121 swab_mar_message_source_t (&req_exec_cpg_mcast->source);
1127 for (iter = process_info_list_head.
next; iter != &process_info_list_head; ) {
1131 if (pi->
pid == pid && pi->
nodeid == nodeid &&
1132 mar_name_compare (&pi->
group, group_name) == 0) {
1140 static void do_proc_join(
1143 unsigned int nodeid,
1152 if (process_info_find (name, pid, nodeid) != NULL) {
1162 memcpy(&pi->
group, name,
sizeof(*name));
1163 list_init(&pi->
list);
1168 list_to_add = &process_info_list_head;
1169 for (list = process_info_list_head.
next; list != &process_info_list_head; list = list->
next) {
1179 list_add (&pi->
list, list_to_add);
1181 notify_info.pid = pi->
pid;
1182 notify_info.nodeid =
nodeid;
1183 notify_info.reason = reason;
1185 notify_lib_joinlist(&pi->
group, NULL,
1191 static void do_proc_leave(
1194 unsigned int nodeid,
1201 notify_info.pid = pid;
1202 notify_info.nodeid =
nodeid;
1203 notify_info.reason = reason;
1205 notify_lib_joinlist(name, NULL,
1210 for (iter = process_info_list_head.
next; iter != &process_info_list_head; ) {
1214 if (pi->
pid == pid && pi->
nodeid == nodeid &&
1215 mar_name_compare (&pi->
group, name)==0) {
1216 list_del (&pi->
list);
1222 static void message_handler_req_exec_cpg_downlist_old (
1223 const void *message,
1224 unsigned int nodeid)
1230 static void message_handler_req_exec_cpg_downlist(
1231 const void *message,
1232 unsigned int nodeid)
1234 const struct req_exec_cpg_downlist *req_exec_cpg_downlist = message;
1237 req_exec_cpg_downlist->left_nodes);
1241 static void message_handler_req_exec_cpg_procjoin (
1242 const void *message,
1243 unsigned int nodeid)
1250 (
unsigned int)req_exec_cpg_procjoin->pid);
1252 do_proc_join (&req_exec_cpg_procjoin->group_name,
1253 req_exec_cpg_procjoin->pid, nodeid,
1257 static void message_handler_req_exec_cpg_procleave (
1258 const void *message,
1259 unsigned int nodeid)
1266 (
unsigned int)req_exec_cpg_procjoin->pid);
1268 do_proc_leave (&req_exec_cpg_procjoin->group_name,
1269 req_exec_cpg_procjoin->pid, nodeid,
1270 req_exec_cpg_procjoin->reason);
1275 static void message_handler_req_exec_cpg_joinlist (
1276 const void *message_v,
1277 unsigned int nodeid)
1279 const char *message = message_v;
1280 const struct qb_ipc_response_header *res = (
const struct qb_ipc_response_header *)message;
1287 while ((
const char*)jle < message + res->size) {
1291 stored_msg->
pid = jle->
pid;
1293 list_init (&stored_msg->
list);
1294 list_add (&stored_msg->
list, &joinlist_messages_head);
1299 static void message_handler_req_exec_cpg_mcast (
1300 const void *message,
1301 unsigned int nodeid)
1305 int msglen = req_exec_cpg_mcast->msglen;
1308 struct iovec iovec[2];
1322 iovec[1].iov_base = (
char*)message+
sizeof(*req_exec_cpg_mcast);
1323 iovec[1].iov_len = msglen;
1325 for (iter = cpg_pd_list_head.
next; iter != &cpg_pd_list_head; ) {
1330 && (mar_name_compare (&cpd->
group_name, &req_exec_cpg_mcast->group_name) == 0)) {
1334 for (pi_iter = process_info_list_head.
next;
1335 pi_iter != &process_info_list_head; pi_iter = pi_iter->
next) {
1339 if (pi->
nodeid == nodeid &&
1340 mar_name_compare (&pi->
group, &req_exec_cpg_mcast->group_name) == 0) {
1357 static void message_handler_req_exec_cpg_partial_mcast (
1358 const void *message,
1359 unsigned int nodeid)
1363 int msglen = req_exec_cpg_mcast->fraglen;
1366 struct iovec iovec[2];
1384 iovec[1].iov_base = (
char*)message+
sizeof(*req_exec_cpg_mcast);
1385 iovec[1].iov_len = msglen;
1387 for (iter = cpg_pd_list_head.
next; iter != &cpg_pd_list_head; ) {
1392 && (mar_name_compare (&cpd->
group_name, &req_exec_cpg_mcast->group_name) == 0)) {
1396 for (pi_iter = process_info_list_head.
next;
1397 pi_iter != &process_info_list_head; pi_iter = pi_iter->
next) {
1401 if (pi->
nodeid == nodeid &&
1402 mar_name_compare (&pi->
group, &req_exec_cpg_mcast->group_name) == 0) {
1420 static int cpg_exec_send_downlist(
void)
1425 g_req_exec_cpg_downlist.header.size =
sizeof(
struct req_exec_cpg_downlist);
1427 g_req_exec_cpg_downlist.old_members = my_old_member_list_entries;
1429 iov.iov_base = (
void *)&g_req_exec_cpg_downlist;
1430 iov.iov_len = g_req_exec_cpg_downlist.header.size;
1435 static int cpg_exec_send_joinlist(
void)
1439 struct qb_ipc_response_header *res;
1442 struct iovec req_exec_cpg_iovec;
1444 for (iter = process_info_list_head.
next; iter != &process_info_list_head; iter = iter->
next) {
1456 buf = alloca(
sizeof(
struct qb_ipc_response_header) +
sizeof(
struct join_list_entry) * count);
1462 jle = (
struct join_list_entry *)(buf +
sizeof(
struct qb_ipc_response_header));
1463 res = (
struct qb_ipc_response_header *)buf;
1465 for (iter = process_info_list_head.
next; iter != &process_info_list_head; iter = iter->
next) {
1476 res->size =
sizeof(
struct qb_ipc_response_header)+sizeof(struct
join_list_entry) * count;
1478 req_exec_cpg_iovec.iov_base = buf;
1479 req_exec_cpg_iovec.iov_len = res->size;
1484 static int cpg_lib_init_fn (
void *conn)
1487 memset (cpd, 0,
sizeof(
struct cpg_pd));
1489 list_add (&cpd->
list, &cpg_pd_list_head);
1500 static void message_handler_req_lib_cpg_join (
void *conn,
const void *message)
1509 for (iter = cpg_pd_list_head.
next; iter != &cpg_pd_list_head; iter = iter->
next) {
1512 if (cpd_item->
pid == req_lib_cpg_join->pid &&
1513 mar_name_compare(&req_lib_cpg_join->group_name, &cpd_item->
group_name) == 0) {
1525 for (iter = process_info_list_head.
next; iter != &process_info_list_head; iter = iter->
next) {
1529 mar_name_compare(&req_lib_cpg_join->group_name, &pi->
group) == 0) {
1545 cpd->
pid = req_lib_cpg_join->pid;
1546 cpd->
flags = req_lib_cpg_join->flags;
1547 memcpy (&cpd->
group_name, &req_lib_cpg_join->group_name,
1550 cpg_node_joinleave_send (req_lib_cpg_join->pid,
1551 &req_lib_cpg_join->group_name,
1573 static void message_handler_req_lib_cpg_leave (
void *conn,
const void *message)
1595 cpg_node_joinleave_send (req_lib_cpg_leave->pid,
1596 &req_lib_cpg_leave->group_name,
1610 static void message_handler_req_lib_cpg_finalize (
1612 const void *message)
1624 list_del (&cpd->
list);
1625 list_init (&cpd->
list);
1645 fd = open (path, O_RDWR, 0600);
1653 res = ftruncate (fd, bytes);
1655 goto error_close_unlink;
1658 addr = mmap (NULL, bytes, PROT_READ | PROT_WRITE,
1661 if (addr == MAP_FAILED) {
1662 goto error_close_unlink;
1665 madvise(addr, bytes, MADV_NOSYNC);
1670 munmap (addr, bytes);
1682 static inline int zcb_alloc (
1684 const char *path_to_file,
1691 zcb_mapped = malloc (
sizeof (
struct zcb_mapped));
1692 if (zcb_mapped == NULL) {
1705 list_init (&zcb_mapped->
list);
1713 static inline int zcb_free (
struct zcb_mapped *zcb_mapped)
1717 res = munmap (zcb_mapped->
addr, zcb_mapped->
size);
1718 list_del (&zcb_mapped->
list);
1723 static inline int zcb_by_addr_free (
struct cpg_pd *cpd,
void *addr)
1726 struct zcb_mapped *zcb_mapped;
1727 unsigned int res = 0;
1732 zcb_mapped =
list_entry (list,
struct zcb_mapped, list);
1734 if (zcb_mapped->
addr == addr) {
1735 res = zcb_free (zcb_mapped);
1743 static inline int zcb_all_free (
1747 struct zcb_mapped *zcb_mapped;
1752 zcb_mapped =
list_entry (list,
struct zcb_mapped, list);
1756 zcb_free (zcb_mapped);
1766 static uint64_t void2serveraddr (
void *server_ptr)
1774 static void *serveraddr2void (uint64_t
server_addr)
1782 static void message_handler_req_lib_cpg_zc_alloc (
1784 const void *message)
1787 struct qb_ipc_response_header res_header;
1795 res = zcb_alloc (cpd, hdr->path_to_file, hdr->map_size,
1802 res_header.size =
sizeof (
struct qb_ipc_response_header);
1809 static void message_handler_req_lib_cpg_zc_free (
1811 const void *message)
1814 struct qb_ipc_response_header res_header;
1820 addr = serveraddr2void (hdr->server_address);
1822 zcb_by_addr_free (cpd, addr);
1824 res_header.size =
sizeof (
struct qb_ipc_response_header);
1832 static void message_handler_req_lib_cpg_partial_mcast (
void *conn,
const void *message)
1838 struct iovec req_exec_cpg_iovec[2];
1841 int msglen = req_lib_cpg_mcast->fraglen;
1863 res_lib_cpg_partial_send.header.size =
sizeof(res_lib_cpg_partial_send);
1873 if (error ==
CS_OK) {
1874 req_exec_cpg_mcast.header.size =
sizeof(req_exec_cpg_mcast) + msglen;
1877 req_exec_cpg_mcast.pid = cpd->
pid;
1878 req_exec_cpg_mcast.msglen = req_lib_cpg_mcast->msglen;
1879 req_exec_cpg_mcast.type = req_lib_cpg_mcast->type;
1880 req_exec_cpg_mcast.fraglen = req_lib_cpg_mcast->fraglen;
1882 memcpy(&req_exec_cpg_mcast.group_name, &group_name,
1885 req_exec_cpg_iovec[0].iov_base = (
char *)&req_exec_cpg_mcast;
1886 req_exec_cpg_iovec[0].iov_len =
sizeof(req_exec_cpg_mcast);
1887 req_exec_cpg_iovec[1].iov_base = (
char *)&req_lib_cpg_mcast->message;
1888 req_exec_cpg_iovec[1].iov_len = msglen;
1891 assert(result == 0);
1894 conn, group_name.value, cpd->
cpd_state, error);
1897 res_lib_cpg_partial_send.header.error = error;
1899 sizeof (res_lib_cpg_partial_send));
1903 static void message_handler_req_lib_cpg_mcast (
void *conn,
const void *message)
1909 struct iovec req_exec_cpg_iovec[2];
1910 struct req_exec_cpg_mcast req_exec_cpg_mcast;
1911 int msglen = req_lib_cpg_mcast->msglen;
1932 if (error ==
CS_OK) {
1933 req_exec_cpg_mcast.header.size =
sizeof(req_exec_cpg_mcast) + msglen;
1936 req_exec_cpg_mcast.pid = cpd->
pid;
1937 req_exec_cpg_mcast.msglen = msglen;
1939 memcpy(&req_exec_cpg_mcast.group_name, &group_name,
1942 req_exec_cpg_iovec[0].iov_base = (
char *)&req_exec_cpg_mcast;
1943 req_exec_cpg_iovec[0].iov_len =
sizeof(req_exec_cpg_mcast);
1944 req_exec_cpg_iovec[1].iov_base = (
char *)&req_lib_cpg_mcast->message;
1945 req_exec_cpg_iovec[1].iov_len = msglen;
1948 assert(result == 0);
1951 conn, group_name.value, cpd->
cpd_state, error);
1955 static void message_handler_req_lib_cpg_zc_execute (
1957 const void *message)
1960 struct qb_ipc_request_header *
header;
1963 struct iovec req_exec_cpg_iovec[2];
1964 struct req_exec_cpg_mcast req_exec_cpg_mcast;
1971 header = (
struct qb_ipc_request_header *)(((
char *)serveraddr2void(hdr->server_address) + sizeof (
struct coroipcs_zc_header)));
1972 req_lib_cpg_mcast = (
struct req_lib_cpg_mcast *)header;
1989 res_lib_cpg_mcast.header.size =
sizeof(res_lib_cpg_mcast);
1991 if (error ==
CS_OK) {
1992 req_exec_cpg_mcast.header.size =
sizeof(req_exec_cpg_mcast) + req_lib_cpg_mcast->msglen;
1995 req_exec_cpg_mcast.pid = cpd->
pid;
1996 req_exec_cpg_mcast.msglen = req_lib_cpg_mcast->msglen;
1998 memcpy(&req_exec_cpg_mcast.group_name, &cpd->
group_name,
2001 req_exec_cpg_iovec[0].iov_base = (
char *)&req_exec_cpg_mcast;
2002 req_exec_cpg_iovec[0].iov_len =
sizeof(req_exec_cpg_mcast);
2003 req_exec_cpg_iovec[1].iov_base = (
char *)header +
sizeof(
struct req_lib_cpg_mcast);
2004 req_exec_cpg_iovec[1].iov_len = req_exec_cpg_mcast.msglen;
2008 res_lib_cpg_mcast.header.error =
CS_OK;
2013 res_lib_cpg_mcast.header.error = error;
2017 sizeof (res_lib_cpg_mcast));
2021 static void message_handler_req_lib_cpg_membership (
void *conn,
2022 const void *message)
2025 (
struct req_lib_cpg_membership_get *)message;
2028 int member_count = 0;
2031 res_lib_cpg_membership_get.header.error =
CS_OK;
2032 res_lib_cpg_membership_get.header.size =
2033 sizeof (
struct res_lib_cpg_membership_get);
2035 for (iter = process_info_list_head.
next;
2036 iter != &process_info_list_head; iter = iter->
next) {
2039 if (mar_name_compare (&pi->
group, &req_lib_cpg_membership_get->group_name) == 0) {
2041 res_lib_cpg_membership_get.
member_list[member_count].pid = pi->
pid;
2045 res_lib_cpg_membership_get.member_count = member_count;
2048 sizeof (res_lib_cpg_membership_get));
2051 static void message_handler_req_lib_cpg_local_get (
void *conn,
2052 const void *message)
2056 res_lib_cpg_local_get.header.size =
sizeof (res_lib_cpg_local_get);
2058 res_lib_cpg_local_get.header.error =
CS_OK;
2062 sizeof (res_lib_cpg_local_get));
2065 static void message_handler_req_lib_cpg_iteration_initialize (
2067 const void *message)
2074 struct cpg_iteration_instance *cpg_iteration_instance;
2087 res = hdb_handle_create (&cpg_iteration_handle_t_db,
sizeof (
struct cpg_iteration_instance),
2088 &cpg_iteration_handle);
2095 res = hdb_handle_get (&cpg_iteration_handle_t_db, cpg_iteration_handle, (
void *)&cpg_iteration_instance);
2102 list_init (&cpg_iteration_instance->items_list_head);
2103 cpg_iteration_instance->handle = cpg_iteration_handle;
2108 for (iter = process_info_list_head.
next; iter != &process_info_list_head; iter = iter->
next) {
2118 for (iter2 = cpg_iteration_instance->items_list_head.
next;
2119 iter2 != &cpg_iteration_instance->items_list_head;
2120 iter2 = iter2->
next) {
2123 if (mar_name_compare (&pi2->
group, &pi->
group) == 0) {
2139 if (mar_name_compare (&pi->
group, &req_lib_cpg_iterationinitialize->group_name) != 0)
2152 goto error_put_destroy;
2156 list_init (&new_pi->
list);
2168 for (iter2 = cpg_iteration_instance->items_list_head.
next;
2169 iter2 != &cpg_iteration_instance->items_list_head;
2170 iter2 = iter2->
next) {
2173 if (mar_name_compare (&pi2->
group, &pi->
group) == 0) {
2178 list_add (&new_pi->
list, iter2);
2188 list_init (&cpg_iteration_instance->list);
2191 cpg_iteration_instance->current_pointer = &cpg_iteration_instance->items_list_head;
2194 hdb_handle_put (&cpg_iteration_handle_t_db, cpg_iteration_handle);
2196 if (error !=
CS_OK) {
2197 hdb_handle_destroy (&cpg_iteration_handle_t_db, cpg_iteration_handle);
2201 res_lib_cpg_iterationinitialize.header.size =
sizeof (res_lib_cpg_iterationinitialize);
2203 res_lib_cpg_iterationinitialize.header.error = error;
2204 res_lib_cpg_iterationinitialize.iteration_handle = cpg_iteration_handle;
2207 sizeof (res_lib_cpg_iterationinitialize));
2210 static void message_handler_req_lib_cpg_iteration_next (
2212 const void *message)
2216 struct cpg_iteration_instance *cpg_iteration_instance;
2223 res = hdb_handle_get (&cpg_iteration_handle_t_db,
2224 req_lib_cpg_iterationnext->iteration_handle,
2225 (
void *)&cpg_iteration_instance);
2232 assert (cpg_iteration_instance);
2234 cpg_iteration_instance->current_pointer = cpg_iteration_instance->current_pointer->next;
2236 if (cpg_iteration_instance->current_pointer == &cpg_iteration_instance->items_list_head) {
2246 res_lib_cpg_iterationnext.description.nodeid = pi->
nodeid;
2247 res_lib_cpg_iterationnext.description.pid = pi->
pid;
2248 memcpy (&res_lib_cpg_iterationnext.description.group,
2253 hdb_handle_put (&cpg_iteration_handle_t_db, req_lib_cpg_iterationnext->iteration_handle);
2255 res_lib_cpg_iterationnext.header.size =
sizeof (res_lib_cpg_iterationnext);
2257 res_lib_cpg_iterationnext.header.error = error;
2260 sizeof (res_lib_cpg_iterationnext));
2263 static void message_handler_req_lib_cpg_iteration_finalize (
2265 const void *message)
2269 struct cpg_iteration_instance *cpg_iteration_instance;
2275 res = hdb_handle_get (&cpg_iteration_handle_t_db,
2276 req_lib_cpg_iterationfinalize->iteration_handle,
2277 (
void *)&cpg_iteration_instance);
2284 assert (cpg_iteration_instance);
2286 cpg_iteration_instance_finalize (cpg_iteration_instance);
2287 hdb_handle_put (&cpg_iteration_handle_t_db, cpg_iteration_instance->handle);
2290 res_lib_cpg_iterationfinalize.header.size =
sizeof (res_lib_cpg_iterationfinalize);
2292 res_lib_cpg_iterationfinalize.header.error = error;
2295 sizeof (res_lib_cpg_iterationfinalize));
void *(* ipc_private_data_get)(void *conn)
int initial_totem_conf_sent
mar_cpg_address_t member_list[]
mar_req_coroipcc_zc_free_t struct
#define CPG_MAX_NAME_LENGTH
uint64_t initial_transition_counter
#define LOGSYS_LEVEL_TRACE
mar_uint32_t sender_nodeid
#define CPG_MODEL_V1_DELIVER_INITIAL_TOTEM_CONF
The req_lib_cpg_join struct.
mar_req_coroipcc_zc_alloc_t struct
The corosync_service_engine struct.
int(* ipc_dispatch_iov_send)(void *conn, const struct iovec *iov, unsigned int iov_len)
int(* ipc_response_send)(void *conn, const void *msg, size_t mlen)
struct corosync_service_engine * cpg_get_service_engine_ver0(void)
The res_lib_cpg_partial_deliver_callback struct.
The req_lib_cpg_mcast struct.
The corosync_lib_handler struct.
The res_lib_cpg_membership_get struct.
struct message_header header
struct list_head * current_pointer
The res_lib_cpg_iterationnext struct.
The res_lib_cpg_iterationinitialize struct.
The corosync_exec_handler struct.
int(* totem_mcast)(const struct iovec *iovec, unsigned int iov_len, unsigned int guarantee)
uint64_t transition_counter
#define log_printf(level, format, args...)
The res_lib_cpg_partial_send struct.
void(* exec_handler_fn)(const void *msg, unsigned int nodeid)
struct list_head iteration_instance_list_head
#define SERVICE_ID_MAKE(a, b)
The req_lib_cpg_iterationinitialize struct.
#define LOGSYS_LEVEL_WARNING
The res_lib_cpg_join struct.
unsigned int(* totem_nodeid_get)(void)
void(* ipc_refcnt_dec)(void *conn)
mar_req_coroipcc_zc_execute_t struct
The res_lib_cpg_mcast struct.
#define LOGSYS_LEVEL_ERROR
struct totem_ip_address rep
mar_uint32_t member_list[]
cs_error_t
The cs_error_t enum.
The req_lib_cpg_leave struct.
#define LOGSYS_LEVEL_DEBUG
mar_cpg_address_t member_list[PROCESSOR_COUNT_MAX]
mar_cpg_name_t group_name
The req_lib_cpg_iterationfinalize struct.
mar_cpg_name_t group_name
The corosync_api_v1 struct.
LOGSYS_DECLARE_SUBSYS("CPG")
DECLARE_HDB_DATABASE(cpg_iteration_handle_t_db, NULL)
#define swab32(x)
The swab32 macro.
The res_lib_cpg_finalize struct.
The res_lib_cpg_local_get struct.
#define PROCESSOR_COUNT_MAX
The res_lib_cpg_iterationfinalize struct.
struct corosync_service_engine cpg_service_engine
The req_lib_cpg_partial_mcast struct.
struct list_head zcb_mapped_list_head
The req_lib_cpg_iterationnext struct.
const char *(* totem_ifaces_print)(unsigned int nodeid)
The res_lib_cpg_confchg_callback struct.
#define list_entry(ptr, type, member)
mar_cpg_name_t group_name
void(* lib_handler_fn)(void *conn, const void *msg)
The req_lib_cpg_membership_get struct.
int(* ipc_dispatch_send)(void *conn, const void *msg, size_t mlen)
struct list_head items_list_head
The res_lib_cpg_leave struct.
struct memb_ring_id ring_id
void(* ipc_source_set)(mar_message_source_t *source, void *conn)
The res_lib_cpg_totem_confchg_callback struct.
DECLARE_LIST_INIT(cpg_pd_list_head)
Message from another node.
The mar_message_source_t struct.
void(* ipc_refcnt_inc)(void *conn)