From 378eacf815893cad989463b0917dcd2dd6553438 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Tue, 9 Dec 2014 16:27:23 +0800 Subject: [PATCH] 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 Signed-off-by: David Sterba --- extent-cache.c | 9 +++++++++ extent-cache.h | 1 + 2 files changed, 10 insertions(+) diff --git a/extent-cache.c b/extent-cache.c index 7656ab25..d80aead6 100644 --- a/extent-cache.c +++ b/extent-cache.c @@ -230,6 +230,15 @@ struct cache_extent *first_cache_extent(struct cache_tree *tree) 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 rb_node *node = rb_prev(&pe->rb_node); diff --git a/extent-cache.h b/extent-cache.h index cba83d15..a9d07e18 100644 --- a/extent-cache.h +++ b/extent-cache.h @@ -41,6 +41,7 @@ struct cache_extent { void cache_tree_init(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 *next_cache_extent(struct cache_extent *pe);