Update make-the-bitmap-read-routines-return-real-errors-code to not
[ext4-patch-queue.git] / do-not-allow-journal_opts-for-fs-wo-journal
blob041bb35b1729d37f5f40dfd9aa0647837dde9a8a
1 ext4: do not allow journal_opts for fs w/o journal
3 From: Dmitry Monakhov <dmonakhov@openvz.org>
5 It is appeared that we can pass journal related mount options and such options
6 be shown in /proc/mounts
8 Example:
9 #mkfs.ext4 -F /dev/vdb
10 #tune2fs -O ^has_journal /dev/vdb
11 #mount /dev/vdb /mnt/  -ocommit=20,journal_async_commit
12 #cat /proc/mounts  | grep /mnt
13  /dev/vdb /mnt ext4 rw,relatime,journal_checksum,journal_async_commit,commit=20,data=ordered 0 0
15 But options:"journal_checksum,journal_async_commit,commit=20,data=ordered" has
16 nothing with reality because there is no journal at all.
18 This patch disallow following options for journalless configurations:
19  - journal_checksum
20  - journal_async_commit
21  - commit=%ld
22  - data={writeback,ordered,journal}
24 Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
25 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
26 Reviewed-by: Andreas Dilger <adilger@dilger.ca>
27 ---
28  fs/ext4/ext4.h  |    3 +++
29  fs/ext4/super.c |   31 +++++++++++++++++++++++++++++--
30  2 files changed, 32 insertions(+), 2 deletions(-)
32 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
33 index 3f248c9..871cdc6 100644
34 --- a/fs/ext4/ext4.h
35 +++ b/fs/ext4/ext4.h
36 @@ -1019,6 +1019,9 @@ struct ext4_inode_info {
37  #define EXT4_MOUNT2_HURD_COMPAT                0x00000004 /* Support HURD-castrated
38                                                       file systems */
40 +#define EXT4_MOUNT2_EXPLICIT_JOURNAL_CHECKSUM  0x00000008 /* User explicitly
41 +                                               specified journal checksum */
43  #define clear_opt(sb, opt)             EXT4_SB(sb)->s_mount_opt &= \
44                                                 ~EXT4_MOUNT_##opt
45  #define set_opt(sb, opt)               EXT4_SB(sb)->s_mount_opt |= \
46 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
47 index e91f6d4..a29b32b 100644
48 --- a/fs/ext4/super.c
49 +++ b/fs/ext4/super.c
50 @@ -1371,10 +1371,10 @@ static const struct mount_opts {
51         {Opt_nojournal_checksum, EXT4_MOUNT_JOURNAL_CHECKSUM,
52          MOPT_EXT4_ONLY | MOPT_CLEAR},
53         {Opt_journal_checksum, EXT4_MOUNT_JOURNAL_CHECKSUM,
54 -        MOPT_EXT4_ONLY | MOPT_SET},
55 +        MOPT_EXT4_ONLY | MOPT_SET | MOPT_EXPLICIT},
56         {Opt_journal_async_commit, (EXT4_MOUNT_JOURNAL_ASYNC_COMMIT |
57                                     EXT4_MOUNT_JOURNAL_CHECKSUM),
58 -        MOPT_EXT4_ONLY | MOPT_SET},
59 +        MOPT_EXT4_ONLY | MOPT_SET | MOPT_EXPLICIT},
60         {Opt_noload, EXT4_MOUNT_NOLOAD, MOPT_NO_EXT2 | MOPT_SET},
61         {Opt_err_panic, EXT4_MOUNT_ERRORS_PANIC, MOPT_SET | MOPT_CLEAR_ERR},
62         {Opt_err_ro, EXT4_MOUNT_ERRORS_RO, MOPT_SET | MOPT_CLEAR_ERR},
63 @@ -1506,6 +1506,8 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
64         if (m->flags & MOPT_EXPLICIT) {
65                 if (m->mount_opt & EXT4_MOUNT_DELALLOC) {
66                         set_opt2(sb, EXPLICIT_DELALLOC);
67 +               } else if (m->mount_opt & EXT4_MOUNT_JOURNAL_CHECKSUM) {
68 +                       set_opt2(sb, EXPLICIT_JOURNAL_CHECKSUM);
69                 } else
70                         return -1;
71         }
72 @@ -3675,6 +3677,31 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
73                        "suppressed and not mounted read-only");
74                 goto failed_mount_wq;
75         } else {
76 +               /* Nojournal mode, all journal mount options are illegal */
77 +               if (test_opt2(sb, EXPLICIT_JOURNAL_CHECKSUM)) {
78 +                       ext4_msg(sb, KERN_ERR, "can't mount with "
79 +                                "journal_checksum, fs mounted w/o journal");
80 +                       goto failed_mount_wq;
81 +               }
82 +               if (test_opt(sb, JOURNAL_ASYNC_COMMIT)) {
83 +                       ext4_msg(sb, KERN_ERR, "can't mount with "
84 +                                "journal_async_commit, fs mounted w/o journal");
85 +                       goto failed_mount_wq;
86 +               }
87 +               if (sbi->s_commit_interval != JBD2_DEFAULT_MAX_COMMIT_AGE*HZ) {
88 +                       ext4_msg(sb, KERN_ERR, "can't mount with "
89 +                                "commit=%lu, fs mounted w/o journal",
90 +                                sbi->s_commit_interval / HZ);
91 +                       goto failed_mount_wq;
92 +               }
93 +               if (EXT4_MOUNT_DATA_FLAGS &
94 +                   (sbi->s_mount_opt ^ sbi->s_def_mount_opt)) {
95 +                       ext4_msg(sb, KERN_ERR, "can't mount with "
96 +                                "data=, fs mounted w/o journal");
97 +                       goto failed_mount_wq;
98 +               }
99 +               sbi->s_def_mount_opt &= EXT4_MOUNT_JOURNAL_CHECKSUM;
100 +               clear_opt(sb, JOURNAL_CHECKSUM);
101                 clear_opt(sb, DATA_FLAGS);
102                 sbi->s_journal = NULL;
103                 needs_recovery = 0;
104 -- 
105 1.7.1