[sheepdog] [PATCH v3 07/11] sheep: don't call get_vnode_info in epoch_log_read_remote()

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Fri Apr 19 10:55:26 CEST 2013


We cannot call get_vnode_info() in epoch_log_read_remote() (in the
worker thread).  We already have the current vnode info, so let's use
it.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 sheep/group.c      | 10 ++++------
 sheep/ops.c        | 14 ++++++++++----
 sheep/recovery.c   |  2 +-
 sheep/sheep_priv.h |  5 +++--
 4 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/sheep/group.c b/sheep/group.c
index 874c3a3..866def5 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -186,7 +186,8 @@ static struct vnode_info *alloc_vnode_info(const struct sd_node *nodes,
 	return vnode_info;
 }
 
-struct vnode_info *get_vnode_info_epoch(uint32_t epoch)
+struct vnode_info *get_vnode_info_epoch(uint32_t epoch,
+					struct vnode_info *cur_vinfo)
 {
 	struct sd_node nodes[SD_MAX_NODES];
 	int nr_nodes;
@@ -194,7 +195,7 @@ struct vnode_info *get_vnode_info_epoch(uint32_t epoch)
 	nr_nodes = epoch_log_read(epoch, nodes, sizeof(nodes));
 	if (nr_nodes < 0) {
 		nr_nodes = epoch_log_read_remote(epoch, nodes, sizeof(nodes),
-						NULL);
+						 NULL, cur_vinfo);
 		if (nr_nodes == 0)
 			return NULL;
 	}
@@ -457,10 +458,9 @@ static void clear_exceptional_node_lists(void)
 }
 
 int epoch_log_read_remote(uint32_t epoch, struct sd_node *nodes, int len,
-			time_t *timestamp)
+			  time_t *timestamp, struct vnode_info *vinfo)
 {
 	int i, nr, ret;
-	struct vnode_info *vinfo = get_vnode_info();
 	char buf[SD_MAX_NODES * sizeof(struct sd_node) + sizeof(time_t)];
 
 	nr = vinfo->nr_nodes;
@@ -490,7 +490,6 @@ int epoch_log_read_remote(uint32_t epoch, struct sd_node *nodes, int len,
 		if (timestamp)
 			memcpy(timestamp, buf + nodes_len, sizeof(timestamp));
 
-		put_vnode_info(vinfo);
 		return nodes_len / sizeof(struct sd_node);
 	}
 
@@ -498,7 +497,6 @@ int epoch_log_read_remote(uint32_t epoch, struct sd_node *nodes, int len,
 	 * If no node has targeted epoch log, return 0 here to at least
 	 * allow reading older epoch logs.
 	 */
-	put_vnode_info(vinfo);
 	return 0;
 }
 
diff --git a/sheep/ops.c b/sheep/ops.c
index bf565fb..a6494b7 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -406,6 +406,11 @@ static int local_stat_cluster(struct request *req)
 	int i, max_logs;
 	uint32_t epoch;
 
+	if (req->vinfo == NULL) {
+		sd_dprintf("cluster is not started up");
+		goto out;
+	}
+
 	max_logs = req->rq.data_length / sizeof(*log);
 	epoch = get_latest_epoch();
 	for (i = 0; i < max_logs; i++) {
@@ -422,14 +427,15 @@ static int local_stat_cluster(struct request *req)
 		if (log->nr_nodes == -1)
 			log->nr_nodes = epoch_log_read_remote(epoch, log->nodes,
 							sizeof(log->nodes),
-							(time_t *)&log->time);
+							(time_t *)&log->time,
+							req->vinfo);
 
 		log->nr_copies = sys->nr_copies;
 
 		rsp->data_length += sizeof(*log);
 		epoch--;
 	}
-
+out:
 	switch (sys->status) {
 	case SD_STATUS_OK:
 		return SD_RES_SUCCESS;
@@ -505,7 +511,8 @@ static int cluster_force_recover(const struct sd_req *req, struct sd_rsp *rsp,
 	sys->nr_copies = c;
 	sys->flags = f;
 
-	old_vnode_info = get_vnode_info_epoch(sys->epoch);
+	vnode_info = get_vnode_info();
+	old_vnode_info = get_vnode_info_epoch(sys->epoch, vnode_info);
 	if (!old_vnode_info) {
 		sd_printf(SDOG_EMERG, "cannot get vnode info for epoch %d",
 			  sys->epoch);
@@ -524,7 +531,6 @@ static int cluster_force_recover(const struct sd_req *req, struct sd_rsp *rsp,
 	else
 		sys->status = SD_STATUS_HALT;
 
-	vnode_info = get_vnode_info();
 	start_recovery(vnode_info, old_vnode_info);
 	put_vnode_info(vnode_info);
 	put_vnode_info(old_vnode_info);
diff --git a/sheep/recovery.c b/sheep/recovery.c
index 57ea38a..23babe0 100644
--- a/sheep/recovery.c
+++ b/sheep/recovery.c
@@ -180,7 +180,7 @@ rollback:
 			goto err;
 		}
 
-		new_old = get_vnode_info_epoch(tgt_epoch);
+		new_old = get_vnode_info_epoch(tgt_epoch, rw->cur_vinfo);
 		if (!new_old)
 			/* We rollback in case we don't get a valid epoch */
 			goto rollback;
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 7f3a16e..56a5acc 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -271,7 +271,8 @@ bool have_enough_zones(void);
 struct vnode_info *grab_vnode_info(struct vnode_info *vnode_info);
 struct vnode_info *get_vnode_info(void);
 void put_vnode_info(struct vnode_info *vinfo);
-struct vnode_info *get_vnode_info_epoch(uint32_t epoch);
+struct vnode_info *get_vnode_info_epoch(uint32_t epoch,
+					struct vnode_info *cur_vinfo);
 void wait_get_vdis_done(void);
 
 int get_nr_copies(struct vnode_info *vnode_info);
@@ -307,7 +308,7 @@ int epoch_log_read(uint32_t epoch, struct sd_node *nodes, int len);
 int epoch_log_read_with_timestamp(uint32_t epoch, struct sd_node *nodes,
 				int len, time_t *timestamp);
 int epoch_log_read_remote(uint32_t epoch, struct sd_node *nodes, int len,
-			time_t *timestamp);
+			  time_t *timestamp, struct vnode_info *vinfo);
 uint32_t get_latest_epoch(void);
 void init_config_path(const char *base_path);
 int init_config_file(void);
-- 
1.8.1.3.566.gaa39828




More information about the sheepdog mailing list