btrfs-progs: Add last_cache_extent() for extent-cache.

Allow direct search for the last cache extent.
Provide the basis for finding the last ino in inode_cache.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
This commit is contained in:
Qu Wenruo 2014-12-09 16:27:23 +08:00 committed by David Sterba
parent c0af17d07f
commit 378eacf815
2 changed files with 10 additions and 0 deletions

View File

@ -230,6 +230,15 @@ struct cache_extent *first_cache_extent(struct cache_tree *tree)
return rb_entry(node, struct cache_extent, rb_node); return rb_entry(node, struct cache_extent, rb_node);
} }
struct cache_extent *last_cache_extent(struct cache_tree *tree)
{
struct rb_node *node = rb_last(&tree->root);
if (!node)
return NULL;
return rb_entry(node, struct cache_extent, rb_node);
}
struct cache_extent *prev_cache_extent(struct cache_extent *pe) struct cache_extent *prev_cache_extent(struct cache_extent *pe)
{ {
struct rb_node *node = rb_prev(&pe->rb_node); struct rb_node *node = rb_prev(&pe->rb_node);

View File

@ -41,6 +41,7 @@ struct cache_extent {
void cache_tree_init(struct cache_tree *tree); void cache_tree_init(struct cache_tree *tree);
struct cache_extent *first_cache_extent(struct cache_tree *tree); struct cache_extent *first_cache_extent(struct cache_tree *tree);
struct cache_extent *last_cache_extent(struct cache_tree *tree);
struct cache_extent *prev_cache_extent(struct cache_extent *pe); struct cache_extent *prev_cache_extent(struct cache_extent *pe);
struct cache_extent *next_cache_extent(struct cache_extent *pe); struct cache_extent *next_cache_extent(struct cache_extent *pe);