ext4: avoid ext4_error()'s caused by ENOMEM in the truncate path
PATCH 1/1 ext4: avoid ext4_error()'s caused by ENOMEM in the truncate path
From: Theodore Ts'o <[email protected]>
We can't fail in the truncate path without requiring an fsck. Add work around for this by using a combination of retry loops and the __GFP_NOFAIL flag.
From: Theodore Ts'o <[email protected]>
--- fs/ext4/ext4.h | 1 + fs/ext4/extents.c | 43 +++++++++++++++++++++++++++++++++---------- 2 files changed, 34 insertions(+), 10 deletions(-)
fs/ext4/ext4.h +1 -0
@@ -632,6 +632,7 @@ enum {*/ #define EXT4_EX_NOCACHE 0x40000000#define EXT4_EX_FORCE_CACHE 0x20000000 +#define EXT4_EX_NOFAIL 0x10000000/* * Flags used by ext4_free_blocks
fs/ext4/extents.c +33 -10
116 lines not on this page · raw message
Signature · 1 line
2.26.2.526.g744177e7f7-goog
kbuild test robot
build botI love your patch! Perhaps something to improve:
Hi Anna,
I love your patch! Perhaps something to improve:
[auto build test WARNING on ext4/dev]
[also build test WARNING on tytso-fscrypt/master v5.7-rc4 next-20200508] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Anna-Pendleton/ext4-avoid-ext4_error-s-caused-by-ENOMEM-in-the-truncate-path/20200508-062229 base: https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev reproduce: # apt-get install sparse # sparse version: make ARCH=x86_64 allmodconfig make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' :::::: branch date: 22 hours ago :::::: commit date: 22 hours ago
If you fix the issue, kindly add following tag as appropriate
sparse warnings: (new ones prefixed by >>)
fs/ext4/extents.c:493:67: sparse: warning: incorrect type in initializer (different base types)
>> fs/ext4/extents.c:493:67: sparse: expected int gfp_flags >> fs/ext4/extents.c:493:67: sparse: got restricted gfp_t fs/ext4/extents.c:496:27: sparse: warning: invalid assignment: |= >> fs/ext4/extents.c:496:27: sparse: left side has type int >> fs/ext4/extents.c:496:27: sparse: right side has type restricted gfp_t fs/ext4/extents.c:498:47: sparse: warning: incorrect type in argument 3 (different base types) >> fs/ext4/extents.c:498:47: sparse: expected restricted gfp_t [usertype] gfp >> fs/ext4/extents.c:498:47: sparse: got int gfp_flags fs/ext4/extents.c:848:25: sparse: warning: incorrect type in initializer (different base types) fs/ext4/extents.c:848:25: sparse: expected int gfp_flags fs/ext4/extents.c:848:25: sparse: got restricted gfp_t fs/ext4/extents.c:851:27: sparse: warning: invalid assignment: |= fs/ext4/extents.c:851:27: sparse: left side has type int fs/ext4/extents.c:851:27: sparse: right side has type restricted gfp_t fs/ext4/extents.c:872:33: sparse: warning: incorrect type in argument 3 (different base types) >> fs/ext4/extents.c:872:33: sparse: expected restricted gfp_t [usertype] flags
fs/ext4/extents.c:872:33: sparse: got int gfp_flags
fs/ext4/extents.c:1022:25: sparse: warning: incorrect type in initializer (different base types)
fs/ext4/extents.c:1022:25: sparse: expected int gfp_flags
fs/ext4/extents.c:1022:25: sparse: got restricted gfp_t
fs/ext4/extents.c:1027:27: sparse: warning: invalid assignment: |=
fs/ext4/extents.c:1027:27: sparse: left side has type int
fs/ext4/extents.c:1027:27: sparse: right side has type restricted gfp_t
fs/ext4/extents.c:1062:56: sparse: warning: incorrect type in argument 3 (different base types)
fs/ext4/extents.c:1062:56: sparse: expected restricted gfp_t [usertype] flags
fs/ext4/extents.c:1062:56: sparse: got int gfp_flags
# https://github.com/0day-ci/linux/commit/7d07f7d72800b68a55822a5705514d3c3bc82b63
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout 7d07f7d72800b68a55822a5705514d3c3bc82b63
vim +493 fs/ext4/extents.c
4068664e3cd231 Dmitry Monakhov 2019-11-06 485
7d7ea89e756ea1 Theodore Ts'o 2013-08-16 486 static struct buffer_head *
7d7ea89e756ea1 Theodore Ts'o 2013-08-16 487 __read_extent_tree_block(const char *function, unsigned int line,
107a7bd31ac003 Theodore Ts'o 2013-08-16 488 struct inode *inode, ext4_fsblk_t pblk, int depth,
107a7bd31ac003 Theodore Ts'o 2013-08-16 489 int flags)
f84891289e62a7 Darrick J. Wong 2012-04-29 490 {
7d7ea89e756ea1 Theodore Ts'o 2013-08-16 491 struct buffer_head *bh;
7d7ea89e756ea1 Theodore Ts'o 2013-08-16 492 int err;
7d07f7d72800b6 Theodore Ts'o 2020-05-07 @493 int gfp_flags = __GFP_MOVABLE | GFP_NOFS;
f84891289e62a7 Darrick J. Wong 2012-04-29 494
7d07f7d72800b6 Theodore Ts'o 2020-05-07 495 if (flags & EXT4_EX_NOFAIL)
7d07f7d72800b6 Theodore Ts'o 2020-05-07 @496 gfp_flags |= __GFP_NOFAIL;
7d07f7d72800b6 Theodore Ts'o 2020-05-07 497
7d07f7d72800b6 Theodore Ts'o 2020-05-07 @498 bh = sb_getblk_gfp(inode->i_sb, pblk, gfp_flags);
7d7ea89e756ea1 Theodore Ts'o 2013-08-16 499 if (unlikely(!bh))
7d7ea89e756ea1 Theodore Ts'o 2013-08-16 500 return ERR_PTR(-ENOMEM);
7d7ea89e756ea1 Theodore Ts'o 2013-08-16 501
7d7ea89e756ea1 Theodore Ts'o 2013-08-16 502 if (!bh_uptodate_or_lock(bh)) {
7d7ea89e756ea1 Theodore Ts'o 2013-08-16 503 trace_ext4_ext_load_extent(inode, pblk, _RET_IP_);
7d7ea89e756ea1 Theodore Ts'o 2013-08-16 504 err = bh_submit_read(bh);
7d7ea89e756ea1 Theodore Ts'o 2013-08-16 505 if (err < 0)
7d7ea89e756ea1 Theodore Ts'o 2013-08-16 506 goto errout;
7d7ea89e756ea1 Theodore Ts'o 2013-08-16 507 }
7869a4a6c5caa7 Theodore Ts'o 2013-08-16 508 if (buffer_verified(bh) && !(flags & EXT4_EX_FORCE_CACHE))
7d7ea89e756ea1 Theodore Ts'o 2013-08-16 509 return bh;
0a944e8a6c66ca Theodore Ts'o 2019-05-22 510 if (!ext4_has_feature_journal(inode->i_sb) ||
0a944e8a6c66ca Theodore Ts'o 2019-05-22 511 (inode->i_ino !=
0a944e8a6c66ca Theodore Ts'o 2019-05-22 512 le32_to_cpu(EXT4_SB(inode->i_sb)->s_es->s_journal_inum))) {
7d7ea89e756ea1 Theodore Ts'o 2013-08-16 513 err = __ext4_ext_check(function, line, inode,
c349179b4808f7 Theodore Ts'o 2013-08-16 514 ext_block_hdr(bh), depth, pblk);
7d7ea89e756ea1 Theodore Ts'o 2013-08-16 515 if (err)
7d7ea89e756ea1 Theodore Ts'o 2013-08-16 516 goto errout;
0a944e8a6c66ca Theodore Ts'o 2019-05-22 517 }
f84891289e62a7 Darrick J. Wong 2012-04-29 518 set_buffer_verified(bh);
107a7bd31ac003 Theodore Ts'o 2013-08-16 519 /*
107a7bd31ac003 Theodore Ts'o 2013-08-16 520 * If this is a leaf block, cache all of its entries
107a7bd31ac003 Theodore Ts'o 2013-08-16 521 */
107a7bd31ac003 Theodore Ts'o 2013-08-16 522 if (!(flags & EXT4_EX_NOCACHE) && depth == 0) {
107a7bd31ac003 Theodore Ts'o 2013-08-16 523 struct ext4_extent_header *eh = ext_block_hdr(bh);
4068664e3cd231 Dmitry Monakhov 2019-11-06 524 ext4_cache_extents(inode, eh);
107a7bd31ac003 Theodore Ts'o 2013-08-16 525 }
7d7ea89e756ea1 Theodore Ts'o 2013-08-16 526 return bh;
7d7ea89e756ea1 Theodore Ts'o 2013-08-16 527 errout:
7d7ea89e756ea1 Theodore Ts'o 2013-08-16 528 put_bh(bh);
7d7ea89e756ea1 Theodore Ts'o 2013-08-16 529 return ERR_PTR(err);
7d7ea89e756ea1 Theodore Ts'o 2013-08-16 530 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
Quoted 10 lines · Anna Pendleton
From: Theodore Ts'o <[email protected]>
We can't fail in the truncate path without requiring an fsck. Add work around for this by using a combination of retry loops and the
__GFP_NOFAILflag.From: Theodore Ts'o <[email protected]>
Signed-off-by Theodore Ts'o <[email protected]>Signed-off-by Anna Pendleton <[email protected]>Reviewed-by Harshad Shirwadkar <[email protected]>
Thanks, applied.
Per the feedback from the kbuild test robot, I changed "int gfp_flags =..." to "gfp_t gfp_flags=..." in three places in the patches.
Cheers,
- Ted