From: Hans Reiser <
[email protected]>
Reiser4 uses radix trees to solve a trouble reiser4_readdir has serving nfs
requests.
Unfortunately, radix tree api lacks an operation suitable for modifying
existing entry. This patch adds radix_tree_lookup_slot which returns pointer
to found item within the tree. That location can be then updated.
Signed-off-by: Andrew Morton <
[email protected]>
---
25-akpm/include/linux/radix-tree.h | 1
25-akpm/lib/radix-tree.c | 41 ++++++++++++++++++++++++++++---------
2 files changed, 33 insertions(+), 9 deletions(-)
diff -puN include/linux/radix-tree.h~reiser4-radix_tree_lookup_slot include/linux/radix-tree.h
--- 25/include/linux/radix-tree.h~reiser4-radix_tree_lookup_slot 2004-12-27 00:31:05.250810928 -0800
+++ 25-akpm/include/linux/radix-tree.h 2004-12-27 00:31:05.256810016 -0800
@@ -46,6 +46,7 @@ do { \
int radix_tree_insert(struct radix_tree_root *, unsigned long, void *);
void *radix_tree_lookup(struct radix_tree_root *, unsigned long);
+void **radix_tree_lookup_slot(struct radix_tree_root *, unsigned long);
void *radix_tree_delete(struct radix_tree_root *, unsigned long);
unsigned int
radix_tree_gang_lookup(struct radix_tree_root *root, void **results,
diff -puN lib/radix-tree.c~reiser4-radix_tree_lookup_slot lib/radix-tree.c
--- 25/lib/radix-tree.c~reiser4-radix_tree_lookup_slot 2004-12-27 00:31:05.252810624 -0800
+++ 25-akpm/lib/radix-tree.c 2004-12-27 00:31:05.257809864 -0800
@@ -277,14 +277,8 @@ int radix_tree_insert(struct radix_tree_
}
EXPORT_SYMBOL(radix_tree_insert);
-/**
- * radix_tree_lookup - perform lookup operation on a radix tree
- * @root: radix tree root
- * @index: index key
- *
- * Lookup the item at the position @index in the radix tree @root.
- */
-void *radix_tree_lookup(struct radix_tree_root *root, unsigned long index)
+static inline void **__lookup_slot(struct radix_tree_root *root,
+ unsigned long index)
{
unsigned int height, shift;
struct radix_tree_node **slot;
@@ -307,7 +301,36 @@ void *radix_tree_lookup(struct radix_tre
height--;
}
- return *slot;
+ return (void **)slot;
+}
+
+/**
+ * radix_tree_lookup_slot - lookup a slot in a radix tree
+ * @root: radix tree root
+ * @index: index key
+ *
+ * Lookup the slot corresponding to the position @index in the radix tree
+ * @root. This is useful for update-if-exists operations.
+ */
+void **radix_tree_lookup_slot(struct radix_tree_root *root, unsigned long index)
+{
+ return __lookup_slot(root, index);
+}
+EXPORT_SYMBOL(radix_tree_lookup_slot);
+
+/**
+ * radix_tree_lookup - perform lookup operation on a radix tree
+ * @root: radix tree root
+ * @index: index key
+ *
+ * Lookup the item at the position @index in the radix tree @root.
+ */
+void *radix_tree_lookup(struct radix_tree_root *root, unsigned long index)
+{
+ void **slot;
+
+ slot = __lookup_slot(root, index);
+ return slot != NULL ? *slot : NULL;
}
EXPORT_SYMBOL(radix_tree_lookup);
_