Skip to content

Commit a7fbc7f

Browse files
JunPiaoHWgregkh
authored andcommitted
ocfs2: return error when we attempt to access a dirty bh in jbd2
[ Upstream commit d984187 ] We should not reuse the dirty bh in jbd2 directly due to the following situation: 1. When removing extent rec, we will dirty the bhs of extent rec and truncate log at the same time, and hand them over to jbd2. 2. The bhs are submitted to jbd2 area successfully. 3. The write-back thread of device help flush the bhs to disk but encounter write error due to abnormal storage link. 4. After a while the storage link become normal. Truncate log flush worker triggered by the next space reclaiming found the dirty bh of truncate log and clear its 'BH_Write_EIO' and then set it uptodate in __ocfs2_journal_access(): ocfs2_truncate_log_worker ocfs2_flush_truncate_log __ocfs2_flush_truncate_log ocfs2_replay_truncate_records ocfs2_journal_access_di __ocfs2_journal_access // here we clear io_error and set 'tl_bh' uptodata. 5. Then jbd2 will flush the bh of truncate log to disk, but the bh of extent rec is still in error state, and unfortunately nobody will take care of it. 6. At last the space of extent rec was not reduced, but truncate log flush worker have given it back to globalalloc. That will cause duplicate cluster problem which could be identified by fsck.ocfs2. Sadly we can hardly revert this but set fs read-only in case of ruining atomicity and consistency of space reclaim. Link: http://lkml.kernel.org/r/[email protected] Fixes: acf8fdb ("ocfs2: do not BUG if buffer not uptodate in __ocfs2_journal_access") Signed-off-by: Jun Piao <[email protected]> Reviewed-by: Yiwen Jiang <[email protected]> Reviewed-by: Changwei Ge <[email protected]> Cc: Mark Fasheh <[email protected]> Cc: Joel Becker <[email protected]> Cc: Junxiao Bi <[email protected]> Cc: Joseph Qi <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent a66174e commit a7fbc7f

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

fs/ocfs2/journal.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -666,23 +666,24 @@ static int __ocfs2_journal_access(handle_t *handle,
666666
/* we can safely remove this assertion after testing. */
667667
if (!buffer_uptodate(bh)) {
668668
mlog(ML_ERROR, "giving me a buffer that's not uptodate!\n");
669-
mlog(ML_ERROR, "b_blocknr=%llu\n",
670-
(unsigned long long)bh->b_blocknr);
669+
mlog(ML_ERROR, "b_blocknr=%llu, b_state=0x%lx\n",
670+
(unsigned long long)bh->b_blocknr, bh->b_state);
671671

672672
lock_buffer(bh);
673673
/*
674-
* A previous attempt to write this buffer head failed.
675-
* Nothing we can do but to retry the write and hope for
676-
* the best.
674+
* A previous transaction with a couple of buffer heads fail
675+
* to checkpoint, so all the bhs are marked as BH_Write_EIO.
676+
* For current transaction, the bh is just among those error
677+
* bhs which previous transaction handle. We can't just clear
678+
* its BH_Write_EIO and reuse directly, since other bhs are
679+
* not written to disk yet and that will cause metadata
680+
* inconsistency. So we should set fs read-only to avoid
681+
* further damage.
677682
*/
678683
if (buffer_write_io_error(bh) && !buffer_uptodate(bh)) {
679-
clear_buffer_write_io_error(bh);
680-
set_buffer_uptodate(bh);
681-
}
682-
683-
if (!buffer_uptodate(bh)) {
684684
unlock_buffer(bh);
685-
return -EIO;
685+
return ocfs2_error(osb->sb, "A previous attempt to "
686+
"write this buffer head failed\n");
686687
}
687688
unlock_buffer(bh);
688689
}

0 commit comments

Comments
 (0)