[sheepdog] [PATCH v3 7/8] object cache: refactor object_cache_remove()
levin li
levin108 at gmail.com
Thu Jul 26 09:17:06 CEST 2012
From: levin li <xingke.lwp at taobao.com>
Since all the cache entry are not stored in memory, we can not
only remove entry from dirty tree/list, we should also remove it
from the object tree/list.
Signed-off-by: levin li <xingke.lwp at taobao.com>
---
sheep/object_cache.c | 29 ++++++-----------------------
1 files changed, 6 insertions(+), 23 deletions(-)
diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index d9750a0..476fb93 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -203,32 +203,12 @@ static struct object_cache_entry *object_tree_search(struct rb_root *root,
return NULL;
}
-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;
-
- while (n) {
- t = rb_entry(n, struct object_cache_entry, dirty_node);
-
- if (idx < t->idx)
- n = n->rb_left;
- else if (idx > t->idx)
- n = n->rb_right;
- else
- return t; /* found it */
- }
-
- return NULL;
-}
-
static inline void
del_from_dirty_tree_and_list(struct object_cache_entry *entry,
struct rb_root *dirty_tree)
{
rb_erase(&entry->dirty_node, dirty_tree);
- list_del(&entry->list);
+ list_del_init(&entry->list);
}
static inline void
@@ -1206,10 +1186,13 @@ void object_cache_remove(uint64_t oid)
return;
pthread_rwlock_wrlock(&oc->lock);
- entry = dirty_tree_search(&oc->dirty_tree, idx);
+ entry = object_tree_search(&oc->object_tree, idx);
if (!entry)
goto out;
- del_from_dirty_tree_and_list(entry, &oc->dirty_tree);
+ if (!list_empty(&entry->list))
+ del_from_dirty_tree_and_list(entry, &oc->dirty_tree);
+ del_from_object_tree_and_list(entry, &oc->object_tree);
+ free(entry);
out:
pthread_rwlock_unlock(&oc->lock);
return;
--
1.7.1
More information about the sheepdog
mailing list