19 #define VARIANT_CLONE 1
26 if (pe_rsc_is_clone(rsc)) {
27 clone_variant_data_t *clone_data = NULL;
29 get_clone_variant_data(clone_data, rsc);
32 "such as %s can be used only as anonymous clones",
33 rsc->
id, standard, rid);
35 clone_data->clone_node_max = 1;
36 clone_data->clone_max = QB_MIN(clone_data->clone_max,
37 g_list_length(data_set->
nodes));
44 char *child_id = NULL;
46 const char *child_base = NULL;
47 clone_variant_data_t *clone_data = NULL;
49 get_clone_variant_data(clone_data, rsc);
51 child_base =
ID(clone_data->xml_obj_child);
52 child_id = crm_concat(child_base, sub_id,
':');
62 gboolean as_orphan = FALSE;
66 xmlNode *child_copy = NULL;
67 clone_variant_data_t *clone_data = NULL;
69 get_clone_variant_data(clone_data, rsc);
71 CRM_CHECK(clone_data->xml_obj_child != NULL,
return FALSE);
73 if (clone_data->total_clones >= clone_data->clone_max) {
79 inc_num = crm_itoa(clone_data->total_clones);
80 inc_max = crm_itoa(clone_data->clone_max);
82 child_copy =
copy_xml(clone_data->xml_obj_child);
86 if (
common_unpack(child_copy, &child_rsc, rsc, data_set) == FALSE) {
94 clone_data->total_clones += 1;
95 pe_rsc_trace(child_rsc,
"Setting clone attributes for: %s", child_rsc->
id);
115 xmlNode *a_child = NULL;
116 xmlNode *xml_obj = rsc->
xml;
117 clone_variant_data_t *clone_data = NULL;
125 clone_data = calloc(1,
sizeof(clone_variant_data_t));
129 const char *promoted_max = NULL;
130 const char *promoted_node_max = NULL;
132 promoted_max = g_hash_table_lookup(rsc->
meta,
134 if (promoted_max == NULL) {
136 promoted_max = g_hash_table_lookup(rsc->
meta,
140 promoted_node_max = g_hash_table_lookup(rsc->
meta,
142 if (promoted_node_max == NULL) {
144 promoted_node_max = g_hash_table_lookup(rsc->
meta,
149 clone_data->promoted_node_max =
crm_parse_int(promoted_node_max,
"1");
155 clone_data->clone_node_max =
crm_parse_int(max_clones_node,
"1");
160 }
else if (g_list_length(data_set->
nodes) > 0) {
161 clone_data->clone_max = g_list_length(data_set->
nodes);
164 clone_data->clone_max = 1;
170 crm_config_err(
"Anonymous clones (%s) may only support one copy per node", rsc->
id);
171 clone_data->clone_node_max = 1;
175 pe_rsc_trace(rsc,
"\tClone max: %d", clone_data->clone_max);
176 pe_rsc_trace(rsc,
"\tClone node max: %d", clone_data->clone_node_max);
183 for (a_child = __xml_first_child_element(xml_obj); a_child != NULL;
184 a_child = __xml_next_element(a_child)) {
188 clone_data->xml_obj_child = a_child;
193 if (clone_data->xml_obj_child == NULL) {
214 if (clone_data->clone_max <= 0) {
224 for (lpc = 0; lpc < clone_data->clone_max; lpc++) {
231 pe_rsc_trace(rsc,
"Added %d children to resource %s...", clone_data->clone_max, rsc->
id);
240 for (; gIter != NULL; gIter = gIter->next) {
242 gboolean child_active = child_rsc->
fns->
active(child_rsc, all);
244 if (all == FALSE && child_active) {
246 }
else if (all && child_active == FALSE) {
259 short_print(
char *list,
const char *prefix,
const char *
type,
const char *suffix,
long options,
void *print_data)
286 const char *target_role = g_hash_table_lookup(rsc->
meta,
299 const char *target_role = configured_role_str(rsc);
308 clone_print_xml(
resource_t * rsc,
const char *pre_text,
long options,
void *print_data)
310 char *child_text = crm_concat(pre_text,
" ",
' ');
311 const char *target_role = configured_role_str(rsc);
327 for (; gIter != NULL; gIter = gIter->next) {
330 child_rsc->
fns->
print(child_rsc, child_text, options, print_data);
342 if(is_set(rsc->
flags, flag)) {
350 for (gIter = rsc->
children; gIter != NULL; gIter = gIter->next) {
370 char *list_text = NULL;
371 char *child_text = NULL;
372 char *stopped_list = NULL;
378 clone_variant_data_t *clone_data = NULL;
379 int active_instances = 0;
381 if (pre_text == NULL) {
386 clone_print_xml(rsc, pre_text, options, print_data);
390 get_clone_variant_data(clone_data, rsc);
392 child_text = crm_concat(pre_text,
" ",
' ');
395 pre_text ? pre_text :
"", rsc->
id,
ID(clone_data->xml_obj_child),
407 for (; gIter != NULL; gIter = gIter->next) {
408 gboolean print_full = FALSE;
410 gboolean partially_active = child_rsc->
fns->
active(child_rsc, FALSE);
430 }
else if (partially_active == FALSE) {
444 }
else if (child_rsc->
fns->
active(child_rsc, TRUE)) {
458 master_list = g_list_append(master_list, location);
461 started_list = g_list_append(started_list, location);
478 child_rsc->
fns->
print(child_rsc, child_text, options, print_data);
487 for (gIter = master_list; gIter; gIter = gIter->next) {
494 short_print(list_text, child_text,
"Masters", NULL, options, print_data);
495 g_list_free(master_list);
501 for (gIter = started_list; gIter; gIter = gIter->next) {
512 short_print(list_text, child_text,
"Slaves (target-role)", NULL, options, print_data);
514 short_print(list_text, child_text,
"Slaves", NULL, options, print_data);
518 short_print(list_text, child_text,
"Started", NULL, options, print_data);
521 g_list_free(started_list);
526 const char *state =
"Stopped";
530 state =
"Stopped (disabled)";
534 && (clone_data->clone_max > active_instances)) {
540 free(stopped_list); stopped_list = NULL;
542 if (g_list_length(list) == 0) {
546 list = g_hash_table_get_values(rsc->
known_on);
550 for (nIter = list; nIter != NULL; nIter = nIter->next) {
560 short_print(stopped_list, child_text, state, NULL, options, print_data);
574 unsigned int options = va_arg(args,
unsigned int);
586 ,
"target_role", configured_role_str(rsc));
589 for (; gIter != NULL; gIter = gIter->next) {
592 out->
message(out, crm_map_element_name(child_rsc->
xml), options, child_rsc);
602 unsigned int options = va_arg(args,
unsigned int);
605 char *list_text = NULL;
606 char *stopped_list = NULL;
612 clone_variant_data_t *clone_data = NULL;
613 int active_instances = 0;
615 get_clone_variant_data(clone_data, rsc);
617 out->
begin_list(out, NULL, NULL,
"Clone Set: %s [%s]%s%s%s",
618 rsc->
id,
ID(clone_data->xml_obj_child),
623 for (; gIter != NULL; gIter = gIter->next) {
624 gboolean print_full = FALSE;
626 gboolean partially_active = child_rsc->
fns->
active(child_rsc, FALSE);
646 }
else if (partially_active == FALSE) {
660 }
else if (child_rsc->
fns->
active(child_rsc, TRUE)) {
674 master_list = g_list_append(master_list, location);
677 started_list = g_list_append(started_list, location);
691 out->
message(out, crm_map_element_name(child_rsc->
xml), options, child_rsc);
697 for (gIter = master_list; gIter; gIter = gIter->next) {
704 if (list_text != NULL) {
705 out->
list_item(out, NULL,
" Masters: [%s ]", list_text);
706 g_list_free(master_list);
713 for (gIter = started_list; gIter; gIter = gIter->next) {
720 if (list_text != NULL) {
725 out->
list_item(out, NULL,
" Slaves (target-role): [%s ]", list_text);
727 out->
list_item(out, NULL,
" Slaves: [%s ]", list_text);
731 out->
list_item(out, NULL,
" Started: [%s ]", list_text);
734 g_list_free(started_list);
740 const char *state =
"Stopped";
744 state =
"Stopped (disabled)";
748 && (clone_data->clone_max > active_instances)) {
757 if (g_list_length(list) == 0) {
761 list = g_hash_table_get_values(rsc->
known_on);
765 for (nIter = list; nIter != NULL; nIter = nIter->next) {
775 if (stopped_list != NULL) {
776 out->
list_item(out, NULL,
" %s: [%s ]", state, stopped_list);
789 unsigned int options = va_arg(args,
unsigned int);
792 char *list_text = NULL;
793 char *stopped_list = NULL;
799 clone_variant_data_t *clone_data = NULL;
800 int active_instances = 0;
802 get_clone_variant_data(clone_data, rsc);
804 out->
begin_list(out, NULL, NULL,
"Clone Set: %s [%s]%s%s%s",
805 rsc->
id,
ID(clone_data->xml_obj_child),
810 for (; gIter != NULL; gIter = gIter->next) {
811 gboolean print_full = FALSE;
813 gboolean partially_active = child_rsc->
fns->
active(child_rsc, FALSE);
833 }
else if (partially_active == FALSE) {
847 }
else if (child_rsc->
fns->
active(child_rsc, TRUE)) {
861 master_list = g_list_append(master_list, location);
864 started_list = g_list_append(started_list, location);
878 out->
message(out, crm_map_element_name(child_rsc->
xml), options, child_rsc);
884 for (gIter = master_list; gIter; gIter = gIter->next) {
891 if (list_text != NULL) {
892 out->
list_item(out,
"Masters",
"[%s ]", list_text);
893 g_list_free(master_list);
900 for (gIter = started_list; gIter; gIter = gIter->next) {
907 if (list_text != NULL) {
912 out->
list_item(out,
"Slaves (target-role)",
"[%s ]", list_text);
914 out->
list_item(out,
"Slaves",
"[%s ]", list_text);
917 out->
list_item(out,
"Started",
"[%s ]", list_text);
920 g_list_free(started_list);
926 const char *state =
"Stopped";
930 state =
"Stopped (disabled)";
934 && (clone_data->clone_max > active_instances)) {
943 if (g_list_length(list) == 0) {
947 list = g_hash_table_get_values(rsc->
known_on);
951 for (nIter = list; nIter != NULL; nIter = nIter->next) {
961 if (stopped_list != NULL) {
962 out->
list_item(out, state,
"[%s ]", stopped_list);
974 clone_variant_data_t *clone_data = NULL;
976 get_clone_variant_data(clone_data, rsc);
986 child_rsc->
xml = NULL;
990 child_rsc->
fns->
free(child_rsc);
996 CRM_ASSERT(clone_data->demote_notify == NULL);
999 CRM_ASSERT(clone_data->promote_notify == NULL);
1011 for (; gIter != NULL; gIter = gIter->next) {
1015 if (a_role > clone_role) {
1016 clone_role = a_role;
1035 if (pe_rsc_is_clone(rsc)) {
1036 clone_variant_data_t *clone_data = NULL;
1038 get_clone_variant_data(clone_data, rsc);
1039 if (clone_data->clone_max == g_list_length(data_set->
nodes)) {