This source file includes following definitions.
- crmd_cs_dispatch
- crmd_quorum_callback
- crmd_cs_destroy
- cpg_membership_callback
- crm_connect_corosync
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <sys/param.h>
13 #include <sys/types.h>
14 #include <sys/stat.h>
15
16 #include <crm/crm.h>
17 #include <crm/cluster/internal.h>
18 #include <crm/common/xml.h>
19
20 #include <pacemaker-controld.h>
21
22 #if SUPPORT_COROSYNC
23
24 extern void post_cache_update(int seq);
25
26
27
28 static void
29 crmd_cs_dispatch(cpg_handle_t handle, const struct cpg_name *groupName,
30 uint32_t nodeid, uint32_t pid, void *msg, size_t msg_len)
31 {
32 uint32_t kind = 0;
33 const char *from = NULL;
34 char *data = pcmk__cpg_message_data(handle, nodeid, pid, msg, &kind, &from);
35
36 if(data == NULL) {
37 return;
38 }
39 if (kind == crm_class_cluster) {
40 crm_node_t *peer = NULL;
41 xmlNode *xml = pcmk__xml_parse(data);
42
43 if (xml == NULL) {
44 crm_err("Could not parse message content (%d): %.100s", kind, data);
45 free(data);
46 return;
47 }
48
49 crm_xml_add(xml, PCMK__XA_SRC, from);
50
51 peer = pcmk__get_node(0, from, NULL, pcmk__node_search_cluster_member);
52 if (!pcmk_is_set(peer->processes, crm_proc_cpg)) {
53
54
55
56 crm_warn("Receiving messages from a node we think is dead: %s[%d]",
57 peer->uname, peer->id);
58 crm_update_peer_proc(__func__, peer, crm_proc_cpg,
59 PCMK_VALUE_ONLINE);
60 }
61 crmd_ha_msg_filter(xml);
62 free_xml(xml);
63 } else {
64 crm_err("Invalid message class (%d): %.100s", kind, data);
65 }
66 free(data);
67 }
68
69 static gboolean
70 crmd_quorum_callback(unsigned long long seq, gboolean quorate)
71 {
72 crm_update_quorum(quorate, FALSE);
73 post_cache_update(seq);
74 return TRUE;
75 }
76
77 static void
78 crmd_cs_destroy(gpointer user_data)
79 {
80 if (!pcmk_is_set(controld_globals.fsa_input_register, R_HA_DISCONNECTED)) {
81 crm_crit("Lost connection to cluster layer, shutting down");
82 crmd_exit(CRM_EX_DISCONNECT);
83 }
84 }
85
86
87
88
89
90
91
92
93
94
95
96
97
98 static void
99 cpg_membership_callback(cpg_handle_t handle, const struct cpg_name *cpg_name,
100 const struct cpg_address *member_list,
101 size_t member_list_entries,
102 const struct cpg_address *left_list,
103 size_t left_list_entries,
104 const struct cpg_address *joined_list,
105 size_t joined_list_entries)
106 {
107
108
109
110
111
112
113
114
115
116
117
118 if (controld_globals.dc_name != NULL) {
119 crm_node_t *peer = NULL;
120
121 peer = pcmk__search_node_caches(0, controld_globals.dc_name,
122 pcmk__node_search_cluster_member);
123 if (peer != NULL) {
124 for (int i = 0; i < left_list_entries; ++i) {
125 if (left_list[i].nodeid == peer->id) {
126 controld_set_global_flags(controld_dc_left);
127 break;
128 }
129 }
130 }
131 }
132
133
134 pcmk__cpg_confchg_cb(handle, cpg_name, member_list, member_list_entries,
135 left_list, left_list_entries,
136 joined_list, joined_list_entries);
137
138 controld_clear_global_flags(controld_dc_left);
139 }
140
141 extern gboolean crm_connect_corosync(pcmk_cluster_t *cluster);
142
143 gboolean
144 crm_connect_corosync(pcmk_cluster_t *cluster)
145 {
146 if (pcmk_get_cluster_layer() == pcmk_cluster_layer_corosync) {
147 pcmk__cluster_set_status_callback(&peer_update_callback);
148
149 pcmk_cluster_set_destroy_fn(cluster, crmd_cs_destroy);
150 pcmk_cpg_set_deliver_fn(cluster, crmd_cs_dispatch);
151 pcmk_cpg_set_confchg_fn(cluster, cpg_membership_callback);
152
153 if (pcmk_cluster_connect(cluster) == pcmk_rc_ok) {
154 pcmk__corosync_quorum_connect(crmd_quorum_callback,
155 crmd_cs_destroy);
156 return TRUE;
157 }
158 }
159 return FALSE;
160 }
161
162 #endif