path: root/extent-cache.h
diff options
authorMiao Xie <>2013-07-03 21:25:13 +0800
committerChris Mason <>2013-07-03 14:06:54 -0400
commitd35300269709a0588b3252373c70eb94df7520fe (patch)
tree23d456e3f13677ff0dadb16848cdd67d3a55fe44 /extent-cache.h
parent615f2867854c186a37cb2e2e5a2e13e9ed4ab0df (diff)
Btrfs-progs: introduce common insert/search/delete functions for rb-tree
In fact, the code of many rb-tree insert/search/delete functions is similar, so we can abstract them, and implement common functions for rb-tree, and then simplify them. Signed-off-by: Miao Xie <> Signed-off-by: Chris Mason <>
Diffstat (limited to 'extent-cache.h')
1 files changed, 21 insertions, 15 deletions
diff --git a/extent-cache.h b/extent-cache.h
index 4cd0f795..2979fc34 100644
--- a/extent-cache.h
+++ b/extent-cache.h
@@ -16,8 +16,8 @@
* Boston, MA 021110-1307, USA.
-#ifndef __PENDING_EXTENT__
-#define __PENDING_EXTENT__
+#ifndef __EXTENT_CACHE_H__
+#define __EXTENT_CACHE_H__
#include "kerncompat.h"
@@ -38,28 +38,34 @@ struct cache_extent {
void cache_tree_init(struct cache_tree *tree);
-void remove_cache_extent(struct cache_tree *tree,
- struct cache_extent *pe);
-struct cache_extent *find_first_cache_extent(struct cache_tree *tree,
- u64 start);
+struct cache_extent *first_cache_extent(struct cache_tree *tree);
struct cache_extent *prev_cache_extent(struct cache_extent *pe);
struct cache_extent *next_cache_extent(struct cache_extent *pe);
+struct cache_extent *find_first_cache_extent(struct cache_tree *tree,
+ u64 start);
struct cache_extent *find_cache_extent(struct cache_tree *tree,
- u64 start, u64 size);
-int insert_cache_extent(struct cache_tree *tree, u64 start, u64 size);
-int insert_existing_cache_extent(struct cache_tree *tree,
- struct cache_extent *pe);
+ u64 start, u64 size);
+int add_cache_extent(struct cache_tree *tree, u64 start, u64 size);
+int insert_cache_extent(struct cache_tree *tree, struct cache_extent *pe);
+void remove_cache_extent(struct cache_tree *tree, struct cache_extent *pe);
static inline int cache_tree_empty(struct cache_tree *tree)
return RB_EMPTY_ROOT(&tree->root);
-static inline void free_cache_extent(struct cache_extent *pe)
- free(pe);
+typedef void (*free_cache_extent)(struct cache_extent *pe);
-struct cache_extent *alloc_pending_extent(u64 start, u64 size);
+void cache_tree_free_extents(struct cache_tree *tree,
+ free_cache_extent free_func);
+#define FREE_EXTENT_CACHE_BASED_TREE(name, free_func) \
+static void free_##name##_tree(struct cache_tree *tree) \
+{ \
+ cache_tree_free_extents(tree, free_func); \