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 23 /*! 24 * \file 25 * \brief Scheduler API for nodes 26 * \ingroup core 27 */ 28 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 37 //!@{ 38 //! \deprecated Do not use (public access will be removed in a future release) 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) 45 node_member = pcmk_node_variant_cluster, 46 node_remote = pcmk_node_variant_remote, 47 #endif 48 }; 49 //!@} 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 53 //!@{ 54 //! \deprecated Do not use (public access will be removed in a future release) 55 enum pe_discover_e { 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) 61 pe_discover_always = pcmk_probe_always, 62 pe_discover_never = pcmk_probe_never, 63 pe_discover_exclusive = pcmk_probe_exclusive, 64 #endif 65 }; 66 //!@} 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 70 //!@{ 71 //! \deprecated Do not use (public access will be removed in a future release) 72 struct pe_node_shared_s { 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 80 //! \deprecated Call pcmk_node_is_online() instead 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 87 //! \deprecated Call pcmk_node_is_pending() instead 88 gboolean pending; // Whether controller membership is pending 89 90 // NOTE: sbd (as of at least 1.5.2) uses this 91 //! \deprecated Call !pcmk_node_is_clean() instead 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 97 //! \deprecated Call pcmk_node_is_shutting_down() instead 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 104 //! \deprecated Call pcmk_node_is_in_maintenance() instead 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 */ 113 gboolean remote_requires_reset; 114 115 /* 116 * Whether this is a Pacemaker Remote node that was fenced since it was last 117 * connected by the cluster 118 */ 119 gboolean remote_was_fenced; 120 121 /* 122 * Whether this is a Pacemaker Remote node previously marked in its 123 * node state as being in maintenance mode 124 */ 125 gboolean remote_maintenance; 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 */ 133 int num_resources; 134 135 // Remote connection resource for node, if it is a Pacemaker Remote node 136 pcmk_resource_t *remote_rsc; 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 }; 156 //!@} 157 158 // Implementation of pcmk_node_t 159 // @COMPAT Make contents internal when we can break API backward compatibility 160 //!@{ 161 //! \deprecated Do not use (public access will be removed in a future release) 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 }; 173 //!@} 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 181 bool pcmk_foreach_active_resource(pcmk_node_t *node, 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 187 /*! 188 * \internal 189 * \brief Return a string suitable for logging as a node name 190 * 191 * \param[in] node Node to return a node name string for 192 * 193 * \return Node name if available, otherwise node ID if available, 194 * otherwise "unspecified node" if node is NULL or "unidentified node" 195 * if node has neither a name nor ID. 196 */ 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 214 /*! 215 * \internal 216 * \brief Check whether two node objects refer to the same node 217 * 218 * \param[in] node1 First node object to compare 219 * \param[in] node2 Second node object to compare 220 * 221 * \return true if \p node1 and \p node2 refer to the same node 222 */ 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