pacemaker  3.0.0-d8340737c4
Scalable High-Availability cluster resource manager
resources_internal.h
Go to the documentation of this file.
1 /*
2  * Copyright 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_RESOURCES_INTERNAL__H
11 #define PCMK__CRM_COMMON_RESOURCES_INTERNAL__H
12 
13 #include <stdint.h> // uint32_t
14 #include <glib.h> // gboolean, guint, GHashTable, GList
15 #include <libxml/tree.h> // xmlNode
16 
17 #include <crm/common/resources.h> // pcmk_resource_t
18 #include <crm/common/roles.h> // enum rsc_role_e
19 #include <crm/common/scheduler_types.h> // pcmk_node_t, etc.
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
32 #define pcmk__set_rsc_flags(resource, flags_to_set) do { \
33  (resource)->flags = pcmk__set_flags_as(__func__, __LINE__, \
34  LOG_TRACE, "Resource", (resource)->id, (resource)->flags, \
35  (flags_to_set), #flags_to_set); \
36  } while (0)
37 
45 #define pcmk__clear_rsc_flags(resource, flags_to_clear) do { \
46  (resource)->flags = pcmk__clear_flags_as(__func__, __LINE__, \
47  LOG_TRACE, "Resource", (resource)->id, (resource)->flags, \
48  (flags_to_clear), #flags_to_clear); \
49  } while (0)
50 
53  // Order matters: some code compares greater or lesser than
59 };
60 
67 };
68 
71  // No resource flags set (compare with equality rather than bit set)
73 
74  // Whether resource has been removed from the configuration
75  pcmk__rsc_removed = (1ULL << 0),
76 
77  /* NOTE: sbd (at least as of 1.5.2) uses pe_rsc_managed which equates to
78  * this value, so the value should not be changed
79  */
80  // Whether resource is managed
81  pcmk__rsc_managed = (1ULL << 1),
82 
83  // Whether resource is blocked from further action
84  pcmk__rsc_blocked = (1ULL << 2),
85 
86  // Whether resource has been removed but was launched
88 
89  // Whether resource has clone notifications enabled
90  pcmk__rsc_notify = (1ULL << 4),
91 
92  // Whether resource is not an anonymous clone instance
93  pcmk__rsc_unique = (1ULL << 5),
94 
95  // Whether resource's class is "stonith"
96  pcmk__rsc_fence_device = (1ULL << 6),
97 
98  // Whether resource can be promoted and demoted
99  pcmk__rsc_promotable = (1ULL << 7),
100 
101  // Whether resource has not yet been assigned to a node
102  pcmk__rsc_unassigned = (1ULL << 8),
103 
104  // Whether resource is in the process of being assigned to a node
105  pcmk__rsc_assigning = (1ULL << 9),
106 
107  // Whether resource is in the process of modifying allowed node scores
108  pcmk__rsc_updating_nodes = (1ULL << 10),
109 
110  // Whether resource is in the process of scheduling actions to restart
111  pcmk__rsc_restarting = (1ULL << 11),
112 
113  // Whether resource must be stopped (instead of demoted) if it is failed
114  pcmk__rsc_stop_if_failed = (1ULL << 12),
115 
116  // Whether a reload action has been scheduled for resource
117  pcmk__rsc_reload = (1ULL << 13),
118 
119  // Whether resource is a remote connection allowed to run on a remote node
121 
122  // Whether resource has \c PCMK_META_CRITICAL meta-attribute enabled
123  pcmk__rsc_critical = (1ULL << 15),
124 
125  // Whether resource is considered failed
126  pcmk__rsc_failed = (1ULL << 16),
127 
128  // Flag for non-scheduler code to use to detect recursion loops
129  pcmk__rsc_detect_loop = (1ULL << 17),
130 
131  // Whether resource is a Pacemaker Remote connection
133 
134  // Whether resource has pending start action in history
135  pcmk__rsc_start_pending = (1ULL << 19),
136 
137  // Whether resource is probed only on nodes marked exclusive
139 
140  /*
141  * Whether resource is multiply active with recovery set to
142  * \c PCMK_VALUE_STOP_UNEXPECTED
143  */
145 
146  // Whether resource is allowed to live-migrate
147  pcmk__rsc_migratable = (1ULL << 23),
148 
149  // Whether resource has an ignorable failure
150  pcmk__rsc_ignore_failure = (1ULL << 24),
151 
152  // Whether resource is an implicit container resource for a bundle replica
154 
155  // Whether resource, its node, or entire cluster is in maintenance mode
156  pcmk__rsc_maintenance = (1ULL << 26),
157 
158  // Whether resource can be started or promoted only on quorate nodes
159  pcmk__rsc_needs_quorum = (1ULL << 28),
160 
161  // Whether resource requires fencing before recovery if on unclean node
162  pcmk__rsc_needs_fencing = (1ULL << 29),
163 
164  // Whether resource can be started or promoted only on unfenced nodes
166 };
167 
168 // Where to look for a resource
170  pcmk__rsc_node_none = 0U, // Nowhere
171  pcmk__rsc_node_assigned = (1U << 0), // Where resource is assigned
172  pcmk__rsc_node_current = (1U << 1), // Where resource is running
173  pcmk__rsc_node_pending = (1U << 2), // Where resource is pending
174 };
175 
178 
180 typedef struct {
190  gboolean (*unpack)(pcmk_resource_t *rsc, pcmk_scheduler_t *scheduler);
191 
203  pcmk_resource_t *(*find_rsc)(pcmk_resource_t *rsc, const char *search,
204  const pcmk_node_t *node, int flags);
205 
219  char *(*parameter)(pcmk_resource_t *rsc, pcmk_node_t *node, gboolean create,
220  const char *name, pcmk_scheduler_t *scheduler);
221 
231  gboolean (*active)(pcmk_resource_t *rsc, gboolean all);
232 
242  enum rsc_role_e (*state)(const pcmk_resource_t *rsc, gboolean current);
243 
255  pcmk_node_t *(*location)(const pcmk_resource_t *rsc, GList **list,
256  uint32_t target);
257 
264  void (*free)(pcmk_resource_t *rsc);
265 
275  void (*count)(pcmk_resource_t *rsc);
276 
288  gboolean (*is_filtered)(const pcmk_resource_t *rsc, GList *only_rsc,
289  gboolean check_parent);
290 
304  pcmk_node_t *(*active_node)(const pcmk_resource_t *rsc,
305  unsigned int *count_all,
306  unsigned int *count_clean);
307 
316  unsigned int (*max_per_node)(const pcmk_resource_t *rsc);
318 
319 // Implementation of pcmk__resource_private_t
321  enum pcmk__rsc_variant variant; // Resource variant
322  void *variant_opaque; // Variant-specific data
323  char *history_id; // Resource instance ID in history
324  GHashTable *meta; // Resource meta-attributes
325  GHashTable *utilization; // Resource utilization attributes
326  int priority; // Priority relative other resources
327  int promotion_priority; // Promotion priority on assigned node
328  enum rsc_role_e orig_role; // Resource's role at start of transition
329  enum rsc_role_e next_role; // Resource's role at end of transition
330  int stickiness; // Extra preference for current node
331  guint failure_expiration_ms; // Failures expire after this much time
332  int ban_after_failures; // Ban from node after this many failures
333  guint remote_reconnect_ms; // Retry interval for remote connections
334  char *pending_action; // Pending action in history, if any
335  const pcmk_node_t *pending_node;// Node on which pending_action is happening
336  time_t lock_time; // When shutdown lock started
337  const pcmk_node_t *lock_node; // Node that resource is shutdown-locked to
338  GList *actions; // Actions scheduled for resource
339  GList *children; // Resource's child resources, if any
340  pcmk_resource_t *parent; // Resource's parent resource, if any
341  pcmk_scheduler_t *scheduler; // Scheduler data containing resource
342 
343  // Resource configuration (possibly expanded from template)
344  xmlNode *xml;
345 
346  // Original resource configuration, if using template
347  xmlNode *orig_xml;
348 
349  // Configuration of resource operations (possibly expanded from template)
350  xmlNode *ops_xml;
351 
352  /*
353  * Resource parameters may have node-attribute-based rules, which means the
354  * values can vary by node. This table has node names as keys and parameter
355  * name/value tables as values. Use pe_rsc_params() to get the table for a
356  * given node rather than use this directly.
357  */
358  GHashTable *parameter_cache;
359 
360  /* A "launcher" is defined in one of these ways:
361  *
362  * - A Pacemaker Remote connection for a guest node or bundle node has its
363  * launcher set to the resource that starts the guest or the bundle
364  * replica's container.
365  *
366  * - If the user configures the PCMK__META_CONTAINER meta-attribute for this
367  * resource, the launcher is set to that.
368  *
369  * If the launcher is a Pacemaker Remote connection resource, this
370  * resource may run only on the node created by that connection.
371  *
372  * Otherwise, this resource will be colocated with and ordered after the
373  * launcher, and failures of this resource will cause the launcher to be
374  * recovered instead of this one. This is appropriate for monitoring-only
375  * resources that represent a service launched by the other resource.
376  */
378 
379  // Resources launched by this one, if any (pcmk_resource_t *)
380  GList *launched;
381 
382  // What to do if the resource is incorrectly active on multiple nodes
384 
385  /* The assigned node (if not NULL) is the one where the resource *should*
386  * be active by the end of the current scheduler transition. Only primitive
387  * resources have an assigned node. This is a node copy (created by
388  * pe__copy_node()) and so must be freed using pcmk__free_node_copy().
389  *
390  * @TODO This should probably be part of the primitive variant data.
391  */
393 
394  /* The active nodes are ones where the resource is (or might be, if
395  * insufficient information is available to be sure) already active at the
396  * start of the current scheduler transition.
397  *
398  * For primitive resources, there should be at most one, but could be more
399  * if it is (incorrectly) multiply active. For collective resources, this
400  * combines active nodes of all descendants.
401  */
402  GList *active_nodes;
403 
404  /* The next two tables store node copies (created by pe__copy_node()), which
405  * share some members with the original node objects and must be freed with
406  * pcmk__free_node_copy().
407  */
408 
409  // Nodes where resource has been probed (key is node ID, not name)
410  GHashTable *probed_nodes;
411 
412  // Nodes where resource is allowed to run (key is node ID, not name)
413  GHashTable *allowed_nodes;
414 
415  // The source node, if migrate_to completed but migrate_from has not
417 
418  // The destination node, if migrate_to completed but migrate_from has not
420 
421  // Source nodes where stop is needed after migrate_from and migrate_to
423 
424  /* Pay special attention to whether you want to use with_this_colocations
425  * and this_with_colocations directly, which include only colocations
426  * explicitly involving this resource, or call libpacemaker's
427  * pcmk__with_this_colocations() and pcmk__this_with_colocations()
428  * functions, which may return relevant colocations involving the resource's
429  * ancestors as well.
430  */
431 
432  // Colocations of other resources with this one
434 
435  // Colocations of this resource with others
437 
438  GList *location_constraints; // Location constraints for resource
439  GList *ticket_constraints; // Ticket constraints for resource
440 
441  const pcmk__rsc_methods_t *fns; // Resource object methods
442  const pcmk__assignment_methods_t *cmds; // Resource assignment methods
443 };
444 
445 const char *pcmk__multiply_active_text(const pcmk_resource_t *rsc);
446 
455 static inline pcmk_node_t *
456 pcmk__current_node(const pcmk_resource_t *rsc)
457 {
458  if (rsc == NULL) {
459  return NULL;
460  }
461  return rsc->priv->fns->active_node(rsc, NULL, NULL);
462 }
463 
464 #ifdef __cplusplus
465 }
466 #endif
467 
468 #endif // PCMK__CRM_COMMON_RESOURCES_INTERNAL__H
Scheduler API for resources.
pcmk_resource_t * parent
const char * name
Definition: cib.c:26
Type aliases needed to define scheduler objects.
Do nothing to resource.
Resource object methods.
pcmk__rsc_variant
Resource variants supported by Pacemaker.
const pcmk__rsc_methods_t * fns
pcmk_node_t * partial_migration_source
pcmk__multiply_active
How to recover a resource that is incorrectly active on multiple nodes.
pcmk_scheduler_t * scheduler
Scheduler API for resource roles.
enum pcmk__rsc_variant variant
enum pcmk__multiply_active multiply_active_policy
pcmk__rsc_flags
Resource scheduling flags.
const char * pcmk__multiply_active_text(const pcmk_resource_t *rsc)
Get readable description of a multiply-active recovery type.
Definition: resources.c:54
Stop unexpected instances.
pcmk__resource_private_t * priv
Definition: resources.h:61
rsc_role_e
Definition: roles.h:34
const pcmk_node_t * pending_node
const pcmk_node_t * lock_node
const char * target
Definition: pcmk_fence.c:31
pcmk__rsc_node
Stop on all, start on desired.
pcmk_scheduler_t * scheduler
pcmk_resource_t * launcher
Unknown resource variant.
Stop on all and leave stopped.
pcmk_node_t *(* active_node)(const pcmk_resource_t *rsc, unsigned int *count_all, unsigned int *count_clean)
uint64_t flags
Definition: remote.c:211
const pcmk__assignment_methods_t * cmds
pcmk_node_t * partial_migration_target