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