Whamcloud - gitweb
LU-2337 scripts: init script to not use -d with zpool import
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / ext4-mmp-rhel5.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    |  351 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
16  fs/ext4/super.c  |   18 +++-
17  4 files changed, 444 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 iopen.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 @@ -878,7 +878,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 @@ -1032,6 +1032,9 @@ struct ext4_sb_info {
48  
49         /* workqueue for dio unwritten */
50         struct workqueue_struct *dio_unwritten_wq;
51 +
52 +       /* Kernel thread for multiple mount protection */
53 +       struct task_struct *s_mmp_tsk;
54  };
55  
56  static inline struct ext4_sb_info *EXT4_SB(struct super_block *sb)
57 @@ -1169,7 +1172,8 @@ static inline void ext4_clear_inode_stat
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 @@ -1376,6 +1380,67 @@ void ext4_get_group_no_and_offset(struct
68  extern struct proc_dir_entry *ext4_proc_root;
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 @@ -1547,6 +1612,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__, msg)
142 +
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 @@ -1784,6 +1853,9 @@ static inline void ext4_unlock_group(str
147         spin_unlock(ext4_group_lock_ptr(sb, group));
148  }
149  
150 +/* mmp.c */
151 +extern int ext4_multi_mount_protect(struct super_block *, ext4_fsblk_t);
152 +
153  /*
154   * Inodes and files operations
155   */
156 Index: linux-stage/fs/ext4/mmp.c
157 ===================================================================
158 --- /dev/null
159 +++ linux-stage/fs/ext4/mmp.c
160 @@ -0,0 +1,351 @@
161 +#include <linux/fs.h>
162 +#include <linux/random.h>
163 +#include <linux/buffer_head.h>
164 +#include <linux/utsname.h>
165 +#include <linux/kthread.h>
166 +
167 +#include "ext4.h"
168 +
169 +/*
170 + * Write the MMP block using WRITE_SYNC to try to get the block on-disk
171 + * faster.
172 + */
173 +static int write_mmp_block(struct buffer_head *bh)
174 +{
175 +       mark_buffer_dirty(bh);
176 +       lock_buffer(bh);
177 +       bh->b_end_io = end_buffer_write_sync;
178 +       get_bh(bh);
179 +       submit_bh(WRITE_SYNC, bh);
180 +       wait_on_buffer(bh);
181 +       if (unlikely(!buffer_uptodate(bh)))
182 +               return 1;
183 +
184 +       return 0;
185 +}
186 +
187 +/*
188 + * Read the MMP block. It _must_ be read from disk and hence we clear the
189 + * uptodate flag on the buffer.
190 + */
191 +static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
192 +                         ext4_fsblk_t mmp_block)
193 +{
194 +       struct mmp_struct *mmp;
195 +
196 +       if (*bh)
197 +               clear_buffer_uptodate(*bh);
198 +
199 +       /* This would be sb_bread(sb, mmp_block), except we need to be sure
200 +        * that the MD RAID device cache has been bypassed, and that the read
201 +        * is not blocked in the elevator. */
202 +       if (!*bh)
203 +               *bh = sb_getblk(sb, mmp_block);
204 +       if (*bh) {
205 +               get_bh(*bh);
206 +               lock_buffer(*bh);
207 +               (*bh)->b_end_io = end_buffer_read_sync;
208 +               submit_bh(READ_SYNC, *bh);
209 +               wait_on_buffer(*bh);
210 +               if (!buffer_uptodate(*bh)) {
211 +                       brelse(*bh);
212 +                       *bh = NULL;
213 +               }
214 +       }
215 +       if (!*bh) {
216 +               ext4_warning(sb, "Error while reading MMP block %llu",
217 +                            mmp_block);
218 +               return -EIO;
219 +       }
220 +
221 +       mmp = (struct mmp_struct *)((*bh)->b_data);
222 +       if (le32_to_cpu(mmp->mmp_magic) != EXT4_MMP_MAGIC)
223 +               return -EINVAL;
224 +
225 +       return 0;
226 +}
227 +
228 +/*
229 + * Dump as much information as possible to help the admin.
230 + */
231 +void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
232 +                   const char *function, const char *msg)
233 +{
234 +       __ext4_warning(sb, function, "%s", msg);
235 +       __ext4_warning(sb, function,
236 +                      "MMP failure info: last update time: %llu, last update "
237 +                      "node: %s, last update device: %s\n",
238 +                      (long long unsigned int) le64_to_cpu(mmp->mmp_time),
239 +                      mmp->mmp_nodename, mmp->mmp_bdevname);
240 +}
241 +
242 +/*
243 + * kmmpd will update the MMP sequence every s_mmp_update_interval seconds
244 + */
245 +static int kmmpd(void *data)
246 +{
247 +       struct super_block *sb = ((struct mmpd_data *) data)->sb;
248 +       struct buffer_head *bh = ((struct mmpd_data *) data)->bh;
249 +       struct ext4_super_block *es = EXT4_SB(sb)->s_es;
250 +       struct mmp_struct *mmp;
251 +       ext4_fsblk_t mmp_block;
252 +       u32 seq = 0;
253 +       unsigned long failed_writes = 0;
254 +       int mmp_update_interval = le16_to_cpu(es->s_mmp_update_interval);
255 +       unsigned mmp_check_interval;
256 +       unsigned long last_update_time;
257 +       unsigned long diff;
258 +       int retval;
259 +
260 +       mmp_block = le64_to_cpu(es->s_mmp_block);
261 +       mmp = (struct mmp_struct *)(bh->b_data);
262 +       mmp->mmp_time = cpu_to_le64(get_seconds());
263 +       /*
264 +        * Start with the higher mmp_check_interval and reduce it if
265 +        * the MMP block is being updated on time.
266 +        */
267 +       mmp_check_interval = max(EXT4_MMP_CHECK_MULT * mmp_update_interval,
268 +                                EXT4_MMP_MIN_CHECK_INTERVAL);
269 +       mmp->mmp_check_interval = cpu_to_le16(mmp_check_interval);
270 +       bdevname(bh->b_bdev, mmp->mmp_bdevname);
271 +
272 +       memcpy(mmp->mmp_nodename, init_utsname()->sysname,
273 +              sizeof(mmp->mmp_nodename));
274 +
275 +       while (!kthread_should_stop()) {
276 +               if (++seq > EXT4_MMP_SEQ_MAX)
277 +                       seq = 1;
278 +
279 +               mmp->mmp_seq = cpu_to_le32(seq);
280 +               mmp->mmp_time = cpu_to_le64(get_seconds());
281 +               last_update_time = jiffies;
282 +
283 +               retval = write_mmp_block(bh);
284 +               /*
285 +                * Don't spew too many error messages. Print one every
286 +                * (s_mmp_update_interval * 60) seconds.
287 +                */
288 +               if (retval) {
289 +                       if ((failed_writes % 60) == 0)
290 +                               ext4_error(sb, "Error writing to MMP block");
291 +                       failed_writes++;
292 +               }
293 +
294 +               if (!(le32_to_cpu(es->s_feature_incompat) &
295 +                   EXT4_FEATURE_INCOMPAT_MMP)) {
296 +                       ext4_warning(sb, "kmmpd being stopped since MMP feature"
297 +                                    " has been disabled.");
298 +                       EXT4_SB(sb)->s_mmp_tsk = NULL;
299 +                       goto failed;
300 +               }
301 +
302 +               if (sb->s_flags & MS_RDONLY) {
303 +                       ext4_warning(sb, "kmmpd being stopped since filesystem "
304 +                                    "has been remounted as readonly.");
305 +                       EXT4_SB(sb)->s_mmp_tsk = NULL;
306 +                       goto failed;
307 +               }
308 +
309 +               diff = jiffies - last_update_time;
310 +               if (diff < mmp_update_interval * HZ)
311 +                       schedule_timeout_interruptible(mmp_update_interval *
312 +                                                      HZ - diff);
313 +
314 +               /*
315 +                * We need to make sure that more than mmp_check_interval
316 +                * seconds have not passed since writing. If that has happened
317 +                * we need to check if the MMP block is as we left it.
318 +                */
319 +               diff = jiffies - last_update_time;
320 +               if (diff > mmp_check_interval * HZ) {
321 +                       struct buffer_head *bh_check = NULL;
322 +                       struct mmp_struct *mmp_check;
323 +
324 +                       retval = read_mmp_block(sb, &bh_check, mmp_block);
325 +                       if (retval) {
326 +                               ext4_error(sb, "error reading MMP data: %d",
327 +                                          retval);
328 +
329 +                               EXT4_SB(sb)->s_mmp_tsk = NULL;
330 +                               goto failed;
331 +                       }
332 +
333 +                       mmp_check = (struct mmp_struct *)(bh_check->b_data);
334 +                       if (mmp->mmp_seq != mmp_check->mmp_seq ||
335 +                           memcmp(mmp->mmp_nodename, mmp_check->mmp_nodename,
336 +                                  sizeof(mmp->mmp_nodename))) {
337 +                               dump_mmp_msg(sb, mmp_check,
338 +                                            "Error while updating MMP info. "
339 +                                            "The filesystem seems to have been"
340 +                                            " multiply mounted.");
341 +                               ext4_error(sb, "abort");
342 +                               goto failed;
343 +                       }
344 +                       put_bh(bh_check);
345 +               }
346 +
347 +                /*
348 +                * Adjust the mmp_check_interval depending on how much time
349 +                * it took for the MMP block to be written.
350 +                */
351 +               mmp_check_interval = max(min(EXT4_MMP_CHECK_MULT * diff / HZ,
352 +                                            EXT4_MMP_MAX_CHECK_INTERVAL),
353 +                                        EXT4_MMP_MIN_CHECK_INTERVAL);
354 +               mmp->mmp_check_interval = cpu_to_le16(mmp_check_interval);
355 +       }
356 +
357 +       /*
358 +        * Unmount seems to be clean.
359 +        */
360 +       mmp->mmp_seq = cpu_to_le32(EXT4_MMP_SEQ_CLEAN);
361 +       mmp->mmp_time = cpu_to_le64(get_seconds());
362 +
363 +       retval = write_mmp_block(bh);
364 +
365 +failed:
366 +       kfree(data);
367 +       brelse(bh);
368 +       return retval;
369 +}
370 +
371 +/*
372 + * Get a random new sequence number but make sure it is not greater than
373 + * EXT4_MMP_SEQ_MAX.
374 + */
375 +static unsigned int mmp_new_seq(void)
376 +{
377 +       u32 new_seq;
378 +
379 +       do {
380 +               get_random_bytes(&new_seq, sizeof(u32));
381 +       } while (new_seq > EXT4_MMP_SEQ_MAX);
382 +
383 +       return new_seq;
384 +}
385 +
386 +/*
387 + * Protect the filesystem from being mounted more than once.
388 + */
389 +int ext4_multi_mount_protect(struct super_block *sb,
390 +                                   ext4_fsblk_t mmp_block)
391 +{
392 +       struct ext4_super_block *es = EXT4_SB(sb)->s_es;
393 +       struct buffer_head *bh = NULL;
394 +       struct mmp_struct *mmp = NULL;
395 +       struct mmpd_data *mmpd_data;
396 +       u32 seq;
397 +       unsigned int mmp_check_interval = le16_to_cpu(es->s_mmp_update_interval);
398 +       unsigned int wait_time = 0;
399 +       int retval;
400 +
401 +       if (mmp_block < le32_to_cpu(es->s_first_data_block) ||
402 +           mmp_block >= ext4_blocks_count(es)) {
403 +               ext4_warning(sb, "Invalid MMP block in superblock");
404 +               goto failed;
405 +       }
406 +
407 +       retval = read_mmp_block(sb, &bh, mmp_block);
408 +       if (retval)
409 +               goto failed;
410 +
411 +       mmp = (struct mmp_struct *)(bh->b_data);
412 +
413 +       if (mmp_check_interval < EXT4_MMP_MIN_CHECK_INTERVAL)
414 +               mmp_check_interval = EXT4_MMP_MIN_CHECK_INTERVAL;
415 +
416 +       /*
417 +        * If check_interval in MMP block is larger, use that instead of
418 +        * update_interval from the superblock.
419 +        */
420 +       if (mmp->mmp_check_interval > mmp_check_interval)
421 +               mmp_check_interval = mmp->mmp_check_interval;
422 +
423 +       seq = le32_to_cpu(mmp->mmp_seq);
424 +       if (seq == EXT4_MMP_SEQ_CLEAN)
425 +               goto skip;
426 +
427 +       if (seq == EXT4_MMP_SEQ_FSCK) {
428 +               dump_mmp_msg(sb, mmp, "fsck is running on the filesystem");
429 +               goto failed;
430 +       }
431 +
432 +       wait_time = min(mmp_check_interval * 2 + 1,
433 +                       mmp_check_interval + 60);
434 +
435 +       /* Print MMP interval if more than 20 secs. */
436 +       if (wait_time > EXT4_MMP_MIN_CHECK_INTERVAL * 4)
437 +               ext4_warning(sb, "MMP interval %u higher than expected, please"
438 +                            " wait.\n", wait_time * 2);
439 +
440 +       if (schedule_timeout_interruptible(HZ * wait_time) != 0) {
441 +               ext4_warning(sb, "MMP startup interrupted, failing mount\n");
442 +               goto failed;
443 +       }
444 +
445 +       retval = read_mmp_block(sb, &bh, mmp_block);
446 +       if (retval)
447 +               goto failed;
448 +       mmp = (struct mmp_struct *)(bh->b_data);
449 +       if (seq != le32_to_cpu(mmp->mmp_seq)) {
450 +               dump_mmp_msg(sb, mmp,
451 +                            "Device is already active on another node.");
452 +               goto failed;
453 +       }
454 +
455 +skip:
456 +       /*
457 +        * write a new random sequence number.
458 +        */
459 +       mmp->mmp_seq = seq = cpu_to_le32(mmp_new_seq());
460 +
461 +       retval = write_mmp_block(bh);
462 +       if (retval)
463 +               goto failed;
464 +
465 +       /*
466 +        * wait for MMP interval and check mmp_seq.
467 +        */
468 +       if (schedule_timeout_interruptible(HZ * wait_time) != 0) {
469 +               ext4_warning(sb, "MMP startup interrupted, failing mount\n");
470 +               goto failed;
471 +       }
472 +
473 +       retval = read_mmp_block(sb, &bh, mmp_block);
474 +       if (retval)
475 +               goto failed;
476 +       mmp = (struct mmp_struct *)(bh->b_data);
477 +       if (seq != le32_to_cpu(mmp->mmp_seq)) {
478 +               dump_mmp_msg(sb, mmp,
479 +                            "Device is already active on another node.");
480 +               goto failed;
481 +       }
482 +
483 +       mmpd_data = kmalloc(sizeof(struct mmpd_data), GFP_KERNEL);
484 +       if (!mmpd_data) {
485 +               ext4_warning(sb, "not enough memory for mmpd_data");
486 +               goto failed;
487 +       }
488 +       mmpd_data->sb = sb;
489 +       mmpd_data->bh = bh;
490 +
491 +       /*
492 +        * Start a kernel thread to update the MMP block periodically.
493 +        */
494 +       EXT4_SB(sb)->s_mmp_tsk = kthread_run(kmmpd, mmpd_data, "kmmpd-%s",
495 +                                            bdevname(bh->b_bdev,
496 +                                                     mmp->mmp_bdevname));
497 +       if (IS_ERR(EXT4_SB(sb)->s_mmp_tsk)) {
498 +               EXT4_SB(sb)->s_mmp_tsk = NULL;
499 +               kfree(mmpd_data);
500 +               ext4_warning(sb, "Unable to create kmmpd thread for %s.",
501 +                            sb->s_id);
502 +               goto failed;
503 +       }
504 +
505 +       return 0;
506 +
507 +failed:
508 +       brelse(bh);
509 +       return 1;
510 +}
511 +
512 +
513 Index: linux-stage/fs/ext4/super.c
514 ===================================================================
515 --- linux-stage.orig/fs/ext4/super.c
516 +++ linux-stage/fs/ext4/super.c
517 @@ -40,6 +40,8 @@
518  #include <linux/log2.h>
519  #include <linux/crc16.h>
520  #include <asm/uaccess.h>
521 +#include <linux/kthread.h>
522 +#include <linux/utsname.h>
523  
524  #include "ext4.h"
525  #include "ext4_jbd2.h"
526 @@ -698,6 +700,8 @@ static void ext4_put_super(struct super_
527                 invalidate_bdev(sbi->journal_bdev, 0);
528                 ext4_blkdev_remove(sbi);
529         }
530 +       if (sbi->s_mmp_tsk)
531 +               kthread_stop(sbi->s_mmp_tsk);
532         sb->s_fs_info = NULL;
533         /*
534          * Now that we are completely done shutting down the
535 @@ -2810,6 +2814,11 @@ static int ext4_fill_super(struct super_
536                           EXT4_HAS_INCOMPAT_FEATURE(sb,
537                                     EXT4_FEATURE_INCOMPAT_RECOVER));
538  
539 +       if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_MMP) &&
540 +           !(sb->s_flags & MS_RDONLY))
541 +               if (ext4_multi_mount_protect(sb, le64_to_cpu(es->s_mmp_block)))
542 +                       goto failed_mount3;
543 +
544         /*
545          * The first inode we look at is the journal inode.  Don't try
546          * root first: it may be modified in the journal!
547 @@ -3048,6 +3057,8 @@ failed_mount3:
548         percpu_counter_destroy(&sbi->s_freeinodes_counter);
549         percpu_counter_destroy(&sbi->s_dirs_counter);
550         percpu_counter_destroy(&sbi->s_dirtyblocks_counter);
551 +       if (sbi->s_mmp_tsk)
552 +               kthread_stop(sbi->s_mmp_tsk);
553  failed_mount2:
554         for (i = 0; i < db_count; i++)
555                 brelse(sbi->s_group_desc[i]);
556 @@ -3557,7 +3568,7 @@ static int ext4_remount(struct super_blo
557         struct ext4_mount_options old_opts;
558         ext4_group_t g;
559         unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO;
560 -       int err;
561 +       int err = 0;
562  #ifdef CONFIG_QUOTA
563         int i;
564  #endif
565 @@ -3676,6 +3687,13 @@ static int ext4_remount(struct super_blo
566                                 goto restore_opts;
567                         if (!ext4_setup_super(sb, es, 0))
568                                 sb->s_flags &= ~MS_RDONLY;
569 +                       if (EXT4_HAS_INCOMPAT_FEATURE(sb,
570 +                                               EXT4_FEATURE_INCOMPAT_MMP))
571 +                               if (ext4_multi_mount_protect(sb,
572 +                                       le64_to_cpu(es->s_mmp_block))) {
573 +                                       err = -EROFS;
574 +                                       goto restore_opts;
575 +                               }
576                 }
577         }
578         ext4_setup_system_zone(sb);