[sheepdog] [PATCH 1/3] sheep: factor out a helper to allocate a struct vnode_info

Christoph Hellwig hch at infradead.org
Mon May 28 14:56:33 CEST 2012


We want to use struct vnode_info in recovery code and thus need a helper to
allocate on for a given node list.  Factor update_vnode_info to allow for
that.

Signed-off-by: Christoph Hellwig <hch at lst.de>

---
 sheep/group.c      |   21 +++++++--------------
 sheep/sheep_priv.h |    1 +
 2 files changed, 8 insertions(+), 14 deletions(-)

Index: sheepdog/sheep/group.c
===================================================================
--- sheepdog.orig/sheep/group.c	2012-05-28 14:40:21.440682850 +0200
+++ sheepdog/sheep/group.c	2012-05-28 14:40:41.660683365 +0200
@@ -207,24 +207,16 @@ void oid_to_vnodes(struct vnode_info *vn
 	}
 }
 
-static int update_vnode_info(void)
+struct vnode_info *alloc_vnode_info(struct sd_node *nodes, size_t nr_nodes)
 {
 	struct vnode_info *vnode_info;
 
-	vnode_info = zalloc(sizeof(*vnode_info));
-	if (!vnode_info) {
-		eprintf("failed to allocate memory\n");
-		return 1;
-	}
-
-	vnode_info->nr_vnodes = nodes_to_vnodes(sys->nodes, sys->nr_nodes,
+	vnode_info = xzalloc(sizeof(*vnode_info));
+	vnode_info->nr_vnodes = nodes_to_vnodes(nodes, nr_nodes,
 						vnode_info->entries);
-	vnode_info->nr_zones = get_zones_nr_from(sys->nodes, sys->nr_nodes);
+	vnode_info->nr_zones = get_zones_nr_from(nodes, nr_nodes);
 	uatomic_set(&vnode_info->refcnt, 1);
-
-	put_vnode_info(current_vnode_info);
-	current_vnode_info = vnode_info;
-	return 0;
+	return vnode_info;
 }
 
 /*
@@ -557,7 +549,8 @@ static void update_node_info(struct sd_n
 	memcpy(sys->nodes, nodes, sizeof(*sys->nodes) * sys->nr_nodes);
 	qsort(sys->nodes, sys->nr_nodes, sizeof(*sys->nodes), node_cmp);
 
-	update_vnode_info();
+	put_vnode_info(current_vnode_info);
+	current_vnode_info = alloc_vnode_info(sys->nodes, sys->nr_nodes);
 }
 
 static void log_last_epoch(struct join_message *msg, struct sd_node *joined,
Index: sheepdog/sheep/sheep_priv.h
===================================================================
--- sheepdog.orig/sheep/sheep_priv.h	2012-05-28 14:40:21.440682850 +0200
+++ sheepdog/sheep/sheep_priv.h	2012-05-28 14:40:41.660683365 +0200
@@ -255,6 +255,7 @@ int get_vdi_attr(struct vnode_info *vnod
 		int excl, int delete);
 
 int get_zones_nr_from(struct sd_node *nodes, int nr_nodes);
+struct vnode_info *alloc_vnode_info(struct sd_node *nodes, size_t nr_nodes);
 struct vnode_info *grab_vnode_info(struct vnode_info *vnode_info);
 struct vnode_info *get_vnode_info(void);
 void put_vnode_info(struct vnode_info *vnodes);



More information about the sheepdog mailing list