Add a helper to check if a given vnode is local to shorten the repeated
calls to is_myself.

Signed-off-by: Christoph Hellwig <hch@lst.de>

---
 sheep/farm/trunk.c   |    2 +-
 sheep/object_cache.c |    4 ++--
 sheep/sdnet.c        |    6 +++---
 sheep/sheep_priv.h   |    5 +++++
 sheep/store.c        |   18 +++++++++---------
 5 files changed, 20 insertions(+), 15 deletions(-)

Index: sheepdog/sheep/farm/trunk.c
===================================================================
--- sheepdog.orig/sheep/farm/trunk.c	2012-04-26 16:11:06.800382318 +0200
+++ sheepdog/sheep/farm/trunk.c	2012-04-26 16:12:38.328384663 +0200
@@ -246,7 +246,7 @@ static int oid_stale(uint64_t oid)
 
 	for (i = 0; i < copies; i++) {
 		v = oid_to_vnode(vnodes, oid, i);
-		if (is_myself(v->addr, v->port)) {
+		if (vnode_is_local(v)) {
 			ret = 0;
 			break;
 		}
Index: sheepdog/sheep/object_cache.c
===================================================================
--- sheepdog.orig/sheep/object_cache.c	2012-04-26 16:11:06.804382316 +0200
+++ sheepdog/sheep/object_cache.c	2012-04-26 16:12:38.328384663 +0200
@@ -400,7 +400,7 @@ int object_cache_pull(struct object_cach
 	/* Check if we can read locally */
 	for (i = 0; i < copies; i++) {
 		v = oid_to_vnode(vnodes, oid, i);
-		if (is_myself(v->addr, v->port)) {
+		if (vnode_is_local(v)) {
 			struct siocb iocb = { 0 };
 			iocb.epoch = sys->epoch;
 			ret = sd_store->open(oid, &iocb, 0);
@@ -426,7 +426,7 @@ pull_remote:
 	for (i = 0; i < copies; i++) {
 		v = oid_to_vnode(vnodes, oid, i);
 
-		if (is_myself(v->addr, v->port))
+		if (vnode_is_local(v))
 			continue;
 
 		hdr.opcode = SD_OP_READ_OBJ;
Index: sheepdog/sheep/sdnet.c
===================================================================
--- sheepdog.orig/sheep/sdnet.c	2012-04-26 16:11:37.548383107 +0200
+++ sheepdog/sheep/sdnet.c	2012-04-26 16:12:38.328384663 +0200
@@ -52,7 +52,7 @@ static int is_access_local(struct reques
 
 	for (i = 0; i < copies; i++) {
 		v = oid_to_vnode(vnodes, oid, i);
-		if (is_myself(v->addr, v->port))
+		if (vnode_is_local(v))
 			return 1;
 	}
 
@@ -691,7 +691,7 @@ int write_object(struct vnode_info *vnod
 		unsigned rlen = 0, wlen = datalen;
 
 		v = oid_to_vnode(vnodes, oid, i);
-		if (is_myself(v->addr, v->port)) {
+		if (vnode_is_local(v)) {
 			ret = write_object_local(oid, data, datalen, offset,
 						 flags, nr, node_version, create);
 
@@ -753,7 +753,7 @@ int read_object(struct vnode_info *vnode
 	/* search a local object first */
 	for (i = 0; i < nr; i++) {
 		v = oid_to_vnode(vnodes, oid, i);
-		if (is_myself(v->addr, v->port)) {
+		if (vnode_is_local(v)) {
 			ret = read_object_local(oid, data, datalen, offset, nr,
 						node_version);
 
Index: sheepdog/sheep/sheep_priv.h
===================================================================
--- sheepdog.orig/sheep/sheep_priv.h	2012-04-26 16:11:06.804382316 +0200
+++ sheepdog/sheep/sheep_priv.h	2012-04-26 16:12:38.328384663 +0200
@@ -344,6 +344,11 @@ static inline int is_myself(uint8_t *add
 		port == sys->this_node.port;
 }
 
+static inline int vnode_is_local(struct sd_vnode *v)
+{
+	return is_myself(v->addr, v->port);
+}
+
 /* Cluster status/flag helper */
 
 static inline int sys_flag_nohalt(void)
Index: sheepdog/sheep/store.c
===================================================================
--- sheepdog.orig/sheep/store.c	2012-04-26 16:11:06.804382316 +0200
+++ sheepdog/sheep/store.c	2012-04-26 16:12:38.328384663 +0200
@@ -241,7 +241,7 @@ static int read_copy_from_replica(struct
 
 		addr_to_str(name, sizeof(name), v->addr, 0);
 
-		if (is_myself(v->addr, v->port)) {
+		if (vnode_is_local(v)) {
 			memset(&iocb, 0, sizeof(iocb));
 			iocb.epoch = epoch;
 			ret = sd_store->open(oid, &iocb, 0);
@@ -324,7 +324,7 @@ static int forward_read_obj_req(struct r
 	/* TODO: we can do better; we need to check this first */
 	for (i = 0; i < copies; i++) {
 		v = oid_to_vnode(req->vnodes, oid, i);
-		if (is_myself(v->addr, v->port)) {
+		if (vnode_is_local(v)) {
 			ret = do_local_io(req, hdr.epoch);
 			if (ret != SD_RES_SUCCESS)
 				goto read_remote;
@@ -335,7 +335,7 @@ static int forward_read_obj_req(struct r
 read_remote:
 	for (i = 0; i < copies; i++) {
 		v = oid_to_vnode(req->vnodes, oid, i);
-		if (is_myself(v->addr, v->port))
+		if (vnode_is_local(v))
 			continue;
 
 		fd = get_sheep_fd(v->addr, v->port, v->node_idx, hdr.epoch);
@@ -364,7 +364,7 @@ read_remote:
 
 int forward_write_obj_req(struct request *req)
 {
-	int i, n, fd, ret, pollret;
+	int i, fd, ret, pollret;
 	unsigned wlen;
 	char name[128];
 	struct sd_obj_req hdr = *(struct sd_obj_req *)&req->rq;
@@ -397,9 +397,9 @@ int forward_write_obj_req(struct request
 	for (i = 0; i < copies; i++) {
 		v = oid_to_vnode(req->vnodes, oid, i);
 
-		addr_to_str(name, sizeof(name), req->vnodes->entries[n].addr, 0);
+		addr_to_str(name, sizeof(name), v->addr, 0);
 
-		if (is_myself(v->addr, v->port)) {
+		if (vnode_is_local(v)) {
 			local = 1;
 			continue;
 		}
@@ -1354,7 +1354,7 @@ static int recover_object_from_replica(u
 		goto out;
 	}
 
-	if (is_myself(entry->addr, entry->port)) {
+	if (vnode_is_local(entry)) {
 		iocb.epoch = epoch;
 		iocb.length = rlen;
 		ret = sd_store->link(oid, &iocb, tgt_epoch);
@@ -1518,7 +1518,7 @@ static int get_replica_idx(struct recove
 	*copy_nr = get_max_copies(rw->cur_nodes, rw->cur_nr_nodes);
 	for (i = 0; i < *copy_nr; i++) {
 		int n = obj_to_sheep(rw->cur_vnodes, rw->cur_nr_vnodes, oid, i);
-		if (is_myself(rw->cur_vnodes[n].addr, rw->cur_vnodes[n].port)) {
+		if (vnode_is_local(&rw->cur_vnodes[n])) {
 			ret = i;
 			break;
 		}
@@ -1798,7 +1798,7 @@ static int screen_obj_list(struct recove
 	for (i = 0; i < list_nr; i++) {
 		for (cp = 0; cp < nr_objs; cp++) {
 			idx = obj_to_sheep(nodes, nodes_nr, list[i], cp);
-			if (is_myself(nodes[idx].addr, nodes[idx].port))
+			if (vnode_is_local(&nodes[idx]))
 				break;
 		}
 		if (cp == nr_objs)


