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