[Sheepdog] [PATCH] fix a bug in the binary search in get_vnode_pos()

levin li levin108 at gmail.com
Tue May 15 12:28:23 CEST 2012


From: levin li <xingke.lwp at taobao.com>

Consider the corner case that id is less than the id
of the first entry in entry list.

Signed-off-by: levin li <xingke.lwp at taobao.com>
---
 include/sheep.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/sheep.h b/include/sheep.h
index e2b9340..36a4498 100644
--- a/include/sheep.h
+++ b/include/sheep.h
@@ -234,7 +234,7 @@ static inline int get_vnode_pos(struct sd_vnode *entries,
 	start = 0;
 	end = nr_entries - 1;
 
-	if (id > entries[end].id)
+	if (id > entries[end].id || id < entries[start].id)
 		return end;
 
 	for (;;) {
-- 
1.7.10




More information about the sheepdog mailing list