Skip to content

Commit 1e381f6

Browse files
Dmitry Monakhovtytso
authored andcommitted
ext4: do not allow journal_opts for fs w/o journal
It is appeared that we can pass journal related mount options and such options be shown in /proc/mounts Example: #mkfs.ext4 -F /dev/vdb #tune2fs -O ^has_journal /dev/vdb #mount /dev/vdb /mnt/ -ocommit=20,journal_async_commit #cat /proc/mounts | grep /mnt /dev/vdb /mnt ext4 rw,relatime,journal_checksum,journal_async_commit,commit=20,data=ordered 0 0 But options:"journal_checksum,journal_async_commit,commit=20,data=ordered" has nothing with reality because there is no journal at all. This patch disallow following options for journalless configurations: - journal_checksum - journal_async_commit - commit=%ld - data={writeback,ordered,journal} Signed-off-by: Dmitry Monakhov <[email protected]> Signed-off-by: Theodore Ts'o <[email protected]> Reviewed-by: Andreas Dilger <[email protected]>
1 parent c93cf2d commit 1e381f6

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

fs/ext4/ext4.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,9 @@ struct ext4_inode_info {
10231023
#define EXT4_MOUNT2_HURD_COMPAT 0x00000004 /* Support HURD-castrated
10241024
file systems */
10251025

1026+
#define EXT4_MOUNT2_EXPLICIT_JOURNAL_CHECKSUM 0x00000008 /* User explicitly
1027+
specified journal checksum */
1028+
10261029
#define clear_opt(sb, opt) EXT4_SB(sb)->s_mount_opt &= \
10271030
~EXT4_MOUNT_##opt
10281031
#define set_opt(sb, opt) EXT4_SB(sb)->s_mount_opt |= \

fs/ext4/super.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,10 +1384,10 @@ static const struct mount_opts {
13841384
{Opt_nojournal_checksum, EXT4_MOUNT_JOURNAL_CHECKSUM,
13851385
MOPT_EXT4_ONLY | MOPT_CLEAR},
13861386
{Opt_journal_checksum, EXT4_MOUNT_JOURNAL_CHECKSUM,
1387-
MOPT_EXT4_ONLY | MOPT_SET},
1387+
MOPT_EXT4_ONLY | MOPT_SET | MOPT_EXPLICIT},
13881388
{Opt_journal_async_commit, (EXT4_MOUNT_JOURNAL_ASYNC_COMMIT |
13891389
EXT4_MOUNT_JOURNAL_CHECKSUM),
1390-
MOPT_EXT4_ONLY | MOPT_SET},
1390+
MOPT_EXT4_ONLY | MOPT_SET | MOPT_EXPLICIT},
13911391
{Opt_noload, EXT4_MOUNT_NOLOAD, MOPT_NO_EXT2 | MOPT_SET},
13921392
{Opt_err_panic, EXT4_MOUNT_ERRORS_PANIC, MOPT_SET | MOPT_CLEAR_ERR},
13931393
{Opt_err_ro, EXT4_MOUNT_ERRORS_RO, MOPT_SET | MOPT_CLEAR_ERR},
@@ -1519,6 +1519,8 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
15191519
if (m->flags & MOPT_EXPLICIT) {
15201520
if (m->mount_opt & EXT4_MOUNT_DELALLOC) {
15211521
set_opt2(sb, EXPLICIT_DELALLOC);
1522+
} else if (m->mount_opt & EXT4_MOUNT_JOURNAL_CHECKSUM) {
1523+
set_opt2(sb, EXPLICIT_JOURNAL_CHECKSUM);
15221524
} else
15231525
return -1;
15241526
}
@@ -3677,6 +3679,31 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
36773679
"suppressed and not mounted read-only");
36783680
goto failed_mount_wq;
36793681
} else {
3682+
/* Nojournal mode, all journal mount options are illegal */
3683+
if (test_opt2(sb, EXPLICIT_JOURNAL_CHECKSUM)) {
3684+
ext4_msg(sb, KERN_ERR, "can't mount with "
3685+
"journal_checksum, fs mounted w/o journal");
3686+
goto failed_mount_wq;
3687+
}
3688+
if (test_opt(sb, JOURNAL_ASYNC_COMMIT)) {
3689+
ext4_msg(sb, KERN_ERR, "can't mount with "
3690+
"journal_async_commit, fs mounted w/o journal");
3691+
goto failed_mount_wq;
3692+
}
3693+
if (sbi->s_commit_interval != JBD2_DEFAULT_MAX_COMMIT_AGE*HZ) {
3694+
ext4_msg(sb, KERN_ERR, "can't mount with "
3695+
"commit=%lu, fs mounted w/o journal",
3696+
sbi->s_commit_interval / HZ);
3697+
goto failed_mount_wq;
3698+
}
3699+
if (EXT4_MOUNT_DATA_FLAGS &
3700+
(sbi->s_mount_opt ^ sbi->s_def_mount_opt)) {
3701+
ext4_msg(sb, KERN_ERR, "can't mount with "
3702+
"data=, fs mounted w/o journal");
3703+
goto failed_mount_wq;
3704+
}
3705+
sbi->s_def_mount_opt &= EXT4_MOUNT_JOURNAL_CHECKSUM;
3706+
clear_opt(sb, JOURNAL_CHECKSUM);
36803707
clear_opt(sb, DATA_FLAGS);
36813708
sbi->s_journal = NULL;
36823709
needs_recovery = 0;

0 commit comments

Comments
 (0)