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()
1050 void xas_split(struct xa_state *xas, void *entry, unsigned int order) in xas_split() argument
1055 void *curr = xas_load(xas); in xas_split()
1058 node = xas->xa_node; in xas_split()
1062 marks = node_get_marks(node, xas->xa_offset); in xas_split()
1064 offset = xas->xa_offset + sibs; in xas_split()
1066 if (xas->xa_shift < node->shift) { in xas_split()
1067 struct xa_node *child = xas->xa_alloc; in xas_split()
1069 xas->xa_alloc = rcu_dereference_raw(child->parent); in xas_split()
1082 unsigned int canon = offset - xas->xa_sibs; in xas_split()
1090 (xas->xa_sibs + 1); in xas_split()
1092 } while (offset-- > xas->xa_offset); in xas_split()
1114 void xas_pause(struct xa_state *xas) in xas_pause() argument
1116 struct xa_node *node = xas->xa_node; in xas_pause()
1118 if (xas_invalid(xas)) in xas_pause()
1121 xas->xa_node = XAS_RESTART; in xas_pause()
1123 unsigned long offset = xas->xa_offset; in xas_pause()
1125 if (!xa_is_sibling(xa_entry(xas->xa, node, offset))) in xas_pause()
1128 xas->xa_index += (offset - xas->xa_offset) << node->shift; in xas_pause()
1129 if (xas->xa_index == 0) in xas_pause()
1130 xas->xa_node = XAS_BOUNDS; in xas_pause()
1132 xas->xa_index++; in xas_pause()
1144 void *__xas_prev(struct xa_state *xas) in __xas_prev() argument
1148 if (!xas_frozen(xas->xa_node)) in __xas_prev()
1149 xas->xa_index--; in __xas_prev()
1150 if (!xas->xa_node) in __xas_prev()
1151 return set_bounds(xas); in __xas_prev()
1152 if (xas_not_node(xas->xa_node)) in __xas_prev()
1153 return xas_load(xas); in __xas_prev()
1155 if (xas->xa_offset != get_offset(xas->xa_index, xas->xa_node)) in __xas_prev()
1156 xas->xa_offset--; in __xas_prev()
1158 while (xas->xa_offset == 255) { in __xas_prev()
1159 xas->xa_offset = xas->xa_node->offset - 1; in __xas_prev()
1160 xas->xa_node = xa_parent(xas->xa, xas->xa_node); in __xas_prev()
1161 if (!xas->xa_node) in __xas_prev()
1162 return set_bounds(xas); in __xas_prev()
1166 entry = xa_entry(xas->xa, xas->xa_node, xas->xa_offset); in __xas_prev()
1170 xas->xa_node = xa_to_node(entry); in __xas_prev()
1171 xas_set_offset(xas); in __xas_prev()
1183 void *__xas_next(struct xa_state *xas) in __xas_next() argument
1187 if (!xas_frozen(xas->xa_node)) in __xas_next()
1188 xas->xa_index++; in __xas_next()
1189 if (!xas->xa_node) in __xas_next()
1190 return set_bounds(xas); in __xas_next()
1191 if (xas_not_node(xas->xa_node)) in __xas_next()
1192 return xas_load(xas); in __xas_next()
1194 if (xas->xa_offset != get_offset(xas->xa_index, xas->xa_node)) in __xas_next()
1195 xas->xa_offset++; in __xas_next()
1197 while (xas->xa_offset == XA_CHUNK_SIZE) { in __xas_next()
1198 xas->xa_offset = xas->xa_node->offset + 1; in __xas_next()
1199 xas->xa_node = xa_parent(xas->xa, xas->xa_node); in __xas_next()
1200 if (!xas->xa_node) in __xas_next()
1201 return set_bounds(xas); in __xas_next()
1205 entry = xa_entry(xas->xa, xas->xa_node, xas->xa_offset); in __xas_next()
1209 xas->xa_node = xa_to_node(entry); in __xas_next()
1210 xas_set_offset(xas); in __xas_next()
1231 void *xas_find(struct xa_state *xas, unsigned long max) in xas_find() argument
1235 if (xas_error(xas) || xas->xa_node == XAS_BOUNDS) in xas_find()
1237 if (xas->xa_index > max) in xas_find()
1238 return set_bounds(xas); in xas_find()
1240 if (!xas->xa_node) { in xas_find()
1241 xas->xa_index = 1; in xas_find()
1242 return set_bounds(xas); in xas_find()
1243 } else if (xas->xa_node == XAS_RESTART) { in xas_find()
1244 entry = xas_load(xas); in xas_find()
1245 if (entry || xas_not_node(xas->xa_node)) in xas_find()
1247 } else if (!xas->xa_node->shift && in xas_find()
1248 xas->xa_offset != (xas->xa_index & XA_CHUNK_MASK)) { in xas_find()
1249 xas->xa_offset = ((xas->xa_index - 1) & XA_CHUNK_MASK) + 1; in xas_find()
1252 xas_advance(xas); in xas_find()
1254 while (xas->xa_node && (xas->xa_index <= max)) { in xas_find()
1255 if (unlikely(xas->xa_offset == XA_CHUNK_SIZE)) { in xas_find()
1256 xas->xa_offset = xas->xa_node->offset + 1; in xas_find()
1257 xas->xa_node = xa_parent(xas->xa, xas->xa_node); in xas_find()
1261 entry = xa_entry(xas->xa, xas->xa_node, xas->xa_offset); in xas_find()
1263 xas->xa_node = xa_to_node(entry); in xas_find()
1264 xas->xa_offset = 0; in xas_find()
1270 xas_advance(xas); in xas_find()
1273 if (!xas->xa_node) in xas_find()
1274 xas->xa_node = XAS_BOUNDS; in xas_find()
1300 void *xas_find_marked(struct xa_state *xas, unsigned long max, xa_mark_t mark) in xas_find_marked() argument
1306 if (xas_error(xas)) in xas_find_marked()
1308 if (xas->xa_index > max) in xas_find_marked()
1311 if (!xas->xa_node) { in xas_find_marked()
1312 xas->xa_index = 1; in xas_find_marked()
1314 } else if (xas_top(xas->xa_node)) { in xas_find_marked()
1316 entry = xa_head(xas->xa); in xas_find_marked()
1317 xas->xa_node = NULL; in xas_find_marked()
1318 if (xas->xa_index > max_index(entry)) in xas_find_marked()
1321 if (xa_marked(xas->xa, mark)) in xas_find_marked()
1323 xas->xa_index = 1; in xas_find_marked()
1326 xas->xa_node = xa_to_node(entry); in xas_find_marked()
1327 xas->xa_offset = xas->xa_index >> xas->xa_node->shift; in xas_find_marked()
1330 while (xas->xa_index <= max) { in xas_find_marked()
1331 if (unlikely(xas->xa_offset == XA_CHUNK_SIZE)) { in xas_find_marked()
1332 xas->xa_offset = xas->xa_node->offset + 1; in xas_find_marked()
1333 xas->xa_node = xa_parent(xas->xa, xas->xa_node); in xas_find_marked()
1334 if (!xas->xa_node) in xas_find_marked()
1341 entry = xa_entry(xas->xa, xas->xa_node, xas->xa_offset); in xas_find_marked()
1343 xas->xa_offset = xa_to_sibling(entry); in xas_find_marked()
1344 xas_move_index(xas, xas->xa_offset); in xas_find_marked()
1348 offset = xas_find_chunk(xas, advance, mark); in xas_find_marked()
1349 if (offset > xas->xa_offset) { in xas_find_marked()
1351 xas_move_index(xas, offset); in xas_find_marked()
1353 if ((xas->xa_index - 1) >= max) in xas_find_marked()
1355 xas->xa_offset = offset; in xas_find_marked()
1360 entry = xa_entry(xas->xa, xas->xa_node, xas->xa_offset); in xas_find_marked()
1361 if (!entry && !(xa_track_free(xas->xa) && mark == XA_FREE_MARK)) in xas_find_marked()
1365 xas->xa_node = xa_to_node(entry); in xas_find_marked()
1366 xas_set_offset(xas); in xas_find_marked()
1370 if (xas->xa_index > max) in xas_find_marked()
1372 return set_bounds(xas); in xas_find_marked()
1374 xas->xa_node = XAS_RESTART; in xas_find_marked()
1388 void *xas_find_conflict(struct xa_state *xas) in xas_find_conflict() argument
1392 if (xas_error(xas)) in xas_find_conflict()
1395 if (!xas->xa_node) in xas_find_conflict()
1398 if (xas_top(xas->xa_node)) { in xas_find_conflict()
1399 curr = xas_start(xas); in xas_find_conflict()
1404 curr = xas_descend(xas, node); in xas_find_conflict()
1410 if (xas->xa_node->shift > xas->xa_shift) in xas_find_conflict()
1414 if (xas->xa_node->shift == xas->xa_shift) { in xas_find_conflict()
1415 if ((xas->xa_offset & xas->xa_sibs) == xas->xa_sibs) in xas_find_conflict()
1417 } else if (xas->xa_offset == XA_CHUNK_MASK) { in xas_find_conflict()
1418 xas->xa_offset = xas->xa_node->offset; in xas_find_conflict()
1419 xas->xa_node = xa_parent_locked(xas->xa, xas->xa_node); in xas_find_conflict()
1420 if (!xas->xa_node) in xas_find_conflict()
1424 curr = xa_entry_locked(xas->xa, xas->xa_node, ++xas->xa_offset); in xas_find_conflict()
1428 xas->xa_node = xa_to_node(curr); in xas_find_conflict()
1429 xas->xa_offset = 0; in xas_find_conflict()
1430 curr = xa_entry_locked(xas->xa, xas->xa_node, 0); in xas_find_conflict()
1435 xas->xa_offset -= xas->xa_sibs; in xas_find_conflict()
1450 XA_STATE(xas, xa, index); in xa_load()
1455 entry = xas_load(&xas); in xa_load()
1458 } while (xas_retry(&xas, entry)); in xa_load()
1465 static void *xas_result(struct xa_state *xas, void *curr) in xas_result() argument
1469 if (xas_error(xas)) in xas_result()
1470 curr = xas->xa_node; in xas_result()
1488 XA_STATE(xas, xa, index); in __xa_erase()
1489 return xas_result(&xas, xas_store(&xas, NULL)); in __xa_erase()
1534 XA_STATE(xas, xa, index); in __xa_store()
1543 curr = xas_store(&xas, entry); in __xa_store()
1545 xas_clear_mark(&xas, XA_FREE_MARK); in __xa_store()
1546 } while (__xas_nomem(&xas, gfp)); in __xa_store()
1548 return xas_result(&xas, curr); in __xa_store()
1600 XA_STATE(xas, xa, index); in __xa_cmpxchg()
1607 curr = xas_load(&xas); in __xa_cmpxchg()
1609 xas_store(&xas, entry); in __xa_cmpxchg()
1611 xas_clear_mark(&xas, XA_FREE_MARK); in __xa_cmpxchg()
1613 } while (__xas_nomem(&xas, gfp)); in __xa_cmpxchg()
1615 return xas_result(&xas, curr); in __xa_cmpxchg()
1637 XA_STATE(xas, xa, index); in __xa_insert()
1646 curr = xas_load(&xas); in __xa_insert()
1648 xas_store(&xas, entry); in __xa_insert()
1650 xas_clear_mark(&xas, XA_FREE_MARK); in __xa_insert()
1652 xas_set_err(&xas, -EBUSY); in __xa_insert()
1654 } while (__xas_nomem(&xas, gfp)); in __xa_insert()
1656 return xas_error(&xas); in __xa_insert()
1661 static void xas_set_range(struct xa_state *xas, unsigned long first, in xas_set_range() argument
1668 xas_set(xas, first); in xas_set_range()
1688 xas->xa_shift = shift; in xas_set_range()
1689 xas->xa_sibs = sibs; in xas_set_range()
1713 XA_STATE(xas, xa, 0); in xa_store_range()
1721 xas_lock(&xas); in xa_store_range()
1726 xas_set_order(&xas, last, order); in xa_store_range()
1727 xas_create(&xas, true); in xa_store_range()
1728 if (xas_error(&xas)) in xa_store_range()
1732 xas_set_range(&xas, first, last); in xa_store_range()
1733 xas_store(&xas, entry); in xa_store_range()
1734 if (xas_error(&xas)) in xa_store_range()
1736 first += xas_size(&xas); in xa_store_range()
1739 xas_unlock(&xas); in xa_store_range()
1740 } while (xas_nomem(&xas, gfp)); in xa_store_range()
1742 return xas_result(&xas, NULL); in xa_store_range()
1755 XA_STATE(xas, xa, index); in xa_get_order()
1760 entry = xas_load(&xas); in xa_get_order()
1765 if (!xas.xa_node) in xa_get_order()
1769 unsigned int slot = xas.xa_offset + (1 << order); in xa_get_order()
1773 if (!xa_is_sibling(xas.xa_node->slots[slot])) in xa_get_order()
1778 order += xas.xa_node->shift; in xa_get_order()
1807 XA_STATE(xas, xa, 0); in __xa_alloc()
1818 xas.xa_index = limit.min; in __xa_alloc()
1819 xas_find_marked(&xas, limit.max, XA_FREE_MARK); in __xa_alloc()
1820 if (xas.xa_node == XAS_RESTART) in __xa_alloc()
1821 xas_set_err(&xas, -EBUSY); in __xa_alloc()
1823 *id = xas.xa_index; in __xa_alloc()
1824 xas_store(&xas, entry); in __xa_alloc()
1825 xas_clear_mark(&xas, XA_FREE_MARK); in __xa_alloc()
1826 } while (__xas_nomem(&xas, gfp)); in __xa_alloc()
1828 return xas_error(&xas); in __xa_alloc()
1894 XA_STATE(xas, xa, index); in __xa_set_mark()
1895 void *entry = xas_load(&xas); in __xa_set_mark()
1898 xas_set_mark(&xas, mark); in __xa_set_mark()
1912 XA_STATE(xas, xa, index); in __xa_clear_mark()
1913 void *entry = xas_load(&xas); in __xa_clear_mark()
1916 xas_clear_mark(&xas, mark); in __xa_clear_mark()
1934 XA_STATE(xas, xa, index); in xa_get_mark()
1938 entry = xas_start(&xas); in xa_get_mark()
1939 while (xas_get_mark(&xas, mark)) { in xa_get_mark()
1942 entry = xas_descend(&xas, xa_to_node(entry)); in xa_get_mark()
2008 XA_STATE(xas, xa, *indexp); in xa_find()
2014 entry = xas_find_marked(&xas, max, filter); in xa_find()
2016 entry = xas_find(&xas, max); in xa_find()
2017 } while (xas_retry(&xas, entry)); in xa_find()
2021 *indexp = xas.xa_index; in xa_find()
2026 static bool xas_sibling(struct xa_state *xas) in xas_sibling() argument
2028 struct xa_node *node = xas->xa_node; in xas_sibling()
2034 return (xas->xa_index & mask) > in xas_sibling()
2035 ((unsigned long)xas->xa_offset << node->shift); in xas_sibling()
2058 XA_STATE(xas, xa, *indexp + 1); in xa_find_after()
2061 if (xas.xa_index == 0) in xa_find_after()
2067 entry = xas_find_marked(&xas, max, filter); in xa_find_after()
2069 entry = xas_find(&xas, max); in xa_find_after()
2071 if (xas_invalid(&xas)) in xa_find_after()
2073 if (xas_sibling(&xas)) in xa_find_after()
2075 if (!xas_retry(&xas, entry)) in xa_find_after()
2081 *indexp = xas.xa_index; in xa_find_after()
2086 static unsigned int xas_extract_present(struct xa_state *xas, void **dst, in xas_extract_present() argument
2093 xas_for_each(xas, entry, max) { in xas_extract_present()
2094 if (xas_retry(xas, entry)) in xas_extract_present()
2105 static unsigned int xas_extract_marked(struct xa_state *xas, void **dst, in xas_extract_marked() argument
2112 xas_for_each_marked(xas, entry, max, mark) { in xas_extract_marked()
2113 if (xas_retry(xas, entry)) in xas_extract_marked()
2155 XA_STATE(xas, xa, start); in xa_extract()
2161 return xas_extract_marked(&xas, dst, max, n, filter); in xa_extract()
2162 return xas_extract_present(&xas, dst, max, n); in xa_extract()
2175 struct xa_state xas = { in xa_delete_node() local
2185 xas_store(&xas, NULL); in xa_delete_node()
2201 XA_STATE(xas, xa, 0); in xa_destroy()
2205 xas.xa_node = NULL; in xa_destroy()
2206 xas_lock_irqsave(&xas, flags); in xa_destroy()
2209 xas_init_marks(&xas); in xa_destroy()
2214 xas_free_nodes(&xas, xa_to_node(entry)); in xa_destroy()
2215 xas_unlock_irqrestore(&xas, flags); in xa_destroy()