diff --git a/include/crm/common/nodes_internal.h b/include/crm/common/nodes_internal.h index 4e0dd86691..b8525758a3 100644 --- a/include/crm/common/nodes_internal.h +++ b/include/crm/common/nodes_internal.h @@ -1,202 +1,204 @@ /* * Copyright 2024 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_NODES_INTERNAL__H #define PCMK__CRM_COMMON_NODES_INTERNAL__H #include // NULL #include // bool #include // uint32_t, UINT32_C() -#include +#include // gpointer, GList, GHashTable #include #ifdef __cplusplus extern "C" { #endif /* * Special node attributes */ #define PCMK__NODE_ATTR_SHUTDOWN "shutdown" /* @COMPAT Deprecated since 2.1.8. Use a location constraint with * PCMK_XA_RSC_PATTERN=".*" and PCMK_XA_RESOURCE_DISCOVERY="never" instead of * PCMK__NODE_ATTR_RESOURCE_DISCOVERY_ENABLED="false". */ #define PCMK__NODE_ATTR_RESOURCE_DISCOVERY_ENABLED "resource-discovery-enabled" enum pcmk__node_variant { // Possible node types pcmk__node_variant_cluster = 1, // Cluster layer node pcmk__node_variant_remote = 2, // Pacemaker Remote node }; enum pcmk__node_flags { pcmk__node_none = UINT32_C(0), // Whether node is in standby mode pcmk__node_standby = (UINT32_C(1) << 0), // Whether node is in standby mode due to PCMK_META_ON_FAIL pcmk__node_fail_standby = (UINT32_C(1) << 1), // Whether node has ever joined cluster (and thus has node state in CIB) pcmk__node_seen = (UINT32_C(1) << 2), // Whether expected join state is member pcmk__node_expected_up = (UINT32_C(1) << 3), // Whether probes are allowed on node pcmk__node_probes_allowed = (UINT32_C(1) << 4), /* Whether this either is a guest node whose guest resource must be * recovered or a remote node that must be fenced */ pcmk__node_remote_reset = (UINT32_C(1) << 5), /* Whether this is a Pacemaker Remote node that was fenced since it was last * connected by the cluster */ pcmk__node_remote_fenced = (UINT32_C(1) << 6), /* * Whether this is a Pacemaker Remote node previously marked in its * node state as being in maintenance mode */ pcmk__node_remote_maint = (UINT32_C(1) << 7), // Whether node history has been unpacked pcmk__node_unpacked = (UINT32_C(1) << 8), }; // When to probe a resource on a node (as specified in location constraints) enum pcmk__probe_mode { pcmk__probe_always = 0, // Always probe resource on node pcmk__probe_never = 1, // Never probe resource on node pcmk__probe_exclusive = 2, // Probe only on designated nodes }; /* Per-node data used in resource assignment * * @COMPAT When we can make the pcmk_node_t implementation internal, move these * there and drop this struct. */ struct pcmk__node_assignment { int score; // Node's score for relevant resource int count; // Counter reused by assignment and promotion code enum pcmk__probe_mode probe_mode; // When to probe resource on this node }; /* Implementation of pcmk__node_private_t (pcmk_node_t objects are shallow * copies, so all pcmk_node_t objects for the same node will share the same * private data) */ struct pcmk__node_private { /* Node's XML ID in the CIB (the cluster layer ID for cluster nodes, * the node name for Pacemaker Remote nodes) */ const char *id; /* * Sum of priorities of all resources active on node and on any guest nodes * connected to this node, with +1 for promoted instances (used to compare * nodes for PCMK_OPT_PRIORITY_FENCING_DELAY) */ int priority; const char *name; // Node name in cluster enum pcmk__node_variant variant; // Node variant uint32_t flags; // Group of enum pcmk__node_flags GHashTable *attrs; // Node attributes GHashTable *utilization; // Node utilization attributes int num_resources; // Number of active resources on node GList *assigned_resources; // List of resources assigned to node GHashTable *digest_cache; // Cache of calculated resource digests pcmk_resource_t *remote; // Pacemaker Remote connection (if any) pcmk_scheduler_t *scheduler; // Scheduler data that node is part of }; void pcmk__free_node_copy(void *data); pcmk_node_t *pcmk__find_node_in_list(const GList *nodes, const char *node_name); /*! * \internal * \brief Set node flags * * \param[in,out] node Node to set flags for * \param[in] flags_to_set Group of enum pcmk_node_flags to set */ #define pcmk__set_node_flags(node, flags_to_set) do { \ (node)->priv->flags = pcmk__set_flags_as(__func__, __LINE__, \ LOG_TRACE, "Node", pcmk__node_name(node), \ (node)->priv->flags, (flags_to_set), #flags_to_set); \ } while (0) /*! * \internal * \brief Clear node flags * * \param[in,out] node Node to clear flags for * \param[in] flags_to_clear Group of enum pcmk_node_flags to clear */ #define pcmk__clear_node_flags(node, flags_to_clear) do { \ (node)->priv->flags = pcmk__clear_flags_as(__func__, __LINE__, \ LOG_TRACE, "Node", pcmk__node_name(node), \ (node)->priv->flags, (flags_to_clear), #flags_to_clear); \ } while (0) +void pcmk__free_node(gpointer user_data); + /*! * \internal * \brief Return a string suitable for logging as a node name * * \param[in] node Node to return a node name string for * * \return Node name if available, otherwise node ID if available, * otherwise "unspecified node" if node is NULL or "unidentified node" * if node has neither a name nor ID. */ static inline const char * pcmk__node_name(const pcmk_node_t *node) { if (node == NULL) { return "unspecified node"; } else if (node->priv->name != NULL) { return node->priv->name; } else if (node->priv->id != NULL) { return node->priv->id; } else { return "unidentified node"; } } /*! * \internal * \brief Check whether two node objects refer to the same node * * \param[in] node1 First node object to compare * \param[in] node2 Second node object to compare * * \return true if \p node1 and \p node2 refer to the same node */ static inline bool pcmk__same_node(const pcmk_node_t *node1, const pcmk_node_t *node2) { return (node1 != NULL) && (node2 != NULL) && (node1->priv == node2->priv); } #ifdef __cplusplus } #endif #endif // PCMK__CRM_COMMON_NODES_INTERNAL__H diff --git a/lib/common/nodes.c b/lib/common/nodes.c index fed3159464..4a059e6520 100644 --- a/lib/common/nodes.c +++ b/lib/common/nodes.c @@ -1,212 +1,254 @@ /* * Copyright 2022-2024 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. */ #include #include // xmlNode #include +/*! + * \internal + * \brief Free a node object + * + * \param[in,out] user_data Node object to free + */ +void +pcmk__free_node(gpointer user_data) +{ + pcmk_node_t *node = user_data; + + if (node == NULL) { + return; + } + if (node->details == NULL) { + free(node); + return; + } + + /* This may be called after freeing resources, which means that we can't + * use node->private->name for Pacemaker Remote nodes. + */ + crm_trace("Freeing node %s", (pcmk__is_pacemaker_remote_node(node)? + "(guest or remote)" : pcmk__node_name(node))); + + if (node->priv->attrs != NULL) { + g_hash_table_destroy(node->priv->attrs); + } + if (node->priv->utilization != NULL) { + g_hash_table_destroy(node->priv->utilization); + } + if (node->priv->digest_cache != NULL) { + g_hash_table_destroy(node->priv->digest_cache); + } + g_list_free(node->details->running_rsc); + g_list_free(node->priv->assigned_resources); + free(node->priv); + free(node->details); + free(node->assign); + free(node); +} + /*! * \internal * \brief Free a copy of a node object * * \param[in] data Node copy (created by pe__copy_node()) to free */ void pcmk__free_node_copy(void *data) { if (data != NULL) { pcmk_node_t *node = data; if (node->assign != NULL) { // This is the only member allocated separately for a node copy free(node->assign); } free(node); } } /*! * \internal * \brief Check whether a node is online * * \param[in] node Node to check * * \return true if \p node is online, otherwise false */ bool pcmk_node_is_online(const pcmk_node_t *node) { return (node != NULL) && node->details->online; } /*! * \internal * \brief Check whether a node is pending * * Check whether a node is pending. A node is pending if it is a member of the * cluster but not the controller group, which means it is in the process of * either joining or leaving the cluster. * * \param[in] node Node to check * * \return true if \p node is pending, otherwise false */ bool pcmk_node_is_pending(const pcmk_node_t *node) { return (node != NULL) && node->details->pending; } /*! * \internal * \brief Check whether a node is clean * * Check whether a node is clean. A node is clean if it is a cluster node or * remote node that has been seen by the cluster at least once, or the * startup-fencing cluster option is false; and the node, and its host if a * guest or bundle node, are not scheduled to be fenced. * * \param[in] node Node to check * * \return true if \p node is clean, otherwise false */ bool pcmk_node_is_clean(const pcmk_node_t *node) { return (node != NULL) && !(node->details->unclean); } /*! * \internal * \brief Check whether a node is shutting down * * \param[in] node Node to check * * \return true if \p node is shutting down, otherwise false */ bool pcmk_node_is_shutting_down(const pcmk_node_t *node) { return (node != NULL) && node->details->shutdown; } /*! * \internal * \brief Check whether a node is in maintenance mode * * \param[in] node Node to check * * \return true if \p node is in maintenance mode, otherwise false */ bool pcmk_node_is_in_maintenance(const pcmk_node_t *node) { return (node != NULL) && node->details->maintenance; } /*! * \internal * \brief Call a function for each resource active on a node * * Call a caller-supplied function with a caller-supplied argument for each * resource that is active on a given node. If the function returns false, this * function will return immediately without processing any remaining resources. * * \param[in] node Node to check * * \return Result of last call of \p fn (or false if none) */ bool pcmk_foreach_active_resource(pcmk_node_t *node, bool (*fn)(pcmk_resource_t *, void *), void *user_data) { bool result = false; if ((node != NULL) && (fn != NULL)) { for (GList *item = node->details->running_rsc; item != NULL; item = item->next) { result = fn((pcmk_resource_t *) item->data, user_data); if (!result) { break; } } } return result; } void pcmk__xe_add_node(xmlNode *xml, const char *node, int nodeid) { pcmk__assert(xml != NULL); if (node != NULL) { crm_xml_add(xml, PCMK__XA_ATTR_HOST, node); } if (nodeid > 0) { crm_xml_add_int(xml, PCMK__XA_ATTR_HOST_ID, nodeid); } } /*! * \internal * \brief Find a node by name in a list of nodes * * \param[in] nodes List of nodes (as pcmk_node_t*) * \param[in] node_name Name of node to find * * \return Node from \p nodes that matches \p node_name if any, otherwise NULL */ pcmk_node_t * pcmk__find_node_in_list(const GList *nodes, const char *node_name) { if (node_name != NULL) { for (const GList *iter = nodes; iter != NULL; iter = iter->next) { pcmk_node_t *node = (pcmk_node_t *) iter->data; if (pcmk__str_eq(node->priv->name, node_name, pcmk__str_casei)) { return node; } } } return NULL; } #define XP_SHUTDOWN "//" PCMK__XE_NODE_STATE "[@" PCMK_XA_UNAME "='%s']/" \ PCMK__XE_TRANSIENT_ATTRIBUTES "/" PCMK_XE_INSTANCE_ATTRIBUTES "/" \ PCMK_XE_NVPAIR "[@" PCMK_XA_NAME "='" PCMK__NODE_ATTR_SHUTDOWN "']" /*! * \brief Get value of a node's shutdown attribute from CIB, if present * * \param[in] cib CIB to check * \param[in] node Name of node to check * * \return Value of shutdown attribute for \p node in \p cib if any, * otherwise NULL * \note The return value is a pointer into \p cib and so is valid only for the * lifetime of that object. */ const char * pcmk_cib_node_shutdown(xmlNode *cib, const char *node) { if ((cib != NULL) && (node != NULL)) { char *xpath = crm_strdup_printf(XP_SHUTDOWN, node); xmlNode *match = get_xpath_object(xpath, cib, LOG_TRACE); free(xpath); if (match != NULL) { return crm_element_value(match, PCMK_XA_VALUE); } } return NULL; } diff --git a/lib/pengine/status.c b/lib/pengine/status.c index 28b40f10c2..4b37cb7db7 100644 --- a/lib/pengine/status.c +++ b/lib/pengine/status.c @@ -1,505 +1,464 @@ /* * Copyright 2004-2024 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. */ #include #include #include #include #include #include #include #include /*! * \brief Create a new object to hold scheduler data * * \return New, initialized scheduler data on success, else NULL (and set errno) * \note Only pcmk_scheduler_t objects created with this function (as opposed * to statically declared or directly allocated) should be used with the * functions in this library, to allow for future extensions to the * data type. The caller is responsible for freeing the memory with * pe_free_working_set() when the instance is no longer needed. */ pcmk_scheduler_t * pe_new_working_set(void) { pcmk_scheduler_t *scheduler = calloc(1, sizeof(pcmk_scheduler_t)); if (scheduler == NULL) { return NULL; } scheduler->priv = calloc(1, sizeof(pcmk__scheduler_private_t)); if (scheduler->priv == NULL) { free(scheduler); return NULL; } pcmk__set_scheduler_defaults(scheduler); return scheduler; } /*! * \brief Free scheduler data * * \param[in,out] scheduler Scheduler data to free */ void pe_free_working_set(pcmk_scheduler_t *scheduler) { if (scheduler != NULL) { pe_reset_working_set(scheduler); free(scheduler->priv->local_node_name); free(scheduler->priv); free(scheduler); } } #define XPATH_DEPRECATED_RULES \ "//" PCMK_XE_OP_DEFAULTS "//" PCMK_XE_EXPRESSION \ "|//" PCMK_XE_OP "//" PCMK_XE_EXPRESSION /*! * \internal * \brief Log a warning for deprecated rule syntax in operations * * \param[in] scheduler Scheduler data */ static void check_for_deprecated_rules(pcmk_scheduler_t *scheduler) { // @COMPAT Drop this function when support for the syntax is dropped xmlNode *deprecated = get_xpath_object(XPATH_DEPRECATED_RULES, scheduler->input, LOG_NEVER); if (deprecated != NULL) { pcmk__warn_once(pcmk__wo_op_attr_expr, "Support for rules with node attribute expressions in " PCMK_XE_OP " or " PCMK_XE_OP_DEFAULTS " is deprecated " "and will be dropped in a future release"); } } /* * Unpack everything * At the end you'll have: * - A list of nodes * - A list of resources (each with any dependencies on other resources) * - A list of constraints between resources and nodes * - A list of constraints between start/stop actions * - A list of nodes that need to be stonith'd * - A list of nodes that need to be shutdown * - A list of the possible stop/start actions (without dependencies) */ gboolean cluster_status(pcmk_scheduler_t * scheduler) { const char *new_version = NULL; xmlNode *section = NULL; if ((scheduler == NULL) || (scheduler->input == NULL)) { return FALSE; } new_version = crm_element_value(scheduler->input, PCMK_XA_CRM_FEATURE_SET); if (pcmk__check_feature_set(new_version) != pcmk_rc_ok) { pcmk__config_err("Can't process CIB with feature set '%s' greater than our own '%s'", new_version, CRM_FEATURE_SET); return FALSE; } crm_trace("Beginning unpack"); if (scheduler->priv->failed != NULL) { pcmk__xml_free(scheduler->priv->failed); } scheduler->priv->failed = pcmk__xe_create(NULL, "failed-ops"); if (scheduler->priv->now == NULL) { scheduler->priv->now = crm_time_new(NULL); } if (pcmk__xe_attr_is_true(scheduler->input, PCMK_XA_HAVE_QUORUM)) { pcmk__set_scheduler_flags(scheduler, pcmk__sched_quorate); } else { pcmk__clear_scheduler_flags(scheduler, pcmk__sched_quorate); } scheduler->priv->op_defaults = get_xpath_object("//" PCMK_XE_OP_DEFAULTS, scheduler->input, LOG_NEVER); check_for_deprecated_rules(scheduler); scheduler->priv->rsc_defaults = get_xpath_object("//" PCMK_XE_RSC_DEFAULTS, scheduler->input, LOG_NEVER); section = get_xpath_object("//" PCMK_XE_CRM_CONFIG, scheduler->input, LOG_TRACE); unpack_config(section, scheduler); if (!pcmk_any_flags_set(scheduler->flags, pcmk__sched_location_only|pcmk__sched_quorate) && (scheduler->no_quorum_policy != pcmk_no_quorum_ignore)) { pcmk__sched_warn(scheduler, "Fencing and resource management disabled " "due to lack of quorum"); } section = get_xpath_object("//" PCMK_XE_NODES, scheduler->input, LOG_TRACE); unpack_nodes(section, scheduler); section = get_xpath_object("//" PCMK_XE_RESOURCES, scheduler->input, LOG_TRACE); if (!pcmk_is_set(scheduler->flags, pcmk__sched_location_only)) { unpack_remote_nodes(section, scheduler); } unpack_resources(section, scheduler); section = get_xpath_object("//" PCMK_XE_FENCING_TOPOLOGY, scheduler->input, LOG_TRACE); pcmk__validate_fencing_topology(section); section = get_xpath_object("//" PCMK_XE_TAGS, scheduler->input, LOG_NEVER); unpack_tags(section, scheduler); if (!pcmk_is_set(scheduler->flags, pcmk__sched_location_only)) { section = get_xpath_object("//" PCMK_XE_STATUS, scheduler->input, LOG_TRACE); unpack_status(section, scheduler); } if (!pcmk_is_set(scheduler->flags, pcmk__sched_no_counts)) { for (GList *item = scheduler->priv->resources; item != NULL; item = item->next) { pcmk_resource_t *rsc = item->data; rsc->priv->fns->count(item->data); } crm_trace("Cluster resource count: %d (%d disabled, %d blocked)", scheduler->priv->ninstances, scheduler->priv->disabled_resources, scheduler->priv->blocked_resources); } if ((scheduler->priv->local_node_name != NULL) && (pcmk_find_node(scheduler, scheduler->priv->local_node_name) == NULL)) { crm_info("Creating a fake local node for %s", scheduler->priv->local_node_name); pe_create_node(scheduler->priv->local_node_name, scheduler->priv->local_node_name, NULL, 0, scheduler); } pcmk__set_scheduler_flags(scheduler, pcmk__sched_have_status); return TRUE; } static void pe_free_actions(GList *actions) { GList *iterator = actions; while (iterator != NULL) { pe_free_action(iterator->data); iterator = iterator->next; } if (actions != NULL) { g_list_free(actions); } } -static void -pe_free_nodes(GList *nodes) -{ - for (GList *iterator = nodes; iterator != NULL; iterator = iterator->next) { - pcmk_node_t *node = (pcmk_node_t *) iterator->data; - - // Shouldn't be possible, but to be safe ... - if (node == NULL) { - continue; - } - if (node->details == NULL) { - free(node); - continue; - } - - /* This is called after freeing resources, which means that we can't - * use node->private->name for Pacemaker Remote nodes. - */ - crm_trace("Freeing node %s", (pcmk__is_pacemaker_remote_node(node)? - "(guest or remote)" : pcmk__node_name(node))); - - if (node->priv->attrs != NULL) { - g_hash_table_destroy(node->priv->attrs); - } - if (node->priv->utilization != NULL) { - g_hash_table_destroy(node->priv->utilization); - } - if (node->priv->digest_cache != NULL) { - g_hash_table_destroy(node->priv->digest_cache); - } - g_list_free(node->details->running_rsc); - g_list_free(node->priv->assigned_resources); - free(node->priv); - free(node->details); - free(node->assign); - free(node); - } - if (nodes != NULL) { - g_list_free(nodes); - } -} - static void pe__free_ordering(GList *constraints) { GList *iterator = constraints; while (iterator != NULL) { pcmk__action_relation_t *order = iterator->data; iterator = iterator->next; free(order->task1); free(order->task2); free(order); } if (constraints != NULL) { g_list_free(constraints); } } static void pe__free_location(GList *constraints) { GList *iterator = constraints; while (iterator != NULL) { pcmk__location_t *cons = iterator->data; iterator = iterator->next; g_list_free_full(cons->nodes, pcmk__free_node_copy); free(cons->id); free(cons); } if (constraints != NULL) { g_list_free(constraints); } } /*! * \brief Reset scheduler data to defaults without freeing it or constraints * * \param[in,out] scheduler Scheduler data to reset * * \deprecated This function is deprecated as part of the API; * pe_reset_working_set() should be used instead. */ void cleanup_calculations(pcmk_scheduler_t *scheduler) { if (scheduler == NULL) { return; } pcmk__clear_scheduler_flags(scheduler, pcmk__sched_have_status); if (scheduler->priv->options != NULL) { g_hash_table_destroy(scheduler->priv->options); } if (scheduler->priv->singletons != NULL) { g_hash_table_destroy(scheduler->priv->singletons); } if (scheduler->priv->ticket_constraints != NULL) { g_hash_table_destroy(scheduler->priv->ticket_constraints); } if (scheduler->priv->templates != NULL) { g_hash_table_destroy(scheduler->priv->templates); } if (scheduler->priv->tags != NULL) { g_hash_table_destroy(scheduler->priv->tags); } crm_trace("deleting resources"); g_list_free_full(scheduler->priv->resources, pcmk__free_resource); crm_trace("deleting actions"); pe_free_actions(scheduler->priv->actions); crm_trace("deleting nodes"); - pe_free_nodes(scheduler->nodes); + g_list_free_full(scheduler->nodes, pcmk__free_node); + scheduler->nodes = NULL; pcmk__free_param_checks(scheduler); g_list_free(scheduler->priv->stop_needed); crm_time_free(scheduler->priv->now); pcmk__xml_free(scheduler->input); pcmk__xml_free(scheduler->priv->failed); pcmk__xml_free(scheduler->priv->graph); set_working_set_defaults(scheduler); CRM_LOG_ASSERT((scheduler->priv->location_constraints == NULL) && (scheduler->priv->ordering_constraints == NULL)); } /*! * \brief Reset scheduler data to default state without freeing it * * \param[in,out] scheduler Scheduler data to reset */ void pe_reset_working_set(pcmk_scheduler_t *scheduler) { if (scheduler == NULL) { return; } crm_trace("Deleting %d ordering constraints", g_list_length(scheduler->priv->ordering_constraints)); pe__free_ordering(scheduler->priv->ordering_constraints); scheduler->priv->ordering_constraints = NULL; crm_trace("Deleting %d location constraints", g_list_length(scheduler->priv->location_constraints)); pe__free_location(scheduler->priv->location_constraints); scheduler->priv->location_constraints = NULL; crm_trace("Deleting %d colocation constraints", g_list_length(scheduler->priv->colocation_constraints)); g_list_free_full(scheduler->priv->colocation_constraints, free); scheduler->priv->colocation_constraints = NULL; cleanup_calculations(scheduler); } void set_working_set_defaults(pcmk_scheduler_t *scheduler) { // These members must be preserved pcmk__scheduler_private_t *priv = scheduler->priv; pcmk__output_t *out = priv->out; char *local_node_name = scheduler->priv->local_node_name; // Wipe the main structs (any other members must have previously been freed) memset(scheduler, 0, sizeof(pcmk_scheduler_t)); memset(priv, 0, sizeof(pcmk__scheduler_private_t)); // Restore the members to preserve scheduler->priv = priv; scheduler->priv->out = out; scheduler->priv->local_node_name = local_node_name; // Set defaults for everything else pcmk__set_scheduler_defaults(scheduler); } pcmk_resource_t * pe_find_resource(GList *rsc_list, const char *id) { return pe_find_resource_with_flags(rsc_list, id, pcmk_rsc_match_history); } pcmk_resource_t * pe_find_resource_with_flags(GList *rsc_list, const char *id, enum pe_find flags) { GList *rIter = NULL; for (rIter = rsc_list; id && rIter; rIter = rIter->next) { pcmk_resource_t *parent = rIter->data; pcmk_resource_t *match = parent->priv->fns->find_rsc(parent, id, NULL, flags); if (match != NULL) { return match; } } crm_trace("No match for %s", id); return NULL; } /*! * \brief Find a node by name or ID in a list of nodes * * \param[in] nodes List of nodes (as pcmk_node_t*) * \param[in] id If not NULL, ID of node to find * \param[in] node_name If not NULL, name of node to find * * \return Node from \p nodes that matches \p id if any, * otherwise node from \p nodes that matches \p uname if any, * otherwise NULL */ pcmk_node_t * pe_find_node_any(const GList *nodes, const char *id, const char *uname) { pcmk_node_t *match = NULL; if (id != NULL) { match = pe_find_node_id(nodes, id); } if ((match == NULL) && (uname != NULL)) { match = pcmk__find_node_in_list(nodes, uname); } return match; } /*! * \brief Find a node by ID in a list of nodes * * \param[in] nodes List of nodes (as pcmk_node_t*) * \param[in] id ID of node to find * * \return Node from \p nodes that matches \p id if any, otherwise NULL */ pcmk_node_t * pe_find_node_id(const GList *nodes, const char *id) { for (const GList *iter = nodes; iter != NULL; iter = iter->next) { pcmk_node_t *node = (pcmk_node_t *) iter->data; /* @TODO Whether node IDs should be considered case-sensitive should * probably depend on the node type, so functionizing the comparison * would be worthwhile */ if (pcmk__str_eq(node->priv->id, id, pcmk__str_casei)) { return node; } } return NULL; } // Deprecated functions kept only for backward API compatibility // LCOV_EXCL_START #include /*! * \brief Find a node by name in a list of nodes * * \param[in] nodes List of nodes (as pcmk_node_t*) * \param[in] node_name Name of node to find * * \return Node from \p nodes that matches \p node_name if any, otherwise NULL */ pcmk_node_t * pe_find_node(const GList *nodes, const char *node_name) { return pcmk__find_node_in_list(nodes, node_name); } // LCOV_EXCL_STOP // End deprecated API