pacemaker  3.0.0-d8340737c4
Scalable High-Availability cluster resource manager
actions_internal.h
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2024 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 Lesser General Public License
7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8  */
9 
10 #ifndef PCMK__CRM_COMMON_ACTIONS_INTERNAL__H
11 #define PCMK__CRM_COMMON_ACTIONS_INTERNAL__H
12 
13 #include <stdbool.h> // bool
14 #include <stdint.h> // uint32_t, UINT32_C()
15 #include <glib.h> // guint, GList, GHashTable
16 #include <libxml/tree.h> // xmlNode
17 
18 #include <crm/common/actions.h> // PCMK_ACTION_MONITOR
19 #include <crm/common/roles.h> // enum rsc_role_e
20 #include <crm/common/scheduler_types.h> // pcmk_resource_t, pcmk_node_t
21 #include <crm/common/strings_internal.h> // pcmk__str_eq()
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
28 #define PCMK__OP_FMT "%s_%s_%u"
29 
37 #define pcmk__set_action_flags(action, flags_to_set) do { \
38  (action)->flags = pcmk__set_flags_as(__func__, __LINE__, \
39  LOG_TRACE, \
40  "Action", (action)->uuid, \
41  (action)->flags, \
42  (flags_to_set), \
43  #flags_to_set); \
44  } while (0)
45 
53 #define pcmk__clear_action_flags(action, flags_to_clear) do { \
54  (action)->flags = pcmk__clear_flags_as(__func__, __LINE__, \
55  LOG_TRACE, \
56  "Action", (action)->uuid, \
57  (action)->flags, \
58  (flags_to_clear), \
59  #flags_to_clear); \
60  } while (0)
61 
70 #define pcmk__set_raw_action_flags(action_flags, action_name, to_set) do { \
71  action_flags = pcmk__set_flags_as(__func__, __LINE__, \
72  LOG_TRACE, "Action", action_name, \
73  (action_flags), \
74  (to_set), #to_set); \
75  } while (0)
76 
85 #define pcmk__clear_raw_action_flags(action_flags, action_name, to_clear) \
86  do { \
87  action_flags = pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, \
88  "Action", action_name, \
89  (action_flags), \
90  (to_clear), #to_clear); \
91  } while (0)
92 
93 // Possible actions (including some pseudo-actions)
95  pcmk__action_unspecified = 0, // Unspecified or unknown action
97 
98  // Each "completed" action must be the regular action plus 1
99 
101  pcmk__action_stopped, // Stop completed
102 
104  pcmk__action_started, // Start completed
105 
107  pcmk__action_notified, // Notify completed
108 
111 
114 
115  pcmk__action_shutdown, // Shut down node
116  pcmk__action_fence, // Fence node
117 };
118 
119 // Action scheduling flags
121  // No action flags set (compare with equality rather than bit set)
123 
124  // Whether action does not require invoking an agent
125  pcmk__action_pseudo = (UINT32_C(1) << 0),
126 
127  // Whether action is runnable
128  pcmk__action_runnable = (UINT32_C(1) << 1),
129 
130  // Whether action should not be executed
131  pcmk__action_optional = (UINT32_C(1) << 2),
132 
133  // Whether action should be added to transition graph even if optional
134  pcmk__action_always_in_graph = (UINT32_C(1) << 3),
135 
136  // Whether operation-specific instance attributes have been unpacked yet
137  pcmk__action_attrs_evaluated = (UINT32_C(1) << 4),
138 
139  // Whether action is allowed to be part of a live migration
140  pcmk__action_migratable = (UINT32_C(1) << 7),
141 
142  // Whether action has been added to transition graph
143  pcmk__action_added_to_graph = (UINT32_C(1) << 8),
144 
145  // Whether action is a stop to abort a dangling migration
146  pcmk__action_migration_abort = (UINT32_C(1) << 11),
147 
148  // Whether action is recurring monitor that must be rescheduled if active
149  pcmk__action_reschedule = (UINT32_C(1) << 13),
150 
151  // Whether action has already been processed by a recursive procedure
152  pcmk__action_detect_loop = (UINT32_C(1) << 14),
153 
154  // Whether action's inputs have been de-duplicated yet
155  pcmk__action_inputs_deduplicated = (UINT32_C(1) << 15),
156 
157  // Whether action can be executed on DC rather than own node
158  pcmk__action_on_dc = (UINT32_C(1) << 16),
159 };
160 
161 /* Possible responses to a resource action failure
162  *
163  * The order is significant; the values are in order of increasing severity so
164  * that they can be compared with less than and greater than.
165  */
167  pcmk__on_fail_ignore, // Act as if failure didn't happen
168  pcmk__on_fail_demote, // Demote if promotable, else stop
169  pcmk__on_fail_restart, // Restart resource
170 
171  /* Fence the remote node created by the resource if fencing is enabled,
172  * otherwise attempt to restart the resource (used internally for some
173  * remote connection failures).
174  */
176 
177  pcmk__on_fail_restart_container, // Restart resource's container
178  pcmk__on_fail_ban, // Ban resource from current node
179  pcmk__on_fail_block, // Treat resource as unmanaged
180  pcmk__on_fail_stop, // Stop resource and leave stopped
181  pcmk__on_fail_standby_node, // Put resource's node in standby
182  pcmk__on_fail_fence_node, // Fence resource's node
183 };
184 
185 // What resource needs before it can be recovered from a failed node
187  pcmk__requires_nothing = 0, // Resource can be recovered immediately
188  pcmk__requires_quorum = 1, // Resource can be recovered if quorate
189  pcmk__requires_fencing = 2, // Resource can be recovered after fencing
190 };
191 
192 // Implementation of pcmk_action_t
193 struct pcmk__action {
194  int id; // Counter to identify action
195 
196  /*
197  * When the controller aborts a transition graph, it sets an abort priority.
198  * If this priority is higher, the action will still be executed anyway.
199  * Pseudo-actions are always allowed, so this is irrelevant for them.
200  */
201  int priority;
202 
203  pcmk_resource_t *rsc; // Resource to apply action to, if any
204  pcmk_node_t *node; // Copy of node to execute action on, if any
205  xmlNode *op_entry; // Action XML configuration, if any
206  char *task; // Action name
207  char *uuid; // Action key
208  char *cancel_task; // If task is "cancel", the action being cancelled
209  char *reason; // Readable description of why action is needed
210  uint32_t flags; // Group of enum pcmk__action_flags
211  enum pcmk__requires needs; // Prerequisite for recovery
212  enum pcmk__on_fail on_fail; // Response to failure
213  enum rsc_role_e fail_role; // Resource role if action fails
214  GHashTable *meta; // Meta-attributes relevant to action
215  GHashTable *extra; // Action-specific instance attributes
216  pcmk_scheduler_t *scheduler; // Scheduler data this action is part of
217 
218  /* Current count of runnable instance actions for "first" action in an
219  * ordering dependency with pcmk__ar_min_runnable set.
220  */
222 
223  /*
224  * Number of instance actions for "first" action in an ordering dependency
225  * with pcmk__ar_min_runnable set that must be runnable before this action
226  * can be runnable.
227  */
229 
230  // Actions in a relation with this one (as pcmk__related_action_t *)
233 };
234 
235 char *pcmk__op_key(const char *rsc_id, const char *op_type, guint interval_ms);
236 char *pcmk__notify_key(const char *rsc_id, const char *notify_type,
237  const char *op_type);
238 char *pcmk__transition_key(int transition_id, int action_id, int target_rc,
239  const char *node);
240 void pcmk__filter_op_for_digest(xmlNode *param_set);
241 bool pcmk__is_fencing_action(const char *action);
242 enum pcmk__action_type pcmk__parse_action(const char *action_name);
243 const char *pcmk__action_text(enum pcmk__action_type action);
244 const char *pcmk__on_fail_text(enum pcmk__on_fail on_fail);
245 
246 
256 static inline const char *
257 pcmk__readable_action(const char *action_name, guint interval_ms) {
258  if ((interval_ms == 0)
259  && pcmk__str_eq(action_name, PCMK_ACTION_MONITOR, pcmk__str_none)) {
260  return "probe";
261  }
262  return action_name;
263 }
264 
265 #ifdef __cplusplus
266 }
267 #endif
268 
269 #endif // PCMK__CRM_COMMON_ACTIONS_INTERNAL__H
pcmk__action_type
void pcmk__filter_op_for_digest(xmlNode *param_set)
Definition: digest.c:299
Type aliases needed to define scheduler objects.
APIs related to actions.
#define PCMK_ACTION_MONITOR
Definition: actions.h:51
enum rsc_role_e fail_role
const char * action
Definition: pcmk_fence.c:32
enum pcmk__on_fail on_fail
pcmk__on_fail
GList * actions_after
GHashTable * extra
char * pcmk__transition_key(int transition_id, int action_id, int target_rc, const char *node)
Definition: actions.c:402
Scheduler API for resource roles.
pcmk_scheduler_t * scheduler
pcmk__action_flags
GList * actions_before
rsc_role_e
Definition: roles.h:34
enum pcmk__requires needs
char * pcmk__op_key(const char *rsc_id, const char *op_type, guint interval_ms)
Generate an operation key (RESOURCE_ACTION_INTERVAL)
Definition: actions.c:195
const char * pcmk__on_fail_text(enum pcmk__on_fail on_fail)
Definition: actions.c:146
char * pcmk__notify_key(const char *rsc_id, const char *notify_type, const char *op_type)
Definition: actions.c:335
pcmk_node_t * node
int required_runnable_before
bool pcmk__is_fencing_action(const char *action)
Definition: actions.c:581
pcmk_resource_t * rsc
enum pcmk__action_type pcmk__parse_action(const char *action_name)
Definition: actions.c:90
const char * pcmk__action_text(enum pcmk__action_type action)
Definition: actions.c:34
GHashTable * meta
xmlNode * op_entry
pcmk__requires