Skip to content

Commit 294e30f

Browse files
Josef BacikChris Mason
authored andcommitted
Btrfs: add tests for find_lock_delalloc_range
So both Liu and I made huge messes of find_lock_delalloc_range trying to fix stuff, me first by fixing extent size, then him by fixing something I broke and then me again telling him to fix it a different way. So this is obviously a candidate for some testing. This patch adds a pseudo fs so we can allocate fake inodes for tests that need an inode or pages. Then it addes a bunch of tests to make sure find_lock_delalloc_range is acting the way it is supposed to. With this patch and all of our previous patches to find_lock_delalloc_range I am sure it is working as expected now. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
1 parent 857cc2f commit 294e30f

File tree

9 files changed

+389
-9
lines changed

9 files changed

+389
-9
lines changed

fs/btrfs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ btrfs-$(CONFIG_BTRFS_FS_POSIX_ACL) += acl.o
1515
btrfs-$(CONFIG_BTRFS_FS_CHECK_INTEGRITY) += check-integrity.o
1616

1717
btrfs-$(CONFIG_BTRFS_FS_RUN_SANITY_TESTS) += tests/free-space-tests.o \
18-
tests/extent-buffer-tests.o
18+
tests/extent-buffer-tests.o tests/btrfs-tests.o tests/extent-io-tests.o

fs/btrfs/ctree.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ extern struct kmem_cache *btrfs_path_cachep;
4747
extern struct kmem_cache *btrfs_free_space_cachep;
4848
struct btrfs_ordered_sum;
4949

50+
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
51+
#define STATIC noinline
52+
#else
53+
#define STATIC static noinline
54+
#endif
55+
5056
#define BTRFS_MAGIC 0x4D5F53665248425FULL /* ascii _BHRfS_M, no null */
5157

5258
#define BTRFS_MAX_MIRRORS 3

fs/btrfs/extent_io.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,11 +1598,10 @@ static noinline int lock_delalloc_pages(struct inode *inode,
15981598
*
15991599
* 1 is returned if we find something, 0 if nothing was in the tree
16001600
*/
1601-
static noinline u64 find_lock_delalloc_range(struct inode *inode,
1602-
struct extent_io_tree *tree,
1603-
struct page *locked_page,
1604-
u64 *start, u64 *end,
1605-
u64 max_bytes)
1601+
STATIC u64 find_lock_delalloc_range(struct inode *inode,
1602+
struct extent_io_tree *tree,
1603+
struct page *locked_page, u64 *start,
1604+
u64 *end, u64 max_bytes)
16061605
{
16071606
u64 delalloc_start;
16081607
u64 delalloc_end;

fs/btrfs/extent_io.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,4 +345,10 @@ int repair_io_failure(struct btrfs_fs_info *fs_info, u64 start,
345345
int end_extent_writepage(struct page *page, int err, u64 start, u64 end);
346346
int repair_eb_io_failure(struct btrfs_root *root, struct extent_buffer *eb,
347347
int mirror_num);
348+
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
349+
noinline u64 find_lock_delalloc_range(struct inode *inode,
350+
struct extent_io_tree *tree,
351+
struct page *locked_page, u64 *start,
352+
u64 *end, u64 max_bytes);
353+
#endif
348354
#endif

fs/btrfs/super.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,10 +1791,20 @@ static int btrfs_run_sanity_tests(void)
17911791
{
17921792
int ret;
17931793

1794-
ret = btrfs_test_free_space_cache();
1794+
ret = btrfs_init_test_fs();
17951795
if (ret)
17961796
return ret;
1797-
return btrfs_test_extent_buffer_operations();
1797+
1798+
ret = btrfs_test_free_space_cache();
1799+
if (ret)
1800+
goto out;
1801+
ret = btrfs_test_extent_buffer_operations();
1802+
if (ret)
1803+
goto out;
1804+
ret = btrfs_test_extent_io();
1805+
out:
1806+
btrfs_destroy_test_fs();
1807+
return ret;
17981808
}
17991809

18001810
static int __init init_btrfs_fs(void)

fs/btrfs/tests/btrfs-tests.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (C) 2013 Fusion IO. All rights reserved.
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public
6+
* License v2 as published by the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
* General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public
14+
* License along with this program; if not, write to the
15+
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16+
* Boston, MA 021110-1307, USA.
17+
*/
18+
19+
#include <linux/fs.h>
20+
#include <linux/mount.h>
21+
#include <linux/magic.h>
22+
#include "btrfs-tests.h"
23+
#include "../ctree.h"
24+
25+
static struct vfsmount *test_mnt = NULL;
26+
27+
static struct dentry *btrfs_test_mount(struct file_system_type *fs_type,
28+
int flags, const char *dev_name,
29+
void *data)
30+
{
31+
return mount_pseudo(fs_type, "btrfs_test:", NULL, NULL, BTRFS_TEST_MAGIC);
32+
}
33+
34+
static struct file_system_type test_type = {
35+
.name = "btrfs_test_fs",
36+
.mount = btrfs_test_mount,
37+
.kill_sb = kill_anon_super,
38+
};
39+
40+
struct inode *btrfs_new_test_inode(void)
41+
{
42+
return new_inode(test_mnt->mnt_sb);
43+
}
44+
45+
int btrfs_init_test_fs(void)
46+
{
47+
int ret;
48+
49+
ret = register_filesystem(&test_type);
50+
if (ret) {
51+
printk(KERN_ERR "btrfs: cannot register test file system\n");
52+
return ret;
53+
}
54+
55+
test_mnt = kern_mount(&test_type);
56+
if (IS_ERR(test_mnt)) {
57+
printk(KERN_ERR "btrfs: cannot mount test file system\n");
58+
unregister_filesystem(&test_type);
59+
return ret;
60+
}
61+
return 0;
62+
}
63+
64+
void btrfs_destroy_test_fs(void)
65+
{
66+
kern_unmount(test_mnt);
67+
unregister_filesystem(&test_type);
68+
}

fs/btrfs/tests/btrfs-tests.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525

2626
int btrfs_test_free_space_cache(void);
2727
int btrfs_test_extent_buffer_operations(void);
28+
int btrfs_test_extent_io(void);
29+
int btrfs_init_test_fs(void);
30+
void btrfs_destroy_test_fs(void);
31+
struct inode *btrfs_new_test_inode(void);
2832
#else
2933
static inline int btrfs_test_free_space_cache(void)
3034
{
@@ -34,6 +38,17 @@ static inline int btrfs_test_extent_buffer_operations(void)
3438
{
3539
return 0;
3640
}
41+
static inline int btrfs_init_test_fs(void)
42+
{
43+
return 0;
44+
}
45+
static inline void btrfs_destroy_test_fs(void)
46+
{
47+
}
48+
static inline int btrfs_test_extent_io(void)
49+
{
50+
return 0;
51+
}
3752
#endif
3853

3954
#endif

0 commit comments

Comments
 (0)