Instead of fixing up the return value down in sd_check_join_cb handle this
special case directly inside cluster_wait_for_join_check.

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

---
 sheep/group.c |   19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/sheep/group.c b/sheep/group.c
index 060674a..6fda1ce 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -495,8 +495,14 @@ static int cluster_wait_for_join_check(struct sd_node *entries,
 	int ret;
 
 	ret = cluster_sanity_check(epoch, ctime);
-	if (ret != CJ_RES_SUCCESS)
+	if (ret != CJ_RES_SUCCESS)  {
+		if (epoch > sys->epoch) {
+			eprintf("transfer mastership (%d, %d)\n",
+				epoch, sys->epoch);
+			return CJ_RES_MASTER_TRANSFER;
+		}
 		return ret;
+	}
 
 	if (epoch < local_epoch) {
 		eprintf("joining node epoch too small: %"
@@ -882,22 +888,15 @@ enum cluster_join_result sd_check_join_cb(struct sd_node *joining, void *opaque)
 
 	jm->nr_copies = sys->nr_copies;
 	jm->cluster_flags = sys->flags;
+	jm->epoch = sys->epoch;
 	jm->ctime = get_cluster_ctime();
 	jm->nr_failed_nodes = 0;
 
 	if (sd_store)
 		strcpy((char *)jm->store, sd_store->name);
 
-	if (ret == CJ_RES_SUCCESS && jm->cluster_status != SD_STATUS_OK) {
+	if (ret == CJ_RES_SUCCESS && jm->cluster_status != SD_STATUS_OK)
 		format_failed_node_list(jm);
-	} else if (ret != CJ_RES_SUCCESS &&
-		   jm->epoch > sys->epoch &&
-		   jm->cluster_status == SD_STATUS_WAIT_FOR_JOIN) {
-		eprintf("transfer mastership (%d, %d)\n", jm->epoch, sys->epoch);
-		return CJ_RES_MASTER_TRANSFER;
-	}
-	jm->epoch = sys->epoch;
-
 	return ret;
 }
 
-- 
1.7.10



