[sheepdog] [PATCH v2 2/9] sheep: clean up log_current_epoch call

MORITA Kazutaka morita.kazutaka at gmail.com
Fri Jul 12 22:25:52 CEST 2013


From: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>

This moves epoch incrementation into log_current_epoch() to simplify
codes, and adds a check of the return value of the function.  As a
result, log_current_epoch() is renamed to inc_and_log_epoch().

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 sheep/group.c      |   42 +++++++++++++++++++++++++-----------------
 sheep/ops.c        |    7 +++----
 sheep/sheep_priv.h |    2 +-
 3 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/sheep/group.c b/sheep/group.c
index 35eaf68..b6ae376 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -586,19 +586,22 @@ static void get_vdis_done(struct work *work)
 	free(w);
 }
 
-int log_current_epoch(void)
+int inc_and_log_epoch(void)
 {
 	struct vnode_info *cur_vinfo = main_thread_get(current_vnode_info);
 
-	if (!cur_vinfo)
-		return update_epoch_log(sys->cinfo.epoch, NULL, 0);
-
-	/* update cluster info to the latest state */
-	sys->cinfo.nr_nodes = cur_vinfo->nr_nodes;
-	memcpy(sys->cinfo.nodes, cur_vinfo->nodes,
-	       sizeof(cur_vinfo->nodes[0]) * cur_vinfo->nr_nodes);
-	return update_epoch_log(sys->cinfo.epoch, cur_vinfo->nodes,
-				cur_vinfo->nr_nodes);
+	if (cur_vinfo) {
+		/* update cluster info to the latest state */
+		sys->cinfo.nr_nodes = cur_vinfo->nr_nodes;
+		memcpy(sys->cinfo.nodes, cur_vinfo->nodes,
+		       sizeof(cur_vinfo->nodes[0]) * cur_vinfo->nr_nodes);
+	} else
+		sys->cinfo.nr_nodes = 0;
+
+	uatomic_inc(&sys->cinfo.epoch);
+
+	return update_epoch_log(sys->cinfo.epoch, sys->cinfo.nodes,
+				sys->cinfo.nr_nodes);
 }
 
 static struct vnode_info *alloc_old_vnode_info(const struct sd_node *joined,
@@ -752,8 +755,10 @@ static void update_cluster_info(const struct join_message *msg,
 		sys->status = msg->cluster_status;
 
 		if (msg->inc_epoch) {
-			uatomic_inc(&sys->cinfo.epoch);
-			log_current_epoch();
+			int ret = inc_and_log_epoch();
+			if (ret != 0)
+				panic("cannot log current epoch %d",
+				      sys->cinfo.epoch);
 
 			if (!old_vnode_info) {
 				old_vnode_info = alloc_old_vnode_info(joined,
@@ -1059,7 +1064,7 @@ void sd_leave_handler(const struct sd_node *left, const struct sd_node *members,
 		      size_t nr_members)
 {
 	struct vnode_info *old_vnode_info;
-	int i;
+	int i, ret;
 
 	sd_dprintf("leave %s", node_to_str(left));
 	for (i = 0; i < nr_members; i++)
@@ -1078,8 +1083,9 @@ void sd_leave_handler(const struct sd_node *left, const struct sd_node *members,
 	switch (sys->status) {
 	case SD_STATUS_HALT:
 	case SD_STATUS_OK:
-		uatomic_inc(&sys->cinfo.epoch);
-		log_current_epoch();
+		ret = inc_and_log_epoch();
+		if (ret != 0)
+			panic("cannot log current epoch %d", sys->cinfo.epoch);
 		start_recovery(main_thread_get(current_vnode_info),
 			       old_vnode_info, true);
 		if (!have_enough_zones())
@@ -1105,11 +1111,13 @@ static void update_node_size(struct sd_node *node)
 static void kick_node_recover(void)
 {
 	struct vnode_info *old = main_thread_get(current_vnode_info);
+	int ret;
 
 	main_thread_set(current_vnode_info,
 			alloc_vnode_info(old->nodes, old->nr_nodes));
-	uatomic_inc(&sys->cinfo.epoch);
-	log_current_epoch();
+	ret = inc_and_log_epoch();
+	if (ret != 0)
+		panic("cannot log current epoch %d", sys->cinfo.epoch);
 	start_recovery(main_thread_get(current_vnode_info), old, true);
 	put_vnode_info(old);
 }
diff --git a/sheep/ops.c b/sheep/ops.c
index 55c2deb..bded4c9 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -258,9 +258,9 @@ static int cluster_make_fs(const struct sd_req *req, struct sd_rsp *rsp,
 	memset(sys->vdi_inuse, 0, sizeof(sys->vdi_inuse));
 	clean_vdi_state();
 
-	sys->cinfo.epoch = 1;
+	sys->cinfo.epoch = 0;
 
-	ret = log_current_epoch();
+	ret = inc_and_log_epoch();
 	if (ret)
 		return SD_RES_EIO;
 
@@ -533,8 +533,7 @@ static int cluster_force_recover_main(const struct sd_req *req,
 		return SD_RES_FORCE_RECOVER;
 	}
 
-	sys->cinfo.epoch++; /* some nodes are left, so we get a new epoch */
-	ret = log_current_epoch();
+	ret = inc_and_log_epoch();
 	if (ret) {
 		sd_printf(SDOG_EMERG, "cannot update epoch log");
 		goto err;
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 546f152..f9d0e57 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -296,7 +296,7 @@ int leave_cluster(void);
 void queue_cluster_request(struct request *req);
 
 int update_epoch_log(uint32_t epoch, struct sd_node *nodes, size_t nr_nodes);
-int log_current_epoch(void);
+int inc_and_log_epoch(void);
 
 extern char *config_path;
 int set_cluster_config(const struct cluster_info *cinfo);
-- 
1.7.9.5




More information about the sheepdog mailing list