From: Liam R. Howlett Date: Tue, 15 Oct 2019 00:44:08 +0000 (-0400) Subject: Merge remote-tracking branch 'willy/maple2' into maple2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=b5e642072c5aebc7b71f2ed0ae8f4bb0de17eadc;p=users%2Fjedix%2Flinux-maple.git Merge remote-tracking branch 'willy/maple2' into maple2 --- b5e642072c5aebc7b71f2ed0ae8f4bb0de17eadc diff --cc include/linux/maple_tree.h index eb1626010935a,3219fec8965b1..826165e4cf695 --- a/include/linux/maple_tree.h +++ b/include/linux/maple_tree.h @@@ -304,32 -304,36 +304,63 @@@ bool mas_nomem(struct ma_state *mas, gf 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)) + /** + * mas_set_range() - Set up Maple Tree operation state for a different index. + * @xas: Maple Tree operation state. + * @start: New start of range in the Maple Tree. + * @last: New end of range in the Maple Tree. + * + * Move the operation state to refer to a different range. This will + * have the effect of starting a walk from the top; see mas_next() + * to move to an adjacent index. + */ + static inline void mas_set_range(struct ma_state *mas, unsigned long start, + unsigned long last) + { + mas->index = start; + mas->last = last; + mas->node = MAS_START; + } + + /** + * mas_set() - Set up Maple Tree operation state for a different index. + * @xas: Maple Tree operation state. + * @index: New index into the Maple Tree. + * + * Move the operation state to refer to a different index. This will + * have the effect of starting a walk from the top; see mas_next() + * to move to an adjacent index. + */ + static inline void mas_set(struct ma_state *mas, unsigned long index) + { + mas_set_range(mas, index, index); + } #endif diff --cc lib/maple_tree.c index 3f696a1eaec1b,c916a27c0ab97..6f14ed658a0e5 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@@ -3195,15 -3223,16 +3195,16 @@@ next } } - ma_set_slot(mas, i); + mas_set_slot(mas, i); return found; ascend: - if (ma_is_root(mas->node)) + if (mte_is_root(mas->node)) found = true; - ma_set_slot(mas, i); + mas_set_slot(mas, i); return found; } + /* * Private: Returns true if mas->node is a leaf */ @@@ -3270,9 -3299,10 +3271,10 @@@ skip_entry mas->node = next; } done: - ma_set_slot(mas, i); + mas_set_slot(mas, i); return ret; } + static inline bool _mas_walk(struct ma_state *mas) { mas->node = mas_start(mas); @@@ -3298,9 -3328,12 +3300,12 @@@ static inline int mas_safe_slot(struct } return false; } + static inline int mas_dead_node(struct ma_state *mas, unsigned long index) { + if (!mas->node) + return 0; - if (!mt_dead_node(mas->node)) + if (!mte_dead_node(mas->node)) return 0; mas->index = index; @@@ -4026,9 -4060,9 +4036,9 @@@ int mtree_store_range(struct maple_tre if (first > last) return -EINVAL; - mtree_lock(mas.tree); + mas_lock(&mas); retry: - ma_add(&mas, entry, true, true); + mas_add(&mas, entry, true, true); if (mas_nomem(&mas, gfp)) goto retry;