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