2023-03-10 05:49:18

by 李扬韬

[permalink] [raw]
Subject: [PATCH v4 1/5] fs: add i_blockmask()

Introduce i_blockmask() to simplify code, which replace
(i_blocksize(node) - 1). Like done in commit
93407472a21b("fs: add i_blocksize()").

Signed-off-by: Yangtao Li <[email protected]>
---
v4:
-drop ext4 patch
-erofs patch based on mainline
-a bit change in ocfs2 patch
include/linux/fs.h | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/include/linux/fs.h b/include/linux/fs.h
index c85916e9f7db..17387d465b8b 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -711,6 +711,11 @@ static inline unsigned int i_blocksize(const struct inode *node)
return (1 << node->i_blkbits);
}

+static inline unsigned int i_blockmask(const struct inode *node)
+{
+ return i_blocksize(node) - 1;
+}
+
static inline int inode_unhashed(struct inode *inode)
{
return hlist_unhashed(&inode->i_hash);
--
2.25.1



2023-03-10 05:49:35

by 李扬韬

[permalink] [raw]
Subject: [PATCH v4 2/5] erofs: convert to use i_blockmask()

Use i_blockmask() to simplify code.

Signed-off-by: Yangtao Li <[email protected]>
---
fs/erofs/data.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/erofs/data.c b/fs/erofs/data.c
index e16545849ea7..d394102ef9de 100644
--- a/fs/erofs/data.c
+++ b/fs/erofs/data.c
@@ -376,7 +376,7 @@ static ssize_t erofs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
if (bdev)
blksize_mask = bdev_logical_block_size(bdev) - 1;
else
- blksize_mask = (1 << inode->i_blkbits) - 1;
+ blksize_mask = i_blockmask(inode);

if ((iocb->ki_pos | iov_iter_count(to) |
iov_iter_alignment(to)) & blksize_mask)
--
2.25.1


2023-03-10 05:49:42

by 李扬韬

[permalink] [raw]
Subject: [PATCH v4 3/5] gfs2: convert to use i_blockmask()

Use i_blockmask() to simplify code.

Signed-off-by: Yangtao Li <[email protected]>
---
fs/gfs2/bmap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c
index eedf6926c652..1c6874b3851a 100644
--- a/fs/gfs2/bmap.c
+++ b/fs/gfs2/bmap.c
@@ -960,7 +960,7 @@ static struct folio *
gfs2_iomap_get_folio(struct iomap_iter *iter, loff_t pos, unsigned len)
{
struct inode *inode = iter->inode;
- unsigned int blockmask = i_blocksize(inode) - 1;
+ unsigned int blockmask = i_blockmask(inode);
struct gfs2_sbd *sdp = GFS2_SB(inode);
unsigned int blocks;
struct folio *folio;
--
2.25.1


2023-03-10 05:49:48

by 李扬韬

[permalink] [raw]
Subject: [PATCH v4 4/5] ocfs2: convert to use i_blockmask()

Use i_blockmask() to simplify code. BTW convert ocfs2_is_io_unaligned
to return bool type and the fact that the value will be the same
(i.e. that ->i_blkbits is never changed by ocfs2).

Signed-off-by: Yangtao Li <[email protected]>
---
fs/ocfs2/file.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index efb09de4343d..7fd06a4d27d4 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -2159,14 +2159,9 @@ int ocfs2_check_range_for_refcount(struct inode *inode, loff_t pos,
return ret;
}

-static int ocfs2_is_io_unaligned(struct inode *inode, size_t count, loff_t pos)
+static bool ocfs2_is_io_unaligned(struct inode *inode, size_t count, loff_t pos)
{
- int blockmask = inode->i_sb->s_blocksize - 1;
- loff_t final_size = pos + count;
-
- if ((pos & blockmask) || (final_size & blockmask))
- return 1;
- return 0;
+ return ((pos | count) & i_blockmask(inode)) != 0;
}

static int ocfs2_inode_lock_for_extent_tree(struct inode *inode,
--
2.25.1


2023-03-10 05:49:51

by 李扬韬

[permalink] [raw]
Subject: [PATCH v4 5/5] fs/remap_range: convert to use i_blockmask()

Use i_blockmask() to simplify code.

Signed-off-by: Yangtao Li <[email protected]>
---
fs/remap_range.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/remap_range.c b/fs/remap_range.c
index 1331a890f2f2..7a524b620e7d 100644
--- a/fs/remap_range.c
+++ b/fs/remap_range.c
@@ -127,7 +127,7 @@ static int generic_remap_check_len(struct inode *inode_in,
loff_t *len,
unsigned int remap_flags)
{
- u64 blkmask = i_blocksize(inode_in) - 1;
+ u64 blkmask = i_blockmask(inode_in);
loff_t new_len = *len;

if ((*len & blkmask) == 0)
--
2.25.1


2023-03-10 06:01:22

by Gao Xiang

[permalink] [raw]
Subject: Re: [PATCH v4 2/5] erofs: convert to use i_blockmask()

Hi Yangtao,

On 2023/3/10 13:48, Yangtao Li wrote:
> Use i_blockmask() to simplify code.
>
> Signed-off-by: Yangtao Li <[email protected]>

Please help drop this one since we'd like to use it until i_blockmask()
lands to upstream.

Thanks,
Gao Xiang

> ---
> fs/erofs/data.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/erofs/data.c b/fs/erofs/data.c
> index e16545849ea7..d394102ef9de 100644
> --- a/fs/erofs/data.c
> +++ b/fs/erofs/data.c
> @@ -376,7 +376,7 @@ static ssize_t erofs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
> if (bdev)
> blksize_mask = bdev_logical_block_size(bdev) - 1;
> else
> - blksize_mask = (1 << inode->i_blkbits) - 1;
> + blksize_mask = i_blockmask(inode);
>
> if ((iocb->ki_pos | iov_iter_count(to) |
> iov_iter_alignment(to)) & blksize_mask)

2023-03-10 06:16:07

by 李扬韬

[permalink] [raw]
Subject: Re: [PATCH v4 2/5] erofs: convert to use i_blockmask()

Hi Gao Xiang,

> Please help drop this one since we'd like to use it until i_blockmask() lands to upstream.

I'm OK. Not sure if I need to resend v5?

Thx,
Yangtao

2023-03-10 06:21:07

by Gao Xiang

[permalink] [raw]
Subject: Re: [PATCH v4 2/5] erofs: convert to use i_blockmask()



On 2023/3/10 14:15, Yangtao Li wrote:
> Hi Gao Xiang,
>
>> Please help drop this one since we'd like to use it until i_blockmask() lands to upstream.
>
> I'm OK. Not sure if I need to resend v5?

Thanks, your patch looks fine to me. The main reasons are that
1) active cross tree development on cleanup stuffs;
2) we'd like to add subpage block support for the next cycle,
and they seem somewhat convolved...

So I will apply your patch when i_blockmask() is landed upstream
then.

Thanks,
Gao Xiang

>
> Thx,
> Yangtao

2023-03-10 11:14:24

by Joseph Qi

[permalink] [raw]
Subject: Re: [PATCH v4 4/5] ocfs2: convert to use i_blockmask()



On 3/10/23 1:48 PM, Yangtao Li wrote:
> Use i_blockmask() to simplify code. BTW convert ocfs2_is_io_unaligned
> to return bool type and the fact that the value will be the same
> (i.e. that ->i_blkbits is never changed by ocfs2).
>
> Signed-off-by: Yangtao Li <[email protected]>
> ---
> fs/ocfs2/file.c | 9 ++-------
> 1 file changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
> index efb09de4343d..7fd06a4d27d4 100644
> --- a/fs/ocfs2/file.c
> +++ b/fs/ocfs2/file.c
> @@ -2159,14 +2159,9 @@ int ocfs2_check_range_for_refcount(struct inode *inode, loff_t pos,
> return ret;
> }
>
> -static int ocfs2_is_io_unaligned(struct inode *inode, size_t count, loff_t pos)
> +static bool ocfs2_is_io_unaligned(struct inode *inode, size_t count, loff_t pos)
> {
> - int blockmask = inode->i_sb->s_blocksize - 1;
> - loff_t final_size = pos + count;
> -
> - if ((pos & blockmask) || (final_size & blockmask))
> - return 1;
> - return 0;
> + return ((pos | count) & i_blockmask(inode)) != 0;

Or !!((pos | count) & i_blockmask(inode))?

My concern is just like erofs, we'd better get vfs helper into mainline
first. Or can we fold the whole series into one patch? Since it's simple
enough I think.

Thanks,
Joseph

> }
>
> static int ocfs2_inode_lock_for_extent_tree(struct inode *inode,