Split object_cache_rw into one helper for reads and one for writes.
Signed-off-by: Christoph Hellwig <[email protected]>
---
sheep/object_cache.c | 56 ++++++++++++++++++++++++++++++---------------------
1 file changed, 33 insertions(+), 23 deletions(-)
Index: sheepdog/sheep/object_cache.c
===================================================================
--- sheepdog.orig/sheep/object_cache.c 2012-07-13 09:24:16.419970922 +0200
+++ sheepdog/sheep/object_cache.c 2012-07-13 12:46:12.396565209 +0200
@@ -412,36 +412,42 @@ out:
return ret;
}
-static int object_cache_rw(struct object_cache *oc, uint32_t idx,
- struct request *req)
+static int object_cache_write_int(struct object_cache *oc, uint32_t idx,
+ struct request *req)
{
struct sd_req *hdr = &req->rq;
+ struct object_cache_entry *entry;
uint64_t bmap = 0;
int ret;
dprintf("%08"PRIx32", len %"PRIu32", off %"PRIu64"\n", idx,
hdr->data_length, hdr->obj.offset);
- if (hdr->flags & SD_FLAG_CMD_WRITE) {
- struct object_cache_entry *entry;
- ret = write_cache_object(oc->vid, idx, req->data,
- hdr->data_length, hdr->obj.offset);
- if (ret != SD_RES_SUCCESS)
- goto out;
- bmap = calc_object_bmap(hdr->data_length, hdr->obj.offset);
- entry = alloc_cache_entry(idx, bmap, 0);
- pthread_mutex_lock(&oc->lock);
- add_to_dirty_tree_and_list(oc, entry);
- pthread_mutex_unlock(&oc->lock);
- } else {
- ret = read_cache_object(oc->vid, idx, req->data,
- hdr->data_length, hdr->obj.offset);
- if (ret != SD_RES_SUCCESS)
- goto out;
+ ret = write_cache_object(oc->vid, idx, req->data, hdr->data_length,
+ hdr->obj.offset);
+ if (ret != SD_RES_SUCCESS)
+ return ret;
+
+ bmap = calc_object_bmap(hdr->data_length, hdr->obj.offset);
+ entry = alloc_cache_entry(idx, bmap, 0);
+
+ pthread_mutex_lock(&oc->lock);
+ add_to_dirty_tree_and_list(oc, entry);
+ pthread_mutex_unlock(&oc->lock);
+ 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;
- }
-out:
return ret;
}
@@ -773,7 +779,11 @@ int object_cache_handle_request(struct r
if (ret != SD_RES_SUCCESS)
return ret;
}
- return object_cache_rw(cache, idx, req);
+
+ 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);
}
int object_cache_write(uint64_t oid, char *data, unsigned int datalen,
@@ -804,7 +814,7 @@ int object_cache_write(uint64_t oid, cha
req->data = data;
req->op = get_sd_op(req->rq.opcode);
- ret = object_cache_rw(cache, idx, req);
+ ret = object_cache_write_int(cache, idx, req);
free(req);
return ret;
@@ -834,7 +844,7 @@ int object_cache_read(uint64_t oid, char
req->data = data;
req->op = get_sd_op(req->rq.opcode);
- ret = object_cache_rw(cache, idx, req);
+ ret = object_cache_read_int(cache, idx, req);
free(req);
--
sheepdog mailing list
[email protected]
http://lists.wpkg.org/mailman/listinfo/sheepdog