diff --git a/include/crm/common/resources.h b/include/crm/common/resources.h index cce26f1abd..f706712229 100644 --- a/include/crm/common/resources.h +++ b/include/crm/common/resources.h @@ -1,262 +1,400 @@ /* * Copyright 2004-2023 the Pacemaker project contributors * * The version control history for this file may have further details. * * This source code is licensed under the GNU Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #ifndef PCMK__CRM_COMMON_RESOURCES__H # define PCMK__CRM_COMMON_RESOURCES__H +#include // gboolean, GList + +#include // enum rsc_role_e +#include // pcmk_resource_t, etc. + #ifdef __cplusplus extern "C" { #endif /*! * \file * \brief Scheduler API for resources * \ingroup core */ //! Resource variants supported by Pacemaker enum pe_obj_types { // Order matters: some code compares greater or lesser than pcmk_rsc_variant_unknown = -1, //!< Unknown resource variant pcmk_rsc_variant_primitive = 0, //!< Primitive resource pcmk_rsc_variant_group = 1, //!< Group resource pcmk_rsc_variant_clone = 2, //!< Clone resource pcmk_rsc_variant_bundle = 3, //!< Bundle resource #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1) //! \deprecated Use pcmk_rsc_variant_unknown instead pe_unknown = pcmk_rsc_variant_unknown, //! \deprecated Use pcmk_rsc_variant_primitive instead pe_native = pcmk_rsc_variant_primitive, //! \deprecated Use pcmk_rsc_variant_group instead pe_group = pcmk_rsc_variant_group, //! \deprecated Use pcmk_rsc_variant_clone instead pe_clone = pcmk_rsc_variant_clone, //! \deprecated Use pcmk_rsc_variant_bundle instead pe_container = pcmk_rsc_variant_bundle, #endif }; //! What resource needs before it can be recovered from a failed node enum rsc_start_requirement { pcmk_requires_nothing = 0, //!< Resource can be recovered immediately pcmk_requires_quorum = 1, //!< Resource can be recovered if quorate pcmk_requires_fencing = 2, //!< Resource can be recovered after fencing #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1) //! \deprecated Use pcmk_requires_nothing instead rsc_req_nothing = pcmk_requires_nothing, //! \deprecated Use pcmk_requires_quorum instead rsc_req_quorum = pcmk_requires_quorum, //! \deprecated Use pcmk_requires_fencing instead rsc_req_stonith = pcmk_requires_fencing, #endif }; //! How to recover a resource that is incorrectly active on multiple nodes enum rsc_recovery_type { pcmk_multiply_active_restart = 0, //!< Stop on all, start on desired pcmk_multiply_active_stop = 1, //!< Stop on all and leave stopped pcmk_multiply_active_block = 2, //!< Do nothing to resource pcmk_multiply_active_unexpected = 3, //!< Stop unexpected instances #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1) //! \deprecated Use pcmk_multiply_active_restart instead recovery_stop_start = pcmk_multiply_active_restart, //! \deprecated Use pcmk_multiply_active_stop instead recovery_stop_only = pcmk_multiply_active_stop, //! \deprecated Use pcmk_multiply_active_block instead recovery_block = pcmk_multiply_active_block, //! \deprecated Use pcmk_multiply_active_unexpected instead recovery_stop_unexpected = pcmk_multiply_active_unexpected, #endif }; //! Resource scheduling flags enum pcmk_rsc_flags { //! No resource flags set (compare with equality rather than bit set) pcmk_no_rsc_flags = 0ULL, //! Whether resource has been removed from the configuration pcmk_rsc_removed = (1ULL << 0), //! Whether resource is managed pcmk_rsc_managed = (1ULL << 1), //! Whether resource is blocked from further action pcmk_rsc_blocked = (1ULL << 2), //! Whether resource has been removed but has a container pcmk_rsc_removed_filler = (1ULL << 3), //! Whether resource has clone notifications enabled pcmk_rsc_notify = (1ULL << 4), //! Whether resource is not an anonymous clone instance pcmk_rsc_unique = (1ULL << 5), //! Whether resource's class is "stonith" pcmk_rsc_fence_device = (1ULL << 6), //! Whether resource can be promoted and demoted pcmk_rsc_promotable = (1ULL << 7), //! Whether resource has not yet been assigned to a node pcmk_rsc_unassigned = (1ULL << 8), //! Whether resource is in the process of being assigned to a node pcmk_rsc_assigning = (1ULL << 9), //! Whether resource is in the process of modifying allowed node scores pcmk_rsc_updating_nodes = (1ULL << 10), //! Whether resource is in the process of scheduling actions to restart pcmk_rsc_restarting = (1ULL << 11), //! Whether resource must be stopped (instead of demoted) if it is failed pcmk_rsc_stop_if_failed = (1ULL << 12), //! Whether a reload action has been scheduled for resource pcmk_rsc_reload = (1ULL << 13), //! Whether resource is a remote connection allowed to run on a remote node pcmk_rsc_remote_nesting_allowed = (1ULL << 14), //! Whether resource has "critical" meta-attribute enabled pcmk_rsc_critical = (1ULL << 15), //! Whether resource is considered failed pcmk_rsc_failed = (1ULL << 16), //! Flag for non-scheduler code to use to detect recursion loops pcmk_rsc_detect_loop = (1ULL << 17), //! \deprecated Do not use pcmk_rsc_runnable = (1ULL << 18), //! Whether resource has pending start action in history pcmk_rsc_start_pending = (1ULL << 19), //! \deprecated Do not use pcmk_rsc_starting = (1ULL << 20), //! \deprecated Do not use pcmk_rsc_stopping = (1ULL << 21), //! Whether resource is multiply active with recovery set to stop_unexpected pcmk_rsc_stop_unexpected = (1ULL << 22), //! Whether resource is allowed to live-migrate pcmk_rsc_migratable = (1ULL << 23), //! Whether resource has an ignorable failure pcmk_rsc_ignore_failure = (1ULL << 24), //! Whether resource is an implicit container resource for a bundle replica pcmk_rsc_replica_container = (1ULL << 25), //! Whether resource, its node, or entire cluster is in maintenance mode pcmk_rsc_maintenance = (1ULL << 26), //! \deprecated Do not use pcmk_rsc_has_filler = (1ULL << 27), //! Whether resource can be started or promoted only on quorate nodes pcmk_rsc_needs_quorum = (1ULL << 28), //! Whether resource requires fencing before recovery if on unclean node pcmk_rsc_needs_fencing = (1ULL << 29), //! Whether resource can be started or promoted only on unfenced nodes pcmk_rsc_needs_unfencing = (1ULL << 30), }; //! Search options for resources (exact resource ID always matches) enum pe_find { //! Also match clone instance ID from resource history pcmk_rsc_match_history = (1 << 0), //! Also match anonymous clone instances by base name pcmk_rsc_match_anon_basename = (1 << 1), //! Match only clones and their instances, by either clone or instance ID pcmk_rsc_match_clone_only = (1 << 2), //! If matching by node, compare current node instead of assigned node pcmk_rsc_match_current_node = (1 << 3), //! \deprecated Do not use pe_find_inactive = (1 << 4), //! Match clone instances (even unique) by base name as well as exact ID pcmk_rsc_match_basename = (1 << 5), #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1) //! \deprecated Use pcmk_rsc_match_history instead pe_find_renamed = pcmk_rsc_match_history, //! \deprecated Use pcmk_rsc_match_anon_basename instead pe_find_anon = pcmk_rsc_match_anon_basename, //! \deprecated Use pcmk_rsc_match_clone_only instead pe_find_clone = pcmk_rsc_match_clone_only, //! \deprecated Use pcmk_rsc_match_current_node instead pe_find_current = pcmk_rsc_match_current_node, //! \deprecated Use pcmk_rsc_match_basename instead pe_find_any = pcmk_rsc_match_basename, #endif }; //!@{ //! \deprecated Do not use enum pe_restart { pe_restart_restart, pe_restart_ignore, }; enum pe_print_options { pe_print_log = (1 << 0), pe_print_html = (1 << 1), pe_print_ncurses = (1 << 2), pe_print_printf = (1 << 3), pe_print_dev = (1 << 4), // Ignored pe_print_details = (1 << 5), // Ignored pe_print_max_details = (1 << 6), // Ignored pe_print_rsconly = (1 << 7), pe_print_ops = (1 << 8), pe_print_suppres_nl = (1 << 9), pe_print_xml = (1 << 10), pe_print_brief = (1 << 11), pe_print_pending = (1 << 12), pe_print_clone_details = (1 << 13), pe_print_clone_active = (1 << 14), // Print clone instances only if active pe_print_implicit = (1 << 15) // Print implicitly created resources }; //!@} // Resource assignment methods (implementation defined by libpacemaker) //! This type should be considered internal to Pacemaker typedef struct resource_alloc_functions_s pcmk_assignment_methods_t; +//! Resource object methods +struct resource_object_functions_s { + /*! + * \brief Parse variant-specific resource XML from CIB into struct members + * + * \param[in,out] rsc Partially unpacked resource + * \param[in,out] scheduler Scheduler data + * + * \return TRUE if resource was unpacked successfully, otherwise FALSE + */ + gboolean (*unpack)(pcmk_resource_t *rsc, pcmk_scheduler_t *scheduler); + + /*! + * \brief Search for a resource ID in a resource and its children + * + * \param[in] rsc Search this resource and its children + * \param[in] id Search for this resource ID + * \param[in] on_node If not NULL, limit search to resources on this node + * \param[in] flags Group of enum pe_find flags + * + * \return Resource that matches search criteria if any, otherwise NULL + */ + pcmk_resource_t *(*find_rsc)(pcmk_resource_t *rsc, const char *search, + const pcmk_node_t *node, int flags); + + /*! + * \brief Get value of a resource instance attribute + * + * \param[in,out] rsc Resource to check + * \param[in] node Node to use to evaluate rules + * \param[in] create Ignored + * \param[in] name Name of instance attribute to check + * \param[in,out] scheduler Scheduler data + * + * \return Value of requested attribute if available, otherwise NULL + * \note The caller is responsible for freeing the result using free(). + */ + char *(*parameter)(pcmk_resource_t *rsc, pcmk_node_t *node, gboolean create, + const char *name, pcmk_scheduler_t *scheduler); + + //! \deprecated Do not use + void (*print)(pcmk_resource_t *rsc, const char *pre_text, long options, + void *print_data); + + /*! + * \brief Check whether a resource is active + * + * \param[in] rsc Resource to check + * \param[in] all If \p rsc is collective, all instances must be active + * + * \return TRUE if \p rsc is active, otherwise FALSE + */ + gboolean (*active)(pcmk_resource_t *rsc, gboolean all); + + /*! + * \brief Get resource's current or assigned role + * + * \param[in] rsc Resource to check + * \param[in] current If TRUE, check current role, otherwise assigned role + * + * \return Current or assigned role of \p rsc + */ + enum rsc_role_e (*state)(const pcmk_resource_t *rsc, gboolean current); + + /*! + * \brief List nodes where a resource (or any of its children) is + * + * \param[in] rsc Resource to check + * \param[out] list List to add result to + * \param[in] current If 0, list nodes where \p rsc is assigned; + * if 1, where active; if 2, where active or pending + * + * \return If list contains only one node, that node, otherwise NULL + */ + pcmk_node_t *(*location)(const pcmk_resource_t *rsc, GList **list, + int current); + + /*! + * \brief Free all memory used by a resource + * + * \param[in,out] rsc Resource to free + */ + void (*free)(pcmk_resource_t *rsc); + + /*! + * \brief Increment cluster's instance counts for a resource + * + * Given a resource, increment its cluster's ninstances, disabled_resources, + * and blocked_resources counts for the resource and its descendants. + * + * \param[in,out] rsc Resource to count + */ + void (*count)(pcmk_resource_t *rsc); + + /*! + * \brief Check whether a given resource is in a list of resources + * + * \param[in] rsc Resource ID to check for + * \param[in] only_rsc List of resource IDs to check + * \param[in] check_parent If TRUE, check top ancestor as well + * + * \return TRUE if \p rsc, its top parent if requested, or '*' is in + * \p only_rsc, otherwise FALSE + */ + gboolean (*is_filtered)(const pcmk_resource_t *rsc, GList *only_rsc, + gboolean check_parent); + + /*! + * \brief Find a node (and optionally count all) where resource is active + * + * \param[in] rsc Resource to check + * \param[out] count_all If not NULL, set this to count of active nodes + * \param[out] count_clean If not NULL, set this to count of clean nodes + * + * \return A node where the resource is active, preferring the source node + * if the resource is involved in a partial migration, or a clean, + * online node if the resource's "requires" is "quorum" or + * "nothing", otherwise NULL. + */ + pcmk_node_t *(*active_node)(const pcmk_resource_t *rsc, + unsigned int *count_all, + unsigned int *count_clean); + + /*! + * \brief Get maximum resource instances per node + * + * \param[in] rsc Resource to check + * + * \return Maximum number of \p rsc instances that can be active on one node + */ + unsigned int (*max_per_node)(const pcmk_resource_t *rsc); +}; + #ifdef __cplusplus } #endif #endif // PCMK__CRM_COMMON_RESOURCES__H diff --git a/include/crm/pengine/pe_types.h b/include/crm/pengine/pe_types.h index 7d28b30edf..f714c208fe 100644 --- a/include/crm/pengine/pe_types.h +++ b/include/crm/pengine/pe_types.h @@ -1,343 +1,303 @@ /* * Copyright 2004-2023 the Pacemaker project contributors * * The version control history for this file may have further details. * * This source code is licensed under the GNU Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #ifndef PCMK__CRM_PENGINE_PE_TYPES__H # define PCMK__CRM_PENGINE_PE_TYPES__H # include // bool # include // time_t # include // xmlNode # include // gboolean, guint, GList, GHashTable # include # include # include #ifdef __cplusplus extern "C" { #endif /*! * \file * \brief Data types for cluster status * \ingroup pengine */ -typedef struct resource_object_functions_s { - gboolean (*unpack)(pcmk_resource_t*, pcmk_scheduler_t*); - pcmk_resource_t *(*find_rsc)(pcmk_resource_t *parent, const char *search, - const pcmk_node_t *node, int flags); - /* parameter result must be free'd */ - char *(*parameter)(pcmk_resource_t*, pcmk_node_t*, gboolean, const char*, - pcmk_scheduler_t*); - //! \deprecated will be removed in a future release - void (*print)(pcmk_resource_t*, const char*, long, void*); - gboolean (*active)(pcmk_resource_t*, gboolean); - enum rsc_role_e (*state)(const pcmk_resource_t*, gboolean); - pcmk_node_t *(*location)(const pcmk_resource_t*, GList**, int); - void (*free)(pcmk_resource_t*); - void (*count)(pcmk_resource_t*); - gboolean (*is_filtered)(const pcmk_resource_t*, GList *, gboolean); - - /*! - * \brief Find a node (and optionally count all) where resource is active - * - * \param[in] rsc Resource to check - * \param[out] count_all If not NULL, set this to count of active nodes - * \param[out] count_clean If not NULL, set this to count of clean nodes - * - * \return A node where the resource is active, preferring the source node - * if the resource is involved in a partial migration or a clean, - * online node if the resource's "requires" is "quorum" or - * "nothing", or NULL if the resource is inactive. - */ - pcmk_node_t *(*active_node)(const pcmk_resource_t *rsc, - unsigned int *count_all, - unsigned int *count_clean); - - /*! - * \brief Get maximum resource instances per node - * - * \param[in] rsc Resource to check - * - * \return Maximum number of \p rsc instances that can be active on one node - */ - unsigned int (*max_per_node)(const pcmk_resource_t *rsc); -} resource_object_functions_t; +typedef struct resource_object_functions_s resource_object_functions_t; struct pe_working_set_s { xmlNode *input; crm_time_t *now; /* options extracted from the input */ char *dc_uuid; pcmk_node_t *dc_node; const char *stonith_action; const char *placement_strategy; unsigned long long flags; int stonith_timeout; enum pe_quorum_policy no_quorum_policy; GHashTable *config_hash; GHashTable *tickets; // Actions for which there can be only one (e.g. fence nodeX) GHashTable *singletons; GList *nodes; GList *resources; GList *placement_constraints; GList *ordering_constraints; GList *colocation_constraints; GList *ticket_constraints; GList *actions; xmlNode *failed; xmlNode *op_defaults; xmlNode *rsc_defaults; /* stats */ int num_synapse; int max_valid_nodes; //! Deprecated (will be removed in a future release) int order_id; int action_id; /* final output */ xmlNode *graph; GHashTable *template_rsc_sets; const char *localhost; GHashTable *tags; int blocked_resources; int disabled_resources; GList *param_check; // History entries that need to be checked GList *stop_needed; // Containers that need stop actions time_t recheck_by; // Hint to controller to re-run scheduler by this time int ninstances; // Total number of resource instances guint shutdown_lock;// How long (seconds) to lock resources to shutdown node int priority_fencing_delay; // Priority fencing delay void *priv; guint node_pending_timeout; // Node pending timeout }; struct pe_resource_s { char *id; char *clone_name; xmlNode *xml; xmlNode *orig_xml; xmlNode *ops_xml; pcmk_scheduler_t *cluster; pcmk_resource_t *parent; enum pe_obj_types variant; void *variant_opaque; resource_object_functions_t *fns; pcmk_assignment_methods_t *cmds; enum rsc_recovery_type recovery_type; enum pe_restart restart_type; //!< \deprecated will be removed in future release int priority; int stickiness; int sort_index; int failure_timeout; int migration_threshold; guint remote_reconnect_ms; char *pending_task; unsigned long long flags; // @TODO merge these into flags gboolean is_remote_node; gboolean exclusive_discover; /* Pay special attention to whether you want to use rsc_cons_lhs and * rsc_cons directly, which include only colocations explicitly involving * this resource, or call libpacemaker's pcmk__with_this_colocations() and * pcmk__this_with_colocations() functions, which may return relevant * colocations involving the resource's ancestors as well. */ //!@{ //! This field should be treated as internal to Pacemaker GList *rsc_cons_lhs; // List of pcmk__colocation_t* GList *rsc_cons; // List of pcmk__colocation_t* GList *rsc_location; // List of pe__location_t* GList *actions; // List of pcmk_action_t* GList *rsc_tickets; // List of rsc_ticket* //!@} pcmk_node_t *allocated_to; pcmk_node_t *partial_migration_target; pcmk_node_t *partial_migration_source; GList *running_on; // pcmk_node_t* GHashTable *known_on; // pcmk_node_t* GHashTable *allowed_nodes; // pcmk_node_t* enum rsc_role_e role; enum rsc_role_e next_role; GHashTable *meta; GHashTable *parameters; //! \deprecated Use pe_rsc_params() instead GHashTable *utilization; GList *children; // pcmk_resource_t* GList *dangling_migrations; // pcmk_node_t* pcmk_resource_t *container; GList *fillers; // @COMPAT These should be made const at next API compatibility break pcmk_node_t *pending_node; // Node on which pending_task is happening pcmk_node_t *lock_node; // Resource is shutdown-locked to this node time_t lock_time; // When shutdown lock started /* Resource parameters may have node-attribute-based rules, which means the * values can vary by node. This table is a cache of parameter name/value * tables for each node (as needed). Use pe_rsc_params() to get the table * for a given node. */ GHashTable *parameter_cache; // Key = node name, value = parameters table }; struct pe_action_s { int id; int priority; pcmk_resource_t *rsc; pcmk_node_t *node; xmlNode *op_entry; char *task; char *uuid; char *cancel_task; char *reason; enum pe_action_flags flags; enum rsc_start_requirement needs; enum action_fail_response on_fail; enum rsc_role_e fail_role; GHashTable *meta; GHashTable *extra; /* * These two varables are associated with the constraint logic * that involves first having one or more actions runnable before * then allowing this action to execute. * * These varables are used with features such as 'clone-min' which * requires at minimum X number of cloned instances to be running * before an order dependency can run. Another option that uses * this is 'require-all=false' in ordering constrants. This option * says "only require one instance of a resource to start before * allowing dependencies to start" -- basically, require-all=false is * the same as clone-min=1. */ /* current number of known runnable actions in the before list. */ int runnable_before; /* the number of "before" runnable actions required for this action * to be considered runnable */ int required_runnable_before; GList *actions_before; /* pe_action_wrapper_t* */ GList *actions_after; /* pe_action_wrapper_t* */ /* Some of the above fields could be moved to the details, * except for API backward compatibility. */ void *action_details; // varies by type of action }; typedef struct pe_ticket_s { char *id; gboolean granted; time_t last_granted; gboolean standby; GHashTable *state; } pe_ticket_t; typedef struct pe_tag_s { char *id; GList *refs; } pe_tag_t; //!@{ //! \deprecated Do not use enum pe_ordering { pe_order_none = 0x0, /* deleted */ #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1) pe_order_optional = 0x1, /* pure ordering, nothing implied */ pe_order_apply_first_non_migratable = 0x2, /* Only apply this constraint's ordering if first is not migratable. */ pe_order_implies_first = 0x10, /* If 'then' is required, ensure 'first' is too */ pe_order_implies_then = 0x20, /* If 'first' is required, ensure 'then' is too */ pe_order_promoted_implies_first = 0x40, /* If 'then' is required and then's rsc is promoted, ensure 'first' becomes required too */ /* first requires then to be both runnable and migrate runnable. */ pe_order_implies_first_migratable = 0x80, pe_order_runnable_left = 0x100, /* 'then' requires 'first' to be runnable */ pe_order_pseudo_left = 0x200, /* 'then' can only be pseudo if 'first' is runnable */ pe_order_implies_then_on_node = 0x400, /* If 'first' is required on 'nodeX', * ensure instances of 'then' on 'nodeX' are too. * Only really useful if 'then' is a clone and 'first' is not */ pe_order_probe = 0x800, /* If 'first->rsc' is * - running but about to stop, ignore the constraint * - otherwise, behave as runnable_left */ pe_order_restart = 0x1000, /* 'then' is runnable if 'first' is optional or runnable */ pe_order_stonith_stop = 0x2000, pe_order_serialize_only = 0x4000, /* serialize */ pe_order_same_node = 0x8000, /* applies only if 'first' and 'then' are on same node */ pe_order_implies_first_printed = 0x10000, /* Like ..implies_first but only ensures 'first' is printed, not mandatory */ pe_order_implies_then_printed = 0x20000, /* Like ..implies_then but only ensures 'then' is printed, not mandatory */ pe_order_asymmetrical = 0x100000, /* Indicates asymmetrical one way ordering constraint. */ pe_order_load = 0x200000, /* Only relevant if... */ pe_order_one_or_more = 0x400000, /* 'then' is runnable only if one or more of its dependencies are too */ pe_order_anti_colocation = 0x800000, pe_order_preserve = 0x1000000, /* Hack for breaking user ordering constraints with container resources */ pe_order_then_cancels_first = 0x2000000, // if 'then' becomes required, 'first' becomes optional pe_order_trace = 0x4000000, /* test marker */ pe_order_implies_first_master = pe_order_promoted_implies_first, #endif }; //!@} typedef struct pe_action_wrapper_s { enum pe_ordering type; enum pe_link_state state; pcmk_action_t *action; } pe_action_wrapper_t; #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1) #include #endif #ifdef __cplusplus } #endif #endif // PCMK__CRM_PENGINE_PE_TYPES__H