pacemaker 2.1.8-2.1.8~rc1
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
status.c
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#include <crm_internal.h>
11
12#include <sys/param.h>
13
14#include <crm/crm.h>
15#include <crm/common/xml.h>
17
18#include <glib.h>
19
21#include <pe_status_private.h>
22
35{
36 pcmk_scheduler_t *scheduler = calloc(1, sizeof(pcmk_scheduler_t));
37
38 if (scheduler != NULL) {
40 }
41 return scheduler;
42}
43
49void
58
59#define XPATH_DEPRECATED_RULES \
60 "//" PCMK_XE_OP_DEFAULTS "//" PCMK_XE_EXPRESSION \
61 "|//" PCMK_XE_OP "//" PCMK_XE_EXPRESSION
62
69static void
70check_for_deprecated_rules(pcmk_scheduler_t *scheduler)
71{
72 // @COMPAT Drop this function when support for the syntax is dropped
73 xmlNode *deprecated = get_xpath_object(XPATH_DEPRECATED_RULES,
75
76 if (deprecated != NULL) {
78 "Support for rules with node attribute expressions in "
79 PCMK_XE_OP " or " PCMK_XE_OP_DEFAULTS " is deprecated "
80 "and will be dropped in a future release");
81 }
82}
83
84/*
85 * Unpack everything
86 * At the end you'll have:
87 * - A list of nodes
88 * - A list of resources (each with any dependencies on other resources)
89 * - A list of constraints between resources and nodes
90 * - A list of constraints between start/stop actions
91 * - A list of nodes that need to be stonith'd
92 * - A list of nodes that need to be shutdown
93 * - A list of the possible stop/start actions (without dependencies)
94 */
95gboolean
97{
98 const char *new_version = NULL;
99 xmlNode *section = NULL;
100
101 if ((scheduler == NULL) || (scheduler->input == NULL)) {
102 return FALSE;
103 }
104
106
107 if (pcmk__check_feature_set(new_version) != pcmk_rc_ok) {
108 pcmk__config_err("Can't process CIB with feature set '%s' greater than our own '%s'",
109 new_version, CRM_FEATURE_SET);
110 return FALSE;
111 }
112
113 crm_trace("Beginning unpack");
114
115 if (scheduler->failed != NULL) {
117 }
118 scheduler->failed = pcmk__xe_create(NULL, "failed-ops");
119
120 if (scheduler->now == NULL) {
121 scheduler->now = crm_time_new(NULL);
122 }
123
124 if (scheduler->dc_uuid == NULL) {
127 }
128
131 } else {
133 }
134
137 check_for_deprecated_rules(scheduler);
138
141
143 LOG_TRACE);
144 unpack_config(section, scheduler);
145
146 if (!pcmk_any_flags_set(scheduler->flags,
149 pcmk__sched_warn("Fencing and resource management disabled "
150 "due to lack of quorum");
151 }
152
154 unpack_nodes(section, scheduler);
155
157 LOG_TRACE);
160 }
161 unpack_resources(section, scheduler);
162
164 unpack_tags(section, scheduler);
165
168 LOG_TRACE);
169 unpack_status(section, scheduler);
170 }
171
173 for (GList *item = scheduler->resources; item != NULL;
174 item = item->next) {
175 ((pcmk_resource_t *) (item->data))->fns->count(item->data);
176 }
177 crm_trace("Cluster resource count: %d (%d disabled, %d blocked)",
180 }
181
183 return TRUE;
184}
185
197static void
198pe_free_resources(GList *resources)
199{
200 pcmk_resource_t *rsc = NULL;
201 GList *iterator = resources;
202
203 while (iterator != NULL) {
204 rsc = (pcmk_resource_t *) iterator->data;
205 iterator = iterator->next;
206 rsc->fns->free(rsc);
207 }
208 if (resources != NULL) {
209 g_list_free(resources);
210 }
211}
212
213static void
214pe_free_actions(GList *actions)
215{
216 GList *iterator = actions;
217
218 while (iterator != NULL) {
219 pe_free_action(iterator->data);
220 iterator = iterator->next;
221 }
222 if (actions != NULL) {
223 g_list_free(actions);
224 }
225}
226
227static void
228pe_free_nodes(GList *nodes)
229{
230 for (GList *iterator = nodes; iterator != NULL; iterator = iterator->next) {
231 pcmk_node_t *node = (pcmk_node_t *) iterator->data;
232
233 // Shouldn't be possible, but to be safe ...
234 if (node == NULL) {
235 continue;
236 }
237 if (node->details == NULL) {
238 free(node);
239 continue;
240 }
241
242 /* This is called after pe_free_resources(), which means that we can't
243 * use node->details->uname for Pacemaker Remote nodes.
244 */
245 crm_trace("Freeing node %s", (pcmk__is_pacemaker_remote_node(node)?
246 "(guest or remote)" : pcmk__node_name(node)));
247
248 if (node->details->attrs != NULL) {
249 g_hash_table_destroy(node->details->attrs);
250 }
251 if (node->details->utilization != NULL) {
252 g_hash_table_destroy(node->details->utilization);
253 }
254 if (node->details->digest_cache != NULL) {
255 g_hash_table_destroy(node->details->digest_cache);
256 }
257 g_list_free(node->details->running_rsc);
258 g_list_free(node->details->allocated_rsc);
259 free(node->details);
260 free(node);
261 }
262 if (nodes != NULL) {
263 g_list_free(nodes);
264 }
265}
266
267static void
268pe__free_ordering(GList *constraints)
269{
270 GList *iterator = constraints;
271
272 while (iterator != NULL) {
273 pcmk__action_relation_t *order = iterator->data;
274
275 iterator = iterator->next;
276
277 free(order->task1);
278 free(order->task2);
279 free(order);
280 }
281 if (constraints != NULL) {
282 g_list_free(constraints);
283 }
284}
285
286static void
287pe__free_location(GList *constraints)
288{
289 GList *iterator = constraints;
290
291 while (iterator != NULL) {
292 pcmk__location_t *cons = iterator->data;
293
294 iterator = iterator->next;
295
296 g_list_free_full(cons->nodes, free);
297 free(cons->id);
298 free(cons);
299 }
300 if (constraints != NULL) {
301 g_list_free(constraints);
302 }
303}
304
313void
315{
316 if (scheduler == NULL) {
317 return;
318 }
319
321 if (scheduler->config_hash != NULL) {
322 g_hash_table_destroy(scheduler->config_hash);
323 }
324
325 if (scheduler->singletons != NULL) {
326 g_hash_table_destroy(scheduler->singletons);
327 }
328
329 if (scheduler->tickets) {
330 g_hash_table_destroy(scheduler->tickets);
331 }
332
334 g_hash_table_destroy(scheduler->template_rsc_sets);
335 }
336
337 if (scheduler->tags) {
338 g_hash_table_destroy(scheduler->tags);
339 }
340
341 free(scheduler->dc_uuid);
342
343 crm_trace("deleting resources");
344 pe_free_resources(scheduler->resources);
345
346 crm_trace("deleting actions");
347 pe_free_actions(scheduler->actions);
348
349 crm_trace("deleting nodes");
350 pe_free_nodes(scheduler->nodes);
351
353 g_list_free(scheduler->stop_needed);
358
360
362 );
364 );
365}
366
372void
374{
375 if (scheduler == NULL) {
376 return;
377 }
378
379 crm_trace("Deleting %d ordering constraints",
380 g_list_length(scheduler->ordering_constraints));
381 pe__free_ordering(scheduler->ordering_constraints);
383
384 crm_trace("Deleting %d location constraints",
385 g_list_length(scheduler->placement_constraints));
386 pe__free_location(scheduler->placement_constraints);
388
389 crm_trace("Deleting %d colocation constraints",
390 g_list_length(scheduler->colocation_constraints));
391 g_list_free_full(scheduler->colocation_constraints, free);
393
394 crm_trace("Deleting %d ticket constraints",
395 g_list_length(scheduler->ticket_constraints));
396 g_list_free_full(scheduler->ticket_constraints, free);
398
400}
401
402void
424
426pe_find_resource(GList *rsc_list, const char *id)
427{
429}
430
432pe_find_resource_with_flags(GList *rsc_list, const char *id, enum pe_find flags)
433{
434 GList *rIter = NULL;
435
436 for (rIter = rsc_list; id && rIter; rIter = rIter->next) {
437 pcmk_resource_t *parent = rIter->data;
438
439 pcmk_resource_t *match =
440 parent->fns->find_rsc(parent, id, NULL, flags);
441 if (match != NULL) {
442 return match;
443 }
444 }
445 crm_trace("No match for %s", id);
446 return NULL;
447}
448
461pe_find_node_any(const GList *nodes, const char *id, const char *uname)
462{
463 pcmk_node_t *match = NULL;
464
465 if (id != NULL) {
466 match = pe_find_node_id(nodes, id);
467 }
468 if ((match == NULL) && (uname != NULL)) {
469 match = pcmk__find_node_in_list(nodes, uname);
470 }
471 return match;
472}
473
483pe_find_node_id(const GList *nodes, const char *id)
484{
485 for (const GList *iter = nodes; iter != NULL; iter = iter->next) {
486 pcmk_node_t *node = (pcmk_node_t *) iter->data;
487
488 /* @TODO Whether node IDs should be considered case-sensitive should
489 * probably depend on the node type, so functionizing the comparison
490 * would be worthwhile
491 */
492 if (pcmk__str_eq(node->details->id, id, pcmk__str_casei)) {
493 return node;
494 }
495 }
496 return NULL;
497}
498
499// Deprecated functions kept only for backward API compatibility
500// LCOV_EXCL_START
501
503
513pe_find_node(const GList *nodes, const char *node_name)
514{
515 return pcmk__find_node_in_list(nodes, node_name);
516}
517
518// LCOV_EXCL_STOP
519// End deprecated API
const char * parent
Definition cib.c:27
int pcmk__check_feature_set(const char *cib_version)
Definition cib.c:184
bool pcmk__xe_attr_is_true(const xmlNode *node, const char *name)
Definition nvpair.c:936
uint64_t flags
Definition remote.c:3
#define pcmk_is_set(g, f)
Convenience alias for pcmk_all_flags_set(), to check single flag.
Definition util.h:100
#define PCMK__CONCURRENT_FENCING_DEFAULT
Definition config.h:553
char uname[MAX_NAME]
Definition cpg.c:5
A dumping ground.
#define CRM_FEATURE_SET
Definition crm.h:72
void crm_time_free(crm_time_t *dt)
Definition iso8601.c:150
crm_time_t * crm_time_new(const char *string)
Definition iso8601.c:112
#define CRM_CHECK(expr, failure_action)
Definition logging.h:245
#define LOG_NEVER
Definition logging.h:48
#define crm_trace(fmt, args...)
Definition logging.h:402
#define LOG_TRACE
Definition logging.h:38
#define pcmk__config_err(fmt...)
@ pcmk__wo_op_attr_expr
#define pcmk__warn_once(wo_flag, fmt...)
pcmk_scheduler_t * scheduler
pcmk_node_t * pcmk__find_node_in_list(const GList *nodes, const char *node_name)
Definition nodes.c:150
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
Definition nvpair.c:446
char * crm_element_value_copy(const xmlNode *data, const char *name)
Retrieve a copy of the value of an XML attribute.
Definition nvpair.c:674
#define PCMK_VALUE_TRUE
Definition options.h:215
G_GNUC_INTERNAL gboolean unpack_resources(const xmlNode *xml_resources, pcmk_scheduler_t *scheduler)
Definition unpack.c:847
G_GNUC_INTERNAL gboolean unpack_tags(xmlNode *xml_tags, pcmk_scheduler_t *scheduler)
Definition unpack.c:913
G_GNUC_INTERNAL gboolean unpack_remote_nodes(xmlNode *xml_resources, pcmk_scheduler_t *scheduler)
Definition unpack.c:703
G_GNUC_INTERNAL gboolean unpack_status(xmlNode *status, pcmk_scheduler_t *scheduler)
Definition unpack.c:1371
G_GNUC_INTERNAL gboolean unpack_nodes(xmlNode *xml_nodes, pcmk_scheduler_t *scheduler)
Definition unpack.c:623
G_GNUC_INTERNAL gboolean unpack_config(xmlNode *config, pcmk_scheduler_t *scheduler)
Definition unpack.c:214
void pe__free_param_checks(pcmk_scheduler_t *scheduler)
Definition remote.c:232
void pe_free_action(pcmk_action_t *action)
pe_find
Search options for resources (exact resource ID always matches)
Definition resources.h:183
@ pcmk_rsc_match_history
Also match clone instance ID from resource history.
Definition resources.h:185
@ pcmk_rc_ok
Definition results.h:162
@ pcmk_no_quorum_stop
Definition scheduler.h:42
@ pcmk_no_quorum_ignore
Definition scheduler.h:43
@ pcmk_sched_stop_removed_resources
Definition scheduler.h:108
@ pcmk_sched_symmetric_cluster
Definition scheduler.h:83
@ pcmk_sched_no_counts
Definition scheduler.h:164
@ pcmk_sched_location_only
Definition scheduler.h:158
@ pcmk_sched_quorate
Definition scheduler.h:80
@ pcmk_sched_concurrent_fencing
Definition scheduler.h:102
@ pcmk_sched_have_status
Definition scheduler.h:145
@ pcmk_sched_cancel_removed_actions
Definition scheduler.h:114
#define pcmk__clear_scheduler_flags(scheduler, flags_to_clear)
#define pcmk__sched_warn(fmt...)
#define pcmk__set_scheduler_flags(scheduler, flags_to_set)
pcmk_node_t * pe_find_node_id(const GList *nodes, const char *id)
Find a node by ID in a list of nodes.
Definition status.c:483
pcmk_node_t * pe_find_node(const GList *nodes, const char *node_name)
Find a node by name in a list of nodes.
Definition status.c:513
void pe_free_working_set(pcmk_scheduler_t *scheduler)
Free scheduler data.
Definition status.c:50
void pe_reset_working_set(pcmk_scheduler_t *scheduler)
Reset scheduler data to default state without freeing it.
Definition status.c:373
pcmk_node_t * pe_find_node_any(const GList *nodes, const char *id, const char *uname)
Find a node by name or ID in a list of nodes.
Definition status.c:461
pcmk_resource_t * pe_find_resource(GList *rsc_list, const char *id)
Definition status.c:426
pcmk_scheduler_t * pe_new_working_set(void)
Create a new object to hold scheduler data.
Definition status.c:34
gboolean cluster_status(pcmk_scheduler_t *scheduler)
Definition status.c:96
void cleanup_calculations(pcmk_scheduler_t *scheduler)
Reset scheduler data to defaults without freeing it or constraints.
Definition status.c:314
void set_working_set_defaults(pcmk_scheduler_t *scheduler)
Definition status.c:403
#define XPATH_DEPRECATED_RULES
Definition status.c:59
pcmk_resource_t * pe_find_resource_with_flags(GList *rsc_list, const char *id, enum pe_find flags)
Definition status.c:432
Deprecated Pacemaker scheduler utilities.
@ pcmk__str_casei
Location constraint object.
struct pe_node_shared_s * details
Definition nodes.h:167
const char * id
Definition nodes.h:72
pcmk_rsc_methods_t * fns
Definition resources.h:412
GHashTable * singletons
Definition scheduler.h:225
GList * colocation_constraints
Definition scheduler.h:234
GList * ticket_constraints
Definition scheduler.h:237
GHashTable * tags
Definition scheduler.h:253
GHashTable * config_hash
Definition scheduler.h:219
GHashTable * template_rsc_sets
Definition scheduler.h:248
xmlNode * input
Definition scheduler.h:196
GList * resources
Definition scheduler.h:231
xmlNode * failed
Definition scheduler.h:240
xmlNode * graph
Definition scheduler.h:247
unsigned long long flags
Definition scheduler.h:211
xmlNode * rsc_defaults
Definition scheduler.h:242
xmlNode * op_defaults
Definition scheduler.h:241
enum pe_quorum_policy no_quorum_policy
Definition scheduler.h:217
GList * stop_needed
Definition scheduler.h:257
GHashTable * tickets
Definition scheduler.h:222
GList * placement_constraints
Definition scheduler.h:232
GList * ordering_constraints
Definition scheduler.h:233
crm_time_t * now
Definition scheduler.h:198
void(* free)(pcmk_resource_t *rsc)
Definition resources.h:336
pcmk_resource_t *(* find_rsc)(pcmk_resource_t *rsc, const char *search, const pcmk_node_t *node, int flags)
Definition resources.h:276
Wrappers for and extensions to libxml2.
xmlNode * get_xpath_object(const char *xpath, xmlNode *xml_obj, int error_level)
Definition xpath.c:189
void free_xml(xmlNode *child)
Definition xml.c:867
xmlNode * pcmk__xe_create(xmlNode *parent, const char *name)
Definition xml.c:720
#define PCMK_XA_DC_UUID
Definition xml_names.h:253
#define PCMK_XE_STATUS
Definition xml_names.h:199
#define PCMK_XE_OP_DEFAULTS
Definition xml_names.h:144
#define PCMK_XE_CRM_CONFIG
Definition xml_names.h:91
#define PCMK_XE_RESOURCES
Definition xml_names.h:175
#define PCMK_XE_TAGS
Definition xml_names.h:204
#define PCMK_XA_HAVE_QUORUM
Definition xml_names.h:290
#define PCMK_XA_CRM_FEATURE_SET
Definition xml_names.h:249
#define PCMK_XE_NODES
Definition xml_names.h:139
#define PCMK_XE_OP
Definition xml_names.h:143
#define PCMK_XE_RSC_DEFAULTS
Definition xml_names.h:182