Whamcloud - gitweb
LU-781 kernel: kernel update [RHEL6.2 2.6.32-220]
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / ext4-mmp-rhel6.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 \
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 @@ -893,7 +893,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 @@ -1040,6 +1040,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         /* Lazy inode table initialization info */
56         struct ext4_li_request *s_li_request;
57 @@ -1176,7 +1179,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 @@ -1383,6 +1387,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 @@ -1552,6 +1617,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 @@ -1833,6 +1902,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,351 @@
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 +               return -EINVAL;
223 +
224 +       return 0;
225 +}
226 +
227 +/*
228 + * Dump as much information as possible to help the admin.
229 + */
230 +void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
231 +                   const char *function, const char *msg)
232 +{
233 +       __ext4_warning(sb, function, msg);
234 +       __ext4_warning(sb, function,
235 +                      "MMP failure info: last update time: %llu, last update "
236 +                      "node: %s, last update device: %s\n",
237 +                      (long long unsigned int) le64_to_cpu(mmp->mmp_time),
238 +                      mmp->mmp_nodename, mmp->mmp_bdevname);
239 +}
240 +
241 +/*
242 + * kmmpd will update the MMP sequence every s_mmp_update_interval seconds
243 + */
244 +static int kmmpd(void *data)
245 +{
246 +       struct super_block *sb = ((struct mmpd_data *) data)->sb;
247 +       struct buffer_head *bh = ((struct mmpd_data *) data)->bh;
248 +       struct ext4_super_block *es = EXT4_SB(sb)->s_es;
249 +       struct mmp_struct *mmp;
250 +       ext4_fsblk_t mmp_block;
251 +       u32 seq = 0;
252 +       unsigned long failed_writes = 0;
253 +       int mmp_update_interval = le16_to_cpu(es->s_mmp_update_interval);
254 +       unsigned mmp_check_interval;
255 +       unsigned long last_update_time;
256 +       unsigned long diff;
257 +       int retval;
258 +
259 +       mmp_block = le64_to_cpu(es->s_mmp_block);
260 +       mmp = (struct mmp_struct *)(bh->b_data);
261 +       mmp->mmp_time = cpu_to_le64(get_seconds());
262 +       /*
263 +        * Start with the higher mmp_check_interval and reduce it if
264 +        * the MMP block is being updated on time.
265 +        */
266 +       mmp_check_interval = max(EXT4_MMP_CHECK_MULT * mmp_update_interval,
267 +                                EXT4_MMP_MIN_CHECK_INTERVAL);
268 +       mmp->mmp_check_interval = cpu_to_le16(mmp_check_interval);
269 +       bdevname(bh->b_bdev, mmp->mmp_bdevname);
270 +
271 +       memcpy(mmp->mmp_nodename, init_utsname()->nodename,
272 +              sizeof(mmp->mmp_nodename));
273 +
274 +       while (!kthread_should_stop()) {
275 +               if (++seq > EXT4_MMP_SEQ_MAX)
276 +                       seq = 1;
277 +
278 +               mmp->mmp_seq = cpu_to_le32(seq);
279 +               mmp->mmp_time = cpu_to_le64(get_seconds());
280 +               last_update_time = jiffies;
281 +
282 +               retval = write_mmp_block(bh);
283 +               /*
284 +                * Don't spew too many error messages. Print one every
285 +                * (s_mmp_update_interval * 60) seconds.
286 +                */
287 +               if (retval && (failed_writes % 60) == 0) {
288 +                       ext4_error(sb, "Error writing to MMP block");
289 +                       failed_writes++;
290 +               }
291 +
292 +               if (!(le32_to_cpu(es->s_feature_incompat) &
293 +                   EXT4_FEATURE_INCOMPAT_MMP)) {
294 +                       ext4_warning(sb, "kmmpd being stopped since MMP feature"
295 +                                    " has been disabled.");
296 +                       EXT4_SB(sb)->s_mmp_tsk = NULL;
297 +                       goto failed;
298 +               }
299 +
300 +               if (sb->s_flags & MS_RDONLY) {
301 +                       ext4_warning(sb, "kmmpd being stopped since filesystem "
302 +                                    "has been remounted as readonly.");
303 +                       EXT4_SB(sb)->s_mmp_tsk = NULL;
304 +                       goto failed;
305 +               }
306 +
307 +               diff = jiffies - last_update_time;
308 +               if (diff < mmp_update_interval * HZ)
309 +                       schedule_timeout_interruptible(mmp_update_interval *
310 +                                                      HZ - diff);
311 +
312 +               /*
313 +                * We need to make sure that more than mmp_check_interval
314 +                * seconds have not passed since writing. If that has happened
315 +                * we need to check if the MMP block is as we left it.
316 +                */
317 +               diff = jiffies - last_update_time;
318 +               if (diff > mmp_check_interval * HZ) {
319 +                       struct buffer_head *bh_check = NULL;
320 +                       struct mmp_struct *mmp_check;
321 +
322 +                       retval = read_mmp_block(sb, &bh_check, mmp_block);
323 +                       if (retval) {
324 +                               ext4_error(sb, "error reading MMP data: %d",
325 +                                          retval);
326 +
327 +                               EXT4_SB(sb)->s_mmp_tsk = NULL;
328 +                               goto failed;
329 +                       }
330 +
331 +                       mmp_check = (struct mmp_struct *)(bh_check->b_data);
332 +                       if (mmp->mmp_seq != mmp_check->mmp_seq ||
333 +                           memcmp(mmp->mmp_nodename, mmp_check->mmp_nodename,
334 +                                  sizeof(mmp->mmp_nodename))) {
335 +                               dump_mmp_msg(sb, mmp_check,
336 +                                            "Error while updating MMP info. "
337 +                                            "The filesystem seems to have been"
338 +                                            " multiply mounted.");
339 +                               ext4_error(sb, "abort");
340 +                               goto failed;
341 +                       }
342 +                       put_bh(bh_check);
343 +               }
344 +
345 +                /*
346 +                * Adjust the mmp_check_interval depending on how much time
347 +                * it took for the MMP block to be written.
348 +                */
349 +               mmp_check_interval = max(min(EXT4_MMP_CHECK_MULT * diff / HZ,
350 +                                            EXT4_MMP_MAX_CHECK_INTERVAL),
351 +                                        EXT4_MMP_MIN_CHECK_INTERVAL);
352 +               mmp->mmp_check_interval = cpu_to_le16(mmp_check_interval);
353 +       }
354 +
355 +       /*
356 +        * Unmount seems to be clean.
357 +        */
358 +       mmp->mmp_seq = cpu_to_le32(EXT4_MMP_SEQ_CLEAN);
359 +       mmp->mmp_time = cpu_to_le64(get_seconds());
360 +
361 +       retval = write_mmp_block(bh);
362 +
363 +failed:
364 +       kfree(data);
365 +       brelse(bh);
366 +       return retval;
367 +}
368 +
369 +/*
370 + * Get a random new sequence number but make sure it is not greater than
371 + * EXT4_MMP_SEQ_MAX.
372 + */
373 +static unsigned int mmp_new_seq(void)
374 +{
375 +       u32 new_seq;
376 +
377 +       do {
378 +               get_random_bytes(&new_seq, sizeof(u32));
379 +       } while (new_seq > EXT4_MMP_SEQ_MAX);
380 +
381 +       return new_seq;
382 +}
383 +
384 +/*
385 + * Protect the filesystem from being mounted more than once.
386 + */
387 +int ext4_multi_mount_protect(struct super_block *sb,
388 +                                   ext4_fsblk_t mmp_block)
389 +{
390 +       struct ext4_super_block *es = EXT4_SB(sb)->s_es;
391 +       struct buffer_head *bh = NULL;
392 +       struct mmp_struct *mmp = NULL;
393 +       struct mmpd_data *mmpd_data;
394 +       u32 seq;
395 +       unsigned int mmp_check_interval = le16_to_cpu(es->s_mmp_update_interval);
396 +       unsigned int wait_time = 0;
397 +       int retval;
398 +
399 +       if (mmp_block < le32_to_cpu(es->s_first_data_block) ||
400 +           mmp_block >= ext4_blocks_count(es)) {
401 +               ext4_warning(sb, "Invalid MMP block in superblock");
402 +               goto failed;
403 +       }
404 +
405 +       retval = read_mmp_block(sb, &bh, mmp_block);
406 +       if (retval)
407 +               goto failed;
408 +
409 +       mmp = (struct mmp_struct *)(bh->b_data);
410 +
411 +       if (mmp_check_interval < EXT4_MMP_MIN_CHECK_INTERVAL)
412 +               mmp_check_interval = EXT4_MMP_MIN_CHECK_INTERVAL;
413 +
414 +       /*
415 +        * If check_interval in MMP block is larger, use that instead of
416 +        * update_interval from the superblock.
417 +        */
418 +       if (mmp->mmp_check_interval > mmp_check_interval)
419 +               mmp_check_interval = mmp->mmp_check_interval;
420 +
421 +       seq = le32_to_cpu(mmp->mmp_seq);
422 +       if (seq == EXT4_MMP_SEQ_CLEAN)
423 +               goto skip;
424 +
425 +       if (seq == EXT4_MMP_SEQ_FSCK) {
426 +               dump_mmp_msg(sb, mmp, "fsck is running on the filesystem");
427 +               goto failed;
428 +       }
429 +
430 +       wait_time = min(mmp_check_interval * 2 + 1,
431 +                       mmp_check_interval + 60);
432 +
433 +       /* Print MMP interval if more than 20 secs. */
434 +       if (wait_time > EXT4_MMP_MIN_CHECK_INTERVAL * 4)
435 +               ext4_warning(sb, "MMP interval %u higher than expected, please"
436 +                            " wait.\n", wait_time * 2);
437 +
438 +       if (schedule_timeout_interruptible(HZ * wait_time) != 0) {
439 +               ext4_warning(sb, "MMP startup interrupted, failing mount\n");
440 +               goto failed;
441 +       }
442 +
443 +       retval = read_mmp_block(sb, &bh, mmp_block);
444 +       if (retval)
445 +               goto failed;
446 +       mmp = (struct mmp_struct *)(bh->b_data);
447 +       if (seq != le32_to_cpu(mmp->mmp_seq)) {
448 +               dump_mmp_msg(sb, mmp,
449 +                            "Device is already active on another node.");
450 +               goto failed;
451 +       }
452 +
453 +skip:
454 +       /*
455 +        * write a new random sequence number.
456 +        */
457 +       mmp->mmp_seq = seq = cpu_to_le32(mmp_new_seq());
458 +
459 +       retval = write_mmp_block(bh);
460 +       if (retval)
461 +               goto failed;
462 +
463 +       /*
464 +        * wait for MMP interval and check mmp_seq.
465 +        */
466 +       if (schedule_timeout_interruptible(HZ * wait_time) != 0) {
467 +               ext4_warning(sb, "MMP startup interrupted, failing mount\n");
468 +               goto failed;
469 +       }
470 +
471 +       retval = read_mmp_block(sb, &bh, mmp_block);
472 +       if (retval)
473 +               goto failed;
474 +       mmp = (struct mmp_struct *)(bh->b_data);
475 +       if (seq != le32_to_cpu(mmp->mmp_seq)) {
476 +               dump_mmp_msg(sb, mmp,
477 +                            "Device is already active on another node.");
478 +               goto failed;
479 +       }
480 +
481 +       mmpd_data = kmalloc(sizeof(struct mmpd_data), GFP_KERNEL);
482 +       if (!mmpd_data) {
483 +               ext4_warning(sb, "not enough memory for mmpd_data");
484 +               goto failed;
485 +       }
486 +       mmpd_data->sb = sb;
487 +       mmpd_data->bh = bh;
488 +
489 +       /*
490 +        * Start a kernel thread to update the MMP block periodically.
491 +        */
492 +       EXT4_SB(sb)->s_mmp_tsk = kthread_run(kmmpd, mmpd_data, "kmmpd-%s",
493 +                                            bdevname(bh->b_bdev,
494 +                                                     mmp->mmp_bdevname));
495 +       if (IS_ERR(EXT4_SB(sb)->s_mmp_tsk)) {
496 +               EXT4_SB(sb)->s_mmp_tsk = NULL;
497 +               kfree(mmpd_data);
498 +               ext4_warning(sb, "Unable to create kmmpd thread for %s.",
499 +                            sb->s_id);
500 +               goto failed;
501 +       }
502 +
503 +       return 0;
504 +
505 +failed:
506 +       brelse(bh);
507 +       return 1;
508 +}
509 +
510 +
511 Index: linux-stage/fs/ext4/super.c
512 ===================================================================
513 --- linux-stage.orig/fs/ext4/super.c
514 +++ linux-stage/fs/ext4/super.c
515 @@ -40,6 +40,8 @@
516  #include <linux/log2.h>
517  #include <linux/crc16.h>
518  #include <asm/uaccess.h>
519 +#include <linux/kthread.h>
520 +#include <linux/utsname.h>
521  
522  #include "ext4.h"
523  #include "ext4_jbd2.h"
524 @@ -700,6 +702,8 @@ static void ext4_put_super(struct super_
525                 invalidate_bdev(sbi->journal_bdev);
526                 ext4_blkdev_remove(sbi);
527         }
528 +       if (sbi->s_mmp_tsk)
529 +               kthread_stop(sbi->s_mmp_tsk);
530         sb->s_fs_info = NULL;
531         /*
532          * Now that we are completely done shutting down the
533 @@ -2799,6 +2803,10 @@ static int ext4_fill_super(struct super_
534         needs_recovery = (es->s_last_orphan != 0 ||
535                           EXT4_HAS_INCOMPAT_FEATURE(sb,
536                                     EXT4_FEATURE_INCOMPAT_RECOVER));
537 +       if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_MMP) &&
538 +           !(sb->s_flags & MS_RDONLY))
539 +               if (ext4_multi_mount_protect(sb, le64_to_cpu(es->s_mmp_block)))
540 +                       goto failed_mount3;
541  
542         /*
543          * The first inode we look at is the journal inode.  Don't try
544 @@ -3036,6 +3044,8 @@ failed_mount3:
545         percpu_counter_destroy(&sbi->s_freeinodes_counter);
546         percpu_counter_destroy(&sbi->s_dirs_counter);
547         percpu_counter_destroy(&sbi->s_dirtyblocks_counter);
548 +       if (sbi->s_mmp_tsk)
549 +               kthread_stop(sbi->s_mmp_tsk);
550  failed_mount2:
551         for (i = 0; i < db_count; i++)
552                 brelse(sbi->s_group_desc[i]);
553 @@ -3544,7 +3554,7 @@ static int ext4_remount(struct super_blo
554         struct ext4_mount_options old_opts;
555         ext4_group_t g;
556         unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO;
557 -       int err;
558 +       int err = 0;
559  #ifdef CONFIG_QUOTA
560         int i;
561  #endif
562 @@ -3666,6 +3676,13 @@ static int ext4_remount(struct super_blo
563                                 goto restore_opts;
564                         if (!ext4_setup_super(sb, es, 0))
565                                 sb->s_flags &= ~MS_RDONLY;
566 +                       if (EXT4_HAS_INCOMPAT_FEATURE(sb,
567 +                                                   EXT4_FEATURE_INCOMPAT_MMP))
568 +                               if (ext4_multi_mount_protect(sb,
569 +                                               le64_to_cpu(es->s_mmp_block))) {
570 +                                       err = -EROFS;
571 +                                       goto restore_opts;
572 +                               }
573                 }
574         }
575         ext4_setup_system_zone(sb);