pacemaker  2.1.6-802a72226b
Scalable High-Availability cluster resource manager
pcmk_sched_actions.c
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2023 the Pacemaker project contributors
3  *
4  * The version control history for this file may have further details.
5  *
6  * This source code is licensed under the GNU General Public License version 2
7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
8  */
9 
10 #include <crm_internal.h>
11 
12 #include <stdio.h>
13 #include <sys/param.h>
14 #include <glib.h>
15 
16 #include <crm/lrmd_internal.h>
17 #include <pacemaker-internal.h>
18 #include "libpacemaker_private.h"
19 
30 static enum pe_action_flags
31 action_flags_for_ordering(pe_action_t *action, const pe_node_t *node)
32 {
33  bool runnable = false;
35 
36  // For non-resource actions, return the action flags
37  if (action->rsc == NULL) {
38  return action->flags;
39  }
40 
41  /* For non-clone resources, or a clone action not assigned to a node,
42  * return the flags as determined by the resource method without a node
43  * specified.
44  */
45  flags = action->rsc->cmds->action_flags(action, NULL);
46  if ((node == NULL) || !pe_rsc_is_clone(action->rsc)) {
47  return flags;
48  }
49 
50  /* Otherwise (i.e., for clone resource actions on a specific node), first
51  * remember whether the non-node-specific action is runnable.
52  */
54 
55  // Then recheck the resource method with the node
56  flags = action->rsc->cmds->action_flags(action, node);
57 
58  /* For clones in ordering constraints, the node-specific "runnable" doesn't
59  * matter, just the non-node-specific setting (i.e., is the action runnable
60  * anywhere).
61  *
62  * This applies only to runnable, and only for ordering constraints. This
63  * function shouldn't be used for other types of constraints without
64  * changes. Not very satisfying, but it's logical and appears to work well.
65  */
66  if (runnable && !pcmk_is_set(flags, pe_action_runnable)) {
69  }
70  return flags;
71 }
72 
91 static char *
92 action_uuid_for_ordering(const char *first_uuid, const pe_resource_t *first_rsc)
93 {
94  guint interval_ms = 0;
95  char *uuid = NULL;
96  char *rid = NULL;
97  char *first_task_str = NULL;
98  enum action_tasks first_task = no_action;
99  enum action_tasks remapped_task = no_action;
100 
101  // Only non-notify actions for collective resources need remapping
102  if ((strstr(first_uuid, "notify") != NULL)
103  || (first_rsc->variant < pe_group)) {
104  goto done;
105  }
106 
107  // Only non-recurring actions need remapping
108  CRM_ASSERT(parse_op_key(first_uuid, &rid, &first_task_str, &interval_ms));
109  if (interval_ms > 0) {
110  goto done;
111  }
112 
113  first_task = text2task(first_task_str);
114  switch (first_task) {
115  case stop_rsc:
116  case start_rsc:
117  case action_notify:
118  case action_promote:
119  case action_demote:
120  remapped_task = first_task + 1;
121  break;
122  case stopped_rsc:
123  case started_rsc:
124  case action_notified:
125  case action_promoted:
126  case action_demoted:
127  remapped_task = first_task;
128  break;
129  case monitor_rsc:
130  case shutdown_crm:
131  case stonith_node:
132  break;
133  default:
134  crm_err("Unknown action '%s' in ordering", first_task_str);
135  break;
136  }
137 
138  if (remapped_task != no_action) {
139  /* If a (clone) resource has notifications enabled, we want to order
140  * relative to when all notifications have been sent for the remapped
141  * task. Only outermost resources or those in bundles have
142  * notifications.
143  */
144  if (pcmk_is_set(first_rsc->flags, pe_rsc_notify)
145  && ((first_rsc->parent == NULL)
146  || (pe_rsc_is_clone(first_rsc)
147  && (first_rsc->parent->variant == pe_container)))) {
148  uuid = pcmk__notify_key(rid, "confirmed-post",
149  task2text(remapped_task));
150  } else {
151  uuid = pcmk__op_key(rid, task2text(remapped_task), 0);
152  }
153  pe_rsc_trace(first_rsc,
154  "Remapped action UUID %s to %s for ordering purposes",
155  first_uuid, uuid);
156  }
157 
158 done:
159  if (uuid == NULL) {
160  uuid = strdup(first_uuid);
161  CRM_ASSERT(uuid != NULL);
162  }
163  free(first_task_str);
164  free(rid);
165  return uuid;
166 }
167 
184 static pe_action_t *
185 action_for_ordering(pe_action_t *action)
186 {
188  pe_resource_t *rsc = action->rsc;
189 
190  if ((rsc != NULL) && (rsc->variant >= pe_group) && (action->uuid != NULL)) {
191  char *uuid = action_uuid_for_ordering(action->uuid, rsc);
192 
193  result = find_first_action(rsc->actions, uuid, NULL, NULL);
194  if (result == NULL) {
195  crm_warn("Not remapping %s to %s because %s does not have "
196  "remapped action", action->uuid, uuid, rsc->id);
197  result = action;
198  }
199  free(uuid);
200  }
201  return result;
202 }
203 
217 static uint32_t
218 update_action_for_ordering_flags(pe_action_t *first, pe_action_t *then,
219  enum pe_action_flags first_flags,
220  enum pe_action_flags then_flags,
221  pe_action_wrapper_t *order,
223 {
224  uint32_t changed = pcmk__updated_none;
225 
226  /* The node will only be used for clones. If interleaved, node will be NULL,
227  * otherwise the ordering scope will be limited to the node. Normally, the
228  * whole 'then' clone should restart if 'first' is restarted, so then->node
229  * is needed.
230  */
231  pe_node_t *node = then->node;
232 
234  /* For unfencing, only instances of 'then' on the same node as 'first'
235  * (the unfencing operation) should restart, so reset node to
236  * first->node, at which point this case is handled like a normal
237  * pe_order_implies_then.
238  */
241  node = first->node;
242  pe_rsc_trace(then->rsc,
243  "%s then %s: mapped pe_order_implies_then_on_node to "
244  "pe_order_implies_then on %s",
245  first->uuid, then->uuid, pe__node_name(node));
246  }
247 
248  if (pcmk_is_set(order->type, pe_order_implies_then)) {
249  if (then->rsc != NULL) {
250  changed |= then->rsc->cmds->update_ordered_actions(first, then,
251  node,
252  first_flags & pe_action_optional,
255  data_set);
256  } else if (!pcmk_is_set(first_flags, pe_action_optional)
257  && pcmk_is_set(then->flags, pe_action_optional)) {
260  }
261  pe_rsc_trace(then->rsc, "%s then %s: %s after pe_order_implies_then",
262  first->uuid, then->uuid,
263  (changed? "changed" : "unchanged"));
264  }
265 
266  if (pcmk_is_set(order->type, pe_order_restart) && (then->rsc != NULL)) {
268 
269  changed |= then->rsc->cmds->update_ordered_actions(first, then, node,
270  first_flags, restart,
272  data_set);
273  pe_rsc_trace(then->rsc, "%s then %s: %s after pe_order_restart",
274  first->uuid, then->uuid,
275  (changed? "changed" : "unchanged"));
276  }
277 
278  if (pcmk_is_set(order->type, pe_order_implies_first)) {
279  if (first->rsc != NULL) {
280  changed |= first->rsc->cmds->update_ordered_actions(first, then,
281  node,
282  first_flags,
285  data_set);
286  } else if (!pcmk_is_set(first_flags, pe_action_optional)
287  && pcmk_is_set(first->flags, pe_action_runnable)) {
290  }
291  pe_rsc_trace(then->rsc, "%s then %s: %s after pe_order_implies_first",
292  first->uuid, then->uuid,
293  (changed? "changed" : "unchanged"));
294  }
295 
297  if (then->rsc != NULL) {
298  changed |= then->rsc->cmds->update_ordered_actions(first, then,
299  node,
300  first_flags & pe_action_optional,
303  data_set);
304  }
305  pe_rsc_trace(then->rsc,
306  "%s then %s: %s after pe_order_promoted_implies_first",
307  first->uuid, then->uuid,
308  (changed? "changed" : "unchanged"));
309  }
310 
311  if (pcmk_is_set(order->type, pe_order_one_or_more)) {
312  if (then->rsc != NULL) {
313  changed |= then->rsc->cmds->update_ordered_actions(first, then,
314  node,
315  first_flags,
318  data_set);
319 
320  } else if (pcmk_is_set(first_flags, pe_action_runnable)) {
321  // We have another runnable instance of "first"
322  then->runnable_before++;
323 
324  /* Mark "then" as runnable if it requires a certain number of
325  * "before" instances to be runnable, and they now are.
326  */
327  if ((then->runnable_before >= then->required_runnable_before)
328  && !pcmk_is_set(then->flags, pe_action_runnable)) {
329 
332  }
333  }
334  pe_rsc_trace(then->rsc, "%s then %s: %s after pe_order_one_or_more",
335  first->uuid, then->uuid,
336  (changed? "changed" : "unchanged"));
337  }
338 
339  if (pcmk_is_set(order->type, pe_order_probe) && (then->rsc != NULL)) {
340  if (!pcmk_is_set(first_flags, pe_action_runnable)
341  && (first->rsc->running_on != NULL)) {
342 
343  pe_rsc_trace(then->rsc,
344  "%s then %s: ignoring because first is stopping",
345  first->uuid, then->uuid);
346  order->type = pe_order_none;
347  } else {
348  changed |= then->rsc->cmds->update_ordered_actions(first, then,
349  node,
350  first_flags,
353  data_set);
354  }
355  pe_rsc_trace(then->rsc, "%s then %s: %s after pe_order_probe",
356  first->uuid, then->uuid,
357  (changed? "changed" : "unchanged"));
358  }
359 
360  if (pcmk_is_set(order->type, pe_order_runnable_left)) {
361  if (then->rsc != NULL) {
362  changed |= then->rsc->cmds->update_ordered_actions(first, then,
363  node,
364  first_flags,
367  data_set);
368 
369  } else if (!pcmk_is_set(first_flags, pe_action_runnable)
370  && pcmk_is_set(then->flags, pe_action_runnable)) {
371 
374  }
375  pe_rsc_trace(then->rsc, "%s then %s: %s after pe_order_runnable_left",
376  first->uuid, then->uuid,
377  (changed? "changed" : "unchanged"));
378  }
379 
381  if (then->rsc != NULL) {
382  changed |= then->rsc->cmds->update_ordered_actions(first, then,
383  node,
384  first_flags,
387  data_set);
388  }
389  pe_rsc_trace(then->rsc, "%s then %s: %s after "
390  "pe_order_implies_first_migratable",
391  first->uuid, then->uuid,
392  (changed? "changed" : "unchanged"));
393  }
394 
395  if (pcmk_is_set(order->type, pe_order_pseudo_left)) {
396  if (then->rsc != NULL) {
397  changed |= then->rsc->cmds->update_ordered_actions(first, then,
398  node,
399  first_flags,
402  data_set);
403  }
404  pe_rsc_trace(then->rsc, "%s then %s: %s after pe_order_pseudo_left",
405  first->uuid, then->uuid,
406  (changed? "changed" : "unchanged"));
407  }
408 
409  if (pcmk_is_set(order->type, pe_order_optional)) {
410  if (then->rsc != NULL) {
411  changed |= then->rsc->cmds->update_ordered_actions(first, then,
412  node,
413  first_flags,
416  data_set);
417  }
418  pe_rsc_trace(then->rsc, "%s then %s: %s after pe_order_optional",
419  first->uuid, then->uuid,
420  (changed? "changed" : "unchanged"));
421  }
422 
423  if (pcmk_is_set(order->type, pe_order_asymmetrical)) {
424  if (then->rsc != NULL) {
425  changed |= then->rsc->cmds->update_ordered_actions(first, then,
426  node,
427  first_flags,
430  data_set);
431  }
432  pe_rsc_trace(then->rsc, "%s then %s: %s after pe_order_asymmetrical",
433  first->uuid, then->uuid,
434  (changed? "changed" : "unchanged"));
435  }
436 
439  && !pcmk_is_set(first_flags, pe_action_optional)) {
440 
441  pe_rsc_trace(then->rsc, "%s will be in graph because %s is required",
442  then->uuid, first->uuid);
444  // Don't bother marking 'then' as changed just for this
445  }
446 
448  && !pcmk_is_set(then_flags, pe_action_optional)) {
449 
450  pe_rsc_trace(then->rsc, "%s will be in graph because %s is required",
451  first->uuid, then->uuid);
453  // Don't bother marking 'first' as changed just for this
454  }
455 
456  if (pcmk_any_flags_set(order->type, pe_order_implies_then
459  && (first->rsc != NULL)
460  && !pcmk_is_set(first->rsc->flags, pe_rsc_managed)
461  && pcmk_is_set(first->rsc->flags, pe_rsc_block)
463  && pcmk__str_eq(first->task, RSC_STOP, pcmk__str_casei)) {
464 
465  if (pcmk_is_set(then->flags, pe_action_runnable)) {
468  }
469  pe_rsc_trace(then->rsc, "%s then %s: %s after checking whether first "
470  "is blocked, unmanaged, unrunnable stop",
471  first->uuid, then->uuid,
472  (changed? "changed" : "unchanged"));
473  }
474 
475  return changed;
476 }
477 
478 // Convenience macros for logging action properties
479 
480 #define action_type_str(flags) \
481  (pcmk_is_set((flags), pe_action_pseudo)? "pseudo-action" : "action")
482 
483 #define action_optional_str(flags) \
484  (pcmk_is_set((flags), pe_action_optional)? "optional" : "required")
485 
486 #define action_runnable_str(flags) \
487  (pcmk_is_set((flags), pe_action_runnable)? "runnable" : "unrunnable")
488 
489 #define action_node_str(a) \
490  (((a)->node == NULL)? "no node" : (a)->node->details->uname)
491 
499 void
501 {
502  GList *lpc = NULL;
503  uint32_t changed = pcmk__updated_none;
504  int last_flags = then->flags;
505 
506  pe_rsc_trace(then->rsc, "Updating %s %s (%s %s) on %s",
507  action_type_str(then->flags), then->uuid,
508  action_optional_str(then->flags),
510 
512  /* Initialize current known "runnable before" actions. As
513  * update_action_for_ordering_flags() is called for each of then's
514  * before actions, this number will increment as runnable 'first'
515  * actions are encountered.
516  */
517  then->runnable_before = 0;
518 
519  if (then->required_runnable_before == 0) {
520  /* @COMPAT This ordering constraint uses the deprecated
521  * "require-all=false" attribute. Treat it like "clone-min=1".
522  */
523  then->required_runnable_before = 1;
524  }
525 
526  /* The pe_order_one_or_more clause of update_action_for_ordering_flags()
527  * (called below) will reset runnable if appropriate.
528  */
530  }
531 
532  for (lpc = then->actions_before; lpc != NULL; lpc = lpc->next) {
533  pe_action_wrapper_t *other = (pe_action_wrapper_t *) lpc->data;
534  pe_action_t *first = other->action;
535 
536  pe_node_t *then_node = then->node;
537  pe_node_t *first_node = first->node;
538 
539  if ((first->rsc != NULL)
540  && (first->rsc->variant == pe_group)
541  && pcmk__str_eq(first->task, RSC_START, pcmk__str_casei)) {
542 
543  first_node = first->rsc->fns->location(first->rsc, NULL, FALSE);
544  if (first_node != NULL) {
545  pe_rsc_trace(first->rsc, "Found %s for 'first' %s",
546  pe__node_name(first_node), first->uuid);
547  }
548  }
549 
550  if ((then->rsc != NULL)
551  && (then->rsc->variant == pe_group)
552  && pcmk__str_eq(then->task, RSC_START, pcmk__str_casei)) {
553 
554  then_node = then->rsc->fns->location(then->rsc, NULL, FALSE);
555  if (then_node != NULL) {
556  pe_rsc_trace(then->rsc, "Found %s for 'then' %s",
557  pe__node_name(then_node), then->uuid);
558  }
559  }
560 
561  // Disable constraint if it only applies when on same node, but isn't
562  if (pcmk_is_set(other->type, pe_order_same_node)
563  && (first_node != NULL) && (then_node != NULL)
564  && (first_node->details != then_node->details)) {
565 
566  pe_rsc_trace(then->rsc,
567  "Disabled ordering %s on %s then %s on %s: not same node",
568  other->action->uuid, pe__node_name(first_node),
569  then->uuid, pe__node_name(then_node));
570  other->type = pe_order_none;
571  continue;
572  }
573 
575 
576  if ((first->rsc != NULL)
578  && !pcmk_is_set(then->flags, pe_action_optional)) {
579 
580  /* 'then' is required, so we must abandon 'first'
581  * (e.g. a required stop cancels any agent reload).
582  */
584  if (!strcmp(first->task, CRMD_ACTION_RELOAD_AGENT)) {
586  }
587  }
588 
589  if ((first->rsc != NULL) && (then->rsc != NULL)
590  && (first->rsc != then->rsc) && !is_parent(then->rsc, first->rsc)) {
591  first = action_for_ordering(first);
592  }
593  if (first != other->action) {
594  pe_rsc_trace(then->rsc, "Ordering %s after %s instead of %s",
595  then->uuid, first->uuid, other->action->uuid);
596  }
597 
598  pe_rsc_trace(then->rsc,
599  "%s (%#.6x) then %s (%#.6x): type=%#.6x node=%s",
600  first->uuid, first->flags, then->uuid, then->flags,
601  other->type, action_node_str(first));
602 
603  if (first == other->action) {
604  /* 'first' was not remapped (e.g. from 'start' to 'running'), which
605  * could mean it is a non-resource action, a primitive resource
606  * action, or already expanded.
607  */
608  enum pe_action_flags first_flags, then_flags;
609 
610  first_flags = action_flags_for_ordering(first, then_node);
611  then_flags = action_flags_for_ordering(then, first_node);
612 
613  changed |= update_action_for_ordering_flags(first, then,
614  first_flags, then_flags,
615  other, data_set);
616 
617  /* 'first' was for a complex resource (clone, group, etc),
618  * create a new dependency if necessary
619  */
620  } else if (order_actions(first, then, other->type)) {
621  /* This was the first time 'first' and 'then' were associated,
622  * start again to get the new actions_before list
623  */
625  pe_rsc_trace(then->rsc,
626  "Disabled ordering %s then %s in favor of %s then %s",
627  other->action->uuid, then->uuid, first->uuid,
628  then->uuid);
629  other->type = pe_order_none;
630  }
631 
632 
633  if (pcmk_is_set(changed, pcmk__updated_first)) {
634  crm_trace("Re-processing %s and its 'after' actions "
635  "because it changed", first->uuid);
636  for (GList *lpc2 = first->actions_after; lpc2 != NULL;
637  lpc2 = lpc2->next) {
638  pe_action_wrapper_t *other = (pe_action_wrapper_t *) lpc2->data;
639 
641  }
643  }
644  }
645 
647  if (last_flags == then->flags) {
649  } else {
651  }
652  }
653 
654  if (pcmk_is_set(changed, pcmk__updated_then)) {
655  crm_trace("Re-processing %s and its 'after' actions because it changed",
656  then->uuid);
657  if (pcmk_is_set(last_flags, pe_action_runnable)
658  && !pcmk_is_set(then->flags, pe_action_runnable)) {
660  }
662  for (lpc = then->actions_after; lpc != NULL; lpc = lpc->next) {
663  pe_action_wrapper_t *other = (pe_action_wrapper_t *) lpc->data;
664 
666  }
667  }
668 }
669 
670 static inline bool
671 is_primitive_action(const pe_action_t *action)
672 {
673  return action && action->rsc && (action->rsc->variant == pe_native);
674 }
675 
684 #define clear_action_flag_because(action, flag, reason) do { \
685  if (pcmk_is_set((action)->flags, (flag))) { \
686  pe__clear_action_flags(action, flag); \
687  if ((action)->rsc != (reason)->rsc) { \
688  char *reason_text = pe__action2reason((reason), (flag)); \
689  pe_action_set_reason((action), reason_text, \
690  ((flag) == pe_action_migrate_runnable)); \
691  free(reason_text); \
692  } \
693  } \
694  } while (0)
695 
706 static void
707 handle_asymmetric_ordering(const pe_action_t *first, pe_action_t *then)
708 {
709  /* Only resource actions after an unrunnable 'first' action need updates for
710  * asymmetric ordering.
711  */
712  if ((then->rsc == NULL) || pcmk_is_set(first->flags, pe_action_runnable)) {
713  return;
714  }
715 
716  // Certain optional 'then' actions are unaffected by unrunnable 'first'
717  if (pcmk_is_set(then->flags, pe_action_optional)) {
718  enum rsc_role_e then_rsc_role = then->rsc->fns->state(then->rsc, TRUE);
719 
720  if ((then_rsc_role == RSC_ROLE_STOPPED)
721  && pcmk__str_eq(then->task, RSC_STOP, pcmk__str_none)) {
722  /* If 'then' should stop after 'first' but is already stopped, the
723  * ordering is irrelevant.
724  */
725  return;
726  } else if ((then_rsc_role >= RSC_ROLE_STARTED)
727  && pcmk__str_eq(then->task, RSC_START, pcmk__str_none)
728  && pe__rsc_running_on_only(then->rsc, then->node)) {
729  /* Similarly if 'then' should start after 'first' but is already
730  * started on a single node.
731  */
732  return;
733  }
734  }
735 
736  // 'First' can't run, so 'then' can't either
739 }
740 
752 static void
753 handle_restart_ordering(pe_action_t *first, pe_action_t *then, uint32_t filter)
754 {
755  const char *reason = NULL;
756 
757  CRM_ASSERT(is_primitive_action(first));
758  CRM_ASSERT(is_primitive_action(then));
759 
760  // We need to update the action in two cases:
761 
762  // ... if 'then' is required
763  if (pcmk_is_set(filter, pe_action_optional)
764  && !pcmk_is_set(then->flags, pe_action_optional)) {
765  reason = "restart";
766  }
767 
768  /* ... if 'then' is unrunnable action on same resource (if a resource
769  * should restart but can't start, we still want to stop)
770  */
771  if (pcmk_is_set(filter, pe_action_runnable)
773  && pcmk_is_set(then->rsc->flags, pe_rsc_managed)
774  && (first->rsc == then->rsc)) {
775  reason = "stop";
776  }
777 
778  if (reason == NULL) {
779  return;
780  }
781 
782  pe_rsc_trace(first->rsc, "Handling %s -> %s for %s",
783  first->uuid, then->uuid, reason);
784 
785  // Make 'first' required if it is runnable
786  if (pcmk_is_set(first->flags, pe_action_runnable)) {
788  }
789 
790  // Make 'first' required if 'then' is required
791  if (!pcmk_is_set(then->flags, pe_action_optional)) {
793  }
794 
795  // Make 'first' unmigratable if 'then' is unmigratable
798  }
799 
800  // Make 'then' unrunnable if 'first' is required but unrunnable
801  if (!pcmk_is_set(first->flags, pe_action_optional)
802  && !pcmk_is_set(first->flags, pe_action_runnable)) {
804  }
805 }
806 
829 uint32_t
831  const pe_node_t *node, uint32_t flags,
832  uint32_t filter, uint32_t type,
834 {
835  uint32_t changed = pcmk__updated_none;
836  uint32_t then_flags = then->flags;
837  uint32_t first_flags = first->flags;
838 
840  handle_asymmetric_ordering(first, then);
841  }
842 
844  && !pcmk_is_set(then_flags, pe_action_optional)) {
845  // Then is required, and implies first should be, too
846 
847  if (pcmk_is_set(filter, pe_action_optional)
849  && pcmk_is_set(first_flags, pe_action_optional)) {
851  }
852 
856  }
857  }
858 
860  && (then->rsc != NULL) && (then->rsc->role == RSC_ROLE_PROMOTED)
861  && pcmk_is_set(filter, pe_action_optional)
862  && !pcmk_is_set(then->flags, pe_action_optional)) {
863 
865 
869  then);
870  }
871  }
872 
874  && pcmk_is_set(filter, pe_action_optional)) {
875 
876  if (!pcmk_all_flags_set(then->flags,
879  }
880 
881  if (!pcmk_is_set(then->flags, pe_action_optional)) {
883  }
884  }
885 
887  && pcmk_is_set(filter, pe_action_optional)
888  && !pcmk_is_set(first->flags, pe_action_runnable)) {
889 
892  }
893 
895  && pcmk_is_set(filter, pe_action_runnable)
898 
901  }
902 
904  && pcmk_is_set(filter, pe_action_optional)
908 
910  }
911 
913  handle_restart_ordering(first, then, filter);
914  }
915 
916  if (then_flags != then->flags) {
918  pe_rsc_trace(then->rsc,
919  "%s on %s: flags are now %#.6x (was %#.6x) "
920  "because of 'first' %s (%#.6x)",
921  then->uuid, pe__node_name(then->node),
922  then->flags, then_flags, first->uuid, first->flags);
923 
924  if ((then->rsc != NULL) && (then->rsc->parent != NULL)) {
925  // Required to handle "X_stop then X_start" for cloned groups
927  }
928  }
929 
930  if (first_flags != first->flags) {
932  pe_rsc_trace(first->rsc,
933  "%s on %s: flags are now %#.6x (was %#.6x) "
934  "because of 'then' %s (%#.6x)",
935  first->uuid, pe__node_name(first->node),
936  first->flags, first_flags, then->uuid, then->flags);
937  }
938 
939  return changed;
940 }
941 
950 void
951 pcmk__log_action(const char *pre_text, const pe_action_t *action, bool details)
952 {
953  const char *node_uname = NULL;
954  const char *node_uuid = NULL;
955  const char *desc = NULL;
956 
957  CRM_CHECK(action != NULL, return);
958 
959  if (!pcmk_is_set(action->flags, pe_action_pseudo)) {
960  if (action->node != NULL) {
961  node_uname = action->node->details->uname;
962  node_uuid = action->node->details->id;
963  } else {
964  node_uname = "<none>";
965  }
966  }
967 
968  switch (text2task(action->task)) {
969  case stonith_node:
970  case shutdown_crm:
971  if (pcmk_is_set(action->flags, pe_action_pseudo)) {
972  desc = "Pseudo ";
973  } else if (pcmk_is_set(action->flags, pe_action_optional)) {
974  desc = "Optional ";
975  } else if (!pcmk_is_set(action->flags, pe_action_runnable)) {
976  desc = "!!Non-Startable!! ";
977  } else if (pcmk_is_set(action->flags, pe_action_processed)) {
978  desc = "";
979  } else {
980  desc = "(Provisional) ";
981  }
982  crm_trace("%s%s%sAction %d: %s%s%s%s%s%s",
983  ((pre_text == NULL)? "" : pre_text),
984  ((pre_text == NULL)? "" : ": "),
985  desc, action->id, action->uuid,
986  (node_uname? "\ton " : ""), (node_uname? node_uname : ""),
987  (node_uuid? "\t\t(" : ""), (node_uuid? node_uuid : ""),
988  (node_uuid? ")" : ""));
989  break;
990  default:
991  if (pcmk_is_set(action->flags, pe_action_optional)) {
992  desc = "Optional ";
993  } else if (pcmk_is_set(action->flags, pe_action_pseudo)) {
994  desc = "Pseudo ";
995  } else if (!pcmk_is_set(action->flags, pe_action_runnable)) {
996  desc = "!!Non-Startable!! ";
997  } else if (pcmk_is_set(action->flags, pe_action_processed)) {
998  desc = "";
999  } else {
1000  desc = "(Provisional) ";
1001  }
1002  crm_trace("%s%s%sAction %d: %s %s%s%s%s%s%s",
1003  ((pre_text == NULL)? "" : pre_text),
1004  ((pre_text == NULL)? "" : ": "),
1005  desc, action->id, action->uuid,
1006  (action->rsc? action->rsc->id : "<none>"),
1007  (node_uname? "\ton " : ""), (node_uname? node_uname : ""),
1008  (node_uuid? "\t\t(" : ""), (node_uuid? node_uuid : ""),
1009  (node_uuid? ")" : ""));
1010  break;
1011  }
1012 
1013  if (details) {
1014  const GList *iter = NULL;
1015  const pe_action_wrapper_t *other = NULL;
1016 
1017  crm_trace("\t\t====== Preceding Actions");
1018  for (iter = action->actions_before; iter != NULL; iter = iter->next) {
1019  other = (const pe_action_wrapper_t *) iter->data;
1020  pcmk__log_action("\t\t", other->action, false);
1021  }
1022  crm_trace("\t\t====== Subsequent Actions");
1023  for (iter = action->actions_after; iter != NULL; iter = iter->next) {
1024  other = (const pe_action_wrapper_t *) iter->data;
1025  pcmk__log_action("\t\t", other->action, false);
1026  }
1027  crm_trace("\t\t====== End");
1028 
1029  } else {
1030  crm_trace("\t\t(before=%d, after=%d)",
1031  g_list_length(action->actions_before),
1032  g_list_length(action->actions_after));
1033  }
1034 }
1035 
1044 pe_action_t *
1046 {
1047  char *shutdown_id = NULL;
1048  pe_action_t *shutdown_op = NULL;
1049 
1050  CRM_ASSERT(node != NULL);
1051 
1052  shutdown_id = crm_strdup_printf("%s-%s", CRM_OP_SHUTDOWN,
1053  node->details->uname);
1054 
1055  shutdown_op = custom_action(NULL, shutdown_id, CRM_OP_SHUTDOWN, node, FALSE,
1056  TRUE, node->details->data_set);
1057 
1058  pcmk__order_stops_before_shutdown(node, shutdown_op);
1060  return shutdown_op;
1061 }
1062 
1074 static void
1075 add_op_digest_to_xml(const lrmd_event_data_t *op, xmlNode *update)
1076 {
1077  char *digest = NULL;
1078  xmlNode *args_xml = NULL;
1079 
1080  if (op->params == NULL) {
1081  return;
1082  }
1083  args_xml = create_xml_node(NULL, XML_TAG_PARAMS);
1084  g_hash_table_foreach(op->params, hash2field, args_xml);
1085  pcmk__filter_op_for_digest(args_xml);
1086  digest = calculate_operation_digest(args_xml, NULL);
1087  crm_xml_add(update, XML_LRM_ATTR_OP_DIGEST, digest);
1088  free_xml(args_xml);
1089  free(digest);
1090 }
1091 
1092 #define FAKE_TE_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
1093 
1107 xmlNode *
1109  const char *caller_version, int target_rc,
1110  const char *node, const char *origin)
1111 {
1112  char *key = NULL;
1113  char *magic = NULL;
1114  char *op_id = NULL;
1115  char *op_id_additional = NULL;
1116  char *local_user_data = NULL;
1117  const char *exit_reason = NULL;
1118 
1119  xmlNode *xml_op = NULL;
1120  const char *task = NULL;
1121 
1122  CRM_CHECK(op != NULL, return NULL);
1123  crm_trace("Creating history XML for %s-interval %s action for %s on %s "
1124  "(DC version: %s, origin: %s)",
1126  ((node == NULL)? "no node" : node), caller_version, origin);
1127 
1128  task = op->op_type;
1129 
1130  /* Record a successful agent reload as a start, and a failed one as a
1131  * monitor, to make life easier for the scheduler when determining the
1132  * current state.
1133  *
1134  * @COMPAT We should check "reload" here only if the operation was for a
1135  * pre-OCF-1.1 resource agent, but we don't know that here, and we should
1136  * only ever get results for actions scheduled by us, so we can reasonably
1137  * assume any "reload" is actually a pre-1.1 agent reload.
1138  */
1140  NULL)) {
1141  if (op->op_status == PCMK_EXEC_DONE) {
1142  task = CRMD_ACTION_START;
1143  } else {
1144  task = CRMD_ACTION_STATUS;
1145  }
1146  }
1147 
1148  key = pcmk__op_key(op->rsc_id, task, op->interval_ms);
1149  if (pcmk__str_eq(task, CRMD_ACTION_NOTIFY, pcmk__str_none)) {
1150  const char *n_type = crm_meta_value(op->params, "notify_type");
1151  const char *n_task = crm_meta_value(op->params, "notify_operation");
1152 
1153  CRM_LOG_ASSERT(n_type != NULL);
1154  CRM_LOG_ASSERT(n_task != NULL);
1155  op_id = pcmk__notify_key(op->rsc_id, n_type, n_task);
1156 
1157  if (op->op_status != PCMK_EXEC_PENDING) {
1158  /* Ignore notify errors.
1159  *
1160  * @TODO It might be better to keep the correct result here, and
1161  * ignore it in process_graph_event().
1162  */
1164  }
1165 
1166  /* Migration history is preserved separately, which usually matters for
1167  * multiple nodes and is important for future cluster transitions.
1168  */
1170  CRMD_ACTION_MIGRATED, NULL)) {
1171  op_id = strdup(key);
1172 
1173  } else if (did_rsc_op_fail(op, target_rc)) {
1174  op_id = pcmk__op_key(op->rsc_id, "last_failure", 0);
1175  if (op->interval_ms == 0) {
1176  // Ensure 'last' gets updated, in case record-pending is true
1177  op_id_additional = pcmk__op_key(op->rsc_id, "last", 0);
1178  }
1179  exit_reason = op->exit_reason;
1180 
1181  } else if (op->interval_ms > 0) {
1182  op_id = strdup(key);
1183 
1184  } else {
1185  op_id = pcmk__op_key(op->rsc_id, "last", 0);
1186  }
1187 
1188  again:
1190  if (xml_op == NULL) {
1192  }
1193 
1194  if (op->user_data == NULL) {
1195  crm_debug("Generating fake transition key for: " PCMK__OP_FMT
1196  " %d from %s", op->rsc_id, op->op_type, op->interval_ms,
1197  op->call_id, origin);
1198  local_user_data = pcmk__transition_key(-1, op->call_id, target_rc,
1199  FAKE_TE_ID);
1200  op->user_data = local_user_data;
1201  }
1202 
1203  if (magic == NULL) {
1204  magic = crm_strdup_printf("%d:%d;%s", op->op_status, op->rc,
1205  (const char *) op->user_data);
1206  }
1207 
1208  crm_xml_add(xml_op, XML_ATTR_ID, op_id);
1209  crm_xml_add(xml_op, XML_LRM_ATTR_TASK_KEY, key);
1210  crm_xml_add(xml_op, XML_LRM_ATTR_TASK, task);
1211  crm_xml_add(xml_op, XML_ATTR_ORIGIN, origin);
1212  crm_xml_add(xml_op, XML_ATTR_CRM_VERSION, caller_version);
1214  crm_xml_add(xml_op, XML_ATTR_TRANSITION_MAGIC, magic);
1215  crm_xml_add(xml_op, XML_LRM_ATTR_EXIT_REASON, exit_reason == NULL ? "" : exit_reason);
1216  crm_xml_add(xml_op, XML_LRM_ATTR_TARGET, node); /* For context during triage */
1217 
1219  crm_xml_add_int(xml_op, XML_LRM_ATTR_RC, op->rc);
1222 
1223  if (compare_version("2.1", caller_version) <= 0) {
1224  if (op->t_run || op->t_rcchange || op->exec_time || op->queue_time) {
1225  crm_trace("Timing data (" PCMK__OP_FMT
1226  "): last=%u change=%u exec=%u queue=%u",
1227  op->rsc_id, op->op_type, op->interval_ms,
1228  op->t_run, op->t_rcchange, op->exec_time, op->queue_time);
1229 
1230  if ((op->interval_ms != 0) && (op->t_rcchange != 0)) {
1231  // Recurring ops may have changed rc after initial run
1233  (long long) op->t_rcchange);
1234  } else {
1236  (long long) op->t_run);
1237  }
1238 
1241  }
1242  }
1243 
1245  /*
1246  * Record migrate_source and migrate_target always for migrate ops.
1247  */
1248  const char *name = XML_LRM_ATTR_MIGRATE_SOURCE;
1249 
1250  crm_xml_add(xml_op, name, crm_meta_value(op->params, name));
1251 
1253  crm_xml_add(xml_op, name, crm_meta_value(op->params, name));
1254  }
1255 
1256  add_op_digest_to_xml(op, xml_op);
1257 
1258  if (op_id_additional) {
1259  free(op_id);
1260  op_id = op_id_additional;
1261  op_id_additional = NULL;
1262  goto again;
1263  }
1264 
1265  if (local_user_data) {
1266  free(local_user_data);
1267  op->user_data = NULL;
1268  }
1269  free(magic);
1270  free(op_id);
1271  free(key);
1272  return xml_op;
1273 }
1274 
1289 bool
1291 {
1292  // Only resource actions taking place on resource's lock node are locked
1293  if ((action == NULL) || (action->rsc == NULL)
1294  || (action->rsc->lock_node == NULL) || (action->node == NULL)
1295  || (action->node->details != action->rsc->lock_node->details)) {
1296  return false;
1297  }
1298 
1299  /* During shutdown, only stops are locked (otherwise, another action such as
1300  * a demote would cause the controller to clear the lock)
1301  */
1302  if (action->node->details->shutdown && (action->task != NULL)
1303  && (strcmp(action->task, RSC_STOP) != 0)) {
1304  return false;
1305  }
1306 
1307  return true;
1308 }
1309 
1310 /* lowest to highest */
1311 static gint
1312 sort_action_id(gconstpointer a, gconstpointer b)
1313 {
1314  const pe_action_wrapper_t *action_wrapper2 = (const pe_action_wrapper_t *)a;
1315  const pe_action_wrapper_t *action_wrapper1 = (const pe_action_wrapper_t *)b;
1316 
1317  if (a == NULL) {
1318  return 1;
1319  }
1320  if (b == NULL) {
1321  return -1;
1322  }
1323  if (action_wrapper1->action->id < action_wrapper2->action->id) {
1324  return 1;
1325  }
1326  if (action_wrapper1->action->id > action_wrapper2->action->id) {
1327  return -1;
1328  }
1329  return 0;
1330 }
1331 
1338 void
1340 {
1341  GList *item = NULL;
1342  GList *next = NULL;
1343  pe_action_wrapper_t *last_input = NULL;
1344 
1345  action->actions_before = g_list_sort(action->actions_before,
1346  sort_action_id);
1347  for (item = action->actions_before; item != NULL; item = next) {
1348  pe_action_wrapper_t *input = (pe_action_wrapper_t *) item->data;
1349 
1350  next = item->next;
1351  if ((last_input != NULL)
1352  && (input->action->id == last_input->action->id)) {
1353  crm_trace("Input %s (%d) duplicate skipped for action %s (%d)",
1354  input->action->uuid, input->action->id,
1355  action->uuid, action->id);
1356 
1357  /* For the purposes of scheduling, the ordering flags no longer
1358  * matter, but crm_simulate looks at certain ones when creating a
1359  * dot graph. Combining the flags is sufficient for that purpose.
1360  */
1361  last_input->type |= input->type;
1362  if (input->state == pe_link_dumped) {
1363  last_input->state = pe_link_dumped;
1364  }
1365 
1366  free(item->data);
1367  action->actions_before = g_list_delete_link(action->actions_before,
1368  item);
1369  } else {
1370  last_input = input;
1371  input->state = pe_link_not_dumped;
1372  }
1373  }
1374 }
1375 
1382 void
1384 {
1385  pcmk__output_t *out = data_set->priv;
1386 
1387  // Output node (non-resource) actions
1388  for (GList *iter = data_set->actions; iter != NULL; iter = iter->next) {
1389  char *node_name = NULL;
1390  char *task = NULL;
1391  pe_action_t *action = (pe_action_t *) iter->data;
1392 
1393  if (action->rsc != NULL) {
1394  continue; // Resource actions will be output later
1395 
1396  } else if (pcmk_is_set(action->flags, pe_action_optional)) {
1397  continue; // This action was not scheduled
1398  }
1399 
1400  if (pcmk__str_eq(action->task, CRM_OP_SHUTDOWN, pcmk__str_casei)) {
1401  task = strdup("Shutdown");
1402 
1403  } else if (pcmk__str_eq(action->task, CRM_OP_FENCE, pcmk__str_casei)) {
1404  const char *op = g_hash_table_lookup(action->meta, "stonith_action");
1405 
1406  task = crm_strdup_printf("Fence (%s)", op);
1407 
1408  } else {
1409  continue; // Don't display other node action types
1410  }
1411 
1412  if (pe__is_guest_node(action->node)) {
1413  node_name = crm_strdup_printf("%s (resource: %s)",
1414  pe__node_name(action->node),
1415  action->node->details->remote_rsc->container->id);
1416  } else if (action->node != NULL) {
1417  node_name = crm_strdup_printf("%s", pe__node_name(action->node));
1418  }
1419 
1420  out->message(out, "node-action", task, node_name, action->reason);
1421 
1422  free(node_name);
1423  free(task);
1424  }
1425 
1426  // Output resource actions
1427  for (GList *iter = data_set->resources; iter != NULL; iter = iter->next) {
1428  pe_resource_t *rsc = (pe_resource_t *) iter->data;
1429 
1430  rsc->cmds->output_actions(rsc);
1431  }
1432 }
1433 
1444 static bool
1445 action_in_config(const pe_resource_t *rsc, const char *task, guint interval_ms)
1446 {
1447  char *key = pcmk__op_key(rsc->id, task, interval_ms);
1448  bool config = (find_rsc_op_entry(rsc, key) != NULL);
1449 
1450  free(key);
1451  return config;
1452 }
1453 
1463 static const char *
1464 task_for_digest(const char *task, guint interval_ms)
1465 {
1466  /* Certain actions need to be compared against the parameters used to start
1467  * the resource.
1468  */
1469  if ((interval_ms == 0)
1471  task = RSC_START;
1472  }
1473  return task;
1474 }
1475 
1493 static bool
1494 only_sanitized_changed(const xmlNode *xml_op,
1495  const op_digest_cache_t *digest_data,
1496  const pe_working_set_t *data_set)
1497 {
1498  const char *digest_secure = NULL;
1499 
1501  // The scheduler is not being run as a simulation
1502  return false;
1503  }
1504 
1505  digest_secure = crm_element_value(xml_op, XML_LRM_ATTR_SECURE_DIGEST);
1506 
1507  return (digest_data->rc != RSC_DIGEST_MATCH) && (digest_secure != NULL)
1508  && (digest_data->digest_secure_calc != NULL)
1509  && (strcmp(digest_data->digest_secure_calc, digest_secure) == 0);
1510 }
1511 
1521 static void
1522 force_restart(pe_resource_t *rsc, const char *task, guint interval_ms,
1523  pe_node_t *node)
1524 {
1525  char *key = pcmk__op_key(rsc->id, task, interval_ms);
1526  pe_action_t *required = custom_action(rsc, key, task, NULL, FALSE, TRUE,
1527  rsc->cluster);
1528 
1529  pe_action_set_reason(required, "resource definition change", true);
1530  trigger_unfencing(rsc, node, "Device parameters changed", NULL,
1531  rsc->cluster);
1532 }
1533 
1541 static void
1542 schedule_reload(pe_resource_t *rsc, const pe_node_t *node)
1543 {
1544  pe_action_t *reload = NULL;
1545 
1546  // For collective resources, just call recursively for children
1547  if (rsc->variant > pe_native) {
1548  g_list_foreach(rsc->children, (GFunc) schedule_reload, (gpointer) node);
1549  return;
1550  }
1551 
1552  // Skip the reload in certain situations
1553  if ((node == NULL)
1554  || !pcmk_is_set(rsc->flags, pe_rsc_managed)
1555  || pcmk_is_set(rsc->flags, pe_rsc_failed)) {
1556  pe_rsc_trace(rsc, "Skip reload of %s:%s%s %s",
1557  rsc->id,
1558  pcmk_is_set(rsc->flags, pe_rsc_managed)? "" : " unmanaged",
1559  pcmk_is_set(rsc->flags, pe_rsc_failed)? " failed" : "",
1560  (node == NULL)? "inactive" : node->details->uname);
1561  return;
1562  }
1563 
1564  /* If a resource's configuration changed while a start was pending,
1565  * force a full restart instead of a reload.
1566  */
1567  if (pcmk_is_set(rsc->flags, pe_rsc_start_pending)) {
1568  pe_rsc_trace(rsc, "%s: preventing agent reload because start pending",
1569  rsc->id);
1570  custom_action(rsc, stop_key(rsc), CRMD_ACTION_STOP, node, FALSE, TRUE,
1571  rsc->cluster);
1572  return;
1573  }
1574 
1575  // Schedule the reload
1577  reload = custom_action(rsc, reload_key(rsc), CRMD_ACTION_RELOAD_AGENT, node,
1578  FALSE, TRUE, rsc->cluster);
1579  pe_action_set_reason(reload, "resource definition change", FALSE);
1580 
1581  // Set orderings so that a required stop or demote cancels the reload
1582  pcmk__new_ordering(NULL, NULL, reload, rsc, stop_key(rsc), NULL,
1584  rsc->cluster);
1585  pcmk__new_ordering(NULL, NULL, reload, rsc, demote_key(rsc), NULL,
1587  rsc->cluster);
1588 }
1589 
1604 bool
1606  const xmlNode *xml_op)
1607 {
1608  guint interval_ms = 0;
1609  const char *task = NULL;
1610  const op_digest_cache_t *digest_data = NULL;
1611 
1612  CRM_CHECK((rsc != NULL) && (node != NULL) && (xml_op != NULL),
1613  return false);
1614 
1615  task = crm_element_value(xml_op, XML_LRM_ATTR_TASK);
1616  CRM_CHECK(task != NULL, return false);
1617 
1618  crm_element_value_ms(xml_op, XML_LRM_ATTR_INTERVAL_MS, &interval_ms);
1619 
1620  // If this is a recurring action, check whether it has been orphaned
1621  if (interval_ms > 0) {
1622  if (action_in_config(rsc, task, interval_ms)) {
1623  pe_rsc_trace(rsc, "%s-interval %s for %s on %s is in configuration",
1624  pcmk__readable_interval(interval_ms), task, rsc->id,
1625  pe__node_name(node));
1626  } else if (pcmk_is_set(rsc->cluster->flags,
1630  task, interval_ms, node, "orphan");
1631  return true;
1632  } else {
1633  pe_rsc_debug(rsc, "%s-interval %s for %s on %s is orphaned",
1634  pcmk__readable_interval(interval_ms), task, rsc->id,
1635  pe__node_name(node));
1636  return true;
1637  }
1638  }
1639 
1640  crm_trace("Checking %s-interval %s for %s on %s for configuration changes",
1641  pcmk__readable_interval(interval_ms), task, rsc->id,
1642  pe__node_name(node));
1643  task = task_for_digest(task, interval_ms);
1644  digest_data = rsc_action_digest_cmp(rsc, xml_op, node, rsc->cluster);
1645 
1646  if (only_sanitized_changed(xml_op, digest_data, rsc->cluster)) {
1647  if (!pcmk__is_daemon && (rsc->cluster->priv != NULL)) {
1648  pcmk__output_t *out = rsc->cluster->priv;
1649 
1650  out->info(out,
1651  "Only 'private' parameters to %s-interval %s for %s "
1652  "on %s changed: %s",
1653  pcmk__readable_interval(interval_ms), task, rsc->id,
1654  pe__node_name(node),
1656  }
1657  return false;
1658  }
1659 
1660  switch (digest_data->rc) {
1661  case RSC_DIGEST_RESTART:
1662  crm_log_xml_debug(digest_data->params_restart, "params:restart");
1663  force_restart(rsc, task, interval_ms, node);
1664  return true;
1665 
1666  case RSC_DIGEST_ALL:
1667  case RSC_DIGEST_UNKNOWN:
1668  // Changes that can potentially be handled by an agent reload
1669 
1670  if (interval_ms > 0) {
1671  /* Recurring actions aren't reloaded per se, they are just
1672  * re-scheduled so the next run uses the new parameters.
1673  * The old instance will be cancelled automatically.
1674  */
1675  crm_log_xml_debug(digest_data->params_all, "params:reschedule");
1676  pcmk__reschedule_recurring(rsc, task, interval_ms, node);
1677 
1678  } else if (crm_element_value(xml_op,
1679  XML_LRM_ATTR_RESTART_DIGEST) != NULL) {
1680  // Agent supports reload, so use it
1681  trigger_unfencing(rsc, node,
1682  "Device parameters changed (reload)", NULL,
1683  rsc->cluster);
1684  crm_log_xml_debug(digest_data->params_all, "params:reload");
1685  schedule_reload(rsc, node);
1686 
1687  } else {
1688  pe_rsc_trace(rsc,
1689  "Restarting %s because agent doesn't support reload",
1690  rsc->id);
1691  crm_log_xml_debug(digest_data->params_restart,
1692  "params:restart");
1693  force_restart(rsc, task, interval_ms, node);
1694  }
1695  return true;
1696 
1697  default:
1698  break;
1699  }
1700  return false;
1701 }
1702 
1711 static GList *
1712 rsc_history_as_list(const xmlNode *rsc_entry, int *start_index, int *stop_index)
1713 {
1714  GList *ops = NULL;
1715 
1716  for (xmlNode *rsc_op = first_named_child(rsc_entry, XML_LRM_TAG_RSC_OP);
1717  rsc_op != NULL; rsc_op = crm_next_same_xml(rsc_op)) {
1718  ops = g_list_prepend(ops, rsc_op);
1719  }
1720  ops = g_list_sort(ops, sort_op_by_callid);
1721  calculate_active_ops(ops, start_index, stop_index);
1722  return ops;
1723 }
1724 
1739 static void
1740 process_rsc_history(const xmlNode *rsc_entry, pe_resource_t *rsc,
1741  pe_node_t *node)
1742 {
1743  int offset = -1;
1744  int stop_index = 0;
1745  int start_index = 0;
1746  GList *sorted_op_list = NULL;
1747 
1748  if (pcmk_is_set(rsc->flags, pe_rsc_orphan)) {
1749  if (pe_rsc_is_anon_clone(pe__const_top_resource(rsc, false))) {
1750  pe_rsc_trace(rsc,
1751  "Skipping configuration check "
1752  "for orphaned clone instance %s",
1753  rsc->id);
1754  } else {
1755  pe_rsc_trace(rsc,
1756  "Skipping configuration check and scheduling clean-up "
1757  "for orphaned resource %s", rsc->id);
1758  pcmk__schedule_cleanup(rsc, node, false);
1759  }
1760  return;
1761  }
1762 
1763  if (pe_find_node_id(rsc->running_on, node->details->id) == NULL) {
1764  if (pcmk__rsc_agent_changed(rsc, node, rsc_entry, false)) {
1765  pcmk__schedule_cleanup(rsc, node, false);
1766  }
1767  pe_rsc_trace(rsc,
1768  "Skipping configuration check for %s "
1769  "because no longer active on %s",
1770  rsc->id, pe__node_name(node));
1771  return;
1772  }
1773 
1774  pe_rsc_trace(rsc, "Checking for configuration changes for %s on %s",
1775  rsc->id, pe__node_name(node));
1776 
1777  if (pcmk__rsc_agent_changed(rsc, node, rsc_entry, true)) {
1778  pcmk__schedule_cleanup(rsc, node, false);
1779  }
1780 
1781  sorted_op_list = rsc_history_as_list(rsc_entry, &start_index, &stop_index);
1782  if (start_index < stop_index) {
1783  return; // Resource is stopped
1784  }
1785 
1786  for (GList *iter = sorted_op_list; iter != NULL; iter = iter->next) {
1787  xmlNode *rsc_op = (xmlNode *) iter->data;
1788  const char *task = NULL;
1789  guint interval_ms = 0;
1790 
1791  if (++offset < start_index) {
1792  // Skip actions that happened before a start
1793  continue;
1794  }
1795 
1796  task = crm_element_value(rsc_op, XML_LRM_ATTR_TASK);
1797  crm_element_value_ms(rsc_op, XML_LRM_ATTR_INTERVAL_MS, &interval_ms);
1798 
1799  if ((interval_ms > 0)
1801  || node->details->maintenance)) {
1802  // Maintenance mode cancels recurring operations
1805  task, interval_ms, node, "maintenance mode");
1806 
1807  } else if ((interval_ms > 0)
1809  RSC_PROMOTE, RSC_MIGRATED, NULL)) {
1810  /* If a resource operation failed, and the operation's definition
1811  * has changed, clear any fail count so they can be retried fresh.
1812  */
1813 
1814  if (pe__bundle_needs_remote_name(rsc)) {
1815  /* We haven't allocated resources to nodes yet, so if the
1816  * REMOTE_CONTAINER_HACK is used, we may calculate the digest
1817  * based on the literal "#uname" value rather than the properly
1818  * substituted value. That would mistakenly make the action
1819  * definition appear to have been changed. Defer the check until
1820  * later in this case.
1821  */
1822  pe__add_param_check(rsc_op, rsc, node, pe_check_active,
1823  rsc->cluster);
1824 
1825  } else if (pcmk__check_action_config(rsc, node, rsc_op)
1826  && (pe_get_failcount(node, rsc, NULL, pe_fc_effective,
1827  NULL) != 0)) {
1828  pe__clear_failcount(rsc, node, "action definition changed",
1829  rsc->cluster);
1830  }
1831  }
1832  }
1833  g_list_free(sorted_op_list);
1834 }
1835 
1849 static void
1850 process_node_history(pe_node_t *node, const xmlNode *lrm_rscs)
1851 {
1852  crm_trace("Processing node history for %s", pe__node_name(node));
1853  for (const xmlNode *rsc_entry = first_named_child(lrm_rscs,
1855  rsc_entry != NULL; rsc_entry = crm_next_same_xml(rsc_entry)) {
1856 
1857  if (xml_has_children(rsc_entry)) {
1858  GList *result = pcmk__rscs_matching_id(ID(rsc_entry),
1859  node->details->data_set);
1860 
1861  for (GList *iter = result; iter != NULL; iter = iter->next) {
1862  pe_resource_t *rsc = (pe_resource_t *) iter->data;
1863 
1864  if (rsc->variant == pe_native) {
1865  process_rsc_history(rsc_entry, rsc, node);
1866  }
1867  }
1868  g_list_free(result);
1869  }
1870  }
1871 }
1872 
1873 // XPath to find a node's resource history
1874 #define XPATH_NODE_HISTORY "/" XML_TAG_CIB "/" XML_CIB_TAG_STATUS \
1875  "/" XML_CIB_TAG_STATE "[@" XML_ATTR_UNAME "='%s']" \
1876  "/" XML_CIB_TAG_LRM "/" XML_LRM_TAG_RESOURCES
1877 
1890 void
1892 {
1893  crm_trace("Check resource and action configuration for changes");
1894 
1895  /* Rather than iterate through the status section, iterate through the nodes
1896  * and search for the appropriate status subsection for each. This skips
1897  * orphaned nodes and lets us eliminate some cases before searching the XML.
1898  */
1899  for (GList *iter = data_set->nodes; iter != NULL; iter = iter->next) {
1900  pe_node_t *node = (pe_node_t *) iter->data;
1901 
1902  /* Don't bother checking actions for a node that can't run actions ...
1903  * unless it's in maintenance mode, in which case we still need to
1904  * cancel any existing recurring monitors.
1905  */
1906  if (node->details->maintenance
1907  || pcmk__node_available(node, false, false)) {
1908 
1909  char *xpath = NULL;
1910  xmlNode *history = NULL;
1911 
1913  history = get_xpath_object(xpath, data_set->input, LOG_NEVER);
1914  free(xpath);
1915 
1916  process_node_history(node, history);
1917  }
1918  }
1919 }
enum pe_link_state state
Definition: pe_types.h:556
#define CRM_CHECK(expr, failure_action)
Definition: logging.h:235
#define XML_RSC_OP_LAST_CHANGE
Definition: msg_xml.h:335
void pcmk__output_actions(pe_working_set_t *data_set)
xmlNode * find_rsc_op_entry(const pe_resource_t *rsc, const char *key)
Definition: pe_actions.c:145
const char * task2text(enum action_tasks task)
Definition: common.c:397
#define RSC_STOP
Definition: crm.h:202
gboolean parse_op_key(const char *key, char **rsc_id, char **op_type, guint *interval_ms)
Definition: operations.c:96
#define CRMD_ACTION_MIGRATED
Definition: crm.h:172
#define pe_flag_stop_action_orphans
Definition: pe_types.h:121
#define pe_rsc_debug(rsc, fmt, args...)
Definition: internal.h:49
G_GNUC_INTERNAL void pcmk__schedule_cleanup(pe_resource_t *rsc, const pe_node_t *node, bool optional)
#define pe__set_action_flags(action, flags_to_set)
Definition: internal.h:89
const char * user_data
Definition: lrmd.h:225
gboolean is_parent(pe_resource_t *child, pe_resource_t *rsc)
Definition: complex.c:905
void hash2field(gpointer key, gpointer value, gpointer user_data)
Set XML attribute based on hash table entry.
Definition: nvpair.c:749
int runnable_before
Definition: pe_types.h:465
xmlNode * pcmk__xe_match(const xmlNode *parent, const char *node_name, const char *attr_n, const char *attr_v)
Definition: xml.c:454
const char * rsc_id
Definition: lrmd.h:221
#define CRM_OP_FENCE
Definition: crm.h:144
const char * crm_xml_add_ms(xmlNode *node, const char *name, guint ms)
Create an XML attribute with specified name and unsigned value.
Definition: nvpair.c:420
#define XML_ATTR_TRANSITION_MAGIC
Definition: msg_xml.h:424
const char * name
Definition: cib.c:24
bool pcmk__strcase_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
Definition: strings.c:933
int(* message)(pcmk__output_t *out, const char *message_id,...)
#define clear_action_flag_because(action, flag, reason)
enum rsc_role_e role
Definition: pe_types.h:402
GList * children
Definition: pe_types.h:409
resource_alloc_functions_t * cmds
Definition: pe_types.h:359
unsigned int queue_time
Definition: lrmd.h:251
Internal tracking for transition graph creation.
Definition: pe_types.h:495
xmlNode * first_named_child(const xmlNode *parent, const char *name)
Definition: xml.c:2521
void pcmk__update_action_for_orderings(pe_action_t *then, pe_working_set_t *data_set)
pe_resource_t * rsc
Definition: pe_types.h:433
const char * crm_xml_add_int(xmlNode *node, const char *name, int value)
Create an XML attribute with specified name and integer value.
Definition: nvpair.c:398
#define reload_key(rsc)
Definition: internal.h:410
pe_action_t * find_first_action(const GList *input, const char *uuid, const char *task, const pe_node_t *on_node)
Definition: pe_actions.c:1298
#define CRMD_ACTION_NOTIFY
Definition: crm.h:185
#define XML_RSC_OP_T_EXEC
Definition: msg_xml.h:337
#define pe_rsc_notify
Definition: pe_types.h:277
const char * crm_meta_value(GHashTable *hash, const char *field)
Definition: utils.c:490
resource_object_functions_t * fns
Definition: pe_types.h:358
#define XML_LRM_TAG_RESOURCE
Definition: msg_xml.h:280
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
Definition: nvpair.c:302
#define XML_LRM_ATTR_OP_DIGEST
Definition: msg_xml.h:328
gint sort_op_by_callid(gconstpointer a, gconstpointer b)
Definition: pe_actions.c:1630
unsigned int t_rcchange
Definition: lrmd.h:247
const pe_resource_t * pe__const_top_resource(const pe_resource_t *rsc, bool include_bundle)
Definition: complex.c:947
xmlNode * pcmk__create_history_xml(xmlNode *parent, lrmd_event_data_t *op, const char *caller_version, int target_rc, const char *node, const char *origin)
void pcmk__filter_op_for_digest(xmlNode *param_set)
Definition: operations.c:344
enum action_tasks text2task(const char *task)
Definition: common.c:349
bool pcmk__check_action_config(pe_resource_t *rsc, pe_node_t *node, const xmlNode *xml_op)
GList * actions
Definition: pe_types.h:187
#define CRM_LOG_ASSERT(expr)
Definition: logging.h:219
int(* info)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
xmlNode * params_restart
Definition: internal.h:511
enum crm_ais_msg_types type
Definition: cpg.c:48
#define demote_key(rsc)
Definition: internal.h:431
enum ocf_exitcode rc
Definition: lrmd.h:239
#define RSC_START
Definition: crm.h:199
pe_action_t * action
Definition: pe_types.h:557
#define XML_RSC_OP_T_QUEUE
Definition: msg_xml.h:338
#define LOG_NEVER
Definition: logging.h:47
bool pe__bundle_needs_remote_name(pe_resource_t *rsc)
Definition: bundle.c:725
#define pe__set_raw_action_flags(action_flags, action_name, flags_to_set)
Definition: internal.h:107
xmlNode * get_xpath_object(const char *xpath, xmlNode *xml_obj, int error_level)
Definition: xpath.c:214
pe_working_set_t * data_set
Cluster that this node is part of.
Definition: pe_types.h:261
bool pcmk__action_locks_rsc_to_node(const pe_action_t *action)
const char * action
Definition: pcmk_fence.c:30
#define pe__set_resource_flags(resource, flags_to_set)
Definition: internal.h:77
GList * resources
Definition: pe_types.h:181
void trigger_unfencing(pe_resource_t *rsc, pe_node_t *node, const char *reason, pe_action_t *dependency, pe_working_set_t *data_set)
Definition: utils.c:616
unsigned int exec_time
Definition: lrmd.h:249
GList * nodes
Definition: pe_types.h:180
#define XML_ATTR_ORIGIN
Definition: msg_xml.h:142
#define CRMD_ACTION_START
Definition: crm.h:174
#define XML_LRM_ATTR_TASK_KEY
Definition: msg_xml.h:316
#define XML_LRM_ATTR_TASK
Definition: msg_xml.h:315
void pcmk__deduplicate_action_inputs(pe_action_t *action)
uint32_t pcmk__update_ordered_actions(pe_action_t *first, pe_action_t *then, const pe_node_t *node, uint32_t flags, uint32_t filter, uint32_t type, pe_working_set_t *data_set)
pe_node_t *(* location)(const pe_resource_t *, GList **, int)
Definition: pe_types.h:55
#define CRMD_ACTION_STOP
Definition: crm.h:177
void * params
Definition: lrmd.h:258
char * calculate_operation_digest(xmlNode *local_cib, const char *version)
Calculate and return digest of XML operation.
Definition: digest.c:150
#define crm_warn(fmt, args...)
Definition: logging.h:378
#define CRMD_ACTION_RELOAD_AGENT
Definition: crm.h:170
void pe_action_set_reason(pe_action_t *action, const char *reason, bool overwrite)
Definition: pe_actions.c:1449
const char * exit_reason
Definition: lrmd.h:266
pe_action_flags
Definition: pe_types.h:316
#define action_type_str(flags)
char * pcmk__notify_key(const char *rsc_id, const char *notify_type, const char *op_type)
Definition: operations.c:183
int crm_element_value_ms(const xmlNode *data, const char *name, guint *dest)
Retrieve the millisecond value of an XML attribute.
Definition: nvpair.c:589
#define action_node_str(a)
#define pe_rsc_failed
Definition: pe_types.h:292
#define crm_debug(fmt, args...)
Definition: logging.h:382
G_GNUC_INTERNAL bool pcmk__node_available(const pe_node_t *node, bool consider_score, bool consider_guest)
#define pe_flag_sanitized
Definition: pe_types.h:137
#define pe__clear_order_flags(order_flags, flags_to_clear)
Definition: internal.h:148
#define XML_ATTR_ID
Definition: msg_xml.h:147
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
Definition: nvpair.c:496
#define XML_BOOLEAN_TRUE
Definition: msg_xml.h:159
bool pe__is_guest_node(const pe_node_t *node)
Definition: remote.c:33
#define stop_key(rsc)
Definition: internal.h:405
#define pe_rsc_start_pending
Definition: pe_types.h:295
char * task
Definition: pe_types.h:437
GList * actions_after
Definition: pe_types.h:471
#define pe__clear_action_flags(action, flags_to_clear)
Definition: internal.h:98
#define crm_trace(fmt, args...)
Definition: logging.h:383
enum rsc_digest_cmp_val rc
Definition: internal.h:508
char * digest_secure_calc
Definition: internal.h:513
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
GHashTable * meta
Definition: pe_types.h:447
#define pcmk_is_set(g, f)
Convenience alias for pcmk_all_flags_set(), to check single flag.
Definition: util.h:121
pe_action_t * pe__clear_failcount(pe_resource_t *rsc, const pe_node_t *node, const char *reason, pe_working_set_t *data_set)
Schedule a controller operation to clear a fail count.
Definition: failcounts.c:388
struct pe_node_shared_s * details
Definition: pe_types.h:268
#define crm_log_xml_debug(xml, text)
Definition: logging.h:390
pe_node_t * node
Definition: pe_types.h:434
bool pcmk__is_daemon
Definition: logging.c:47
gboolean order_actions(pe_action_t *lh_action, pe_action_t *rh_action, enum pe_ordering order)
Definition: utils.c:488
unsigned long long flags
Definition: pe_types.h:373
const char * uname
Definition: pe_types.h:232
pe_working_set_t * data_set
#define XML_ATTR_TE_NOWAIT
Definition: msg_xml.h:427
bool pe__rsc_running_on_only(const pe_resource_t *rsc, const pe_node_t *node)
Definition: utils.c:784
void(* output_actions)(pe_resource_t *rsc)
xmlNode * create_xml_node(xmlNode *parent, const char *name)
Definition: xml.c:677
Action completed, result is known.
Definition: results.h:315
GList * actions
Definition: pe_types.h:391
G_GNUC_INTERNAL void pcmk__new_ordering(pe_resource_t *first_rsc, char *first_task, pe_action_t *first_action, pe_resource_t *then_rsc, char *then_task, pe_action_t *then_action, uint32_t flags, pe_working_set_t *data_set)
void pe__add_param_check(const xmlNode *rsc_op, pe_resource_t *rsc, pe_node_t *node, enum pe_check_parameters, pe_working_set_t *data_set)
Definition: remote.c:222
#define pcmk__clear_updated_flags(au_flags, action, flags_to_clear)
#define XML_LRM_ATTR_MIGRATE_TARGET
Definition: msg_xml.h:341
#define XML_LRM_ATTR_EXIT_REASON
Definition: msg_xml.h:333
char * uuid
Definition: pe_types.h:438
#define XML_LRM_ATTR_RESTART_DIGEST
Definition: msg_xml.h:331
void free_xml(xmlNode *child)
Definition: xml.c:813
enum pe_obj_types variant
Definition: pe_types.h:356
bool pcmk__str_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
Definition: strings.c:957
gboolean xml_has_children(const xmlNode *root)
Definition: xml.c:1726
xmlNode * input
Definition: pe_types.h:160
G_GNUC_INTERNAL GList * pcmk__rscs_matching_id(const char *id, const pe_working_set_t *data_set)
xmlNode * params_all
Definition: internal.h:509
#define CRM_OP_SHUTDOWN
Definition: crm.h:143
G_GNUC_INTERNAL void pcmk__reschedule_recurring(pe_resource_t *rsc, const char *task, guint interval_ms, pe_node_t *node)
G_GNUC_INTERNAL void pcmk__order_stops_before_shutdown(pe_node_t *node, pe_action_t *shutdown_op)
const char * id
Definition: pe_types.h:231
char * pcmk__op_key(const char *rsc_id, const char *op_type, guint interval_ms)
Generate an operation key (RESOURCE_ACTION_INTERVAL)
Definition: operations.c:42
const char * op_type
Definition: lrmd.h:223
#define CRMD_ACTION_RELOAD
Definition: crm.h:169
const char * crm_xml_add_ll(xmlNode *node, const char *name, long long value)
Create an XML attribute with specified name and long long int value.
Definition: nvpair.c:448
void pcmk__handle_rsc_config_changes(pe_working_set_t *data_set)
unsigned int t_run
Definition: lrmd.h:245
#define XML_ATTR_TRANSITION_KEY
Definition: msg_xml.h:425
#define XML_LRM_ATTR_SECURE_DIGEST
Definition: msg_xml.h:332
#define action_runnable_str(flags)
enum rsc_role_e(* state)(const pe_resource_t *, gboolean)
Definition: pe_types.h:54
#define action_optional_str(flags)
pe_node_t * pe_find_node_id(const GList *node_list, const char *id)
Find a node by ID in a list of nodes.
Definition: status.c:448
G_GNUC_INTERNAL bool pcmk__rsc_agent_changed(pe_resource_t *rsc, pe_node_t *node, const xmlNode *rsc_entry, bool active_on_node)
pcmk__action_result_t result
Definition: pcmk_fence.c:35
void add_hash_param(GHashTable *hash, const char *name, const char *value)
Definition: common.c:500
gboolean did_rsc_op_fail(lrmd_event_data_t *event, int target_rc)
Definition: operations.c:391
#define XPATH_NODE_HISTORY
#define pcmk__set_updated_flags(au_flags, action, flags_to_set)
#define crm_err(fmt, args...)
Definition: logging.h:377
#define CRM_ASSERT(expr)
Definition: results.h:42
#define RSC_STATUS
Definition: crm.h:213
Success.
Definition: results.h:167
void lrmd__set_result(lrmd_event_data_t *event, enum ocf_exitcode rc, int op_status, const char *exit_reason)
Definition: lrmd_client.c:2481
#define pe_rsc_reload
Definition: pe_types.h:288
#define RSC_PROMOTE
Definition: crm.h:205
xmlNode * input
void calculate_active_ops(const GList *sorted_op_list, int *start_index, int *stop_index)
Definition: unpack.c:2311
This structure contains everything that makes up a single output formatter.
int compare_version(const char *version1, const char *version2)
Definition: utils.c:189
#define XML_LRM_ATTR_INTERVAL_MS
Definition: msg_xml.h:313
#define XML_LRM_ATTR_CALLID
Definition: msg_xml.h:327
#define CRMD_ACTION_MIGRATE
Definition: crm.h:171
#define pe__clear_resource_flags(resource, flags_to_clear)
Definition: internal.h:83
#define XML_LRM_ATTR_OPSTATUS
Definition: msg_xml.h:325
#define XML_ATTR_CRM_VERSION
Definition: msg_xml.h:131
char * pcmk__transition_key(int transition_id, int action_id, int target_rc, const char *node)
Definition: operations.c:250
void pcmk__log_action(const char *pre_text, const pe_action_t *action, bool details)
G_GNUC_INTERNAL void pcmk__schedule_cancel(pe_resource_t *rsc, const char *call_id, const char *task, guint interval_ms, const pe_node_t *node, const char *reason)
rsc_role_e
Possible roles that a resource can be in.
Definition: common.h:92
GList * running_on
Definition: pe_types.h:398
#define pe_rsc_block
Definition: pe_types.h:274
enum pe_action_flags flags
Definition: pe_types.h:442
gboolean maintenance
Definition: pe_types.h:245
#define XML_LRM_ATTR_RC
Definition: msg_xml.h:326
#define pe_rsc_maintenance
Definition: pe_types.h:308
pe_working_set_t * cluster
Definition: pe_types.h:353
Action is in progress.
Definition: results.h:314
const char * pcmk__readable_interval(guint interval_ms)
Definition: iso8601.c:1926
#define XML_LRM_ATTR_TARGET
Definition: msg_xml.h:317
#define XML_LRM_TAG_RSC_OP
Definition: msg_xml.h:281
#define pe_rsc_trace(rsc, fmt, args...)
Definition: internal.h:50
#define pe__set_order_flags(order_flags, flags_to_set)
Definition: internal.h:141
#define ID(x)
Definition: msg_xml.h:480
unsigned long long flags
Definition: pe_types.h:169
#define FAKE_TE_ID
const char * parent
Definition: cib.c:25
uint32_t(* update_ordered_actions)(pe_action_t *first, pe_action_t *then, const pe_node_t *node, uint32_t flags, uint32_t filter, uint32_t type, pe_working_set_t *data_set)
#define PCMK__OP_FMT
Definition: internal.h:170
#define XML_LRM_ATTR_MIGRATE_SOURCE
Definition: msg_xml.h:340
G_GNUC_INTERNAL void pcmk__block_colocation_dependents(pe_action_t *action, pe_working_set_t *data_set)
int pe_get_failcount(const pe_node_t *node, pe_resource_t *rsc, time_t *last_failure, uint32_t flags, const xmlNode *xml_op)
Definition: failcounts.c:275
pe_action_t * custom_action(pe_resource_t *rsc, char *key, const char *task, const pe_node_t *on_node, gboolean optional, gboolean foo, pe_working_set_t *data_set)
Create or update an action object.
Definition: pe_actions.c:942
op_digest_cache_t * rsc_action_digest_cmp(pe_resource_t *rsc, const xmlNode *xml_op, pe_node_t *node, pe_working_set_t *data_set)
Definition: pe_digest.c:381
enum pe_ordering type
Definition: pe_types.h:555
pe_action_t * pcmk__new_shutdown_action(pe_node_t *node)
#define XML_TAG_PARAMS
Definition: msg_xml.h:225
#define pe_rsc_managed
Definition: pe_types.h:273
#define pe_rsc_orphan
Definition: pe_types.h:272
uint64_t flags
Definition: remote.c:215
GList * actions_before
Definition: pe_types.h:470
int required_runnable_before
Definition: pe_types.h:468
action_tasks
Definition: common.h:61
pe_resource_t * parent
Definition: pe_types.h:354
guint interval_ms
Definition: lrmd.h:232
char * id
Definition: pe_types.h:347
#define RSC_MIGRATED
Definition: crm.h:197
#define CRMD_ACTION_STATUS
Definition: crm.h:188
xmlNode * crm_next_same_xml(const xmlNode *sibling)
Get next instance of same XML tag.
Definition: xml.c:2547