pacemaker 2.1.5-a3f44794f94
Scalable High-Availability cluster resource manager
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>
18
19GList *
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
50GList *
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;
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
83bool
84pe__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
98bool
99pe__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}
Utility functions.
pe_working_set_t * data_set
Data types for cluster status.
@ pe_find_any
match base name of any clone instance
Definition: pe_types.h:90
@ pe_find_renamed
match resource ID or LRM history ID
Definition: pe_types.h:85
pe_resource_t * pe_find_resource_with_flags(GList *rsc_list, const char *id, enum pe_find flags)
Definition: status.c:397
pe_node_t * pe_find_node_id(GList *node_list, const char *id)
Definition: status.c:427
const char * rsc_printable_id(pe_resource_t *rsc)
Definition: utils.c:568
GHashTable * tags
Definition: pe_types.h:187
GList * resources
Definition: pe_types.h:165
GList * nodes
Definition: pe_types.h:164
bool pe__rsc_has_tag(pe_working_set_t *data_set, const char *rsc_name, const char *tag_name)
Definition: tags.c:84
GList * pe__unames_with_tag(pe_working_set_t *data_set, const char *tag_name)
Definition: tags.c:51
GList * pe__rscs_with_tag(pe_working_set_t *data_set, const char *tag_name)
Definition: tags.c:20
bool pe__uname_has_tag(pe_working_set_t *data_set, const char *node_name, const char *tag_name)
Definition: tags.c:99