Merge branch 'virtio' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux...
[safe/jmp/linux-2.6] / lib / radix-tree.c
index 23abbd9..05da38b 100644 (file)
@@ -28,7 +28,6 @@
 #include <linux/slab.h>
 #include <linux/notifier.h>
 #include <linux/cpu.h>
-#include <linux/gfp.h>
 #include <linux/string.h>
 #include <linux/bitops.h>
 #include <linux/rcupdate.h>
@@ -200,6 +199,9 @@ radix_tree_node_free(struct radix_tree_node *node)
  * ensure that the addition of a single element in the tree cannot fail.  On
  * success, return zero, with preemption disabled.  On error, return -ENOMEM
  * with preemption not disabled.
+ *
+ * To make use of this facility, the radix tree must be initialised without
+ * __GFP_WAIT being passed to INIT_RADIX_TREE().
  */
 int radix_tree_preload(gfp_t gfp_mask)
 {
@@ -361,7 +363,7 @@ static void *radix_tree_lookup_element(struct radix_tree_root *root,
        unsigned int height, shift;
        struct radix_tree_node *node, **slot;
 
-       node = rcu_dereference(root->rnode);
+       node = rcu_dereference_raw(root->rnode);
        if (node == NULL)
                return NULL;
 
@@ -381,7 +383,7 @@ static void *radix_tree_lookup_element(struct radix_tree_root *root,
        do {
                slot = (struct radix_tree_node **)
                        (node->slots + ((index>>shift) & RADIX_TREE_MAP_MASK));
-               node = rcu_dereference(*slot);
+               node = rcu_dereference_raw(*slot);
                if (node == NULL)
                        return NULL;
 
@@ -543,7 +545,6 @@ out:
 }
 EXPORT_SYMBOL(radix_tree_tag_clear);
 
-#ifndef __KERNEL__     /* Only the test harness uses this at present */
 /**
  * radix_tree_tag_get - get a tag on a radix tree node
  * @root:              radix tree root
@@ -554,6 +555,10 @@ EXPORT_SYMBOL(radix_tree_tag_clear);
  *
  *  0: tag not present or not set
  *  1: tag set
+ *
+ * Note that the return value of this function may not be relied on, even if
+ * the RCU lock is held, unless tag modification and node deletion are excluded
+ * from concurrency.
  */
 int radix_tree_tag_get(struct radix_tree_root *root,
                        unsigned long index, unsigned int tag)
@@ -566,7 +571,7 @@ int radix_tree_tag_get(struct radix_tree_root *root,
        if (!root_tag_get(root, tag))
                return 0;
 
-       node = rcu_dereference(root->rnode);
+       node = rcu_dereference_raw(root->rnode);
        if (node == NULL)
                return 0;
 
@@ -594,19 +599,14 @@ int radix_tree_tag_get(struct radix_tree_root *root,
                 */
                if (!tag_get(node, tag, offset))
                        saw_unset_tag = 1;
-               if (height == 1) {
-                       int ret = tag_get(node, tag, offset);
-
-                       BUG_ON(ret && saw_unset_tag);
-                       return !!ret;
-               }
-               node = rcu_dereference(node->slots[offset]);
+               if (height == 1)
+                       return !!tag_get(node, tag, offset);
+               node = rcu_dereference_raw(node->slots[offset]);
                shift -= RADIX_TREE_MAP_SHIFT;
                height--;
        }
 }
 EXPORT_SYMBOL(radix_tree_tag_get);
-#endif
 
 /**
  *     radix_tree_next_hole    -    find the next hole (not-present entry)
@@ -656,7 +656,7 @@ EXPORT_SYMBOL(radix_tree_next_hole);
  *
  *     Returns: the index of the hole if found, otherwise returns an index
  *     outside of the set specified (in which case 'index - return >= max_scan'
- *     will be true). In rare cases of wrap-around, LONG_MAX will be returned.
+ *     will be true). In rare cases of wrap-around, ULONG_MAX will be returned.
  *
  *     radix_tree_next_hole may be called under rcu_read_lock. However, like
  *     radix_tree_gang_lookup, this will not atomically search a snapshot of
@@ -674,7 +674,7 @@ unsigned long radix_tree_prev_hole(struct radix_tree_root *root,
                if (!radix_tree_lookup(root, index))
                        break;
                index--;
-               if (index == LONG_MAX)
+               if (index == ULONG_MAX)
                        break;
        }
 
@@ -710,7 +710,7 @@ __lookup(struct radix_tree_node *slot, void ***results, unsigned long index,
                }
 
                shift -= RADIX_TREE_MAP_SHIFT;
-               slot = rcu_dereference(slot->slots[i]);
+               slot = rcu_dereference_raw(slot->slots[i]);
                if (slot == NULL)
                        goto out;
        }
@@ -757,7 +757,7 @@ radix_tree_gang_lookup(struct radix_tree_root *root, void **results,
        unsigned long cur_index = first_index;
        unsigned int ret;
 
-       node = rcu_dereference(root->rnode);
+       node = rcu_dereference_raw(root->rnode);
        if (!node)
                return 0;
 
@@ -786,7 +786,7 @@ radix_tree_gang_lookup(struct radix_tree_root *root, void **results,
                        slot = *(((void ***)results)[ret + i]);
                        if (!slot)
                                continue;
-                       results[ret + nr_found] = rcu_dereference(slot);
+                       results[ret + nr_found] = rcu_dereference_raw(slot);
                        nr_found++;
                }
                ret += nr_found;
@@ -825,7 +825,7 @@ radix_tree_gang_lookup_slot(struct radix_tree_root *root, void ***results,
        unsigned long cur_index = first_index;
        unsigned int ret;
 
-       node = rcu_dereference(root->rnode);
+       node = rcu_dereference_raw(root->rnode);
        if (!node)
                return 0;
 
@@ -914,7 +914,7 @@ __lookup_tag(struct radix_tree_node *slot, void ***results, unsigned long index,
                        }
                }
                shift -= RADIX_TREE_MAP_SHIFT;
-               slot = rcu_dereference(slot->slots[i]);
+               slot = rcu_dereference_raw(slot->slots[i]);
                if (slot == NULL)
                        break;
        }
@@ -950,7 +950,7 @@ radix_tree_gang_lookup_tag(struct radix_tree_root *root, void **results,
        if (!root_tag_get(root, tag))
                return 0;
 
-       node = rcu_dereference(root->rnode);
+       node = rcu_dereference_raw(root->rnode);
        if (!node)
                return 0;
 
@@ -979,7 +979,7 @@ radix_tree_gang_lookup_tag(struct radix_tree_root *root, void **results,
                        slot = *(((void ***)results)[ret + i]);
                        if (!slot)
                                continue;
-                       results[ret + nr_found] = rcu_dereference(slot);
+                       results[ret + nr_found] = rcu_dereference_raw(slot);
                        nr_found++;
                }
                ret += nr_found;
@@ -1019,7 +1019,7 @@ radix_tree_gang_lookup_tag_slot(struct radix_tree_root *root, void ***results,
        if (!root_tag_get(root, tag))
                return 0;
 
-       node = rcu_dereference(root->rnode);
+       node = rcu_dereference_raw(root->rnode);
        if (!node)
                return 0;