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

diff --git a/sheep/group.c b/sheep/group.c
index 3dea97a..0456e56 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -91,7 +91,7 @@ static size_t get_join_message_size(struct join_message *jm)
 	return sizeof(*jm) + jm->nr_nodes * sizeof(jm->nodes[0]);
 }
 
-int get_zones_nr_from(struct sd_node *nodes, int nr_nodes)
+static int get_zones_nr_from(struct sd_node *nodes, int nr_nodes)
 {
 	int nr_zones = 0, i, j;
 	uint32_t zones[SD_MAX_REDUNDANCY];
@@ -119,6 +119,21 @@ int get_zones_nr_from(struct sd_node *nodes, int nr_nodes)
 	return nr_zones;
 }
 
+bool have_enough_zones(void)
+{
+	int nr_zones = get_zones_nr_from(sys->nodes, sys->nr_nodes);
+
+	dprintf("flags %d, nr_zones %d, copies %d\n", sys->flags, nr_zones,
+		sys->nr_copies);
+
+	if (sys_flag_nohalt())
+		return true;
+
+	if (nr_zones >= sys->nr_copies)
+		return true;
+	return false;
+}
+
 /*
  * If we have less zones available than the desired redundancy we have to do
  * with nr_zones copies, sorry.
diff --git a/sheep/ops.c b/sheep/ops.c
index b662b9e..29be94f 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -251,17 +251,10 @@ static int cluster_make_fs(const struct sd_req *req, struct sd_rsp *rsp,
 
 	set_cluster_copies(sys->nr_copies);
 	set_cluster_flags(sys->flags);
-
-	if (sys_flag_nohalt())
+	if (have_enough_zones())
 		sys_stat_set(SD_STATUS_OK);
-	else {
-		int nr_zones = get_zones_nr_from(sys->nodes, sys->nr_nodes);
-
-		if (nr_zones >= sys->nr_copies)
-			sys_stat_set(SD_STATUS_OK);
-		else
-			sys_stat_set(SD_STATUS_HALT);
-	}
+	else
+		sys_stat_set(SD_STATUS_HALT);
 
 	return SD_RES_SUCCESS;
 }
@@ -453,7 +446,7 @@ static int local_get_epoch(struct request *req)
 static int cluster_manual_recover(const struct sd_req *req, struct sd_rsp *rsp,
 				void *data)
 {
-	int s, nr_zones = 0, ret = SD_RES_SUCCESS;
+	int ret = SD_RES_SUCCESS;
 	uint8_t c;
 	uint16_t f;
 
@@ -477,16 +470,6 @@ static int cluster_manual_recover(const struct sd_req *req, struct sd_rsp *rsp,
 	sys->nr_copies = c;
 	sys->flags = f;
 
-	s = SD_STATUS_OK;
-	if (!sys_flag_nohalt()) {
-		nr_zones = get_zones_nr_from(sys->nodes, sys->nr_nodes);
-		if (nr_zones < sys->nr_copies)
-			s = SD_STATUS_HALT;
-	}
-
-	dprintf("flags %d, nr_zones %d, copies %d\n", sys->flags, nr_zones,
-		sys->nr_copies);
-
 	sys->epoch++; /* some nodes are left, so we get a new epoch */
 	ret = update_epoch_log(sys->epoch, sys->nodes, sys->nr_nodes);
 	if (ret) {
@@ -494,7 +477,11 @@ static int cluster_manual_recover(const struct sd_req *req, struct sd_rsp *rsp,
 		sys->epoch--;
 		goto out;
 	}
-	sys_stat_set(s);
+
+	if (have_enough_zones())
+		sys_stat_set(SD_STATUS_OK);
+	else
+		sys_stat_set(SD_STATUS_HALT);
 out:
 	return ret;
 }
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 28eb5fa..9a23f57 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -12,6 +12,7 @@
 #define __SHEEP_PRIV_H__
 
 #include <inttypes.h>
+#include <stdbool.h>
 #include <urcu/uatomic.h>
 
 #include "sheepdog_proto.h"
@@ -227,7 +228,7 @@ int get_vdi_attr(struct vnode_info *vnode_info, uint32_t epoch,
 		uint32_t *attrid, int copies, uint64_t ctime, int write,
 		int excl, int delete);
 
-int get_zones_nr_from(struct sd_node *nodes, int nr_nodes);
+bool have_enough_zones(void);
 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);


