[sheepdog] [PATCH] sheep: rework send join message for corosync and local drivers

Liu Yuan namei.unix at gmail.com
Sun Oct 13 13:29:12 CEST 2013


They can't send the whole struct cluster_info. Instead of doing tricks in
send_join_request(), we just min(SD_MAX_EVENT_BUF_SIZE, join_msg_len) for
corosync and local drivers.

This patch also fixes a bug that corosync can't work with node join because
not enough buffer allocated for join message.

Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 sheep/cluster/corosync.c  |    7 ++++---
 sheep/cluster/local.c     |    2 ++
 sheep/cluster/zookeeper.c |    5 ++---
 sheep/group.c             |    4 +---
 4 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/sheep/cluster/corosync.c b/sheep/cluster/corosync.c
index 45756e8..8af1efe 100644
--- a/sheep/cluster/corosync.c
+++ b/sheep/cluster/corosync.c
@@ -168,9 +168,11 @@ static int send_message(enum corosync_message_type type,
 {
 	struct iovec iov[2];
 	int ret, iov_cnt = 1;
+	size_t mlen = msg_len > SD_MAX_EVENT_BUF_SIZE ?
+		SD_MAX_EVENT_BUF_SIZE : msg_len;
 	struct corosync_message cmsg = {
 		.type = type,
-		.msg_len = msg_len,
+		.msg_len = mlen,
 		.sender = *sender,
 		.nr_nodes = nr_nodes,
 	};
@@ -182,7 +184,7 @@ static int send_message(enum corosync_message_type type,
 	iov[0].iov_len = sizeof(cmsg);
 	if (msg) {
 		iov[1].iov_base = msg;
-		iov[1].iov_len = msg_len;
+		iov[1].iov_len = mlen;
 		iov_cnt++;
 	}
 retry:
@@ -640,7 +642,6 @@ static int corosync_join(const struct sd_node *myself,
 			 void *opaque, size_t opaque_len)
 {
 	int ret;
-
 retry:
 	ret = cpg_join(cpg_handle, &cpg_group);
 	switch (ret) {
diff --git a/sheep/cluster/local.c b/sheep/cluster/local.c
index 824279c..be2c216 100644
--- a/sheep/cluster/local.c
+++ b/sheep/cluster/local.c
@@ -257,6 +257,8 @@ static int add_event(enum local_event_type type, struct local_node *lnode,
 		.sender = *lnode,
 	};
 
+	buf_len = buf_len > SD_MAX_EVENT_BUF_SIZE ?
+		SD_MAX_EVENT_BUF_SIZE : buf_len;
 	ev.buf_len = buf_len;
 	if (buf)
 		memcpy(ev.buf, buf, buf_len);
diff --git a/sheep/cluster/zookeeper.c b/sheep/cluster/zookeeper.c
index 7ce8180..fa89c46 100644
--- a/sheep/cluster/zookeeper.c
+++ b/sheep/cluster/zookeeper.c
@@ -561,15 +561,14 @@ static void zk_watcher(zhandle_t *zh, int type, int state, const char *path,
 static int add_join_event(void *msg, size_t msglen)
 {
 	struct zk_event ev;
-	size_t msg_len = sizeof(struct cluster_info);
-	size_t len = msg_len + sizeof(struct sd_node) * SD_MAX_NODES;
+	size_t len = msglen + sizeof(struct sd_node) * SD_MAX_NODES;
 
 	if (unlikely((offsetof(struct zk_event, buf) + len) > ZK_MAX_BUF_SIZE))
 		panic("Zookeeper can't send message more than 1M");
 	ev.id = get_uniq_id();
 	ev.type = EVENT_JOIN;
 	ev.sender = this_node;
-	ev.msg_len = msg_len;
+	ev.msg_len = msglen;
 	ev.buf_len = len;
 	if (msg)
 		memcpy(ev.buf, msg, msglen);
diff --git a/sheep/group.c b/sheep/group.c
index 16f1532..4328547 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -773,11 +773,9 @@ main_fn bool sd_join_handler(const struct sd_node *joining,
 static int send_join_request(void)
 {
 	struct sd_node *n = &sys->this_node;
-	int len = offsetof(struct cluster_info, nodes) +
-		sys->cinfo.nr_nodes * sizeof(struct sd_node);
 
 	sd_info("%s", node_to_str(n));
-	return sys->cdrv->join(n, &sys->cinfo, len);
+	return sys->cdrv->join(n, &sys->cinfo, sizeof(sys->cinfo));
 }
 
 static void requeue_cluster_request(void)
-- 
1.7.9.5




More information about the sheepdog mailing list