[sheepdog] [PATCH 2/2] sheep: release object cache when vdi is released

Liu Yuan namei.unix at gmail.com
Tue Jan 29 06:22:06 CET 2013


From: Liu Yuan <tailai.ly at taobao.com>

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/object_cache.c |    3 +--
 sheep/ops.c          |   20 +++++++++++++++++++-
 sheep/sheep_priv.h   |    2 +-
 3 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index 4e26392..b0a4224 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -1145,9 +1145,8 @@ int object_cache_read(uint64_t oid, char *data, unsigned int datalen,
 	return ret;
 }
 
-int object_cache_flush_vdi(const struct request *req)
+int object_cache_flush_vdi(uint32_t vid)
 {
-	uint32_t vid = oid_to_vid(req->rq.obj.oid);
 	struct object_cache *cache;
 
 	cache = find_object_cache(vid, false);
diff --git a/sheep/ops.c b/sheep/ops.c
index c7370cd..e0ab1db 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -359,6 +359,22 @@ static int cluster_get_vdi_attr(struct request *req)
 	return ret;
 }
 
+static int local_release_vdi(struct request *req)
+{
+	uint32_t vid = req->rq.vdi.base_vdi_id;
+
+	if (!vid) {
+		sd_iprintf("Some VDI failed to release the object cache. "
+			   "Probably you are running old QEMU.\n");
+		return SD_RES_SUCCESS;
+	}
+
+	object_cache_flush_vdi(vid);
+	object_cache_delete(vid);
+
+	return SD_RES_SUCCESS;
+}
+
 static int local_get_store_list(struct request *req)
 {
 	struct strbuf buf = STRBUF_INIT;
@@ -680,7 +696,8 @@ static int local_flush_vdi(struct request *req)
 	int ret = SD_RES_INVALID_PARMS;
 
 	if (is_object_cache_enabled()) {
-		ret = object_cache_flush_vdi(req);
+		uint32_t vid = oid_to_vid(req->rq.obj.oid);
+		ret = object_cache_flush_vdi(vid);
 		if (ret != SD_RES_SUCCESS)
 			return ret;
 	}
@@ -996,6 +1013,7 @@ static struct sd_op_template sd_ops[] = {
 	[SD_OP_RELEASE_VDI] = {
 		.name = "RELEASE_VDI",
 		.type = SD_OP_TYPE_LOCAL,
+		.process_work = local_release_vdi,
 	},
 
 	[SD_OP_GET_STORE_LIST] = {
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 5b58185..a1e89c0 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -390,7 +390,7 @@ int object_cache_write(uint64_t oid, char *data, unsigned int datalen,
 		       uint64_t offset, uint16_t flags, bool create);
 int object_cache_read(uint64_t oid, char *data, unsigned int datalen,
 		      uint64_t offset);
-int object_cache_flush_vdi(const struct request *req);
+int object_cache_flush_vdi(uint32_t vid);
 int object_cache_flush_and_del(const struct request *req);
 void object_cache_delete(uint32_t vid);
 int object_cache_init(const char *p);
-- 
1.7.9.5




More information about the sheepdog mailing list