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