[sheepdog] [PATCH 5/8] sheep: use main_refcnt_t for vnode_info

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Tue Jul 9 04:36:39 CEST 2013


Get and put of vnode_info are only allowed for the main thread. So
this patch changes the type of current refnct of vnode_info from int
to main_refcnt_t.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
 include/sheep.h |    3 ++-
 sheep/group.c   |   10 +++++-----
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/include/sheep.h b/include/sheep.h
index 0d3fae4..e144245 100644
--- a/include/sheep.h
+++ b/include/sheep.h
@@ -17,6 +17,7 @@
 #include "list.h"
 #include "net.h"
 #include "logger.h"
+#include "work.h"
 
 struct sd_vnode {
 	struct node_id  nid;
@@ -33,7 +34,7 @@ struct vnode_info {
 	int nr_nodes;
 
 	int nr_zones;
-	int refcnt;
+	main_refcnt_t refcnt;
 };
 
 #define TRACE_GRAPH_ENTRY  0x01
diff --git a/sheep/group.c b/sheep/group.c
index 6e01a8d..5e7fc2f 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -107,9 +107,9 @@ static int get_node_idx(struct vnode_info *vnode_info, struct sd_node *ent)
  */
 struct vnode_info *grab_vnode_info(struct vnode_info *vnode_info)
 {
-	assert(uatomic_read(&vnode_info->refcnt) > 0);
+	assert(main_refcnt_read(&vnode_info->refcnt) > 0);
 
-	uatomic_inc(&vnode_info->refcnt);
+	main_refcnt_inc(&vnode_info->refcnt);
 	return vnode_info;
 }
 
@@ -132,9 +132,9 @@ struct vnode_info *get_vnode_info(void)
 void put_vnode_info(struct vnode_info *vnode_info)
 {
 	if (vnode_info) {
-		assert(uatomic_read(&vnode_info->refcnt) > 0);
+		assert(main_refcnt_read(&vnode_info->refcnt) > 0);
 
-		if (uatomic_sub_return(&vnode_info->refcnt, 1) == 0)
+		if (main_refcnt_dec_return(&vnode_info->refcnt) == 0)
 			free(vnode_info);
 	}
 }
@@ -155,7 +155,7 @@ struct vnode_info *alloc_vnode_info(const struct sd_node *nodes,
 	vnode_info->nr_vnodes = nodes_to_vnodes(vnode_info->nodes, nr_nodes,
 						vnode_info->vnodes);
 	vnode_info->nr_zones = get_zones_nr_from(nodes, nr_nodes);
-	uatomic_set(&vnode_info->refcnt, 1);
+	main_refcnt_set(&vnode_info->refcnt, 1);
 	return vnode_info;
 }
 
-- 
1.7.10.4




More information about the sheepdog mailing list