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