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