[Sheepdog] [PATCH 4/7] sheep: clean up struct join_message

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Wed Oct 12 15:22:16 CEST 2011


Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 sheep/group.c |   48 ++++++++++++++++++------------------------------
 1 files changed, 18 insertions(+), 30 deletions(-)

diff --git a/sheep/group.c b/sheep/group.c
index 4f5724c..f9958c3 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -45,7 +45,8 @@ struct message_header {
 
 struct join_message {
 	struct message_header header;
-	uint32_t nr_nodes;
+	uint16_t nr_nodes;
+	uint16_t nr_leave_nodes;
 	uint32_t nr_sobjs;
 	uint32_t cluster_status;
 	uint32_t epoch;
@@ -53,13 +54,10 @@ struct join_message {
 	uint32_t result;
 	uint8_t inc_epoch; /* set non-zero when we increment epoch of all nodes */
 	uint8_t pad[3];
-	struct {
-		struct sheepdog_node_list_entry ent;
-	} nodes[SD_MAX_NODES];
-	uint32_t nr_leave_nodes;
-	struct {
-		struct sheepdog_node_list_entry ent;
-	} leave_nodes[SD_MAX_NODES];
+	union {
+		struct sheepdog_node_list_entry nodes[SD_MAX_NODES];
+		struct sheepdog_node_list_entry leave_nodes[SD_MAX_NODES];
+	};
 };
 
 struct vdi_op_message {
@@ -511,19 +509,13 @@ static int get_cluster_status(struct sheepdog_node_list_entry *from,
 
 static void join(struct join_message *msg)
 {
-	struct sheepdog_node_list_entry entry[SD_MAX_NODES];
-	int i;
-
 	if (msg->header.proto_ver != SD_SHEEP_PROTO_VER) {
 		eprintf("joining node send a wrong version message\n");
 		msg->result = SD_RES_VER_MISMATCH;
 		return;
 	}
 
-	for (i = 0; i < msg->nr_nodes; i++)
-		entry[i] = msg->nodes[i].ent;
-
-	msg->result = get_cluster_status(&msg->header.from, entry,
+	msg->result = get_cluster_status(&msg->header.from, msg->nodes,
 					 msg->nr_nodes, msg->ctime,
 					 msg->epoch, &msg->cluster_status,
 					 &msg->inc_epoch);
@@ -667,13 +659,13 @@ static void update_cluster_info(struct join_message *msg,
 			if (!n)
 				panic("oom\n");
 
-			if (find_entry_list(&msg->leave_nodes[i].ent, &sys->leave_list)
-			    || !find_entry_epoch(&msg->leave_nodes[i].ent, le)) {
+			if (find_entry_list(&msg->leave_nodes[i], &sys->leave_list)
+			    || !find_entry_epoch(&msg->leave_nodes[i], le)) {
 				free(n);
 				continue;
 			}
 
-			n->ent = msg->leave_nodes[i].ent;
+			n->ent = msg->leave_nodes[i];
 
 			list_add_tail(&n->list, &sys->leave_list);
 		}
@@ -1012,8 +1004,7 @@ static void __sd_leave(struct cpg_event *cevent)
 static int send_join_request(struct sheepdog_node_list_entry *ent)
 {
 	struct join_message msg;
-	struct sheepdog_node_list_entry entries[SD_MAX_NODES];
-	int nr_entries, i, ret;
+	int nr_entries, ret;
 
 	memset(&msg, 0, sizeof(msg));
 	msg.header.proto_ver = SD_SHEEP_PROTO_VER;
@@ -1023,13 +1014,10 @@ static int send_join_request(struct sheepdog_node_list_entry *ent)
 
 	get_global_nr_copies(&msg.nr_sobjs);
 
-	nr_entries = ARRAY_SIZE(entries);
-	ret = read_epoch(&msg.epoch, &msg.ctime, entries, &nr_entries);
-	if (ret == SD_RES_SUCCESS) {
+	nr_entries = ARRAY_SIZE(msg.nodes);
+	ret = read_epoch(&msg.epoch, &msg.ctime, msg.nodes, &nr_entries);
+	if (ret == SD_RES_SUCCESS)
 		msg.nr_nodes = nr_entries;
-		for (i = 0; i < nr_entries; i++)
-			msg.nodes[i].ent = entries[i];
-	}
 
 	ret = sys->cdrv->join(ent, &msg, msg.header.msg_length);
 
@@ -1413,7 +1401,7 @@ static enum cluster_join_result sd_check_join_handler(struct sheepdog_node_list_
 	if (jm->result == SD_RES_SUCCESS && jm->cluster_status != SD_STATUS_OK) {
 		jm->nr_leave_nodes = 0;
 		list_for_each_entry(node, &sys->leave_list, list) {
-			jm->leave_nodes[jm->nr_leave_nodes].ent = node->ent;
+			jm->leave_nodes[jm->nr_leave_nodes] = node->ent;
 			jm->nr_leave_nodes++;
 		}
 		print_node_list(&sys->leave_list);
@@ -1531,13 +1519,13 @@ static void sd_join_handler(struct sheepdog_node_list_entry *joined,
 			if (!n)
 				panic("oom\n");
 
-			if (find_entry_list(&jm->leave_nodes[i].ent, &sys->leave_list)
-			    || !find_entry_epoch(&jm->leave_nodes[i].ent, le)) {
+			if (find_entry_list(&jm->leave_nodes[i], &sys->leave_list)
+			    || !find_entry_epoch(&jm->leave_nodes[i], le)) {
 				free(n);
 				continue;
 			}
 
-			n->ent = jm->leave_nodes[i].ent;
+			n->ent = jm->leave_nodes[i];
 
 			list_add_tail(&n->list, &sys->leave_list);
 		}
-- 
1.7.2.5




More information about the sheepdog mailing list