Skip to content

Commit f8814f3

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 b841ca8c8fa93a16880e0c28068adb69704f2aba)
1 parent b9f1b04 commit f8814f3

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
@@ -3369,6 +3369,13 @@ static inline unsigned int ext4_flex_bg_size(struct ext4_sb_info *sbi)
33693369
return 1 << sbi->s_log_groups_per_flex;
33703370
}
33713371

3372+
static inline loff_t ext4_get_maxbytes(struct inode *inode)
3373+
{
3374+
if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
3375+
return inode->i_sb->s_maxbytes;
3376+
return EXT4_SB(inode->i_sb)->s_bitmap_maxbytes;
3377+
}
3378+
33723379
#define ext4_std_error(sb, errno) \
33733380
do { \
33743381
if ((errno)) \

fs/ext4/extents.c

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

49784978
static int ext4_fiemap_check_ranges(struct inode *inode, u64 start, u64 *len)
49794979
{
4980-
u64 maxbytes;
4981-
4982-
if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
4983-
maxbytes = inode->i_sb->s_maxbytes;
4984-
else
4985-
maxbytes = EXT4_SB(inode->i_sb)->s_bitmap_maxbytes;
4980+
u64 maxbytes = ext4_get_maxbytes(inode);
49864981

49874982
if (*len == 0)
49884983
return -EINVAL;

fs/ext4/file.c

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

906901
switch (whence) {
907902
default:

0 commit comments

Comments
 (0)