Skip to content

Commit

Permalink
High: Cluster: Allow cman and corosync 2.0 nodes to use a name other …
Browse files Browse the repository at this point in the history
…than uname()
  • Loading branch information
beekhof committed Sep 24, 2012
1 parent ec40999 commit 4f88cb1
Show file tree
Hide file tree
Showing 19 changed files with 279 additions and 145 deletions.
1 change: 0 additions & 1 deletion TODO.markdown
Expand Up @@ -2,7 +2,6 @@

## Targeted for 1.2
- Need a way to indicate when unfencing operations need to be initiated from the host to be unfenced
- Remove all calls to uname() and replace with get_node_name() whcih redirects to ${stack}_node_name()

## Targeted for 1.2.x

Expand Down
4 changes: 2 additions & 2 deletions crmd/election.c
Expand Up @@ -166,7 +166,7 @@ struct election_data_s {
};

static void
log_member_uname(gpointer key, gpointer value, gpointer user_data)
log_member_name(gpointer key, gpointer value, gpointer user_data)
{
const crm_node_t *node = value;

Expand Down Expand Up @@ -208,7 +208,7 @@ do_election_check(long long action,
char *data = NULL;

data = strdup("member");
g_hash_table_foreach(crm_peer_cache, log_member_uname, data);
g_hash_table_foreach(crm_peer_cache, log_member_name, data);
free(data);

data = strdup("voted");
Expand Down
1 change: 0 additions & 1 deletion include/crm/cib/util.h
Expand Up @@ -71,7 +71,6 @@ int set_standby(cib_t * the_cib, const char *uuid, const char *scope, const char

xmlNode *get_cib_copy(cib_t * cib);
xmlNode *cib_get_generation(cib_t * cib);
gboolean determine_host(cib_t * cib_conn, char **node_uname, char **node_uuid);

void cib_metadata(void);
const char *cib_pref(GHashTable * options, const char *name);
Expand Down
3 changes: 3 additions & 0 deletions include/crm/cluster.h
Expand Up @@ -170,4 +170,7 @@ gboolean is_openais_cluster(void);
gboolean is_classic_ais_cluster(void);
gboolean is_heartbeat_cluster(void);

char *get_local_node_name(void);
char *get_node_name(uint32_t nodeid);

#endif
17 changes: 17 additions & 0 deletions include/crm/cluster/internal.h
Expand Up @@ -25,6 +25,10 @@
# define AIS_IPC_MESSAGE_SIZE 8192*128
# define CRM_MESSAGE_IPC_ACK 0

#ifndef INTERFACE_MAX
# define INTERFACE_MAX 2 /* from the private coroapi.h header */
#endif

typedef struct crm_ais_host_s AIS_Host;
typedef struct crm_ais_msg_s AIS_Message;

Expand Down Expand Up @@ -344,6 +348,12 @@ gboolean heartbeat_initialize_nodelist(void *cluster, gboolean force_member, xml

# if SUPPORT_COROSYNC

# if SUPPORT_PLUGIN
char *classic_node_name(uint32_t nodeid);
# else
char *corosync_node_name(uint64_t /*cmap_handle_t*/ cmap_handle, uint32_t nodeid);
# endif

gboolean corosync_initialize_nodelist(void *cluster, gboolean force_member, xmlNode *xml_parent);

gboolean send_ais_message(xmlNode * msg, gboolean local,
Expand All @@ -356,6 +366,10 @@ gboolean init_cs_connection(crm_cluster_t *cluster);
gboolean init_cs_connection_once(crm_cluster_t *cluster);
# endif

#ifdef SUPPORT_CMAN
char *cman_node_name(uint32_t nodeid);
#endif

enum crm_quorum_source {
crm_quorum_cman,
crm_quorum_corosync,
Expand All @@ -381,4 +395,7 @@ gboolean init_quorum_connection(
gboolean(*dispatch) (unsigned long long, gboolean), void (*destroy) (gpointer));

void set_node_uuid(const char *uname, const char *uuid);

gboolean node_name_is_valid(const char *key, const char *name);

#endif
7 changes: 7 additions & 0 deletions lib/cib/cib_attrs.c
Expand Up @@ -451,6 +451,13 @@ query_node_uuid(cib_t * the_cib, const char *uname, char **uuid)
}
}
}

if (rc != pcmk_ok) {
crm_debug("Could not map name=%s to a UUID: %s\n", uname, pcmk_strerror(rc));
} else {
crm_info("Mapped %s to %s", uname, *uuid);
}

free_xml(fragment);
return rc;
}
Expand Down
29 changes: 0 additions & 29 deletions lib/cib/cib_utils.c
Expand Up @@ -674,35 +674,6 @@ cib_native_notify(gpointer data, gpointer user_data)
crm_trace("Callback invoked...");
}

gboolean
determine_host(cib_t * cib_conn, char **node_uname, char **node_uuid)
{
CRM_CHECK(node_uname != NULL, return FALSE);

if (*node_uname == NULL) {
struct utsname name;

if (uname(&name) < 0) {
crm_perror(LOG_ERR, "uname(2) call failed");
return FALSE;
}
*node_uname = strdup(name.nodename);
crm_info("Detected uname: %s", *node_uname);
}

if (cib_conn && *node_uname != NULL && node_uuid != NULL && *node_uuid == NULL) {
int rc = query_node_uuid(cib_conn, *node_uname, node_uuid);

if (rc != pcmk_ok) {
fprintf(stderr, "Could not map uname=%s to a UUID: %s\n",
*node_uname, pcmk_strerror(rc));
return FALSE;
}
crm_info("Mapped %s to %s", *node_uname, crm_str(*node_uuid));
}
return TRUE;
}

pe_cluster_option cib_opts[] = {
/* name, old-name, validate, default, description */
{"enable-acl", NULL, "boolean", NULL, "false", &check_boolean,
Expand Down
105 changes: 103 additions & 2 deletions lib/cluster/cluster.c
Expand Up @@ -19,13 +19,14 @@
#include <crm_internal.h>
#include <dlfcn.h>

#include <sys/param.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/utsname.h>

#include <crm/crm.h>
#include <crm/msg_xml.h>
Expand Down Expand Up @@ -344,6 +345,85 @@ get_uuid(const char *uname)
return get_node_uuid(0, uname);
}

char *
get_local_node_name(void)
{
int rc;
char *name = NULL;
struct utsname res;
enum cluster_type_e stack = get_cluster_type();

switch(stack) {

#if SUPPORT_CMAN
case pcmk_cluster_cman:
name = cman_node_name(0 /* AKA. CMAN_NODEID_US */);
break;
#endif

#if SUPPORT_COROSYNC
# if !SUPPORT_PLUGIN
case pcmk_cluster_corosync:
name = corosync_node_name(0, 0);
break;
# endif
#endif
case pcmk_cluster_heartbeat:
case pcmk_cluster_classic_ais:
rc = uname(&res);
if(rc == 0) {
name = strdup(res.nodename);
}
break;
default:
crm_err("Unknown cluster type: %s (%d)", name_for_cluster_type(stack), stack);
}

if(name == NULL) {
crm_err("Could not obtain the local %s node name", name_for_cluster_type(stack));
exit(100);
}
return name;
}

char *
get_node_name(uint32_t nodeid)
{
char *name = NULL;
enum cluster_type_e stack = get_cluster_type();

switch (stack) {
case pcmk_cluster_heartbeat:
break;

#if SUPPORT_PLUGIN
case pcmk_cluster_classic_ais:
name = classic_node_name(nodeid);
break;
#else
case pcmk_cluster_corosync:
name = corosync_node_name(0, nodeid);
break;
#endif

#if SUPPORT_CMAN
case pcmk_cluster_cman:
name = cman_node_name(nodeid);
break;
#endif

default:
crm_err("Unknown cluster type: %s (%d)", name_for_cluster_type(stack), stack);
}

if(name == NULL) {
crm_notice("Could not obtain a node name for %s nodeid %u",
name_for_cluster_type(stack), nodeid);
}
return name;
}

/* Only used by te_utils.c */
const char *
get_uname(const char *uuid)
{
Expand Down Expand Up @@ -563,3 +643,24 @@ is_heartbeat_cluster(void)
{
return get_cluster_type() == pcmk_cluster_heartbeat;
}

gboolean
node_name_is_valid(const char *key, const char *name)
{
int octet;

if(name == NULL) {
crm_trace("%s is empty", key);
return FALSE;

} else if(sscanf(name, "%d.%d.%d.%d", &octet, &octet, &octet, &octet) == 4) {
crm_trace("%s contains an ipv4 address, ignoring: %s", key, name);
return FALSE;

} else if(strstr(name, ":") != NULL) {
crm_trace("%s contains an ipv6 address, ignoring: %s", key, name);
return FALSE;
}
crm_trace("%s is valid", key);
return TRUE;
}
69 changes: 30 additions & 39 deletions lib/cluster/corosync.c
Expand Up @@ -66,36 +66,11 @@ static uint32_t pcmk_nodeid = 0;
} \
} while(counter < max)

#ifndef INTERFACE_MAX
# define INTERFACE_MAX 2 /* from the private coroapi.h header */
#endif

static gboolean
corosync_name_is_valid(const char *key, const char *name)
{
int octet;

if(name == NULL) {
crm_trace("%s is empty", key);
return FALSE;

} else if(sscanf(name, "%d.%d.%d.%d", &octet, &octet, &octet, &octet) == 4) {
crm_trace("%s contains an ipv4 address, ignoring: %s", key, name);
return FALSE;

} else if(strstr(name, ":") != NULL) {
crm_trace("%s contains an ipv4 address, ignoring: %s", key, name);
return FALSE;
}
crm_trace("%s is valid", key);
return TRUE;
}

/*
* CFG functionality stolen from node_name() in corosync-quorumtool.c
* This resolves the first address assigned to a node and returns the name or IP address.
*/
static char *corosync_node_name(cmap_handle_t cmap_handle, uint32_t nodeid)
char *corosync_node_name(uint64_t /*cmap_handle_t*/ cmap_handle, uint32_t nodeid)
{
int lpc = 0;
int rc = CS_OK;
Expand All @@ -106,6 +81,29 @@ static char *corosync_node_name(cmap_handle_t cmap_handle, uint32_t nodeid)
corosync_cfg_handle_t cfg_handle = 0;
static corosync_cfg_callbacks_t cfg_callbacks = {};

/* nodeid == 0 == CMAN_NODEID_US */
if(nodeid == 0 && pcmk_nodeid) {
nodeid = pcmk_nodeid;

} else if(nodeid == 0) {
/* Look it up */
int rc = -1;
int retries = 0;
cpg_handle_t handle = 0;
cpg_callbacks_t cb = {};

cs_repeat(retries, 5, rc = cpg_initialize(&handle, &cb));
if (rc == CS_OK) {
retries = 0;
cs_repeat(retries, 5, rc = cpg_local_get(handle, &pcmk_nodeid));
}

if (rc != CS_OK) {
crm_err("Could not get local node id from the CPG API: %d", rc);
}
cpg_finalize(handle);
}

if(cmap_handle == 0 && local_handle == 0) {
retries = 0;
crm_trace("Initializing CMAP connection");
Expand All @@ -120,7 +118,7 @@ static char *corosync_node_name(cmap_handle_t cmap_handle, uint32_t nodeid)
} while(retries < 5 && rc != CS_OK);

if (rc != CS_OK) {
crm_warn("Could not connect to Cluster Configuration Database API, error %d", cs_strerror(rc));
crm_warn("Could not connect to Cluster Configuration Database API, error %s", cs_strerror(rc));
local_handle = 0;
}
}
Expand Down Expand Up @@ -149,7 +147,7 @@ static char *corosync_node_name(cmap_handle_t cmap_handle, uint32_t nodeid)
rc = cmap_get_string(cmap_handle, key, &name);
crm_trace("%s = %s", key, name);

if(corosync_name_is_valid(key, name) == FALSE) {
if(node_name_is_valid(key, name) == FALSE) {
free(name); name = NULL;
}
g_free(key);
Expand All @@ -160,7 +158,7 @@ static char *corosync_node_name(cmap_handle_t cmap_handle, uint32_t nodeid)
rc = cmap_get_string(cmap_handle, key, &name);
crm_trace("%s = %s %d", key, name, rc);

if(corosync_name_is_valid(key, name) == FALSE) {
if(node_name_is_valid(key, name) == FALSE) {
free(name); name = NULL;
}
g_free(key);
Expand Down Expand Up @@ -210,14 +208,14 @@ static char *corosync_node_name(cmap_handle_t cmap_handle, uint32_t nodeid)
if (getnameinfo((struct sockaddr *)addrs[0].address, addrlen, buf, sizeof(buf), NULL, 0, 0) == 0) {
crm_notice("Inferred node name '%s' for nodeid %u from DNS", buf, nodeid);

if(corosync_name_is_valid("DNS", buf)) {
if(node_name_is_valid("DNS", buf)) {
name = strdup(buf);
}
}
} else {
crm_debug("Unable to get node address for nodeid %u: %s", nodeid, cs_strerror(rc));
}
cmap_finalize(cfg_handle);
corosync_cfg_finalize(cfg_handle);
}

if(local_handle) {
Expand Down Expand Up @@ -886,7 +884,6 @@ init_cs_connection(crm_cluster_t *cluster)
gboolean
init_cs_connection_once(crm_cluster_t *cluster)
{
struct utsname res;
enum cluster_type_e stack = get_cluster_type();

crm_peer_init();
Expand All @@ -899,14 +896,8 @@ init_cs_connection_once(crm_cluster_t *cluster)

if (init_cpg_connection(cluster->cs_dispatch, cluster->destroy, &pcmk_nodeid) == FALSE) {
return FALSE;
} else if (uname(&res) < 0) {
crm_perror(LOG_ERR, "Could not determin the current host");
exit(100);

} else {
pcmk_uname = strdup(res.nodename);
}

pcmk_uname = get_local_node_name();
crm_info("Connection to '%s': established", name_for_cluster_type(stack));

CRM_ASSERT(pcmk_uname != NULL);
Expand Down

0 comments on commit 4f88cb1

Please sign in to comment.