]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
btrfs: tests: initialize test inodes location
authorJosef Bacik <josef@toxicpanda.com>
Tue, 15 Dec 2020 17:00:26 +0000 (12:00 -0500)
committerDavid Sterba <dsterba@suse.com>
Fri, 18 Dec 2020 13:59:49 +0000 (14:59 +0100)
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>
fs/btrfs/tests/btrfs-tests.c
fs/btrfs/tests/inode-tests.c

index 8ca334d554afb9cef5539d1a94af71d2468ac36c..6bd97bd4cb37114720393f252202844dd9653593 100644 (file)
@@ -55,8 +55,14 @@ struct inode *btrfs_new_test_inode(void)
        struct inode *inode;
 
        inode = new_inode(test_mnt->mnt_sb);
-       if (inode)
-               inode_init_owner(inode, NULL, S_IFREG);
+       if (!inode)
+               return NULL;
+
+       inode->i_mode = S_IFREG;
+       BTRFS_I(inode)->location.type = BTRFS_INODE_ITEM_KEY;
+       BTRFS_I(inode)->location.objectid = BTRFS_FIRST_FREE_OBJECTID;
+       BTRFS_I(inode)->location.offset = 0;
+       inode_init_owner(inode, NULL, S_IFREG);
 
        return inode;
 }
index 04022069761deb90a2651d9eed9a94469268eb92..c9874b12d337c7e8323584178b0ce55b321fe34e 100644 (file)
@@ -232,11 +232,6 @@ static noinline int test_btrfs_get_extent(u32 sectorsize, u32 nodesize)
                return ret;
        }
 
-       inode->i_mode = S_IFREG;
-       BTRFS_I(inode)->location.type = BTRFS_INODE_ITEM_KEY;
-       BTRFS_I(inode)->location.objectid = BTRFS_FIRST_FREE_OBJECTID;
-       BTRFS_I(inode)->location.offset = 0;
-
        fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize);
        if (!fs_info) {
                test_std_err(TEST_ALLOC_FS_INFO);
@@ -835,10 +830,6 @@ static int test_hole_first(u32 sectorsize, u32 nodesize)
                return ret;
        }
 
-       BTRFS_I(inode)->location.type = BTRFS_INODE_ITEM_KEY;
-       BTRFS_I(inode)->location.objectid = BTRFS_FIRST_FREE_OBJECTID;
-       BTRFS_I(inode)->location.offset = 0;
-
        fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize);
        if (!fs_info) {
                test_std_err(TEST_ALLOC_FS_INFO);