pacemaker  2.0.4-2deceaa
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 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__unames_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  /* Iterate over the list of node IDs. */
34  for (GListPtr refs = ((pe_tag_t *) value)->refs; refs; refs = refs->next) {
35  /* Find the node that has this ID. */
36  const char *id = (const char *) refs->data;
37  pe_node_t *node = pe_find_node_id(data_set->nodes, id);
38 
39  if (!node) {
40  continue;
41  }
42 
43  /* Get the uname for the node and add it to the return list. */
44  retval = g_list_append(retval, strdup(node->details->uname));
45  }
46 
47  return retval;
48 }
49 
50 bool
51 pe__uname_has_tag(pe_working_set_t *data_set, const char *node_name, const char *tag_name)
52 {
53  GListPtr unames = pe__unames_with_tag(data_set, tag_name);
54  bool retval = false;
55 
56  if (unames == NULL) {
57  return retval;
58  }
59 
60  retval = g_list_find_custom(unames, node_name, (GCompareFunc) strcmp) != NULL;
61  g_list_free_full(unames, free);
62  return retval;
63 }
GHashTable * tags
Definition: pe_types.h:169
GListPtr nodes
Definition: pe_types.h:146
GListPtr pe__unames_with_tag(pe_working_set_t *data_set, const char *tag_name)
Definition: tags.c:18
pe_node_t * pe_find_node_id(GListPtr node_list, const char *id)
Definition: status.c:411
bool pe__uname_has_tag(pe_working_set_t *data_set, const char *node, const char *tag)
Definition: tags.c:51
Utility functions.
Data types for cluster status.
GList * GListPtr
Definition: crm.h:214