Skip to content

Commit c044f3d

Browse files
zhangyi089tytso
authored andcommitted
jbd2: abort journal if free a async write error metadata buffer
If we free a metadata buffer which has been failed to async write out in the background, the jbd2 checkpoint procedure will not detect this failure in jbd2_log_do_checkpoint(), so it may lead to filesystem inconsistency after cleanup journal tail. This patch abort the journal if free a buffer has write_io_error flag to prevent potential further inconsistency. Signed-off-by: zhangyi (F) <yi.zhang@huawei.com> Link: https://lore.kernel.org/r/20200620025427.1756360-5-yi.zhang@huawei.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent bc71726 commit c044f3d

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎fs/jbd2/transaction.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2120,6 +2120,7 @@ int jbd2_journal_try_to_free_buffers(journal_t *journal,
21202120
{
21212121
struct buffer_head *head;
21222122
struct buffer_head *bh;
2123+
bool has_write_io_error = false;
21232124
int ret = 0;
21242125

21252126
J_ASSERT(PageLocked(page));
@@ -2144,11 +2145,26 @@ int jbd2_journal_try_to_free_buffers(journal_t *journal,
21442145
jbd2_journal_put_journal_head(jh);
21452146
if (buffer_jbd(bh))
21462147
goto busy;
2148+
2149+
/*
2150+
* If we free a metadata buffer which has been failed to
2151+
* write out, the jbd2 checkpoint procedure will not detect
2152+
* this failure and may lead to filesystem inconsistency
2153+
* after cleanup journal tail.
2154+
*/
2155+
if (buffer_write_io_error(bh)) {
2156+
pr_err("JBD2: Error while async write back metadata bh %llu.",
2157+
(unsigned long long)bh->b_blocknr);
2158+
has_write_io_error = true;
2159+
}
21472160
} while ((bh = bh->b_this_page) != head);
21482161

21492162
ret = try_to_free_buffers(page);
21502163

21512164
busy:
2165+
if (has_write_io_error)
2166+
jbd2_journal_abort(journal, -EIO);
2167+
21522168
return ret;
21532169
}
21542170

0 commit comments

Comments
 (0)