pacemaker  2.1.0-7c3f660
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
tags.c
Go to the documentation of this file.
1 /*
2  * Copyright 2020-2021 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/pengine/internal.h>
17 #include <crm/pengine/pe_types.h>
18 
19 GList *
20 pe__rscs_with_tag(pe_working_set_t *data_set, const char *tag_name)
21 {
22  gpointer value;
23  GList *retval = NULL;
24 
25  if (data_set->tags == NULL) {
26  return retval;
27  }
28 
29  value = g_hash_table_lookup(data_set->tags, tag_name);
30 
31  if (value == NULL) {
32  return retval;
33  }
34 
35  for (GList *refs = ((pe_tag_t *) value)->refs; refs; refs = refs->next) {
36  const char *id = (const char *) refs->data;
39 
40  if (!rsc) {
41  continue;
42  }
43 
44  retval = g_list_append(retval, strdup(rsc_printable_id(rsc)));
45  }
46 
47  return retval;
48 }
49 
50 GList *
51 pe__unames_with_tag(pe_working_set_t *data_set, const char *tag_name)
52 {
53  gpointer value;
54  GList *retval = NULL;
55 
56  if (data_set->tags == NULL) {
57  return retval;
58  }
59 
60  value = g_hash_table_lookup(data_set->tags, tag_name);
61 
62  if (value == NULL) {
63  return retval;
64  }
65 
66  /* Iterate over the list of node IDs. */
67  for (GList *refs = ((pe_tag_t *) value)->refs; refs; refs = refs->next) {
68  /* Find the node that has this ID. */
69  const char *id = (const char *) refs->data;
70  pe_node_t *node = pe_find_node_id(data_set->nodes, id);
71 
72  if (!node) {
73  continue;
74  }
75 
76  /* Get the uname for the node and add it to the return list. */
77  retval = g_list_append(retval, strdup(node->details->uname));
78  }
79 
80  return retval;
81 }
82 
83 bool
84 pe__rsc_has_tag(pe_working_set_t *data_set, const char *rsc_name, const char *tag_name)
85 {
86  GList *rscs = pe__rscs_with_tag(data_set, tag_name);
87  bool retval = false;
88 
89  if (rscs == NULL) {
90  return retval;
91  }
92 
93  retval = g_list_find_custom(rscs, rsc_name, (GCompareFunc) strcmp) != NULL;
94  g_list_free_full(rscs, free);
95  return retval;
96 }
97 
98 bool
99 pe__uname_has_tag(pe_working_set_t *data_set, const char *node_name, const char *tag_name)
100 {
101  GList *unames = pe__unames_with_tag(data_set, tag_name);
102  bool retval = false;
103 
104  if (unames == NULL) {
105  return retval;
106  }
107 
108  retval = g_list_find_custom(unames, node_name, (GCompareFunc) strcmp) != NULL;
109  g_list_free_full(unames, free);
110  return retval;
111 }
GHashTable * tags
Definition: pe_types.h:180
pe_resource_t * pe_find_resource_with_flags(GList *rsc_list, const char *id, enum pe_find flags)
Definition: status.c:388
bool pe__uname_has_tag(pe_working_set_t *data_set, const char *node, const char *tag)
Definition: tags.c:99
GList * pe__rscs_with_tag(pe_working_set_t *data_set, const char *tag_name)
Definition: tags.c:20
GList * resources
Definition: pe_types.h:158
GList * nodes
Definition: pe_types.h:157
Utility functions.
bool pe__rsc_has_tag(pe_working_set_t *data_set, const char *rsc, const char *tag)
Definition: tags.c:84
match base name of any clone instance
Definition: pe_types.h:89
pe_node_t * pe_find_node_id(GList *node_list, const char *id)
Definition: status.c:418
match resource ID or LRM history ID
Definition: pe_types.h:84
const char * rsc_printable_id(pe_resource_t *rsc)
Definition: utils.c:1911
Data types for cluster status.
GList * pe__unames_with_tag(pe_working_set_t *data_set, const char *tag_name)
Definition: tags.c:51