From: Liu Yuan <[email protected]>

Signed-off-by: Liu Yuan <[email protected]>
---
 sheep/object_cache.c |   29 +++++++++++++++++++++++++++++
 sheep/ops.c          |    2 ++
 sheep/sheep_priv.h   |    1 +
 3 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index 847635a..f45d852 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -461,6 +461,35 @@ int object_is_cached(uint64_t oid)
                return 1; /* found it */
 }
 
+void object_cache_delete(uint32_t vid)
+{
+       struct object_cache *cache;
+
+       cache = find_object_cache(vid);
+       if (cache) {
+               int h = hash(vid);
+               struct object_cache_entry *entry, *t;
+               struct strbuf buf = STRBUF_INIT;
+
+               /* Firstly we free memeory */
+               pthread_mutex_lock(&hashtable_lock[h]);
+               hlist_del(&cache->hash);
+               pthread_mutex_unlock(&hashtable_lock[h]);
+
+               list_for_each_entry_safe(entry, t, &cache->dirty_list, list) {
+                       free(entry);
+               }
+               free(cache);
+
+               /* Then we free disk */
+               strbuf_addf(&buf, "%s/%06"PRIx32, cache_dir, vid);
+               rmdir_r(buf.buf);
+
+               strbuf_release(&buf);
+       }
+
+}
+
 int object_cache_init(const char *p)
 {
        int ret = 0;
diff --git a/sheep/ops.c b/sheep/ops.c
index 3edd932..6da9457 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -93,6 +93,8 @@ static int cluster_del_vdi(const struct sd_req *req, struct 
sd_rsp *rsp,
        ret = del_vdi(hdr->epoch, data, hdr->data_length, &vid,
                      hdr->snapid, &nr_copies);
 
+       if (ret == SD_RES_SUCCESS)
+               object_cache_delete(vid);
        vdi_rsp->vdi_id = vid;
        vdi_rsp->copies = nr_copies;
 
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 6d9a8f8..7b1b05e 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -423,5 +423,6 @@ int object_cache_pull(struct object_cache *oc, uint32_t 
index);
 int object_cache_push(struct object_cache *oc);
 int object_cache_init(const char *p);
 int object_is_cached(uint64_t oid);
+void object_cache_delete(uint32_t vid);
 
 #endif
-- 
1.7.8.2

-- 
sheepdog mailing list
[email protected]
http://lists.wpkg.org/mailman/listinfo/sheepdog

Reply via email to