42#include <sys/socket.h>
45#include <netinet/in.h>
61#include <qb/qbipc_common.h>
70#define MAP_ANONYMOUS MAP_ANON
77#define GROUP_HASH_SIZE 32
172static unsigned int my_member_list_entries;
176static unsigned int my_old_member_list_entries = 0;
208static int cpg_lib_init_fn (
void *conn);
210static int cpg_lib_exit_fn (
void *conn);
212static void message_handler_req_exec_cpg_procjoin (
216static void message_handler_req_exec_cpg_procleave (
220static void message_handler_req_exec_cpg_joinlist (
224static void message_handler_req_exec_cpg_mcast (
228static void message_handler_req_exec_cpg_partial_mcast (
232static void message_handler_req_exec_cpg_downlist_old (
236static void message_handler_req_exec_cpg_downlist (
240static void exec_cpg_procjoin_endian_convert (
void *msg);
242static void exec_cpg_joinlist_endian_convert (
void *msg);
244static void exec_cpg_mcast_endian_convert (
void *msg);
246static void exec_cpg_partial_mcast_endian_convert (
void *msg);
248static void exec_cpg_downlist_endian_convert_old (
void *msg);
250static void exec_cpg_downlist_endian_convert (
void *msg);
252static void message_handler_req_lib_cpg_join (
void *conn,
const void *
message);
254static void message_handler_req_lib_cpg_leave (
void *conn,
const void *
message);
256static void message_handler_req_lib_cpg_finalize (
void *conn,
const void *
message);
258static void message_handler_req_lib_cpg_mcast (
void *conn,
const void *
message);
260static void message_handler_req_lib_cpg_partial_mcast (
void *conn,
const void *
message);
262static void message_handler_req_lib_cpg_membership (
void *conn,
265static void message_handler_req_lib_cpg_local_get (
void *conn,
268static void message_handler_req_lib_cpg_iteration_initialize (
272static void message_handler_req_lib_cpg_iteration_next (
276static void message_handler_req_lib_cpg_iteration_finalize (
280static void message_handler_req_lib_cpg_zc_alloc (
284static void message_handler_req_lib_cpg_zc_free (
288static void message_handler_req_lib_cpg_zc_execute (
292static int cpg_node_joinleave_send (
unsigned int pid,
const mar_cpg_name_t *group_name,
int fn,
int reason);
294static int cpg_exec_send_downlist(
void);
296static int cpg_exec_send_joinlist(
void);
298static void downlist_inform_clients (
void);
300static void joinlist_inform_clients (
void);
302static void joinlist_messages_delete (
void);
304static void cpg_sync_init (
307 const unsigned int *member_list,
308 size_t member_list_entries,
311static int cpg_sync_process (
void);
313static void cpg_sync_activate (
void);
315static void cpg_sync_abort (
void);
317static void do_proc_join(
324static void do_proc_leave(
330static int notify_lib_totem_membership (
332 int member_list_entries,
333 const unsigned int *member_list);
335static inline int zcb_all_free (
338static char *cpg_print_group_name (
351 .lib_handler_fn = message_handler_req_lib_cpg_leave,
355 .lib_handler_fn = message_handler_req_lib_cpg_mcast,
359 .lib_handler_fn = message_handler_req_lib_cpg_membership,
363 .lib_handler_fn = message_handler_req_lib_cpg_local_get,
367 .lib_handler_fn = message_handler_req_lib_cpg_iteration_initialize,
371 .lib_handler_fn = message_handler_req_lib_cpg_iteration_next,
375 .lib_handler_fn = message_handler_req_lib_cpg_iteration_finalize,
379 .lib_handler_fn = message_handler_req_lib_cpg_finalize,
383 .lib_handler_fn = message_handler_req_lib_cpg_zc_alloc,
387 .lib_handler_fn = message_handler_req_lib_cpg_zc_free,
391 .lib_handler_fn = message_handler_req_lib_cpg_zc_execute,
395 .lib_handler_fn = message_handler_req_lib_cpg_partial_mcast,
405 .exec_endian_convert_fn = exec_cpg_procjoin_endian_convert
408 .exec_handler_fn = message_handler_req_exec_cpg_procleave,
409 .exec_endian_convert_fn = exec_cpg_procjoin_endian_convert
412 .exec_handler_fn = message_handler_req_exec_cpg_joinlist,
413 .exec_endian_convert_fn = exec_cpg_joinlist_endian_convert
416 .exec_handler_fn = message_handler_req_exec_cpg_mcast,
417 .exec_endian_convert_fn = exec_cpg_mcast_endian_convert
420 .exec_handler_fn = message_handler_req_exec_cpg_downlist_old,
421 .exec_endian_convert_fn = exec_cpg_downlist_endian_convert_old
424 .exec_handler_fn = message_handler_req_exec_cpg_downlist,
425 .exec_endian_convert_fn = exec_cpg_downlist_endian_convert
428 .exec_handler_fn = message_handler_req_exec_cpg_partial_mcast,
429 .exec_endian_convert_fn = exec_cpg_partial_mcast_endian_convert
434 .
name =
"corosync cluster closed process group service v1.01",
437 .private_data_size =
sizeof (
struct cpg_pd),
440 .lib_init_fn = cpg_lib_init_fn,
441 .lib_exit_fn = cpg_lib_exit_fn,
442 .lib_engine = cpg_lib_engine,
444 .exec_init_fn = cpg_exec_init_fn,
445 .exec_dump_fn =
NULL,
446 .exec_engine = cpg_exec_engine,
448 .sync_init = cpg_sync_init,
449 .sync_process = cpg_sync_process,
450 .sync_activate = cpg_sync_activate,
451 .sync_abort = cpg_sync_abort
520 for (
i = 0;
i < group->length;
i++) {
523 if (c >=
' ' && c < 0x7f && c !=
'\\') {
540static void cpg_sync_init (
543 const unsigned int *member_list,
544 size_t member_list_entries,
553 memcpy (my_member_list, member_list, member_list_entries *
554 sizeof (
unsigned int));
555 my_member_list_entries = member_list_entries;
564 for (
i = 0;
i < my_old_member_list_entries;
i++) {
573 g_req_exec_cpg_downlist.nodeids[entries++] =
574 my_old_member_list[
i];
577 g_req_exec_cpg_downlist.left_nodes = entries;
580static int cpg_sync_process (
void)
585 res = cpg_exec_send_downlist();
592 res = cpg_exec_send_joinlist();
597static void cpg_sync_activate (
void)
599 memcpy (my_old_member_list, my_member_list,
600 my_member_list_entries *
sizeof (
unsigned int));
601 my_old_member_list_entries = my_member_list_entries;
603 downlist_inform_clients ();
605 joinlist_inform_clients ();
607 joinlist_messages_delete ();
609 notify_lib_totem_membership (
NULL, my_member_list_entries, my_member_list);
612static void cpg_sync_abort (
void)
615 joinlist_messages_delete ();
618static int notify_lib_totem_membership (
620 int member_list_entries,
621 const unsigned int *member_list)
635 res->member_list_entries = member_list_entries;
636 res->header.size = size;
663static void notify_lib_joinlist_fill_member_list(
667 int *member_list_entries,
673 if (member_list_entries !=
NULL) {
674 *member_list_entries = 0;
680 if (mar_name_compare (&
pi->group, group_name) == 0) {
691 if (member_list_entries !=
NULL) {
692 (*member_list_entries)++;
695 if (member_list !=
NULL) {
696 (*member_list)->nodeid =
pi->nodeid;
697 (*member_list)->pid =
pi->pid;
706static int notify_lib_joinlist(
717 int member_list_entries;
726 &member_list_entries,
NULL);
737 res->member_list_entries = member_list_entries;
739 res->header.size = size;
791 cpd->transition_counter++;
826 cpd->initial_totem_conf_sent = 1;
828 notify_lib_totem_membership (
cpd->conn, my_old_member_list_entries, my_old_member_list);
838 "%s: members(old:%d left:%d)",
844static void downlist_inform_clients (
void)
860 downlist_log(
"my downlist", &g_req_exec_cpg_downlist);
873 for (
i = 0;
i < g_req_exec_cpg_downlist.left_nodes;
i++) {
875 if (
pi->nodeid == g_req_exec_cpg_downlist.nodeids[
i]) {
882 marshall_from_mar_cpg_name_t(&cpg_group, &
left_pi->group);
883 cpg_group.value[cpg_group.length] = 0;
891 size =
pcd->left_list_entries;
892 pcd->left_list[size].nodeid =
left_pi->nodeid;
895 pcd->left_list_entries++;
904 marshall_to_mar_cpg_name_t(&group, &
pcd->cpg_group);
907 for (
i=0;
i<
pcd->left_list_entries;
i++) {
909 i, cpg_print_group_name(&group),
911 pcd->left_list[
i].pid);
915 notify_lib_joinlist(&group,
917 pcd->left_list_entries,
930static void joinlist_remove_zombie_pi_entries (
void)
961 mar_name_compare (&
pi->group, &
stored_msg->group_name) == 0) {
973static void joinlist_inform_clients (
void)
989 i++, cpg_print_group_name(&
stored_msg->group_name),
1004 notify_lib_joinlist(&
jld->cpg_group,
1005 jld->join_list_entries,
jld->join_list,
1013 joinlist_remove_zombie_pi_entries ();
1016static void joinlist_messages_delete (
void)
1051static void cpg_pd_finalize (
struct cpg_pd *
cpd)
1060 cpg_iteration_instance_finalize (
cpii);
1066static int cpg_lib_exit_fn (
void *conn)
1073 cpg_node_joinleave_send (
cpd->pid, &
cpd->group_name,
1077 cpg_pd_finalize (
cpd);
1107static void exec_cpg_procjoin_endian_convert (
void *msg)
1116static void exec_cpg_joinlist_endian_convert (
void *
msg_v)
1122 swab_mar_int32_t (&
res->size);
1126 swab_mar_cpg_name_t (&
jle->group_name);
1131static void exec_cpg_downlist_endian_convert_old (
void *msg)
1135static void exec_cpg_downlist_endian_convert (
void *msg)
1149static void exec_cpg_mcast_endian_convert (
void *msg)
1160static void exec_cpg_partial_mcast_endian_convert (
void *msg)
1180 mar_name_compare (&
pi->group, group_name) == 0) {
1188static void do_proc_join(
1202 if (process_info_find (name, pid,
nodeid) !=
NULL) {
1212 memcpy(&
pi->group, name,
sizeof(*name));
1235 notify_lib_joinlist(&
pi->group,
1246 size =
jld->join_list_entries;
1250 jld->join_list_entries++;
1254static void do_proc_leave(
1268 notify_lib_joinlist(name,
1276 if (
pi->pid == pid &&
pi->nodeid ==
nodeid &&
1277 mar_name_compare (&
pi->group, name)==0) {
1284static void message_handler_req_exec_cpg_downlist_old (
1292static void message_handler_req_exec_cpg_downlist(
1303static void message_handler_req_exec_cpg_procjoin (
1319static void message_handler_req_exec_cpg_procleave (
1337static void message_handler_req_exec_cpg_joinlist (
1361static void message_handler_req_exec_cpg_mcast (
1415static void message_handler_req_exec_cpg_partial_mcast (
1475static int cpg_exec_send_downlist(
void)
1482 g_req_exec_cpg_downlist.old_members = my_old_member_list_entries;
1484 iov.iov_base = (
void *)&g_req_exec_cpg_downlist;
1485 iov.iov_len = g_req_exec_cpg_downlist.header.size;
1490static int cpg_exec_send_joinlist(
void)
1542static int cpg_lib_init_fn (
void *conn)
1558static void message_handler_req_lib_cpg_join (
void *
conn,
const void *
message)
1599 switch (
cpd->cpd_state) {
1631static void message_handler_req_lib_cpg_leave (
void *conn,
const void *
message)
1640 switch (
cpd->cpd_state) {
1668static void message_handler_req_lib_cpg_finalize (
1740static inline int zcb_alloc (
1781static inline int zcb_by_addr_free (
struct cpg_pd *
cpd,
void *
addr)
1785 unsigned int res = 0;
1799static inline int zcb_all_free (
1818static uint64_t void2serveraddr (
void *server_ptr)
1834static void message_handler_req_lib_cpg_zc_alloc (
1847 res = zcb_alloc (
cpd, hdr->path_to_file, hdr->map_size,
1861static void message_handler_req_lib_cpg_zc_free (
1872 addr = serveraddr2void (hdr->server_address);
1884static void message_handler_req_lib_cpg_partial_mcast (
void *conn,
const void *
message)
1900 switch (
cpd->cpd_state) {
1919 cpd->initial_transition_counter =
cpd->transition_counter;
1921 if (
cpd->transition_counter !=
cpd->initial_transition_counter) {
1946 conn, group_name.value,
cpd->cpd_state,
error);
1955static void message_handler_req_lib_cpg_mcast (
void *conn,
const void *
message)
1969 switch (
cpd->cpd_state) {
2005 conn, group_name.value,
cpd->cpd_state,
error);
2009static void message_handler_req_lib_cpg_zc_execute (
2028 switch (
cpd->cpd_state) {
2075static void message_handler_req_lib_cpg_membership (
void *conn,
2082 int member_count = 0;
2103static void message_handler_req_lib_cpg_local_get (
void *conn,
2117static void message_handler_req_lib_cpg_iteration_initialize (
2140 &cpg_iteration_handle);
2173 if (mar_name_compare (&
pi2->group, &
pi->group) == 0) {
2221 if (mar_name_compare (&
pi2->group, &
pi->group) == 0) {
2258static void message_handler_req_lib_cpg_iteration_next (
2311static void message_handler_req_lib_cpg_iteration_finalize (
#define SERVICE_ID_MAKE(a, b)
unsigned char addr[TOTEMIP_ADDRLEN]
@ CS_LIB_FLOW_CONTROL_REQUIRED
@ CS_LIB_FLOW_CONTROL_NOT_REQUIRED
#define PROCESSOR_COUNT_MAX
cs_error_t
The cs_error_t enum.
struct corosync_service_engine cpg_service_engine
QB_LIST_DECLARE(cpg_pd_list_head)
@ MESSAGE_REQ_EXEC_CPG_JOINLIST
@ MESSAGE_REQ_EXEC_CPG_PARTIAL_MCAST
@ MESSAGE_REQ_EXEC_CPG_PROCLEAVE
@ MESSAGE_REQ_EXEC_CPG_DOWNLIST_OLD
@ MESSAGE_REQ_EXEC_CPG_MCAST
@ MESSAGE_REQ_EXEC_CPG_PROCJOIN
@ MESSAGE_REQ_EXEC_CPG_DOWNLIST
@ CPD_STATE_LEAVE_STARTED
@ CPD_STATE_JOIN_COMPLETED
struct corosync_service_engine * cpg_get_service_engine_ver0(void)
#define CPG_MAX_NAME_LENGTH
#define CPG_MODEL_V1_DELIVER_INITIAL_TOTEM_CONF
@ CPG_ITERATION_ONE_GROUP
@ CPG_ITERATION_NAME_ONLY
#define DECLARE_HDB_DATABASE
@ MESSAGE_RES_CPG_ITERATIONFINALIZE
@ MESSAGE_RES_CPG_MEMBERSHIP
@ MESSAGE_RES_CPG_PARTIAL_DELIVER_CALLBACK
@ MESSAGE_RES_CPG_FINALIZE
@ MESSAGE_RES_CPG_DELIVER_CALLBACK
@ MESSAGE_RES_CPG_TOTEM_CONFCHG_CALLBACK
@ MESSAGE_RES_CPG_ITERATIONNEXT
@ MESSAGE_RES_CPG_CONFCHG_CALLBACK
@ MESSAGE_RES_CPG_PARTIAL_SEND
@ MESSAGE_RES_CPG_ITERATIONINITIALIZE
@ MESSAGE_RES_CPG_LOCAL_GET
@ CONFCHG_CPG_REASON_LEAVE
@ CONFCHG_CPG_REASON_PROCDOWN
@ CONFCHG_CPG_REASON_NODEUP
@ CONFCHG_CPG_REASON_JOIN
@ CONFCHG_CPG_REASON_NODEDOWN
#define LOGSYS_LEVEL_ERROR
#define log_printf(level, format, args...)
#define LOGSYS_DECLARE_SUBSYS(subsys)
The LOGSYS_DECLARE_SUBSYS macro.
#define LOGSYS_LEVEL_WARNING
#define LOGSYS_LEVEL_DEBUG
#define LOGSYS_LEVEL_TRACE
The corosync_api_v1 struct.
int(* totem_mcast)(const struct iovec *iovec, unsigned int iov_len, unsigned int guarantee)
void *(* ipc_private_data_get)(void *conn)
unsigned int(* totem_nodeid_get)(void)
const char *(* totem_ifaces_print)(unsigned int nodeid)
void(* ipc_refcnt_dec)(void *conn)
void(* ipc_source_set)(mar_message_source_t *source, void *conn)
void(* ipc_refcnt_inc)(void *conn)
int(* ipc_dispatch_send)(void *conn, const void *msg, size_t mlen)
int(* ipc_response_send)(void *conn, const void *msg, size_t mlen)
int(* ipc_dispatch_iov_send)(void *conn, const struct iovec *iov, unsigned int iov_len)
The corosync_exec_handler struct.
void(* exec_handler_fn)(const void *msg, unsigned int nodeid)
The corosync_lib_handler struct.
void(* lib_handler_fn)(void *conn, const void *msg)
The corosync_service_engine struct.
struct qb_list_head items_list_head
struct qb_list_head * current_pointer
uint64_t transition_counter
int initial_totem_conf_sent
mar_cpg_name_t group_name
struct qb_list_head iteration_instance_list_head
uint64_t initial_transition_counter
struct qb_list_head zcb_mapped_list_head
mar_cpg_address_t join_list[CPG_MEMBERS_MAX]
mar_cpg_name_t group_name
mar_uint32_t sender_nodeid
mar_cpg_name_t group_name
The mar_message_source_t struct.
mar_req_coroipcc_zc_alloc_t struct
mar_req_coroipcc_zc_execute_t struct
mar_req_coroipcc_zc_free_t struct
mar_uint32_t nodeids[PROCESSOR_COUNT_MAX] __attribute__((aligned(8)))
mar_uint32_t left_nodes __attribute__((aligned(8)))
mar_uint32_t old_members __attribute__((aligned(8)))
mar_uint32_t left_nodes __attribute__((aligned(8)))
mar_uint32_t nodeids[PROCESSOR_COUNT_MAX] __attribute__((aligned(8)))
mar_cpg_name_t group_name __attribute__((aligned(8)))
mar_uint32_t pid __attribute__((aligned(8)))
mar_uint32_t msglen __attribute__((aligned(8)))
mar_message_source_t source __attribute__((aligned(8)))
mar_uint8_t message[] __attribute__((aligned(8)))
mar_uint32_t type __attribute__((aligned(8)))
mar_message_source_t source __attribute__((aligned(8)))
mar_cpg_name_t group_name __attribute__((aligned(8)))
mar_uint32_t pid __attribute__((aligned(8)))
mar_uint8_t message[] __attribute__((aligned(8)))
mar_uint32_t msglen __attribute__((aligned(8)))
mar_uint32_t fraglen __attribute__((aligned(8)))
mar_uint32_t pid __attribute__((aligned(8)))
mar_uint32_t reason __attribute__((aligned(8)))
mar_cpg_name_t group_name __attribute__((aligned(8)))
The req_lib_cpg_iterationfinalize struct.
The req_lib_cpg_iterationinitialize struct.
The req_lib_cpg_iterationnext struct.
The req_lib_cpg_join struct.
The req_lib_cpg_leave struct.
The req_lib_cpg_mcast struct.
The req_lib_cpg_membership_get struct.
The req_lib_cpg_partial_mcast struct.
The res_lib_cpg_confchg_callback struct.
Message from another node.
The res_lib_cpg_finalize struct.
The res_lib_cpg_iterationfinalize struct.
The res_lib_cpg_iterationinitialize struct.
The res_lib_cpg_iterationnext struct.
The res_lib_cpg_join struct.
The res_lib_cpg_leave struct.
The res_lib_cpg_local_get struct.
The res_lib_cpg_mcast struct.
The res_lib_cpg_membership_get struct.
mar_cpg_address_t member_list[PROCESSOR_COUNT_MAX]
The res_lib_cpg_partial_deliver_callback struct.
The res_lib_cpg_partial_send struct.
The res_lib_cpg_totem_confchg_callback struct.
mar_uint32_t member_list[]
#define swab32(x)
The swab32 macro.
struct memb_ring_id ring_id
struct totem_message_header header