MCPcopy Create free account
hub / github.com/ClusterLabs/pacemaker / colocation_match

Function colocation_match

pengine/native.c:1374–1439  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1372}
1373
1374static void
1375colocation_match(resource_t * rsc_lh, resource_t * rsc_rh, rsc_colocation_t * constraint)
1376{
1377 const char *tmp = NULL;
1378 const char *value = NULL;
1379 const char *attribute = "#id";
1380
1381 GHashTable *work = NULL;
1382 gboolean do_check = FALSE;
1383
1384 GHashTableIter iter;
1385 node_t *node = NULL;
1386
1387 if (constraint->node_attribute != NULL) {
1388 attribute = constraint->node_attribute;
1389 }
1390
1391 if (rsc_rh->allocated_to) {
1392 value = g_hash_table_lookup(rsc_rh->allocated_to->details->attrs, attribute);
1393 do_check = TRUE;
1394
1395 } else if (constraint->score < 0) {
1396 /* nothing to do:
1397 * anti-colocation with something thats not running
1398 */
1399 return;
1400 }
1401
1402 work = node_hash_dup(rsc_lh->allowed_nodes);
1403
1404 g_hash_table_iter_init(&iter, work);
1405 while (g_hash_table_iter_next(&iter, NULL, (void **)&node)) {
1406 tmp = g_hash_table_lookup(node->details->attrs, attribute);
1407 if (do_check && safe_str_eq(tmp, value)) {
1408 if (constraint->score < INFINITY) {
1409 pe_rsc_trace(rsc_lh, "%s: %s.%s += %d", constraint->id, rsc_lh->id,
1410 node->details->uname, constraint->score);
1411 node->weight = merge_weights(constraint->score, node->weight);
1412 }
1413
1414 } else if (do_check == FALSE || constraint->score >= INFINITY) {
1415 pe_rsc_trace(rsc_lh, "%s: %s.%s -= %d (%s)", constraint->id, rsc_lh->id,
1416 node->details->uname, constraint->score,
1417 do_check ? "failed" : "unallocated");
1418 node->weight = merge_weights(-constraint->score, node->weight);
1419 }
1420 }
1421
1422 if (can_run_any(work)
1423 || constraint->score <= -INFINITY || constraint->score >= INFINITY) {
1424 g_hash_table_destroy(rsc_lh->allowed_nodes);
1425 rsc_lh->allowed_nodes = work;
1426 work = NULL;
1427
1428 } else {
1429 char *score = score2char(constraint->score);
1430
1431 pe_rsc_info(rsc_lh, "%s: Rolling back scores from %s (%d, %s)",

Callers 1

native_rsc_colocation_rhFunction · 0.85

Calls 6

node_hash_dupFunction · 0.85
g_hash_table_iter_initFunction · 0.85
g_hash_table_iter_nextFunction · 0.85
merge_weightsFunction · 0.85
can_run_anyFunction · 0.85
score2charFunction · 0.85

Tested by

no test coverage detected