This source file includes following definitions.
- update_dc_expected
- do_cl_join_query
- do_cl_join_announce
- do_cl_join_offer_respond
- join_query_callback
- set_join_state
- update_conn_host_cache
- do_cl_join_finalize_respond
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <crm/crm.h>
13 #include <crm/cib.h>
14 #include <crm/msg_xml.h>
15 #include <crm/common/xml.h>
16
17 #include <pacemaker-controld.h>
18
19 void join_query_callback(xmlNode * msg, int call_id, int rc, xmlNode * output, void *user_data);
20
21 extern ha_msg_input_t *copy_ha_msg_input(ha_msg_input_t * orig);
22
23
24
25
26
27
28
29
30
31
32
33 static void
34 update_dc_expected(const xmlNode *msg)
35 {
36 if ((controld_globals.dc_name != NULL)
37 && pcmk__xe_attr_is_true(msg, F_CRM_DC_LEAVING)) {
38 crm_node_t *dc_node = crm_get_peer(0, controld_globals.dc_name);
39
40 pcmk__update_peer_expected(__func__, dc_node, CRMD_JOINSTATE_DOWN);
41 }
42 }
43
44
45
46 void
47 do_cl_join_query(long long action,
48 enum crmd_fsa_cause cause,
49 enum crmd_fsa_state cur_state,
50 enum crmd_fsa_input current_input, fsa_data_t * msg_data)
51 {
52 xmlNode *req = create_request(CRM_OP_JOIN_ANNOUNCE, NULL, NULL,
53 CRM_SYSTEM_DC, CRM_SYSTEM_CRMD, NULL);
54
55 sleep(1);
56 update_dc(NULL);
57 crm_debug("Querying for a DC");
58 send_cluster_message(NULL, crm_msg_crmd, req, FALSE);
59 free_xml(req);
60 }
61
62
63
64
65
66
67 void
68 do_cl_join_announce(long long action,
69 enum crmd_fsa_cause cause,
70 enum crmd_fsa_state cur_state,
71 enum crmd_fsa_input current_input, fsa_data_t * msg_data)
72 {
73
74 if (cur_state != S_PENDING) {
75 crm_warn("Not announcing cluster join because in state %s",
76 fsa_state2string(cur_state));
77 return;
78 }
79
80 if (!pcmk_is_set(controld_globals.fsa_input_register, R_STARTING)) {
81
82 xmlNode *req = create_request(CRM_OP_JOIN_ANNOUNCE, NULL, NULL,
83 CRM_SYSTEM_DC, CRM_SYSTEM_CRMD, NULL);
84
85 crm_debug("Announcing availability");
86 update_dc(NULL);
87 send_cluster_message(NULL, crm_msg_crmd, req, FALSE);
88 free_xml(req);
89
90 } else {
91
92 crm_warn("Delaying announce of cluster join until local startup is complete");
93 return;
94 }
95 }
96
97 static int query_call_id = 0;
98
99
100
101 void
102 do_cl_join_offer_respond(long long action,
103 enum crmd_fsa_cause cause,
104 enum crmd_fsa_state cur_state,
105 enum crmd_fsa_input current_input, fsa_data_t * msg_data)
106 {
107 cib_t *cib_conn = controld_globals.cib_conn;
108
109 ha_msg_input_t *input = fsa_typed_data(fsa_dt_ha_msg);
110 const char *welcome_from;
111 const char *join_id;
112
113 CRM_CHECK(input != NULL, return);
114
115 welcome_from = crm_element_value(input->msg, F_CRM_HOST_FROM);
116 join_id = crm_element_value(input->msg, F_CRM_JOIN_ID);
117 crm_trace("Accepting cluster join offer from node %s "CRM_XS" join-%s",
118 welcome_from, crm_element_value(input->msg, F_CRM_JOIN_ID));
119
120
121 if (query_call_id > 0) {
122 crm_trace("Cancelling previous join query: %d", query_call_id);
123 remove_cib_op_callback(query_call_id, FALSE);
124 query_call_id = 0;
125 }
126
127 if (update_dc(input->msg) == FALSE) {
128 crm_warn("Discarding cluster join offer from node %s (expected %s)",
129 welcome_from, controld_globals.dc_name);
130 return;
131 }
132
133 update_dc_expected(input->msg);
134
135 query_call_id = cib_conn->cmds->query(cib_conn, NULL, NULL,
136 cib_scope_local|cib_no_children);
137 fsa_register_cib_callback(query_call_id, strdup(join_id),
138 join_query_callback);
139 crm_trace("Registered join query callback: %d", query_call_id);
140
141 controld_set_fsa_action_flags(A_DC_TIMER_STOP);
142 controld_trigger_fsa();
143 }
144
145 void
146 join_query_callback(xmlNode * msg, int call_id, int rc, xmlNode * output, void *user_data)
147 {
148 char *join_id = user_data;
149 xmlNode *generation = create_xml_node(NULL, XML_CIB_TAG_GENERATION_TUPPLE);
150
151 CRM_LOG_ASSERT(join_id != NULL);
152
153 if (query_call_id != call_id) {
154 crm_trace("Query %d superseded", call_id);
155 goto done;
156 }
157
158 query_call_id = 0;
159 if(rc != pcmk_ok || output == NULL) {
160 crm_err("Could not retrieve version details for join-%s: %s (%d)",
161 join_id, pcmk_strerror(rc), rc);
162 register_fsa_error_adv(C_FSA_INTERNAL, I_ERROR, NULL, NULL, __func__);
163
164 } else if (controld_globals.dc_name == NULL) {
165 crm_debug("Membership is in flux, not continuing join-%s", join_id);
166
167 } else {
168 xmlNode *reply = NULL;
169
170 crm_debug("Respond to join offer join-%s from %s",
171 join_id, controld_globals.dc_name);
172 copy_in_properties(generation, output);
173
174 reply = create_request(CRM_OP_JOIN_REQUEST, generation,
175 controld_globals.dc_name, CRM_SYSTEM_DC,
176 CRM_SYSTEM_CRMD, NULL);
177
178 crm_xml_add(reply, F_CRM_JOIN_ID, join_id);
179 crm_xml_add(reply, XML_ATTR_CRM_VERSION, CRM_FEATURE_SET);
180 send_cluster_message(crm_get_peer(0, controld_globals.dc_name),
181 crm_msg_crmd, reply, TRUE);
182 free_xml(reply);
183 }
184
185 done:
186 free_xml(generation);
187 }
188
189 void
190 set_join_state(const char *start_state, const char *node_name, const char *node_uuid,
191 bool remote)
192 {
193 if (pcmk__str_eq(start_state, "standby", pcmk__str_casei)) {
194 crm_notice("Forcing node %s to join in %s state per configured "
195 "environment", node_name, start_state);
196 cib__update_node_attr(controld_globals.logger_out,
197 controld_globals.cib_conn, cib_sync_call,
198 XML_CIB_TAG_NODES, node_uuid,
199 NULL, NULL, NULL, "standby", "on", NULL,
200 remote ? "remote" : NULL);
201
202 } else if (pcmk__str_eq(start_state, "online", pcmk__str_casei)) {
203 crm_notice("Forcing node %s to join in %s state per configured "
204 "environment", node_name, start_state);
205 cib__update_node_attr(controld_globals.logger_out,
206 controld_globals.cib_conn, cib_sync_call,
207 XML_CIB_TAG_NODES, node_uuid,
208 NULL, NULL, NULL, "standby", "off", NULL,
209 remote ? "remote" : NULL);
210
211 } else if (pcmk__str_eq(start_state, "default", pcmk__str_casei)) {
212 crm_debug("Not forcing a starting state on node %s", node_name);
213
214 } else {
215 crm_warn("Unrecognized start state '%s', using 'default' (%s)",
216 start_state, node_name);
217 }
218 }
219
220 static int
221 update_conn_host_cache(xmlNode *node, void *userdata)
222 {
223 const char *remote = crm_element_value(node, XML_ATTR_ID);
224 const char *conn_host = crm_element_value(node, PCMK__XA_CONN_HOST);
225 const char *state = crm_element_value(node, XML_CIB_TAG_STATE);
226
227 crm_node_t *remote_peer = crm_remote_peer_get(remote);
228
229 if (remote_peer == NULL) {
230 return pcmk_rc_ok;
231 }
232
233 if (conn_host != NULL) {
234 pcmk__str_update(&remote_peer->conn_host, conn_host);
235 }
236
237 if (state != NULL) {
238 pcmk__update_peer_state(__func__, remote_peer, state, 0);
239 }
240
241 return pcmk_rc_ok;
242 }
243
244
245
246 void
247 do_cl_join_finalize_respond(long long action,
248 enum crmd_fsa_cause cause,
249 enum crmd_fsa_state cur_state,
250 enum crmd_fsa_input current_input, fsa_data_t * msg_data)
251 {
252 xmlNode *tmp1 = NULL;
253 gboolean was_nack = TRUE;
254 static gboolean first_join = TRUE;
255 ha_msg_input_t *input = fsa_typed_data(fsa_dt_ha_msg);
256 const char *start_state = pcmk__env_option(PCMK__ENV_NODE_START_STATE);
257
258 int join_id = -1;
259 const char *op = crm_element_value(input->msg, F_CRM_TASK);
260 const char *welcome_from = crm_element_value(input->msg, F_CRM_HOST_FROM);
261
262 if (!pcmk__str_eq(op, CRM_OP_JOIN_ACKNAK, pcmk__str_casei)) {
263 crm_trace("Ignoring op=%s message", op);
264 return;
265 }
266
267
268 if (pcmk__xe_attr_is_true(input->msg, CRM_OP_JOIN_ACKNAK)) {
269 was_nack = FALSE;
270 }
271
272 crm_element_value_int(input->msg, F_CRM_JOIN_ID, &join_id);
273
274 if (was_nack) {
275 crm_err("Shutting down because cluster join with leader %s failed "
276 CRM_XS" join-%d NACK'd", welcome_from, join_id);
277 register_fsa_error(C_FSA_INTERNAL, I_ERROR, NULL);
278 controld_set_fsa_input_flags(R_STAYDOWN);
279 return;
280 }
281
282 if (!AM_I_DC
283 && pcmk__str_eq(welcome_from, controld_globals.our_nodename,
284 pcmk__str_casei)) {
285 crm_warn("Discarding our own welcome - we're no longer the DC");
286 return;
287 }
288
289 if (update_dc(input->msg) == FALSE) {
290 crm_warn("Discarding %s from node %s (expected from %s)",
291 op, welcome_from, controld_globals.dc_name);
292 return;
293 }
294
295 update_dc_expected(input->msg);
296
297
298 update_attrd(controld_globals.our_nodename, CRM_ATTR_FEATURE_SET,
299 CRM_FEATURE_SET, NULL, FALSE);
300
301
302 tmp1 = controld_query_executor_state();
303 if (tmp1 != NULL) {
304 xmlNode *remotes = NULL;
305 xmlNode *reply = create_request(CRM_OP_JOIN_CONFIRM, tmp1,
306 controld_globals.dc_name, CRM_SYSTEM_DC,
307 CRM_SYSTEM_CRMD, NULL);
308
309 crm_xml_add_int(reply, F_CRM_JOIN_ID, join_id);
310
311 crm_debug("Confirming join-%d: sending local operation history to %s",
312 join_id, controld_globals.dc_name);
313
314
315
316
317
318
319
320
321
322
323
324
325
326 if (first_join
327 && !pcmk_is_set(controld_globals.fsa_input_register, R_SHUTDOWN)) {
328
329 first_join = FALSE;
330 if (start_state) {
331 set_join_state(start_state, controld_globals.our_nodename,
332 controld_globals.our_uuid, false);
333 }
334 }
335
336 send_cluster_message(crm_get_peer(0, controld_globals.dc_name),
337 crm_msg_crmd, reply, TRUE);
338 free_xml(reply);
339
340 if (AM_I_DC == FALSE) {
341 register_fsa_input_adv(cause, I_NOT_DC, NULL, A_NOTHING, TRUE,
342 __func__);
343 }
344
345 free_xml(tmp1);
346
347
348
349
350 remotes = pcmk__xe_match(input->msg, XML_CIB_TAG_NODES, NULL, NULL);
351 if (remotes != NULL) {
352 pcmk__xe_foreach_child(remotes, XML_CIB_TAG_NODE, update_conn_host_cache, NULL);
353 }
354
355 } else {
356 crm_err("Could not confirm join-%d with %s: Local operation history "
357 "failed", join_id, controld_globals.dc_name);
358 register_fsa_error(C_FSA_INTERNAL, I_FAIL, NULL);
359 }
360 }