pacemaker  2.1.8-3980678f03
Scalable High-Availability cluster resource manager
actions.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__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 
37 #define PCMK_DEFAULT_ACTION_TIMEOUT_MS 20000
39 
40 // @COMPAT We don't need a separate timeout for metadata, much less a longer one
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_METADATA "metadata"
58 #define PCMK_ACTION_MIGRATE_FROM "migrate_from"
59 #define PCMK_ACTION_MIGRATE_TO "migrate_to"
60 #define PCMK_ACTION_MONITOR "monitor"
61 #define PCMK_ACTION_NOTIFIED "notified"
62 #define PCMK_ACTION_NOTIFY "notify"
63 #define PCMK_ACTION_OFF "off"
64 #define PCMK_ACTION_ON "on"
65 #define PCMK_ACTION_ONE_OR_MORE "one-or-more"
66 #define PCMK_ACTION_PROMOTE "promote"
67 #define PCMK_ACTION_PROMOTED "promoted"
68 #define PCMK_ACTION_REBOOT "reboot"
69 #define PCMK_ACTION_RELOAD "reload"
70 #define PCMK_ACTION_RELOAD_AGENT "reload-agent"
71 #define PCMK_ACTION_RUNNING "running"
72 #define PCMK_ACTION_START "start"
73 #define PCMK_ACTION_STATUS "status"
74 #define PCMK_ACTION_STONITH "stonith"
75 #define PCMK_ACTION_STOP "stop"
76 #define PCMK_ACTION_STOPPED "stopped"
77 #define PCMK_ACTION_VALIDATE_ALL "validate-all"
78 
79 // Possible actions (including some pseudo-actions)
80 // @COMPAT Make this internal when we can break API backward compatibility
84  pcmk_action_unspecified = 0, // Unspecified or unknown action
85  pcmk_action_monitor, // Monitor
86 
87  // Each "completed" action must be the regular action plus 1
88 
90  pcmk_action_stopped, // Stop completed
91 
93  pcmk_action_started, // Start completed
94 
95  pcmk_action_notify, // Notify
96  pcmk_action_notified, // Notify completed
97 
98  pcmk_action_promote, // Promote
99  pcmk_action_promoted, // Promoted
100 
103 
104  pcmk_action_shutdown, // Shut down node
105  pcmk_action_fence, // Fence node
106 
107 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
122 #endif
123 };
125 
126 // Possible responses to a resource action failure
127 // @COMPAT Make this internal when we can break API backward compatibility
131  /* The order is (partially) significant here; the values from
132  * pcmk_on_fail_ignore through pcmk_on_fail_fence_node are in order of
133  * increasing severity.
134  *
135  * @COMPAT The values should be ordered and numbered per the "TODO" comments
136  * below, so all values are in order of severity and there is room for
137  * future additions, but that would break API compatibility.
138  * @TODO For now, we just use a function to compare the values specially, but
139  * at the next compatibility break, we should arrange things
140  * properly so we can compare with less than and greater than.
141  */
142 
143  // @TODO Define as 10
144  pcmk_on_fail_ignore = 0, // Act as if failure didn't happen
145 
146  // @TODO Define as 30
147  pcmk_on_fail_restart = 1, // Restart resource
148 
149  // @TODO Define as 60
150  pcmk_on_fail_ban = 2, // Ban resource from current node
151 
152  // @TODO Define as 70
153  pcmk_on_fail_block = 3, // Treat resource as unmanaged
154 
155  // @TODO Define as 80
156  pcmk_on_fail_stop = 4, // Stop resource and leave stopped
157 
158  // @TODO Define as 90
159  pcmk_on_fail_standby_node = 5, // Put resource's node in standby
160 
161  // @TODO Define as 100
162  pcmk_on_fail_fence_node = 6, // Fence resource's node
163 
164  // @COMPAT Values below here are out of desired order for API compatibility
165 
166  // @TODO Define as 50
167  pcmk_on_fail_restart_container = 7, // Restart resource's container
168 
169  // @TODO Define as 40
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  // @TODO Define as 20
178  pcmk_on_fail_demote = 9, // Demote if promotable, else stop
179 
180 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
191 #endif
192 };
194 
195 // Action scheduling flags
196 // @COMPAT Make this internal when we can break API backward compatibility
200  // No action flags set (compare with equality rather than bit set)
202 
203  // Whether action does not require invoking an agent
204  pcmk_action_pseudo = (1 << 0),
205 
206  // Whether action is runnable
208 
209  // Whether action should not be executed
211 
212  // Whether action should be added to transition graph even if optional
214 
215  // Whether operation-specific instance attributes have been unpacked yet
217 
218  // Whether action is allowed to be part of a live migration
220 
221  // Whether action has been added to transition graph
223 
224  // Whether action is a stop to abort a dangling migration
226 
227  /*
228  * Whether action is an ordering point for minimum required instances
229  * (used to implement ordering after clones with \c PCMK_META_CLONE_MIN
230  * configured, and ordered sets with \c PCMK_XA_REQUIRE_ALL set to
231  * \c PCMK_VALUE_FALSE).
232  */
234 
235  // Whether action is recurring monitor that must be rescheduled if active
237 
238  // Whether action has already been processed by a recursive procedure
240 
241  // Whether action's inputs have been de-duplicated yet
243 
244  // Whether action can be executed on DC rather than own node
245  pcmk_action_on_dc = (1 << 16),
246 
247 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
257  pe_action_clear = (1 << 10),
264 #endif
265 };
267 
268 /* @COMPAT enum pe_link_state and enum pe_ordering are currently needed for
269  * struct pe_action_wrapper_s (which is public) but should be removed at an
270  * API compatibility break when that can be refactored and made internal
271  */
272 
278 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
280 #endif
281 };
282 
285 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
295  pe_order_probe = 0x800,
303  pe_order_load = 0x200000,
306  pe_order_preserve = 0x1000000,
308  pe_order_trace = 0x4000000,
310 #endif
311 };
312 
313 // Action sequenced relative to another action
314 // @COMPAT This should be internal
316  // @COMPAT This should be uint32_t
317  enum pe_ordering type; // Group of enum pcmk__action_relation_flags
318 
319  // @COMPAT This should be a bool
320  enum pe_link_state state; // Whether action has been added to graph yet
321 
322  pcmk_action_t *action; // Action to be sequenced
323 };
325 
326 // Implementation of pcmk_action_t
327 // @COMPAT Make this internal when we can break API backward compatibility
330 struct pe_action_s {
331  int id; // Counter to identify action
332 
333  /*
334  * When the controller aborts a transition graph, it sets an abort priority.
335  * If this priority is higher, the action will still be executed anyway.
336  * Pseudo-actions are always allowed, so this is irrelevant for them.
337  */
338  int priority;
339 
340  pcmk_resource_t *rsc; // Resource to apply action to, if any
341  pcmk_node_t *node; // Node to execute action on, if any
342  xmlNode *op_entry; // Action XML configuration, if any
343  char *task; // Action name
344  char *uuid; // Action key
345  char *cancel_task; // If task is "cancel", the action being cancelled
346  char *reason; // Readable description of why action is needed
347 
348  //@ COMPAT Change to uint32_t at a compatibility break
349  enum pe_action_flags flags; // Group of enum pe_action_flags
350 
351  enum rsc_start_requirement needs; // Prerequisite for recovery
352  enum action_fail_response on_fail; // Response to failure
353  enum rsc_role_e fail_role; // Resource role if action fails
354  GHashTable *meta; // Meta-attributes relevant to action
355  GHashTable *extra; // Action-specific instance attributes
356 
357  /* Current count of runnable instance actions for "first" action in an
358  * ordering dependency with pcmk__ar_min_runnable set.
359  */
360  int runnable_before; // For Pacemaker use only
361 
362  /*
363  * Number of instance actions for "first" action in an ordering dependency
364  * with pcmk__ar_min_runnable set that must be runnable before this action
365  * can be runnable.
366  */
368 
369  // Actions in a relation with this one (as pcmk__related_action_t *)
372 
373  /* This is intended to hold data that varies by the type of action, but is
374  * not currently used. Some of the above fields could be moved here except
375  * for API backward compatibility.
376  */
378 };
380 
381 // @COMPAT Make this internal when we can break API backward compatibility
383 const char *pcmk_action_text(enum action_tasks action);
384 
385 // @COMPAT Make this internal when we can break API backward compatibility
387 enum action_tasks pcmk_parse_action(const char *action_name);
388 
389 // @COMPAT Make this internal when we can break API backward compatibility
391 const char *pcmk_on_fail_text(enum action_fail_response on_fail);
392 
393 // For parsing various action-related string specifications
394 gboolean parse_op_key(const char *key, char **rsc_id, char **op_type,
395  guint *interval_ms);
396 gboolean decode_transition_key(const char *key, char **uuid, int *transition_id,
397  int *action_id, int *target_rc);
398 gboolean decode_transition_magic(const char *magic, char **uuid,
399  int *transition_id, int *action_id,
400  int *op_status, int *op_rc, int *target_rc);
401 
402 // @COMPAT Either these shouldn't be in libcrmcommon or lrmd_event_data_t should
403 int rsc_op_expected_rc(const lrmd_event_data_t *event);
404 gboolean did_rsc_op_fail(lrmd_event_data_t *event, int target_rc);
405 
406 bool crm_op_needs_metadata(const char *rsc_class, const char *op);
407 
408 xmlNode *crm_create_op_xml(xmlNode *parent, const char *prefix,
409  const char *task, const char *interval_spec,
410  const char *timeout);
411 
412 bool pcmk_is_probe(const char *task, guint interval);
413 bool pcmk_xe_is_probe(const xmlNode *xml_op);
414 bool pcmk_xe_mask_probe_failure(const xmlNode *xml_op);
415 
416 #ifdef __cplusplus
417 }
418 #endif
419 
420 #endif // PCMK__CRM_COMMON_ACTIONS__H
enum pe_link_state state
Definition: actions.h:320
enum rsc_start_requirement needs
Definition: actions.h:351
Scheduler API for resources.
int runnable_before
Definition: actions.h:360
enum action_tasks pcmk_parse_action(const char *action_name)
Parse an action type from an action name.
Definition: actions.c:92
int priority
Definition: actions.h:338
Type aliases needed to define scheduler objects.
pcmk_action_t * action
Definition: actions.h:322
pe_ordering
Definition: actions.h:283
enum action_fail_response on_fail
Definition: actions.h:352
bool pcmk_is_probe(const char *task, guint interval)
Check whether an action name and interval represent a probe.
Definition: probes.c:30
char * cancel_task
Definition: actions.h:345
pe_link_state
Definition: actions.h:275
action_tasks
Definition: actions.h:83
gboolean decode_transition_magic(const char *magic, char **uuid, int *transition_id, int *action_id, int *op_status, int *op_rc, int *target_rc)
Parse a transition magic string into its constituent parts.
Definition: actions.c:363
const char * pcmk_on_fail_text(enum action_fail_response on_fail)
Get string equivalent of a failure handling type.
Definition: actions.c:147
action_fail_response
Definition: actions.h:130
xmlNode * op_entry
Definition: actions.h:342
char * reason
Definition: actions.h:346
void * action_details
Definition: actions.h:377
const char * action
Definition: pcmk_fence.c:30
GHashTable * extra
Definition: actions.h:355
rsc_start_requirement
Definition: resources.h:52
bool pcmk_xe_is_probe(const xmlNode *xml_op)
Check whether an action history entry represents a probe.
Definition: probes.c:45
gboolean decode_transition_key(const char *key, char **uuid, int *transition_id, int *action_id, int *target_rc)
Parse a transition key into its constituent parts.
Definition: actions.c:426
gboolean did_rsc_op_fail(lrmd_event_data_t *event, int target_rc)
Definition: actions.c:484
op_status
pcmk_node_t * node
Definition: actions.h:341
int rsc_op_expected_rc(const lrmd_event_data_t *event)
Definition: actions.c:473
bool crm_op_needs_metadata(const char *rsc_class, const char *op)
Check whether an operation requires resource agent meta-data.
Definition: actions.c:548
char * task
Definition: actions.h:343
GList * actions_after
Definition: actions.h:371
bool pcmk_xe_mask_probe_failure(const xmlNode *xml_op)
Check whether an action history entry represents a maskable probe.
Definition: probes.c:69
GHashTable * meta
Definition: actions.h:354
rsc_role_e
Definition: roles.h:34
pe_action_flags
Definition: actions.h:199
char * uuid
Definition: actions.h:344
#define PCMK_ALLOW_DEPRECATED
Allow use of deprecated Pacemaker APIs.
Definition: crm.h:46
const char * pcmk_action_text(enum action_tasks action)
Get string equivalent of an action type.
Definition: actions.c:37
Scheduler API for nodes.
gboolean parse_op_key(const char *key, char **rsc_id, char **op_type, guint *interval_ms)
Definition: actions.c:250
enum rsc_role_e fail_role
Definition: actions.h:353
enum pe_action_flags flags
Definition: actions.h:349
xmlNode * crm_create_op_xml(xmlNode *parent, const char *prefix, const char *task, const char *interval_spec, const char *timeout)
Create a CIB XML element for an operation.
Definition: actions.c:521
pcmk_resource_t * rsc
Definition: actions.h:340
const char * parent
Definition: cib.c:27
Resource agent executor events.
enum pe_ordering type
Definition: actions.h:317
unsigned int timeout
Definition: pcmk_fence.c:32
GList * actions_before
Definition: actions.h:370
int required_runnable_before
Definition: actions.h:367