This source file includes following definitions.
- register_fsa_error_adv
- register_fsa_input_adv
- fsa_dump_queue
- copy_ha_msg_input
- delete_fsa_input
- get_message
- fsa_typed_data_adv
- do_msg_route
- route_message
- relay_message
- authorize_version
- controld_authorize_ipc_message
- handle_message
- handle_failcount_op
- handle_lrm_delete
- handle_remote_state
- handle_ping
- handle_node_list
- handle_node_info_request
- verify_feature_set
- handle_shutdown_self_ack
- handle_shutdown_ack
- handle_request
- handle_response
- handle_shutdown_request
- send_msg_via_ipc
- delete_ha_msg_input
- send_remote_state_message
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <sys/param.h>
13 #include <string.h>
14 #include <time.h>
15
16 #include <crm/crm.h>
17 #include <crm/msg_xml.h>
18 #include <crm/common/xml.h>
19 #include <crm/cluster/internal.h>
20 #include <crm/cib.h>
21 #include <crm/common/ipc_internal.h>
22
23 #include <pacemaker-controld.h>
24
25 GList *fsa_message_queue = NULL;
26 extern void crm_shutdown(int nsig);
27
28 static enum crmd_fsa_input handle_message(xmlNode *msg,
29 enum crmd_fsa_cause cause);
30 static void handle_response(xmlNode *stored_msg);
31 static enum crmd_fsa_input handle_request(xmlNode *stored_msg,
32 enum crmd_fsa_cause cause);
33 static enum crmd_fsa_input handle_shutdown_request(xmlNode *stored_msg);
34 static void send_msg_via_ipc(xmlNode * msg, const char *sys);
35
36
37 int last_data_id = 0;
38
39 void
40 register_fsa_error_adv(enum crmd_fsa_cause cause, enum crmd_fsa_input input,
41 fsa_data_t * cur_data, void *new_data, const char *raised_from)
42 {
43
44 if (fsa_actions != A_NOTHING) {
45 register_fsa_input_adv(cur_data ? cur_data->fsa_cause : C_FSA_INTERNAL,
46 I_NULL, cur_data ? cur_data->data : NULL,
47 fsa_actions, TRUE, __func__);
48 }
49
50
51 crm_info("Resetting the current action list");
52 fsa_dump_actions(fsa_actions, "Drop");
53 fsa_actions = A_NOTHING;
54
55
56 register_fsa_input_adv(cause, input, new_data, A_NOTHING, TRUE, raised_from);
57 }
58
59 int
60 register_fsa_input_adv(enum crmd_fsa_cause cause, enum crmd_fsa_input input,
61 void *data, uint64_t with_actions,
62 gboolean prepend, const char *raised_from)
63 {
64 unsigned old_len = g_list_length(fsa_message_queue);
65 fsa_data_t *fsa_data = NULL;
66
67 if (raised_from == NULL) {
68 raised_from = "<unknown>";
69 }
70
71 if (input == I_NULL && with_actions == A_NOTHING ) {
72
73 crm_err("Cannot add entry to queue: no input and no action");
74 return 0;
75 }
76
77 if (input == I_WAIT_FOR_EVENT) {
78 do_fsa_stall = TRUE;
79 crm_debug("Stalling the FSA pending further input: source=%s cause=%s data=%p queue=%d",
80 raised_from, fsa_cause2string(cause), data, old_len);
81
82 if (old_len > 0) {
83 fsa_dump_queue(LOG_TRACE);
84 prepend = FALSE;
85 }
86
87 if (data == NULL) {
88 controld_set_fsa_action_flags(with_actions);
89 fsa_dump_actions(with_actions, "Restored");
90 return 0;
91 }
92
93
94 with_actions |= fsa_actions;
95 fsa_actions = A_NOTHING;
96 }
97
98 last_data_id++;
99 crm_trace("%s %s FSA input %d (%s) due to %s, %s data",
100 raised_from, (prepend? "prepended" : "appended"), last_data_id,
101 fsa_input2string(input), fsa_cause2string(cause),
102 (data? "with" : "without"));
103
104 fsa_data = calloc(1, sizeof(fsa_data_t));
105 fsa_data->id = last_data_id;
106 fsa_data->fsa_input = input;
107 fsa_data->fsa_cause = cause;
108 fsa_data->origin = raised_from;
109 fsa_data->data = NULL;
110 fsa_data->data_type = fsa_dt_none;
111 fsa_data->actions = with_actions;
112
113 if (with_actions != A_NOTHING) {
114 crm_trace("Adding actions %.16llx to input",
115 (unsigned long long) with_actions);
116 }
117
118 if (data != NULL) {
119 switch (cause) {
120 case C_FSA_INTERNAL:
121 case C_CRMD_STATUS_CALLBACK:
122 case C_IPC_MESSAGE:
123 case C_HA_MESSAGE:
124 CRM_CHECK(((ha_msg_input_t *) data)->msg != NULL,
125 crm_err("Bogus data from %s", raised_from));
126 crm_trace("Copying %s data from %s as cluster message data",
127 fsa_cause2string(cause), raised_from);
128 fsa_data->data = copy_ha_msg_input(data);
129 fsa_data->data_type = fsa_dt_ha_msg;
130 break;
131
132 case C_LRM_OP_CALLBACK:
133 crm_trace("Copying %s data from %s as lrmd_event_data_t",
134 fsa_cause2string(cause), raised_from);
135 fsa_data->data = lrmd_copy_event((lrmd_event_data_t *) data);
136 fsa_data->data_type = fsa_dt_lrm;
137 break;
138
139 case C_TIMER_POPPED:
140 case C_SHUTDOWN:
141 case C_UNKNOWN:
142 case C_STARTUP:
143 crm_crit("Copying %s data (from %s) is not yet implemented",
144 fsa_cause2string(cause), raised_from);
145 crmd_exit(CRM_EX_SOFTWARE);
146 break;
147 }
148 }
149
150
151 if (prepend) {
152 fsa_message_queue = g_list_prepend(fsa_message_queue, fsa_data);
153 } else {
154 fsa_message_queue = g_list_append(fsa_message_queue, fsa_data);
155 }
156
157 crm_trace("FSA message queue length is %d",
158 g_list_length(fsa_message_queue));
159
160
161
162 if (old_len == g_list_length(fsa_message_queue)) {
163 crm_err("Couldn't add message to the queue");
164 }
165
166 if (fsa_source && input != I_WAIT_FOR_EVENT) {
167 crm_trace("Triggering FSA");
168 mainloop_set_trigger(fsa_source);
169 }
170 return last_data_id;
171 }
172
173 void
174 fsa_dump_queue(int log_level)
175 {
176 int offset = 0;
177 GList *lpc = NULL;
178
179 for (lpc = fsa_message_queue; lpc != NULL; lpc = lpc->next) {
180 fsa_data_t *data = (fsa_data_t *) lpc->data;
181
182 do_crm_log_unlikely(log_level,
183 "queue[%d.%d]: input %s raised by %s(%p.%d)\t(cause=%s)",
184 offset++, data->id, fsa_input2string(data->fsa_input),
185 data->origin, data->data, data->data_type,
186 fsa_cause2string(data->fsa_cause));
187 }
188 }
189
190 ha_msg_input_t *
191 copy_ha_msg_input(ha_msg_input_t * orig)
192 {
193 ha_msg_input_t *copy = calloc(1, sizeof(ha_msg_input_t));
194
195 CRM_ASSERT(copy != NULL);
196 copy->msg = (orig && orig->msg)? copy_xml(orig->msg) : NULL;
197 copy->xml = get_message_xml(copy->msg, F_CRM_DATA);
198 return copy;
199 }
200
201 void
202 delete_fsa_input(fsa_data_t * fsa_data)
203 {
204 lrmd_event_data_t *op = NULL;
205 xmlNode *foo = NULL;
206
207 if (fsa_data == NULL) {
208 return;
209 }
210 crm_trace("About to free %s data", fsa_cause2string(fsa_data->fsa_cause));
211
212 if (fsa_data->data != NULL) {
213 switch (fsa_data->data_type) {
214 case fsa_dt_ha_msg:
215 delete_ha_msg_input(fsa_data->data);
216 break;
217
218 case fsa_dt_xml:
219 foo = fsa_data->data;
220 free_xml(foo);
221 break;
222
223 case fsa_dt_lrm:
224 op = (lrmd_event_data_t *) fsa_data->data;
225 lrmd_free_event(op);
226 break;
227
228 case fsa_dt_none:
229 if (fsa_data->data != NULL) {
230 crm_err("Don't know how to free %s data from %s",
231 fsa_cause2string(fsa_data->fsa_cause), fsa_data->origin);
232 crmd_exit(CRM_EX_SOFTWARE);
233 }
234 break;
235 }
236 crm_trace("%s data freed", fsa_cause2string(fsa_data->fsa_cause));
237 }
238
239 free(fsa_data);
240 }
241
242
243 fsa_data_t *
244 get_message(void)
245 {
246 fsa_data_t *message = g_list_nth_data(fsa_message_queue, 0);
247
248 fsa_message_queue = g_list_remove(fsa_message_queue, message);
249 crm_trace("Processing input %d", message->id);
250 return message;
251 }
252
253 void *
254 fsa_typed_data_adv(fsa_data_t * fsa_data, enum fsa_data_type a_type, const char *caller)
255 {
256 void *ret_val = NULL;
257
258 if (fsa_data == NULL) {
259 crm_err("%s: No FSA data available", caller);
260
261 } else if (fsa_data->data == NULL) {
262 crm_err("%s: No message data available. Origin: %s", caller, fsa_data->origin);
263
264 } else if (fsa_data->data_type != a_type) {
265 crm_crit("%s: Message data was the wrong type! %d vs. requested=%d. Origin: %s",
266 caller, fsa_data->data_type, a_type, fsa_data->origin);
267 CRM_ASSERT(fsa_data->data_type == a_type);
268 } else {
269 ret_val = fsa_data->data;
270 }
271
272 return ret_val;
273 }
274
275
276 void
277 do_msg_route(long long action,
278 enum crmd_fsa_cause cause,
279 enum crmd_fsa_state cur_state,
280 enum crmd_fsa_input current_input, fsa_data_t * msg_data)
281 {
282 ha_msg_input_t *input = fsa_typed_data(fsa_dt_ha_msg);
283
284 route_message(msg_data->fsa_cause, input->msg);
285 }
286
287 void
288 route_message(enum crmd_fsa_cause cause, xmlNode * input)
289 {
290 ha_msg_input_t fsa_input;
291 enum crmd_fsa_input result = I_NULL;
292
293 fsa_input.msg = input;
294 CRM_CHECK(cause == C_IPC_MESSAGE || cause == C_HA_MESSAGE, return);
295
296
297 if (relay_message(input, cause == C_IPC_MESSAGE)) {
298 return;
299 }
300
301
302 result = handle_message(input, cause);
303
304
305 switch (result) {
306 case I_NULL:
307 case I_CIB_OP:
308 case I_ROUTER:
309 case I_NODE_JOIN:
310 case I_JOIN_REQUEST:
311 case I_JOIN_RESULT:
312 break;
313 default:
314
315 register_fsa_input_later(cause, result, &fsa_input);
316 return;
317 }
318
319 if (result != I_NULL) {
320
321 register_fsa_input(cause, result, &fsa_input);
322 }
323 }
324
325 gboolean
326 relay_message(xmlNode * msg, gboolean originated_locally)
327 {
328 int dest = 1;
329 bool is_for_dc = false;
330 bool is_for_dcib = false;
331 bool is_for_te = false;
332 bool is_for_crm = false;
333 bool is_for_cib = false;
334 bool is_local = false;
335 const char *host_to = crm_element_value(msg, F_CRM_HOST_TO);
336 const char *sys_to = crm_element_value(msg, F_CRM_SYS_TO);
337 const char *sys_from = crm_element_value(msg, F_CRM_SYS_FROM);
338 const char *type = crm_element_value(msg, F_TYPE);
339 const char *task = crm_element_value(msg, F_CRM_TASK);
340 const char *ref = crm_element_value(msg, XML_ATTR_REFERENCE);
341
342 if (ref == NULL) {
343 ref = "without reference ID";
344 }
345
346 if (msg == NULL) {
347 crm_warn("Cannot route empty message");
348 return TRUE;
349
350 } else if (pcmk__str_eq(task, CRM_OP_HELLO, pcmk__str_casei)) {
351
352 crm_trace("No routing needed for hello message %s", ref);
353 return TRUE;
354
355 } else if (!pcmk__str_eq(type, T_CRM, pcmk__str_casei)) {
356 crm_warn("Cannot route message %s: Type is '%s' not '" T_CRM "'",
357 ref, (type? type : "missing"));
358 crm_log_xml_warn(msg, "[bad message type]");
359 return TRUE;
360
361 } else if (sys_to == NULL) {
362 crm_warn("Cannot route message %s: No subsystem specified", ref);
363 crm_log_xml_warn(msg, "[no subsystem]");
364 return TRUE;
365 }
366
367 is_for_dc = (strcasecmp(CRM_SYSTEM_DC, sys_to) == 0);
368 is_for_dcib = (strcasecmp(CRM_SYSTEM_DCIB, sys_to) == 0);
369 is_for_te = (strcasecmp(CRM_SYSTEM_TENGINE, sys_to) == 0);
370 is_for_cib = (strcasecmp(CRM_SYSTEM_CIB, sys_to) == 0);
371 is_for_crm = (strcasecmp(CRM_SYSTEM_CRMD, sys_to) == 0);
372
373 is_local = false;
374 if (pcmk__str_empty(host_to)) {
375 if (is_for_dc || is_for_te) {
376 is_local = false;
377
378 } else if (is_for_crm) {
379 if (pcmk__strcase_any_of(task, CRM_OP_NODE_INFO,
380 PCMK__CONTROLD_CMD_NODES, NULL)) {
381
382
383
384
385
386 is_local = true;
387 } else {
388 is_local = !originated_locally;
389 }
390
391 } else {
392 is_local = true;
393 }
394
395 } else if (pcmk__str_eq(fsa_our_uname, host_to, pcmk__str_casei)) {
396 is_local = true;
397 } else if (is_for_crm && pcmk__str_eq(task, CRM_OP_LRM_DELETE, pcmk__str_casei)) {
398 xmlNode *msg_data = get_message_xml(msg, F_CRM_DATA);
399 const char *mode = crm_element_value(msg_data, PCMK__XA_MODE);
400
401 if (pcmk__str_eq(mode, XML_TAG_CIB, pcmk__str_casei)) {
402
403 is_local = true;
404 }
405 }
406
407 if (is_for_dc || is_for_dcib || is_for_te) {
408 if (AM_I_DC && is_for_te) {
409 crm_trace("Route message %s locally as transition request", ref);
410 send_msg_via_ipc(msg, sys_to);
411
412 } else if (AM_I_DC) {
413 crm_trace("Route message %s locally as DC request", ref);
414 return FALSE;
415
416 } else if (originated_locally && !pcmk__strcase_any_of(sys_from, CRM_SYSTEM_PENGINE,
417 CRM_SYSTEM_TENGINE, NULL)) {
418
419 #if SUPPORT_COROSYNC
420 if (is_corosync_cluster()) {
421 dest = text2msg_type(sys_to);
422 }
423 #endif
424 crm_trace("Relay message %s to DC", ref);
425 send_cluster_message(host_to ? crm_get_peer(0, host_to) : NULL, dest, msg, TRUE);
426
427 } else {
428
429
430
431
432 crm_trace("Discard message %s because we are not DC", ref);
433 }
434
435 } else if (is_local && (is_for_crm || is_for_cib)) {
436 crm_trace("Route message %s locally as controller request", ref);
437 return FALSE;
438
439 } else if (is_local) {
440 crm_trace("Relay message %s locally to %s",
441 ref, (sys_to? sys_to : "unknown client"));
442 crm_log_xml_trace(msg, "[IPC relay]");
443 send_msg_via_ipc(msg, sys_to);
444
445 } else {
446 crm_node_t *node_to = NULL;
447
448 #if SUPPORT_COROSYNC
449 if (is_corosync_cluster()) {
450 dest = text2msg_type(sys_to);
451
452 if (dest == crm_msg_none || dest > crm_msg_stonith_ng) {
453 dest = crm_msg_crmd;
454 }
455 }
456 #endif
457
458 if (host_to) {
459 node_to = pcmk__search_cluster_node_cache(0, host_to);
460 if (node_to == NULL) {
461 crm_warn("Cannot route message %s: Unknown node %s",
462 ref, host_to);
463 return TRUE;
464 }
465 crm_trace("Relay message %s to %s",
466 ref, (node_to->uname? node_to->uname : "peer"));
467 } else {
468 crm_trace("Broadcast message %s to all peers", ref);
469 }
470 send_cluster_message(host_to ? node_to : NULL, dest, msg, TRUE);
471 }
472
473 return TRUE;
474 }
475
476
477 static bool
478 authorize_version(xmlNode *message_data, const char *field,
479 const char *client_name, const char *ref, const char *uuid)
480 {
481 const char *version = crm_element_value(message_data, field);
482 long long version_num;
483
484 if ((pcmk__scan_ll(version, &version_num, -1LL) != pcmk_rc_ok)
485 || (version_num < 0LL)) {
486
487 crm_warn("Rejected IPC hello from %s: '%s' is not a valid protocol %s "
488 CRM_XS " ref=%s uuid=%s",
489 client_name, ((version == NULL)? "" : version),
490 field, (ref? ref : "none"), uuid);
491 return false;
492 }
493 return true;
494 }
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511 bool
512 controld_authorize_ipc_message(xmlNode *client_msg, pcmk__client_t *curr_client,
513 const char *proxy_session)
514 {
515 xmlNode *message_data = NULL;
516 const char *client_name = NULL;
517 const char *op = crm_element_value(client_msg, F_CRM_TASK);
518 const char *ref = crm_element_value(client_msg, XML_ATTR_REFERENCE);
519 const char *uuid = (curr_client? curr_client->id : proxy_session);
520
521 if (uuid == NULL) {
522 crm_warn("IPC message from client rejected: No client identifier "
523 CRM_XS " ref=%s", (ref? ref : "none"));
524 goto rejected;
525 }
526
527 if (!pcmk__str_eq(CRM_OP_HELLO, op, pcmk__str_casei)) {
528
529 return true;
530 }
531
532 message_data = get_message_xml(client_msg, F_CRM_DATA);
533
534 client_name = crm_element_value(message_data, "client_name");
535 if (pcmk__str_empty(client_name)) {
536 crm_warn("IPC hello from client rejected: No client name",
537 CRM_XS " ref=%s uuid=%s", (ref? ref : "none"), uuid);
538 goto rejected;
539 }
540 if (!authorize_version(message_data, "major_version", client_name, ref,
541 uuid)) {
542 goto rejected;
543 }
544 if (!authorize_version(message_data, "minor_version", client_name, ref,
545 uuid)) {
546 goto rejected;
547 }
548
549 crm_trace("Validated IPC hello from client %s", client_name);
550 if (curr_client) {
551 curr_client->userdata = strdup(client_name);
552 }
553 mainloop_set_trigger(fsa_source);
554 return false;
555
556 rejected:
557 if (curr_client) {
558 qb_ipcs_disconnect(curr_client->ipcs);
559 }
560 return false;
561 }
562
563 static enum crmd_fsa_input
564 handle_message(xmlNode *msg, enum crmd_fsa_cause cause)
565 {
566 const char *type = NULL;
567
568 CRM_CHECK(msg != NULL, return I_NULL);
569
570 type = crm_element_value(msg, F_CRM_MSG_TYPE);
571 if (pcmk__str_eq(type, XML_ATTR_REQUEST, pcmk__str_none)) {
572 return handle_request(msg, cause);
573
574 } else if (pcmk__str_eq(type, XML_ATTR_RESPONSE, pcmk__str_none)) {
575 handle_response(msg);
576 return I_NULL;
577 }
578
579 crm_err("Unknown message type: %s", type);
580 return I_NULL;
581 }
582
583 static enum crmd_fsa_input
584 handle_failcount_op(xmlNode * stored_msg)
585 {
586 const char *rsc = NULL;
587 const char *uname = NULL;
588 const char *op = NULL;
589 char *interval_spec = NULL;
590 guint interval_ms = 0;
591 gboolean is_remote_node = FALSE;
592 xmlNode *xml_op = get_message_xml(stored_msg, F_CRM_DATA);
593
594 if (xml_op) {
595 xmlNode *xml_rsc = first_named_child(xml_op, XML_CIB_TAG_RESOURCE);
596 xmlNode *xml_attrs = first_named_child(xml_op, XML_TAG_ATTRS);
597
598 if (xml_rsc) {
599 rsc = ID(xml_rsc);
600 }
601 if (xml_attrs) {
602 op = crm_element_value(xml_attrs,
603 CRM_META "_" XML_RSC_ATTR_CLEAR_OP);
604 crm_element_value_ms(xml_attrs,
605 CRM_META "_" XML_RSC_ATTR_CLEAR_INTERVAL,
606 &interval_ms);
607 }
608 }
609 uname = crm_element_value(xml_op, XML_LRM_ATTR_TARGET);
610
611 if ((rsc == NULL) || (uname == NULL)) {
612 crm_log_xml_warn(stored_msg, "invalid failcount op");
613 return I_NULL;
614 }
615
616 if (crm_element_value(xml_op, XML_LRM_ATTR_ROUTER_NODE)) {
617 is_remote_node = TRUE;
618 }
619
620 if (interval_ms) {
621 interval_spec = crm_strdup_printf("%ums", interval_ms);
622 }
623 update_attrd_clear_failures(uname, rsc, op, interval_spec, is_remote_node);
624 free(interval_spec);
625
626 lrm_clear_last_failure(rsc, uname, op, interval_ms);
627
628 return I_NULL;
629 }
630
631 static enum crmd_fsa_input
632 handle_lrm_delete(xmlNode *stored_msg)
633 {
634 const char *mode = NULL;
635 xmlNode *msg_data = get_message_xml(stored_msg, F_CRM_DATA);
636
637 CRM_CHECK(msg_data != NULL, return I_NULL);
638
639
640
641
642
643
644
645
646
647
648
649 mode = crm_element_value(msg_data, PCMK__XA_MODE);
650 if ((mode == NULL) || strcmp(mode, XML_TAG_CIB)) {
651
652 crm_xml_add(stored_msg, F_CRM_SYS_TO, CRM_SYSTEM_LRMD);
653 return I_ROUTER;
654
655 } else {
656
657 const char *from_sys = NULL;
658 const char *user_name = NULL;
659 const char *rsc_id = NULL;
660 const char *node = NULL;
661 xmlNode *rsc_xml = NULL;
662 int rc = pcmk_rc_ok;
663
664 rsc_xml = first_named_child(msg_data, XML_CIB_TAG_RESOURCE);
665 CRM_CHECK(rsc_xml != NULL, return I_NULL);
666
667 rsc_id = ID(rsc_xml);
668 from_sys = crm_element_value(stored_msg, F_CRM_SYS_FROM);
669 node = crm_element_value(msg_data, XML_LRM_ATTR_TARGET);
670 user_name = pcmk__update_acl_user(stored_msg, F_CRM_USER, NULL);
671 crm_debug("Handling " CRM_OP_LRM_DELETE " for %s on %s locally%s%s "
672 "(clearing CIB resource history only)", rsc_id, node,
673 (user_name? " for user " : ""), (user_name? user_name : ""));
674 rc = controld_delete_resource_history(rsc_id, node, user_name,
675 cib_dryrun|cib_sync_call);
676 if (rc == pcmk_rc_ok) {
677 rc = controld_delete_resource_history(rsc_id, node, user_name,
678 crmd_cib_smart_opt());
679 }
680
681
682 if (from_sys) {
683 lrmd_event_data_t *op = NULL;
684 const char *from_host = crm_element_value(stored_msg,
685 F_CRM_HOST_FROM);
686 const char *transition;
687
688 if (strcmp(from_sys, CRM_SYSTEM_TENGINE)) {
689 transition = crm_element_value(msg_data,
690 XML_ATTR_TRANSITION_KEY);
691 } else {
692 transition = crm_element_value(stored_msg,
693 XML_ATTR_TRANSITION_KEY);
694 }
695
696 crm_info("Notifying %s on %s that %s was%s deleted",
697 from_sys, (from_host? from_host : "local node"), rsc_id,
698 ((rc == pcmk_rc_ok)? "" : " not"));
699 op = lrmd_new_event(rsc_id, CRMD_ACTION_DELETE, 0);
700 op->type = lrmd_event_exec_complete;
701 op->user_data = strdup(transition? transition : FAKE_TE_ID);
702 op->params = pcmk__strkey_table(free, free);
703 g_hash_table_insert(op->params, strdup(XML_ATTR_CRM_VERSION),
704 strdup(CRM_FEATURE_SET));
705 controld_rc2event(op, rc);
706 controld_ack_event_directly(from_host, from_sys, NULL, op, rsc_id);
707 lrmd_free_event(op);
708 controld_trigger_delete_refresh(from_sys, rsc_id);
709 }
710 return I_NULL;
711 }
712 }
713
714
715
716
717
718
719
720
721 static enum crmd_fsa_input
722 handle_remote_state(xmlNode *msg)
723 {
724 const char *remote_uname = ID(msg);
725 crm_node_t *remote_peer;
726 bool remote_is_up = false;
727 int rc = pcmk_rc_ok;
728
729 rc = pcmk__xe_get_bool_attr(msg, XML_NODE_IN_CLUSTER, &remote_is_up);
730
731 CRM_CHECK(remote_uname && rc == pcmk_rc_ok, return I_NULL);
732
733 remote_peer = crm_remote_peer_get(remote_uname);
734 CRM_CHECK(remote_peer, return I_NULL);
735
736 pcmk__update_peer_state(__func__, remote_peer,
737 remote_is_up ? CRM_NODE_MEMBER : CRM_NODE_LOST,
738 0);
739 return I_NULL;
740 }
741
742
743
744
745
746
747
748
749 static enum crmd_fsa_input
750 handle_ping(xmlNode *msg)
751 {
752 const char *value = NULL;
753 xmlNode *ping = NULL;
754
755
756
757 ping = create_xml_node(NULL, XML_CRM_TAG_PING);
758 value = crm_element_value(msg, F_CRM_SYS_TO);
759 crm_xml_add(ping, XML_PING_ATTR_SYSFROM, value);
760
761
762 value = fsa_state2string(fsa_state);
763 crm_xml_add(ping, XML_PING_ATTR_CRMDSTATE, value);
764 crm_notice("Current ping state: %s", value);
765
766
767
768 crm_xml_add(ping, XML_PING_ATTR_STATUS, "ok");
769
770
771 msg = create_reply(msg, ping);
772 free_xml(ping);
773 if (msg) {
774 (void) relay_message(msg, TRUE);
775 free_xml(msg);
776 }
777
778
779 return I_NULL;
780 }
781
782
783
784
785
786
787 static enum crmd_fsa_input
788 handle_node_list(xmlNode *request)
789 {
790 GHashTableIter iter;
791 crm_node_t *node = NULL;
792 xmlNode *reply = NULL;
793 xmlNode *reply_data = NULL;
794
795
796 reply_data = create_xml_node(NULL, XML_CIB_TAG_NODES);
797 g_hash_table_iter_init(&iter, crm_peer_cache);
798 while (g_hash_table_iter_next(&iter, NULL, (gpointer *) & node)) {
799 xmlNode *xml = create_xml_node(reply_data, XML_CIB_TAG_NODE);
800
801 crm_xml_add_ll(xml, XML_ATTR_ID, (long long) node->id);
802 crm_xml_add(xml, XML_ATTR_UNAME, node->uname);
803 crm_xml_add(xml, XML_NODE_IN_CLUSTER, node->state);
804 }
805
806
807 reply = create_reply(request, reply_data);
808 free_xml(reply_data);
809 if (reply) {
810 (void) relay_message(reply, TRUE);
811 free_xml(reply);
812 }
813
814
815 return I_NULL;
816 }
817
818
819
820
821
822
823
824
825 static enum crmd_fsa_input
826 handle_node_info_request(xmlNode *msg)
827 {
828 const char *value = NULL;
829 crm_node_t *node = NULL;
830 int node_id = 0;
831 xmlNode *reply = NULL;
832
833
834
835 reply = create_xml_node(NULL, XML_CIB_TAG_NODE);
836 crm_xml_add(reply, XML_PING_ATTR_SYSFROM, CRM_SYSTEM_CRMD);
837
838
839 pcmk__xe_set_bool_attr(reply, XML_ATTR_HAVE_QUORUM, fsa_has_quorum);
840
841
842 crm_element_value_int(msg, XML_ATTR_ID, &node_id);
843 if (node_id < 0) {
844 node_id = 0;
845 }
846 value = crm_element_value(msg, XML_ATTR_UNAME);
847
848
849 if ((node_id == 0) && (value == NULL)) {
850 value = fsa_our_uname;
851 }
852
853 node = pcmk__search_node_caches(node_id, value, CRM_GET_PEER_ANY);
854 if (node) {
855 crm_xml_add_int(reply, XML_ATTR_ID, node->id);
856 crm_xml_add(reply, XML_ATTR_UUID, node->uuid);
857 crm_xml_add(reply, XML_ATTR_UNAME, node->uname);
858 crm_xml_add(reply, XML_NODE_IS_PEER, node->state);
859 pcmk__xe_set_bool_attr(reply, XML_NODE_IS_REMOTE,
860 pcmk_is_set(node->flags, crm_remote_node));
861 }
862
863
864 msg = create_reply(msg, reply);
865 free_xml(reply);
866 if (msg) {
867 (void) relay_message(msg, TRUE);
868 free_xml(msg);
869 }
870
871
872 return I_NULL;
873 }
874
875 static void
876 verify_feature_set(xmlNode *msg)
877 {
878 const char *dc_version = crm_element_value(msg, XML_ATTR_CRM_VERSION);
879
880 if (dc_version == NULL) {
881
882
883
884 dc_version = "3.0.14";
885 }
886
887 if (feature_set_compatible(dc_version, CRM_FEATURE_SET)) {
888 crm_trace("Local feature set (%s) is compatible with DC's (%s)",
889 CRM_FEATURE_SET, dc_version);
890 } else {
891 crm_err("Local feature set (%s) is incompatible with DC's (%s)",
892 CRM_FEATURE_SET, dc_version);
893
894
895 controld_set_fsa_input_flags(R_STAYDOWN);
896 crmd_exit(CRM_EX_FATAL);
897 }
898 }
899
900
901 static enum crmd_fsa_input
902 handle_shutdown_self_ack(xmlNode *stored_msg)
903 {
904 const char *host_from = crm_element_value(stored_msg, F_CRM_HOST_FROM);
905
906 if (pcmk_is_set(fsa_input_register, R_SHUTDOWN)) {
907
908 crm_info("Shutting down controller");
909 return I_STOP;
910 }
911
912 if (pcmk__str_eq(host_from, fsa_our_dc, pcmk__str_casei)) {
913
914 crm_err("Shutting down controller immediately due to "
915 "unexpected shutdown confirmation");
916 return I_TERMINATE;
917 }
918
919 if (fsa_state != S_STOPPING) {
920
921 crm_err("Starting new DC election because %s is "
922 "confirming shutdown we did not request",
923 (host_from? host_from : "another node"));
924 return I_ELECTION;
925 }
926
927
928 crm_debug("Ignoring unexpected shutdown confirmation from %s",
929 (host_from? host_from : "another node"));
930 return I_NULL;
931 }
932
933
934 static enum crmd_fsa_input
935 handle_shutdown_ack(xmlNode *stored_msg)
936 {
937 const char *host_from = crm_element_value(stored_msg, F_CRM_HOST_FROM);
938
939 if (host_from == NULL) {
940 crm_warn("Ignoring shutdown request without origin specified");
941 return I_NULL;
942 }
943
944 if ((fsa_our_dc == NULL) || (strcmp(host_from, fsa_our_dc) == 0)) {
945
946 if (pcmk_is_set(fsa_input_register, R_SHUTDOWN)) {
947 crm_info("Shutting down controller after confirmation from %s",
948 host_from);
949 } else {
950 crm_err("Shutting down controller after unexpected "
951 "shutdown request from %s", host_from);
952 controld_set_fsa_input_flags(R_STAYDOWN);
953 }
954 return I_STOP;
955 }
956
957 crm_warn("Ignoring shutdown request from %s because DC is %s",
958 host_from, fsa_our_dc);
959 return I_NULL;
960 }
961
962 static enum crmd_fsa_input
963 handle_request(xmlNode *stored_msg, enum crmd_fsa_cause cause)
964 {
965 xmlNode *msg = NULL;
966 const char *op = crm_element_value(stored_msg, F_CRM_TASK);
967
968
969
970 if (op == NULL) {
971 crm_log_xml_warn(stored_msg, "[request without " F_CRM_TASK "]");
972 return I_NULL;
973 }
974
975 if (strcmp(op, CRM_OP_SHUTDOWN_REQ) == 0) {
976 const char *from = crm_element_value(stored_msg, F_CRM_HOST_FROM);
977 crm_node_t *node = pcmk__search_cluster_node_cache(0, from);
978
979 pcmk__update_peer_expected(__func__, node, CRMD_JOINSTATE_DOWN);
980 if(AM_I_DC == FALSE) {
981 return I_NULL;
982 }
983 }
984
985
986 if (AM_I_DC) {
987 if (strcmp(op, CRM_OP_JOIN_ANNOUNCE) == 0) {
988 return I_NODE_JOIN;
989
990 } else if (strcmp(op, CRM_OP_JOIN_REQUEST) == 0) {
991 return I_JOIN_REQUEST;
992
993 } else if (strcmp(op, CRM_OP_JOIN_CONFIRM) == 0) {
994 return I_JOIN_RESULT;
995
996 } else if (strcmp(op, CRM_OP_SHUTDOWN) == 0) {
997 return handle_shutdown_self_ack(stored_msg);
998
999 } else if (strcmp(op, CRM_OP_SHUTDOWN_REQ) == 0) {
1000
1001 return handle_shutdown_request(stored_msg);
1002
1003 } else if (strcmp(op, CRM_OP_REMOTE_STATE) == 0) {
1004
1005 return handle_remote_state(stored_msg);
1006 }
1007 }
1008
1009
1010 if (strcmp(op, CRM_OP_NOVOTE) == 0) {
1011 ha_msg_input_t fsa_input;
1012
1013 fsa_input.msg = stored_msg;
1014 register_fsa_input_adv(C_HA_MESSAGE, I_NULL, &fsa_input,
1015 A_ELECTION_COUNT | A_ELECTION_CHECK, FALSE,
1016 __func__);
1017
1018 } else if (strcmp(op, CRM_OP_THROTTLE) == 0) {
1019 throttle_update(stored_msg);
1020 if (AM_I_DC && transition_graph != NULL) {
1021 if (transition_graph->complete == FALSE) {
1022 crm_debug("The throttle changed. Trigger a graph.");
1023 trigger_graph();
1024 }
1025 }
1026 return I_NULL;
1027
1028 } else if (strcmp(op, CRM_OP_CLEAR_FAILCOUNT) == 0) {
1029 return handle_failcount_op(stored_msg);
1030
1031 } else if (strcmp(op, CRM_OP_VOTE) == 0) {
1032
1033 ha_msg_input_t fsa_input;
1034
1035 fsa_input.msg = stored_msg;
1036 register_fsa_input_adv(C_HA_MESSAGE, I_NULL, &fsa_input,
1037 A_ELECTION_COUNT | A_ELECTION_CHECK, FALSE,
1038 __func__);
1039
1040
1041 if (fsa_state == S_HALT) {
1042 crm_debug("Forcing an election from S_HALT");
1043 return I_ELECTION;
1044 #if 0
1045 } else if (AM_I_DC) {
1046
1047 return I_ELECTION;
1048 #endif
1049 }
1050
1051 } else if (strcmp(op, CRM_OP_JOIN_OFFER) == 0) {
1052 verify_feature_set(stored_msg);
1053 crm_debug("Raising I_JOIN_OFFER: join-%s", crm_element_value(stored_msg, F_CRM_JOIN_ID));
1054 return I_JOIN_OFFER;
1055
1056 } else if (strcmp(op, CRM_OP_JOIN_ACKNAK) == 0) {
1057 crm_debug("Raising I_JOIN_RESULT: join-%s", crm_element_value(stored_msg, F_CRM_JOIN_ID));
1058 return I_JOIN_RESULT;
1059
1060 } else if (strcmp(op, CRM_OP_LRM_DELETE) == 0) {
1061 return handle_lrm_delete(stored_msg);
1062
1063 } else if ((strcmp(op, CRM_OP_LRM_FAIL) == 0)
1064 || (strcmp(op, CRM_OP_LRM_REFRESH) == 0)
1065 || (strcmp(op, CRM_OP_REPROBE) == 0)) {
1066
1067 crm_xml_add(stored_msg, F_CRM_SYS_TO, CRM_SYSTEM_LRMD);
1068 return I_ROUTER;
1069
1070 } else if (strcmp(op, CRM_OP_NOOP) == 0) {
1071 return I_NULL;
1072
1073 } else if (strcmp(op, CRM_OP_LOCAL_SHUTDOWN) == 0) {
1074
1075 crm_shutdown(SIGTERM);
1076
1077 return I_NULL;
1078
1079 } else if (strcmp(op, CRM_OP_PING) == 0) {
1080 return handle_ping(stored_msg);
1081
1082 } else if (strcmp(op, CRM_OP_NODE_INFO) == 0) {
1083 return handle_node_info_request(stored_msg);
1084
1085 } else if (strcmp(op, CRM_OP_RM_NODE_CACHE) == 0) {
1086 int id = 0;
1087 const char *name = NULL;
1088
1089 crm_element_value_int(stored_msg, XML_ATTR_ID, &id);
1090 name = crm_element_value(stored_msg, XML_ATTR_UNAME);
1091
1092 if(cause == C_IPC_MESSAGE) {
1093 msg = create_request(CRM_OP_RM_NODE_CACHE, NULL, NULL, CRM_SYSTEM_CRMD, CRM_SYSTEM_CRMD, NULL);
1094 if (send_cluster_message(NULL, crm_msg_crmd, msg, TRUE) == FALSE) {
1095 crm_err("Could not instruct peers to remove references to node %s/%u", name, id);
1096 } else {
1097 crm_notice("Instructing peers to remove references to node %s/%u", name, id);
1098 }
1099 free_xml(msg);
1100
1101 } else {
1102 reap_crm_member(id, name);
1103
1104
1105
1106
1107
1108 st_fail_count_reset(name);
1109 }
1110
1111 } else if (strcmp(op, CRM_OP_MAINTENANCE_NODES) == 0) {
1112 xmlNode *xml = get_message_xml(stored_msg, F_CRM_DATA);
1113
1114 remote_ra_process_maintenance_nodes(xml);
1115
1116 } else if (strcmp(op, PCMK__CONTROLD_CMD_NODES) == 0) {
1117 return handle_node_list(stored_msg);
1118
1119
1120 } else if (!AM_I_DC) {
1121
1122 if (strcmp(op, CRM_OP_SHUTDOWN) == 0) {
1123 return handle_shutdown_ack(stored_msg);
1124 }
1125
1126 } else {
1127 crm_err("Unexpected request (%s) sent to %s", op, AM_I_DC ? "the DC" : "non-DC node");
1128 crm_log_xml_err(stored_msg, "Unexpected");
1129 }
1130
1131 return I_NULL;
1132 }
1133
1134 static void
1135 handle_response(xmlNode *stored_msg)
1136 {
1137 const char *op = crm_element_value(stored_msg, F_CRM_TASK);
1138
1139 if (op == NULL) {
1140 crm_log_xml_err(stored_msg, "Bad message");
1141
1142 } else if (AM_I_DC && strcmp(op, CRM_OP_PECALC) == 0) {
1143
1144 const char *msg_ref = crm_element_value(stored_msg, XML_ATTR_REFERENCE);
1145
1146 if (msg_ref == NULL) {
1147 crm_err("%s - Ignoring calculation with no reference", op);
1148
1149 } else if (pcmk__str_eq(msg_ref, fsa_pe_ref, pcmk__str_casei)) {
1150 ha_msg_input_t fsa_input;
1151
1152 controld_stop_sched_timer();
1153 fsa_input.msg = stored_msg;
1154 register_fsa_input_later(C_IPC_MESSAGE, I_PE_SUCCESS, &fsa_input);
1155
1156 } else {
1157 crm_info("%s calculation %s is obsolete", op, msg_ref);
1158 }
1159
1160 } else if (strcmp(op, CRM_OP_VOTE) == 0
1161 || strcmp(op, CRM_OP_SHUTDOWN_REQ) == 0 || strcmp(op, CRM_OP_SHUTDOWN) == 0) {
1162
1163 } else {
1164 const char *host_from = crm_element_value(stored_msg, F_CRM_HOST_FROM);
1165
1166 crm_err("Unexpected response (op=%s, src=%s) sent to the %s",
1167 op, host_from, AM_I_DC ? "DC" : "controller");
1168 }
1169 }
1170
1171 static enum crmd_fsa_input
1172 handle_shutdown_request(xmlNode * stored_msg)
1173 {
1174
1175
1176
1177
1178
1179
1180
1181 char *now_s = NULL;
1182 const char *host_from = crm_element_value(stored_msg, F_CRM_HOST_FROM);
1183
1184 if (host_from == NULL) {
1185
1186 host_from = fsa_our_uname;
1187 }
1188
1189 crm_info("Creating shutdown request for %s (state=%s)", host_from, fsa_state2string(fsa_state));
1190 crm_log_xml_trace(stored_msg, "message");
1191
1192 now_s = pcmk__ttoa(time(NULL));
1193 update_attrd(host_from, XML_CIB_ATTR_SHUTDOWN, now_s, NULL, FALSE);
1194 free(now_s);
1195
1196
1197 return I_NULL;
1198 }
1199
1200
1201 extern gboolean process_te_message(xmlNode * msg, xmlNode * xml_data);
1202
1203 static void
1204 send_msg_via_ipc(xmlNode * msg, const char *sys)
1205 {
1206 pcmk__client_t *client_channel = pcmk__find_client_by_id(sys);
1207
1208 if (crm_element_value(msg, F_CRM_HOST_FROM) == NULL) {
1209 crm_xml_add(msg, F_CRM_HOST_FROM, fsa_our_uname);
1210 }
1211
1212 if (client_channel != NULL) {
1213
1214 pcmk__ipc_send_xml(client_channel, 0, msg, crm_ipc_server_event);
1215
1216 } else if (sys != NULL && strcmp(sys, CRM_SYSTEM_TENGINE) == 0) {
1217 xmlNode *data = get_message_xml(msg, F_CRM_DATA);
1218
1219 process_te_message(msg, data);
1220
1221 } else if (sys != NULL && strcmp(sys, CRM_SYSTEM_LRMD) == 0) {
1222 fsa_data_t fsa_data;
1223 ha_msg_input_t fsa_input;
1224
1225 fsa_input.msg = msg;
1226 fsa_input.xml = get_message_xml(msg, F_CRM_DATA);
1227
1228 fsa_data.id = 0;
1229 fsa_data.actions = 0;
1230 fsa_data.data = &fsa_input;
1231 fsa_data.fsa_input = I_MESSAGE;
1232 fsa_data.fsa_cause = C_IPC_MESSAGE;
1233 fsa_data.origin = __func__;
1234 fsa_data.data_type = fsa_dt_ha_msg;
1235
1236 do_lrm_invoke(A_LRM_INVOKE, C_IPC_MESSAGE, fsa_state, I_MESSAGE, &fsa_data);
1237
1238 } else if (sys != NULL && crmd_is_proxy_session(sys)) {
1239 crmd_proxy_send(sys, msg);
1240
1241 } else {
1242 crm_debug("Unknown Sub-system (%s)... discarding message.", crm_str(sys));
1243 }
1244 }
1245
1246 void
1247 delete_ha_msg_input(ha_msg_input_t * orig)
1248 {
1249 if (orig == NULL) {
1250 return;
1251 }
1252 free_xml(orig->msg);
1253 free(orig);
1254 }
1255
1256
1257
1258
1259
1260
1261
1262
1263 void
1264 send_remote_state_message(const char *node_name, gboolean node_up)
1265 {
1266
1267
1268
1269
1270 if (fsa_our_dc) {
1271 xmlNode *msg = create_request(CRM_OP_REMOTE_STATE, NULL, fsa_our_dc,
1272 CRM_SYSTEM_DC, CRM_SYSTEM_CRMD, NULL);
1273
1274 crm_info("Notifying DC %s of Pacemaker Remote node %s %s",
1275 fsa_our_dc, node_name, (node_up? "coming up" : "going down"));
1276 crm_xml_add(msg, XML_ATTR_ID, node_name);
1277 pcmk__xe_set_bool_attr(msg, XML_NODE_IN_CLUSTER, node_up);
1278 send_cluster_message(crm_get_peer(0, fsa_our_dc), crm_msg_crmd, msg,
1279 TRUE);
1280 free_xml(msg);
1281 } else {
1282 crm_debug("No DC to notify of Pacemaker Remote node %s %s",
1283 node_name, (node_up? "coming up" : "going down"));
1284 }
1285 }
1286