Skip to content

Commit 8b67f04

Browse files
committed
ext4: Add mount options in superblock
Allow mount options to be stored in the superblock. Also add default mount option bits for nobarrier, block_validity, discard, and nodelalloc. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
1 parent ca0e05e commit 8b67f04

2 files changed

Lines changed: 30 additions & 8 deletions

File tree

‎fs/ext4/ext4.h‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,8 +1025,9 @@ struct ext4_super_block {
10251025
__le32 s_last_error_line; /* line number where error happened */
10261026
__le64 s_last_error_block; /* block involved of last error */
10271027
__u8 s_last_error_func[32]; /* function where the error happened */
1028-
#define EXT4_S_ERR_END offsetof(struct ext4_super_block, s_reserved)
1029-
__le32 s_reserved[128]; /* Padding to the end of the block */
1028+
#define EXT4_S_ERR_END offsetof(struct ext4_super_block, s_mount_opts)
1029+
__u8 s_mount_opts[64];
1030+
__le32 s_reserved[112]; /* Padding to the end of the block */
10301031
};
10311032

10321033
#define EXT4_S_ERR_LEN (EXT4_S_ERR_END - EXT4_S_ERR_START)
@@ -1341,6 +1342,10 @@ EXT4_INODE_BIT_FNS(state, state_flags)
13411342
#define EXT4_DEFM_JMODE_DATA 0x0020
13421343
#define EXT4_DEFM_JMODE_ORDERED 0x0040
13431344
#define EXT4_DEFM_JMODE_WBACK 0x0060
1345+
#define EXT4_DEFM_NOBARRIER 0x0100
1346+
#define EXT4_DEFM_BLOCK_VALIDITY 0x0200
1347+
#define EXT4_DEFM_DISCARD 0x0400
1348+
#define EXT4_DEFM_NODELALLOC 0x0800
13441349

13451350
/*
13461351
* Default journal batch times

‎fs/ext4/super.c‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,10 +1003,10 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)
10031003
seq_puts(seq, ",journal_checksum");
10041004
if (test_opt(sb, I_VERSION))
10051005
seq_puts(seq, ",i_version");
1006-
if (!test_opt(sb, DELALLOC))
1006+
if (!test_opt(sb, DELALLOC) &&
1007+
!(def_mount_opts & EXT4_DEFM_NODELALLOC))
10071008
seq_puts(seq, ",nodelalloc");
10081009

1009-
10101010
if (sbi->s_stripe)
10111011
seq_printf(seq, ",stripe=%lu", sbi->s_stripe);
10121012
/*
@@ -1030,7 +1030,7 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)
10301030
if (test_opt(sb, NO_AUTO_DA_ALLOC))
10311031
seq_puts(seq, ",noauto_da_alloc");
10321032

1033-
if (test_opt(sb, DISCARD))
1033+
if (test_opt(sb, DISCARD) && !(def_mount_opts & EXT4_DEFM_DISCARD))
10341034
seq_puts(seq, ",discard");
10351035

10361036
if (test_opt(sb, NOLOAD))
@@ -1039,6 +1039,10 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)
10391039
if (test_opt(sb, DIOREAD_NOLOCK))
10401040
seq_puts(seq, ",dioread_nolock");
10411041

1042+
if (test_opt(sb, BLOCK_VALIDITY) &&
1043+
!(def_mount_opts & EXT4_DEFM_BLOCK_VALIDITY))
1044+
seq_puts(seq, ",block_validity");
1045+
10421046
ext4_show_quota_options(seq, sb);
10431047

10441048
return 0;
@@ -2655,22 +2659,34 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
26552659
set_opt(sbi->s_mount_opt, ERRORS_CONT);
26562660
else
26572661
set_opt(sbi->s_mount_opt, ERRORS_RO);
2662+
if (def_mount_opts & EXT4_DEFM_BLOCK_VALIDITY)
2663+
set_opt(sbi->s_mount_opt, BLOCK_VALIDITY);
2664+
if (def_mount_opts & EXT4_DEFM_DISCARD)
2665+
set_opt(sbi->s_mount_opt, DISCARD);
26582666

26592667
sbi->s_resuid = le16_to_cpu(es->s_def_resuid);
26602668
sbi->s_resgid = le16_to_cpu(es->s_def_resgid);
26612669
sbi->s_commit_interval = JBD2_DEFAULT_MAX_COMMIT_AGE * HZ;
26622670
sbi->s_min_batch_time = EXT4_DEF_MIN_BATCH_TIME;
26632671
sbi->s_max_batch_time = EXT4_DEF_MAX_BATCH_TIME;
26642672

2665-
set_opt(sbi->s_mount_opt, BARRIER);
2673+
if ((def_mount_opts & EXT4_DEFM_NOBARRIER) == 0)
2674+
set_opt(sbi->s_mount_opt, BARRIER);
26662675

26672676
/*
26682677
* enable delayed allocation by default
26692678
* Use -o nodelalloc to turn it off
26702679
*/
2671-
if (!IS_EXT3_SB(sb))
2680+
if (!IS_EXT3_SB(sb) &&
2681+
((def_mount_opts & EXT4_DEFM_NODELALLOC) == 0))
26722682
set_opt(sbi->s_mount_opt, DELALLOC);
26732683

2684+
if (!parse_options((char *) sbi->s_es->s_mount_opts, sb,
2685+
&journal_devnum, &journal_ioprio, NULL, 0)) {
2686+
ext4_msg(sb, KERN_WARNING,
2687+
"failed to parse options in superblock: %s",
2688+
sbi->s_es->s_mount_opts);
2689+
}
26742690
if (!parse_options((char *) data, sb, &journal_devnum,
26752691
&journal_ioprio, NULL, 0))
26762692
goto failed_mount;
@@ -3141,7 +3157,8 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
31413157
descr = "out journal";
31423158

31433159
ext4_msg(sb, KERN_INFO, "mounted filesystem with%s. "
3144-
"Opts: %s", descr, orig_data);
3160+
"Opts: %s%s%s", descr, sbi->s_es->s_mount_opts,
3161+
*sbi->s_es->s_mount_opts ? "; " : "", orig_data);
31453162

31463163
init_timer(&sbi->s_err_report);
31473164
sbi->s_err_report.function = print_daily_error_info;

0 commit comments

Comments
 (0)