pacemaker 2.1.8-2.1.8
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
tags.c
Go to the documentation of this file.
1/*
2 * Copyright 2020-2023 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 (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;
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
51GList *
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 /* Iterate over the list of node IDs. */
68 for (GList *refs = ((pcmk_tag_t *) value)->refs; refs; refs = refs->next) {
69 /* Find the node that has this ID. */
70 const char *id = (const char *) refs->data;
72
73 if (!node) {
74 continue;
75 }
76
77 /* Get the uname for the node and add it to the return list. */
78 retval = g_list_append(retval, strdup(node->details->uname));
79 }
80
81 return retval;
82}
83
84bool
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
100bool
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}
uint64_t flags
Definition remote.c:3
Utility functions.
pcmk_scheduler_t * scheduler
@ pcmk_rsc_match_basename
Match clone instances (even unique) by base name as well as exact ID.
Definition resources.h:200
@ pcmk_rsc_match_history
Also match clone instance ID from resource history.
Definition resources.h:185
Scheduler API.
pcmk_node_t * pe_find_node_id(const GList *node_list, const char *id)
Find a node by ID in a list of nodes.
Definition status.c:487
const char * rsc_printable_id(const pcmk_resource_t *rsc)
Definition utils.c:553
pcmk_resource_t * pe_find_resource_with_flags(GList *rsc_list, const char *id, enum pe_find flags)
Definition status.c:436
struct pe_node_shared_s * details
Definition nodes.h:167
const char * uname
Definition nodes.h:73
GHashTable * tags
Definition scheduler.h:253
GList * resources
Definition scheduler.h:231
bool pe__rsc_has_tag(pcmk_scheduler_t *scheduler, const char *rsc_name, const char *tag_name)
Definition tags.c:85
GList * pe__rscs_with_tag(pcmk_scheduler_t *scheduler, const char *tag_name)
Definition tags.c:20
bool pe__uname_has_tag(pcmk_scheduler_t *scheduler, const char *node_name, const char *tag_name)
Definition tags.c:101
GList * pe__unames_with_tag(pcmk_scheduler_t *scheduler, const char *tag_name)
Definition tags.c:52