Re: [PATCH 4.20 079/145] ext4: check for shutdown and r/o file system in ext4_write_inode()

From: Sasha Levin
Date: Wed Jan 09 2019 - 18:18:53 EST


On Wed, Jan 09, 2019 at 05:44:55PM +0100, Greg Kroah-Hartman wrote:
On Mon, Jan 07, 2019 at 04:56:06PM -0500, Sasha Levin wrote:
On Mon, Jan 07, 2019 at 01:31:56PM +0100, Greg Kroah-Hartman wrote:
> 4.20-stable review patch. If anyone has any objections, please let me know.
>
> ------------------
>
> From: Theodore Ts'o <tytso@xxxxxxx>
>
> commit 18f2c4fcebf2582f96cbd5f2238f4f354a0e4847 upstream.
>
> If the file system has been shut down or is read-only, then
> ext4_write_inode() needs to bail out early.
>
> Also use jbd2_complete_transaction() instead of ext4_force_commit() so
> we only force a commit if it is needed.
>
> Signed-off-by: Theodore Ts'o <tytso@xxxxxxx>
> Cc: stable@xxxxxxxxxx
> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
>
> ---
> fs/ext4/inode.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -5400,9 +5400,13 @@ int ext4_write_inode(struct inode *inode
> {
> int err;
>
> - if (WARN_ON_ONCE(current->flags & PF_MEMALLOC))
> + if (WARN_ON_ONCE(current->flags & PF_MEMALLOC) ||
> + sb_rdonly(inode->i_sb))
> return 0;
>
> + if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb))))
> + return -EIO;
> +
> if (EXT4_SB(inode->i_sb)->s_journal) {
> if (ext4_journal_current_handle()) {
> jbd_debug(1, "called recursively, non-PF_MEMALLOC!\n");
> @@ -5418,7 +5422,8 @@ int ext4_write_inode(struct inode *inode
> if (wbc->sync_mode != WB_SYNC_ALL || wbc->for_sync)
> return 0;
>
> - err = ext4_force_commit(inode->i_sb);
> + err = jbd2_complete_transaction(EXT4_SB(inode->i_sb)->s_journal,
> + EXT4_I(inode)->i_sync_tid);
> } else {
> struct ext4_iloc iloc;

Hi Ted,

I'm not sure if this patch is the culprit or no, but testing with
xfstests on 4.20.1-rc1 started failing generic/390 with:

[ 3405.656893] run fstests generic/390 at 2019-01-07 20:26:55
[ 3406.524380] EXT4-fs (nvme0n1p2): mounted filesystem without journal. Opts: acl,user_xattr
[ 3406.731410] WARNING: CPU: 0 PID: 93128 at fs/ext4/ext4_jbd2.c:53 ext4_journal_check_start+0x121/0x190
[ 3406.731418] CPU: 0 PID: 93128 Comm: fsstress Tainted: G B W 4.20.1-rc1+ #1
[ 3406.731420] Hardware name: Microsoft Corporation Virtual Machine/Virtual Machine, BIOS 090007 05/18/2018
[ 3406.731425] RIP: 0010:ext4_journal_check_start+0x121/0x190
[ 3406.731430] Code: 4d 85 e4 74 1e 4c 89 e2 48 b8 00 00 00 00 00 fc ff df 48 c1 ea 03 80 3c 02 00 75 4f 41 f6 04 24 02 75 0b 31 c0 5b 41 5c 5d c3 <0f> 0b eb ab 48 c7 c1 60 b4 f9 a4 ba 3d 00 00 00 48 c7 c6 a0 b8 f9
[ 3406.731432] RSP: 0018:ffff888f30317648 EFLAGS: 00010246
[ 3406.731437] RAX: 0000000000000000 RBX: ffff888ee6ce12c8 RCX: 000000000000000c
[ 3406.731440] RDX: 1ffff111dcd9c2a0 RSI: 0000000000000b33 RDI: ffff888ee6ce1500
[ 3406.731442] RBP: ffff888f30317658 R08: 0000000000000000 R09: ffffed11db5f01a7
[ 3406.731444] R10: 0000000000000001 R11: ffffed11db5f01a6 R12: ffff888ee6ce2ee8
[ 3406.731447] R13: dffffc0000000000 R14: 0000000000000000 R15: ffff888f303178e0
[ 3406.731450] FS: 00007fc015d5cb80(0000) GS:ffff888f6b800000(0000) knlGS:0000000000000000
[ 3406.731452] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 3406.731455] CR2: 0000557f34651000 CR3: 0000000f2c722000 CR4: 00000000003406f0
[ 3406.731459] Call Trace:
[ 3406.731465] __ext4_journal_start_sb+0x95/0x380
[ 3406.731479] ext4_writepages+0x10e1/0x3170
[ 3406.731567] do_writepages+0xc7/0x120
[ 3406.731577] __filemap_fdatawrite_range+0x313/0x470
[ 3406.731594] file_write_and_wait_range+0x7c/0xd0
[ 3406.731598] __generic_file_fsync+0x6c/0x180
[ 3406.731601] ext4_sync_file+0x60b/0xf90
[ 3406.731626] vfs_fsync_range+0xf5/0x210
[ 3406.731630] do_fsync+0x3d/0x70
[ 3406.731634] __x64_sys_fdatasync+0x36/0x50
[ 3406.731638] do_syscall_64+0x153/0x460
[ 3406.731666] entry_SYSCALL_64_after_hwframe+0x44/0xa9
[ 3406.731669] RIP: 0033:0x7fc0152412c4
[ 3406.731673] Code: 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 8d 05 41 96 2d 00 8b 00 85 c0 75 13 b8 4b 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 3c f3 c3 66 90 53 89 fb 48 83 ec 10 e8 04 94
[ 3406.731675] RSP: 002b:00007ffc445f72f8 EFLAGS: 00000246 ORIG_RAX: 000000000000004b
[ 3406.731679] RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 00007fc0152412c4
[ 3406.731681] RDX: 00007ffc445f7250 RSI: 00007ffc445f7250 RDI: 0000000000000003
[ 3406.731683] RBP: 0000000000000034 R08: 00007fc015515c40 R09: 0000000000000000
[ 3406.731685] R10: 0000000000000000 R11: 0000000000000246 R12: 00000000000001f4
[ 3406.731687] R13: 0000000051eb851f R14: 00007ffc445f73f6 R15: 0000557f33ad1930
[ 3406.731690] ---[ end trace 698eba2a0467d312 ]---

I'm also slightly confused here because this test is for ext4 without
journal (see even "EXT4-fs (nvme0n1p2): mounted filesystem without
journal") but for some reason it seems that this still goes to the
journal?


Does this also fail on 4.19? The same patch is here and in 4.14 as
well.

I'm seeing a failure with this config only on 4.20.

--
Thanks,
Sasha