Lines Matching refs:state
37 static inline bool extent_state_in_tree(const struct extent_state *state) in extent_state_in_tree() argument
39 return !RB_EMPTY_NODE(&state->rb_node); in extent_state_in_tree()
95 struct extent_state *state; in btrfs_extent_state_leak_debug_check() local
98 state = list_entry(states.next, struct extent_state, leak_list); in btrfs_extent_state_leak_debug_check()
100 state->start, state->end, state->state, in btrfs_extent_state_leak_debug_check()
101 extent_state_in_tree(state), in btrfs_extent_state_leak_debug_check()
102 refcount_read(&state->refs)); in btrfs_extent_state_leak_debug_check()
103 list_del(&state->leak_list); in btrfs_extent_state_leak_debug_check()
104 kmem_cache_free(extent_state_cache, state); in btrfs_extent_state_leak_debug_check()
150 static int add_extent_changeset(struct extent_state *state, u32 bits, in add_extent_changeset() argument
158 if (set && (state->state & bits) == bits) in add_extent_changeset()
160 if (!set && (state->state & bits) == 0) in add_extent_changeset()
162 changeset->bytes_changed += state->end - state->start + 1; in add_extent_changeset()
163 ret = ulist_add(&changeset->range_changed, state->start, state->end, in add_extent_changeset()
293 tree->state = RB_ROOT; in extent_io_tree_init()
311 while (!RB_EMPTY_ROOT(&tree->state)) { in extent_io_tree_release()
313 struct extent_state *state; in extent_io_tree_release() local
315 node = rb_first(&tree->state); in extent_io_tree_release()
316 state = rb_entry(node, struct extent_state, rb_node); in extent_io_tree_release()
317 rb_erase(&state->rb_node, &tree->state); in extent_io_tree_release()
318 RB_CLEAR_NODE(&state->rb_node); in extent_io_tree_release()
323 ASSERT(!waitqueue_active(&state->wq)); in extent_io_tree_release()
324 free_extent_state(state); in extent_io_tree_release()
333 struct extent_state *state; in alloc_extent_state() local
340 state = kmem_cache_alloc(extent_state_cache, mask); in alloc_extent_state()
341 if (!state) in alloc_extent_state()
342 return state; in alloc_extent_state()
343 state->state = 0; in alloc_extent_state()
344 state->failrec = NULL; in alloc_extent_state()
345 RB_CLEAR_NODE(&state->rb_node); in alloc_extent_state()
346 btrfs_leak_debug_add(&leak_lock, &state->leak_list, &states); in alloc_extent_state()
347 refcount_set(&state->refs, 1); in alloc_extent_state()
348 init_waitqueue_head(&state->wq); in alloc_extent_state()
349 trace_alloc_extent_state(state, mask, _RET_IP_); in alloc_extent_state()
350 return state; in alloc_extent_state()
353 void free_extent_state(struct extent_state *state) in free_extent_state() argument
355 if (!state) in free_extent_state()
357 if (refcount_dec_and_test(&state->refs)) { in free_extent_state()
358 WARN_ON(extent_state_in_tree(state)); in free_extent_state()
359 btrfs_leak_debug_del(&leak_lock, &state->leak_list); in free_extent_state()
360 trace_free_extent_state(state, _RET_IP_); in free_extent_state()
361 kmem_cache_free(extent_state_cache, state); in free_extent_state()
425 struct rb_root *root = &tree->state; in __etree_search()
502 struct extent_state *state) in merge_state() argument
507 if (state->state & (EXTENT_LOCKED | EXTENT_BOUNDARY)) in merge_state()
510 other_node = rb_prev(&state->rb_node); in merge_state()
513 if (other->end == state->start - 1 && in merge_state()
514 other->state == state->state) { in merge_state()
518 state, other); in merge_state()
519 state->start = other->start; in merge_state()
520 rb_erase(&other->rb_node, &tree->state); in merge_state()
525 other_node = rb_next(&state->rb_node); in merge_state()
528 if (other->start == state->end + 1 && in merge_state()
529 other->state == state->state) { in merge_state()
533 state, other); in merge_state()
534 state->end = other->end; in merge_state()
535 rb_erase(&other->rb_node, &tree->state); in merge_state()
543 struct extent_state *state, u32 *bits,
557 struct extent_state *state, u64 start, u64 end, in insert_state() argument
569 state->start = start; in insert_state()
570 state->end = end; in insert_state()
572 set_state_bits(tree, state, bits, changeset); in insert_state()
574 node = tree_insert(&tree->state, NULL, end, &state->rb_node, p, parent); in insert_state()
583 merge_state(tree, state); in insert_state()
611 prealloc->state = orig->state; in split_state()
614 node = tree_insert(&tree->state, &orig->rb_node, prealloc->end, in split_state()
623 static struct extent_state *next_state(struct extent_state *state) in next_state() argument
625 struct rb_node *next = rb_next(&state->rb_node); in next_state()
640 struct extent_state *state, in clear_state_bit() argument
648 if ((bits_to_clear & EXTENT_DIRTY) && (state->state & EXTENT_DIRTY)) { in clear_state_bit()
649 u64 range = state->end - state->start + 1; in clear_state_bit()
655 btrfs_clear_delalloc_extent(tree->private_data, state, bits); in clear_state_bit()
657 ret = add_extent_changeset(state, bits_to_clear, changeset, 0); in clear_state_bit()
659 state->state &= ~bits_to_clear; in clear_state_bit()
661 wake_up(&state->wq); in clear_state_bit()
662 if (state->state == 0) { in clear_state_bit()
663 next = next_state(state); in clear_state_bit()
664 if (extent_state_in_tree(state)) { in clear_state_bit()
665 rb_erase(&state->rb_node, &tree->state); in clear_state_bit()
666 RB_CLEAR_NODE(&state->rb_node); in clear_state_bit()
667 free_extent_state(state); in clear_state_bit()
672 merge_state(tree, state); in clear_state_bit()
673 next = next_state(state); in clear_state_bit()
710 struct extent_state *state; in __clear_extent_bit() local
754 state = cached; in __clear_extent_bit()
767 state = rb_entry(node, struct extent_state, rb_node); in __clear_extent_bit()
769 if (state->start > end) in __clear_extent_bit()
771 WARN_ON(state->end < start); in __clear_extent_bit()
772 last_end = state->end; in __clear_extent_bit()
775 if (!(state->state & bits)) { in __clear_extent_bit()
776 state = next_state(state); in __clear_extent_bit()
796 if (state->start < start) { in __clear_extent_bit()
799 err = split_state(tree, state, prealloc, start); in __clear_extent_bit()
806 if (state->end <= end) { in __clear_extent_bit()
807 state = clear_state_bit(tree, state, &bits, wake, in __clear_extent_bit()
819 if (state->start <= end && state->end > end) { in __clear_extent_bit()
822 err = split_state(tree, state, prealloc, end + 1); in __clear_extent_bit()
827 wake_up(&state->wq); in __clear_extent_bit()
835 state = clear_state_bit(tree, state, &bits, wake, changeset); in __clear_extent_bit()
840 if (start <= end && state && !need_resched()) in __clear_extent_bit()
861 struct extent_state *state) in wait_on_state() argument
866 prepare_to_wait(&state->wq, &wait, TASK_UNINTERRUPTIBLE); in wait_on_state()
870 finish_wait(&state->wq, &wait); in wait_on_state()
881 struct extent_state *state; in wait_extent_bit() local
898 state = rb_entry(node, struct extent_state, rb_node); in wait_extent_bit()
900 if (state->start > end) in wait_extent_bit()
903 if (state->state & bits) { in wait_extent_bit()
904 start = state->start; in wait_extent_bit()
905 refcount_inc(&state->refs); in wait_extent_bit()
906 wait_on_state(tree, state); in wait_extent_bit()
907 free_extent_state(state); in wait_extent_bit()
910 start = state->end + 1; in wait_extent_bit()
925 struct extent_state *state, in set_state_bits() argument
932 btrfs_set_delalloc_extent(tree->private_data, state, bits); in set_state_bits()
934 if ((bits_to_set & EXTENT_DIRTY) && !(state->state & EXTENT_DIRTY)) { in set_state_bits()
935 u64 range = state->end - state->start + 1; in set_state_bits()
938 ret = add_extent_changeset(state, bits_to_set, changeset, 1); in set_state_bits()
940 state->state |= bits_to_set; in set_state_bits()
943 static void cache_state_if_flags(struct extent_state *state, in cache_state_if_flags() argument
948 if (!flags || (state->state & flags)) { in cache_state_if_flags()
949 *cached_ptr = state; in cache_state_if_flags()
950 refcount_inc(&state->refs); in cache_state_if_flags()
955 static void cache_state(struct extent_state *state, in cache_state() argument
958 return cache_state_if_flags(state, cached_ptr, in cache_state()
977 struct extent_state *state; in set_extent_bit() local
1007 state = *cached_state; in set_extent_bit()
1008 if (state->start <= start && state->end > start && in set_extent_bit()
1009 extent_state_in_tree(state)) { in set_extent_bit()
1010 node = &state->rb_node; in set_extent_bit()
1031 state = rb_entry(node, struct extent_state, rb_node); in set_extent_bit()
1033 last_start = state->start; in set_extent_bit()
1034 last_end = state->end; in set_extent_bit()
1042 if (state->start == start && state->end <= end) { in set_extent_bit()
1043 if (state->state & exclusive_bits) { in set_extent_bit()
1044 *failed_start = state->start; in set_extent_bit()
1049 set_state_bits(tree, state, &bits, changeset); in set_extent_bit()
1050 cache_state(state, cached_state); in set_extent_bit()
1051 merge_state(tree, state); in set_extent_bit()
1055 state = next_state(state); in set_extent_bit()
1056 if (start < end && state && state->start == start && in set_extent_bit()
1078 if (state->start < start) { in set_extent_bit()
1079 if (state->state & exclusive_bits) { in set_extent_bit()
1089 if ((state->state & bits) == bits) { in set_extent_bit()
1090 start = state->end + 1; in set_extent_bit()
1091 cache_state(state, cached_state); in set_extent_bit()
1097 err = split_state(tree, state, prealloc, start); in set_extent_bit()
1104 if (state->end <= end) { in set_extent_bit()
1105 set_state_bits(tree, state, &bits, changeset); in set_extent_bit()
1106 cache_state(state, cached_state); in set_extent_bit()
1107 merge_state(tree, state); in set_extent_bit()
1111 state = next_state(state); in set_extent_bit()
1112 if (start < end && state && state->start == start && in set_extent_bit()
1125 if (state->start > start) { in set_extent_bit()
1155 if (state->start <= end && state->end > end) { in set_extent_bit()
1156 if (state->state & exclusive_bits) { in set_extent_bit()
1164 err = split_state(tree, state, prealloc, end + 1); in set_extent_bit()
1214 struct extent_state *state; in convert_extent_bit() local
1244 state = *cached_state; in convert_extent_bit()
1245 if (state->start <= start && state->end > start && in convert_extent_bit()
1246 extent_state_in_tree(state)) { in convert_extent_bit()
1247 node = &state->rb_node; in convert_extent_bit()
1271 state = rb_entry(node, struct extent_state, rb_node); in convert_extent_bit()
1273 last_start = state->start; in convert_extent_bit()
1274 last_end = state->end; in convert_extent_bit()
1282 if (state->start == start && state->end <= end) { in convert_extent_bit()
1283 set_state_bits(tree, state, &bits, NULL); in convert_extent_bit()
1284 cache_state(state, cached_state); in convert_extent_bit()
1285 state = clear_state_bit(tree, state, &clear_bits, 0, NULL); in convert_extent_bit()
1289 if (start < end && state && state->start == start && in convert_extent_bit()
1311 if (state->start < start) { in convert_extent_bit()
1317 err = split_state(tree, state, prealloc, start); in convert_extent_bit()
1323 if (state->end <= end) { in convert_extent_bit()
1324 set_state_bits(tree, state, &bits, NULL); in convert_extent_bit()
1325 cache_state(state, cached_state); in convert_extent_bit()
1326 state = clear_state_bit(tree, state, &clear_bits, 0, in convert_extent_bit()
1331 if (start < end && state && state->start == start && in convert_extent_bit()
1344 if (state->start > start) { in convert_extent_bit()
1376 if (state->start <= end && state->end > end) { in convert_extent_bit()
1383 err = split_state(tree, state, prealloc, end + 1); in convert_extent_bit()
1533 struct extent_state *state; in find_first_extent_bit_state() local
1544 state = rb_entry(node, struct extent_state, rb_node); in find_first_extent_bit_state()
1545 if (state->end >= start && (state->state & bits)) in find_first_extent_bit_state()
1546 return state; in find_first_extent_bit_state()
1568 struct extent_state *state; in find_first_extent_bit() local
1573 state = *cached_state; in find_first_extent_bit()
1574 if (state->end == start - 1 && extent_state_in_tree(state)) { in find_first_extent_bit()
1575 while ((state = next_state(state)) != NULL) { in find_first_extent_bit()
1576 if (state->state & bits) in find_first_extent_bit()
1587 state = find_first_extent_bit_state(tree, start, bits); in find_first_extent_bit()
1589 if (state) { in find_first_extent_bit()
1590 cache_state_if_flags(state, cached_state, 0); in find_first_extent_bit()
1591 *start_ret = state->start; in find_first_extent_bit()
1592 *end_ret = state->end; in find_first_extent_bit()
1619 struct extent_state *state; in find_contiguous_extent_bit() local
1623 state = find_first_extent_bit_state(tree, start, bits); in find_contiguous_extent_bit()
1624 if (state) { in find_contiguous_extent_bit()
1625 *start_ret = state->start; in find_contiguous_extent_bit()
1626 *end_ret = state->end; in find_contiguous_extent_bit()
1627 while ((state = next_state(state)) != NULL) { in find_contiguous_extent_bit()
1628 if (state->start > (*end_ret + 1)) in find_contiguous_extent_bit()
1630 *end_ret = state->end; in find_contiguous_extent_bit()
1656 struct extent_state *state; in find_first_clear_extent_bit() local
1677 state = rb_entry(prev, struct extent_state, rb_node); in find_first_clear_extent_bit()
1678 *start_ret = state->end + 1; in find_first_clear_extent_bit()
1688 state = rb_entry(node, struct extent_state, rb_node); in find_first_clear_extent_bit()
1690 if (in_range(start, state->start, state->end - state->start + 1)) { in find_first_clear_extent_bit()
1691 if (state->state & bits) { in find_first_clear_extent_bit()
1697 start = state->end + 1; in find_first_clear_extent_bit()
1708 *start_ret = state->start; in find_first_clear_extent_bit()
1724 state = rb_entry(prev, struct extent_state, in find_first_clear_extent_bit()
1726 *start_ret = state->end + 1; in find_first_clear_extent_bit()
1739 state = rb_entry(node, struct extent_state, rb_node); in find_first_clear_extent_bit()
1740 if (state->end >= start && !(state->state & bits)) { in find_first_clear_extent_bit()
1741 *end_ret = state->end; in find_first_clear_extent_bit()
1743 *end_ret = state->start - 1; in find_first_clear_extent_bit()
1766 struct extent_state *state; in btrfs_find_delalloc_range() local
1784 state = rb_entry(node, struct extent_state, rb_node); in btrfs_find_delalloc_range()
1785 if (found && (state->start != cur_start || in btrfs_find_delalloc_range()
1786 (state->state & EXTENT_BOUNDARY))) { in btrfs_find_delalloc_range()
1789 if (!(state->state & EXTENT_DELALLOC)) { in btrfs_find_delalloc_range()
1791 *end = state->end; in btrfs_find_delalloc_range()
1795 *start = state->start; in btrfs_find_delalloc_range()
1796 *cached_state = state; in btrfs_find_delalloc_range()
1797 refcount_inc(&state->refs); in btrfs_find_delalloc_range()
1800 *end = state->end; in btrfs_find_delalloc_range()
1801 cur_start = state->end + 1; in btrfs_find_delalloc_range()
1803 total_bytes += state->end - state->start + 1; in btrfs_find_delalloc_range()
2087 struct extent_state *state; in count_range_bits() local
2110 state = rb_entry(node, struct extent_state, rb_node); in count_range_bits()
2111 if (state->start > search_end) in count_range_bits()
2113 if (contig && found && state->start > last + 1) in count_range_bits()
2115 if (state->end >= cur_start && (state->state & bits) == bits) { in count_range_bits()
2116 total_bytes += min(search_end, state->end) + 1 - in count_range_bits()
2117 max(cur_start, state->start); in count_range_bits()
2121 *start = max(cur_start, state->start); in count_range_bits()
2124 last = state->end; in count_range_bits()
2145 struct extent_state *state; in set_state_failrec() local
2158 state = rb_entry(node, struct extent_state, rb_node); in set_state_failrec()
2159 if (state->start != start) { in set_state_failrec()
2163 state->failrec = failrec; in set_state_failrec()
2172 struct extent_state *state; in get_state_failrec() local
2185 state = rb_entry(node, struct extent_state, rb_node); in get_state_failrec()
2186 if (state->start != start) { in get_state_failrec()
2191 failrec = state->failrec; in get_state_failrec()
2206 struct extent_state *state = NULL; in test_range_bit() local
2217 state = rb_entry(node, struct extent_state, rb_node); in test_range_bit()
2219 if (filled && state->start > start) { in test_range_bit()
2224 if (state->start > end) in test_range_bit()
2227 if (state->state & bits) { in test_range_bit()
2236 if (state->end == (u64)-1) in test_range_bit()
2239 start = state->end + 1; in test_range_bit()
2405 struct extent_state *state; in clean_io_failure() local
2425 state = find_first_extent_bit_state(io_tree, in clean_io_failure()
2430 if (state && state->start <= failrec->start && in clean_io_failure()
2431 state->end >= failrec->start + failrec->len - 1) { in clean_io_failure()
2457 struct extent_state *state, *next; in btrfs_free_io_failure_record() local
2459 if (RB_EMPTY_ROOT(&failure_tree->state)) in btrfs_free_io_failure_record()
2463 state = find_first_extent_bit_state(failure_tree, start, EXTENT_DIRTY); in btrfs_free_io_failure_record()
2464 while (state) { in btrfs_free_io_failure_record()
2465 if (state->start > end) in btrfs_free_io_failure_record()
2468 ASSERT(state->end <= end); in btrfs_free_io_failure_record()
2470 next = next_state(state); in btrfs_free_io_failure_record()
2472 failrec = state->failrec; in btrfs_free_io_failure_record()
2473 free_extent_state(state); in btrfs_free_io_failure_record()
2476 state = next; in btrfs_free_io_failure_record()