Lines Matching refs:xas

36 static inline void xas_lock_type(struct xa_state *xas, unsigned int lock_type)  in xas_lock_type()  argument
39 xas_lock_irq(xas); in xas_lock_type()
41 xas_lock_bh(xas); in xas_lock_type()
43 xas_lock(xas); in xas_lock_type()
46 static inline void xas_unlock_type(struct xa_state *xas, unsigned int lock_type) in xas_unlock_type() argument
49 xas_unlock_irq(xas); in xas_unlock_type()
51 xas_unlock_bh(xas); in xas_unlock_type()
53 xas_unlock(xas); in xas_unlock_type()
124 static void xas_squash_marks(const struct xa_state *xas) in xas_squash_marks() argument
127 unsigned int limit = xas->xa_offset + xas->xa_sibs + 1; in xas_squash_marks()
129 if (!xas->xa_sibs) in xas_squash_marks()
133 unsigned long *marks = xas->xa_node->marks[mark]; in xas_squash_marks()
134 if (find_next_bit(marks, limit, xas->xa_offset + 1) == limit) in xas_squash_marks()
136 __set_bit(xas->xa_offset, marks); in xas_squash_marks()
137 bitmap_clear(marks, xas->xa_offset + 1, xas->xa_sibs); in xas_squash_marks()
147 static void xas_set_offset(struct xa_state *xas) in xas_set_offset() argument
149 xas->xa_offset = get_offset(xas->xa_index, xas->xa_node); in xas_set_offset()
153 static void xas_move_index(struct xa_state *xas, unsigned long offset) in xas_move_index() argument
155 unsigned int shift = xas->xa_node->shift; in xas_move_index()
156 xas->xa_index &= ~XA_CHUNK_MASK << shift; in xas_move_index()
157 xas->xa_index += offset << shift; in xas_move_index()
160 static void xas_advance(struct xa_state *xas) in xas_advance() argument
162 xas->xa_offset++; in xas_advance()
163 xas_move_index(xas, xas->xa_offset); in xas_advance()
166 static void *set_bounds(struct xa_state *xas) in set_bounds() argument
168 xas->xa_node = XAS_BOUNDS; in set_bounds()
179 static void *xas_start(struct xa_state *xas) in xas_start() argument
183 if (xas_valid(xas)) in xas_start()
184 return xas_reload(xas); in xas_start()
185 if (xas_error(xas)) in xas_start()
188 entry = xa_head(xas->xa); in xas_start()
190 if (xas->xa_index) in xas_start()
191 return set_bounds(xas); in xas_start()
193 if ((xas->xa_index >> xa_to_node(entry)->shift) > XA_CHUNK_MASK) in xas_start()
194 return set_bounds(xas); in xas_start()
197 xas->xa_node = NULL; in xas_start()
201 static void *xas_descend(struct xa_state *xas, struct xa_node *node) in xas_descend() argument
203 unsigned int offset = get_offset(xas->xa_index, node); in xas_descend()
204 void *entry = xa_entry(xas->xa, node, offset); in xas_descend()
206 xas->xa_node = node; in xas_descend()
209 entry = xa_entry(xas->xa, node, offset); in xas_descend()
212 xas->xa_offset = offset; in xas_descend()
231 void *xas_load(struct xa_state *xas) in xas_load() argument
233 void *entry = xas_start(xas); in xas_load()
238 if (xas->xa_shift > node->shift) in xas_load()
240 entry = xas_descend(xas, node); in xas_load()
267 static void xas_destroy(struct xa_state *xas) in xas_destroy() argument
269 struct xa_node *next, *node = xas->xa_alloc; in xas_destroy()
275 xas->xa_alloc = node = next; in xas_destroy()
297 bool xas_nomem(struct xa_state *xas, gfp_t gfp) in xas_nomem() argument
299 if (xas->xa_node != XA_ERROR(-ENOMEM)) { in xas_nomem()
300 xas_destroy(xas); in xas_nomem()
303 if (xas->xa->xa_flags & XA_FLAGS_ACCOUNT) in xas_nomem()
305 xas->xa_alloc = kmem_cache_alloc(radix_tree_node_cachep, gfp); in xas_nomem()
306 if (!xas->xa_alloc) in xas_nomem()
308 xas->xa_alloc->parent = NULL; in xas_nomem()
309 XA_NODE_BUG_ON(xas->xa_alloc, !list_empty(&xas->xa_alloc->private_list)); in xas_nomem()
310 xas->xa_node = XAS_RESTART; in xas_nomem()
324 static bool __xas_nomem(struct xa_state *xas, gfp_t gfp) in __xas_nomem() argument
325 __must_hold(xas->xa->xa_lock) in __xas_nomem()
327 unsigned int lock_type = xa_lock_type(xas->xa); in __xas_nomem()
329 if (xas->xa_node != XA_ERROR(-ENOMEM)) { in __xas_nomem()
330 xas_destroy(xas); in __xas_nomem()
333 if (xas->xa->xa_flags & XA_FLAGS_ACCOUNT) in __xas_nomem()
336 xas_unlock_type(xas, lock_type); in __xas_nomem()
337 xas->xa_alloc = kmem_cache_alloc(radix_tree_node_cachep, gfp); in __xas_nomem()
338 xas_lock_type(xas, lock_type); in __xas_nomem()
340 xas->xa_alloc = kmem_cache_alloc(radix_tree_node_cachep, gfp); in __xas_nomem()
342 if (!xas->xa_alloc) in __xas_nomem()
344 xas->xa_alloc->parent = NULL; in __xas_nomem()
345 XA_NODE_BUG_ON(xas->xa_alloc, !list_empty(&xas->xa_alloc->private_list)); in __xas_nomem()
346 xas->xa_node = XAS_RESTART; in __xas_nomem()
350 static void xas_update(struct xa_state *xas, struct xa_node *node) in xas_update() argument
352 if (xas->xa_update) in xas_update()
353 xas->xa_update(node); in xas_update()
358 static void *xas_alloc(struct xa_state *xas, unsigned int shift) in xas_alloc() argument
360 struct xa_node *parent = xas->xa_node; in xas_alloc()
361 struct xa_node *node = xas->xa_alloc; in xas_alloc()
363 if (xas_invalid(xas)) in xas_alloc()
367 xas->xa_alloc = NULL; in xas_alloc()
371 if (xas->xa->xa_flags & XA_FLAGS_ACCOUNT) in xas_alloc()
376 xas_set_err(xas, -ENOMEM); in xas_alloc()
382 node->offset = xas->xa_offset; in xas_alloc()
385 xas_update(xas, parent); in xas_alloc()
392 RCU_INIT_POINTER(node->parent, xas->xa_node); in xas_alloc()
393 node->array = xas->xa; in xas_alloc()
400 static unsigned long xas_size(const struct xa_state *xas) in xas_size() argument
402 return (xas->xa_sibs + 1UL) << xas->xa_shift; in xas_size()
412 static unsigned long xas_max(struct xa_state *xas) in xas_max() argument
414 unsigned long max = xas->xa_index; in xas_max()
417 if (xas->xa_shift || xas->xa_sibs) { in xas_max()
418 unsigned long mask = xas_size(xas) - 1; in xas_max()
436 static void xas_shrink(struct xa_state *xas) in xas_shrink() argument
438 struct xarray *xa = xas->xa; in xas_shrink()
439 struct xa_node *node = xas->xa_node; in xas_shrink()
454 xas->xa_node = XAS_BOUNDS; in xas_shrink()
464 xas_update(xas, node); in xas_shrink()
480 static void xas_delete_node(struct xa_state *xas) in xas_delete_node() argument
482 struct xa_node *node = xas->xa_node; in xas_delete_node()
491 parent = xa_parent_locked(xas->xa, node); in xas_delete_node()
492 xas->xa_node = parent; in xas_delete_node()
493 xas->xa_offset = node->offset; in xas_delete_node()
497 xas->xa->xa_head = NULL; in xas_delete_node()
498 xas->xa_node = XAS_BOUNDS; in xas_delete_node()
502 parent->slots[xas->xa_offset] = NULL; in xas_delete_node()
506 xas_update(xas, node); in xas_delete_node()
510 xas_shrink(xas); in xas_delete_node()
522 static void xas_free_nodes(struct xa_state *xas, struct xa_node *top) in xas_free_nodes() argument
528 void *entry = xa_entry_locked(xas->xa, node, offset); in xas_free_nodes()
541 parent = xa_parent_locked(xas->xa, node); in xas_free_nodes()
545 xas_update(xas, node); in xas_free_nodes()
558 static int xas_expand(struct xa_state *xas, void *head) in xas_expand() argument
560 struct xarray *xa = xas->xa; in xas_expand()
563 unsigned long max = xas_max(xas); in xas_expand()
575 xas->xa_node = NULL; in xas_expand()
581 node = xas_alloc(xas, shift); in xas_expand()
616 xas_update(xas, node); in xas_expand()
621 xas->xa_node = node; in xas_expand()
638 static void *xas_create(struct xa_state *xas, bool allow_root) in xas_create() argument
640 struct xarray *xa = xas->xa; in xas_create()
643 struct xa_node *node = xas->xa_node; in xas_create()
645 unsigned int order = xas->xa_shift; in xas_create()
649 xas->xa_node = NULL; in xas_create()
652 shift = xas_expand(xas, entry); in xas_create()
659 } else if (xas_error(xas)) { in xas_create()
662 unsigned int offset = xas->xa_offset; in xas_create()
676 node = xas_alloc(xas, shift); in xas_create()
687 entry = xas_descend(xas, node); in xas_create()
688 slot = &node->slots[xas->xa_offset]; in xas_create()
703 void xas_create_range(struct xa_state *xas) in xas_create_range() argument
705 unsigned long index = xas->xa_index; in xas_create_range()
706 unsigned char shift = xas->xa_shift; in xas_create_range()
707 unsigned char sibs = xas->xa_sibs; in xas_create_range()
709 xas->xa_index |= ((sibs + 1UL) << shift) - 1; in xas_create_range()
710 if (xas_is_node(xas) && xas->xa_node->shift == xas->xa_shift) in xas_create_range()
711 xas->xa_offset |= sibs; in xas_create_range()
712 xas->xa_shift = 0; in xas_create_range()
713 xas->xa_sibs = 0; in xas_create_range()
716 xas_create(xas, true); in xas_create_range()
717 if (xas_error(xas)) in xas_create_range()
719 if (xas->xa_index <= (index | XA_CHUNK_MASK)) in xas_create_range()
721 xas->xa_index -= XA_CHUNK_SIZE; in xas_create_range()
724 struct xa_node *node = xas->xa_node; in xas_create_range()
725 xas->xa_node = xa_parent_locked(xas->xa, node); in xas_create_range()
726 xas->xa_offset = node->offset - 1; in xas_create_range()
733 xas->xa_shift = shift; in xas_create_range()
734 xas->xa_sibs = sibs; in xas_create_range()
735 xas->xa_index = index; in xas_create_range()
738 xas->xa_index = index; in xas_create_range()
739 if (xas->xa_node) in xas_create_range()
740 xas_set_offset(xas); in xas_create_range()
744 static void update_node(struct xa_state *xas, struct xa_node *node, in update_node() argument
754 xas_update(xas, node); in update_node()
756 xas_delete_node(xas); in update_node()
772 void *xas_store(struct xa_state *xas, void *entry) in xas_store() argument
775 void __rcu **slot = &xas->xa->xa_head; in xas_store()
784 first = xas_create(xas, allow_root); in xas_store()
786 first = xas_load(xas); in xas_store()
789 if (xas_invalid(xas)) in xas_store()
791 node = xas->xa_node; in xas_store()
792 if (node && (xas->xa_shift < node->shift)) in xas_store()
793 xas->xa_sibs = 0; in xas_store()
794 if ((first == entry) && !xas->xa_sibs) in xas_store()
798 offset = xas->xa_offset; in xas_store()
799 max = xas->xa_offset + xas->xa_sibs; in xas_store()
802 if (xas->xa_sibs) in xas_store()
803 xas_squash_marks(xas); in xas_store()
806 xas_init_marks(xas); in xas_store()
818 xas_free_nodes(xas, xa_to_node(next)); in xas_store()
827 entry = xa_mk_sibling(xas->xa_offset); in xas_store()
832 next = xa_entry_locked(xas->xa, node, ++offset); in xas_store()
841 update_node(xas, node, count, values); in xas_store()
854 bool xas_get_mark(const struct xa_state *xas, xa_mark_t mark) in xas_get_mark() argument
856 if (xas_invalid(xas)) in xas_get_mark()
858 if (!xas->xa_node) in xas_get_mark()
859 return xa_marked(xas->xa, mark); in xas_get_mark()
860 return node_get_mark(xas->xa_node, xas->xa_offset, mark); in xas_get_mark()
873 void xas_set_mark(const struct xa_state *xas, xa_mark_t mark) in xas_set_mark() argument
875 struct xa_node *node = xas->xa_node; in xas_set_mark()
876 unsigned int offset = xas->xa_offset; in xas_set_mark()
878 if (xas_invalid(xas)) in xas_set_mark()
885 node = xa_parent_locked(xas->xa, node); in xas_set_mark()
888 if (!xa_marked(xas->xa, mark)) in xas_set_mark()
889 xa_mark_set(xas->xa, mark); in xas_set_mark()
902 void xas_clear_mark(const struct xa_state *xas, xa_mark_t mark) in xas_clear_mark() argument
904 struct xa_node *node = xas->xa_node; in xas_clear_mark()
905 unsigned int offset = xas->xa_offset; in xas_clear_mark()
907 if (xas_invalid(xas)) in xas_clear_mark()
917 node = xa_parent_locked(xas->xa, node); in xas_clear_mark()
920 if (xa_marked(xas->xa, mark)) in xas_clear_mark()
921 xa_mark_clear(xas->xa, mark); in xas_clear_mark()
936 void xas_init_marks(const struct xa_state *xas) in xas_init_marks() argument
941 if (xa_track_free(xas->xa) && mark == XA_FREE_MARK) in xas_init_marks()
942 xas_set_mark(xas, mark); in xas_init_marks()
944 xas_clear_mark(xas, mark); in xas_init_marks()
1000 void xas_split_alloc(struct xa_state *xas, void *entry, unsigned int order, in xas_split_alloc() argument
1004 unsigned int mask = xas->xa_sibs; in xas_split_alloc()
1007 if (WARN_ON(xas->xa_shift + 2 * XA_CHUNK_SHIFT < order)) in xas_split_alloc()
1009 if (xas->xa_shift + XA_CHUNK_SHIFT > order) in xas_split_alloc()
1020 node->array = xas->xa; in xas_split_alloc()
1029 RCU_INIT_POINTER(node->parent, xas->xa_alloc); in xas_split_alloc()
1030 xas->xa_alloc = node; in xas_split_alloc()
1035 xas_destroy(xas); in xas_split_alloc()
1036 xas_set_err(xas, -ENOMEM); in xas_split_alloc()
1051 void xas_split(struct xa_state *xas, void *entry, unsigned int order) in xas_split() argument
1056 void *curr = xas_load(xas); in xas_split()
1059 node = xas->xa_node; in xas_split()
1063 marks = node_get_marks(node, xas->xa_offset); in xas_split()
1065 offset = xas->xa_offset + sibs; in xas_split()
1067 if (xas->xa_shift < node->shift) { in xas_split()
1068 struct xa_node *child = xas->xa_alloc; in xas_split()
1070 xas->xa_alloc = rcu_dereference_raw(child->parent); in xas_split()
1083 unsigned int canon = offset - xas->xa_sibs; in xas_split()
1091 (xas->xa_sibs + 1); in xas_split()
1093 } while (offset-- > xas->xa_offset); in xas_split()
1115 void xas_pause(struct xa_state *xas) in xas_pause() argument
1117 struct xa_node *node = xas->xa_node; in xas_pause()
1119 if (xas_invalid(xas)) in xas_pause()
1122 xas->xa_node = XAS_RESTART; in xas_pause()
1124 unsigned long offset = xas->xa_offset; in xas_pause()
1126 if (!xa_is_sibling(xa_entry(xas->xa, node, offset))) in xas_pause()
1129 xas->xa_index += (offset - xas->xa_offset) << node->shift; in xas_pause()
1130 if (xas->xa_index == 0) in xas_pause()
1131 xas->xa_node = XAS_BOUNDS; in xas_pause()
1133 xas->xa_index++; in xas_pause()
1145 void *__xas_prev(struct xa_state *xas) in __xas_prev() argument
1149 if (!xas_frozen(xas->xa_node)) in __xas_prev()
1150 xas->xa_index--; in __xas_prev()
1151 if (!xas->xa_node) in __xas_prev()
1152 return set_bounds(xas); in __xas_prev()
1153 if (xas_not_node(xas->xa_node)) in __xas_prev()
1154 return xas_load(xas); in __xas_prev()
1156 if (xas->xa_offset != get_offset(xas->xa_index, xas->xa_node)) in __xas_prev()
1157 xas->xa_offset--; in __xas_prev()
1159 while (xas->xa_offset == 255) { in __xas_prev()
1160 xas->xa_offset = xas->xa_node->offset - 1; in __xas_prev()
1161 xas->xa_node = xa_parent(xas->xa, xas->xa_node); in __xas_prev()
1162 if (!xas->xa_node) in __xas_prev()
1163 return set_bounds(xas); in __xas_prev()
1167 entry = xa_entry(xas->xa, xas->xa_node, xas->xa_offset); in __xas_prev()
1171 xas->xa_node = xa_to_node(entry); in __xas_prev()
1172 xas_set_offset(xas); in __xas_prev()
1184 void *__xas_next(struct xa_state *xas) in __xas_next() argument
1188 if (!xas_frozen(xas->xa_node)) in __xas_next()
1189 xas->xa_index++; in __xas_next()
1190 if (!xas->xa_node) in __xas_next()
1191 return set_bounds(xas); in __xas_next()
1192 if (xas_not_node(xas->xa_node)) in __xas_next()
1193 return xas_load(xas); in __xas_next()
1195 if (xas->xa_offset != get_offset(xas->xa_index, xas->xa_node)) in __xas_next()
1196 xas->xa_offset++; in __xas_next()
1198 while (xas->xa_offset == XA_CHUNK_SIZE) { in __xas_next()
1199 xas->xa_offset = xas->xa_node->offset + 1; in __xas_next()
1200 xas->xa_node = xa_parent(xas->xa, xas->xa_node); in __xas_next()
1201 if (!xas->xa_node) in __xas_next()
1202 return set_bounds(xas); in __xas_next()
1206 entry = xa_entry(xas->xa, xas->xa_node, xas->xa_offset); in __xas_next()
1210 xas->xa_node = xa_to_node(entry); in __xas_next()
1211 xas_set_offset(xas); in __xas_next()
1232 void *xas_find(struct xa_state *xas, unsigned long max) in xas_find() argument
1236 if (xas_error(xas) || xas->xa_node == XAS_BOUNDS) in xas_find()
1238 if (xas->xa_index > max) in xas_find()
1239 return set_bounds(xas); in xas_find()
1241 if (!xas->xa_node) { in xas_find()
1242 xas->xa_index = 1; in xas_find()
1243 return set_bounds(xas); in xas_find()
1244 } else if (xas->xa_node == XAS_RESTART) { in xas_find()
1245 entry = xas_load(xas); in xas_find()
1246 if (entry || xas_not_node(xas->xa_node)) in xas_find()
1248 } else if (!xas->xa_node->shift && in xas_find()
1249 xas->xa_offset != (xas->xa_index & XA_CHUNK_MASK)) { in xas_find()
1250 xas->xa_offset = ((xas->xa_index - 1) & XA_CHUNK_MASK) + 1; in xas_find()
1253 xas_advance(xas); in xas_find()
1255 while (xas->xa_node && (xas->xa_index <= max)) { in xas_find()
1256 if (unlikely(xas->xa_offset == XA_CHUNK_SIZE)) { in xas_find()
1257 xas->xa_offset = xas->xa_node->offset + 1; in xas_find()
1258 xas->xa_node = xa_parent(xas->xa, xas->xa_node); in xas_find()
1262 entry = xa_entry(xas->xa, xas->xa_node, xas->xa_offset); in xas_find()
1264 xas->xa_node = xa_to_node(entry); in xas_find()
1265 xas->xa_offset = 0; in xas_find()
1271 xas_advance(xas); in xas_find()
1274 if (!xas->xa_node) in xas_find()
1275 xas->xa_node = XAS_BOUNDS; in xas_find()
1301 void *xas_find_marked(struct xa_state *xas, unsigned long max, xa_mark_t mark) in xas_find_marked() argument
1307 if (xas_error(xas)) in xas_find_marked()
1309 if (xas->xa_index > max) in xas_find_marked()
1312 if (!xas->xa_node) { in xas_find_marked()
1313 xas->xa_index = 1; in xas_find_marked()
1315 } else if (xas_top(xas->xa_node)) { in xas_find_marked()
1317 entry = xa_head(xas->xa); in xas_find_marked()
1318 xas->xa_node = NULL; in xas_find_marked()
1319 if (xas->xa_index > max_index(entry)) in xas_find_marked()
1322 if (xa_marked(xas->xa, mark)) in xas_find_marked()
1324 xas->xa_index = 1; in xas_find_marked()
1327 xas->xa_node = xa_to_node(entry); in xas_find_marked()
1328 xas->xa_offset = xas->xa_index >> xas->xa_node->shift; in xas_find_marked()
1331 while (xas->xa_index <= max) { in xas_find_marked()
1332 if (unlikely(xas->xa_offset == XA_CHUNK_SIZE)) { in xas_find_marked()
1333 xas->xa_offset = xas->xa_node->offset + 1; in xas_find_marked()
1334 xas->xa_node = xa_parent(xas->xa, xas->xa_node); in xas_find_marked()
1335 if (!xas->xa_node) in xas_find_marked()
1342 entry = xa_entry(xas->xa, xas->xa_node, xas->xa_offset); in xas_find_marked()
1344 xas->xa_offset = xa_to_sibling(entry); in xas_find_marked()
1345 xas_move_index(xas, xas->xa_offset); in xas_find_marked()
1349 offset = xas_find_chunk(xas, advance, mark); in xas_find_marked()
1350 if (offset > xas->xa_offset) { in xas_find_marked()
1352 xas_move_index(xas, offset); in xas_find_marked()
1354 if ((xas->xa_index - 1) >= max) in xas_find_marked()
1356 xas->xa_offset = offset; in xas_find_marked()
1361 entry = xa_entry(xas->xa, xas->xa_node, xas->xa_offset); in xas_find_marked()
1362 if (!entry && !(xa_track_free(xas->xa) && mark == XA_FREE_MARK)) in xas_find_marked()
1366 xas->xa_node = xa_to_node(entry); in xas_find_marked()
1367 xas_set_offset(xas); in xas_find_marked()
1371 if (xas->xa_index > max) in xas_find_marked()
1373 return set_bounds(xas); in xas_find_marked()
1375 xas->xa_node = XAS_RESTART; in xas_find_marked()
1389 void *xas_find_conflict(struct xa_state *xas) in xas_find_conflict() argument
1393 if (xas_error(xas)) in xas_find_conflict()
1396 if (!xas->xa_node) in xas_find_conflict()
1399 if (xas_top(xas->xa_node)) { in xas_find_conflict()
1400 curr = xas_start(xas); in xas_find_conflict()
1405 curr = xas_descend(xas, node); in xas_find_conflict()
1411 if (xas->xa_node->shift > xas->xa_shift) in xas_find_conflict()
1415 if (xas->xa_node->shift == xas->xa_shift) { in xas_find_conflict()
1416 if ((xas->xa_offset & xas->xa_sibs) == xas->xa_sibs) in xas_find_conflict()
1418 } else if (xas->xa_offset == XA_CHUNK_MASK) { in xas_find_conflict()
1419 xas->xa_offset = xas->xa_node->offset; in xas_find_conflict()
1420 xas->xa_node = xa_parent_locked(xas->xa, xas->xa_node); in xas_find_conflict()
1421 if (!xas->xa_node) in xas_find_conflict()
1425 curr = xa_entry_locked(xas->xa, xas->xa_node, ++xas->xa_offset); in xas_find_conflict()
1429 xas->xa_node = xa_to_node(curr); in xas_find_conflict()
1430 xas->xa_offset = 0; in xas_find_conflict()
1431 curr = xa_entry_locked(xas->xa, xas->xa_node, 0); in xas_find_conflict()
1436 xas->xa_offset -= xas->xa_sibs; in xas_find_conflict()
1451 XA_STATE(xas, xa, index); in xa_load()
1456 entry = xas_load(&xas); in xa_load()
1459 } while (xas_retry(&xas, entry)); in xa_load()
1466 static void *xas_result(struct xa_state *xas, void *curr) in xas_result() argument
1470 if (xas_error(xas)) in xas_result()
1471 curr = xas->xa_node; in xas_result()
1489 XA_STATE(xas, xa, index); in __xa_erase()
1490 return xas_result(&xas, xas_store(&xas, NULL)); in __xa_erase()
1535 XA_STATE(xas, xa, index); in __xa_store()
1544 curr = xas_store(&xas, entry); in __xa_store()
1546 xas_clear_mark(&xas, XA_FREE_MARK); in __xa_store()
1547 } while (__xas_nomem(&xas, gfp)); in __xa_store()
1549 return xas_result(&xas, curr); in __xa_store()
1601 XA_STATE(xas, xa, index); in __xa_cmpxchg()
1608 curr = xas_load(&xas); in __xa_cmpxchg()
1610 xas_store(&xas, entry); in __xa_cmpxchg()
1612 xas_clear_mark(&xas, XA_FREE_MARK); in __xa_cmpxchg()
1614 } while (__xas_nomem(&xas, gfp)); in __xa_cmpxchg()
1616 return xas_result(&xas, curr); in __xa_cmpxchg()
1638 XA_STATE(xas, xa, index); in __xa_insert()
1647 curr = xas_load(&xas); in __xa_insert()
1649 xas_store(&xas, entry); in __xa_insert()
1651 xas_clear_mark(&xas, XA_FREE_MARK); in __xa_insert()
1653 xas_set_err(&xas, -EBUSY); in __xa_insert()
1655 } while (__xas_nomem(&xas, gfp)); in __xa_insert()
1657 return xas_error(&xas); in __xa_insert()
1662 static void xas_set_range(struct xa_state *xas, unsigned long first, in xas_set_range() argument
1669 xas_set(xas, first); in xas_set_range()
1689 xas->xa_shift = shift; in xas_set_range()
1690 xas->xa_sibs = sibs; in xas_set_range()
1714 XA_STATE(xas, xa, 0); in xa_store_range()
1722 xas_lock(&xas); in xa_store_range()
1727 xas_set_order(&xas, last, order); in xa_store_range()
1728 xas_create(&xas, true); in xa_store_range()
1729 if (xas_error(&xas)) in xa_store_range()
1733 xas_set_range(&xas, first, last); in xa_store_range()
1734 xas_store(&xas, entry); in xa_store_range()
1735 if (xas_error(&xas)) in xa_store_range()
1737 first += xas_size(&xas); in xa_store_range()
1740 xas_unlock(&xas); in xa_store_range()
1741 } while (xas_nomem(&xas, gfp)); in xa_store_range()
1743 return xas_result(&xas, NULL); in xa_store_range()
1756 XA_STATE(xas, xa, index); in xa_get_order()
1761 entry = xas_load(&xas); in xa_get_order()
1766 if (!xas.xa_node) in xa_get_order()
1770 unsigned int slot = xas.xa_offset + (1 << order); in xa_get_order()
1774 if (!xa_is_sibling(xas.xa_node->slots[slot])) in xa_get_order()
1779 order += xas.xa_node->shift; in xa_get_order()
1808 XA_STATE(xas, xa, 0); in __xa_alloc()
1819 xas.xa_index = limit.min; in __xa_alloc()
1820 xas_find_marked(&xas, limit.max, XA_FREE_MARK); in __xa_alloc()
1821 if (xas.xa_node == XAS_RESTART) in __xa_alloc()
1822 xas_set_err(&xas, -EBUSY); in __xa_alloc()
1824 *id = xas.xa_index; in __xa_alloc()
1825 xas_store(&xas, entry); in __xa_alloc()
1826 xas_clear_mark(&xas, XA_FREE_MARK); in __xa_alloc()
1827 } while (__xas_nomem(&xas, gfp)); in __xa_alloc()
1829 return xas_error(&xas); in __xa_alloc()
1895 XA_STATE(xas, xa, index); in __xa_set_mark()
1896 void *entry = xas_load(&xas); in __xa_set_mark()
1899 xas_set_mark(&xas, mark); in __xa_set_mark()
1913 XA_STATE(xas, xa, index); in __xa_clear_mark()
1914 void *entry = xas_load(&xas); in __xa_clear_mark()
1917 xas_clear_mark(&xas, mark); in __xa_clear_mark()
1935 XA_STATE(xas, xa, index); in xa_get_mark()
1939 entry = xas_start(&xas); in xa_get_mark()
1940 while (xas_get_mark(&xas, mark)) { in xa_get_mark()
1943 entry = xas_descend(&xas, xa_to_node(entry)); in xa_get_mark()
2009 XA_STATE(xas, xa, *indexp); in xa_find()
2015 entry = xas_find_marked(&xas, max, filter); in xa_find()
2017 entry = xas_find(&xas, max); in xa_find()
2018 } while (xas_retry(&xas, entry)); in xa_find()
2022 *indexp = xas.xa_index; in xa_find()
2027 static bool xas_sibling(struct xa_state *xas) in xas_sibling() argument
2029 struct xa_node *node = xas->xa_node; in xas_sibling()
2035 return (xas->xa_index & mask) > in xas_sibling()
2036 ((unsigned long)xas->xa_offset << node->shift); in xas_sibling()
2059 XA_STATE(xas, xa, *indexp + 1); in xa_find_after()
2062 if (xas.xa_index == 0) in xa_find_after()
2068 entry = xas_find_marked(&xas, max, filter); in xa_find_after()
2070 entry = xas_find(&xas, max); in xa_find_after()
2072 if (xas_invalid(&xas)) in xa_find_after()
2074 if (xas_sibling(&xas)) in xa_find_after()
2076 if (!xas_retry(&xas, entry)) in xa_find_after()
2082 *indexp = xas.xa_index; in xa_find_after()
2087 static unsigned int xas_extract_present(struct xa_state *xas, void **dst, in xas_extract_present() argument
2094 xas_for_each(xas, entry, max) { in xas_extract_present()
2095 if (xas_retry(xas, entry)) in xas_extract_present()
2106 static unsigned int xas_extract_marked(struct xa_state *xas, void **dst, in xas_extract_marked() argument
2113 xas_for_each_marked(xas, entry, max, mark) { in xas_extract_marked()
2114 if (xas_retry(xas, entry)) in xas_extract_marked()
2156 XA_STATE(xas, xa, start); in xa_extract()
2162 return xas_extract_marked(&xas, dst, max, n, filter); in xa_extract()
2163 return xas_extract_present(&xas, dst, max, n); in xa_extract()
2176 struct xa_state xas = { in xa_delete_node() local
2186 xas_store(&xas, NULL); in xa_delete_node()
2202 XA_STATE(xas, xa, 0); in xa_destroy()
2206 xas.xa_node = NULL; in xa_destroy()
2207 xas_lock_irqsave(&xas, flags); in xa_destroy()
2210 xas_init_marks(&xas); in xa_destroy()
2215 xas_free_nodes(&xas, xa_to_node(entry)); in xa_destroy()
2216 xas_unlock_irqrestore(&xas, flags); in xa_destroy()