[sheepdog] [PATCH 2/2] collie: use SD_OP_DELETE_CACHE to delete cache

Liu Yuan namei.unix at gmail.com
Mon Jan 28 04:05:07 CET 2013


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

We'd better broadcast SD_OP_DELETE_CACHE to all the nodes that delete cache in
one shot to make sure the cache is completely removed on all nodes.

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

diff --git a/collie/vdi.c b/collie/vdi.c
index 7109be9..581dcdc 100644
--- a/collie/vdi.c
+++ b/collie/vdi.c
@@ -727,6 +727,22 @@ static int do_vdi_delete(const char *vdiname, int snap_id, const char *snap_tag)
 	struct sd_req hdr;
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
 	char data[SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN];
+	uint32_t vid;
+
+	ret = find_vdi_name(vdiname, snap_id, snap_tag, &vid, 0);
+	if (ret < 0) {
+		fprintf(stderr, "Failed to open VDI %s\n", vdiname);
+		return EXIT_FAILURE;
+	}
+
+	sd_init_req(&hdr, SD_OP_DELETE_CACHE);
+	hdr.obj.oid = vid_to_vdi_oid(vid);
+
+	ret = send_light_req(&hdr, sdhost, sdport);
+	if (ret) {
+		fprintf(stderr, "failed to execute request\n");
+		return EXIT_FAILURE;
+	}
 
 	fd = connect_to(sdhost, sdport);
 	if (fd < 0)
diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index 355acae..db7d936 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -1172,27 +1172,6 @@ int object_cache_flush_and_del(const struct request *req)
 	return SD_RES_SUCCESS;
 }
 
-void object_cache_remove(uint64_t oid)
-{
-	uint32_t vid = oid_to_vid(oid);
-	uint32_t idx = object_cache_oid_to_idx(oid);
-	struct object_cache *oc;
-	struct object_cache_entry *entry;
-
-	oc = find_object_cache(vid, false);
-	if (!oc)
-		return;
-
-	write_lock_cache(oc);
-	entry = lru_tree_search(&oc->lru_tree, idx);
-	if (!entry)
-		goto out;
-	free_cache_entry(entry);
-out:
-	unlock_cache(oc);
-	return;
-}
-
 static int load_cache_object(struct object_cache *cache)
 {
 	DIR *dir;
diff --git a/sheep/ops.c b/sheep/ops.c
index b660b9f..43aaa2f 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -772,7 +772,6 @@ int peer_remove_obj(struct request *req)
 	uint64_t oid = req->rq.obj.oid;
 
 	objlist_cache_remove(oid);
-	object_cache_remove(oid);
 
 	return sd_store->remove_object(oid);
 }
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index c48b686..5b58185 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -394,7 +394,6 @@ int object_cache_flush_vdi(const struct request *req);
 int object_cache_flush_and_del(const struct request *req);
 void object_cache_delete(uint32_t vid);
 int object_cache_init(const char *p);
-void object_cache_remove(uint64_t oid);
 
 /* store layout migration */
 int sd_migrate_store(int from, int to);
-- 
1.7.9.5




More information about the sheepdog mailing list