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