[Sheepdog] [PATCH v2 4/7] sheep: teach sheep to use object cache
Liu Yuan
namei.unix at gmail.com
Mon Mar 12 13:10:16 CET 2012
From: Liu Yuan <tailai.ly at taobao.com>
We only intrude IO code for gateway requests. Object IO path from
recovery logic is intact.
Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
sheep/store.c | 42 ++++++++++++++++++++++++++++++++++++++----
1 files changed, 38 insertions(+), 4 deletions(-)
diff --git a/sheep/store.c b/sheep/store.c
index b66f136..1386ed5 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -741,6 +741,28 @@ out:
return ret;
}
+static int handle_gateway_request(struct request *req)
+{
+ struct sd_obj_req *hdr = (struct sd_obj_req *)&req->rq;
+ uint64_t oid = hdr->oid;
+ uint32_t vid = oid_to_vid(oid);
+ uint32_t idx = data_oid_to_idx(oid);
+ struct object_cache *cache;
+ int ret;
+
+ if (is_vdi_obj(oid))
+ idx |= 1 << CACHE_VDI_SHIFT;
+
+ cache = find_object_cache(vid);
+ cache->oid = oid;
+ if (object_cache_lookup(cache, idx) < 0) {
+ ret = object_cache_pull(cache, idx);
+ if (ret != SD_RES_SUCCESS)
+ return ret;
+ }
+ return object_cache_rw(cache, idx, req);
+}
+
void do_io_request(struct work *work)
{
struct request *req = container_of(work, struct request, work);
@@ -765,11 +787,19 @@ void do_io_request(struct work *work)
if (ret != SD_RES_SUCCESS)
goto out;
}
+ if (opcode == SD_OP_CREATE_AND_WRITE_OBJ || is_vmstate_obj(oid)
+ || is_vdi_attr_obj(oid)) {
+ /* For create, we skip the cache.
+ * For vmstate && vdi_attr object, we don't do caching
+ */
+ if (hdr->flags & SD_FLAG_CMD_WRITE)
+ ret = forward_write_obj_req(req);
+ else
+ ret = forward_read_obj_req(req);
+ goto out;
+ }
- if (hdr->flags & SD_FLAG_CMD_WRITE)
- ret = forward_write_obj_req(req);
- else
- ret = forward_read_obj_req(req);
+ ret = handle_gateway_request(req);
}
out:
if (ret != SD_RES_SUCCESS)
@@ -1987,6 +2017,10 @@ int init_store(const char *d)
return ret;
} else
dprintf("no store found\n");
+
+ ret = object_cache_init(d);
+ if (ret)
+ return 1;
return ret;
}
--
1.7.8.2
More information about the sheepdog
mailing list