Skip to content

Commit d9774bb

Browse files
LiBaokun96gregkh
authored andcommitted
ext4: add ext4_sb_bread_nofail() helper function for ext4_free_branches()
commit d8b90e6387a74bcb1714c8d1e6a782ff709de9a9 upstream. The implicit __GFP_NOFAIL flag in ext4_sb_bread() was removed in commit 8a83ac5 ("ext4: call bdev_getblk() from sb_getblk_gfp()"), meaning the function can now fail under memory pressure. Most callers of ext4_sb_bread() propagate the error to userspace and do not remount the filesystem read-only. However, ext4_free_branches() handles ext4_sb_bread() failure by remounting the filesystem read-only. This implies that an ext3 filesystem (mounted via the ext4 driver) could be forcibly remounted read-only due to a transient page allocation failure, which is unacceptable. To mitigate this, introduce a new helper function, ext4_sb_bread_nofail(), which explicitly uses __GFP_NOFAIL, and use it in ext4_free_branches(). Fixes: 8a83ac5 ("ext4: call bdev_getblk() from sb_getblk_gfp()") Cc: [email protected] Signed-off-by: Baokun Li <[email protected]> Reviewed-by: Jan Kara <[email protected]> Signed-off-by: Theodore Ts'o <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 8699bc1 commit d9774bb

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

fs/ext4/ext4.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3144,6 +3144,8 @@ extern struct buffer_head *ext4_sb_bread(struct super_block *sb,
31443144
sector_t block, blk_opf_t op_flags);
31453145
extern struct buffer_head *ext4_sb_bread_unmovable(struct super_block *sb,
31463146
sector_t block);
3147+
extern struct buffer_head *ext4_sb_bread_nofail(struct super_block *sb,
3148+
sector_t block);
31473149
extern void ext4_read_bh_nowait(struct buffer_head *bh, blk_opf_t op_flags,
31483150
bh_end_io_t *end_io, bool simu_fail);
31493151
extern int ext4_read_bh(struct buffer_head *bh, blk_opf_t op_flags,

fs/ext4/indirect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ static void ext4_free_branches(handle_t *handle, struct inode *inode,
10251025
}
10261026

10271027
/* Go read the buffer for the next level down */
1028-
bh = ext4_sb_bread(inode->i_sb, nr, 0);
1028+
bh = ext4_sb_bread_nofail(inode->i_sb, nr);
10291029

10301030
/*
10311031
* A read failure? Report error and clear slot

fs/ext4/super.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,15 @@ struct buffer_head *ext4_sb_bread_unmovable(struct super_block *sb,
265265
return __ext4_sb_bread_gfp(sb, block, 0, gfp);
266266
}
267267

268+
struct buffer_head *ext4_sb_bread_nofail(struct super_block *sb,
269+
sector_t block)
270+
{
271+
gfp_t gfp = mapping_gfp_constraint(sb->s_bdev->bd_mapping,
272+
~__GFP_FS) | __GFP_MOVABLE | __GFP_NOFAIL;
273+
274+
return __ext4_sb_bread_gfp(sb, block, 0, gfp);
275+
}
276+
268277
void ext4_sb_breadahead_unmovable(struct super_block *sb, sector_t block)
269278
{
270279
struct buffer_head *bh = bdev_getblk(sb->s_bdev, block,

0 commit comments

Comments
 (0)