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