Skip to content

Commit fb7c024

Browse files
committed
ext4: pass -ESHUTDOWN code to jbd2 layer
Previously the jbd2 layer assumed that a file system check would be required after a journal abort. In the case of the deliberate file system shutdown, this should not be necessary. Allow the jbd2 layer to distinguish between these two cases by using the ESHUTDOWN errno. Also add proper locking to __journal_abort_soft(). Signed-off-by: Theodore Ts'o <tytso@mit.edu> Cc: stable@vger.kernel.org
1 parent a6d9946 commit fb7c024

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

fs/ext4/ioctl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,13 +493,13 @@ static int ext4_shutdown(struct super_block *sb, unsigned long arg)
493493
set_bit(EXT4_FLAGS_SHUTDOWN, &sbi->s_ext4_flags);
494494
if (sbi->s_journal && !is_journal_aborted(sbi->s_journal)) {
495495
(void) ext4_force_commit(sb);
496-
jbd2_journal_abort(sbi->s_journal, 0);
496+
jbd2_journal_abort(sbi->s_journal, -ESHUTDOWN);
497497
}
498498
break;
499499
case EXT4_GOING_FLAGS_NOLOGFLUSH:
500500
set_bit(EXT4_FLAGS_SHUTDOWN, &sbi->s_ext4_flags);
501501
if (sbi->s_journal && !is_journal_aborted(sbi->s_journal))
502-
jbd2_journal_abort(sbi->s_journal, 0);
502+
jbd2_journal_abort(sbi->s_journal, -ESHUTDOWN);
503503
break;
504504
default:
505505
return -EINVAL;

fs/jbd2/journal.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,12 +1483,15 @@ static void jbd2_mark_journal_empty(journal_t *journal, int write_op)
14831483
void jbd2_journal_update_sb_errno(journal_t *journal)
14841484
{
14851485
journal_superblock_t *sb = journal->j_superblock;
1486+
int errcode;
14861487

14871488
read_lock(&journal->j_state_lock);
1488-
jbd_debug(1, "JBD2: updating superblock error (errno %d)\n",
1489-
journal->j_errno);
1490-
sb->s_errno = cpu_to_be32(journal->j_errno);
1489+
errcode = journal->j_errno;
14911490
read_unlock(&journal->j_state_lock);
1491+
if (errcode == -ESHUTDOWN)
1492+
errcode = 0;
1493+
jbd_debug(1, "JBD2: updating superblock error (errno %d)\n", errcode);
1494+
sb->s_errno = cpu_to_be32(errcode);
14921495

14931496
jbd2_write_superblock(journal, REQ_SYNC | REQ_FUA);
14941497
}
@@ -2105,12 +2108,22 @@ void __jbd2_journal_abort_hard(journal_t *journal)
21052108
* but don't do any other IO. */
21062109
static void __journal_abort_soft (journal_t *journal, int errno)
21072110
{
2108-
if (journal->j_flags & JBD2_ABORT)
2109-
return;
2111+
int old_errno;
21102112

2111-
if (!journal->j_errno)
2113+
write_lock(&journal->j_state_lock);
2114+
old_errno = journal->j_errno;
2115+
if (!journal->j_errno || errno == -ESHUTDOWN)
21122116
journal->j_errno = errno;
21132117

2118+
if (journal->j_flags & JBD2_ABORT) {
2119+
write_unlock(&journal->j_state_lock);
2120+
if (!old_errno && old_errno != -ESHUTDOWN &&
2121+
errno == -ESHUTDOWN)
2122+
jbd2_journal_update_sb_errno(journal);
2123+
return;
2124+
}
2125+
write_unlock(&journal->j_state_lock);
2126+
21142127
__jbd2_journal_abort_hard(journal);
21152128

21162129
if (errno) {

0 commit comments

Comments
 (0)