pacemaker  2.1.9-49aab99839
Scalable High-Availability cluster resource manager
nodes.h
Go to the documentation of this file.
1 /*
2  * Copyright 2004-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 #ifndef PCMK__CRM_COMMON_NODES__H
11 #define PCMK__CRM_COMMON_NODES__H
12 
13 #include <stdbool.h> // bool
14 #include <glib.h> // gboolean, GList, GHashTable
15 #include <libxml/tree.h> // xmlNode
16 
17 #include <crm/common/scheduler_types.h> // pcmk_resource_t, pcmk_scheduler_t
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
29 // Special node attributes
30 
31 #define PCMK_NODE_ATTR_MAINTENANCE "maintenance"
32 #define PCMK_NODE_ATTR_STANDBY "standby"
33 #define PCMK_NODE_ATTR_TERMINATE "terminate"
34 
35 
36 // @COMPAT Make this internal when we can break API backward compatibility
39 enum node_type { // Possible node types
40  pcmk_node_variant_cluster = 1, // Cluster layer node
41  pcmk_node_variant_remote = 2, // Pacemaker Remote node
42 
43  node_ping = 0, // deprecated
44 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
47 #endif
48 };
50 
51 // When to probe a resource on a node (as specified in location constraints)
52 // @COMPAT Make this internal when we can break API backward compatibility
56  pcmk_probe_always = 0, // Always probe resource on node
57  pcmk_probe_never = 1, // Never probe resource on node
58  pcmk_probe_exclusive = 2, // Probe only on designated nodes
59 
60 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
64 #endif
65 };
67 
68 // Basic node information (all node objects for the same node share this)
69 // @COMPAT Make this internal when we can break API backward compatibility
73  const char *id; // Node ID at the cluster layer
74  const char *uname; // Node name in cluster
75  enum node_type type; // Node variant
76 
77  // @TODO Convert these into a flag group
78 
79  // NOTE: sbd (as of at least 1.5.2) uses this
81  gboolean online; // Whether online
82 
83  gboolean standby; // Whether in standby mode
84  gboolean standby_onfail; // Whether in standby mode due to on-fail
85 
86  // NOTE: sbd (as of at least 1.5.2) uses this
88  gboolean pending; // Whether controller membership is pending
89 
90  // NOTE: sbd (as of at least 1.5.2) uses this
92  gboolean unclean; // Whether node requires fencing
93 
94  gboolean unseen; // Whether node has never joined cluster
95 
96  // NOTE: sbd (as of at least 1.5.2) uses this
98  gboolean shutdown; // Whether shutting down
99 
100  gboolean expected_up; // Whether expected join state is member
101  gboolean is_dc; // Whether node is cluster's DC
102 
103  // NOTE: sbd (as of at least 1.5.2) uses this
105  gboolean maintenance; // Whether in maintenance mode
106 
107  gboolean rsc_discovery_enabled; // Whether probes are allowed on node
108 
109  /*
110  * Whether this is a guest node whose guest resource must be recovered or a
111  * remote node that must be fenced
112  */
114 
115  /*
116  * Whether this is a Pacemaker Remote node that was fenced since it was last
117  * connected by the cluster
118  */
120 
121  /*
122  * Whether this is a Pacemaker Remote node previously marked in its
123  * node state as being in maintenance mode
124  */
126 
127  gboolean unpacked; // Whether node history has been unpacked
128 
129  /*
130  * Number of resources active on this node (valid after CIB status section
131  * has been unpacked, as long as pcmk_sched_no_counts was not set)
132  */
134 
135  // Remote connection resource for node, if it is a Pacemaker Remote node
137 
138  // NOTE: sbd (as of at least 1.5.2) uses this
139  // \deprecated Call pcmk_foreach_active_resource() instead
140  GList *running_rsc; // List of resources active on node
141 
142  GList *allocated_rsc; // List of resources assigned to node
143  GHashTable *attrs; // Node attributes
144  GHashTable *utilization; // Node utilization attributes
145  GHashTable *digest_cache; // Cache of calculated resource digests
146 
147  /*
148  * Sum of priorities of all resources active on node and on any guest nodes
149  * connected to this node, with +1 for promoted instances (used to compare
150  * nodes for PCMK_OPT_PRIORITY_FENCING_DELAY)
151  */
152  int priority;
153 
154  pcmk_scheduler_t *data_set; // Cluster that node is part of
155 };
157 
158 // Implementation of pcmk_node_t
159 // @COMPAT Make contents internal when we can break API backward compatibility
162 struct pe_node_s {
163  int weight; // Node score for a given resource
164  gboolean fixed; // \deprecated Do not use
165  int count; // Counter reused by assignment and promotion code
166 
167  // NOTE: sbd (as of at least 1.5.2) uses this
168  struct pe_node_shared_s *details; // Basic node information
169 
170  // @COMPAT This should be enum pe_discover_e
171  int rsc_discover_mode; // Probe mode (enum pe_discover_e)
172 };
174 
175 bool pcmk_node_is_online(const pcmk_node_t *node);
176 bool pcmk_node_is_pending(const pcmk_node_t *node);
177 bool pcmk_node_is_clean(const pcmk_node_t *node);
178 bool pcmk_node_is_shutting_down(const pcmk_node_t *node);
179 bool pcmk_node_is_in_maintenance(const pcmk_node_t *node);
180 
182  bool (*fn)(pcmk_resource_t *, void *),
183  void *user_data);
184 
185 const char *pcmk_cib_node_shutdown(xmlNode *cib, const char *node);
186 
197 static inline const char *
198 pcmk__node_name(const pcmk_node_t *node)
199 {
200  if (node == NULL) {
201  return "unspecified node";
202 
203  } else if (node->details->uname != NULL) {
204  return node->details->uname;
205 
206  } else if (node->details->id != NULL) {
207  return node->details->id;
208 
209  } else {
210  return "unidentified node";
211  }
212 }
213 
223 static inline bool
224 pcmk__same_node(const pcmk_node_t *node1, const pcmk_node_t *node2)
225 {
226  return (node1 != NULL) && (node2 != NULL)
227  && (node1->details == node2->details);
228 }
229 
230 #ifdef __cplusplus
231 }
232 #endif
233 
234 #endif // PCMK__CRM_COMMON_NODES__H
bool pcmk_node_is_online(const pcmk_node_t *node)
Definition: nodes.c:24
GHashTable * attrs
Definition: nodes.h:143
gboolean unseen
Definition: nodes.h:94
node_type
Definition: nodes.h:39
gboolean fixed
Definition: nodes.h:164
Type aliases needed to define scheduler objects.
int count
Definition: nodes.h:165
bool pcmk_node_is_shutting_down(const pcmk_node_t *node)
Definition: nodes.c:75
gboolean pending
Definition: nodes.h:88
pcmk_node_t node2
pcmk_scheduler_t * data_set
Definition: nodes.h:154
gboolean remote_was_fenced
Definition: nodes.h:119
gboolean remote_requires_reset
Definition: nodes.h:113
gboolean remote_maintenance
Definition: nodes.h:125
gboolean is_dc
Definition: nodes.h:101
int weight
Definition: nodes.h:163
bool pcmk_node_is_in_maintenance(const pcmk_node_t *node)
Definition: nodes.c:89
gboolean unpacked
Definition: nodes.h:127
int num_resources
Definition: nodes.h:133
bool pcmk_node_is_clean(const pcmk_node_t *node)
Definition: nodes.c:61
struct pe_node_shared_s * details
Definition: nodes.h:168
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 * uname
Definition: nodes.h:74
gboolean standby
Definition: nodes.h:83
gboolean expected_up
Definition: nodes.h:100
int rsc_discover_mode
Definition: nodes.h:171
const char * id
Definition: nodes.h:73
GList * running_rsc
Definition: nodes.h:140
gboolean rsc_discovery_enabled
Definition: nodes.h:107
bool pcmk_foreach_active_resource(pcmk_node_t *node, bool(*fn)(pcmk_resource_t *, void *), void *user_data)
Definition: nodes.c:107
pe_discover_e
Definition: nodes.h:55
GHashTable * utilization
Definition: nodes.h:144
gboolean shutdown
Definition: nodes.h:98
gboolean maintenance
Definition: nodes.h:105
GHashTable * digest_cache
Definition: nodes.h:145
GList * allocated_rsc
Definition: nodes.h:142
pcmk_node_t node1
gboolean standby_onfail
Definition: nodes.h:84
gboolean unclean
Definition: nodes.h:92
enum node_type type
Definition: nodes.h:75
bool pcmk_node_is_pending(const pcmk_node_t *node)
Definition: nodes.c:42
gboolean online
Definition: nodes.h:81
pcmk_resource_t * remote_rsc
Definition: nodes.h:136