This allows farm to reuse the old epoch node list instead of re-reading it.

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

---
 sheep/farm/farm.c  |   20 +++++++-------------
 sheep/recovery.c   |    9 ++++-----
 sheep/sheep_priv.h |    2 +-
 3 files changed, 12 insertions(+), 19 deletions(-)

diff --git a/sheep/farm/farm.c b/sheep/farm/farm.c
index f17173f..42a2570 100644
--- a/sheep/farm/farm.c
+++ b/sheep/farm/farm.c
@@ -528,31 +528,25 @@ out:
 	return ret;
 }
 
-static int farm_end_recover(struct siocb *iocb)
+static int farm_end_recover(int old_epoch, struct vnode_info *old_vnode_info)
 {
 	unsigned char snap_sha1[SHA1_LEN];
 	unsigned char trunk_sha1[SHA1_LEN];
-	uint32_t epoch = iocb->epoch - 1;
-	struct sd_node nodes[SD_MAX_NODES];
-	int nr_nodes;
 
-	if (epoch == 0)
+	if (old_epoch == 0)
 		return SD_RES_SUCCESS;
 
-	nr_nodes = epoch_log_read(epoch, nodes, sizeof(nodes));
-	if (nr_nodes < 0) {
-		dprintf("failed to read nodes for epoch %d\n", epoch);
-		return SD_RES_EIO;
-	}
+	dprintf("old epoch %d\n", old_epoch);
 
-	dprintf("epoch %d\n", iocb->epoch);
 	if (trunk_file_write_recovery(trunk_sha1) < 0)
 		return SD_RES_EIO;
 
-	if (snap_file_write(epoch, nodes, nr_nodes, trunk_sha1, snap_sha1) < 0)
+	if (snap_file_write(old_epoch, old_vnode_info->nodes,
+			    old_vnode_info->nr_nodes, trunk_sha1,
+			    snap_sha1) < 0)
 		return SD_RES_EIO;
 
-	if (snap_log_write(epoch, snap_sha1, 0) < 0)
+	if (snap_log_write(old_epoch, snap_sha1, 0) < 0)
 		return SD_RES_EIO;
 
 	return SD_RES_SUCCESS;
diff --git a/sheep/recovery.c b/sheep/recovery.c
index 64309df..42d1b34 100644
--- a/sheep/recovery.c
+++ b/sheep/recovery.c
@@ -334,13 +334,12 @@ static inline void finish_recovery(struct recovery_work *rw)
 {
 	recovering_work = NULL;
 	sys->recovered_epoch = rw->epoch;
+
+	if (sd_store->end_recover)
+		sd_store->end_recover(sys->epoch - 1, rw->old_vnodes);
+
 	free_recovery_work(rw);
 
-	if (sd_store->end_recover) {
-		struct siocb iocb = { 0 };
-		iocb.epoch = sys->epoch;
-		sd_store->end_recover(&iocb);
-	}
 	dprintf("recovery complete: new epoch %"PRIu32"\n",
 		sys->recovered_epoch);
 }
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 4c760e0..b726b27 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -168,7 +168,7 @@ struct store_driver {
 	int (*link)(uint64_t oid, struct siocb *, uint32_t tgt_epoch);
 	int (*atomic_put)(uint64_t oid, struct siocb *);
 	int (*begin_recover)(struct siocb *);
-	int (*end_recover)(struct siocb *);
+	int (*end_recover)(int epoch, struct vnode_info *old_vnode_info);
 	int (*purge_obj)(void);
 	/* Operations for snapshot */
 	int (*snapshot)(struct siocb *);
-- 
1.7.10



