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