41 #include <sys/types.h> 42 #include <sys/socket.h> 44 #include <sys/ioctl.h> 45 #include <netinet/in.h> 54 #include <arpa/inet.h> 57 #include <qb/qblist.h> 61 #include <qb/qbipc_common.h> 70 #define MAP_ANONYMOUS MAP_ANON 77 #define GROUP_HASH_SIZE 32 143 static struct qb_list_head joinlist_messages_head;
155 struct qb_list_head iteration_instance_list_head;
156 struct qb_list_head zcb_mapped_list_head;
162 struct qb_list_head items_list_head;
172 static unsigned int my_member_list_entries;
176 static unsigned int my_old_member_list_entries = 0;
202 static int cpg_lib_init_fn (
void *conn);
204 static int cpg_lib_exit_fn (
void *conn);
206 static void message_handler_req_exec_cpg_procjoin (
210 static void message_handler_req_exec_cpg_procleave (
214 static void message_handler_req_exec_cpg_joinlist (
218 static void message_handler_req_exec_cpg_mcast (
222 static void message_handler_req_exec_cpg_partial_mcast (
226 static void message_handler_req_exec_cpg_downlist_old (
230 static void message_handler_req_exec_cpg_downlist (
234 static void exec_cpg_procjoin_endian_convert (
void *msg);
236 static void exec_cpg_joinlist_endian_convert (
void *msg);
238 static void exec_cpg_mcast_endian_convert (
void *msg);
240 static void exec_cpg_partial_mcast_endian_convert (
void *msg);
242 static void exec_cpg_downlist_endian_convert_old (
void *msg);
244 static void exec_cpg_downlist_endian_convert (
void *msg);
246 static void message_handler_req_lib_cpg_join (
void *conn,
const void *message);
248 static void message_handler_req_lib_cpg_leave (
void *conn,
const void *message);
250 static void message_handler_req_lib_cpg_finalize (
void *conn,
const void *message);
252 static void message_handler_req_lib_cpg_mcast (
void *conn,
const void *message);
254 static void message_handler_req_lib_cpg_partial_mcast (
void *conn,
const void *message);
256 static void message_handler_req_lib_cpg_membership (
void *conn,
257 const void *message);
259 static void message_handler_req_lib_cpg_local_get (
void *conn,
260 const void *message);
262 static void message_handler_req_lib_cpg_iteration_initialize (
264 const void *message);
266 static void message_handler_req_lib_cpg_iteration_next (
268 const void *message);
270 static void message_handler_req_lib_cpg_iteration_finalize (
272 const void *message);
274 static void message_handler_req_lib_cpg_zc_alloc (
276 const void *message);
278 static void message_handler_req_lib_cpg_zc_free (
280 const void *message);
282 static void message_handler_req_lib_cpg_zc_execute (
284 const void *message);
286 static int cpg_node_joinleave_send (
unsigned int pid,
const mar_cpg_name_t *group_name,
int fn,
int reason);
288 static int cpg_exec_send_downlist(
void);
290 static int cpg_exec_send_joinlist(
void);
292 static void downlist_inform_clients (
void);
294 static void joinlist_inform_clients (
void);
296 static void joinlist_messages_delete (
void);
298 static void cpg_sync_init (
299 const unsigned int *trans_list,
300 size_t trans_list_entries,
301 const unsigned int *member_list,
302 size_t member_list_entries,
305 static int cpg_sync_process (
void);
307 static void cpg_sync_activate (
void);
309 static void cpg_sync_abort (
void);
311 static void do_proc_join(
317 static void do_proc_leave(
323 static int notify_lib_totem_membership (
325 int member_list_entries,
326 const unsigned int *member_list);
328 static inline int zcb_all_free (
331 static char *cpg_print_group_name (
344 .lib_handler_fn = message_handler_req_lib_cpg_leave,
348 .lib_handler_fn = message_handler_req_lib_cpg_mcast,
352 .lib_handler_fn = message_handler_req_lib_cpg_membership,
356 .lib_handler_fn = message_handler_req_lib_cpg_local_get,
360 .lib_handler_fn = message_handler_req_lib_cpg_iteration_initialize,
364 .lib_handler_fn = message_handler_req_lib_cpg_iteration_next,
368 .lib_handler_fn = message_handler_req_lib_cpg_iteration_finalize,
372 .lib_handler_fn = message_handler_req_lib_cpg_finalize,
376 .lib_handler_fn = message_handler_req_lib_cpg_zc_alloc,
380 .lib_handler_fn = message_handler_req_lib_cpg_zc_free,
384 .lib_handler_fn = message_handler_req_lib_cpg_zc_execute,
388 .lib_handler_fn = message_handler_req_lib_cpg_partial_mcast,
398 .exec_endian_convert_fn = exec_cpg_procjoin_endian_convert
401 .exec_handler_fn = message_handler_req_exec_cpg_procleave,
402 .exec_endian_convert_fn = exec_cpg_procjoin_endian_convert
405 .exec_handler_fn = message_handler_req_exec_cpg_joinlist,
406 .exec_endian_convert_fn = exec_cpg_joinlist_endian_convert
409 .exec_handler_fn = message_handler_req_exec_cpg_mcast,
410 .exec_endian_convert_fn = exec_cpg_mcast_endian_convert
413 .exec_handler_fn = message_handler_req_exec_cpg_downlist_old,
414 .exec_endian_convert_fn = exec_cpg_downlist_endian_convert_old
417 .exec_handler_fn = message_handler_req_exec_cpg_downlist,
418 .exec_endian_convert_fn = exec_cpg_downlist_endian_convert
421 .exec_handler_fn = message_handler_req_exec_cpg_partial_mcast,
422 .exec_endian_convert_fn = exec_cpg_partial_mcast_endian_convert
427 .
name =
"corosync cluster closed process group service v1.01",
430 .private_data_size =
sizeof (
struct cpg_pd),
433 .lib_init_fn = cpg_lib_init_fn,
434 .lib_exit_fn = cpg_lib_exit_fn,
435 .lib_engine = cpg_lib_engine,
437 .exec_init_fn = cpg_exec_init_fn,
438 .exec_dump_fn = NULL,
439 .exec_engine = cpg_exec_engine,
441 .sync_init = cpg_sync_init,
442 .sync_process = cpg_sync_process,
443 .sync_activate = cpg_sync_activate,
444 .sync_abort = cpg_sync_abort
449 return (&cpg_service_engine);
453 struct qb_ipc_request_header header __attribute__((aligned(8)));
460 struct qb_ipc_request_header header __attribute__((aligned(8)));
469 struct qb_ipc_request_header header __attribute__((aligned(8)));
480 struct qb_ipc_request_header header __attribute__((aligned(8)));
486 struct qb_ipc_request_header header __attribute__((aligned(8)));
513 for (i = 0; i < group->length; i++) {
516 if (c >=
' ' && c < 0x7f && c !=
'\\') {
520 res[dest_pos++] =
'\\';
521 res[dest_pos++] =
'\\';
523 snprintf(res + dest_pos,
sizeof(res) - dest_pos,
"\\x%02X", c);
533 static void cpg_sync_init (
534 const unsigned int *trans_list,
535 size_t trans_list_entries,
536 const unsigned int *member_list,
537 size_t member_list_entries,
546 memcpy (my_member_list, member_list, member_list_entries *
547 sizeof (
unsigned int));
548 my_member_list_entries = member_list_entries;
550 last_sync_ring_id.nodeid = ring_id->
nodeid;
551 last_sync_ring_id.seq = ring_id->
seq;
557 for (i = 0; i < my_old_member_list_entries; i++) {
559 for (j = 0; j < trans_list_entries; j++) {
560 if (my_old_member_list[i] == trans_list[j]) {
566 g_req_exec_cpg_downlist.nodeids[entries++] =
567 my_old_member_list[i];
570 g_req_exec_cpg_downlist.left_nodes = entries;
573 static int cpg_sync_process (
void)
578 res = cpg_exec_send_downlist();
585 res = cpg_exec_send_joinlist();
590 static void cpg_sync_activate (
void)
592 memcpy (my_old_member_list, my_member_list,
593 my_member_list_entries *
sizeof (
unsigned int));
594 my_old_member_list_entries = my_member_list_entries;
596 downlist_inform_clients ();
598 joinlist_inform_clients ();
600 joinlist_messages_delete ();
602 notify_lib_totem_membership (NULL, my_member_list_entries, my_member_list);
605 static void cpg_sync_abort (
void)
608 joinlist_messages_delete ();
611 static int notify_lib_totem_membership (
613 int member_list_entries,
614 const unsigned int *member_list)
616 struct qb_list_head *iter;
628 res->member_list_entries = member_list_entries;
629 res->header.size =
size;
631 res->header.error =
CS_OK;
637 qb_list_for_each(iter, &cpg_pd_list_head) {
648 static int notify_lib_joinlist(
651 int joined_list_entries,
653 int left_list_entries,
659 struct qb_list_head *iter;
666 qb_list_for_each(iter, &process_info_list_head) {
668 if (mar_name_compare (&pi->
group, group_name) == 0) {
672 for (i = 0; i < left_list_entries; i++) {
673 if (left_list[i].
nodeid == pi->
nodeid && left_list[i].pid == pi->
pid) {
690 res->joined_list_entries = joined_list_entries;
691 res->left_list_entries = left_list_entries;
692 res->member_list_entries = count;
694 res->header.size =
size;
696 res->header.error =
CS_OK;
699 qb_list_for_each(iter, &process_info_list_head) {
702 if (mar_name_compare (&pi->
group, group_name) == 0) {
706 for (i = 0;i < left_list_entries; i++) {
707 if (left_list[i].
nodeid == pi->
nodeid && left_list[i].pid == pi->
pid) {
713 retgi->nodeid = pi->
nodeid;
714 retgi->pid = pi->
pid;
720 if (left_list_entries) {
722 retgi += left_list_entries;
725 if (joined_list_entries) {
727 retgi += joined_list_entries;
733 qb_list_for_each(iter, &cpg_pd_list_head) {
735 if (mar_name_compare (&cpd->
group_name, group_name) == 0) {
736 assert (joined_list_entries <= 1);
737 if (joined_list_entries) {
738 if (joined_list[0].
pid == cpd->
pid &&
749 if (left_list_entries) {
750 if (left_list[0].
pid == cpd->
pid &&
767 qb_list_for_each(iter, &cpg_pd_list_head) {
773 notify_lib_totem_membership (cpd->
conn, my_old_member_list_entries, my_old_member_list);
783 "%s: members(old:%d left:%d)",
789 static void downlist_inform_clients (
void)
791 struct qb_list_head *iter, *tmp_iter;
799 int left_list_entries;
800 struct qb_list_head
list;
802 qb_map_iter_t *miter;
805 downlist_log(
"my downlist", &g_req_exec_cpg_downlist);
807 group_map = qb_skiplist_create();
814 qb_list_for_each_safe(iter, tmp_iter, &process_info_list_head) {
818 for (i = 0; i < g_req_exec_cpg_downlist.left_nodes; i++) {
820 if (pi->
nodeid == g_req_exec_cpg_downlist.nodeids[i]) {
827 marshall_from_mar_cpg_name_t(&cpg_group, &left_pi->
group);
828 cpg_group.value[cpg_group.length] = 0;
830 pcd = (
struct confchg_data *)qb_map_get(group_map, cpg_group.value);
832 pcd = (
struct confchg_data *)calloc(1,
sizeof(
struct confchg_data));
833 memcpy(&pcd->cpg_group, &cpg_group,
sizeof(
struct cpg_name));
834 qb_map_put(group_map, pcd->cpg_group.value, pcd);
836 size = pcd->left_list_entries;
837 pcd->left_list[
size].nodeid = left_pi->
nodeid;
838 pcd->left_list[
size].pid = left_pi->
pid;
840 pcd->left_list_entries++;
841 qb_list_del (&left_pi->
list);
847 miter = qb_map_iter_create(group_map);
848 while (qb_map_iter_next(miter, (
void **)&pcd)) {
849 marshall_to_mar_cpg_name_t(&group, &pcd->cpg_group);
851 log_printf (LOG_DEBUG,
"left_list_entries:%d", pcd->left_list_entries);
852 for (i=0; i<pcd->left_list_entries; i++) {
853 log_printf (LOG_DEBUG,
"left_list[%d] group:%s, ip:%s, pid:%d",
854 i, cpg_print_group_name(&group),
856 pcd->left_list[i].pid);
860 notify_lib_joinlist(&group, NULL,
862 pcd->left_list_entries,
868 qb_map_iter_free(miter);
869 qb_map_destroy(group_map);
875 static void joinlist_remove_zombie_pi_entries (
void)
877 struct qb_list_head *pi_iter, *tmp_iter;
878 struct qb_list_head *jl_iter;
883 qb_list_for_each_safe(pi_iter, tmp_iter, &process_info_list_head) {
897 qb_list_for_each(jl_iter, &joinlist_messages_head) {
905 pi->
pid == stored_msg->
pid &&
918 static void joinlist_inform_clients (
void)
921 struct qb_list_head *iter;
925 qb_list_for_each(iter, &joinlist_messages_head) {
928 log_printf (LOG_DEBUG,
"joinlist_messages[%u] group:%s, ip:%s, pid:%d",
929 i++, cpg_print_group_name(&stored_msg->
group_name),
942 joinlist_remove_zombie_pi_entries ();
945 static void joinlist_messages_delete (
void)
948 struct qb_list_head *iter, *tmp_iter;
950 qb_list_for_each_safe(iter, tmp_iter, &joinlist_messages_head) {
952 qb_list_del (&stored_msg->
list);
955 qb_list_init (&joinlist_messages_head);
960 qb_list_init (&joinlist_messages_head);
967 struct qb_list_head *iter, *tmp_iter;
970 qb_list_for_each_safe(iter, tmp_iter, &(cpg_iteration_instance->
items_list_head)) {
972 qb_list_del (&pi->
list);
976 qb_list_del (&cpg_iteration_instance->
list);
977 hdb_handle_destroy (&cpg_iteration_handle_t_db, cpg_iteration_instance->
handle);
980 static void cpg_pd_finalize (
struct cpg_pd *cpd)
982 struct qb_list_head *iter, *tmp_iter;
983 struct cpg_iteration_instance *cpii;
987 cpii = qb_list_entry (iter,
struct cpg_iteration_instance,
list);
989 cpg_iteration_instance_finalize (cpii);
992 qb_list_del (&cpd->
list);
995 static int cpg_lib_exit_fn (
void *conn)
1006 cpg_pd_finalize (cpd);
1012 static int cpg_node_joinleave_send (
unsigned int pid,
const mar_cpg_name_t *group_name,
int fn,
int reason)
1015 struct iovec req_exec_cpg_iovec;
1034 static void exec_cpg_procjoin_endian_convert (
void *msg)
1038 req_exec_cpg_procjoin->pid =
swab32(req_exec_cpg_procjoin->pid);
1039 swab_mar_cpg_name_t (&req_exec_cpg_procjoin->group_name);
1040 req_exec_cpg_procjoin->reason =
swab32(req_exec_cpg_procjoin->reason);
1043 static void exec_cpg_joinlist_endian_convert (
void *msg_v)
1046 struct qb_ipc_response_header *res = (
struct qb_ipc_response_header *)msg;
1049 swab_mar_int32_t (&res->size);
1051 while ((
const char*)jle < msg + res->size) {
1058 static void exec_cpg_downlist_endian_convert_old (
void *msg)
1062 static void exec_cpg_downlist_endian_convert (
void *msg)
1067 req_exec_cpg_downlist->left_nodes =
swab32(req_exec_cpg_downlist->left_nodes);
1068 req_exec_cpg_downlist->old_members =
swab32(req_exec_cpg_downlist->old_members);
1070 for (i = 0; i < req_exec_cpg_downlist->left_nodes; i++) {
1071 req_exec_cpg_downlist->nodeids[i] =
swab32(req_exec_cpg_downlist->nodeids[i]);
1076 static void exec_cpg_mcast_endian_convert (
void *msg)
1080 swab_coroipc_request_header_t (&req_exec_cpg_mcast->header);
1081 swab_mar_cpg_name_t (&req_exec_cpg_mcast->group_name);
1082 req_exec_cpg_mcast->pid =
swab32(req_exec_cpg_mcast->pid);
1083 req_exec_cpg_mcast->msglen =
swab32(req_exec_cpg_mcast->msglen);
1084 swab_mar_message_source_t (&req_exec_cpg_mcast->source);
1087 static void exec_cpg_partial_mcast_endian_convert (
void *msg)
1091 swab_coroipc_request_header_t (&req_exec_cpg_mcast->header);
1092 swab_mar_cpg_name_t (&req_exec_cpg_mcast->group_name);
1093 req_exec_cpg_mcast->pid =
swab32(req_exec_cpg_mcast->pid);
1094 req_exec_cpg_mcast->msglen =
swab32(req_exec_cpg_mcast->msglen);
1095 req_exec_cpg_mcast->fraglen =
swab32(req_exec_cpg_mcast->fraglen);
1096 req_exec_cpg_mcast->type =
swab32(req_exec_cpg_mcast->type);
1097 swab_mar_message_source_t (&req_exec_cpg_mcast->source);
1101 struct qb_list_head *iter;
1103 qb_list_for_each(iter, &process_info_list_head) {
1106 if (pi->
pid == pid && pi->
nodeid == nodeid &&
1107 mar_name_compare (&pi->
group, group_name) == 0) {
1115 static void do_proc_join(
1118 unsigned int nodeid,
1124 struct qb_list_head *
list;
1125 struct qb_list_head *list_to_add = NULL;
1127 if (process_info_find (name, pid, nodeid) != NULL) {
1137 memcpy(&pi->
group, name,
sizeof(*name));
1138 qb_list_init(&pi->
list);
1143 list_to_add = &process_info_list_head;
1144 qb_list_for_each(list, &process_info_list_head) {
1145 pi_entry = qb_list_entry(list,
struct process_info, list);
1153 qb_list_add (&pi->
list, list_to_add);
1155 notify_info.pid = pi->
pid;
1156 notify_info.nodeid =
nodeid;
1157 notify_info.reason = reason;
1159 notify_lib_joinlist(&pi->
group, NULL,
1165 static void do_proc_leave(
1168 unsigned int nodeid,
1172 struct qb_list_head *iter, *tmp_iter;
1175 notify_info.pid = pid;
1176 notify_info.nodeid =
nodeid;
1177 notify_info.reason = reason;
1179 notify_lib_joinlist(name, NULL,
1184 qb_list_for_each_safe(iter, tmp_iter, &process_info_list_head) {
1187 if (pi->
pid == pid && pi->
nodeid == nodeid &&
1188 mar_name_compare (&pi->
group, name)==0) {
1189 qb_list_del (&pi->
list);
1195 static void message_handler_req_exec_cpg_downlist_old (
1196 const void *message,
1197 unsigned int nodeid)
1203 static void message_handler_req_exec_cpg_downlist(
1204 const void *message,
1205 unsigned int nodeid)
1207 const struct req_exec_cpg_downlist *req_exec_cpg_downlist = message;
1210 req_exec_cpg_downlist->left_nodes);
1214 static void message_handler_req_exec_cpg_procjoin (
1215 const void *message,
1216 unsigned int nodeid)
1223 (
unsigned int)req_exec_cpg_procjoin->pid);
1225 do_proc_join (&req_exec_cpg_procjoin->group_name,
1226 req_exec_cpg_procjoin->pid, nodeid,
1230 static void message_handler_req_exec_cpg_procleave (
1231 const void *message,
1232 unsigned int nodeid)
1239 (
unsigned int)req_exec_cpg_procjoin->pid);
1241 do_proc_leave (&req_exec_cpg_procjoin->group_name,
1242 req_exec_cpg_procjoin->pid, nodeid,
1243 req_exec_cpg_procjoin->reason);
1248 static void message_handler_req_exec_cpg_joinlist (
1249 const void *message_v,
1250 unsigned int nodeid)
1252 const char *message = message_v;
1253 const struct qb_ipc_response_header *res = (
const struct qb_ipc_response_header *)message;
1260 while ((
const char*)jle < message + res->size) {
1264 stored_msg->
pid = jle->
pid;
1266 qb_list_init (&stored_msg->
list);
1267 qb_list_add (&stored_msg->
list, &joinlist_messages_head);
1272 static void message_handler_req_exec_cpg_mcast (
1273 const void *message,
1274 unsigned int nodeid)
1278 int msglen = req_exec_cpg_mcast->msglen;
1279 struct qb_list_head *iter, *pi_iter, *tmp_iter;
1281 struct iovec iovec[2];
1295 iovec[1].iov_base = (
char*)message+
sizeof(*req_exec_cpg_mcast);
1296 iovec[1].iov_len = msglen;
1298 qb_list_for_each_safe(iter, tmp_iter, &cpg_pd_list_head) {
1299 cpd = qb_list_entry(iter,
struct cpg_pd, list);
1301 && (mar_name_compare (&cpd->
group_name, &req_exec_cpg_mcast->group_name) == 0)) {
1305 qb_list_for_each(pi_iter, &process_info_list_head) {
1308 if (pi->
nodeid == nodeid &&
1309 mar_name_compare (&pi->
group, &req_exec_cpg_mcast->group_name) == 0) {
1326 static void message_handler_req_exec_cpg_partial_mcast (
1327 const void *message,
1328 unsigned int nodeid)
1332 int msglen = req_exec_cpg_mcast->fraglen;
1333 struct qb_list_head *iter, *pi_iter, *tmp_iter;
1335 struct iovec iovec[2];
1353 iovec[1].iov_base = (
char*)message+
sizeof(*req_exec_cpg_mcast);
1354 iovec[1].iov_len = msglen;
1356 qb_list_for_each_safe(iter, tmp_iter, &cpg_pd_list_head) {
1357 cpd = qb_list_entry(iter,
struct cpg_pd, list);
1360 && (mar_name_compare (&cpd->
group_name, &req_exec_cpg_mcast->group_name) == 0)) {
1364 qb_list_for_each(pi_iter, &process_info_list_head) {
1367 if (pi->
nodeid == nodeid &&
1368 mar_name_compare (&pi->
group, &req_exec_cpg_mcast->group_name) == 0) {
1386 static int cpg_exec_send_downlist(
void)
1391 g_req_exec_cpg_downlist.header.size =
sizeof(
struct req_exec_cpg_downlist);
1393 g_req_exec_cpg_downlist.old_members = my_old_member_list_entries;
1395 iov.iov_base = (
void *)&g_req_exec_cpg_downlist;
1396 iov.iov_len = g_req_exec_cpg_downlist.header.size;
1401 static int cpg_exec_send_joinlist(
void)
1404 struct qb_list_head *iter;
1405 struct qb_ipc_response_header *res;
1408 struct iovec req_exec_cpg_iovec;
1410 qb_list_for_each(iter, &process_info_list_head) {
1422 buf = alloca(
sizeof(
struct qb_ipc_response_header) +
sizeof(
struct join_list_entry) * count);
1428 jle = (
struct join_list_entry *)(buf +
sizeof(
struct qb_ipc_response_header));
1429 res = (
struct qb_ipc_response_header *)buf;
1431 qb_list_for_each(iter, &process_info_list_head) {
1442 res->size =
sizeof(
struct qb_ipc_response_header)+sizeof(struct
join_list_entry) * count;
1444 req_exec_cpg_iovec.iov_base = buf;
1445 req_exec_cpg_iovec.iov_len = res->size;
1450 static int cpg_lib_init_fn (
void *conn)
1453 memset (cpd, 0,
sizeof(
struct cpg_pd));
1455 qb_list_add (&cpd->
list, &cpg_pd_list_head);
1466 static void message_handler_req_lib_cpg_join (
void *conn,
const void *message)
1472 struct qb_list_head *iter;
1475 qb_list_for_each(iter, &cpg_pd_list_head) {
1476 struct cpg_pd *cpd_item = qb_list_entry (iter,
struct cpg_pd, list);
1478 if (cpd_item->
pid == req_lib_cpg_join->pid &&
1479 mar_name_compare(&req_lib_cpg_join->group_name, &cpd_item->
group_name) == 0) {
1491 qb_list_for_each(iter, &process_info_list_head) {
1495 mar_name_compare(&req_lib_cpg_join->group_name, &pi->
group) == 0) {
1511 cpd->
pid = req_lib_cpg_join->pid;
1512 cpd->
flags = req_lib_cpg_join->flags;
1513 memcpy (&cpd->
group_name, &req_lib_cpg_join->group_name,
1516 cpg_node_joinleave_send (req_lib_cpg_join->pid,
1517 &req_lib_cpg_join->group_name,
1539 static void message_handler_req_lib_cpg_leave (
void *conn,
const void *message)
1561 cpg_node_joinleave_send (req_lib_cpg_leave->pid,
1562 &req_lib_cpg_leave->group_name,
1576 static void message_handler_req_lib_cpg_finalize (
1578 const void *message)
1590 qb_list_del (&cpd->
list);
1591 qb_list_init (&cpd->
list);
1611 fd = open (path, O_RDWR, 0600);
1619 res = ftruncate (fd, bytes);
1621 goto error_close_unlink;
1624 addr = mmap (NULL, bytes, PROT_READ | PROT_WRITE,
1627 if (addr == MAP_FAILED) {
1628 goto error_close_unlink;
1631 madvise(addr, bytes, MADV_NOSYNC);
1636 munmap (addr, bytes);
1648 static inline int zcb_alloc (
1650 const char *path_to_file,
1657 zcb_mapped = malloc (
sizeof (
struct zcb_mapped));
1658 if (zcb_mapped == NULL) {
1671 qb_list_init (&zcb_mapped->
list);
1679 static inline int zcb_free (
struct zcb_mapped *zcb_mapped)
1683 res = munmap (zcb_mapped->
addr, zcb_mapped->
size);
1684 qb_list_del (&zcb_mapped->
list);
1689 static inline int zcb_by_addr_free (
struct cpg_pd *cpd,
void *addr)
1691 struct qb_list_head *
list, *tmp_iter;
1692 struct zcb_mapped *zcb_mapped;
1693 unsigned int res = 0;
1696 zcb_mapped = qb_list_entry (list,
struct zcb_mapped, list);
1698 if (zcb_mapped->
addr == addr) {
1699 res = zcb_free (zcb_mapped);
1707 static inline int zcb_all_free (
1710 struct qb_list_head *
list, *tmp_iter;
1711 struct zcb_mapped *zcb_mapped;
1714 zcb_mapped = qb_list_entry (list,
struct zcb_mapped, list);
1716 zcb_free (zcb_mapped);
1726 static uint64_t void2serveraddr (
void *server_ptr)
1734 static void *serveraddr2void (uint64_t
server_addr)
1742 static void message_handler_req_lib_cpg_zc_alloc (
1744 const void *message)
1747 struct qb_ipc_response_header res_header;
1755 res = zcb_alloc (cpd, hdr->path_to_file, hdr->map_size,
1762 res_header.size =
sizeof (
struct qb_ipc_response_header);
1769 static void message_handler_req_lib_cpg_zc_free (
1771 const void *message)
1774 struct qb_ipc_response_header res_header;
1780 addr = serveraddr2void (hdr->server_address);
1782 zcb_by_addr_free (cpd, addr);
1784 res_header.size =
sizeof (
struct qb_ipc_response_header);
1792 static void message_handler_req_lib_cpg_partial_mcast (
void *conn,
const void *message)
1798 struct iovec req_exec_cpg_iovec[2];
1801 int msglen = req_lib_cpg_mcast->fraglen;
1823 res_lib_cpg_partial_send.header.size =
sizeof(res_lib_cpg_partial_send);
1833 if (error ==
CS_OK) {
1834 req_exec_cpg_mcast.header.size =
sizeof(req_exec_cpg_mcast) + msglen;
1837 req_exec_cpg_mcast.pid = cpd->
pid;
1838 req_exec_cpg_mcast.msglen = req_lib_cpg_mcast->msglen;
1839 req_exec_cpg_mcast.type = req_lib_cpg_mcast->type;
1840 req_exec_cpg_mcast.fraglen = req_lib_cpg_mcast->fraglen;
1842 memcpy(&req_exec_cpg_mcast.group_name, &group_name,
1845 req_exec_cpg_iovec[0].iov_base = (
char *)&req_exec_cpg_mcast;
1846 req_exec_cpg_iovec[0].iov_len =
sizeof(req_exec_cpg_mcast);
1847 req_exec_cpg_iovec[1].iov_base = (
char *)&req_lib_cpg_mcast->message;
1848 req_exec_cpg_iovec[1].iov_len = msglen;
1851 assert(result == 0);
1854 conn, group_name.value, cpd->
cpd_state, error);
1857 res_lib_cpg_partial_send.header.error = error;
1859 sizeof (res_lib_cpg_partial_send));
1863 static void message_handler_req_lib_cpg_mcast (
void *conn,
const void *message)
1869 struct iovec req_exec_cpg_iovec[2];
1870 struct req_exec_cpg_mcast req_exec_cpg_mcast;
1871 int msglen = req_lib_cpg_mcast->msglen;
1892 if (error ==
CS_OK) {
1893 req_exec_cpg_mcast.header.size =
sizeof(req_exec_cpg_mcast) + msglen;
1896 req_exec_cpg_mcast.pid = cpd->
pid;
1897 req_exec_cpg_mcast.msglen = msglen;
1899 memcpy(&req_exec_cpg_mcast.group_name, &group_name,
1902 req_exec_cpg_iovec[0].iov_base = (
char *)&req_exec_cpg_mcast;
1903 req_exec_cpg_iovec[0].iov_len =
sizeof(req_exec_cpg_mcast);
1904 req_exec_cpg_iovec[1].iov_base = (
char *)&req_lib_cpg_mcast->message;
1905 req_exec_cpg_iovec[1].iov_len = msglen;
1908 assert(result == 0);
1911 conn, group_name.value, cpd->
cpd_state, error);
1915 static void message_handler_req_lib_cpg_zc_execute (
1917 const void *message)
1920 struct qb_ipc_request_header *
header;
1923 struct iovec req_exec_cpg_iovec[2];
1924 struct req_exec_cpg_mcast req_exec_cpg_mcast;
1931 header = (
struct qb_ipc_request_header *)(((
char *)serveraddr2void(hdr->server_address) + sizeof (
struct coroipcs_zc_header)));
1932 req_lib_cpg_mcast = (
struct req_lib_cpg_mcast *)header;
1949 res_lib_cpg_mcast.header.size =
sizeof(res_lib_cpg_mcast);
1951 if (error ==
CS_OK) {
1952 req_exec_cpg_mcast.header.size =
sizeof(req_exec_cpg_mcast) + req_lib_cpg_mcast->msglen;
1955 req_exec_cpg_mcast.pid = cpd->
pid;
1956 req_exec_cpg_mcast.msglen = req_lib_cpg_mcast->msglen;
1958 memcpy(&req_exec_cpg_mcast.group_name, &cpd->
group_name,
1961 req_exec_cpg_iovec[0].iov_base = (
char *)&req_exec_cpg_mcast;
1962 req_exec_cpg_iovec[0].iov_len =
sizeof(req_exec_cpg_mcast);
1963 req_exec_cpg_iovec[1].iov_base = (
char *)header +
sizeof(
struct req_lib_cpg_mcast);
1964 req_exec_cpg_iovec[1].iov_len = req_exec_cpg_mcast.msglen;
1968 res_lib_cpg_mcast.header.error =
CS_OK;
1973 res_lib_cpg_mcast.header.error = error;
1977 sizeof (res_lib_cpg_mcast));
1981 static void message_handler_req_lib_cpg_membership (
void *conn,
1982 const void *message)
1985 (
struct req_lib_cpg_membership_get *)message;
1987 struct qb_list_head *iter;
1988 int member_count = 0;
1991 res_lib_cpg_membership_get.header.error =
CS_OK;
1992 res_lib_cpg_membership_get.header.size =
1993 sizeof (
struct res_lib_cpg_membership_get);
1995 qb_list_for_each(iter, &process_info_list_head) {
1997 if (mar_name_compare (&pi->
group, &req_lib_cpg_membership_get->group_name) == 0) {
1999 res_lib_cpg_membership_get.
member_list[member_count].pid = pi->
pid;
2003 res_lib_cpg_membership_get.member_count = member_count;
2006 sizeof (res_lib_cpg_membership_get));
2009 static void message_handler_req_lib_cpg_local_get (
void *conn,
2010 const void *message)
2014 res_lib_cpg_local_get.header.size =
sizeof (res_lib_cpg_local_get);
2016 res_lib_cpg_local_get.header.error =
CS_OK;
2020 sizeof (res_lib_cpg_local_get));
2023 static void message_handler_req_lib_cpg_iteration_initialize (
2025 const void *message)
2031 struct qb_list_head *iter, *iter2;
2032 struct cpg_iteration_instance *cpg_iteration_instance;
2045 res = hdb_handle_create (&cpg_iteration_handle_t_db,
sizeof (
struct cpg_iteration_instance),
2046 &cpg_iteration_handle);
2053 res = hdb_handle_get (&cpg_iteration_handle_t_db, cpg_iteration_handle, (
void *)&cpg_iteration_instance);
2060 qb_list_init (&cpg_iteration_instance->items_list_head);
2061 cpg_iteration_instance->handle = cpg_iteration_handle;
2066 qb_list_for_each(iter, &process_info_list_head) {
2076 qb_list_for_each(iter2, &(cpg_iteration_instance->items_list_head)) {
2079 if (mar_name_compare (&pi2->
group, &pi->
group) == 0) {
2095 if (mar_name_compare (&pi->
group, &req_lib_cpg_iterationinitialize->group_name) != 0)
2108 goto error_put_destroy;
2112 qb_list_init (&new_pi->
list);
2124 qb_list_for_each(iter2, &(cpg_iteration_instance->items_list_head)) {
2127 if (mar_name_compare (&pi2->
group, &pi->
group) == 0) {
2132 qb_list_add (&new_pi->
list, iter2);
2142 qb_list_init (&cpg_iteration_instance->list);
2145 cpg_iteration_instance->current_pointer = &cpg_iteration_instance->items_list_head;
2148 hdb_handle_put (&cpg_iteration_handle_t_db, cpg_iteration_handle);
2150 if (error !=
CS_OK) {
2151 hdb_handle_destroy (&cpg_iteration_handle_t_db, cpg_iteration_handle);
2155 res_lib_cpg_iterationinitialize.header.size =
sizeof (res_lib_cpg_iterationinitialize);
2157 res_lib_cpg_iterationinitialize.header.error = error;
2158 res_lib_cpg_iterationinitialize.iteration_handle = cpg_iteration_handle;
2161 sizeof (res_lib_cpg_iterationinitialize));
2164 static void message_handler_req_lib_cpg_iteration_next (
2166 const void *message)
2170 struct cpg_iteration_instance *cpg_iteration_instance;
2177 res = hdb_handle_get (&cpg_iteration_handle_t_db,
2178 req_lib_cpg_iterationnext->iteration_handle,
2179 (
void *)&cpg_iteration_instance);
2186 assert (cpg_iteration_instance);
2188 cpg_iteration_instance->current_pointer = cpg_iteration_instance->current_pointer->next;
2190 if (cpg_iteration_instance->current_pointer == &cpg_iteration_instance->items_list_head) {
2195 pi = qb_list_entry (cpg_iteration_instance->current_pointer,
struct process_info, list);
2200 res_lib_cpg_iterationnext.description.nodeid = pi->
nodeid;
2201 res_lib_cpg_iterationnext.description.pid = pi->
pid;
2202 memcpy (&res_lib_cpg_iterationnext.description.group,
2207 hdb_handle_put (&cpg_iteration_handle_t_db, req_lib_cpg_iterationnext->iteration_handle);
2209 res_lib_cpg_iterationnext.header.size =
sizeof (res_lib_cpg_iterationnext);
2211 res_lib_cpg_iterationnext.header.error = error;
2214 sizeof (res_lib_cpg_iterationnext));
2217 static void message_handler_req_lib_cpg_iteration_finalize (
2219 const void *message)
2223 struct cpg_iteration_instance *cpg_iteration_instance;
2229 res = hdb_handle_get (&cpg_iteration_handle_t_db,
2230 req_lib_cpg_iterationfinalize->iteration_handle,
2231 (
void *)&cpg_iteration_instance);
2238 assert (cpg_iteration_instance);
2240 cpg_iteration_instance_finalize (cpg_iteration_instance);
2241 hdb_handle_put (&cpg_iteration_handle_t_db, cpg_iteration_instance->handle);
2244 res_lib_cpg_iterationfinalize.header.size =
sizeof (res_lib_cpg_iterationfinalize);
2246 res_lib_cpg_iterationfinalize.header.error = error;
2249 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.
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)
#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)
struct qb_list_head * current_pointer
mar_req_coroipcc_zc_execute_t struct
The res_lib_cpg_mcast struct.
#define LOGSYS_LEVEL_ERROR
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)
struct totem_message_header header
#define swab32(x)
The swab32 macro.
The res_lib_cpg_finalize struct.
struct qb_list_head items_list_head
struct qb_list_head zcb_mapped_list_head
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.
The req_lib_cpg_iterationnext struct.
const char *(* totem_ifaces_print)(unsigned int nodeid)
The res_lib_cpg_confchg_callback struct.
mar_cpg_name_t group_name
struct qb_list_head iteration_instance_list_head
void(* lib_handler_fn)(void *conn, const void *msg)
The req_lib_cpg_membership_get struct.
QB_LIST_DECLARE(cpg_pd_list_head)
int(* ipc_dispatch_send)(void *conn, const void *msg, size_t mlen)
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.
Message from another node.
The mar_message_source_t struct.
void(* ipc_refcnt_inc)(void *conn)