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