]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Move iterators to the header
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Fri, 11 Oct 2019 14:39:35 +0000 (10:39 -0400)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Fri, 11 Oct 2019 14:39:35 +0000 (10:39 -0400)
This is part of the api, so expose it through the header.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
include/linux/maple_tree.h
lib/maple_tree.c

index ad7f0af2794bc7e328077433e5e3e348fc59c534..eb1626010935aa7cf071a0a11432dd18433cd4b9 100644 (file)
@@ -303,4 +303,33 @@ void *mas_find(struct ma_state *mas, unsigned long max);
 bool mas_nomem(struct ma_state *mas, gfp_t gfp);
 void mas_pause(struct ma_state *mas);
 void maple_tree_init(void);
+
+/**
+ * mas_for_each() - Iterate over a range of the maple tree.
+ * @mas: Maple Tree operation state (maple_state)
+ * @entry: Entry retrieved from the tree
+ * @max: maximum index to retrieve from the tree
+ *
+ * When returned, mas->index and mas->last will hold the entire range for the
+ * entry.
+ *
+ * Note: may return the zero entry.
+ *
+ */
+#define mas_for_each(mas, entry, max) \
+       while ((entry = mas_find(mas, max)) != NULL)
+
+/**
+ * mt_for_each - Searches for an entry starting at index until max.
+ *
+ *
+ *
+ * Note: Will not return the zero entry.
+ *
+ *
+ */
+#define mt_for_each(tree, entry, index, max) \
+       for (entry = mt_find(mt, index, max); \
+            entry; entry = mt_find_after(mt, &index, max))
+
 #endif
index 1680659dbce1267d40ec7f6769e8524c339fa6f5..50ee13a0f83addefe4a3ad32734ba2bdaadd003e 100644 (file)
@@ -2372,6 +2372,17 @@ no_entry:
        mas->node = MAS_NONE;
 }
 
+static inline void* mas_prev_entry(struct ma_state *mas, unsigned long min)
+{
+       if (mas->node == MAS_NONE)
+               return NULL;
+
+       mas_prev_node(mas, min);
+       if (mas->node == MAS_NONE)
+               return NULL;
+
+       return mte_get_rcu_slot(mas->node, mas_get_slot(mas));
+}
 /*
  * Find the next non-null entry at the same level in the tree.  The next value
  * will be mas->node[mas_get_slot(mas)] or MAS_NONE.
@@ -3327,6 +3338,14 @@ static inline int mas_dead_node(struct ma_state *mas, unsigned long index)
        return 1;
 }
 
+void *mas_load(struct ma_state *mas)
+{
+       void *entry = mas_walk(&mas);
+       if (xa_is_zero(entry) || mt_is_empty(entry))
+               return NULL;
+
+       return entry;
+}
 /**
  * mas_find - Find the first entry that overlaps the range.
  *   If mas->node is root, finds mas->index and returns the value.  If the
@@ -4020,13 +4039,9 @@ void *mtree_load(struct maple_tree *mt, unsigned long index)
 
        MA_STATE(mas, mt, index, index);
        rcu_read_lock();
-       entry = mas_walk(&mas);
+       entry = mas_load(mas);
        rcu_read_unlock();
-
-       if (xa_is_zero(entry) || mt_is_empty(entry))
-               return NULL;
-
-       return entry;
+       return mas_load(mas);
 }
 EXPORT_SYMBOL(mtree_load);