* [PATCH 0/2] Block size helper cleanups
@ 2024-01-17 17:10 David Sterba
2024-01-17 17:10 ` [PATCH 1/2] btrfs: replace sb::s_blocksize by fs_info::sectorsize David Sterba
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: David Sterba @ 2024-01-17 17:10 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
Unify using fs_info::sectorsize for inode or superblock.
David Sterba (2):
btrfs: replace sb::s_blocksize by fs_info::sectorsize
btrfs: replace i_blocksize by fs_info::sectorsize
fs/btrfs/disk-io.c | 2 ++
fs/btrfs/extent_io.c | 4 ++--
fs/btrfs/file.c | 4 ++--
fs/btrfs/inode.c | 2 +-
fs/btrfs/ioctl.c | 2 +-
fs/btrfs/reflink.c | 6 +++---
fs/btrfs/send.c | 2 +-
fs/btrfs/super.c | 2 +-
8 files changed, 13 insertions(+), 11 deletions(-)
--
2.42.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] btrfs: replace sb::s_blocksize by fs_info::sectorsize
2024-01-17 17:10 [PATCH 0/2] Block size helper cleanups David Sterba
@ 2024-01-17 17:10 ` David Sterba
2024-01-17 17:10 ` [PATCH 2/2] btrfs: replace i_blocksize " David Sterba
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: David Sterba @ 2024-01-17 17:10 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
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.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/disk-io.c | 2 ++
fs/btrfs/extent_io.c | 4 ++--
fs/btrfs/inode.c | 2 +-
fs/btrfs/ioctl.c | 2 +-
fs/btrfs/reflink.c | 6 +++---
fs/btrfs/send.c | 2 +-
fs/btrfs/super.c | 2 +-
7 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 6e17496769ff..51c6127508af 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2831,6 +2831,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);
@@ -3348,6 +3349,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);
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 48ece936d733..cbf2feab2f8b 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -1035,7 +1035,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);
@@ -2325,7 +2325,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);
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 7199670599d9..5919731c4355 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -8686,7 +8686,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;
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index dfed9dd9c2d7..58e0c59bc4cd 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -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);
diff --git a/fs/btrfs/reflink.c b/fs/btrfs/reflink.c
index ae90894dc7dc..e38cb40e150c 100644
--- a/fs/btrfs/reflink.c
+++ b/fs/btrfs/reflink.c
@@ -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;
diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index 7902298c1f25..141ab89fb63e 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -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)
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 101f786963d4..c45fdaf24cd1 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -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_)
--
2.42.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] btrfs: replace i_blocksize by fs_info::sectorsize
2024-01-17 17:10 [PATCH 0/2] Block size helper cleanups David Sterba
2024-01-17 17:10 ` [PATCH 1/2] btrfs: replace sb::s_blocksize by fs_info::sectorsize David Sterba
@ 2024-01-17 17:10 ` David Sterba
2024-01-17 18:53 ` [PATCH 0/2] Block size helper cleanups Josef Bacik
2024-01-18 6:16 ` Anand Jain
3 siblings, 0 replies; 6+ messages in thread
From: David Sterba @ 2024-01-17 17:10 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
The block size calculated by i_blocksize from inode is the same as what
we have in fs_info, initalized in inode_init_always(). Unify that to use
the fs_info value everywhere.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/file.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index f8e1a7ce3d39..bd8d13740f41 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -3004,7 +3004,7 @@ static int btrfs_zero_range(struct inode *inode,
}
ret = btrfs_prealloc_file_range(inode, mode, alloc_start,
alloc_end - alloc_start,
- i_blocksize(inode),
+ fs_info->sectorsize,
offset + len, &alloc_hint);
unlock_extent(&BTRFS_I(inode)->io_tree, lockstart, lockend,
&cached_state);
@@ -3176,7 +3176,7 @@ static long btrfs_fallocate(struct file *file, int mode,
if (!ret) {
ret = btrfs_prealloc_file_range(inode, mode,
range->start,
- range->len, i_blocksize(inode),
+ range->len, blocksize,
offset + len, &alloc_hint);
/*
* btrfs_prealloc_file_range() releases space even
--
2.42.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] Block size helper cleanups
2024-01-17 17:10 [PATCH 0/2] Block size helper cleanups David Sterba
2024-01-17 17:10 ` [PATCH 1/2] btrfs: replace sb::s_blocksize by fs_info::sectorsize David Sterba
2024-01-17 17:10 ` [PATCH 2/2] btrfs: replace i_blocksize " David Sterba
@ 2024-01-17 18:53 ` Josef Bacik
2024-01-18 6:16 ` Anand Jain
3 siblings, 0 replies; 6+ messages in thread
From: Josef Bacik @ 2024-01-17 18:53 UTC (permalink / raw)
To: David Sterba; +Cc: linux-btrfs
On Wed, Jan 17, 2024 at 06:10:13PM +0100, David Sterba wrote:
> Unify using fs_info::sectorsize for inode or superblock.
>
> David Sterba (2):
> btrfs: replace sb::s_blocksize by fs_info::sectorsize
> btrfs: replace i_blocksize by fs_info::sectorsize
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Thanks,
Josef
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] Block size helper cleanups
2024-01-17 17:10 [PATCH 0/2] Block size helper cleanups David Sterba
` (2 preceding siblings ...)
2024-01-17 18:53 ` [PATCH 0/2] Block size helper cleanups Josef Bacik
@ 2024-01-18 6:16 ` Anand Jain
2024-01-18 22:29 ` David Sterba
3 siblings, 1 reply; 6+ messages in thread
From: Anand Jain @ 2024-01-18 6:16 UTC (permalink / raw)
To: David Sterba, linux-btrfs
Sorry for the late comments. Looks good
Reviewed-by: Anand Jain <anand.jain@oracle.com>
just one nit:
You may also bring the following repetitive code into a new
helper function as it is used once in init_mount_fs_info()
and again in open_ctree():
sb->s_blocksize = sectorsize;
sb->s_blocksize_bits = blksize_bits(sectorsize);
For example:
static inline void btrfs_set_blocksize(struct super_block *sb,
int sectorsize)
{
sb->s_blocksize = sectorsize;
sb->s_blocksize_bits = blksize_bits(sectorsize);
}
btrfs_set_blocksize(sb, sectorsize);
On 1/18/24 01:10, David Sterba wrote:
> Unify using fs_info::sectorsize for inode or superblock.
>
> David Sterba (2):
> btrfs: replace sb::s_blocksize by fs_info::sectorsize
> btrfs: replace i_blocksize by fs_info::sectorsize
>
> fs/btrfs/disk-io.c | 2 ++
> fs/btrfs/extent_io.c | 4 ++--
> fs/btrfs/file.c | 4 ++--
> fs/btrfs/inode.c | 2 +-
> fs/btrfs/ioctl.c | 2 +-
> fs/btrfs/reflink.c | 6 +++---
> fs/btrfs/send.c | 2 +-
> fs/btrfs/super.c | 2 +-
> 8 files changed, 13 insertions(+), 11 deletions(-)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] Block size helper cleanups
2024-01-18 6:16 ` Anand Jain
@ 2024-01-18 22:29 ` David Sterba
0 siblings, 0 replies; 6+ messages in thread
From: David Sterba @ 2024-01-18 22:29 UTC (permalink / raw)
To: Anand Jain; +Cc: David Sterba, linux-btrfs
On Thu, Jan 18, 2024 at 02:16:11PM +0800, Anand Jain wrote:
>
>
>
> Sorry for the late comments. Looks good
>
> Reviewed-by: Anand Jain <anand.jain@oracle.com>
>
>
>
> just one nit:
> You may also bring the following repetitive code into a new
> helper function as it is used once in init_mount_fs_info()
> and again in open_ctree():
I don't think we need the helper here, it's for the one-time
initializations, unlikely to be needed anywhere else that would justify
it.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-01-18 22:30 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-17 17:10 [PATCH 0/2] Block size helper cleanups David Sterba
2024-01-17 17:10 ` [PATCH 1/2] btrfs: replace sb::s_blocksize by fs_info::sectorsize David Sterba
2024-01-17 17:10 ` [PATCH 2/2] btrfs: replace i_blocksize " David Sterba
2024-01-17 18:53 ` [PATCH 0/2] Block size helper cleanups Josef Bacik
2024-01-18 6:16 ` Anand Jain
2024-01-18 22:29 ` David Sterba
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.