ext4: factor out ext4_get_maxbytes()
authorZhang Yi <yi.zhang@huawei.com>
Tue, 6 May 2025 01:20:08 +0000 (09:20 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 20 May 2025 14:30:59 +0000 (10:30 -0400)
There are several locations that get the correct maxbytes value based on
the inode's block type. It would be beneficial to extract a common
helper function to make the code more clear.

Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Baokun Li <libaokun1@huawei.com>
Link: https://patch.msgid.link/20250506012009.3896990-3-yi.zhang@huaweicloud.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Cc: stable@kernel.org
fs/ext4/ext4.h
fs/ext4/extents.c
fs/ext4/file.c

index 3f352f2a6d851a19f4ae06540dbcf0cde5d8db0f..f329aa0517b4584e20224c1ca39b5f8d908a2396 100644 (file)
@@ -3395,6 +3395,13 @@ static inline unsigned int ext4_flex_bg_size(struct ext4_sb_info *sbi)
        return 1 << sbi->s_log_groups_per_flex;
 }
 
+static inline loff_t ext4_get_maxbytes(struct inode *inode)
+{
+       if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
+               return inode->i_sb->s_maxbytes;
+       return EXT4_SB(inode->i_sb)->s_bitmap_maxbytes;
+}
+
 #define ext4_std_error(sb, errno)                              \
 do {                                                           \
        if ((errno))                                            \
index 9053fe68ee4cccd999f486fa4c6b52811b77c28e..c42472fd4b63e3fa636371879c78de54edad1f56 100644 (file)
@@ -4941,12 +4941,7 @@ static const struct iomap_ops ext4_iomap_xattr_ops = {
 
 static int ext4_fiemap_check_ranges(struct inode *inode, u64 start, u64 *len)
 {
-       u64 maxbytes;
-
-       if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
-               maxbytes = inode->i_sb->s_maxbytes;
-       else
-               maxbytes = EXT4_SB(inode->i_sb)->s_bitmap_maxbytes;
+       u64 maxbytes = ext4_get_maxbytes(inode);
 
        if (*len == 0)
                return -EINVAL;
index beb078ee4811d6092e362e37307e7d87e5276cbc..b845a25f7932c6b49606cc7e2c1b8872b9781bb8 100644 (file)
@@ -929,12 +929,7 @@ static int ext4_file_open(struct inode *inode, struct file *filp)
 loff_t ext4_llseek(struct file *file, loff_t offset, int whence)
 {
        struct inode *inode = file->f_mapping->host;
-       loff_t maxbytes;
-
-       if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)))
-               maxbytes = EXT4_SB(inode->i_sb)->s_bitmap_maxbytes;
-       else
-               maxbytes = inode->i_sb->s_maxbytes;
+       loff_t maxbytes = ext4_get_maxbytes(inode);
 
        switch (whence) {
        default: