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 int is_for_dc = 0;
330 int is_for_dcib = 0;
331 int is_for_te = 0;
332 int is_for_crm = 0;
333 int is_for_cib = 0;
334 int is_local = 0;
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 = 0;
374 if (pcmk__str_empty(host_to)) {
375 if (is_for_dc || is_for_te) {
376 is_local = 0;
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 = 1;
387 } else {
388 is_local = !originated_locally;
389 }
390
391 } else {
392 is_local = 1;
393 }
394
395 } else if (pcmk__str_eq(fsa_our_uname, host_to, pcmk__str_casei)) {
396 is_local = 1;
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 = 1;
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 const char *remote_is_up = crm_element_value(msg, XML_NODE_IN_CLUSTER);
726 crm_node_t *remote_peer;
727
728 CRM_CHECK(remote_uname && remote_is_up, return I_NULL);
729
730 remote_peer = crm_remote_peer_get(remote_uname);
731 CRM_CHECK(remote_peer, return I_NULL);
732
733 pcmk__update_peer_state(__func__, remote_peer,
734 crm_is_true(remote_is_up)? CRM_NODE_MEMBER : CRM_NODE_LOST,
735 0);
736 return I_NULL;
737 }
738
739
740
741
742
743
744
745
746 static enum crmd_fsa_input
747 handle_ping(xmlNode *msg)
748 {
749 const char *value = NULL;
750 xmlNode *ping = NULL;
751
752
753
754 ping = create_xml_node(NULL, XML_CRM_TAG_PING);
755 value = crm_element_value(msg, F_CRM_SYS_TO);
756 crm_xml_add(ping, XML_PING_ATTR_SYSFROM, value);
757
758
759 value = fsa_state2string(fsa_state);
760 crm_xml_add(ping, XML_PING_ATTR_CRMDSTATE, value);
761 crm_notice("Current ping state: %s", value);
762
763
764
765 crm_xml_add(ping, XML_PING_ATTR_STATUS, "ok");
766
767
768 msg = create_reply(msg, ping);
769 free_xml(ping);
770 if (msg) {
771 (void) relay_message(msg, TRUE);
772 free_xml(msg);
773 }
774
775
776 return I_NULL;
777 }
778
779
780
781
782
783
784 static enum crmd_fsa_input
785 handle_node_list(xmlNode *request)
786 {
787 GHashTableIter iter;
788 crm_node_t *node = NULL;
789 xmlNode *reply = NULL;
790 xmlNode *reply_data = NULL;
791
792
793 reply_data = create_xml_node(NULL, XML_CIB_TAG_NODES);
794 g_hash_table_iter_init(&iter, crm_peer_cache);
795 while (g_hash_table_iter_next(&iter, NULL, (gpointer *) & node)) {
796 xmlNode *xml = create_xml_node(reply_data, XML_CIB_TAG_NODE);
797
798 crm_xml_add_ll(xml, XML_ATTR_ID, (long long) node->id);
799 crm_xml_add(xml, XML_ATTR_UNAME, node->uname);
800 crm_xml_add(xml, XML_NODE_IN_CLUSTER, node->state);
801 }
802
803
804 reply = create_reply(request, reply_data);
805 free_xml(reply_data);
806 if (reply) {
807 (void) relay_message(reply, TRUE);
808 free_xml(reply);
809 }
810
811
812 return I_NULL;
813 }
814
815
816
817
818
819
820
821
822 static enum crmd_fsa_input
823 handle_node_info_request(xmlNode *msg)
824 {
825 const char *value = NULL;
826 crm_node_t *node = NULL;
827 int node_id = 0;
828 xmlNode *reply = NULL;
829
830
831
832 reply = create_xml_node(NULL, XML_CIB_TAG_NODE);
833 crm_xml_add(reply, XML_PING_ATTR_SYSFROM, CRM_SYSTEM_CRMD);
834
835
836 crm_xml_add_boolean(reply, XML_ATTR_HAVE_QUORUM, fsa_has_quorum);
837
838
839 crm_element_value_int(msg, XML_ATTR_ID, &node_id);
840 if (node_id < 0) {
841 node_id = 0;
842 }
843 value = crm_element_value(msg, XML_ATTR_UNAME);
844
845
846 if ((node_id == 0) && (value == NULL)) {
847 value = fsa_our_uname;
848 }
849
850 node = pcmk__search_node_caches(node_id, value, CRM_GET_PEER_ANY);
851 if (node) {
852 crm_xml_add_int(reply, XML_ATTR_ID, node->id);
853 crm_xml_add(reply, XML_ATTR_UUID, node->uuid);
854 crm_xml_add(reply, XML_ATTR_UNAME, node->uname);
855 crm_xml_add(reply, XML_NODE_IS_PEER, node->state);
856 crm_xml_add_boolean(reply, XML_NODE_IS_REMOTE,
857 node->flags & crm_remote_node);
858 }
859
860
861 msg = create_reply(msg, reply);
862 free_xml(reply);
863 if (msg) {
864 (void) relay_message(msg, TRUE);
865 free_xml(msg);
866 }
867
868
869 return I_NULL;
870 }
871
872 static void
873 verify_feature_set(xmlNode *msg)
874 {
875 const char *dc_version = crm_element_value(msg, XML_ATTR_CRM_VERSION);
876
877 if (dc_version == NULL) {
878
879
880
881 dc_version = "3.0.14";
882 }
883
884 if (feature_set_compatible(dc_version, CRM_FEATURE_SET)) {
885 crm_trace("Local feature set (%s) is compatible with DC's (%s)",
886 CRM_FEATURE_SET, dc_version);
887 } else {
888 crm_err("Local feature set (%s) is incompatible with DC's (%s)",
889 CRM_FEATURE_SET, dc_version);
890
891
892 controld_set_fsa_input_flags(R_STAYDOWN);
893 crmd_exit(CRM_EX_FATAL);
894 }
895 }
896
897
898 static enum crmd_fsa_input
899 handle_shutdown_self_ack(xmlNode *stored_msg)
900 {
901 const char *host_from = crm_element_value(stored_msg, F_CRM_HOST_FROM);
902
903 if (pcmk_is_set(fsa_input_register, R_SHUTDOWN)) {
904
905 crm_info("Shutting down controller");
906 return I_STOP;
907 }
908
909 if (pcmk__str_eq(host_from, fsa_our_dc, pcmk__str_casei)) {
910
911 crm_err("Shutting down controller immediately due to "
912 "unexpected shutdown confirmation");
913 return I_TERMINATE;
914 }
915
916 if (fsa_state != S_STOPPING) {
917
918 crm_err("Starting new DC election because %s is "
919 "confirming shutdown we did not request",
920 (host_from? host_from : "another node"));
921 return I_ELECTION;
922 }
923
924
925 crm_debug("Ignoring unexpected shutdown confirmation from %s",
926 (host_from? host_from : "another node"));
927 return I_NULL;
928 }
929
930
931 static enum crmd_fsa_input
932 handle_shutdown_ack(xmlNode *stored_msg)
933 {
934 const char *host_from = crm_element_value(stored_msg, F_CRM_HOST_FROM);
935
936 if (host_from == NULL) {
937 crm_warn("Ignoring shutdown request without origin specified");
938 return I_NULL;
939 }
940
941 if ((fsa_our_dc == NULL) || (strcmp(host_from, fsa_our_dc) == 0)) {
942
943 if (pcmk_is_set(fsa_input_register, R_SHUTDOWN)) {
944 crm_info("Shutting down controller after confirmation from %s",
945 host_from);
946 } else {
947 crm_err("Shutting down controller after unexpected "
948 "shutdown request from %s", host_from);
949 controld_set_fsa_input_flags(R_STAYDOWN);
950 }
951 return I_STOP;
952 }
953
954 crm_warn("Ignoring shutdown request from %s because DC is %s",
955 host_from, fsa_our_dc);
956 return I_NULL;
957 }
958
959 static enum crmd_fsa_input
960 handle_request(xmlNode *stored_msg, enum crmd_fsa_cause cause)
961 {
962 xmlNode *msg = NULL;
963 const char *op = crm_element_value(stored_msg, F_CRM_TASK);
964
965
966
967 if (op == NULL) {
968 crm_log_xml_warn(stored_msg, "[request without " F_CRM_TASK "]");
969 return I_NULL;
970 }
971
972 if (strcmp(op, CRM_OP_SHUTDOWN_REQ) == 0) {
973 const char *from = crm_element_value(stored_msg, F_CRM_HOST_FROM);
974 crm_node_t *node = pcmk__search_cluster_node_cache(0, from);
975
976 pcmk__update_peer_expected(__func__, node, CRMD_JOINSTATE_DOWN);
977 if(AM_I_DC == FALSE) {
978 return I_NULL;
979 }
980 }
981
982
983 if (AM_I_DC) {
984 if (strcmp(op, CRM_OP_JOIN_ANNOUNCE) == 0) {
985 return I_NODE_JOIN;
986
987 } else if (strcmp(op, CRM_OP_JOIN_REQUEST) == 0) {
988 return I_JOIN_REQUEST;
989
990 } else if (strcmp(op, CRM_OP_JOIN_CONFIRM) == 0) {
991 return I_JOIN_RESULT;
992
993 } else if (strcmp(op, CRM_OP_SHUTDOWN) == 0) {
994 return handle_shutdown_self_ack(stored_msg);
995
996 } else if (strcmp(op, CRM_OP_SHUTDOWN_REQ) == 0) {
997
998 return handle_shutdown_request(stored_msg);
999
1000 } else if (strcmp(op, CRM_OP_REMOTE_STATE) == 0) {
1001
1002 return handle_remote_state(stored_msg);
1003 }
1004 }
1005
1006
1007 if (strcmp(op, CRM_OP_NOVOTE) == 0) {
1008 ha_msg_input_t fsa_input;
1009
1010 fsa_input.msg = stored_msg;
1011 register_fsa_input_adv(C_HA_MESSAGE, I_NULL, &fsa_input,
1012 A_ELECTION_COUNT | A_ELECTION_CHECK, FALSE,
1013 __func__);
1014
1015 } else if (strcmp(op, CRM_OP_THROTTLE) == 0) {
1016 throttle_update(stored_msg);
1017 if (AM_I_DC && transition_graph != NULL) {
1018 if (transition_graph->complete == FALSE) {
1019 crm_debug("The throttle changed. Trigger a graph.");
1020 trigger_graph();
1021 }
1022 }
1023 return I_NULL;
1024
1025 } else if (strcmp(op, CRM_OP_CLEAR_FAILCOUNT) == 0) {
1026 return handle_failcount_op(stored_msg);
1027
1028 } else if (strcmp(op, CRM_OP_VOTE) == 0) {
1029
1030 ha_msg_input_t fsa_input;
1031
1032 fsa_input.msg = stored_msg;
1033 register_fsa_input_adv(C_HA_MESSAGE, I_NULL, &fsa_input,
1034 A_ELECTION_COUNT | A_ELECTION_CHECK, FALSE,
1035 __func__);
1036
1037
1038 if (fsa_state == S_HALT) {
1039 crm_debug("Forcing an election from S_HALT");
1040 return I_ELECTION;
1041 #if 0
1042 } else if (AM_I_DC) {
1043
1044 return I_ELECTION;
1045 #endif
1046 }
1047
1048 } else if (strcmp(op, CRM_OP_JOIN_OFFER) == 0) {
1049 verify_feature_set(stored_msg);
1050 crm_debug("Raising I_JOIN_OFFER: join-%s", crm_element_value(stored_msg, F_CRM_JOIN_ID));
1051 return I_JOIN_OFFER;
1052
1053 } else if (strcmp(op, CRM_OP_JOIN_ACKNAK) == 0) {
1054 crm_debug("Raising I_JOIN_RESULT: join-%s", crm_element_value(stored_msg, F_CRM_JOIN_ID));
1055 return I_JOIN_RESULT;
1056
1057 } else if (strcmp(op, CRM_OP_LRM_DELETE) == 0) {
1058 return handle_lrm_delete(stored_msg);
1059
1060 } else if ((strcmp(op, CRM_OP_LRM_FAIL) == 0)
1061 || (strcmp(op, CRM_OP_LRM_REFRESH) == 0)
1062 || (strcmp(op, CRM_OP_REPROBE) == 0)) {
1063
1064 crm_xml_add(stored_msg, F_CRM_SYS_TO, CRM_SYSTEM_LRMD);
1065 return I_ROUTER;
1066
1067 } else if (strcmp(op, CRM_OP_NOOP) == 0) {
1068 return I_NULL;
1069
1070 } else if (strcmp(op, CRM_OP_LOCAL_SHUTDOWN) == 0) {
1071
1072 crm_shutdown(SIGTERM);
1073
1074 return I_NULL;
1075
1076 } else if (strcmp(op, CRM_OP_PING) == 0) {
1077 return handle_ping(stored_msg);
1078
1079 } else if (strcmp(op, CRM_OP_NODE_INFO) == 0) {
1080 return handle_node_info_request(stored_msg);
1081
1082 } else if (strcmp(op, CRM_OP_RM_NODE_CACHE) == 0) {
1083 int id = 0;
1084 const char *name = NULL;
1085
1086 crm_element_value_int(stored_msg, XML_ATTR_ID, &id);
1087 name = crm_element_value(stored_msg, XML_ATTR_UNAME);
1088
1089 if(cause == C_IPC_MESSAGE) {
1090 msg = create_request(CRM_OP_RM_NODE_CACHE, NULL, NULL, CRM_SYSTEM_CRMD, CRM_SYSTEM_CRMD, NULL);
1091 if (send_cluster_message(NULL, crm_msg_crmd, msg, TRUE) == FALSE) {
1092 crm_err("Could not instruct peers to remove references to node %s/%u", name, id);
1093 } else {
1094 crm_notice("Instructing peers to remove references to node %s/%u", name, id);
1095 }
1096 free_xml(msg);
1097
1098 } else {
1099 reap_crm_member(id, name);
1100
1101
1102
1103
1104
1105 st_fail_count_reset(name);
1106 }
1107
1108 } else if (strcmp(op, CRM_OP_MAINTENANCE_NODES) == 0) {
1109 xmlNode *xml = get_message_xml(stored_msg, F_CRM_DATA);
1110
1111 remote_ra_process_maintenance_nodes(xml);
1112
1113 } else if (strcmp(op, PCMK__CONTROLD_CMD_NODES) == 0) {
1114 return handle_node_list(stored_msg);
1115
1116
1117 } else if (!AM_I_DC) {
1118
1119 if (strcmp(op, CRM_OP_SHUTDOWN) == 0) {
1120 return handle_shutdown_ack(stored_msg);
1121 }
1122
1123 } else {
1124 crm_err("Unexpected request (%s) sent to %s", op, AM_I_DC ? "the DC" : "non-DC node");
1125 crm_log_xml_err(stored_msg, "Unexpected");
1126 }
1127
1128 return I_NULL;
1129 }
1130
1131 static void
1132 handle_response(xmlNode *stored_msg)
1133 {
1134 const char *op = crm_element_value(stored_msg, F_CRM_TASK);
1135
1136 if (op == NULL) {
1137 crm_log_xml_err(stored_msg, "Bad message");
1138
1139 } else if (AM_I_DC && strcmp(op, CRM_OP_PECALC) == 0) {
1140
1141 const char *msg_ref = crm_element_value(stored_msg, XML_ATTR_REFERENCE);
1142
1143 if (msg_ref == NULL) {
1144 crm_err("%s - Ignoring calculation with no reference", op);
1145
1146 } else if (pcmk__str_eq(msg_ref, fsa_pe_ref, pcmk__str_casei)) {
1147 ha_msg_input_t fsa_input;
1148
1149 controld_stop_sched_timer();
1150 fsa_input.msg = stored_msg;
1151 register_fsa_input_later(C_IPC_MESSAGE, I_PE_SUCCESS, &fsa_input);
1152
1153 } else {
1154 crm_info("%s calculation %s is obsolete", op, msg_ref);
1155 }
1156
1157 } else if (strcmp(op, CRM_OP_VOTE) == 0
1158 || strcmp(op, CRM_OP_SHUTDOWN_REQ) == 0 || strcmp(op, CRM_OP_SHUTDOWN) == 0) {
1159
1160 } else {
1161 const char *host_from = crm_element_value(stored_msg, F_CRM_HOST_FROM);
1162
1163 crm_err("Unexpected response (op=%s, src=%s) sent to the %s",
1164 op, host_from, AM_I_DC ? "DC" : "controller");
1165 }
1166 }
1167
1168 static enum crmd_fsa_input
1169 handle_shutdown_request(xmlNode * stored_msg)
1170 {
1171
1172
1173
1174
1175
1176
1177
1178 char *now_s = NULL;
1179 const char *host_from = crm_element_value(stored_msg, F_CRM_HOST_FROM);
1180
1181 if (host_from == NULL) {
1182
1183 host_from = fsa_our_uname;
1184 }
1185
1186 crm_info("Creating shutdown request for %s (state=%s)", host_from, fsa_state2string(fsa_state));
1187 crm_log_xml_trace(stored_msg, "message");
1188
1189 now_s = pcmk__ttoa(time(NULL));
1190 update_attrd(host_from, XML_CIB_ATTR_SHUTDOWN, now_s, NULL, FALSE);
1191 free(now_s);
1192
1193
1194 return I_NULL;
1195 }
1196
1197
1198 extern gboolean process_te_message(xmlNode * msg, xmlNode * xml_data);
1199
1200 static void
1201 send_msg_via_ipc(xmlNode * msg, const char *sys)
1202 {
1203 pcmk__client_t *client_channel = pcmk__find_client_by_id(sys);
1204
1205 if (crm_element_value(msg, F_CRM_HOST_FROM) == NULL) {
1206 crm_xml_add(msg, F_CRM_HOST_FROM, fsa_our_uname);
1207 }
1208
1209 if (client_channel != NULL) {
1210
1211 pcmk__ipc_send_xml(client_channel, 0, msg, crm_ipc_server_event);
1212
1213 } else if (sys != NULL && strcmp(sys, CRM_SYSTEM_TENGINE) == 0) {
1214 xmlNode *data = get_message_xml(msg, F_CRM_DATA);
1215
1216 process_te_message(msg, data);
1217
1218 } else if (sys != NULL && strcmp(sys, CRM_SYSTEM_LRMD) == 0) {
1219 fsa_data_t fsa_data;
1220 ha_msg_input_t fsa_input;
1221
1222 fsa_input.msg = msg;
1223 fsa_input.xml = get_message_xml(msg, F_CRM_DATA);
1224
1225 fsa_data.id = 0;
1226 fsa_data.actions = 0;
1227 fsa_data.data = &fsa_input;
1228 fsa_data.fsa_input = I_MESSAGE;
1229 fsa_data.fsa_cause = C_IPC_MESSAGE;
1230 fsa_data.origin = __func__;
1231 fsa_data.data_type = fsa_dt_ha_msg;
1232
1233 do_lrm_invoke(A_LRM_INVOKE, C_IPC_MESSAGE, fsa_state, I_MESSAGE, &fsa_data);
1234
1235 } else if (sys != NULL && crmd_is_proxy_session(sys)) {
1236 crmd_proxy_send(sys, msg);
1237
1238 } else {
1239 crm_debug("Unknown Sub-system (%s)... discarding message.", crm_str(sys));
1240 }
1241 }
1242
1243 void
1244 delete_ha_msg_input(ha_msg_input_t * orig)
1245 {
1246 if (orig == NULL) {
1247 return;
1248 }
1249 free_xml(orig->msg);
1250 free(orig);
1251 }
1252
1253
1254
1255
1256
1257
1258
1259
1260 void
1261 send_remote_state_message(const char *node_name, gboolean node_up)
1262 {
1263
1264
1265
1266
1267 if (fsa_our_dc) {
1268 xmlNode *msg = create_request(CRM_OP_REMOTE_STATE, NULL, fsa_our_dc,
1269 CRM_SYSTEM_DC, CRM_SYSTEM_CRMD, NULL);
1270
1271 crm_info("Notifying DC %s of pacemaker_remote node %s %s",
1272 fsa_our_dc, node_name, (node_up? "coming up" : "going down"));
1273 crm_xml_add(msg, XML_ATTR_ID, node_name);
1274 crm_xml_add_boolean(msg, XML_NODE_IN_CLUSTER, node_up);
1275 send_cluster_message(crm_get_peer(0, fsa_our_dc), crm_msg_crmd, msg,
1276 TRUE);
1277 free_xml(msg);
1278 } else {
1279 crm_debug("No DC to notify of pacemaker_remote node %s %s",
1280 node_name, (node_up? "coming up" : "going down"));
1281 }
1282 }
1283