Lines Matching +full:non +full:- +full:overlapping
1 // SPDX-License-Identifier: GPL-2.0
7 #include "btrfs-tests.h"
9 #include "../disk-io.h"
10 #include "../free-space-cache.h"
11 #include "../block-group.h"
41 return -1; in test_extents()
71 return -1; in test_extents()
76 return -1; in test_extents()
81 return -1; in test_extents()
111 return -1; in test_bitmaps()
133 ret = test_add_free_space_entry(cache, next_bitmap_offset - SZ_2M, in test_bitmaps()
141 ret = btrfs_remove_free_space(cache, next_bitmap_offset - SZ_1M, SZ_2M); in test_bitmaps()
143 test_err("couldn't remove overlapping space %d", ret); in test_bitmaps()
147 if (test_check_exists(cache, next_bitmap_offset - SZ_1M, SZ_2M)) { in test_bitmaps()
148 test_err("left some space when removing overlapping"); in test_bitmaps()
149 return -1; in test_bitmaps()
191 return -1; in test_bitmaps_and_extents()
197 test_err("couldn't re-add extent entry %d", ret); in test_bitmaps_and_extents()
209 return -1; in test_bitmaps_and_extents()
214 * removing an overlapping chunk. in test_bitmaps_and_extents()
224 test_err("couldn't remove overlapping space %d", ret); in test_bitmaps_and_extents()
229 test_err("left over pieces after removing overlapping"); in test_bitmaps_and_extents()
230 return -1; in test_bitmaps_and_extents()
250 test_err("problem removing overlapping space %d", ret); in test_bitmaps_and_extents()
256 return -1; in test_bitmaps_and_extents()
276 ret = test_add_free_space_entry(cache, bitmap_offset - SZ_1M, in test_bitmaps_and_extents()
291 return -1; in test_bitmaps_and_extents()
299 * to return -EAGAIN back from btrfs_remove_extent, make sure this in test_bitmaps_and_extents()
316 test_err("error removing bitmap and extent overlapping %d", ret); in test_bitmaps_and_extents()
328 return ctl->free_extents > 0; in test_use_bitmap()
337 if (cache->free_space_ctl->free_extents != num_extents) { in check_num_extents_and_bitmaps()
340 cache->free_space_ctl->free_extents, num_extents); in check_num_extents_and_bitmaps()
341 return -EINVAL; in check_num_extents_and_bitmaps()
343 if (cache->free_space_ctl->total_bitmaps != num_bitmaps) { in check_num_extents_and_bitmaps()
346 cache->free_space_ctl->total_bitmaps, num_bitmaps); in check_num_extents_and_bitmaps()
347 return -EINVAL; in check_num_extents_and_bitmaps()
362 if (cache->free_space_ctl->free_space != 0) { in check_cache_empty()
364 return -EINVAL; in check_cache_empty()
373 return -EINVAL; in check_cache_empty()
391 * from extent entries, both for clustered and non-clustered allocation
415 * with existing extent entries - the space ends up being marked in test_steal_space_from_bitmap_to_extent()
419 * cache->free_space_ctl->extents_thresh, which currently is in test_steal_space_from_bitmap_to_extent()
426 orig_free_space_ops = cache->free_space_ctl->op; in test_steal_space_from_bitmap_to_extent()
427 cache->free_space_ctl->op = &test_free_space_ops; in test_steal_space_from_bitmap_to_extent()
430 * Extent entry covering free space range [128Mb - 256Kb, 128Mb - 128Kb[ in test_steal_space_from_bitmap_to_extent()
432 ret = test_add_free_space_entry(cache, SZ_128M - SZ_256K, SZ_128K, 0); in test_steal_space_from_bitmap_to_extent()
440 SZ_128M - SZ_512K, 1); in test_steal_space_from_bitmap_to_extent()
454 * [128Mb - 256Kb, 128Mb - 128Kb[ in test_steal_space_from_bitmap_to_extent()
459 SZ_128M - 768 * SZ_1K); in test_steal_space_from_bitmap_to_extent()
466 if (!test_check_exists(cache, SZ_128M - SZ_256K, SZ_128K)) { in test_steal_space_from_bitmap_to_extent()
468 return -ENOENT; in test_steal_space_from_bitmap_to_extent()
472 return -ENOENT; in test_steal_space_from_bitmap_to_extent()
480 SZ_128M - 768 * SZ_1K)) { in test_steal_space_from_bitmap_to_extent()
482 return -EINVAL; in test_steal_space_from_bitmap_to_extent()
491 return -EINVAL; in test_steal_space_from_bitmap_to_extent()
500 return -EINVAL; in test_steal_space_from_bitmap_to_extent()
516 return -ENOENT; in test_steal_space_from_bitmap_to_extent()
548 * Now mark the region [128Mb - 128Kb, 128Mb[ as free too. This will in test_steal_space_from_bitmap_to_extent()
550 * the free space [128Mb - 256Kb, 128Mb - 128Kb[. in test_steal_space_from_bitmap_to_extent()
552 ret = btrfs_add_free_space(cache, SZ_128M - SZ_128K, SZ_128K); in test_steal_space_from_bitmap_to_extent()
558 if (!test_check_exists(cache, SZ_128M - SZ_128K, SZ_128K)) { in test_steal_space_from_bitmap_to_extent()
560 return -ENOENT; in test_steal_space_from_bitmap_to_extent()
572 * So now we have the range [128Mb - 256Kb, 128Mb + 768Kb[ as free in test_steal_space_from_bitmap_to_extent()
577 * extent entry covering range: [128Mb - 256Kb, 128Mb[ in test_steal_space_from_bitmap_to_extent()
586 if (!test_check_exists(cache, SZ_128M - SZ_256K, SZ_1M)) { in test_steal_space_from_bitmap_to_extent()
588 return -ENOENT; in test_steal_space_from_bitmap_to_extent()
591 if (cache->free_space_ctl->free_space != (SZ_1M + sectorsize)) { in test_steal_space_from_bitmap_to_extent()
593 return -EINVAL; in test_steal_space_from_bitmap_to_extent()
599 if (offset != (SZ_128M - SZ_256K)) { in test_steal_space_from_bitmap_to_extent()
603 return -EINVAL; in test_steal_space_from_bitmap_to_extent()
614 if (cache->free_space_ctl->free_space != sectorsize) { in test_steal_space_from_bitmap_to_extent()
616 return -EINVAL; in test_steal_space_from_bitmap_to_extent()
625 return -EINVAL; in test_steal_space_from_bitmap_to_extent()
649 /* Bitmap entry covering free space range [0, 128Mb - 512Kb[ */ in test_steal_space_from_bitmap_to_extent()
650 ret = test_add_free_space_entry(cache, 0, SZ_128M - SZ_512K, 1); in test_steal_space_from_bitmap_to_extent()
665 * [128Mb - 768Kb, 128Mb - 512Kb[ in test_steal_space_from_bitmap_to_extent()
667 ret = btrfs_remove_free_space(cache, 0, SZ_128M - 768 * SZ_1K); in test_steal_space_from_bitmap_to_extent()
676 return -ENOENT; in test_steal_space_from_bitmap_to_extent()
678 if (!test_check_exists(cache, SZ_128M - 768 * SZ_1K, SZ_256K)) { in test_steal_space_from_bitmap_to_extent()
680 return -ENOENT; in test_steal_space_from_bitmap_to_extent()
684 * Confirm that the bitmap range [0, 128Mb - 768Kb[ isn't marked in test_steal_space_from_bitmap_to_extent()
687 if (test_check_exists(cache, 0, SZ_128M - 768 * SZ_1K)) { in test_steal_space_from_bitmap_to_extent()
689 return -EINVAL; in test_steal_space_from_bitmap_to_extent()
693 * Confirm that the region [128Mb - 512Kb, 128Mb[, which is in test_steal_space_from_bitmap_to_extent()
696 if (test_check_exists(cache, SZ_128M - SZ_512K, SZ_512K)) { in test_steal_space_from_bitmap_to_extent()
698 return -EINVAL; in test_steal_space_from_bitmap_to_extent()
702 * Now lets mark the region [128Mb - 512Kb, 128Mb[ as free too. But, in test_steal_space_from_bitmap_to_extent()
706 ret = btrfs_add_free_space(cache, SZ_128M - SZ_512K, SZ_512K); in test_steal_space_from_bitmap_to_extent()
712 if (!test_check_exists(cache, SZ_128M - SZ_512K, SZ_512K)) { in test_steal_space_from_bitmap_to_extent()
714 return -ENOENT; in test_steal_space_from_bitmap_to_extent()
750 return -ENOENT; in test_steal_space_from_bitmap_to_extent()
762 * So now we have the range [128Mb - 768Kb, 128Mb + 256Kb[ as free in test_steal_space_from_bitmap_to_extent()
768 * bitmap entry covering range: [128Mb - 768Kb, 128Mb[ in test_steal_space_from_bitmap_to_extent()
776 if (!test_check_exists(cache, SZ_128M - 768 * SZ_1K, SZ_1M)) { in test_steal_space_from_bitmap_to_extent()
778 return -ENOENT; in test_steal_space_from_bitmap_to_extent()
781 if (cache->free_space_ctl->free_space != (SZ_1M + 2 * sectorsize)) { in test_steal_space_from_bitmap_to_extent()
783 return -EINVAL; in test_steal_space_from_bitmap_to_extent()
788 if (offset != (SZ_128M - 768 * SZ_1K)) { in test_steal_space_from_bitmap_to_extent()
792 return -EINVAL; in test_steal_space_from_bitmap_to_extent()
803 if (cache->free_space_ctl->free_space != 2 * sectorsize) { in test_steal_space_from_bitmap_to_extent()
805 return -EINVAL; in test_steal_space_from_bitmap_to_extent()
814 return -EINVAL; in test_steal_space_from_bitmap_to_extent()
821 cache->free_space_ctl->op = orig_free_space_ops; in test_steal_space_from_bitmap_to_extent()
839 struct btrfs_free_space_ctl *ctl = cache->free_space_ctl; in test_bytes_index()
859 for (node = rb_first_cached(&ctl->free_space_bytes), i = 9; node; in test_bytes_index()
860 node = rb_next(node), i--) { in test_bytes_index()
863 if (entry->bytes != bytes) { in test_bytes_index()
865 entry->bytes, bytes); in test_bytes_index()
866 return -EINVAL; in test_bytes_index()
882 for (node = rb_first_cached(&ctl->free_space_bytes), i = 1; node; in test_bytes_index()
883 node = rb_next(node), i--) { in test_bytes_index()
886 if (entry->bytes != bytes) { in test_bytes_index()
888 entry->bytes, bytes); in test_bytes_index()
889 return -EINVAL; in test_bytes_index()
893 /* Now validate bitmaps with different ->max_extent_size. */ in test_bytes_index()
895 orig_free_space_ops = cache->free_space_ctl->op; in test_bytes_index()
896 cache->free_space_ctl->op = &test_free_space_ops; in test_bytes_index()
913 * ->bytes is large. in test_bytes_index()
926 * ->max_extent_size is larger than the first bitmaps. in test_bytes_index()
936 * Since we don't set ->max_extent_size unless we search everything in test_bytes_index()
939 entry = rb_entry(rb_first_cached(&ctl->free_space_bytes), in test_bytes_index()
941 if (entry->bytes != (10 * sectorsize)) { in test_bytes_index()
943 return -EINVAL; in test_bytes_index()
947 offset = btrfs_find_space_for_alloc(cache, cache->start, sectorsize * 3, in test_bytes_index()
951 return -EINVAL; in test_bytes_index()
957 return -EINVAL; in test_bytes_index()
961 * The search should have re-arranged the bytes index to use the in test_bytes_index()
962 * ->max_extent_size, validate it's now what we expect it to be. in test_bytes_index()
964 entry = rb_entry(rb_first_cached(&ctl->free_space_bytes), in test_bytes_index()
966 if (entry->bytes != (2 * sectorsize)) { in test_bytes_index()
968 return -EINVAL; in test_bytes_index()
971 /* Add another sectorsize to re-arrange the tree back to ->bytes. */ in test_bytes_index()
972 offset = (BITS_PER_BITMAP * sectorsize) - sectorsize; in test_bytes_index()
979 entry = rb_entry(rb_first_cached(&ctl->free_space_bytes), in test_bytes_index()
981 if (entry->bytes != (11 * sectorsize)) { in test_bytes_index()
983 return -EINVAL; in test_bytes_index()
988 * result in a re-arranging of the tree. in test_bytes_index()
991 offset = btrfs_find_space_for_alloc(cache, cache->start, sectorsize * 2, in test_bytes_index()
997 return -EINVAL; in test_bytes_index()
1000 cache->free_space_ctl->op = orig_free_space_ops; in test_bytes_index()
1010 int ret = -ENOMEM; in btrfs_test_free_space_cache()
1016 return -ENOMEM; in btrfs_test_free_space_cache()
1039 root->root_key.objectid = BTRFS_EXTENT_TREE_OBJECTID; in btrfs_test_free_space_cache()
1040 root->root_key.type = BTRFS_ROOT_ITEM_KEY; in btrfs_test_free_space_cache()
1041 root->root_key.offset = 0; in btrfs_test_free_space_cache()