[sheepdog] [PATCH 1/3] sheep: remove oid from object cache internal list and tree
Liu Yuan
namei.unix at gmail.com
Wed Jun 13 11:17:26 CEST 2012
From: Liu Yuan <tailai.ly at taobao.com>
We should remove it from object cache internal state too otherwise
flush will return ERROR by reading a non-existent object later on
Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
sheep/object_cache.c | 38 +++++++++++++++++++++++++++++++++-----
sheep/ops.c | 4 +++-
sheep/sheep_priv.h | 1 +
3 files changed, 37 insertions(+), 6 deletions(-)
diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index 007edfc..c844436 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -125,9 +125,8 @@ dirty_tree_insert(struct rb_root *root, struct object_cache_entry *new)
return NULL; /* insert successfully */
}
-__attribute__ ((unused)) static struct
-object_cache_entry *dirty_tree_search(struct rb_root *root,
- struct object_cache_entry *entry)
+static struct object_cache_entry *dirty_tree_search(struct rb_root *root,
+ uint32_t idx)
{
struct rb_node *n = root->rb_node;
struct object_cache_entry *t;
@@ -135,9 +134,9 @@ object_cache_entry *dirty_tree_search(struct rb_root *root,
while (n) {
t = rb_entry(n, struct object_cache_entry, rb);
- if (entry->idx < t->idx)
+ if (idx < t->idx)
n = n->rb_left;
- else if (entry->idx > t->idx)
+ else if (idx > t->idx)
n = n->rb_right;
else
return t; /* found it */
@@ -927,6 +926,35 @@ int object_cache_flush_and_del(struct request *req)
return SD_RES_SUCCESS;
}
+void object_cache_remove(uint64_t oid)
+{
+ uint32_t vid = oid_to_vid(oid);
+ uint32_t idx = data_oid_to_idx(oid);
+ struct object_cache *oc;
+ struct object_cache_entry *entry;
+ int tree_id = 0;
+
+ if (is_vdi_obj(oid))
+ idx |= 1 << CACHE_VDI_SHIFT;
+
+ oc = find_object_cache(vid, 0);
+ if (!oc)
+ return;
+
+ pthread_mutex_lock(&oc->lock);
+ entry = dirty_tree_search(&oc->dirty_trees[tree_id], idx);
+ if (!entry) {
+ tree_id = 1;
+ entry = dirty_tree_search(&oc->dirty_trees[tree_id], idx);
+ }
+ if (!entry)
+ goto out;
+ del_from_dirty_tree_and_list(entry, &oc->dirty_trees[tree_id]);
+out:
+ pthread_mutex_unlock(&oc->lock);
+ return;
+}
+
int object_cache_init(const char *p)
{
int ret = 0;
diff --git a/sheep/ops.c b/sheep/ops.c
index 59df88e..541882d 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -583,6 +583,9 @@ static int store_remove_obj(struct request *req)
struct strbuf buf = STRBUF_INIT;
int ret = SD_RES_SUCCESS;
+ objlist_cache_remove(oid);
+ object_cache_remove(oid);
+
strbuf_addf(&buf, "%s%016" PRIx64, obj_path, oid);
if (unlink(buf.buf) < 0) {
if (errno == ENOENT) {
@@ -592,7 +595,6 @@ static int store_remove_obj(struct request *req)
eprintf("%m\n");
ret = SD_RES_EIO;
}
- objlist_cache_remove(oid);
out:
strbuf_release(&buf);
return ret;
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 14bb1e7..f082c5b 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -303,6 +303,7 @@ int prealloc(int fd, uint32_t size);
int objlist_cache_insert(uint64_t oid);
void objlist_cache_remove(uint64_t oid);
+void object_cache_remove(uint64_t oid);
void req_done(struct request *req);
--
1.7.10.2
More information about the sheepdog
mailing list