diff options
Diffstat (limited to 'fs/btrfs/tests/extent-io-tests.c')
-rw-r--r-- | fs/btrfs/tests/extent-io-tests.c | 86 |
1 files changed, 54 insertions, 32 deletions
diff --git a/fs/btrfs/tests/extent-io-tests.c b/fs/btrfs/tests/extent-io-tests.c index 55724607f79b..d19ab0317283 100644 --- a/fs/btrfs/tests/extent-io-tests.c +++ b/fs/btrfs/tests/extent-io-tests.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/slab.h> | 21 | #include <linux/slab.h> |
22 | #include <linux/sizes.h> | 22 | #include <linux/sizes.h> |
23 | #include "btrfs-tests.h" | 23 | #include "btrfs-tests.h" |
24 | #include "../ctree.h" | ||
24 | #include "../extent_io.h" | 25 | #include "../extent_io.h" |
25 | 26 | ||
26 | #define PROCESS_UNLOCK (1 << 0) | 27 | #define PROCESS_UNLOCK (1 << 0) |
@@ -65,7 +66,7 @@ static noinline int process_page_range(struct inode *inode, u64 start, u64 end, | |||
65 | return count; | 66 | return count; |
66 | } | 67 | } |
67 | 68 | ||
68 | static int test_find_delalloc(void) | 69 | static int test_find_delalloc(u32 sectorsize) |
69 | { | 70 | { |
70 | struct inode *inode; | 71 | struct inode *inode; |
71 | struct extent_io_tree tmp; | 72 | struct extent_io_tree tmp; |
@@ -113,7 +114,7 @@ static int test_find_delalloc(void) | |||
113 | * |--- delalloc ---| | 114 | * |--- delalloc ---| |
114 | * |--- search ---| | 115 | * |--- search ---| |
115 | */ | 116 | */ |
116 | set_extent_delalloc(&tmp, 0, 4095, NULL); | 117 | set_extent_delalloc(&tmp, 0, sectorsize - 1, NULL); |
117 | start = 0; | 118 | start = 0; |
118 | end = 0; | 119 | end = 0; |
119 | found = find_lock_delalloc_range(inode, &tmp, locked_page, &start, | 120 | found = find_lock_delalloc_range(inode, &tmp, locked_page, &start, |
@@ -122,9 +123,9 @@ static int test_find_delalloc(void) | |||
122 | test_msg("Should have found at least one delalloc\n"); | 123 | test_msg("Should have found at least one delalloc\n"); |
123 | goto out_bits; | 124 | goto out_bits; |
124 | } | 125 | } |
125 | if (start != 0 || end != 4095) { | 126 | if (start != 0 || end != (sectorsize - 1)) { |
126 | test_msg("Expected start 0 end 4095, got start %Lu end %Lu\n", | 127 | test_msg("Expected start 0 end %u, got start %llu end %llu\n", |
127 | start, end); | 128 | sectorsize - 1, start, end); |
128 | goto out_bits; | 129 | goto out_bits; |
129 | } | 130 | } |
130 | unlock_extent(&tmp, start, end); | 131 | unlock_extent(&tmp, start, end); |
@@ -144,7 +145,7 @@ static int test_find_delalloc(void) | |||
144 | test_msg("Couldn't find the locked page\n"); | 145 | test_msg("Couldn't find the locked page\n"); |
145 | goto out_bits; | 146 | goto out_bits; |
146 | } | 147 | } |
147 | set_extent_delalloc(&tmp, 4096, max_bytes - 1, NULL); | 148 | set_extent_delalloc(&tmp, sectorsize, max_bytes - 1, NULL); |
148 | start = test_start; | 149 | start = test_start; |
149 | end = 0; | 150 | end = 0; |
150 | found = find_lock_delalloc_range(inode, &tmp, locked_page, &start, | 151 | found = find_lock_delalloc_range(inode, &tmp, locked_page, &start, |
@@ -172,7 +173,7 @@ static int test_find_delalloc(void) | |||
172 | * |--- delalloc ---| | 173 | * |--- delalloc ---| |
173 | * |--- search ---| | 174 | * |--- search ---| |
174 | */ | 175 | */ |
175 | test_start = max_bytes + 4096; | 176 | test_start = max_bytes + sectorsize; |
176 | locked_page = find_lock_page(inode->i_mapping, test_start >> | 177 | locked_page = find_lock_page(inode->i_mapping, test_start >> |
177 | PAGE_SHIFT); | 178 | PAGE_SHIFT); |
178 | if (!locked_page) { | 179 | if (!locked_page) { |
@@ -272,6 +273,16 @@ out: | |||
272 | return ret; | 273 | return ret; |
273 | } | 274 | } |
274 | 275 | ||
276 | /** | ||
277 | * test_bit_in_byte - Determine whether a bit is set in a byte | ||
278 | * @nr: bit number to test | ||
279 | * @addr: Address to start counting from | ||
280 | */ | ||
281 | static inline int test_bit_in_byte(int nr, const u8 *addr) | ||
282 | { | ||
283 | return 1UL & (addr[nr / BITS_PER_BYTE] >> (nr & (BITS_PER_BYTE - 1))); | ||
284 | } | ||
285 | |||
275 | static int __test_eb_bitmaps(unsigned long *bitmap, struct extent_buffer *eb, | 286 | static int __test_eb_bitmaps(unsigned long *bitmap, struct extent_buffer *eb, |
276 | unsigned long len) | 287 | unsigned long len) |
277 | { | 288 | { |
@@ -298,25 +309,29 @@ static int __test_eb_bitmaps(unsigned long *bitmap, struct extent_buffer *eb, | |||
298 | return -EINVAL; | 309 | return -EINVAL; |
299 | } | 310 | } |
300 | 311 | ||
301 | bitmap_set(bitmap, (PAGE_SIZE - sizeof(long) / 2) * BITS_PER_BYTE, | 312 | /* Straddling pages test */ |
302 | sizeof(long) * BITS_PER_BYTE); | 313 | if (len > PAGE_SIZE) { |
303 | extent_buffer_bitmap_set(eb, PAGE_SIZE - sizeof(long) / 2, 0, | 314 | bitmap_set(bitmap, |
304 | sizeof(long) * BITS_PER_BYTE); | 315 | (PAGE_SIZE - sizeof(long) / 2) * BITS_PER_BYTE, |
305 | if (memcmp_extent_buffer(eb, bitmap, 0, len) != 0) { | 316 | sizeof(long) * BITS_PER_BYTE); |
306 | test_msg("Setting straddling pages failed\n"); | 317 | extent_buffer_bitmap_set(eb, PAGE_SIZE - sizeof(long) / 2, 0, |
307 | return -EINVAL; | 318 | sizeof(long) * BITS_PER_BYTE); |
308 | } | 319 | if (memcmp_extent_buffer(eb, bitmap, 0, len) != 0) { |
320 | test_msg("Setting straddling pages failed\n"); | ||
321 | return -EINVAL; | ||
322 | } | ||
309 | 323 | ||
310 | bitmap_set(bitmap, 0, len * BITS_PER_BYTE); | 324 | bitmap_set(bitmap, 0, len * BITS_PER_BYTE); |
311 | bitmap_clear(bitmap, | 325 | bitmap_clear(bitmap, |
312 | (PAGE_SIZE - sizeof(long) / 2) * BITS_PER_BYTE, | 326 | (PAGE_SIZE - sizeof(long) / 2) * BITS_PER_BYTE, |
313 | sizeof(long) * BITS_PER_BYTE); | 327 | sizeof(long) * BITS_PER_BYTE); |
314 | extent_buffer_bitmap_set(eb, 0, 0, len * BITS_PER_BYTE); | 328 | extent_buffer_bitmap_set(eb, 0, 0, len * BITS_PER_BYTE); |
315 | extent_buffer_bitmap_clear(eb, PAGE_SIZE - sizeof(long) / 2, 0, | 329 | extent_buffer_bitmap_clear(eb, PAGE_SIZE - sizeof(long) / 2, 0, |
316 | sizeof(long) * BITS_PER_BYTE); | 330 | sizeof(long) * BITS_PER_BYTE); |
317 | if (memcmp_extent_buffer(eb, bitmap, 0, len) != 0) { | 331 | if (memcmp_extent_buffer(eb, bitmap, 0, len) != 0) { |
318 | test_msg("Clearing straddling pages failed\n"); | 332 | test_msg("Clearing straddling pages failed\n"); |
319 | return -EINVAL; | 333 | return -EINVAL; |
334 | } | ||
320 | } | 335 | } |
321 | 336 | ||
322 | /* | 337 | /* |
@@ -333,7 +348,7 @@ static int __test_eb_bitmaps(unsigned long *bitmap, struct extent_buffer *eb, | |||
333 | for (i = 0; i < len * BITS_PER_BYTE; i++) { | 348 | for (i = 0; i < len * BITS_PER_BYTE; i++) { |
334 | int bit, bit1; | 349 | int bit, bit1; |
335 | 350 | ||
336 | bit = !!test_bit(i, bitmap); | 351 | bit = !!test_bit_in_byte(i, (u8 *)bitmap); |
337 | bit1 = !!extent_buffer_test_bit(eb, 0, i); | 352 | bit1 = !!extent_buffer_test_bit(eb, 0, i); |
338 | if (bit1 != bit) { | 353 | if (bit1 != bit) { |
339 | test_msg("Testing bit pattern failed\n"); | 354 | test_msg("Testing bit pattern failed\n"); |
@@ -351,15 +366,22 @@ static int __test_eb_bitmaps(unsigned long *bitmap, struct extent_buffer *eb, | |||
351 | return 0; | 366 | return 0; |
352 | } | 367 | } |
353 | 368 | ||
354 | static int test_eb_bitmaps(void) | 369 | static int test_eb_bitmaps(u32 sectorsize, u32 nodesize) |
355 | { | 370 | { |
356 | unsigned long len = PAGE_SIZE * 4; | 371 | unsigned long len; |
357 | unsigned long *bitmap; | 372 | unsigned long *bitmap; |
358 | struct extent_buffer *eb; | 373 | struct extent_buffer *eb; |
359 | int ret; | 374 | int ret; |
360 | 375 | ||
361 | test_msg("Running extent buffer bitmap tests\n"); | 376 | test_msg("Running extent buffer bitmap tests\n"); |
362 | 377 | ||
378 | /* | ||
379 | * In ppc64, sectorsize can be 64K, thus 4 * 64K will be larger than | ||
380 | * BTRFS_MAX_METADATA_BLOCKSIZE. | ||
381 | */ | ||
382 | len = (sectorsize < BTRFS_MAX_METADATA_BLOCKSIZE) | ||
383 | ? sectorsize * 4 : sectorsize; | ||
384 | |||
363 | bitmap = kmalloc(len, GFP_KERNEL); | 385 | bitmap = kmalloc(len, GFP_KERNEL); |
364 | if (!bitmap) { | 386 | if (!bitmap) { |
365 | test_msg("Couldn't allocate test bitmap\n"); | 387 | test_msg("Couldn't allocate test bitmap\n"); |
@@ -379,7 +401,7 @@ static int test_eb_bitmaps(void) | |||
379 | 401 | ||
380 | /* Do it over again with an extent buffer which isn't page-aligned. */ | 402 | /* Do it over again with an extent buffer which isn't page-aligned. */ |
381 | free_extent_buffer(eb); | 403 | free_extent_buffer(eb); |
382 | eb = __alloc_dummy_extent_buffer(NULL, PAGE_SIZE / 2, len); | 404 | eb = __alloc_dummy_extent_buffer(NULL, nodesize / 2, len); |
383 | if (!eb) { | 405 | if (!eb) { |
384 | test_msg("Couldn't allocate test extent buffer\n"); | 406 | test_msg("Couldn't allocate test extent buffer\n"); |
385 | kfree(bitmap); | 407 | kfree(bitmap); |
@@ -393,17 +415,17 @@ out: | |||
393 | return ret; | 415 | return ret; |
394 | } | 416 | } |
395 | 417 | ||
396 | int btrfs_test_extent_io(void) | 418 | int btrfs_test_extent_io(u32 sectorsize, u32 nodesize) |
397 | { | 419 | { |
398 | int ret; | 420 | int ret; |
399 | 421 | ||
400 | test_msg("Running extent I/O tests\n"); | 422 | test_msg("Running extent I/O tests\n"); |
401 | 423 | ||
402 | ret = test_find_delalloc(); | 424 | ret = test_find_delalloc(sectorsize); |
403 | if (ret) | 425 | if (ret) |
404 | goto out; | 426 | goto out; |
405 | 427 | ||
406 | ret = test_eb_bitmaps(); | 428 | ret = test_eb_bitmaps(sectorsize, nodesize); |
407 | out: | 429 | out: |
408 | test_msg("Extent I/O tests finished\n"); | 430 | test_msg("Extent I/O tests finished\n"); |
409 | return ret; | 431 | return ret; |