[sheepdog] [PATCH] sheep: remove invalid usage of current_vnode_info

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Mon Jan 6 08:13:12 CET 2014


The variable current_vnode_info should be treated with the functions
get_vnode_info() and put_vnode_info(). But some part of group.c didn't
follow this rule. Some of them clearly caused invalid releasing of the
structure. Others didn't caused anomaly but their style is not so
good. This patch fixes this invalid usage of current_vnode_info.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
 sheep/group.c |   21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/sheep/group.c b/sheep/group.c
index 623fa55..d6c9e90 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -176,13 +176,15 @@ int local_get_node_list(const struct sd_req *req, struct sd_rsp *rsp,
 			void *data)
 {
 	int nr_nodes;
-	struct vnode_info *cur_vinfo = main_thread_get(current_vnode_info);
+	struct vnode_info *cur_vinfo = get_vnode_info();
 
 	if (cur_vinfo) {
 		nr_nodes = cur_vinfo->nr_nodes;
 		nodes_to_buffer(&cur_vinfo->nroot, data);
 		rsp->data_length = nr_nodes * sizeof(struct sd_node);
 		rsp->node.nr_nodes = nr_nodes;
+
+		put_vnode_info(cur_vinfo);
 	} else {
 		rsp->node.nr_nodes = 0;
 	}
@@ -536,12 +538,14 @@ static void get_vdis_done(struct work *work)
 
 int inc_and_log_epoch(void)
 {
-	struct vnode_info *cur_vinfo = main_thread_get(current_vnode_info);
+	struct vnode_info *cur_vinfo = get_vnode_info();
 
 	if (cur_vinfo) {
 		/* update cluster info to the latest state */
 		sys->cinfo.nr_nodes = cur_vinfo->nr_nodes;
 		nodes_to_buffer(&cur_vinfo->nroot, sys->cinfo.nodes);
+
+		put_vnode_info(cur_vinfo);
 	} else
 		sys->cinfo.nr_nodes = 0;
 
@@ -648,7 +652,7 @@ static void update_cluster_info(const struct cluster_info *cinfo,
 		sockfd_cache_add_group(nroot);
 	sockfd_cache_add(&joined->nid);
 
-	old_vnode_info = main_thread_get(current_vnode_info);
+	old_vnode_info = get_vnode_info();
 	main_thread_set(current_vnode_info, alloc_vnode_info(nroot));
 
 	get_vdis(nroot, joined);
@@ -678,7 +682,8 @@ static void update_cluster_info(const struct cluster_info *cinfo,
 		set_cluster_shutdown(false);
 	}
 
-	put_vnode_info(old_vnode_info);
+	if (old_vnode_info)
+		put_vnode_info(old_vnode_info);
 }
 
 /*
@@ -928,7 +933,7 @@ main_fn void sd_leave_handler(const struct sd_node *left,
 		/* Mark leave node as gateway only node */
 		sys->this_node.nr_vnodes = 0;
 
-	old_vnode_info = main_thread_get(current_vnode_info);
+	old_vnode_info = get_vnode_info();
 	main_thread_set(current_vnode_info, alloc_vnode_info(nroot));
 	if (sys->cinfo.status == SD_STATUS_OK) {
 		ret = inc_and_log_epoch();
@@ -945,17 +950,19 @@ main_fn void sd_leave_handler(const struct sd_node *left,
 
 static void update_node_size(struct sd_node *node)
 {
-	struct vnode_info *cur_vinfo = main_thread_get(current_vnode_info);
+	struct vnode_info *cur_vinfo = get_vnode_info();
 	struct sd_node *n = rb_search(&cur_vinfo->nroot, node, rb, node_cmp);
 
 	if (unlikely(!n))
 		panic("can't find %s", node_to_str(node));
 	n->space = node->space;
+
+	put_vnode_info(cur_vinfo);
 }
 
 static void kick_node_recover(void)
 {
-	struct vnode_info *old = main_thread_get(current_vnode_info);
+	struct vnode_info *old = get_vnode_info();
 	int ret;
 
 	main_thread_set(current_vnode_info, alloc_vnode_info(&old->nroot));
-- 
1.7.10.4




More information about the sheepdog mailing list