[Sheepdog] [PATCH v3 2/3] sheep: refactor local and io request handling

Liu Yuan namei.unix at gmail.com
Tue Nov 22 08:31:02 CET 2011


From: Liu Yuan <tailai.ly at taobao.com>

They don't share any code or logic, let's split 'em out.
 - add a new function to handle local request.

other minor changes:
 - rename store/cluster_queue_request into do_io/cluster_request to conform naming in ops.c

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/group.c      |    2 +-
 sheep/sdnet.c      |   20 +++++++++++++++++---
 sheep/sheep_priv.h |    4 ++--
 sheep/store.c      |   29 ++++++++++-------------------
 4 files changed, 30 insertions(+), 25 deletions(-)

diff --git a/sheep/group.c b/sheep/group.c
index bd1356a..f126de5 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -211,7 +211,7 @@ static void do_cluster_op(void *arg)
 	msg->rsp.result = ret;
 }
 
-void cluster_queue_request(struct work *work, int idx)
+void do_cluster_request(struct work *work, int idx)
 {
 	struct request *req = container_of(work, struct request, work);
 	struct sd_req *hdr = (struct sd_req *)&req->rq;
diff --git a/sheep/sdnet.c b/sheep/sdnet.c
index 98cafd8..8455653 100644
--- a/sheep/sdnet.c
+++ b/sheep/sdnet.c
@@ -184,6 +184,20 @@ static void cluster_op_done(struct work *work, int idx)
 	/* request is forwarded to cpg group */
 }
 
+static void do_local_request(struct work *work, int idx)
+{
+	struct request *req = container_of(work, struct request, work);
+	struct sd_obj_rsp *rsp = (struct sd_obj_rsp *)&req->rp;
+	int ret = SD_RES_SUCCESS;
+
+	dprintf("%d\n", idx);
+
+	if (has_process_work(req->op))
+		ret = do_process_work(req->op, &req->rq, &req->rp, req->data);
+
+	rsp->result = ret;
+}
+
 static void queue_request(struct request *req)
 {
 	struct cpg_event *cevent = &req->cev;
@@ -221,13 +235,13 @@ static void queue_request(struct request *req)
 	}
 
 	if (is_io_op(req->op)) {
-		req->work.fn = store_queue_request;
+		req->work.fn = do_io_request;
 		req->work.done = io_op_done;
 	} else if (is_local_op(req->op)) {
-		req->work.fn = store_queue_request;
+		req->work.fn = do_local_request;
 		req->work.done = local_op_done;
 	} else if (is_cluster_op(req->op)) {
-		req->work.fn = cluster_queue_request;
+		req->work.fn = do_cluster_request;
 		req->work.done = cluster_op_done;
 	} else {
 		eprintf("unknown operation %d\n", hdr->opcode);
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 5e10a2f..cfc497d 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -214,7 +214,7 @@ int create_cluster(int port, int64_t zone);
 int leave_cluster(void);
 
 void start_cpg_event_work(void);
-void store_queue_request(struct work *work, int idx);
+void do_io_request(struct work *work, int idx);
 int write_object_local(uint64_t oid, char *data, unsigned int datalen,
 		       uint64_t offset, uint16_t flags, int copies,
 		       uint32_t epoch, int create);
@@ -223,7 +223,7 @@ int read_object_local(uint64_t oid, char *data, unsigned int datalen,
 
 int read_epoch(uint32_t *epoch, uint64_t *ctime,
 	       struct sheepdog_node_list_entry *entries, int *nr_entries);
-void cluster_queue_request(struct work *work, int idx);
+void do_cluster_request(struct work *work, int idx);
 
 int update_epoch_store(uint32_t epoch);
 int update_epoch_log(int epoch);
diff --git a/sheep/store.c b/sheep/store.c
index 1eefee4..7022a61 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -239,7 +239,7 @@ out:
 	return ret;
 }
 
-static int store_queue_request_local(struct request *req, uint32_t epoch);
+static int do_local_io(struct request *req, uint32_t epoch);
 
 static int forward_read_obj_req(struct request *req, int idx)
 {
@@ -269,7 +269,7 @@ static int forward_read_obj_req(struct request *req, int idx)
 		n = obj_to_sheep(e, nr, oid, i);
 
 		if (is_myself(e[n].addr, e[n].port)) {
-			ret = store_queue_request_local(req, hdr.epoch);
+			ret = do_local_io(req, hdr.epoch);
 			goto out;
 		}
 	}
@@ -361,7 +361,7 @@ static int forward_write_obj_req(struct request *req, int idx)
 	}
 
 	if (local) {
-		ret = store_queue_request_local(req, hdr.epoch);
+		ret = do_local_io(req, hdr.epoch);
 		rsp->result = ret;
 
 		if (nr_fds == 0) {
@@ -492,7 +492,7 @@ int write_object_local(uint64_t oid, char *data, unsigned int datalen,
 	hdr->data_length = datalen;
 	req->data = data;
 
-	ret = store_queue_request_local(req, epoch);
+	ret = do_local_io(req, epoch);
 
 	free(req);
 
@@ -522,7 +522,7 @@ int read_object_local(uint64_t oid, char *data, unsigned int datalen,
 	hdr->data_length = datalen;
 	req->data = data;
 
-	ret = store_queue_request_local(req, epoch);
+	ret = do_local_io(req, epoch);
 
 	rsp_data_length = rsp->data_length;
 	free(req);
@@ -663,7 +663,7 @@ out:
 	return ret;
 }
 
-static int store_queue_request_local(struct request *req, uint32_t epoch)
+static int do_local_io(struct request *req, uint32_t epoch)
 {
 	struct sd_obj_req *hdr = (struct sd_obj_req *)&req->rq;
 	int ret = SD_RES_SUCCESS;
@@ -748,7 +748,7 @@ out:
 	return ret;
 }
 
-void store_queue_request(struct work *work, int idx)
+void do_io_request(struct work *work, int idx)
 {
 	struct request *req = container_of(work, struct request, work);
 	int ret = SD_RES_SUCCESS;
@@ -763,14 +763,9 @@ void store_queue_request(struct work *work, int idx)
 	if (hdr->flags & SD_FLAG_CMD_RECOVERY)
 		epoch = hdr->tgt_epoch;
 
-	if (is_local_op(req->op)) {
-		if (has_process_work(req->op))
-			ret = do_process_work(req->op, &req->rq,
-					      &req->rp, req->data);
-		goto out;
-	}
-
-	if (!(hdr->flags & SD_FLAG_CMD_IO_LOCAL)) {
+	if (hdr->flags & SD_FLAG_CMD_IO_LOCAL) {
+		ret = do_local_io(req, epoch);
+	} else {
 		/* fix object consistency when we read the object for the first time */
 		if (req->check_consistency) {
 			ret = fix_object_consistency(req, idx);
@@ -782,15 +777,11 @@ void store_queue_request(struct work *work, int idx)
 			ret = forward_write_obj_req(req, idx);
 		else
 			ret = forward_read_obj_req(req, idx);
-		goto out;
 	}
-
-	ret = store_queue_request_local(req, epoch);
 out:
 	if (ret != SD_RES_SUCCESS)
 		dprintf("failed: %"PRIu32", %x, %" PRIx64" , %u, %"PRIu32"\n",
 			idx, opcode, oid, epoch, ret);
-
 	rsp->result = ret;
 }
 
-- 
1.7.8.rc3




More information about the sheepdog mailing list