Whamcloud - gitweb
70f04bb10e6dd54b81858032a7372adf4a8db64f
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / rhel6.4 / ext4-mmp.patch
1 Prevent an ext4 filesystem from being mounted multiple times.
2 A sequence number is stored on disk and is periodically updated (every 5
3 seconds by default) by a mounted filesystem.
4 At mount time, we now wait for s_mmp_update_interval seconds to make sure
5 that the MMP sequence does not change.
6 In case of failure, the nodename, bdevname and the time at which the MMP
7 block was last updated is displayed.
8 Move all mmp code to a dedicated file (mmp.c).
9
10 Signed-off-by: Andreas Dilger <adilger <at> whamcloud.com>
11 Signed-off-by: Johann Lombardi <johann <at> whamcloud.com>
12 ---
13  fs/ext4/Makefile |    3 +-
14  fs/ext4/ext4.h   |   76 ++++++++++++-
15  fs/ext4/mmp.c    |  354 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
16  fs/ext4/super.c  |   18 +++-
17  4 files changed, 447 insertions(+), 4 deletions(-)
18  create mode 100644 fs/ext4/mmp.c
19
20 Index: linux-stage/fs/ext4/Makefile
21 ===================================================================
22 --- linux-stage.orig/fs/ext4/Makefile
23 +++ linux-stage/fs/ext4/Makefile
24 @@ -6,7 +6,8 @@ obj-$(CONFIG_EXT4_FS) += ext4.o
25  
26  ext4-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
27                 ioctl.o namei.o super.o symlink.o hash.o resize.o extents.o \
28 -               ext4_jbd2.o migrate.o mballoc.o block_validity.o move_extent.o
29 +               ext4_jbd2.o migrate.o mballoc.o block_validity.o move_extent.o \
30 +               mmp.o
31  
32  ext4-$(CONFIG_EXT4_FS_XATTR)           += xattr.o xattr_user.o xattr_trusted.o
33  ext4-$(CONFIG_EXT4_FS_POSIX_ACL)       += acl.o
34 Index: linux-stage/fs/ext4/ext4.h
35 ===================================================================
36 --- linux-stage.orig/fs/ext4/ext4.h
37 +++ linux-stage/fs/ext4/ext4.h
38 @@ -1009,7 +1009,7 @@ struct ext4_super_block {
39         __le16  s_want_extra_isize;     /* New inodes should reserve # bytes */
40         __le32  s_flags;                /* Miscellaneous flags */
41         __le16  s_raid_stride;          /* RAID stride */
42 -       __le16  s_mmp_interval;         /* # seconds to wait in MMP checking */
43 +       __le16  s_mmp_update_interval;  /* # seconds to wait in MMP checking */
44         __le64  s_mmp_block;            /* Block for multi-mount protection */
45         __le32  s_raid_stripe_width;    /* blocks on all data disks (N*stride)*/
46         __u8    s_log_groups_per_flex;  /* FLEX_BG group size */
47 @@ -1177,6 +1177,9 @@ struct ext4_sb_info {
48         /* workqueue for dio unwritten */
49         struct workqueue_struct *dio_unwritten_wq;
50  
51 +       /* Kernel thread for multiple mount protection */
52 +       struct task_struct *s_mmp_tsk;
53 +
54         /* Lazy inode table initialization info */
55         struct ext4_li_request *s_li_request;
56         /* Wait multiplier for lazy initialization thread */
57 @@ -1322,7 +1325,8 @@ EXT4_INODE_BIT_FNS(state, state_flags)
58                                          EXT4_FEATURE_INCOMPAT_META_BG| \
59                                          EXT4_FEATURE_INCOMPAT_EXTENTS| \
60                                          EXT4_FEATURE_INCOMPAT_64BIT| \
61 -                                        EXT4_FEATURE_INCOMPAT_FLEX_BG)
62 +                                        EXT4_FEATURE_INCOMPAT_FLEX_BG| \
63 +                                        EXT4_FEATURE_INCOMPAT_MMP)
64  #define EXT4_FEATURE_RO_COMPAT_SUPP    (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \
65                                          EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \
66                                          EXT4_FEATURE_RO_COMPAT_GDT_CSUM| \
67 @@ -1576,6 +1580,67 @@ struct ext4_features {
68  };
69  
70  /*
71 + * This structure will be used for multiple mount protection. It will be
72 + * written into the block number saved in the s_mmp_block field in the
73 + * superblock. Programs that check MMP should assume that if
74 + * SEQ_FSCK (or any unknown code above SEQ_MAX) is present then it is NOT safe
75 + * to use the filesystem, regardless of how old the timestamp is.
76 + */
77 +#define EXT4_MMP_MAGIC     0x004D4D50U /* ASCII for MMP */
78 +#define EXT4_MMP_SEQ_CLEAN 0xFF4D4D50U /* mmp_seq value for clean unmount */
79 +#define EXT4_MMP_SEQ_FSCK  0xE24D4D50U /* mmp_seq value when being fscked */
80 +#define EXT4_MMP_SEQ_MAX   0xE24D4D4FU /* maximum valid mmp_seq value */
81 +
82 +struct mmp_struct {
83 +       __le32  mmp_magic;              /* Magic number for MMP */
84 +       __le32  mmp_seq;                /* Sequence no. updated periodically */
85 +
86 +       /*
87 +        * mmp_time, mmp_nodename & mmp_bdevname are only used for information
88 +        * purposes and do not affect the correctness of the algorithm
89 +        */
90 +       __le64  mmp_time;               /* Time last updated */
91 +       char    mmp_nodename[64];       /* Node which last updated MMP block */
92 +       char    mmp_bdevname[32];       /* Bdev which last updated MMP block */
93 +
94 +       /*
95 +        * mmp_check_interval is used to verify if the MMP block has been
96 +        * updated on the block device. The value is updated based on the
97 +        * maximum time to write the MMP block during an update cycle.
98 +        */
99 +       __le16  mmp_check_interval;
100 +
101 +       __le16  mmp_pad1;
102 +       __le32  mmp_pad2[227];
103 +};
104 +
105 +/* arguments passed to the mmp thread */
106 +struct mmpd_data {
107 +       struct buffer_head *bh; /* bh from initial read_mmp_block() */
108 +       struct super_block *sb;  /* super block of the fs */
109 +};
110 +
111 +/*
112 + * Check interval multiplier
113 + * The MMP block is written every update interval and initially checked every
114 + * update interval x the multiplier (the value is then adapted based on the
115 + * write latency). The reason is that writes can be delayed under load and we
116 + * don't want readers to incorrectly assume that the filesystem is no longer
117 + * in use.
118 + */
119 +#define EXT4_MMP_CHECK_MULT            2UL
120 +
121 +/*
122 + * Minimum interval for MMP checking in seconds.
123 + */
124 +#define EXT4_MMP_MIN_CHECK_INTERVAL    5UL
125 +
126 +/*
127 + * Maximum interval for MMP checking in seconds.
128 + */
129 +#define EXT4_MMP_MAX_CHECK_INTERVAL    300UL
130 +
131 +/*
132   * Function prototypes
133   */
134  
135 @@ -1757,6 +1822,10 @@ extern void __ext4_warning(struct super_
136  #define ext4_warning(sb, message...)   __ext4_warning(sb, __func__, ## message)
137  extern void ext4_msg(struct super_block *, const char *, const char *, ...)
138         __attribute__ ((format (printf, 3, 4)));
139 +extern void __dump_mmp_msg(struct super_block *, struct mmp_struct *mmp,
140 +                          const char *, const char *);
141 +#define dump_mmp_msg(sb, mmp, msg)     __dump_mmp_msg(sb, mmp, __func__, \
142 +                                                      msg)
143  extern void ext4_grp_locked_error(struct super_block *, ext4_group_t,
144                                 const char *, const char *, ...)
145         __attribute__ ((format (printf, 4, 5)));
146 @@ -2050,6 +2119,8 @@ extern int ext4_move_extents(struct file
147                              __u64 start_orig, __u64 start_donor,
148                              __u64 len, __u64 *moved_len);
149  
150 +/* mmp.c */
151 +extern int ext4_multi_mount_protect(struct super_block *, ext4_fsblk_t);
152  
153  /*
154   * Add new method to test wether block and inode bitmaps are properly
155 Index: linux-stage/fs/ext4/mmp.c
156 ===================================================================
157 --- /dev/null
158 +++ linux-stage/fs/ext4/mmp.c
159 @@ -0,0 +1,357 @@
160 +#include <linux/fs.h>
161 +#include <linux/random.h>
162 +#include <linux/buffer_head.h>
163 +#include <linux/utsname.h>
164 +#include <linux/kthread.h>
165 +
166 +#include "ext4.h"
167 +
168 +/*
169 + * Write the MMP block using WRITE_SYNC to try to get the block on-disk
170 + * faster.
171 + */
172 +static int write_mmp_block(struct buffer_head *bh)
173 +{
174 +       mark_buffer_dirty(bh);
175 +       lock_buffer(bh);
176 +       bh->b_end_io = end_buffer_write_sync;
177 +       get_bh(bh);
178 +       submit_bh(WRITE_SYNC, bh);
179 +       wait_on_buffer(bh);
180 +       if (unlikely(!buffer_uptodate(bh)))
181 +               return 1;
182 +
183 +       return 0;
184 +}
185 +
186 +/*
187 + * Read the MMP block. It _must_ be read from disk and hence we clear the
188 + * uptodate flag on the buffer.
189 + */
190 +static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
191 +                         ext4_fsblk_t mmp_block)
192 +{
193 +       struct mmp_struct *mmp;
194 +
195 +       if (*bh)
196 +               clear_buffer_uptodate(*bh);
197 +
198 +       /* This would be sb_bread(sb, mmp_block), except we need to be sure
199 +        * that the MD RAID device cache has been bypassed, and that the read
200 +        * is not blocked in the elevator. */
201 +       if (!*bh)
202 +               *bh = sb_getblk(sb, mmp_block);
203 +       if (*bh) {
204 +               get_bh(*bh);
205 +               lock_buffer(*bh);
206 +               (*bh)->b_end_io = end_buffer_read_sync;
207 +               submit_bh(READ_SYNC, *bh);
208 +               wait_on_buffer(*bh);
209 +               if (!buffer_uptodate(*bh)) {
210 +                       brelse(*bh);
211 +                       *bh = NULL;
212 +               }
213 +       }
214 +       if (!*bh) {
215 +               ext4_warning(sb, "Error while reading MMP block %llu",
216 +                            mmp_block);
217 +               return -EIO;
218 +       }
219 +
220 +       mmp = (struct mmp_struct *)((*bh)->b_data);
221 +       if (le32_to_cpu(mmp->mmp_magic) != EXT4_MMP_MAGIC) {
222 +               brelse(*bh);
223 +               *bh = NULL;
224 +               return -EINVAL;
225 +       }
226 +
227 +       return 0;
228 +}
229 +
230 +/*
231 + * Dump as much information as possible to help the admin.
232 + */
233 +void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
234 +                   const char *function, const char *msg)
235 +{
236 +       __ext4_warning(sb, function, msg);
237 +       __ext4_warning(sb, function,
238 +                      "MMP failure info: last update time: %llu, last update "
239 +                      "node: %s, last update device: %s\n",
240 +                      (long long unsigned int) le64_to_cpu(mmp->mmp_time),
241 +                      mmp->mmp_nodename, mmp->mmp_bdevname);
242 +}
243 +
244 +/*
245 + * kmmpd will update the MMP sequence every s_mmp_update_interval seconds
246 + */
247 +static int kmmpd(void *data)
248 +{
249 +       struct super_block *sb = ((struct mmpd_data *) data)->sb;
250 +       struct buffer_head *bh = ((struct mmpd_data *) data)->bh;
251 +       struct ext4_super_block *es = EXT4_SB(sb)->s_es;
252 +       struct mmp_struct *mmp;
253 +       ext4_fsblk_t mmp_block;
254 +       u32 seq = 0;
255 +       unsigned long failed_writes = 0;
256 +       int mmp_update_interval = le16_to_cpu(es->s_mmp_update_interval);
257 +       unsigned mmp_check_interval;
258 +       unsigned long last_update_time;
259 +       unsigned long diff;
260 +       int retval;
261 +
262 +       mmp_block = le64_to_cpu(es->s_mmp_block);
263 +       mmp = (struct mmp_struct *)(bh->b_data);
264 +       mmp->mmp_time = cpu_to_le64(get_seconds());
265 +       /*
266 +        * Start with the higher mmp_check_interval and reduce it if
267 +        * the MMP block is being updated on time.
268 +        */
269 +       mmp_check_interval = max(EXT4_MMP_CHECK_MULT * mmp_update_interval,
270 +                                EXT4_MMP_MIN_CHECK_INTERVAL);
271 +       mmp->mmp_check_interval = cpu_to_le16(mmp_check_interval);
272 +       bdevname(bh->b_bdev, mmp->mmp_bdevname);
273 +
274 +       memcpy(mmp->mmp_nodename, init_utsname()->nodename,
275 +              sizeof(mmp->mmp_nodename));
276 +
277 +       while (!kthread_should_stop()) {
278 +               if (++seq > EXT4_MMP_SEQ_MAX)
279 +                       seq = 1;
280 +
281 +               mmp->mmp_seq = cpu_to_le32(seq);
282 +               mmp->mmp_time = cpu_to_le64(get_seconds());
283 +               last_update_time = jiffies;
284 +
285 +               retval = write_mmp_block(bh);
286 +               /*
287 +                * Don't spew too many error messages. Print one every
288 +                * (s_mmp_update_interval * 60) seconds.
289 +                */
290 +               if (retval) {
291 +                       if ((failed_writes % 60) == 0)
292 +                               ext4_error(sb, "Error writing to MMP block");
293 +                       failed_writes++;
294 +               }
295 +
296 +               if (!(le32_to_cpu(es->s_feature_incompat) &
297 +                   EXT4_FEATURE_INCOMPAT_MMP)) {
298 +                       ext4_warning(sb, "kmmpd being stopped since MMP feature"
299 +                                    " has been disabled.");
300 +                       EXT4_SB(sb)->s_mmp_tsk = NULL;
301 +                       goto failed;
302 +               }
303 +
304 +               if (sb->s_flags & MS_RDONLY) {
305 +                       ext4_warning(sb, "kmmpd being stopped since filesystem "
306 +                                    "has been remounted as readonly.");
307 +                       EXT4_SB(sb)->s_mmp_tsk = NULL;
308 +                       goto failed;
309 +               }
310 +
311 +               diff = jiffies - last_update_time;
312 +               if (diff < mmp_update_interval * msecs_to_jiffies(MSEC_PER_SEC))
313 +                       schedule_timeout_interruptible(mmp_update_interval *
314 +                               msecs_to_jiffies(MSEC_PER_SEC) - diff);
315 +
316 +               /*
317 +                * We need to make sure that more than mmp_check_interval
318 +                * seconds have not passed since writing. If that has happened
319 +                * we need to check if the MMP block is as we left it.
320 +                */
321 +               diff = jiffies - last_update_time;
322 +               if (diff > mmp_check_interval * msecs_to_jiffies(MSEC_PER_SEC)) {
323 +                       struct buffer_head *bh_check = NULL;
324 +                       struct mmp_struct *mmp_check;
325 +
326 +                       retval = read_mmp_block(sb, &bh_check, mmp_block);
327 +                       if (retval) {
328 +                               ext4_error(sb, "error reading MMP data: %d",
329 +                                          retval);
330 +                               EXT4_SB(sb)->s_mmp_tsk = NULL;
331 +                               goto failed;
332 +                       }
333 +
334 +                       mmp_check = (struct mmp_struct *)(bh_check->b_data);
335 +                       if (mmp->mmp_seq != mmp_check->mmp_seq ||
336 +                           memcmp(mmp->mmp_nodename, mmp_check->mmp_nodename,
337 +                                  sizeof(mmp->mmp_nodename))) {
338 +                               dump_mmp_msg(sb, mmp_check,
339 +                                            "Error while updating MMP info. "
340 +                                            "The filesystem seems to have been"
341 +                                            " multiply mounted.");
342 +                               ext4_error(sb, "abort");
343 +                               put_bh(bh_check);
344 +                               goto failed;
345 +                       }
346 +                       put_bh(bh_check);
347 +               }
348 +
349 +               /*
350 +                * Adjust the mmp_check_interval depending on how much time
351 +                * it took for the MMP block to be written.
352 +                */
353 +               mmp_check_interval = max(min(EXT4_MMP_CHECK_MULT * diff /
354 +                                            msecs_to_jiffies(MSEC_PER_SEC),
355 +                                            EXT4_MMP_MAX_CHECK_INTERVAL),
356 +                                        EXT4_MMP_MIN_CHECK_INTERVAL);
357 +               mmp->mmp_check_interval = cpu_to_le16(mmp_check_interval);
358 +       }
359 +
360 +       /*
361 +        * Unmount seems to be clean.
362 +        */
363 +       mmp->mmp_seq = cpu_to_le32(EXT4_MMP_SEQ_CLEAN);
364 +       mmp->mmp_time = cpu_to_le64(get_seconds());
365 +
366 +       retval = write_mmp_block(bh);
367 +
368 +failed:
369 +       kfree(data);
370 +       brelse(bh);
371 +       return retval;
372 +}
373 +
374 +/*
375 + * Get a random new sequence number but make sure it is not greater than
376 + * EXT4_MMP_SEQ_MAX.
377 + */
378 +static unsigned int mmp_new_seq(void)
379 +{
380 +       u32 new_seq;
381 +
382 +       do {
383 +               get_random_bytes(&new_seq, sizeof(u32));
384 +       } while (new_seq > EXT4_MMP_SEQ_MAX);
385 +
386 +       return new_seq;
387 +}
388 +
389 +/*
390 + * Protect the filesystem from being mounted more than once.
391 + */
392 +int ext4_multi_mount_protect(struct super_block *sb,
393 +                                   ext4_fsblk_t mmp_block)
394 +{
395 +       struct ext4_super_block *es = EXT4_SB(sb)->s_es;
396 +       struct buffer_head *bh = NULL;
397 +       struct mmp_struct *mmp = NULL;
398 +       struct mmpd_data *mmpd_data;
399 +       u32 seq;
400 +       unsigned int mmp_check_interval = le16_to_cpu(es->s_mmp_update_interval);
401 +       unsigned int wait_time = 0;
402 +       int retval;
403 +
404 +       if (mmp_block < le32_to_cpu(es->s_first_data_block) ||
405 +           mmp_block >= ext4_blocks_count(es)) {
406 +               ext4_warning(sb, "Invalid MMP block in superblock");
407 +               goto failed;
408 +       }
409 +
410 +       retval = read_mmp_block(sb, &bh, mmp_block);
411 +       if (retval)
412 +               goto failed;
413 +
414 +       mmp = (struct mmp_struct *)(bh->b_data);
415 +
416 +       if (mmp_check_interval < EXT4_MMP_MIN_CHECK_INTERVAL)
417 +               mmp_check_interval = EXT4_MMP_MIN_CHECK_INTERVAL;
418 +
419 +       /*
420 +        * If check_interval in MMP block is larger, use that instead of
421 +        * update_interval from the superblock.
422 +        */
423 +       if (mmp->mmp_check_interval > mmp_check_interval)
424 +               mmp_check_interval = mmp->mmp_check_interval;
425 +
426 +       seq = le32_to_cpu(mmp->mmp_seq);
427 +       if (seq == EXT4_MMP_SEQ_CLEAN)
428 +               goto skip;
429 +
430 +       if (seq == EXT4_MMP_SEQ_FSCK) {
431 +               dump_mmp_msg(sb, mmp, "fsck is running on the filesystem");
432 +               goto failed;
433 +       }
434 +
435 +       wait_time = min(mmp_check_interval * 2 + 1,
436 +                       mmp_check_interval + 60);
437 +
438 +       /* Print MMP interval if more than 20 secs. */
439 +       if (wait_time > EXT4_MMP_MIN_CHECK_INTERVAL * 4)
440 +               ext4_warning(sb, "MMP interval %u higher than expected, please"
441 +                            " wait.\n", wait_time * 2);
442 +
443 +       if (schedule_timeout_interruptible(msecs_to_jiffies(MSEC_PER_SEC) *
444 +                                          wait_time) != 0) {
445 +               ext4_warning(sb, "MMP startup interrupted, failing mount\n");
446 +               goto failed;
447 +       }
448 +
449 +       retval = read_mmp_block(sb, &bh, mmp_block);
450 +       if (retval)
451 +               goto failed;
452 +       mmp = (struct mmp_struct *)(bh->b_data);
453 +       if (seq != le32_to_cpu(mmp->mmp_seq)) {
454 +               dump_mmp_msg(sb, mmp,
455 +                            "Device is already active on another node.");
456 +               goto failed;
457 +       }
458 +
459 +skip:
460 +       /*
461 +        * write a new random sequence number.
462 +        */
463 +       mmp->mmp_seq = seq = cpu_to_le32(mmp_new_seq());
464 +
465 +       retval = write_mmp_block(bh);
466 +       if (retval)
467 +               goto failed;
468 +
469 +       /*
470 +        * wait for MMP interval and check mmp_seq.
471 +        */
472 +       if (schedule_timeout_interruptible(msecs_to_jiffies(MSEC_PER_SEC) *
473 +                                          wait_time) != 0) {
474 +               ext4_warning(sb, "MMP startup interrupted, failing mount\n");
475 +               goto failed;
476 +       }
477 +
478 +       retval = read_mmp_block(sb, &bh, mmp_block);
479 +       if (retval)
480 +               goto failed;
481 +       mmp = (struct mmp_struct *)(bh->b_data);
482 +       if (seq != le32_to_cpu(mmp->mmp_seq)) {
483 +               dump_mmp_msg(sb, mmp,
484 +                            "Device is already active on another node.");
485 +               goto failed;
486 +       }
487 +
488 +       mmpd_data = kmalloc(sizeof(struct mmpd_data), GFP_KERNEL);
489 +       if (!mmpd_data) {
490 +               ext4_warning(sb, "not enough memory for mmpd_data");
491 +               goto failed;
492 +       }
493 +       mmpd_data->sb = sb;
494 +       mmpd_data->bh = bh;
495 +
496 +       /*
497 +        * Start a kernel thread to update the MMP block periodically.
498 +        */
499 +       EXT4_SB(sb)->s_mmp_tsk = kthread_run(kmmpd, mmpd_data, "kmmpd-%s",
500 +                                            bdevname(bh->b_bdev,
501 +                                                     mmp->mmp_bdevname));
502 +       if (IS_ERR(EXT4_SB(sb)->s_mmp_tsk)) {
503 +               EXT4_SB(sb)->s_mmp_tsk = NULL;
504 +               kfree(mmpd_data);
505 +               ext4_warning(sb, "Unable to create kmmpd thread for %s.",
506 +                            sb->s_id);
507 +               goto failed;
508 +       }
509 +
510 +       return 0;
511 +
512 +failed:
513 +       brelse(bh);
514 +       return 1;
515 +}
516 +
517 Index: linux-stage/fs/ext4/super.c
518 ===================================================================
519 --- linux-stage.orig/fs/ext4/super.c
520 +++ linux-stage/fs/ext4/super.c
521 @@ -40,6 +40,8 @@
522  #include <linux/log2.h>
523  #include <linux/crc16.h>
524  #include <asm/uaccess.h>
525 +#include <linux/kthread.h>
526 +#include <linux/utsname.h>
527  
528  #include <linux/kthread.h>
529  #include <linux/freezer.h>
530 @@ -716,6 +718,8 @@ static void ext4_put_super(struct super_
531                 invalidate_bdev(sbi->journal_bdev);
532                 ext4_blkdev_remove(sbi);
533         }
534 +       if (sbi->s_mmp_tsk)
535 +               kthread_stop(sbi->s_mmp_tsk);
536         sb->s_fs_info = NULL;
537         /*
538          * Now that we are completely done shutting down the
539 @@ -3241,6 +3245,10 @@ static int ext4_fill_super(struct super_
540         needs_recovery = (es->s_last_orphan != 0 ||
541                           EXT4_HAS_INCOMPAT_FEATURE(sb,
542                                     EXT4_FEATURE_INCOMPAT_RECOVER));
543 +       if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_MMP) &&
544 +           !(sb->s_flags & MS_RDONLY))
545 +               if (ext4_multi_mount_protect(sb, le64_to_cpu(es->s_mmp_block)))
546 +                       goto failed_mount3;
547  
548         /*
549          * The first inode we look at is the journal inode.  Don't try
550 @@ -3491,6 +3499,8 @@ failed_mount3:
551         percpu_counter_destroy(&sbi->s_freeinodes_counter);
552         percpu_counter_destroy(&sbi->s_dirs_counter);
553         percpu_counter_destroy(&sbi->s_dirtyblocks_counter);
554 +       if (sbi->s_mmp_tsk)
555 +               kthread_stop(sbi->s_mmp_tsk);
556  failed_mount2:
557         for (i = 0; i < db_count; i++)
558                 brelse(sbi->s_group_desc[i]);
559 @@ -4001,7 +4011,7 @@ static int ext4_remount(struct super_blo
560         int enable_quota = 0;
561         ext4_group_t g;
562         unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO;
563 -       int err;
564 +       int err = 0;
565  #ifdef CONFIG_QUOTA
566         int i;
567  #endif
568 @@ -4129,6 +4139,13 @@ static int ext4_remount(struct super_blo
569                                 goto restore_opts;
570                         if (!ext4_setup_super(sb, es, 0))
571                                 sb->s_flags &= ~MS_RDONLY;
572 +                       if (EXT4_HAS_INCOMPAT_FEATURE(sb,
573 +                                                   EXT4_FEATURE_INCOMPAT_MMP))
574 +                               if (ext4_multi_mount_protect(sb,
575 +                                               le64_to_cpu(es->s_mmp_block))) {
576 +                                       err = -EROFS;
577 +                                       goto restore_opts;
578 +                               }
579                         enable_quota = 1;
580                 }
581         }