]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: replace sb::s_blocksize by fs_info::sectorsize
authorDavid Sterba <dsterba@suse.com>
Tue, 16 Jan 2024 16:33:20 +0000 (17:33 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 4 Mar 2024 15:24:46 +0000 (16:24 +0100)
The block size stored in the super block is used by subsystems outside
of btrfs and it's a copy of fs_info::sectorsize. Unify that to always
use our sectorsize, with the exception of mount where we first need to
use fixed values (4K) until we read the super block and can set the
sectorsize.

Replace all uses, in most cases it's fewer pointer indirections.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/disk-io.c
fs/btrfs/extent_io.c
fs/btrfs/inode.c
fs/btrfs/ioctl.c
fs/btrfs/reflink.c
fs/btrfs/send.c
fs/btrfs/super.c

index bcd35be4b841b5a8d4d612007664dc83cebf84b2..751e693be050c2e80f5f49513b277078354f4dfe 100644 (file)
@@ -2840,6 +2840,7 @@ static int init_mount_fs_info(struct btrfs_fs_info *fs_info, struct super_block
        int ret;
 
        fs_info->sb = sb;
+       /* Temporary fixed values for block size until we read the superblock. */
        sb->s_blocksize = BTRFS_BDEV_BLOCKSIZE;
        sb->s_blocksize_bits = blksize_bits(BTRFS_BDEV_BLOCKSIZE);
 
@@ -3357,6 +3358,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
        sb->s_bdi->ra_pages *= btrfs_super_num_devices(disk_super);
        sb->s_bdi->ra_pages = max(sb->s_bdi->ra_pages, SZ_4M / PAGE_SIZE);
 
+       /* Update the values for the current filesystem. */
        sb->s_blocksize = sectorsize;
        sb->s_blocksize_bits = blksize_bits(sectorsize);
        memcpy(&sb->s_uuid, fs_info->fs_devices->fsid, BTRFS_FSID_SIZE);
index cff67d03424df90304932aadd2d500cc370abccd..9f6ac8a26e07068cb6f1d5e7d80c66e30707760a 100644 (file)
@@ -1015,7 +1015,7 @@ static int btrfs_do_readpage(struct page *page, struct extent_map **em_cached,
        int ret = 0;
        size_t pg_offset = 0;
        size_t iosize;
-       size_t blocksize = inode->i_sb->s_blocksize;
+       size_t blocksize = fs_info->sectorsize;
        struct extent_io_tree *tree = &BTRFS_I(inode)->io_tree;
 
        ret = set_page_extent_mapped(page);
@@ -2305,7 +2305,7 @@ int extent_invalidate_folio(struct extent_io_tree *tree,
        struct extent_state *cached_state = NULL;
        u64 start = folio_pos(folio);
        u64 end = start + folio_size(folio) - 1;
-       size_t blocksize = folio->mapping->host->i_sb->s_blocksize;
+       size_t blocksize = btrfs_sb(folio->mapping->host->i_sb)->sectorsize;
 
        /* This function is only called for the btree inode */
        ASSERT(tree->owner == IO_TREE_BTREE_INODE_IO);
index 0fbea8505b46528971f0784f45b6d6e27c90a935..ea71df398f86cf831eb6dacf6f4b5e67f39b7709 100644 (file)
@@ -8721,7 +8721,7 @@ static int btrfs_getattr(struct mnt_idmap *idmap,
        u64 delalloc_bytes;
        u64 inode_bytes;
        struct inode *inode = d_inode(path->dentry);
-       u32 blocksize = inode->i_sb->s_blocksize;
+       u32 blocksize = btrfs_sb(inode->i_sb)->sectorsize;
        u32 bi_flags = BTRFS_I(inode)->flags;
        u32 bi_ro_flags = BTRFS_I(inode)->ro_flags;
 
index 9d1eac15e09e141212cf0edadffcca873cba58f1..8d80903e9bff620f4f2cb0cbdc1b7dda939a1232 100644 (file)
@@ -528,7 +528,7 @@ static noinline int btrfs_ioctl_fitrim(struct btrfs_fs_info *fs_info,
         * block group is in the logical address space, which can be any
         * sectorsize aligned bytenr in  the range [0, U64_MAX].
         */
-       if (range.len < fs_info->sb->s_blocksize)
+       if (range.len < fs_info->sectorsize)
                return -EINVAL;
 
        range.minlen = max(range.minlen, minlen);
index ae90894dc7dc7d44f9b5b7f3a41a1c4862e7df23..e38cb40e150c962880ca71d6e2e252aa6144776c 100644 (file)
@@ -663,7 +663,7 @@ static int btrfs_extent_same_range(struct inode *src, u64 loff, u64 len,
                                   struct inode *dst, u64 dst_loff)
 {
        struct btrfs_fs_info *fs_info = BTRFS_I(src)->root->fs_info;
-       const u64 bs = fs_info->sb->s_blocksize;
+       const u64 bs = fs_info->sectorsize;
        int ret;
 
        /*
@@ -730,7 +730,7 @@ static noinline int btrfs_clone_files(struct file *file, struct file *file_src,
        int ret;
        int wb_ret;
        u64 len = olen;
-       u64 bs = fs_info->sb->s_blocksize;
+       u64 bs = fs_info->sectorsize;
 
        /*
         * VFS's generic_remap_file_range_prep() protects us from cloning the
@@ -796,7 +796,7 @@ static int btrfs_remap_file_range_prep(struct file *file_in, loff_t pos_in,
 {
        struct inode *inode_in = file_inode(file_in);
        struct inode *inode_out = file_inode(file_out);
-       u64 bs = BTRFS_I(inode_out)->root->fs_info->sb->s_blocksize;
+       u64 bs = BTRFS_I(inode_out)->root->fs_info->sectorsize;
        u64 wb_len;
        int ret;
 
index e48a063ef0851f9476fd37a00572c1dd6c6fe379..e9516509b2761c8363903877fba0d11a39523a79 100644 (file)
@@ -6140,7 +6140,7 @@ static int send_write_or_clone(struct send_ctx *sctx,
        int ret = 0;
        u64 offset = key->offset;
        u64 end;
-       u64 bs = sctx->send_root->fs_info->sb->s_blocksize;
+       u64 bs = sctx->send_root->fs_info->sectorsize;
 
        end = min_t(u64, btrfs_file_extent_end(path), sctx->cur_inode_size);
        if (offset >= end)
index 101f786963d4d7712baab28c912226fb741c0c9b..c45fdaf24cd1c2fe61b8e99b126893b1ca7c1fbf 100644 (file)
@@ -1767,7 +1767,7 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)
                buf->f_bavail = 0;
 
        buf->f_type = BTRFS_SUPER_MAGIC;
-       buf->f_bsize = dentry->d_sb->s_blocksize;
+       buf->f_bsize = fs_info->sectorsize;
        buf->f_namelen = BTRFS_NAME_LEN;
 
        /* We treat it as constant endianness (it doesn't matter _which_)