[sheepdog] [PATCH 05/10] sheep: cleanup preallocate
Liu Yuan
namei.unix at gmail.com
Tue Oct 15 16:36:38 CEST 2013
Since trim/untrim is removed from sheep, we don't need to extend buffer.
Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
sheep/object_cache.c | 21 ++++-----------------
sheep/plain_store.c | 10 ++++------
2 files changed, 8 insertions(+), 23 deletions(-)
diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index 6ad5642..e1968fc 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -745,8 +745,7 @@ out:
}
static int create_cache_object(struct object_cache *oc, uint32_t idx,
- void *buffer, size_t buf_size, off_t offset,
- size_t obj_size)
+ void *buffer, size_t buf_size)
{
int flags = def_open_flags | O_CREAT | O_EXCL, fd;
int ret = SD_RES_OID_EXIST;
@@ -765,17 +764,7 @@ static int create_cache_object(struct object_cache *oc, uint32_t idx,
goto out;
}
- /* We need to extend it if the buffer is trimmed */
- if (offset != 0 || buf_size != obj_size) {
- ret = prealloc(fd, obj_size);
- if (unlikely(ret < 0)) {
- ret = SD_RES_EIO;
- sd_err("%m");
- goto out_close;
- }
- }
-
- ret = xpwrite(fd, buffer, buf_size, offset);
+ ret = xwrite(fd, buffer, buf_size);
if (unlikely(ret != buf_size)) {
ret = SD_RES_EIO;
sd_err("failed, vid %"PRIx32", idx %"PRIx32, oc->vid, idx);
@@ -796,7 +785,7 @@ static int create_cache_object(struct object_cache *oc, uint32_t idx,
goto out_close;
}
ret = SD_RES_SUCCESS;
- sd_debug("%08"PRIx32" size %zu", idx, obj_size);
+ sd_debug("%08"PRIx32" size %zu", idx, buf_size);
out_close:
close(fd);
unlink(tmp_path);
@@ -808,7 +797,6 @@ out:
static int object_cache_pull(struct object_cache *oc, uint32_t idx)
{
struct sd_req hdr;
- struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
int ret = SD_RES_NO_MEM;
uint64_t oid = idx_to_oid(oc->vid, idx);
uint32_t data_length = get_objsize(oid);
@@ -824,8 +812,7 @@ static int object_cache_pull(struct object_cache *oc, uint32_t idx)
goto err;
sd_debug("oid %"PRIx64" pulled successfully", oid);
- ret = create_cache_object(oc, idx, buf, rsp->data_length,
- rsp->obj.offset, data_length);
+ ret = create_cache_object(oc, idx, buf, data_length);
/*
* We try to delay reclaim objects to avoid object ping-pong
* because the pulled object is clean and likely to be reclaimed
diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index 9dc3b7a..4367a9e 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -374,12 +374,10 @@ int default_create_and_write(uint64_t oid, const struct siocb *iocb)
return err_to_sderr(path, oid, errno);
}
- if (iocb->offset != 0 || iocb->length != get_store_objsize(oid)) {
- ret = prealloc(fd, get_store_objsize(oid));
- if (ret < 0) {
- ret = err_to_sderr(path, oid, errno);
- goto out;
- }
+ ret = prealloc(fd, get_store_objsize(oid));
+ if (ret < 0) {
+ ret = err_to_sderr(path, oid, errno);
+ goto out;
}
ret = xpwrite(fd, iocb->buf, len, iocb->offset);
--
1.7.9.5
More information about the sheepdog
mailing list