dhodovsk / source-git / pacemaker

Forked from source-git/pacemaker 3 years ago
Clone

Blame lib/pacemaker/pcmk_sched_promotable.c

rpm-build 3ee90c
/*
rpm-build 3ee90c
 * Copyright 2004-2018 Andrew Beekhof <andrew@beekhof.net>
rpm-build 3ee90c
 *
rpm-build 3ee90c
 * This source code is licensed under the GNU General Public License version 2
rpm-build 3ee90c
 * or later (GPLv2+) WITHOUT ANY WARRANTY.
rpm-build 3ee90c
 */
rpm-build 3ee90c
rpm-build 3ee90c
#include <crm_internal.h>
rpm-build 3ee90c
rpm-build 3ee90c
#include <crm/msg_xml.h>
rpm-build 3ee90c
#include <pacemaker-internal.h>
rpm-build 3ee90c
rpm-build 3ee90c
#define VARIANT_CLONE 1
rpm-build 3ee90c
#include <lib/pengine/variant.h>
rpm-build 3ee90c
rpm-build 3ee90c
extern gint sort_clone_instance(gconstpointer a, gconstpointer b, gpointer data_set);
rpm-build 3ee90c
rpm-build 3ee90c
static void
rpm-build 3ee90c
child_promoting_constraints(clone_variant_data_t * clone_data, enum pe_ordering type,
rpm-build 3ee90c
                            resource_t * rsc, resource_t * child, resource_t * last,
rpm-build 3ee90c
                            pe_working_set_t * data_set)
