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