pacemaker 3.0.1-16e74fc4da
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
nodes.c
Go to the documentation of this file.
1/*
2 * Copyright 2022-2025 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 <libxml/tree.h> // xmlNode
13#include <crm/common/nvpair.h>
14
21void
22pcmk__free_node(gpointer user_data)
23{
24 pcmk_node_t *node = user_data;
25
26 if (node == NULL) {
27 return;
28 }
29 if (node->details == NULL) {
30 free(node);
31 return;
32 }
33
34 /* This may be called after freeing resources, which means that we can't
35 * use node->private->name for Pacemaker Remote nodes.
36 */
37 crm_trace("Freeing node %s", (pcmk__is_pacemaker_remote_node(node)?
38 "(guest or remote)" : pcmk__node_name(node)));
39
40 if (node->priv->attrs != NULL) {
41 g_hash_table_destroy(node->priv->attrs);
42 }
43 if (node->priv->utilization != NULL) {
44 g_hash_table_destroy(node->priv->utilization);
45 }
46 if (node->priv->digest_cache != NULL) {
47 g_hash_table_destroy(node->priv->digest_cache);
48 }
49 g_list_free(node->details->running_rsc);
50 g_list_free(node->priv->assigned_resources);
51 free(node->priv);
52 free(node->details);
53 free(node->assign);
54 free(node);
55}
56
63void
65{
66 if (data != NULL) {
67 pcmk_node_t *node = data;
68
69 if (node->assign != NULL) {
70 // This is the only member allocated separately for a node copy
71 free(node->assign);
72 }
73 free(node);
74 }
75}
76
85bool
87{
88 return (node != NULL) && node->details->online;
89}
90
103bool
105{
106 return (node != NULL) && node->details->pending;
107}
108
122bool
124{
125 return (node != NULL) && !(node->details->unclean);
126}
127
136bool
138{
139 return (node != NULL) && node->details->shutdown;
140}
141
150bool
152{
153 return (node != NULL) && node->details->maintenance;
154}
155
168bool
170 bool (*fn)(pcmk_resource_t *, void *),
171 void *user_data)
172{
173 bool result = false;
174
175 if ((node != NULL) && (fn != NULL)) {
176 for (GList *item = node->details->running_rsc; item != NULL;
177 item = item->next) {
178
179 result = fn((pcmk_resource_t *) item->data, user_data);
180 if (!result) {
181 break;
182 }
183 }
184 }
185 return result;
186}
187
198pcmk__find_node_in_list(const GList *nodes, const char *node_name)
199{
200 if (node_name != NULL) {
201 for (const GList *iter = nodes; iter != NULL; iter = iter->next) {
202 pcmk_node_t *node = (pcmk_node_t *) iter->data;
203
204 if (pcmk__str_eq(node->priv->name, node_name, pcmk__str_casei)) {
205 return node;
206 }
207 }
208 }
209 return NULL;
210}
211
212#define XP_SHUTDOWN "//" PCMK__XE_NODE_STATE "[@" PCMK_XA_UNAME "='%s']/" \
213 PCMK__XE_TRANSIENT_ATTRIBUTES "/" PCMK_XE_INSTANCE_ATTRIBUTES "/" \
214 PCMK_XE_NVPAIR "[@" PCMK_XA_NAME "='" PCMK__NODE_ATTR_SHUTDOWN "']"
215
227const char *
228pcmk_cib_node_shutdown(xmlNode *cib, const char *node)
229{
230 if ((cib != NULL) && (node != NULL)) {
231 char *xpath = crm_strdup_printf(XP_SHUTDOWN, node);
232 xmlNode *match = pcmk__xpath_find_one(cib->doc, xpath, LOG_TRACE);
233
234 free(xpath);
235 if (match != NULL) {
236 return crm_element_value(match, PCMK_XA_VALUE);
237 }
238 }
239 return NULL;
240}
char data[0]
Definition cpg.c:10
#define crm_trace(fmt, args...)
Definition logging.h:370
#define LOG_TRACE
Definition logging.h:38
pcmk_node_t * pcmk__find_node_in_list(const GList *nodes, const char *node_name)
Definition nodes.c:198
void pcmk__free_node(gpointer user_data)
Definition nodes.c:22
bool pcmk_node_is_online(const pcmk_node_t *node)
Definition nodes.c:86
bool pcmk_node_is_shutting_down(const pcmk_node_t *node)
Definition nodes.c:137
const char * pcmk_cib_node_shutdown(xmlNode *cib, const char *node)
Get value of a node's shutdown attribute from CIB, if present.
Definition nodes.c:228
bool pcmk_node_is_clean(const pcmk_node_t *node)
Definition nodes.c:123
bool pcmk_node_is_pending(const pcmk_node_t *node)
Definition nodes.c:104
#define XP_SHUTDOWN
Definition nodes.c:212
bool pcmk_foreach_active_resource(pcmk_node_t *node, bool(*fn)(pcmk_resource_t *, void *), void *user_data)
Definition nodes.c:169
void pcmk__free_node_copy(void *data)
Definition nodes.c:64
bool pcmk_node_is_in_maintenance(const pcmk_node_t *node)
Definition nodes.c:151
Functionality for manipulating name/value pairs.
pcmk__action_result_t result
Definition pcmk_fence.c:37
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
@ pcmk__str_casei
gboolean shutdown
Definition nodes.h:62
gboolean online
Definition nodes.h:50
gboolean pending
Definition nodes.h:54
GList * running_rsc
Definition nodes.h:70
gboolean maintenance
Definition nodes.h:66
gboolean unclean
Definition nodes.h:58
GHashTable * digest_cache
GHashTable * utilization
pcmk__node_private_t * priv
Definition nodes.h:85
struct pcmk__node_details * details
Definition nodes.h:82
struct pcmk__node_assignment * assign
Definition nodes.h:79
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
#define PCMK_XA_VALUE
Definition xml_names.h:442
xmlNode * pcmk__xpath_find_one(xmlDoc *doc, const char *path, uint8_t level)
Definition xpath.c:206