pacemaker 2.1.8-2.1.8
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
resources.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_RESOURCES__H
11#define PCMK__CRM_COMMON_RESOURCES__H
12
13#include <stdbool.h> // bool
14#include <sys/types.h> // time_t
15#include <libxml/tree.h> // xmlNode
16#include <glib.h> // gboolean, guint, GList, GHashTable
17
18#include <crm/common/roles.h> // enum rsc_role_e
19#include <crm/common/scheduler_types.h> // pcmk_resource_t, etc.
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
31// Resource variants supported by Pacemaker
35 // Order matters: some code compares greater or lesser than
36 pcmk_rsc_variant_unknown = -1, // Unknown resource variant
37 pcmk_rsc_variant_primitive = 0, // Primitive resource
38 pcmk_rsc_variant_group = 1, // Group resource
39 pcmk_rsc_variant_clone = 2, // Clone resource
40 pcmk_rsc_variant_bundle = 3, // Bundle resource
41
42#if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
48#endif
49};
50
51// What resource needs before it can be recovered from a failed node
53 pcmk_requires_nothing = 0, // Resource can be recovered immediately
54 pcmk_requires_quorum = 1, // Resource can be recovered if quorate
55 pcmk_requires_fencing = 2, // Resource can be recovered after fencing
56
57#if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
61#endif
62};
63
64// How to recover a resource that is incorrectly active on multiple nodes
66 pcmk_multiply_active_restart = 0, // Stop on all, start on desired
67 pcmk_multiply_active_stop = 1, // Stop on all and leave stopped
68 pcmk_multiply_active_block = 2, // Do nothing to resource
69 pcmk_multiply_active_unexpected = 3, // Stop unexpected instances
70
71#if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
76#endif
77};
78
79// Resource scheduling flags
81 // No resource flags set (compare with equality rather than bit set)
83
84 // Whether resource has been removed from the configuration
85 pcmk_rsc_removed = (1ULL << 0),
86
87 // Whether resource is managed
88 pcmk_rsc_managed = (1ULL << 1),
89
90 // Whether resource is blocked from further action
91 pcmk_rsc_blocked = (1ULL << 2),
92
93 // Whether resource has been removed but has a container
95
96 // Whether resource has clone notifications enabled
97 pcmk_rsc_notify = (1ULL << 4),
98
99 // Whether resource is not an anonymous clone instance
100 pcmk_rsc_unique = (1ULL << 5),
101
102 // Whether resource's class is "stonith"
104
105 // Whether resource can be promoted and demoted
106 pcmk_rsc_promotable = (1ULL << 7),
107
108 // Whether resource has not yet been assigned to a node
109 pcmk_rsc_unassigned = (1ULL << 8),
110
111 // Whether resource is in the process of being assigned to a node
112 pcmk_rsc_assigning = (1ULL << 9),
113
114 // Whether resource is in the process of modifying allowed node scores
116
117 // Whether resource is in the process of scheduling actions to restart
118 pcmk_rsc_restarting = (1ULL << 11),
119
120 // Whether resource must be stopped (instead of demoted) if it is failed
122
123 // Whether a reload action has been scheduled for resource
124 pcmk_rsc_reload = (1ULL << 13),
125
126 // Whether resource is a remote connection allowed to run on a remote node
128
129 // Whether resource has \c PCMK_META_CRITICAL meta-attribute enabled
130 pcmk_rsc_critical = (1ULL << 15),
131
132 // Whether resource is considered failed
133 pcmk_rsc_failed = (1ULL << 16),
134
135 // Flag for non-scheduler code to use to detect recursion loops
136 pcmk_rsc_detect_loop = (1ULL << 17),
137
138 // \deprecated Do not use
139 pcmk_rsc_runnable = (1ULL << 18),
140
141 // Whether resource has pending start action in history
143
144 // \deprecated Do not use
145 pcmk_rsc_starting = (1ULL << 20),
146
147 // \deprecated Do not use
148 pcmk_rsc_stopping = (1ULL << 21),
149
150 /*
151 * Whether resource is multiply active with recovery set to
152 * \c PCMK_VALUE_STOP_UNEXPECTED
153 */
155
156 // Whether resource is allowed to live-migrate
157 pcmk_rsc_migratable = (1ULL << 23),
158
159 // Whether resource has an ignorable failure
161
162 // Whether resource is an implicit container resource for a bundle replica
164
165 // Whether resource, its node, or entire cluster is in maintenance mode
166 pcmk_rsc_maintenance = (1ULL << 26),
167
168 // \deprecated Do not use
169 pcmk_rsc_has_filler = (1ULL << 27),
170
171 // Whether resource can be started or promoted only on quorate nodes
172 pcmk_rsc_needs_quorum = (1ULL << 28),
173
174 // Whether resource requires fencing before recovery if on unclean node
176
177 // Whether resource can be started or promoted only on unfenced nodes
179};
181
219
226
228 pe_print_log = (1 << 0),
229 pe_print_html = (1 << 1),
231 pe_print_printf = (1 << 3),
232 pe_print_dev = (1 << 4), // Ignored
233 pe_print_details = (1 << 5), // Ignored
234 pe_print_max_details = (1 << 6), // Ignored
236 pe_print_ops = (1 << 8),
238 pe_print_xml = (1 << 10),
239 pe_print_brief = (1 << 11),
240 pe_print_pending = (1 << 12),
242 pe_print_clone_active = (1 << 14), // Print clone instances only if active
243 pe_print_implicit = (1 << 15) // Print implicitly created resources
246
247// Resource assignment methods (implementation defined by libpacemaker)
250
251// Resource object methods
252// @COMPAT Make this internal when we can break API backward compatibility
256 /*
257 * \brief Parse variant-specific resource XML from CIB into struct members
258 *
259 * \param[in,out] rsc Partially unpacked resource
260 * \param[in,out] scheduler Scheduler data
261 *
262 * \return TRUE if resource was unpacked successfully, otherwise FALSE
263 */
265
266 /*
267 * \brief Search for a resource ID in a resource and its children
268 *
269 * \param[in] rsc Search this resource and its children
270 * \param[in] id Search for this resource ID
271 * \param[in] on_node If not NULL, limit search to resources on this node
272 * \param[in] flags Group of enum pe_find flags
273 *
274 * \return Resource that matches search criteria if any, otherwise NULL
275 */
276 pcmk_resource_t *(*find_rsc)(pcmk_resource_t *rsc, const char *search,
277 const pcmk_node_t *node, int flags);
278
279 /*
280 * \brief Get value of a resource instance attribute
281 *
282 * \param[in,out] rsc Resource to check
283 * \param[in] node Node to use to evaluate rules
284 * \param[in] create Ignored
285 * \param[in] name Name of instance attribute to check
286 * \param[in,out] scheduler Scheduler data
287 *
288 * \return Value of requested attribute if available, otherwise NULL
289 * \note The caller is responsible for freeing the result using free().
290 */
291 char *(*parameter)(pcmk_resource_t *rsc, pcmk_node_t *node, gboolean create,
292 const char *name, pcmk_scheduler_t *scheduler);
293
294 // \deprecated Do not use
295 void (*print)(pcmk_resource_t *rsc, const char *pre_text, long options,
296 void *print_data);
297
298 /*
299 * \brief Check whether a resource is active
300 *
301 * \param[in] rsc Resource to check
302 * \param[in] all If \p rsc is collective, all instances must be active
303 *
304 * \return TRUE if \p rsc is active, otherwise FALSE
305 */
306 gboolean (*active)(pcmk_resource_t *rsc, gboolean all);
307
308 /*
309 * \brief Get resource's current or assigned role
310 *
311 * \param[in] rsc Resource to check
312 * \param[in] current If TRUE, check current role, otherwise assigned role
313 *
314 * \return Current or assigned role of \p rsc
315 */
316 enum rsc_role_e (*state)(const pcmk_resource_t *rsc, gboolean current);
317
318 /*
319 * \brief List nodes where a resource (or any of its children) is
320 *
321 * \param[in] rsc Resource to check
322 * \param[out] list List to add result to
323 * \param[in] current If 0, list nodes where \p rsc is assigned;
324 * if 1, where active; if 2, where active or pending
325 *
326 * \return If list contains only one node, that node, otherwise NULL
327 */
328 pcmk_node_t *(*location)(const pcmk_resource_t *rsc, GList **list,
329 int current);
330
331 /*
332 * \brief Free all memory used by a resource
333 *
334 * \param[in,out] rsc Resource to free
335 */
336 void (*free)(pcmk_resource_t *rsc);
337
338 /*
339 * \brief Increment cluster's instance counts for a resource
340 *
341 * Given a resource, increment its cluster's ninstances, disabled_resources,
342 * and blocked_resources counts for the resource and its descendants.
343 *
344 * \param[in,out] rsc Resource to count
345 */
346 void (*count)(pcmk_resource_t *rsc);
347
348 /*
349 * \brief Check whether a given resource is in a list of resources
350 *
351 * \param[in] rsc Resource ID to check for
352 * \param[in] only_rsc List of resource IDs to check
353 * \param[in] check_parent If TRUE, check top ancestor as well
354 *
355 * \return TRUE if \p rsc, its top parent if requested, or '*' is in
356 * \p only_rsc, otherwise FALSE
357 */
358 gboolean (*is_filtered)(const pcmk_resource_t *rsc, GList *only_rsc,
359 gboolean check_parent);
360
361 /*
362 * \brief Find a node (and optionally count all) where resource is active
363 *
364 * \param[in] rsc Resource to check
365 * \param[out] count_all If not NULL, set this to count of active nodes
366 * \param[out] count_clean If not NULL, set this to count of clean nodes
367 *
368 * \return A node where the resource is active, preferring the source node
369 * if the resource is involved in a partial migration, or a clean,
370 * online node if the resource's \c PCMK_META_REQUIRES is
371 * \c PCMK_VALUE_QUORUM or \c PCMK_VALUE_NOTHING, otherwise \c NULL.
372 */
373 pcmk_node_t *(*active_node)(const pcmk_resource_t *rsc,
374 unsigned int *count_all,
375 unsigned int *count_clean);
376
377 /*
378 * \brief Get maximum resource instances per node
379 *
380 * \param[in] rsc Resource to check
381 *
382 * \return Maximum number of \p rsc instances that can be active on one node
383 */
384 unsigned int (*max_per_node)(const pcmk_resource_t *rsc);
387
388// Implementation of pcmk_resource_t
389// @COMPAT Make this internal when we can break API backward compatibility
393 // NOTE: sbd (as of at least 1.5.2) uses this
395 char *id; // Resource ID in configuration
396
397 char *clone_name; // Resource instance ID in history
398
399 // Resource configuration (possibly expanded from template)
400 xmlNode *xml;
401
402 // Original resource configuration, if using template
403 xmlNode *orig_xml;
404
405 // Configuration of resource operations (possibly expanded from template)
406 xmlNode *ops_xml;
407
408 pcmk_scheduler_t *cluster; // Cluster that resource is part of
409 pcmk_resource_t *parent; // Resource's parent resource, if any
410 enum pe_obj_types variant; // Resource variant
411 void *variant_opaque; // Variant-specific (and private) data
412 pcmk_rsc_methods_t *fns; // Resource object methods
413 pcmk_assignment_methods_t *cmds; // Resource assignment methods
414
415 enum rsc_recovery_type recovery_type; // How to recover if failed
416
417 enum pe_restart restart_type; // \deprecated Do not use
418 int priority; // Configured priority
419 int stickiness; // Extra preference for current node
420 int sort_index; // Promotion score on assigned node
421 int failure_timeout; // Failure timeout
422 int migration_threshold; // Migration threshold
423 guint remote_reconnect_ms; // Retry interval for remote connections
424 char *pending_task; // Pending action in history, if any
425
426 // NOTE: sbd (as of at least 1.5.2) uses this
428 unsigned long long flags; // Group of enum pcmk_rsc_flags
429
430 // @TODO Merge these into flags
431 gboolean is_remote_node; // Whether this is a remote connection
432 gboolean exclusive_discover; // Whether exclusive probing is enabled
433
434 /* Pay special attention to whether you want to use rsc_cons_lhs and
435 * rsc_cons directly, which include only colocations explicitly involving
436 * this resource, or call libpacemaker's pcmk__with_this_colocations() and
437 * pcmk__this_with_colocations() functions, which may return relevant
438 * colocations involving the resource's ancestors as well.
439 */
440
441 GList *rsc_cons_lhs; // Colocations of other resources with this one
442 GList *rsc_cons; // Colocations of this resource with others
443 GList *rsc_location; // Location constraints for resource
444 GList *actions; // Actions scheduled for resource
445 GList *rsc_tickets; // Ticket constraints for resource
446
447 pcmk_node_t *allocated_to; // Node resource is assigned to
448
449 // The destination node, if migrate_to completed but migrate_from has not
451
452 // The source node, if migrate_to completed but migrate_from has not
454
455 // Nodes where resource may be active
457
458 // Nodes where resource has been probed (key is node ID, not name)
459 GHashTable *known_on;
460
461 // Nodes where resource may run (key is node ID, not name)
462 GHashTable *allowed_nodes;
463
464 enum rsc_role_e role; // Resource's current role
465 enum rsc_role_e next_role; // Resource's scheduled next role
466
467 GHashTable *meta; // Resource's meta-attributes
468 GHashTable *parameters; // \deprecated Use pe_rsc_params() instead
469 GHashTable *utilization; // Resource's utilization attributes
470
471 GList *children; // Resource's child resources, if any
472
473 // Source nodes where stop is needed after migrate_from and migrate_to
475
476 pcmk_resource_t *container; // Resource containing this one, if any
477 GList *fillers; // Resources contained by this one, if any
478
479 // @COMPAT These should be made const at next API compatibility break
480 pcmk_node_t *pending_node; // Node on which pending_task is happening
481 pcmk_node_t *lock_node; // Resource shutdown-locked to this node
482
483 time_t lock_time; // When shutdown lock started
484
485 /*
486 * Resource parameters may have node-attribute-based rules, which means the
487 * values can vary by node. This table has node names as keys and parameter
488 * name/value tables as values. Use pe_rsc_params() to get the table for a
489 * given node rather than use this directly.
490 */
491 GHashTable *parameter_cache;
492};
494
495const char *pcmk_resource_id(const pcmk_resource_t *rsc);
497
498#ifdef __cplusplus
499}
500#endif
501
502#endif // PCMK__CRM_COMMON_RESOURCES__H
const char * name
Definition cib.c:26
uint64_t flags
Definition remote.c:3
pcmk_scheduler_t * scheduler
pe_print_options
Definition resources.h:227
@ pe_print_ncurses
Definition resources.h:230
@ pe_print_printf
Definition resources.h:231
@ pe_print_rsconly
Definition resources.h:235
@ pe_print_implicit
Definition resources.h:243
@ pe_print_log
Definition resources.h:228
@ pe_print_brief
Definition resources.h:239
@ pe_print_xml
Definition resources.h:238
@ pe_print_clone_active
Definition resources.h:242
@ pe_print_max_details
Definition resources.h:234
@ pe_print_details
Definition resources.h:233
@ pe_print_dev
Definition resources.h:232
@ pe_print_pending
Definition resources.h:240
@ pe_print_suppres_nl
Definition resources.h:237
@ pe_print_clone_details
Definition resources.h:241
@ pe_print_html
Definition resources.h:229
@ pe_print_ops
Definition resources.h:236
rsc_start_requirement
Definition resources.h:52
@ pcmk_requires_fencing
Definition resources.h:55
@ pcmk_requires_quorum
Definition resources.h:54
@ rsc_req_quorum
Definition resources.h:59
@ pcmk_requires_nothing
Definition resources.h:53
@ rsc_req_stonith
Definition resources.h:60
@ rsc_req_nothing
Definition resources.h:58
rsc_recovery_type
Definition resources.h:65
@ recovery_stop_start
Definition resources.h:72
@ pcmk_multiply_active_block
Definition resources.h:68
@ pcmk_multiply_active_restart
Definition resources.h:66
@ recovery_block
Definition resources.h:74
@ pcmk_multiply_active_stop
Definition resources.h:67
@ recovery_stop_only
Definition resources.h:73
@ recovery_stop_unexpected
Definition resources.h:75
@ pcmk_multiply_active_unexpected
Definition resources.h:69
pe_find
Search options for resources (exact resource ID always matches)
Definition resources.h:183
@ pcmk_rsc_match_anon_basename
Also match anonymous clone instances by base name.
Definition resources.h:188
@ pe_find_inactive
Definition resources.h:197
@ pcmk_rsc_match_clone_only
Match only clones and their instances, by either clone or instance ID.
Definition resources.h:191
@ pe_find_any
Definition resources.h:216
@ pcmk_rsc_match_basename
Match clone instances (even unique) by base name as well as exact ID.
Definition resources.h:200
@ pe_find_clone
Definition resources.h:210
@ pcmk_rsc_match_history
Also match clone instance ID from resource history.
Definition resources.h:185
@ pcmk_rsc_match_current_node
If matching by node, compare current node instead of assigned node.
Definition resources.h:194
@ pe_find_renamed
Definition resources.h:204
@ pe_find_current
Definition resources.h:213
@ pe_find_anon
Definition resources.h:207
pe_obj_types
Definition resources.h:34
@ pcmk_rsc_variant_group
Definition resources.h:38
@ pcmk_rsc_variant_primitive
Definition resources.h:37
@ pe_group
Definition resources.h:45
@ pcmk_rsc_variant_bundle
Definition resources.h:40
@ pcmk_rsc_variant_unknown
Definition resources.h:36
@ pe_container
Definition resources.h:47
@ pe_unknown
Definition resources.h:43
@ pe_native
Definition resources.h:44
@ pe_clone
Definition resources.h:46
@ pcmk_rsc_variant_clone
Definition resources.h:39
pcmk_rsc_flags
Definition resources.h:80
@ pcmk_rsc_detect_loop
Definition resources.h:136
@ pcmk_rsc_promotable
Definition resources.h:106
@ pcmk_rsc_unassigned
Definition resources.h:109
@ pcmk_rsc_assigning
Definition resources.h:112
@ pcmk_rsc_stop_if_failed
Definition resources.h:121
@ pcmk_rsc_critical
Definition resources.h:130
@ pcmk_rsc_migratable
Definition resources.h:157
@ pcmk_rsc_unique
Definition resources.h:100
@ pcmk_rsc_maintenance
Definition resources.h:166
@ pcmk_no_rsc_flags
Definition resources.h:82
@ pcmk_rsc_needs_fencing
Definition resources.h:175
@ pcmk_rsc_replica_container
Definition resources.h:163
@ pcmk_rsc_runnable
Definition resources.h:139
@ pcmk_rsc_needs_unfencing
Definition resources.h:178
@ pcmk_rsc_removed
Definition resources.h:85
@ pcmk_rsc_notify
Definition resources.h:97
@ pcmk_rsc_updating_nodes
Definition resources.h:115
@ pcmk_rsc_remote_nesting_allowed
Definition resources.h:127
@ pcmk_rsc_reload
Definition resources.h:124
@ pcmk_rsc_start_pending
Definition resources.h:142
@ pcmk_rsc_stopping
Definition resources.h:148
@ pcmk_rsc_blocked
Definition resources.h:91
@ pcmk_rsc_restarting
Definition resources.h:118
@ pcmk_rsc_fence_device
Definition resources.h:103
@ pcmk_rsc_needs_quorum
Definition resources.h:172
@ pcmk_rsc_removed_filler
Definition resources.h:94
@ pcmk_rsc_stop_unexpected
Definition resources.h:154
@ pcmk_rsc_has_filler
Definition resources.h:169
@ pcmk_rsc_managed
Definition resources.h:88
@ pcmk_rsc_ignore_failure
Definition resources.h:160
@ pcmk_rsc_failed
Definition resources.h:133
@ pcmk_rsc_starting
Definition resources.h:145
struct resource_object_functions_s pcmk_rsc_methods_t
pe_restart
Definition resources.h:222
@ pe_restart_ignore
Definition resources.h:224
@ pe_restart_restart
Definition resources.h:223
bool pcmk_resource_is_managed(const pcmk_resource_t *rsc)
Definition resources.c:41
const char * pcmk_resource_id(const pcmk_resource_t *rsc)
Definition resources.c:27
Scheduler API for resource roles.
rsc_role_e
Definition roles.h:34
Type aliases needed to define scheduler objects.
pcmk_assignment_methods_t * cmds
Definition resources.h:413
GList * running_on
Definition resources.h:456
GList * actions
Definition resources.h:444
GList * rsc_location
Definition resources.h:443
int failure_timeout
Definition resources.h:421
enum pe_obj_types variant
Definition resources.h:410
pcmk_node_t * partial_migration_target
Definition resources.h:450
GHashTable * meta
Definition resources.h:467
GList * rsc_cons
Definition resources.h:442
GList * rsc_cons_lhs
Definition resources.h:441
GList * children
Definition resources.h:471
pcmk_scheduler_t * cluster
Definition resources.h:408
int migration_threshold
Definition resources.h:422
gboolean exclusive_discover
Definition resources.h:432
pcmk_node_t * partial_migration_source
Definition resources.h:453
enum pe_restart restart_type
Definition resources.h:417
pcmk_resource_t * container
Definition resources.h:476
pcmk_rsc_methods_t * fns
Definition resources.h:412
GHashTable * known_on
Definition resources.h:459
char * clone_name
Definition resources.h:397
GHashTable * parameters
Definition resources.h:468
gboolean is_remote_node
Definition resources.h:431
pcmk_node_t * allocated_to
Definition resources.h:447
xmlNode * xml
Definition resources.h:400
GHashTable * utilization
Definition resources.h:469
GHashTable * allowed_nodes
Definition resources.h:462
GList * dangling_migrations
Definition resources.h:474
pcmk_node_t * lock_node
Definition resources.h:481
GHashTable * parameter_cache
Definition resources.h:491
GList * rsc_tickets
Definition resources.h:445
void * variant_opaque
Definition resources.h:411
unsigned long long flags
Definition resources.h:428
pcmk_node_t * pending_node
Definition resources.h:480
char * pending_task
Definition resources.h:424
guint remote_reconnect_ms
Definition resources.h:423
enum rsc_recovery_type recovery_type
Definition resources.h:415
GList * fillers
Definition resources.h:477
xmlNode * orig_xml
Definition resources.h:403
enum rsc_role_e next_role
Definition resources.h:465
enum rsc_role_e role
Definition resources.h:464
pcmk_resource_t * parent
Definition resources.h:409
xmlNode * ops_xml
Definition resources.h:406
time_t lock_time
Definition resources.h:483
void(* free)(pcmk_resource_t *rsc)
Definition resources.h:336
void(* print)(pcmk_resource_t *rsc, const char *pre_text, long options, void *print_data)
Definition resources.h:295
enum rsc_role_e(* state)(const pcmk_resource_t *rsc, gboolean current)
Definition resources.h:316
void(* count)(pcmk_resource_t *rsc)
Definition resources.h:346
gboolean(* unpack)(pcmk_resource_t *rsc, pcmk_scheduler_t *scheduler)
Definition resources.h:264
unsigned int(* max_per_node)(const pcmk_resource_t *rsc)
Definition resources.h:384
gboolean(* is_filtered)(const pcmk_resource_t *rsc, GList *only_rsc, gboolean check_parent)
Definition resources.h:358
gboolean(* active)(pcmk_resource_t *rsc, gboolean all)
Definition resources.h:306