2 * Copyright (C) 2007 Oracle. All rights reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 021110-1307, USA.
19 #ifndef __BTRFS_EXTENT_CACHE_H__
20 #define __BTRFS_EXTENT_CACHE_H__
22 #if BTRFS_FLAT_INCLUDES
23 #include "kerncompat.h"
26 #include <btrfs/kerncompat.h>
27 #include <btrfs/rbtree.h>
28 #endif /* BTRFS_FLAT_INCLUDES */
35 struct rb_node rb_node;
41 void cache_tree_init(struct cache_tree *tree);
43 struct cache_extent *first_cache_extent(struct cache_tree *tree);
44 struct cache_extent *last_cache_extent(struct cache_tree *tree);
45 struct cache_extent *prev_cache_extent(struct cache_extent *pe);
46 struct cache_extent *next_cache_extent(struct cache_extent *pe);
48 struct cache_extent *search_cache_extent(struct cache_tree *tree, u64 start);
49 struct cache_extent *lookup_cache_extent(struct cache_tree *tree,
52 int add_cache_extent(struct cache_tree *tree, u64 start, u64 size);
53 int insert_cache_extent(struct cache_tree *tree, struct cache_extent *pe);
54 void remove_cache_extent(struct cache_tree *tree, struct cache_extent *pe);
56 static inline int cache_tree_empty(struct cache_tree *tree)
58 return RB_EMPTY_ROOT(&tree->root);
61 typedef void (*free_cache_extent)(struct cache_extent *pe);
63 void cache_tree_free_extents(struct cache_tree *tree,
64 free_cache_extent free_func);
66 #define FREE_EXTENT_CACHE_BASED_TREE(name, free_func) \
67 static void free_##name##_tree(struct cache_tree *tree) \
69 cache_tree_free_extents(tree, free_func); \
72 void free_extent_cache_tree(struct cache_tree *tree);
74 struct cache_extent *search_cache_extent2(struct cache_tree *tree,
75 u64 objectid, u64 start);
76 struct cache_extent *lookup_cache_extent2(struct cache_tree *tree,
77 u64 objectid, u64 start, u64 size);
78 int add_cache_extent2(struct cache_tree *tree,
79 u64 objectid, u64 start, u64 size);
80 int insert_cache_extent2(struct cache_tree *tree, struct cache_extent *pe);