Skip to content

Commit 80d05f6

Browse files
Wengang-oracletytso
authored andcommitted
jbd2: store more accurate errno in superblock when possible
When jbd2_journal_abort() is called, the provided error code is stored in the journal superblock. Some existing calls hard-code -EIO even when the actual failure is not I/O related. This patch updates those calls to pass more accurate error codes, allowing the superblock to record the true cause of failure. This helps improve diagnostics and debugging clarity when analyzing journal aborts. Signed-off-by: Wengang Wang <wen.gang.wang@oracle.com> Reviewed-by: Zhang Yi <yi.zhang@huawei.com> Message-ID: <20251031210501.7337-1-wen.gang.wang@oracle.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 986835b commit 80d05f6

4 files changed

Lines changed: 15 additions & 11 deletions

File tree

fs/ext4/super.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ static void ext4_handle_error(struct super_block *sb, bool force_ro, int error,
698698
WARN_ON_ONCE(1);
699699

700700
if (!continue_fs && !ext4_emergency_ro(sb) && journal)
701-
jbd2_journal_abort(journal, -EIO);
701+
jbd2_journal_abort(journal, -error);
702702

703703
if (!bdev_read_only(sb->s_bdev)) {
704704
save_error_info(sb, error, ino, block, func, line);
@@ -5843,7 +5843,7 @@ static int ext4_journal_bmap(journal_t *journal, sector_t *block)
58435843
ext4_msg(journal->j_inode->i_sb, KERN_CRIT,
58445844
"journal bmap failed: block %llu ret %d\n",
58455845
*block, ret);
5846-
jbd2_journal_abort(journal, ret ? ret : -EIO);
5846+
jbd2_journal_abort(journal, ret ? ret : -EFSCORRUPTED);
58475847
return ret;
58485848
}
58495849
*block = map.m_pblk;

fs/jbd2/checkpoint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ __releases(&journal->j_state_lock)
113113
"journal space in %s\n", __func__,
114114
journal->j_devname);
115115
WARN_ON(1);
116-
jbd2_journal_abort(journal, -EIO);
116+
jbd2_journal_abort(journal, -ENOSPC);
117117
}
118118
write_lock(&journal->j_state_lock);
119119
} else {

fs/jbd2/journal.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -937,8 +937,8 @@ int jbd2_journal_bmap(journal_t *journal, unsigned long blocknr,
937937
printk(KERN_ALERT "%s: journal block not found "
938938
"at offset %lu on %s\n",
939939
__func__, blocknr, journal->j_devname);
940+
jbd2_journal_abort(journal, ret ? ret : -EFSCORRUPTED);
940941
err = -EIO;
941-
jbd2_journal_abort(journal, err);
942942
} else {
943943
*retp = block;
944944
}
@@ -1859,8 +1859,9 @@ int jbd2_journal_update_sb_log_tail(journal_t *journal, tid_t tail_tid,
18591859

18601860
if (is_journal_aborted(journal))
18611861
return -EIO;
1862-
if (jbd2_check_fs_dev_write_error(journal)) {
1863-
jbd2_journal_abort(journal, -EIO);
1862+
ret = jbd2_check_fs_dev_write_error(journal);
1863+
if (ret) {
1864+
jbd2_journal_abort(journal, ret);
18641865
return -EIO;
18651866
}
18661867

@@ -2157,9 +2158,11 @@ int jbd2_journal_destroy(journal_t *journal)
21572158
* failed to write back to the original location, otherwise the
21582159
* filesystem may become inconsistent.
21592160
*/
2160-
if (!is_journal_aborted(journal) &&
2161-
jbd2_check_fs_dev_write_error(journal))
2162-
jbd2_journal_abort(journal, -EIO);
2161+
if (!is_journal_aborted(journal)) {
2162+
int ret = jbd2_check_fs_dev_write_error(journal);
2163+
if (ret)
2164+
jbd2_journal_abort(journal, ret);
2165+
}
21632166

21642167
if (journal->j_sb_buffer) {
21652168
if (!is_journal_aborted(journal)) {

fs/jbd2/transaction.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,15 +1219,16 @@ int jbd2_journal_get_write_access(handle_t *handle, struct buffer_head *bh)
12191219
return -EROFS;
12201220

12211221
journal = handle->h_transaction->t_journal;
1222-
if (jbd2_check_fs_dev_write_error(journal)) {
1222+
rc = jbd2_check_fs_dev_write_error(journal);
1223+
if (rc) {
12231224
/*
12241225
* If the fs dev has writeback errors, it may have failed
12251226
* to async write out metadata buffers in the background.
12261227
* In this case, we could read old data from disk and write
12271228
* it out again, which may lead to on-disk filesystem
12281229
* inconsistency. Aborting journal can avoid it happen.
12291230
*/
1230-
jbd2_journal_abort(journal, -EIO);
1231+
jbd2_journal_abort(journal, rc);
12311232
return -EIO;
12321233
}
12331234

0 commit comments

Comments
 (0)