# HG changeset patch
# User Andrew Beekhof <andrew@beekhof.net>
# Date 1260359389 -3600
# Branch stable-1.0
# Node ID 66b7bfd467f3de43b7921474711cd9158fbb2721
# Parent  1b98663ac3ee3c035537da08c3e14ac473a7463d
Medium: ais: Some clients such as gfs_controld want a cluster name, allow one to be specified in corosync.conf

diff -r 1b98663ac3ee -r 66b7bfd467f3 include/crm/ais.h
--- a/include/crm/ais.h	Tue Dec 08 09:07:49 2009 +0100
+++ b/include/crm/ais.h	Wed Dec 09 12:49:49 2009 +0100
@@ -220,6 +220,7 @@ struct crm_ais_nodeid_resp_s
 	uint32_t		id;	
 	uint32_t		counter;
 	char			uname[MAX_NAME];
+	char			cname[MAX_NAME];
 } __attribute__((packed));
 
 struct crm_ais_quorum_resp_s
diff -r 1b98663ac3ee -r 66b7bfd467f3 include/crm/common/cluster.h
--- a/include/crm/common/cluster.h	Tue Dec 08 09:07:49 2009 +0100
+++ b/include/crm/common/cluster.h	Wed Dec 09 12:49:49 2009 +0100
@@ -67,6 +67,7 @@ extern guint crm_active_peers(uint32_t p
 extern gboolean crm_calculate_quorum(void);
 extern int crm_terminate_member(int nodeid, const char *uname, IPC_Channel *cluster);
 extern int crm_terminate_member_no_mainloop(int nodeid, const char *uname, int *connection);
+extern gboolean crm_get_cluster_name(char **cname);
 
 #if SUPPORT_HEARTBEAT
 extern gboolean ccm_have_quorum(oc_ed_t event);
diff -r 1b98663ac3ee -r 66b7bfd467f3 lib/ais/plugin.c
--- a/lib/ais/plugin.c	Tue Dec 08 09:07:49 2009 +0100
+++ b/lib/ais/plugin.c	Wed Dec 09 12:49:49 2009 +0100
@@ -62,6 +62,8 @@ int use_mgmtd = 0;
 int plugin_log_level = LOG_DEBUG;
 char *local_uname = NULL;
 int local_uname_len = 0;
+char *local_cname = NULL;
+int local_cname_len = 0;
 uint32_t local_nodeid = 0;
 char *ipc_channel_name = NULL;
 static uint64_t local_born_on = 0;
@@ -365,6 +367,9 @@ static void process_ais_conf(void)
 	local_handle = config_find_next(pcmk_api, "service", top_handle);
     }
 
+    get_config_opt(pcmk_api, local_handle, "clustername", &local_cname, "pcmk");
+    local_cname_len = strlen(local_cname);
+    
     get_config_opt(pcmk_api, local_handle, "use_logd", &value, "no");
     setenv("HA_use_logd", value, 1);
 
@@ -1197,8 +1202,10 @@ void pcmk_nodeid(void *conn, ais_void_pt
     resp.header.error = CS_OK;
     resp.id = local_nodeid;
     resp.counter = counter++;
-    memset(resp.uname, 0, 256);
+    memset(resp.uname, 0, MAX_NAME);
     memcpy(resp.uname, local_uname, local_uname_len);
+    memset(resp.cname, 0, MAX_NAME);
+    memcpy(resp.cname, local_cname, local_cname_len);
     
 #ifdef AIS_COROSYNC
     pcmk_api->ipc_response_send (conn, &resp, resp.header.size);
diff -r 1b98663ac3ee -r 66b7bfd467f3 lib/common/ais.c
--- a/lib/common/ais.c	Tue Dec 08 09:07:49 2009 +0100
+++ b/lib/common/ais.c	Wed Dec 09 12:49:49 2009 +0100
@@ -101,6 +101,7 @@ void *ais_ipc_ctx = NULL;
 #endif
 GFDSource *ais_source = NULL;
 GFDSource *ais_source_sync = NULL;
+static char *ais_cluster_name = NULL;
 
 gboolean get_ais_nodeid(uint32_t *id, char **uname)
 {
@@ -156,13 +157,26 @@ gboolean get_ais_nodeid(uint32_t *id, ch
 	return FALSE;
     }
 
-    crm_info("Server details: id=%u uname=%s", answer.id, answer.uname);
+    crm_info("Server details: id=%u uname=%s cname=%s",
+	     answer.id, answer.uname, answer.cname);
     
     *id = answer.id;
     *uname = crm_strdup(answer.uname);
+    ais_cluster_name = crm_strdup(answer.cname);
+
     return TRUE;
 }
 
+gboolean crm_get_cluster_name(char **cname)
+{
+    CRM_CHECK(cname != NULL, return FALSE);
+    if(ais_cluster_name) {
+	*cname = crm_strdup(ais_cluster_name);
+	return TRUE;
+    }
+    return FALSE;
+}
+
 gboolean
 send_ais_text(int class, const char *data,
 	      gboolean local, const char *node, enum crm_ais_msg_types dest)
