Skip to content

Commit e3645d7

Browse files
zhangyi089tytso
authored andcommitted
ext4: fix incorrect options show of original mount_opt and extend mount_opt2
Current _ext4_show_options() do not distinguish MOPT_2 flag, so it mixed extend sbi->s_mount_opt2 options with sbi->s_mount_opt, it could lead to show incorrect options, e.g. show fc_debug_force if we mount with errors=continue mode and miss it if we set. $ mkfs.ext4 /dev/pmem0 $ mount -o errors=remount-ro /dev/pmem0 /mnt $ cat /proc/fs/ext4/pmem0/options | grep fc_debug_force #empty $ mount -o remount,errors=continue /mnt $ cat /proc/fs/ext4/pmem0/options | grep fc_debug_force fc_debug_force $ mount -o remount,errors=remount-ro,fc_debug_force /mnt $ cat /proc/fs/ext4/pmem0/options | grep fc_debug_force #empty Fixes: 995a3ed ("ext4: add fast_commit feature and handling for extended mount options") Signed-off-by: Zhang Yi <[email protected]> Reviewed-by: Jan Kara <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 0813299 commit e3645d7

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

fs/ext4/ext4.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,6 +1529,7 @@ struct ext4_sb_info {
15291529
unsigned int s_mount_opt2;
15301530
unsigned long s_mount_flags;
15311531
unsigned int s_def_mount_opt;
1532+
unsigned int s_def_mount_opt2;
15321533
ext4_fsblk_t s_sb_block;
15331534
atomic64_t s_resv_clusters;
15341535
kuid_t s_resuid;

fs/ext4/super.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2894,7 +2894,7 @@ static int _ext4_show_options(struct seq_file *seq, struct super_block *sb,
28942894
{
28952895
struct ext4_sb_info *sbi = EXT4_SB(sb);
28962896
struct ext4_super_block *es = sbi->s_es;
2897-
int def_errors, def_mount_opt = sbi->s_def_mount_opt;
2897+
int def_errors;
28982898
const struct mount_opts *m;
28992899
char sep = nodefs ? '\n' : ',';
29002900

@@ -2906,15 +2906,28 @@ static int _ext4_show_options(struct seq_file *seq, struct super_block *sb,
29062906

29072907
for (m = ext4_mount_opts; m->token != Opt_err; m++) {
29082908
int want_set = m->flags & MOPT_SET;
2909+
int opt_2 = m->flags & MOPT_2;
2910+
unsigned int mount_opt, def_mount_opt;
2911+
29092912
if (((m->flags & (MOPT_SET|MOPT_CLEAR)) == 0) ||
29102913
m->flags & MOPT_SKIP)
29112914
continue;
2912-
if (!nodefs && !(m->mount_opt & (sbi->s_mount_opt ^ def_mount_opt)))
2913-
continue; /* skip if same as the default */
2915+
2916+
if (opt_2) {
2917+
mount_opt = sbi->s_mount_opt2;
2918+
def_mount_opt = sbi->s_def_mount_opt2;
2919+
} else {
2920+
mount_opt = sbi->s_mount_opt;
2921+
def_mount_opt = sbi->s_def_mount_opt;
2922+
}
2923+
/* skip if same as the default */
2924+
if (!nodefs && !(m->mount_opt & (mount_opt ^ def_mount_opt)))
2925+
continue;
2926+
/* select Opt_noFoo vs Opt_Foo */
29142927
if ((want_set &&
2915-
(sbi->s_mount_opt & m->mount_opt) != m->mount_opt) ||
2916-
(!want_set && (sbi->s_mount_opt & m->mount_opt)))
2917-
continue; /* select Opt_noFoo vs Opt_Foo */
2928+
(mount_opt & m->mount_opt) != m->mount_opt) ||
2929+
(!want_set && (mount_opt & m->mount_opt)))
2930+
continue;
29182931
SEQ_OPTS_PRINT("%s", token2str(m->token));
29192932
}
29202933

@@ -2942,7 +2955,7 @@ static int _ext4_show_options(struct seq_file *seq, struct super_block *sb,
29422955
if (nodefs || sbi->s_stripe)
29432956
SEQ_OPTS_PRINT("stripe=%lu", sbi->s_stripe);
29442957
if (nodefs || EXT4_MOUNT_DATA_FLAGS &
2945-
(sbi->s_mount_opt ^ def_mount_opt)) {
2958+
(sbi->s_mount_opt ^ sbi->s_def_mount_opt)) {
29462959
if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)
29472960
SEQ_OPTS_PUTS("data=journal");
29482961
else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA)
@@ -5081,6 +5094,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
50815094
goto failed_mount;
50825095

50835096
sbi->s_def_mount_opt = sbi->s_mount_opt;
5097+
sbi->s_def_mount_opt2 = sbi->s_mount_opt2;
50845098

50855099
err = ext4_check_opt_consistency(fc, sb);
50865100
if (err < 0)

0 commit comments

Comments
 (0)