[Sheepdog] [PATCH 1/2] move epoch checking to start_cpg_evet_work from queue_request

FUJITA Tomonori fujita.tomonori at lab.ntt.co.jp
Thu May 6 12:45:36 CEST 2010


We can't access to sys->epoch after start_cpg_event_work (via work
threads).

Signed-off-by: FUJITA Tomonori <fujita.tomonori at lab.ntt.co.jp>
---
 collie/group.c |   32 ++++++++++++++++++++++++++++++--
 collie/net.c   |    9 +++++++++
 collie/store.c |   26 --------------------------
 3 files changed, 39 insertions(+), 28 deletions(-)

diff --git a/collie/group.c b/collie/group.c
index 2e054ac..617f262 100644
--- a/collie/group.c
+++ b/collie/group.c
@@ -1297,6 +1297,24 @@ out:
 		start_cpg_event_work();
 }
 
+static int check_epoch(struct request *req)
+{
+	uint32_t req_epoch = req->rq.epoch;
+	uint32_t opcode = req->rq.opcode;
+	int ret = SD_RES_SUCCESS;
+
+	if (before(req_epoch, sys->epoch)) {
+		ret = SD_RES_OLD_NODE_VER;
+		eprintf("old node version %u %u, %x\n",
+			sys->epoch, req_epoch, opcode);
+	} else if (after(req_epoch, sys->epoch)) {
+		ret = SD_RES_NEW_NODE_VER;
+			eprintf("new node version %u %u %x\n",
+				sys->epoch, req_epoch, opcode);
+	}
+	return ret;
+}
+
 /* can be called only by the main process */
 void start_cpg_event_work(void)
 {
@@ -1337,10 +1355,20 @@ void start_cpg_event_work(void)
 		if (cevent->ctype != CPG_EVENT_REQUEST)
 			break;
 
-		if (is_io_request(req->rq.opcode))
+		list_del(&cevent->cpg_event_list);
+
+		if (is_io_request(req->rq.opcode)) {
 			sys->nr_outstanding_io++;
 
-		list_del(&cevent->cpg_event_list);
+			if (req->rq.flags & SD_FLAG_CMD_DIRECT) {
+				int ret = check_epoch(req);
+				if (ret != SD_RES_SUCCESS) {
+					req->rp.result = ret;
+					req->done(req);
+					continue;
+				}
+			}
+		}
 		queue_work(&req->work);
 	}
 
diff --git a/collie/net.c b/collie/net.c
index fddc5b0..448459c 100644
--- a/collie/net.c
+++ b/collie/net.c
@@ -145,6 +145,15 @@ static void queue_request(struct request *req)
 
 	list_del(&req->r_wlist);
 
+	/*
+	 * we set epoch for non direct requests here. Note that we
+	 * can't access to sys->epoch after calling
+	 * start_cpg_event_work(that is, passing requests to work
+	 * threads).
+	 */
+	if (!(hdr->flags & SD_FLAG_CMD_DIRECT))
+		hdr->epoch = sys->epoch;
+
 	cevent->ctype = CPG_EVENT_REQUEST;
 	list_add_tail(&cevent->cpg_event_list, &sys->cpg_event_siblings);
 	start_cpg_event_work();
diff --git a/collie/store.c b/collie/store.c
index e18a091..2dfaf54 100644
--- a/collie/store.c
+++ b/collie/store.c
@@ -577,26 +577,6 @@ out:
 	return ret;
 }
 
-static int check_epoch(struct request *req)
-{
-	struct sd_req *hdr = (struct sd_req *)&req->rq;
-	uint32_t req_epoch = hdr->epoch;
-	uint32_t opcode = hdr->opcode;
-	int ret = SD_RES_SUCCESS;
-
-	if (before(req_epoch, sys->epoch)) {
-		ret = SD_RES_OLD_NODE_VER;
-		eprintf("old node version %u %u, %x\n",
-			sys->epoch, req_epoch, opcode);
-	} else if (after(req_epoch, sys->epoch)) {
-		ret = SD_RES_NEW_NODE_VER;
-			eprintf("new node version %u %u %x\n",
-				sys->epoch, req_epoch, opcode);
-	}
-
-	return ret;
-}
-
 static int ob_open(uint32_t epoch, uint64_t oid, int aflags, int *ret)
 {
 	char path[1024];
@@ -811,12 +791,6 @@ void store_queue_request(struct work *work, int idx)
 
 	dprintf("%d, %x, %" PRIx64" , %u, %u\n", idx, opcode, oid, epoch, req_epoch);
 
-	if (hdr->flags & SD_FLAG_CMD_DIRECT) {
-		ret = check_epoch(req);
-		if (ret != SD_RES_SUCCESS)
-			goto out;
-	}
-
 	if (hdr->flags & SD_FLAG_CMD_RECOVERY)
 		epoch = hdr->tgt_epoch;
 
-- 
1.6.5




More information about the sheepdog mailing list