pacemaker  2.0.4-2deceaa
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
unpack.c
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2020 the Pacemaker project contributors
3  *
4  * The version control history for this file may have further details.
5  *
6  * This source code is licensed under the GNU Lesser General Public License
7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8  */
9 
10 #include <crm_internal.h>
11 
12 #include <stdio.h>
13 #include <string.h>
14 #include <glib.h>
15 #include <time.h>
16 
17 #include <crm/crm.h>
18 #include <crm/services.h>
19 #include <crm/msg_xml.h>
20 #include <crm/common/xml.h>
21 
22 #include <crm/common/util.h>
23 #include <crm/pengine/rules.h>
24 #include <crm/pengine/internal.h>
26 #include <pe_status_private.h>
27 
28 CRM_TRACE_INIT_DATA(pe_status);
29 
30 #define set_config_flag(data_set, option, flag) do { \
31  const char *tmp = pe_pref(data_set->config_hash, option); \
32  if(tmp) { \
33  if(crm_is_true(tmp)) { \
34  set_bit(data_set->flags, flag); \
35  } else { \
36  clear_bit(data_set->flags, flag); \
37  } \
38  } \
39  } while(0)
40 
41 static void unpack_rsc_op(pe_resource_t *rsc, pe_node_t *node, xmlNode *xml_op,
42  xmlNode **last_failure,
43  enum action_fail_response *failed,
44  pe_working_set_t *data_set);
45 static void determine_remote_online_status(pe_working_set_t *data_set,
46  pe_node_t *this_node);
47 static void add_node_attrs(xmlNode *attrs, pe_node_t *node, bool overwrite,
48  pe_working_set_t *data_set);
49 static void determine_online_status(xmlNode *node_state, pe_node_t *this_node,
50  pe_working_set_t *data_set);
51 
52 static void unpack_lrm_resources(pe_node_t *node, xmlNode *lrm_state,
53  pe_working_set_t *data_set);
54 
55 
56 // Bitmask for warnings we only want to print once
57 uint32_t pe_wo = 0;
58 
59 static gboolean
60 is_dangling_guest_node(pe_node_t *node)
61 {
62  /* we are looking for a remote-node that was supposed to be mapped to a
63  * container resource, but all traces of that container have disappeared
64  * from both the config and the status section. */
65  if (pe__is_guest_or_remote_node(node) &&
66  node->details->remote_rsc &&
67  node->details->remote_rsc->container == NULL &&
69  return TRUE;
70  }
71 
72  return FALSE;
73 }
74 
75 
84 void
86  const char *reason, bool priority_delay)
87 {
88  CRM_CHECK(node, return);
89 
90  /* A guest node is fenced by marking its container as failed */
91  if (pe__is_guest_node(node)) {
93 
94  if (is_set(rsc->flags, pe_rsc_failed) == FALSE) {
95  if (!is_set(rsc->flags, pe_rsc_managed)) {
96  crm_notice("Not fencing guest node %s "
97  "(otherwise would because %s): "
98  "its guest resource %s is unmanaged",
99  node->details->uname, reason, rsc->id);
100  } else {
101  crm_warn("Guest node %s will be fenced "
102  "(by recovering its guest resource %s): %s",
103  node->details->uname, rsc->id, reason);
104 
105  /* We don't mark the node as unclean because that would prevent the
106  * node from running resources. We want to allow it to run resources
107  * in this transition if the recovery succeeds.
108  */
109  node->details->remote_requires_reset = TRUE;
110  set_bit(rsc->flags, pe_rsc_failed);
111  }
112  }
113 
114  } else if (is_dangling_guest_node(node)) {
115  crm_info("Cleaning up dangling connection for guest node %s: "
116  "fencing was already done because %s, "
117  "and guest resource no longer exists",
118  node->details->uname, reason);
120 
121  } else if (pe__is_remote_node(node)) {
122  pe_resource_t *rsc = node->details->remote_rsc;
123 
124  if (rsc && (!is_set(rsc->flags, pe_rsc_managed))) {
125  crm_notice("Not fencing remote node %s "
126  "(otherwise would because %s): connection is unmanaged",
127  node->details->uname, reason);
128  } else if(node->details->remote_requires_reset == FALSE) {
129  node->details->remote_requires_reset = TRUE;
130  crm_warn("Remote node %s %s: %s",
131  node->details->uname,
132  pe_can_fence(data_set, node)? "will be fenced" : "is unclean",
133  reason);
134  }
135  node->details->unclean = TRUE;
136  // No need to apply `priority-fencing-delay` for remote nodes
137  pe_fence_op(node, NULL, TRUE, reason, FALSE, data_set);
138 
139  } else if (node->details->unclean) {
140  crm_trace("Cluster node %s %s because %s",
141  node->details->uname,
142  pe_can_fence(data_set, node)? "would also be fenced" : "also is unclean",
143  reason);
144 
145  } else {
146  crm_warn("Cluster node %s %s: %s",
147  node->details->uname,
148  pe_can_fence(data_set, node)? "will be fenced" : "is unclean",
149  reason);
150  node->details->unclean = TRUE;
151  pe_fence_op(node, NULL, TRUE, reason, priority_delay, data_set);
152  }
153 }
154 
155 // @TODO xpaths can't handle templates, rules, or id-refs
156 
157 // nvpair with provides or requires set to unfencing
158 #define XPATH_UNFENCING_NVPAIR XML_CIB_TAG_NVPAIR \
159  "[(@" XML_NVPAIR_ATTR_NAME "='" XML_RSC_ATTR_PROVIDES "'" \
160  "or @" XML_NVPAIR_ATTR_NAME "='" XML_RSC_ATTR_REQUIRES "') " \
161  "and @" XML_NVPAIR_ATTR_VALUE "='unfencing']"
162 
163 // unfencing in rsc_defaults or any resource
164 #define XPATH_ENABLE_UNFENCING \
165  "/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_RESOURCES \
166  "//" XML_TAG_META_SETS "/" XPATH_UNFENCING_NVPAIR \
167  "|/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_RSCCONFIG \
168  "/" XML_TAG_META_SETS "/" XPATH_UNFENCING_NVPAIR
169 
170 static
171 void set_if_xpath(unsigned long long flag, const char *xpath,
172  pe_working_set_t *data_set)
173 {
174  xmlXPathObjectPtr result = NULL;
175 
176  if (is_not_set(data_set->flags, flag)) {
177  result = xpath_search(data_set->input, xpath);
178  if (result && (numXpathResults(result) > 0)) {
179  set_bit(data_set->flags, flag);
180  }
181  freeXpathObject(result);
182  }
183 }
184 
185 gboolean
186 unpack_config(xmlNode * config, pe_working_set_t * data_set)
187 {
188  const char *value = NULL;
189  GHashTable *config_hash = crm_str_table_new();
190 
191  data_set->config_hash = config_hash;
192 
193  pe__unpack_dataset_nvpairs(config, XML_CIB_TAG_PROPSET, NULL, config_hash,
194  CIB_OPTIONS_FIRST, FALSE, data_set);
195 
196  verify_pe_options(data_set->config_hash);
197 
198  set_config_flag(data_set, "enable-startup-probes", pe_flag_startup_probes);
199  if(is_not_set(data_set->flags, pe_flag_startup_probes)) {
200  crm_info("Startup probes: disabled (dangerous)");
201  }
202 
203  value = pe_pref(data_set->config_hash, XML_ATTR_HAVE_WATCHDOG);
204  if (value && crm_is_true(value)) {
205  crm_notice("Watchdog will be used via SBD if fencing is required "
206  "and stonith-watchdog-timeout is nonzero");
208  }
209 
210  /* Set certain flags via xpath here, so they can be used before the relevant
211  * configuration sections are unpacked.
212  */
213  set_if_xpath(pe_flag_enable_unfencing, XPATH_ENABLE_UNFENCING, data_set);
214 
215  value = pe_pref(data_set->config_hash, "stonith-timeout");
216  data_set->stonith_timeout = (int) crm_parse_interval_spec(value);
217  crm_debug("STONITH timeout: %d", data_set->stonith_timeout);
218 
219  set_config_flag(data_set, "stonith-enabled", pe_flag_stonith_enabled);
220  crm_debug("STONITH of failed nodes is %s",
221  is_set(data_set->flags, pe_flag_stonith_enabled) ? "enabled" : "disabled");
222 
223  data_set->stonith_action = pe_pref(data_set->config_hash, "stonith-action");
224  if (!strcmp(data_set->stonith_action, "poweroff")) {
226  "Support for stonith-action of 'poweroff' is deprecated "
227  "and will be removed in a future release (use 'off' instead)");
228  data_set->stonith_action = "off";
229  }
230  crm_trace("STONITH will %s nodes", data_set->stonith_action);
231 
232  set_config_flag(data_set, "concurrent-fencing", pe_flag_concurrent_fencing);
233  crm_debug("Concurrent fencing is %s",
234  is_set(data_set->flags, pe_flag_concurrent_fencing) ? "enabled" : "disabled");
235 
236  value = pe_pref(data_set->config_hash,
238  if (value) {
239  data_set->priority_fencing_delay = crm_parse_interval_spec(value) / 1000;
240  crm_trace("Priority fencing delay is %ds", data_set->priority_fencing_delay);
241  }
242 
243  set_config_flag(data_set, "stop-all-resources", pe_flag_stop_everything);
244  crm_debug("Stop all active resources: %s",
245  is_set(data_set->flags, pe_flag_stop_everything) ? "true" : "false");
246 
247  set_config_flag(data_set, "symmetric-cluster", pe_flag_symmetric_cluster);
248  if (is_set(data_set->flags, pe_flag_symmetric_cluster)) {
249  crm_debug("Cluster is symmetric" " - resources can run anywhere by default");
250  }
251 
252  value = pe_pref(data_set->config_hash, "no-quorum-policy");
253 
254  if (safe_str_eq(value, "ignore")) {
256 
257  } else if (safe_str_eq(value, "freeze")) {
259 
260  } else if (safe_str_eq(value, "suicide")) {
261  if (is_set(data_set->flags, pe_flag_stonith_enabled)) {
262  int do_panic = 0;
263 
265  &do_panic);
266  if (do_panic || is_set(data_set->flags, pe_flag_have_quorum)) {
268  } else {
269  crm_notice("Resetting no-quorum-policy to 'stop': cluster has never had quorum");
270  data_set->no_quorum_policy = no_quorum_stop;
271  }
272  } else {
273  pcmk__config_err("Resetting no-quorum-policy to 'stop' because "
274  "fencing is disabled");
275  data_set->no_quorum_policy = no_quorum_stop;
276  }
277 
278  } else {
279  data_set->no_quorum_policy = no_quorum_stop;
280  }
281 
282  switch (data_set->no_quorum_policy) {
283  case no_quorum_freeze:
284  crm_debug("On loss of quorum: Freeze resources");
285  break;
286  case no_quorum_stop:
287  crm_debug("On loss of quorum: Stop ALL resources");
288  break;
289  case no_quorum_suicide:
290  crm_notice("On loss of quorum: Fence all remaining nodes");
291  break;
292  case no_quorum_ignore:
293  crm_notice("On loss of quorum: Ignore");
294  break;
295  }
296 
297  set_config_flag(data_set, "stop-orphan-resources", pe_flag_stop_rsc_orphans);
298  crm_trace("Orphan resources are %s",
299  is_set(data_set->flags, pe_flag_stop_rsc_orphans) ? "stopped" : "ignored");
300 
301  set_config_flag(data_set, "stop-orphan-actions", pe_flag_stop_action_orphans);
302  crm_trace("Orphan resource actions are %s",
303  is_set(data_set->flags, pe_flag_stop_action_orphans) ? "stopped" : "ignored");
304 
305  set_config_flag(data_set, "remove-after-stop", pe_flag_remove_after_stop);
306  crm_trace("Stopped resources are removed from the status section: %s",
307  is_set(data_set->flags, pe_flag_remove_after_stop) ? "true" : "false");
308 
309  set_config_flag(data_set, "maintenance-mode", pe_flag_maintenance_mode);
310  crm_trace("Maintenance mode: %s",
311  is_set(data_set->flags, pe_flag_maintenance_mode) ? "true" : "false");
312 
313  set_config_flag(data_set, "start-failure-is-fatal", pe_flag_start_failure_fatal);
314  crm_trace("Start failures are %s",
315  is_set(data_set->flags,
316  pe_flag_start_failure_fatal) ? "always fatal" : "handled by failcount");
317 
318  if (is_set(data_set->flags, pe_flag_stonith_enabled)) {
319  set_config_flag(data_set, "startup-fencing", pe_flag_startup_fencing);
320  }
321  if (is_set(data_set->flags, pe_flag_startup_fencing)) {
322  crm_trace("Unseen nodes will be fenced");
323  } else {
324  pe_warn_once(pe_wo_blind, "Blind faith: not fencing unseen nodes");
325  }
326 
327  pcmk__score_red = char2score(pe_pref(data_set->config_hash, "node-health-red"));
328  pcmk__score_green = char2score(pe_pref(data_set->config_hash, "node-health-green"));
329  pcmk__score_yellow = char2score(pe_pref(data_set->config_hash, "node-health-yellow"));
330 
331  crm_debug("Node scores: 'red' = %s, 'yellow' = %s, 'green' = %s",
332  pe_pref(data_set->config_hash, "node-health-red"),
333  pe_pref(data_set->config_hash, "node-health-yellow"),
334  pe_pref(data_set->config_hash, "node-health-green"));
335 
336  data_set->placement_strategy = pe_pref(data_set->config_hash, "placement-strategy");
337  crm_trace("Placement strategy: %s", data_set->placement_strategy);
338 
339  set_config_flag(data_set, "shutdown-lock", pe_flag_shutdown_lock);
340  crm_trace("Resources will%s be locked to cleanly shut down nodes",
341  (is_set(data_set->flags, pe_flag_shutdown_lock)? "" : " not"));
342  if (is_set(data_set->flags, pe_flag_shutdown_lock)) {
343  value = pe_pref(data_set->config_hash,
345  data_set->shutdown_lock = crm_parse_interval_spec(value) / 1000;
346  crm_trace("Shutdown locks expire after %us", data_set->shutdown_lock);
347  }
348 
349  return TRUE;
350 }
351 
352 static void
353 destroy_digest_cache(gpointer ptr)
354 {
355  op_digest_cache_t *data = ptr;
356 
357  free_xml(data->params_all);
358  free_xml(data->params_secure);
359  free_xml(data->params_restart);
360 
361  free(data->digest_all_calc);
362  free(data->digest_restart_calc);
363  free(data->digest_secure_calc);
364 
365  free(data);
366 }
367 
368 pe_node_t *
369 pe_create_node(const char *id, const char *uname, const char *type,
370  const char *score, pe_working_set_t * data_set)
371 {
372  pe_node_t *new_node = NULL;
373 
374  if (pe_find_node(data_set->nodes, uname) != NULL) {
375  pcmk__config_warn("More than one node entry has name '%s'", uname);
376  }
377 
378  new_node = calloc(1, sizeof(pe_node_t));
379  if (new_node == NULL) {
380  return NULL;
381  }
382 
383  new_node->weight = char2score(score);
384  new_node->fixed = FALSE;
385  new_node->details = calloc(1, sizeof(struct pe_node_shared_s));
386 
387  if (new_node->details == NULL) {
388  free(new_node);
389  return NULL;
390  }
391 
392  crm_trace("Creating node for entry %s/%s", uname, id);
393  new_node->details->id = id;
394  new_node->details->uname = uname;
395  new_node->details->online = FALSE;
396  new_node->details->shutdown = FALSE;
397  new_node->details->rsc_discovery_enabled = TRUE;
398  new_node->details->running_rsc = NULL;
399  new_node->details->type = node_ping;
400 
401  if (safe_str_eq(type, "remote")) {
402  new_node->details->type = node_remote;
404  } else if ((type == NULL) || safe_str_eq(type, "member")) {
405  new_node->details->type = node_member;
406  }
407 
408  new_node->details->attrs = crm_str_table_new();
409 
410  if (pe__is_guest_or_remote_node(new_node)) {
411  g_hash_table_insert(new_node->details->attrs, strdup(CRM_ATTR_KIND),
412  strdup("remote"));
413  } else {
414  g_hash_table_insert(new_node->details->attrs, strdup(CRM_ATTR_KIND),
415  strdup("cluster"));
416  }
417 
418  new_node->details->utilization = crm_str_table_new();
419 
420  new_node->details->digest_cache = g_hash_table_new_full(crm_str_hash,
421  g_str_equal, free,
422  destroy_digest_cache);
423 
424  data_set->nodes = g_list_insert_sorted(data_set->nodes, new_node, sort_node_uname);
425  return new_node;
426 }
427 
428 static const char *
429 expand_remote_rsc_meta(xmlNode *xml_obj, xmlNode *parent, pe_working_set_t *data)
430 {
431  xmlNode *attr_set = NULL;
432  xmlNode *attr = NULL;
433 
434  const char *container_id = ID(xml_obj);
435  const char *remote_name = NULL;
436  const char *remote_server = NULL;
437  const char *remote_port = NULL;
438  const char *connect_timeout = "60s";
439  const char *remote_allow_migrate=NULL;
440  const char *is_managed = NULL;
441 
442  for (attr_set = __xml_first_child_element(xml_obj); attr_set != NULL;
443  attr_set = __xml_next_element(attr_set)) {
444  if (safe_str_neq((const char *)attr_set->name, XML_TAG_META_SETS)) {
445  continue;
446  }
447 
448  for (attr = __xml_first_child_element(attr_set); attr != NULL;
449  attr = __xml_next_element(attr)) {
450  const char *value = crm_element_value(attr, XML_NVPAIR_ATTR_VALUE);
451  const char *name = crm_element_value(attr, XML_NVPAIR_ATTR_NAME);
452 
454  remote_name = value;
455  } else if (safe_str_eq(name, "remote-addr")) {
456  remote_server = value;
457  } else if (safe_str_eq(name, "remote-port")) {
458  remote_port = value;
459  } else if (safe_str_eq(name, "remote-connect-timeout")) {
460  connect_timeout = value;
461  } else if (safe_str_eq(name, "remote-allow-migrate")) {
462  remote_allow_migrate=value;
463  } else if (safe_str_eq(name, XML_RSC_ATTR_MANAGED)) {
464  is_managed = value;
465  }
466  }
467  }
468 
469  if (remote_name == NULL) {
470  return NULL;
471  }
472 
473  if (pe_find_resource(data->resources, remote_name) != NULL) {
474  return NULL;
475  }
476 
477  pe_create_remote_xml(parent, remote_name, container_id,
478  remote_allow_migrate, is_managed,
479  connect_timeout, remote_server, remote_port);
480  return remote_name;
481 }
482 
483 static void
484 handle_startup_fencing(pe_working_set_t *data_set, pe_node_t *new_node)
485 {
486  if ((new_node->details->type == node_remote) && (new_node->details->remote_rsc == NULL)) {
487  /* Ignore fencing for remote nodes that don't have a connection resource
488  * associated with them. This happens when remote node entries get left
489  * in the nodes section after the connection resource is removed.
490  */
491  return;
492  }
493 
494  if (is_set(data_set->flags, pe_flag_startup_fencing)) {
495  // All nodes are unclean until we've seen their status entry
496  new_node->details->unclean = TRUE;
497 
498  } else {
499  // Blind faith ...
500  new_node->details->unclean = FALSE;
501  }
502 
503  /* We need to be able to determine if a node's status section
504  * exists or not separate from whether the node is unclean. */
505  new_node->details->unseen = TRUE;
506 }
507 
508 gboolean
509 unpack_nodes(xmlNode * xml_nodes, pe_working_set_t * data_set)
510 {
511  xmlNode *xml_obj = NULL;
512  pe_node_t *new_node = NULL;
513  const char *id = NULL;
514  const char *uname = NULL;
515  const char *type = NULL;
516  const char *score = NULL;
517 
518  for (xml_obj = __xml_first_child_element(xml_nodes); xml_obj != NULL;
519  xml_obj = __xml_next_element(xml_obj)) {
520 
521  if (crm_str_eq((const char *)xml_obj->name, XML_CIB_TAG_NODE, TRUE)) {
522  new_node = NULL;
523 
524  id = crm_element_value(xml_obj, XML_ATTR_ID);
525  uname = crm_element_value(xml_obj, XML_ATTR_UNAME);
526  type = crm_element_value(xml_obj, XML_ATTR_TYPE);
527  score = crm_element_value(xml_obj, XML_RULE_ATTR_SCORE);
528  crm_trace("Processing node %s/%s", uname, id);
529 
530  if (id == NULL) {
532  "> entry in configuration without id");
533  continue;
534  }
535  new_node = pe_create_node(id, uname, type, score, data_set);
536 
537  if (new_node == NULL) {
538  return FALSE;
539  }
540 
541 /* if(data_set->have_quorum == FALSE */
542 /* && data_set->no_quorum_policy == no_quorum_stop) { */
543 /* /\* start shutting resources down *\/ */
544 /* new_node->weight = -INFINITY; */
545 /* } */
546 
547  handle_startup_fencing(data_set, new_node);
548 
549  add_node_attrs(xml_obj, new_node, FALSE, data_set);
551  new_node->details->utilization, NULL,
552  FALSE, data_set);
553 
554  crm_trace("Done with node %s", crm_element_value(xml_obj, XML_ATTR_UNAME));
555  }
556  }
557 
558  if (data_set->localhost && pe_find_node(data_set->nodes, data_set->localhost) == NULL) {
559  crm_info("Creating a fake local node");
560  pe_create_node(data_set->localhost, data_set->localhost, NULL, 0,
561  data_set);
562  }
563 
564  return TRUE;
565 }
566 
567 static void
568 setup_container(pe_resource_t * rsc, pe_working_set_t * data_set)
569 {
570  const char *container_id = NULL;
571 
572  if (rsc->children) {
573  GListPtr gIter = rsc->children;
574 
575  for (; gIter != NULL; gIter = gIter->next) {
576  pe_resource_t *child_rsc = (pe_resource_t *) gIter->data;
577 
578  setup_container(child_rsc, data_set);
579  }
580  return;
581  }
582 
583  container_id = g_hash_table_lookup(rsc->meta, XML_RSC_ATTR_CONTAINER);
584  if (container_id && safe_str_neq(container_id, rsc->id)) {
585  pe_resource_t *container = pe_find_resource(data_set->resources, container_id);
586 
587  if (container) {
588  rsc->container = container;
589  set_bit(container->flags, pe_rsc_is_container);
590  container->fillers = g_list_append(container->fillers, rsc);
591  pe_rsc_trace(rsc, "Resource %s's container is %s", rsc->id, container_id);
592  } else {
593  pe_err("Resource %s: Unknown resource container (%s)", rsc->id, container_id);
594  }
595  }
596 }
597 
598 gboolean
599 unpack_remote_nodes(xmlNode * xml_resources, pe_working_set_t * data_set)
600 {
601  xmlNode *xml_obj = NULL;
602 
603  /* Create remote nodes and guest nodes from the resource configuration
604  * before unpacking resources.
605  */
606  for (xml_obj = __xml_first_child_element(xml_resources); xml_obj != NULL;
607  xml_obj = __xml_next_element(xml_obj)) {
608 
609  const char *new_node_id = NULL;
610 
611  /* Check for remote nodes, which are defined by ocf:pacemaker:remote
612  * primitives.
613  */
614  if (xml_contains_remote_node(xml_obj)) {
615  new_node_id = ID(xml_obj);
616  /* The "pe_find_node" check is here to make sure we don't iterate over
617  * an expanded node that has already been added to the node list. */
618  if (new_node_id && pe_find_node(data_set->nodes, new_node_id) == NULL) {
619  crm_trace("Found remote node %s defined by resource %s",
620  new_node_id, ID(xml_obj));
621  pe_create_node(new_node_id, new_node_id, "remote", NULL,
622  data_set);
623  }
624  continue;
625  }
626 
627  /* Check for guest nodes, which are defined by special meta-attributes
628  * of a primitive of any type (for example, VirtualDomain or Xen).
629  */
630  if (crm_str_eq((const char *)xml_obj->name, XML_CIB_TAG_RESOURCE, TRUE)) {
631  /* This will add an ocf:pacemaker:remote primitive to the
632  * configuration for the guest node's connection, to be unpacked
633  * later.
634  */
635  new_node_id = expand_remote_rsc_meta(xml_obj, xml_resources, data_set);
636  if (new_node_id && pe_find_node(data_set->nodes, new_node_id) == NULL) {
637  crm_trace("Found guest node %s in resource %s",
638  new_node_id, ID(xml_obj));
639  pe_create_node(new_node_id, new_node_id, "remote", NULL,
640  data_set);
641  }
642  continue;
643  }
644 
645  /* Check for guest nodes inside a group. Clones are currently not
646  * supported as guest nodes.
647  */
648  if (crm_str_eq((const char *)xml_obj->name, XML_CIB_TAG_GROUP, TRUE)) {
649  xmlNode *xml_obj2 = NULL;
650  for (xml_obj2 = __xml_first_child_element(xml_obj); xml_obj2 != NULL;
651  xml_obj2 = __xml_next_element(xml_obj2)) {
652 
653  new_node_id = expand_remote_rsc_meta(xml_obj2, xml_resources, data_set);
654 
655  if (new_node_id && pe_find_node(data_set->nodes, new_node_id) == NULL) {
656  crm_trace("Found guest node %s in resource %s inside group %s",
657  new_node_id, ID(xml_obj2), ID(xml_obj));
658  pe_create_node(new_node_id, new_node_id, "remote", NULL,
659  data_set);
660  }
661  }
662  }
663  }
664  return TRUE;
665 }
666 
667 /* Call this after all the nodes and resources have been
668  * unpacked, but before the status section is read.
669  *
670  * A remote node's online status is reflected by the state
671  * of the remote node's connection resource. We need to link
672  * the remote node to this connection resource so we can have
673  * easy access to the connection resource during the scheduler calculations.
674  */
675 static void
676 link_rsc2remotenode(pe_working_set_t *data_set, pe_resource_t *new_rsc)
677 {
678  pe_node_t *remote_node = NULL;
679 
680  if (new_rsc->is_remote_node == FALSE) {
681  return;
682  }
683 
684  if (is_set(data_set->flags, pe_flag_quick_location)) {
685  /* remote_nodes and remote_resources are not linked in quick location calculations */
686  return;
687  }
688 
689  remote_node = pe_find_node(data_set->nodes, new_rsc->id);
690  CRM_CHECK(remote_node != NULL, return;);
691 
692  pe_rsc_trace(new_rsc, "Linking remote connection resource %s to node %s",
693  new_rsc->id, remote_node->details->uname);
694  remote_node->details->remote_rsc = new_rsc;
695 
696  if (new_rsc->container == NULL) {
697  /* Handle start-up fencing for remote nodes (as opposed to guest nodes)
698  * the same as is done for cluster nodes.
699  */
700  handle_startup_fencing(data_set, remote_node);
701 
702  } else {
703  /* pe_create_node() marks the new node as "remote" or "cluster"; now
704  * that we know the node is a guest node, update it correctly.
705  */
706  g_hash_table_replace(remote_node->details->attrs, strdup(CRM_ATTR_KIND),
707  strdup("container"));
708  }
709 }
710 
711 static void
712 destroy_tag(gpointer data)
713 {
714  pe_tag_t *tag = data;
715 
716  if (tag) {
717  free(tag->id);
718  g_list_free_full(tag->refs, free);
719  free(tag);
720  }
721 }
722 
735 gboolean
736 unpack_resources(xmlNode * xml_resources, pe_working_set_t * data_set)
737 {
738  xmlNode *xml_obj = NULL;
739  GListPtr gIter = NULL;
740 
741  data_set->template_rsc_sets = g_hash_table_new_full(crm_str_hash,
742  g_str_equal, free,
743  destroy_tag);
744 
745  for (xml_obj = __xml_first_child_element(xml_resources); xml_obj != NULL;
746  xml_obj = __xml_next_element(xml_obj)) {
747 
748  pe_resource_t *new_rsc = NULL;
749 
750  if (crm_str_eq((const char *)xml_obj->name, XML_CIB_TAG_RSC_TEMPLATE, TRUE)) {
751  const char *template_id = ID(xml_obj);
752 
753  if (template_id && g_hash_table_lookup_extended(data_set->template_rsc_sets,
754  template_id, NULL, NULL) == FALSE) {
755  /* Record the template's ID for the knowledge of its existence anyway. */
756  g_hash_table_insert(data_set->template_rsc_sets, strdup(template_id), NULL);
757  }
758  continue;
759  }
760 
761  crm_trace("Beginning unpack... <%s id=%s... >", crm_element_name(xml_obj), ID(xml_obj));
762  if (common_unpack(xml_obj, &new_rsc, NULL, data_set) && (new_rsc != NULL)) {
763  data_set->resources = g_list_append(data_set->resources, new_rsc);
764  pe_rsc_trace(new_rsc, "Added resource %s", new_rsc->id);
765 
766  } else {
767  pcmk__config_err("Ignoring <%s> resource '%s' "
768  "because configuration is invalid",
769  crm_element_name(xml_obj), crm_str(ID(xml_obj)));
770  if (new_rsc != NULL && new_rsc->fns != NULL) {
771  new_rsc->fns->free(new_rsc);
772  }
773  }
774  }
775 
776  for (gIter = data_set->resources; gIter != NULL; gIter = gIter->next) {
777  pe_resource_t *rsc = (pe_resource_t *) gIter->data;
778 
779  setup_container(rsc, data_set);
780  link_rsc2remotenode(data_set, rsc);
781  }
782 
783  data_set->resources = g_list_sort(data_set->resources, sort_rsc_priority);
784  if (is_set(data_set->flags, pe_flag_quick_location)) {
785  /* Ignore */
786 
787  } else if (is_set(data_set->flags, pe_flag_stonith_enabled)
788  && is_set(data_set->flags, pe_flag_have_stonith_resource) == FALSE) {
789 
790  pcmk__config_err("Resource start-up disabled since no STONITH resources have been defined");
791  pcmk__config_err("Either configure some or disable STONITH with the stonith-enabled option");
792  pcmk__config_err("NOTE: Clusters with shared data need STONITH to ensure data integrity");
793  }
794 
795  return TRUE;
796 }
797 
798 gboolean
799 unpack_tags(xmlNode * xml_tags, pe_working_set_t * data_set)
800 {
801  xmlNode *xml_tag = NULL;
802 
803  data_set->tags = g_hash_table_new_full(crm_str_hash, g_str_equal, free,
804  destroy_tag);
805 
806  for (xml_tag = __xml_first_child_element(xml_tags); xml_tag != NULL;
807  xml_tag = __xml_next_element(xml_tag)) {
808 
809  xmlNode *xml_obj_ref = NULL;
810  const char *tag_id = ID(xml_tag);
811 
812  if (crm_str_eq((const char *)xml_tag->name, XML_CIB_TAG_TAG, TRUE) == FALSE) {
813  continue;
814  }
815 
816  if (tag_id == NULL) {
817  pcmk__config_err("Ignoring <%s> without " XML_ATTR_ID,
818  crm_element_name(xml_tag));
819  continue;
820  }
821 
822  for (xml_obj_ref = __xml_first_child_element(xml_tag); xml_obj_ref != NULL;
823  xml_obj_ref = __xml_next_element(xml_obj_ref)) {
824 
825  const char *obj_ref = ID(xml_obj_ref);
826 
827  if (crm_str_eq((const char *)xml_obj_ref->name, XML_CIB_TAG_OBJ_REF, TRUE) == FALSE) {
828  continue;
829  }
830 
831  if (obj_ref == NULL) {
832  pcmk__config_err("Ignoring <%s> for tag '%s' without " XML_ATTR_ID,
833  crm_element_name(xml_obj_ref), tag_id);
834  continue;
835  }
836 
837  if (add_tag_ref(data_set->tags, tag_id, obj_ref) == FALSE) {
838  return FALSE;
839  }
840  }
841  }
842 
843  return TRUE;
844 }
845 
846 /* The ticket state section:
847  * "/cib/status/tickets/ticket_state" */
848 static gboolean
849 unpack_ticket_state(xmlNode * xml_ticket, pe_working_set_t * data_set)
850 {
851  const char *ticket_id = NULL;
852  const char *granted = NULL;
853  const char *last_granted = NULL;
854  const char *standby = NULL;
855  xmlAttrPtr xIter = NULL;
856 
857  pe_ticket_t *ticket = NULL;
858 
859  ticket_id = ID(xml_ticket);
860  if (ticket_id == NULL || strlen(ticket_id) == 0) {
861  return FALSE;
862  }
863 
864  crm_trace("Processing ticket state for %s", ticket_id);
865 
866  ticket = g_hash_table_lookup(data_set->tickets, ticket_id);
867  if (ticket == NULL) {
868  ticket = ticket_new(ticket_id, data_set);
869  if (ticket == NULL) {
870  return FALSE;
871  }
872  }
873 
874  for (xIter = xml_ticket->properties; xIter; xIter = xIter->next) {
875  const char *prop_name = (const char *)xIter->name;
876  const char *prop_value = crm_element_value(xml_ticket, prop_name);
877 
878  if (crm_str_eq(prop_name, XML_ATTR_ID, TRUE)) {
879  continue;
880  }
881  g_hash_table_replace(ticket->state, strdup(prop_name), strdup(prop_value));
882  }
883 
884  granted = g_hash_table_lookup(ticket->state, "granted");
885  if (granted && crm_is_true(granted)) {
886  ticket->granted = TRUE;
887  crm_info("We have ticket '%s'", ticket->id);
888  } else {
889  ticket->granted = FALSE;
890  crm_info("We do not have ticket '%s'", ticket->id);
891  }
892 
893  last_granted = g_hash_table_lookup(ticket->state, "last-granted");
894  if (last_granted) {
895  ticket->last_granted = crm_parse_int(last_granted, 0);
896  }
897 
898  standby = g_hash_table_lookup(ticket->state, "standby");
899  if (standby && crm_is_true(standby)) {
900  ticket->standby = TRUE;
901  if (ticket->granted) {
902  crm_info("Granted ticket '%s' is in standby-mode", ticket->id);
903  }
904  } else {
905  ticket->standby = FALSE;
906  }
907 
908  crm_trace("Done with ticket state for %s", ticket_id);
909 
910  return TRUE;
911 }
912 
913 static gboolean
914 unpack_tickets_state(xmlNode * xml_tickets, pe_working_set_t * data_set)
915 {
916  xmlNode *xml_obj = NULL;
917 
918  for (xml_obj = __xml_first_child_element(xml_tickets); xml_obj != NULL;
919  xml_obj = __xml_next_element(xml_obj)) {
920 
921  if (crm_str_eq((const char *)xml_obj->name, XML_CIB_TAG_TICKET_STATE, TRUE) == FALSE) {
922  continue;
923  }
924  unpack_ticket_state(xml_obj, data_set);
925  }
926 
927  return TRUE;
928 }
929 
930 static void
931 unpack_handle_remote_attrs(pe_node_t *this_node, xmlNode *state, pe_working_set_t * data_set)
932 {
933  const char *resource_discovery_enabled = NULL;
934  xmlNode *attrs = NULL;
935  pe_resource_t *rsc = NULL;
936 
937  if (crm_str_eq((const char *)state->name, XML_CIB_TAG_STATE, TRUE) == FALSE) {
938  return;
939  }
940 
941  if ((this_node == NULL) || !pe__is_guest_or_remote_node(this_node)) {
942  return;
943  }
944  crm_trace("Processing remote node id=%s, uname=%s", this_node->details->id, this_node->details->uname);
945 
946  this_node->details->remote_maintenance =
948 
949  rsc = this_node->details->remote_rsc;
950  if (this_node->details->remote_requires_reset == FALSE) {
951  this_node->details->unclean = FALSE;
952  this_node->details->unseen = FALSE;
953  }
954  attrs = find_xml_node(state, XML_TAG_TRANSIENT_NODEATTRS, FALSE);
955  add_node_attrs(attrs, this_node, TRUE, data_set);
956 
957  if (pe__shutdown_requested(this_node)) {
958  crm_info("Node %s is shutting down", this_node->details->uname);
959  this_node->details->shutdown = TRUE;
960  if (rsc) {
962  }
963  }
964 
965  if (crm_is_true(pe_node_attribute_raw(this_node, "standby"))) {
966  crm_info("Node %s is in standby-mode", this_node->details->uname);
967  this_node->details->standby = TRUE;
968  }
969 
970  if (crm_is_true(pe_node_attribute_raw(this_node, "maintenance")) ||
971  (rsc && !is_set(rsc->flags, pe_rsc_managed))) {
972  crm_info("Node %s is in maintenance-mode", this_node->details->uname);
973  this_node->details->maintenance = TRUE;
974  }
975 
976  resource_discovery_enabled = pe_node_attribute_raw(this_node, XML_NODE_ATTR_RSC_DISCOVERY);
977  if (resource_discovery_enabled && !crm_is_true(resource_discovery_enabled)) {
978  if (pe__is_remote_node(this_node)
979  && is_not_set(data_set->flags, pe_flag_stonith_enabled)) {
980  crm_warn("Ignoring %s attribute on remote node %s because stonith is disabled",
982  } else {
983  /* This is either a remote node with fencing enabled, or a guest
984  * node. We don't care whether fencing is enabled when fencing guest
985  * nodes, because they are "fenced" by recovering their containing
986  * resource.
987  */
988  crm_info("Node %s has resource discovery disabled", this_node->details->uname);
989  this_node->details->rsc_discovery_enabled = FALSE;
990  }
991  }
992 }
993 
994 static bool
995 unpack_node_loop(xmlNode * status, bool fence, pe_working_set_t * data_set)
996 {
997  bool changed = false;
998  xmlNode *lrm_rsc = NULL;
999 
1000  for (xmlNode *state = __xml_first_child_element(status); state != NULL;
1001  state = __xml_next_element(state)) {
1002 
1003  const char *id = NULL;
1004  const char *uname = NULL;
1005  pe_node_t *this_node = NULL;
1006  bool process = FALSE;
1007 
1008  if (crm_str_eq((const char *)state->name, XML_CIB_TAG_STATE, TRUE) == FALSE) {
1009  continue;
1010  }
1011 
1012  id = crm_element_value(state, XML_ATTR_ID);
1013  uname = crm_element_value(state, XML_ATTR_UNAME);
1014  this_node = pe_find_node_any(data_set->nodes, id, uname);
1015 
1016  if (this_node == NULL) {
1017  crm_info("Node %s is unknown", id);
1018  continue;
1019 
1020  } else if (this_node->details->unpacked) {
1021  crm_trace("Node %s was already processed", id);
1022  continue;
1023 
1024  } else if (!pe__is_guest_or_remote_node(this_node)
1025  && is_set(data_set->flags, pe_flag_stonith_enabled)) {
1026  // A redundant test, but preserves the order for regression tests
1027  process = TRUE;
1028 
1029  } else if (pe__is_guest_or_remote_node(this_node)) {
1030  bool check = FALSE;
1031  pe_resource_t *rsc = this_node->details->remote_rsc;
1032 
1033  if(fence) {
1034  check = TRUE;
1035 
1036  } else if(rsc == NULL) {
1037  /* Not ready yet */
1038 
1039  } else if (pe__is_guest_node(this_node)
1040  && rsc->role == RSC_ROLE_STARTED
1041  && rsc->container->role == RSC_ROLE_STARTED) {
1042  /* Both the connection and its containing resource need to be
1043  * known to be up before we process resources running in it.
1044  */
1045  check = TRUE;
1046  crm_trace("Checking node %s/%s/%s status %d/%d/%d", id, rsc->id, rsc->container->id, fence, rsc->role, RSC_ROLE_STARTED);
1047 
1048  } else if (!pe__is_guest_node(this_node)
1049  && ((rsc->role == RSC_ROLE_STARTED)
1050  || is_set(data_set->flags, pe_flag_shutdown_lock))) {
1051  check = TRUE;
1052  crm_trace("Checking node %s/%s status %d/%d/%d", id, rsc->id, fence, rsc->role, RSC_ROLE_STARTED);
1053  }
1054 
1055  if (check) {
1056  determine_remote_online_status(data_set, this_node);
1057  unpack_handle_remote_attrs(this_node, state, data_set);
1058  process = TRUE;
1059  }
1060 
1061  } else if (this_node->details->online) {
1062  process = TRUE;
1063 
1064  } else if (fence) {
1065  process = TRUE;
1066 
1067  } else if (is_set(data_set->flags, pe_flag_shutdown_lock)) {
1068  process = TRUE;
1069  }
1070 
1071  if(process) {
1072  crm_trace("Processing lrm resource entries on %shealthy%s node: %s",
1073  fence?"un":"",
1074  (pe__is_guest_or_remote_node(this_node)? " remote" : ""),
1075  this_node->details->uname);
1076  changed = TRUE;
1077  this_node->details->unpacked = TRUE;
1078 
1079  lrm_rsc = find_xml_node(state, XML_CIB_TAG_LRM, FALSE);
1080  lrm_rsc = find_xml_node(lrm_rsc, XML_LRM_TAG_RESOURCES, FALSE);
1081  unpack_lrm_resources(this_node, lrm_rsc, data_set);
1082  }
1083  }
1084  return changed;
1085 }
1086 
1087 /* remove nodes that are down, stopping */
1088 /* create positive rsc_to_node constraints between resources and the nodes they are running on */
1089 /* anything else? */
1090 gboolean
1091 unpack_status(xmlNode * status, pe_working_set_t * data_set)
1092 {
1093  const char *id = NULL;
1094  const char *uname = NULL;
1095 
1096  xmlNode *state = NULL;
1097  pe_node_t *this_node = NULL;
1098 
1099  crm_trace("Beginning unpack");
1100 
1101  if (data_set->tickets == NULL) {
1102  data_set->tickets = g_hash_table_new_full(crm_str_hash, g_str_equal,
1103  free, destroy_ticket);
1104  }
1105 
1106  for (state = __xml_first_child_element(status); state != NULL;
1107  state = __xml_next_element(state)) {
1108 
1109  if (crm_str_eq((const char *)state->name, XML_CIB_TAG_TICKETS, TRUE)) {
1110  unpack_tickets_state((xmlNode *) state, data_set);
1111 
1112  } else if (crm_str_eq((const char *)state->name, XML_CIB_TAG_STATE, TRUE)) {
1113  xmlNode *attrs = NULL;
1114  const char *resource_discovery_enabled = NULL;
1115 
1116  id = crm_element_value(state, XML_ATTR_ID);
1117  uname = crm_element_value(state, XML_ATTR_UNAME);
1118  this_node = pe_find_node_any(data_set->nodes, id, uname);
1119 
1120  if (uname == NULL) {
1121  /* error */
1122  continue;
1123 
1124  } else if (this_node == NULL) {
1125  pcmk__config_warn("Ignoring recorded node status for '%s' "
1126  "because no longer in configuration", uname);
1127  continue;
1128 
1129  } else if (pe__is_guest_or_remote_node(this_node)) {
1130  /* online state for remote nodes is determined by the
1131  * rsc state after all the unpacking is done. we do however
1132  * need to mark whether or not the node has been fenced as this plays
1133  * a role during unpacking cluster node resource state */
1134  this_node->details->remote_was_fenced =
1136  continue;
1137  }
1138 
1139  crm_trace("Processing node id=%s, uname=%s", id, uname);
1140 
1141  /* Mark the node as provisionally clean
1142  * - at least we have seen it in the current cluster's lifetime
1143  */
1144  this_node->details->unclean = FALSE;
1145  this_node->details->unseen = FALSE;
1146  attrs = find_xml_node(state, XML_TAG_TRANSIENT_NODEATTRS, FALSE);
1147  add_node_attrs(attrs, this_node, TRUE, data_set);
1148 
1149  if (crm_is_true(pe_node_attribute_raw(this_node, "standby"))) {
1150  crm_info("Node %s is in standby-mode", this_node->details->uname);
1151  this_node->details->standby = TRUE;
1152  }
1153 
1154  if (crm_is_true(pe_node_attribute_raw(this_node, "maintenance"))) {
1155  crm_info("Node %s is in maintenance-mode", this_node->details->uname);
1156  this_node->details->maintenance = TRUE;
1157  }
1158 
1159  resource_discovery_enabled = pe_node_attribute_raw(this_node, XML_NODE_ATTR_RSC_DISCOVERY);
1160  if (resource_discovery_enabled && !crm_is_true(resource_discovery_enabled)) {
1161  crm_warn("ignoring %s attribute on node %s, disabling resource discovery is not allowed on cluster nodes",
1163  }
1164 
1165  crm_trace("determining node state");
1166  determine_online_status(state, this_node, data_set);
1167 
1168  if (is_not_set(data_set->flags, pe_flag_have_quorum)
1169  && this_node->details->online
1170  && (data_set->no_quorum_policy == no_quorum_suicide)) {
1171  /* Everything else should flow from this automatically
1172  * (at least until the scheduler becomes able to migrate off
1173  * healthy resources)
1174  */
1175  pe_fence_node(data_set, this_node, "cluster does not have quorum", FALSE);
1176  }
1177  }
1178  }
1179 
1180 
1181  while(unpack_node_loop(status, FALSE, data_set)) {
1182  crm_trace("Start another loop");
1183  }
1184 
1185  // Now catch any nodes we didn't see
1186  unpack_node_loop(status, is_set(data_set->flags, pe_flag_stonith_enabled), data_set);
1187 
1188  /* Now that we know where resources are, we can schedule stops of containers
1189  * with failed bundle connections
1190  */
1191  if (data_set->stop_needed != NULL) {
1192  for (GList *item = data_set->stop_needed; item; item = item->next) {
1193  pe_resource_t *container = item->data;
1194  pe_node_t *node = pe__current_node(container);
1195 
1196  if (node) {
1197  stop_action(container, node, FALSE);
1198  }
1199  }
1200  g_list_free(data_set->stop_needed);
1201  data_set->stop_needed = NULL;
1202  }
1203 
1204  for (GListPtr gIter = data_set->nodes; gIter != NULL; gIter = gIter->next) {
1205  pe_node_t *this_node = gIter->data;
1206 
1207  if (this_node == NULL) {
1208  continue;
1209  } else if (!pe__is_guest_or_remote_node(this_node)) {
1210  continue;
1211  } else if(this_node->details->unpacked) {
1212  continue;
1213  }
1214  determine_remote_online_status(data_set, this_node);
1215  }
1216 
1217  return TRUE;
1218 }
1219 
1220 static gboolean
1221 determine_online_status_no_fencing(pe_working_set_t * data_set, xmlNode * node_state,
1222  pe_node_t * this_node)
1223 {
1224  gboolean online = FALSE;
1225  const char *join = crm_element_value(node_state, XML_NODE_JOIN_STATE);
1226  const char *is_peer = crm_element_value(node_state, XML_NODE_IS_PEER);
1227  const char *in_cluster = crm_element_value(node_state, XML_NODE_IN_CLUSTER);
1228  const char *exp_state = crm_element_value(node_state, XML_NODE_EXPECTED);
1229 
1230  if (!crm_is_true(in_cluster)) {
1231  crm_trace("Node is down: in_cluster=%s", crm_str(in_cluster));
1232 
1233  } else if (safe_str_eq(is_peer, ONLINESTATUS)) {
1234  if (safe_str_eq(join, CRMD_JOINSTATE_MEMBER)) {
1235  online = TRUE;
1236  } else {
1237  crm_debug("Node is not ready to run resources: %s", join);
1238  }
1239 
1240  } else if (this_node->details->expected_up == FALSE) {
1241  crm_trace("Controller is down: in_cluster=%s", crm_str(in_cluster));
1242  crm_trace("\tis_peer=%s, join=%s, expected=%s",
1243  crm_str(is_peer), crm_str(join), crm_str(exp_state));
1244 
1245  } else {
1246  /* mark it unclean */
1247  pe_fence_node(data_set, this_node, "peer is unexpectedly down", FALSE);
1248  crm_info("\tin_cluster=%s, is_peer=%s, join=%s, expected=%s",
1249  crm_str(in_cluster), crm_str(is_peer), crm_str(join), crm_str(exp_state));
1250  }
1251  return online;
1252 }
1253 
1254 static gboolean
1255 determine_online_status_fencing(pe_working_set_t * data_set, xmlNode * node_state,
1256  pe_node_t * this_node)
1257 {
1258  gboolean online = FALSE;
1259  gboolean do_terminate = FALSE;
1260  bool crmd_online = FALSE;
1261  const char *join = crm_element_value(node_state, XML_NODE_JOIN_STATE);
1262  const char *is_peer = crm_element_value(node_state, XML_NODE_IS_PEER);
1263  const char *in_cluster = crm_element_value(node_state, XML_NODE_IN_CLUSTER);
1264  const char *exp_state = crm_element_value(node_state, XML_NODE_EXPECTED);
1265  const char *terminate = pe_node_attribute_raw(this_node, "terminate");
1266 
1267 /*
1268  - XML_NODE_IN_CLUSTER ::= true|false
1269  - XML_NODE_IS_PEER ::= online|offline
1270  - XML_NODE_JOIN_STATE ::= member|down|pending|banned
1271  - XML_NODE_EXPECTED ::= member|down
1272 */
1273 
1274  if (crm_is_true(terminate)) {
1275  do_terminate = TRUE;
1276 
1277  } else if (terminate != NULL && strlen(terminate) > 0) {
1278  /* could be a time() value */
1279  char t = terminate[0];
1280 
1281  if (t != '0' && isdigit(t)) {
1282  do_terminate = TRUE;
1283  }
1284  }
1285 
1286  crm_trace("%s: in_cluster=%s, is_peer=%s, join=%s, expected=%s, term=%d",
1287  this_node->details->uname, crm_str(in_cluster), crm_str(is_peer),
1288  crm_str(join), crm_str(exp_state), do_terminate);
1289 
1290  online = crm_is_true(in_cluster);
1291  crmd_online = safe_str_eq(is_peer, ONLINESTATUS);
1292  if (exp_state == NULL) {
1293  exp_state = CRMD_JOINSTATE_DOWN;
1294  }
1295 
1296  if (this_node->details->shutdown) {
1297  crm_debug("%s is shutting down", this_node->details->uname);
1298 
1299  /* Slightly different criteria since we can't shut down a dead peer */
1300  online = crmd_online;
1301 
1302  } else if (in_cluster == NULL) {
1303  pe_fence_node(data_set, this_node, "peer has not been seen by the cluster", FALSE);
1304 
1305  } else if (safe_str_eq(join, CRMD_JOINSTATE_NACK)) {
1306  pe_fence_node(data_set, this_node, "peer failed the pacemaker membership criteria", FALSE);
1307 
1308  } else if (do_terminate == FALSE && safe_str_eq(exp_state, CRMD_JOINSTATE_DOWN)) {
1309 
1310  if (crm_is_true(in_cluster) || crmd_online) {
1311  crm_info("- Node %s is not ready to run resources", this_node->details->uname);
1312  this_node->details->standby = TRUE;
1313  this_node->details->pending = TRUE;
1314 
1315  } else {
1316  crm_trace("%s is down or still coming up", this_node->details->uname);
1317  }
1318 
1319  } else if (do_terminate && safe_str_eq(join, CRMD_JOINSTATE_DOWN)
1320  && crm_is_true(in_cluster) == FALSE && !crmd_online) {
1321  crm_info("Node %s was just shot", this_node->details->uname);
1322  online = FALSE;
1323 
1324  } else if (crm_is_true(in_cluster) == FALSE) {
1325  // Consider `priority-fencing-delay` for lost nodes
1326  pe_fence_node(data_set, this_node, "peer is no longer part of the cluster", TRUE);
1327 
1328  } else if (!crmd_online) {
1329  pe_fence_node(data_set, this_node, "peer process is no longer available", FALSE);
1330 
1331  /* Everything is running at this point, now check join state */
1332  } else if (do_terminate) {
1333  pe_fence_node(data_set, this_node, "termination was requested", FALSE);
1334 
1335  } else if (safe_str_eq(join, CRMD_JOINSTATE_MEMBER)) {
1336  crm_info("Node %s is active", this_node->details->uname);
1337 
1338  } else if (safe_str_eq(join, CRMD_JOINSTATE_PENDING)
1339  || safe_str_eq(join, CRMD_JOINSTATE_DOWN)) {
1340  crm_info("Node %s is not ready to run resources", this_node->details->uname);
1341  this_node->details->standby = TRUE;
1342  this_node->details->pending = TRUE;
1343 
1344  } else {
1345  pe_fence_node(data_set, this_node, "peer was in an unknown state", FALSE);
1346  crm_warn("%s: in-cluster=%s, is-peer=%s, join=%s, expected=%s, term=%d, shutdown=%d",
1347  this_node->details->uname, crm_str(in_cluster), crm_str(is_peer),
1348  crm_str(join), crm_str(exp_state), do_terminate, this_node->details->shutdown);
1349  }
1350 
1351  return online;
1352 }
1353 
1354 static void
1355 determine_remote_online_status(pe_working_set_t * data_set, pe_node_t * this_node)
1356 {
1357  pe_resource_t *rsc = this_node->details->remote_rsc;
1358  pe_resource_t *container = NULL;
1359  pe_node_t *host = NULL;
1360 
1361  /* If there is a node state entry for a (former) Pacemaker Remote node
1362  * but no resource creating that node, the node's connection resource will
1363  * be NULL. Consider it an offline remote node in that case.
1364  */
1365  if (rsc == NULL) {
1366  this_node->details->online = FALSE;
1367  goto remote_online_done;
1368  }
1369 
1370  container = rsc->container;
1371 
1372  if (container && pcmk__list_of_1(rsc->running_on)) {
1373  host = rsc->running_on->data;
1374  }
1375 
1376  /* If the resource is currently started, mark it online. */
1377  if (rsc->role == RSC_ROLE_STARTED) {
1378  crm_trace("%s node %s presumed ONLINE because connection resource is started",
1379  (container? "Guest" : "Remote"), this_node->details->id);
1380  this_node->details->online = TRUE;
1381  }
1382 
1383  /* consider this node shutting down if transitioning start->stop */
1384  if (rsc->role == RSC_ROLE_STARTED && rsc->next_role == RSC_ROLE_STOPPED) {
1385  crm_trace("%s node %s shutting down because connection resource is stopping",
1386  (container? "Guest" : "Remote"), this_node->details->id);
1387  this_node->details->shutdown = TRUE;
1388  }
1389 
1390  /* Now check all the failure conditions. */
1391  if(container && is_set(container->flags, pe_rsc_failed)) {
1392  crm_trace("Guest node %s UNCLEAN because guest resource failed",
1393  this_node->details->id);
1394  this_node->details->online = FALSE;
1395  this_node->details->remote_requires_reset = TRUE;
1396 
1397  } else if(is_set(rsc->flags, pe_rsc_failed)) {
1398  crm_trace("%s node %s OFFLINE because connection resource failed",
1399  (container? "Guest" : "Remote"), this_node->details->id);
1400  this_node->details->online = FALSE;
1401 
1402  } else if (rsc->role == RSC_ROLE_STOPPED
1403  || (container && container->role == RSC_ROLE_STOPPED)) {
1404 
1405  crm_trace("%s node %s OFFLINE because its resource is stopped",
1406  (container? "Guest" : "Remote"), this_node->details->id);
1407  this_node->details->online = FALSE;
1408  this_node->details->remote_requires_reset = FALSE;
1409 
1410  } else if (host && (host->details->online == FALSE)
1411  && host->details->unclean) {
1412  crm_trace("Guest node %s UNCLEAN because host is unclean",
1413  this_node->details->id);
1414  this_node->details->online = FALSE;
1415  this_node->details->remote_requires_reset = TRUE;
1416  }
1417 
1418 remote_online_done:
1419  crm_trace("Remote node %s online=%s",
1420  this_node->details->id, this_node->details->online ? "TRUE" : "FALSE");
1421 }
1422 
1423 static void
1424 determine_online_status(xmlNode * node_state, pe_node_t * this_node, pe_working_set_t * data_set)
1425 {
1426  gboolean online = FALSE;
1427  const char *exp_state = crm_element_value(node_state, XML_NODE_EXPECTED);
1428 
1429  CRM_CHECK(this_node != NULL, return);
1430 
1431  this_node->details->shutdown = FALSE;
1432  this_node->details->expected_up = FALSE;
1433 
1434  if (pe__shutdown_requested(this_node)) {
1435  this_node->details->shutdown = TRUE;
1436 
1437  } else if (safe_str_eq(exp_state, CRMD_JOINSTATE_MEMBER)) {
1438  this_node->details->expected_up = TRUE;
1439  }
1440 
1441  if (this_node->details->type == node_ping) {
1442  this_node->details->unclean = FALSE;
1443  online = FALSE; /* As far as resource management is concerned,
1444  * the node is safely offline.
1445  * Anyone caught abusing this logic will be shot
1446  */
1447 
1448  } else if (is_set(data_set->flags, pe_flag_stonith_enabled) == FALSE) {
1449  online = determine_online_status_no_fencing(data_set, node_state, this_node);
1450 
1451  } else {
1452  online = determine_online_status_fencing(data_set, node_state, this_node);
1453  }
1454 
1455  if (online) {
1456  this_node->details->online = TRUE;
1457 
1458  } else {
1459  /* remove node from contention */
1460  this_node->fixed = TRUE;
1461  this_node->weight = -INFINITY;
1462  }
1463 
1464  if (online && this_node->details->shutdown) {
1465  /* don't run resources here */
1466  this_node->fixed = TRUE;
1467  this_node->weight = -INFINITY;
1468  }
1469 
1470  if (this_node->details->type == node_ping) {
1471  crm_info("Node %s is not a pacemaker node", this_node->details->uname);
1472 
1473  } else if (this_node->details->unclean) {
1474  pe_proc_warn("Node %s is unclean", this_node->details->uname);
1475 
1476  } else if (this_node->details->online) {
1477  crm_info("Node %s is %s", this_node->details->uname,
1478  this_node->details->shutdown ? "shutting down" :
1479  this_node->details->pending ? "pending" :
1480  this_node->details->standby ? "standby" :
1481  this_node->details->maintenance ? "maintenance" : "online");
1482 
1483  } else {
1484  crm_trace("Node %s is offline", this_node->details->uname);
1485  }
1486 }
1487 
1496 const char *
1497 pe_base_name_end(const char *id)
1498 {
1499  if (!pcmk__str_empty(id)) {
1500  const char *end = id + strlen(id) - 1;
1501 
1502  for (const char *s = end; s > id; --s) {
1503  switch (*s) {
1504  case '0':
1505  case '1':
1506  case '2':
1507  case '3':
1508  case '4':
1509  case '5':
1510  case '6':
1511  case '7':
1512  case '8':
1513  case '9':
1514  break;
1515  case ':':
1516  return (s == end)? s : (s - 1);
1517  default:
1518  return end;
1519  }
1520  }
1521  return end;
1522  }
1523  return NULL;
1524 }
1525 
1536 char *
1537 clone_strip(const char *last_rsc_id)
1538 {
1539  const char *end = pe_base_name_end(last_rsc_id);
1540  char *basename = NULL;
1541 
1542  CRM_ASSERT(end);
1543  basename = strndup(last_rsc_id, end - last_rsc_id + 1);
1544  CRM_ASSERT(basename);
1545  return basename;
1546 }
1547 
1558 char *
1559 clone_zero(const char *last_rsc_id)
1560 {
1561  const char *end = pe_base_name_end(last_rsc_id);
1562  size_t base_name_len = end - last_rsc_id + 1;
1563  char *zero = NULL;
1564 
1565  CRM_ASSERT(end);
1566  zero = calloc(base_name_len + 3, sizeof(char));
1567  CRM_ASSERT(zero);
1568  memcpy(zero, last_rsc_id, base_name_len);
1569  zero[base_name_len] = ':';
1570  zero[base_name_len + 1] = '0';
1571  return zero;
1572 }
1573 
1574 static pe_resource_t *
1575 create_fake_resource(const char *rsc_id, xmlNode * rsc_entry, pe_working_set_t * data_set)
1576 {
1577  pe_resource_t *rsc = NULL;
1578  xmlNode *xml_rsc = create_xml_node(NULL, XML_CIB_TAG_RESOURCE);
1579 
1580  copy_in_properties(xml_rsc, rsc_entry);
1581  crm_xml_add(xml_rsc, XML_ATTR_ID, rsc_id);
1582  crm_log_xml_debug(xml_rsc, "Orphan resource");
1583 
1584  if (!common_unpack(xml_rsc, &rsc, NULL, data_set)) {
1585  return NULL;
1586  }
1587 
1588  if (xml_contains_remote_node(xml_rsc)) {
1589  pe_node_t *node;
1590 
1591  crm_debug("Detected orphaned remote node %s", rsc_id);
1592  node = pe_find_node(data_set->nodes, rsc_id);
1593  if (node == NULL) {
1594  node = pe_create_node(rsc_id, rsc_id, "remote", NULL, data_set);
1595  }
1596  link_rsc2remotenode(data_set, rsc);
1597 
1598  if (node) {
1599  crm_trace("Setting node %s as shutting down due to orphaned connection resource", rsc_id);
1600  node->details->shutdown = TRUE;
1601  }
1602  }
1603 
1604  if (crm_element_value(rsc_entry, XML_RSC_ATTR_CONTAINER)) {
1605  /* This orphaned rsc needs to be mapped to a container. */
1606  crm_trace("Detected orphaned container filler %s", rsc_id);
1608  }
1609  set_bit(rsc->flags, pe_rsc_orphan);
1610  data_set->resources = g_list_append(data_set->resources, rsc);
1611  return rsc;
1612 }
1613 
1618 static pe_resource_t *
1619 create_anonymous_orphan(pe_resource_t *parent, const char *rsc_id,
1620  pe_node_t *node, pe_working_set_t *data_set)
1621 {
1622  pe_resource_t *top = pe__create_clone_child(parent, data_set);
1623 
1624  // find_rsc() because we might be a cloned group
1625  pe_resource_t *orphan = top->fns->find_rsc(top, rsc_id, NULL, pe_find_clone);
1626 
1627  pe_rsc_debug(parent, "Created orphan %s for %s: %s on %s",
1628  top->id, parent->id, rsc_id, node->details->uname);
1629  return orphan;
1630 }
1631 
1646 static pe_resource_t *
1647 find_anonymous_clone(pe_working_set_t * data_set, pe_node_t * node, pe_resource_t * parent,
1648  const char *rsc_id)
1649 {
1650  GListPtr rIter = NULL;
1651  pe_resource_t *rsc = NULL;
1652  pe_resource_t *inactive_instance = NULL;
1653  gboolean skip_inactive = FALSE;
1654 
1655  CRM_ASSERT(parent != NULL);
1656  CRM_ASSERT(pe_rsc_is_clone(parent));
1657  CRM_ASSERT(is_not_set(parent->flags, pe_rsc_unique));
1658 
1659  // Check for active (or partially active, for cloned groups) instance
1660  pe_rsc_trace(parent, "Looking for %s on %s in %s", rsc_id, node->details->uname, parent->id);
1661  for (rIter = parent->children; rsc == NULL && rIter; rIter = rIter->next) {
1662  GListPtr locations = NULL;
1663  pe_resource_t *child = rIter->data;
1664 
1665  /* Check whether this instance is already known to be active or pending
1666  * anywhere, at this stage of unpacking. Because this function is called
1667  * for a resource before the resource's individual operation history
1668  * entries are unpacked, locations will generally not contain the
1669  * desired node.
1670  *
1671  * However, there are three exceptions:
1672  * (1) when child is a cloned group and we have already unpacked the
1673  * history of another member of the group on the same node;
1674  * (2) when we've already unpacked the history of another numbered
1675  * instance on the same node (which can happen if globally-unique
1676  * was flipped from true to false); and
1677  * (3) when we re-run calculations on the same data set as part of a
1678  * simulation.
1679  */
1680  child->fns->location(child, &locations, 2);
1681  if (locations) {
1682  /* We should never associate the same numbered anonymous clone
1683  * instance with multiple nodes, and clone instances can't migrate,
1684  * so there must be only one location, regardless of history.
1685  */
1686  CRM_LOG_ASSERT(locations->next == NULL);
1687 
1688  if (((pe_node_t *)locations->data)->details == node->details) {
1689  /* This child instance is active on the requested node, so check
1690  * for a corresponding configured resource. We use find_rsc()
1691  * instead of child because child may be a cloned group, and we
1692  * need the particular member corresponding to rsc_id.
1693  *
1694  * If the history entry is orphaned, rsc will be NULL.
1695  */
1696  rsc = parent->fns->find_rsc(child, rsc_id, NULL, pe_find_clone);
1697  if (rsc) {
1698  /* If there are multiple instance history entries for an
1699  * anonymous clone in a single node's history (which can
1700  * happen if globally-unique is switched from true to
1701  * false), we want to consider the instances beyond the
1702  * first as orphans, even if there are inactive instance
1703  * numbers available.
1704  */
1705  if (rsc->running_on) {
1706  crm_notice("Active (now-)anonymous clone %s has "
1707  "multiple (orphan) instance histories on %s",
1708  parent->id, node->details->uname);
1709  skip_inactive = TRUE;
1710  rsc = NULL;
1711  } else {
1712  pe_rsc_trace(parent, "Resource %s, active", rsc->id);
1713  }
1714  }
1715  }
1716  g_list_free(locations);
1717 
1718  } else {
1719  pe_rsc_trace(parent, "Resource %s, skip inactive", child->id);
1720  if (!skip_inactive && !inactive_instance
1721  && is_not_set(child->flags, pe_rsc_block)) {
1722  // Remember one inactive instance in case we don't find active
1723  inactive_instance = parent->fns->find_rsc(child, rsc_id, NULL,
1724  pe_find_clone);
1725 
1726  /* ... but don't use it if it was already associated with a
1727  * pending action on another node
1728  */
1729  if (inactive_instance && inactive_instance->pending_node
1730  && (inactive_instance->pending_node->details != node->details)) {
1731  inactive_instance = NULL;
1732  }
1733  }
1734  }
1735  }
1736 
1737  if ((rsc == NULL) && !skip_inactive && (inactive_instance != NULL)) {
1738  pe_rsc_trace(parent, "Resource %s, empty slot", inactive_instance->id);
1739  rsc = inactive_instance;
1740  }
1741 
1742  /* If the resource has "requires" set to "quorum" or "nothing", and we don't
1743  * have a clone instance for every node, we don't want to consume a valid
1744  * instance number for unclean nodes. Such instances may appear to be active
1745  * according to the history, but should be considered inactive, so we can
1746  * start an instance elsewhere. Treat such instances as orphans.
1747  *
1748  * An exception is instances running on guest nodes -- since guest node
1749  * "fencing" is actually just a resource stop, requires shouldn't apply.
1750  *
1751  * @TODO Ideally, we'd use an inactive instance number if it is not needed
1752  * for any clean instances. However, we don't know that at this point.
1753  */
1754  if ((rsc != NULL) && is_not_set(rsc->flags, pe_rsc_needs_fencing)
1755  && (!node->details->online || node->details->unclean)
1756  && !pe__is_guest_node(node)
1757  && !pe__is_universal_clone(parent, data_set)) {
1758 
1759  rsc = NULL;
1760  }
1761 
1762  if (rsc == NULL) {
1763  rsc = create_anonymous_orphan(parent, rsc_id, node, data_set);
1764  pe_rsc_trace(parent, "Resource %s, orphan", rsc->id);
1765  }
1766  return rsc;
1767 }
1768 
1769 static pe_resource_t *
1770 unpack_find_resource(pe_working_set_t * data_set, pe_node_t * node, const char *rsc_id,
1771  xmlNode * rsc_entry)
1772 {
1773  pe_resource_t *rsc = NULL;
1774  pe_resource_t *parent = NULL;
1775 
1776  crm_trace("looking for %s", rsc_id);
1777  rsc = pe_find_resource(data_set->resources, rsc_id);
1778 
1779  if (rsc == NULL) {
1780  /* If we didn't find the resource by its name in the operation history,
1781  * check it again as a clone instance. Even when clone-max=0, we create
1782  * a single :0 orphan to match against here.
1783  */
1784  char *clone0_id = clone_zero(rsc_id);
1785  pe_resource_t *clone0 = pe_find_resource(data_set->resources, clone0_id);
1786 
1787  if (clone0 && is_not_set(clone0->flags, pe_rsc_unique)) {
1788  rsc = clone0;
1789  parent = uber_parent(clone0);
1790  crm_trace("%s found as %s (%s)", rsc_id, clone0_id, parent->id);
1791  } else {
1792  crm_trace("%s is not known as %s either (orphan)",
1793  rsc_id, clone0_id);
1794  }
1795  free(clone0_id);
1796 
1797  } else if (rsc->variant > pe_native) {
1798  crm_trace("Resource history for %s is orphaned because it is no longer primitive",
1799  rsc_id);
1800  return NULL;
1801 
1802  } else {
1803  parent = uber_parent(rsc);
1804  }
1805 
1806  if (pe_rsc_is_anon_clone(parent)) {
1807 
1808  if (pe_rsc_is_bundled(parent)) {
1809  rsc = pe__find_bundle_replica(parent->parent, node);
1810  } else {
1811  char *base = clone_strip(rsc_id);
1812 
1813  rsc = find_anonymous_clone(data_set, node, parent, base);
1814  free(base);
1815  CRM_ASSERT(rsc != NULL);
1816  }
1817  }
1818 
1819  if (rsc && safe_str_neq(rsc_id, rsc->id)
1820  && safe_str_neq(rsc_id, rsc->clone_name)) {
1821 
1822  free(rsc->clone_name);
1823  rsc->clone_name = strdup(rsc_id);
1824  pe_rsc_debug(rsc, "Internally renamed %s on %s to %s%s",
1825  rsc_id, node->details->uname, rsc->id,
1826  (is_set(rsc->flags, pe_rsc_orphan)? " (ORPHAN)" : ""));
1827  }
1828  return rsc;
1829 }
1830 
1831 static pe_resource_t *
1832 process_orphan_resource(xmlNode * rsc_entry, pe_node_t * node, pe_working_set_t * data_set)
1833 {
1834  pe_resource_t *rsc = NULL;
1835  const char *rsc_id = crm_element_value(rsc_entry, XML_ATTR_ID);
1836 
1837  crm_debug("Detected orphan resource %s on %s", rsc_id, node->details->uname);
1838  rsc = create_fake_resource(rsc_id, rsc_entry, data_set);
1839 
1840  if (is_set(data_set->flags, pe_flag_stop_rsc_orphans) == FALSE) {
1842 
1843  } else {
1844  CRM_CHECK(rsc != NULL, return NULL);
1845  pe_rsc_trace(rsc, "Added orphan %s", rsc->id);
1846  resource_location(rsc, NULL, -INFINITY, "__orphan_do_not_run__", data_set);
1847  }
1848  return rsc;
1849 }
1850 
1851 static void
1852 process_rsc_state(pe_resource_t * rsc, pe_node_t * node,
1853  enum action_fail_response on_fail,
1854  xmlNode * migrate_op, pe_working_set_t * data_set)
1855 {
1856  pe_node_t *tmpnode = NULL;
1857  char *reason = NULL;
1858 
1859  CRM_ASSERT(rsc);
1860  pe_rsc_trace(rsc, "Resource %s is %s on %s: on_fail=%s",
1861  rsc->id, role2text(rsc->role), node->details->uname, fail2text(on_fail));
1862 
1863  /* process current state */
1864  if (rsc->role != RSC_ROLE_UNKNOWN) {
1865  pe_resource_t *iter = rsc;
1866 
1867  while (iter) {
1868  if (g_hash_table_lookup(iter->known_on, node->details->id) == NULL) {
1869  pe_node_t *n = pe__copy_node(node);
1870 
1871  pe_rsc_trace(rsc, "%s (aka. %s) known on %s", rsc->id, rsc->clone_name,
1872  n->details->uname);
1873  g_hash_table_insert(iter->known_on, (gpointer) n->details->id, n);
1874  }
1875  if (is_set(iter->flags, pe_rsc_unique)) {
1876  break;
1877  }
1878  iter = iter->parent;
1879  }
1880  }
1881 
1882  /* If a managed resource is believed to be running, but node is down ... */
1883  if (rsc->role > RSC_ROLE_STOPPED
1884  && node->details->online == FALSE
1885  && node->details->maintenance == FALSE
1886  && is_set(rsc->flags, pe_rsc_managed)) {
1887 
1888  gboolean should_fence = FALSE;
1889 
1890  /* If this is a guest node, fence it (regardless of whether fencing is
1891  * enabled, because guest node fencing is done by recovery of the
1892  * container resource rather than by the fencer). Mark the resource
1893  * we're processing as failed. When the guest comes back up, its
1894  * operation history in the CIB will be cleared, freeing the affected
1895  * resource to run again once we are sure we know its state.
1896  */
1897  if (pe__is_guest_node(node)) {
1898  set_bit(rsc->flags, pe_rsc_failed);
1899  should_fence = TRUE;
1900 
1901  } else if (is_set(data_set->flags, pe_flag_stonith_enabled)) {
1902  if (pe__is_remote_node(node) && node->details->remote_rsc
1903  && is_not_set(node->details->remote_rsc->flags, pe_rsc_failed)) {
1904 
1905  /* Setting unseen means that fencing of the remote node will
1906  * occur only if the connection resource is not going to start
1907  * somewhere. This allows connection resources on a failed
1908  * cluster node to move to another node without requiring the
1909  * remote nodes to be fenced as well.
1910  */
1911  node->details->unseen = TRUE;
1912  reason = crm_strdup_printf("%s is active there (fencing will be"
1913  " revoked if remote connection can "
1914  "be re-established elsewhere)",
1915  rsc->id);
1916  }
1917  should_fence = TRUE;
1918  }
1919 
1920  if (should_fence) {
1921  if (reason == NULL) {
1922  reason = crm_strdup_printf("%s is thought to be active there", rsc->id);
1923  }
1924  pe_fence_node(data_set, node, reason, FALSE);
1925  }
1926  free(reason);
1927  }
1928 
1929  if (node->details->unclean) {
1930  /* No extra processing needed
1931  * Also allows resources to be started again after a node is shot
1932  */
1933  on_fail = action_fail_ignore;
1934  }
1935 
1936  switch (on_fail) {
1937  case action_fail_ignore:
1938  /* nothing to do */
1939  break;
1940 
1941  case action_fail_fence:
1942  /* treat it as if it is still running
1943  * but also mark the node as unclean
1944  */
1945  reason = crm_strdup_printf("%s failed there", rsc->id);
1946  pe_fence_node(data_set, node, reason, FALSE);
1947  free(reason);
1948  break;
1949 
1950  case action_fail_standby:
1951  node->details->standby = TRUE;
1952  node->details->standby_onfail = TRUE;
1953  break;
1954 
1955  case action_fail_block:
1956  /* is_managed == FALSE will prevent any
1957  * actions being sent for the resource
1958  */
1960  set_bit(rsc->flags, pe_rsc_block);
1961  break;
1962 
1963  case action_fail_migrate:
1964  /* make sure it comes up somewhere else
1965  * or not at all
1966  */
1967  resource_location(rsc, node, -INFINITY, "__action_migration_auto__", data_set);
1968  break;
1969 
1970  case action_fail_stop:
1971  rsc->next_role = RSC_ROLE_STOPPED;
1972  break;
1973 
1974  case action_fail_recover:
1975  if (rsc->role != RSC_ROLE_STOPPED && rsc->role != RSC_ROLE_UNKNOWN) {
1976  set_bit(rsc->flags, pe_rsc_failed);
1977  stop_action(rsc, node, FALSE);
1978  }
1979  break;
1980 
1982  set_bit(rsc->flags, pe_rsc_failed);
1983 
1984  if (rsc->container && pe_rsc_is_bundled(rsc)) {
1985  /* A bundle's remote connection can run on a different node than
1986  * the bundle's container. We don't necessarily know where the
1987  * container is running yet, so remember it and add a stop
1988  * action for it later.
1989  */
1990  data_set->stop_needed = g_list_prepend(data_set->stop_needed,
1991  rsc->container);
1992  } else if (rsc->container) {
1993  stop_action(rsc->container, node, FALSE);
1994  } else if (rsc->role != RSC_ROLE_STOPPED && rsc->role != RSC_ROLE_UNKNOWN) {
1995  stop_action(rsc, node, FALSE);
1996  }
1997  break;
1998 
2000  set_bit(rsc->flags, pe_rsc_failed);
2001  if (is_set(data_set->flags, pe_flag_stonith_enabled)) {
2002  tmpnode = NULL;
2003  if (rsc->is_remote_node) {
2004  tmpnode = pe_find_node(data_set->nodes, rsc->id);
2005  }
2006  if (tmpnode &&
2007  pe__is_remote_node(tmpnode) &&
2008  tmpnode->details->remote_was_fenced == 0) {
2009 
2010  /* The remote connection resource failed in a way that
2011  * should result in fencing the remote node.
2012  */
2013  pe_fence_node(data_set, tmpnode,
2014  "remote connection is unrecoverable", FALSE);
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_ms) {
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  pcmk__config_warn("Detected active orphan %s running on %s",
2046  rsc->id, node->details->uname);
2047  } else {
2048  pcmk__config_warn("Resource '%s' must be stopped manually on "
2049  "%s because cluster is configured not to "
2050  "stop active orphans",
2051  rsc->id, node->details->uname);
2052  }
2053  }
2054 
2055  native_add_running(rsc, node, data_set);
2056  if (on_fail != action_fail_ignore) {
2057  set_bit(rsc->flags, pe_rsc_failed);
2058  }
2059 
2060  } else if (rsc->clone_name && strchr(rsc->clone_name, ':') != NULL) {
2061  /* Only do this for older status sections that included instance numbers
2062  * Otherwise stopped instances will appear as orphans
2063  */
2064  pe_rsc_trace(rsc, "Resetting clone_name %s for %s (stopped)", rsc->clone_name, rsc->id);
2065  free(rsc->clone_name);
2066  rsc->clone_name = NULL;
2067 
2068  } else {
2069  GList *possible_matches = pe__resource_actions(rsc, node, RSC_STOP,
2070  FALSE);
2071  GListPtr gIter = possible_matches;
2072 
2073  for (; gIter != NULL; gIter = gIter->next) {
2074  pe_action_t *stop = (pe_action_t *) gIter->data;
2075 
2076  stop->flags |= pe_action_optional;
2077  }
2078 
2079  g_list_free(possible_matches);
2080  }
2081 }
2082 
2083 /* create active recurring operations as optional */
2084 static void
2085 process_recurring(pe_node_t * node, pe_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  guint interval_ms = 0;
2101  char *key = NULL;
2102  const char *id = ID(rsc_op);
2103 
2104  counter++;
2105 
2106  if (node->details->online == FALSE) {
2107  pe_rsc_trace(rsc, "Skipping %s/%s: node is offline", rsc->id, node->details->uname);
2108  break;
2109 
2110  /* Need to check if there's a monitor for role="Stopped" */
2111  } else if (start_index < stop_index && counter <= stop_index) {
2112  pe_rsc_trace(rsc, "Skipping %s/%s: resource is not active", id, node->details->uname);
2113  continue;
2114 
2115  } else if (counter < start_index) {
2116  pe_rsc_trace(rsc, "Skipping %s/%s: old %d", id, node->details->uname, counter);
2117  continue;
2118  }
2119 
2120  crm_element_value_ms(rsc_op, XML_LRM_ATTR_INTERVAL_MS, &interval_ms);
2121  if (interval_ms == 0) {
2122  pe_rsc_trace(rsc, "Skipping %s/%s: non-recurring", id, node->details->uname);
2123  continue;
2124  }
2125 
2126  status = crm_element_value(rsc_op, XML_LRM_ATTR_OPSTATUS);
2127  if (safe_str_eq(status, "-1")) {
2128  pe_rsc_trace(rsc, "Skipping %s/%s: status", id, node->details->uname);
2129  continue;
2130  }
2131  task = crm_element_value(rsc_op, XML_LRM_ATTR_TASK);
2132  /* create the action */
2133  key = pcmk__op_key(rsc->id, task, interval_ms);
2134  pe_rsc_trace(rsc, "Creating %s/%s", key, node->details->uname);
2135  custom_action(rsc, key, task, node, TRUE, TRUE, data_set);
2136  }
2137 }
2138 
2139 void
2140 calculate_active_ops(GListPtr sorted_op_list, int *start_index, int *stop_index)
2141 {
2142  int counter = -1;
2143  int implied_monitor_start = -1;
2144  int implied_clone_start = -1;
2145  const char *task = NULL;
2146  const char *status = NULL;
2147  GListPtr gIter = sorted_op_list;
2148 
2149  *stop_index = -1;
2150  *start_index = -1;
2151 
2152  for (; gIter != NULL; gIter = gIter->next) {
2153  xmlNode *rsc_op = (xmlNode *) gIter->data;
2154 
2155  counter++;
2156 
2157  task = crm_element_value(rsc_op, XML_LRM_ATTR_TASK);
2158  status = crm_element_value(rsc_op, XML_LRM_ATTR_OPSTATUS);
2159 
2160  if (safe_str_eq(task, CRMD_ACTION_STOP)
2161  && safe_str_eq(status, "0")) {
2162  *stop_index = counter;
2163 
2164  } else if (safe_str_eq(task, CRMD_ACTION_START) || safe_str_eq(task, CRMD_ACTION_MIGRATED)) {
2165  *start_index = counter;
2166 
2167  } else if ((implied_monitor_start <= *stop_index) && safe_str_eq(task, CRMD_ACTION_STATUS)) {
2168  const char *rc = crm_element_value(rsc_op, XML_LRM_ATTR_RC);
2169 
2170  if (safe_str_eq(rc, "0") || safe_str_eq(rc, "8")) {
2171  implied_monitor_start = counter;
2172  }
2173  } else if (safe_str_eq(task, CRMD_ACTION_PROMOTE) || safe_str_eq(task, CRMD_ACTION_DEMOTE)) {
2174  implied_clone_start = counter;
2175  }
2176  }
2177 
2178  if (*start_index == -1) {
2179  if (implied_clone_start != -1) {
2180  *start_index = implied_clone_start;
2181  } else if (implied_monitor_start != -1) {
2182  *start_index = implied_monitor_start;
2183  }
2184  }
2185 }
2186 
2187 // If resource history entry has shutdown lock, remember lock node and time
2188 static void
2189 unpack_shutdown_lock(xmlNode *rsc_entry, pe_resource_t *rsc, pe_node_t *node,
2190  pe_working_set_t *data_set)
2191 {
2192  time_t lock_time = 0; // When lock started (i.e. node shutdown time)
2193 
2195  &lock_time) == pcmk_ok) && (lock_time != 0)) {
2196 
2197  if ((data_set->shutdown_lock > 0)
2198  && (get_effective_time(data_set)
2199  > (lock_time + data_set->shutdown_lock))) {
2200  pe_rsc_info(rsc, "Shutdown lock for %s on %s expired",
2201  rsc->id, node->details->uname);
2202  pe__clear_resource_history(rsc, node, data_set);
2203  } else {
2204  rsc->lock_node = node;
2205  rsc->lock_time = lock_time;
2206  }
2207  }
2208 }
2209 
2210 static pe_resource_t *
2211 unpack_lrm_rsc_state(pe_node_t * node, xmlNode * rsc_entry, pe_working_set_t * data_set)
2212 {
2213  GListPtr gIter = NULL;
2214  int stop_index = -1;
2215  int start_index = -1;
2216  enum rsc_role_e req_role = RSC_ROLE_UNKNOWN;
2217 
2218  const char *task = NULL;
2219  const char *rsc_id = crm_element_value(rsc_entry, XML_ATTR_ID);
2220 
2221  pe_resource_t *rsc = NULL;
2222  GListPtr op_list = NULL;
2223  GListPtr sorted_op_list = NULL;
2224 
2225  xmlNode *migrate_op = NULL;
2226  xmlNode *rsc_op = NULL;
2227  xmlNode *last_failure = NULL;
2228 
2229  enum action_fail_response on_fail = FALSE;
2230  enum rsc_role_e saved_role = RSC_ROLE_UNKNOWN;
2231 
2232  crm_trace("[%s] Processing %s on %s",
2233  crm_element_name(rsc_entry), rsc_id, node->details->uname);
2234 
2235  /* extract operations */
2236  op_list = NULL;
2237  sorted_op_list = NULL;
2238 
2239  for (rsc_op = __xml_first_child_element(rsc_entry); rsc_op != NULL;
2240  rsc_op = __xml_next_element(rsc_op)) {
2241  if (crm_str_eq((const char *)rsc_op->name, XML_LRM_TAG_RSC_OP, TRUE)) {
2242  op_list = g_list_prepend(op_list, rsc_op);
2243  }
2244  }
2245 
2246  if (is_not_set(data_set->flags, pe_flag_shutdown_lock)) {
2247  if (op_list == NULL) {
2248  // If there are no operations, there is nothing to do
2249  return NULL;
2250  }
2251  }
2252 
2253  /* find the resource */
2254  rsc = unpack_find_resource(data_set, node, rsc_id, rsc_entry);
2255  if (rsc == NULL) {
2256  if (op_list == NULL) {
2257  // If there are no operations, there is nothing to do
2258  return NULL;
2259  } else {
2260  rsc = process_orphan_resource(rsc_entry, node, data_set);
2261  }
2262  }
2263  CRM_ASSERT(rsc != NULL);
2264 
2265  // Check whether the resource is "shutdown-locked" to this node
2266  if (is_set(data_set->flags, pe_flag_shutdown_lock)) {
2267  unpack_shutdown_lock(rsc_entry, rsc, node, data_set);
2268  }
2269 
2270  /* process operations */
2271  saved_role = rsc->role;
2272  on_fail = action_fail_ignore;
2273  rsc->role = RSC_ROLE_UNKNOWN;
2274  sorted_op_list = g_list_sort(op_list, sort_op_by_callid);
2275 
2276  for (gIter = sorted_op_list; gIter != NULL; gIter = gIter->next) {
2277  xmlNode *rsc_op = (xmlNode *) gIter->data;
2278 
2279  task = crm_element_value(rsc_op, XML_LRM_ATTR_TASK);
2280  if (safe_str_eq(task, CRMD_ACTION_MIGRATED)) {
2281  migrate_op = rsc_op;
2282  }
2283 
2284  unpack_rsc_op(rsc, node, rsc_op, &last_failure, &on_fail, data_set);
2285  }
2286 
2287  /* create active recurring operations as optional */
2288  calculate_active_ops(sorted_op_list, &start_index, &stop_index);
2289  process_recurring(node, rsc, start_index, stop_index, sorted_op_list, data_set);
2290 
2291  /* no need to free the contents */
2292  g_list_free(sorted_op_list);
2293 
2294  process_rsc_state(rsc, node, on_fail, migrate_op, data_set);
2295 
2296  if (get_target_role(rsc, &req_role)) {
2297  if (rsc->next_role == RSC_ROLE_UNKNOWN || req_role < rsc->next_role) {
2298  pe_rsc_debug(rsc, "%s: Overwriting calculated next role %s"
2299  " with requested next role %s",
2300  rsc->id, role2text(rsc->next_role), role2text(req_role));
2301  rsc->next_role = req_role;
2302 
2303  } else if (req_role > rsc->next_role) {
2304  pe_rsc_info(rsc, "%s: Not overwriting calculated next role %s"
2305  " with requested next role %s",
2306  rsc->id, role2text(rsc->next_role), role2text(req_role));
2307  }
2308  }
2309 
2310  if (saved_role > rsc->role) {
2311  rsc->role = saved_role;
2312  }
2313 
2314  return rsc;
2315 }
2316 
2317 static void
2318 handle_orphaned_container_fillers(xmlNode * lrm_rsc_list, pe_working_set_t * data_set)
2319 {
2320  xmlNode *rsc_entry = NULL;
2321  for (rsc_entry = __xml_first_child_element(lrm_rsc_list); rsc_entry != NULL;
2322  rsc_entry = __xml_next_element(rsc_entry)) {
2323 
2324  pe_resource_t *rsc;
2325  pe_resource_t *container;
2326  const char *rsc_id;
2327  const char *container_id;
2328 
2329  if (safe_str_neq((const char *)rsc_entry->name, XML_LRM_TAG_RESOURCE)) {
2330  continue;
2331  }
2332 
2333  container_id = crm_element_value(rsc_entry, XML_RSC_ATTR_CONTAINER);
2334  rsc_id = crm_element_value(rsc_entry, XML_ATTR_ID);
2335  if (container_id == NULL || rsc_id == NULL) {
2336  continue;
2337  }
2338 
2339  container = pe_find_resource(data_set->resources, container_id);
2340  if (container == NULL) {
2341  continue;
2342  }
2343 
2344  rsc = pe_find_resource(data_set->resources, rsc_id);
2345  if (rsc == NULL ||
2346  is_set(rsc->flags, pe_rsc_orphan_container_filler) == FALSE ||
2347  rsc->container != NULL) {
2348  continue;
2349  }
2350 
2351  pe_rsc_trace(rsc, "Mapped container of orphaned resource %s to %s",
2352  rsc->id, container_id);
2353  rsc->container = container;
2354  container->fillers = g_list_append(container->fillers, rsc);
2355  }
2356 }
2357 
2358 static void
2359 unpack_lrm_resources(pe_node_t *node, xmlNode *lrm_rsc_list,
2360  pe_working_set_t *data_set)
2361 {
2362  xmlNode *rsc_entry = NULL;
2363  gboolean found_orphaned_container_filler = FALSE;
2364 
2365  for (rsc_entry = __xml_first_child_element(lrm_rsc_list); rsc_entry != NULL;
2366  rsc_entry = __xml_next_element(rsc_entry)) {
2367 
2368  if (crm_str_eq((const char *)rsc_entry->name, XML_LRM_TAG_RESOURCE, TRUE)) {
2369  pe_resource_t *rsc = unpack_lrm_rsc_state(node, rsc_entry, data_set);
2370  if (!rsc) {
2371  continue;
2372  }
2373  if (is_set(rsc->flags, pe_rsc_orphan_container_filler)) {
2374  found_orphaned_container_filler = TRUE;
2375  }
2376  }
2377  }
2378 
2379  /* now that all the resource state has been unpacked for this node
2380  * we have to go back and map any orphaned container fillers to their
2381  * container resource */
2382  if (found_orphaned_container_filler) {
2383  handle_orphaned_container_fillers(lrm_rsc_list, data_set);
2384  }
2385 }
2386 
2387 static void
2388 set_active(pe_resource_t * rsc)
2389 {
2390  pe_resource_t *top = uber_parent(rsc);
2391 
2392  if (top && is_set(top->flags, pe_rsc_promotable)) {
2393  rsc->role = RSC_ROLE_SLAVE;
2394  } else {
2395  rsc->role = RSC_ROLE_STARTED;
2396  }
2397 }
2398 
2399 static void
2400 set_node_score(gpointer key, gpointer value, gpointer user_data)
2401 {
2402  pe_node_t *node = value;
2403  int *score = user_data;
2404 
2405  node->weight = *score;
2406 }
2407 
2408 #define STATUS_PATH_MAX 1024
2409 static xmlNode *
2410 find_lrm_op(const char *resource, const char *op, const char *node, const char *source,
2411  bool success_only, pe_working_set_t *data_set)
2412 {
2413  int offset = 0;
2414  char xpath[STATUS_PATH_MAX];
2415  xmlNode *xml = NULL;
2416 
2417  offset += snprintf(xpath + offset, STATUS_PATH_MAX - offset, "//node_state[@uname='%s']", node);
2418  offset +=
2419  snprintf(xpath + offset, STATUS_PATH_MAX - offset, "//" XML_LRM_TAG_RESOURCE "[@id='%s']",
2420  resource);
2421 
2422  /* Need to check against transition_magic too? */
2423  if (source && safe_str_eq(op, CRMD_ACTION_MIGRATE)) {
2424  offset +=
2425  snprintf(xpath + offset, STATUS_PATH_MAX - offset,
2426  "/" XML_LRM_TAG_RSC_OP "[@operation='%s' and @migrate_target='%s']", op,
2427  source);
2428  } else if (source && safe_str_eq(op, CRMD_ACTION_MIGRATED)) {
2429  offset +=
2430  snprintf(xpath + offset, STATUS_PATH_MAX - offset,
2431  "/" XML_LRM_TAG_RSC_OP "[@operation='%s' and @migrate_source='%s']", op,
2432  source);
2433  } else {
2434  offset +=
2435  snprintf(xpath + offset, STATUS_PATH_MAX - offset,
2436  "/" XML_LRM_TAG_RSC_OP "[@operation='%s']", op);
2437  }
2438 
2439  CRM_LOG_ASSERT(offset > 0);
2440  xml = get_xpath_object(xpath, data_set->input, LOG_DEBUG);
2441 
2442  if (xml && success_only) {
2443  int rc = PCMK_OCF_UNKNOWN_ERROR;
2444  int status = PCMK_LRM_OP_ERROR;
2445 
2448  if ((rc != PCMK_OCF_OK) || (status != PCMK_LRM_OP_DONE)) {
2449  return NULL;
2450  }
2451  }
2452  return xml;
2453 }
2454 
2455 static int
2456 pe__call_id(xmlNode *op_xml)
2457 {
2458  int id = 0;
2459 
2460  if (op_xml) {
2462  }
2463  return id;
2464 }
2465 
2482 static bool
2483 stop_happened_after(pe_resource_t *rsc, pe_node_t *node, xmlNode *xml_op,
2484  pe_working_set_t *data_set)
2485 {
2486  xmlNode *stop_op = find_lrm_op(rsc->id, CRMD_ACTION_STOP,
2487  node->details->uname, NULL, TRUE, data_set);
2488 
2489  return (stop_op && (pe__call_id(stop_op) > pe__call_id(xml_op)));
2490 }
2491 
2492 static void
2493 unpack_migrate_to_success(pe_resource_t *rsc, pe_node_t *node, xmlNode *xml_op,
2494  pe_working_set_t *data_set)
2495 {
2496  /* A successful migration sequence is:
2497  * migrate_to on source node
2498  * migrate_from on target node
2499  * stop on source node
2500  *
2501  * If a migrate_to is followed by a stop, the entire migration (successful
2502  * or failed) is complete, and we don't care what happened on the target.
2503  *
2504  * If no migrate_from has happened, the migration is considered to be
2505  * "partial". If the migrate_from failed, make sure the resource gets
2506  * stopped on both source and target (if up).
2507  *
2508  * If the migrate_to and migrate_from both succeeded (which also implies the
2509  * resource is no longer running on the source), but there is no stop, the
2510  * migration is considered to be "dangling". Schedule a stop on the source
2511  * in this case.
2512  */
2513  int from_rc = 0;
2514  int from_status = 0;
2515  pe_node_t *target_node = NULL;
2516  pe_node_t *source_node = NULL;
2517  xmlNode *migrate_from = NULL;
2518  const char *source = crm_element_value(xml_op, XML_LRM_ATTR_MIGRATE_SOURCE);
2519  const char *target = crm_element_value(xml_op, XML_LRM_ATTR_MIGRATE_TARGET);
2520 
2521  // Sanity check
2522  CRM_CHECK(source && target && !strcmp(source, node->details->uname), return);
2523 
2524  if (stop_happened_after(rsc, node, xml_op, data_set)) {
2525  return;
2526  }
2527 
2528  // Clones are not allowed to migrate, so role can't be master
2529  rsc->role = RSC_ROLE_STARTED;
2530 
2531  target_node = pe_find_node(data_set->nodes, target);
2532  source_node = pe_find_node(data_set->nodes, source);
2533 
2534  // Check whether there was a migrate_from action on the target
2535  migrate_from = find_lrm_op(rsc->id, CRMD_ACTION_MIGRATED, target,
2536  source, FALSE, data_set);
2537  if (migrate_from) {
2538  crm_element_value_int(migrate_from, XML_LRM_ATTR_RC, &from_rc);
2539  crm_element_value_int(migrate_from, XML_LRM_ATTR_OPSTATUS, &from_status);
2540  pe_rsc_trace(rsc, "%s op on %s exited with status=%d, rc=%d",
2541  ID(migrate_from), target, from_status, from_rc);
2542  }
2543 
2544  if (migrate_from && from_rc == PCMK_OCF_OK
2545  && from_status == PCMK_LRM_OP_DONE) {
2546  /* The migrate_to and migrate_from both succeeded, so mark the migration
2547  * as "dangling". This will be used to schedule a stop action on the
2548  * source without affecting the target.
2549  */
2550  pe_rsc_trace(rsc, "Detected dangling migration op: %s on %s", ID(xml_op),
2551  source);
2552  rsc->role = RSC_ROLE_STOPPED;
2553  rsc->dangling_migrations = g_list_prepend(rsc->dangling_migrations, node);
2554 
2555  } else if (migrate_from && (from_status != PCMK_LRM_OP_PENDING)) { // Failed
2556  if (target_node && target_node->details->online) {
2557  pe_rsc_trace(rsc, "Marking active on %s %p %d", target, target_node,
2558  target_node->details->online);
2559  native_add_running(rsc, target_node, data_set);
2560  }
2561 
2562  } else { // Pending, or complete but erased
2563  if (target_node && target_node->details->online) {
2564  pe_rsc_trace(rsc, "Marking active on %s %p %d", target, target_node,
2565  target_node->details->online);
2566 
2567  native_add_running(rsc, target_node, data_set);
2568  if (source_node && source_node->details->online) {
2569  /* This is a partial migration: the migrate_to completed
2570  * successfully on the source, but the migrate_from has not
2571  * completed. Remember the source and target; if the newly
2572  * chosen target remains the same when we schedule actions
2573  * later, we may continue with the migration.
2574  */
2575  rsc->partial_migration_target = target_node;
2576  rsc->partial_migration_source = source_node;
2577  }
2578  } else {
2579  /* Consider it failed here - forces a restart, prevents migration */
2580  set_bit(rsc->flags, pe_rsc_failed);
2582  }
2583  }
2584 }
2585 
2586 static void
2587 unpack_migrate_to_failure(pe_resource_t *rsc, pe_node_t *node, xmlNode *xml_op,
2588  pe_working_set_t *data_set)
2589 {
2590  int target_stop_id = 0;
2591  int target_migrate_from_id = 0;
2592  xmlNode *target_stop = NULL;
2593  xmlNode *target_migrate_from = NULL;
2594  const char *source = crm_element_value(xml_op, XML_LRM_ATTR_MIGRATE_SOURCE);
2595  const char *target = crm_element_value(xml_op, XML_LRM_ATTR_MIGRATE_TARGET);
2596 
2597  // Sanity check
2598  CRM_CHECK(source && target && !strcmp(source, node->details->uname), return);
2599 
2600  /* If a migration failed, we have to assume the resource is active. Clones
2601  * are not allowed to migrate, so role can't be master.
2602  */
2603  rsc->role = RSC_ROLE_STARTED;
2604 
2605  // Check for stop on the target
2606  target_stop = find_lrm_op(rsc->id, CRMD_ACTION_STOP, target, NULL,
2607  TRUE, data_set);
2608  target_stop_id = pe__call_id(target_stop);
2609 
2610  // Check for migrate_from on the target
2611  target_migrate_from = find_lrm_op(rsc->id, CRMD_ACTION_MIGRATED, target,
2612  source, TRUE, data_set);
2613  target_migrate_from_id = pe__call_id(target_migrate_from);
2614 
2615  if ((target_stop == NULL) || (target_stop_id < target_migrate_from_id)) {
2616  /* There was no stop on the source, or a stop that happened before a
2617  * migrate_from, so assume the resource is still active on the target
2618  * (if it is up).
2619  */
2620  pe_node_t *target_node = pe_find_node(data_set->nodes, target);
2621 
2622  pe_rsc_trace(rsc, "stop (%d) + migrate_from (%d)",
2623  target_stop_id, target_migrate_from_id);
2624  if (target_node && target_node->details->online) {
2625  native_add_running(rsc, target_node, data_set);
2626  }
2627 
2628  } else if (target_migrate_from == NULL) {
2629  /* We know there was a stop on the target, but there may not have been a
2630  * migrate_from (the stop could have happened before migrate_from was
2631  * scheduled or attempted).
2632  *
2633  * That means this could be a "dangling" migration. But first, check
2634  * whether there is a newer migrate_from or start on the source node --
2635  * it's possible the failed migration was followed by a successful
2636  * full restart or migration in the reverse direction, in which case we
2637  * don't want to force it to stop.
2638  */
2639  xmlNode *source_migrate_from = NULL;
2640  xmlNode *source_start = NULL;
2641  int source_migrate_to_id = pe__call_id(xml_op);
2642 
2643  source_migrate_from = find_lrm_op(rsc->id, CRMD_ACTION_MIGRATED, source,
2644  NULL, TRUE, data_set);
2645  if (pe__call_id(source_migrate_from) > source_migrate_to_id) {
2646  return;
2647  }
2648 
2649  source_start = find_lrm_op(rsc->id, CRMD_ACTION_START, source, NULL,
2650  TRUE, data_set);
2651  if (pe__call_id(source_start) > source_migrate_to_id) {
2652  return;
2653  }
2654 
2655  // Mark node as having dangling migration so we can force a stop later
2656  rsc->dangling_migrations = g_list_prepend(rsc->dangling_migrations, node);
2657  }
2658 }
2659 
2660 static void
2661 unpack_migrate_from_failure(pe_resource_t *rsc, pe_node_t *node,
2662  xmlNode *xml_op, pe_working_set_t *data_set)
2663 {
2664  xmlNode *source_stop = NULL;
2665  xmlNode *source_migrate_to = NULL;
2666  const char *source = crm_element_value(xml_op, XML_LRM_ATTR_MIGRATE_SOURCE);
2667  const char *target = crm_element_value(xml_op, XML_LRM_ATTR_MIGRATE_TARGET);
2668 
2669  // Sanity check
2670  CRM_CHECK(source && target && !strcmp(target, node->details->uname), return);
2671 
2672  /* If a migration failed, we have to assume the resource is active. Clones
2673  * are not allowed to migrate, so role can't be master.
2674  */
2675  rsc->role = RSC_ROLE_STARTED;
2676 
2677  // Check for a stop on the source
2678  source_stop = find_lrm_op(rsc->id, CRMD_ACTION_STOP, source, NULL,
2679  TRUE, data_set);
2680 
2681  // Check for a migrate_to on the source
2682  source_migrate_to = find_lrm_op(rsc->id, CRMD_ACTION_MIGRATE,
2683  source, target, TRUE, data_set);
2684 
2685  if ((source_stop == NULL)
2686  || (pe__call_id(source_stop) < pe__call_id(source_migrate_to))) {
2687  /* There was no stop on the source, or a stop that happened before
2688  * migrate_to, so assume the resource is still active on the source (if
2689  * it is up).
2690  */
2691  pe_node_t *source_node = pe_find_node(data_set->nodes, source);
2692 
2693  if (source_node && source_node->details->online) {
2694  native_add_running(rsc, source_node, data_set);
2695  }
2696  }
2697 }
2698 
2699 static void
2700 record_failed_op(xmlNode *op, const pe_node_t *node,
2701  const pe_resource_t *rsc, pe_working_set_t *data_set)
2702 {
2703  xmlNode *xIter = NULL;
2704  const char *op_key = crm_element_value(op, XML_LRM_ATTR_TASK_KEY);
2705 
2706  if (node->details->online == FALSE) {
2707  return;
2708  }
2709 
2710  for (xIter = data_set->failed->children; xIter; xIter = xIter->next) {
2711  const char *key = crm_element_value(xIter, XML_LRM_ATTR_TASK_KEY);
2712  const char *uname = crm_element_value(xIter, XML_ATTR_UNAME);
2713 
2714  if(safe_str_eq(op_key, key) && safe_str_eq(uname, node->details->uname)) {
2715  crm_trace("Skipping duplicate entry %s on %s", op_key, node->details->uname);
2716  return;
2717  }
2718  }
2719 
2720  crm_trace("Adding entry %s on %s", op_key, node->details->uname);
2721  crm_xml_add(op, XML_ATTR_UNAME, node->details->uname);
2722  crm_xml_add(op, XML_LRM_ATTR_RSCID, rsc->id);
2723  add_node_copy(data_set->failed, op);
2724 }
2725 
2726 static const char *get_op_key(xmlNode *xml_op)
2727 {
2728  const char *key = crm_element_value(xml_op, XML_LRM_ATTR_TASK_KEY);
2729  if(key == NULL) {
2730  key = ID(xml_op);
2731  }
2732  return key;
2733 }
2734 
2735 static const char *
2736 last_change_str(xmlNode *xml_op)
2737 {
2738  time_t when;
2739  const char *when_s = NULL;
2740 
2742  &when) == pcmk_ok) {
2743  when_s = pcmk__epoch2str(&when);
2744  if (when_s) {
2745  // Skip day of week to make message shorter
2746  when_s = strchr(when_s, ' ');
2747  if (when_s) {
2748  ++when_s;
2749  }
2750  }
2751  }
2752  return ((when_s && *when_s)? when_s : "unknown time");
2753 }
2754 
2755 static void
2756 unpack_rsc_op_failure(pe_resource_t * rsc, pe_node_t * node, int rc, xmlNode * xml_op, xmlNode ** last_failure,
2757  enum action_fail_response * on_fail, pe_working_set_t * data_set)
2758 {
2759  guint interval_ms = 0;
2760  bool is_probe = false;
2761  pe_action_t *action = NULL;
2762 
2763  const char *key = get_op_key(xml_op);
2764  const char *task = crm_element_value(xml_op, XML_LRM_ATTR_TASK);
2765  const char *exit_reason = crm_element_value(xml_op,
2767 
2768  CRM_ASSERT(rsc);
2769  CRM_CHECK(task != NULL, return);
2770 
2771  *last_failure = xml_op;
2772 
2773  crm_element_value_ms(xml_op, XML_LRM_ATTR_INTERVAL_MS, &interval_ms);
2774  if ((interval_ms == 0) && !strcmp(task, CRMD_ACTION_STATUS)) {
2775  is_probe = true;
2776  }
2777 
2778  if (exit_reason == NULL) {
2779  exit_reason = "";
2780  }
2781 
2782  if (is_not_set(data_set->flags, pe_flag_symmetric_cluster)
2783  && (rc == PCMK_OCF_NOT_INSTALLED)) {
2784  crm_trace("Unexpected result (%s%s%s) was recorded for "
2785  "%s of %s on %s at %s " CRM_XS " rc=%d id=%s",
2786  services_ocf_exitcode_str(rc),
2787  (*exit_reason? ": " : ""), exit_reason,
2788  (is_probe? "probe" : task), rsc->id, node->details->uname,
2789  last_change_str(xml_op), rc, ID(xml_op));
2790  } else {
2791  crm_warn("Unexpected result (%s%s%s) was recorded for "
2792  "%s of %s on %s at %s " CRM_XS " rc=%d id=%s",
2793  services_ocf_exitcode_str(rc),
2794  (*exit_reason? ": " : ""), exit_reason,
2795  (is_probe? "probe" : task), rsc->id, node->details->uname,
2796  last_change_str(xml_op), rc, ID(xml_op));
2797 
2798  if (is_probe && (rc != PCMK_OCF_OK)
2799  && (rc != PCMK_OCF_NOT_RUNNING)
2800  && (rc != PCMK_OCF_RUNNING_MASTER)) {
2801 
2802  /* A failed (not just unexpected) probe result could mean the user
2803  * didn't know resources will be probed even where they can't run.
2804  */
2805  crm_notice("If it is not possible for %s to run on %s, see "
2806  "the resource-discovery option for location constraints",
2807  rsc->id, node->details->uname);
2808  }
2809 
2810  record_failed_op(xml_op, node, rsc, data_set);
2811  }
2812 
2813  action = custom_action(rsc, strdup(key), task, NULL, TRUE, FALSE, data_set);
2814  if ((action->on_fail <= action_fail_fence && *on_fail < action->on_fail) ||
2815  (action->on_fail == action_fail_reset_remote && *on_fail <= action_fail_recover) ||
2816  (action->on_fail == action_fail_restart_container && *on_fail <= action_fail_recover) ||
2817  (*on_fail == action_fail_restart_container && action->on_fail >= action_fail_migrate)) {
2818  pe_rsc_trace(rsc, "on-fail %s -> %s for %s (%s)", fail2text(*on_fail),
2819  fail2text(action->on_fail), action->uuid, key);
2820  *on_fail = action->on_fail;
2821  }
2822 
2823  if (!strcmp(task, CRMD_ACTION_STOP)) {
2824  resource_location(rsc, node, -INFINITY, "__stop_fail__", data_set);
2825 
2826  } else if (!strcmp(task, CRMD_ACTION_MIGRATE)) {
2827  unpack_migrate_to_failure(rsc, node, xml_op, data_set);
2828 
2829  } else if (!strcmp(task, CRMD_ACTION_MIGRATED)) {
2830  unpack_migrate_from_failure(rsc, node, xml_op, data_set);
2831 
2832  } else if (!strcmp(task, CRMD_ACTION_PROMOTE)) {
2833  rsc->role = RSC_ROLE_MASTER;
2834 
2835  } else if (!strcmp(task, CRMD_ACTION_DEMOTE)) {
2836  if (action->on_fail == action_fail_block) {
2837  rsc->role = RSC_ROLE_MASTER;
2838  rsc->next_role = RSC_ROLE_STOPPED;
2839 
2840  } else if(rc == PCMK_OCF_NOT_RUNNING) {
2841  rsc->role = RSC_ROLE_STOPPED;
2842 
2843  } else {
2844  /* Staying in master role would put the scheduler and controller
2845  * into a loop. Setting slave role is not dangerous because the
2846  * resource will be stopped as part of recovery, and any master
2847  * promotion will be ordered after that stop.
2848  */
2849  rsc->role = RSC_ROLE_SLAVE;
2850  }
2851  }
2852 
2853  if(is_probe && rc == PCMK_OCF_NOT_INSTALLED) {
2854  /* leave stopped */
2855  pe_rsc_trace(rsc, "Leaving %s stopped", rsc->id);
2856  rsc->role = RSC_ROLE_STOPPED;
2857 
2858  } else if (rsc->role < RSC_ROLE_STARTED) {
2859  pe_rsc_trace(rsc, "Setting %s active", rsc->id);
2860  set_active(rsc);
2861  }
2862 
2863  pe_rsc_trace(rsc, "Resource %s: role=%s, unclean=%s, on_fail=%s, fail_role=%s",
2864  rsc->id, role2text(rsc->role),
2865  node->details->unclean ? "true" : "false",
2866  fail2text(action->on_fail), role2text(action->fail_role));
2867 
2868  if (action->fail_role != RSC_ROLE_STARTED && rsc->next_role < action->fail_role) {
2869  rsc->next_role = action->fail_role;
2870  }
2871 
2872  if (action->fail_role == RSC_ROLE_STOPPED) {
2873  int score = -INFINITY;
2874 
2875  pe_resource_t *fail_rsc = rsc;
2876 
2877  if (fail_rsc->parent) {
2878  pe_resource_t *parent = uber_parent(fail_rsc);
2879 
2880  if (pe_rsc_is_clone(parent)
2881  && is_not_set(parent->flags, pe_rsc_unique)) {
2882  /* For clone resources, if a child fails on an operation
2883  * with on-fail = stop, all the resources fail. Do this by preventing
2884  * the parent from coming up again. */
2885  fail_rsc = parent;
2886  }
2887  }
2888  crm_notice("%s will not be started under current conditions",
2889  fail_rsc->id);
2890  /* make sure it doesn't come up again */
2891  if (fail_rsc->allowed_nodes != NULL) {
2892  g_hash_table_destroy(fail_rsc->allowed_nodes);
2893  }
2894  fail_rsc->allowed_nodes = pe__node_list2table(data_set->nodes);
2895  g_hash_table_foreach(fail_rsc->allowed_nodes, set_node_score, &score);
2896  }
2897 
2898  pe_free_action(action);
2899 }
2900 
2920 static int
2921 determine_op_status(
2922  pe_resource_t *rsc, int rc, int target_rc, pe_node_t * node, xmlNode * xml_op, enum action_fail_response * on_fail, pe_working_set_t * data_set)
2923 {
2924  guint interval_ms = 0;
2925  bool is_probe = false;
2926  int result = PCMK_LRM_OP_DONE;
2927  const char *key = get_op_key(xml_op);
2928  const char *task = crm_element_value(xml_op, XML_LRM_ATTR_TASK);
2929  const char *exit_reason = crm_element_value(xml_op,
2931 
2932  CRM_ASSERT(rsc);
2933  CRM_CHECK(task != NULL, return PCMK_LRM_OP_ERROR);
2934 
2935  if (exit_reason == NULL) {
2936  exit_reason = "";
2937  }
2938 
2939  crm_element_value_ms(xml_op, XML_LRM_ATTR_INTERVAL_MS, &interval_ms);
2940  if ((interval_ms == 0) && !strcmp(task, CRMD_ACTION_STATUS)) {
2941  is_probe = true;
2942  task = "probe";
2943  }
2944 
2945  if (target_rc < 0) {
2946  /* Pre-1.0 Pacemaker versions, and Pacemaker 1.1.6 or earlier with
2947  * Heartbeat 2.0.7 or earlier as the cluster layer, did not include the
2948  * target_rc in the transition key, which (along with the similar case
2949  * of a corrupted transition key in the CIB) will be reported to this
2950  * function as -1. Pacemaker 2.0+ does not support rolling upgrades from
2951  * those versions or processing of saved CIB files from those versions,
2952  * so we do not need to care much about this case.
2953  */
2954  result = PCMK_LRM_OP_ERROR;
2955  crm_warn("Expected result not found for %s on %s (corrupt or obsolete CIB?)",
2956  key, node->details->uname);
2957 
2958  } else if (target_rc != rc) {
2959  result = PCMK_LRM_OP_ERROR;
2960  pe_rsc_debug(rsc, "%s on %s: expected %d (%s), got %d (%s%s%s)",
2961  key, node->details->uname,
2962  target_rc, services_ocf_exitcode_str(target_rc),
2963  rc, services_ocf_exitcode_str(rc),
2964  (*exit_reason? ": " : ""), exit_reason);
2965  }
2966 
2967  switch (rc) {
2968  case PCMK_OCF_OK:
2969  if (is_probe && (target_rc == PCMK_OCF_NOT_RUNNING)) {
2970  result = PCMK_LRM_OP_DONE;
2971  pe_rsc_info(rsc, "Probe found %s active on %s at %s",
2972  rsc->id, node->details->uname,
2973  last_change_str(xml_op));
2974  }
2975  break;
2976 
2977  case PCMK_OCF_NOT_RUNNING:
2978  if (is_probe || target_rc == rc || is_not_set(rsc->flags, pe_rsc_managed)) {
2979  result = PCMK_LRM_OP_DONE;
2980  rsc->role = RSC_ROLE_STOPPED;
2981 
2982  /* clear any previous failure actions */
2983  *on_fail = action_fail_ignore;
2984  rsc->next_role = RSC_ROLE_UNKNOWN;
2985  }
2986  break;
2987 
2989  if (is_probe && (rc != target_rc)) {
2990  result = PCMK_LRM_OP_DONE;
2991  pe_rsc_info(rsc,
2992  "Probe found %s active and promoted on %s at %s",
2993  rsc->id, node->details->uname,
2994  last_change_str(xml_op));
2995  }
2996  rsc->role = RSC_ROLE_MASTER;
2997  break;
2998 
3001  rsc->role = RSC_ROLE_MASTER;
3002  result = PCMK_LRM_OP_ERROR;
3003  break;
3004 
3006  result = PCMK_LRM_OP_ERROR_FATAL;
3007  break;
3008 
3010  if (interval_ms > 0) {
3011  result = PCMK_LRM_OP_NOTSUPPORTED;
3012  break;
3013  }
3014  // fall through
3018  if (!pe_can_fence(data_set, node)
3019  && !strcmp(task, CRMD_ACTION_STOP)) {
3020  /* If a stop fails and we can't fence, there's nothing else we can do */
3021  pe_proc_err("No further recovery can be attempted for %s "
3022  "because %s on %s failed (%s%s%s) at %s "
3023  CRM_XS " rc=%d id=%s", rsc->id, task,
3024  node->details->uname, services_ocf_exitcode_str(rc),
3025  (*exit_reason? ": " : ""), exit_reason,
3026  last_change_str(xml_op), rc, ID(xml_op));
3028  set_bit(rsc->flags, pe_rsc_block);
3029  }
3030  result = PCMK_LRM_OP_ERROR_HARD;
3031  break;
3032 
3033  default:
3034  if (result == PCMK_LRM_OP_DONE) {
3035  crm_info("Treating unknown exit status %d from %s of %s "
3036  "on %s at %s as failure",
3037  rc, task, rsc->id, node->details->uname,
3038  last_change_str(xml_op));
3039  result = PCMK_LRM_OP_ERROR;
3040  }
3041  break;
3042  }
3043  return result;
3044 }
3045 
3046 // return TRUE if start or monitor last failure but parameters changed
3047 static bool
3048 should_clear_for_param_change(xmlNode *xml_op, const char *task,
3049  pe_resource_t *rsc, pe_node_t *node,
3050  pe_working_set_t *data_set)
3051 {
3052  if (!strcmp(task, "start") || !strcmp(task, "monitor")) {
3053 
3054  if (pe__bundle_needs_remote_name(rsc)) {
3055  /* We haven't allocated resources yet, so we can't reliably
3056  * substitute addr parameters for the REMOTE_CONTAINER_HACK.
3057  * When that's needed, defer the check until later.
3058  */
3059  pe__add_param_check(xml_op, rsc, node, pe_check_last_failure,
3060  data_set);
3061 
3062  } else {
3063  op_digest_cache_t *digest_data = NULL;
3064 
3065  digest_data = rsc_action_digest_cmp(rsc, xml_op, node, data_set);
3066  switch (digest_data->rc) {
3067  case RSC_DIGEST_UNKNOWN:
3068  crm_trace("Resource %s history entry %s on %s"
3069  " has no digest to compare",
3070  rsc->id, get_op_key(xml_op), node->details->id);
3071  break;
3072  case RSC_DIGEST_MATCH:
3073  break;
3074  default:
3075  return TRUE;
3076  }
3077  }
3078  }
3079  return FALSE;
3080 }
3081 
3082 // Order action after fencing of remote node, given connection rsc
3083 static void
3084 order_after_remote_fencing(pe_action_t *action, pe_resource_t *remote_conn,
3085  pe_working_set_t *data_set)
3086 {
3087  pe_node_t *remote_node = pe_find_node(data_set->nodes, remote_conn->id);
3088 
3089  if (remote_node) {
3090  pe_action_t *fence = pe_fence_op(remote_node, NULL, TRUE, NULL,
3091  FALSE, data_set);
3092 
3093  order_actions(fence, action, pe_order_implies_then);
3094  }
3095 }
3096 
3097 static bool
3098 should_ignore_failure_timeout(pe_resource_t *rsc, xmlNode *xml_op,
3099  const char *task, guint interval_ms,
3100  bool is_last_failure, pe_working_set_t *data_set)
3101 {
3102  /* Clearing failures of recurring monitors has special concerns. The
3103  * executor reports only changes in the monitor result, so if the
3104  * monitor is still active and still getting the same failure result,
3105  * that will go undetected after the failure is cleared.
3106  *
3107  * Also, the operation history will have the time when the recurring
3108  * monitor result changed to the given code, not the time when the
3109  * result last happened.
3110  *
3111  * @TODO We probably should clear such failures only when the failure
3112  * timeout has passed since the last occurrence of the failed result.
3113  * However we don't record that information. We could maybe approximate
3114  * that by clearing only if there is a more recent successful monitor or
3115  * stop result, but we don't even have that information at this point
3116  * since we are still unpacking the resource's operation history.
3117  *
3118  * This is especially important for remote connection resources with a
3119  * reconnect interval, so in that case, we skip clearing failures
3120  * if the remote node hasn't been fenced.
3121  */
3122  if (rsc->remote_reconnect_ms
3123  && is_set(data_set->flags, pe_flag_stonith_enabled)
3124  && (interval_ms != 0) && safe_str_eq(task, CRMD_ACTION_STATUS)) {
3125 
3126  pe_node_t *remote_node = pe_find_node(data_set->nodes, rsc->id);
3127 
3128  if (remote_node && !remote_node->details->remote_was_fenced) {
3129  if (is_last_failure) {
3130  crm_info("Waiting to clear monitor failure for remote node %s"
3131  " until fencing has occurred", rsc->id);
3132  }
3133  return TRUE;
3134  }
3135  }
3136  return FALSE;
3137 }
3138 
3161 static bool
3162 check_operation_expiry(pe_resource_t *rsc, pe_node_t *node, int rc,
3163  xmlNode *xml_op, pe_working_set_t *data_set)
3164 {
3165  bool expired = FALSE;
3166  bool is_last_failure = pcmk__ends_with(ID(xml_op), "_last_failure_0");
3167  time_t last_run = 0;
3168  guint interval_ms = 0;
3169  int unexpired_fail_count = 0;
3170  const char *task = crm_element_value(xml_op, XML_LRM_ATTR_TASK);
3171  const char *clear_reason = NULL;
3172 
3173  crm_element_value_ms(xml_op, XML_LRM_ATTR_INTERVAL_MS, &interval_ms);
3174 
3175  if ((rsc->failure_timeout > 0)
3177  &last_run) == 0)) {
3178 
3179  // Resource has a failure-timeout, and history entry has a timestamp
3180 
3181  time_t now = get_effective_time(data_set);
3182  time_t last_failure = 0;
3183 
3184  // Is this particular operation history older than the failure timeout?
3185  if ((now >= (last_run + rsc->failure_timeout))
3186  && !should_ignore_failure_timeout(rsc, xml_op, task, interval_ms,
3187  is_last_failure, data_set)) {
3188  expired = TRUE;
3189  }
3190 
3191  // Does the resource as a whole have an unexpired fail count?
3192  unexpired_fail_count = pe_get_failcount(node, rsc, &last_failure,
3193  pe_fc_effective, xml_op,
3194  data_set);
3195 
3196  // Update scheduler recheck time according to *last* failure
3197  crm_trace("%s@%lld is %sexpired @%lld with unexpired_failures=%d timeout=%ds"
3198  " last-failure@%lld",
3199  ID(xml_op), (long long) last_run, (expired? "" : "not "),
3200  (long long) now, unexpired_fail_count, rsc->failure_timeout,
3201  (long long) last_failure);
3202  last_failure += rsc->failure_timeout + 1;
3203  if (unexpired_fail_count && (now < last_failure)) {
3204  pe__update_recheck_time(last_failure, data_set);
3205  }
3206  }
3207 
3208  if (expired) {
3209  if (pe_get_failcount(node, rsc, NULL, pe_fc_default, xml_op, data_set)) {
3210 
3211  // There is a fail count ignoring timeout
3212 
3213  if (unexpired_fail_count == 0) {
3214  // There is no fail count considering timeout
3215  clear_reason = "it expired";
3216 
3217  } else {
3218  /* This operation is old, but there is an unexpired fail count.
3219  * In a properly functioning cluster, this should only be
3220  * possible if this operation is not a failure (otherwise the
3221  * fail count should be expired too), so this is really just a
3222  * failsafe.
3223  */
3224  expired = FALSE;
3225  }
3226 
3227  } else if (is_last_failure && rsc->remote_reconnect_ms) {
3228  /* Clear any expired last failure when reconnect interval is set,
3229  * even if there is no fail count.
3230  */
3231  clear_reason = "reconnect interval is set";
3232  }
3233  }
3234 
3235  if (!expired && is_last_failure
3236  && should_clear_for_param_change(xml_op, task, rsc, node, data_set)) {
3237  clear_reason = "resource parameters have changed";
3238  }
3239 
3240  if (clear_reason != NULL) {
3241  // Schedule clearing of the fail count
3242  pe_action_t *clear_op = pe__clear_failcount(rsc, node, clear_reason,
3243  data_set);
3244 
3245  if (is_set(data_set->flags, pe_flag_stonith_enabled)
3246  && rsc->remote_reconnect_ms) {
3247  /* If we're clearing a remote connection due to a reconnect
3248  * interval, we want to wait until any scheduled fencing
3249  * completes.
3250  *
3251  * We could limit this to remote_node->details->unclean, but at
3252  * this point, that's always true (it won't be reliable until
3253  * after unpack_node_loop() is done).
3254  */
3255  crm_info("Clearing %s failure will wait until any scheduled "
3256  "fencing of %s completes", task, rsc->id);
3257  order_after_remote_fencing(clear_op, rsc, data_set);
3258  }
3259  }
3260 
3261  if (expired && (interval_ms == 0) && safe_str_eq(task, CRMD_ACTION_STATUS)) {
3262  switch(rc) {
3263  case PCMK_OCF_OK:
3264  case PCMK_OCF_NOT_RUNNING:
3266  case PCMK_OCF_DEGRADED:
3268  // Don't expire probes that return these values
3269  expired = FALSE;
3270  break;
3271  }
3272  }
3273 
3274  return expired;
3275 }
3276 
3277 int pe__target_rc_from_xml(xmlNode *xml_op)
3278 {
3279  int target_rc = 0;
3280  const char *key = crm_element_value(xml_op, XML_ATTR_TRANSITION_KEY);
3281 
3282  if (key == NULL) {
3283  return -1;
3284  }
3285  decode_transition_key(key, NULL, NULL, NULL, &target_rc);
3286  return target_rc;
3287 }
3288 
3289 static enum action_fail_response
3290 get_action_on_fail(pe_resource_t *rsc, const char *key, const char *task, pe_working_set_t * data_set)
3291 {
3292  int result = action_fail_recover;
3293  pe_action_t *action = custom_action(rsc, strdup(key), task, NULL, TRUE, FALSE, data_set);
3294 
3295  result = action->on_fail;
3296  pe_free_action(action);
3297 
3298  return result;
3299 }
3300 
3301 static void
3302 update_resource_state(pe_resource_t * rsc, pe_node_t * node, xmlNode * xml_op, const char * task, int rc,
3303  xmlNode * last_failure, enum action_fail_response * on_fail, pe_working_set_t * data_set)
3304 {
3305  gboolean clear_past_failure = FALSE;
3306 
3307  CRM_ASSERT(rsc);
3308  CRM_ASSERT(xml_op);
3309 
3310  if (rc == PCMK_OCF_NOT_RUNNING) {
3311  clear_past_failure = TRUE;
3312 
3313  } else if (rc == PCMK_OCF_NOT_INSTALLED) {
3314  rsc->role = RSC_ROLE_STOPPED;
3315 
3316  } else if (safe_str_eq(task, CRMD_ACTION_STATUS)) {
3317  if (last_failure) {
3318  const char *op_key = get_op_key(xml_op);
3319  const char *last_failure_key = get_op_key(last_failure);
3320 
3321  if (safe_str_eq(op_key, last_failure_key)) {
3322  clear_past_failure = TRUE;
3323  }
3324  }
3325 
3326  if (rsc->role < RSC_ROLE_STARTED) {
3327  set_active(rsc);
3328  }
3329 
3330  } else if (safe_str_eq(task, CRMD_ACTION_START)) {
3331  rsc->role = RSC_ROLE_STARTED;
3332  clear_past_failure = TRUE;
3333 
3334  } else if (safe_str_eq(task, CRMD_ACTION_STOP)) {
3335  rsc->role = RSC_ROLE_STOPPED;
3336  clear_past_failure = TRUE;
3337 
3338  } else if (safe_str_eq(task, CRMD_ACTION_PROMOTE)) {
3339  rsc->role = RSC_ROLE_MASTER;
3340  clear_past_failure = TRUE;
3341 
3342  } else if (safe_str_eq(task, CRMD_ACTION_DEMOTE)) {
3343  /* Demote from Master does not clear an error */
3344  rsc->role = RSC_ROLE_SLAVE;
3345 
3346  } else if (safe_str_eq(task, CRMD_ACTION_MIGRATED)) {
3347  rsc->role = RSC_ROLE_STARTED;
3348  clear_past_failure = TRUE;
3349 
3350  } else if (safe_str_eq(task, CRMD_ACTION_MIGRATE)) {
3351  unpack_migrate_to_success(rsc, node, xml_op, data_set);
3352 
3353  } else if (rsc->role < RSC_ROLE_STARTED) {
3354  pe_rsc_trace(rsc, "%s active on %s", rsc->id, node->details->uname);
3355  set_active(rsc);
3356  }
3357 
3358  /* clear any previous failure actions */
3359  if (clear_past_failure) {
3360  switch (*on_fail) {
3361  case action_fail_stop:
3362  case action_fail_fence:
3363  case action_fail_migrate:
3364  case action_fail_standby:
3365  pe_rsc_trace(rsc, "%s.%s is not cleared by a completed stop",
3366  rsc->id, fail2text(*on_fail));
3367  break;
3368 
3369  case action_fail_block:
3370  case action_fail_ignore:
3371  case action_fail_recover:
3373  *on_fail = action_fail_ignore;
3374  rsc->next_role = RSC_ROLE_UNKNOWN;
3375  break;
3377  if (rsc->remote_reconnect_ms == 0) {
3378  /* With no reconnect interval, the connection is allowed to
3379  * start again after the remote node is fenced and
3380  * completely stopped. (With a reconnect interval, we wait
3381  * for the failure to be cleared entirely before attempting
3382  * to reconnect.)
3383  */
3384  *on_fail = action_fail_ignore;
3385  rsc->next_role = RSC_ROLE_UNKNOWN;
3386  }
3387  break;
3388  }
3389  }
3390 }
3391 
3412 static int
3413 remap_monitor_rc(int rc, xmlNode *xml_op, const pe_node_t *node,
3414  const pe_resource_t *rsc, pe_working_set_t *data_set)
3415 {
3416  int remapped_rc = rc;
3417 
3418  switch (rc) {
3419  case PCMK_OCF_DEGRADED:
3420  remapped_rc = PCMK_OCF_OK;
3421  break;
3422 
3424  remapped_rc = PCMK_OCF_RUNNING_MASTER;
3425  break;
3426 
3427  default:
3428  break;
3429  }
3430 
3431  if (rc != remapped_rc) {
3432  crm_trace("Remapping monitor result %d to %d", rc, remapped_rc);
3433  if (!node->details->shutdown || node->details->online) {
3434  record_failed_op(xml_op, node, rsc, data_set);
3435  }
3436  }
3437  return remapped_rc;
3438 }
3439 
3440 static void
3441 unpack_rsc_op(pe_resource_t *rsc, pe_node_t *node, xmlNode *xml_op,
3442  xmlNode **last_failure, enum action_fail_response *on_fail,
3443  pe_working_set_t *data_set)
3444 {
3445  int rc = 0;
3446  int task_id = 0;
3447  int target_rc = 0;
3448  int status = PCMK_LRM_OP_UNKNOWN;
3449  guint interval_ms = 0;
3450  const char *task = NULL;
3451  const char *task_key = NULL;
3452  const char *exit_reason = NULL;
3453  bool expired = FALSE;
3454  pe_resource_t *parent = rsc;
3455  enum action_fail_response failure_strategy = action_fail_recover;
3456 
3457  CRM_CHECK(rsc && node && xml_op, return);
3458 
3459  target_rc = pe__target_rc_from_xml(xml_op);
3460  task_key = get_op_key(xml_op);
3461  task = crm_element_value(xml_op, XML_LRM_ATTR_TASK);
3462  exit_reason = crm_element_value(xml_op, XML_LRM_ATTR_EXIT_REASON);
3463  if (exit_reason == NULL) {
3464  exit_reason = "";
3465  }
3466 
3467  crm_element_value_int(xml_op, XML_LRM_ATTR_RC, &rc);
3468  crm_element_value_int(xml_op, XML_LRM_ATTR_CALLID, &task_id);
3469  crm_element_value_int(xml_op, XML_LRM_ATTR_OPSTATUS, &status);
3470  crm_element_value_ms(xml_op, XML_LRM_ATTR_INTERVAL_MS, &interval_ms);
3471 
3472  CRM_CHECK(task != NULL, return);
3473  CRM_CHECK(status <= PCMK_LRM_OP_INVALID, return);
3474  CRM_CHECK(status >= PCMK_LRM_OP_PENDING, return);
3475 
3476  if (!strcmp(task, CRMD_ACTION_NOTIFY) ||
3477  !strcmp(task, CRMD_ACTION_METADATA)) {
3478  /* safe to ignore these */
3479  return;
3480  }
3481 
3482  if (is_not_set(rsc->flags, pe_rsc_unique)) {
3483  parent = uber_parent(rsc);
3484  }
3485 
3486  pe_rsc_trace(rsc, "Unpacking task %s/%s (call_id=%d, status=%d, rc=%d) on %s (role=%s)",
3487  task_key, task, task_id, status, rc, node->details->uname, role2text(rsc->role));
3488 
3489  if (node->details->unclean) {
3490  pe_rsc_trace(rsc, "Node %s (where %s is running) is unclean."
3491  " Further action depends on the value of the stop's on-fail attribute",
3492  node->details->uname, rsc->id);
3493  }
3494 
3495  /* It should be possible to call remap_monitor_rc() first then call
3496  * check_operation_expiry() only if rc != target_rc, because there should
3497  * never be a fail count without at least one unexpected result in the
3498  * resource history. That would be more efficient by avoiding having to call
3499  * check_operation_expiry() for expected results.
3500  *
3501  * However, we do have such configurations in the scheduler regression
3502  * tests, even if it shouldn't be possible with the current code. It's
3503  * probably a good idea anyway, but that would require updating the test
3504  * inputs to something currently possible.
3505  */
3506 
3507  if ((status != PCMK_LRM_OP_NOT_INSTALLED)
3508  && check_operation_expiry(rsc, node, rc, xml_op, data_set)) {
3509  expired = TRUE;
3510  }
3511 
3512  if (!strcmp(task, CRMD_ACTION_STATUS)) {
3513  rc = remap_monitor_rc(rc, xml_op, node, rsc, data_set);
3514  }
3515 
3516  if (expired && (rc != target_rc)) {
3517  const char *magic = crm_element_value(xml_op, XML_ATTR_TRANSITION_MAGIC);
3518 
3519  if (interval_ms == 0) {
3520  crm_notice("Ignoring expired %s failure on %s "
3521  CRM_XS " actual=%d expected=%d magic=%s",
3522  task_key, node->details->uname, rc, target_rc, magic);
3523  goto done;
3524 
3525  } else if(node->details->online && node->details->unclean == FALSE) {
3526  /* Reschedule the recurring monitor. CancelXmlOp() won't work at
3527  * this stage, so as a hacky workaround, forcibly change the restart
3528  * digest so check_action_definition() does what we want later.
3529  *
3530  * @TODO We should skip this if there is a newer successful monitor.
3531  * Also, this causes rescheduling only if the history entry
3532  * has an op-digest (which the expire-non-blocked-failure
3533  * scheduler regression test doesn't, but that may not be a
3534  * realistic scenario in production).
3535  */
3536  crm_notice("Rescheduling %s after failure expired on %s "
3537  CRM_XS " actual=%d expected=%d magic=%s",
3538  task_key, node->details->uname, rc, target_rc, magic);
3539  crm_xml_add(xml_op, XML_LRM_ATTR_RESTART_DIGEST, "calculated-failure-timeout");
3540  goto done;
3541  }
3542  }
3543 
3544  /* If the executor reported an operation status of anything but done or
3545  * error, consider that final. But for done or error, we know better whether
3546  * it should be treated as a failure or not, because we know the expected
3547  * result.
3548  */
3549  if(status == PCMK_LRM_OP_DONE || status == PCMK_LRM_OP_ERROR) {
3550  status = determine_op_status(rsc, rc, target_rc, node, xml_op, on_fail, data_set);
3551  pe_rsc_trace(rsc, "Remapped %s status to %d", task_key, status);
3552  }
3553 
3554  switch (status) {
3555  case PCMK_LRM_OP_CANCELLED:
3556  // Should never happen
3557  pe_err("Resource history contains cancellation '%s' "
3558  "(%s of %s on %s at %s)",
3559  ID(xml_op), task, rsc->id, node->details->uname,
3560  last_change_str(xml_op));
3561  break;
3562 
3563  case PCMK_LRM_OP_PENDING:
3564  if (!strcmp(task, CRMD_ACTION_START)) {
3566  set_active(rsc);
3567 
3568  } else if (!strcmp(task, CRMD_ACTION_PROMOTE)) {
3569  rsc->role = RSC_ROLE_MASTER;
3570 
3571  } else if (!strcmp(task, CRMD_ACTION_MIGRATE) && node->details->unclean) {
3572  /* If a pending migrate_to action is out on a unclean node,
3573  * we have to force the stop action on the target. */
3574  const char *migrate_target = crm_element_value(xml_op, XML_LRM_ATTR_MIGRATE_TARGET);
3575  pe_node_t *target = pe_find_node(data_set->nodes, migrate_target);
3576  if (target) {
3577  stop_action(rsc, target, FALSE);
3578  }
3579  }
3580 
3581  if (rsc->pending_task == NULL) {
3582  if ((interval_ms != 0) || strcmp(task, CRMD_ACTION_STATUS)) {
3583  rsc->pending_task = strdup(task);
3584  rsc->pending_node = node;
3585  } else {
3586  /* Pending probes are not printed, even if pending
3587  * operations are requested. If someone ever requests that
3588  * behavior, enable the below and the corresponding part of
3589  * native.c:native_pending_task().
3590  */
3591 #if 0
3592  rsc->pending_task = strdup("probe");
3593  rsc->pending_node = node;
3594 #endif
3595  }
3596  }
3597  break;
3598 
3599  case PCMK_LRM_OP_DONE:
3600  pe_rsc_trace(rsc, "%s of %s on %s completed at %s " CRM_XS " id=%s",
3601  task, rsc->id, node->details->uname,
3602  last_change_str(xml_op), ID(xml_op));
3603  update_resource_state(rsc, node, xml_op, task, rc, *last_failure, on_fail, data_set);
3604  break;
3605 
3607  failure_strategy = get_action_on_fail(rsc, task_key, task, data_set);
3608  if (failure_strategy == action_fail_ignore) {
3609  crm_warn("Cannot ignore failed %s of %s on %s: "
3610  "Resource agent doesn't exist "
3611  CRM_XS " status=%d rc=%d id=%s",
3612  task, rsc->id, node->details->uname, status, rc,
3613  ID(xml_op));
3614  /* Also for printing it as "FAILED" by marking it as pe_rsc_failed later */
3615  *on_fail = action_fail_migrate;
3616  }
3617  resource_location(parent, node, -INFINITY, "hard-error", data_set);
3618  unpack_rsc_op_failure(rsc, node, rc, xml_op, last_failure, on_fail, data_set);
3619  break;
3620 
3622  if (pe__is_guest_or_remote_node(node)
3623  && is_set(node->details->remote_rsc->flags, pe_rsc_managed)) {
3624  /* We should never get into a situation where a managed remote
3625  * connection resource is considered OK but a resource action
3626  * behind the connection gets a "not connected" status. But as a
3627  * fail-safe in case a bug or unusual circumstances do lead to
3628  * that, ensure the remote connection is considered failed.
3629  */
3631  }
3632 
3633  // fall through
3634 
3635  case PCMK_LRM_OP_ERROR:
3638  case PCMK_LRM_OP_TIMEOUT:
3640  case PCMK_LRM_OP_INVALID:
3641 
3642  failure_strategy = get_action_on_fail(rsc, task_key, task, data_set);
3643  if ((failure_strategy == action_fail_ignore)
3644  || (failure_strategy == action_fail_restart_container
3645  && !strcmp(task, CRMD_ACTION_STOP))) {
3646 
3647  crm_warn("Pretending failed %s (%s%s%s) of %s on %s at %s "
3648  "succeeded " CRM_XS " rc=%d id=%s",
3649  task, services_ocf_exitcode_str(rc),
3650  (*exit_reason? ": " : ""), exit_reason, rsc->id,
3651  node->details->uname, last_change_str(xml_op), rc,
3652  ID(xml_op));
3653 
3654  update_resource_state(rsc, node, xml_op, task, target_rc, *last_failure, on_fail, data_set);
3655  crm_xml_add(xml_op, XML_ATTR_UNAME, node->details->uname);
3657 
3658  record_failed_op(xml_op, node, rsc, data_set);
3659 
3660  if (failure_strategy == action_fail_restart_container && *on_fail <= action_fail_recover) {
3661  *on_fail = failure_strategy;
3662  }
3663 
3664  } else {
3665  unpack_rsc_op_failure(rsc, node, rc, xml_op, last_failure, on_fail, data_set);
3666 
3667  if(status == PCMK_LRM_OP_ERROR_HARD) {
3668  do_crm_log(rc != PCMK_OCF_NOT_INSTALLED?LOG_ERR:LOG_NOTICE,
3669  "Preventing %s from restarting on %s because "
3670  "of hard failure (%s%s%s)" CRM_XS " rc=%d id=%s",
3671  parent->id, node->details->uname,
3672  services_ocf_exitcode_str(rc),
3673  (*exit_reason? ": " : ""), exit_reason,
3674  rc, ID(xml_op));
3675  resource_location(parent, node, -INFINITY, "hard-error", data_set);
3676 
3677  } else if(status == PCMK_LRM_OP_ERROR_FATAL) {
3678  crm_err("Preventing %s from restarting anywhere because "
3679  "of fatal failure (%s%s%s) " CRM_XS " rc=%d id=%s",
3680  parent->id, services_ocf_exitcode_str(rc),
3681  (*exit_reason? ": " : ""), exit_reason,
3682  rc, ID(xml_op));
3683  resource_location(parent, NULL, -INFINITY, "fatal-error", data_set);
3684  }
3685  }
3686  break;
3687  }
3688 
3689  done:
3690  pe_rsc_trace(rsc, "Resource %s after %s: role=%s, next=%s",
3691  rsc->id, task, role2text(rsc->role),
3692  role2text(rsc->next_role));
3693 }
3694 
3695 static void
3696 add_node_attrs(xmlNode *xml_obj, pe_node_t *node, bool overwrite,
3697  pe_working_set_t *data_set)
3698 {
3699  const char *cluster_name = NULL;
3700 
3701  g_hash_table_insert(node->details->attrs,
3702  strdup(CRM_ATTR_UNAME), strdup(node->details->uname));
3703 
3704  g_hash_table_insert(node->details->attrs, strdup(CRM_ATTR_ID),
3705  strdup(node->details->id));
3706  if (safe_str_eq(node->details->id, data_set->dc_uuid)) {
3707  data_set->dc_node = node;
3708  node->details->is_dc = TRUE;
3709  g_hash_table_insert(node->details->attrs,
3710  strdup(CRM_ATTR_IS_DC), strdup(XML_BOOLEAN_TRUE));
3711  } else {
3712  g_hash_table_insert(node->details->attrs,
3713  strdup(CRM_ATTR_IS_DC), strdup(XML_BOOLEAN_FALSE));
3714  }
3715 
3716  cluster_name = g_hash_table_lookup(data_set->config_hash, "cluster-name");
3717  if (cluster_name) {
3718  g_hash_table_insert(node->details->attrs, strdup(CRM_ATTR_CLUSTER_NAME),
3719  strdup(cluster_name));
3720  }
3721 
3723  node->details->attrs, NULL, overwrite, data_set);
3724 
3725  if (pe_node_attribute_raw(node, CRM_ATTR_SITE_NAME) == NULL) {
3726  const char *site_name = pe_node_attribute_raw(node, "site-name");
3727 
3728  if (site_name) {
3729  g_hash_table_insert(node->details->attrs,
3730  strdup(CRM_ATTR_SITE_NAME),
3731  strdup(site_name));
3732 
3733  } else if (cluster_name) {
3734  /* Default to cluster-name if unset */
3735  g_hash_table_insert(node->details->attrs,
3736  strdup(CRM_ATTR_SITE_NAME),
3737  strdup(cluster_name));
3738  }
3739  }
3740 }
3741 
3742 static GListPtr
3743 extract_operations(const char *node, const char *rsc, xmlNode * rsc_entry, gboolean active_filter)
3744 {
3745  int counter = -1;
3746  int stop_index = -1;
3747  int start_index = -1;
3748 
3749  xmlNode *rsc_op = NULL;
3750 
3751  GListPtr gIter = NULL;
3752  GListPtr op_list = NULL;
3753  GListPtr sorted_op_list = NULL;
3754 
3755  /* extract operations */
3756  op_list = NULL;
3757  sorted_op_list = NULL;
3758 
3759  for (rsc_op = __xml_first_child_element(rsc_entry);
3760  rsc_op != NULL; rsc_op = __xml_next_element(rsc_op)) {
3761  if (crm_str_eq((const char *)rsc_op->name, XML_LRM_TAG_RSC_OP, TRUE)) {
3762  crm_xml_add(rsc_op, "resource", rsc);
3763  crm_xml_add(rsc_op, XML_ATTR_UNAME, node);
3764  op_list = g_list_prepend(op_list, rsc_op);
3765  }
3766  }
3767 
3768  if (op_list == NULL) {
3769  /* if there are no operations, there is nothing to do */
3770  return NULL;
3771  }
3772 
3773  sorted_op_list = g_list_sort(op_list, sort_op_by_callid);
3774 
3775  /* create active recurring operations as optional */
3776  if (active_filter == FALSE) {
3777  return sorted_op_list;
3778  }
3779 
3780  op_list = NULL;
3781 
3782  calculate_active_ops(sorted_op_list, &start_index, &stop_index);
3783 
3784  for (gIter = sorted_op_list; gIter != NULL; gIter = gIter->next) {
3785  xmlNode *rsc_op = (xmlNode *) gIter->data;
3786 
3787  counter++;
3788 
3789  if (start_index < stop_index) {
3790  crm_trace("Skipping %s: not active", ID(rsc_entry));
3791  break;
3792 
3793  } else if (counter < start_index) {
3794  crm_trace("Skipping %s: old", ID(rsc_op));
3795  continue;
3796  }
3797  op_list = g_list_append(op_list, rsc_op);
3798  }
3799 
3800  g_list_free(sorted_op_list);
3801  return op_list;
3802 }
3803 
3804 GListPtr
3805 find_operations(const char *rsc, const char *node, gboolean active_filter,
3806  pe_working_set_t * data_set)
3807 {
3808  GListPtr output = NULL;
3809  GListPtr intermediate = NULL;
3810 
3811  xmlNode *tmp = NULL;
3812  xmlNode *status = find_xml_node(data_set->input, XML_CIB_TAG_STATUS, TRUE);
3813 
3814  pe_node_t *this_node = NULL;
3815 
3816  xmlNode *node_state = NULL;
3817 
3818  for (node_state = __xml_first_child_element(status); node_state != NULL;
3819  node_state = __xml_next_element(node_state)) {
3820 
3821  if (crm_str_eq((const char *)node_state->name, XML_CIB_TAG_STATE, TRUE)) {
3822  const char *uname = crm_element_value(node_state, XML_ATTR_UNAME);
3823 
3824  if (node != NULL && safe_str_neq(uname, node)) {
3825  continue;
3826  }
3827 
3828  this_node = pe_find_node(data_set->nodes, uname);
3829  if(this_node == NULL) {
3830  CRM_LOG_ASSERT(this_node != NULL);
3831  continue;
3832 
3833  } else if (pe__is_guest_or_remote_node(this_node)) {
3834  determine_remote_online_status(data_set, this_node);
3835 
3836  } else {
3837  determine_online_status(node_state, this_node, data_set);
3838  }
3839 
3840  if (this_node->details->online || is_set(data_set->flags, pe_flag_stonith_enabled)) {
3841  /* offline nodes run no resources...
3842  * unless stonith is enabled in which case we need to
3843  * make sure rsc start events happen after the stonith
3844  */
3845  xmlNode *lrm_rsc = NULL;
3846 
3847  tmp = find_xml_node(node_state, XML_CIB_TAG_LRM, FALSE);
3848  tmp = find_xml_node(tmp, XML_LRM_TAG_RESOURCES, FALSE);
3849 
3850  for (lrm_rsc = __xml_first_child_element(tmp); lrm_rsc != NULL;
3851  lrm_rsc = __xml_next_element(lrm_rsc)) {
3852  if (crm_str_eq((const char *)lrm_rsc->name, XML_LRM_TAG_RESOURCE, TRUE)) {
3853 
3854  const char *rsc_id = crm_element_value(lrm_rsc, XML_ATTR_ID);
3855 
3856  if (rsc != NULL && safe_str_neq(rsc_id, rsc)) {
3857  continue;
3858  }
3859 
3860  intermediate = extract_operations(uname, rsc_id, lrm_rsc, active_filter);
3861  output = g_list_concat(output, intermediate);
3862  }
3863  }
3864  }
3865  }
3866  }
3867 
3868  return output;
3869 }
GHashTable * tags
Definition: pe_types.h:169
Services API.
#define CRM_CHECK(expr, failure_action)
Definition: logging.h:233
char uname[MAX_NAME]
Definition: internal.h:85
GListPtr nodes
Definition: pe_types.h:146
#define XML_RSC_OP_LAST_CHANGE
Definition: msg_xml.h:280
void verify_pe_options(GHashTable *options)
Definition: common.c:309
xmlNode * find_xml_node(xmlNode *cib, const char *node_path, gboolean must_find)
Definition: xml.c:1764
enum pe_quorum_policy no_quorum_policy
Definition: pe_types.h:138
#define RSC_STOP
Definition: crm.h:199
A dumping ground.
GHashTable * pe__node_list2table(GList *list)
Definition: utils.c:201
#define crm_notice(fmt, args...)
Definition: logging.h:365
GHashTable * known_on
Definition: pe_types.h:351
int pe__target_rc_from_xml(xmlNode *xml_op)
Definition: unpack.c:3277
#define CRMD_ACTION_MIGRATED
Definition: crm.h:169
xmlNode * failed
Definition: pe_types.h:154
#define pe_flag_stop_action_orphans
Definition: pe_types.h:101
GHashTable * attrs
Definition: pe_types.h:221
#define pe_rsc_debug(rsc, fmt, args...)
Definition: internal.h:18
gboolean unseen
Definition: pe_types.h:205
#define XML_CONFIG_ATTR_SHUTDOWN_LOCK
Definition: msg_xml.h:349
gboolean fixed
Definition: pe_types.h:229
gboolean safe_str_neq(const char *a, const char *b)
Definition: strings.c:263
#define INFINITY
Definition: crm.h:95
gint sort_rsc_priority(gconstpointer a, gconstpointer b)
Definition: utils.c:458
#define CRM_ATTR_KIND
Definition: crm.h:112
GListPtr dangling_migrations
Definition: pe_types.h:362
#define XML_NODE_IS_FENCED
Definition: msg_xml.h:243
#define XML_ATTR_TRANSITION_MAGIC
Definition: msg_xml.h:360
GHashTable * state
Definition: pe_types.h:439
G_GNUC_INTERNAL gboolean unpack_remote_nodes(xmlNode *xml_resources, pe_working_set_t *data_set)
Definition: unpack.c:599
#define CRM_ATTR_IS_DC
Definition: crm.h:114
#define stop_action(rsc, node, optional)
Definition: internal.h:297
void pe__add_param_check(xmlNode *rsc_op, pe_resource_t *rsc, pe_node_t *node, enum pe_check_parameters, pe_working_set_t *data_set)
Definition: remote.c:222
pe_resource_t * container
Definition: pe_types.h:364
pe_node_t * partial_migration_source
Definition: pe_types.h:349
#define XML_ATTR_QUORUM_PANIC
Definition: msg_xml.h:84
#define pe_flag_concurrent_fencing
Definition: pe_types.h:98
#define XML_ATTR_TYPE
Definition: msg_xml.h:99
#define XML_CONFIG_ATTR_PRIORITY_FENCING_DELAY
Definition: msg_xml.h:351
void pe__update_recheck_time(time_t recheck, pe_working_set_t *data_set)
Definition: utils.c:2681
enum rsc_role_e role
Definition: pe_types.h:354
#define XML_TAG_UTILIZATION
Definition: msg_xml.h:171
#define XML_RULE_ATTR_SCORE
Definition: msg_xml.h:296
#define XML_BOOLEAN_FALSE
Definition: msg_xml.h:108
#define pe_flag_symmetric_cluster
Definition: pe_types.h:92
gboolean standby
Definition: pe_types.h:438
int priority_fencing_delay
Definition: pe_types.h:179
#define pcmk__config_err(fmt...)
Definition: internal.h:95
#define pe_flag_remove_after_stop
Definition: pe_types.h:105
enum rsc_role_e next_role
Definition: pe_types.h:355
#define pe_flag_maintenance_mode
Definition: pe_types.h:93
enum action_fail_response on_fail
Definition: pe_types.h:399
int char2score(const char *score)
Definition: utils.c:59
#define pe_proc_warn(fmt...)
Definition: internal.h:24
pe_resource_t * remote_rsc
Definition: pe_types.h:217
#define XML_TAG_TRANSIENT_NODEATTRS
Definition: msg_xml.h:365
#define CRMD_ACTION_NOTIFY
Definition: crm.h:182
GHashTable * meta
Definition: pe_types.h:357
#define pe_rsc_unique
Definition: pe_types.h:241
resource_object_functions_t * fns
Definition: pe_types.h:316
gboolean pe__is_guest_or_remote_node(pe_node_t *node)
Definition: remote.c:58
#define XML_CIB_TAG_TAG
Definition: msg_xml.h:392
G_GNUC_INTERNAL gboolean unpack_status(xmlNode *status, pe_working_set_t *data_set)
Definition: unpack.c:1091
#define XML_LRM_TAG_RESOURCE
Definition: msg_xml.h:227
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
Definition: nvpair.c:316
pe_node_t * pe__copy_node(const pe_node_t *this_node)
Definition: utils.c:139
#define CRMD_ACTION_PROMOTE
Definition: crm.h:177
int crm_parse_int(const char *text, const char *default_text)
Parse an integer value from a string.
Definition: strings.c:126
GListPtr fillers
Definition: pe_types.h:365
gboolean pending
Definition: pe_types.h:203
GListPtr resources
Definition: pe_types.h:147
#define XML_NVPAIR_ATTR_NAME
Definition: msg_xml.h:339
#define XML_NODE_IS_MAINTENANCE
Definition: msg_xml.h:244
char * id
Definition: pe_types.h:443
gint sort_op_by_callid(gconstpointer a, gconstpointer b)
Definition: utils.c:1653
#define XML_NODE_EXPECTED
Definition: msg_xml.h:239
gboolean xml_contains_remote_node(xmlNode *xml)
Definition: remote.c:99
#define XML_CIB_TAG_RSC_TEMPLATE
Definition: msg_xml.h:180
AIS_Host host
Definition: internal.h:84
time_t get_effective_time(pe_working_set_t *data_set)
Definition: utils.c:1770
#define CRM_LOG_ASSERT(expr)
Definition: logging.h:219
pe_node_t * pe_find_node(GListPtr node_list, const char *uname)
Definition: status.c:427
const char * pe_pref(GHashTable *options, const char *name)
Definition: common.c:315
void resource_location(pe_resource_t *rsc, pe_node_t *node, int score, const char *tag, pe_working_set_t *data_set)
Definition: utils.c:1609
xmlNode * params_restart
Definition: internal.h:399
#define clear_bit(word, bit)
Definition: crm_internal.h:69
guint crm_parse_interval_spec(const char *input)
Parse milliseconds from a Pacemaker interval specification.
Definition: utils.c:309
void copy_in_properties(xmlNode *target, xmlNode *src)
Definition: xml.c:1836
#define CRMD_JOINSTATE_NACK
Definition: crm.h:162
#define XML_CIB_TAG_LRM
Definition: msg_xml.h:225
#define CRM_ATTR_CLUSTER_NAME
Definition: crm.h:115
pe_node_t * partial_migration_target
Definition: pe_types.h:348
GHashTable * tickets
Definition: pe_types.h:141
gboolean remote_was_fenced
Definition: pe_types.h:212
int crm_element_value_int(const xmlNode *data, const char *name, int *dest)
Retrieve the integer value of an XML attribute.
Definition: nvpair.c:558
#define pe_flag_have_quorum
Definition: pe_types.h:91
char * pending_task
Definition: pe_types.h:330
bool pe__bundle_needs_remote_name(pe_resource_t *rsc)
Definition: bundle.c:956
xmlNode * get_xpath_object(const char *xpath, xmlNode *xml_obj, int error_level)
Definition: xpath.c:211
#define pe_proc_err(fmt...)
Definition: internal.h:23
gboolean remote_requires_reset
Definition: pe_types.h:211
action_fail_response
Definition: common.h:26
char * strndup(const char *str, size_t len)
char * dc_uuid
Definition: pe_types.h:130
const char * action
Definition: pcmk_fence.c:29
#define XML_CIB_TAG_PROPSET
Definition: msg_xml.h:162
pe_node_t * lock_node
Definition: pe_types.h:368
gboolean pe__is_remote_node(pe_node_t *node)
Definition: remote.c:36
#define CRM_TRACE_INIT_DATA(name)
Definition: logging.h:134
#define pe_flag_stop_everything
Definition: pe_types.h:102
#define XML_LRM_ATTR_RSCID
Definition: msg_xml.h:269
gboolean remote_maintenance
Definition: pe_types.h:213
#define CRMD_ACTION_START
Definition: crm.h:171
uint32_t id
Definition: internal.h:80
gboolean is_dc
Definition: pe_types.h:208
#define XML_LRM_ATTR_TASK_KEY
Definition: msg_xml.h:261
#define XML_TAG_ATTR_SETS
Definition: msg_xml.h:163
#define XML_LRM_ATTR_TASK
Definition: msg_xml.h:260
const char * role2text(enum rsc_role_e role)
Definition: common.c:463
xmlNode * pe_create_remote_xml(xmlNode *parent, const char *uname, const char *container_id, const char *migrateable, const char *is_managed, const char *start_timeout, const char *server, const char *port)
Definition: remote.c:158
G_GNUC_INTERNAL gboolean unpack_tags(xmlNode *xml_tags, pe_working_set_t *data_set)
Definition: unpack.c:799
GListPtr find_operations(const char *rsc, const char *node, gboolean active_filter, pe_working_set_t *data_set)
Definition: unpack.c:3805
#define CRMD_ACTION_STOP
Definition: crm.h:174
pe_resource_t * pe__find_bundle_replica(const pe_resource_t *bundle, const pe_node_t *node)
Definition: bundle.c:1410
#define STATUS_PATH_MAX
Definition: unpack.c:2408
int weight
Definition: pe_types.h:228
#define pe_flag_have_remote_nodes
Definition: pe_types.h:111
#define CRMD_JOINSTATE_DOWN
Definition: crm.h:159
#define crm_warn(fmt, args...)
Definition: logging.h:364
guint remote_reconnect_ms
Definition: pe_types.h:329
#define XML_CONFIG_ATTR_SHUTDOWN_LOCK_LIMIT
Definition: msg_xml.h:350
#define CRMD_ACTION_DEMOTE
Definition: crm.h:179
#define set_bit(word, bit)
Definition: crm_internal.h:68
#define crm_atoi(text, default_text)
Definition: util.h:114
#define pe_rsc_allow_migrate
Definition: pe_types.h:258
#define pe_rsc_orphan_container_filler
Definition: pe_types.h:238
int rc
Definition: pcmk_fence.c:34
int crm_element_value_ms(const xmlNode *data, const char *name, guint *dest)
Retrieve the millisecond value of an XML attribute.
Definition: nvpair.c:614
#define pe_rsc_failed
Definition: pe_types.h:252
#define crm_debug(fmt, args...)
Definition: logging.h:368
G_GNUC_INTERNAL gboolean unpack_nodes(xmlNode *xml_nodes, pe_working_set_t *data_set)
Definition: unpack.c:509
pe_resource_t * uber_parent(pe_resource_t *rsc)
Definition: complex.c:762
#define XML_RSC_ATTR_CONTAINER
Definition: msg_xml.h:205
Utility functions.
#define XML_ATTR_ID
Definition: msg_xml.h:96
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
Definition: nvpair.c:522
#define XML_CIB_TAG_RESOURCE
Definition: msg_xml.h:174
#define pe_rsc_is_container
Definition: pe_types.h:262
#define XML_BOOLEAN_TRUE
Definition: msg_xml.h:107
#define XML_CIB_TAG_STATE
Definition: msg_xml.h:158
gboolean unpacked
Definition: pe_types.h:214
char * digest_all_calc
Definition: internal.h:400
int failure_timeout
Definition: pe_types.h:327
char * clone_strip(const char *last_rsc_id)
Definition: unpack.c:1537
pe_resource_t *(* find_rsc)(pe_resource_t *parent, const char *search, const pe_node_t *node, int flags)
Definition: pe_types.h:45
match only clone instances
Definition: pe_types.h:83
#define pe_rsc_start_pending
Definition: pe_types.h:254
#define pe_warn_once(pe_wo_bit, fmt...)
Definition: internal.h:42
pe_ticket_t * ticket_new(const char *ticket_id, pe_working_set_t *data_set)
Definition: utils.c:1904
#define CRM_ATTR_UNAME
Definition: crm.h:110
#define XML_NODE_IS_PEER
Definition: msg_xml.h:241
GListPtr refs
Definition: pe_types.h:444
#define crm_trace(fmt, args...)
Definition: logging.h:369
#define CRMD_JOINSTATE_MEMBER
Definition: crm.h:161
#define do_crm_log(level, fmt, args...)
Log a message.
Definition: logging.h:150
enum rsc_digest_cmp_val rc
Definition: internal.h:396
void pe_fence_node(pe_working_set_t *data_set, pe_node_t *node, const char *reason, bool priority_delay)
Schedule a fence action for a node.
Definition: unpack.c:85
char * digest_secure_calc
Definition: internal.h:401
void calculate_active_ops(GList *sorted_op_list, int *start_index, int *stop_index)
Definition: unpack.c:2140
xmlNode * add_node_copy(xmlNode *new_parent, xmlNode *xml_node)
Definition: xml.c:1954
#define pe_flag_startup_fencing
Definition: pe_types.h:106
const char * stonith_action
Definition: pe_types.h:132
struct pe_node_shared_s * details
Definition: pe_types.h:231
GListPtr running_on
Definition: pe_types.h:350
gboolean get_target_role(pe_resource_t *rsc, enum rsc_role_e *role)
Definition: utils.c:1785
#define crm_log_xml_debug(xml, text)
Definition: logging.h:376
G_GNUC_INTERNAL gboolean unpack_resources(xmlNode *xml_resources, pe_working_set_t *data_set)
Definition: unpack.c:736
void pe__unpack_dataset_nvpairs(xmlNode *xml_obj, const char *set_name, GHashTable *node_hash, GHashTable *hash, const char *always_first, gboolean overwrite, pe_working_set_t *data_set)
Definition: utils.c:2695
bool pe__shutdown_requested(pe_node_t *node)
Definition: utils.c:2666
#define pe_rsc_needs_fencing
Definition: pe_types.h:265
gboolean order_actions(pe_action_t *lh_action, pe_action_t *rh_action, enum pe_ordering order)
Definition: utils.c:1823
unsigned long long flags
Definition: pe_types.h:332
const char * uname
Definition: pe_types.h:196
#define pe_rsc_promotable
Definition: pe_types.h:243
#define XML_TAG_META_SETS
Definition: msg_xml.h:164
Wrappers for and extensions to libxml2.
GHashTable * config_hash
Definition: pe_types.h:140
#define XML_ATTR_UNAME
Definition: msg_xml.h:118
char * clone_name
Definition: pe_types.h:306
gboolean add_tag_ref(GHashTable *tags, const char *tag_name, const char *obj_ref)
Definition: utils.c:2538
#define XML_RSC_ATTR_MANAGED
Definition: msg_xml.h:195
xmlNode * create_xml_node(xmlNode *parent, const char *name)
Definition: xml.c:1976
time_t lock_time
Definition: pe_types.h:369
#define pe_flag_stonith_enabled
Definition: pe_types.h:95
int crm_element_value_epoch(const xmlNode *xml, const char *name, time_t *dest)
Retrieve the seconds-since-epoch value of an XML attribute.
Definition: nvpair.c:649
const char * pe_node_attribute_raw(pe_node_t *node, const char *name)
Definition: common.c:629
time_t last_granted
Definition: pe_types.h:437
pe_resource_t * pe__create_clone_child(pe_resource_t *rsc, pe_working_set_t *data_set)
Definition: clone.c:59
#define XML_LRM_ATTR_MIGRATE_TARGET
Definition: msg_xml.h:286
#define CIB_OPTIONS_FIRST
Definition: msg_xml.h:49
gboolean standby
Definition: pe_types.h:201
#define XML_RSC_ATTR_REMOTE_NODE
Definition: msg_xml.h:208
#define XML_LRM_ATTR_EXIT_REASON
Definition: msg_xml.h:278
char * uuid
Definition: pe_types.h:393
#define XML_LRM_ATTR_RESTART_DIGEST
Definition: msg_xml.h:276
gboolean expected_up
Definition: pe_types.h:207
void free_xml(xmlNode *child)
Definition: xml.c:2136
enum pe_obj_types variant
Definition: pe_types.h:314
xmlNode * input
Definition: pe_types.h:126
gboolean granted
Definition: pe_types.h:436
gboolean crm_str_eq(const char *a, const char *b, gboolean use_case)
Definition: strings.c:326
#define XML_CIB_TAG_NODE
Definition: msg_xml.h:159
const char * placement_strategy
Definition: pe_types.h:133
const char * pcmk__epoch2str(time_t *when)
Definition: iso8601.c:1715
xmlNode * params_all
Definition: internal.h:397
pe_resource_t * pe_find_resource(GListPtr rsc_list, const char *id_rh)
Definition: status.c:375
const char * id
Definition: pe_types.h:195
char * pcmk__op_key(const char *rsc_id, const char *op_type, guint interval_ms)
Generate an operation key (RESOURCE_ACTION_INTERVAL)
Definition: operations.c:40
char * id
Definition: pe_types.h:435
guint shutdown_lock
Definition: pe_types.h:178
const char * target
Definition: pcmk_fence.c:28
void native_add_running(pe_resource_t *rsc, pe_node_t *node, pe_working_set_t *data_set)
Definition: native.c:83
bool pe_can_fence(pe_working_set_t *data_set, pe_node_t *node)
Definition: utils.c:87
int pcmk__score_green
Definition: utils.c:55
#define XML_ATTR_TRANSITION_KEY
Definition: msg_xml.h:361
gboolean rsc_discovery_enabled
Definition: pe_types.h:210
#define CRM_XS
Definition: logging.h:54
GListPtr running_rsc
Definition: pe_types.h:218
pe_node_t * dc_node
Definition: pe_types.h:131
uint32_t pe_wo
Definition: unpack.c:57
const char * localhost
Definition: pe_types.h:168
#define pe_flag_quick_location
Definition: pe_types.h:113
gboolean pe__is_guest_node(pe_node_t *node)
Definition: remote.c:47
gboolean is_remote_node
Definition: pe_types.h:335
pe_node_t * pending_node
Definition: pe_types.h:367
const char * fail2text(enum action_fail_response fail)
Definition: common.c:321
GListPtr children
Definition: pe_types.h:361
int pcmk__score_red
Definition: utils.c:54
#define XML_LRM_TAG_RESOURCES
Definition: msg_xml.h:226
#define crm_err(fmt, args...)
Definition: logging.h:363
#define XML_CIB_TAG_TICKET_STATE
Definition: msg_xml.h:389
#define set_config_flag(data_set, option, flag)
Definition: unpack.c:30
bool pcmk__ends_with(const char *s, const char *match)
Definition: strings.c:410
#define CRM_ASSERT(expr)
Definition: results.h:42
xmlXPathObjectPtr xpath_search(xmlNode *xml_top, const char *path)
Definition: xpath.c:136
pe_action_t * pe__clear_failcount(pe_resource_t *rsc, pe_node_t *node, const char *reason, pe_working_set_t *data_set)
Schedule a controller operation to clear a fail count.
Definition: failcounts.c:360
gboolean decode_transition_key(const char *key, char **uuid, int *transition_id, int *action_id, int *target_rc)
Parse a transition key into its constituent parts.
Definition: operations.c:218
op_digest_cache_t * rsc_action_digest_cmp(pe_resource_t *rsc, xmlNode *xml_op, pe_node_t *node, pe_working_set_t *data_set)
Definition: utils.c:2095
char * clone_zero(const char *last_rsc_id)
Definition: unpack.c:1559
#define XML_ATTR_HAVE_WATCHDOG
Definition: msg_xml.h:86
#define XML_NODE_ATTR_RSC_DISCOVERY
Definition: msg_xml.h:342
int pcmk__score_yellow
Definition: utils.c:56
#define CRMD_ACTION_METADATA
Definition: crm.h:186
#define XML_LRM_ATTR_INTERVAL_MS
Definition: msg_xml.h:258
xmlNode * params_secure
Definition: internal.h:398
#define XML_LRM_ATTR_CALLID
Definition: msg_xml.h:272
#define CRMD_ACTION_MIGRATE
Definition: crm.h:168
#define XML_NVPAIR_ATTR_VALUE
Definition: msg_xml.h:340
#define crm_str_hash
Definition: util.h:66
void(* free)(pe_resource_t *)
Definition: pe_types.h:54
GHashTable * utilization
Definition: pe_types.h:222
enum rsc_role_e fail_role
Definition: pe_types.h:400
gboolean shutdown
Definition: pe_types.h:206
char data[0]
Definition: internal.h:90
#define crm_str(x)
Definition: logging.h:389
#define XML_LRM_ATTR_OPSTATUS
Definition: msg_xml.h:270
#define CRMD_JOINSTATE_PENDING
Definition: crm.h:160
rsc_role_e
Definition: common.h:76
#define pe_rsc_block
Definition: pe_types.h:237
enum pe_action_flags flags
Definition: pe_types.h:397
gboolean maintenance
Definition: pe_types.h:209
#define XML_LRM_ATTR_RC
Definition: msg_xml.h:271
#define pcmk_ok
Definition: results.h:67
GHashTable * digest_cache
cache of calculated resource digests
Definition: pe_types.h:223
bool pe__is_universal_clone(pe_resource_t *rsc, pe_working_set_t *data_set)
Definition: clone.c:1095
pe_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:369
#define pe_rsc_failure_ignored
Definition: pe_types.h:260
pe_node_t *(* location)(const pe_resource_t *, GList **, int)
Definition: pe_types.h:53
#define XML_NODE_JOIN_STATE
Definition: msg_xml.h:238
void destroy_ticket(gpointer data)
Definition: utils.c:1892
#define XML_CIB_TAG_STATUS
Definition: msg_xml.h:139
#define XML_CIB_TAG_OBJ_REF
Definition: msg_xml.h:393
gboolean common_unpack(xmlNode *xml_obj, pe_resource_t **rsc, pe_resource_t *parent, pe_working_set_t *data_set)
Definition: complex.c:366
#define XML_NODE_IN_CLUSTER
Definition: msg_xml.h:240
gboolean crm_is_true(const char *s)
Definition: strings.c:278
#define pe_flag_have_stonith_resource
Definition: pe_types.h:96
#define CRM_ATTR_SITE_NAME
Definition: crm.h:116
#define XML_CIB_TAG_GROUP
Definition: msg_xml.h:175
#define pe_flag_enable_unfencing
Definition: pe_types.h:97
#define XML_LRM_TAG_RSC_OP
Definition: msg_xml.h:228
#define pe_rsc_trace(rsc, fmt, args...)
Definition: internal.h:19
#define ID(x)
Definition: msg_xml.h:418
unsigned long long flags
Definition: pe_types.h:135
#define pe_err(fmt...)
Definition: internal.h:21
#define safe_str_eq(a, b)
Definition: util.h:65
#define ONLINESTATUS
Definition: util.h:37
GList * pe__resource_actions(const pe_resource_t *rsc, const pe_node_t *node, const char *task, bool require_node)
Find all actions of given type for a resource.
Definition: utils.c:1561
gboolean standby_onfail
Definition: pe_types.h:202
pe_action_t * pe__clear_resource_history(pe_resource_t *rsc, pe_node_t *node, pe_working_set_t *data_set)
Definition: utils.c:2741
char * name
Definition: pcmk_fence.c:30
#define XML_LRM_ATTR_MIGRATE_SOURCE
Definition: msg_xml.h:285
G_GNUC_INTERNAL gboolean unpack_config(xmlNode *config, pe_working_set_t *data_set)
Definition: unpack.c:186
void freeXpathObject(xmlXPathObjectPtr xpathObj)
Definition: xpath.c:36
#define CRM_ATTR_ID
Definition: crm.h:111
const char * pe_base_name_end(const char *id)
Definition: unpack.c:1497
gint sort_node_uname(gconstpointer a, gconstpointer b)
Definition: utils.c:215
gboolean unclean
Definition: pe_types.h:204
char * crm_strdup_printf(char const *format,...) __attribute__((__format__(__printf__
#define XPATH_ENABLE_UNFENCING
Definition: unpack.c:164
GList * GListPtr
Definition: crm.h:214
#define pe_flag_start_failure_fatal
Definition: pe_types.h:104
enum node_type type
Definition: pe_types.h:197
#define XML_CIB_TAG_TICKETS
Definition: msg_xml.h:388
#define crm_info(fmt, args...)
Definition: logging.h:366
char * digest_restart_calc
Definition: internal.h:402
#define pe_rsc_managed
Definition: pe_types.h:236
#define pe_rsc_orphan
Definition: pe_types.h:235
GHashTable * template_rsc_sets
Definition: pe_types.h:167
#define pcmk__config_warn(fmt...)
Definition: internal.h:100
pe_node_t * pe_find_node_any(GListPtr node_list, const char *id, const char *uname)
Definition: status.c:399
gboolean online
Definition: pe_types.h:200
int pe_get_failcount(pe_node_t *node, pe_resource_t *rsc, time_t *last_failure, uint32_t flags, xmlNode *xml_op, pe_working_set_t *data_set)
Definition: failcounts.c:251
GList * stop_needed
Definition: pe_types.h:175
pe_resource_t * parent
Definition: pe_types.h:312
pe_action_t * pe_fence_op(pe_node_t *node, const char *op, bool optional, const char *reason, bool priority_delay, pe_working_set_t *data_set)
Definition: utils.c:2398
void pe_free_action(pe_action_t *action)
Definition: utils.c:1357
#define pe_flag_shutdown_lock
Definition: pe_types.h:107
enum crm_ais_msg_types type
Definition: internal.h:83
#define pe_rsc_info(rsc, fmt, args...)
Definition: internal.h:17
char * id
Definition: pe_types.h:305
GHashTable * allowed_nodes
Definition: pe_types.h:352
pe_action_t * custom_action(pe_resource_t *rsc, char *key, const char *task, pe_node_t *on_node, gboolean optional, gboolean foo, pe_working_set_t *data_set)
Definition: utils.c:485
#define pe_flag_startup_probes
Definition: pe_types.h:109
#define CRMD_ACTION_STATUS
Definition: crm.h:185
#define pe_flag_stop_rsc_orphans
Definition: pe_types.h:100