void mas_pause(struct ma_state *mas);
void maple_tree_init(void);
+/**
+ * mas_reset() - Reset a Maple Tree operation state.
+ * @mas: Maple Tree operation state.
+ *
+ * Resets the error or walk state of the @mas so future walks of the
+ * array will start from the root. Use this if you have dropped the
+ * lock and want to reuse the ma_state.
+ *
+ * Context: Any context.
+ */
+static inline void mas_reset(struct ma_state *mas)
+{
+ mas->node = MAS_START;
+}
+
+/**
+ * mas_retry() - Retry the operation if appropriate.
+ * @mas: Maple Tree operation state.
+ * @entry: Entry from tree.
+ *
+ * The advanced functions may sometimes return an internal entry, such as
+ * a retry entry or a zero entry. This function sets up the @mas to restart
+ * the walk from the head of the array if needed.
+ *
+ * Context: Any context.
+ * Return: true if the operation needs to be retried.
+ */
+static inline bool mas_retry(struct ma_state *mas, const void *entry)
+{
+ if (xa_is_skip(entry))
+ return true;
+ if (xa_is_deleted(entry))
+ return true;
+ if (xa_is_zero(entry))
+ return true;
+ if (!xa_is_retry(entry))
+ return false;
+ mas_reset(mas);
+ return true;
+}
+
/**
* mas_for_each() - Iterate over a range of the maple tree.
* @mas: Maple Tree operation state (maple_state)
#define mt_for_each(tree, entry, index, max) \
for (entry = mt_find(mt, index, max); \
entry; entry = mt_find_after(mt, &index, max))
+
/**
* mas_set_range() - Set up Maple Tree operation state for a different index.
- * @xas: Maple Tree operation state.
+ * @mas: Maple Tree operation state.
* @start: New start of range in the Maple Tree.
* @last: New end of range in the Maple Tree.
*
/**
* mas_set() - Set up Maple Tree operation state for a different index.
- * @xas: Maple Tree operation state.
+ * @mas: Maple Tree operation state.
* @index: New index into the Maple Tree.
*
* Move the operation state to refer to a different index. This will
{
mas_set_range(mas, index, index);
}
-
#endif
for (i = 0; i < 256; i++) {
mtree_erase_index(mt, i);
+ j = i + 1;
+ mas_set(&mas, 0);
+ rcu_read_lock();
+ mas_for_each(&mas, entry, ULONG_MAX) {
+ if (mas_retry(&mas, entry))
+ continue;
+ MT_BUG_ON(mt, entry != xa_mk_value(j));
+ j++;
+ }
+ rcu_read_unlock();
+ MT_BUG_ON(mt, j != 256);
}
MT_BUG_ON(mt, !mtree_empty(mt));