add patch fix-ext4_show_options-for-fs-wo-journal
[ext4-patch-queue.git] / check-superblock-mapped-prior-to-committing
blobf2ea81de68810284ad4d99e46af4366938d86a7b
1 jbd2: check superblock mapped prior to committing
3 From: Jiufei Xue <jiufei.xue@linux.alibaba.com>
5 We hit a BUG at fs/buffer.c:3057 if we detached the nbd device
6 before unmounting ext4 filesystem.
8 The typical chain of events leading to the BUG:
9 jbd2_write_superblock
10   submit_bh
11     submit_bh_wbc
12       BUG_ON(!buffer_mapped(bh));
14 The block device is removed and all the pages are invalidated. JBD2
15 was trying to write journal superblock to the block device which is
16 no longer present.
18 Fix this by checking the journal superblock's buffer head prior to
19 submitting.
21 Reported-by: Eric Ren <renzhen@linux.alibaba.com>
22 Signed-off-by: Jiufei Xue <jiufei.xue@linux.alibaba.com>
23 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
24 Reviewed-by: Jan Kara <jack@suse.cz>
25 Cc: stable@kernel.org
26 ---
27  fs/jbd2/journal.c | 4 ++++
28  1 file changed, 4 insertions(+)
30 diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
31 index 382c030cc78b..37e16d969925 100644
32 --- a/fs/jbd2/journal.c
33 +++ b/fs/jbd2/journal.c
34 @@ -1350,6 +1350,10 @@ static int jbd2_write_superblock(journal_t *journal, int write_flags)
35         journal_superblock_t *sb = journal->j_superblock;
36         int ret;
38 +       /* Buffer got discarded which means block device got invalidated */
39 +       if (!buffer_mapped(bh))
40 +               return -EIO;
42         trace_jbd2_write_superblock(journal, write_flags);
43         if (!(journal->j_flags & JBD2_BARRIER))
44                 write_flags &= ~(REQ_FUA | REQ_PREFLUSH);
45 -- 
46 2.19.1.856.g8858448bb