1
2
3
4
5
6
7
8
9
10 #ifndef CRMD_FSA__H
11 # define CRMD_FSA__H
12
13 # include <crm/crm.h>
14 # include <crm/cib.h>
15 # include <crm/common/xml.h>
16 # include <crm/common/mainloop.h>
17 # include <crm/cluster.h>
18 # include <crm/cluster/election_internal.h>
19 # include <crm/common/ipc_internal.h>
20
21
22 enum crmd_fsa_state {
23 S_IDLE = 0,
24
25 S_ELECTION,
26
27
28 S_INTEGRATION,
29
30
31
32
33 S_FINALIZE_JOIN,
34
35
36
37
38 S_NOT_DC,
39 S_POLICY_ENGINE,
40 S_RECOVERY,
41
42
43
44 S_RELEASE_DC,
45
46
47
48
49
50
51 S_STARTING,
52 S_PENDING,
53 S_STOPPING,
54 S_TERMINATE,
55
56
57
58
59 S_TRANSITION_ENGINE,
60
61
62
63 S_HALT,
64
65
66
67
68
69 S_ILLEGAL
70
71 };
72
73 # define MAXSTATE S_ILLEGAL
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135 enum crmd_fsa_input {
136
137 I_NULL,
138
139
140 I_CIB_OP,
141 I_CIB_UPDATE,
142 I_DC_TIMEOUT,
143 I_ELECTION,
144 I_PE_CALC,
145 I_RELEASE_DC,
146
147
148 I_ELECTION_DC,
149
150
151 I_ERROR,
152
153
154
155
156
157 I_FAIL,
158 I_INTEGRATED,
159 I_FINALIZED,
160 I_NODE_JOIN,
161 I_NOT_DC,
162
163
164 I_RECOVERED,
165 I_RELEASE_FAIL,
166
167 I_RELEASE_SUCCESS,
168 I_RESTART,
169
170
171 I_TE_SUCCESS,
172
173
174
175 I_ROUTER,
176
177
178 I_SHUTDOWN,
179 I_STOP,
180 I_TERMINATE,
181 I_STARTUP,
182 I_PE_SUCCESS,
183
184 I_JOIN_OFFER,
185 I_JOIN_REQUEST,
186 I_JOIN_RESULT,
187
188
189
190 I_WAIT_FOR_EVENT,
191
192
193
194 I_DC_HEARTBEAT,
195
196 I_LRM_EVENT,
197
198
199 I_PENDING,
200 I_HALT,
201
202
203 I_ILLEGAL
204
205 };
206
207 # define MAXINPUT I_ILLEGAL
208
209 # define I_MESSAGE I_ROUTER
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225 # define A_NOTHING 0x0000000000000000ULL
226
227
228
229
230
231 # define A_STARTUP 0x0000000000000001ULL
232
233
234
235 # define A_STARTED 0x0000000000000002ULL
236
237 # define A_HA_CONNECT 0x0000000000000004ULL
238 # define A_HA_DISCONNECT 0x0000000000000008ULL
239
240 # define A_INTEGRATE_TIMER_START 0x0000000000000010ULL
241 # define A_INTEGRATE_TIMER_STOP 0x0000000000000020ULL
242 # define A_FINALIZE_TIMER_START 0x0000000000000040ULL
243 # define A_FINALIZE_TIMER_STOP 0x0000000000000080ULL
244
245
246 # define A_DC_TIMER_START 0x0000000000000100ULL
247 # define A_DC_TIMER_STOP 0x0000000000000200ULL
248 # define A_ELECTION_COUNT 0x0000000000000400ULL
249 # define A_ELECTION_VOTE 0x0000000000000800ULL
250
251 # define A_ELECTION_START 0x0000000000001000ULL
252
253
254
255 # define A_MSG_PROCESS 0x0000000000002000ULL
256
257 # define A_MSG_ROUTE 0x0000000000004000ULL
258
259
260 # define A_DC_JOIN_OFFER_ONE 0x0000000000008000ULL
261
262
263
264 # define A_DC_JOIN_OFFER_ALL 0x0000000000010000ULL
265
266 # define A_DC_JOIN_PROCESS_REQ 0x0000000000020000ULL
267
268 # define A_DC_JOIN_FINALIZE 0x0000000000040000ULL
269
270 # define A_DC_JOIN_PROCESS_ACK 0x0000000000080000ULL
271
272
273 # define A_CL_JOIN_QUERY 0x0000000000100000ULL
274 # define A_CL_JOIN_ANNOUNCE 0x0000000000200000ULL
275
276 # define A_CL_JOIN_REQUEST 0x0000000000400000ULL
277
278 # define A_CL_JOIN_RESULT 0x0000000000800000ULL
279
280
281
282 # define A_RECOVER 0x0000000001000000ULL
283
284
285
286
287 # define A_DC_RELEASE 0x0000000002000000ULL
288
289 # define A_DC_RELEASED 0x0000000004000000ULL
290
291
292
293
294 # define A_DC_TAKEOVER 0x0000000008000000ULL
295
296
297 # define A_SHUTDOWN 0x0000000010000000ULL
298 # define A_STOP 0x0000000020000000ULL
299 # define A_EXIT_0 0x0000000040000000ULL
300 # define A_EXIT_1 0x0000000080000000ULL
301
302 # define A_SHUTDOWN_REQ 0x0000000100000000ULL
303 # define A_ELECTION_CHECK 0x0000000200000000ULL
304 # define A_DC_JOIN_FINAL 0x0000000400000000ULL
305
306
307 # define A_CIB_START 0x0000020000000000ULL
308 # define A_CIB_STOP 0x0000040000000000ULL
309
310
311
312
313
314
315
316
317
318
319 # define A_TE_INVOKE 0x0000100000000000ULL
320 # define A_TE_START 0x0000200000000000ULL
321 # define A_TE_STOP 0x0000400000000000ULL
322 # define A_TE_CANCEL 0x0000800000000000ULL
323 # define A_TE_HALT 0x0001000000000000ULL
324
325
326
327
328
329 # define A_PE_INVOKE 0x0002000000000000ULL
330 # define A_PE_START 0x0004000000000000ULL
331 # define A_PE_STOP 0x0008000000000000ULL
332
333
334
335
336
337 # define A_NODE_BLOCK 0x0010000000000000ULL
338
339 # define A_UPDATE_NODESTATUS 0x0020000000000000ULL
340 # define A_READCONFIG 0x0080000000000000ULL
341
342
343
344 # define A_LRM_CONNECT 0x0100000000000000ULL
345
346 # define A_LRM_DISCONNECT 0x0200000000000000ULL
347 # define A_LRM_INVOKE 0x0400000000000000ULL
348 # define A_LRM_EVENT 0x0800000000000000ULL
349
350
351 # define A_LOG 0x1000000000000000ULL
352 # define A_ERROR 0x2000000000000000ULL
353 # define A_WARN 0x4000000000000000ULL
354
355 # define O_EXIT (A_SHUTDOWN|A_STOP|A_LRM_DISCONNECT|A_HA_DISCONNECT|A_EXIT_0|A_CIB_STOP)
356 # define O_RELEASE (A_DC_TIMER_STOP|A_DC_RELEASE|A_PE_STOP|A_TE_STOP|A_DC_RELEASED)
357 # define O_PE_RESTART (A_PE_START|A_PE_STOP)
358 # define O_TE_RESTART (A_TE_START|A_TE_STOP)
359 # define O_CIB_RESTART (A_CIB_START|A_CIB_STOP)
360 # define O_LRM_RECONNECT (A_LRM_CONNECT|A_LRM_DISCONNECT)
361 # define O_DC_TIMER_RESTART (A_DC_TIMER_STOP|A_DC_TIMER_START)
362
363
364
365
366
367
368
369
370
371 # define R_THE_DC 0x00000001ULL
372
373 # define R_STARTING 0x00000002ULL
374
375 # define R_SHUTDOWN 0x00000004ULL
376
377 # define R_STAYDOWN 0x00000008ULL
378
379
380 # define R_JOIN_OK 0x00000010ULL
381 # define R_READ_CONFIG 0x00000040ULL
382 # define R_INVOKE_PE 0x00000080ULL
383
384 # define R_CIB_CONNECTED 0x00000100ULL
385
386 # define R_PE_CONNECTED 0x00000200ULL
387 # define R_TE_CONNECTED 0x00000400ULL
388
389 # define R_LRM_CONNECTED 0x00000800ULL
390
391 # define R_CIB_REQUIRED 0x00001000ULL
392
393 # define R_PE_REQUIRED 0x00002000ULL
394 # define R_TE_REQUIRED 0x00004000ULL
395
396 # define R_ST_REQUIRED 0x00008000ULL
397
398
399 # define R_CIB_DONE 0x00010000ULL
400
401 # define R_HAVE_CIB 0x00020000ULL
402 # define R_CIB_ASKED 0x00040000ULL
403
404 # define R_MEMBERSHIP 0x00100000ULL
405 # define R_PEER_DATA 0x00200000ULL
406
407 # define R_HA_DISCONNECTED 0x00400000ULL
408
409 # define R_REQ_PEND 0x01000000ULL
410
411
412 # define R_PE_PEND 0x02000000ULL
413 # define R_TE_PEND 0x04000000ULL
414
415
416 # define R_RESP_PEND 0x08000000ULL
417
418
419
420
421 # define R_IN_TRANSITION 0x10000000ULL
422
423 # define R_SENT_RSC_STOP 0x20000000ULL
424
425
426
427 # define R_IN_RECOVERY 0x80000000ULL
428
429 #define CRM_DIRECT_NACK_RC (99)
430
431 enum crmd_fsa_cause {
432 C_UNKNOWN = 0,
433 C_STARTUP,
434 C_IPC_MESSAGE,
435 C_HA_MESSAGE,
436 C_CRMD_STATUS_CALLBACK,
437 C_LRM_OP_CALLBACK,
438 C_TIMER_POPPED,
439 C_SHUTDOWN,
440 C_FSA_INTERNAL,
441 };
442
443 enum fsa_data_type {
444 fsa_dt_none,
445 fsa_dt_ha_msg,
446 fsa_dt_xml,
447 fsa_dt_lrm,
448 };
449
450 typedef struct fsa_data_s fsa_data_t;
451 struct fsa_data_s {
452 int id;
453 enum crmd_fsa_input fsa_input;
454 enum crmd_fsa_cause fsa_cause;
455 uint64_t actions;
456 const char *origin;
457 void *data;
458 enum fsa_data_type data_type;
459 };
460
461
462 extern gboolean do_fsa_stall;
463 extern enum crmd_fsa_state fsa_state;
464 extern uint64_t fsa_input_register;
465 extern uint64_t fsa_actions;
466
467 #define controld_set_fsa_input_flags(flags_to_set) do { \
468 fsa_input_register = pcmk__set_flags_as(__func__, __LINE__, \
469 LOG_TRACE, \
470 "FSA input", "controller", \
471 fsa_input_register, \
472 (flags_to_set), \
473 #flags_to_set); \
474 } while (0)
475
476 #define controld_clear_fsa_input_flags(flags_to_clear) do { \
477 fsa_input_register = pcmk__clear_flags_as(__func__, __LINE__, \
478 LOG_TRACE, \
479 "FSA input", "controller",\
480 fsa_input_register, \
481 (flags_to_clear), \
482 #flags_to_clear); \
483 } while (0)
484
485 #define controld_set_fsa_action_flags(flags_to_set) do { \
486 fsa_actions = pcmk__set_flags_as(__func__, __LINE__, \
487 LOG_DEBUG, \
488 "FSA action", "controller", \
489 fsa_actions, (flags_to_set), \
490 #flags_to_set); \
491 } while (0)
492
493 #define controld_clear_fsa_action_flags(flags_to_clear) do { \
494 fsa_actions = pcmk__clear_flags_as(__func__, __LINE__, \
495 LOG_DEBUG, \
496 "FSA action", "controller", \
497 fsa_actions, (flags_to_clear), \
498 #flags_to_clear); \
499 } while (0)
500
501 extern cib_t *fsa_cib_conn;
502
503 extern char *fsa_our_uname;
504 extern char *fsa_our_uuid;
505 extern char *fsa_pe_ref;
506 extern char *fsa_our_dc;
507 extern char *fsa_our_dc_version;
508 extern GList *fsa_message_queue;
509
510 extern char *fsa_cluster_name;
511
512 extern crm_trigger_t *fsa_source;
513 extern crm_trigger_t *config_read;
514
515 extern unsigned long long saved_ccm_membership_id;
516 extern gboolean ever_had_quorum;
517
518
519 void do_update_cib_nodes(gboolean overwrite, const char *caller);
520 int crmd_cib_smart_opt(void);
521 xmlNode *controld_query_executor_state(void);
522
523 const char *fsa_input2string(enum crmd_fsa_input input);
524 const char *fsa_state2string(enum crmd_fsa_state state);
525 const char *fsa_cause2string(enum crmd_fsa_cause cause);
526 const char *fsa_action2string(long long action);
527
528 enum crmd_fsa_state s_crmd_fsa(enum crmd_fsa_cause cause);
529
530 # define AM_I_DC pcmk_is_set(fsa_input_register, R_THE_DC)
531 # define AM_I_OPERATIONAL !pcmk_is_set(fsa_input_register, R_STARTING)
532 # define trigger_fsa() do { \
533 if (fsa_source != NULL) { \
534 crm_trace("Triggering FSA"); \
535 mainloop_set_trigger(fsa_source); \
536 } \
537 } while(0)
538
539
540 void do_read_config(long long action, enum crmd_fsa_cause cause,
541 enum crmd_fsa_state cur_state,
542 enum crmd_fsa_input current_input, fsa_data_t *msg_data);
543
544
545 void do_pe_invoke(long long action, enum crmd_fsa_cause cause,
546 enum crmd_fsa_state cur_state,
547 enum crmd_fsa_input current_input, fsa_data_t *msg_data);
548
549
550 void do_log(long long action, enum crmd_fsa_cause cause,
551 enum crmd_fsa_state cur_state,
552 enum crmd_fsa_input cur_input, fsa_data_t *msg_data);
553
554
555 void do_startup(long long action, enum crmd_fsa_cause cause,
556 enum crmd_fsa_state cur_state,
557 enum crmd_fsa_input cur_input, fsa_data_t *msg_data);
558
559
560 void do_cib_control(long long action, enum crmd_fsa_cause cause,
561 enum crmd_fsa_state cur_state,
562 enum crmd_fsa_input cur_input, fsa_data_t *msg_data);
563
564
565 void do_ha_control(long long action, enum crmd_fsa_cause cause,
566 enum crmd_fsa_state cur_state,
567 enum crmd_fsa_input cur_input, fsa_data_t *msg_data);
568
569
570 void do_lrm_control(long long action, enum crmd_fsa_cause cause,
571 enum crmd_fsa_state cur_state,
572 enum crmd_fsa_input cur_input, fsa_data_t *msg_data);
573
574
575 void do_pe_control(long long action, enum crmd_fsa_cause cause,
576 enum crmd_fsa_state cur_state,
577 enum crmd_fsa_input cur_input, fsa_data_t *msg_data);
578
579
580 void do_te_control(long long action, enum crmd_fsa_cause cause,
581 enum crmd_fsa_state cur_state,
582 enum crmd_fsa_input cur_input, fsa_data_t *msg_data);
583
584
585 void do_started(long long action, enum crmd_fsa_cause cause,
586 enum crmd_fsa_state cur_state,
587 enum crmd_fsa_input cur_input, fsa_data_t *msg_data);
588
589
590 void do_msg_route(long long action, enum crmd_fsa_cause cause,
591 enum crmd_fsa_state cur_state,
592 enum crmd_fsa_input cur_input, fsa_data_t *msg_data);
593
594
595 void do_recover(long long action, enum crmd_fsa_cause cause,
596 enum crmd_fsa_state cur_state,
597 enum crmd_fsa_input cur_input, fsa_data_t *msg_data);
598
599
600 void do_election_vote(long long action, enum crmd_fsa_cause cause,
601 enum crmd_fsa_state cur_state,
602 enum crmd_fsa_input cur_input, fsa_data_t *msg_data);
603
604
605 void do_election_count_vote(long long action, enum crmd_fsa_cause cause,
606 enum crmd_fsa_state cur_state,
607 enum crmd_fsa_input cur_input,
608 fsa_data_t *msg_data);
609
610
611 void do_election_check(long long action, enum crmd_fsa_cause cause,
612 enum crmd_fsa_state cur_state,
613 enum crmd_fsa_input cur_input, fsa_data_t *msg_data);
614
615
616 void do_timer_control(long long action, enum crmd_fsa_cause cause,
617 enum crmd_fsa_state cur_state,
618 enum crmd_fsa_input cur_input, fsa_data_t *msg_data);
619
620
621 void do_dc_takeover(long long action, enum crmd_fsa_cause cause,
622 enum crmd_fsa_state cur_state,
623 enum crmd_fsa_input cur_input, fsa_data_t *msg_data);
624
625
626 void do_dc_release(long long action, enum crmd_fsa_cause cause,
627 enum crmd_fsa_state cur_state,
628 enum crmd_fsa_input cur_input, fsa_data_t *msg_data);
629
630
631 void do_dc_join_offer_all(long long action, enum crmd_fsa_cause cause,
632 enum crmd_fsa_state cur_state,
633 enum crmd_fsa_input cur_input, fsa_data_t *msg_data);
634
635
636 void do_dc_join_offer_one(long long action, enum crmd_fsa_cause cause,
637 enum crmd_fsa_state cur_state,
638 enum crmd_fsa_input cur_input, fsa_data_t *msg_data);
639
640
641 void do_dc_join_ack(long long action, enum crmd_fsa_cause cause,
642 enum crmd_fsa_state cur_state,
643 enum crmd_fsa_input cur_input, fsa_data_t *msg_data);
644
645
646 void do_dc_join_filter_offer(long long action, enum crmd_fsa_cause cause,
647 enum crmd_fsa_state cur_state,
648 enum crmd_fsa_input cur_input,
649 fsa_data_t *msg_data);
650
651
652 void do_dc_join_finalize(long long action, enum crmd_fsa_cause cause,
653 enum crmd_fsa_state cur_state,
654 enum crmd_fsa_input cur_input, fsa_data_t *msg_data);
655
656
657
658 void do_cl_join_query(long long action, enum crmd_fsa_cause cause,
659 enum crmd_fsa_state cur_state,
660 enum crmd_fsa_input current_input, fsa_data_t *msg_data);
661
662
663 void do_cl_join_announce(long long action, enum crmd_fsa_cause cause,
664 enum crmd_fsa_state cur_state,
665 enum crmd_fsa_input current_input, fsa_data_t *msg_data);
666
667
668 void do_cl_join_offer_respond(long long action, enum crmd_fsa_cause cause,
669 enum crmd_fsa_state cur_state,
670 enum crmd_fsa_input current_input,
671 fsa_data_t *msg_data);
672
673
674 void do_cl_join_finalize_respond(long long action, enum crmd_fsa_cause cause,
675 enum crmd_fsa_state cur_state,
676 enum crmd_fsa_input current_input,
677 fsa_data_t *msg_data);
678
679
680 void do_lrm_invoke(long long action, enum crmd_fsa_cause cause,
681 enum crmd_fsa_state cur_state,
682 enum crmd_fsa_input cur_input, fsa_data_t *msg_data);
683
684
685 void do_lrm_event(long long action, enum crmd_fsa_cause cause,
686 enum crmd_fsa_state cur_state,
687 enum crmd_fsa_input cur_input, fsa_data_t *msg_data);
688
689
690 void do_te_invoke(long long action, enum crmd_fsa_cause cause,
691 enum crmd_fsa_state cur_state,
692 enum crmd_fsa_input cur_input, fsa_data_t *msg_data);
693
694
695 void do_shutdown_req(long long action, enum crmd_fsa_cause cause,
696 enum crmd_fsa_state cur_state,
697 enum crmd_fsa_input cur_input, fsa_data_t *msg_data);
698
699
700 void do_shutdown(long long action, enum crmd_fsa_cause cause,
701 enum crmd_fsa_state cur_state,
702 enum crmd_fsa_input cur_input, fsa_data_t *msg_data);
703
704
705 void do_stop(long long action, enum crmd_fsa_cause cause,
706 enum crmd_fsa_state cur_state,
707 enum crmd_fsa_input cur_input, fsa_data_t *msg_data);
708
709
710 void do_exit(long long action, enum crmd_fsa_cause cause,
711 enum crmd_fsa_state cur_state,
712 enum crmd_fsa_input cur_input, fsa_data_t *msg_data);
713
714
715 void do_dc_join_final(long long action, enum crmd_fsa_cause cause,
716 enum crmd_fsa_state cur_state,
717 enum crmd_fsa_input current_input, fsa_data_t *msg_data);
718 #endif