Skip to content

Commit 675a4fc

Browse files
josefbacikkdave
authored andcommitted
btrfs: tests: initialize test inodes location
I noticed that sometimes the module failed to load because the self tests failed like this: BTRFS: selftest: fs/btrfs/tests/inode-tests.c:963 miscount, wanted 1, got 0 This turned out to be because sometimes the btrfs ino would be the btree inode number, and thus we'd skip calling the set extent delalloc bit helper, and thus not adjust ->outstanding_extents. Fix this by making sure we initialize test inodes with a valid inode number so that we don't get random failures during self tests. Signed-off-by: Josef Bacik <josef@toxicpanda.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 0b3f407 commit 675a4fc

2 files changed

Lines changed: 8 additions & 11 deletions

File tree

fs/btrfs/tests/btrfs-tests.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,14 @@ struct inode *btrfs_new_test_inode(void)
5555
struct inode *inode;
5656

5757
inode = new_inode(test_mnt->mnt_sb);
58-
if (inode)
59-
inode_init_owner(inode, NULL, S_IFREG);
58+
if (!inode)
59+
return NULL;
60+
61+
inode->i_mode = S_IFREG;
62+
BTRFS_I(inode)->location.type = BTRFS_INODE_ITEM_KEY;
63+
BTRFS_I(inode)->location.objectid = BTRFS_FIRST_FREE_OBJECTID;
64+
BTRFS_I(inode)->location.offset = 0;
65+
inode_init_owner(inode, NULL, S_IFREG);
6066

6167
return inode;
6268
}

fs/btrfs/tests/inode-tests.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,6 @@ static noinline int test_btrfs_get_extent(u32 sectorsize, u32 nodesize)
232232
return ret;
233233
}
234234

235-
inode->i_mode = S_IFREG;
236-
BTRFS_I(inode)->location.type = BTRFS_INODE_ITEM_KEY;
237-
BTRFS_I(inode)->location.objectid = BTRFS_FIRST_FREE_OBJECTID;
238-
BTRFS_I(inode)->location.offset = 0;
239-
240235
fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize);
241236
if (!fs_info) {
242237
test_std_err(TEST_ALLOC_FS_INFO);
@@ -835,10 +830,6 @@ static int test_hole_first(u32 sectorsize, u32 nodesize)
835830
return ret;
836831
}
837832

838-
BTRFS_I(inode)->location.type = BTRFS_INODE_ITEM_KEY;
839-
BTRFS_I(inode)->location.objectid = BTRFS_FIRST_FREE_OBJECTID;
840-
BTRFS_I(inode)->location.offset = 0;
841-
842833
fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize);
843834
if (!fs_info) {
844835
test_std_err(TEST_ALLOC_FS_INFO);

0 commit comments

Comments
 (0)