Skip to content

Commit 7ffe1ea

Browse files
h-kawai-eztytso
authored andcommitted
ext4: add checks for errors from jbd2
If the journal has aborted due to a checkpointing failure, we have to keep the contents of the journal space. Otherwise, the filesystem will lose uncheckpointed metadata completely and become inconsistent. To avoid this, we need to keep needs_recovery flag if checkpoint has failed. With this patch, ext4_put_super() detects a checkpointing failure from the return value of journal_destroy(), then it invokes ext4_abort() to make the filesystem read only and keep needs_recovery flag. Errors from jbd2_journal_flush() are also handled by this patch in some places. Signed-off-by: Hidehiro Kawai <hidehiro.kawai.ez@hitachi.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 44519fa commit 7ffe1ea

2 files changed

Lines changed: 27 additions & 8 deletions

File tree

‎fs/ext4/ioctl.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
192192
case EXT4_IOC_GROUP_EXTEND: {
193193
ext4_fsblk_t n_blocks_count;
194194
struct super_block *sb = inode->i_sb;
195-
int err;
195+
int err, err2;
196196

197197
if (!capable(CAP_SYS_RESOURCE))
198198
return -EPERM;
@@ -206,16 +206,18 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
206206

207207
err = ext4_group_extend(sb, EXT4_SB(sb)->s_es, n_blocks_count);
208208
jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal);
209-
jbd2_journal_flush(EXT4_SB(sb)->s_journal);
209+
err2 = jbd2_journal_flush(EXT4_SB(sb)->s_journal);
210210
jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
211+
if (err == 0)
212+
err = err2;
211213
mnt_drop_write(filp->f_path.mnt);
212214

213215
return err;
214216
}
215217
case EXT4_IOC_GROUP_ADD: {
216218
struct ext4_new_group_data input;
217219
struct super_block *sb = inode->i_sb;
218-
int err;
220+
int err, err2;
219221

220222
if (!capable(CAP_SYS_RESOURCE))
221223
return -EPERM;
@@ -230,8 +232,10 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
230232

231233
err = ext4_group_add(sb, &input);
232234
jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal);
233-
jbd2_journal_flush(EXT4_SB(sb)->s_journal);
235+
err2 = jbd2_journal_flush(EXT4_SB(sb)->s_journal);
234236
jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
237+
if (err == 0)
238+
err = err2;
235239
mnt_drop_write(filp->f_path.mnt);
236240

237241
return err;

‎fs/ext4/super.c‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,8 @@ static void ext4_put_super(struct super_block *sb)
507507
ext4_mb_release(sb);
508508
ext4_ext_release(sb);
509509
ext4_xattr_put_super(sb);
510-
jbd2_journal_destroy(sbi->s_journal);
510+
if (jbd2_journal_destroy(sbi->s_journal) < 0)
511+
ext4_abort(sb, __func__, "Couldn't clean up the journal");
511512
sbi->s_journal = NULL;
512513
if (!(sb->s_flags & MS_RDONLY)) {
513514
EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
@@ -2853,7 +2854,9 @@ static void ext4_mark_recovery_complete(struct super_block *sb,
28532854
journal_t *journal = EXT4_SB(sb)->s_journal;
28542855

28552856
jbd2_journal_lock_updates(journal);
2856-
jbd2_journal_flush(journal);
2857+
if (jbd2_journal_flush(journal) < 0)
2858+
goto out;
2859+
28572860
lock_super(sb);
28582861
if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER) &&
28592862
sb->s_flags & MS_RDONLY) {
@@ -2862,6 +2865,8 @@ static void ext4_mark_recovery_complete(struct super_block *sb,
28622865
ext4_commit_super(sb, es, 1);
28632866
}
28642867
unlock_super(sb);
2868+
2869+
out:
28652870
jbd2_journal_unlock_updates(journal);
28662871
}
28672872

@@ -2962,7 +2967,13 @@ static void ext4_write_super_lockfs(struct super_block *sb)
29622967

29632968
/* Now we set up the journal barrier. */
29642969
jbd2_journal_lock_updates(journal);
2965-
jbd2_journal_flush(journal);
2970+
2971+
/*
2972+
* We don't want to clear needs_recovery flag when we failed
2973+
* to flush the journal.
2974+
*/
2975+
if (jbd2_journal_flush(journal) < 0)
2976+
return;
29662977

29672978
/* Journal blocked and flushed, clear needs_recovery flag. */
29682979
EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
@@ -3402,8 +3413,12 @@ static int ext4_quota_on(struct super_block *sb, int type, int format_id,
34023413
* otherwise be livelocked...
34033414
*/
34043415
jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal);
3405-
jbd2_journal_flush(EXT4_SB(sb)->s_journal);
3416+
err = jbd2_journal_flush(EXT4_SB(sb)->s_journal);
34063417
jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
3418+
if (err) {
3419+
path_put(&nd.path);
3420+
return err;
3421+
}
34073422
}
34083423

34093424
err = vfs_quota_on_path(sb, type, format_id, &nd.path);

0 commit comments

Comments
 (0)