Skip to contentSkip to conversation

btrfs: init file_extent_tree after i_mode has been set

PATCH Superseded austinchang 2 participants 2 messages Sep 5, 2025 – Sep 9, 2025 Btrfs file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: init file_extent_tree after i_mode has been set

btrfs_init_file_extent_tree uses S_ISREG() to determine if the file is a regular file. In the beginning of btrfs_read_locked_inode(), the i_mode hasn't been read from inode item, then file_extent_tree won't be used at all in volumes without NO_HOLES.

This patch is based on version 6.17-rc4. It moves the initialization to where i_mode has been set and before the first time file_extent_tree is used(btrfs_inode_set_file_extent_range).

---
 fs/btrfs/inode.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
fs/btrfs/inode.c +5 -4
index 9e4aec733..5731cd296 100644
@@ -3885,10 +3885,6 @@ static int btrfs_read_locked_inode(struct btrfs_inode *inode, struct btrfs_path
 	bool filled = false;
 	int first_xattr_slot;
 
-	ret = btrfs_init_file_extent_tree(inode);
-	if (ret)
-		goto out;
-
 	ret = btrfs_fill_inode(inode, &rdev);
 	if (!ret)
 		filled = true;
@@ -3919,6 +3915,11 @@ static int btrfs_read_locked_inode(struct btrfs_inode *inode, struct btrfs_path
 	set_nlink(vfs_inode, btrfs_inode_nlink(leaf, inode_item));
 	i_uid_write(vfs_inode, btrfs_inode_uid(leaf, inode_item));
 	i_gid_write(vfs_inode, btrfs_inode_gid(leaf, inode_item));
+
+	ret = btrfs_init_file_extent_tree(inode);
+	if (ret)
+		goto out;
+
 	btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
 	btrfs_inode_set_file_extent_range(inode, 0,
 			round_up(i_size_read(vfs_inode), fs_info->sectorsize));
Signature · 4 lines
2.34.1


Disclaimer: The contents of this e-mail message and any attachments are confidential and are intended solely for addressee. The information may also be legally privileged. This transmission is sent in trust, for the sole purpose of delivery to the intended recipient. If you have received this transmission in error, any use, reproduction or dissemination of this transmission is strictly prohibited. If you are not the intended recipient, please immediately notify the sender by reply e-mail or phone and delete this message and its attachments, if any.
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · austinchang

btrfs_init_file_extent_tree uses S_ISREG() to determine if the file is a

Please use () after a function name, not only makes it more clear, it's also more consistent with what we do and what you did below.

Quoted 1 line

regular file. In the beginning of btrfs_read_locked_inode(), the i_mode

Here you placed the ().

Quoted 4 lines

hasn't been read from inode item, then file_extent_tree won't be used at all in volumes without NO_HOLES.

This patch is based on version 6.17-rc4.

There's no need to mention on which version it's based, it's useless to have this in the changelog.
If there's really a need for that, place it under --- below so that it's not included.

Quoted 3 lines

It moves the initialization to
where i_mode has been set and before the first time file_extent_tree is used(btrfs_inode_set_file_extent_range).

I have replaced this paragraph with:

Fix this by calling btrfs_init_file_extent_tree() after i_mode is initialized in btrfs_read_locked_inode().

Quoted 2 lines

I've pushed the patch to github's for-next branch and made those corrections and added a Fixes tag.

Thanks.

Quoted 37 lines
---
 fs/btrfs/inode.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
fs/btrfs/inode.c +5 -5
index 9e4aec733..5731cd296 100644
@@ -3885,10 +3885,6 @@ static int btrfs_read_locked_inode(struct btrfs_inode *inode, struct btrfs_path
        bool filled = false;
        int first_xattr_slot;
 
-       ret = btrfs_init_file_extent_tree(inode);
-       if (ret)
-               goto out;
-
        ret = btrfs_fill_inode(inode, &rdev);
        if (!ret)
                filled = true;
@@ -3919,6 +3915,11 @@ static int btrfs_read_locked_inode(struct btrfs_inode *inode, struct btrfs_path
        set_nlink(vfs_inode, btrfs_inode_nlink(leaf, inode_item));
        i_uid_write(vfs_inode, btrfs_inode_uid(leaf, inode_item));
        i_gid_write(vfs_inode, btrfs_inode_gid(leaf, inode_item));
+
+       ret = btrfs_init_file_extent_tree(inode);
+       if (ret)
+               goto out;
+
        btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
        btrfs_inode_set_file_extent_range(inode, 0,
                        round_up(i_size_read(vfs_inode), fs_info->sectorsize));
--

2.34.1

Disclaimer: The contents of this e-mail message and any attachments are confidential and are intended solely for addressee. The information may also be legally privileged. This transmission is sent in trust, for the sole purpose of delivery to the intended recipient. If you have received this transmission in error, any use, reproduction or dissemination of this transmission is strictly prohibited. If you are not the intended recipient, please immediately notify the sender by reply e-mail or phone and delete this message and its attachments, if any.