Beispiel #1
0
const char *
get_node_uuid(uint32_t id, const char *uname)
{
    char *uuid = NULL;
    enum cluster_type_e type = get_cluster_type();

    if (crm_uuid_cache == NULL) {
        crm_uuid_cache = g_hash_table_new_full(crm_str_hash, g_str_equal,
                                               g_hash_destroy_str, g_hash_destroy_str);
    }

    /* avoid blocking heartbeat calls where possible */
    if (uname) {
        uuid = g_hash_table_lookup(crm_uuid_cache, uname);
    }
    if (uuid != NULL) {
        return uuid;
    }

    switch (type) {
        case pcmk_cluster_corosync:
            uuid = get_corosync_uuid(id, uname);
            break;

        case pcmk_cluster_cman:
        case pcmk_cluster_classic_ais:
            if (uname) {
                uuid = strdup(uname);
            }
            break;

        case pcmk_cluster_heartbeat:
            uuid = get_heartbeat_uuid(id, uname);
            break;

        case pcmk_cluster_unknown:
        case pcmk_cluster_invalid:
            crm_err("Unsupported cluster type");
            break;
    }

    if (uuid == NULL) {
        return NULL;
    }

    if (uname) {
        g_hash_table_insert(crm_uuid_cache, strdup(uname), uuid);
        return g_hash_table_lookup(crm_uuid_cache, uname);
    }

    /* Memory leak! */
    CRM_LOG_ASSERT(uuid != NULL);
    return uuid;
}
Beispiel #2
0
const char *
crm_peer_uuid(crm_node_t *peer)
{
    char *uuid = NULL;
    enum cluster_type_e type = get_cluster_type();

    /* avoid blocking heartbeat calls where possible */
    if(peer == NULL) {
        return NULL;

    } else if (peer->uuid) {
        return peer->uuid;
    }

    switch (type) {
        case pcmk_cluster_corosync:
            uuid = get_corosync_uuid(peer);
            break;

        case pcmk_cluster_cman:
        case pcmk_cluster_classic_ais:
            if (peer->uname) {
                uuid = strdup(peer->uname);
            }
            break;

        case pcmk_cluster_heartbeat:
            uuid = get_heartbeat_uuid(peer->uname);
            break;

        case pcmk_cluster_unknown:
        case pcmk_cluster_invalid:
            crm_err("Unsupported cluster type");
            break;
    }

    peer->uuid = uuid;
    return peer->uuid;
}