15 #define VARIANT_CLONE 1
22 sort_rsc_id(gconstpointer a, gconstpointer b)
35 num1 = strtol(strrchr(resource1->
id,
':') + 1, NULL, 10);
36 num2 = strtol(strrchr(resource2->
id,
':') + 1, NULL, 10);
39 }
else if (num1 > num2) {
50 if (node != NULL && rsc->
parent) {
52 }
else if(node != NULL) {
67 for (; gIter != NULL; gIter = gIter->next) {
70 if (did_fail(child_rsc)) {
85 unsigned int nnodes1 = 0;
86 unsigned int nnodes2 = 0;
108 if (nnodes1 && nnodes2) {
109 if (nnodes1 < nnodes2) {
110 crm_trace(
"%s < %s: running_on", resource1->
id, resource2->
id);
113 }
else if (nnodes1 > nnodes2) {
114 crm_trace(
"%s > %s: running_on", resource1->
id, resource2->
id);
119 node1 = current_node1;
120 node2 = current_node2;
124 if (match == NULL || match->
weight < 0) {
125 crm_trace(
"%s: current location is unavailable", resource1->
id);
134 if (match == NULL || match->
weight < 0) {
135 crm_trace(
"%s: current location is unavailable", resource2->
id);
143 crm_trace(
"%s < %s: availability of current location", resource1->
id, resource2->
id);
146 crm_trace(
"%s > %s: availability of current location", resource1->
id, resource2->
id);
151 crm_trace(
"%s < %s: priority", resource1->
id, resource2->
id);
155 crm_trace(
"%s > %s: priority", resource1->
id, resource2->
id);
159 if (node1 == NULL && node2 == NULL) {
160 crm_trace(
"%s == %s: not active", resource1->
id, resource2->
id);
164 if (node1 != node2) {
168 }
else if (node2 == NULL) {
185 node1 = parent_node_instance(resource1, node1);
186 node2 = parent_node_instance(resource2, node2);
187 if (node1 != NULL && node2 == NULL) {
188 crm_trace(
"%s < %s: not allowed", resource1->
id, resource2->
id);
190 }
else if (node1 == NULL && node2 != NULL) {
191 crm_trace(
"%s > %s: not allowed", resource1->
id, resource2->
id);
195 if (node1 == NULL || node2 == NULL) {
196 crm_trace(
"%s == %s: not allowed", resource1->
id, resource2->
id);
209 can1 = did_fail(resource1);
210 can2 = did_fail(resource2);
220 if (node1 && node2) {
228 g_hash_table_new_full(
crm_str_hash, g_str_equal, NULL, free);
230 g_hash_table_new_full(
crm_str_hash, g_str_equal, NULL, free);
233 g_hash_table_insert(hash1, (gpointer) n->
details->
id, n);
236 g_hash_table_insert(hash2, (gpointer) n->
details->
id, n);
239 for (gIter = resource1->
parent->
rsc_cons; gIter; gIter = gIter->next) {
242 if (constraint->
score == 0) {
245 crm_trace(
"Applying %s to %s", constraint->
id, resource1->
id);
248 resource1->
id, hash1,
257 if (constraint->
score == 0) {
260 crm_trace(
"Applying %s to %s", constraint->
id, resource1->
id);
263 resource1->
id, hash1,
271 for (gIter = resource2->
parent->
rsc_cons; gIter; gIter = gIter->next) {
274 crm_trace(
"Applying %s to %s", constraint->
id, resource2->
id);
277 resource2->
id, hash2,
286 crm_trace(
"Applying %s to %s", constraint->
id, resource2->
id);
289 resource2->
id, hash2,
297 node1 = g_hash_table_lookup(hash1, current_node1->
details->
id);
298 node2 = g_hash_table_lookup(hash2, current_node2->
details->
id);
319 list1 = g_hash_table_get_values(hash1);
320 list2 = g_hash_table_get_values(hash2);
324 max = g_list_length(list1);
325 if (max < g_list_length(list2)) {
326 max = g_list_length(list2);
329 for (; lpc < max; lpc++) {
330 node1 = g_list_nth_data(list1, lpc);
331 node2 = g_list_nth_data(list2, lpc);
333 crm_trace(
"%s < %s: colocated score NULL", resource1->
id, resource2->
id);
337 }
else if (node2 == NULL) {
338 crm_trace(
"%s > %s: colocated score NULL", resource1->
id, resource2->
id);
344 crm_trace(
"%s < %s: colocated score", resource1->
id, resource2->
id);
349 crm_trace(
"%s > %s: colocated score", resource1->
id, resource2->
id);
357 g_hash_table_destroy(hash1);
358 g_hash_table_destroy(hash2);
367 rc = strcmp(resource1->
id, resource2->
id);
368 crm_trace(
"%s %c %s: default", resource1->
id,
rc < 0 ?
'<' :
'>', resource2->
id);
380 while (g_hash_table_iter_next(&iter, NULL, (
void **)&local_node)) {
381 can_run_instance(rsc, local_node, limit);
397 local_node = parent_node_instance(rsc, node);
399 if (local_node == NULL) {
403 }
else if (local_node->
weight < 0) {
405 pe_rsc_trace(rsc,
"%s cannot run on %s: Parent node weight doesn't allow it.",
408 }
else if (local_node->
count < limit) {
409 pe_rsc_trace(rsc,
"%s can run on %s (already running %d)",
414 pe_rsc_trace(rsc,
"%s cannot run on %s: node full (%d >= %d)",
430 GHashTable *backup = NULL;
433 pe_rsc_trace(rsc,
"Checking allocation of %s (preferring %s, using %s parent colocations)",
435 (all_coloc?
"all" :
"some"));
441 pe_rsc_debug(rsc,
"Dependency loop detected involving %s", rsc->
id);
448 append_parent_colocation(rsc->
parent, rsc, all_coloc);
453 if (local_prefer == NULL || local_prefer->
weight < 0) {
454 pe_rsc_trace(rsc,
"Not pre-allocating %s to %s - unavailable", rsc->
id,
460 can_run_instance(rsc, NULL, limit);
466 crm_info(
"Not pre-allocating %s to %s because %s is better",
475 pe_node_t *local_node = parent_node_instance(rsc, chosen);
489 g_hash_table_destroy(backup);
501 for (; gIter != NULL; gIter = gIter->next) {
504 if (cons->
score == 0) {
513 for (; gIter != NULL; gIter = gIter->next) {
516 if (cons->
score == 0) {
519 if (all || cons->
score < 0) {
536 int available_nodes = 0;
539 for(
GListPtr nIter = nodes; nIter != NULL; nIter = nIter->next) {
548 if(available_nodes) {
549 loop_max = max / available_nodes;
555 pe_rsc_debug(rsc,
"Allocating up to %d %s instances to a possible %d nodes (at most %d per host, %d optimal)",
556 max, rsc->
id, available_nodes, per_host_max, loop_max);
559 for (
GListPtr gIter = children; gIter != NULL && allocated < max; gIter = gIter->next) {
564 pe_node_t *child_node = pe__current_node(child);
565 pe_node_t *local_node = parent_node_instance(child, child_node);
567 pe_rsc_trace(rsc,
"Checking pre-allocation of %s to %s (%d remaining of %d)",
571 pe_rsc_trace(rsc,
"Not pre-allocating because %s can not run %s",
574 }
else if(local_node && local_node->
count >= loop_max) {
576 "Not pre-allocating because %s already allocated optimal instances",
579 }
else if (allocate_instance(child, child_node,
580 max < available_nodes, per_host_max,
589 pe_rsc_trace(rsc,
"Done pre-allocating (%d of %d)", allocated, max);
591 for (
GListPtr gIter = children; gIter != NULL; gIter = gIter->next) {
595 pe_node_t *child_node = pe__current_node(child);
596 pe_node_t *local_node = parent_node_instance(child, child_node);
598 if (local_node == NULL) {
599 crm_err(
"%s is running on %s which isn't allowed",
605 }
else if (allocated >= max) {
606 pe_rsc_debug(rsc,
"Child %s not allocated - limit reached %d %d", child->
id, allocated, max);
609 if (allocate_instance(child, NULL, max < available_nodes,
610 per_host_max, data_set)) {
616 pe_rsc_debug(rsc,
"Allocated %d %s instances of a possible %d",
617 allocated, rsc->
id, max);
626 clone_variant_data_t *clone_data = NULL;
628 get_clone_variant_data(clone_data, rsc);
634 pe_rsc_debug(rsc,
"Dependency loop detected involving %s", rsc->
id);
650 if (constraint->
score == 0) {
661 if (constraint->
score == 0) {
690 clone_update_pseudo_status(
pe_resource_t * rsc, gboolean * stopping, gboolean * starting,
698 for (; gIter != NULL; gIter = gIter->next) {
701 clone_update_pseudo_status(child, stopping, starting, active);
716 for (; gIter != NULL; gIter = gIter->next) {
719 if (*starting && *stopping) {
737 pe_rsc_trace(rsc,
"Skipping pseudo-op: %s run=%d, pseudo=%d",
752 find_rsc_action(
pe_resource_t *rsc,
const char *task, gboolean active_only,
764 for (; gIter != NULL; gIter = gIter->next) {
768 active = g_list_prepend(active, op);
772 if (active && pcmk__list_of_1(active)) {
773 match = g_list_nth_data(active, 0);
781 }
else if (possible && pcmk__list_of_1(possible)) {
782 match = g_list_nth_data(possible, 0);
791 g_list_free(possible);
808 gboolean active_only = TRUE;
809 clone_variant_data_t *clone_data = NULL;
811 get_clone_variant_data(clone_data, rsc);
813 if (clone_data->ordered == FALSE) {
819 for (gIter = rsc->
children; gIter != NULL; gIter = gIter->next) {
822 stop = find_rsc_action(child,
RSC_STOP, active_only, NULL);
831 start = find_rsc_action(child,
RSC_START, active_only, NULL);
845 clone_variant_data_t *clone_data = NULL;
847 get_clone_variant_data(clone_data, rsc);
849 child_ordering_constraints(rsc, data_set);
859 gboolean child_active = FALSE;
860 gboolean child_starting = FALSE;
861 gboolean child_stopping = FALSE;
862 gboolean allow_dependent_migrations = TRUE;
872 for (
GListPtr gIter = children; gIter != NULL; gIter = gIter->next) {
874 gboolean starting = FALSE;
875 gboolean stopping = FALSE;
878 clone_update_pseudo_status(child_rsc, &stopping, &starting, &child_active);
879 if (stopping && starting) {
880 allow_dependent_migrations = FALSE;
883 child_stopping |= stopping;
884 child_starting |= starting;
892 if (child_active || child_starting) {
896 if (start_notify != NULL && *start_notify == NULL) {
904 if (allow_dependent_migrations) {
908 if (stop_notify != NULL && *stop_notify == NULL) {
911 if (start_notify && *start_notify && *stop_notify) {
922 clone_variant_data_t *clone_data = NULL;
924 get_clone_variant_data(clone_data, rsc);
936 if (clone_data->ordered) {
940 for (gIter = rsc->
children; gIter != NULL; gIter = gIter->next) {
948 if (clone_data->ordered && last_rsc) {
955 if (clone_data->ordered && last_rsc) {
959 last_rsc = child_rsc;
969 bool changed = FALSE;
996 CRM_CHECK(child_rsc && local_node,
return FALSE);
999 node = child_rsc->
fns->
location(child_rsc, NULL, current);
1015 crm_trace(
"%s - not allocated %d", child_rsc->
id, current);
1030 local_node = local_child->
fns->
location(local_child, NULL, current);
1035 scratch = g_hash_table_get_values(local_child->
allowed_nodes);
1039 for (; gIter != NULL; gIter = gIter->next) {
1050 g_list_free(scratch);
1072 gboolean do_interleave = FALSE;
1073 const char *interleave_s = NULL;
1076 CRM_CHECK(rsc_lh != NULL,
pe_err(
"rsc_lh was NULL for %s", constraint->
id);
return);
1077 CRM_CHECK(rsc_rh != NULL,
pe_err(
"rsc_rh was NULL for %s", constraint->
id);
return);
1080 if (constraint->
score == 0) {
1083 pe_rsc_trace(rsc_rh,
"Processing constraint %s: %s -> %s %d",
1084 constraint->
id, rsc_lh->
id, rsc_rh->
id, constraint->
score);
1091 pe_rsc_trace(rsc_rh,
"Handling %s as a clone colocation", constraint->
id);
1104 "support the same number of instances per node",
1108 do_interleave = TRUE;
1116 }
else if (do_interleave) {
1128 crm_notice(
"Cannot pair %s with instance of %s", rsc_lh->
id, rsc_rh->
id);
1132 pe_rsc_debug(rsc_rh,
"Cannot pair %s with instance of %s", rsc_lh->
id, rsc_rh->
id);
1141 for (; gIter != NULL; gIter = gIter->next) {
1147 rhs = g_list_prepend(rhs, chosen);
1157 for (; gIter != NULL; gIter = gIter->next) {
1177 char *key =
action->uuid;
1178 int lpc = strlen(key);
1180 for (; lpc > 0; lpc--) {
1181 if (key[lpc] ==
'_' && stop == 0) {
1184 }
else if (key[lpc] ==
'_') {
1185 char *task_mutable = NULL;
1188 task_mutable = strdup(key + lpc);
1189 task_mutable[stop - lpc] = 0;
1191 crm_trace(
"Extracted action '%s' from '%s'", task_mutable, key);
1208 gboolean any_runnable = FALSE;
1209 gboolean check_runnable = TRUE;
1214 for (gIter = children; gIter != NULL; gIter = gIter->next) {
1220 node ? node->details->uname :
"none", child_action?child_action->
uuid:
"NA");
1227 child_action->
uuid);
1232 any_runnable = TRUE;
1237 if (check_runnable && any_runnable == FALSE) {
1259 pe_rsc_trace(rsc,
"Processing location constraint %s for %s", constraint->
id, rsc->
id);
1263 for (; gIter != NULL; gIter = gIter->next) {
1274 clone_variant_data_t *clone_data = NULL;
1276 get_clone_variant_data(clone_data, rsc);
1279 for (; gIter != NULL; gIter = gIter->next) {
1285 if (clone_data->start_notify) {
1291 if (clone_data->stop_notify) {
1297 if (clone_data->promote_notify) {
1303 if (clone_data->demote_notify) {
1312 for (; gIter != NULL; gIter = gIter->next) {
1315 child_rsc->
cmds->
expand(child_rsc, data_set);
1322 clone_data->demote_notify = NULL;
1324 clone_data->stop_notify = NULL;
1326 clone_data->start_notify = NULL;
1328 clone_data->promote_notify = NULL;
1336 for (GList *child_iter = rsc->
children; child_iter != NULL;
1337 child_iter = child_iter->next) {
1341 if (rsc_known_on(child, node)) {
1347 GHashTableIter iter;
1350 g_hash_table_iter_init(&iter, rsc->
known_on);
1351 while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &known_node)) {
1352 if (node->
details == known_node->details) {
1364 for (GList *gIter = clone->
children; gIter != NULL; gIter = gIter->next) {
1367 if (rsc_known_on(child, node)) {
1379 gboolean any_created = FALSE;
1381 for (GList *child_iter = rsc->
children; child_iter != NULL;
1382 child_iter = child_iter->next) {
1402 if (child == NULL) {
1403 for (GList *child_iter = rsc->
children; child_iter && !child;
1404 child_iter = child_iter->next) {
1410 local_node = child_rsc->
fns->
location(child_rsc, NULL, FALSE);
1419 if (child == NULL) {
1430 gboolean any_created = FALSE;
1436 pe_warn(
"Clone %s has no children", rsc->
id);
1458 any_created = probe_unique_clone(rsc, node, complete, force, data_set);
1460 any_created = probe_anonymous_clone(rsc, node, complete, force,
1470 clone_variant_data_t *clone_data = NULL;
1472 get_clone_variant_data(clone_data, rsc);