From 72e918dc1f4ae3b1ccfbeb72108d9e5dd21503ac Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Mon, 19 Oct 2015 00:01:22 -0400 Subject: [PATCH] add patch do-not-allow-journal_opts-for-fs-wo-journal --- do-not-allow-journal_opts-for-fs-wo-journal | 107 ++++++++++++++++++++++++++++ series | 1 + timestamps | 7 +- 3 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 do-not-allow-journal_opts-for-fs-wo-journal diff --git a/do-not-allow-journal_opts-for-fs-wo-journal b/do-not-allow-journal_opts-for-fs-wo-journal new file mode 100644 index 00000000..041bb35b --- /dev/null +++ b/do-not-allow-journal_opts-for-fs-wo-journal @@ -0,0 +1,107 @@ +ext4: do not allow journal_opts for fs w/o journal + +From: Dmitry Monakhov + +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 +Signed-off-by: Theodore Ts'o +Reviewed-by: Andreas Dilger +--- + fs/ext4/ext4.h | 3 +++ + fs/ext4/super.c | 31 +++++++++++++++++++++++++++++-- + 2 files changed, 32 insertions(+), 2 deletions(-) + +diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h +index 3f248c9..871cdc6 100644 +--- a/fs/ext4/ext4.h ++++ b/fs/ext4/ext4.h +@@ -1019,6 +1019,9 @@ struct ext4_inode_info { + #define EXT4_MOUNT2_HURD_COMPAT 0x00000004 /* Support HURD-castrated + file systems */ + ++#define EXT4_MOUNT2_EXPLICIT_JOURNAL_CHECKSUM 0x00000008 /* User explicitly ++ specified journal checksum */ ++ + #define clear_opt(sb, opt) EXT4_SB(sb)->s_mount_opt &= \ + ~EXT4_MOUNT_##opt + #define set_opt(sb, opt) EXT4_SB(sb)->s_mount_opt |= \ +diff --git a/fs/ext4/super.c b/fs/ext4/super.c +index e91f6d4..a29b32b 100644 +--- a/fs/ext4/super.c ++++ b/fs/ext4/super.c +@@ -1371,10 +1371,10 @@ static const struct mount_opts { + {Opt_nojournal_checksum, EXT4_MOUNT_JOURNAL_CHECKSUM, + MOPT_EXT4_ONLY | MOPT_CLEAR}, + {Opt_journal_checksum, EXT4_MOUNT_JOURNAL_CHECKSUM, +- MOPT_EXT4_ONLY | MOPT_SET}, ++ MOPT_EXT4_ONLY | MOPT_SET | MOPT_EXPLICIT}, + {Opt_journal_async_commit, (EXT4_MOUNT_JOURNAL_ASYNC_COMMIT | + EXT4_MOUNT_JOURNAL_CHECKSUM), +- MOPT_EXT4_ONLY | MOPT_SET}, ++ MOPT_EXT4_ONLY | MOPT_SET | MOPT_EXPLICIT}, + {Opt_noload, EXT4_MOUNT_NOLOAD, MOPT_NO_EXT2 | MOPT_SET}, + {Opt_err_panic, EXT4_MOUNT_ERRORS_PANIC, MOPT_SET | MOPT_CLEAR_ERR}, + {Opt_err_ro, EXT4_MOUNT_ERRORS_RO, MOPT_SET | MOPT_CLEAR_ERR}, +@@ -1506,6 +1506,8 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token, + if (m->flags & MOPT_EXPLICIT) { + if (m->mount_opt & EXT4_MOUNT_DELALLOC) { + set_opt2(sb, EXPLICIT_DELALLOC); ++ } else if (m->mount_opt & EXT4_MOUNT_JOURNAL_CHECKSUM) { ++ set_opt2(sb, EXPLICIT_JOURNAL_CHECKSUM); + } else + return -1; + } +@@ -3675,6 +3677,31 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) + "suppressed and not mounted read-only"); + goto failed_mount_wq; + } else { ++ /* Nojournal mode, all journal mount options are illegal */ ++ if (test_opt2(sb, EXPLICIT_JOURNAL_CHECKSUM)) { ++ ext4_msg(sb, KERN_ERR, "can't mount with " ++ "journal_checksum, fs mounted w/o journal"); ++ goto failed_mount_wq; ++ } ++ if (test_opt(sb, JOURNAL_ASYNC_COMMIT)) { ++ ext4_msg(sb, KERN_ERR, "can't mount with " ++ "journal_async_commit, fs mounted w/o journal"); ++ goto failed_mount_wq; ++ } ++ if (sbi->s_commit_interval != JBD2_DEFAULT_MAX_COMMIT_AGE*HZ) { ++ ext4_msg(sb, KERN_ERR, "can't mount with " ++ "commit=%lu, fs mounted w/o journal", ++ sbi->s_commit_interval / HZ); ++ goto failed_mount_wq; ++ } ++ if (EXT4_MOUNT_DATA_FLAGS & ++ (sbi->s_mount_opt ^ sbi->s_def_mount_opt)) { ++ ext4_msg(sb, KERN_ERR, "can't mount with " ++ "data=, fs mounted w/o journal"); ++ goto failed_mount_wq; ++ } ++ sbi->s_def_mount_opt &= EXT4_MOUNT_JOURNAL_CHECKSUM; ++ clear_opt(sb, JOURNAL_CHECKSUM); + clear_opt(sb, DATA_FLAGS); + sbi->s_journal = NULL; + needs_recovery = 0; +-- +1.7.1 + + diff --git a/series b/series index 87e65d38..5c113ca4 100644 --- a/series +++ b/series @@ -26,6 +26,7 @@ fix-calculation-of-meta_bg-descriptor-backups ensure-entering-into-panic-after-recording-an-error-in-superblock explicit-mount-options-parsing-cleanup +do-not-allow-journal_opts-for-fs-wo-journal ########################################## # unstable patches diff --git a/timestamps b/timestamps index 2840ba4c..42b8e339 100755 --- a/timestamps +++ b/timestamps @@ -47,7 +47,8 @@ touch -d @1445135709 fix-checkpoint-list-cleanup touch -d @1445137026 fix-potential-use-after-free-in-ext4_journal-stop touch -d @1445142989 fix-calculation-of-meta_bg-descriptor-backups touch -d @1445202176 ensure-entering-into-panic-after-recording-an-error-in-superblock -touch -d @1445202193 status touch -d @1445225732 explicit-mount-options-parsing-cleanup -touch -d @1445226423 series -touch -d @1445226427 timestamps +touch -d @1445226434 status +touch -d @1445226626 do-not-allow-journal_opts-for-fs-wo-journal +touch -d @1445226642 series +touch -d @1445226644 timestamps -- 2.11.4.GIT