pacemaker  1.1.18-1a4ef7d180
Scalable High-Availability cluster resource manager
unpack.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2004 Andrew Beekhof <andrew@beekhof.net>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 #include <crm_internal.h>
19 
20 #include <glib.h>
21 
22 #include <crm/crm.h>
23 #include <crm/services.h>
24 #include <crm/msg_xml.h>
25 #include <crm/common/xml.h>
26 
27 #include <crm/common/util.h>
28 #include <crm/pengine/rules.h>
29 #include <crm/pengine/internal.h>
30 #include <unpack.h>
31 
32 CRM_TRACE_INIT_DATA(pe_status);
33 
34 #define set_config_flag(data_set, option, flag) do { \
35  const char *tmp = pe_pref(data_set->config_hash, option); \
36  if(tmp) { \
37  if(crm_is_true(tmp)) { \
38  set_bit(data_set->flags, flag); \
39  } else { \
40  clear_bit(data_set->flags, flag); \
41  } \
42  } \
43  } while(0)
44 
45 gboolean unpack_rsc_op(resource_t * rsc, node_t * node, xmlNode * xml_op, xmlNode ** last_failure,
46  enum action_fail_response *failed, pe_working_set_t * data_set);
47 static gboolean determine_remote_online_status(pe_working_set_t * data_set, node_t * this_node);
48 
49 // Bitmask for warnings we only want to print once
51 
52 static gboolean
53 is_dangling_container_remote_node(node_t *node)
54 {
55  /* we are looking for a remote-node that was supposed to be mapped to a
56  * container resource, but all traces of that container have disappeared
57  * from both the config and the status section. */
58  if (is_remote_node(node) &&
59  node->details->remote_rsc &&
60  node->details->remote_rsc->container == NULL &&
62  return TRUE;
63  }
64 
65  return FALSE;
66 }
67 
68 
76 void
77 pe_fence_node(pe_working_set_t * data_set, node_t * node, const char *reason)
78 {
79  CRM_CHECK(node, return);
80 
81  /* A guest node is fenced by marking its container as failed */
82  if (is_container_remote_node(node)) {
83  resource_t *rsc = node->details->remote_rsc->container;
84 
85  if (is_set(rsc->flags, pe_rsc_failed) == FALSE) {
86  if (!is_set(rsc->flags, pe_rsc_managed)) {
87  crm_notice("Not fencing guest node %s "
88  "(otherwise would because %s): "
89  "its guest resource %s is unmanaged",
90  node->details->uname, reason, rsc->id);
91  } else {
92  crm_warn("Guest node %s will be fenced "
93  "(by recovering its guest resource %s): %s",
94  node->details->uname, rsc->id, reason);
95 
96  /* We don't mark the node as unclean because that would prevent the
97  * node from running resources. We want to allow it to run resources
98  * in this transition if the recovery succeeds.
99  */
100  node->details->remote_requires_reset = TRUE;
101  set_bit(rsc->flags, pe_rsc_failed);
102  }
103  }
104 
105  } else if (is_dangling_container_remote_node(node)) {
106  crm_info("Cleaning up dangling connection for guest node %s: "
107  "fencing was already done because %s, "
108  "and guest resource no longer exists",
109  node->details->uname, reason);
111 
112  } else if (is_baremetal_remote_node(node)) {
113  resource_t *rsc = node->details->remote_rsc;
114 
115  if (rsc && (!is_set(rsc->flags, pe_rsc_managed))) {
116  crm_notice("Not fencing remote node %s "
117  "(otherwise would because %s): connection is unmanaged",
118  node->details->uname, reason);
119  } else if(node->details->remote_requires_reset == FALSE) {
120  node->details->remote_requires_reset = TRUE;
121  crm_warn("Remote node %s %s: %s",
122  node->details->uname,
123  pe_can_fence(data_set, node)? "will be fenced" : "is unclean",
124  reason);
125  }
126  node->details->unclean = TRUE;
127  pe_fence_op(node, NULL, TRUE, reason, data_set);
128 
129  } else if (node->details->unclean) {
130  crm_trace("Cluster node %s %s because %s",
131  node->details->uname,
132  pe_can_fence(data_set, node)? "would also be fenced" : "also is unclean",
133  reason);
134 
135  } else {
136  crm_warn("Cluster node %s %s: %s",
137  node->details->uname,
138  pe_can_fence(data_set, node)? "will be fenced" : "is unclean",
139  reason);
140  node->details->unclean = TRUE;
141  pe_fence_op(node, NULL, TRUE, reason, data_set);
142  }
143 }
144 
145 // @TODO xpaths can't handle templates, rules, or id-refs
146 
147 // nvpair with provides or requires set to unfencing
148 #define XPATH_UNFENCING_NVPAIR XML_CIB_TAG_NVPAIR \
149  "[(@" XML_NVPAIR_ATTR_NAME "='" XML_RSC_ATTR_PROVIDES "'" \
150  "or @" XML_NVPAIR_ATTR_NAME "='" XML_RSC_ATTR_REQUIRES "') " \
151  "and @" XML_NVPAIR_ATTR_VALUE "='unfencing']"
152 
153 // unfencing in rsc_defaults or any resource
154 #define XPATH_ENABLE_UNFENCING \
155  "/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_RESOURCES \
156  "//" XML_TAG_META_SETS "/" XPATH_UNFENCING_NVPAIR \
157  "|/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_RSCCONFIG \
158  "/" XML_TAG_META_SETS "/" XPATH_UNFENCING_NVPAIR
159 
160 static
161 void set_if_xpath(unsigned long long flag, const char *xpath,
162  pe_working_set_t *data_set)
163 {
164  xmlXPathObjectPtr result = NULL;
165 
166  if (is_not_set(data_set->flags, flag)) {
167  result = xpath_search(data_set->input, xpath);
168  if (result && (numXpathResults(result) > 0)) {
169  set_bit(data_set->flags, flag);
170  }
171  freeXpathObject(result);
172  }
173 }
174 
175 gboolean
176 unpack_config(xmlNode * config, pe_working_set_t * data_set)
177 {
178  const char *value = NULL;
179  GHashTable *config_hash = crm_str_table_new();
180 
181  data_set->config_hash = config_hash;
182 
183  unpack_instance_attributes(data_set->input, config, XML_CIB_TAG_PROPSET, NULL, config_hash,
184  CIB_OPTIONS_FIRST, FALSE, data_set->now);
185 
186  verify_pe_options(data_set->config_hash);
187 
188  set_config_flag(data_set, "enable-startup-probes", pe_flag_startup_probes);
189  if(is_not_set(data_set->flags, pe_flag_startup_probes)) {
190  crm_info("Startup probes: disabled (dangerous)");
191  }
192 
193  value = pe_pref(data_set->config_hash, XML_ATTR_HAVE_WATCHDOG);
194  if (value && crm_is_true(value)) {
195  crm_notice("Watchdog will be used via SBD if fencing is required");
197  }
198 
199  /* Set certain flags via xpath here, so they can be used before the relevant
200  * configuration sections are unpacked.
201  */
202  set_if_xpath(pe_flag_enable_unfencing, XPATH_ENABLE_UNFENCING, data_set);
203 
204  value = pe_pref(data_set->config_hash, "stonith-timeout");
205  data_set->stonith_timeout = crm_get_msec(value);
206  crm_debug("STONITH timeout: %d", data_set->stonith_timeout);
207 
208  set_config_flag(data_set, "stonith-enabled", pe_flag_stonith_enabled);
209  crm_debug("STONITH of failed nodes is %s",
210  is_set(data_set->flags, pe_flag_stonith_enabled) ? "enabled" : "disabled");
211 
212  data_set->stonith_action = pe_pref(data_set->config_hash, "stonith-action");
213  crm_trace("STONITH will %s nodes", data_set->stonith_action);
214 
215  set_config_flag(data_set, "concurrent-fencing", pe_flag_concurrent_fencing);
216  crm_debug("Concurrent fencing is %s",
217  is_set(data_set->flags, pe_flag_concurrent_fencing) ? "enabled" : "disabled");
218 
219  set_config_flag(data_set, "stop-all-resources", pe_flag_stop_everything);
220  crm_debug("Stop all active resources: %s",
221  is_set(data_set->flags, pe_flag_stop_everything) ? "true" : "false");
222 
223  set_config_flag(data_set, "symmetric-cluster", pe_flag_symmetric_cluster);
224  if (is_set(data_set->flags, pe_flag_symmetric_cluster)) {
225  crm_debug("Cluster is symmetric" " - resources can run anywhere by default");
226  }
227 
228  value = pe_pref(data_set->config_hash, "default-resource-stickiness");
229  if (value) {
231  "Support for 'default-resource-stickiness' cluster property"
232  " is deprecated and will be removed in a future release"
233  " (use resource-stickiness in rsc_defaults instead)");
234  }
235  data_set->default_resource_stickiness = char2score(value);
236  crm_debug("Default stickiness: %d", data_set->default_resource_stickiness);
237 
238  value = pe_pref(data_set->config_hash, "no-quorum-policy");
239 
240  if (safe_str_eq(value, "ignore")) {
242 
243  } else if (safe_str_eq(value, "freeze")) {
245 
246  } else if (safe_str_eq(value, "suicide")) {
247  if (is_set(data_set->flags, pe_flag_stonith_enabled)) {
248  int do_panic = 0;
249 
251  &do_panic);
252  if (do_panic || is_set(data_set->flags, pe_flag_have_quorum)) {
254  } else {
255  crm_notice("Resetting no-quorum-policy to 'stop': cluster has never had quorum");
256  data_set->no_quorum_policy = no_quorum_stop;
257  }
258  } else {
259  crm_config_err("Resetting no-quorum-policy to 'stop': stonith is not configured");
260  data_set->no_quorum_policy = no_quorum_stop;
261  }
262 
263  } else {
264  data_set->no_quorum_policy = no_quorum_stop;
265  }
266 
267  switch (data_set->no_quorum_policy) {
268  case no_quorum_freeze:
269  crm_debug("On loss of CCM Quorum: Freeze resources");
270  break;
271  case no_quorum_stop:
272  crm_debug("On loss of CCM Quorum: Stop ALL resources");
273  break;
274  case no_quorum_suicide:
275  crm_notice("On loss of CCM Quorum: Fence all remaining nodes");
276  break;
277  case no_quorum_ignore:
278  crm_notice("On loss of CCM Quorum: Ignore");
279  break;
280  }
281 
282  set_config_flag(data_set, "stop-orphan-resources", pe_flag_stop_rsc_orphans);
283  crm_trace("Orphan resources are %s",
284  is_set(data_set->flags, pe_flag_stop_rsc_orphans) ? "stopped" : "ignored");
285 
286  set_config_flag(data_set, "stop-orphan-actions", pe_flag_stop_action_orphans);
287  crm_trace("Orphan resource actions are %s",
288  is_set(data_set->flags, pe_flag_stop_action_orphans) ? "stopped" : "ignored");
289 
290  set_config_flag(data_set, "remove-after-stop", pe_flag_remove_after_stop);
291  crm_trace("Stopped resources are removed from the status section: %s",
292  is_set(data_set->flags, pe_flag_remove_after_stop) ? "true" : "false");
293 
294  set_config_flag(data_set, "maintenance-mode", pe_flag_maintenance_mode);
295  crm_trace("Maintenance mode: %s",
296  is_set(data_set->flags, pe_flag_maintenance_mode) ? "true" : "false");
297 
298  if (is_set(data_set->flags, pe_flag_maintenance_mode)) {
300  } else if (pe_pref(data_set->config_hash, "is-managed-default")) {
301  set_config_flag(data_set, "is-managed-default", pe_flag_is_managed_default);
303  "Support for 'is-managed-default' cluster property"
304  " is deprecated and will be removed in a future release"
305  " (use is-managed in rsc_defaults instead)");
306  }
307  crm_trace("By default resources are %smanaged",
308  is_set(data_set->flags, pe_flag_is_managed_default) ? "" : "not ");
309 
310  set_config_flag(data_set, "start-failure-is-fatal", pe_flag_start_failure_fatal);
311  crm_trace("Start failures are %s",
312  is_set(data_set->flags,
313  pe_flag_start_failure_fatal) ? "always fatal" : "handled by failcount");
314 
315  if (is_set(data_set->flags, pe_flag_stonith_enabled)) {
316  set_config_flag(data_set, "startup-fencing", pe_flag_startup_fencing);
317  }
318  if (is_set(data_set->flags, pe_flag_startup_fencing)) {
319  crm_trace("Unseen nodes will be fenced");
320  } else {
321  pe_warn_once(pe_wo_blind, "Blind faith: not fencing unseen nodes");
322  }
323 
324  node_score_red = char2score(pe_pref(data_set->config_hash, "node-health-red"));
325  node_score_green = char2score(pe_pref(data_set->config_hash, "node-health-green"));
326  node_score_yellow = char2score(pe_pref(data_set->config_hash, "node-health-yellow"));
327 
328  crm_debug("Node scores: 'red' = %s, 'yellow' = %s, 'green' = %s",
329  pe_pref(data_set->config_hash, "node-health-red"),
330  pe_pref(data_set->config_hash, "node-health-yellow"),
331  pe_pref(data_set->config_hash, "node-health-green"));
332 
333  data_set->placement_strategy = pe_pref(data_set->config_hash, "placement-strategy");
334  crm_trace("Placement strategy: %s", data_set->placement_strategy);
335 
336  return TRUE;
337 }
338 
339 static void
340 destroy_digest_cache(gpointer ptr)
341 {
342  op_digest_cache_t *data = ptr;
343 
344  free_xml(data->params_all);
345  free_xml(data->params_secure);
346  free_xml(data->params_restart);
347 
348  free(data->digest_all_calc);
349  free(data->digest_restart_calc);
350  free(data->digest_secure_calc);
351 
352  free(data);
353 }
354 
355 node_t *
356 pe_create_node(const char *id, const char *uname, const char *type,
357  const char *score, pe_working_set_t * data_set)
358 {
359  node_t *new_node = NULL;
360 
361  if (pe_find_node(data_set->nodes, uname) != NULL) {
362  crm_config_warn("Detected multiple node entries with uname=%s"
363  " - this is rarely intended", uname);
364  }
365 
366  new_node = calloc(1, sizeof(node_t));
367  if (new_node == NULL) {
368  return NULL;
369  }
370 
371  new_node->weight = char2score(score);
372  new_node->fixed = FALSE;
373  new_node->details = calloc(1, sizeof(struct node_shared_s));
374 
375  if (new_node->details == NULL) {
376  free(new_node);
377  return NULL;
378  }
379 
380  crm_trace("Creating node for entry %s/%s", uname, id);
381  new_node->details->id = id;
382  new_node->details->uname = uname;
383  new_node->details->online = FALSE;
384  new_node->details->shutdown = FALSE;
385  new_node->details->rsc_discovery_enabled = TRUE;
386  new_node->details->running_rsc = NULL;
387  new_node->details->type = node_ping;
388 
389  if (safe_str_eq(type, "remote")) {
390  new_node->details->type = node_remote;
392  } else if (type == NULL || safe_str_eq(type, "member")
393  || safe_str_eq(type, NORMALNODE)) {
394  new_node->details->type = node_member;
395  }
396 
397  new_node->details->attrs = crm_str_table_new();
398 
399  if (is_remote_node(new_node)) {
400  g_hash_table_insert(new_node->details->attrs, strdup(CRM_ATTR_KIND),
401  strdup("remote"));
402  } else {
403  g_hash_table_insert(new_node->details->attrs, strdup(CRM_ATTR_KIND),
404  strdup("cluster"));
405  }
406 
407  new_node->details->utilization = crm_str_table_new();
408 
409  new_node->details->digest_cache =
410  g_hash_table_new_full(crm_str_hash, g_str_equal, g_hash_destroy_str,
411  destroy_digest_cache);
412 
413  data_set->nodes = g_list_insert_sorted(data_set->nodes, new_node, sort_node_uname);
414  return new_node;
415 }
416 
417 bool
418 remote_id_conflict(const char *remote_name, pe_working_set_t *data)
419 {
420  bool match = FALSE;
421 #if 1
422  pe_find_resource(data->resources, remote_name);
423 #else
424  if (data->name_check == NULL) {
425  data->name_check = g_hash_table_new(crm_str_hash, g_str_equal);
426  for (xml_rsc = __xml_first_child(parent); xml_rsc != NULL; xml_rsc = __xml_next_element(xml_rsc)) {
427  const char *id = ID(xml_rsc);
428 
429  /* avoiding heap allocation here because we know the duration of this hashtable allows us to */
430  g_hash_table_insert(data->name_check, (char *) id, (char *) id);
431  }
432  }
433  if (g_hash_table_lookup(data->name_check, remote_name)) {
434  match = TRUE;
435  }
436 #endif
437  if (match) {
438  crm_err("Invalid remote-node name, a resource called '%s' already exists.", remote_name);
439  return NULL;
440  }
441 
442  return match;
443 }
444 
445 
446 static const char *
447 expand_remote_rsc_meta(xmlNode *xml_obj, xmlNode *parent, pe_working_set_t *data)
448 {
449  xmlNode *attr_set = NULL;
450  xmlNode *attr = NULL;
451 
452  const char *container_id = ID(xml_obj);
453  const char *remote_name = NULL;
454  const char *remote_server = NULL;
455  const char *remote_port = NULL;
456  const char *connect_timeout = "60s";
457  const char *remote_allow_migrate=NULL;
458  const char *container_managed = NULL;
459 
460  for (attr_set = __xml_first_child(xml_obj); attr_set != NULL; attr_set = __xml_next_element(attr_set)) {
461  if (safe_str_neq((const char *)attr_set->name, XML_TAG_META_SETS)) {
462  continue;
463  }
464 
465  for (attr = __xml_first_child(attr_set); attr != NULL; attr = __xml_next_element(attr)) {
466  const char *value = crm_element_value(attr, XML_NVPAIR_ATTR_VALUE);
467  const char *name = crm_element_value(attr, XML_NVPAIR_ATTR_NAME);
468 
470  remote_name = value;
471  } else if (safe_str_eq(name, "remote-addr")) {
472  remote_server = value;
473  } else if (safe_str_eq(name, "remote-port")) {
474  remote_port = value;
475  } else if (safe_str_eq(name, "remote-connect-timeout")) {
476  connect_timeout = value;
477  } else if (safe_str_eq(name, "remote-allow-migrate")) {
478  remote_allow_migrate=value;
479  } else if (safe_str_eq(name, XML_RSC_ATTR_MANAGED)) {
480  container_managed = value;
481  }
482  }
483  }
484 
485  if (remote_name == NULL) {
486  return NULL;
487  }
488 
489  if (remote_id_conflict(remote_name, data)) {
490  return NULL;
491  }
492 
493  pe_create_remote_xml(parent, remote_name, container_id,
494  remote_allow_migrate, container_managed, "30s", "30s",
495  connect_timeout, remote_server, remote_port);
496  return remote_name;
497 }
498 
499 static void
500 handle_startup_fencing(pe_working_set_t *data_set, node_t *new_node)
501 {
502  if ((new_node->details->type == node_remote) && (new_node->details->remote_rsc == NULL)) {
503  /* Ignore fencing for remote nodes that don't have a connection resource
504  * associated with them. This happens when remote node entries get left
505  * in the nodes section after the connection resource is removed.
506  */
507  return;
508  }
509 
510  if (is_set(data_set->flags, pe_flag_startup_fencing)) {
511  // All nodes are unclean until we've seen their status entry
512  new_node->details->unclean = TRUE;
513 
514  } else {
515  // Blind faith ...
516  new_node->details->unclean = FALSE;
517  }
518 
519  /* We need to be able to determine if a node's status section
520  * exists or not separate from whether the node is unclean. */
521  new_node->details->unseen = TRUE;
522 }
523 
524 gboolean
525 unpack_nodes(xmlNode * xml_nodes, pe_working_set_t * data_set)
526 {
527  xmlNode *xml_obj = NULL;
528  node_t *new_node = NULL;
529  const char *id = NULL;
530  const char *uname = NULL;
531  const char *type = NULL;
532  const char *score = NULL;
533 
534  for (xml_obj = __xml_first_child(xml_nodes); xml_obj != NULL; xml_obj = __xml_next_element(xml_obj)) {
535  if (crm_str_eq((const char *)xml_obj->name, XML_CIB_TAG_NODE, TRUE)) {
536  new_node = NULL;
537 
538  id = crm_element_value(xml_obj, XML_ATTR_ID);
539  uname = crm_element_value(xml_obj, XML_ATTR_UNAME);
540  type = crm_element_value(xml_obj, XML_ATTR_TYPE);
541  score = crm_element_value(xml_obj, XML_RULE_ATTR_SCORE);
542  crm_trace("Processing node %s/%s", uname, id);
543 
544  if (id == NULL) {
545  crm_config_err("Must specify id tag in <node>");
546  continue;
547  }
548  new_node = pe_create_node(id, uname, type, score, data_set);
549 
550  if (new_node == NULL) {
551  return FALSE;
552  }
553 
554 /* if(data_set->have_quorum == FALSE */
555 /* && data_set->no_quorum_policy == no_quorum_stop) { */
556 /* /\* start shutting resources down *\/ */
557 /* new_node->weight = -INFINITY; */
558 /* } */
559 
560  handle_startup_fencing(data_set, new_node);
561 
562  add_node_attrs(xml_obj, new_node, FALSE, data_set);
563  unpack_instance_attributes(data_set->input, xml_obj, XML_TAG_UTILIZATION, NULL,
564  new_node->details->utilization, NULL, FALSE, data_set->now);
565 
566  crm_trace("Done with node %s", crm_element_value(xml_obj, XML_ATTR_UNAME));
567  }
568  }
569 
570  if (data_set->localhost && pe_find_node(data_set->nodes, data_set->localhost) == NULL) {
571  crm_info("Creating a fake local node");
572  pe_create_node(data_set->localhost, data_set->localhost, NULL, 0,
573  data_set);
574  }
575 
576  return TRUE;
577 }
578 
579 static void
580 setup_container(resource_t * rsc, pe_working_set_t * data_set)
581 {
582  const char *container_id = NULL;
583 
584  if (rsc->children) {
585  GListPtr gIter = rsc->children;
586 
587  for (; gIter != NULL; gIter = gIter->next) {
588  resource_t *child_rsc = (resource_t *) gIter->data;
589 
590  setup_container(child_rsc, data_set);
591  }
592  return;
593  }
594 
595  container_id = g_hash_table_lookup(rsc->meta, XML_RSC_ATTR_CONTAINER);
596  if (container_id && safe_str_neq(container_id, rsc->id)) {
597  resource_t *container = pe_find_resource(data_set->resources, container_id);
598 
599  if (container) {
600  rsc->container = container;
601  set_bit(container->flags, pe_rsc_is_container);
602  container->fillers = g_list_append(container->fillers, rsc);
603  pe_rsc_trace(rsc, "Resource %s's container is %s", rsc->id, container_id);
604  } else {
605  pe_err("Resource %s: Unknown resource container (%s)", rsc->id, container_id);
606  }
607  }
608 }
609 
610 gboolean
611 unpack_remote_nodes(xmlNode * xml_resources, pe_working_set_t * data_set)
612 {
613  xmlNode *xml_obj = NULL;
614 
615  /* generate remote nodes from resource config before unpacking resources */
616  for (xml_obj = __xml_first_child(xml_resources); xml_obj != NULL; xml_obj = __xml_next_element(xml_obj)) {
617  const char *new_node_id = NULL;
618 
619  /* first check if this is a bare metal remote node. Bare metal remote nodes
620  * are defined as a resource primitive only. */
621  if (xml_contains_remote_node(xml_obj)) {
622  new_node_id = ID(xml_obj);
623  /* The "pe_find_node" check is here to make sure we don't iterate over
624  * an expanded node that has already been added to the node list. */
625  if (new_node_id && pe_find_node(data_set->nodes, new_node_id) == NULL) {
626  crm_trace("Found baremetal remote node %s in container resource %s", new_node_id, ID(xml_obj));
627  pe_create_node(new_node_id, new_node_id, "remote", NULL,
628  data_set);
629  }
630  continue;
631  }
632 
633  /* Now check for guest remote nodes.
634  * guest remote nodes are defined within a resource primitive.
635  * Example1: a vm resource might be configured as a remote node.
636  * Example2: a vm resource might be configured within a group to be a remote node.
637  * Note: right now we only support guest remote nodes in as a standalone primitive
638  * or a primitive within a group. No cloned primitives can be a guest remote node
639  * right now */
640  if (crm_str_eq((const char *)xml_obj->name, XML_CIB_TAG_RESOURCE, TRUE)) {
641  /* expands a metadata defined remote resource into the xml config
642  * as an actual rsc primitive to be unpacked later. */
643  new_node_id = expand_remote_rsc_meta(xml_obj, xml_resources, data_set);
644 
645  if (new_node_id && pe_find_node(data_set->nodes, new_node_id) == NULL) {
646  crm_trace("Found guest remote node %s in container resource %s", new_node_id, ID(xml_obj));
647  pe_create_node(new_node_id, new_node_id, "remote", NULL,
648  data_set);
649  }
650  continue;
651 
652  } else if (crm_str_eq((const char *)xml_obj->name, XML_CIB_TAG_GROUP, TRUE)) {
653  xmlNode *xml_obj2 = NULL;
654  /* search through a group to see if any of the primitive contain a remote node. */
655  for (xml_obj2 = __xml_first_child(xml_obj); xml_obj2 != NULL; xml_obj2 = __xml_next_element(xml_obj2)) {
656 
657  new_node_id = expand_remote_rsc_meta(xml_obj2, xml_resources, data_set);
658 
659  if (new_node_id && pe_find_node(data_set->nodes, new_node_id) == NULL) {
660  crm_trace("Found guest remote node %s in container resource %s which is in group %s", new_node_id, ID(xml_obj2), ID(xml_obj));
661  pe_create_node(new_node_id, new_node_id, "remote", NULL,
662  data_set);
663  }
664  }
665  }
666  }
667  return TRUE;
668 }
669 
670 
671 /* Call this after all the nodes and resources have been
672  * unpacked, but before the status section is read.
673  *
674  * A remote node's online status is reflected by the state
675  * of the remote node's connection resource. We need to link
676  * the remote node to this connection resource so we can have
677  * easy access to the connection resource during the PE calculations.
678  */
679 static void
680 link_rsc2remotenode(pe_working_set_t *data_set, resource_t *new_rsc)
681 {
682  node_t *remote_node = NULL;
683 
684  if (new_rsc->is_remote_node == FALSE) {
685  return;
686  }
687 
688  if (is_set(data_set->flags, pe_flag_quick_location)) {
689  /* remote_nodes and remote_resources are not linked in quick location calculations */
690  return;
691  }
692 
693  print_resource(LOG_DEBUG_3, "Linking remote-node connection resource, ", new_rsc, FALSE);
694 
695  remote_node = pe_find_node(data_set->nodes, new_rsc->id);
696  CRM_CHECK(remote_node != NULL, return;);
697 
698  remote_node->details->remote_rsc = new_rsc;
699  /* If this is a baremetal remote-node (no container resource
700  * associated with it) then we need to handle startup fencing the same way
701  * as cluster nodes. */
702  if (new_rsc->container == NULL) {
703  handle_startup_fencing(data_set, remote_node);
704  } else {
705  /* At this point we know if the remote node is a container or baremetal
706  * remote node, update the #kind attribute if a container is involved */
707  g_hash_table_replace(remote_node->details->attrs, strdup(CRM_ATTR_KIND),
708  strdup("container"));
709  }
710 }
711 
712 static void
713 destroy_tag(gpointer data)
714 {
715  tag_t *tag = data;
716 
717  if (tag) {
718  free(tag->id);
719  g_list_free_full(tag->refs, free);
720  free(tag);
721  }
722 }
723 
736 gboolean
737 unpack_resources(xmlNode * xml_resources, pe_working_set_t * data_set)
738 {
739  xmlNode *xml_obj = NULL;
740  GListPtr gIter = NULL;
741 
742  data_set->template_rsc_sets =
743  g_hash_table_new_full(crm_str_hash, g_str_equal, g_hash_destroy_str,
744  destroy_tag);
745 
746  for (xml_obj = __xml_first_child(xml_resources); xml_obj != NULL; xml_obj = __xml_next_element(xml_obj)) {
747  resource_t *new_rsc = NULL;
748 
749  if (crm_str_eq((const char *)xml_obj->name, XML_CIB_TAG_RSC_TEMPLATE, TRUE)) {
750  const char *template_id = ID(xml_obj);
751 
752  if (template_id && g_hash_table_lookup_extended(data_set->template_rsc_sets,
753  template_id, NULL, NULL) == FALSE) {
754  /* Record the template's ID for the knowledge of its existence anyway. */
755  g_hash_table_insert(data_set->template_rsc_sets, strdup(template_id), NULL);
756  }
757  continue;
758  }
759 
760  crm_trace("Beginning unpack... <%s id=%s... >", crm_element_name(xml_obj), ID(xml_obj));
761  if (common_unpack(xml_obj, &new_rsc, NULL, data_set)) {
762  data_set->resources = g_list_append(data_set->resources, new_rsc);
763  print_resource(LOG_DEBUG_3, "Added ", new_rsc, FALSE);
764 
765  } else {
766  crm_config_err("Failed unpacking %s %s",
767  crm_element_name(xml_obj), crm_element_value(xml_obj, XML_ATTR_ID));
768  if (new_rsc != NULL && new_rsc->fns != NULL) {
769  new_rsc->fns->free(new_rsc);
770  }
771  }
772  }
773 
774  for (gIter = data_set->resources; gIter != NULL; gIter = gIter->next) {
775  resource_t *rsc = (resource_t *) gIter->data;
776 
777  setup_container(rsc, data_set);
778  link_rsc2remotenode(data_set, rsc);
779  }
780 
781  data_set->resources = g_list_sort(data_set->resources, sort_rsc_priority);
782  if (is_set(data_set->flags, pe_flag_quick_location)) {
783  /* Ignore */
784 
785  } else if (is_set(data_set->flags, pe_flag_stonith_enabled)
786  && is_set(data_set->flags, pe_flag_have_stonith_resource) == FALSE) {
787 
788  crm_config_err("Resource start-up disabled since no STONITH resources have been defined");
789  crm_config_err("Either configure some or disable STONITH with the stonith-enabled option");
790  crm_config_err("NOTE: Clusters with shared data need STONITH to ensure data integrity");
791  }
792 
793  return TRUE;
794 }
795 
796 gboolean
797 unpack_tags(xmlNode * xml_tags, pe_working_set_t * data_set)
798 {
799  xmlNode *xml_tag = NULL;
800 
801  data_set->tags =
802  g_hash_table_new_full(crm_str_hash, g_str_equal, g_hash_destroy_str, destroy_tag);
803 
804  for (xml_tag = __xml_first_child(xml_tags); xml_tag != NULL; xml_tag = __xml_next_element(xml_tag)) {
805  xmlNode *xml_obj_ref = NULL;
806  const char *tag_id = ID(xml_tag);
807 
808  if (crm_str_eq((const char *)xml_tag->name, XML_CIB_TAG_TAG, TRUE) == FALSE) {
809  continue;
810  }
811 
812  if (tag_id == NULL) {
813  crm_config_err("Failed unpacking %s: %s should be specified",
814  crm_element_name(xml_tag), XML_ATTR_ID);
815  continue;
816  }
817 
818  for (xml_obj_ref = __xml_first_child(xml_tag); xml_obj_ref != NULL; xml_obj_ref = __xml_next_element(xml_obj_ref)) {
819  const char *obj_ref = ID(xml_obj_ref);
820 
821  if (crm_str_eq((const char *)xml_obj_ref->name, XML_CIB_TAG_OBJ_REF, TRUE) == FALSE) {
822  continue;
823  }
824 
825  if (obj_ref == NULL) {
826  crm_config_err("Failed unpacking %s for tag %s: %s should be specified",
827  crm_element_name(xml_obj_ref), tag_id, XML_ATTR_ID);
828  continue;
829  }
830 
831  if (add_tag_ref(data_set->tags, tag_id, obj_ref) == FALSE) {
832  return FALSE;
833  }
834  }
835  }
836 
837  return TRUE;
838 }
839 
840 /* The ticket state section:
841  * "/cib/status/tickets/ticket_state" */
842 static gboolean
843 unpack_ticket_state(xmlNode * xml_ticket, pe_working_set_t * data_set)
844 {
845  const char *ticket_id = NULL;
846  const char *granted = NULL;
847  const char *last_granted = NULL;
848  const char *standby = NULL;
849  xmlAttrPtr xIter = NULL;
850 
851  ticket_t *ticket = NULL;
852 
853  ticket_id = ID(xml_ticket);
854  if (ticket_id == NULL || strlen(ticket_id) == 0) {
855  return FALSE;
856  }
857 
858  crm_trace("Processing ticket state for %s", ticket_id);
859 
860  ticket = g_hash_table_lookup(data_set->tickets, ticket_id);
861  if (ticket == NULL) {
862  ticket = ticket_new(ticket_id, data_set);
863  if (ticket == NULL) {
864  return FALSE;
865  }
866  }
867 
868  for (xIter = xml_ticket->properties; xIter; xIter = xIter->next) {
869  const char *prop_name = (const char *)xIter->name;
870  const char *prop_value = crm_element_value(xml_ticket, prop_name);
871 
872  if (crm_str_eq(prop_name, XML_ATTR_ID, TRUE)) {
873  continue;
874  }
875  g_hash_table_replace(ticket->state, strdup(prop_name), strdup(prop_value));
876  }
877 
878  granted = g_hash_table_lookup(ticket->state, "granted");
879  if (granted && crm_is_true(granted)) {
880  ticket->granted = TRUE;
881  crm_info("We have ticket '%s'", ticket->id);
882  } else {
883  ticket->granted = FALSE;
884  crm_info("We do not have ticket '%s'", ticket->id);
885  }
886 
887  last_granted = g_hash_table_lookup(ticket->state, "last-granted");
888  if (last_granted) {
889  ticket->last_granted = crm_parse_int(last_granted, 0);
890  }
891 
892  standby = g_hash_table_lookup(ticket->state, "standby");
893  if (standby && crm_is_true(standby)) {
894  ticket->standby = TRUE;
895  if (ticket->granted) {
896  crm_info("Granted ticket '%s' is in standby-mode", ticket->id);
897  }
898  } else {
899  ticket->standby = FALSE;
900  }
901 
902  crm_trace("Done with ticket state for %s", ticket_id);
903 
904  return TRUE;
905 }
906 
907 static gboolean
908 unpack_tickets_state(xmlNode * xml_tickets, pe_working_set_t * data_set)
909 {
910  xmlNode *xml_obj = NULL;
911 
912  for (xml_obj = __xml_first_child(xml_tickets); xml_obj != NULL; xml_obj = __xml_next_element(xml_obj)) {
913  if (crm_str_eq((const char *)xml_obj->name, XML_CIB_TAG_TICKET_STATE, TRUE) == FALSE) {
914  continue;
915  }
916  unpack_ticket_state(xml_obj, data_set);
917  }
918 
919  return TRUE;
920 }
921 
922 /* @COMPAT DC < 1.1.7: Compatibility with the deprecated ticket state section:
923  * "/cib/status/tickets/instance_attributes" */
924 static void
925 get_ticket_state_legacy(gpointer key, gpointer value, gpointer user_data)
926 {
927  const char *long_key = key;
928  char *state_key = NULL;
929 
930  const char *granted_prefix = "granted-ticket-";
931  const char *last_granted_prefix = "last-granted-";
932  static int granted_prefix_strlen = 0;
933  static int last_granted_prefix_strlen = 0;
934 
935  const char *ticket_id = NULL;
936  const char *is_granted = NULL;
937  const char *last_granted = NULL;
938  const char *sep = NULL;
939 
940  ticket_t *ticket = NULL;
941  pe_working_set_t *data_set = user_data;
942 
943  if (granted_prefix_strlen == 0) {
944  granted_prefix_strlen = strlen(granted_prefix);
945  }
946 
947  if (last_granted_prefix_strlen == 0) {
948  last_granted_prefix_strlen = strlen(last_granted_prefix);
949  }
950 
951  if (strstr(long_key, granted_prefix) == long_key) {
952  ticket_id = long_key + granted_prefix_strlen;
953  if (strlen(ticket_id)) {
954  state_key = strdup("granted");
955  is_granted = value;
956  }
957  } else if (strstr(long_key, last_granted_prefix) == long_key) {
958  ticket_id = long_key + last_granted_prefix_strlen;
959  if (strlen(ticket_id)) {
960  state_key = strdup("last-granted");
961  last_granted = value;
962  }
963  } else if ((sep = strrchr(long_key, '-'))) {
964  ticket_id = sep + 1;
965  state_key = strndup(long_key, strlen(long_key) - strlen(sep));
966  }
967 
968  if (ticket_id == NULL || strlen(ticket_id) == 0) {
969  free(state_key);
970  return;
971  }
972 
973  if (state_key == NULL || strlen(state_key) == 0) {
974  free(state_key);
975  return;
976  }
977 
978  ticket = g_hash_table_lookup(data_set->tickets, ticket_id);
979  if (ticket == NULL) {
980  ticket = ticket_new(ticket_id, data_set);
981  if (ticket == NULL) {
982  free(state_key);
983  return;
984  }
985  }
986 
987  g_hash_table_replace(ticket->state, state_key, strdup(value));
988 
989  if (is_granted) {
990  if (crm_is_true(is_granted)) {
991  ticket->granted = TRUE;
992  crm_info("We have ticket '%s'", ticket->id);
993  } else {
994  ticket->granted = FALSE;
995  crm_info("We do not have ticket '%s'", ticket->id);
996  }
997 
998  } else if (last_granted) {
999  ticket->last_granted = crm_parse_int(last_granted, 0);
1000  }
1001 }
1002 
1003 static void
1004 unpack_handle_remote_attrs(node_t *this_node, xmlNode *state, pe_working_set_t * data_set)
1005 {
1006  const char *resource_discovery_enabled = NULL;
1007  xmlNode *attrs = NULL;
1008  resource_t *rsc = NULL;
1009  const char *shutdown = NULL;
1010 
1011  if (crm_str_eq((const char *)state->name, XML_CIB_TAG_STATE, TRUE) == FALSE) {
1012  return;
1013  }
1014 
1015  if ((this_node == NULL) || (is_remote_node(this_node) == FALSE)) {
1016  return;
1017  }
1018  crm_trace("Processing remote node id=%s, uname=%s", this_node->details->id, this_node->details->uname);
1019 
1020  this_node->details->remote_maintenance =
1022 
1023  rsc = this_node->details->remote_rsc;
1024  if (this_node->details->remote_requires_reset == FALSE) {
1025  this_node->details->unclean = FALSE;
1026  this_node->details->unseen = FALSE;
1027  }
1028  attrs = find_xml_node(state, XML_TAG_TRANSIENT_NODEATTRS, FALSE);
1029  add_node_attrs(attrs, this_node, TRUE, data_set);
1030 
1031  shutdown = pe_node_attribute_raw(this_node, XML_CIB_ATTR_SHUTDOWN);
1032  if (shutdown != NULL && safe_str_neq("0", shutdown)) {
1033  crm_info("Node %s is shutting down", this_node->details->uname);
1034  this_node->details->shutdown = TRUE;
1035  if (rsc) {
1036  rsc->next_role = RSC_ROLE_STOPPED;
1037  }
1038  }
1039 
1040  if (crm_is_true(pe_node_attribute_raw(this_node, "standby"))) {
1041  crm_info("Node %s is in standby-mode", this_node->details->uname);
1042  this_node->details->standby = TRUE;
1043  }
1044 
1045  if (crm_is_true(pe_node_attribute_raw(this_node, "maintenance")) ||
1046  (rsc && !is_set(rsc->flags, pe_rsc_managed))) {
1047  crm_info("Node %s is in maintenance-mode", this_node->details->uname);
1048  this_node->details->maintenance = TRUE;
1049  }
1050 
1051  resource_discovery_enabled = pe_node_attribute_raw(this_node, XML_NODE_ATTR_RSC_DISCOVERY);
1052  if (resource_discovery_enabled && !crm_is_true(resource_discovery_enabled)) {
1053  if (is_baremetal_remote_node(this_node) && is_not_set(data_set->flags, pe_flag_stonith_enabled)) {
1054  crm_warn("ignoring %s attribute on baremetal remote node %s, disabling resource discovery requires stonith to be enabled.",
1056  } else {
1057  /* if we're here, this is either a baremetal node and fencing is enabled,
1058  * or this is a container node which we don't care if fencing is enabled
1059  * or not on. container nodes are 'fenced' by recovering the container resource
1060  * regardless of whether fencing is enabled. */
1061  crm_info("Node %s has resource discovery disabled", this_node->details->uname);
1062  this_node->details->rsc_discovery_enabled = FALSE;
1063  }
1064  }
1065 }
1066 
1067 static bool
1068 unpack_node_loop(xmlNode * status, bool fence, pe_working_set_t * data_set)
1069 {
1070  bool changed = false;
1071  xmlNode *lrm_rsc = NULL;
1072 
1073  for (xmlNode *state = __xml_first_child(status); state != NULL; state = __xml_next_element(state)) {
1074  const char *id = NULL;
1075  const char *uname = NULL;
1076  node_t *this_node = NULL;
1077  bool process = FALSE;
1078 
1079  if (crm_str_eq((const char *)state->name, XML_CIB_TAG_STATE, TRUE) == FALSE) {
1080  continue;
1081  }
1082 
1083  id = crm_element_value(state, XML_ATTR_ID);
1084  uname = crm_element_value(state, XML_ATTR_UNAME);
1085  this_node = pe_find_node_any(data_set->nodes, id, uname);
1086 
1087  if (this_node == NULL) {
1088  crm_info("Node %s is unknown", id);
1089  continue;
1090 
1091  } else if (this_node->details->unpacked) {
1092  crm_info("Node %s is already processed", id);
1093  continue;
1094 
1095  } else if (is_remote_node(this_node) == FALSE && is_set(data_set->flags, pe_flag_stonith_enabled)) {
1096  // A redundant test, but preserves the order for regression tests
1097  process = TRUE;
1098 
1099  } else if (is_remote_node(this_node)) {
1100  bool check = FALSE;
1101  resource_t *rsc = this_node->details->remote_rsc;
1102 
1103  if(fence) {
1104  check = TRUE;
1105 
1106  } else if(rsc == NULL) {
1107  /* Not ready yet */
1108 
1109  } else if (is_container_remote_node(this_node)
1110  && rsc->role == RSC_ROLE_STARTED
1111  && rsc->container->role == RSC_ROLE_STARTED) {
1112  /* Both the connection and the underlying container
1113  * need to be known 'up' before we volunterily process
1114  * resources inside it
1115  */
1116  check = TRUE;
1117  crm_trace("Checking node %s/%s/%s status %d/%d/%d", id, rsc->id, rsc->container->id, fence, rsc->role, RSC_ROLE_STARTED);
1118 
1119  } else if (is_container_remote_node(this_node) == FALSE
1120  && rsc->role == RSC_ROLE_STARTED) {
1121  check = TRUE;
1122  crm_trace("Checking node %s/%s status %d/%d/%d", id, rsc->id, fence, rsc->role, RSC_ROLE_STARTED);
1123  }
1124 
1125  if (check) {
1126  determine_remote_online_status(data_set, this_node);
1127  unpack_handle_remote_attrs(this_node, state, data_set);
1128  process = TRUE;
1129  }
1130 
1131  } else if (this_node->details->online) {
1132  process = TRUE;
1133 
1134  } else if (fence) {
1135  process = TRUE;
1136  }
1137 
1138  if(process) {
1139  crm_trace("Processing lrm resource entries on %shealthy%s node: %s",
1140  fence?"un":"", is_remote_node(this_node)?" remote":"",
1141  this_node->details->uname);
1142  changed = TRUE;
1143  this_node->details->unpacked = TRUE;
1144 
1145  lrm_rsc = find_xml_node(state, XML_CIB_TAG_LRM, FALSE);
1146  lrm_rsc = find_xml_node(lrm_rsc, XML_LRM_TAG_RESOURCES, FALSE);
1147  unpack_lrm_resources(this_node, lrm_rsc, data_set);
1148  }
1149  }
1150  return changed;
1151 }
1152 
1153 /* remove nodes that are down, stopping */
1154 /* create +ve rsc_to_node constraints between resources and the nodes they are running on */
1155 /* anything else? */
1156 gboolean
1157 unpack_status(xmlNode * status, pe_working_set_t * data_set)
1158 {
1159  const char *id = NULL;
1160  const char *uname = NULL;
1161 
1162  xmlNode *state = NULL;
1163  node_t *this_node = NULL;
1164 
1165  crm_trace("Beginning unpack");
1166 
1167  if (data_set->tickets == NULL) {
1168  data_set->tickets =
1169  g_hash_table_new_full(crm_str_hash, g_str_equal, g_hash_destroy_str, destroy_ticket);
1170  }
1171 
1172  for (state = __xml_first_child(status); state != NULL; state = __xml_next_element(state)) {
1173  if (crm_str_eq((const char *)state->name, XML_CIB_TAG_TICKETS, TRUE)) {
1174  xmlNode *xml_tickets = state;
1175  GHashTable *state_hash = NULL;
1176 
1177  /* @COMPAT DC < 1.1.7: Compatibility with the deprecated ticket state section:
1178  * Unpack the attributes in the deprecated "/cib/status/tickets/instance_attributes" if it exists. */
1179  state_hash = crm_str_table_new();
1180 
1181  unpack_instance_attributes(data_set->input, xml_tickets, XML_TAG_ATTR_SETS, NULL,
1182  state_hash, NULL, TRUE, data_set->now);
1183 
1184  g_hash_table_foreach(state_hash, get_ticket_state_legacy, data_set);
1185 
1186  if (state_hash) {
1187  g_hash_table_destroy(state_hash);
1188  }
1189 
1190  /* Unpack the new "/cib/status/tickets/ticket_state"s */
1191  unpack_tickets_state(xml_tickets, data_set);
1192  }
1193 
1194  if (crm_str_eq((const char *)state->name, XML_CIB_TAG_STATE, TRUE)) {
1195  xmlNode *attrs = NULL;
1196  const char *resource_discovery_enabled = NULL;
1197 
1198  id = crm_element_value(state, XML_ATTR_ID);
1199  uname = crm_element_value(state, XML_ATTR_UNAME);
1200  this_node = pe_find_node_any(data_set->nodes, id, uname);
1201 
1202  if (uname == NULL) {
1203  /* error */
1204  continue;
1205 
1206  } else if (this_node == NULL) {
1207  crm_config_warn("Node %s in status section no longer exists", uname);
1208  continue;
1209 
1210  } else if (is_remote_node(this_node)) {
1211  /* online state for remote nodes is determined by the
1212  * rsc state after all the unpacking is done. we do however
1213  * need to mark whether or not the node has been fenced as this plays
1214  * a role during unpacking cluster node resource state */
1215  this_node->details->remote_was_fenced =
1217  continue;
1218  }
1219 
1220  crm_trace("Processing node id=%s, uname=%s", id, uname);
1221 
1222  /* Mark the node as provisionally clean
1223  * - at least we have seen it in the current cluster's lifetime
1224  */
1225  this_node->details->unclean = FALSE;
1226  this_node->details->unseen = FALSE;
1227  attrs = find_xml_node(state, XML_TAG_TRANSIENT_NODEATTRS, FALSE);
1228  add_node_attrs(attrs, this_node, TRUE, data_set);
1229 
1230  if (crm_is_true(pe_node_attribute_raw(this_node, "standby"))) {
1231  crm_info("Node %s is in standby-mode", this_node->details->uname);
1232  this_node->details->standby = TRUE;
1233  }
1234 
1235  if (crm_is_true(pe_node_attribute_raw(this_node, "maintenance"))) {
1236  crm_info("Node %s is in maintenance-mode", this_node->details->uname);
1237  this_node->details->maintenance = TRUE;
1238  }
1239 
1240  resource_discovery_enabled = pe_node_attribute_raw(this_node, XML_NODE_ATTR_RSC_DISCOVERY);
1241  if (resource_discovery_enabled && !crm_is_true(resource_discovery_enabled)) {
1242  crm_warn("ignoring %s attribute on node %s, disabling resource discovery is not allowed on cluster nodes",
1244  }
1245 
1246  crm_trace("determining node state");
1247  determine_online_status(state, this_node, data_set);
1248 
1249  if (is_not_set(data_set->flags, pe_flag_have_quorum)
1250  && this_node->details->online
1251  && (data_set->no_quorum_policy == no_quorum_suicide)) {
1252  /* Everything else should flow from this automatically
1253  * At least until the PE becomes able to migrate off healthy resources
1254  */
1255  pe_fence_node(data_set, this_node, "cluster does not have quorum");
1256  }
1257  }
1258  }
1259 
1260 
1261  while(unpack_node_loop(status, FALSE, data_set)) {
1262  crm_trace("Start another loop");
1263  }
1264 
1265  // Now catch any nodes we didn't see
1266  unpack_node_loop(status, is_set(data_set->flags, pe_flag_stonith_enabled), data_set);
1267 
1268  for (GListPtr gIter = data_set->nodes; gIter != NULL; gIter = gIter->next) {
1269  node_t *this_node = gIter->data;
1270 
1271  if (this_node == NULL) {
1272  continue;
1273  } else if(is_remote_node(this_node) == FALSE) {
1274  continue;
1275  } else if(this_node->details->unpacked) {
1276  continue;
1277  }
1278  determine_remote_online_status(data_set, this_node);
1279  }
1280 
1281  return TRUE;
1282 }
1283 
1284 static gboolean
1285 determine_online_status_no_fencing(pe_working_set_t * data_set, xmlNode * node_state,
1286  node_t * this_node)
1287 {
1288  gboolean online = FALSE;
1289  const char *join = crm_element_value(node_state, XML_NODE_JOIN_STATE);
1290  const char *is_peer = crm_element_value(node_state, XML_NODE_IS_PEER);
1291  const char *in_cluster = crm_element_value(node_state, XML_NODE_IN_CLUSTER);
1292  const char *exp_state = crm_element_value(node_state, XML_NODE_EXPECTED);
1293 
1294  if (!crm_is_true(in_cluster)) {
1295  crm_trace("Node is down: in_cluster=%s", crm_str(in_cluster));
1296 
1297  } else if (safe_str_eq(is_peer, ONLINESTATUS)) {
1298  if (safe_str_eq(join, CRMD_JOINSTATE_MEMBER)) {
1299  online = TRUE;
1300  } else {
1301  crm_debug("Node is not ready to run resources: %s", join);
1302  }
1303 
1304  } else if (this_node->details->expected_up == FALSE) {
1305  crm_trace("CRMd is down: in_cluster=%s", crm_str(in_cluster));
1306  crm_trace("\tis_peer=%s, join=%s, expected=%s",
1307  crm_str(is_peer), crm_str(join), crm_str(exp_state));
1308 
1309  } else {
1310  /* mark it unclean */
1311  pe_fence_node(data_set, this_node, "peer is unexpectedly down");
1312  crm_info("\tin_cluster=%s, is_peer=%s, join=%s, expected=%s",
1313  crm_str(in_cluster), crm_str(is_peer), crm_str(join), crm_str(exp_state));
1314  }
1315  return online;
1316 }
1317 
1318 static gboolean
1319 determine_online_status_fencing(pe_working_set_t * data_set, xmlNode * node_state,
1320  node_t * this_node)
1321 {
1322  gboolean online = FALSE;
1323  gboolean do_terminate = FALSE;
1324  const char *join = crm_element_value(node_state, XML_NODE_JOIN_STATE);
1325  const char *is_peer = crm_element_value(node_state, XML_NODE_IS_PEER);
1326  const char *in_cluster = crm_element_value(node_state, XML_NODE_IN_CLUSTER);
1327  const char *exp_state = crm_element_value(node_state, XML_NODE_EXPECTED);
1328  const char *terminate = pe_node_attribute_raw(this_node, "terminate");
1329 
1330 /*
1331  - XML_NODE_IN_CLUSTER ::= true|false
1332  - XML_NODE_IS_PEER ::= true|false|online|offline
1333  - XML_NODE_JOIN_STATE ::= member|down|pending|banned
1334  - XML_NODE_EXPECTED ::= member|down
1335 */
1336 
1337  if (crm_is_true(terminate)) {
1338  do_terminate = TRUE;
1339 
1340  } else if (terminate != NULL && strlen(terminate) > 0) {
1341  /* could be a time() value */
1342  char t = terminate[0];
1343 
1344  if (t != '0' && isdigit(t)) {
1345  do_terminate = TRUE;
1346  }
1347  }
1348 
1349  crm_trace("%s: in_cluster=%s, is_peer=%s, join=%s, expected=%s, term=%d",
1350  this_node->details->uname, crm_str(in_cluster), crm_str(is_peer),
1351  crm_str(join), crm_str(exp_state), do_terminate);
1352 
1353  online = crm_is_true(in_cluster);
1354  if (safe_str_eq(is_peer, ONLINESTATUS)) {
1355  is_peer = XML_BOOLEAN_YES;
1356  }
1357  if (exp_state == NULL) {
1358  exp_state = CRMD_JOINSTATE_DOWN;
1359  }
1360 
1361  if (this_node->details->shutdown) {
1362  crm_debug("%s is shutting down", this_node->details->uname);
1363 
1364  /* Slightly different criteria since we can't shut down a dead peer */
1365  online = crm_is_true(is_peer);
1366 
1367  } else if (in_cluster == NULL) {
1368  pe_fence_node(data_set, this_node, "peer has not been seen by the cluster");
1369 
1370  } else if (safe_str_eq(join, CRMD_JOINSTATE_NACK)) {
1371  pe_fence_node(data_set, this_node, "peer failed the pacemaker membership criteria");
1372 
1373  } else if (do_terminate == FALSE && safe_str_eq(exp_state, CRMD_JOINSTATE_DOWN)) {
1374 
1375  if (crm_is_true(in_cluster) || crm_is_true(is_peer)) {
1376  crm_info("- Node %s is not ready to run resources", this_node->details->uname);
1377  this_node->details->standby = TRUE;
1378  this_node->details->pending = TRUE;
1379 
1380  } else {
1381  crm_trace("%s is down or still coming up", this_node->details->uname);
1382  }
1383 
1384  } else if (do_terminate && safe_str_eq(join, CRMD_JOINSTATE_DOWN)
1385  && crm_is_true(in_cluster) == FALSE && crm_is_true(is_peer) == FALSE) {
1386  crm_info("Node %s was just shot", this_node->details->uname);
1387  online = FALSE;
1388 
1389  } else if (crm_is_true(in_cluster) == FALSE) {
1390  pe_fence_node(data_set, this_node, "peer is no longer part of the cluster");
1391 
1392  } else if (crm_is_true(is_peer) == FALSE) {
1393  pe_fence_node(data_set, this_node, "peer process is no longer available");
1394 
1395  /* Everything is running at this point, now check join state */
1396  } else if (do_terminate) {
1397  pe_fence_node(data_set, this_node, "termination was requested");
1398 
1399  } else if (safe_str_eq(join, CRMD_JOINSTATE_MEMBER)) {
1400  crm_info("Node %s is active", this_node->details->uname);
1401 
1402  } else if (safe_str_eq(join, CRMD_JOINSTATE_PENDING)
1403  || safe_str_eq(join, CRMD_JOINSTATE_DOWN)) {
1404  crm_info("Node %s is not ready to run resources", this_node->details->uname);
1405  this_node->details->standby = TRUE;
1406  this_node->details->pending = TRUE;
1407 
1408  } else {
1409  pe_fence_node(data_set, this_node, "peer was in an unknown state");
1410  crm_warn("%s: in-cluster=%s, is-peer=%s, join=%s, expected=%s, term=%d, shutdown=%d",
1411  this_node->details->uname, crm_str(in_cluster), crm_str(is_peer),
1412  crm_str(join), crm_str(exp_state), do_terminate, this_node->details->shutdown);
1413  }
1414 
1415  return online;
1416 }
1417 
1418 static gboolean
1419 determine_remote_online_status(pe_working_set_t * data_set, node_t * this_node)
1420 {
1421  resource_t *rsc = this_node->details->remote_rsc;
1422  resource_t *container = NULL;
1423  pe_node_t *host = NULL;
1424 
1425  /* If there is a node state entry for a (former) Pacemaker Remote node
1426  * but no resource creating that node, the node's connection resource will
1427  * be NULL. Consider it an offline remote node in that case.
1428  */
1429  if (rsc == NULL) {
1430  this_node->details->online = FALSE;
1431  goto remote_online_done;
1432  }
1433 
1434  container = rsc->container;
1435 
1436  if (container && (g_list_length(rsc->running_on) == 1)) {
1437  host = rsc->running_on->data;
1438  }
1439 
1440  /* If the resource is currently started, mark it online. */
1441  if (rsc->role == RSC_ROLE_STARTED) {
1442  crm_trace("%s node %s presumed ONLINE because connection resource is started",
1443  (container? "Guest" : "Remote"), this_node->details->id);
1444  this_node->details->online = TRUE;
1445  }
1446 
1447  /* consider this node shutting down if transitioning start->stop */
1448  if (rsc->role == RSC_ROLE_STARTED && rsc->next_role == RSC_ROLE_STOPPED) {
1449  crm_trace("%s node %s shutting down because connection resource is stopping",
1450  (container? "Guest" : "Remote"), this_node->details->id);
1451  this_node->details->shutdown = TRUE;
1452  }
1453 
1454  /* Now check all the failure conditions. */
1455  if(container && is_set(container->flags, pe_rsc_failed)) {
1456  crm_trace("Guest node %s UNCLEAN because guest resource failed",
1457  this_node->details->id);
1458  this_node->details->online = FALSE;
1459  this_node->details->remote_requires_reset = TRUE;
1460 
1461  } else if(is_set(rsc->flags, pe_rsc_failed)) {
1462  crm_trace("%s node %s OFFLINE because connection resource failed",
1463  (container? "Guest" : "Remote"), this_node->details->id);
1464  this_node->details->online = FALSE;
1465 
1466  } else if (rsc->role == RSC_ROLE_STOPPED
1467  || (container && container->role == RSC_ROLE_STOPPED)) {
1468 
1469  crm_trace("%s node %s OFFLINE because its resource is stopped",
1470  (container? "Guest" : "Remote"), this_node->details->id);
1471  this_node->details->online = FALSE;
1472  this_node->details->remote_requires_reset = FALSE;
1473 
1474  } else if (host && (host->details->online == FALSE)
1475  && host->details->unclean) {
1476  crm_trace("Guest node %s UNCLEAN because host is unclean",
1477  this_node->details->id);
1478  this_node->details->online = FALSE;
1479  this_node->details->remote_requires_reset = TRUE;
1480  }
1481 
1482 remote_online_done:
1483  crm_trace("Remote node %s online=%s",
1484  this_node->details->id, this_node->details->online ? "TRUE" : "FALSE");
1485  return this_node->details->online;
1486 }
1487 
1488 gboolean
1489 determine_online_status(xmlNode * node_state, node_t * this_node, pe_working_set_t * data_set)
1490 {
1491  gboolean online = FALSE;
1492  const char *shutdown = NULL;
1493  const char *exp_state = crm_element_value(node_state, XML_NODE_EXPECTED);
1494 
1495  if (this_node == NULL) {
1496  crm_config_err("No node to check");
1497  return online;
1498  }
1499 
1500  this_node->details->shutdown = FALSE;
1501  this_node->details->expected_up = FALSE;
1502  shutdown = pe_node_attribute_raw(this_node, XML_CIB_ATTR_SHUTDOWN);
1503 
1504  if (shutdown != NULL && safe_str_neq("0", shutdown)) {
1505  this_node->details->shutdown = TRUE;
1506 
1507  } else if (safe_str_eq(exp_state, CRMD_JOINSTATE_MEMBER)) {
1508  this_node->details->expected_up = TRUE;
1509  }
1510 
1511  if (this_node->details->type == node_ping) {
1512  this_node->details->unclean = FALSE;
1513  online = FALSE; /* As far as resource management is concerned,
1514  * the node is safely offline.
1515  * Anyone caught abusing this logic will be shot
1516  */
1517 
1518  } else if (is_set(data_set->flags, pe_flag_stonith_enabled) == FALSE) {
1519  online = determine_online_status_no_fencing(data_set, node_state, this_node);
1520 
1521  } else {
1522  online = determine_online_status_fencing(data_set, node_state, this_node);
1523  }
1524 
1525  if (online) {
1526  this_node->details->online = TRUE;
1527 
1528  } else {
1529  /* remove node from contention */
1530  this_node->fixed = TRUE;
1531  this_node->weight = -INFINITY;
1532  }
1533 
1534  if (online && this_node->details->shutdown) {
1535  /* don't run resources here */
1536  this_node->fixed = TRUE;
1537  this_node->weight = -INFINITY;
1538  }
1539 
1540  if (this_node->details->type == node_ping) {
1541  crm_info("Node %s is not a pacemaker node", this_node->details->uname);
1542 
1543  } else if (this_node->details->unclean) {
1544  pe_proc_warn("Node %s is unclean", this_node->details->uname);
1545 
1546  } else if (this_node->details->online) {
1547  crm_info("Node %s is %s", this_node->details->uname,
1548  this_node->details->shutdown ? "shutting down" :
1549  this_node->details->pending ? "pending" :
1550  this_node->details->standby ? "standby" :
1551  this_node->details->maintenance ? "maintenance" : "online");
1552 
1553  } else {
1554  crm_trace("Node %s is offline", this_node->details->uname);
1555  }
1556 
1557  return online;
1558 }
1559 
1560 char *
1561 clone_strip(const char *last_rsc_id)
1562 {
1563  int lpc = 0;
1564  char *zero = NULL;
1565 
1566  CRM_CHECK(last_rsc_id != NULL, return NULL);
1567  lpc = strlen(last_rsc_id);
1568  while (--lpc > 0) {
1569  switch (last_rsc_id[lpc]) {
1570  case 0:
1571  crm_err("Empty string: %s", last_rsc_id);
1572  return NULL;
1573  break;
1574  case '0':
1575  case '1':
1576  case '2':
1577  case '3':
1578  case '4':
1579  case '5':
1580  case '6':
1581  case '7':
1582  case '8':
1583  case '9':
1584  break;
1585  case ':':
1586  zero = calloc(1, lpc + 1);
1587  memcpy(zero, last_rsc_id, lpc);
1588  zero[lpc] = 0;
1589  return zero;
1590  default:
1591  goto done;
1592  }
1593  }
1594  done:
1595  zero = strdup(last_rsc_id);
1596  return zero;
1597 }
1598 
1599 char *
1600 clone_zero(const char *last_rsc_id)
1601 {
1602  int lpc = 0;
1603  char *zero = NULL;
1604 
1605  CRM_CHECK(last_rsc_id != NULL, return NULL);
1606  if (last_rsc_id != NULL) {
1607  lpc = strlen(last_rsc_id);
1608  }
1609 
1610  while (--lpc > 0) {
1611  switch (last_rsc_id[lpc]) {
1612  case 0:
1613  return NULL;
1614  break;
1615  case '0':
1616  case '1':
1617  case '2':
1618  case '3':
1619  case '4':
1620  case '5':
1621  case '6':
1622  case '7':
1623  case '8':
1624  case '9':
1625  break;
1626  case ':':
1627  zero = calloc(1, lpc + 3);
1628  memcpy(zero, last_rsc_id, lpc);
1629  zero[lpc] = ':';
1630  zero[lpc + 1] = '0';
1631  zero[lpc + 2] = 0;
1632  return zero;
1633  default:
1634  goto done;
1635  }
1636  }
1637  done:
1638  lpc = strlen(last_rsc_id);
1639  zero = calloc(1, lpc + 3);
1640  memcpy(zero, last_rsc_id, lpc);
1641  zero[lpc] = ':';
1642  zero[lpc + 1] = '0';
1643  zero[lpc + 2] = 0;
1644  crm_trace("%s -> %s", last_rsc_id, zero);
1645  return zero;
1646 }
1647 
1648 static resource_t *
1649 create_fake_resource(const char *rsc_id, xmlNode * rsc_entry, pe_working_set_t * data_set)
1650 {
1651  resource_t *rsc = NULL;
1652  xmlNode *xml_rsc = create_xml_node(NULL, XML_CIB_TAG_RESOURCE);
1653 
1654  copy_in_properties(xml_rsc, rsc_entry);
1655  crm_xml_add(xml_rsc, XML_ATTR_ID, rsc_id);
1656  crm_log_xml_debug(xml_rsc, "Orphan resource");
1657 
1658  if (!common_unpack(xml_rsc, &rsc, NULL, data_set)) {
1659  return NULL;
1660  }
1661 
1662  if (xml_contains_remote_node(xml_rsc)) {
1663  node_t *node;
1664 
1665  crm_debug("Detected orphaned remote node %s", rsc_id);
1666  node = pe_find_node(data_set->nodes, rsc_id);
1667  if (node == NULL) {
1668  node = pe_create_node(rsc_id, rsc_id, "remote", NULL, data_set);
1669  }
1670  link_rsc2remotenode(data_set, rsc);
1671 
1672  if (node) {
1673  crm_trace("Setting node %s as shutting down due to orphaned connection resource", rsc_id);
1674  node->details->shutdown = TRUE;
1675  }
1676  }
1677 
1678  if (crm_element_value(rsc_entry, XML_RSC_ATTR_CONTAINER)) {
1679  /* This orphaned rsc needs to be mapped to a container. */
1680  crm_trace("Detected orphaned container filler %s", rsc_id);
1682  }
1683  set_bit(rsc->flags, pe_rsc_orphan);
1684  data_set->resources = g_list_append(data_set->resources, rsc);
1685  return rsc;
1686 }
1687 
1688 extern resource_t *create_child_clone(resource_t * rsc, int sub_id, pe_working_set_t * data_set);
1689 
1690 static resource_t *
1691 find_anonymous_clone(pe_working_set_t * data_set, node_t * node, resource_t * parent,
1692  const char *rsc_id)
1693 {
1694  GListPtr rIter = NULL;
1695  resource_t *rsc = NULL;
1696  gboolean skip_inactive = FALSE;
1697 
1698  CRM_ASSERT(parent != NULL);
1699  CRM_ASSERT(pe_rsc_is_clone(parent));
1700  CRM_ASSERT(is_not_set(parent->flags, pe_rsc_unique));
1701 
1702  /* Find an instance active (or partially active for grouped clones) on the specified node */
1703  pe_rsc_trace(parent, "Looking for %s on %s in %s", rsc_id, node->details->uname, parent->id);
1704  for (rIter = parent->children; rsc == NULL && rIter; rIter = rIter->next) {
1705  GListPtr nIter = NULL;
1706  GListPtr locations = NULL;
1707  resource_t *child = rIter->data;
1708 
1709  child->fns->location(child, &locations, TRUE);
1710  if (locations == NULL) {
1711  pe_rsc_trace(child, "Resource %s, skip inactive", child->id);
1712  continue;
1713  }
1714 
1715  for (nIter = locations; nIter && rsc == NULL; nIter = nIter->next) {
1716  node_t *childnode = nIter->data;
1717 
1718  if (childnode->details == node->details) {
1719  /* ->find_rsc() because we might be a cloned group */
1720  rsc = parent->fns->find_rsc(child, rsc_id, NULL, pe_find_clone);
1721  if(rsc) {
1722  pe_rsc_trace(rsc, "Resource %s, active", rsc->id);
1723  }
1724  }
1725 
1726  /* Keep this block, it means we'll do the right thing if
1727  * anyone toggles the unique flag to 'off'
1728  */
1729  if (rsc && rsc->running_on) {
1730  crm_notice("/Anonymous/ clone %s is already running on %s",
1731  parent->id, node->details->uname);
1732  skip_inactive = TRUE;
1733  rsc = NULL;
1734  }
1735  }
1736 
1737  g_list_free(locations);
1738  }
1739 
1740  /* Find an inactive instance */
1741  if (skip_inactive == FALSE) {
1742  pe_rsc_trace(parent, "Looking for %s anywhere", rsc_id);
1743  for (rIter = parent->children; rsc == NULL && rIter; rIter = rIter->next) {
1744  GListPtr locations = NULL;
1745  resource_t *child = rIter->data;
1746 
1747  if (is_set(child->flags, pe_rsc_block)) {
1748  pe_rsc_trace(child, "Skip: blocked in stopped state");
1749  continue;
1750  }
1751 
1752  child->fns->location(child, &locations, TRUE);
1753  if (locations == NULL) {
1754  /* ->find_rsc() because we might be a cloned group */
1755  rsc = parent->fns->find_rsc(child, rsc_id, NULL, pe_find_clone);
1756  pe_rsc_trace(parent, "Resource %s, empty slot", rsc->id);
1757  }
1758  g_list_free(locations);
1759  }
1760  }
1761 
1762  if (rsc == NULL) {
1763  /* Create an extra orphan */
1764  resource_t *top = create_child_clone(parent, -1, data_set);
1765 
1766  /* ->find_rsc() because we might be a cloned group */
1767  rsc = top->fns->find_rsc(top, rsc_id, NULL, pe_find_clone);
1768  CRM_ASSERT(rsc != NULL);
1769 
1770  pe_rsc_debug(parent, "Created orphan %s for %s: %s on %s", top->id, parent->id, rsc_id,
1771  node->details->uname);
1772  }
1773 
1774  if (safe_str_neq(rsc_id, rsc->id)) {
1775  pe_rsc_debug(rsc, "Internally renamed %s on %s to %s%s",
1776  rsc_id, node->details->uname, rsc->id,
1777  is_set(rsc->flags, pe_rsc_orphan) ? " (ORPHAN)" : "");
1778  }
1779 
1780  return rsc;
1781 }
1782 
1783 static resource_t *
1784 unpack_find_resource(pe_working_set_t * data_set, node_t * node, const char *rsc_id,
1785  xmlNode * rsc_entry)
1786 {
1787  resource_t *rsc = NULL;
1788  resource_t *parent = NULL;
1789 
1790  crm_trace("looking for %s", rsc_id);
1791  rsc = pe_find_resource(data_set->resources, rsc_id);
1792 
1793  /* no match */
1794  if (rsc == NULL) {
1795  /* Even when clone-max=0, we still create a single :0 orphan to match against */
1796  char *tmp = clone_zero(rsc_id);
1797  resource_t *clone0 = pe_find_resource(data_set->resources, tmp);
1798 
1799  if (clone0 && is_not_set(clone0->flags, pe_rsc_unique)) {
1800  rsc = clone0;
1801  } else {
1802  crm_trace("%s is not known as %s either", rsc_id, tmp);
1803  }
1804 
1805  parent = uber_parent(clone0);
1806  free(tmp);
1807 
1808  crm_trace("%s not found: %s", rsc_id, parent ? parent->id : "orphan");
1809 
1810  } else if (rsc->variant > pe_native) {
1811  crm_trace("%s is no longer a primitive resource, the lrm_resource entry is obsolete",
1812  rsc_id);
1813  return NULL;
1814 
1815  } else {
1816  parent = uber_parent(rsc);
1817  }
1818 
1819  if(parent && parent->parent) {
1820  rsc = find_container_child(rsc_id, rsc, node);
1821 
1822  } else if (pe_rsc_is_clone(parent)) {
1823  if (is_not_set(parent->flags, pe_rsc_unique)) {
1824  char *base = clone_strip(rsc_id);
1825 
1826  rsc = find_anonymous_clone(data_set, node, parent, base);
1827  CRM_ASSERT(rsc != NULL);
1828  free(base);
1829  }
1830 
1831  if (rsc && safe_str_neq(rsc_id, rsc->id)) {
1832  free(rsc->clone_name);
1833  rsc->clone_name = strdup(rsc_id);
1834  }
1835  }
1836 
1837  return rsc;
1838 }
1839 
1840 static resource_t *
1841 process_orphan_resource(xmlNode * rsc_entry, node_t * node, pe_working_set_t * data_set)
1842 {
1843  resource_t *rsc = NULL;
1844  const char *rsc_id = crm_element_value(rsc_entry, XML_ATTR_ID);
1845 
1846  crm_debug("Detected orphan resource %s on %s", rsc_id, node->details->uname);
1847  rsc = create_fake_resource(rsc_id, rsc_entry, data_set);
1848 
1849  if (is_set(data_set->flags, pe_flag_stop_rsc_orphans) == FALSE) {
1851 
1852  } else {
1853  print_resource(LOG_DEBUG_3, "Added orphan", rsc, FALSE);
1854 
1855  CRM_CHECK(rsc != NULL, return NULL);
1856  resource_location(rsc, NULL, -INFINITY, "__orphan_dont_run__", data_set);
1857  }
1858  return rsc;
1859 }
1860 
1861 static void
1862 process_rsc_state(resource_t * rsc, node_t * node,
1863  enum action_fail_response on_fail,
1864  xmlNode * migrate_op, pe_working_set_t * data_set)
1865 {
1866  node_t *tmpnode = NULL;
1867  char *reason = NULL;
1868 
1869  CRM_ASSERT(rsc);
1870  pe_rsc_trace(rsc, "Resource %s is %s on %s: on_fail=%s",
1871  rsc->id, role2text(rsc->role), node->details->uname, fail2text(on_fail));
1872 
1873  /* process current state */
1874  if (rsc->role != RSC_ROLE_UNKNOWN) {
1875  resource_t *iter = rsc;
1876 
1877  while (iter) {
1878  if (g_hash_table_lookup(iter->known_on, node->details->id) == NULL) {
1879  node_t *n = node_copy(node);
1880 
1881  pe_rsc_trace(rsc, "%s (aka. %s) known on %s", rsc->id, rsc->clone_name,
1882  n->details->uname);
1883  g_hash_table_insert(iter->known_on, (gpointer) n->details->id, n);
1884  }
1885  if (is_set(iter->flags, pe_rsc_unique)) {
1886  break;
1887  }
1888  iter = iter->parent;
1889  }
1890  }
1891 
1892  /* If a managed resource is believed to be running, but node is down ... */
1893  if (rsc->role > RSC_ROLE_STOPPED
1894  && node->details->online == FALSE
1895  && node->details->maintenance == FALSE
1896  && is_set(rsc->flags, pe_rsc_managed)) {
1897 
1898  gboolean should_fence = FALSE;
1899 
1900  /* If this is a guest node, fence it (regardless of whether fencing is
1901  * enabled, because guest node fencing is done by recovery of the
1902  * container resource rather than by stonithd). Mark the resource
1903  * we're processing as failed. When the guest comes back up, its
1904  * operation history in the CIB will be cleared, freeing the affected
1905  * resource to run again once we are sure we know its state.
1906  */
1907  if (is_container_remote_node(node)) {
1908  set_bit(rsc->flags, pe_rsc_failed);
1909  should_fence = TRUE;
1910 
1911  } else if (is_set(data_set->flags, pe_flag_stonith_enabled)) {
1912  if (is_baremetal_remote_node(node) && node->details->remote_rsc
1913  && is_not_set(node->details->remote_rsc->flags, pe_rsc_failed)) {
1914 
1915  /* setting unseen = true means that fencing of the remote node will
1916  * only occur if the connection resource is not going to start somewhere.
1917  * This allows connection resources on a failed cluster-node to move to
1918  * another node without requiring the baremetal remote nodes to be fenced
1919  * as well. */
1920  node->details->unseen = TRUE;
1921  reason = crm_strdup_printf("%s is active there (fencing will be"
1922  " revoked if remote connection can "
1923  "be re-established elsewhere)",
1924  rsc->id);
1925  }
1926  should_fence = TRUE;
1927  }
1928 
1929  if (should_fence) {
1930  if (reason == NULL) {
1931  reason = crm_strdup_printf("%s is thought to be active there", rsc->id);
1932  }
1933  pe_fence_node(data_set, node, reason);
1934  }
1935  free(reason);
1936  }
1937 
1938  if (node->details->unclean) {
1939  /* No extra processing needed
1940  * Also allows resources to be started again after a node is shot
1941  */
1942  on_fail = action_fail_ignore;
1943  }
1944 
1945  switch (on_fail) {
1946  case action_fail_ignore:
1947  /* nothing to do */
1948  break;
1949 
1950  case action_fail_fence:
1951  /* treat it as if it is still running
1952  * but also mark the node as unclean
1953  */
1954  reason = crm_strdup_printf("%s failed there", rsc->id);
1955  pe_fence_node(data_set, node, reason);
1956  free(reason);
1957  break;
1958 
1959  case action_fail_standby:
1960  node->details->standby = TRUE;
1961  node->details->standby_onfail = TRUE;
1962  break;
1963 
1964  case action_fail_block:
1965  /* is_managed == FALSE will prevent any
1966  * actions being sent for the resource
1967  */
1969  set_bit(rsc->flags, pe_rsc_block);
1970  break;
1971 
1972  case action_fail_migrate:
1973  /* make sure it comes up somewhere else
1974  * or not at all
1975  */
1976  resource_location(rsc, node, -INFINITY, "__action_migration_auto__", data_set);
1977  break;
1978 
1979  case action_fail_stop:
1980  rsc->next_role = RSC_ROLE_STOPPED;
1981  break;
1982 
1983  case action_fail_recover:
1984  if (rsc->role != RSC_ROLE_STOPPED && rsc->role != RSC_ROLE_UNKNOWN) {
1985  set_bit(rsc->flags, pe_rsc_failed);
1986  stop_action(rsc, node, FALSE);
1987  }
1988  break;
1989 
1991  set_bit(rsc->flags, pe_rsc_failed);
1992 
1993  if (rsc->container) {
1994  stop_action(rsc->container, node, FALSE);
1995  } else if (rsc->role != RSC_ROLE_STOPPED && rsc->role != RSC_ROLE_UNKNOWN) {
1996  stop_action(rsc, node, FALSE);
1997  }
1998  break;
1999 
2001  set_bit(rsc->flags, pe_rsc_failed);
2002  if (is_set(data_set->flags, pe_flag_stonith_enabled)) {
2003  tmpnode = NULL;
2004  if (rsc->is_remote_node) {
2005  tmpnode = pe_find_node(data_set->nodes, rsc->id);
2006  }
2007  if (tmpnode &&
2008  is_baremetal_remote_node(tmpnode) &&
2009  tmpnode->details->remote_was_fenced == 0) {
2010 
2011  /* connection resource to baremetal resource failed in a way that
2012  * should result in fencing the remote-node. */
2013  pe_fence_node(data_set, tmpnode,
2014  "remote connection is unrecoverable");
2015  }
2016  }
2017 
2018  /* require the stop action regardless if fencing is occurring or not. */
2019  if (rsc->role > RSC_ROLE_STOPPED) {
2020  stop_action(rsc, node, FALSE);
2021  }
2022 
2023  /* if reconnect delay is in use, prevent the connection from exiting the
2024  * "STOPPED" role until the failure is cleared by the delay timeout. */
2025  if (rsc->remote_reconnect_interval) {
2026  rsc->next_role = RSC_ROLE_STOPPED;
2027  }
2028  break;
2029  }
2030 
2031  /* ensure a remote-node connection failure forces an unclean remote-node
2032  * to be fenced. By setting unseen = FALSE, the remote-node failure will
2033  * result in a fencing operation regardless if we're going to attempt to
2034  * reconnect to the remote-node in this transition or not. */
2035  if (is_set(rsc->flags, pe_rsc_failed) && rsc->is_remote_node) {
2036  tmpnode = pe_find_node(data_set->nodes, rsc->id);
2037  if (tmpnode && tmpnode->details->unclean) {
2038  tmpnode->details->unseen = FALSE;
2039  }
2040  }
2041 
2042  if (rsc->role != RSC_ROLE_STOPPED && rsc->role != RSC_ROLE_UNKNOWN) {
2043  if (is_set(rsc->flags, pe_rsc_orphan)) {
2044  if (is_set(rsc->flags, pe_rsc_managed)) {
2045  crm_config_warn("Detected active orphan %s running on %s",
2046  rsc->id, node->details->uname);
2047  } else {
2048  crm_config_warn("Cluster configured not to stop active orphans."
2049  " %s must be stopped manually on %s",
2050  rsc->id, node->details->uname);
2051  }
2052  }
2053 
2054  native_add_running(rsc, node, data_set);
2055  if (on_fail != action_fail_ignore) {
2056  set_bit(rsc->flags, pe_rsc_failed);
2057  }
2058 
2059  } else if (rsc->clone_name && strchr(rsc->clone_name, ':') != NULL) {
2060  /* Only do this for older status sections that included instance numbers
2061  * Otherwise stopped instances will appear as orphans
2062  */
2063  pe_rsc_trace(rsc, "Resetting clone_name %s for %s (stopped)", rsc->clone_name, rsc->id);
2064  free(rsc->clone_name);
2065  rsc->clone_name = NULL;
2066 
2067  } else {
2068  char *key = stop_key(rsc);
2069  GListPtr possible_matches = find_actions(rsc->actions, key, node);
2070  GListPtr gIter = possible_matches;
2071 
2072  for (; gIter != NULL; gIter = gIter->next) {
2073  action_t *stop = (action_t *) gIter->data;
2074 
2075  stop->flags |= pe_action_optional;
2076  }
2077 
2078  g_list_free(possible_matches);
2079  free(key);
2080  }
2081 }
2082 
2083 /* create active recurring operations as optional */
2084 static void
2085 process_recurring(node_t * node, resource_t * rsc,
2086  int start_index, int stop_index,
2087  GListPtr sorted_op_list, pe_working_set_t * data_set)
2088 {
2089  int counter = -1;
2090  const char *task = NULL;
2091  const char *status = NULL;
2092  GListPtr gIter = sorted_op_list;
2093 
2094  CRM_ASSERT(rsc);
2095  pe_rsc_trace(rsc, "%s: Start index %d, stop index = %d", rsc->id, start_index, stop_index);
2096 
2097  for (; gIter != NULL; gIter = gIter->next) {
2098  xmlNode *rsc_op = (xmlNode *) gIter->data;
2099 
2100  int interval = 0;
2101  char *key = NULL;
2102  const char *id = ID(rsc_op);
2103  const char *interval_s = NULL;
2104 
2105  counter++;
2106 
2107  if (node->details->online == FALSE) {
2108  pe_rsc_trace(rsc, "Skipping %s/%s: node is offline", rsc->id, node->details->uname);
2109  break;
2110 
2111  /* Need to check if there's a monitor for role="Stopped" */
2112  } else if (start_index < stop_index && counter <= stop_index) {
2113  pe_rsc_trace(rsc, "Skipping %s/%s: resource is not active", id, node->details->uname);
2114  continue;
2115 
2116  } else if (counter < start_index) {
2117  pe_rsc_trace(rsc, "Skipping %s/%s: old %d", id, node->details->uname, counter);
2118  continue;
2119  }
2120 
2121  interval_s = crm_element_value(rsc_op, XML_LRM_ATTR_INTERVAL);
2122  interval = crm_parse_int(interval_s, "0");
2123  if (interval == 0) {
2124  pe_rsc_trace(rsc, "Skipping %s/%s: non-recurring", id, node->details->uname);
2125  continue;
2126  }
2127 
2128  status = crm_element_value(rsc_op, XML_LRM_ATTR_OPSTATUS);
2129  if (safe_str_eq(status, "-1")) {
2130  pe_rsc_trace(rsc, "Skipping %s/%s: status", id, node->details->uname);
2131  continue;
2132  }
2133  task = crm_element_value(rsc_op, XML_LRM_ATTR_TASK);
2134  /* create the action */
2135  key = generate_op_key(rsc->id, task, interval);
2136  pe_rsc_trace(rsc, "Creating %s/%s", key, node->details->uname);
2137  custom_action(rsc, key, task, node, TRUE, TRUE, data_set);
2138  }
2139 }
2140 
2141 void
2142 calculate_active_ops(GListPtr sorted_op_list, int *start_index, int *stop_index)
2143 {
2144  int counter = -1;
2145  int implied_monitor_start = -1;
2146  int implied_master_start = -1;
2147  const char *task = NULL;
2148  const char *status = NULL;
2149  GListPtr gIter = sorted_op_list;
2150 
2151  *stop_index = -1;
2152  *start_index = -1;
2153 
2154  for (; gIter != NULL; gIter = gIter->next) {
2155  xmlNode *rsc_op = (xmlNode *) gIter->data;
2156 
2157  counter++;
2158 
2159  task = crm_element_value(rsc_op, XML_LRM_ATTR_TASK);
2160  status = crm_element_value(rsc_op, XML_LRM_ATTR_OPSTATUS);
2161 
2162  if (safe_str_eq(task, CRMD_ACTION_STOP)
2163  && safe_str_eq(status, "0")) {
2164  *stop_index = counter;
2165 
2166  } else if (safe_str_eq(task, CRMD_ACTION_START) || safe_str_eq(task, CRMD_ACTION_MIGRATED)) {
2167  *start_index = counter;
2168 
2169  } else if ((implied_monitor_start <= *stop_index) && safe_str_eq(task, CRMD_ACTION_STATUS)) {
2170  const char *rc = crm_element_value(rsc_op, XML_LRM_ATTR_RC);
2171 
2172  if (safe_str_eq(rc, "0") || safe_str_eq(rc, "8")) {
2173  implied_monitor_start = counter;
2174  }
2175  } else if (safe_str_eq(task, CRMD_ACTION_PROMOTE) || safe_str_eq(task, CRMD_ACTION_DEMOTE)) {
2176  implied_master_start = counter;
2177  }
2178  }
2179 
2180  if (*start_index == -1) {
2181  if (implied_master_start != -1) {
2182  *start_index = implied_master_start;
2183  } else if (implied_monitor_start != -1) {
2184  *start_index = implied_monitor_start;
2185  }
2186  }
2187 }
2188 
2189 static resource_t *
2190 unpack_lrm_rsc_state(node_t * node, xmlNode * rsc_entry, pe_working_set_t * data_set)
2191 {
2192  GListPtr gIter = NULL;
2193  int stop_index = -1;
2194  int start_index = -1;
2195  enum rsc_role_e req_role = RSC_ROLE_UNKNOWN;
2196 
2197  const char *task = NULL;
2198  const char *rsc_id = crm_element_value(rsc_entry, XML_ATTR_ID);
2199 
2200  resource_t *rsc = NULL;
2201  GListPtr op_list = NULL;
2202  GListPtr sorted_op_list = NULL;
2203 
2204  xmlNode *migrate_op = NULL;
2205  xmlNode *rsc_op = NULL;
2206  xmlNode *last_failure = NULL;
2207 
2208  enum action_fail_response on_fail = FALSE;
2209  enum rsc_role_e saved_role = RSC_ROLE_UNKNOWN;
2210 
2211  crm_trace("[%s] Processing %s on %s",
2212  crm_element_name(rsc_entry), rsc_id, node->details->uname);
2213 
2214  /* extract operations */
2215  op_list = NULL;
2216  sorted_op_list = NULL;
2217 
2218  for (rsc_op = __xml_first_child(rsc_entry); rsc_op != NULL; rsc_op = __xml_next_element(rsc_op)) {
2219  if (crm_str_eq((const char *)rsc_op->name, XML_LRM_TAG_RSC_OP, TRUE)) {
2220  op_list = g_list_prepend(op_list, rsc_op);
2221  }
2222  }
2223 
2224  if (op_list == NULL) {
2225  /* if there are no operations, there is nothing to do */
2226  return NULL;
2227  }
2228 
2229  /* find the resource */
2230  rsc = unpack_find_resource(data_set, node, rsc_id, rsc_entry);
2231  if (rsc == NULL) {
2232  rsc = process_orphan_resource(rsc_entry, node, data_set);
2233  }
2234  CRM_ASSERT(rsc != NULL);
2235 
2236  /* process operations */
2237  saved_role = rsc->role;
2238  on_fail = action_fail_ignore;
2239  rsc->role = RSC_ROLE_UNKNOWN;
2240  sorted_op_list = g_list_sort(op_list, sort_op_by_callid);
2241 
2242  for (gIter = sorted_op_list; gIter != NULL; gIter = gIter->next) {
2243  xmlNode *rsc_op = (xmlNode *) gIter->data;
2244 
2245  task = crm_element_value(rsc_op, XML_LRM_ATTR_TASK);
2246  if (safe_str_eq(task, CRMD_ACTION_MIGRATED)) {
2247  migrate_op = rsc_op;
2248  }
2249 
2250  unpack_rsc_op(rsc, node, rsc_op, &last_failure, &on_fail, data_set);
2251  }
2252 
2253  /* create active recurring operations as optional */
2254  calculate_active_ops(sorted_op_list, &start_index, &stop_index);
2255  process_recurring(node, rsc, start_index, stop_index, sorted_op_list, data_set);
2256 
2257  /* no need to free the contents */
2258  g_list_free(sorted_op_list);
2259 
2260  process_rsc_state(rsc, node, on_fail, migrate_op, data_set);
2261 
2262  if (get_target_role(rsc, &req_role)) {
2263  if (rsc->next_role == RSC_ROLE_UNKNOWN || req_role < rsc->next_role) {
2264  pe_rsc_debug(rsc, "%s: Overwriting calculated next role %s"
2265  " with requested next role %s",
2266  rsc->id, role2text(rsc->next_role), role2text(req_role));
2267  rsc->next_role = req_role;
2268 
2269  } else if (req_role > rsc->next_role) {
2270  pe_rsc_info(rsc, "%s: Not overwriting calculated next role %s"
2271  " with requested next role %s",
2272  rsc->id, role2text(rsc->next_role), role2text(req_role));
2273  }
2274  }
2275 
2276  if (saved_role > rsc->role) {
2277  rsc->role = saved_role;
2278  }
2279 
2280  return rsc;
2281 }
2282 
2283 static void
2284 handle_orphaned_container_fillers(xmlNode * lrm_rsc_list, pe_working_set_t * data_set)
2285 {
2286  xmlNode *rsc_entry = NULL;
2287  for (rsc_entry = __xml_first_child(lrm_rsc_list); rsc_entry != NULL;
2288  rsc_entry = __xml_next_element(rsc_entry)) {
2289 
2290  resource_t *rsc;
2291  resource_t *container;
2292  const char *rsc_id;
2293  const char *container_id;
2294 
2295  if (safe_str_neq((const char *)rsc_entry->name, XML_LRM_TAG_RESOURCE)) {
2296  continue;
2297  }
2298 
2299  container_id = crm_element_value(rsc_entry, XML_RSC_ATTR_CONTAINER);
2300  rsc_id = crm_element_value(rsc_entry, XML_ATTR_ID);
2301  if (container_id == NULL || rsc_id == NULL) {
2302  continue;
2303  }
2304 
2305  container = pe_find_resource(data_set->resources, container_id);
2306  if (container == NULL) {
2307  continue;
2308  }
2309 
2310  rsc = pe_find_resource(data_set->resources, rsc_id);
2311  if (rsc == NULL ||
2312  is_set(rsc->flags, pe_rsc_orphan_container_filler) == FALSE ||
2313  rsc->container != NULL) {
2314  continue;
2315  }
2316 
2317  pe_rsc_trace(rsc, "Mapped orphaned rsc %s's container to %s", rsc->id, container_id);
2318  rsc->container = container;
2319  container->fillers = g_list_append(container->fillers, rsc);
2320  }
2321 }
2322 
2323 gboolean
2324 unpack_lrm_resources(node_t * node, xmlNode * lrm_rsc_list, pe_working_set_t * data_set)
2325 {
2326  xmlNode *rsc_entry = NULL;
2327  gboolean found_orphaned_container_filler = FALSE;
2328 
2329  CRM_CHECK(node != NULL, return FALSE);
2330 
2331  crm_trace("Unpacking resources on %s", node->details->uname);
2332 
2333  for (rsc_entry = __xml_first_child(lrm_rsc_list); rsc_entry != NULL;
2334  rsc_entry = __xml_next_element(rsc_entry)) {
2335 
2336  if (crm_str_eq((const char *)rsc_entry->name, XML_LRM_TAG_RESOURCE, TRUE)) {
2337  resource_t *rsc = unpack_lrm_rsc_state(node, rsc_entry, data_set);
2338  if (!rsc) {
2339  continue;
2340  }
2341  if (is_set(rsc->flags, pe_rsc_orphan_container_filler)) {
2342  found_orphaned_container_filler = TRUE;
2343  }
2344  }
2345  }
2346 
2347  /* now that all the resource state has been unpacked for this node
2348  * we have to go back and map any orphaned container fillers to their
2349  * container resource */
2350  if (found_orphaned_container_filler) {
2351  handle_orphaned_container_fillers(lrm_rsc_list, data_set);
2352  }
2353  return TRUE;
2354 }
2355 
2356 static void
2357 set_active(resource_t * rsc)
2358 {
2359  resource_t *top = uber_parent(rsc);
2360 
2361  if (top && top->variant == pe_master) {
2362  rsc->role = RSC_ROLE_SLAVE;
2363  } else {
2364  rsc->role = RSC_ROLE_STARTED;
2365  }
2366 }
2367 
2368 static void
2369 set_node_score(gpointer key, gpointer value, gpointer user_data)
2370 {
2371  node_t *node = value;
2372  int *score = user_data;
2373 
2374  node->weight = *score;
2375 }
2376 
2377 #define STATUS_PATH_MAX 1024
2378 static xmlNode *
2379 find_lrm_op(const char *resource, const char *op, const char *node, const char *source,
2380  pe_working_set_t * data_set)
2381 {
2382  int offset = 0;
2383  char xpath[STATUS_PATH_MAX];
2384 
2385  offset += snprintf(xpath + offset, STATUS_PATH_MAX - offset, "//node_state[@uname='%s']", node);
2386  offset +=
2387  snprintf(xpath + offset, STATUS_PATH_MAX - offset, "//" XML_LRM_TAG_RESOURCE "[@id='%s']",
2388  resource);
2389 
2390  /* Need to check against transition_magic too? */
2391  if (source && safe_str_eq(op, CRMD_ACTION_MIGRATE)) {
2392  offset +=
2393  snprintf(xpath + offset, STATUS_PATH_MAX - offset,
2394  "/" XML_LRM_TAG_RSC_OP "[@operation='%s' and @migrate_target='%s']", op,
2395  source);
2396  } else if (source && safe_str_eq(op, CRMD_ACTION_MIGRATED)) {
2397  offset +=
2398  snprintf(xpath + offset, STATUS_PATH_MAX - offset,
2399  "/" XML_LRM_TAG_RSC_OP "[@operation='%s' and @migrate_source='%s']", op,
2400  source);
2401  } else {
2402  offset +=
2403  snprintf(xpath + offset, STATUS_PATH_MAX - offset,
2404  "/" XML_LRM_TAG_RSC_OP "[@operation='%s']", op);
2405  }
2406 
2407  CRM_LOG_ASSERT(offset > 0);
2408  return get_xpath_object(xpath, data_set->input, LOG_DEBUG);
2409 }
2410 
2411 static void
2412 unpack_rsc_migration(resource_t *rsc, node_t *node, xmlNode *xml_op, pe_working_set_t * data_set)
2413 {
2414 
2415  /*
2416  * The normal sequence is (now): migrate_to(Src) -> migrate_from(Tgt) -> stop(Src)
2417  *
2418  * So if a migrate_to is followed by a stop, then we don't need to care what
2419  * happened on the target node
2420  *
2421  * Without the stop, we need to look for a successful migrate_from.
2422  * This would also imply we're no longer running on the source
2423  *
2424  * Without the stop, and without a migrate_from op we make sure the resource
2425  * gets stopped on both source and target (assuming the target is up)
2426  *
2427  */
2428  int stop_id = 0;
2429  int task_id = 0;
2430  xmlNode *stop_op =
2431  find_lrm_op(rsc->id, CRMD_ACTION_STOP, node->details->id, NULL, data_set);
2432 
2433  if (stop_op) {
2434  crm_element_value_int(stop_op, XML_LRM_ATTR_CALLID, &stop_id);
2435  }
2436 
2437  crm_element_value_int(xml_op, XML_LRM_ATTR_CALLID, &task_id);
2438 
2439  if (stop_op == NULL || stop_id < task_id) {
2440  int from_rc = 0, from_status = 0;
2441  const char *migrate_source =
2443  const char *migrate_target =
2445 
2446  node_t *target = pe_find_node(data_set->nodes, migrate_target);
2447  node_t *source = pe_find_node(data_set->nodes, migrate_source);
2448  xmlNode *migrate_from =
2449  find_lrm_op(rsc->id, CRMD_ACTION_MIGRATED, migrate_target, migrate_source,
2450  data_set);
2451 
2452  rsc->role = RSC_ROLE_STARTED; /* can be master? */
2453  if (migrate_from) {
2454  crm_element_value_int(migrate_from, XML_LRM_ATTR_RC, &from_rc);
2455  crm_element_value_int(migrate_from, XML_LRM_ATTR_OPSTATUS, &from_status);
2456  pe_rsc_trace(rsc, "%s op on %s exited with status=%d, rc=%d",
2457  ID(migrate_from), migrate_target, from_status, from_rc);
2458  }
2459 
2460  if (migrate_from && from_rc == PCMK_OCF_OK
2461  && from_status == PCMK_LRM_OP_DONE) {
2462  pe_rsc_trace(rsc, "Detected dangling migration op: %s on %s", ID(xml_op),
2463  migrate_source);
2464 
2465  /* all good
2466  * just need to arrange for the stop action to get sent
2467  * but _without_ affecting the target somehow
2468  */
2469  rsc->role = RSC_ROLE_STOPPED;
2470  rsc->dangling_migrations = g_list_prepend(rsc->dangling_migrations, node);
2471 
2472  } else if (migrate_from) { /* Failed */
2473  if (target && target->details->online) {
2474  pe_rsc_trace(rsc, "Marking active on %s %p %d", migrate_target, target,
2475  target->details->online);
2476  native_add_running(rsc, target, data_set);
2477  }
2478 
2479  } else { /* Pending or complete but erased */
2480  if (target && target->details->online) {
2481  pe_rsc_trace(rsc, "Marking active on %s %p %d", migrate_target, target,
2482  target->details->online);
2483 
2484  native_add_running(rsc, target, data_set);
2485  if (source && source->details->online) {
2486  /* If we make it here we have a partial migration. The migrate_to
2487  * has completed but the migrate_from on the target has not. Hold on
2488  * to the target and source on the resource. Later on if we detect that
2489  * the resource is still going to run on that target, we may continue
2490  * the migration */
2491  rsc->partial_migration_target = target;
2492  rsc->partial_migration_source = source;
2493  }
2494  } else {
2495  /* Consider it failed here - forces a restart, prevents migration */
2496  set_bit(rsc->flags, pe_rsc_failed);
2498  }
2499  }
2500  }
2501 }
2502 
2503 static void
2504 unpack_rsc_migration_failure(resource_t *rsc, node_t *node, xmlNode *xml_op, pe_working_set_t * data_set)
2505 {
2506  const char *task = crm_element_value(xml_op, XML_LRM_ATTR_TASK);
2507 
2508  CRM_ASSERT(rsc);
2509  if (safe_str_eq(task, CRMD_ACTION_MIGRATED)) {
2510  int stop_id = 0;
2511  int migrate_id = 0;
2512  const char *migrate_source = crm_element_value(xml_op, XML_LRM_ATTR_MIGRATE_SOURCE);
2513  const char *migrate_target = crm_element_value(xml_op, XML_LRM_ATTR_MIGRATE_TARGET);
2514 
2515  xmlNode *stop_op =
2516  find_lrm_op(rsc->id, CRMD_ACTION_STOP, migrate_source, NULL, data_set);
2517  xmlNode *migrate_op =
2518  find_lrm_op(rsc->id, CRMD_ACTION_MIGRATE, migrate_source, migrate_target,
2519  data_set);
2520 
2521  if (stop_op) {
2522  crm_element_value_int(stop_op, XML_LRM_ATTR_CALLID, &stop_id);
2523  }
2524  if (migrate_op) {
2525  crm_element_value_int(migrate_op, XML_LRM_ATTR_CALLID, &migrate_id);
2526  }
2527 
2528  /* Get our state right */
2529  rsc->role = RSC_ROLE_STARTED; /* can be master? */
2530 
2531  if (stop_op == NULL || stop_id < migrate_id) {
2532  node_t *source = pe_find_node(data_set->nodes, migrate_source);
2533 
2534  if (source && source->details->online) {
2535  native_add_running(rsc, source, data_set);
2536  }
2537  }
2538 
2539  } else if (safe_str_eq(task, CRMD_ACTION_MIGRATE)) {
2540  int stop_id = 0;
2541  int migrate_id = 0;
2542  const char *migrate_source = crm_element_value(xml_op, XML_LRM_ATTR_MIGRATE_SOURCE);
2543  const char *migrate_target = crm_element_value(xml_op, XML_LRM_ATTR_MIGRATE_TARGET);
2544 
2545  xmlNode *stop_op =
2546  find_lrm_op(rsc->id, CRMD_ACTION_STOP, migrate_target, NULL, data_set);
2547  xmlNode *migrate_op =
2548  find_lrm_op(rsc->id, CRMD_ACTION_MIGRATED, migrate_target, migrate_source,
2549  data_set);
2550 
2551  if (stop_op) {
2552  crm_element_value_int(stop_op, XML_LRM_ATTR_CALLID, &stop_id);
2553  }
2554  if (migrate_op) {
2555  crm_element_value_int(migrate_op, XML_LRM_ATTR_CALLID, &migrate_id);
2556  }
2557 
2558  /* Get our state right */
2559  rsc->role = RSC_ROLE_STARTED; /* can be master? */
2560 
2561  if (stop_op == NULL || stop_id < migrate_id) {
2562  node_t *target = pe_find_node(data_set->nodes, migrate_target);
2563 
2564  pe_rsc_trace(rsc, "Stop: %p %d, Migrated: %p %d", stop_op, stop_id, migrate_op,
2565  migrate_id);
2566  if (target && target->details->online) {
2567  native_add_running(rsc, target, data_set);
2568  }
2569 
2570  } else if (migrate_op == NULL) {
2571  /* Make sure it gets cleaned up, the stop may pre-date the migrate_from */
2572  rsc->dangling_migrations = g_list_prepend(rsc->dangling_migrations, node);
2573  }
2574  }
2575 }
2576 
2577 static void
2578 record_failed_op(xmlNode *op, node_t* node, resource_t *rsc, pe_working_set_t * data_set)
2579 {
2580  xmlNode *xIter = NULL;
2581  const char *op_key = crm_element_value(op, XML_LRM_ATTR_TASK_KEY);
2582 
2583  if (node->details->online == FALSE) {
2584  return;
2585  }
2586 
2587  for (xIter = data_set->failed->children; xIter; xIter = xIter->next) {
2588  const char *key = crm_element_value(xIter, XML_LRM_ATTR_TASK_KEY);
2589  const char *uname = crm_element_value(xIter, XML_ATTR_UNAME);
2590 
2591  if(safe_str_eq(op_key, key) && safe_str_eq(uname, node->details->uname)) {
2592  crm_trace("Skipping duplicate entry %s on %s", op_key, node->details->uname);
2593  return;
2594  }
2595  }
2596 
2597  crm_trace("Adding entry %s on %s", op_key, node->details->uname);
2598  crm_xml_add(op, XML_ATTR_UNAME, node->details->uname);
2599  crm_xml_add(op, XML_LRM_ATTR_RSCID, rsc->id);
2600  add_node_copy(data_set->failed, op);
2601 }
2602 
2603 static const char *get_op_key(xmlNode *xml_op)
2604 {
2605  const char *key = crm_element_value(xml_op, XML_LRM_ATTR_TASK_KEY);
2606  if(key == NULL) {
2607  key = ID(xml_op);
2608  }
2609  return key;
2610 }
2611 
2612 static void
2613 unpack_rsc_op_failure(resource_t * rsc, node_t * node, int rc, xmlNode * xml_op, xmlNode ** last_failure,
2614  enum action_fail_response * on_fail, pe_working_set_t * data_set)
2615 {
2616  int interval = 0;
2617  bool is_probe = FALSE;
2618  action_t *action = NULL;
2619 
2620  const char *key = get_op_key(xml_op);
2621  const char *task = crm_element_value(xml_op, XML_LRM_ATTR_TASK);
2622  const char *op_version = crm_element_value(xml_op, XML_ATTR_CRM_VERSION);
2623 
2624  CRM_ASSERT(rsc);
2625 
2626  *last_failure = xml_op;
2627 
2628  crm_element_value_int(xml_op, XML_LRM_ATTR_INTERVAL, &interval);
2629  if(interval == 0 && safe_str_eq(task, CRMD_ACTION_STATUS)) {
2630  is_probe = TRUE;
2631  pe_rsc_trace(rsc, "is a probe: %s", key);
2632  }
2633 
2634  if (rc != PCMK_OCF_NOT_INSTALLED || is_set(data_set->flags, pe_flag_symmetric_cluster)) {
2635  crm_warn("Processing failed op %s for %s on %s: %s (%d)",
2636  task, rsc->id, node->details->uname, services_ocf_exitcode_str(rc),
2637  rc);
2638 
2639  record_failed_op(xml_op, node, rsc, data_set);
2640 
2641  } else {
2642  crm_trace("Processing failed op %s for %s on %s: %s (%d)",
2643  task, rsc->id, node->details->uname, services_ocf_exitcode_str(rc),
2644  rc);
2645  }
2646 
2647  action = custom_action(rsc, strdup(key), task, NULL, TRUE, FALSE, data_set);
2648  if ((action->on_fail <= action_fail_fence && *on_fail < action->on_fail) ||
2649  (action->on_fail == action_fail_reset_remote && *on_fail <= action_fail_recover) ||
2650  (action->on_fail == action_fail_restart_container && *on_fail <= action_fail_recover) ||
2651  (*on_fail == action_fail_restart_container && action->on_fail >= action_fail_migrate)) {
2652  pe_rsc_trace(rsc, "on-fail %s -> %s for %s (%s)", fail2text(*on_fail),
2653  fail2text(action->on_fail), action->uuid, key);
2654  *on_fail = action->on_fail;
2655  }
2656 
2657  if (safe_str_eq(task, CRMD_ACTION_STOP)) {
2658  resource_location(rsc, node, -INFINITY, "__stop_fail__", data_set);
2659 
2660  } else if (safe_str_eq(task, CRMD_ACTION_MIGRATE) || safe_str_eq(task, CRMD_ACTION_MIGRATED)) {
2661  unpack_rsc_migration_failure(rsc, node, xml_op, data_set);
2662 
2663  } else if (safe_str_eq(task, CRMD_ACTION_PROMOTE)) {
2664  rsc->role = RSC_ROLE_MASTER;
2665 
2666  } else if (safe_str_eq(task, CRMD_ACTION_DEMOTE)) {
2667  /*
2668  * staying in role=master ends up putting the PE/TE into a loop
2669  * setting role=slave is not dangerous because no master will be
2670  * promoted until the failed resource has been fully stopped
2671  */
2672  if (action->on_fail == action_fail_block) {
2673  rsc->role = RSC_ROLE_MASTER;
2674  rsc->next_role = RSC_ROLE_STOPPED;
2675 
2676  } else if(rc == PCMK_OCF_NOT_RUNNING) {
2677  rsc->role = RSC_ROLE_STOPPED;
2678 
2679  } else {
2680  crm_warn("Forcing %s to stop after a failed demote action", rsc->id);
2681  rsc->role = RSC_ROLE_SLAVE;
2682  rsc->next_role = RSC_ROLE_STOPPED;
2683  }
2684 
2685  } else if (compare_version("2.0", op_version) > 0 && safe_str_eq(task, CRMD_ACTION_START)) {
2686  crm_warn("Compatibility handling for failed op %s on %s", key, node->details->uname);
2687  resource_location(rsc, node, -INFINITY, "__legacy_start__", data_set);
2688  }
2689 
2690  if(is_probe && rc == PCMK_OCF_NOT_INSTALLED) {
2691  /* leave stopped */
2692  pe_rsc_trace(rsc, "Leaving %s stopped", rsc->id);
2693  rsc->role = RSC_ROLE_STOPPED;
2694 
2695  } else if (rsc->role < RSC_ROLE_STARTED) {
2696  pe_rsc_trace(rsc, "Setting %s active", rsc->id);
2697  set_active(rsc);
2698  }
2699 
2700  pe_rsc_trace(rsc, "Resource %s: role=%s, unclean=%s, on_fail=%s, fail_role=%s",
2701  rsc->id, role2text(rsc->role),
2702  node->details->unclean ? "true" : "false",
2703  fail2text(action->on_fail), role2text(action->fail_role));
2704 
2705  if (action->fail_role != RSC_ROLE_STARTED && rsc->next_role < action->fail_role) {
2706  rsc->next_role = action->fail_role;
2707  }
2708 
2709  if (action->fail_role == RSC_ROLE_STOPPED) {
2710  int score = -INFINITY;
2711 
2712  resource_t *fail_rsc = rsc;
2713 
2714  if (fail_rsc->parent) {
2715  resource_t *parent = uber_parent(fail_rsc);
2716 
2717  if (pe_rsc_is_clone(parent)
2718  && is_not_set(parent->flags, pe_rsc_unique)) {
2719  /* for clone and master resources, if a child fails on an operation
2720  * with on-fail = stop, all the resources fail. Do this by preventing
2721  * the parent from coming up again. */
2722  fail_rsc = parent;
2723  }
2724  }
2725  crm_warn("Making sure %s doesn't come up again", fail_rsc->id);
2726  /* make sure it doesn't come up again */
2727  g_hash_table_destroy(fail_rsc->allowed_nodes);
2728  fail_rsc->allowed_nodes = node_hash_from_list(data_set->nodes);
2729  g_hash_table_foreach(fail_rsc->allowed_nodes, set_node_score, &score);
2730  }
2731 
2732  pe_free_action(action);
2733 }
2734 
2735 static int
2736 determine_op_status(
2737  resource_t *rsc, int rc, int target_rc, node_t * node, xmlNode * xml_op, enum action_fail_response * on_fail, pe_working_set_t * data_set)
2738 {
2739  int interval = 0;
2740  int result = PCMK_LRM_OP_DONE;
2741 
2742  const char *key = get_op_key(xml_op);
2743  const char *task = crm_element_value(xml_op, XML_LRM_ATTR_TASK);
2744 
2745  bool is_probe = FALSE;
2746 
2747  CRM_ASSERT(rsc);
2748  crm_element_value_int(xml_op, XML_LRM_ATTR_INTERVAL, &interval);
2749  if (interval == 0 && safe_str_eq(task, CRMD_ACTION_STATUS)) {
2750  is_probe = TRUE;
2751  }
2752 
2753  if (target_rc >= 0 && target_rc != rc) {
2754  result = PCMK_LRM_OP_ERROR;
2755  pe_rsc_debug(rsc, "%s on %s returned '%s' (%d) instead of the expected value: '%s' (%d)",
2756  key, node->details->uname,
2757  services_ocf_exitcode_str(rc), rc,
2758  services_ocf_exitcode_str(target_rc), target_rc);
2759  }
2760 
2761  /* we could clean this up significantly except for old LRMs and CRMs that
2762  * didn't include target_rc and liked to remap status
2763  */
2764  switch (rc) {
2765  case PCMK_OCF_OK:
2766  if (is_probe && target_rc == 7) {
2767  result = PCMK_LRM_OP_DONE;
2768  pe_rsc_info(rsc, "Operation %s found resource %s active on %s",
2769  task, rsc->id, node->details->uname);
2770 
2771  /* legacy code for pre-0.6.5 operations */
2772  } else if (target_rc < 0 && interval > 0 && rsc->role == RSC_ROLE_MASTER) {
2773  /* catch status ops that return 0 instead of 8 while they
2774  * are supposed to be in master mode
2775  */
2776  result = PCMK_LRM_OP_ERROR;
2777  }
2778  break;
2779 
2780  case PCMK_OCF_NOT_RUNNING:
2781  if (is_probe || target_rc == rc || is_not_set(rsc->flags, pe_rsc_managed)) {
2782  result = PCMK_LRM_OP_DONE;
2783  rsc->role = RSC_ROLE_STOPPED;
2784 
2785  /* clear any previous failure actions */
2786  *on_fail = action_fail_ignore;
2787  rsc->next_role = RSC_ROLE_UNKNOWN;
2788 
2789  } else if (safe_str_neq(task, CRMD_ACTION_STOP)) {
2790  result = PCMK_LRM_OP_ERROR;
2791  }
2792  break;
2793 
2795  if (is_probe) {
2796  result = PCMK_LRM_OP_DONE;
2797  pe_rsc_info(rsc, "Operation %s found resource %s active in master mode on %s",
2798  task, rsc->id, node->details->uname);
2799 
2800  } else if (target_rc == rc) {
2801  /* nothing to do */
2802 
2803  } else if (target_rc >= 0) {
2804  result = PCMK_LRM_OP_ERROR;
2805 
2806  /* legacy code for pre-0.6.5 operations */
2807  } else if (safe_str_neq(task, CRMD_ACTION_STATUS)
2808  || rsc->role != RSC_ROLE_MASTER) {
2809  result = PCMK_LRM_OP_ERROR;
2810  if (rsc->role != RSC_ROLE_MASTER) {
2811  crm_err("%s reported %s in master mode on %s",
2812  key, rsc->id, node->details->uname);
2813  }
2814  }
2815  rsc->role = RSC_ROLE_MASTER;
2816  break;
2817 
2820  rsc->role = RSC_ROLE_MASTER;
2821  result = PCMK_LRM_OP_ERROR;
2822  break;
2823 
2825  result = PCMK_LRM_OP_ERROR_FATAL;
2826  break;
2827 
2832  if (rc == PCMK_OCF_UNIMPLEMENT_FEATURE && interval > 0) {
2833  result = PCMK_LRM_OP_NOTSUPPORTED;
2834  break;
2835 
2836  } else if (pe_can_fence(data_set, node) == FALSE
2837  && safe_str_eq(task, CRMD_ACTION_STOP)) {
2838  /* If a stop fails and we can't fence, there's nothing else we can do */
2839  pe_proc_err("No further recovery can be attempted for %s: %s action failed with '%s' (%d)",
2840  rsc->id, task, services_ocf_exitcode_str(rc), rc);
2842  set_bit(rsc->flags, pe_rsc_block);
2843  }
2844  result = PCMK_LRM_OP_ERROR_HARD;
2845  break;
2846 
2847  default:
2848  if (result == PCMK_LRM_OP_DONE) {
2849  crm_info("Treating %s (rc=%d) on %s as an ERROR",
2850  key, rc, node->details->uname);
2851  result = PCMK_LRM_OP_ERROR;
2852  }
2853  }
2854 
2855  return result;
2856 }
2857 
2858 static bool check_operation_expiry(resource_t *rsc, node_t *node, int rc, xmlNode *xml_op, pe_working_set_t * data_set)
2859 {
2860  bool expired = FALSE;
2861  time_t last_failure = 0;
2862  int interval = 0;
2863  int failure_timeout = rsc->failure_timeout;
2864  const char *key = get_op_key(xml_op);
2865  const char *task = crm_element_value(xml_op, XML_LRM_ATTR_TASK);
2866  const char *clear_reason = NULL;
2867 
2868  /* clearing recurring monitor operation failures automatically
2869  * needs to be carefully considered */
2870  if (safe_str_eq(crm_element_value(xml_op, XML_LRM_ATTR_TASK), "monitor") &&
2872 
2873  /* TODO, in the future we should consider not clearing recurring monitor
2874  * op failures unless the last action for a resource was a "stop" action.
2875  * otherwise it is possible that clearing the monitor failure will result
2876  * in the resource being in an undeterministic state.
2877  *
2878  * For now we handle this potential undeterministic condition for remote
2879  * node connection resources by not clearing a recurring monitor op failure
2880  * until after the node has been fenced. */
2881 
2882  if (is_set(data_set->flags, pe_flag_stonith_enabled) &&
2883  (rsc->remote_reconnect_interval)) {
2884 
2885  node_t *remote_node = pe_find_node(data_set->nodes, rsc->id);
2886  if (remote_node && remote_node->details->remote_was_fenced == 0) {
2887  if (strstr(ID(xml_op), "last_failure")) {
2888  crm_info("Waiting to clear monitor failure for remote node %s until fencing has occurred", rsc->id);
2889  }
2890  /* disabling failure timeout for this operation because we believe
2891  * fencing of the remote node should occur first. */
2892  failure_timeout = 0;
2893  }
2894  }
2895  }
2896 
2897  if (failure_timeout > 0) {
2898  int last_run = 0;
2899 
2900  if (crm_element_value_int(xml_op, XML_RSC_OP_LAST_CHANGE, &last_run) == 0) {
2901  time_t now = get_effective_time(data_set);
2902 
2903  if (now > (last_run + failure_timeout)) {
2904  expired = TRUE;
2905  }
2906  }
2907  }
2908 
2909  if (expired) {
2910  if (failure_timeout > 0) {
2911  if (pe_get_failcount(node, rsc, &last_failure, pe_fc_default,
2912  xml_op, data_set)) {
2913 
2914  if (pe_get_failcount(node, rsc, &last_failure, pe_fc_effective,
2915  xml_op, data_set) == 0) {
2916  clear_reason = "it expired";
2917  } else {
2918  expired = FALSE;
2919  }
2920 
2921  } else if (rsc->remote_reconnect_interval && strstr(ID(xml_op), "last_failure")) {
2922  /* always clear last failure when reconnect interval is set */
2923  clear_reason = "reconnect interval is set";
2924  }
2925  }
2926 
2927  } else if (strstr(ID(xml_op), "last_failure") &&
2928  ((strcmp(task, "start") == 0) || (strcmp(task, "monitor") == 0))) {
2929 
2930  op_digest_cache_t *digest_data = NULL;
2931 
2932  digest_data = rsc_action_digest_cmp(rsc, xml_op, node, data_set);
2933 
2934  if (digest_data->rc == RSC_DIGEST_UNKNOWN) {
2935  crm_trace("rsc op %s/%s on node %s does not have a op digest to compare against", rsc->id,
2936  key, node->details->id);
2937  } else if(container_fix_remote_addr(rsc) && digest_data->rc != RSC_DIGEST_MATCH) {
2938  // We can't sanely check the changing 'addr' attribute. Yet
2939  crm_trace("Ignoring rsc op %s/%s on node %s", rsc->id, key, node->details->id);
2940 
2941  } else if (digest_data->rc != RSC_DIGEST_MATCH) {
2942  clear_reason = "resource parameters have changed";
2943  }
2944  }
2945 
2946  if (clear_reason != NULL) {
2947  char *key = generate_op_key(rsc->id, CRM_OP_CLEAR_FAILCOUNT, 0);
2948  action_t *clear_op = custom_action(rsc, key, CRM_OP_CLEAR_FAILCOUNT,
2949  node, FALSE, TRUE, data_set);
2950 
2952 
2953  crm_notice("Clearing failure of %s on %s because %s " CRM_XS " %s",
2954  rsc->id, node->details->uname, clear_reason, clear_op->uuid);
2955  }
2956 
2957  crm_element_value_int(xml_op, XML_LRM_ATTR_INTERVAL, &interval);
2958  if(expired && interval == 0 && safe_str_eq(task, CRMD_ACTION_STATUS)) {
2959  switch(rc) {
2960  case PCMK_OCF_OK:
2961  case PCMK_OCF_NOT_RUNNING:
2963  case PCMK_OCF_DEGRADED:
2965  /* Don't expire probes that return these values */
2966  expired = FALSE;
2967  break;
2968  }
2969  }
2970 
2971  return expired;
2972 }
2973 
2974 int get_target_rc(xmlNode *xml_op)
2975 {
2976  int dummy = 0;
2977  int target_rc = 0;
2978  char *dummy_string = NULL;
2979  const char *key = crm_element_value(xml_op, XML_ATTR_TRANSITION_KEY);
2980  if (key == NULL) {
2981  return -1;
2982  }
2983 
2984  decode_transition_key(key, &dummy_string, &dummy, &dummy, &target_rc);
2985  free(dummy_string);
2986 
2987  return target_rc;
2988 }
2989 
2990 static enum action_fail_response
2991 get_action_on_fail(resource_t *rsc, const char *key, const char *task, pe_working_set_t * data_set)
2992 {
2993  int result = action_fail_recover;
2994  action_t *action = custom_action(rsc, strdup(key), task, NULL, TRUE, FALSE, data_set);
2995 
2996  result = action->on_fail;
2997  pe_free_action(action);
2998 
2999  return result;
3000 }
3001 
3002 static void
3003 update_resource_state(resource_t * rsc, node_t * node, xmlNode * xml_op, const char * task, int rc,
3004  xmlNode * last_failure, enum action_fail_response * on_fail, pe_working_set_t * data_set)
3005 {
3006  gboolean clear_past_failure = FALSE;
3007 
3008  CRM_ASSERT(rsc);
3009  CRM_ASSERT(xml_op);
3010 
3011  if (rc == PCMK_OCF_NOT_RUNNING) {
3012  clear_past_failure = TRUE;
3013 
3014  } else if (rc == PCMK_OCF_NOT_INSTALLED) {
3015  rsc->role = RSC_ROLE_STOPPED;
3016 
3017  } else if (safe_str_eq(task, CRMD_ACTION_STATUS)) {
3018  if (last_failure) {
3019  const char *op_key = get_op_key(xml_op);
3020  const char *last_failure_key = get_op_key(last_failure);
3021 
3022  if (safe_str_eq(op_key, last_failure_key)) {
3023  clear_past_failure = TRUE;
3024  }
3025  }
3026 
3027  if (rsc->role < RSC_ROLE_STARTED) {
3028  set_active(rsc);
3029  }
3030 
3031  } else if (safe_str_eq(task, CRMD_ACTION_START)) {
3032  rsc->role = RSC_ROLE_STARTED;
3033  clear_past_failure = TRUE;
3034 
3035  } else if (safe_str_eq(task, CRMD_ACTION_STOP)) {
3036  rsc->role = RSC_ROLE_STOPPED;
3037  clear_past_failure = TRUE;
3038 
3039  } else if (safe_str_eq(task, CRMD_ACTION_PROMOTE)) {
3040  rsc->role = RSC_ROLE_MASTER;
3041  clear_past_failure = TRUE;
3042 
3043  } else if (safe_str_eq(task, CRMD_ACTION_DEMOTE)) {
3044  /* Demote from Master does not clear an error */
3045  rsc->role = RSC_ROLE_SLAVE;
3046 
3047  } else if (safe_str_eq(task, CRMD_ACTION_MIGRATED)) {
3048  rsc->role = RSC_ROLE_STARTED;
3049  clear_past_failure = TRUE;
3050 
3051  } else if (safe_str_eq(task, CRMD_ACTION_MIGRATE)) {
3052  unpack_rsc_migration(rsc, node, xml_op, data_set);
3053 
3054  } else if (rsc->role < RSC_ROLE_STARTED) {
3055  pe_rsc_trace(rsc, "%s active on %s", rsc->id, node->details->uname);
3056  set_active(rsc);
3057  }
3058 
3059  /* clear any previous failure actions */
3060  if (clear_past_failure) {
3061  switch (*on_fail) {
3062  case action_fail_stop:
3063  case action_fail_fence:
3064  case action_fail_migrate:
3065  case action_fail_standby:
3066  pe_rsc_trace(rsc, "%s.%s is not cleared by a completed stop",
3067  rsc->id, fail2text(*on_fail));
3068  break;
3069 
3070  case action_fail_block:
3071  case action_fail_ignore:
3072  case action_fail_recover:
3074  *on_fail = action_fail_ignore;
3075  rsc->next_role = RSC_ROLE_UNKNOWN;
3076  break;
3078  if (rsc->remote_reconnect_interval == 0) {
3079  /* when reconnect delay is not in use, the connection is allowed
3080  * to start again after the remote node is fenced and completely
3081  * stopped. Otherwise, with reconnect delay we wait for the failure
3082  * to be cleared entirely before reconnected can be attempted. */
3083  *on_fail = action_fail_ignore;
3084  rsc->next_role = RSC_ROLE_UNKNOWN;
3085  }
3086  break;
3087  }
3088  }
3089 }
3090 
3091 
3092 gboolean
3093 unpack_rsc_op(resource_t * rsc, node_t * node, xmlNode * xml_op, xmlNode ** last_failure,
3094  enum action_fail_response * on_fail, pe_working_set_t * data_set)
3095 {
3096  int task_id = 0;
3097 
3098  const char *key = NULL;
3099  const char *task = NULL;
3100  const char *task_key = NULL;
3101 
3102  int rc = 0;
3103  int status = PCMK_LRM_OP_PENDING-1;
3104  int target_rc = get_target_rc(xml_op);
3105  int interval = 0;
3106 
3107  gboolean expired = FALSE;
3108  resource_t *parent = rsc;
3109  enum action_fail_response failure_strategy = action_fail_recover;
3110 
3111  CRM_CHECK(rsc != NULL, return FALSE);
3112  CRM_CHECK(node != NULL, return FALSE);
3113  CRM_CHECK(xml_op != NULL, return FALSE);
3114 
3115  task_key = get_op_key(xml_op);
3116 
3117  task = crm_element_value(xml_op, XML_LRM_ATTR_TASK);
3119 
3120  crm_element_value_int(xml_op, XML_LRM_ATTR_RC, &rc);
3121  crm_element_value_int(xml_op, XML_LRM_ATTR_CALLID, &task_id);
3122  crm_element_value_int(xml_op, XML_LRM_ATTR_OPSTATUS, &status);
3123  crm_element_value_int(xml_op, XML_LRM_ATTR_INTERVAL, &interval);
3124 
3125  CRM_CHECK(task != NULL, return FALSE);
3126  CRM_CHECK(status <= PCMK_LRM_OP_NOT_INSTALLED, return FALSE);
3127  CRM_CHECK(status >= PCMK_LRM_OP_PENDING, return FALSE);
3128 
3129  if (safe_str_eq(task, CRMD_ACTION_NOTIFY) ||
3131  /* safe to ignore these */
3132  return TRUE;
3133  }
3134 
3135  if (is_not_set(rsc->flags, pe_rsc_unique)) {
3136  parent = uber_parent(rsc);
3137  }
3138 
3139  pe_rsc_trace(rsc, "Unpacking task %s/%s (call_id=%d, status=%d, rc=%d) on %s (role=%s)",
3140  task_key, task, task_id, status, rc, node->details->uname, role2text(rsc->role));
3141 
3142  if (node->details->unclean) {
3143  pe_rsc_trace(rsc, "Node %s (where %s is running) is unclean."
3144  " Further action depends on the value of the stop's on-fail attribute",
3145  node->details->uname, rsc->id);
3146  }
3147 
3148  if (status == PCMK_LRM_OP_ERROR) {
3149  /* Older versions set this if rc != 0 but it's up to us to decide */
3150  status = PCMK_LRM_OP_DONE;
3151  }
3152 
3153  if(status != PCMK_LRM_OP_NOT_INSTALLED) {
3154  expired = check_operation_expiry(rsc, node, rc, xml_op, data_set);
3155  }
3156 
3157  /* Degraded results are informational only, re-map them to their error-free equivalents */
3158  if (rc == PCMK_OCF_DEGRADED && safe_str_eq(task, CRMD_ACTION_STATUS)) {
3159  rc = PCMK_OCF_OK;
3160 
3161  /* Add them to the failed list to highlight them for the user */
3162  if ((node->details->shutdown == FALSE) || (node->details->online == TRUE)) {
3163  crm_trace("Remapping %d to %d", PCMK_OCF_DEGRADED, PCMK_OCF_OK);
3164  record_failed_op(xml_op, node, rsc, data_set);
3165  }
3166 
3167  } else if (rc == PCMK_OCF_DEGRADED_MASTER && safe_str_eq(task, CRMD_ACTION_STATUS)) {
3169 
3170  /* Add them to the failed list to highlight them for the user */
3171  if ((node->details->shutdown == FALSE) || (node->details->online == TRUE)) {
3173  record_failed_op(xml_op, node, rsc, data_set);
3174  }
3175  }
3176 
3177  if (expired && target_rc != rc) {
3178  const char *magic = crm_element_value(xml_op, XML_ATTR_TRANSITION_MAGIC);
3179 
3180  pe_rsc_debug(rsc, "Expired operation '%s' on %s returned '%s' (%d) instead of the expected value: '%s' (%d)",
3181  key, node->details->uname,
3182  services_ocf_exitcode_str(rc), rc,
3183  services_ocf_exitcode_str(target_rc), target_rc);
3184 
3185  if(interval == 0) {
3186  crm_notice("Ignoring expired calculated failure %s (rc=%d, magic=%s) on %s",
3187  task_key, rc, magic, node->details->uname);
3188  goto done;
3189 
3190  } else if(node->details->online && node->details->unclean == FALSE) {
3191  crm_notice("Re-initiated expired calculated failure %s (rc=%d, magic=%s) on %s",
3192  task_key, rc, magic, node->details->uname);
3193  /* This is SO horrible, but we don't have access to CancelXmlOp() yet */
3194  crm_xml_add(xml_op, XML_LRM_ATTR_RESTART_DIGEST, "calculated-failure-timeout");
3195  goto done;
3196  }
3197  }
3198 
3199  if(status == PCMK_LRM_OP_DONE || status == PCMK_LRM_OP_ERROR) {
3200  status = determine_op_status(rsc, rc, target_rc, node, xml_op, on_fail, data_set);
3201  }
3202 
3203  pe_rsc_trace(rsc, "Handling status: %d", status);
3204  switch (status) {
3205  case PCMK_LRM_OP_CANCELLED:
3206  /* do nothing?? */
3207  pe_err("Don't know what to do for cancelled ops yet");
3208  break;
3209 
3210  case PCMK_LRM_OP_PENDING:
3211  if (safe_str_eq(task, CRMD_ACTION_START)) {
3213  set_active(rsc);
3214 
3215  } else if (safe_str_eq(task, CRMD_ACTION_PROMOTE)) {
3216  rsc->role = RSC_ROLE_MASTER;
3217 
3218  } else if (safe_str_eq(task, CRMD_ACTION_MIGRATE) && node->details->unclean) {
3219  /* If a pending migrate_to action is out on a unclean node,
3220  * we have to force the stop action on the target. */
3221  const char *migrate_target = crm_element_value(xml_op, XML_LRM_ATTR_MIGRATE_TARGET);
3222  node_t *target = pe_find_node(data_set->nodes, migrate_target);
3223  if (target) {
3224  stop_action(rsc, target, FALSE);
3225  }
3226  }
3227 
3228  if (rsc->pending_task == NULL) {
3229  if (safe_str_eq(task, CRMD_ACTION_STATUS) && interval == 0) {
3230  /* Pending probes are not printed, even if pending
3231  * operations are requested. If someone ever requests that
3232  * behavior, uncomment this and the corresponding part of
3233  * native.c:native_pending_task().
3234  */
3235  /*rsc->pending_task = strdup("probe");*/
3236 
3237  } else {
3238  rsc->pending_task = strdup(task);
3239  }
3240  }
3241  break;
3242 
3243  case PCMK_LRM_OP_DONE:
3244  pe_rsc_trace(rsc, "%s/%s completed on %s", rsc->id, task, node->details->uname);
3245  update_resource_state(rsc, node, xml_op, task, rc, *last_failure, on_fail, data_set);
3246  break;
3247 
3249  failure_strategy = get_action_on_fail(rsc, task_key, task, data_set);
3250  if (failure_strategy == action_fail_ignore) {
3251  crm_warn("Cannot ignore failed %s (status=%d, rc=%d) on %s: "
3252  "Resource agent doesn't exist",
3253  task_key, status, rc, node->details->uname);
3254  /* Also for printing it as "FAILED" by marking it as pe_rsc_failed later */
3255  *on_fail = action_fail_migrate;
3256  }
3257  resource_location(parent, node, -INFINITY, "hard-error", data_set);
3258  unpack_rsc_op_failure(rsc, node, rc, xml_op, last_failure, on_fail, data_set);
3259  break;
3260 
3261  case PCMK_LRM_OP_ERROR:
3264  case PCMK_LRM_OP_TIMEOUT:
3266 
3267  failure_strategy = get_action_on_fail(rsc, task_key, task, data_set);
3268  if ((failure_strategy == action_fail_ignore)
3269  || (failure_strategy == action_fail_restart_container
3270  && safe_str_eq(task, CRMD_ACTION_STOP))) {
3271 
3272  crm_warn("Pretending the failure of %s (rc=%d) on %s succeeded",
3273  task_key, rc, node->details->uname);
3274 
3275  update_resource_state(rsc, node, xml_op, task, target_rc, *last_failure, on_fail, data_set);
3276  crm_xml_add(xml_op, XML_ATTR_UNAME, node->details->uname);
3278 
3279  record_failed_op(xml_op, node, rsc, data_set);
3280 
3281  if (failure_strategy == action_fail_restart_container && *on_fail <= action_fail_recover) {
3282  *on_fail = failure_strategy;
3283  }
3284 
3285  } else {
3286  unpack_rsc_op_failure(rsc, node, rc, xml_op, last_failure, on_fail, data_set);
3287 
3288  if(status == PCMK_LRM_OP_ERROR_HARD) {
3289  do_crm_log(rc != PCMK_OCF_NOT_INSTALLED?LOG_ERR:LOG_NOTICE,
3290  "Preventing %s from re-starting on %s: operation %s failed '%s' (%d)",
3291  parent->id, node->details->uname,
3292  task, services_ocf_exitcode_str(rc), rc);
3293 
3294  resource_location(parent, node, -INFINITY, "hard-error", data_set);
3295 
3296  } else if(status == PCMK_LRM_OP_ERROR_FATAL) {
3297  crm_err("Preventing %s from re-starting anywhere: operation %s failed '%s' (%d)",
3298  parent->id, task, services_ocf_exitcode_str(rc), rc);
3299 
3300  resource_location(parent, NULL, -INFINITY, "fatal-error", data_set);
3301  }
3302  }
3303  break;
3304  }
3305 
3306  done:
3307  pe_rsc_trace(rsc, "Resource %s after %s: role=%s, next=%s", rsc->id, task, role2text(rsc->role), role2text(rsc->next_role));
3308  return TRUE;
3309 }
3310 
3311 gboolean
3312 add_node_attrs(xmlNode * xml_obj, node_t * node, gboolean overwrite, pe_working_set_t * data_set)
3313 {
3314  const char *cluster_name = NULL;
3315 
3316  g_hash_table_insert(node->details->attrs,
3317  strdup(CRM_ATTR_UNAME), strdup(node->details->uname));
3318 
3319  g_hash_table_insert(node->details->attrs, strdup(CRM_ATTR_ID),
3320  strdup(node->details->id));
3321  if (safe_str_eq(node->details->id, data_set->dc_uuid)) {
3322  data_set->dc_node = node;
3323  node->details->is_dc = TRUE;
3324  g_hash_table_insert(node->details->attrs,
3325  strdup(CRM_ATTR_IS_DC), strdup(XML_BOOLEAN_TRUE));
3326  } else {
3327  g_hash_table_insert(node->details->attrs,
3328  strdup(CRM_ATTR_IS_DC), strdup(XML_BOOLEAN_FALSE));
3329  }
3330 
3331  cluster_name = g_hash_table_lookup(data_set->config_hash, "cluster-name");
3332  if (cluster_name) {
3333  g_hash_table_insert(node->details->attrs, strdup(CRM_ATTR_CLUSTER_NAME),
3334  strdup(cluster_name));
3335  }
3336 
3337  unpack_instance_attributes(data_set->input, xml_obj, XML_TAG_ATTR_SETS, NULL,
3338  node->details->attrs, NULL, overwrite, data_set->now);
3339 
3340  if (pe_node_attribute_raw(node, CRM_ATTR_SITE_NAME) == NULL) {
3341  const char *site_name = pe_node_attribute_raw(node, "site-name");
3342 
3343  if (site_name) {
3344  g_hash_table_insert(node->details->attrs,
3345  strdup(CRM_ATTR_SITE_NAME),
3346  strdup(site_name));
3347 
3348  } else if (cluster_name) {
3349  /* Default to cluster-name if unset */
3350  g_hash_table_insert(node->details->attrs,
3351  strdup(CRM_ATTR_SITE_NAME),
3352  strdup(cluster_name));
3353  }
3354  }
3355  return TRUE;
3356 }
3357 
3358 static GListPtr
3359 extract_operations(const char *node, const char *rsc, xmlNode * rsc_entry, gboolean active_filter)
3360 {
3361  int counter = -1;
3362  int stop_index = -1;
3363  int start_index = -1;
3364 
3365  xmlNode *rsc_op = NULL;
3366 
3367  GListPtr gIter = NULL;
3368  GListPtr op_list = NULL;
3369  GListPtr sorted_op_list = NULL;
3370 
3371  /* extract operations */
3372  op_list = NULL;
3373  sorted_op_list = NULL;
3374 
3375  for (rsc_op = __xml_first_child(rsc_entry); rsc_op != NULL; rsc_op = __xml_next_element(rsc_op)) {
3376  if (crm_str_eq((const char *)rsc_op->name, XML_LRM_TAG_RSC_OP, TRUE)) {
3377  crm_xml_add(rsc_op, "resource", rsc);
3378  crm_xml_add(rsc_op, XML_ATTR_UNAME, node);
3379  op_list = g_list_prepend(op_list, rsc_op);
3380  }
3381  }
3382 
3383  if (op_list == NULL) {
3384  /* if there are no operations, there is nothing to do */
3385  return NULL;
3386  }
3387 
3388  sorted_op_list = g_list_sort(op_list, sort_op_by_callid);
3389 
3390  /* create active recurring operations as optional */
3391  if (active_filter == FALSE) {
3392  return sorted_op_list;
3393  }
3394 
3395  op_list = NULL;
3396 
3397  calculate_active_ops(sorted_op_list, &start_index, &stop_index);
3398 
3399  for (gIter = sorted_op_list; gIter != NULL; gIter = gIter->next) {
3400  xmlNode *rsc_op = (xmlNode *) gIter->data;
3401 
3402  counter++;
3403 
3404  if (start_index < stop_index) {
3405  crm_trace("Skipping %s: not active", ID(rsc_entry));
3406  break;
3407 
3408  } else if (counter < start_index) {
3409  crm_trace("Skipping %s: old", ID(rsc_op));
3410  continue;
3411  }
3412  op_list = g_list_append(op_list, rsc_op);
3413  }
3414 
3415  g_list_free(sorted_op_list);
3416  return op_list;
3417 }
3418 
3419 GListPtr
3420 find_operations(const char *rsc, const char *node, gboolean active_filter,
3421  pe_working_set_t * data_set)
3422 {
3423  GListPtr output = NULL;
3424  GListPtr intermediate = NULL;
3425 
3426  xmlNode *tmp = NULL;
3427  xmlNode *status = find_xml_node(data_set->input, XML_CIB_TAG_STATUS, TRUE);
3428 
3429  node_t *this_node = NULL;
3430 
3431  xmlNode *node_state = NULL;
3432 
3433  for (node_state = __xml_first_child(status); node_state != NULL;
3434  node_state = __xml_next_element(node_state)) {
3435 
3436  if (crm_str_eq((const char *)node_state->name, XML_CIB_TAG_STATE, TRUE)) {
3437  const char *uname = crm_element_value(node_state, XML_ATTR_UNAME);
3438 
3439  if (node != NULL && safe_str_neq(uname, node)) {
3440  continue;
3441  }
3442 
3443  this_node = pe_find_node(data_set->nodes, uname);
3444  if(this_node == NULL) {
3445  CRM_LOG_ASSERT(this_node != NULL);
3446  continue;
3447 
3448  } else if (is_remote_node(this_node)) {
3449  determine_remote_online_status(data_set, this_node);
3450 
3451  } else {
3452  determine_online_status(node_state, this_node, data_set);
3453  }
3454 
3455  if (this_node->details->online || is_set(data_set->flags, pe_flag_stonith_enabled)) {
3456  /* offline nodes run no resources...
3457  * unless stonith is enabled in which case we need to
3458  * make sure rsc start events happen after the stonith
3459  */
3460  xmlNode *lrm_rsc = NULL;
3461 
3462  tmp = find_xml_node(node_state, XML_CIB_TAG_LRM, FALSE);
3463  tmp = find_xml_node(tmp, XML_LRM_TAG_RESOURCES, FALSE);
3464 
3465  for (lrm_rsc = __xml_first_child(tmp); lrm_rsc != NULL;
3466  lrm_rsc = __xml_next_element(lrm_rsc)) {
3467  if (crm_str_eq((const char *)lrm_rsc->name, XML_LRM_TAG_RESOURCE, TRUE)) {
3468 
3469  const char *rsc_id = crm_element_value(lrm_rsc, XML_ATTR_ID);
3470 
3471  if (rsc != NULL && safe_str_neq(rsc_id, rsc)) {
3472  continue;
3473  }
3474 
3475  intermediate = extract_operations(uname, rsc_id, lrm_rsc, active_filter);
3476  output = g_list_concat(output, intermediate);
3477  }
3478  }
3479  }
3480  }
3481  }
3482 
3483  return output;
3484 }
GHashTable * tags
Definition: status.h:129
Services API.
gboolean unpack_config(xmlNode *config, pe_working_set_t *data_set)
Definition: unpack.c:176
#define CRM_CHECK(expr, failure_action)
Definition: logging.h:164
GListPtr nodes
Definition: status.h:106
#define XML_RSC_OP_LAST_CHANGE
Definition: msg_xml.h:304
gboolean unpack_rsc_op(resource_t *rsc, node_t *node, xmlNode *xml_op, xmlNode **last_failure, enum action_fail_response *failed, pe_working_set_t *data_set)
Definition: unpack.c:3093
void verify_pe_options(GHashTable *options)
Definition: common.c:184
#define STATUS_PATH_MAX
Definition: unpack.c:2377
xmlNode * find_xml_node(xmlNode *cib, const char *node_path, gboolean must_find)
Definition: xml.c:2235
const char * uname
Definition: status.h:138
A dumping ground.
#define crm_notice(fmt, args...)
Definition: logging.h:250
#define CRMD_ACTION_MIGRATED
Definition: crm.h:173
xmlNode * failed
Definition: status.h:114
#define pe_rsc_debug(rsc, fmt, args...)
Definition: internal.h:24
#define pe_flag_have_stonith_resource
Definition: status.h:65
node_t * pe_create_node(const char *id, const char *uname, const char *type, const char *score, pe_working_set_t *data_set)
Definition: unpack.c:356
gboolean safe_str_neq(const char *a, const char *b)
Definition: strings.c:150
#define INFINITY
Definition: crm.h:83
gint sort_rsc_priority(gconstpointer a, gconstpointer b)
Definition: utils.c:392
gboolean determine_online_status(xmlNode *node_state, node_t *this_node, pe_working_set_t *data_set)
Definition: unpack.c:1489
#define CRM_ATTR_KIND
Definition: crm.h:100
gboolean get_target_role(resource_t *rsc, enum rsc_role_e *role)
Definition: utils.c:1690
#define XML_NODE_IS_FENCED
Definition: msg_xml.h:273
#define XML_ATTR_TRANSITION_MAGIC
Definition: msg_xml.h:384
node_t * node_copy(const node_t *this_node)
Definition: utils.c:127
#define CRM_ATTR_IS_DC
Definition: crm.h:102
#define stop_action(rsc, node, optional)
Definition: internal.h:190
#define pe_flag_enable_unfencing
Definition: status.h:66
#define pe_rsc_orphan_container_filler
Definition: status.h:186
int default_resource_stickiness
Definition: status.h:97
const char * id
Definition: status.h:137
char * clone_strip(const char *last_rsc_id)
Definition: unpack.c:1561
#define XML_ATTR_QUORUM_PANIC
Definition: msg_xml.h:89
int weight
Definition: status.h:174
#define XML_ATTR_TYPE
Definition: msg_xml.h:105
bool pe_can_fence(pe_working_set_t *data_set, node_t *node)
Definition: utils.c:100
#define XML_TAG_UTILIZATION
Definition: msg_xml.h:192
time_t last_granted
Definition: status.h:391
#define pe_flag_have_remote_nodes
Definition: status.h:79
void(* free)(resource_t *)
Definition: complex.h:51
bool container_fix_remote_addr(resource_t *rsc)
Definition: container.c:753
#define XML_RULE_ATTR_SCORE
Definition: msg_xml.h:320
#define XML_BOOLEAN_FALSE
Definition: msg_xml.h:118
#define crm_config_err(fmt...)
Definition: crm_internal.h:256
int get_target_rc(xmlNode *xml_op)
Definition: unpack.c:2974
action_t * pe_fence_op(node_t *node, const char *op, bool optional, const char *reason, pe_working_set_t *data_set)
Definition: utils.c:2138
enum action_fail_response on_fail
Definition: status.h:344
#define pe_rsc_orphan
Definition: status.h:183
int char2score(const char *score)
Definition: utils.c:230
#define pe_proc_warn(fmt...)
Definition: internal.h:30
#define XML_TAG_TRANSIENT_NODEATTRS
Definition: msg_xml.h:390
#define CRMD_ACTION_NOTIFY
Definition: crm.h:186
#define pe_flag_startup_probes
Definition: status.h:77
long long crm_get_msec(const char *input)
Definition: utils.c:598
GListPtr running_rsc
Definition: status.h:152
GListPtr find_actions(GListPtr input, const char *key, const node_t *on_node)
Definition: utils.c:1415
gboolean common_unpack(xmlNode *xml_obj, resource_t **rsc, resource_t *parent, pe_working_set_t *data_set)
Definition: complex.c:465
enum pe_obj_types variant
Definition: status.h:264
#define XML_LRM_ATTR_INTERVAL
Definition: msg_xml.h:283
#define XML_CIB_TAG_TAG
Definition: msg_xml.h:417
#define XML_LRM_TAG_RESOURCE
Definition: msg_xml.h:249
#define pe_flag_stop_rsc_orphans
Definition: status.h:69
gboolean pending
Definition: status.h:144
node_t * partial_migration_source
Definition: status.h:304
#define CRMD_ACTION_PROMOTE
Definition: crm.h:181
int crm_parse_int(const char *text, const char *default_text)
Definition: strings.c:125
gboolean fixed
Definition: status.h:175
GListPtr resources
Definition: status.h:107
#define XML_NVPAIR_ATTR_NAME
Definition: msg_xml.h:366
#define XML_NODE_IS_MAINTENANCE
Definition: msg_xml.h:274
gint sort_op_by_callid(gconstpointer a, gconstpointer b)
Definition: utils.c:1560
#define XML_NODE_EXPECTED
Definition: msg_xml.h:269
node_t * pe_find_node(GListPtr node_list, const char *uname)
Definition: status.c:301
#define XML_CIB_TAG_RSC_TEMPLATE
Definition: msg_xml.h:201
AIS_Host host
Definition: internal.h:52
resource_t * create_child_clone(resource_t *rsc, int sub_id, pe_working_set_t *data_set)
Definition: clone.c:84
time_t get_effective_time(pe_working_set_t *data_set)
Definition: utils.c:1675
no_quorum_policy_t no_quorum_policy
Definition: status.h:98
#define CRM_LOG_ASSERT(expr)
Definition: logging.h:150
const char * pe_pref(GHashTable *options, const char *name)
Definition: common.c:190
char * clone_name
Definition: status.h:257
xmlNode * params_restart
Definition: internal.h:275
resource_t * uber_parent(resource_t *rsc)
Definition: complex.c:897
resource_t * remote_rsc
Definition: status.h:155
#define clear_bit(word, bit)
Definition: crm_internal.h:191
void copy_in_properties(xmlNode *target, xmlNode *src)
Definition: xml.c:2287
#define CRMD_JOINSTATE_NACK
Definition: crm.h:166
#define XML_CIB_TAG_LRM
Definition: msg_xml.h:247
#define CRM_ATTR_CLUSTER_NAME
Definition: crm.h:103
GHashTable * tickets
Definition: status.h:101
node_t * dc_node
Definition: status.h:90
enum rsc_role_e role
Definition: status.h:293
#define pe_rsc_allow_migrate
Definition: status.h:209
GListPtr children
Definition: status.h:300
#define XPATH_ENABLE_UNFENCING
Definition: unpack.c:154
xmlNode * get_xpath_object(const char *xpath, xmlNode *xml_obj, int error_level)
Definition: xpath.c:224
#define pe_proc_err(fmt...)
Definition: internal.h:29
action_fail_response
Definition: common.h:29
char * strndup(const char *str, size_t len)
char * dc_uuid
Definition: status.h:89
gboolean is_remote_node
Definition: status.h:278
int stonith_timeout
Definition: status.h:96
gboolean standby
Definition: status.h:142
#define XML_CIB_TAG_PROPSET
Definition: msg_xml.h:183
char * id
Definition: status.h:256
gboolean decode_transition_key(const char *key, char **uuid, int *action, int *transition_id, int *target_rc)
Definition: operations.c:217
#define XML_LRM_ATTR_RSCID
Definition: msg_xml.h:293
gboolean unpack_resources(xmlNode *xml_resources, pe_working_set_t *data_set)
Definition: unpack.c:737
#define CRMD_ACTION_START
Definition: crm.h:175
#define XML_LRM_ATTR_TASK_KEY
Definition: msg_xml.h:285
#define pe_rsc_block
Definition: status.h:185
#define XML_TAG_ATTR_SETS
Definition: msg_xml.h:184
GHashTable * utilization
Definition: status.h:160
#define XML_LRM_ATTR_TASK
Definition: msg_xml.h:284
const char * role2text(enum rsc_role_e role)
Definition: common.c:346
char uname[MAX_NAME]
Definition: internal.h:53
gboolean is_remote_node(node_t *node)
Definition: remote.c:62
#define CRMD_ACTION_STOP
Definition: crm.h:178
#define CRM_OP_CLEAR_FAILCOUNT
Definition: crm.h:137
struct node_shared_s * details
Definition: status.h:177
gboolean unpack_status(xmlNode *status, pe_working_set_t *data_set)
Definition: unpack.c:1157
#define CRMD_JOINSTATE_DOWN
Definition: crm.h:163
#define crm_warn(fmt, args...)
Definition: logging.h:249
resource_t * find_container_child(const char *stem, resource_t *rsc, node_t *node)
Definition: container.c:1170
#define CRMD_ACTION_DEMOTE
Definition: crm.h:183
#define set_bit(word, bit)
Definition: crm_internal.h:190
#define crm_atoi(text, default_text)
Definition: util.h:110
gboolean unclean
Definition: status.h:145
xmlNode * pe_create_remote_xml(xmlNode *parent, const char *uname, const char *container_id, const char *migrateable, const char *is_managed, const char *interval, const char *monitor_timeout, const char *start_timeout, const char *server, const char *port)
Definition: remote.c:158
uint32_t id
Definition: internal.h:48
#define crm_debug(fmt, args...)
Definition: logging.h:253
void native_add_running(resource_t *rsc, node_t *node, pe_working_set_t *data_set)
Definition: native.c:32
#define XML_CIB_ATTR_SHUTDOWN
Definition: msg_xml.h:276
#define XML_RSC_ATTR_CONTAINER
Definition: msg_xml.h:229
Utility functions.
#define XML_ATTR_ID
Definition: msg_xml.h:102
char * pending_task
Definition: status.h:309
#define XML_CIB_TAG_RESOURCE
Definition: msg_xml.h:195
gboolean unpack_nodes(xmlNode *xml_nodes, pe_working_set_t *data_set)
Definition: unpack.c:525
#define XML_BOOLEAN_TRUE
Definition: msg_xml.h:117
#define XML_CIB_TAG_STATE
Definition: msg_xml.h:177
#define pe_rsc_failed
Definition: status.h:201
char * digest_all_calc
Definition: internal.h:276
#define stop_key(rsc)
Definition: internal.h:189
node_t * partial_migration_target
Definition: status.h:303
#define pe_flag_startup_fencing
Definition: status.h:75
resource_object_functions_t * fns
Definition: status.h:265
resource_t * container
Definition: status.h:306
#define CRM_ATTR_UNAME
Definition: crm.h:98
GHashTable * allowed_nodes
Definition: status.h:291
GHashTable * digest_cache
Definition: status.h:163
#define set_config_flag(data_set, option, flag)
Definition: unpack.c:34
#define XML_NODE_IS_PEER
Definition: msg_xml.h:271
#define crm_trace(fmt, args...)
Definition: logging.h:254
#define CRMD_JOINSTATE_MEMBER
Definition: crm.h:165
#define do_crm_log(level, fmt, args...)
Log a message.
Definition: logging.h:129
enum rsc_digest_cmp_val rc
Definition: internal.h:272
gboolean is_baremetal_remote_node(node_t *node)
Definition: remote.c:44
#define pe_rsc_is_container
Definition: status.h:214
char * digest_secure_calc
Definition: internal.h:277
gboolean unpack_remote_nodes(xmlNode *xml_resources, pe_working_set_t *data_set)
Definition: unpack.c:611
gboolean add_node_attrs(xmlNode *xml_obj, node_t *node, gboolean overwrite, pe_working_set_t *data_set)
Definition: unpack.c:3312
GHashTable * meta
Definition: status.h:354
gboolean is_container_remote_node(node_t *node)
Definition: remote.c:53
xmlNode * add_node_copy(xmlNode *new_parent, xmlNode *xml_node)
Definition: xml.c:2405
GListPtr refs
Definition: status.h:398
gboolean unpacked
Definition: status.h:170
const char * stonith_action
Definition: status.h:91
#define crm_log_xml_debug(xml, text)
Definition: logging.h:261
#define XML_TAG_META_SETS
Definition: msg_xml.h:185
Wrappers for and extensions to libxml2.
#define XML_ATTR_TE_NOWAIT
Definition: msg_xml.h:387
GHashTable * config_hash
Definition: status.h:100
#define XML_ATTR_UNAME
Definition: msg_xml.h:130
gboolean add_tag_ref(GHashTable *tags, const char *tag_name, const char *obj_ref)
Definition: utils.c:2254
#define XML_BOOLEAN_YES
Definition: msg_xml.h:119
#define XML_RSC_ATTR_MANAGED
Definition: msg_xml.h:218
xmlNode * create_xml_node(xmlNode *parent, const char *name)
Definition: xml.c:2588
gboolean is_dc
Definition: status.h:149
int crm_element_value_int(xmlNode *data, const char *name, int *dest)
Definition: xml.c:3844
char * clone_zero(const char *last_rsc_id)
Definition: unpack.c:1600
const char * crm_element_value(xmlNode *data, const char *name)
Definition: xml.c:5165
action_t * custom_action(resource_t *rsc, char *key, const char *task, node_t *on_node, gboolean optional, gboolean foo, pe_working_set_t *data_set)
Definition: utils.c:419
unsigned long long flags
Definition: status.h:280
const char * pe_node_attribute_raw(pe_node_t *node, const char *name)
Definition: common.c:478
#define pe_flag_maintenance_mode
Definition: status.h:62
resource_t * parent
Definition: status.h:262
node_t *(* location)(resource_t *, GListPtr *, gboolean)
Definition: complex.h:50
#define XML_LRM_ATTR_MIGRATE_TARGET
Definition: msg_xml.h:310
#define CIB_OPTIONS_FIRST
Definition: msg_xml.h:53
#define XML_RSC_ATTR_REMOTE_NODE
Definition: msg_xml.h:232
char * uuid
Definition: status.h:339
#define XML_LRM_ATTR_RESTART_DIGEST
Definition: msg_xml.h:300
GListPtr dangling_migrations
Definition: status.h:301
void free_xml(xmlNode *child)
Definition: xml.c:2706
#define pe_flag_stop_everything
Definition: status.h:71
xmlNode * input
Definition: status.h:85
gboolean crm_str_eq(const char *a, const char *b, gboolean use_case)
Definition: strings.c:213
#define XML_CIB_TAG_NODE
Definition: msg_xml.h:178
GListPtr fillers
Definition: status.h:307
const char * placement_strategy
Definition: status.h:92
gboolean unseen
Definition: status.h:146
int failure_timeout
Definition: status.h:274
xmlNode * params_all
Definition: internal.h:273
uint32_t counter
Definition: internal.h:50
int remote_reconnect_interval
Definition: status.h:313
gboolean remote_maintenance
Definition: status.h:169
#define crm_config_warn(fmt...)
Definition: crm_internal.h:257
GListPtr actions
Definition: status.h:285
#define XML_ATTR_TRANSITION_KEY
Definition: msg_xml.h:385
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Definition: xml.c:2490
#define CRM_XS
Definition: logging.h:42
gboolean maintenance
Definition: status.h:165
#define pe_rsc_unique
Definition: status.h:189
GHashTable * node_hash_from_list(GListPtr list)
Definition: utils.c:183
const char * localhost
Definition: status.h:128
GHashTable * meta
Definition: status.h:296
gboolean xml_contains_remote_node(xmlNode *xml)
Definition: remote.c:91
node_t * pe_find_node_any(GListPtr node_list, const char *id, const char *uname)
Definition: status.c:273
const char * fail2text(enum action_fail_response fail)
Definition: common.c:196
void add_hash_param(GHashTable *hash, const char *name, const char *value)
Definition: common.c:423
#define pe_flag_quick_location
Definition: status.h:81
#define pe_rsc_start_pending
Definition: status.h:204
#define XML_LRM_TAG_RESOURCES
Definition: msg_xml.h:248
gboolean standby_onfail
Definition: status.h:143
#define crm_err(fmt, args...)
Definition: logging.h:248
resource_t *(* find_rsc)(resource_t *parent, const char *search, node_t *node, int flags)
Definition: complex.h:44
#define XML_CIB_TAG_TICKET_STATE
Definition: msg_xml.h:414
void resource_location(resource_t *rsc, node_t *node, int score, const char *tag, pe_working_set_t *data_set)
Definition: utils.c:1516
xmlXPathObjectPtr xpath_search(xmlNode *xml_top, const char *path)
Definition: xpath.c:145
void pe_fence_node(pe_working_set_t *data_set, node_t *node, const char *reason)
Schedule a fence action for a node.
Definition: unpack.c:77
ticket_t * ticket_new(const char *ticket_id, pe_working_set_t *data_set)
Definition: utils.c:1807
GHashTable * attrs
Definition: status.h:157
bool remote_id_conflict(const char *remote_name, pe_working_set_t *data)
Definition: unpack.c:418
enum rsc_role_e next_role
Definition: status.h:294
gboolean online
Definition: status.h:141
#define XML_ATTR_HAVE_WATCHDOG
Definition: msg_xml.h:91
#define XML_NODE_ATTR_RSC_DISCOVERY
Definition: msg_xml.h:370
gboolean shutdown
Definition: status.h:147
int compare_version(const char *version1, const char *version2)
Definition: utils.c:486
gboolean rsc_discovery_enabled
Definition: status.h:166
#define pe_flag_remove_after_stop
Definition: status.h:74
#define CRMD_ACTION_METADATA
Definition: crm.h:190
#define pe_rsc_failure_ignored
Definition: status.h:211
xmlNode * params_secure
Definition: internal.h:274
#define XML_LRM_ATTR_CALLID
Definition: msg_xml.h:296
#define pe_rsc_managed
Definition: status.h:184
#define CRMD_ACTION_MIGRATE
Definition: crm.h:172
#define XML_NVPAIR_ATTR_VALUE
Definition: msg_xml.h:367
int node_score_red
Definition: utils.c:72
#define crm_str_hash
Definition: util.h:73
#define uint32_t
Definition: stdint.in.h:158
enum rsc_role_e fail_role
Definition: status.h:345
gboolean remote_requires_reset
Definition: status.h:167
char * id
Definition: status.h:397
#define CRM_ASSERT(expr)
Definition: error.h:35
char data[0]
Definition: internal.h:58
#define crm_str(x)
Definition: logging.h:274
#define XML_ATTR_CRM_VERSION
Definition: msg_xml.h:84
#define XML_LRM_ATTR_OPSTATUS
Definition: msg_xml.h:294
gboolean unpack_lrm_resources(node_t *node, xmlNode *lrm_rsc_list, pe_working_set_t *data_set)
Definition: unpack.c:2324
int pe_get_failcount(node_t *node, resource_t *rsc, time_t *last_failure, uint32_t flags, xmlNode *xml_op, pe_working_set_t *data_set)
Definition: failcounts.c:237
#define CRMD_JOINSTATE_PENDING
Definition: crm.h:164
enum node_type type
Definition: status.h:158
uint32_t pe_wo
Definition: unpack.c:50
rsc_role_e
Definition: common.h:81
enum pe_action_flags flags
Definition: status.h:342
GHashTable * known_on
Definition: status.h:290
#define XML_LRM_ATTR_RC
Definition: msg_xml.h:295
gboolean standby
Definition: status.h:392
Definition: status.h:396
GListPtr find_operations(const char *rsc, const char *node, gboolean active_filter, pe_working_set_t *data_set)
Definition: unpack.c:3420
#define XML_NODE_JOIN_STATE
Definition: msg_xml.h:268
gboolean expected_up
Definition: status.h:148
void pe_free_action(action_t *action)
Definition: utils.c:1300
#define pe_flag_have_quorum
Definition: status.h:59
void destroy_ticket(gpointer data)
Definition: utils.c:1795
#define XML_CIB_TAG_STATUS
Definition: msg_xml.h:158
#define XML_CIB_TAG_OBJ_REF
Definition: msg_xml.h:418
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:919
#define pe_flag_is_managed_default
Definition: status.h:61
gboolean granted
Definition: status.h:390
Definition: status.h:173
gboolean remote_was_fenced
Definition: status.h:168
#define XML_NODE_IN_CLUSTER
Definition: msg_xml.h:270
#define pe_flag_stop_action_orphans
Definition: status.h:70
#define NORMALNODE
Definition: util.h:42
gboolean crm_is_true(const char *s)
Definition: strings.c:165
#define CRM_ATTR_SITE_NAME
Definition: crm.h:104
void calculate_active_ops(GListPtr sorted_op_list, int *start_index, int *stop_index)
Definition: unpack.c:2142
#define XML_CIB_TAG_GROUP
Definition: msg_xml.h:196
CRM_TRACE_INIT_DATA(pe_status)
#define XML_LRM_TAG_RSC_OP
Definition: msg_xml.h:252
#define pe_rsc_trace(rsc, fmt, args...)
Definition: internal.h:25
#define pe_flag_symmetric_cluster
Definition: status.h:60
#define ID(x)
Definition: msg_xml.h:446
unsigned long long flags
Definition: status.h:94
char * generate_op_key(const char *rsc_id, const char *op_type, int interval)
Generate an operation key.
Definition: operations.c:37
#define pe_err(fmt...)
Definition: internal.h:27
void print_resource(int log_level, const char *pre_text, resource_t *rsc, gboolean details)
Definition: utils.c:1284
gboolean unpack_tags(xmlNode *xml_tags, pe_working_set_t *data_set)
Definition: unpack.c:797
resource_t * pe_find_resource(GListPtr rsc_list, const char *id_rh)
Definition: status.c:249
#define safe_str_eq(a, b)
Definition: util.h:72
int node_score_green
Definition: utils.c:73
#define ONLINESTATUS
Definition: util.h:52
char * id
Definition: status.h:389
op_digest_cache_t * rsc_action_digest_cmp(resource_t *rsc, xmlNode *xml_op, node_t *node, pe_working_set_t *data_set)
Definition: utils.c:1980
char * crm_strdup_printf(char const *format,...) __attribute__((__format__(__printf__
#define XML_LRM_ATTR_MIGRATE_SOURCE
Definition: msg_xml.h:309
#define LOG_DEBUG_3
Definition: logging.h:32
void freeXpathObject(xmlXPathObjectPtr xpathObj)
Definition: xpath.c:45
#define CRM_ATTR_ID
Definition: crm.h:99
gint sort_node_uname(gconstpointer a, gconstpointer b)
Definition: utils.c:225
GList * GListPtr
Definition: crm.h:218
int node_score_yellow
Definition: utils.c:74
#define XML_CIB_TAG_TICKETS
Definition: msg_xml.h:413
crm_time_t * now
Definition: status.h:86
#define crm_info(fmt, args...)
Definition: logging.h:251
char * digest_restart_calc
Definition: internal.h:278
void g_hash_destroy_str(gpointer data)
Definition: strings.c:74
GHashTable * template_rsc_sets
Definition: status.h:127
#define pe_flag_concurrent_fencing
Definition: status.h:67
GHashTable * state
Definition: status.h:393
#define pe_flag_start_failure_fatal
Definition: status.h:73
#define pe_flag_stonith_enabled
Definition: status.h:64
enum crm_ais_msg_types type
Definition: internal.h:51
#define pe_warn_once(pe_wo_bit, fmt...)
Definition: unpack.h:115
#define pe_rsc_info(rsc, fmt, args...)
Definition: internal.h:23
#define CRMD_ACTION_STATUS
Definition: crm.h:189
GListPtr running_on
Definition: status.h:289