[sheepdog] [PATCH] sheep: pass the old and new vnode_info to recovery

Christoph Hellwig hch at infradead.org
Wed May 30 16:39:23 CEST 2012


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

diff --git a/sheep/group.c b/sheep/group.c
index f3b7d1f..ea5a69e 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -652,6 +652,7 @@ static void update_cluster_info(struct join_message *msg,
 		struct sd_node *joined, struct sd_node *nodes, size_t nr_nodes)
 {
 	struct node *n, *t;
+	struct vnode_info *old_vnode_info;
 
 	eprintf("status = %d, epoch = %d, %x, %d\n", msg->cluster_status,
 		msg->epoch, msg->result, sys->join_finished);
@@ -662,7 +663,7 @@ static void update_cluster_info(struct join_message *msg,
 	if (!sys->join_finished)
 		finish_join(msg, joined, nodes, nr_nodes);
 
-	put_vnode_info(current_vnode_info);
+	old_vnode_info = current_vnode_info;
 	current_vnode_info = alloc_vnode_info(nodes, nr_nodes);
 
 	if (msg->cluster_status == SD_STATUS_OK ||
@@ -699,9 +700,11 @@ static void update_cluster_info(struct join_message *msg,
 	if (sys_can_recover() && msg->inc_epoch) {
 		list_for_each_entry_safe(n, t, &sys->leave_list, list)
 			list_del(&n->list);
-		start_recovery(sys->epoch);
+		start_recovery(current_vnode_info, old_vnode_info);
 	}
 
+	put_vnode_info(old_vnode_info);
+
 	if (sys_stat_halt()) {
 		if (current_vnode_info->nr_zones >= sys->nr_copies)
 			sys_stat_set(SD_STATUS_OK);
@@ -1044,6 +1047,7 @@ void sd_join_handler(struct sd_node *joined, struct sd_node *members,
 void sd_leave_handler(struct sd_node *left, struct sd_node *members,
 		size_t nr_members)
 {
+	struct vnode_info *old_vnode_info;
 	int i;
 
 	dprintf("leave %s\n", node_to_str(left));
@@ -1053,14 +1057,15 @@ void sd_leave_handler(struct sd_node *left, struct sd_node *members,
 	if (sys_stat_shutdown())
 		return;
 
-	put_vnode_info(current_vnode_info);
+	old_vnode_info = current_vnode_info;
 	current_vnode_info = alloc_vnode_info(members, nr_members);
 
 	if (sys_can_recover()) {
 		uatomic_inc(&sys->epoch);
 		log_current_epoch();
-		start_recovery(sys->epoch);
+		start_recovery(current_vnode_info, old_vnode_info);
 	}
+	put_vnode_info(old_vnode_info);
 
 	if (sys_can_halt()) {
 		if (current_vnode_info->nr_zones < sys->nr_copies)
diff --git a/sheep/recovery.c b/sheep/recovery.c
index 69432ee..9ee876f 100644
--- a/sheep/recovery.c
+++ b/sheep/recovery.c
@@ -631,29 +631,6 @@ again:
 	return 0;
 }
 
-/* setup node list and virtual node list */
-static int init_rw(struct recovery_work *rw)
-{
-	struct sd_node nodes[SD_MAX_NODES];
-	int nr_nodes;
-	uint32_t epoch = rw->epoch;
-
-	nr_nodes = epoch_log_read_nr(epoch, (char *)nodes, sizeof(nodes));
-	if (nr_nodes <= 0) {
-		eprintf("failed to read epoch log for epoch %"PRIu32"\n", epoch);
-		return -1;
-	}
-	rw->cur_vnodes = alloc_vnode_info(nodes, nr_nodes);
-
-	nr_nodes = epoch_log_read_nr(epoch - 1, (char *)nodes, sizeof(nodes));
-	if (nr_nodes <= 0) {
-		eprintf("failed to read epoch log for epoch %"PRIu32"\n", epoch - 1);
-		return -1;
-	}
-	rw->old_vnodes = alloc_vnode_info(nodes, nr_nodes);
-	return 0;
-}
-
 static void do_recovery_work(struct work *work)
 {
 	struct recovery_work *rw = container_of(work, struct recovery_work, work);
@@ -663,8 +640,6 @@ static void do_recovery_work(struct work *work)
 	if (!sys->nr_copies)
 		return;
 
-	init_rw(rw);
-
 	if (fill_obj_list(rw) < 0) {
 		eprintf("fatal recovery error\n");
 		rw->count = 0;
@@ -672,7 +647,7 @@ static void do_recovery_work(struct work *work)
 	}
 }
 
-int start_recovery(uint32_t epoch)
+int start_recovery(struct vnode_info *cur_vnodes, struct vnode_info *old_vnodes)
 {
 	struct recovery_work *rw;
 
@@ -682,15 +657,18 @@ int start_recovery(uint32_t epoch)
 
 	rw->state = RW_INIT;
 	rw->oids = malloc(1 << 20); /* FIXME */
-	rw->epoch = epoch;
+	rw->epoch = sys->epoch;
 	rw->count = 0;
 
+	rw->cur_vnodes = grab_vnode_info(cur_vnodes);
+	rw->old_vnodes = grab_vnode_info(old_vnodes);
+
 	rw->work.fn = do_recovery_work;
 	rw->work.done = do_recover_main;
 
 	if (sd_store->begin_recover) {
 		struct siocb iocb = { 0 };
-		iocb.epoch = epoch;
+		iocb.epoch = rw->epoch;
 		sd_store->begin_recover(&iocb);
 	}
 
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index e5f8f44..c31a484 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -284,7 +284,8 @@ int set_cluster_ctime(uint64_t ctime);
 uint64_t get_cluster_ctime(void);
 int get_obj_list(const struct sd_list_req *, struct sd_list_rsp *, void *);
 
-int start_recovery(uint32_t epoch);
+int start_recovery(struct vnode_info *cur_vnodes,
+	struct vnode_info *old_vnodes);
 void resume_recovery_work(void);
 int is_recoverying_oid(uint64_t oid);
 int is_recovery_init(void);



More information about the sheepdog mailing list