[sheepdog] [PATCH 2/2] remove redundant list_node

MORITA Kazutaka morita.kazutaka at gmail.com
Thu Aug 22 05:39:46 CEST 2013


From: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>

We can iterate over a rbtree without a linked list.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 dog/farm/object_tree.c    |    8 +++-----
 sheep/object_list_cache.c |   10 ++--------
 2 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/dog/farm/object_tree.c b/dog/farm/object_tree.c
index 4be3c46..28cd4e6 100644
--- a/dog/farm/object_tree.c
+++ b/dog/farm/object_tree.c
@@ -18,19 +18,16 @@ struct object_tree_entry {
 	uint64_t oid;
 	int nr_copies;
 	struct rb_node node;
-	struct list_node list;
 };
 
 struct object_tree {
 	int nr_objs;
 	struct rb_root root;
-	struct list_head list;
 };
 
 static struct object_tree tree = {
 	.nr_objs = 0,
 	.root = RB_ROOT,
-	.list = LIST_HEAD_INIT(tree.list)
 };
 static struct object_tree_entry *cached_entry;
 
@@ -58,7 +55,6 @@ void object_tree_insert(uint64_t oid, int nr_copies)
 	rb_init_node(&cached_entry->node);
 	p = do_insert(root, cached_entry);
 	if (!p) {
-		list_add(&cached_entry->list, &tree.list);
 		tree.nr_objs++;
 		cached_entry = NULL;
 	}
@@ -76,8 +72,10 @@ void object_tree_print(void)
 void object_tree_free(void)
 {
 	struct object_tree_entry *entry;
-	list_for_each_entry(entry, &tree.list, list)
+	rb_for_each_entry(entry, &tree.root, node) {
+		rb_erase(&entry->node, &tree.root);
 		free(entry);
+	}
 
 	free(cached_entry);
 }
diff --git a/sheep/object_list_cache.c b/sheep/object_list_cache.c
index 8717972..caba3ce 100644
--- a/sheep/object_list_cache.c
+++ b/sheep/object_list_cache.c
@@ -15,7 +15,6 @@
 
 struct objlist_cache_entry {
 	uint64_t oid;
-	struct list_node list;
 	struct rb_node node;
 };
 
@@ -24,7 +23,6 @@ struct objlist_cache {
 	int buf_version;
 	int cache_size;
 	uint64_t *buf;
-	struct list_head entry_list;
 	struct rb_root root;
 	struct sd_lock lock;
 };
@@ -37,7 +35,6 @@ struct objlist_deletion_work {
 static struct objlist_cache obj_list_cache = {
 	.tree_version	= 1,
 	.root		= RB_ROOT,
-	.entry_list     = LIST_HEAD_INIT(obj_list_cache.entry_list),
 	.lock		= SD_LOCK_INITIALIZER,
 };
 
@@ -61,7 +58,6 @@ static int objlist_cache_rb_remove(struct rb_root *root, uint64_t oid)
 	if (!entry)
 		return -1;
 
-	list_del(&entry->list);
 	rb_erase(&entry->node, root);
 	free(entry);
 
@@ -91,7 +87,6 @@ int objlist_cache_insert(uint64_t oid)
 	if (p)
 		free(entry);
 	else {
-		list_add(&entry->list, &obj_list_cache.entry_list);
 		obj_list_cache.cache_size++;
 		obj_list_cache.tree_version++;
 	}
@@ -120,7 +115,7 @@ int get_obj_list(const struct sd_req *hdr, struct sd_rsp *rsp, void *data)
 	obj_list_cache.buf = xrealloc(obj_list_cache.buf,
 				obj_list_cache.cache_size * sizeof(uint64_t));
 
-	list_for_each_entry(entry, &obj_list_cache.entry_list, list) {
+	rb_for_each_entry(entry, &obj_list_cache.root, node) {
 		obj_list_cache.buf[nr++] = entry->oid;
 	}
 
@@ -158,7 +153,7 @@ static void objlist_deletion_work(struct work *work)
 	}
 
 	sd_write_lock(&obj_list_cache.lock);
-	list_for_each_entry(entry, &obj_list_cache.entry_list, list) {
+	rb_for_each_entry(entry, &obj_list_cache.root, node) {
 		entry_vid = oid_to_vid(entry->oid);
 		if (entry_vid != vid)
 			continue;
@@ -168,7 +163,6 @@ static void objlist_deletion_work(struct work *work)
 			continue;
 
 		sd_debug("delete object entry %" PRIx64, entry->oid);
-		list_del(&entry->list);
 		rb_erase(&entry->node, &obj_list_cache.root);
 		free(entry);
 	}
-- 
1.7.9.5




More information about the sheepdog mailing list