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 <frank.li at vivo.com>
---
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
Yangtao Li
2023-Mar-10 05:48 UTC
[Ocfs2-devel] [PATCH v4 2/5] erofs: convert to use i_blockmask()
Use i_blockmask() to simplify code. Signed-off-by: Yangtao Li <frank.li at vivo.com> --- 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
Yangtao Li
2023-Mar-10 05:48 UTC
[Ocfs2-devel] [PATCH v4 3/5] gfs2: convert to use i_blockmask()
Use i_blockmask() to simplify code.
Signed-off-by: Yangtao Li <frank.li at vivo.com>
---
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
Yangtao Li
2023-Mar-10 05:48 UTC
[Ocfs2-devel] [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 <frank.li at vivo.com>
---
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
Yangtao Li
2023-Mar-10 05:48 UTC
[Ocfs2-devel] [PATCH v4 5/5] fs/remap_range: convert to use i_blockmask()
Use i_blockmask() to simplify code.
Signed-off-by: Yangtao Li <frank.li at vivo.com>
---
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
Joseph Qi
2023-Mar-10 11:13 UTC
[Ocfs2-devel] [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 <frank.li at vivo.com> > --- > 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,