[Sheepdog] [PATCH v6 4/8] sheep: teach sheep to use object cache

Liu Yuan namei.unix at gmail.com
Mon Mar 26 15:48:26 CEST 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>
---
 include/sheepdog_proto.h |    1 +
 sheep/store.c            |   54 +++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 50 insertions(+), 5 deletions(-)

diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index 2d0d5ec..84f12f1 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -32,6 +32,7 @@
 
 #define SD_FLAG_CMD_WRITE    0x01
 #define SD_FLAG_CMD_COW      0x02
+#define SD_FLAG_CMD_CACHE    0x04
 
 #define SD_RES_SUCCESS       0x00 /* Success */
 #define SD_RES_UNKNOWN       0x01 /* Unknown error */
diff --git a/sheep/store.c b/sheep/store.c
index 82bbff1..66ac020 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -758,6 +758,44 @@ 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, 1);
+	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);
+}
+
+static int bypass_object_cache(struct sd_obj_req *hdr)
+{
+	uint64_t oid = hdr->oid;
+
+	if (!(hdr->flags & SD_FLAG_CMD_CACHE))
+		return 1;
+
+	/* For create, we skip the cache because of consistency check.
+	 * For vmstate && vdi_attr object, we don't do caching
+	 */
+	if (hdr->opcode == SD_OP_CREATE_AND_WRITE_OBJ || is_vmstate_obj(oid)
+			|| is_vdi_attr_obj(oid))
+		return 1;
+	return 0;
+}
+
 void do_io_request(struct work *work)
 {
 	struct request *req = container_of(work, struct request, work);
@@ -782,11 +820,13 @@ void do_io_request(struct work *work)
 			if (ret != SD_RES_SUCCESS)
 				goto out;
 		}
-
-		if (hdr->flags & SD_FLAG_CMD_WRITE)
-			ret = forward_write_obj_req(req);
-		else
-			ret = forward_read_obj_req(req);
+		if (bypass_object_cache(hdr)) {
+			if (hdr->flags & SD_FLAG_CMD_WRITE)
+				ret = forward_write_obj_req(req);
+			else
+				ret = forward_read_obj_req(req);
+		} else
+			ret = handle_gateway_request(req);
 	}
 out:
 	if (ret != SD_RES_SUCCESS)
@@ -2009,6 +2049,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