[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] cluster/group/daemon app.c cpg.c gd_internal.h



CVSROOT:	/cvs/cluster
Module name:	cluster
Branch: 	RHEL50
Changes by:	teigland sourceware org	2007-01-05 19:56:09

Modified files:
	group/daemon   : app.c cpg.c gd_internal.h 

Log message:
	groupd creates uint32 global id's for each group.  It doesn't
	use them itself, but provides them to each registered app to use
	if it wants.  (The dlm and gfs each use the global id in messages
	to distinguish between different lockspaces/fs's.)  groupd's
	method of creating these gid's (local counter | local nodeid)
	can result in duplicate gid's in the cluster given a somewhat
	uncommon sequence of events.
	bz 221629

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/group/daemon/app.c.diff?cvsroot=cluster&only_with_tag=RHEL50&r1=1.52.4.1&r2=1.52.4.2
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/group/daemon/cpg.c.diff?cvsroot=cluster&only_with_tag=RHEL50&r1=1.36.4.1&r2=1.36.4.2
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/group/daemon/gd_internal.h.diff?cvsroot=cluster&only_with_tag=RHEL50&r1=1.44.4.1&r2=1.44.4.2

--- cluster/group/daemon/app.c	2006/12/01 20:27:36	1.52.4.1
+++ cluster/group/daemon/app.c	2007/01/05 19:56:09	1.52.4.2
@@ -21,6 +21,8 @@
 		return "recover";
 	case MSG_APP_INTERNAL:
 		return "internal";
+	case MSG_GLOBAL_ID:
+		return "global_id";
 	}
 	return "unknown";
 }
--- cluster/group/daemon/cpg.c	2006/12/01 20:27:36	1.36.4.1
+++ cluster/group/daemon/cpg.c	2007/01/05 19:56:09	1.36.4.2
@@ -149,10 +149,47 @@
 	queue_app_leave(g, nodeid);
 }
 
+static uint32_t max_global_id(uint32_t add_nodeid)
+{
+	group_t *g;
+	uint32_t nodeid, counter, max_counter = 0, max_gid = 0;
+
+	list_for_each_entry(g, &gd_groups, list) {
+		nodeid = g->global_id & 0x0000FFFF;
+		counter = (g->global_id >> 16) & 0x0000FFFF;
+		if (nodeid != add_nodeid)
+			continue;
+		if (!max_counter || counter > max_counter) {
+			max_counter = counter;
+			max_gid = g->global_id;
+		}
+	}
+	return max_gid;
+}
+
+static int send_gid(uint32_t gid)
+{
+	group_t g;
+	msg_t msg;
+
+	/* just so log_group will work */
+	memset(&g, 0, sizeof(group_t));
+	strcpy(g.name, "groupd");
+
+	memset(&msg, 0, sizeof(msg));
+	msg.ms_type = MSG_GLOBAL_ID;
+	msg.ms_global_id = gid;
+
+	msg_bswap_out(&msg);
+
+	return send_message_groupd(&g, &msg, sizeof(msg), MSG_GLOBAL_ID);
+}
+
 void process_groupd_confchg(void)
 {
 	struct recovery_set *rs;
 	int i, found = 0;
+	uint32_t gid;
 
 	log_debug("groupd confchg total %d left %d joined %d",
 		  saved_member_count, saved_left_count, saved_joined_count);
@@ -167,6 +204,23 @@
 		}
 	}
 
+	if (!groupd_joined)
+		goto next;
+
+	/* find any groups that were created in the past by a new node
+	   and send it the id it used so it can initialize global_id_counter
+	   to avoid creating a new group with a duplicate id */
+
+	for (i = 0; i < saved_joined_count; i++) {
+		gid = max_global_id(saved_joined[i].nodeid);
+		if (!gid)
+			continue;
+		log_debug("joined node %d had old max gid %x",
+			  saved_joined[i].nodeid, gid);
+		send_gid(gid);
+	}
+
+ next:
 	if (found)
 		groupd_joined = 1;
 	else
@@ -235,12 +289,26 @@
 	msg_t *msg = (msg_t *) data;
 	char *buf;
 	char name[MAX_NAMELEN+1];
+	uint32_t to_nodeid, counter;
 	int len;
 
 	memset(&name, 0, sizeof(name));
 
 	msg_bswap_in(msg);
 
+	if (msg->ms_type == MSG_GLOBAL_ID) {
+		to_nodeid = msg->ms_global_id & 0x0000FFFF;
+		counter = (msg->ms_global_id >> 16) & 0x0000FFFF;
+
+		if (to_nodeid == our_nodeid) {
+			log_debug("recv global_id %x from %u cur counter %u",
+			  	  msg->ms_global_id, nodeid, global_id_counter);
+			if (counter > global_id_counter)
+				global_id_counter = counter;
+		}
+		return;
+	}
+
 	if (handle == groupd_handle) {
 		memcpy(&name, &msg->ms_name, MAX_NAMELEN);
 
--- cluster/group/daemon/gd_internal.h	2006/12/01 20:27:36	1.44.4.1
+++ cluster/group/daemon/gd_internal.h	2007/01/05 19:56:09	1.44.4.2
@@ -189,6 +189,7 @@
 #define MSG_APP_STARTED        2
 #define MSG_APP_RECOVER        3
 #define MSG_APP_INTERNAL       4
+#define MSG_GLOBAL_ID          5
 
 #define MSG_VER_MAJOR          1
 #define MSG_VER_MINOR          0


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]