]> git.baikalelectronics.ru Git - kernel.git/commitdiff
radix-tree: introduce radix_tree_load_root()
authorMatthew Wilcox <willy@linux.intel.com>
Sat, 21 May 2016 00:02:08 +0000 (17:02 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 21 May 2016 00:58:30 +0000 (17:58 -0700)
All the tree walking functions start with some variant of this code;
centralise it in one place so we're not chasing subtly different bugs
everywhere.

Signed-off-by: Matthew Wilcox <willy@linux.intel.com>
Reviewed-by: Ross Zwisler <ross.zwisler@linux.intel.com>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Kirill Shutemov <kirill.shutemov@linux.intel.com>
Cc: Jan Kara <jack@suse.com>
Cc: Neil Brown <neilb@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
lib/radix-tree.c

index 6900f7b67c4909515be475c0d6b5ea5a3c1c30f9..272ce810d29b629c9e07e8165acc4bc8cfeef752 100644 (file)
@@ -405,6 +405,29 @@ static inline unsigned long radix_tree_maxindex(unsigned int height)
        return height_to_maxindex[height];
 }
 
+static inline unsigned long node_maxindex(struct radix_tree_node *node)
+{
+       return radix_tree_maxindex(node->path & RADIX_TREE_HEIGHT_MASK);
+}
+
+static unsigned radix_tree_load_root(struct radix_tree_root *root,
+               struct radix_tree_node **nodep, unsigned long *maxindex)
+{
+       struct radix_tree_node *node = rcu_dereference_raw(root->rnode);
+
+       *nodep = node;
+
+       if (likely(radix_tree_is_indirect_ptr(node))) {
+               node = indirect_to_ptr(node);
+               *maxindex = node_maxindex(node);
+               return (node->path & RADIX_TREE_HEIGHT_MASK) *
+                       RADIX_TREE_MAP_SHIFT;
+       }
+
+       *maxindex = 0;
+       return 0;
+}
+
 /*
  *     Extend a radix tree so it can store key @index.
  */