[sheepdog] [PATCH v2 2/3] sheep: make push_cache_object() queue a local gateway request

levin li levin108 at gmail.com
Tue Jun 26 04:45:30 CEST 2012


From: levin li <xingke.lwp at taobao.com>

The same reason as write/read/remove_object(), push_cache_object()
also needs a retrying machanism like gateway, so we also queue a
local gateway request instead of directly calling forward_write_obj_req().

Signed-off-by: levin li <xingke.lwp at taobao.com>
---
 sheep/gateway.c      |    3 ++-
 sheep/object_cache.c |   24 ++++++++----------------
 sheep/sdnet.c        |    2 +-
 3 files changed, 11 insertions(+), 18 deletions(-)

diff --git a/sheep/gateway.c b/sheep/gateway.c
index 42f028a..18ab926 100644
--- a/sheep/gateway.c
+++ b/sheep/gateway.c
@@ -216,7 +216,8 @@ void do_gateway_request(struct work *work)
 	dprintf("%x, %" PRIx64" , %u\n",
 		req->rq.opcode, req->rq.obj.oid, req->rq.epoch);
 
-	if (!sys->enable_write_cache || bypass_object_cache(req)) {
+	if (!sys->enable_write_cache || req->local ||
+	    bypass_object_cache(req)) {
 		if (req->rq.flags & SD_FLAG_CMD_WRITE)
 			ret = forward_write_obj_req(req);
 		else
diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index 1854a77..e538cda 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -552,8 +552,7 @@ static uint64_t idx_to_oid(uint32_t vid, uint32_t idx)
 static int push_cache_object(struct vnode_info *vnode_info, uint32_t vid,
 			     uint32_t idx, uint64_t bmap, int create)
 {
-	struct request fake_req;
-	struct sd_req *hdr = &fake_req.rq;
+	struct sd_req hdr;
 	void *buf;
 	off_t offset;
 	unsigned data_length;
@@ -568,8 +567,6 @@ static int push_cache_object(struct vnode_info *vnode_info, uint32_t vid,
 		return SD_RES_SUCCESS;
 	}
 
-	memset(&fake_req, 0, sizeof(fake_req));
-
 	first_bit = ffsll(bmap) - 1;
 	last_bit = fls64(bmap) - 1;
 
@@ -595,20 +592,15 @@ static int push_cache_object(struct vnode_info *vnode_info, uint32_t vid,
 	if (ret != SD_RES_SUCCESS)
 		goto out;
 
-	hdr->opcode = create ? SD_OP_CREATE_AND_WRITE_OBJ : SD_OP_WRITE_OBJ;
-	hdr->flags = SD_FLAG_CMD_WRITE;
-	hdr->data_length = data_length;
-	hdr->epoch = sys_epoch();
-
-	hdr->obj.oid = oid;
-	hdr->obj.offset = offset;
-	hdr->obj.copies = sys->nr_copies;
+	memset(&hdr, 0, sizeof(hdr));
+	hdr.opcode = create ? SD_OP_CREATE_AND_WRITE_OBJ : SD_OP_WRITE_OBJ;
+	hdr.flags = SD_FLAG_CMD_WRITE;
 
-	fake_req.data = buf;
-	fake_req.op = get_sd_op(hdr->opcode);
-	fake_req.vnodes = vnode_info;
+	hdr.obj.oid = oid;
+	hdr.obj.offset = offset;
+	hdr.obj.copies = sys->nr_copies;
 
-	ret = forward_write_obj_req(&fake_req);
+	ret = exec_local_req(&hdr, buf, data_length);
 	if (ret != SD_RES_SUCCESS)
 		eprintf("failed to push object %x\n", ret);
 
diff --git a/sheep/sdnet.c b/sheep/sdnet.c
index af28125..6dd9a26 100644
--- a/sheep/sdnet.c
+++ b/sheep/sdnet.c
@@ -476,11 +476,11 @@ void req_done(struct request *req)
 	struct client_info *ci = req->ci;
 
 	if (req->local) {
-		req->done = 1;
 		sys->nr_outstanding_reqs--;
 		sys->outstanding_data_size -= req->data_length;
 
 		pthread_mutex_lock(&req->wait_mutex);
+		req->done = 1;
 		pthread_cond_signal(&req->wait_cond);
 		pthread_mutex_unlock(&req->wait_mutex);
 	} else {
-- 
1.7.10




More information about the sheepdog mailing list