Пример #1
0
char *
get_corosync_uuid(uint32_t id, const char *uname)
{
    if (!uname_is_uuid() && is_corosync_cluster()) {
        if (id <= 0) {
            /* Try the membership cache... */
            crm_node_t *node = g_hash_table_lookup(crm_peer_cache, uname);

            if (node != NULL) {
                id = node->id;
            }
        }

        if (id > 0) {
            int len = 32;
            char *buffer = NULL;

            buffer = calloc(1, (len + 1));
            if (buffer != NULL) {
                snprintf(buffer, len, "%u", id);
            }

            return buffer;

        } else {
            crm_warn("Node %s is not yet known by corosync", uname);
        }

    } else if (uname != NULL) {
        return strdup(uname);
    }

    return NULL;
}
Пример #2
0
char *
get_corosync_uuid(crm_node_t *node)
{
    if(node == NULL) {
        return NULL;

    } else if (!uname_is_uuid() && is_corosync_cluster()) {
        if (node->id > 0) {
            int len = 32;
            char *buffer = NULL;

            buffer = calloc(1, (len + 1));
            if (buffer != NULL) {
                snprintf(buffer, len, "%u", node->id);
            }

            return buffer;

        } else {
            crm_info("Node %s is not yet known by corosync", node->uname);
        }

    } else if (node->uname != NULL) {
        return strdup(node->uname);
    }

    return NULL;
}
Пример #3
0
char *
get_corosync_uuid(uint32_t id, const char *uname)
{
    if (!uname_is_uuid() && is_corosync_cluster()) {
        if (id <= 0) {
            /* Try the membership cache... */
            crm_node_t *node = g_hash_table_lookup(crm_peer_cache, uname);

            if (node != NULL) {
                id = node->id;
            }
        }

        if (id > 0) {
            return crm_itoa(id);
        } else {
            crm_warn("Node %s is not yet known by corosync", uname);
        }

    } else if (uname != NULL) {
        return strdup(uname);
    }

    return NULL;
}
Пример #4
0
int get_corosync_id(int id, const char *uuid) 
{
    if(id == 0 && !uname_is_uuid() && is_corosync_cluster()) {
        id = crm_atoi(uuid, "0");
    }
    
    return id;
}
Пример #5
0
const char *
crm_peer_uname(const char *uuid)
{
    GHashTableIter iter;
    crm_node_t *node = NULL;

    CRM_CHECK(uuid != NULL, return NULL);

    /* remote nodes have the same uname and uuid */
    if (g_hash_table_lookup(crm_remote_peer_cache, uuid)) {
        return uuid;
    }

    /* avoid blocking calls where possible */
    g_hash_table_iter_init(&iter, crm_peer_cache);
    while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &node)) {
        if(node->uuid && strcasecmp(node->uuid, uuid) == 0) {
            if(node->uname) {
                return node->uname;
            }
            break;
        }
    }

#if SUPPORT_COROSYNC
    if (is_openais_cluster()) {
        if (uname_is_uuid() == FALSE && is_corosync_cluster()) {
            uint32_t id = crm_int_helper(uuid, NULL);
            if(id != 0) {
                node = crm_find_peer(id, NULL);
            } else {
                crm_err("Invalid node id: %s", uuid);
            }

        } else {
            node = crm_find_peer(0, uuid);
        }

        if (node) {
            crm_info("Setting uuid for node %s[%u] to '%s'", node->uname, node->id, uuid);
            node->uuid = strdup(uuid);
            if(node->uname) {
                return node->uname;
            }
        }
        return NULL;
    }
#endif

#if SUPPORT_HEARTBEAT
    if (is_heartbeat_cluster()) {
        if (heartbeat_cluster != NULL) {
            cl_uuid_t uuid_raw;
            char *uuid_copy = strdup(uuid);
            char *uname = malloc(MAX_NAME);

            cl_uuid_parse(uuid_copy, &uuid_raw);

            if (heartbeat_cluster->llc_ops->get_name_by_uuid(heartbeat_cluster, &uuid_raw, uname,
                                                             MAX_NAME) == HA_FAIL) {
                crm_err("Could not calculate uname for %s", uuid);
            } else {
                node = crm_get_peer(0, uname);
            }

            free(uuid_copy);
            free(uname);
        }

        if (node) {
            crm_info("Setting uuid for node %s to '%s'", node->uname, uuid);
            node->uuid = strdup(uuid);
            if(node->uname) {
                return node->uname;
            }
        }
        return NULL;
    }
#endif

    return NULL;
}