[sheepdog] [PATCH v3 3/3] sheep: remove cache object for discard operation

Liu Yuan namei.unix at gmail.com
Wed Jul 17 10:12:35 CEST 2013


Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 sheep/object_cache.c |   29 +++++++++++++++++++++++++++++
 sheep/sheep_priv.h   |    1 +
 sheep/store.c        |    6 ++++++
 3 files changed, 36 insertions(+)

diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index e3270df..1212dc2 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -1317,6 +1317,35 @@ out:
 	return ret;
 }
 
+int object_cache_remove(uint64_t oid)
+{
+	/* Inc the entry refcount to exclude the reclaimer */
+	struct object_cache_entry *entry = oid_to_entry(oid);
+	struct object_cache *oc = entry->oc;
+	int ret;
+
+	if (!entry)
+		return SD_RES_NO_OBJ;
+
+	sd_dprintf("%" PRIx64, oid);
+	while (refcount_read(&entry->refcnt) > 1)
+		usleep(100000); /* Object might be in push */
+
+	write_lock_cache(oc);
+	assert(refcount_read(&entry->refcnt) == 1);
+	ret = remove_cache_object(oc, entry_idx(entry));
+	if (ret != SD_RES_SUCCESS) {
+		unlock_cache(oc);
+		return ret;
+	}
+	free_cache_entry(entry);
+	unlock_cache(oc);
+
+	uatomic_sub(&gcache.capacity, CACHE_OBJECT_SIZE);
+
+	return SD_RES_SUCCESS;
+}
+
 int object_cache_init(const char *p)
 {
 	int ret = 0;
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 4d7f28e..bc95cd1 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -394,6 +394,7 @@ 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);
+int object_cache_remove(uint64_t oid);
 
 /* store layout migration */
 int sd_migrate_store(int from, int to);
diff --git a/sheep/store.c b/sheep/store.c
index 177cbcb..6a773d1 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -436,6 +436,12 @@ int remove_object(uint64_t oid)
 	struct sd_req hdr;
 	int ret;
 
+	if (sys->enable_object_cache && object_is_cached(oid)) {
+		ret = object_cache_remove(oid);
+		if (ret != SD_RES_SUCCESS)
+			return ret;
+	}
+
 	sd_init_req(&hdr, SD_OP_REMOVE_OBJ);
 	hdr.obj.oid = oid;
 	hdr.obj.copies = get_vdi_copy_number(oid_to_vid(oid));
-- 
1.7.9.5




More information about the sheepdog mailing list