[sheepdog] [PATCH 1/5] sheep: restructure sd_vnode

Liu Yuan namei.unix at gmail.com
Thu Sep 5 06:38:09 CEST 2013


- remove duplicate fields that sd_node has
- point to sd_node directly instead of using index

This will allow changing the structure of sd_node for later patch.

Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 dog/vdi.c          |   15 +++++++++------
 include/sheep.h    |   26 ++++++++------------------
 sheep/gateway.c    |    4 ++--
 sheep/recovery.c   |    3 +--
 sheep/sheep_priv.h |    2 +-
 5 files changed, 21 insertions(+), 29 deletions(-)

diff --git a/dog/vdi.c b/dog/vdi.c
index 231a3a4..a31d8c5 100644
--- a/dog/vdi.c
+++ b/dog/vdi.c
@@ -948,7 +948,7 @@ static int do_track_object(uint64_t oid, uint8_t nr_copies)
 					    logs[i].nr_nodes, vnodes);
 		oid_to_vnodes(vnodes, vnodes_nr, oid, nr_copies, vnode_buf);
 		for (j = 0; j < nr_copies; j++) {
-			const struct node_id *n = &vnode_buf[j]->nid;
+			const struct node_id *n = &vnode_buf[j]->node->nid;
 
 			printf("%s\n", addr_to_str(n->addr, n->port));
 		}
@@ -1357,7 +1357,8 @@ static void *read_object_from(const struct sd_vnode *vnode, uint64_t oid)
 
 	hdr.obj.oid = oid;
 
-	ret = dog_exec_req(vnode->nid.addr, vnode->nid.port, &hdr, buf);
+	ret = dog_exec_req(vnode->node->nid.addr, vnode->node->nid.port,
+			   &hdr, buf);
 
 	if (ret < 0)
 		exit(EXIT_SYSFAIL);
@@ -1394,7 +1395,8 @@ static void write_object_to(const struct sd_vnode *vnode, uint64_t oid,
 	hdr.data_length = get_objsize(oid);
 	hdr.obj.oid = oid;
 
-	ret = dog_exec_req(vnode->nid.addr, vnode->nid.port, &hdr, buf);
+	ret = dog_exec_req(vnode->node->nid.addr, vnode->node->nid.port,
+			   &hdr, buf);
 
 	if (ret < 0)
 		exit(EXIT_SYSFAIL);
@@ -1475,8 +1477,8 @@ static void vdi_hash_check_work(struct work *work)
 	hdr.obj.oid = info->oid;
 	hdr.obj.tgt_epoch = sd_epoch;
 
-	ret = dog_exec_req(vcw->vnode->nid.addr, vcw->vnode->nid.port, &hdr,
-			      NULL);
+	ret = dog_exec_req(vcw->vnode->node->nid.addr,
+			   vcw->vnode->node->nid.port, &hdr, NULL);
 	if (ret < 0)
 		exit(EXIT_SYSFAIL);
 
@@ -1491,7 +1493,8 @@ static void vdi_hash_check_work(struct work *work)
 		break;
 	default:
 		sd_err("failed to read %" PRIx64 " from %s, %s", info->oid,
-		       addr_to_str(vcw->vnode->nid.addr, vcw->vnode->nid.port),
+		       addr_to_str(vcw->vnode->node->nid.addr,
+				   vcw->vnode->node->nid.port),
 		       sd_strerror(rsp->result));
 		exit(EXIT_FAILURE);
 	}
diff --git a/include/sheep.h b/include/sheep.h
index d08c86b..bbb7721 100644
--- a/include/sheep.h
+++ b/include/sheep.h
@@ -19,9 +19,7 @@
 #include "net.h"
 
 struct sd_vnode {
-	struct node_id  nid;
-	uint16_t	node_idx;
-	uint32_t	zone;
+	const struct sd_node *node;
 	uint64_t        id;
 };
 
@@ -60,7 +58,7 @@ static inline void sd_init_req(struct sd_req *req, uint8_t opcode)
 
 static inline int same_zone(const struct sd_vnode *e, int n1, int n2)
 {
-	return e[n1].zone == e[n2].zone;
+	return e[n1].node->zone == e[n2].node->zone;
 }
 
 /* Get the first vnode's index which is matching the OID */
