This source file includes following definitions.
- get_resource_type
- dup_attr
- expand_parents_fixed_nvpairs
- get_meta_attributes
- get_rsc_attributes
- template_op_key
- unpack_template
- add_template_rsc
- detect_promotable
- free_params_table
- pe_rsc_params
- unpack_requires
- warn_about_deprecated_classes
- pe__unpack_resource
- is_parent
- uber_parent
- pe__const_top_resource
- common_free
- pe__count_active_node
- active_node
- pe__find_active_requires
- pe__count_common
- pe__set_next_role
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <crm/pengine/rules.h>
13 #include <crm/pengine/internal.h>
14 #include <crm/msg_xml.h>
15 #include <crm/common/xml_internal.h>
16
17 #include "pe_status_private.h"
18
19 void populate_hash(xmlNode * nvpair_list, GHashTable * hash, const char **attrs, int attrs_length);
20
21 static pe_node_t *active_node(const pe_resource_t *rsc, unsigned int *count_all,
22 unsigned int *count_clean);
23
24 resource_object_functions_t resource_class_functions[] = {
25 {
26 native_unpack,
27 native_find_rsc,
28 native_parameter,
29 native_print,
30 native_active,
31 native_resource_state,
32 native_location,
33 native_free,
34 pe__count_common,
35 pe__native_is_filtered,
36 active_node,
37 },
38 {
39 group_unpack,
40 native_find_rsc,
41 native_parameter,
42 group_print,
43 group_active,
44 group_resource_state,
45 native_location,
46 group_free,
47 pe__count_common,
48 pe__group_is_filtered,
49 active_node,
50 },
51 {
52 clone_unpack,
53 native_find_rsc,
54 native_parameter,
55 clone_print,
56 clone_active,
57 clone_resource_state,
58 native_location,
59 clone_free,
60 pe__count_common,
61 pe__clone_is_filtered,
62 active_node,
63 },
64 {
65 pe__unpack_bundle,
66 native_find_rsc,
67 native_parameter,
68 pe__print_bundle,
69 pe__bundle_active,
70 pe__bundle_resource_state,
71 native_location,
72 pe__free_bundle,
73 pe__count_bundle,
74 pe__bundle_is_filtered,
75 pe__bundle_active_node,
76 }
77 };
78
79 static enum pe_obj_types
80 get_resource_type(const char *name)
81 {
82 if (pcmk__str_eq(name, XML_CIB_TAG_RESOURCE, pcmk__str_casei)) {
83 return pe_native;
84
85 } else if (pcmk__str_eq(name, XML_CIB_TAG_GROUP, pcmk__str_casei)) {
86 return pe_group;
87
88 } else if (pcmk__str_eq(name, XML_CIB_TAG_INCARNATION, pcmk__str_casei)) {
89 return pe_clone;
90
91 } else if (pcmk__str_eq(name, PCMK_XE_PROMOTABLE_LEGACY, pcmk__str_casei)) {
92
93 return pe_clone;
94
95 } else if (pcmk__str_eq(name, XML_CIB_TAG_CONTAINER, pcmk__str_casei)) {
96 return pe_container;
97 }
98
99 return pe_unknown;
100 }
101
102 static void
103 dup_attr(gpointer key, gpointer value, gpointer user_data)
104 {
105 add_hash_param(user_data, key, value);
106 }
107
108 static void
109 expand_parents_fixed_nvpairs(pe_resource_t * rsc, pe_rule_eval_data_t * rule_data, GHashTable * meta_hash, pe_working_set_t * data_set)
110 {
111 GHashTable *parent_orig_meta = pcmk__strkey_table(free, free);
112 pe_resource_t *p = rsc->parent;
113
114 if (p == NULL) {
115 return ;
116 }
117
118
119
120 while(p != NULL) {
121
122 pe__unpack_dataset_nvpairs(p->xml, XML_TAG_META_SETS,
123 rule_data, parent_orig_meta, NULL, FALSE, data_set);
124 p = p->parent;
125 }
126
127
128 if (parent_orig_meta != NULL) {
129 GHashTableIter iter;
130 char *key = NULL;
131 char *value = NULL;
132
133 g_hash_table_iter_init(&iter, parent_orig_meta);
134 while (g_hash_table_iter_next(&iter, (gpointer *) &key, (gpointer *) &value)) {
135
136
137 dup_attr(key, value, meta_hash);
138 }
139 }
140
141 if (parent_orig_meta != NULL) {
142 g_hash_table_destroy(parent_orig_meta);
143 }
144
145 return ;
146
147 }
148 void
149 get_meta_attributes(GHashTable * meta_hash, pe_resource_t * rsc,
150 pe_node_t * node, pe_working_set_t * data_set)
151 {
152 pe_rsc_eval_data_t rsc_rule_data = {
153 .standard = crm_element_value(rsc->xml, XML_AGENT_ATTR_CLASS),
154 .provider = crm_element_value(rsc->xml, XML_AGENT_ATTR_PROVIDER),
155 .agent = crm_element_value(rsc->xml, XML_EXPR_ATTR_TYPE)
156 };
157
158 pe_rule_eval_data_t rule_data = {
159 .node_hash = NULL,
160 .role = RSC_ROLE_UNKNOWN,
161 .now = data_set->now,
162 .match_data = NULL,
163 .rsc_data = &rsc_rule_data,
164 .op_data = NULL
165 };
166
167 if (node) {
168 rule_data.node_hash = node->details->attrs;
169 }
170
171 for (xmlAttrPtr a = pcmk__xe_first_attr(rsc->xml); a != NULL; a = a->next) {
172 const char *prop_name = (const char *) a->name;
173 const char *prop_value = crm_element_value(rsc->xml, prop_name);
174
175 add_hash_param(meta_hash, prop_name, prop_value);
176 }
177
178 pe__unpack_dataset_nvpairs(rsc->xml, XML_TAG_META_SETS, &rule_data,
179 meta_hash, NULL, FALSE, data_set);
180
181
182
183 if (rsc->parent != NULL) {
184 expand_parents_fixed_nvpairs(rsc, &rule_data, meta_hash, data_set);
185 }
186
187
188 pe__unpack_dataset_nvpairs(data_set->rsc_defaults, XML_TAG_META_SETS,
189 &rule_data, meta_hash, NULL, FALSE, data_set);
190
191
192
193 if (rsc->parent) {
194 g_hash_table_foreach(rsc->parent->meta, dup_attr, meta_hash);
195 }
196 }
197
198 void
199 get_rsc_attributes(GHashTable *meta_hash, const pe_resource_t *rsc,
200 const pe_node_t *node, pe_working_set_t *data_set)
201 {
202 pe_rule_eval_data_t rule_data = {
203 .node_hash = NULL,
204 .role = RSC_ROLE_UNKNOWN,
205 .now = data_set->now,
206 .match_data = NULL,
207 .rsc_data = NULL,
208 .op_data = NULL
209 };
210
211 if (node) {
212 rule_data.node_hash = node->details->attrs;
213 }
214
215 pe__unpack_dataset_nvpairs(rsc->xml, XML_TAG_ATTR_SETS, &rule_data,
216 meta_hash, NULL, FALSE, data_set);
217
218
219 if (rsc->parent != NULL) {
220 get_rsc_attributes(meta_hash, rsc->parent, node, data_set);
221
222 } else {
223
224 pe__unpack_dataset_nvpairs(data_set->rsc_defaults, XML_TAG_ATTR_SETS,
225 &rule_data, meta_hash, NULL, FALSE, data_set);
226 }
227 }
228
229 static char *
230 template_op_key(xmlNode * op)
231 {
232 const char *name = crm_element_value(op, "name");
233 const char *role = crm_element_value(op, "role");
234 char *key = NULL;
235
236 if ((role == NULL)
237 || pcmk__strcase_any_of(role, RSC_ROLE_STARTED_S, RSC_ROLE_UNPROMOTED_S,
238 RSC_ROLE_UNPROMOTED_LEGACY_S, NULL)) {
239 role = RSC_ROLE_UNKNOWN_S;
240 }
241
242 key = crm_strdup_printf("%s-%s", name, role);
243 return key;
244 }
245
246 static gboolean
247 unpack_template(xmlNode * xml_obj, xmlNode ** expanded_xml, pe_working_set_t * data_set)
248 {
249 xmlNode *cib_resources = NULL;
250 xmlNode *template = NULL;
251 xmlNode *new_xml = NULL;
252 xmlNode *child_xml = NULL;
253 xmlNode *rsc_ops = NULL;
254 xmlNode *template_ops = NULL;
255 const char *template_ref = NULL;
256 const char *clone = NULL;
257 const char *id = NULL;
258
259 if (xml_obj == NULL) {
260 pe_err("No resource object for template unpacking");
261 return FALSE;
262 }
263
264 template_ref = crm_element_value(xml_obj, XML_CIB_TAG_RSC_TEMPLATE);
265 if (template_ref == NULL) {
266 return TRUE;
267 }
268
269 id = ID(xml_obj);
270 if (id == NULL) {
271 pe_err("'%s' object must have a id", crm_element_name(xml_obj));
272 return FALSE;
273 }
274
275 if (pcmk__str_eq(template_ref, id, pcmk__str_none)) {
276 pe_err("The resource object '%s' should not reference itself", id);
277 return FALSE;
278 }
279
280 cib_resources = get_xpath_object("//"XML_CIB_TAG_RESOURCES, data_set->input, LOG_TRACE);
281 if (cib_resources == NULL) {
282 pe_err("No resources configured");
283 return FALSE;
284 }
285
286 template = pcmk__xe_match(cib_resources, XML_CIB_TAG_RSC_TEMPLATE,
287 XML_ATTR_ID, template_ref);
288 if (template == NULL) {
289 pe_err("No template named '%s'", template_ref);
290 return FALSE;
291 }
292
293 new_xml = copy_xml(template);
294 xmlNodeSetName(new_xml, xml_obj->name);
295 crm_xml_replace(new_xml, XML_ATTR_ID, id);
296
297 clone = crm_element_value(xml_obj, XML_RSC_ATTR_INCARNATION);
298 if(clone) {
299 crm_xml_add(new_xml, XML_RSC_ATTR_INCARNATION, clone);
300 }
301
302 template_ops = find_xml_node(new_xml, "operations", FALSE);
303
304 for (child_xml = pcmk__xe_first_child(xml_obj); child_xml != NULL;
305 child_xml = pcmk__xe_next(child_xml)) {
306 xmlNode *new_child = NULL;
307
308 new_child = add_node_copy(new_xml, child_xml);
309
310 if (pcmk__str_eq((const char *)new_child->name, "operations", pcmk__str_none)) {
311 rsc_ops = new_child;
312 }
313 }
314
315 if (template_ops && rsc_ops) {
316 xmlNode *op = NULL;
317 GHashTable *rsc_ops_hash = pcmk__strkey_table(free, NULL);
318
319 for (op = pcmk__xe_first_child(rsc_ops); op != NULL;
320 op = pcmk__xe_next(op)) {
321
322 char *key = template_op_key(op);
323
324 g_hash_table_insert(rsc_ops_hash, key, op);
325 }
326
327 for (op = pcmk__xe_first_child(template_ops); op != NULL;
328 op = pcmk__xe_next(op)) {
329
330 char *key = template_op_key(op);
331
332 if (g_hash_table_lookup(rsc_ops_hash, key) == NULL) {
333 add_node_copy(rsc_ops, op);
334 }
335
336 free(key);
337 }
338
339 if (rsc_ops_hash) {
340 g_hash_table_destroy(rsc_ops_hash);
341 }
342
343 free_xml(template_ops);
344 }
345
346
347 *expanded_xml = new_xml;
348
349
350
351
352
353
354
355
356
357 return TRUE;
358 }
359
360 static gboolean
361 add_template_rsc(xmlNode * xml_obj, pe_working_set_t * data_set)
362 {
363 const char *template_ref = NULL;
364 const char *id = NULL;
365
366 if (xml_obj == NULL) {
367 pe_err("No resource object for processing resource list of template");
368 return FALSE;
369 }
370
371 template_ref = crm_element_value(xml_obj, XML_CIB_TAG_RSC_TEMPLATE);
372 if (template_ref == NULL) {
373 return TRUE;
374 }
375
376 id = ID(xml_obj);
377 if (id == NULL) {
378 pe_err("'%s' object must have a id", crm_element_name(xml_obj));
379 return FALSE;
380 }
381
382 if (pcmk__str_eq(template_ref, id, pcmk__str_none)) {
383 pe_err("The resource object '%s' should not reference itself", id);
384 return FALSE;
385 }
386
387 if (add_tag_ref(data_set->template_rsc_sets, template_ref, id) == FALSE) {
388 return FALSE;
389 }
390
391 return TRUE;
392 }
393
394 static bool
395 detect_promotable(pe_resource_t *rsc)
396 {
397 const char *promotable = g_hash_table_lookup(rsc->meta,
398 XML_RSC_ATTR_PROMOTABLE);
399
400 if (crm_is_true(promotable)) {
401 return TRUE;
402 }
403
404
405 if (pcmk__str_eq(crm_element_name(rsc->xml), PCMK_XE_PROMOTABLE_LEGACY,
406 pcmk__str_casei)) {
407
408
409
410 g_hash_table_insert(rsc->meta, strdup(XML_RSC_ATTR_PROMOTABLE),
411 strdup(XML_BOOLEAN_TRUE));
412 return TRUE;
413 }
414 return FALSE;
415 }
416
417 static void
418 free_params_table(gpointer data)
419 {
420 g_hash_table_destroy((GHashTable *) data);
421 }
422
423
424
425
426
427
428
429
430
431
432
433
434
435 GHashTable *
436 pe_rsc_params(pe_resource_t *rsc, const pe_node_t *node,
437 pe_working_set_t *data_set)
438 {
439 GHashTable *params_on_node = NULL;
440
441
442
443
444
445 const char *node_name = "";
446
447
448 if ((rsc == NULL) || (data_set == NULL)) {
449 return NULL;
450 }
451 if ((node != NULL) && (node->details->uname != NULL)) {
452 node_name = node->details->uname;
453 }
454
455
456 if (rsc->parameter_cache == NULL) {
457 rsc->parameter_cache = pcmk__strikey_table(free, free_params_table);
458 } else {
459 params_on_node = g_hash_table_lookup(rsc->parameter_cache, node_name);
460 }
461
462
463 if (params_on_node == NULL) {
464 params_on_node = pcmk__strkey_table(free, free);
465 get_rsc_attributes(params_on_node, rsc, node, data_set);
466 g_hash_table_insert(rsc->parameter_cache, strdup(node_name),
467 params_on_node);
468 }
469 return params_on_node;
470 }
471
472
473
474
475
476
477
478
479
480 static void
481 unpack_requires(pe_resource_t *rsc, const char *value, bool is_default)
482 {
483 if (pcmk__str_eq(value, PCMK__VALUE_NOTHING, pcmk__str_casei)) {
484
485 } else if (pcmk__str_eq(value, PCMK__VALUE_QUORUM, pcmk__str_casei)) {
486 pe__set_resource_flags(rsc, pe_rsc_needs_quorum);
487
488 } else if (pcmk__str_eq(value, PCMK__VALUE_FENCING, pcmk__str_casei)) {
489 pe__set_resource_flags(rsc, pe_rsc_needs_fencing);
490 if (!pcmk_is_set(rsc->cluster->flags, pe_flag_stonith_enabled)) {
491 pcmk__config_warn("%s requires fencing but fencing is disabled",
492 rsc->id);
493 }
494
495 } else if (pcmk__str_eq(value, PCMK__VALUE_UNFENCING, pcmk__str_casei)) {
496 if (pcmk_is_set(rsc->flags, pe_rsc_fence_device)) {
497 pcmk__config_warn("Resetting \"" XML_RSC_ATTR_REQUIRES "\" for %s "
498 "to \"" PCMK__VALUE_QUORUM "\" because fencing "
499 "devices cannot require unfencing", rsc->id);
500 unpack_requires(rsc, PCMK__VALUE_QUORUM, true);
501 return;
502
503 } else if (!pcmk_is_set(rsc->cluster->flags, pe_flag_stonith_enabled)) {
504 pcmk__config_warn("Resetting \"" XML_RSC_ATTR_REQUIRES "\" for %s "
505 "to \"" PCMK__VALUE_QUORUM "\" because fencing "
506 "is disabled", rsc->id);
507 unpack_requires(rsc, PCMK__VALUE_QUORUM, true);
508 return;
509
510 } else {
511 pe__set_resource_flags(rsc,
512 pe_rsc_needs_fencing|pe_rsc_needs_unfencing);
513 }
514
515 } else {
516 const char *orig_value = value;
517
518 if (pcmk_is_set(rsc->flags, pe_rsc_fence_device)) {
519 value = PCMK__VALUE_QUORUM;
520
521 } else if ((rsc->variant == pe_native)
522 && xml_contains_remote_node(rsc->xml)) {
523 value = PCMK__VALUE_QUORUM;
524
525 } else if (pcmk_is_set(rsc->cluster->flags, pe_flag_enable_unfencing)) {
526 value = PCMK__VALUE_UNFENCING;
527
528 } else if (pcmk_is_set(rsc->cluster->flags, pe_flag_stonith_enabled)) {
529 value = PCMK__VALUE_FENCING;
530
531 } else if (rsc->cluster->no_quorum_policy == no_quorum_ignore) {
532 value = PCMK__VALUE_NOTHING;
533
534 } else {
535 value = PCMK__VALUE_QUORUM;
536 }
537
538 if (orig_value != NULL) {
539 pcmk__config_err("Resetting '" XML_RSC_ATTR_REQUIRES "' for %s "
540 "to '%s' because '%s' is not valid",
541 rsc->id, value, orig_value);
542 }
543 unpack_requires(rsc, value, true);
544 return;
545 }
546
547 pe_rsc_trace(rsc, "\tRequired to start: %s%s", value,
548 (is_default? " (default)" : ""));
549 }
550
551 #ifndef PCMK__COMPAT_2_0
552 static void
553 warn_about_deprecated_classes(pe_resource_t *rsc)
554 {
555 const char *std = crm_element_value(rsc->xml, XML_AGENT_ATTR_CLASS);
556
557 if (pcmk__str_eq(std, PCMK_RESOURCE_CLASS_UPSTART, pcmk__str_none)) {
558 pe_warn_once(pe_wo_upstart,
559 "Support for Upstart resources (such as %s) is deprecated "
560 "and will be removed in a future release of Pacemaker",
561 rsc->id);
562
563 } else if (pcmk__str_eq(std, PCMK_RESOURCE_CLASS_NAGIOS, pcmk__str_none)) {
564 pe_warn_once(pe_wo_nagios,
565 "Support for Nagios resources (such as %s) is deprecated "
566 "and will be removed in a future release of Pacemaker",
567 rsc->id);
568 }
569 }
570 #endif
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589 int
590 pe__unpack_resource(xmlNode *xml_obj, pe_resource_t **rsc,
591 pe_resource_t *parent, pe_working_set_t *data_set)
592 {
593 xmlNode *expanded_xml = NULL;
594 xmlNode *ops = NULL;
595 const char *value = NULL;
596 const char *id = NULL;
597 bool guest_node = false;
598 bool remote_node = false;
599
600 pe_rule_eval_data_t rule_data = {
601 .node_hash = NULL,
602 .role = RSC_ROLE_UNKNOWN,
603 .now = NULL,
604 .match_data = NULL,
605 .rsc_data = NULL,
606 .op_data = NULL
607 };
608
609 CRM_CHECK(rsc != NULL, return EINVAL);
610 CRM_CHECK((xml_obj != NULL) && (data_set != NULL),
611 *rsc = NULL;
612 return EINVAL);
613
614 rule_data.now = data_set->now;
615
616 crm_log_xml_trace(xml_obj, "[raw XML]");
617
618 id = crm_element_value(xml_obj, XML_ATTR_ID);
619 if (id == NULL) {
620 pe_err("Ignoring <%s> configuration without " XML_ATTR_ID,
621 crm_element_name(xml_obj));
622 return pcmk_rc_unpack_error;
623 }
624
625 if (unpack_template(xml_obj, &expanded_xml, data_set) == FALSE) {
626 return pcmk_rc_unpack_error;
627 }
628
629 *rsc = calloc(1, sizeof(pe_resource_t));
630 if (*rsc == NULL) {
631 crm_crit("Unable to allocate memory for resource '%s'", id);
632 return ENOMEM;
633 }
634 (*rsc)->cluster = data_set;
635
636 if (expanded_xml) {
637 crm_log_xml_trace(expanded_xml, "[expanded XML]");
638 (*rsc)->xml = expanded_xml;
639 (*rsc)->orig_xml = xml_obj;
640
641 } else {
642 (*rsc)->xml = xml_obj;
643 (*rsc)->orig_xml = NULL;
644 }
645
646
647
648 (*rsc)->parent = parent;
649
650 ops = find_xml_node((*rsc)->xml, "operations", FALSE);
651 (*rsc)->ops_xml = expand_idref(ops, data_set->input);
652
653 (*rsc)->variant = get_resource_type(crm_element_name((*rsc)->xml));
654 if ((*rsc)->variant == pe_unknown) {
655 pe_err("Ignoring resource '%s' of unknown type '%s'",
656 id, crm_element_name((*rsc)->xml));
657 common_free(*rsc);
658 *rsc = NULL;
659 return pcmk_rc_unpack_error;
660 }
661
662 #ifndef PCMK__COMPAT_2_0
663 warn_about_deprecated_classes(*rsc);
664 #endif
665
666 (*rsc)->meta = pcmk__strkey_table(free, free);
667 (*rsc)->allowed_nodes = pcmk__strkey_table(NULL, free);
668 (*rsc)->known_on = pcmk__strkey_table(NULL, free);
669
670 value = crm_element_value((*rsc)->xml, XML_RSC_ATTR_INCARNATION);
671 if (value) {
672 (*rsc)->id = crm_strdup_printf("%s:%s", id, value);
673 add_hash_param((*rsc)->meta, XML_RSC_ATTR_INCARNATION, value);
674
675 } else {
676 (*rsc)->id = strdup(id);
677 }
678
679 (*rsc)->fns = &resource_class_functions[(*rsc)->variant];
680
681 get_meta_attributes((*rsc)->meta, *rsc, NULL, data_set);
682 (*rsc)->parameters = pe_rsc_params(*rsc, NULL, data_set);
683
684 (*rsc)->flags = 0;
685 pe__set_resource_flags(*rsc, pe_rsc_runnable|pe_rsc_provisional);
686
687 if (!pcmk_is_set(data_set->flags, pe_flag_maintenance_mode)) {
688 pe__set_resource_flags(*rsc, pe_rsc_managed);
689 }
690
691 (*rsc)->rsc_cons = NULL;
692 (*rsc)->rsc_tickets = NULL;
693 (*rsc)->actions = NULL;
694 (*rsc)->role = RSC_ROLE_STOPPED;
695 (*rsc)->next_role = RSC_ROLE_UNKNOWN;
696
697 (*rsc)->recovery_type = recovery_stop_start;
698 (*rsc)->stickiness = 0;
699 (*rsc)->migration_threshold = INFINITY;
700 (*rsc)->failure_timeout = 0;
701
702 value = g_hash_table_lookup((*rsc)->meta, XML_CIB_ATTR_PRIORITY);
703 (*rsc)->priority = char2score(value);
704
705 value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_CRITICAL);
706 if ((value == NULL) || crm_is_true(value)) {
707 pe__set_resource_flags(*rsc, pe_rsc_critical);
708 }
709
710 value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_NOTIFY);
711 if (crm_is_true(value)) {
712 pe__set_resource_flags(*rsc, pe_rsc_notify);
713 }
714
715 if (xml_contains_remote_node((*rsc)->xml)) {
716 (*rsc)->is_remote_node = TRUE;
717 if (g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_CONTAINER)) {
718 guest_node = true;
719 } else {
720 remote_node = true;
721 }
722 }
723
724 value = g_hash_table_lookup((*rsc)->meta, XML_OP_ATTR_ALLOW_MIGRATE);
725 if (crm_is_true(value)) {
726 pe__set_resource_flags(*rsc, pe_rsc_allow_migrate);
727 } else if ((value == NULL) && remote_node) {
728
729
730
731
732
733
734
735 pe__set_resource_flags(*rsc, pe_rsc_allow_migrate);
736 }
737
738 value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_MANAGED);
739 if (value != NULL && !pcmk__str_eq("default", value, pcmk__str_casei)) {
740 if (crm_is_true(value)) {
741 pe__set_resource_flags(*rsc, pe_rsc_managed);
742 } else {
743 pe__clear_resource_flags(*rsc, pe_rsc_managed);
744 }
745 }
746
747 value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_MAINTENANCE);
748 if (crm_is_true(value)) {
749 pe__clear_resource_flags(*rsc, pe_rsc_managed);
750 pe__set_resource_flags(*rsc, pe_rsc_maintenance);
751 }
752 if (pcmk_is_set(data_set->flags, pe_flag_maintenance_mode)) {
753 pe__clear_resource_flags(*rsc, pe_rsc_managed);
754 pe__set_resource_flags(*rsc, pe_rsc_maintenance);
755 }
756
757 if (pe_rsc_is_clone(pe__const_top_resource(*rsc, false))) {
758 value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_UNIQUE);
759 if (crm_is_true(value)) {
760 pe__set_resource_flags(*rsc, pe_rsc_unique);
761 }
762 if (detect_promotable(*rsc)) {
763 pe__set_resource_flags(*rsc, pe_rsc_promotable);
764 }
765 } else {
766 pe__set_resource_flags(*rsc, pe_rsc_unique);
767 }
768
769 value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_RESTART);
770 if (pcmk__str_eq(value, "restart", pcmk__str_casei)) {
771 (*rsc)->restart_type = pe_restart_restart;
772 pe_rsc_trace((*rsc), "%s dependency restart handling: restart",
773 (*rsc)->id);
774 pe_warn_once(pe_wo_restart_type,
775 "Support for restart-type is deprecated and will be removed in a future release");
776
777 } else {
778 (*rsc)->restart_type = pe_restart_ignore;
779 pe_rsc_trace((*rsc), "%s dependency restart handling: ignore",
780 (*rsc)->id);
781 }
782
783 value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_MULTIPLE);
784 if (pcmk__str_eq(value, "stop_only", pcmk__str_casei)) {
785 (*rsc)->recovery_type = recovery_stop_only;
786 pe_rsc_trace((*rsc), "%s multiple running resource recovery: stop only",
787 (*rsc)->id);
788
789 } else if (pcmk__str_eq(value, "block", pcmk__str_casei)) {
790 (*rsc)->recovery_type = recovery_block;
791 pe_rsc_trace((*rsc), "%s multiple running resource recovery: block",
792 (*rsc)->id);
793
794 } else if (pcmk__str_eq(value, "stop_unexpected", pcmk__str_casei)) {
795 (*rsc)->recovery_type = recovery_stop_unexpected;
796 pe_rsc_trace((*rsc), "%s multiple running resource recovery: "
797 "stop unexpected instances",
798 (*rsc)->id);
799
800 } else {
801 if (!pcmk__str_eq(value, "stop_start",
802 pcmk__str_casei|pcmk__str_null_matches)) {
803 pe_warn("%s is not a valid value for " XML_RSC_ATTR_MULTIPLE
804 ", using default of \"stop_start\"", value);
805 }
806 (*rsc)->recovery_type = recovery_stop_start;
807 pe_rsc_trace((*rsc), "%s multiple running resource recovery: "
808 "stop/start", (*rsc)->id);
809 }
810
811 value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_STICKINESS);
812 if (value != NULL && !pcmk__str_eq("default", value, pcmk__str_casei)) {
813 (*rsc)->stickiness = char2score(value);
814 }
815
816 value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_FAIL_STICKINESS);
817 if (value != NULL && !pcmk__str_eq("default", value, pcmk__str_casei)) {
818 (*rsc)->migration_threshold = char2score(value);
819 if ((*rsc)->migration_threshold < 0) {
820
821
822
823
824 pe_warn_once(pe_wo_neg_threshold,
825 XML_RSC_ATTR_FAIL_STICKINESS
826 " must be non-negative, using 1 instead");
827 (*rsc)->migration_threshold = 1;
828 }
829 }
830
831 if (pcmk__str_eq(crm_element_value((*rsc)->xml, XML_AGENT_ATTR_CLASS),
832 PCMK_RESOURCE_CLASS_STONITH, pcmk__str_casei)) {
833 pe__set_working_set_flags(data_set, pe_flag_have_stonith_resource);
834 pe__set_resource_flags(*rsc, pe_rsc_fence_device);
835 }
836
837 value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_REQUIRES);
838 unpack_requires(*rsc, value, false);
839
840 value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_FAIL_TIMEOUT);
841 if (value != NULL) {
842
843 (*rsc)->failure_timeout = (int) (crm_parse_interval_spec(value) / 1000);
844 }
845
846 if (remote_node) {
847 GHashTable *params = pe_rsc_params(*rsc, NULL, data_set);
848
849
850
851
852
853
854
855 value = g_hash_table_lookup(params, XML_REMOTE_ATTR_RECONNECT_INTERVAL);
856 if (value) {
857
858
859 (*rsc)->remote_reconnect_ms = crm_parse_interval_spec(value);
860
861
862 (*rsc)->failure_timeout = (*rsc)->remote_reconnect_ms / 1000;
863 }
864 }
865
866 get_target_role(*rsc, &((*rsc)->next_role));
867 pe_rsc_trace((*rsc), "%s desired next state: %s", (*rsc)->id,
868 (*rsc)->next_role != RSC_ROLE_UNKNOWN ? role2text((*rsc)->next_role) : "default");
869
870 if ((*rsc)->fns->unpack(*rsc, data_set) == FALSE) {
871 (*rsc)->fns->free(*rsc);
872 *rsc = NULL;
873 return pcmk_rc_unpack_error;
874 }
875
876 if (pcmk_is_set(data_set->flags, pe_flag_symmetric_cluster)) {
877
878 resource_location(*rsc, NULL, 0, "symmetric_default", data_set);
879 } else if (guest_node) {
880
881
882
883 resource_location(*rsc, NULL, 0, "remote_connection_default", data_set);
884 }
885
886 pe_rsc_trace((*rsc), "%s action notification: %s", (*rsc)->id,
887 pcmk_is_set((*rsc)->flags, pe_rsc_notify)? "required" : "not required");
888
889 (*rsc)->utilization = pcmk__strkey_table(free, free);
890
891 pe__unpack_dataset_nvpairs((*rsc)->xml, XML_TAG_UTILIZATION, &rule_data,
892 (*rsc)->utilization, NULL, FALSE, data_set);
893
894 if (expanded_xml) {
895 if (add_template_rsc(xml_obj, data_set) == FALSE) {
896 (*rsc)->fns->free(*rsc);
897 *rsc = NULL;
898 return pcmk_rc_unpack_error;
899 }
900 }
901 return pcmk_rc_ok;
902 }
903
904 gboolean
905 is_parent(pe_resource_t *child, pe_resource_t *rsc)
906 {
907 pe_resource_t *parent = child;
908
909 if (parent == NULL || rsc == NULL) {
910 return FALSE;
911 }
912 while (parent->parent != NULL) {
913 if (parent->parent == rsc) {
914 return TRUE;
915 }
916 parent = parent->parent;
917 }
918 return FALSE;
919 }
920
921 pe_resource_t *
922 uber_parent(pe_resource_t * rsc)
923 {
924 pe_resource_t *parent = rsc;
925
926 if (parent == NULL) {
927 return NULL;
928 }
929 while (parent->parent != NULL && parent->parent->variant != pe_container) {
930 parent = parent->parent;
931 }
932 return parent;
933 }
934
935
936
937
938
939
940
941
942
943
944
945
946 const pe_resource_t *
947 pe__const_top_resource(const pe_resource_t *rsc, bool include_bundle)
948 {
949 const pe_resource_t *parent = rsc;
950
951 if (parent == NULL) {
952 return NULL;
953 }
954 while (parent->parent != NULL) {
955 if (!include_bundle && (parent->parent->variant == pe_container)) {
956 break;
957 }
958 parent = parent->parent;
959 }
960 return parent;
961 }
962
963 void
964 common_free(pe_resource_t * rsc)
965 {
966 if (rsc == NULL) {
967 return;
968 }
969
970 pe_rsc_trace(rsc, "Freeing %s %d", rsc->id, rsc->variant);
971
972 g_list_free(rsc->rsc_cons);
973 g_list_free(rsc->rsc_cons_lhs);
974 g_list_free(rsc->rsc_tickets);
975 g_list_free(rsc->dangling_migrations);
976
977 if (rsc->parameter_cache != NULL) {
978 g_hash_table_destroy(rsc->parameter_cache);
979 }
980 if (rsc->meta != NULL) {
981 g_hash_table_destroy(rsc->meta);
982 }
983 if (rsc->utilization != NULL) {
984 g_hash_table_destroy(rsc->utilization);
985 }
986
987 if ((rsc->parent == NULL) && pcmk_is_set(rsc->flags, pe_rsc_orphan)) {
988 free_xml(rsc->xml);
989 rsc->xml = NULL;
990 free_xml(rsc->orig_xml);
991 rsc->orig_xml = NULL;
992
993
994 } else if (rsc->orig_xml) {
995 free_xml(rsc->xml);
996 rsc->xml = NULL;
997 }
998 if (rsc->running_on) {
999 g_list_free(rsc->running_on);
1000 rsc->running_on = NULL;
1001 }
1002 if (rsc->known_on) {
1003 g_hash_table_destroy(rsc->known_on);
1004 rsc->known_on = NULL;
1005 }
1006 if (rsc->actions) {
1007 g_list_free(rsc->actions);
1008 rsc->actions = NULL;
1009 }
1010 if (rsc->allowed_nodes) {
1011 g_hash_table_destroy(rsc->allowed_nodes);
1012 rsc->allowed_nodes = NULL;
1013 }
1014 g_list_free(rsc->fillers);
1015 g_list_free(rsc->rsc_location);
1016 pe_rsc_trace(rsc, "Resource freed");
1017 free(rsc->id);
1018 free(rsc->clone_name);
1019 free(rsc->allocated_to);
1020 free(rsc->variant_opaque);
1021 free(rsc->pending_task);
1022 free(rsc);
1023 }
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039 bool
1040 pe__count_active_node(const pe_resource_t *rsc, pe_node_t *node,
1041 pe_node_t **active, unsigned int *count_all,
1042 unsigned int *count_clean)
1043 {
1044 bool keep_looking = false;
1045 bool is_happy = false;
1046
1047 CRM_CHECK((rsc != NULL) && (node != NULL) && (active != NULL),
1048 return false);
1049
1050 is_happy = node->details->online && !node->details->unclean;
1051
1052 if (count_all != NULL) {
1053 ++*count_all;
1054 }
1055 if ((count_clean != NULL) && is_happy) {
1056 ++*count_clean;
1057 }
1058 if ((count_all != NULL) || (count_clean != NULL)) {
1059 keep_looking = true;
1060 }
1061
1062 if (rsc->partial_migration_source != NULL) {
1063 if (node->details == rsc->partial_migration_source->details) {
1064 *active = node;
1065 } else {
1066 keep_looking = true;
1067 }
1068 } else if (!pcmk_is_set(rsc->flags, pe_rsc_needs_fencing)) {
1069 if (is_happy && ((*active == NULL) || !(*active)->details->online
1070 || (*active)->details->unclean)) {
1071 *active = node;
1072 } else {
1073 keep_looking = true;
1074 }
1075 }
1076 if (*active == NULL) {
1077 *active = node;
1078 }
1079 return keep_looking;
1080 }
1081
1082
1083 static pe_node_t *
1084 active_node(const pe_resource_t *rsc, unsigned int *count_all,
1085 unsigned int *count_clean)
1086 {
1087 pe_node_t *active = NULL;
1088
1089 if (count_all != NULL) {
1090 *count_all = 0;
1091 }
1092 if (count_clean != NULL) {
1093 *count_clean = 0;
1094 }
1095 if (rsc == NULL) {
1096 return NULL;
1097 }
1098 for (GList *iter = rsc->running_on; iter != NULL; iter = iter->next) {
1099 if (!pe__count_active_node(rsc, (pe_node_t *) iter->data, &active,
1100 count_all, count_clean)) {
1101 break;
1102 }
1103 }
1104 return active;
1105 }
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120 pe_node_t *
1121 pe__find_active_requires(const pe_resource_t *rsc, unsigned int *count)
1122 {
1123 if (rsc == NULL) {
1124 if (count != NULL) {
1125 *count = 0;
1126 }
1127 return NULL;
1128
1129 } else if (pcmk_is_set(rsc->flags, pe_rsc_needs_fencing)) {
1130 return rsc->fns->active_node(rsc, count, NULL);
1131
1132 } else {
1133 return rsc->fns->active_node(rsc, NULL, count);
1134 }
1135 }
1136
1137 void
1138 pe__count_common(pe_resource_t *rsc)
1139 {
1140 if (rsc->children != NULL) {
1141 for (GList *item = rsc->children; item != NULL; item = item->next) {
1142 ((pe_resource_t *) item->data)->fns->count(item->data);
1143 }
1144
1145 } else if (!pcmk_is_set(rsc->flags, pe_rsc_orphan)
1146 || (rsc->role > RSC_ROLE_STOPPED)) {
1147 rsc->cluster->ninstances++;
1148 if (pe__resource_is_disabled(rsc)) {
1149 rsc->cluster->disabled_resources++;
1150 }
1151 if (pcmk_is_set(rsc->flags, pe_rsc_block)) {
1152 rsc->cluster->blocked_resources++;
1153 }
1154 }
1155 }
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165 void
1166 pe__set_next_role(pe_resource_t *rsc, enum rsc_role_e role, const char *why)
1167 {
1168 CRM_ASSERT((rsc != NULL) && (why != NULL));
1169 if (rsc->next_role != role) {
1170 pe_rsc_trace(rsc, "Resetting next role for %s from %s to %s (%s)",
1171 rsc->id, role2text(rsc->next_role), role2text(role), why);
1172 rsc->next_role = role;
1173 }
1174 }