diff options
author | Matthew Wilcox <willy@linux.intel.com> | 2016-05-20 20:02:08 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-05-20 20:58:30 -0400 |
commit | 1456a439fc2dcc0c3d1a2d7af1fd83962813aaee (patch) | |
tree | 48bf013e6dae70a848ad0f501f60855e8d77929d /lib/radix-tree.c | |
parent | aa5475760235672f316fbf29cdfb82a75016dbdf (diff) |
radix-tree: introduce radix_tree_load_root()
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>
Diffstat (limited to 'lib/radix-tree.c')
-rw-r--r-- | lib/radix-tree.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/radix-tree.c b/lib/radix-tree.c index 6900f7b67c49..272ce810d29b 100644 --- a/lib/radix-tree.c +++ b/lib/radix-tree.c | |||
@@ -405,6 +405,29 @@ static inline unsigned long radix_tree_maxindex(unsigned int height) | |||
405 | return height_to_maxindex[height]; | 405 | return height_to_maxindex[height]; |
406 | } | 406 | } |
407 | 407 | ||
408 | static inline unsigned long node_maxindex(struct radix_tree_node *node) | ||
409 | { | ||
410 | return radix_tree_maxindex(node->path & RADIX_TREE_HEIGHT_MASK); | ||
411 | } | ||
412 | |||
413 | static unsigned radix_tree_load_root(struct radix_tree_root *root, | ||
414 | struct radix_tree_node **nodep, unsigned long *maxindex) | ||
415 | { | ||
416 | struct radix_tree_node *node = rcu_dereference_raw(root->rnode); | ||
417 | |||
418 | *nodep = node; | ||
419 | |||
420 | if (likely(radix_tree_is_indirect_ptr(node))) { | ||
421 | node = indirect_to_ptr(node); | ||
422 | *maxindex = node_maxindex(node); | ||
423 | return (node->path & RADIX_TREE_HEIGHT_MASK) * | ||
424 | RADIX_TREE_MAP_SHIFT; | ||
425 | } | ||
426 | |||
427 | *maxindex = 0; | ||
428 | return 0; | ||
429 | } | ||
430 | |||
408 | /* | 431 | /* |
409 | * Extend a radix tree so it can store key @index. | 432 | * Extend a radix tree so it can store key @index. |
410 | */ | 433 | */ |