Skip to content

Commit 5bc27f4

Browse files
LiBaokun96tytso
authored andcommitted
ext4: add more ext4_emergency_state() checks around sb_rdonly()
Some functions check sb_rdonly() to make sure the file system isn't modified after it's read-only. Since we also don't want the file system modified if it's in an emergency state (shutdown or emergency_ro), we're adding additional ext4_emergency_state() checks where sb_rdonly() is checked. Suggested-by: Jan Kara <[email protected]> Signed-off-by: Baokun Li <[email protected]> Reviewed-by: Zhang Yi <[email protected]> Reviewed-by: Jan Kara <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 0a1b2f5 commit 5bc27f4

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

fs/ext4/file.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,8 @@ static int ext4_sample_last_mounted(struct super_block *sb,
844844
if (likely(ext4_test_mount_flag(sb, EXT4_MF_MNTDIR_SAMPLED)))
845845
return 0;
846846

847-
if (sb_rdonly(sb) || !sb_start_intwrite_trylock(sb))
847+
if (ext4_emergency_state(sb) || sb_rdonly(sb) ||
848+
!sb_start_intwrite_trylock(sb))
848849
return 0;
849850

850851
ext4_set_mount_flag(sb, EXT4_MF_MNTDIR_SAMPLED);

fs/ext4/ioctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1705,7 +1705,7 @@ int ext4_update_overhead(struct super_block *sb, bool force)
17051705
{
17061706
struct ext4_sb_info *sbi = EXT4_SB(sb);
17071707

1708-
if (sb_rdonly(sb))
1708+
if (ext4_emergency_state(sb) || sb_rdonly(sb))
17091709
return 0;
17101710
if (!force &&
17111711
(sbi->s_overhead == 0 ||

fs/ext4/super.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,9 @@ static void ext4_maybe_update_superblock(struct super_block *sb)
472472
__u64 lifetime_write_kbytes;
473473
__u64 diff_size;
474474

475-
if (sb_rdonly(sb) || !(sb->s_flags & SB_ACTIVE) ||
476-
!journal || (journal->j_flags & JBD2_UNMOUNT))
475+
if (ext4_emergency_state(sb) || sb_rdonly(sb) ||
476+
!(sb->s_flags & SB_ACTIVE) || !journal ||
477+
journal->j_flags & JBD2_UNMOUNT)
477478
return;
478479

479480
now = ktime_get_real_seconds();
@@ -750,7 +751,8 @@ static void update_super_work(struct work_struct *work)
750751
* We use directly jbd2 functions here to avoid recursing back into
751752
* ext4 error handling code during handling of previous errors.
752753
*/
753-
if (!sb_rdonly(sbi->s_sb) && journal) {
754+
if (!ext4_emergency_state(sbi->s_sb) &&
755+
!sb_rdonly(sbi->s_sb) && journal) {
754756
struct buffer_head *sbh = sbi->s_sbh;
755757
bool call_notify_err = false;
756758

@@ -1310,13 +1312,14 @@ static void ext4_put_super(struct super_block *sb)
13101312
ext4_mb_release(sb);
13111313
ext4_ext_release(sb);
13121314

1313-
if (!sb_rdonly(sb) && !aborted) {
1314-
ext4_clear_feature_journal_needs_recovery(sb);
1315-
ext4_clear_feature_orphan_present(sb);
1316-
es->s_state = cpu_to_le16(sbi->s_mount_state);
1317-
}
1318-
if (!sb_rdonly(sb))
1315+
if (!ext4_emergency_state(sb) && !sb_rdonly(sb)) {
1316+
if (!aborted) {
1317+
ext4_clear_feature_journal_needs_recovery(sb);
1318+
ext4_clear_feature_orphan_present(sb);
1319+
es->s_state = cpu_to_le16(sbi->s_mount_state);
1320+
}
13191321
ext4_commit_super(sb);
1322+
}
13201323

13211324
ext4_group_desc_free(sbi);
13221325
ext4_flex_groups_free(sbi);
@@ -3684,7 +3687,8 @@ static int ext4_run_li_request(struct ext4_li_request *elr)
36843687
if (group >= elr->lr_next_group) {
36853688
ret = 1;
36863689
if (elr->lr_first_not_zeroed != ngroups &&
3687-
!sb_rdonly(sb) && test_opt(sb, INIT_INODE_TABLE)) {
3690+
!ext4_emergency_state(sb) && !sb_rdonly(sb) &&
3691+
test_opt(sb, INIT_INODE_TABLE)) {
36883692
elr->lr_next_group = elr->lr_first_not_zeroed;
36893693
elr->lr_mode = EXT4_LI_MODE_ITABLE;
36903694
ret = 0;
@@ -3989,7 +3993,7 @@ int ext4_register_li_request(struct super_block *sb,
39893993
goto out;
39903994
}
39913995

3992-
if (sb_rdonly(sb) ||
3996+
if (ext4_emergency_state(sb) || sb_rdonly(sb) ||
39933997
(test_opt(sb, NO_PREFETCH_BLOCK_BITMAPS) &&
39943998
(first_not_zeroed == ngroups || !test_opt(sb, INIT_INODE_TABLE))))
39953999
goto out;

0 commit comments

Comments
 (0)