[Sheepdog] [PATCH] collie: add is_myself helper function

FUJITA Tomonori fujita.tomonori at lab.ntt.co.jp
Mon Apr 5 14:02:09 CEST 2010


we use various ways to see if a node entry is myself or not. So let's
add a helper function to do it.

Signed-off-by: FUJITA Tomonori <fujita.tomonori at lab.ntt.co.jp>
---
 collie/collie.h |    5 +++++
 collie/group.c  |   11 +++++------
 collie/store.c  |   10 +++++-----
 3 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/collie/collie.h b/collie/collie.h
index 2b3420f..3b17ee7 100644
--- a/collie/collie.h
+++ b/collie/collie.h
@@ -124,4 +124,9 @@ uint64_t get_cluster_ctime(void);
 
 int start_recovery(uint32_t epoch, int add);
 
+static inline int is_myself(struct sheepdog_node_list_entry *e)
+{
+	return e->id == sys->this_node.id;
+}
+
 #endif
diff --git a/collie/group.c b/collie/group.c
index dfcde9a..570464b 100644
--- a/collie/group.c
+++ b/collie/group.c
@@ -255,7 +255,7 @@ static void print_node_list(struct list_head *node_list)
 	char name[128];
 	list_for_each_entry(node, node_list, list) {
 		dprintf("%c nodeid: %x, pid: %d, ip: %s\n",
-			node_cmp(&node->ent, &sys->this_node) ? ' ' : 'l',
+			is_myself(&node->ent) ? 'l' : ' ',
 			node->nodeid, node->pid,
 			addr_to_str(name, sizeof(name), node->ent.addr, node->ent.port));
 	}
@@ -301,9 +301,8 @@ static int is_master(void)
 		return 1;
 
 	node = list_first_entry(&sys->sd_node_list, struct node, list);
-	if (node_cmp(&node->ent, &sys->this_node) == 0)
+	if (is_myself(&node->ent))
 		return 1;
-
 	return 0;
 }
 
@@ -323,7 +322,7 @@ static int get_cluster_status(struct sheepdog_node_list_entry *node)
 	if (sys->status == SD_STATUS_INCONSISTENT_EPOCHS)
 		return SD_STATUS_INCONSISTENT_EPOCHS;
 
-	if (node->id == sys->this_node.id) {
+	if (is_myself(node)) {
 		nr_entries = ARRAY_SIZE(entries);
 		ret = read_epoch(&epoch, &ctime, entries, &nr_entries);
 	} else {
@@ -448,7 +447,7 @@ static void get_vdi_bitmap_from_all(void)
 	nr_nodes = build_node_list(&sys->sd_node_list, entry);
 
 	for (i = 0; i < nr_nodes; i++) {
-		if (!memcmp(&sys->this_node, &entry[i], sizeof(sys->this_node)))
+		if (is_myself(&entry[i]))
 			continue;
 
 		addr_to_str(host, sizeof(host), entry[i].addr, 0);
@@ -683,7 +682,7 @@ static void vdi_op_done(struct vdi_op_message *msg)
 		ret = SD_RES_UNKNOWN;
 	}
 out:
-	if (node_cmp(&sys->this_node, &msg->header.from) != 0)
+	if (!is_myself(&msg->header.from))
 		return;
 
 	req = list_first_entry(&sys->pending_list, struct request, pending_list);
diff --git a/collie/store.c b/collie/store.c
index 75ac12e..9b5584f 100644
--- a/collie/store.c
+++ b/collie/store.c
@@ -155,7 +155,7 @@ again:
 		addr_to_str(name, sizeof(name), e[n].addr, 0);
 
 		/* FIXME: do like store_queue_request_local() */
-		if (e[n].id == sys->this_node.id)
+		if (is_myself(&e[n]))
 			continue;
 
 		fd = connect_to(name, e[n].port);
@@ -242,7 +242,7 @@ again:
 		addr_to_str(name, sizeof(name), e[n].addr, 0);
 
 		/* TODO: we can do better; we need to chech this first */
-		if (e[n].id == sys->this_node.id) {
+		if (is_myself(&e[n])) {
 			ret = store_queue_request_local(req, buf, sys->epoch);
 			memcpy(rsp, &req->rp, sizeof(*rsp));
 			rsp->result = ret;
@@ -343,7 +343,7 @@ static int is_my_obj(uint64_t oid, int copies)
 
 	for (i = 0; i < copies; i++) {
 		n = obj_to_sheep(e, nr, oid, i);
-		if (e[n].id == sys->this_node.id)
+		if (is_myself(&e[n]))
 			return 1;
 	}
 
@@ -930,7 +930,7 @@ static void __start_recovery(struct work *work, int idx)
 
 	if (cur_nr < old_nr) {
 		for (i = 0; i < old_nr; i++) {
-			if (old_entry[i].id == sys->this_node.id) {
+			if (is_myself(&old_entry[i])) {
 				my_idx = i;
 				break;
 			}
@@ -970,7 +970,7 @@ static void __start_recovery(struct work *work, int idx)
 		fill_obj_list(rw, old_entry + n, start_hash, end_hash);
 	} else {
 		for (i = 0; i < cur_nr; i++) {
-			if (cur_entry[i].id == sys->this_node.id) {
+			if (is_myself(&cur_entry[i])) {
 				my_idx = i;
 				break;
 			}
-- 
1.7.0




More information about the sheepdog mailing list