pacemaker  2.1.9-49aab99839
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 
23 bool
25 {
26  return (node != NULL) && node->details->online;
27 }
28 
41 bool
43 {
44  return (node != NULL) && node->details->pending;
45 }
46 
60 bool
62 {
63  return (node != NULL) && !(node->details->unclean);
64 }
65 
74 bool
76 {
77  return (node != NULL) && node->details->shutdown;
78 }
79 
88 bool
90 {
91  return (node != NULL) && node->details->maintenance;
92 }
93 
106 bool
108  bool (*fn)(pcmk_resource_t *, void *),
109  void *user_data)
110 {
111  bool result = false;
112 
113  if ((node != NULL) && (fn != NULL)) {
114  for (GList *item = node->details->running_rsc; item != NULL;
115  item = item->next) {
116 
117  result = fn((pcmk_resource_t *) item->data, user_data);
118  if (!result) {
119  break;
120  }
121  }
122  }
123  return result;
124 }
125 
126 void
127 pcmk__xe_add_node(xmlNode *xml, const char *node, int nodeid)
128 {
129  pcmk__assert(xml != NULL);
130 
131  if (node != NULL) {
132  crm_xml_add(xml, PCMK__XA_ATTR_HOST, node);
133  }
134 
135  if (nodeid > 0) {
137  }
138 }
139 
149 pcmk_node_t *
150 pcmk__find_node_in_list(const GList *nodes, const char *node_name)
151 {
152  if (node_name != NULL) {
153  for (const GList *iter = nodes; iter != NULL; iter = iter->next) {
154  pcmk_node_t *node = (pcmk_node_t *) iter->data;
155 
156  if (pcmk__str_eq(node->details->uname, node_name,
157  pcmk__str_casei)) {
158  return node;
159  }
160  }
161  }
162  return NULL;
163 }
164 
165 #define XP_SHUTDOWN "//" PCMK__XE_NODE_STATE "[@" PCMK_XA_UNAME "='%s']/" \
166  PCMK__XE_TRANSIENT_ATTRIBUTES "/" PCMK_XE_INSTANCE_ATTRIBUTES "/" \
167  PCMK_XE_NVPAIR "[@" PCMK_XA_NAME "='" PCMK__NODE_ATTR_SHUTDOWN "']"
168 
180 const char *
181 pcmk_cib_node_shutdown(xmlNode *cib, const char *node)
182 {
183  if ((cib != NULL) && (node != NULL)) {
184  char *xpath = crm_strdup_printf(XP_SHUTDOWN, node);
185  xmlNode *match = get_xpath_object(xpath, cib, LOG_TRACE);
186 
187  free(xpath);
188  if (match != NULL) {
189  return crm_element_value(match, PCMK_XA_VALUE);
190  }
191  }
192  return NULL;
193 }
#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:150
const char * crm_xml_add_int(xmlNode *node, const char *name, int value)
Create an XML attribute with specified name and integer value.
Definition: nvpair.c:360
bool pcmk_foreach_active_resource(pcmk_node_t *node, bool(*fn)(pcmk_resource_t *, void *), void *user_data)
Definition: nodes.c:107
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
Definition: nvpair.c:313
gboolean pending
Definition: nodes.h:88
bool pcmk_node_is_clean(const pcmk_node_t *node)
Definition: nodes.c:61
#define PCMK__XA_ATTR_HOST_ID
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:75
void pcmk__xe_add_node(xmlNode *xml, const char *node, int nodeid)
Definition: nodes.c:127
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:181
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
Definition: nvpair.c:458
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
bool pcmk_node_is_in_maintenance(const pcmk_node_t *node)
Definition: nodes.c:89
struct pe_node_shared_s * details
Definition: nodes.h:168
const char * uname
Definition: nodes.h:74
bool pcmk_node_is_pending(const pcmk_node_t *node)
Definition: nodes.c:42
#define PCMK_XA_VALUE
Definition: xml_names.h:442
bool pcmk_node_is_online(const pcmk_node_t *node)
Definition: nodes.c:24
Functionality for manipulating name/value pairs.
#define XP_SHUTDOWN
Definition: nodes.c:165
#define pcmk__assert(expr)
GList * running_rsc
Definition: nodes.h:140
#define PCMK__XA_ATTR_HOST
pcmk__action_result_t result
Definition: pcmk_fence.c:35
gboolean shutdown
Definition: nodes.h:98
gboolean maintenance
Definition: nodes.h:105
gboolean unclean
Definition: nodes.h:92
gboolean online
Definition: nodes.h:81