@@ -147,14 +145,13 @@ static inline const struct sd_vnode *oid_to_vnode(const struct sd_vnode *entries
 
 static inline const struct sd_node *oid_to_node(const struct sd_vnode *entries,
 						int nr_entries, uint64_t oid,
-						int copy_idx,
-						const struct sd_node *all_nodes)
+						int copy_idx)
 {
 	const struct sd_vnode *vnode;
 
 	vnode = oid_to_vnode(entries, nr_entries, oid, copy_idx);
 
-	return &all_nodes[vnode->node_idx];
+	return vnode->node;
 }
 
 static inline void oid_to_vnodes(const struct sd_vnode *entries, int nr_entries,
@@ -179,7 +176,6 @@ static inline void oid_to_vnodes(const struct sd_vnode *entries, int nr_entries,
 
 static inline void oid_to_nodes(const struct sd_vnode *entries, int nr_entries,
 				uint64_t oid, int nr_copies,
-				const struct sd_node *all_nodes,
 				const struct sd_node **nodes)
 {
 	int i;
@@ -187,7 +183,7 @@ static inline void oid_to_nodes(const struct sd_vnode *entries, int nr_entries,
 
 	oid_to_vnodes(entries, nr_entries, oid, nr_copies, vnodes);
 	for (i = 0; i < nr_copies; i++)
-		nodes[i] = &all_nodes[vnodes[i]->node_idx];
+		nodes[i] = vnodes[i]->node;
 }
 
 static inline const char *sd_strerror(int err)
@@ -283,22 +279,16 @@ static inline int vnode_cmp(const struct sd_vnode *node1,
 	return intcmp(node1->id, node2->id);
 }
 
-static inline int node_to_vnodes(const struct sd_node *nodes, int idx,
+static inline int node_to_vnodes(const struct sd_node *n,
 				 struct sd_vnode *vnodes)
 {
 	int nr = 0;
-	const struct sd_node *n = nodes + idx;
 	uint64_t hval = sd_hash(&n->nid, offsetof(typeof(n->nid), io_addr));
 
 	for (int i = 0; i < n->nr_vnodes; i++) {
 		hval = sd_hash_next(hval);
-
 		vnodes[nr].id = hval;
-		memcpy(vnodes[nr].nid.addr, n->nid.addr, sizeof(n->nid.addr));
-		vnodes[nr].nid.port = n->nid.port;
-		vnodes[nr].node_idx = idx;
-		vnodes[nr].zone = n->zone;
-
+		vnodes[nr].node = n;
 		nr++;
 	}
 
@@ -311,7 +301,7 @@ static inline int nodes_to_vnodes(const struct sd_node *nodes, int nr_nodes,
 	int nr_vnodes = 0;
 
 	for (int i = 0; i < nr_nodes; i++)
-		nr_vnodes += node_to_vnodes(nodes, i, vnodes + nr_vnodes);
+		nr_vnodes += node_to_vnodes(nodes + i, vnodes + nr_vnodes);
 
 	xqsort(vnodes, nr_vnodes, vnode_cmp);
 
diff --git a/sheep/gateway.c b/sheep/gateway.c
index dc2cc7d..33f04e0 100644
--- a/sheep/gateway.c
+++ b/sheep/gateway.c
@@ -74,7 +74,7 @@ int gateway_read_obj(struct request *req)
 		 * structure.
 		 */
 		gateway_init_fwd_hdr(&fwd_hdr, &req->rq);
-		ret = sheep_exec_req(&v->nid, &fwd_hdr, req->data);
+		ret = sheep_exec_req(&v->node->nid, &fwd_hdr, req->data);
 		if (ret != SD_RES_SUCCESS)
 			continue;
 
@@ -243,7 +243,7 @@ static int init_target_nodes(struct request *req, uint64_t oid,
 
 	nr_to_send = get_req_copy_number(req);
 	oid_to_nodes(vinfo->vnodes, vinfo->nr_vnodes, oid, nr_to_send,
-		     vinfo->nodes, target_nodes);
+		     target_nodes);
 
 	return nr_to_send;
 }
diff --git a/sheep/recovery.c b/sheep/recovery.c
index 521661b..6a02adf 100644
--- a/sheep/recovery.c
+++ b/sheep/recovery.c
@@ -197,8 +197,7 @@ static int recover_object_from_replica(struct recovery_obj_work *row,
 		const struct sd_node *node;
 		int idx = (i + start) % nr_copies;
 
-		node = oid_to_node(old->vnodes, old->nr_vnodes, oid, idx,
-				   old->nodes);
+		node = oid_to_node(old->vnodes, old->nr_vnodes, oid, idx);
 
 		if (invalid_node(node, row->base.cur_vinfo))
 			continue;
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 3643d12..7796d86 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -385,7 +385,7 @@ int gateway_to_peer_opcode(int opcode);
 
 static inline bool vnode_is_local(const struct sd_vnode *v)
 {
-	return node_id_cmp(&v->nid, &sys->this_node.nid) == 0;
+	return node_id_cmp(&v->node->nid, &sys->this_node.nid) == 0;
 }
 
 static inline bool node_is_local(const struct sd_node *n)
-- 
1.7.9.5




More information about the sheepdog mailing list