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:
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
18 Fix this by checking the journal superblock's buffer head prior to
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>
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;
38 + /* Buffer got discarded which means block device got invalidated */
39 + if (!buffer_mapped(bh))
42 trace_jbd2_write_superblock(journal, write_flags);
43 if (!(journal->j_flags & JBD2_BARRIER))
44 write_flags &= ~(REQ_FUA | REQ_PREFLUSH);