[sheepdog] [PATCH 2/2] sheep: clean up exec_local_req()
Liu Yuan
namei.unix at gmail.com
Thu Jun 28 11:57:40 CEST 2012
From: Liu Yuan <tailai.ly at taobao.com>
Since sd_req has length field, we don't need data_len arg in exec_local_req()
Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
sheep/object_cache.c | 5 +++--
sheep/sdnet.c | 10 +++++++---
sheep/sheep_priv.h | 2 +-
sheep/store.c | 8 +++++---
4 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index ecceba8..124650d 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -519,7 +519,7 @@ static int object_cache_pull(struct object_cache *oc, uint32_t idx)
hdr.data_length = data_length;
hdr.obj.oid = oid;
hdr.obj.offset = 0;
- ret = exec_local_req(&hdr, buf, data_length);
+ ret = exec_local_req(&hdr, buf);
if (ret == SD_RES_SUCCESS) {
dprintf("oid %"PRIx64" pulled successfully\n", oid);
@@ -584,10 +584,11 @@ static int push_cache_object(uint32_t vid, uint32_t idx, uint64_t bmap,
memset(&hdr, 0, sizeof(hdr));
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.obj.oid = oid;
hdr.obj.offset = offset;
- ret = exec_local_req(&hdr, buf, data_length);
+ ret = exec_local_req(&hdr, buf);
if (ret != SD_RES_SUCCESS)
eprintf("failed to push object %x\n", ret);
diff --git a/sheep/sdnet.c b/sheep/sdnet.c
index 01b598f..f9c85ae 100644
--- a/sheep/sdnet.c
+++ b/sheep/sdnet.c
@@ -406,15 +406,19 @@ static struct request *alloc_local_request(void *data, int data_length)
return req;
}
-int exec_local_req(struct sd_req *rq, void *data, int data_length)
+/*
+ * Exec the request locally and synchronously.
+ *
+ * This function takes advantage of gateway's retry mechanism.
+ */
+int exec_local_req(struct sd_req *rq, void *data)
{
struct request *req;
eventfd_t value = 1;
int ret;
- req = alloc_local_request(data, data_length);
+ req = alloc_local_request(data, rq->data_length);
req->rq = *rq;
- req->rq.data_length = data_length;
req->wait_efd = eventfd(0, 0);
pthread_mutex_lock(&sys->wait_req_lock);
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 8b38e15..4437551 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -285,7 +285,7 @@ int read_object(uint64_t oid, char *data, unsigned int datalen,
uint64_t offset);
int remove_object(uint64_t oid);
-int exec_local_req(struct sd_req *rq, void *data, int data_length);
+int exec_local_req(struct sd_req *rq, void *data);
void local_req_init(void);
int prealloc(int fd, uint32_t size);
diff --git a/sheep/store.c b/sheep/store.c
index ce56e34..dcbbb87 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -532,11 +532,12 @@ int write_object(uint64_t oid, char *data, unsigned int datalen,
memset(&hdr, 0, sizeof(hdr));
hdr.opcode = create ? SD_OP_CREATE_AND_WRITE_OBJ : SD_OP_WRITE_OBJ;
hdr.flags = flags | SD_FLAG_CMD_WRITE;
+ hdr.data_length = datalen;
hdr.obj.oid = oid;
hdr.obj.offset = offset;
- ret = exec_local_req(&hdr, data, datalen);
+ ret = exec_local_req(&hdr, data);
if (ret != SD_RES_SUCCESS)
eprintf("failed to write object %" PRIx64 ", %x\n", oid, ret);
@@ -566,10 +567,11 @@ int read_object(uint64_t oid, char *data, unsigned int datalen,
forward_read:
memset(&hdr, 0, sizeof(hdr));
hdr.opcode = SD_OP_READ_OBJ;
+ hdr.data_length = datalen;
hdr.obj.oid = oid;
hdr.obj.offset = offset;
- ret = exec_local_req(&hdr, data, datalen);
+ ret = exec_local_req(&hdr, data);
if (ret != SD_RES_SUCCESS)
eprintf("failed to read object %" PRIx64 ", %x\n", oid, ret);
@@ -585,7 +587,7 @@ int remove_object(uint64_t oid)
hdr.opcode = SD_OP_REMOVE_OBJ;
hdr.obj.oid = oid;
- ret = exec_local_req(&hdr, NULL, 0);
+ ret = exec_local_req(&hdr, NULL);
if (ret != SD_RES_SUCCESS)
eprintf("failed to remove object %" PRIx64 ", %x\n", oid, ret);
--
1.7.10.2
More information about the sheepdog
mailing list