pacemaker  2.0.2-debe490
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
complex.c
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2019 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 <crm/pengine/rules.h>
13 #include <crm/pengine/internal.h>
14 #include <crm/msg_xml.h>
15 
16 #include <unpack.h>
17 
18 void populate_hash(xmlNode * nvpair_list, GHashTable * hash, const char **attrs, int attrs_length);
19 
21  {
30  },
31  {
40  },
41  {
50  },
51  {
60  }
61 };
62 
63 static enum pe_obj_types
64 get_resource_type(const char *name)
65 {
66  if (safe_str_eq(name, XML_CIB_TAG_RESOURCE)) {
67  return pe_native;
68 
69  } else if (safe_str_eq(name, XML_CIB_TAG_GROUP)) {
70  return pe_group;
71 
72  } else if (safe_str_eq(name, XML_CIB_TAG_INCARNATION)) {
73  return pe_clone;
74 
75  } else if (safe_str_eq(name, XML_CIB_TAG_MASTER)) {
76  // @COMPAT deprecated since 2.0.0
77  return pe_clone;
78 
79  } else if (safe_str_eq(name, XML_CIB_TAG_CONTAINER)) {
80  return pe_container;
81  }
82 
83  return pe_unknown;
84 }
85 
86 static void
87 dup_attr(gpointer key, gpointer value, gpointer user_data)
88 {
89  add_hash_param(user_data, key, value);
90 }
91 
92 void
93 get_meta_attributes(GHashTable * meta_hash, resource_t * rsc,
94  node_t * node, pe_working_set_t * data_set)
95 {
96  GHashTable *node_hash = NULL;
97 
98  if (node) {
99  node_hash = node->details->attrs;
100  }
101 
102  if (rsc->xml) {
103  xmlAttrPtr xIter = NULL;
104 
105  for (xIter = rsc->xml->properties; xIter; xIter = xIter->next) {
106  const char *prop_name = (const char *)xIter->name;
107  const char *prop_value = crm_element_value(rsc->xml, prop_name);
108 
109  add_hash_param(meta_hash, prop_name, prop_value);
110  }
111  }
112 
113  unpack_instance_attributes(data_set->input, rsc->xml, XML_TAG_META_SETS, node_hash,
114  meta_hash, NULL, FALSE, data_set->now);
115 
116  /* set anything else based on the parent */
117  if (rsc->parent != NULL) {
118  g_hash_table_foreach(rsc->parent->meta, dup_attr, meta_hash);
119  }
120 
121  /* and finally check the defaults */
123  node_hash, meta_hash, NULL, FALSE, data_set->now);
124 }
125 
126 void
127 get_rsc_attributes(GHashTable * meta_hash, resource_t * rsc,
128  node_t * node, pe_working_set_t * data_set)
129 {
130  GHashTable *node_hash = NULL;
131 
132  if (node) {
133  node_hash = node->details->attrs;
134  }
135 
136  unpack_instance_attributes(data_set->input, rsc->xml, XML_TAG_ATTR_SETS, node_hash,
137  meta_hash, NULL, FALSE, data_set->now);
138 
139  /* set anything else based on the parent */
140  if (rsc->parent != NULL) {
141  get_rsc_attributes(meta_hash, rsc->parent, node, data_set);
142 
143  } else {
144  /* and finally check the defaults */
146  node_hash, meta_hash, NULL, FALSE, data_set->now);
147  }
148 }
149 
150 #if ENABLE_VERSIONED_ATTRS
151 void
152 pe_get_versioned_attributes(xmlNode * meta_hash, resource_t * rsc,
153  node_t * node, pe_working_set_t * data_set)
154 {
155  GHashTable *node_hash = NULL;
156 
157  if (node) {
158  node_hash = node->details->attrs;
159  }
160 
161  pe_unpack_versioned_attributes(data_set->input, rsc->xml, XML_TAG_ATTR_SETS, node_hash,
162  meta_hash, data_set->now);
163 
164  /* set anything else based on the parent */
165  if (rsc->parent != NULL) {
166  pe_get_versioned_attributes(meta_hash, rsc->parent, node, data_set);
167 
168  } else {
169  /* and finally check the defaults */
170  pe_unpack_versioned_attributes(data_set->input, data_set->rsc_defaults, XML_TAG_ATTR_SETS,
171  node_hash, meta_hash, data_set->now);
172  }
173 }
174 #endif
175 
176 static char *
177 template_op_key(xmlNode * op)
178 {
179  const char *name = crm_element_value(op, "name");
180  const char *role = crm_element_value(op, "role");
181  char *key = NULL;
182 
183  if (role == NULL || crm_str_eq(role, RSC_ROLE_STARTED_S, TRUE)
184  || crm_str_eq(role, RSC_ROLE_SLAVE_S, TRUE)) {
185  role = RSC_ROLE_UNKNOWN_S;
186  }
187 
188  key = crm_concat(name, role, '-');
189  return key;
190 }
191 
192 static gboolean
193 unpack_template(xmlNode * xml_obj, xmlNode ** expanded_xml, pe_working_set_t * data_set)
194 {
195  xmlNode *cib_resources = NULL;
196  xmlNode *template = NULL;
197  xmlNode *new_xml = NULL;
198  xmlNode *child_xml = NULL;
199  xmlNode *rsc_ops = NULL;
200  xmlNode *template_ops = NULL;
201  const char *template_ref = NULL;
202  const char *clone = NULL;
203  const char *id = NULL;
204 
205  if (xml_obj == NULL) {
206  pe_err("No resource object for template unpacking");
207  return FALSE;
208  }
209 
210  template_ref = crm_element_value(xml_obj, XML_CIB_TAG_RSC_TEMPLATE);
211  if (template_ref == NULL) {
212  return TRUE;
213  }
214 
215  id = ID(xml_obj);
216  if (id == NULL) {
217  pe_err("'%s' object must have a id", crm_element_name(xml_obj));
218  return FALSE;
219  }
220 
221  if (crm_str_eq(template_ref, id, TRUE)) {
222  pe_err("The resource object '%s' should not reference itself", id);
223  return FALSE;
224  }
225 
226  cib_resources = get_xpath_object("//"XML_CIB_TAG_RESOURCES, data_set->input, LOG_TRACE);
227  if (cib_resources == NULL) {
228  pe_err("No resources configured");
229  return FALSE;
230  }
231 
232  template = find_entity(cib_resources, XML_CIB_TAG_RSC_TEMPLATE, template_ref);
233  if (template == NULL) {
234  pe_err("No template named '%s'", template_ref);
235  return FALSE;
236  }
237 
238  new_xml = copy_xml(template);
239  xmlNodeSetName(new_xml, xml_obj->name);
240  crm_xml_replace(new_xml, XML_ATTR_ID, id);
241 
243  if(clone) {
244  crm_xml_add(new_xml, XML_RSC_ATTR_INCARNATION, clone);
245  }
246 
247  template_ops = find_xml_node(new_xml, "operations", FALSE);
248 
249  for (child_xml = __xml_first_child(xml_obj); child_xml != NULL;
250  child_xml = __xml_next_element(child_xml)) {
251  xmlNode *new_child = NULL;
252 
253  new_child = add_node_copy(new_xml, child_xml);
254 
255  if (crm_str_eq((const char *)new_child->name, "operations", TRUE)) {
256  rsc_ops = new_child;
257  }
258  }
259 
260  if (template_ops && rsc_ops) {
261  xmlNode *op = NULL;
262  GHashTable *rsc_ops_hash = g_hash_table_new_full(crm_str_hash,
263  g_str_equal, free,
264  NULL);
265 
266  for (op = __xml_first_child(rsc_ops); op != NULL; op = __xml_next_element(op)) {
267  char *key = template_op_key(op);
268 
269  g_hash_table_insert(rsc_ops_hash, key, op);
270  }
271 
272  for (op = __xml_first_child(template_ops); op != NULL; op = __xml_next_element(op)) {
273  char *key = template_op_key(op);
274 
275  if (g_hash_table_lookup(rsc_ops_hash, key) == NULL) {
276  add_node_copy(rsc_ops, op);
277  }
278 
279  free(key);
280  }
281 
282  if (rsc_ops_hash) {
283  g_hash_table_destroy(rsc_ops_hash);
284  }
285 
286  free_xml(template_ops);
287  }
288 
289  /*free_xml(*expanded_xml); */
290  *expanded_xml = new_xml;
291 
292  /* Disable multi-level templates for now */
293  /*if(unpack_template(new_xml, expanded_xml, data_set) == FALSE) {
294  free_xml(*expanded_xml);
295  *expanded_xml = NULL;
296 
297  return FALSE;
298  } */
299 
300  return TRUE;
301 }
302 
303 static gboolean
304 add_template_rsc(xmlNode * xml_obj, pe_working_set_t * data_set)
305 {
306  const char *template_ref = NULL;
307  const char *id = NULL;
308 
309  if (xml_obj == NULL) {
310  pe_err("No resource object for processing resource list of template");
311  return FALSE;
312  }
313 
314  template_ref = crm_element_value(xml_obj, XML_CIB_TAG_RSC_TEMPLATE);
315  if (template_ref == NULL) {
316  return TRUE;
317  }
318 
319  id = ID(xml_obj);
320  if (id == NULL) {
321  pe_err("'%s' object must have a id", crm_element_name(xml_obj));
322  return FALSE;
323  }
324 
325  if (crm_str_eq(template_ref, id, TRUE)) {
326  pe_err("The resource object '%s' should not reference itself", id);
327  return FALSE;
328  }
329 
330  if (add_tag_ref(data_set->template_rsc_sets, template_ref, id) == FALSE) {
331  return FALSE;
332  }
333 
334  return TRUE;
335 }
336 
337 static bool
338 detect_promotable(resource_t *rsc)
339 {
340  const char *promotable = g_hash_table_lookup(rsc->meta,
342 
343  if (crm_is_true(promotable)) {
344  return TRUE;
345  }
346 
347  // @COMPAT deprecated since 2.0.0
348  if (safe_str_eq(crm_element_name(rsc->xml), XML_CIB_TAG_MASTER)) {
349  /* @TODO in some future version, pe_warn_once() here,
350  * then drop support in even later version
351  */
352  g_hash_table_insert(rsc->meta, strdup(XML_RSC_ATTR_PROMOTABLE),
353  strdup(XML_BOOLEAN_TRUE));
354  return TRUE;
355  }
356  return FALSE;
357 }
358 
359 gboolean
360 common_unpack(xmlNode * xml_obj, resource_t ** rsc,
361  resource_t * parent, pe_working_set_t * data_set)
362 {
363  bool isdefault = FALSE;
364  xmlNode *expanded_xml = NULL;
365  xmlNode *ops = NULL;
366  const char *value = NULL;
367  const char *rclass = NULL; /* Look for this after any templates have been expanded */
368  const char *id = crm_element_value(xml_obj, XML_ATTR_ID);
369  bool guest_node = FALSE;
370  bool remote_node = FALSE;
371  bool has_versioned_params = FALSE;
372 
373  crm_log_xml_trace(xml_obj, "Processing resource input...");
374 
375  if (id == NULL) {
376  pe_err("Must specify id tag in <resource>");
377  return FALSE;
378 
379  } else if (rsc == NULL) {
380  pe_err("Nowhere to unpack resource into");
381  return FALSE;
382 
383  }
384 
385  if (unpack_template(xml_obj, &expanded_xml, data_set) == FALSE) {
386  return FALSE;
387  }
388 
389  *rsc = calloc(1, sizeof(resource_t));
390  (*rsc)->cluster = data_set;
391 
392  if (expanded_xml) {
393  crm_log_xml_trace(expanded_xml, "Expanded resource...");
394  (*rsc)->xml = expanded_xml;
395  (*rsc)->orig_xml = xml_obj;
396 
397  } else {
398  (*rsc)->xml = xml_obj;
399  (*rsc)->orig_xml = NULL;
400  }
401 
402  /* Do not use xml_obj from here on, use (*rsc)->xml in case templates are involved */
403  rclass = crm_element_value((*rsc)->xml, XML_AGENT_ATTR_CLASS);
404  (*rsc)->parent = parent;
405 
406  ops = find_xml_node((*rsc)->xml, "operations", FALSE);
407  (*rsc)->ops_xml = expand_idref(ops, data_set->input);
408 
409  (*rsc)->variant = get_resource_type(crm_element_name((*rsc)->xml));
410  if ((*rsc)->variant == pe_unknown) {
411  pe_err("Unknown resource type: %s", crm_element_name((*rsc)->xml));
412  free(*rsc);
413  return FALSE;
414  }
415 
416  (*rsc)->parameters = crm_str_table_new();
417 
418 #if ENABLE_VERSIONED_ATTRS
419  (*rsc)->versioned_parameters = create_xml_node(NULL, XML_TAG_RSC_VER_ATTRS);
420 #endif
421 
422  (*rsc)->meta = crm_str_table_new();
423 
424  (*rsc)->allowed_nodes =
425  g_hash_table_new_full(crm_str_hash, g_str_equal, NULL, free);
426 
427  (*rsc)->known_on = g_hash_table_new_full(crm_str_hash, g_str_equal, NULL,
428  free);
429 
430  value = crm_element_value((*rsc)->xml, XML_RSC_ATTR_INCARNATION);
431  if (value) {
432  (*rsc)->id = crm_concat(id, value, ':');
433  add_hash_param((*rsc)->meta, XML_RSC_ATTR_INCARNATION, value);
434 
435  } else {
436  (*rsc)->id = strdup(id);
437  }
438 
439  (*rsc)->fns = &resource_class_functions[(*rsc)->variant];
440  pe_rsc_trace((*rsc), "Unpacking resource...");
441 
442  get_meta_attributes((*rsc)->meta, *rsc, NULL, data_set);
443  get_rsc_attributes((*rsc)->parameters, *rsc, NULL, data_set);
444 #if ENABLE_VERSIONED_ATTRS
445  pe_get_versioned_attributes((*rsc)->versioned_parameters, *rsc, NULL, data_set);
446 #endif
447 
448  (*rsc)->flags = 0;
449  set_bit((*rsc)->flags, pe_rsc_runnable);
450  set_bit((*rsc)->flags, pe_rsc_provisional);
451 
452  if (is_not_set(data_set->flags, pe_flag_maintenance_mode)) {
453  set_bit((*rsc)->flags, pe_rsc_managed);
454  }
455 
456  (*rsc)->rsc_cons = NULL;
457  (*rsc)->rsc_tickets = NULL;
458  (*rsc)->actions = NULL;
459  (*rsc)->role = RSC_ROLE_STOPPED;
460  (*rsc)->next_role = RSC_ROLE_UNKNOWN;
461 
462  (*rsc)->recovery_type = recovery_stop_start;
463  (*rsc)->stickiness = 0;
464  (*rsc)->migration_threshold = INFINITY;
465  (*rsc)->failure_timeout = 0;
466 
467  value = g_hash_table_lookup((*rsc)->meta, XML_CIB_ATTR_PRIORITY);
468  (*rsc)->priority = crm_parse_int(value, "0");
469 
470  value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_NOTIFY);
471  if (crm_is_true(value)) {
472  set_bit((*rsc)->flags, pe_rsc_notify);
473  }
474 
475  if (xml_contains_remote_node((*rsc)->xml)) {
476  (*rsc)->is_remote_node = TRUE;
477  if (g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_CONTAINER)) {
478  guest_node = TRUE;
479  } else {
480  remote_node = TRUE;
481  }
482  }
483 
484  value = g_hash_table_lookup((*rsc)->meta, XML_OP_ATTR_ALLOW_MIGRATE);
485 #if ENABLE_VERSIONED_ATTRS
486  has_versioned_params = xml_has_children((*rsc)->versioned_parameters);
487 #endif
488  if (crm_is_true(value) && has_versioned_params) {
489  pe_rsc_trace((*rsc), "Migration is disabled for resources with versioned parameters");
490  } else if (crm_is_true(value)) {
491  set_bit((*rsc)->flags, pe_rsc_allow_migrate);
492  } else if ((value == NULL) && remote_node && !has_versioned_params) {
493  /* By default, we want remote nodes to be able
494  * to float around the cluster without having to stop all the
495  * resources within the remote-node before moving. Allowing
496  * migration support enables this feature. If this ever causes
497  * problems, migration support can be explicitly turned off with
498  * allow-migrate=false.
499  * We don't support migration for versioned resources, though. */
500  set_bit((*rsc)->flags, pe_rsc_allow_migrate);
501  }
502 
503  value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_MANAGED);
504  if (value != NULL && safe_str_neq("default", value)) {
505  gboolean bool_value = TRUE;
506 
507  crm_str_to_boolean(value, &bool_value);
508  if (bool_value == FALSE) {
509  clear_bit((*rsc)->flags, pe_rsc_managed);
510  } else {
511  set_bit((*rsc)->flags, pe_rsc_managed);
512  }
513  }
514 
515  value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_MAINTENANCE);
516  if (value != NULL && safe_str_neq("default", value)) {
517  gboolean bool_value = FALSE;
518 
519  crm_str_to_boolean(value, &bool_value);
520  if (bool_value == TRUE) {
521  clear_bit((*rsc)->flags, pe_rsc_managed);
522  set_bit((*rsc)->flags, pe_rsc_maintenance);
523  }
524 
525  } else if (is_set(data_set->flags, pe_flag_maintenance_mode)) {
526  clear_bit((*rsc)->flags, pe_rsc_managed);
527  set_bit((*rsc)->flags, pe_rsc_maintenance);
528  }
529 
530  if (pe_rsc_is_clone(uber_parent(*rsc))) {
531  value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_UNIQUE);
532  if (crm_is_true(value)) {
533  set_bit((*rsc)->flags, pe_rsc_unique);
534  }
535  if (detect_promotable(*rsc)) {
536  set_bit((*rsc)->flags, pe_rsc_promotable);
537  }
538  } else {
539  set_bit((*rsc)->flags, pe_rsc_unique);
540  }
541 
542  pe_rsc_trace((*rsc), "Options for %s", (*rsc)->id);
543 
544  value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_RESTART);
545  if (safe_str_eq(value, "restart")) {
546  (*rsc)->restart_type = pe_restart_restart;
547  pe_rsc_trace((*rsc), "\tDependency restart handling: restart");
549  "Support for restart-type is deprecated and will be removed in a future release");
550 
551  } else {
552  (*rsc)->restart_type = pe_restart_ignore;
553  pe_rsc_trace((*rsc), "\tDependency restart handling: ignore");
554  }
555 
556  value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_MULTIPLE);
557  if (safe_str_eq(value, "stop_only")) {
558  (*rsc)->recovery_type = recovery_stop_only;
559  pe_rsc_trace((*rsc), "\tMultiple running resource recovery: stop only");
560 
561  } else if (safe_str_eq(value, "block")) {
562  (*rsc)->recovery_type = recovery_block;
563  pe_rsc_trace((*rsc), "\tMultiple running resource recovery: block");
564 
565  } else {
566  (*rsc)->recovery_type = recovery_stop_start;
567  pe_rsc_trace((*rsc), "\tMultiple running resource recovery: stop/start");
568  }
569 
570  value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_STICKINESS);
571  if (value != NULL && safe_str_neq("default", value)) {
572  (*rsc)->stickiness = char2score(value);
573  }
574 
575  value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_FAIL_STICKINESS);
576  if (value != NULL && safe_str_neq("default", value)) {
577  (*rsc)->migration_threshold = char2score(value);
578  }
579 
582  set_bit((*rsc)->flags, pe_rsc_fence_device);
583  }
584 
585  value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_REQUIRES);
586 
587  handle_requires_pref:
588  if (safe_str_eq(value, "nothing")) {
589 
590  } else if (safe_str_eq(value, "quorum")) {
591  set_bit((*rsc)->flags, pe_rsc_needs_quorum);
592 
593  } else if (safe_str_eq(value, "unfencing")) {
594  if (is_set((*rsc)->flags, pe_rsc_fence_device)) {
595  crm_config_warn("%s is a fencing device but requires (un)fencing", (*rsc)->id);
596  value = "quorum";
597  isdefault = TRUE;
598  goto handle_requires_pref;
599 
600  } else if (is_not_set(data_set->flags, pe_flag_stonith_enabled)) {
601  crm_config_warn("%s requires (un)fencing but fencing is disabled", (*rsc)->id);
602  value = "quorum";
603  isdefault = TRUE;
604  goto handle_requires_pref;
605 
606  } else {
607  set_bit((*rsc)->flags, pe_rsc_needs_fencing);
608  set_bit((*rsc)->flags, pe_rsc_needs_unfencing);
609  }
610 
611  } else if (safe_str_eq(value, "fencing")) {
612  set_bit((*rsc)->flags, pe_rsc_needs_fencing);
613  if (is_not_set(data_set->flags, pe_flag_stonith_enabled)) {
614  crm_config_warn("%s requires fencing but fencing is disabled", (*rsc)->id);
615  }
616 
617  } else {
618  if (value) {
619  crm_config_err("Invalid value for %s->requires: %s%s",
620  (*rsc)->id, value,
621  is_set(data_set->flags, pe_flag_stonith_enabled) ? "" : " (stonith-enabled=false)");
622  }
623 
624  isdefault = TRUE;
625  if(is_set((*rsc)->flags, pe_rsc_fence_device)) {
626  value = "quorum";
627 
628  } else if (((*rsc)->variant == pe_native)
631  && safe_str_eq(crm_element_value((*rsc)->xml, XML_AGENT_ATTR_PROVIDER), "pacemaker")
632  && safe_str_eq(crm_element_value((*rsc)->xml, XML_ATTR_TYPE), "remote")
633  ) {
634  value = "quorum";
635 
636  } else if (is_set(data_set->flags, pe_flag_enable_unfencing)) {
637  value = "unfencing";
638 
639  } else if (is_set(data_set->flags, pe_flag_stonith_enabled)) {
640  value = "fencing";
641 
642  } else if (data_set->no_quorum_policy == no_quorum_ignore) {
643  value = "nothing";
644 
645  } else {
646  value = "quorum";
647  }
648  goto handle_requires_pref;
649  }
650 
651  pe_rsc_trace((*rsc), "\tRequired to start: %s%s", value, isdefault?" (default)":"");
652  value = g_hash_table_lookup((*rsc)->meta, XML_RSC_ATTR_FAIL_TIMEOUT);
653  if (value != NULL) {
654  /* call crm_get_msec() and convert back to seconds */
655  (*rsc)->failure_timeout = (crm_get_msec(value) / 1000);
656  }
657 
658  if (remote_node) {
659  value = g_hash_table_lookup((*rsc)->parameters, XML_REMOTE_ATTR_RECONNECT_INTERVAL);
660  if (value) {
661  /* reconnect delay works by setting failure_timeout and preventing the
662  * connection from starting until the failure is cleared. */
663  (*rsc)->remote_reconnect_ms = crm_parse_interval_spec(value);
664  /* we want to override any default failure_timeout in use when remote
665  * reconnect_interval is in use. */
666  (*rsc)->failure_timeout = (*rsc)->remote_reconnect_ms / 1000;
667  }
668  }
669 
670  get_target_role(*rsc, &((*rsc)->next_role));
671  pe_rsc_trace((*rsc), "\tDesired next state: %s",
672  (*rsc)->next_role != RSC_ROLE_UNKNOWN ? role2text((*rsc)->next_role) : "default");
673 
674  if ((*rsc)->fns->unpack(*rsc, data_set) == FALSE) {
675  return FALSE;
676  }
677 
678  if (is_set(data_set->flags, pe_flag_symmetric_cluster)) {
679  // This tag must stay exactly the same because it is tested elsewhere
680  resource_location(*rsc, NULL, 0, "symmetric_default", data_set);
681  } else if (guest_node) {
682  /* remote resources tied to a container resource must always be allowed
683  * to opt-in to the cluster. Whether the connection resource is actually
684  * allowed to be placed on a node is dependent on the container resource */
685  resource_location(*rsc, NULL, 0, "remote_connection_default", data_set);
686  }
687 
688  pe_rsc_trace((*rsc), "\tAction notification: %s",
689  is_set((*rsc)->flags, pe_rsc_notify) ? "required" : "not required");
690 
691  (*rsc)->utilization = crm_str_table_new();
692 
693  unpack_instance_attributes(data_set->input, (*rsc)->xml, XML_TAG_UTILIZATION, NULL,
694  (*rsc)->utilization, NULL, FALSE, data_set->now);
695 
696 /* data_set->resources = g_list_append(data_set->resources, (*rsc)); */
697 
698  if (expanded_xml) {
699  if (add_template_rsc(xml_obj, data_set) == FALSE) {
700  return FALSE;
701  }
702  }
703  return TRUE;
704 }
705 
706 void
707 common_update_score(resource_t * rsc, const char *id, int score)
708 {
709  node_t *node = NULL;
710 
711  node = pe_hash_table_lookup(rsc->allowed_nodes, id);
712  if (node != NULL) {
713  pe_rsc_trace(rsc, "Updating score for %s on %s: %d + %d", rsc->id, id, node->weight, score);
714  node->weight = merge_weights(node->weight, score);
715  }
716 
717  if (rsc->children) {
718  GListPtr gIter = rsc->children;
719 
720  for (; gIter != NULL; gIter = gIter->next) {
721  resource_t *child_rsc = (resource_t *) gIter->data;
722 
723  common_update_score(child_rsc, id, score);
724  }
725  }
726 }
727 
728 gboolean
730 {
731  resource_t *parent = child;
732 
733  if (parent == NULL || rsc == NULL) {
734  return FALSE;
735  }
736  while (parent->parent != NULL) {
737  if (parent->parent == rsc) {
738  return TRUE;
739  }
740  parent = parent->parent;
741  }
742  return FALSE;
743 }
744 
745 resource_t *
747 {
748  resource_t *parent = rsc;
749 
750  if (parent == NULL) {
751  return NULL;
752  }
753  while (parent->parent != NULL && parent->parent->variant != pe_container) {
754  parent = parent->parent;
755  }
756  return parent;
757 }
758 
759 void
761 {
762  if (rsc == NULL) {
763  return;
764  }
765 
766  pe_rsc_trace(rsc, "Freeing %s %d", rsc->id, rsc->variant);
767 
768  g_list_free(rsc->rsc_cons);
769  g_list_free(rsc->rsc_cons_lhs);
770  g_list_free(rsc->rsc_tickets);
771  g_list_free(rsc->dangling_migrations);
772 
773  if (rsc->parameters != NULL) {
774  g_hash_table_destroy(rsc->parameters);
775  }
776 #if ENABLE_VERSIONED_ATTRS
777  if (rsc->versioned_parameters != NULL) {
778  free_xml(rsc->versioned_parameters);
779  }
780 #endif
781  if (rsc->meta != NULL) {
782  g_hash_table_destroy(rsc->meta);
783  }
784  if (rsc->utilization != NULL) {
785  g_hash_table_destroy(rsc->utilization);
786  }
787 
788  if (rsc->parent == NULL && is_set(rsc->flags, pe_rsc_orphan)) {
789  free_xml(rsc->xml);
790  rsc->xml = NULL;
791  free_xml(rsc->orig_xml);
792  rsc->orig_xml = NULL;
793 
794  /* if rsc->orig_xml, then rsc->xml is an expanded xml from a template */
795  } else if (rsc->orig_xml) {
796  free_xml(rsc->xml);
797  rsc->xml = NULL;
798  }
799  if (rsc->running_on) {
800  g_list_free(rsc->running_on);
801  rsc->running_on = NULL;
802  }
803  if (rsc->known_on) {
804  g_hash_table_destroy(rsc->known_on);
805  rsc->known_on = NULL;
806  }
807  if (rsc->actions) {
808  g_list_free(rsc->actions);
809  rsc->actions = NULL;
810  }
811  if (rsc->allowed_nodes) {
812  g_hash_table_destroy(rsc->allowed_nodes);
813  rsc->allowed_nodes = NULL;
814  }
815  g_list_free(rsc->fillers);
816  g_list_free(rsc->rsc_location);
817  pe_rsc_trace(rsc, "Resource freed");
818  free(rsc->id);
819  free(rsc->clone_name);
820  free(rsc->allocated_to);
821  free(rsc->variant_opaque);
822  free(rsc->pending_task);
823  free(rsc);
824 }
825 
841 pe_node_t *
842 pe__find_active_on(const pe_resource_t *rsc, unsigned int *count_all,
843  unsigned int *count_clean)
844 {
845  pe_node_t *active = NULL;
846  pe_node_t *node = NULL;
847  bool keep_looking = FALSE;
848  bool is_happy = FALSE;
849 
850  if (count_all) {
851  *count_all = 0;
852  }
853  if (count_clean) {
854  *count_clean = 0;
855  }
856  if (rsc == NULL) {
857  return NULL;
858  }
859 
860  for (GList *node_iter = rsc->running_on; node_iter != NULL;
861  node_iter = node_iter->next) {
862 
863  node = node_iter->data;
864  keep_looking = FALSE;
865 
866  is_happy = node->details->online && !node->details->unclean;
867 
868  if (count_all) {
869  ++*count_all;
870  }
871  if (count_clean && is_happy) {
872  ++*count_clean;
873  }
874  if (count_all || count_clean) {
875  // If we're counting, we need to go through entire list
876  keep_looking = TRUE;
877  }
878 
879  if (rsc->partial_migration_source != NULL) {
880  if (node->details == rsc->partial_migration_source->details) {
881  // This is the migration source
882  active = node;
883  } else {
884  keep_looking = TRUE;
885  }
886  } else if (is_not_set(rsc->flags, pe_rsc_needs_fencing)) {
887  if (is_happy && (!active || !active->details->online
888  || active->details->unclean)) {
889  // This is the first clean node
890  active = node;
891  } else {
892  keep_looking = TRUE;
893  }
894  }
895  if (active == NULL) {
896  // This is first node in list
897  active = node;
898  }
899 
900  if (keep_looking == FALSE) {
901  // Don't waste time iterating if we don't have to
902  break;
903  }
904  }
905  return active;
906 }
907 
921 pe_node_t *
922 pe__find_active_requires(const pe_resource_t *rsc, unsigned int *count)
923 {
924  if (rsc && is_not_set(rsc->flags, pe_rsc_needs_fencing)) {
925  return pe__find_active_on(rsc, NULL, count);
926  }
927  return pe__find_active_on(rsc, count, NULL);
928 }
#define LOG_TRACE
Definition: logging.h:26
xmlNode * find_xml_node(xmlNode *cib, const char *node_path, gboolean must_find)
Definition: xml.c:1678
xmlNode * orig_xml
Definition: pe_types.h:287
enum pe_quorum_policy no_quorum_policy
Definition: pe_types.h:125
void clone_print(resource_t *rsc, const char *pre_text, long options, void *print_data)
Definition: clone.c:367
void get_meta_attributes(GHashTable *meta_hash, pe_resource_t *rsc, pe_node_t *node, pe_working_set_t *data_set)
Definition: complex.c:93
GHashTable * known_on
Definition: pe_types.h:330
void group_free(resource_t *rsc)
Definition: group.c:184
GHashTable * attrs
Definition: pe_types.h:204
gboolean safe_str_neq(const char *a, const char *b)
Definition: strings.c:157
#define INFINITY
Definition: crm.h:73
gboolean is_parent(pe_resource_t *child, pe_resource_t *rsc)
Definition: complex.c:729
gboolean get_target_role(resource_t *rsc, enum rsc_role_e *role)
Definition: utils.c:1740
GListPtr dangling_migrations
Definition: pe_types.h:341
#define XML_CIB_TAG_CONTAINER
Definition: msg_xml.h:178
pe_node_t * pe__find_active_on(const pe_resource_t *rsc, unsigned int *count_all, unsigned int *count_clean)
Definition: complex.c:842
pe_node_t * partial_migration_source
Definition: pe_types.h:328
#define XML_ATTR_TYPE
Definition: msg_xml.h:99
#define pe_rsc_runnable
Definition: pe_types.h:235
#define XML_TAG_UTILIZATION
Definition: msg_xml.h:171
#define RSC_ROLE_STARTED_S
Definition: common.h:98
void pe__free_bundle(pe_resource_t *rsc)
Definition: bundle.c:1623
#define crm_config_err(fmt...)
Definition: crm_internal.h:179
#define pe_flag_symmetric_cluster
Definition: pe_types.h:88
enum rsc_role_e pe__bundle_resource_state(const pe_resource_t *rsc, gboolean current)
Definition: bundle.c:1657
GListPtr rsc_tickets
Definition: pe_types.h:323
xmlNode * xml
Definition: pe_types.h:286
#define XML_RSC_ATTR_INCARNATION
Definition: msg_xml.h:186
#define pe_flag_maintenance_mode
Definition: pe_types.h:89
char * native_parameter(resource_t *rsc, node_t *node, gboolean create, const char *name, pe_working_set_t *data_set)
Definition: native.c:267
int char2score(const char *score)
Definition: utils.c:199
pe_node_t * native_location(const pe_resource_t *rsc, GList **list, int current)
Definition: native.c:800
long long crm_get_msec(const char *input)
Definition: utils.c:567
GHashTable * meta
Definition: pe_types.h:336
#define pe_rsc_unique
Definition: pe_types.h:223
xmlNode * find_entity(xmlNode *parent, const char *node_name, const char *id)
Definition: xml.c:1743
#define pe_rsc_notify
Definition: pe_types.h:222
gboolean common_unpack(xmlNode *xml_obj, resource_t **rsc, resource_t *parent, pe_working_set_t *data_set)
Definition: complex.c:360
void common_update_score(resource_t *rsc, const char *id, int score)
Definition: complex.c:707
void common_free(resource_t *rsc)
Definition: complex.c:760
GHashTable * parameters
Definition: pe_types.h:337
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
Definition: nvpair.c:275
int crm_parse_int(const char *text, const char *default_text)
Parse an integer value from a string.
Definition: strings.c:110
GListPtr fillers
Definition: pe_types.h:344
#define XML_CIB_TAG_RSC_TEMPLATE
Definition: msg_xml.h:180
#define XML_RSC_ATTR_STICKINESS
Definition: msg_xml.h:199
#define clear_bit(word, bit)
Definition: crm_internal.h:168
guint crm_parse_interval_spec(const char *input)
Definition: utils.c:542
GListPtr rsc_cons
Definition: pe_types.h:320
pe_node_t * allocated_to
Definition: pe_types.h:326
void native_print(resource_t *rsc, const char *pre_text, long options, void *print_data)
Definition: native.c:750
void pe__print_bundle(pe_resource_t *rsc, const char *pre_text, long options, void *print_data)
Definition: bundle.c:1521
resource_t * native_find_rsc(resource_t *rsc, const char *id, const node_t *node, int flags)
Definition: native.c:212
char * pending_task
Definition: pe_types.h:309
xmlNode * get_xpath_object(const char *xpath, xmlNode *xml_obj, int error_level)
Definition: xpath.c:220
gboolean pe__unpack_bundle(pe_resource_t *rsc, pe_working_set_t *data_set)
Definition: bundle.c:1024
void clone_free(resource_t *rsc)
Definition: clone.c:571
enum rsc_role_e group_resource_state(const resource_t *rsc, gboolean current)
Definition: group.c:205
#define XML_CIB_ATTR_PRIORITY
Definition: msg_xml.h:235
xmlNode * copy_xml(xmlNode *src_node)
Definition: xml.c:2020
#define pe_rsc_provisional
Definition: pe_types.h:227
#define XML_TAG_ATTR_SETS
Definition: msg_xml.h:163
#define XML_CIB_TAG_RESOURCES
Definition: msg_xml.h:140
#define XML_RSC_ATTR_PROMOTABLE
Definition: msg_xml.h:190
const char * role2text(enum rsc_role_e role)
Definition: common.c:329
int weight
Definition: pe_types.h:210
#define set_bit(word, bit)
Definition: crm_internal.h:167
#define XML_RSC_ATTR_REQUIRES
Definition: msg_xml.h:203
#define PCMK_RESOURCE_CLASS_OCF
Definition: services.h:43
#define pe_rsc_allow_migrate
Definition: pe_types.h:240
pe_resource_t * uber_parent(pe_resource_t *rsc)
Definition: complex.c:746
#define XML_RSC_ATTR_CONTAINER
Definition: msg_xml.h:205
#define XML_ATTR_ID
Definition: msg_xml.h:96
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
Definition: nvpair.c:423
#define XML_CIB_TAG_RESOURCE
Definition: msg_xml.h:174
#define XML_BOOLEAN_TRUE
Definition: msg_xml.h:107
xmlNode * rsc_defaults
Definition: pe_types.h:143
const char * crm_xml_replace(xmlNode *node, const char *name, const char *value)
Replace an XML attribute with specified name and (possibly NULL) value.
Definition: nvpair.c:332
xmlNode * add_node_copy(xmlNode *new_parent, xmlNode *xml_node)
Definition: xml.c:1868
struct pe_node_shared_s * details
Definition: pe_types.h:213
GListPtr running_on
Definition: pe_types.h:329
xmlNode * expand_idref(xmlNode *input, xmlNode *top)
Definition: xml.c:4227
#define XML_AGENT_ATTR_PROVIDER
Definition: msg_xml.h:230
#define pe_rsc_needs_fencing
Definition: pe_types.h:247
unsigned long long flags
Definition: pe_types.h:311
#define pe_rsc_promotable
Definition: pe_types.h:225
#define XML_TAG_META_SETS
Definition: msg_xml.h:164
char * clone_name
Definition: pe_types.h:285
gboolean add_tag_ref(GHashTable *tags, const char *tag_name, const char *obj_ref)
Definition: utils.c:2309
#define XML_RSC_ATTR_MANAGED
Definition: msg_xml.h:195
xmlNode * create_xml_node(xmlNode *parent, const char *name)
Definition: xml.c:1890
#define pe_flag_stonith_enabled
Definition: pe_types.h:91
enum rsc_role_e native_resource_state(const resource_t *rsc, gboolean current)
Definition: native.c:778
void group_print(resource_t *rsc, const char *pre_text, long options, void *print_data)
Definition: group.c:135
GHashTable * utilization
Definition: pe_types.h:338
GListPtr rsc_cons_lhs
Definition: pe_types.h:319
gboolean native_active(resource_t *rsc, gboolean all)
Definition: native.c:312
#define XML_TAG_RSC_VER_ATTRS
Definition: msg_xml.h:166
void free_xml(xmlNode *child)
Definition: xml.c:2014
enum pe_obj_types variant
Definition: pe_types.h:293
gboolean xml_has_children(const xmlNode *root)
Definition: xml.c:3206
xmlNode * input
Definition: pe_types.h:113
gboolean crm_str_eq(const char *a, const char *b, gboolean use_case)
Definition: strings.c:220
#define XML_REMOTE_ATTR_RECONNECT_INTERVAL
Definition: msg_xml.h:215
#define XML_RSC_ATTR_NOTIFY
Definition: msg_xml.h:198
GListPtr actions
Definition: pe_types.h:322
#define XML_RSC_ATTR_FAIL_STICKINESS
Definition: msg_xml.h:200
GListPtr rsc_location
Definition: pe_types.h:321
resource_object_functions_t resource_class_functions[]
Definition: complex.c:20
enum rsc_role_e clone_resource_state(const resource_t *rsc, gboolean current)
Definition: clone.c:605
void populate_hash(xmlNode *nvpair_list, GHashTable *hash, const char **attrs, int attrs_length)
#define pe_rsc_fence_device
Definition: pe_types.h:224
#define XML_RSC_ATTR_UNIQUE
Definition: msg_xml.h:197
#define crm_config_warn(fmt...)
Definition: crm_internal.h:180
#define PCMK_RESOURCE_CLASS_STONITH
Definition: services.h:49
int crm_str_to_boolean(const char *s, int *ret)
Definition: strings.c:183
gboolean clone_active(resource_t *rsc, gboolean all)
Definition: clone.c:235
void get_rsc_attributes(GHashTable *meta_hash, pe_resource_t *rsc, pe_node_t *node, pe_working_set_t *data_set)
Definition: complex.c:127
gboolean xml_contains_remote_node(xmlNode *xml)
Definition: remote.c:92
#define XML_CIB_TAG_INCARNATION
Definition: msg_xml.h:176
#define XML_RSC_ATTR_MAINTENANCE
Definition: msg_xml.h:207
#define XML_RSC_ATTR_FAIL_TIMEOUT
Definition: msg_xml.h:201
GListPtr children
Definition: pe_types.h:340
void add_hash_param(GHashTable *hash, const char *name, const char *value)
Definition: common.c:406
void * variant_opaque
Definition: pe_types.h:294
void resource_location(resource_t *rsc, node_t *node, int score, const char *tag, pe_working_set_t *data_set)
Definition: utils.c:1565
gboolean group_active(resource_t *rsc, gboolean all)
Definition: group.c:90
#define RSC_ROLE_SLAVE_S
Definition: common.h:99
int merge_weights(int w1, int w2)
Definition: common.c:369
#define pe_rsc_needs_unfencing
Definition: pe_types.h:248
#define crm_str_hash
Definition: util.h:60
#define XML_RSC_ATTR_MULTIPLE
Definition: msg_xml.h:202
#define pe_rsc_maintenance
Definition: pe_types.h:243
#define XML_RSC_ATTR_RESTART
Definition: msg_xml.h:183
#define XML_CIB_TAG_MASTER
Definition: msg_xml.h:177
void native_free(resource_t *rsc)
Definition: native.c:771
gboolean native_unpack(resource_t *rsc, pe_working_set_t *data_set)
Definition: native.c:143
#define RSC_ROLE_UNKNOWN_S
Definition: common.h:96
void unpack_instance_attributes(xmlNode *top, xmlNode *xml_obj, const char *set_name, GHashTable *node_hash, GHashTable *hash, const char *always_first, gboolean overwrite, crm_time_t *now)
Definition: rules.c:904
#define pe_rsc_needs_quorum
Definition: pe_types.h:246
#define crm_log_xml_trace(xml, text)
Definition: logging.h:254
gboolean crm_is_true(const char *s)
Definition: strings.c:172
#define pe_flag_have_stonith_resource
Definition: pe_types.h:92
#define XML_CIB_TAG_GROUP
Definition: msg_xml.h:175
#define pe_flag_enable_unfencing
Definition: pe_types.h:93
#define pe_rsc_trace(rsc, fmt, args...)
Definition: internal.h:18
pe_node_t * pe__find_active_requires(const pe_resource_t *rsc, unsigned int *count)
Definition: complex.c:922
unsigned long long flags
Definition: pe_types.h:122
#define ID(x)
Definition: msg_xml.h:414
#define pe_err(fmt...)
Definition: internal.h:20
#define safe_str_eq(a, b)
Definition: util.h:59
gboolean group_unpack(resource_t *rsc, pe_working_set_t *data_set)
Definition: group.c:20
gboolean unclean
Definition: pe_types.h:187
GList * GListPtr
Definition: crm.h:192
crm_time_t * now
Definition: pe_types.h:114
#define pe_rsc_managed
Definition: pe_types.h:218
#define pe_rsc_orphan
Definition: pe_types.h:217
GHashTable * template_rsc_sets
Definition: pe_types.h:154
gboolean online
Definition: pe_types.h:183
#define XML_OP_ATTR_ALLOW_MIGRATE
Definition: msg_xml.h:219
pe_resource_t * parent
Definition: pe_types.h:291
pe_obj_types
Definition: pe_types.h:34
#define pe_warn_once(pe_wo_bit, fmt...)
Definition: unpack.h:97
gboolean clone_unpack(resource_t *rsc, pe_working_set_t *data_set)
Definition: clone.c:111
gboolean pe__bundle_active(pe_resource_t *rsc, gboolean all)
Definition: bundle.c:1356
#define XML_AGENT_ATTR_CLASS
Definition: msg_xml.h:229
char * id
Definition: pe_types.h:284
GHashTable * allowed_nodes
Definition: pe_types.h:331