[Sheepdog] [PATCH 1/3] sheep: unify cow object and regular object writing path
Liu Yuan
namei.unix at gmail.com
Sun Nov 20 12:11:25 CET 2011
From: Liu Yuan <tailai.ly at taobao.com>
This is necessary to do further unifying of sheep requests handling.
small changes on other:
- rename read_from_one into do_read_copy and make it return sd result.
- rename read_from_other_sheep into read_copy_from_cluster
Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
sheep/store.c | 83 +++++++++++++++++---------------------------------------
1 files changed, 25 insertions(+), 58 deletions(-)
diff --git a/sheep/store.c b/sheep/store.c
index c0dc8db..335da61 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -162,8 +162,8 @@ out:
return res;
}
-static int read_from_one(struct request *req, uint32_t epoch, uint64_t oid,
- unsigned ori_rlen, void *buf, uint64_t offset)
+static int do_read_copy(struct request *req, uint32_t epoch, uint64_t oid,
+ unsigned ori_rlen, void *buf, uint64_t offset)
{
int i, n, nr, ret;
unsigned wlen, rlen;
@@ -195,7 +195,6 @@ static int read_from_one(struct request *req, uint32_t epoch, uint64_t oid,
ret = store.read(oid, &iocb);
if (ret != SD_RES_SUCCESS)
continue;
- ret = 0;
store.close(oid, &iocb);
goto out;
}
@@ -224,7 +223,7 @@ static int read_from_one(struct request *req, uint32_t epoch, uint64_t oid,
switch (rsp->result) {
case SD_RES_SUCCESS:
- ret = 0;
+ ret = SD_RES_SUCCESS;
goto out;
case SD_RES_OLD_NODE_VER:
case SD_RES_NEW_NODE_VER:
@@ -235,12 +234,12 @@ static int read_from_one(struct request *req, uint32_t epoch, uint64_t oid,
}
}
- ret = -1;
+ ret = SD_RES_EIO;
out:
return ret;
}
-static int read_from_other_sheep(struct request *req, uint32_t epoch,
+static int read_copy_from_cluster(struct request *req, uint32_t epoch,
uint64_t oid, char *buf, int copies)
{
int ret;
@@ -248,7 +247,7 @@ static int read_from_other_sheep(struct request *req, uint32_t epoch,
rlen = SD_DATA_OBJ_SIZE;
- ret = read_from_one(req, epoch, oid, rlen, buf, 0);
+ ret = do_read_copy(req, epoch, oid, rlen, buf, 0);
return ret;
}
@@ -636,7 +635,7 @@ static int store_write_obj(struct request *req, uint32_t epoch)
return ret;
}
-static int store_create_and_write_obj_cow(struct request *req, uint32_t epoch)
+static int store_create_and_write_obj(struct request *req, uint32_t epoch)
{
struct sd_obj_req *hdr = (struct sd_obj_req *)&req->rq;
int ret;
@@ -654,30 +653,24 @@ static int store_create_and_write_obj_cow(struct request *req, uint32_t epoch)
ret = store.open(hdr->oid, &iocb, 1);
if (ret != SD_RES_SUCCESS)
return ret;
-
- dprintf("%" PRIu64 ", %" PRIx64 "\n", hdr->oid, hdr->cow_oid);
-
- buf = valloc(SD_DATA_OBJ_SIZE);
- if (!buf) {
- eprintf("failed to allocate memory\n");
- ret = SD_RES_NO_MEM;
- goto out;
- }
- ret = read_from_other_sheep(req, hdr->epoch, hdr->cow_oid, buf,
- hdr->copies);
- if (ret) {
- eprintf("failed to read old object\n");
- ret = SD_RES_EIO;
- goto out;
- }
- iocb.buf = buf;
- iocb.length = SD_DATA_OBJ_SIZE;
- iocb.offset = 0;
- ret = store.write(hdr->oid, &iocb);
- if (ret != SD_RES_SUCCESS) {
- goto out;
+ if (hdr->flags & SD_FLAG_CMD_COW) {
+ dprintf("%" PRIu64 ", %" PRIx64 "\n", hdr->oid, hdr->cow_oid);
+
+ buf = xzalloc(SD_DATA_OBJ_SIZE);
+ ret = read_copy_from_cluster(req, hdr->epoch, hdr->cow_oid, buf,
+ hdr->copies);
+ if (ret != SD_RES_SUCCESS) {
+ eprintf("failed to read cow object\n");
+ goto out;
+ }
+ iocb.buf = buf;
+ iocb.length = SD_DATA_OBJ_SIZE;
+ iocb.offset = 0;
+ ret = store.write(hdr->oid, &iocb);
+ if (ret != SD_RES_SUCCESS) {
+ goto out;
+ }
}
-
ret = do_write_obj(&iocb, req, epoch);
out:
free(buf);
@@ -685,29 +678,6 @@ out:
return ret;
}
-static int store_create_and_write_obj(struct request *req, uint32_t epoch)
-{
- struct sd_obj_req *hdr = (struct sd_obj_req *)&req->rq;
- int ret;
- struct siocb iocb;
-
- if (!hdr->copies) {
- eprintf("the number of copies cannot be zero\n");
- return SD_RES_INVALID_PARMS;
- }
-
- memset(&iocb, 0, sizeof(iocb));
- iocb.epoch = epoch;
- iocb.flags = hdr->flags;
- ret = store.open(hdr->oid, &iocb, 1);
- if (ret != SD_RES_SUCCESS)
- return ret;
-
- ret = do_write_obj(&iocb, req, epoch);
- store.close(hdr->oid, &iocb);
- return ret;
-}
-
static int store_queue_request_local(struct request *req, uint32_t epoch)
{
struct sd_obj_req *hdr = (struct sd_obj_req *)&req->rq;
@@ -726,10 +696,7 @@ static int store_queue_request_local(struct request *req, uint32_t epoch)
ret = store_read_obj(req, epoch);
break;
case SD_OP_CREATE_AND_WRITE_OBJ:
- if (hdr->flags & SD_FLAG_CMD_COW)
- ret = store_create_and_write_obj_cow(req, epoch);
- else
- ret = store_create_and_write_obj(req, epoch);
+ ret = store_create_and_write_obj(req, epoch);
break;
}
--
1.7.8.rc3
More information about the sheepdog
mailing list