rpm-build 3ee90c
{
rpm-build 3ee90c
    if (child == NULL) {
rpm-build 3ee90c
        if (clone_data->ordered && last != NULL) {
rpm-build 3ee90c
            pe_rsc_trace(rsc, "Ordered version (last node)");
rpm-build 3ee90c
            /* last child promote before promoted started */
rpm-build 3ee90c
            new_rsc_order(last, RSC_PROMOTE, rsc, RSC_PROMOTED, type, data_set);
rpm-build 3ee90c
        }
rpm-build 3ee90c
        return;
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    /* child promote before global promoted */
rpm-build 3ee90c
    new_rsc_order(child, RSC_PROMOTE, rsc, RSC_PROMOTED, type, data_set);
rpm-build 3ee90c
rpm-build 3ee90c
    /* global promote before child promote */
rpm-build 3ee90c
    new_rsc_order(rsc, RSC_PROMOTE, child, RSC_PROMOTE, type, data_set);
rpm-build 3ee90c
rpm-build 3ee90c
    if (clone_data->ordered) {
rpm-build 3ee90c
        pe_rsc_trace(rsc, "Ordered version");
rpm-build 3ee90c
        if (last == NULL) {
rpm-build 3ee90c
            /* global promote before first child promote */
rpm-build 3ee90c
            last = rsc;
rpm-build 3ee90c
rpm-build 3ee90c
        }
rpm-build 3ee90c
        /* else: child/child relative promote */
rpm-build 3ee90c
        order_start_start(last, child, type);
rpm-build 3ee90c
        new_rsc_order(last, RSC_PROMOTE, child, RSC_PROMOTE, type, data_set);
rpm-build 3ee90c
rpm-build 3ee90c
    } else {
rpm-build 3ee90c
        pe_rsc_trace(rsc, "Un-ordered version");
rpm-build 3ee90c
    }
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
static void
rpm-build 3ee90c
child_demoting_constraints(clone_variant_data_t * clone_data, enum pe_ordering type,
rpm-build 3ee90c
                           resource_t * rsc, resource_t * child, resource_t * last,
rpm-build 3ee90c
                           pe_working_set_t * data_set)
rpm-build 3ee90c
{
rpm-build 3ee90c
    if (child == NULL) {
rpm-build 3ee90c
        if (clone_data->ordered && last != NULL) {
rpm-build 3ee90c
            pe_rsc_trace(rsc, "Ordered version (last node)");
rpm-build 3ee90c
            /* global demote before first child demote */
rpm-build 3ee90c
            new_rsc_order(rsc, RSC_DEMOTE, last, RSC_DEMOTE, pe_order_optional, data_set);
rpm-build 3ee90c
        }
rpm-build 3ee90c
        return;
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    /* child demote before global demoted */
rpm-build 3ee90c
    new_rsc_order(child, RSC_DEMOTE, rsc, RSC_DEMOTED, pe_order_implies_then_printed, data_set);
rpm-build 3ee90c
rpm-build 3ee90c
    /* global demote before child demote */
rpm-build 3ee90c
    new_rsc_order(rsc, RSC_DEMOTE, child, RSC_DEMOTE, pe_order_implies_first_printed, data_set);
rpm-build 3ee90c
rpm-build 3ee90c
    if (clone_data->ordered && last != NULL) {
rpm-build 3ee90c
        pe_rsc_trace(rsc, "Ordered version");
rpm-build 3ee90c
rpm-build 3ee90c
        /* child/child relative demote */
rpm-build 3ee90c
        new_rsc_order(child, RSC_DEMOTE, last, RSC_DEMOTE, type, data_set);
rpm-build 3ee90c
rpm-build 3ee90c
    } else if (clone_data->ordered) {
rpm-build 3ee90c
        pe_rsc_trace(rsc, "Ordered version (1st node)");
rpm-build 3ee90c
        /* first child stop before global stopped */
rpm-build 3ee90c
        new_rsc_order(child, RSC_DEMOTE, rsc, RSC_DEMOTED, type, data_set);
rpm-build 3ee90c
rpm-build 3ee90c
    } else {
rpm-build 3ee90c
        pe_rsc_trace(rsc, "Un-ordered version");
rpm-build 3ee90c
    }
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
static void
rpm-build 3ee90c
check_promotable_actions(resource_t *rsc, gboolean *demoting,
rpm-build 3ee90c
                         gboolean *promoting)
rpm-build 3ee90c
{
rpm-build 3ee90c
    GListPtr gIter = NULL;
rpm-build 3ee90c
rpm-build 3ee90c
    if (rsc->children) {
rpm-build 3ee90c
        gIter = rsc->children;
rpm-build 3ee90c
        for (; gIter != NULL; gIter = gIter->next) {
rpm-build 3ee90c
            resource_t *child = (resource_t *) gIter->data;
rpm-build 3ee90c
rpm-build 3ee90c
            check_promotable_actions(child, demoting, promoting);
rpm-build 3ee90c
        }
rpm-build 3ee90c
        return;
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    CRM_ASSERT(demoting != NULL);
rpm-build 3ee90c
    CRM_ASSERT(promoting != NULL);
rpm-build 3ee90c
rpm-build 3ee90c
    gIter = rsc->actions;
rpm-build 3ee90c
    for (; gIter != NULL; gIter = gIter->next) {
rpm-build 3ee90c
        action_t *action = (action_t *) gIter->data;
rpm-build 3ee90c
rpm-build 3ee90c
        if (*promoting && *demoting) {
rpm-build 3ee90c
            return;
rpm-build 3ee90c
rpm-build 3ee90c
        } else if (is_set(action->flags, pe_action_optional)) {
rpm-build 3ee90c
            continue;
rpm-build 3ee90c
rpm-build 3ee90c
        } else if (safe_str_eq(RSC_DEMOTE, action->task)) {
rpm-build 3ee90c
            *demoting = TRUE;
rpm-build 3ee90c
rpm-build 3ee90c
        } else if (safe_str_eq(RSC_PROMOTE, action->task)) {
rpm-build 3ee90c
            *promoting = TRUE;
rpm-build 3ee90c
        }
rpm-build 3ee90c
    }
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
static void apply_master_location(resource_t *child, GListPtr location_constraints, pe_node_t *chosen)
rpm-build 3ee90c
{
rpm-build 3ee90c
    CRM_CHECK(child && chosen, return);
rpm-build 3ee90c
    for (GListPtr gIter = location_constraints; gIter; gIter = gIter->next) {
rpm-build 3ee90c
        pe_node_t *cons_node = NULL;
rpm-build 3ee90c
        pe__location_t *cons = gIter->data;
rpm-build 3ee90c
rpm-build 3ee90c
        if (cons->role_filter == RSC_ROLE_MASTER) {
rpm-build 3ee90c
            pe_rsc_trace(child, "Applying %s to %s", cons->id, child->id);
rpm-build 3ee90c
            cons_node = pe_find_node_id(cons->node_list_rh, chosen->details->id);
rpm-build 3ee90c
        }
rpm-build 3ee90c
        if (cons_node != NULL) {
rpm-build 3ee90c
            int new_priority = merge_weights(child->priority, cons_node->weight);
rpm-build 3ee90c
rpm-build 3ee90c
            pe_rsc_trace(child, "\t%s[%s]: %d -> %d (%d)",
rpm-build 3ee90c
                         child->id, cons_node->details->uname, child->priority,
rpm-build 3ee90c
                         new_priority, cons_node->weight);
rpm-build 3ee90c
            child->priority = new_priority;
rpm-build 3ee90c
        }
rpm-build 3ee90c
    }
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
static node_t *
rpm-build 3ee90c
can_be_master(resource_t * rsc)
rpm-build 3ee90c
{
rpm-build 3ee90c
    node_t *node = NULL;
rpm-build 3ee90c
    node_t *local_node = NULL;
rpm-build 3ee90c
    resource_t *parent = uber_parent(rsc);
rpm-build 3ee90c
    clone_variant_data_t *clone_data = NULL;
rpm-build 3ee90c
rpm-build 3ee90c
#if 0
rpm-build 3ee90c
    enum rsc_role_e role = RSC_ROLE_UNKNOWN;
rpm-build 3ee90c
rpm-build 3ee90c
    role = rsc->fns->state(rsc, FALSE);
rpm-build 3ee90c
    crm_info("%s role: %s", rsc->id, role2text(role));
rpm-build 3ee90c
#endif
rpm-build 3ee90c
rpm-build 3ee90c
    if (rsc->children) {
rpm-build 3ee90c
        GListPtr gIter = rsc->children;
rpm-build 3ee90c
rpm-build 3ee90c
        for (; gIter != NULL; gIter = gIter->next) {
rpm-build 3ee90c
            resource_t *child = (resource_t *) gIter->data;
rpm-build 3ee90c
rpm-build 3ee90c
            if (can_be_master(child) == NULL) {
rpm-build 3ee90c
                pe_rsc_trace(rsc, "Child %s of %s can't be promoted", child->id, rsc->id);
rpm-build 3ee90c
                return NULL;
rpm-build 3ee90c
            }
rpm-build 3ee90c
        }
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    node = rsc->fns->location(rsc, NULL, FALSE);
rpm-build 3ee90c
    if (node == NULL) {
rpm-build 3ee90c
        pe_rsc_trace(rsc, "%s cannot be master: not allocated", rsc->id);
rpm-build 3ee90c
        return NULL;
rpm-build 3ee90c
rpm-build 3ee90c
    } else if (is_not_set(rsc->flags, pe_rsc_managed)) {
rpm-build 3ee90c
        if (rsc->fns->state(rsc, TRUE) == RSC_ROLE_MASTER) {
rpm-build 3ee90c
            crm_notice("Forcing unmanaged master %s to remain promoted on %s",
rpm-build 3ee90c
                       rsc->id, node->details->uname);
rpm-build 3ee90c
rpm-build 3ee90c
        } else {
rpm-build 3ee90c
            return NULL;
rpm-build 3ee90c
        }
rpm-build 3ee90c
rpm-build 3ee90c
    } else if (rsc->priority < 0) {
rpm-build 3ee90c
        pe_rsc_trace(rsc, "%s cannot be master: preference: %d", rsc->id, rsc->priority);
rpm-build 3ee90c
        return NULL;
rpm-build 3ee90c
rpm-build 3ee90c
    } else if (can_run_resources(node) == FALSE) {
rpm-build 3ee90c
        crm_trace("Node can't run any resources: %s", node->details->uname);
rpm-build 3ee90c
        return NULL;
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    get_clone_variant_data(clone_data, parent);
rpm-build 3ee90c
    local_node = pe_hash_table_lookup(parent->allowed_nodes, node->details->id);
rpm-build 3ee90c
rpm-build 3ee90c
    if (local_node == NULL) {
rpm-build 3ee90c
        crm_err("%s cannot run on %s: node not allowed", rsc->id, node->details->uname);
rpm-build 3ee90c
        return NULL;
rpm-build 3ee90c
rpm-build 3ee90c
    } else if ((local_node->count < clone_data->promoted_node_max)
rpm-build 3ee90c
               || is_not_set(rsc->flags, pe_rsc_managed)) {
rpm-build 3ee90c
        return local_node;
rpm-build 3ee90c
rpm-build 3ee90c
    } else {
rpm-build 3ee90c
        pe_rsc_trace(rsc, "%s cannot be master on %s: node full", rsc->id, node->details->uname);
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    return NULL;
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
static gint
rpm-build 3ee90c
sort_promotable_instance(gconstpointer a, gconstpointer b, gpointer data_set)
rpm-build 3ee90c
{
rpm-build 3ee90c
    int rc;
rpm-build 3ee90c
    enum rsc_role_e role1 = RSC_ROLE_UNKNOWN;
rpm-build 3ee90c
    enum rsc_role_e role2 = RSC_ROLE_UNKNOWN;
rpm-build 3ee90c
rpm-build 3ee90c
    const resource_t *resource1 = (const resource_t *)a;
rpm-build 3ee90c
    const resource_t *resource2 = (const resource_t *)b;
rpm-build 3ee90c
rpm-build 3ee90c
    CRM_ASSERT(resource1 != NULL);
rpm-build 3ee90c
    CRM_ASSERT(resource2 != NULL);
rpm-build 3ee90c
rpm-build 3ee90c
    role1 = resource1->fns->state(resource1, TRUE);
rpm-build 3ee90c
    role2 = resource2->fns->state(resource2, TRUE);
rpm-build 3ee90c
rpm-build 3ee90c
    rc = sort_rsc_index(a, b);
rpm-build 3ee90c
    if (rc != 0) {
rpm-build 3ee90c
        crm_trace("%s %c %s (index)", resource1->id, rc < 0 ? '<' : '>', resource2->id);
rpm-build 3ee90c
        return rc;
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    if (role1 > role2) {
rpm-build 3ee90c
        crm_trace("%s %c %s (role)", resource1->id, '<', resource2->id);
rpm-build 3ee90c
        return -1;
rpm-build 3ee90c
rpm-build 3ee90c
    } else if (role1 < role2) {
rpm-build 3ee90c
        crm_trace("%s %c %s (role)", resource1->id, '>', resource2->id);
rpm-build 3ee90c
        return 1;
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    return sort_clone_instance(a, b, data_set);
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
static void
rpm-build 3ee90c
promotion_order(resource_t *rsc, pe_working_set_t *data_set)
rpm-build 3ee90c
{
rpm-build 3ee90c
    GListPtr gIter = NULL;
rpm-build 3ee90c
    node_t *node = NULL;
rpm-build 3ee90c
    node_t *chosen = NULL;
rpm-build 3ee90c
    clone_variant_data_t *clone_data = NULL;
rpm-build 3ee90c
    char score[33];
rpm-build 3ee90c
    size_t len = sizeof(score);
rpm-build 3ee90c
rpm-build 3ee90c
    get_clone_variant_data(clone_data, rsc);
rpm-build 3ee90c
rpm-build 3ee90c
    if (clone_data->merged_master_weights) {
rpm-build 3ee90c
        return;
rpm-build 3ee90c
    }
rpm-build 3ee90c
    clone_data->merged_master_weights = TRUE;
rpm-build 3ee90c
    pe_rsc_trace(rsc, "Merging weights for %s", rsc->id);
rpm-build 3ee90c
    set_bit(rsc->flags, pe_rsc_merging);
rpm-build 3ee90c
rpm-build 3ee90c
    for (gIter = rsc->children; gIter != NULL; gIter = gIter->next) {
rpm-build 3ee90c
        resource_t *child = (resource_t *) gIter->data;
rpm-build 3ee90c
rpm-build 3ee90c
        pe_rsc_trace(rsc, "Sort index: %s = %d", child->id, child->sort_index);
rpm-build 3ee90c
    }
rpm-build 3ee90c
    dump_node_scores(LOG_TRACE, rsc, "Before", rsc->allowed_nodes);
rpm-build 3ee90c
rpm-build 3ee90c
    gIter = rsc->children;
rpm-build 3ee90c
    for (; gIter != NULL; gIter = gIter->next) {
rpm-build 3ee90c
        resource_t *child = (resource_t *) gIter->data;
rpm-build 3ee90c
rpm-build 3ee90c
        chosen = child->fns->location(child, NULL, FALSE);
rpm-build 3ee90c
        if (chosen == NULL || child->sort_index < 0) {
rpm-build 3ee90c
            pe_rsc_trace(rsc, "Skipping %s", child->id);
rpm-build 3ee90c
            continue;
rpm-build 3ee90c
        }
rpm-build 3ee90c
rpm-build 3ee90c
        node = (node_t *) pe_hash_table_lookup(rsc->allowed_nodes, chosen->details->id);
rpm-build 3ee90c
        CRM_ASSERT(node != NULL);
rpm-build 3ee90c
        /* adds in master preferences and rsc_location.role=Master */
rpm-build 3ee90c
        score2char_stack(child->sort_index, score, len);
rpm-build 3ee90c
        pe_rsc_trace(rsc, "Adding %s to %s from %s", score,
rpm-build 3ee90c
                     node->details->uname, child->id);
rpm-build 3ee90c
        node->weight = merge_weights(child->sort_index, node->weight);
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    dump_node_scores(LOG_TRACE, rsc, "Middle", rsc->allowed_nodes);
rpm-build 3ee90c
rpm-build 3ee90c
    gIter = rsc->rsc_cons;
rpm-build 3ee90c
    for (; gIter != NULL; gIter = gIter->next) {
rpm-build 3ee90c
        rsc_colocation_t *constraint = (rsc_colocation_t *) gIter->data;
rpm-build 3ee90c
rpm-build 3ee90c
        /* (re-)adds location preferences of resources that the
rpm-build 3ee90c
         * master instance should/must be colocated with
rpm-build 3ee90c
         */
rpm-build 3ee90c
        if (constraint->role_lh == RSC_ROLE_MASTER) {
rpm-build 3ee90c
            enum pe_weights flags = constraint->score == INFINITY ? 0 : pe_weights_rollback;
rpm-build 3ee90c
rpm-build 3ee90c
            pe_rsc_trace(rsc, "RHS: %s with %s: %d", constraint->rsc_lh->id, constraint->rsc_rh->id,
rpm-build 3ee90c
                         constraint->score);
rpm-build 3ee90c
            rsc->allowed_nodes =
rpm-build 3ee90c
                constraint->rsc_rh->cmds->merge_weights(constraint->rsc_rh, rsc->id,
rpm-build 3ee90c
                                                        rsc->allowed_nodes,
rpm-build 3ee90c
                                                        constraint->node_attribute,
rpm-build 3ee90c
                                                        (float)constraint->score / INFINITY, flags);
rpm-build 3ee90c
        }
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    gIter = rsc->rsc_cons_lhs;
rpm-build 3ee90c
    for (; gIter != NULL; gIter = gIter->next) {
rpm-build 3ee90c
        rsc_colocation_t *constraint = (rsc_colocation_t *) gIter->data;
rpm-build 3ee90c
rpm-build 3ee90c
        /* (re-)adds location preferences of resource that wish to be
rpm-build 3ee90c
         * colocated with the master instance
rpm-build 3ee90c
         */
rpm-build 3ee90c
        if (constraint->role_rh == RSC_ROLE_MASTER) {
rpm-build 3ee90c
            pe_rsc_trace(rsc, "LHS: %s with %s: %d", constraint->rsc_lh->id, constraint->rsc_rh->id,
rpm-build 3ee90c
                         constraint->score);
rpm-build 3ee90c
            rsc->allowed_nodes =
rpm-build 3ee90c
                constraint->rsc_lh->cmds->merge_weights(constraint->rsc_lh, rsc->id,
rpm-build 3ee90c
                                                        rsc->allowed_nodes,
rpm-build 3ee90c
                                                        constraint->node_attribute,
rpm-build 3ee90c
                                                        (float)constraint->score / INFINITY,
rpm-build 3ee90c
                                                        (pe_weights_rollback |
rpm-build 3ee90c
                                                         pe_weights_positive));
rpm-build 3ee90c
        }
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    gIter = rsc->rsc_tickets;
rpm-build 3ee90c
    for (; gIter != NULL; gIter = gIter->next) {
rpm-build 3ee90c
        rsc_ticket_t *rsc_ticket = (rsc_ticket_t *) gIter->data;
rpm-build 3ee90c
rpm-build 3ee90c
        if (rsc_ticket->role_lh == RSC_ROLE_MASTER
rpm-build 3ee90c
            && (rsc_ticket->ticket->granted == FALSE || rsc_ticket->ticket->standby)) {
rpm-build 3ee90c
            resource_location(rsc, NULL, -INFINITY, "__stateful_without_ticket__", data_set);
rpm-build 3ee90c
        }
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    dump_node_scores(LOG_TRACE, rsc, "After", rsc->allowed_nodes);
rpm-build 3ee90c
rpm-build 3ee90c
    /* write them back and sort */
rpm-build 3ee90c
rpm-build 3ee90c
    gIter = rsc->children;
rpm-build 3ee90c
    for (; gIter != NULL; gIter = gIter->next) {
rpm-build 3ee90c
        resource_t *child = (resource_t *) gIter->data;
rpm-build 3ee90c
rpm-build 3ee90c
        chosen = child->fns->location(child, NULL, FALSE);
rpm-build 3ee90c
        if (is_not_set(child->flags, pe_rsc_managed) && child->next_role == RSC_ROLE_MASTER) {
rpm-build 3ee90c
            child->sort_index = INFINITY;
rpm-build 3ee90c
rpm-build 3ee90c
        } else if (chosen == NULL || child->sort_index < 0) {
rpm-build 3ee90c
            pe_rsc_trace(rsc, "%s: %d", child->id, child->sort_index);
rpm-build 3ee90c
rpm-build 3ee90c
        } else {
rpm-build 3ee90c
            node = (node_t *) pe_hash_table_lookup(rsc->allowed_nodes, chosen->details->id);
rpm-build 3ee90c
            CRM_ASSERT(node != NULL);
rpm-build 3ee90c
rpm-build 3ee90c
            child->sort_index = node->weight;
rpm-build 3ee90c
        }
rpm-build 3ee90c
        pe_rsc_trace(rsc, "Set sort index: %s = %d", child->id, child->sort_index);
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    rsc->children = g_list_sort_with_data(rsc->children,
rpm-build 3ee90c
                                          sort_promotable_instance, data_set);
rpm-build 3ee90c
    clear_bit(rsc->flags, pe_rsc_merging);
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
static gboolean
rpm-build 3ee90c
filter_anonymous_instance(resource_t *rsc, const node_t *node)
rpm-build 3ee90c
{
rpm-build 3ee90c
    GListPtr rIter = NULL;
rpm-build 3ee90c
    char *key = clone_strip(rsc->id);
rpm-build 3ee90c
    resource_t *parent = uber_parent(rsc);
rpm-build 3ee90c
rpm-build 3ee90c
    for (rIter = parent->children; rIter; rIter = rIter->next) {
rpm-build 3ee90c
        /* If there is an active instance on the node, only it receives the
rpm-build 3ee90c
         * promotion score. Use ->find_rsc() in case this is a cloned group.
rpm-build 3ee90c
         */
rpm-build 3ee90c
        resource_t *child = rIter->data;
rpm-build 3ee90c
        resource_t *active = parent->fns->find_rsc(child, key, node, pe_find_clone|pe_find_current);
rpm-build 3ee90c
rpm-build 3ee90c
        if(rsc == active) {
rpm-build 3ee90c
            pe_rsc_trace(rsc, "Found %s for %s active on %s: done", active->id, key, node->details->uname);
rpm-build 3ee90c
            free(key);
rpm-build 3ee90c
            return TRUE;
rpm-build 3ee90c
        } else if(active) {
rpm-build 3ee90c
            pe_rsc_trace(rsc, "Found %s for %s on %s: not %s", active->id, key, node->details->uname, rsc->id);
rpm-build 3ee90c
            free(key);
rpm-build 3ee90c
            return FALSE;
rpm-build 3ee90c
        } else {
rpm-build 3ee90c
            pe_rsc_trace(rsc, "%s on %s: not active", key, node->details->uname);
rpm-build 3ee90c
        }
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    for (rIter = parent->children; rIter; rIter = rIter->next) {
rpm-build 3ee90c
        resource_t *child = rIter->data;
rpm-build 3ee90c
rpm-build 3ee90c
        /*
rpm-build 3ee90c
         * We know it's not running, but any score will still count if
rpm-build 3ee90c
         * the instance has been probed on $node
rpm-build 3ee90c
         *
rpm-build 3ee90c
         * Again use ->find_rsc() because we might be a cloned group
rpm-build 3ee90c
         * and knowing that other members of the group are known here
rpm-build 3ee90c
         * implies nothing
rpm-build 3ee90c
         */
rpm-build 3ee90c
        rsc = parent->fns->find_rsc(child, key, NULL, pe_find_clone);
rpm-build 3ee90c
        CRM_LOG_ASSERT(rsc);
rpm-build 3ee90c
        if(rsc) {
rpm-build 3ee90c
            pe_rsc_trace(rsc, "Checking %s for %s on %s", rsc->id, key, node->details->uname);
rpm-build 3ee90c
            if (g_hash_table_lookup(rsc->known_on, node->details->id)) {
rpm-build 3ee90c
                free(key);
rpm-build 3ee90c
                return TRUE;
rpm-build 3ee90c
            }
rpm-build 3ee90c
        }
rpm-build 3ee90c
    }
rpm-build 3ee90c
    free(key);
rpm-build 3ee90c
    return FALSE;
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
static const char *
rpm-build 3ee90c
lookup_promotion_score(resource_t *rsc, const node_t *node, const char *name)
rpm-build 3ee90c
{
rpm-build 3ee90c
    const char *attr_value = NULL;
rpm-build 3ee90c
rpm-build 3ee90c
    if (node && name) {
rpm-build 3ee90c
        char *attr_name = crm_strdup_printf("master-%s", name);
rpm-build 3ee90c
rpm-build 3ee90c
        attr_value = pe_node_attribute_calculated(node, attr_name, rsc);
rpm-build 3ee90c
        free(attr_name);
rpm-build 3ee90c
    }
rpm-build 3ee90c
    return attr_value;
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
static int
rpm-build 3ee90c
promotion_score(resource_t *rsc, const node_t *node, int not_set_value)
rpm-build 3ee90c
{
rpm-build 3ee90c
    char *name = rsc->id;
rpm-build 3ee90c
    const char *attr_value = NULL;
rpm-build 3ee90c
    int score = not_set_value;
rpm-build 3ee90c
    node_t *match = NULL;
rpm-build 3ee90c
rpm-build 3ee90c
    CRM_CHECK(node != NULL, return not_set_value);
rpm-build 3ee90c
rpm-build 3ee90c
    if (rsc->children) {
rpm-build 3ee90c
        GListPtr gIter = rsc->children;
rpm-build 3ee90c
rpm-build 3ee90c
        for (; gIter != NULL; gIter = gIter->next) {
rpm-build 3ee90c
            resource_t *child = (resource_t *) gIter->data;
rpm-build 3ee90c
            int c_score = promotion_score(child, node, not_set_value);
rpm-build 3ee90c
rpm-build 3ee90c
            if (score == not_set_value) {
rpm-build 3ee90c
                score = c_score;
rpm-build 3ee90c
            } else {
rpm-build 3ee90c
                score += c_score;
rpm-build 3ee90c
            }
rpm-build 3ee90c
        }
rpm-build 3ee90c
        return score;
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    if (is_not_set(rsc->flags, pe_rsc_unique) && filter_anonymous_instance(rsc, node)) {
rpm-build 3ee90c
        pe_rsc_trace(rsc, "Anonymous clone %s is allowed on %s", rsc->id, node->details->uname);
rpm-build 3ee90c
rpm-build 3ee90c
    } else if (rsc->running_on || g_hash_table_size(rsc->known_on)) {
rpm-build 3ee90c
        /* If we've probed and/or started the resource anywhere, consider
rpm-build 3ee90c
         * promotion scores only from nodes where we know the status. However,
rpm-build 3ee90c
         * if the status of all nodes is unknown (e.g. cluster startup),
rpm-build 3ee90c
         * skip this code, to make sure we take into account any permanent
rpm-build 3ee90c
         * promotion scores set previously.
rpm-build 3ee90c
         */
rpm-build 3ee90c
        node_t *known = pe_hash_table_lookup(rsc->known_on, node->details->id);
rpm-build 3ee90c
rpm-build 3ee90c
        match = pe_find_node_id(rsc->running_on, node->details->id);
rpm-build 3ee90c
        if ((match == NULL) && (known == NULL)) {
rpm-build 3ee90c
            pe_rsc_trace(rsc, "skipping %s (aka. %s) promotion score on %s because inactive",
rpm-build 3ee90c
                         rsc->id, rsc->clone_name, node->details->uname);
rpm-build 3ee90c
            return score;
rpm-build 3ee90c
        }
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    match = pe_hash_table_lookup(rsc->allowed_nodes, node->details->id);
rpm-build 3ee90c
    if (match == NULL) {
rpm-build 3ee90c
        return score;
rpm-build 3ee90c
rpm-build 3ee90c
    } else if (match->weight < 0) {
rpm-build 3ee90c
        pe_rsc_trace(rsc, "%s on %s has score: %d - ignoring",
rpm-build 3ee90c
                     rsc->id, match->details->uname, match->weight);
rpm-build 3ee90c
        return score;
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    if (rsc->clone_name) {
rpm-build 3ee90c
        /* Use the name the lrm knows this resource as,
rpm-build 3ee90c
         * since that's what crm_master would have used too
rpm-build 3ee90c
         */
rpm-build 3ee90c
        name = rsc->clone_name;
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    attr_value = lookup_promotion_score(rsc, node, name);
rpm-build 3ee90c
    pe_rsc_trace(rsc, "promotion score for %s on %s = %s",
rpm-build 3ee90c
                 name, node->details->uname, crm_str(attr_value));
rpm-build 3ee90c
rpm-build 3ee90c
    if ((attr_value == NULL) && is_not_set(rsc->flags, pe_rsc_unique)) {
rpm-build 3ee90c
        /* If we don't have any LRM history yet, we won't have clone_name -- in
rpm-build 3ee90c
         * that case, for anonymous clones, try the resource name without any
rpm-build 3ee90c
         * instance number.
rpm-build 3ee90c
         */
rpm-build 3ee90c
        name = clone_strip(rsc->id);
rpm-build 3ee90c
        if (strcmp(rsc->id, name)) {
rpm-build 3ee90c
            attr_value = lookup_promotion_score(rsc, node, name);
rpm-build 3ee90c
            pe_rsc_trace(rsc, "stripped promotion score for %s on %s = %s",
rpm-build 3ee90c
                         name, node->details->uname, crm_str(attr_value));
rpm-build 3ee90c
        }
rpm-build 3ee90c
        free(name);
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    if (attr_value != NULL) {
rpm-build 3ee90c
        score = char2score(attr_value);
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    return score;
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
void
rpm-build 3ee90c
apply_master_prefs(resource_t *rsc)
rpm-build 3ee90c
{
rpm-build 3ee90c
    int score, new_score;
rpm-build 3ee90c
    GListPtr gIter = rsc->children;
rpm-build 3ee90c
    clone_variant_data_t *clone_data = NULL;
rpm-build 3ee90c
rpm-build 3ee90c
    get_clone_variant_data(clone_data, rsc);
rpm-build 3ee90c
rpm-build 3ee90c
    if (clone_data->applied_master_prefs) {
rpm-build 3ee90c
        /* Make sure we only do this once */
rpm-build 3ee90c
        return;
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    clone_data->applied_master_prefs = TRUE;
rpm-build 3ee90c
rpm-build 3ee90c
    for (; gIter != NULL; gIter = gIter->next) {
rpm-build 3ee90c
        GHashTableIter iter;
rpm-build 3ee90c
        node_t *node = NULL;
rpm-build 3ee90c
        resource_t *child_rsc = (resource_t *) gIter->data;
rpm-build 3ee90c
rpm-build 3ee90c
        g_hash_table_iter_init(&iter, child_rsc->allowed_nodes);
rpm-build 3ee90c
        while (g_hash_table_iter_next(&iter, NULL, (void **)&node)) {
rpm-build 3ee90c
            if (can_run_resources(node) == FALSE) {
rpm-build 3ee90c
                /* This node will never be promoted to master,
rpm-build 3ee90c
                 *  so don't apply the promotion score as that may
rpm-build 3ee90c
                 *  lead to clone shuffling
rpm-build 3ee90c
                 */
rpm-build 3ee90c
                continue;
rpm-build 3ee90c
            }
rpm-build 3ee90c
rpm-build 3ee90c
            score = promotion_score(child_rsc, node, 0);
rpm-build 3ee90c
            if (score > 0) {
rpm-build 3ee90c
                new_score = merge_weights(node->weight, score);
rpm-build 3ee90c
                if (new_score != node->weight) {
rpm-build 3ee90c
                    pe_rsc_trace(rsc, "\t%s: Updating preference for %s (%d->%d)",
rpm-build 3ee90c
                                 child_rsc->id, node->details->uname, node->weight, new_score);
rpm-build 3ee90c
                    node->weight = new_score;
rpm-build 3ee90c
                }
rpm-build 3ee90c
            }
rpm-build 3ee90c
rpm-build 3ee90c
            new_score = QB_MAX(child_rsc->priority, score);
rpm-build 3ee90c
            if (new_score != child_rsc->priority) {
rpm-build 3ee90c
                pe_rsc_trace(rsc, "\t%s: Updating priority (%d->%d)",
rpm-build 3ee90c
                             child_rsc->id, child_rsc->priority, new_score);
rpm-build 3ee90c
                child_rsc->priority = new_score;
rpm-build 3ee90c
            }
rpm-build 3ee90c
        }
rpm-build 3ee90c
    }
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
static void
rpm-build 3ee90c
set_role_slave(resource_t * rsc, gboolean current)
rpm-build 3ee90c
{
rpm-build 3ee90c
    GListPtr gIter = rsc->children;
rpm-build 3ee90c
rpm-build 3ee90c
    if (current) {
rpm-build 3ee90c
        if (rsc->role == RSC_ROLE_STARTED) {
rpm-build 3ee90c
            rsc->role = RSC_ROLE_SLAVE;
rpm-build 3ee90c
        }
rpm-build 3ee90c
rpm-build 3ee90c
    } else {
rpm-build 3ee90c
        GListPtr allocated = NULL;
rpm-build 3ee90c
rpm-build 3ee90c
        rsc->fns->location(rsc, &allocated, FALSE);
rpm-build 3ee90c
rpm-build 3ee90c
        if (allocated) {
rpm-build 3ee90c
            rsc->next_role = RSC_ROLE_SLAVE;
rpm-build 3ee90c
rpm-build 3ee90c
        } else {
rpm-build 3ee90c
            rsc->next_role = RSC_ROLE_STOPPED;
rpm-build 3ee90c
        }
rpm-build 3ee90c
        g_list_free(allocated);
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    for (; gIter != NULL; gIter = gIter->next) {
rpm-build 3ee90c
        resource_t *child_rsc = (resource_t *) gIter->data;
rpm-build 3ee90c
rpm-build 3ee90c
        set_role_slave(child_rsc, current);
rpm-build 3ee90c
    }
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
static void
rpm-build 3ee90c
set_role_master(resource_t * rsc)
rpm-build 3ee90c
{
rpm-build 3ee90c
    GListPtr gIter = rsc->children;
rpm-build 3ee90c
rpm-build 3ee90c
    if (rsc->next_role == RSC_ROLE_UNKNOWN) {
rpm-build 3ee90c
        rsc->next_role = RSC_ROLE_MASTER;
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    for (; gIter != NULL; gIter = gIter->next) {
rpm-build 3ee90c
        resource_t *child_rsc = (resource_t *) gIter->data;
rpm-build 3ee90c
rpm-build 3ee90c
        set_role_master(child_rsc);
rpm-build 3ee90c
    }
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
node_t *
rpm-build 3ee90c
color_promotable(resource_t *rsc, pe_working_set_t *data_set)
rpm-build 3ee90c
{
rpm-build 3ee90c
    int promoted = 0;
rpm-build 3ee90c
    GListPtr gIter = NULL;
rpm-build 3ee90c
    GListPtr gIter2 = NULL;
rpm-build 3ee90c
    GHashTableIter iter;
rpm-build 3ee90c
    node_t *node = NULL;
rpm-build 3ee90c
    node_t *chosen = NULL;
rpm-build 3ee90c
    enum rsc_role_e next_role = RSC_ROLE_UNKNOWN;
rpm-build 3ee90c
    char score[33];
rpm-build 3ee90c
    size_t len = sizeof(score);
rpm-build 3ee90c
    clone_variant_data_t *clone_data = NULL;
rpm-build 3ee90c
rpm-build 3ee90c
    get_clone_variant_data(clone_data, rsc);
rpm-build 3ee90c
rpm-build 3ee90c
    /* count now tracks the number of masters allocated */
rpm-build 3ee90c
    g_hash_table_iter_init(&iter, rsc->allowed_nodes);
rpm-build 3ee90c
    while (g_hash_table_iter_next(&iter, NULL, (void **)&node)) {
rpm-build 3ee90c
        node->count = 0;
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    /*
rpm-build 3ee90c
     * assign priority
rpm-build 3ee90c
     */
rpm-build 3ee90c
    for (gIter = rsc->children; gIter != NULL; gIter = gIter->next) {
rpm-build 3ee90c
        GListPtr list = NULL;
rpm-build 3ee90c
        resource_t *child_rsc = (resource_t *) gIter->data;
rpm-build 3ee90c
rpm-build 3ee90c
        pe_rsc_trace(rsc, "Assigning priority for %s: %s", child_rsc->id,
rpm-build 3ee90c
                     role2text(child_rsc->next_role));
rpm-build 3ee90c
rpm-build 3ee90c
        if (child_rsc->fns->state(child_rsc, TRUE) == RSC_ROLE_STARTED) {
rpm-build 3ee90c
            set_role_slave(child_rsc, TRUE);
rpm-build 3ee90c
        }
rpm-build 3ee90c
rpm-build 3ee90c
        chosen = child_rsc->fns->location(child_rsc, &list, FALSE);
rpm-build 3ee90c
        if (g_list_length(list) > 1) {
rpm-build 3ee90c
            crm_config_err("Cannot promote non-colocated child %s", child_rsc->id);
rpm-build 3ee90c
        }
rpm-build 3ee90c
rpm-build 3ee90c
        g_list_free(list);
rpm-build 3ee90c
        if (chosen == NULL) {
rpm-build 3ee90c
            continue;
rpm-build 3ee90c
        }
rpm-build 3ee90c
rpm-build 3ee90c
        next_role = child_rsc->fns->state(child_rsc, FALSE);
rpm-build 3ee90c
        switch (next_role) {
rpm-build 3ee90c
            case RSC_ROLE_STARTED:
rpm-build 3ee90c
            case RSC_ROLE_UNKNOWN:
rpm-build 3ee90c
                /*
rpm-build 3ee90c
                 * Default to -1 if no value is set
rpm-build 3ee90c
                 *
rpm-build 3ee90c
                 * This allows master locations to be specified
rpm-build 3ee90c
                 * based solely on rsc_location constraints,
rpm-build 3ee90c
                 * but prevents anyone from being promoted if
rpm-build 3ee90c
                 * neither a constraint nor a promotion score is present
rpm-build 3ee90c
                 */
rpm-build 3ee90c
                child_rsc->priority = promotion_score(child_rsc, chosen, -1);
rpm-build 3ee90c
                break;
rpm-build 3ee90c
rpm-build 3ee90c
            case RSC_ROLE_SLAVE:
rpm-build 3ee90c
            case RSC_ROLE_STOPPED:
rpm-build 3ee90c
                child_rsc->priority = -INFINITY;
rpm-build 3ee90c
                break;
rpm-build 3ee90c
            case RSC_ROLE_MASTER:
rpm-build 3ee90c
                /* We will arrive here if we're re-creating actions after a stonith
rpm-build 3ee90c
                 */
rpm-build 3ee90c
                break;
rpm-build 3ee90c
            default:
rpm-build 3ee90c
                CRM_CHECK(FALSE /* unhandled */ ,
rpm-build 3ee90c
                          crm_err("Unknown resource role: %d for %s", next_role, child_rsc->id));
rpm-build 3ee90c
        }
rpm-build 3ee90c
rpm-build 3ee90c
        apply_master_location(child_rsc, child_rsc->rsc_location, chosen);
rpm-build 3ee90c
        apply_master_location(child_rsc, rsc->rsc_location, chosen);
rpm-build 3ee90c
rpm-build 3ee90c
        for (gIter2 = child_rsc->rsc_cons; gIter2 != NULL; gIter2 = gIter2->next) {
rpm-build 3ee90c
            rsc_colocation_t *cons = (rsc_colocation_t *) gIter2->data;
rpm-build 3ee90c
rpm-build 3ee90c
            child_rsc->cmds->rsc_colocation_lh(child_rsc, cons->rsc_rh, cons,
rpm-build 3ee90c
                                               data_set);
rpm-build 3ee90c
        }
rpm-build 3ee90c
rpm-build 3ee90c
        child_rsc->sort_index = child_rsc->priority;
rpm-build 3ee90c
        pe_rsc_trace(rsc, "Assigning priority for %s: %d", child_rsc->id, child_rsc->priority);
rpm-build 3ee90c
rpm-build 3ee90c
        if (next_role == RSC_ROLE_MASTER) {
rpm-build 3ee90c
            child_rsc->sort_index = INFINITY;
rpm-build 3ee90c
        }
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    dump_node_scores(LOG_TRACE, rsc, "Pre merge", rsc->allowed_nodes);
rpm-build 3ee90c
    promotion_order(rsc, data_set);
rpm-build 3ee90c
rpm-build 3ee90c
    /* mark the first N as masters */
rpm-build 3ee90c
rpm-build 3ee90c
    for (gIter = rsc->children; gIter != NULL; gIter = gIter->next) {
rpm-build 3ee90c
        resource_t *child_rsc = (resource_t *) gIter->data;
rpm-build 3ee90c
        score2char_stack(child_rsc->sort_index, score, len);
rpm-build 3ee90c
rpm-build 3ee90c
        chosen = child_rsc->fns->location(child_rsc, NULL, FALSE);
rpm-build 3ee90c
        if (show_scores) {
rpm-build 3ee90c
            if (is_set(data_set->flags, pe_flag_stdout)) {
rpm-build 3ee90c
                printf("%s promotion score on %s: %s\n",
rpm-build 3ee90c
                       child_rsc->id,
rpm-build 3ee90c
                       (chosen? chosen->details->uname : "none"), score);
rpm-build 3ee90c
            }
rpm-build 3ee90c
rpm-build 3ee90c
        } else {
rpm-build 3ee90c
            do_crm_log(scores_log_level, "%s promotion score on %s: %s",
rpm-build 3ee90c
                       child_rsc->id, chosen ? chosen->details->uname : "none", score);
rpm-build 3ee90c
        }
rpm-build 3ee90c
rpm-build 3ee90c
        chosen = NULL;          /* nuke 'chosen' so that we don't promote more than the
rpm-build 3ee90c
                                 * required number of instances
rpm-build 3ee90c
                                 */
rpm-build 3ee90c
rpm-build 3ee90c
        if (child_rsc->sort_index < 0) {
rpm-build 3ee90c
            pe_rsc_trace(rsc, "Not supposed to promote child: %s", child_rsc->id);
rpm-build 3ee90c
rpm-build 3ee90c
        } else if ((promoted < clone_data->promoted_max)
rpm-build 3ee90c
                   || is_not_set(rsc->flags, pe_rsc_managed)) {
rpm-build 3ee90c
            chosen = can_be_master(child_rsc);
rpm-build 3ee90c
        }
rpm-build 3ee90c
rpm-build 3ee90c
        pe_rsc_debug(rsc, "%s promotion score: %d", child_rsc->id, child_rsc->priority);
rpm-build 3ee90c
rpm-build 3ee90c
        if (chosen == NULL) {
rpm-build 3ee90c
            set_role_slave(child_rsc, FALSE);
rpm-build 3ee90c
            continue;
rpm-build 3ee90c
rpm-build 3ee90c
        } else if(child_rsc->role < RSC_ROLE_MASTER
rpm-build 3ee90c
              && is_set(data_set->flags, pe_flag_have_quorum) == FALSE
rpm-build 3ee90c
              && data_set->no_quorum_policy == no_quorum_freeze) {
rpm-build 3ee90c
            crm_notice("Resource %s cannot be elevated from %s to %s: no-quorum-policy=freeze",
rpm-build 3ee90c
                       child_rsc->id, role2text(child_rsc->role), role2text(child_rsc->next_role));
rpm-build 3ee90c
            set_role_slave(child_rsc, FALSE);
rpm-build 3ee90c
            continue;
rpm-build 3ee90c
        }
rpm-build 3ee90c
rpm-build 3ee90c
        chosen->count++;
rpm-build 3ee90c
        pe_rsc_info(rsc, "Promoting %s (%s %s)",
rpm-build 3ee90c
                    child_rsc->id, role2text(child_rsc->role), chosen->details->uname);
rpm-build 3ee90c
        set_role_master(child_rsc);
rpm-build 3ee90c
        promoted++;
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    pe_rsc_info(rsc, "%s: Promoted %d instances of a possible %d to master",
rpm-build 3ee90c
                rsc->id, promoted, clone_data->promoted_max);
rpm-build 3ee90c
rpm-build 3ee90c
    return NULL;
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
void
rpm-build 3ee90c
create_promotable_actions(resource_t * rsc, pe_working_set_t * data_set)
rpm-build 3ee90c
{
rpm-build 3ee90c
    action_t *action = NULL;
rpm-build 3ee90c
    GListPtr gIter = rsc->children;
rpm-build 3ee90c
    action_t *action_complete = NULL;
rpm-build 3ee90c
    gboolean any_promoting = FALSE;
rpm-build 3ee90c
    gboolean any_demoting = FALSE;
rpm-build 3ee90c
    resource_t *last_promote_rsc = NULL;
rpm-build 3ee90c
    resource_t *last_demote_rsc = NULL;
rpm-build 3ee90c
rpm-build 3ee90c
    clone_variant_data_t *clone_data = NULL;
rpm-build 3ee90c
rpm-build 3ee90c
    get_clone_variant_data(clone_data, rsc);
rpm-build 3ee90c
rpm-build 3ee90c
    pe_rsc_debug(rsc, "Creating actions for %s", rsc->id);
rpm-build 3ee90c
rpm-build 3ee90c
    for (; gIter != NULL; gIter = gIter->next) {
rpm-build 3ee90c
        gboolean child_promoting = FALSE;
rpm-build 3ee90c
        gboolean child_demoting = FALSE;
rpm-build 3ee90c
        resource_t *child_rsc = (resource_t *) gIter->data;
rpm-build 3ee90c
rpm-build 3ee90c
        pe_rsc_trace(rsc, "Creating actions for %s", child_rsc->id);
rpm-build 3ee90c
        child_rsc->cmds->create_actions(child_rsc, data_set);
rpm-build 3ee90c
        check_promotable_actions(child_rsc, &child_demoting, &child_promoting);
rpm-build 3ee90c
rpm-build 3ee90c
        any_demoting = any_demoting || child_demoting;
rpm-build 3ee90c
        any_promoting = any_promoting || child_promoting;
rpm-build 3ee90c
        pe_rsc_trace(rsc, "Created actions for %s: %d %d", child_rsc->id, child_promoting,
rpm-build 3ee90c
                     child_demoting);
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    /* promote */
rpm-build 3ee90c
    action = create_pseudo_resource_op(rsc, RSC_PROMOTE, !any_promoting, TRUE, data_set);
rpm-build 3ee90c
    action_complete = create_pseudo_resource_op(rsc, RSC_PROMOTED, !any_promoting, TRUE, data_set);
rpm-build 3ee90c
    action_complete->priority = INFINITY;
rpm-build 3ee90c
rpm-build 3ee90c
    child_promoting_constraints(clone_data, pe_order_optional,
rpm-build 3ee90c
                                rsc, NULL, last_promote_rsc, data_set);
rpm-build 3ee90c
rpm-build 3ee90c
    if (clone_data->promote_notify == NULL) {
rpm-build 3ee90c
        clone_data->promote_notify =
rpm-build 3ee90c
            create_notification_boundaries(rsc, RSC_PROMOTE, action, action_complete, data_set);
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    /* demote */
rpm-build 3ee90c
    action = create_pseudo_resource_op(rsc, RSC_DEMOTE, !any_demoting, TRUE, data_set);
rpm-build 3ee90c
    action_complete = create_pseudo_resource_op(rsc, RSC_DEMOTED, !any_demoting, TRUE, data_set);
rpm-build 3ee90c
    action_complete->priority = INFINITY;
rpm-build 3ee90c
rpm-build 3ee90c
    child_demoting_constraints(clone_data, pe_order_optional, rsc, NULL, last_demote_rsc, data_set);
rpm-build 3ee90c
rpm-build 3ee90c
    if (clone_data->demote_notify == NULL) {
rpm-build 3ee90c
        clone_data->demote_notify =
rpm-build 3ee90c
            create_notification_boundaries(rsc, RSC_DEMOTE, action, action_complete, data_set);
rpm-build 3ee90c
rpm-build 3ee90c
        if (clone_data->promote_notify) {
rpm-build 3ee90c
            /* If we ever wanted groups to have notifications we'd need to move this to native_internal_constraints() one day
rpm-build 3ee90c
             * Requires exposing *_notify
rpm-build 3ee90c
             */
rpm-build 3ee90c
            order_actions(clone_data->stop_notify->post_done, clone_data->promote_notify->pre,
rpm-build 3ee90c
                          pe_order_optional);
rpm-build 3ee90c
            order_actions(clone_data->start_notify->post_done, clone_data->promote_notify->pre,
rpm-build 3ee90c
                          pe_order_optional);
rpm-build 3ee90c
            order_actions(clone_data->demote_notify->post_done, clone_data->promote_notify->pre,
rpm-build 3ee90c
                          pe_order_optional);
rpm-build 3ee90c
            order_actions(clone_data->demote_notify->post_done, clone_data->start_notify->pre,
rpm-build 3ee90c
                          pe_order_optional);
rpm-build 3ee90c
            order_actions(clone_data->demote_notify->post_done, clone_data->stop_notify->pre,
rpm-build 3ee90c
                          pe_order_optional);
rpm-build 3ee90c
        }
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    /* restore the correct priority */
rpm-build 3ee90c
rpm-build 3ee90c
    gIter = rsc->children;
rpm-build 3ee90c
    for (; gIter != NULL; gIter = gIter->next) {
rpm-build 3ee90c
        resource_t *child_rsc = (resource_t *) gIter->data;
rpm-build 3ee90c
rpm-build 3ee90c
        child_rsc->priority = rsc->priority;
rpm-build 3ee90c
    }
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
void
rpm-build 3ee90c
promote_demote_constraints(resource_t *rsc, pe_working_set_t *data_set)
rpm-build 3ee90c
{
rpm-build 3ee90c
    /* global stopped before start */
rpm-build 3ee90c
    new_rsc_order(rsc, RSC_STOPPED, rsc, RSC_START, pe_order_optional, data_set);
rpm-build 3ee90c
rpm-build 3ee90c
    /* global stopped before promote */
rpm-build 3ee90c
    new_rsc_order(rsc, RSC_STOPPED, rsc, RSC_PROMOTE, pe_order_optional, data_set);
rpm-build 3ee90c
rpm-build 3ee90c
    /* global demoted before start */
rpm-build 3ee90c
    new_rsc_order(rsc, RSC_DEMOTED, rsc, RSC_START, pe_order_optional, data_set);
rpm-build 3ee90c
rpm-build 3ee90c
    /* global started before promote */
rpm-build 3ee90c
    new_rsc_order(rsc, RSC_STARTED, rsc, RSC_PROMOTE, pe_order_optional, data_set);
rpm-build 3ee90c
rpm-build 3ee90c
    /* global demoted before stop */
rpm-build 3ee90c
    new_rsc_order(rsc, RSC_DEMOTED, rsc, RSC_STOP, pe_order_optional, data_set);
rpm-build 3ee90c
rpm-build 3ee90c
    /* global demote before demoted */
rpm-build 3ee90c
    new_rsc_order(rsc, RSC_DEMOTE, rsc, RSC_DEMOTED, pe_order_optional, data_set);
rpm-build 3ee90c
rpm-build 3ee90c
    /* global demoted before promote */
rpm-build 3ee90c
    new_rsc_order(rsc, RSC_DEMOTED, rsc, RSC_PROMOTE, pe_order_optional, data_set);
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
rpm-build 3ee90c
void
rpm-build 3ee90c
promotable_constraints(resource_t * rsc, pe_working_set_t * data_set)
rpm-build 3ee90c
{
rpm-build 3ee90c
    GListPtr gIter = rsc->children;
rpm-build 3ee90c
    resource_t *last_rsc = NULL;
rpm-build 3ee90c
    clone_variant_data_t *clone_data = NULL;
rpm-build 3ee90c
rpm-build 3ee90c
    get_clone_variant_data(clone_data, rsc);
rpm-build 3ee90c
rpm-build 3ee90c
    promote_demote_constraints(rsc, data_set);
rpm-build 3ee90c
rpm-build 3ee90c
    for (; gIter != NULL; gIter = gIter->next) {
rpm-build 3ee90c
        resource_t *child_rsc = (resource_t *) gIter->data;
rpm-build 3ee90c
rpm-build 3ee90c
        /* child demote before promote */
rpm-build 3ee90c
        new_rsc_order(child_rsc, RSC_DEMOTE, child_rsc, RSC_PROMOTE, pe_order_optional, data_set);
rpm-build 3ee90c
rpm-build 3ee90c
        child_promoting_constraints(clone_data, pe_order_optional,
rpm-build 3ee90c
                                    rsc, child_rsc, last_rsc, data_set);
rpm-build 3ee90c
rpm-build 3ee90c
        child_demoting_constraints(clone_data, pe_order_optional,
rpm-build 3ee90c
                                   rsc, child_rsc, last_rsc, data_set);
rpm-build 3ee90c
rpm-build 3ee90c
        last_rsc = child_rsc;
rpm-build 3ee90c
    }
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
static void
rpm-build 3ee90c
node_hash_update_one(GHashTable * hash, node_t * other, const char *attr, int score)
rpm-build 3ee90c
{
rpm-build 3ee90c
    GHashTableIter iter;
rpm-build 3ee90c
    node_t *node = NULL;
rpm-build 3ee90c
    const char *value = NULL;
rpm-build 3ee90c
rpm-build 3ee90c
    if (other == NULL) {
rpm-build 3ee90c
        return;
rpm-build 3ee90c
rpm-build 3ee90c
    } else if (attr == NULL) {
rpm-build 3ee90c
        attr = CRM_ATTR_UNAME;
rpm-build 3ee90c
    }
rpm-build 3ee90c
 
rpm-build 3ee90c
    value = pe_node_attribute_raw(other, attr);
rpm-build 3ee90c
    g_hash_table_iter_init(&iter, hash);
rpm-build 3ee90c
    while (g_hash_table_iter_next(&iter, NULL, (void **)&node)) {
rpm-build 3ee90c
        const char *tmp = pe_node_attribute_raw(node, attr);
rpm-build 3ee90c
rpm-build 3ee90c
        if (safe_str_eq(value, tmp)) {
rpm-build 3ee90c
            crm_trace("%s: %d + %d", node->details->uname, node->weight, other->weight);
rpm-build 3ee90c
            node->weight = merge_weights(node->weight, score);
rpm-build 3ee90c
        }
rpm-build 3ee90c
    }
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
void
rpm-build 3ee90c
promotable_colocation_rh(resource_t *rsc_lh, resource_t *rsc_rh,
rpm-build 3ee90c
                         rsc_colocation_t *constraint,
rpm-build 3ee90c
                         pe_working_set_t *data_set)
rpm-build 3ee90c
{
rpm-build 3ee90c
    GListPtr gIter = NULL;
rpm-build 3ee90c
rpm-build 3ee90c
    if (is_set(rsc_lh->flags, pe_rsc_provisional)) {
rpm-build 3ee90c
        GListPtr rhs = NULL;
rpm-build 3ee90c
rpm-build 3ee90c
        for (gIter = rsc_rh->children; gIter != NULL; gIter = gIter->next) {
rpm-build 3ee90c
            resource_t *child_rsc = (resource_t *) gIter->data;
rpm-build 3ee90c
            node_t *chosen = child_rsc->fns->location(child_rsc, NULL, FALSE);
rpm-build 3ee90c
            enum rsc_role_e next_role = child_rsc->fns->state(child_rsc, FALSE);
rpm-build 3ee90c
rpm-build 3ee90c
            pe_rsc_trace(rsc_rh, "Processing: %s", child_rsc->id);
rpm-build 3ee90c
            if (chosen != NULL && next_role == constraint->role_rh) {
rpm-build 3ee90c
                pe_rsc_trace(rsc_rh, "Applying: %s %s %s %d", child_rsc->id,
rpm-build 3ee90c
                             role2text(next_role), chosen->details->uname, constraint->score);
rpm-build 3ee90c
                if (constraint->score < INFINITY) {
rpm-build 3ee90c
                    node_hash_update_one(rsc_lh->allowed_nodes, chosen,
rpm-build 3ee90c
                                         constraint->node_attribute, constraint->score);
rpm-build 3ee90c
                }
rpm-build 3ee90c
                rhs = g_list_prepend(rhs, chosen);
rpm-build 3ee90c
            }
rpm-build 3ee90c
        }
rpm-build 3ee90c
rpm-build 3ee90c
        /* Only do this if it's not a master-master colocation
rpm-build 3ee90c
         * Doing this unconditionally would prevent the slaves from being started
rpm-build 3ee90c
         */
rpm-build 3ee90c
        if (constraint->role_lh != RSC_ROLE_MASTER || constraint->role_rh != RSC_ROLE_MASTER) {
rpm-build 3ee90c
            if (constraint->score >= INFINITY) {
rpm-build 3ee90c
                node_list_exclude(rsc_lh->allowed_nodes, rhs, TRUE);
rpm-build 3ee90c
            }
rpm-build 3ee90c
        }
rpm-build 3ee90c
        g_list_free(rhs);
rpm-build 3ee90c
rpm-build 3ee90c
    } else if (constraint->role_lh == RSC_ROLE_MASTER) {
rpm-build 3ee90c
        pe_resource_t *rh_child = find_compatible_child(rsc_lh, rsc_rh,
rpm-build 3ee90c
                                                        constraint->role_rh,
rpm-build 3ee90c
                                                        FALSE, data_set);
rpm-build 3ee90c
rpm-build 3ee90c
        if (rh_child == NULL && constraint->score >= INFINITY) {
rpm-build 3ee90c
            pe_rsc_trace(rsc_lh, "%s can't be promoted %s", rsc_lh->id, constraint->id);
rpm-build 3ee90c
            rsc_lh->priority = -INFINITY;
rpm-build 3ee90c
rpm-build 3ee90c
        } else if (rh_child != NULL) {
rpm-build 3ee90c
            int new_priority = merge_weights(rsc_lh->priority, constraint->score);
rpm-build 3ee90c
rpm-build 3ee90c
            pe_rsc_debug(rsc_lh, "Applying %s to %s", constraint->id, rsc_lh->id);
rpm-build 3ee90c
            pe_rsc_debug(rsc_lh, "\t%s: %d->%d", rsc_lh->id, rsc_lh->priority, new_priority);
rpm-build 3ee90c
            rsc_lh->priority = new_priority;
rpm-build 3ee90c
        }
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    return;
rpm-build 3ee90c
}