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