There are only two callers, of which one doesn't need the data_length update and can be simplified a lot by not having to fake up the request.
Signed-off-by: Christoph Hellwig <[email protected]> --- sheep/object_cache.c | 54 ++++++++++++--------------------------------------- 1 file changed, 13 insertions(+), 41 deletions(-) Index: sheepdog/sheep/object_cache.c =================================================================== --- sheepdog.orig/sheep/object_cache.c 2012-07-13 12:46:12.396565209 +0200 +++ sheepdog/sheep/object_cache.c 2012-07-13 12:47:14.059898174 +0200 @@ -438,19 +438,6 @@ static int object_cache_write_int(struct return 0; } -static int object_cache_read_int(struct object_cache *oc, uint32_t idx, - struct request *req) -{ - struct sd_req *hdr = &req->rq; - int ret; - - ret = read_cache_object(oc->vid, idx, req->data, hdr->data_length, - hdr->obj.offset); - if (ret == SD_RES_SUCCESS) - req->rp.data_length = hdr->data_length; - return ret; -} - static int create_cache_object(struct object_cache *oc, uint32_t idx, void *buffer, size_t buf_size) { @@ -781,9 +768,16 @@ int object_cache_handle_request(struct r } if (req->rq.flags & SD_FLAG_CMD_WRITE) - return object_cache_write_int(cache, idx, req); - else - return object_cache_read_int(cache, idx, req); + ret = object_cache_write_int(cache, idx, req); + else { + ret = read_cache_object(cache->vid, idx, req->data, + req->rq.data_length, + req->rq.obj.offset); + if (ret == SD_RES_SUCCESS) + req->rp.data_length = req->rq.data_length; + } + + return ret; } int object_cache_write(uint64_t oid, char *data, unsigned int datalen, @@ -823,32 +817,10 @@ int object_cache_write(uint64_t oid, cha int object_cache_read(uint64_t oid, char *data, unsigned int datalen, uint64_t offset) { - int ret; - struct request *req; - uint32_t vid = oid_to_vid(oid); - uint32_t idx = object_cache_oid_to_idx(oid); - struct object_cache *cache; - - cache = find_object_cache(vid, 0); + struct object_cache *cache = find_object_cache(oid_to_vid(oid), 0); - req = zalloc(sizeof(*req)); - if (!req) - return SD_RES_NO_MEM; - - sd_init_req(&req->rq, SD_OP_READ_OBJ); - req->rq.data_length = datalen; - - req->rq.obj.oid = oid; - req->rq.obj.offset = offset; - - req->data = data; - req->op = get_sd_op(req->rq.opcode); - - ret = object_cache_read_int(cache, idx, req); - - free(req); - - return ret; + return read_cache_object(cache->vid, object_cache_oid_to_idx(oid), + data, datalen, offset); } int object_cache_flush_vdi(struct request *req) -- sheepdog mailing list [email protected] http://lists.wpkg.org/mailman/listinfo/sheepdog
