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 Lesser General Public License
7 * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8 */
9
10 #ifndef PCMK__CRM_COMMON_ACTIONS__H
11 #define PCMK__CRM_COMMON_ACTIONS__H
12
13 #include <stdbool.h> // bool
14 #include <strings.h> // strcasecmp()
15 #include <glib.h> // gboolean, guint
16 #include <libxml/tree.h> // xmlNode
17
18 #include <crm/lrmd_events.h> // lrmd_event_data_t
19
20 #include <glib.h> // GList, GHashTable
21 #include <libxml/tree.h> // xmlNode
22
23 #include <crm/common/nodes.h>
24 #include <crm/common/resources.h> // enum rsc_start_requirement, etc.
25 #include <crm/common/scheduler_types.h> // pcmk_resource_t, pcmk_node_t
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 /*!
32 * \file
33 * \brief APIs related to actions
34 * \ingroup core
35 */
36
37 //! Default timeout (in milliseconds) for non-metadata actions
38 #define PCMK_DEFAULT_ACTION_TIMEOUT_MS 20000
39
40 // @COMPAT We don't need a separate timeout for metadata, much less a longer one
41 //! \deprecated Default timeout (in milliseconds) for metadata actions
42 #define PCMK_DEFAULT_METADATA_TIMEOUT_MS 30000
43
44 // Action names as strings
45 #define PCMK_ACTION_CANCEL "cancel"
46 #define PCMK_ACTION_CLEAR_FAILCOUNT "clear_failcount"
47 #define PCMK_ACTION_CLONE_ONE_OR_MORE "clone-one-or-more"
48 #define PCMK_ACTION_DELETE "delete"
49 #define PCMK_ACTION_DEMOTE "demote"
50 #define PCMK_ACTION_DEMOTED "demoted"
51 #define PCMK_ACTION_DO_SHUTDOWN "do_shutdown"
52 #define PCMK_ACTION_LIST "list"
53 #define PCMK_ACTION_LRM_DELETE "lrm_delete"
54 #define PCMK_ACTION_LOAD_STOPPED "load_stopped"
55 #define PCMK_ACTION_MAINTENANCE_NODES "maintenance_nodes"
56 #define PCMK_ACTION_META_DATA "meta-data"
57 #define PCMK_ACTION_MIGRATE_FROM "migrate_from"
58 #define PCMK_ACTION_MIGRATE_TO "migrate_to"
59 #define PCMK_ACTION_MONITOR "monitor"
60 #define PCMK_ACTION_NOTIFIED "notified"
61 #define PCMK_ACTION_NOTIFY "notify"
62 #define PCMK_ACTION_OFF "off"
63 #define PCMK_ACTION_ON "on"
64 #define PCMK_ACTION_ONE_OR_MORE "one-or-more"
65 #define PCMK_ACTION_PROMOTE "promote"
66 #define PCMK_ACTION_PROMOTED "promoted"
67 #define PCMK_ACTION_REBOOT "reboot"
68 #define PCMK_ACTION_RELOAD "reload"
69 #define PCMK_ACTION_RELOAD_AGENT "reload-agent"
70 #define PCMK_ACTION_RUNNING "running"
71 #define PCMK_ACTION_START "start"
72 #define PCMK_ACTION_STATUS "status"
73 #define PCMK_ACTION_STONITH "stonith"
74 #define PCMK_ACTION_STOP "stop"
75 #define PCMK_ACTION_STOPPED "stopped"
76 #define PCMK_ACTION_VALIDATE_ALL "validate-all"
77
78 //! Possible actions (including some pseudo-actions)
79 enum action_tasks {
80 pcmk_action_unspecified = 0, //!< Unspecified or unknown action
81 pcmk_action_monitor, //!< Monitor
82
83 // Each "completed" action must be the regular action plus 1
84
85 pcmk_action_stop, //!< Stop
86 pcmk_action_stopped, //!< Stop completed
87
88 pcmk_action_start, //!< Start
89 pcmk_action_started, //!< Start completed
90
91 pcmk_action_notify, //!< Notify
92 pcmk_action_notified, //!< Notify completed
93
94 pcmk_action_promote, //!< Promote
95 pcmk_action_promoted, //!< Promoted
96
97 pcmk_action_demote, //!< Demote
98 pcmk_action_demoted, //!< Demoted
99
100 pcmk_action_shutdown, //!< Shut down node
101 pcmk_action_fence, //!< Fence node
102
103 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
104 //! \deprecated Use pcmk_action_unspecified instead
105 no_action = pcmk_action_unspecified,
106
107 //! \deprecated Use pcmk_action_monitor instead
108 monitor_rsc = pcmk_action_monitor,
109
110 //! \deprecated Use pcmk_action_stop instead
111 stop_rsc = pcmk_action_stop,
112
113 //! \deprecated Use pcmk_action_stopped instead
114 stopped_rsc = pcmk_action_stopped,
115
116 //! \deprecated Use pcmk_action_start instead
117 start_rsc = pcmk_action_start,
118
119 //! \deprecated Use pcmk_action_started instead
120 started_rsc = pcmk_action_started,
121
122 //! \deprecated Use pcmk_action_notify instead
123 action_notify = pcmk_action_notify,
124
125 //! \deprecated Use pcmk_action_notified instead
126 action_notified = pcmk_action_notified,
127
128 //! \deprecated Use pcmk_action_promote instead
129 action_promote = pcmk_action_promote,
130
131 //! \deprecated Use pcmk_action_promoted instead
132 action_promoted = pcmk_action_promoted,
133
134 //! \deprecated Use pcmk_action_demote instead
135 action_demote = pcmk_action_demote,
136
137 //! \deprecated Use pcmk_action_demoted instead
138 action_demoted = pcmk_action_demoted,
139
140 //! \deprecated Use pcmk_action_shutdown instead
141 shutdown_crm = pcmk_action_shutdown,
142
143 //! \deprecated Use pcmk_action_fence instead
144 stonith_node = pcmk_action_fence,
145 #endif
146 };
147
148 //! Possible responses to a resource action failure
149 enum action_fail_response {
150 /* The order is (partially) significant here; the values from
151 * pcmk_on_fail_ignore through pcmk_on_fail_fence_node are in order of
152 * increasing severity.
153 *
154 * @COMPAT The values should be ordered and numbered per the "TODO" comments
155 * below, so all values are in order of severity and there is room for
156 * future additions, but that would break API compatibility.
157 * @TODO For now, we just use a function to compare the values specially, but
158 * at the next compatibility break, we should arrange things
159 * properly so we can compare with less than and greater than.
160 */
161
162 // @TODO Define as 10
163 pcmk_on_fail_ignore = 0, //!< Act as if failure didn't happen
164
165 // @TODO Define as 30
166 pcmk_on_fail_restart = 1, //!< Restart resource
167
168 // @TODO Define as 60
169 pcmk_on_fail_ban = 2, //!< Ban resource from current node
170
171 // @TODO Define as 70
172 pcmk_on_fail_block = 3, //!< Treat resource as unmanaged
173
174 // @TODO Define as 80
175 pcmk_on_fail_stop = 4, //!< Stop resource and leave stopped
176
177 // @TODO Define as 90
178 pcmk_on_fail_standby_node = 5, //!< Put resource's node in standby
179
180 // @TODO Define as 100
181 pcmk_on_fail_fence_node = 6, //!< Fence resource's node
182
183 // @COMPAT Values below here are out of desired order for API compatibility
184
185 // @TODO Define as 50
186 pcmk_on_fail_restart_container = 7, //!< Restart resource's container
187
188 // @TODO Define as 40
189 /*!
190 * Fence the remote node created by the resource if fencing is enabled,
191 * otherwise attempt to restart the resource (used internally for some
192 * remote connection failures).
193 */
194 pcmk_on_fail_reset_remote = 8,
195
196 // @TODO Define as 20
197 pcmk_on_fail_demote = 9, //!< Demote if promotable, else stop
198
199 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
200 //! \deprecated Use pcmk_on_fail_ignore instead
201 action_fail_ignore = pcmk_on_fail_ignore,
202
203 //! \deprecated Use pcmk_on_fail_restart instead
204 action_fail_recover = pcmk_on_fail_restart,
205
206 //! \deprecated Use pcmk_on_fail_ban instead
207 action_fail_migrate = pcmk_on_fail_ban,
208
209 //! \deprecated Use pcmk_on_fail_block instead
210 action_fail_block = pcmk_on_fail_block,
211
212 //! \deprecated Use pcmk_on_fail_stop instead
213 action_fail_stop = pcmk_on_fail_stop,
214
215 //! \deprecated Use pcmk_on_fail_standby_node instead
216 action_fail_standby = pcmk_on_fail_standby_node,
217
218 //! \deprecated Use pcmk_on_fail_fence_node instead
219 action_fail_fence = pcmk_on_fail_fence_node,
220
221 //! \deprecated Use pcmk_on_fail_restart_container instead
222 action_fail_restart_container = pcmk_on_fail_restart_container,
223
224 //! \deprecated Use pcmk_on_fail_reset_remote instead
225 action_fail_reset_remote = pcmk_on_fail_reset_remote,
226
227 //! \deprecated Use pcmk_on_fail_demote instead
228 action_fail_demote = pcmk_on_fail_demote,
229 #endif
230 };
231
232 //! Action scheduling flags
233 enum pe_action_flags {
234 //! No action flags set (compare with equality rather than bit set)
235 pcmk_no_action_flags = 0,
236
237 //! Whether action does not require invoking an agent
238 pcmk_action_pseudo = (1 << 0),
239
240 //! Whether action is runnable
241 pcmk_action_runnable = (1 << 1),
242
243 //! Whether action should not be executed
244 pcmk_action_optional = (1 << 2),
245
246 //! Whether action should be added to transition graph even if optional
247 pcmk_action_always_in_graph = (1 << 3),
248
249 //! Whether operation-specific instance attributes have been unpacked yet
250 pcmk_action_attrs_evaluated = (1 << 4),
251
252 //! Whether action is allowed to be part of a live migration
253 pcmk_action_migratable = (1 << 7),
254
255 //! Whether action has been added to transition graph
256 pcmk_action_added_to_graph = (1 << 8),
257
258 //! Whether action is a stop to abort a dangling migration
259 pcmk_action_migration_abort = (1 << 11),
260
261 /*!
262 * Whether action is an ordering point for minimum required instances
263 * (used to implement ordering after clones with clone-min configured,
264 * and ordered sets with require-all=false)
265 */
266 pcmk_action_min_runnable = (1 << 12),
267
268 //! Whether action is recurring monitor that must be rescheduled if active
269 pcmk_action_reschedule = (1 << 13),
270
271 //! Whether action has already been processed by a recursive procedure
272 pcmk_action_detect_loop = (1 << 14),
273
274 //! Whether action's inputs have been de-duplicated yet
275 pcmk_action_inputs_deduplicated = (1 << 15),
276
277 //! Whether action can be executed on DC rather than own node
278 pcmk_action_on_dc = (1 << 16),
279
280 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
281 //! \deprecated Use pcmk_action_pseudo instead
282 pe_action_pseudo = pcmk_action_pseudo,
283
284 //! \deprecated Use pcmk_action_runnable instead
285 pe_action_runnable = pcmk_action_runnable,
286
287 //! \deprecated Use pcmk_action_optional instead
288 pe_action_optional = pcmk_action_optional,
289
290 //! \deprecated Use pcmk_action_always_in_graph instead
291 pe_action_print_always = pcmk_action_always_in_graph,
292
293 //! \deprecated Use pcmk_action_attrs_evaluated instead
294 pe_action_have_node_attrs = pcmk_action_attrs_evaluated,
295
296 //! \deprecated Do not use
297 pe_action_implied_by_stonith = (1 << 6),
298
299 //! \deprecated Use pcmk_action_migratable instead
300 pe_action_migrate_runnable = pcmk_action_migratable,
301
302 //! \deprecated Use pcmk_action_added_to_graph instead
303 pe_action_dumped = pcmk_action_added_to_graph,
304
305 //! \deprecated Do not use
306 pe_action_processed = (1 << 9),
307
308 //! \deprecated Do not use
309 pe_action_clear = (1 << 10),
310
311 //! \deprecated Use pcmk_action_migration_abort instead
312 pe_action_dangle = pcmk_action_migration_abort,
313
314 //! \deprecated Use pcmk_action_min_runnable instead
315 pe_action_requires_any = pcmk_action_min_runnable,
316
317 //! \deprecated Use pcmk_action_reschedule instead
318 pe_action_reschedule = pcmk_action_reschedule,
319
320 //! \deprecated Use pcmk_action_detect_loop instead
321 pe_action_tracking = pcmk_action_detect_loop,
322
323 //! \deprecated Use pcmk_action_inputs_deduplicated instead
324 pe_action_dedup = pcmk_action_inputs_deduplicated,
325
326 //! \deprecated Use pcmk_action_on_dc instead
327 pe_action_dc = pcmk_action_on_dc,
328 #endif
329 };
330
331 /* @COMPAT enum pe_link_state and enum pe_ordering are currently needed for
332 * struct pe_action_wrapper_s (which is public) but should be removed at an
333 * API compatibility break when that can be refactored and made internal
334 */
335
336 //!@{
337 //! \deprecated Do not use
338 enum pe_link_state {
339 pe_link_not_dumped = 0,
340 pe_link_dumped = 1,
341 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
342 pe_link_dup = 2,
343 #endif
344 };
345
346 enum pe_ordering {
347 pe_order_none = 0x0,
348 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
349 pe_order_optional = 0x1,
350 pe_order_apply_first_non_migratable = 0x2,
351 pe_order_implies_first = 0x10,
352 pe_order_implies_then = 0x20,
353 pe_order_promoted_implies_first = 0x40,
354 pe_order_implies_first_migratable = 0x80,
355 pe_order_runnable_left = 0x100,
356 pe_order_pseudo_left = 0x200,
357 pe_order_implies_then_on_node = 0x400,
358 pe_order_probe = 0x800,
359 pe_order_restart = 0x1000,
360 pe_order_stonith_stop = 0x2000,
361 pe_order_serialize_only = 0x4000,
362 pe_order_same_node = 0x8000,
363 pe_order_implies_first_printed = 0x10000,
364 pe_order_implies_then_printed = 0x20000,
365 pe_order_asymmetrical = 0x100000,
366 pe_order_load = 0x200000,
367 pe_order_one_or_more = 0x400000,
368 pe_order_anti_colocation = 0x800000,
369 pe_order_preserve = 0x1000000,
370 pe_order_then_cancels_first = 0x2000000,
371 pe_order_trace = 0x4000000,
372 pe_order_implies_first_master = pe_order_promoted_implies_first,
373 #endif
374 };
375
376 // Action sequenced relative to another action
377 // @COMPAT This should be internal
378 struct pe_action_wrapper_s {
379 // @COMPAT This should be uint32_t
380 enum pe_ordering type; // Group of enum pcmk__action_relation_flags
381
382 // @COMPAT This should be a bool
383 enum pe_link_state state; // Whether action has been added to graph yet
384
385 pcmk_action_t *action; // Action to be sequenced
386 };
387 //!@}
388
389 //! Implementation of pcmk_action_t
390 struct pe_action_s {
391 int id; //!< Counter to identify action
392
393 /*!
394 * When the controller aborts a transition graph, it sets an abort priority.
395 * If this priority is higher, the action will still be executed anyway.
396 * Pseudo-actions are always allowed, so this is irrelevant for them.
397 */
398 int priority;
399
400 pcmk_resource_t *rsc; //!< Resource to apply action to, if any
401 pcmk_node_t *node; //!< Node to execute action on, if any
402 xmlNode *op_entry; //!< Action XML configuration, if any
403 char *task; //!< Action name
404 char *uuid; //!< Action key
405 char *cancel_task; //!< If task is "cancel", the action being cancelled
406 char *reason; //!< Readable description of why action is needed
407
408 //@ COMPAT Change to uint32_t at a compatibility break
409 enum pe_action_flags flags; //!< Group of enum pe_action_flags
410
411 enum rsc_start_requirement needs; //!< Prerequisite for recovery
412 enum action_fail_response on_fail; //!< Response to failure
413 enum rsc_role_e fail_role; //!< Resource role if action fails
414 GHashTable *meta; //!< Meta-attributes relevant to action
415 GHashTable *extra; //!< Action-specific instance attributes
416
417 /* Current count of runnable instance actions for "first" action in an
418 * ordering dependency with pcmk__ar_min_runnable set.
419 */
420 int runnable_before; //!< For Pacemaker use only
421
422 /*!
423 * Number of instance actions for "first" action in an ordering dependency
424 * with pcmk__ar_min_runnable set that must be runnable before this action
425 * can be runnable.
426 */
427 int required_runnable_before;
428
429 // Actions in a relation with this one (as pcmk__related_action_t *)
430 GList *actions_before; //!< For Pacemaker use only
431 GList *actions_after; //!< For Pacemaker use only
432
433 /* This is intended to hold data that varies by the type of action, but is
434 * not currently used. Some of the above fields could be moved here except
435 * for API backward compatibility.
436 */
437 void *action_details; //!< For Pacemaker use only
438 };
439
440 // For parsing various action-related string specifications
441 gboolean parse_op_key(const char *key, char **rsc_id, char **op_type,
442 guint *interval_ms);
443 gboolean decode_transition_key(const char *key, char **uuid, int *transition_id,
444 int *action_id, int *target_rc);
445 gboolean decode_transition_magic(const char *magic, char **uuid,
446 int *transition_id, int *action_id,
447 int *op_status, int *op_rc, int *target_rc);
448
449 // @COMPAT Either these shouldn't be in libcrmcommon or lrmd_event_data_t should
450 int rsc_op_expected_rc(const lrmd_event_data_t *event);
451 gboolean did_rsc_op_fail(lrmd_event_data_t *event, int target_rc);
452
453 bool crm_op_needs_metadata(const char *rsc_class, const char *op);
454
455 xmlNode *crm_create_op_xml(xmlNode *parent, const char *prefix,
456 const char *task, const char *interval_spec,
457 const char *timeout);
458
459 bool pcmk_is_probe(const char *task, guint interval);
460 bool pcmk_xe_is_probe(const xmlNode *xml_op);
461 bool pcmk_xe_mask_probe_failure(const xmlNode *xml_op);
462
463 #ifdef __cplusplus
464 }
465 #endif
466
467 #endif // PCMK__CRM_COMMON_ACTIONS__H