[Sheepdog] [PATCH 04/14] check return value of get_nth_node()

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Sat May 14 09:03:49 CEST 2011


Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 include/sheep.h |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/include/sheep.h b/include/sheep.h
index 5e0d8b4..31f1159 100644
--- a/include/sheep.h
+++ b/include/sheep.h
@@ -166,6 +166,8 @@ static inline int get_nth_node(struct sheepdog_vnode_list_entry *entries,
 		nodes[nr++] = idx;
 next:
 		idx = (idx + 1) % nr_entries;
+		if (idx == base)
+			return -1; /* not found */
 		for (i = 0; i < nr; i++)
 			if (same_node(entries, idx, nodes[i]))
 				/* this node is already selected, so skip here */
@@ -178,7 +180,7 @@ next:
 static inline int hval_to_sheep(struct sheepdog_vnode_list_entry *entries,
 				int nr_entries, uint64_t id, int idx)
 {
-	int i;
+	int i, ret;
 	struct sheepdog_vnode_list_entry *e = entries, *n;
 
 	for (i = 0; i < nr_entries - 1; i++, e++) {
@@ -186,7 +188,13 @@ static inline int hval_to_sheep(struct sheepdog_vnode_list_entry *entries,
 		if (id > e->id && id <= n->id)
 			break;
 	}
-	return get_nth_node(entries, nr_entries, (i + 1) % nr_entries, idx);
+	ret = get_nth_node(entries, nr_entries, (i + 1) % nr_entries, idx);
+	if (ret < 0) {
+		printf("bug\n");
+		abort();
+	}
+
+	return ret;
 }
 
 static inline int obj_to_sheep(struct sheepdog_vnode_list_entry *entries,
-- 
1.5.6.5




More information about the sheepdog mailing list