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