[Sheepdog] [PATCH 2/2] sheep: return error when read/write cannot process full-length data
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Fri Nov 18 11:43:37 CET 2011
Sheepdog block driver doesn't expect that SD_OP_READ/WRITE_OBJECT
processes less data than requested, so we should return SD_RES_EIO in
that case.
With this patch, we can return the result code in read_object() and
make code readable.
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
sheep/sdnet.c | 10 +++++-----
sheep/sheep_priv.h | 1 -
sheep/simple_store.c | 8 ++++----
sheep/store.c | 37 +++++++++++--------------------------
sheep/vdi.c | 20 ++++++++++----------
5 files changed, 30 insertions(+), 46 deletions(-)
diff --git a/sheep/sdnet.c b/sheep/sdnet.c
index 053ee8d..98cafd8 100644
--- a/sheep/sdnet.c
+++ b/sheep/sdnet.c
@@ -683,12 +683,12 @@ int read_object(struct sheepdog_vnode_list_entry *e,
ret = read_object_local(oid, data, datalen, offset, nr,
node_version);
- if (ret < 0) {
+ if (ret != SD_RES_SUCCESS) {
eprintf("fail %"PRIx64" %"PRId32"\n", oid, ret);
return ret;
}
- return ret;
+ return SD_RES_SUCCESS;
}
}
@@ -704,7 +704,7 @@ int read_object(struct sheepdog_vnode_list_entry *e,
if (fd < 0) {
printf("%s(%d): %s, %m\n", __func__, __LINE__,
name);
- return -SD_RES_EIO;
+ return SD_RES_EIO;
}
memset(&hdr, 0, sizeof(hdr));
@@ -725,12 +725,12 @@ int read_object(struct sheepdog_vnode_list_entry *e,
}
if (rsp->result == SD_RES_SUCCESS)
- return rsp->data_length;
+ return SD_RES_SUCCESS;
last_error = rsp->result;
}
- return -last_error;
+ return last_error;
}
int remove_object(struct sheepdog_vnode_list_entry *e,
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 99924dd..5e10a2f 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -163,7 +163,6 @@ struct siocb {
void *buf;
uint32_t length;
uint64_t offset;
- size_t rw_size;
};
struct store_driver {
diff --git a/sheep/simple_store.c b/sheep/simple_store.c
index 59d0a8a..92e5504 100644
--- a/sheep/simple_store.c
+++ b/sheep/simple_store.c
@@ -115,16 +115,16 @@ out:
static int simple_store_write(uint64_t oid, struct siocb *iocb)
{
- iocb->rw_size = xpwrite(iocb->fd, iocb->buf, iocb->length, iocb->offset);
- if (iocb->rw_size < 0)
+ int size = xpwrite(iocb->fd, iocb->buf, iocb->length, iocb->offset);
+ if (size != iocb->length)
return SD_RES_EIO;
return SD_RES_SUCCESS;
}
static int simple_store_read(uint64_t oid, struct siocb *iocb)
{
- iocb->rw_size = xpread(iocb->fd, iocb->buf, iocb->length, iocb->offset);
- if (iocb->rw_size < 0)
+ int size = xpread(iocb->fd, iocb->buf, iocb->length, iocb->offset);
+ if (size != iocb->length)
return SD_RES_EIO;
return SD_RES_SUCCESS;
}
diff --git a/sheep/store.c b/sheep/store.c
index f794785..c0dc8db 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -163,7 +163,7 @@ out:
}
static int read_from_one(struct request *req, uint32_t epoch, uint64_t oid,
- unsigned *ori_rlen, void *buf, uint64_t offset)
+ unsigned ori_rlen, void *buf, uint64_t offset)
{
int i, n, nr, ret;
unsigned wlen, rlen;
@@ -190,12 +190,11 @@ static int read_from_one(struct request *req, uint32_t epoch, uint64_t oid,
continue;
iocb.buf = buf;
- iocb.length = *ori_rlen;
+ iocb.length = ori_rlen;
iocb.offset = offset;
ret = store.read(oid, &iocb);
if (ret != SD_RES_SUCCESS)
continue;
- *ori_rlen = iocb.rw_size;
ret = 0;
store.close(oid, &iocb);
goto out;
@@ -210,7 +209,7 @@ static int read_from_one(struct request *req, uint32_t epoch, uint64_t oid,
hdr.oid = oid;
hdr.epoch = epoch;
- rlen = *ori_rlen;
+ rlen = ori_rlen;
wlen = 0;
hdr.flags = SD_FLAG_CMD_IO_LOCAL;
hdr.data_length = rlen;
@@ -225,7 +224,6 @@ static int read_from_one(struct request *req, uint32_t epoch, uint64_t oid,
switch (rsp->result) {
case SD_RES_SUCCESS:
- *ori_rlen = rlen;
ret = 0;
goto out;
case SD_RES_OLD_NODE_VER:
@@ -250,7 +248,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 = read_from_one(req, epoch, oid, rlen, buf, 0);
return ret;
}
@@ -526,7 +524,7 @@ int read_object_local(uint64_t oid, char *data, unsigned int datalen,
req = zalloc(sizeof(*req));
if (!req)
- return -SD_RES_NO_MEM;
+ return SD_RES_NO_MEM;
hdr = (struct sd_obj_req *)&req->rq;
rsp = (struct sd_obj_rsp *)&req->rp;
@@ -543,13 +541,7 @@ int read_object_local(uint64_t oid, char *data, unsigned int datalen,
rsp_data_length = rsp->data_length;
free(req);
- if (ret != 0)
- return -ret;
-
- if (rsp_data_length != datalen)
- return -SD_RES_EIO;
-
- return rsp_data_length;
+ return ret;
}
static int store_remove_obj(struct request *req, uint32_t epoch)
@@ -591,20 +583,13 @@ static int store_read_obj(struct request *req, uint32_t epoch)
if (ret != SD_RES_SUCCESS)
goto out;
- rsp->data_length = iocb.rw_size;
+ rsp->data_length = hdr->data_length;
rsp->copies = sys->nr_sobjs;
out:
store.close(hdr->oid, &iocb);
return ret;
}
-static inline int write_object_in_full(uint64_t oid, struct siocb *iocb)
-{
- if (!store.write(oid, iocb) && iocb->rw_size != iocb->length)
- return SD_RES_EIO;
- return SD_RES_SUCCESS;
-}
-
static int do_write_obj(struct siocb *iocb, struct request *req, uint32_t epoch)
{
struct sd_obj_req *hdr = (struct sd_obj_req *)&req->rq;
@@ -624,11 +609,11 @@ static int do_write_obj(struct siocb *iocb, struct request *req, uint32_t epoch)
hdr->offset, path, jrnl_path);
if (!jd)
return SD_RES_EIO;
- ret = write_object_in_full(oid, iocb);
+ ret = store.write(oid, iocb);
jrnl_end(jd);
- } else {
- ret = write_object_in_full(oid, iocb);
- }
+ } else
+ ret = store.write(oid, iocb);
+
return ret;
}
diff --git a/sheep/vdi.c b/sheep/vdi.c
index 3d36d89..84ab539 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -61,7 +61,7 @@ static int create_vdi_obj(uint32_t epoch, char *name, uint32_t new_vid, uint64_t
ret = read_object(entries, nr_vnodes, nr_zones, epoch,
vid_to_vdi_oid(base_vid), (char *)base,
sizeof(*base), 0, copies);
- if (ret < 0) {
+ if (ret != SD_RES_SUCCESS) {
ret = SD_RES_BASE_VDI_READ;
goto out;
}
@@ -77,7 +77,7 @@ static int create_vdi_obj(uint32_t epoch, char *name, uint32_t new_vid, uint64_t
ret = read_object(entries, nr_vnodes, nr_zones, epoch,
vid_to_vdi_oid(cur_vid), (char *)cur,
SD_INODE_HEADER_SIZE, 0, copies);
- if (ret < 0) {
+ if (ret != SD_RES_SUCCESS) {
vprintf(SDOG_ERR, "failed\n");
ret = SD_RES_BASE_VDI_READ;
goto out;
@@ -181,7 +181,7 @@ static int find_first_vdi(uint32_t epoch, unsigned long start, unsigned long end
ret = read_object(entries, nr_vnodes, nr_zones, epoch,
vid_to_vdi_oid(i), (char *)inode,
SD_INODE_HEADER_SIZE, 0, nr_reqs);
- if (ret < 0) {
+ if (ret != SD_RES_SUCCESS) {
ret = SD_RES_EIO;
goto out;
}
@@ -381,7 +381,7 @@ int del_vdi(uint32_t epoch, char *data, int data_len, uint32_t *vid,
ret = read_object(entries, nr_vnodes, nr_zones, epoch,
vid_to_vdi_oid(*vid), (char *)inode,
SD_INODE_HEADER_SIZE, 0, nr_reqs);
- if (ret < 0) {
+ if (ret != SD_RES_SUCCESS) {
ret = SD_RES_EIO;
goto out;
}
@@ -460,7 +460,7 @@ static void delete_one(struct work *work, int idx)
vid_to_vdi_oid(vdi_id), (void *)inode, sizeof(*inode),
0, sys->nr_sobjs);
- if (ret != sizeof(*inode)) {
+ if (ret != SD_RES_SUCCESS) {
eprintf("cannot find vdi object\n");
goto out;
}
@@ -523,7 +523,7 @@ again:
vid_to_vdi_oid(vid), (char *)inode,
SD_INODE_HEADER_SIZE, 0, sys->nr_sobjs);
- if (ret != SD_INODE_HEADER_SIZE) {
+ if (ret != SD_RES_SUCCESS) {
eprintf("cannot find vdi object\n");
goto err;
}
@@ -566,7 +566,7 @@ next:
vid_to_vdi_oid(vid), (char *)inode,
SD_INODE_HEADER_SIZE, 0, sys->nr_sobjs);
- if (ret != SD_INODE_HEADER_SIZE) {
+ if (ret != SD_RES_SUCCESS) {
eprintf("cannot find vdi object\n");
vid = 0;
goto out;
@@ -678,7 +678,7 @@ int get_vdi_attr(uint32_t epoch, struct sheepdog_vdi_attr *vattr, int data_len,
ret = read_object(entries, nr_vnodes, nr_zones, epoch, oid, (char *)&tmp_attr,
sizeof(tmp_attr), 0, copies);
- if (ret == -SD_RES_NO_OBJ && write) {
+ if (ret == SD_RES_NO_OBJ && write) {
ret = write_object(entries, nr_vnodes, nr_zones, epoch, oid,
(char *)vattr, data_len, 0, 0, copies, 1);
if (ret)
@@ -688,8 +688,8 @@ int get_vdi_attr(uint32_t epoch, struct sheepdog_vdi_attr *vattr, int data_len,
goto out;
}
- if (ret < 0)
- return -ret;
+ if (ret != SD_RES_SUCCESS)
+ return ret;
/* compare attribute header */
if (strcmp(tmp_attr.name, vattr->name) == 0 &&
--
1.7.2.5
More information about the sheepdog
mailing list