pacemaker  2.0.4-2deceaa
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
clone.c
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2020 the Pacemaker project contributors
3  *
4  * The version control history for this file may have further details.
5  *
6  * This source code is licensed under the GNU Lesser General Public License
7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8  */
9 
10 #include <crm_internal.h>
11 
12 #include <crm/pengine/rules.h>
13 #include <crm/pengine/status.h>
14 #include <crm/pengine/internal.h>
15 #include <pe_status_private.h>
16 #include <crm/msg_xml.h>
17 
18 #define VARIANT_CLONE 1
19 #include "./variant.h"
20 
21 void
22 pe__force_anon(const char *standard, pe_resource_t *rsc, const char *rid,
23  pe_working_set_t *data_set)
24 {
25  if (pe_rsc_is_clone(rsc)) {
26  clone_variant_data_t *clone_data = NULL;
27 
28  get_clone_variant_data(clone_data, rsc);
29 
30  pe_warn("Ignoring " XML_RSC_ATTR_UNIQUE " for %s because %s resources "
31  "such as %s can be used only as anonymous clones",
32  rsc->id, standard, rid);
33 
34  clone_data->clone_node_max = 1;
35  clone_data->clone_max = QB_MIN(clone_data->clone_max,
36  g_list_length(data_set->nodes));
37  }
38 }
39 
41 find_clone_instance(pe_resource_t * rsc, const char *sub_id, pe_working_set_t * data_set)
42 {
43  char *child_id = NULL;
44  pe_resource_t *child = NULL;
45  const char *child_base = NULL;
46  clone_variant_data_t *clone_data = NULL;
47 
48  get_clone_variant_data(clone_data, rsc);
49 
50  child_base = ID(clone_data->xml_obj_child);
51  child_id = crm_strdup_printf("%s:%s", child_base, sub_id);
52  child = pe_find_resource(rsc->children, child_id);
53 
54  free(child_id);
55  return child;
56 }
57 
60 {
61  gboolean as_orphan = FALSE;
62  char *inc_num = NULL;
63  char *inc_max = NULL;
64  pe_resource_t *child_rsc = NULL;
65  xmlNode *child_copy = NULL;
66  clone_variant_data_t *clone_data = NULL;
67 
68  get_clone_variant_data(clone_data, rsc);
69 
70  CRM_CHECK(clone_data->xml_obj_child != NULL, return FALSE);
71 
72  if (clone_data->total_clones >= clone_data->clone_max) {
73  // If we've already used all available instances, this is an orphan
74  as_orphan = TRUE;
75  }
76 
77  // Allocate instance numbers in numerical order (starting at 0)
78  inc_num = crm_itoa(clone_data->total_clones);
79  inc_max = crm_itoa(clone_data->clone_max);
80 
81  child_copy = copy_xml(clone_data->xml_obj_child);
82 
83  crm_xml_add(child_copy, XML_RSC_ATTR_INCARNATION, inc_num);
84 
85  if (common_unpack(child_copy, &child_rsc, rsc, data_set) == FALSE) {
86  pe_err("Failed unpacking resource %s", crm_element_value(child_copy, XML_ATTR_ID));
87  child_rsc = NULL;
88  goto bail;
89  }
90 /* child_rsc->globally_unique = rsc->globally_unique; */
91 
92  CRM_ASSERT(child_rsc);
93  clone_data->total_clones += 1;
94  pe_rsc_trace(child_rsc, "Setting clone attributes for: %s", child_rsc->id);
95  rsc->children = g_list_append(rsc->children, child_rsc);
96  if (as_orphan) {
97  set_bit_recursive(child_rsc, pe_rsc_orphan);
98  }
99 
100  add_hash_param(child_rsc->meta, XML_RSC_ATTR_INCARNATION_MAX, inc_max);
101  pe_rsc_trace(rsc, "Added %s instance %s", rsc->id, child_rsc->id);
102 
103  bail:
104  free(inc_num);
105  free(inc_max);
106 
107  return child_rsc;
108 }
109 
110 gboolean
112 {
113  int lpc = 0;
114  xmlNode *a_child = NULL;
115  xmlNode *xml_obj = rsc->xml;
116  clone_variant_data_t *clone_data = NULL;
117 
118  const char *ordered = g_hash_table_lookup(rsc->meta, XML_RSC_ATTR_ORDERED);
119  const char *max_clones = g_hash_table_lookup(rsc->meta, XML_RSC_ATTR_INCARNATION_MAX);
120  const char *max_clones_node = g_hash_table_lookup(rsc->meta, XML_RSC_ATTR_INCARNATION_NODEMAX);
121 
122  pe_rsc_trace(rsc, "Processing resource %s...", rsc->id);
123 
124  clone_data = calloc(1, sizeof(clone_variant_data_t));
125  rsc->variant_opaque = clone_data;
126 
127  if (is_set(rsc->flags, pe_rsc_promotable)) {
128  const char *promoted_max = NULL;
129  const char *promoted_node_max = NULL;
130 
131  promoted_max = g_hash_table_lookup(rsc->meta,
133  if (promoted_max == NULL) {
134  // @COMPAT deprecated since 2.0.0
135  promoted_max = g_hash_table_lookup(rsc->meta,
137  }
138 
139  promoted_node_max = g_hash_table_lookup(rsc->meta,
141  if (promoted_node_max == NULL) {
142  // @COMPAT deprecated since 2.0.0
143  promoted_node_max = g_hash_table_lookup(rsc->meta,
145  }
146 
147  clone_data->promoted_max = crm_parse_int(promoted_max, "1");
148  clone_data->promoted_node_max = crm_parse_int(promoted_node_max, "1");
149  }
150 
151  // Implied by calloc()
152  /* clone_data->xml_obj_child = NULL; */
153 
154  clone_data->clone_node_max = crm_parse_int(max_clones_node, "1");
155 
156  if (max_clones) {
157  clone_data->clone_max = crm_parse_int(max_clones, "1");
158 
159  } else if (pcmk__list_of_multiple(data_set->nodes)) {
160  clone_data->clone_max = g_list_length(data_set->nodes);
161 
162  } else {
163  clone_data->clone_max = 1; /* Handy during crm_verify */
164  }
165 
166  clone_data->ordered = crm_is_true(ordered);
167 
168  if ((rsc->flags & pe_rsc_unique) == 0 && clone_data->clone_node_max > 1) {
169  pcmk__config_err("Ignoring " XML_RSC_ATTR_PROMOTED_MAX " for %s "
170  "because anonymous clones support only one instance "
171  "per node", rsc->id);
172  clone_data->clone_node_max = 1;
173  }
174 
175  pe_rsc_trace(rsc, "Options for %s", rsc->id);
176  pe_rsc_trace(rsc, "\tClone max: %d", clone_data->clone_max);
177  pe_rsc_trace(rsc, "\tClone node max: %d", clone_data->clone_node_max);
178  pe_rsc_trace(rsc, "\tClone is unique: %s",
179  is_set(rsc->flags, pe_rsc_unique) ? "true" : "false");
180  pe_rsc_trace(rsc, "\tClone is promotable: %s",
181  is_set(rsc->flags, pe_rsc_promotable) ? "true" : "false");
182 
183  // Clones may contain a single group or primitive
184  for (a_child = __xml_first_child_element(xml_obj); a_child != NULL;
185  a_child = __xml_next_element(a_child)) {
186 
187  if (crm_str_eq((const char *)a_child->name, XML_CIB_TAG_RESOURCE, TRUE)
188  || crm_str_eq((const char *)a_child->name, XML_CIB_TAG_GROUP, TRUE)) {
189  clone_data->xml_obj_child = a_child;
190  break;
191  }
192  }
193 
194  if (clone_data->xml_obj_child == NULL) {
195  pcmk__config_err("%s has nothing to clone", rsc->id);
196  return FALSE;
197  }
198 
199  /*
200  * Make clones ever so slightly sticky by default
201  *
202  * This helps ensure clone instances are not shuffled around the cluster
203  * for no benefit in situations when pre-allocation is not appropriate
204  */
205  if (g_hash_table_lookup(rsc->meta, XML_RSC_ATTR_STICKINESS) == NULL) {
207  }
208 
209  /* This ensures that the globally-unique value always exists for children to
210  * inherit when being unpacked, as well as in resource agents' environment.
211  */
214 
215  if (clone_data->clone_max <= 0) {
216  /* Create one child instance so that unpack_find_resource() will hook up
217  * any orphans up to the parent correctly.
218  */
219  if (pe__create_clone_child(rsc, data_set) == NULL) {
220  return FALSE;
221  }
222 
223  } else {
224  // Create a child instance for each available instance number
225  for (lpc = 0; lpc < clone_data->clone_max; lpc++) {
226  if (pe__create_clone_child(rsc, data_set) == NULL) {
227  return FALSE;
228  }
229  }
230  }
231 
232  pe_rsc_trace(rsc, "Added %d children to resource %s...", clone_data->clone_max, rsc->id);
233  return TRUE;
234 }
235 
236 gboolean
237 clone_active(pe_resource_t * rsc, gboolean all)
238 {
239  GListPtr gIter = rsc->children;
240 
241  for (; gIter != NULL; gIter = gIter->next) {
242  pe_resource_t *child_rsc = (pe_resource_t *) gIter->data;
243  gboolean child_active = child_rsc->fns->active(child_rsc, all);
244 
245  if (all == FALSE && child_active) {
246  return TRUE;
247  } else if (all && child_active == FALSE) {
248  return FALSE;
249  }
250  }
251 
252  if (all) {
253  return TRUE;
254  } else {
255  return FALSE;
256  }
257 }
258 
259 static void
260 short_print(char *list, const char *prefix, const char *type, const char *suffix, long options, void *print_data)
261 {
262  if(suffix == NULL) {
263  suffix = "";
264  }
265 
266  if (list) {
267  if (options & pe_print_html) {
268  status_print("<li>");
269  }
270  status_print("%s%s: [%s ]%s", prefix, type, list, suffix);
271 
272  if (options & pe_print_html) {
273  status_print("</li>\n");
274 
275  } else if (options & pe_print_suppres_nl) {
276  /* nothing */
277  } else if ((options & pe_print_printf) || (options & pe_print_ncurses)) {
278  status_print("\n");
279  }
280 
281  }
282 }
283 
284 static const char *
285 configured_role_str(pe_resource_t * rsc)
286 {
287  const char *target_role = g_hash_table_lookup(rsc->meta,
289 
290  if ((target_role == NULL) && rsc->children && rsc->children->data) {
291  target_role = g_hash_table_lookup(((pe_resource_t*)rsc->children->data)->meta,
293  }
294  return target_role;
295 }
296 
297 static enum rsc_role_e
298 configured_role(pe_resource_t * rsc)
299 {
300  const char *target_role = configured_role_str(rsc);
301 
302  if (target_role) {
303  return text2role(target_role);
304  }
305  return RSC_ROLE_UNKNOWN;
306 }
307 
308 static void
309 clone_print_xml(pe_resource_t * rsc, const char *pre_text, long options, void *print_data)
310 {
311  char *child_text = crm_strdup_printf("%s ", pre_text);
312  const char *target_role = configured_role_str(rsc);
313  GListPtr gIter = rsc->children;
314 
315  status_print("%s<clone ", pre_text);
316  status_print("id=\"%s\" ", rsc->id);
317  status_print("multi_state=\"%s\" ", is_set(rsc->flags, pe_rsc_promotable)? "true" : "false");
318  status_print("unique=\"%s\" ", is_set(rsc->flags, pe_rsc_unique) ? "true" : "false");
319  status_print("managed=\"%s\" ", is_set(rsc->flags, pe_rsc_managed) ? "true" : "false");
320  status_print("failed=\"%s\" ", is_set(rsc->flags, pe_rsc_failed) ? "true" : "false");
321  status_print("failure_ignored=\"%s\" ",
322  is_set(rsc->flags, pe_rsc_failure_ignored) ? "true" : "false");
323  if (target_role) {
324  status_print("target_role=\"%s\" ", target_role);
325  }
326  status_print(">\n");
327 
328  for (; gIter != NULL; gIter = gIter->next) {
329  pe_resource_t *child_rsc = (pe_resource_t *) gIter->data;
330 
331  child_rsc->fns->print(child_rsc, child_text, options, print_data);
332  }
333 
334  status_print("%s</clone>\n", pre_text);
335  free(child_text);
336 }
337 
338 bool is_set_recursive(pe_resource_t * rsc, long long flag, bool any)
339 {
340  GListPtr gIter;
341  bool all = !any;
342 
343  if(is_set(rsc->flags, flag)) {
344  if(any) {
345  return TRUE;
346  }
347  } else if(all) {
348  return FALSE;
349  }
350 
351  for (gIter = rsc->children; gIter != NULL; gIter = gIter->next) {
352  if(is_set_recursive(gIter->data, flag, any)) {
353  if(any) {
354  return TRUE;
355  }
356 
357  } else if(all) {
358  return FALSE;
359  }
360  }
361 
362  if(all) {
363  return TRUE;
364  }
365  return FALSE;
366 }
367 
368 void
369 clone_print(pe_resource_t * rsc, const char *pre_text, long options, void *print_data)
370 {
371  char *list_text = NULL;
372  char *child_text = NULL;
373  char *stopped_list = NULL;
374 
375  GListPtr master_list = NULL;
376  GListPtr started_list = NULL;
377  GListPtr gIter = rsc->children;
378 
379  clone_variant_data_t *clone_data = NULL;
380  int active_instances = 0;
381 
382  if (pre_text == NULL) {
383  pre_text = " ";
384  }
385 
386  if (options & pe_print_xml) {
387  clone_print_xml(rsc, pre_text, options, print_data);
388  return;
389  }
390 
391  get_clone_variant_data(clone_data, rsc);
392 
393  child_text = crm_strdup_printf("%s ", pre_text);
394 
395  status_print("%sClone Set: %s [%s]%s%s%s",
396  pre_text ? pre_text : "", rsc->id, ID(clone_data->xml_obj_child),
397  is_set(rsc->flags, pe_rsc_promotable) ? " (promotable)" : "",
398  is_set(rsc->flags, pe_rsc_unique) ? " (unique)" : "",
399  is_set(rsc->flags, pe_rsc_managed) ? "" : " (unmanaged)");
400 
401  if (options & pe_print_html) {
402  status_print("\n<ul>\n");
403 
404  } else if ((options & pe_print_log) == 0) {
405  status_print("\n");
406  }
407 
408  for (; gIter != NULL; gIter = gIter->next) {
409  gboolean print_full = FALSE;
410  pe_resource_t *child_rsc = (pe_resource_t *) gIter->data;
411  gboolean partially_active = child_rsc->fns->active(child_rsc, FALSE);
412 
413  if (options & pe_print_clone_details) {
414  print_full = TRUE;
415  }
416 
417  if (is_set(rsc->flags, pe_rsc_unique)) {
418  // Print individual instance when unique (except stopped orphans)
419  if (partially_active || is_not_set(rsc->flags, pe_rsc_orphan)) {
420  print_full = TRUE;
421  }
422 
423  // Everything else in this block is for anonymous clones
424 
425  } else if (is_set(options, pe_print_pending)
426  && (child_rsc->pending_task != NULL)
427  && strcmp(child_rsc->pending_task, "probe")) {
428  // Print individual instance when non-probe action is pending
429  print_full = TRUE;
430 
431  } else if (partially_active == FALSE) {
432  // List stopped instances when requested (except orphans)
433  if (is_not_set(child_rsc->flags, pe_rsc_orphan)
434  && is_not_set(options, pe_print_clone_active)) {
435  stopped_list = pcmk__add_word(stopped_list, child_rsc->id);
436  }
437 
438  } else if (is_set_recursive(child_rsc, pe_rsc_orphan, TRUE)
439  || is_set_recursive(child_rsc, pe_rsc_managed, FALSE) == FALSE
440  || is_set_recursive(child_rsc, pe_rsc_failed, TRUE)) {
441 
442  // Print individual instance when active orphaned/unmanaged/failed
443  print_full = TRUE;
444 
445  } else if (child_rsc->fns->active(child_rsc, TRUE)) {
446  // Instance of fully active anonymous clone
447 
448  pe_node_t *location = child_rsc->fns->location(child_rsc, NULL, TRUE);
449 
450  if (location) {
451  // Instance is active on a single node
452 
453  enum rsc_role_e a_role = child_rsc->fns->state(child_rsc, TRUE);
454 
455  if (location->details->online == FALSE && location->details->unclean) {
456  print_full = TRUE;
457 
458  } else if (a_role > RSC_ROLE_SLAVE) {
459  master_list = g_list_append(master_list, location);
460 
461  } else {
462  started_list = g_list_append(started_list, location);
463  }
464 
465  } else {
466  /* uncolocated group - bleh */
467  print_full = TRUE;
468  }
469 
470  } else {
471  // Instance of partially active anonymous clone
472  print_full = TRUE;
473  }
474 
475  if (print_full) {
476  if (options & pe_print_html) {
477  status_print("<li>\n");
478  }
479  child_rsc->fns->print(child_rsc, child_text, options, print_data);
480  if (options & pe_print_html) {
481  status_print("</li>\n");
482  }
483  }
484  }
485 
486  /* Masters */
487  master_list = g_list_sort(master_list, sort_node_uname);
488  for (gIter = master_list; gIter; gIter = gIter->next) {
489  pe_node_t *host = gIter->data;
490 
491  list_text = pcmk__add_word(list_text, host->details->uname);
492  active_instances++;
493  }
494 
495  short_print(list_text, child_text, "Masters", NULL, options, print_data);
496  g_list_free(master_list);
497  free(list_text);
498  list_text = NULL;
499 
500  /* Started/Slaves */
501  started_list = g_list_sort(started_list, sort_node_uname);
502  for (gIter = started_list; gIter; gIter = gIter->next) {
503  pe_node_t *host = gIter->data;
504 
505  list_text = pcmk__add_word(list_text, host->details->uname);
506  active_instances++;
507  }
508 
509  if (is_set(rsc->flags, pe_rsc_promotable)) {
510  enum rsc_role_e role = configured_role(rsc);
511 
512  if(role == RSC_ROLE_SLAVE) {
513  short_print(list_text, child_text, "Slaves (target-role)", NULL, options, print_data);
514  } else {
515  short_print(list_text, child_text, "Slaves", NULL, options, print_data);
516  }
517 
518  } else {
519  short_print(list_text, child_text, "Started", NULL, options, print_data);
520  }
521 
522  g_list_free(started_list);
523  free(list_text);
524  list_text = NULL;
525 
526  if (is_not_set(options, pe_print_clone_active)) {
527  const char *state = "Stopped";
528  enum rsc_role_e role = configured_role(rsc);
529 
530  if (role == RSC_ROLE_STOPPED) {
531  state = "Stopped (disabled)";
532  }
533 
534  if (is_not_set(rsc->flags, pe_rsc_unique)
535  && (clone_data->clone_max > active_instances)) {
536 
537  GListPtr nIter;
538  GListPtr list = g_hash_table_get_values(rsc->allowed_nodes);
539 
540  /* Custom stopped list for non-unique clones */
541  free(stopped_list); stopped_list = NULL;
542 
543  if (list == NULL) {
544  /* Clusters with symmetrical=false haven't calculated allowed_nodes yet
545  * If we've not probed for them yet, the Stopped list will be empty
546  */
547  list = g_hash_table_get_values(rsc->known_on);
548  }
549 
550  list = g_list_sort(list, sort_node_uname);
551  for (nIter = list; nIter != NULL; nIter = nIter->next) {
552  pe_node_t *node = (pe_node_t *)nIter->data;
553 
554  if (pe_find_node(rsc->running_on, node->details->uname) == NULL) {
555  stopped_list = pcmk__add_word(stopped_list,
556  node->details->uname);
557  }
558  }
559  g_list_free(list);
560  }
561 
562  short_print(stopped_list, child_text, state, NULL, options, print_data);
563  free(stopped_list);
564  }
565 
566  if (options & pe_print_html) {
567  status_print("</ul>\n");
568  }
569 
570  free(child_text);
571 }
572 
573 PCMK__OUTPUT_ARGS("clone", "unsigned int", "struct pe_resource_t *", "GListPtr")
574 int
575 pe__clone_xml(pcmk__output_t *out, va_list args)
576 {
577  unsigned int options = va_arg(args, unsigned int);
578  pe_resource_t *rsc = va_arg(args, pe_resource_t *);
579  GListPtr only_show = va_arg(args, GListPtr);
580 
581  GListPtr gIter = rsc->children;
582 
583  int rc = pcmk_rc_no_output;
584  gboolean printed_header = FALSE;
585 
586  for (; gIter != NULL; gIter = gIter->next) {
587  pe_resource_t *child_rsc = (pe_resource_t *) gIter->data;
588 
589  if (pcmk__rsc_is_filtered(child_rsc, only_show)) {
590  continue;
591  }
592 
593  if (!printed_header) {
594  printed_header = TRUE;
595 
596  rc = pe__name_and_nvpairs_xml(out, true, "clone", 7
597  , "id", rsc->id
598  , "multi_state", BOOL2STR(is_set(rsc->flags, pe_rsc_promotable))
599  , "unique", BOOL2STR(is_set(rsc->flags, pe_rsc_unique))
600  , "managed", BOOL2STR(is_set(rsc->flags, pe_rsc_managed))
601  , "failed", BOOL2STR(is_set(rsc->flags, pe_rsc_failed))
602  , "failure_ignored", BOOL2STR(is_set(rsc->flags, pe_rsc_failure_ignored))
603  , "target_role", configured_role_str(rsc));
604  CRM_ASSERT(rc == pcmk_rc_ok);
605  }
606 
607  out->message(out, crm_map_element_name(child_rsc->xml), options, child_rsc, only_show);
608  }
609 
610  if (printed_header) {
612  }
613 
614  return rc;
615 }
616 
617 PCMK__OUTPUT_ARGS("clone", "unsigned int", "struct pe_resource_t *", "GListPtr")
618 int
619 pe__clone_html(pcmk__output_t *out, va_list args)
620 {
621  unsigned int options = va_arg(args, unsigned int);
622  pe_resource_t *rsc = va_arg(args, pe_resource_t *);
623  GListPtr only_show = va_arg(args, GListPtr);
624 
625  char *list_text = NULL;
626  char *stopped_list = NULL;
627 
628  GListPtr master_list = NULL;
629  GListPtr started_list = NULL;
630  GListPtr gIter = rsc->children;
631 
632  clone_variant_data_t *clone_data = NULL;
633  int active_instances = 0;
634 
635  get_clone_variant_data(clone_data, rsc);
636 
637  out->begin_list(out, NULL, NULL, "Clone Set: %s [%s]%s%s%s",
638  rsc->id, ID(clone_data->xml_obj_child),
639  is_set(rsc->flags, pe_rsc_promotable) ? " (promotable)" : "",
640  is_set(rsc->flags, pe_rsc_unique) ? " (unique)" : "",
641  is_set(rsc->flags, pe_rsc_managed) ? "" : " (unmanaged)");
642 
643  for (; gIter != NULL; gIter = gIter->next) {
644  gboolean print_full = FALSE;
645  pe_resource_t *child_rsc = (pe_resource_t *) gIter->data;
646  gboolean partially_active = child_rsc->fns->active(child_rsc, FALSE);
647 
648  if (pcmk__rsc_is_filtered(child_rsc, only_show)) {
649  continue;
650  }
651 
652  if (options & pe_print_clone_details) {
653  print_full = TRUE;
654  }
655 
656  if (is_set(rsc->flags, pe_rsc_unique)) {
657  // Print individual instance when unique (except stopped orphans)
658  if (partially_active || is_not_set(rsc->flags, pe_rsc_orphan)) {
659  print_full = TRUE;
660  }
661 
662  // Everything else in this block is for anonymous clones
663 
664  } else if (is_set(options, pe_print_pending)
665  && (child_rsc->pending_task != NULL)
666  && strcmp(child_rsc->pending_task, "probe")) {
667  // Print individual instance when non-probe action is pending
668  print_full = TRUE;
669 
670  } else if (partially_active == FALSE) {
671  // List stopped instances when requested (except orphans)
672  if (is_not_set(child_rsc->flags, pe_rsc_orphan)
673  && is_not_set(options, pe_print_clone_active)) {
674  stopped_list = pcmk__add_word(stopped_list, child_rsc->id);
675  }
676 
677  } else if (is_set_recursive(child_rsc, pe_rsc_orphan, TRUE)
678  || is_set_recursive(child_rsc, pe_rsc_managed, FALSE) == FALSE
679  || is_set_recursive(child_rsc, pe_rsc_failed, TRUE)) {
680 
681  // Print individual instance when active orphaned/unmanaged/failed
682  print_full = TRUE;
683 
684  } else if (child_rsc->fns->active(child_rsc, TRUE)) {
685  // Instance of fully active anonymous clone
686 
687  pe_node_t *location = child_rsc->fns->location(child_rsc, NULL, TRUE);
688 
689  if (location) {
690  // Instance is active on a single node
691 
692  enum rsc_role_e a_role = child_rsc->fns->state(child_rsc, TRUE);
693 
694  if (location->details->online == FALSE && location->details->unclean) {
695  print_full = TRUE;
696 
697  } else if (a_role > RSC_ROLE_SLAVE) {
698  master_list = g_list_append(master_list, location);
699 
700  } else {
701  started_list = g_list_append(started_list, location);
702  }
703 
704  } else {
705  /* uncolocated group - bleh */
706  print_full = TRUE;
707  }
708 
709  } else {
710  // Instance of partially active anonymous clone
711  print_full = TRUE;
712  }
713 
714  if (print_full) {
715  out->message(out, crm_map_element_name(child_rsc->xml), options, child_rsc, only_show);
716  }
717  }
718 
719  if (is_set(options, pe_print_clone_details)) {
720  free(stopped_list);
721  out->end_list(out);
722  return pcmk_rc_ok;
723  }
724 
725  /* Masters */
726  master_list = g_list_sort(master_list, sort_node_uname);
727  for (gIter = master_list; gIter; gIter = gIter->next) {
728  pe_node_t *host = gIter->data;
729 
730  if (!pcmk__str_in_list(only_show, host->details->uname)) {
731  continue;
732  }
733 
734  list_text = pcmk__add_word(list_text, host->details->uname);
735  active_instances++;
736  }
737 
738  if (list_text != NULL) {
739  out->list_item(out, NULL, " Masters: [%s ]", list_text);
740  g_list_free(master_list);
741  free(list_text);
742  list_text = NULL;
743  }
744 
745  /* Started/Slaves */
746  started_list = g_list_sort(started_list, sort_node_uname);
747  for (gIter = started_list; gIter; gIter = gIter->next) {
748  pe_node_t *host = gIter->data;
749 
750  if (!pcmk__str_in_list(only_show, host->details->uname)) {
751  continue;
752  }
753 
754  list_text = pcmk__add_word(list_text, host->details->uname);
755  active_instances++;
756  }
757 
758  if (list_text != NULL) {
759  if (is_set(rsc->flags, pe_rsc_promotable)) {
760  enum rsc_role_e role = configured_role(rsc);
761 
762  if(role == RSC_ROLE_SLAVE) {
763  out->list_item(out, NULL, " Slaves (target-role): [%s ]", list_text);
764  } else {
765  out->list_item(out, NULL, " Slaves: [%s ]", list_text);
766  }
767 
768  } else {
769  out->list_item(out, NULL, " Started: [%s ]", list_text);
770  }
771 
772  g_list_free(started_list);
773  free(list_text);
774  list_text = NULL;
775  }
776 
777  if (is_not_set(options, pe_print_clone_active)) {
778  const char *state = "Stopped";
779  enum rsc_role_e role = configured_role(rsc);
780 
781  if (role == RSC_ROLE_STOPPED) {
782  state = "Stopped (disabled)";
783  }
784 
785  if (is_not_set(rsc->flags, pe_rsc_unique)
786  && (clone_data->clone_max > active_instances)) {
787 
788  GListPtr nIter;
789  GListPtr list = g_hash_table_get_values(rsc->allowed_nodes);
790 
791  /* Custom stopped list for non-unique clones */
792  free(stopped_list);
793  stopped_list = NULL;
794 
795  if (list == NULL) {
796  /* Clusters with symmetrical=false haven't calculated allowed_nodes yet
797  * If we've not probed for them yet, the Stopped list will be empty
798  */
799  list = g_hash_table_get_values(rsc->known_on);
800  }
801 
802  list = g_list_sort(list, sort_node_uname);
803  for (nIter = list; nIter != NULL; nIter = nIter->next) {
804  pe_node_t *node = (pe_node_t *)nIter->data;
805 
806  if (pe_find_node(rsc->running_on, node->details->uname) == NULL &&
807  pcmk__str_in_list(only_show, node->details->uname)) {
808  stopped_list = pcmk__add_word(stopped_list,
809  node->details->uname);
810  }
811  }
812  g_list_free(list);
813  }
814 
815  if (stopped_list != NULL) {
816  out->list_item(out, NULL, " %s: [%s ]", state, stopped_list);
817  free(stopped_list);
818  }
819  }
820 
821  out->end_list(out);
822 
823  return pcmk_rc_ok;
824 }
825 
826 PCMK__OUTPUT_ARGS("clone", "unsigned int", "struct pe_resource_t *", "GListPtr")
827 int
828 pe__clone_text(pcmk__output_t *out, va_list args)
829 {
830  unsigned int options = va_arg(args, unsigned int);
831  pe_resource_t *rsc = va_arg(args, pe_resource_t *);
832  GListPtr only_show = va_arg(args, GListPtr);
833 
834  char *list_text = NULL;
835  char *stopped_list = NULL;
836 
837  GListPtr master_list = NULL;
838  GListPtr started_list = NULL;
839  GListPtr gIter = rsc->children;
840 
841  clone_variant_data_t *clone_data = NULL;
842  int active_instances = 0;
843 
844  get_clone_variant_data(clone_data, rsc);
845 
846  out->begin_list(out, NULL, NULL, "Clone Set: %s [%s]%s%s%s",
847  rsc->id, ID(clone_data->xml_obj_child),
848  is_set(rsc->flags, pe_rsc_promotable) ? " (promotable)" : "",
849  is_set(rsc->flags, pe_rsc_unique) ? " (unique)" : "",
850  is_set(rsc->flags, pe_rsc_managed) ? "" : " (unmanaged)");
851 
852  for (; gIter != NULL; gIter = gIter->next) {
853  gboolean print_full = FALSE;
854  pe_resource_t *child_rsc = (pe_resource_t *) gIter->data;
855  gboolean partially_active = child_rsc->fns->active(child_rsc, FALSE);
856 
857  if (pcmk__rsc_is_filtered(child_rsc, only_show)) {
858  continue;
859  }
860 
861  if (options & pe_print_clone_details) {
862  print_full = TRUE;
863  }
864 
865  if (is_set(rsc->flags, pe_rsc_unique)) {
866  // Print individual instance when unique (except stopped orphans)
867  if (partially_active || is_not_set(rsc->flags, pe_rsc_orphan)) {
868  print_full = TRUE;
869  }
870 
871  // Everything else in this block is for anonymous clones
872 
873  } else if (is_set(options, pe_print_pending)
874  && (child_rsc->pending_task != NULL)
875  && strcmp(child_rsc->pending_task, "probe")) {
876  // Print individual instance when non-probe action is pending
877  print_full = TRUE;
878 
879  } else if (partially_active == FALSE) {
880  // List stopped instances when requested (except orphans)
881  if (is_not_set(child_rsc->flags, pe_rsc_orphan)
882  && is_not_set(options, pe_print_clone_active)) {
883  stopped_list = pcmk__add_word(stopped_list, child_rsc->id);
884  }
885 
886  } else if (is_set_recursive(child_rsc, pe_rsc_orphan, TRUE)
887  || is_set_recursive(child_rsc, pe_rsc_managed, FALSE) == FALSE
888  || is_set_recursive(child_rsc, pe_rsc_failed, TRUE)) {
889 
890  // Print individual instance when active orphaned/unmanaged/failed
891  print_full = TRUE;
892 
893  } else if (child_rsc->fns->active(child_rsc, TRUE)) {
894  // Instance of fully active anonymous clone
895 
896  pe_node_t *location = child_rsc->fns->location(child_rsc, NULL, TRUE);
897 
898  if (location) {
899  // Instance is active on a single node
900 
901  enum rsc_role_e a_role = child_rsc->fns->state(child_rsc, TRUE);
902 
903  if (location->details->online == FALSE && location->details->unclean) {
904  print_full = TRUE;
905 
906  } else if (a_role > RSC_ROLE_SLAVE) {
907  master_list = g_list_append(master_list, location);
908 
909  } else {
910  started_list = g_list_append(started_list, location);
911  }
912 
913  } else {
914  /* uncolocated group - bleh */
915  print_full = TRUE;
916  }
917 
918  } else {
919  // Instance of partially active anonymous clone
920  print_full = TRUE;
921  }
922 
923  if (print_full) {
924  out->message(out, crm_map_element_name(child_rsc->xml), options, child_rsc, only_show);
925  }
926  }
927 
928  if (is_set(options, pe_print_clone_details)) {
929  free(stopped_list);
930  out->end_list(out);
931  return pcmk_rc_ok;
932  }
933 
934  /* Masters */
935  master_list = g_list_sort(master_list, sort_node_uname);
936  for (gIter = master_list; gIter; gIter = gIter->next) {
937  pe_node_t *host = gIter->data;
938 
939  if (!pcmk__str_in_list(only_show, host->details->uname)) {
940  continue;
941  }
942 
943  list_text = pcmk__add_word(list_text, host->details->uname);
944  active_instances++;
945  }
946 
947  if (list_text != NULL) {
948  out->list_item(out, "Masters", "[%s ]", list_text);
949  g_list_free(master_list);
950  free(list_text);
951  list_text = NULL;
952  }
953 
954  /* Started/Slaves */
955  started_list = g_list_sort(started_list, sort_node_uname);
956  for (gIter = started_list; gIter; gIter = gIter->next) {
957  pe_node_t *host = gIter->data;
958 
959  if (!pcmk__str_in_list(only_show, host->details->uname)) {
960  continue;
961  }
962 
963  list_text = pcmk__add_word(list_text, host->details->uname);
964  active_instances++;
965  }
966 
967  if (list_text != NULL) {
968  if (is_set(rsc->flags, pe_rsc_promotable)) {
969  enum rsc_role_e role = configured_role(rsc);
970 
971  if(role == RSC_ROLE_SLAVE) {
972  out->list_item(out, "Slaves (target-role)", "[%s ]", list_text);
973  } else {
974  out->list_item(out, "Slaves", "[%s ]", list_text);
975  }
976  } else {
977  out->list_item(out, "Started", "[%s ]", list_text);
978  }
979 
980  g_list_free(started_list);
981  free(list_text);
982  list_text = NULL;
983  }
984 
985  if (is_not_set(options, pe_print_clone_active)) {
986  const char *state = "Stopped";
987  enum rsc_role_e role = configured_role(rsc);
988 
989  if (role == RSC_ROLE_STOPPED) {
990  state = "Stopped (disabled)";
991  }
992 
993  if (is_not_set(rsc->flags, pe_rsc_unique)
994  && (clone_data->clone_max > active_instances)) {
995 
996  GListPtr nIter;
997  GListPtr list = g_hash_table_get_values(rsc->allowed_nodes);
998 
999  /* Custom stopped list for non-unique clones */
1000  free(stopped_list);
1001  stopped_list = NULL;
1002 
1003  if (list == NULL) {
1004  /* Clusters with symmetrical=false haven't calculated allowed_nodes yet
1005  * If we've not probed for them yet, the Stopped list will be empty
1006  */
1007  list = g_hash_table_get_values(rsc->known_on);
1008  }
1009 
1010  list = g_list_sort(list, sort_node_uname);
1011  for (nIter = list; nIter != NULL; nIter = nIter->next) {
1012  pe_node_t *node = (pe_node_t *)nIter->data;
1013 
1014  if (pe_find_node(rsc->running_on, node->details->uname) == NULL &&
1015  pcmk__str_in_list(only_show, node->details->uname)) {
1016  stopped_list = pcmk__add_word(stopped_list,
1017  node->details->uname);
1018  }
1019  }
1020  g_list_free(list);
1021  }
1022 
1023  if (stopped_list != NULL) {
1024  out->list_item(out, state, "[%s ]", stopped_list);
1025  free(stopped_list);
1026  }
1027  }
1028 
1029  out->end_list(out);
1030 
1031  return pcmk_rc_ok;
1032 }
1033 
1034 void
1036 {
1037  clone_variant_data_t *clone_data = NULL;
1038 
1039  get_clone_variant_data(clone_data, rsc);
1040 
1041  pe_rsc_trace(rsc, "Freeing %s", rsc->id);
1042 
1043  for (GListPtr gIter = rsc->children; gIter != NULL; gIter = gIter->next) {
1044  pe_resource_t *child_rsc = (pe_resource_t *) gIter->data;
1045 
1046  CRM_ASSERT(child_rsc);
1047  pe_rsc_trace(child_rsc, "Freeing child %s", child_rsc->id);
1048  free_xml(child_rsc->xml);
1049  child_rsc->xml = NULL;
1050  /* There could be a saved unexpanded xml */
1051  free_xml(child_rsc->orig_xml);
1052  child_rsc->orig_xml = NULL;
1053  child_rsc->fns->free(child_rsc);
1054  }
1055 
1056  g_list_free(rsc->children);
1057 
1058  if (clone_data) {
1059  CRM_ASSERT(clone_data->demote_notify == NULL);
1060  CRM_ASSERT(clone_data->stop_notify == NULL);
1061  CRM_ASSERT(clone_data->start_notify == NULL);
1062  CRM_ASSERT(clone_data->promote_notify == NULL);
1063  }
1064 
1065  common_free(rsc);
1066 }
1067 
1068 enum rsc_role_e
1069 clone_resource_state(const pe_resource_t * rsc, gboolean current)
1070 {
1071  enum rsc_role_e clone_role = RSC_ROLE_UNKNOWN;
1072  GListPtr gIter = rsc->children;
1073 
1074  for (; gIter != NULL; gIter = gIter->next) {
1075  pe_resource_t *child_rsc = (pe_resource_t *) gIter->data;
1076  enum rsc_role_e a_role = child_rsc->fns->state(child_rsc, current);
1077 
1078  if (a_role > clone_role) {
1079  clone_role = a_role;
1080  }
1081  }
1082 
1083  pe_rsc_trace(rsc, "%s role: %s", rsc->id, role2text(clone_role));
1084  return clone_role;
1085 }
1086 
1094 bool
1096  pe_working_set_t *data_set)
1097 {
1098  if (pe_rsc_is_clone(rsc)) {
1099  clone_variant_data_t *clone_data = NULL;
1100 
1101  get_clone_variant_data(clone_data, rsc);
1102  if (clone_data->clone_max == g_list_length(data_set->nodes)) {
1103  return TRUE;
1104  }
1105  }
1106  return FALSE;
1107 }
#define CRM_CHECK(expr, failure_action)
Definition: logging.h:233
GListPtr nodes
Definition: pe_types.h:146
xmlNode * orig_xml
Definition: pe_types.h:308
bool is_set_recursive(pe_resource_t *rsc, long long flag, bool any)
Definition: clone.c:338
GHashTable * known_on
Definition: pe_types.h:351
gboolean pcmk__str_in_list(GList *lst, const gchar *s)
Definition: strings.c:660
enum rsc_role_e(* state)(const pe_resource_t *, gboolean)
Definition: pe_types.h:52
void pcmk__output_xml_pop_parent(pcmk__output_t *out)
Definition: output_xml.c:397
#define XML_BOOLEAN_FALSE
Definition: msg_xml.h:108
#define pcmk__config_err(fmt...)
Definition: internal.h:95
xmlNode * xml
Definition: pe_types.h:307
#define XML_RSC_ATTR_INCARNATION
Definition: msg_xml.h:186
void pe__force_anon(const char *standard, pe_resource_t *rsc, const char *rid, pe_working_set_t *data_set)
Definition: clone.c:22
GHashTable * meta
Definition: pe_types.h:357
#define pe_rsc_unique
Definition: pe_types.h:241
resource_object_functions_t * fns
Definition: pe_types.h:316
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
Definition: nvpair.c:316
int crm_parse_int(const char *text, const char *default_text)
Parse an integer value from a string.
Definition: strings.c:126
AIS_Host host
Definition: internal.h:84
pe_node_t * pe_find_node(GListPtr node_list, const char *uname)
Definition: status.c:427
#define XML_RSC_ATTR_STICKINESS
Definition: msg_xml.h:199
#define XML_RSC_ATTR_MASTER_NODEMAX
Definition: msg_xml.h:194
#define XML_RSC_ATTR_INCARNATION_MAX
Definition: msg_xml.h:187
char * pending_task
Definition: pe_types.h:330
void clone_free(pe_resource_t *rsc)
Definition: clone.c:1035
int pe__clone_html(pcmk__output_t *out, va_list args)
Definition: clone.c:619
xmlNode * copy_xml(xmlNode *src_node)
Definition: xml.c:2142
const char * role2text(enum rsc_role_e role)
Definition: common.c:463
#define pe_warn(fmt...)
Definition: internal.h:22
enum rsc_role_e clone_resource_state(const pe_resource_t *rsc, gboolean current)
Definition: clone.c:1069
int rc
Definition: pcmk_fence.c:34
#define pe_rsc_failed
Definition: pe_types.h:252
gboolean clone_active(pe_resource_t *rsc, gboolean all)
Definition: clone.c:237
#define XML_ATTR_ID
Definition: msg_xml.h:96
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
Definition: nvpair.c:522
#define XML_CIB_TAG_RESOURCE
Definition: msg_xml.h:174
#define XML_BOOLEAN_TRUE
Definition: msg_xml.h:107
int pe__name_and_nvpairs_xml(pcmk__output_t *out, bool is_list, const char *tag_name, size_t pairs_count,...)
Definition: pe_output.c:413
int pe__clone_xml(pcmk__output_t *out, va_list args)
Definition: clone.c:575
struct pe_node_shared_s * details
Definition: pe_types.h:231
GListPtr running_on
Definition: pe_types.h:350
pe_resource_t * find_clone_instance(pe_resource_t *rsc, const char *sub_id, pe_working_set_t *data_set)
Definition: clone.c:41
void common_free(pe_resource_t *rsc)
Definition: complex.c:776
unsigned long long flags
Definition: pe_types.h:332
const char * uname
Definition: pe_types.h:196
#define pe_rsc_promotable
Definition: pe_types.h:243
#define XML_RSC_ATTR_ORDERED
Definition: msg_xml.h:184
PCMK__OUTPUT_ARGS("cluster-summary","struct pe_working_set_t *","gboolean","gboolean","gboolean","gboolean","gboolean","gboolean")
Definition: pe_output.c:214
void clone_print(pe_resource_t *rsc, const char *pre_text, long options, void *print_data)
Definition: clone.c:369
#define XML_RSC_ATTR_INCARNATION_NODEMAX
Definition: msg_xml.h:189
pe_resource_t * pe__create_clone_child(pe_resource_t *rsc, pe_working_set_t *data_set)
Definition: clone.c:59
#define XML_RSC_ATTR_TARGET_ROLE
Definition: msg_xml.h:196
void free_xml(xmlNode *child)
Definition: xml.c:2136
enum rsc_role_e text2role(const char *role)
Definition: common.c:484
gboolean crm_str_eq(const char *a, const char *b, gboolean use_case)
Definition: strings.c:326
pe_resource_t * pe_find_resource(GListPtr rsc_list, const char *id_rh)
Definition: status.c:375
void(* print)(pe_resource_t *, const char *, long, void *)
Definition: pe_types.h:50
#define XML_RSC_ATTR_UNIQUE
Definition: msg_xml.h:197
#define XML_RSC_ATTR_MASTER_MAX
Definition: msg_xml.h:193
#define XML_RSC_ATTR_PROMOTED_MAX
Definition: msg_xml.h:191
Cluster status and scheduling.
int pe__clone_text(pcmk__output_t *out, va_list args)
Definition: clone.c:828
GListPtr children
Definition: pe_types.h:361
void add_hash_param(GHashTable *hash, const char *name, const char *value)
Definition: common.c:573
void * variant_opaque
Definition: pe_types.h:315
bool pcmk__rsc_is_filtered(pe_resource_t *rsc, GListPtr only_show)
Definition: utils.c:2766
#define CRM_ASSERT(expr)
Definition: results.h:42
gboolean clone_unpack(pe_resource_t *rsc, pe_working_set_t *data_set)
Definition: clone.c:111
#define status_print(fmt, args...)
This structure contains everything that makes up a single output formatter.
Definition: output.h:153
char * pcmk__add_word(char *list, const char *word)
Definition: strings.c:517
void(* free)(pe_resource_t *)
Definition: pe_types.h:54
rsc_role_e
Definition: common.h:76
#define XML_RSC_ATTR_PROMOTED_NODEMAX
Definition: msg_xml.h:192
#define BOOL2STR(x)
Definition: internal.h:455
bool pe__is_universal_clone(pe_resource_t *rsc, pe_working_set_t *data_set)
Definition: clone.c:1095
#define pe_rsc_failure_ignored
Definition: pe_types.h:260
pe_node_t *(* location)(const pe_resource_t *, GList **, int)
Definition: pe_types.h:53
gboolean common_unpack(xmlNode *xml_obj, pe_resource_t **rsc, pe_resource_t *parent, pe_working_set_t *data_set)
Definition: complex.c:366
gboolean crm_is_true(const char *s)
Definition: strings.c:278
#define XML_CIB_TAG_GROUP
Definition: msg_xml.h:175
void set_bit_recursive(pe_resource_t *rsc, unsigned long long flag)
Definition: utils.c:2298
#define pe_rsc_trace(rsc, fmt, args...)
Definition: internal.h:19
gboolean(* active)(pe_resource_t *, gboolean)
Definition: pe_types.h:51
#define ID(x)
Definition: msg_xml.h:418
#define pe_err(fmt...)
Definition: internal.h:21
gint sort_node_uname(gconstpointer a, gconstpointer b)
Definition: utils.c:215
gboolean unclean
Definition: pe_types.h:204
char * crm_strdup_printf(char const *format,...) __attribute__((__format__(__printf__
GList * GListPtr
Definition: crm.h:214
#define pe_rsc_managed
Definition: pe_types.h:236
#define pe_rsc_orphan
Definition: pe_types.h:235
gboolean online
Definition: pe_types.h:200
enum crm_ais_msg_types type
Definition: internal.h:83
char * id
Definition: pe_types.h:305
GHashTable * allowed_nodes
Definition: pe_types.h:352