Line data Source code
1 : /* 2 : * Copyright 2020-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 : #include <crm_internal.h> 11 : 12 : #include <glib.h> 13 : #include <stdbool.h> 14 : 15 : #include <crm/common/util.h> 16 : #include <crm/common/scheduler.h> 17 : #include <crm/pengine/internal.h> 18 : 19 : GList * 20 0 : pe__rscs_with_tag(pcmk_scheduler_t *scheduler, const char *tag_name) 21 : { 22 : gpointer value; 23 0 : GList *retval = NULL; 24 : 25 0 : if (scheduler->tags == NULL) { 26 0 : return retval; 27 : } 28 : 29 0 : value = g_hash_table_lookup(scheduler->tags, tag_name); 30 : 31 0 : if (value == NULL) { 32 0 : return retval; 33 : } 34 : 35 0 : for (GList *refs = ((pcmk_tag_t *) value)->refs; refs; refs = refs->next) { 36 0 : const char *id = (const char *) refs->data; 37 0 : const uint32_t flags = pcmk_rsc_match_history|pcmk_rsc_match_basename; 38 0 : pcmk_resource_t *rsc = pe_find_resource_with_flags(scheduler->resources, 39 : id, flags); 40 : 41 0 : if (!rsc) { 42 0 : continue; 43 : } 44 : 45 0 : retval = g_list_append(retval, strdup(rsc_printable_id(rsc))); 46 : } 47 : 48 0 : return retval; 49 : } 50 : 51 : GList * 52 0 : pe__unames_with_tag(pcmk_scheduler_t *scheduler, const char *tag_name) 53 : { 54 : gpointer value; 55 0 : GList *retval = NULL; 56 : 57 0 : if (scheduler->tags == NULL) { 58 0 : return retval; 59 : } 60 : 61 0 : value = g_hash_table_lookup(scheduler->tags, tag_name); 62 : 63 0 : if (value == NULL) { 64 0 : return retval; 65 : } 66 : 67 : /* Iterate over the list of node IDs. */ 68 0 : for (GList *refs = ((pcmk_tag_t *) value)->refs; refs; refs = refs->next) { 69 : /* Find the node that has this ID. */ 70 0 : const char *id = (const char *) refs->data; 71 0 : pcmk_node_t *node = pe_find_node_id(scheduler->nodes, id); 72 : 73 0 : if (!node) { 74 0 : continue; 75 : } 76 : 77 : /* Get the uname for the node and add it to the return list. */ 78 0 : retval = g_list_append(retval, strdup(node->details->uname)); 79 : } 80 : 81 0 : return retval; 82 : } 83 : 84 : bool 85 0 : pe__rsc_has_tag(pcmk_scheduler_t *scheduler, const char *rsc_name, 86 : const char *tag_name) 87 : { 88 0 : GList *rscs = pe__rscs_with_tag(scheduler, tag_name); 89 0 : bool retval = false; 90 : 91 0 : if (rscs == NULL) { 92 0 : return retval; 93 : } 94 : 95 0 : retval = g_list_find_custom(rscs, rsc_name, (GCompareFunc) strcmp) != NULL; 96 0 : g_list_free_full(rscs, free); 97 0 : return retval; 98 : } 99 : 100 : bool 101 0 : pe__uname_has_tag(pcmk_scheduler_t *scheduler, const char *node_name, 102 : const char *tag_name) 103 : { 104 0 : GList *unames = pe__unames_with_tag(scheduler, tag_name); 105 0 : bool retval = false; 106 : 107 0 : if (unames == NULL) { 108 0 : return retval; 109 : } 110 : 111 0 : retval = g_list_find_custom(unames, node_name, (GCompareFunc) strcmp) != NULL; 112 0 : g_list_free_full(unames, free); 113 0 : return retval; 114 : }