This source file includes following definitions.
- pe__rscs_with_tag
- pe__unames_with_tag
- pe__rsc_has_tag
- pe__uname_has_tag
1
2
3
4
5
6
7
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 pe__rscs_with_tag(pcmk_scheduler_t *scheduler, const char *tag_name)
21 {
22 gpointer value;
23 GList *retval = NULL;
24
25 if (scheduler->tags == NULL) {
26 return retval;
27 }
28
29 value = g_hash_table_lookup(scheduler->tags, tag_name);
30
31 if (value == NULL) {
32 return retval;
33 }
34
35 for (GList *refs = ((pcmk_tag_t *) value)->refs; refs; refs = refs->next) {
36 const char *id = (const char *) refs->data;
37 const uint32_t flags = pcmk_rsc_match_history|pcmk_rsc_match_basename;
38 pcmk_resource_t *rsc = pe_find_resource_with_flags(scheduler->resources,
39 id, flags);
40
41 if (!rsc) {
42 continue;
43 }
44
45 retval = g_list_append(retval, strdup(rsc_printable_id(rsc)));
46 }
47
48 return retval;
49 }
50
51 GList *
52 pe__unames_with_tag(pcmk_scheduler_t *scheduler, const char *tag_name)
53 {
54 gpointer value;
55 GList *retval = NULL;
56
57 if (scheduler->tags == NULL) {
58 return retval;
59 }
60
61 value = g_hash_table_lookup(scheduler->tags, tag_name);
62
63 if (value == NULL) {
64 return retval;
65 }
66
67
68 for (GList *refs = ((pcmk_tag_t *) value)->refs; refs; refs = refs->next) {
69
70 const char *id = (const char *) refs->data;
71 pcmk_node_t *node = pe_find_node_id(scheduler->nodes, id);
72
73 if (!node) {
74 continue;
75 }
76
77
78 retval = g_list_append(retval, strdup(node->details->uname));
79 }
80
81 return retval;
82 }
83
84 bool
85 pe__rsc_has_tag(pcmk_scheduler_t *scheduler, const char *rsc_name,
86 const char *tag_name)
87 {
88 GList *rscs = pe__rscs_with_tag(scheduler, tag_name);
89 bool retval = false;
90
91 if (rscs == NULL) {
92 return retval;
93 }
94
95 retval = g_list_find_custom(rscs, rsc_name, (GCompareFunc) strcmp) != NULL;
96 g_list_free_full(rscs, free);
97 return retval;
98 }
99
100 bool
101 pe__uname_has_tag(pcmk_scheduler_t *scheduler, const char *node_name,
102 const char *tag_name)
103 {
104 GList *unames = pe__unames_with_tag(scheduler, tag_name);
105 bool retval = false;
106
107 if (unames == NULL) {
108 return retval;
109 }
110
111 retval = g_list_find_custom(unames, node_name, (GCompareFunc) strcmp) != NULL;
112 g_list_free_full(unames, free);
113 return retval;
114 }