btrfs: use a runtime flag to indicate an inode is a free space inode
authorJosef Bacik <josef@toxicpanda.com>
Wed, 14 Sep 2022 23:04:50 +0000 (19:04 -0400)
committerDavid Sterba <dsterba@suse.com>
Mon, 26 Sep 2022 10:28:07 +0000 (12:28 +0200)
We always check the root of an inode as well as it's inode number to
determine if it's a free space inode.  This is problematic as the helper
is in a header file where it doesn't have the fs_info definition.  To
avoid this and make the check a little cleaner simply add a flag to the
runtime_flags to indicate that the inode is a free space inode, set that
when we create the inode, and then change the helper to check for this
flag.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Anand Jain <anand.jain@oracle.com>
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/btrfs_inode.h
fs/btrfs/inode.c

index 0cbdee9d93a7910a5bea2523fda018119440da35..54c2ccb36b61253f4a9f4745ebd257da0a3b5e87 100644 (file)
@@ -65,6 +65,8 @@ enum {
         * on the same file.
         */
        BTRFS_INODE_VERITY_IN_PROGRESS,
+       /* Set when this inode is a free space inode. */
+       BTRFS_INODE_FREE_SPACE_INODE,
 };
 
 /* in memory btrfs inode */
@@ -301,13 +303,7 @@ static inline void btrfs_i_size_write(struct btrfs_inode *inode, u64 size)
 
 static inline bool btrfs_is_free_space_inode(struct btrfs_inode *inode)
 {
-       struct btrfs_root *root = inode->root;
-
-       if (root == root->fs_info->tree_root &&
-           btrfs_ino(inode) != BTRFS_BTREE_INODE_OBJECTID)
-               return true;
-
-       return false;
+       return test_bit(BTRFS_INODE_FREE_SPACE_INODE, &inode->runtime_flags);
 }
 
 static inline bool is_data_inode(struct inode *inode)
index feccb36eb919f71d249e88545676b44bd9c66130..30b6c1eaa89f4fd6528d26d7f11bb176bf763e4d 100644 (file)
@@ -5707,6 +5707,11 @@ static int btrfs_init_locked_inode(struct inode *inode, void *p)
        BTRFS_I(inode)->location.offset = 0;
        BTRFS_I(inode)->root = btrfs_grab_root(args->root);
        BUG_ON(args->root && !BTRFS_I(inode)->root);
+
+       if (args->root && args->root == args->root->fs_info->tree_root &&
+           args->ino != BTRFS_BTREE_INODE_OBJECTID)
+               set_bit(BTRFS_INODE_FREE_SPACE_INODE,
+                       &BTRFS_I(inode)->runtime_flags);
        return 0;
 }