Skip to content

Commit 847243a

Browse files
zhangyi089opsiff
authored andcommitted
ext4: factor out ext4_get_maxbytes()
commit dbe27f0 upstream. 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 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> (cherry picked from commit 68cea04f1fb2ead5e10e1be8be98cb1cb24334ba)
1 parent b104bd8 commit 847243a

3 files changed

Lines changed: 9 additions & 12 deletions

File tree

fs/ext4/ext4.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3351,6 +3351,13 @@ static inline unsigned int ext4_flex_bg_size(struct ext4_sb_info *sbi)
33513351
return 1 << sbi->s_log_groups_per_flex;
33523352
}
33533353

3354+
static inline loff_t ext4_get_maxbytes(struct inode *inode)
3355+
{
3356+
if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
3357+
return inode->i_sb->s_maxbytes;
3358+
return EXT4_SB(inode->i_sb)->s_bitmap_maxbytes;
3359+
}
3360+
33543361
#define ext4_std_error(sb, errno) \
33553362
do { \
33563363
if ((errno)) \

fs/ext4/extents.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4970,12 +4970,7 @@ static const struct iomap_ops ext4_iomap_xattr_ops = {
49704970

49714971
static int ext4_fiemap_check_ranges(struct inode *inode, u64 start, u64 *len)
49724972
{
4973-
u64 maxbytes;
4974-
4975-
if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
4976-
maxbytes = inode->i_sb->s_maxbytes;
4977-
else
4978-
maxbytes = EXT4_SB(inode->i_sb)->s_bitmap_maxbytes;
4973+
u64 maxbytes = ext4_get_maxbytes(inode);
49794974

49804975
if (*len == 0)
49814976
return -EINVAL;

fs/ext4/file.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -898,12 +898,7 @@ static int ext4_file_open(struct inode *inode, struct file *filp)
898898
loff_t ext4_llseek(struct file *file, loff_t offset, int whence)
899899
{
900900
struct inode *inode = file->f_mapping->host;
901-
loff_t maxbytes;
902-
903-
if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)))
904-
maxbytes = EXT4_SB(inode->i_sb)->s_bitmap_maxbytes;
905-
else
906-
maxbytes = inode->i_sb->s_maxbytes;
901+
loff_t maxbytes = ext4_get_maxbytes(inode);
907902

908903
switch (whence) {
909904
default:

0 commit comments

Comments
 (0)