[Sheepdog] [PATCH v3] sheep: fix get_nr_copies()

Liu Yuan namei.unix at gmail.com
Mon Apr 30 20:31:03 CEST 2012


From: Liu Yuan <tailai.ly at taobao.com>

We should never return anything greater than sys->nr_copies.

- use min() to get the better readability
- change sys->nr_copies as 'int' to stay in line with nr_zones

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/group.c      |    5 +----
 sheep/sheep_priv.h |    2 +-
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/sheep/group.c b/sheep/group.c
index ea02602..f9a5437 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -203,10 +203,7 @@ static int update_vnode_info(void)
  */
 int get_nr_copies(struct vnode_info *vnode_info)
 {
-	int nr_copies = vnode_info->nr_zones;
-	if (nr_copies < sys->nr_copies)
-		nr_copies = sys->nr_copies;
-	return nr_copies;
+	return min(vnode_info->nr_zones, sys->nr_copies);
 }
 
 static void do_cluster_op(void *arg)
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index afd5c1b..57be935 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -136,7 +136,7 @@ struct cluster_info {
 	struct list_head consistent_obj_list;
 	struct list_head blocking_conn_list;
 
-	uint32_t nr_copies;
+	int nr_copies;
 
 	struct list_head request_queue;
 	struct list_head event_queue;
-- 
1.7.8.2




More information about the sheepdog mailing list