pacemaker  3.0.0-d8340737c4
Scalable High-Availability cluster resource manager
nodes.c
Go to the documentation of this file.
1 /*
2  * Copyright 2022-2024 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 
21 void
23 {
24  if (data != NULL) {
25  pcmk_node_t *node = data;
26 
27  if (node->assign != NULL) {
28  // This is the only member allocated separately for a node copy
29  free(node->assign);
30  }
31  free(node);
32  }
33 }
34 
43 bool
45 {
46  return (node != NULL) && node->details->online;
47 }
48 
61 bool
63 {
64  return (node != NULL) && node->details->pending;
65 }
66 
80 bool
82 {
83  return (node != NULL) && !(node->details->unclean);
84 }
85 
94 bool
96 {
97  return (node != NULL) && node->details->shutdown;
98 }
99 
108 bool
110 {
111  return (node != NULL) && node->details->maintenance;
112 }
113 
126 bool
128  bool (*fn)(pcmk_resource_t *, void *),
129  void *user_data)
130 {
131  bool result = false;
132 
133  if ((node != NULL) && (fn != NULL)) {
134  for (GList *item = node->details->running_rsc; item != NULL;
135  item = item->next) {
136 
137  result = fn((pcmk_resource_t *) item->data, user_data);
138  if (!result) {
139  break;
140  }
141  }
142  }
143  return result;
144 }
145 
146 void
147 pcmk__xe_add_node(xmlNode *xml, const char *node, int nodeid)
148 {
149  pcmk__assert(xml != NULL);
150 
151  if (node != NULL) {
152  crm_xml_add(xml, PCMK__XA_ATTR_HOST, node);
153  }
154 
155  if (nodeid > 0) {
157  }
158 }
159 
169 pcmk_node_t *
170 pcmk__find_node_in_list(const GList *nodes, const char *node_name)
171 {
172  if (node_name != NULL) {
173  for (const GList *iter = nodes; iter != NULL; iter = iter->next) {
174  pcmk_node_t *node = (pcmk_node_t *) iter->data;
175 
176  if (pcmk__str_eq(node->priv->name, node_name, pcmk__str_casei)) {
177  return node;
178  }
179  }
180  }
181  return NULL;
182 }
183 
184 #define XP_SHUTDOWN "//" PCMK__XE_NODE_STATE "[@" PCMK_XA_UNAME "='%s']/" \
185  PCMK__XE_TRANSIENT_ATTRIBUTES "/" PCMK_XE_INSTANCE_ATTRIBUTES "/" \
186  PCMK_XE_NVPAIR "[@" PCMK_XA_NAME "='" PCMK__NODE_ATTR_SHUTDOWN "']"
187 
199 const char *
200 pcmk_cib_node_shutdown(xmlNode *cib, const char *node)
201 {
202  if ((cib != NULL) && (node != NULL)) {
203  char *xpath = crm_strdup_printf(XP_SHUTDOWN, node);
204  xmlNode *match = get_xpath_object(xpath, cib, LOG_TRACE);
205 
206  free(xpath);
207  if (match != NULL) {
208  return crm_element_value(match, PCMK_XA_VALUE);
209  }
210  }
211  return NULL;
212 }
#define LOG_TRACE
Definition: logging.h:38
char data[0]
Definition: cpg.c:58
pcmk_node_t * pcmk__find_node_in_list(const GList *nodes, const char *node_name)
Definition: nodes.c:170
bool pcmk_foreach_active_resource(pcmk_node_t *node, bool(*fn)(pcmk_resource_t *, void *), void *user_data)
Definition: nodes.c:127
gboolean shutdown
Definition: nodes.h:62
gboolean unclean
Definition: nodes.h:58
bool pcmk_node_is_clean(const pcmk_node_t *node)
Definition: nodes.c:81
#define PCMK__XA_ATTR_HOST_ID
gboolean pending
Definition: nodes.h:54
xmlNode * get_xpath_object(const char *xpath, xmlNode *xml_obj, int error_level)
Definition: xpath.c:189
bool pcmk_node_is_shutting_down(const pcmk_node_t *node)
Definition: nodes.c:95
void pcmk__xe_add_node(xmlNode *xml, const char *node, int nodeid)
Definition: nodes.c:147
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
Definition: xml_element.c:1015
const char * pcmk_cib_node_shutdown(xmlNode *cib, const char *node)
Get value of a node&#39;s shutdown attribute from CIB, if present.
Definition: nodes.c:200
pcmk__node_private_t * priv
Definition: nodes.h:85
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
Definition: xml_element.c:1168
gboolean maintenance
Definition: nodes.h:66
bool pcmk_node_is_in_maintenance(const pcmk_node_t *node)
Definition: nodes.c:109
bool pcmk_node_is_pending(const pcmk_node_t *node)
Definition: nodes.c:62
#define PCMK_XA_VALUE
Definition: xml_names.h:442
bool pcmk_node_is_online(const pcmk_node_t *node)
Definition: nodes.c:44
GList * running_rsc
Definition: nodes.h:70
Functionality for manipulating name/value pairs.
#define XP_SHUTDOWN
Definition: nodes.c:184
#define pcmk__assert(expr)
#define PCMK__XA_ATTR_HOST
pcmk__action_result_t result
Definition: pcmk_fence.c:37
void pcmk__free_node_copy(void *data)
Definition: nodes.c:22
gboolean online
Definition: nodes.h:50
struct pcmk__node_details * details
Definition: nodes.h:82
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
const char * crm_xml_add_int(xmlNode *node, const char *name, int value)
Create an XML attribute with specified name and integer value.
Definition: xml_element.c:1070
struct pcmk__node_assignment * assign
Definition: nodes.h:79