-Index: linux-2.6.18/fs/ext3/super.c
+Index: linux-stage/fs/ext3/super.c
===================================================================
---- linux-2.6.18.orig/fs/ext3/super.c
-+++ linux-2.6.18/fs/ext3/super.c
+--- linux-stage.orig/fs/ext3/super.c
++++ linux-stage/fs/ext3/super.c
@@ -35,6 +35,8 @@
#include <linux/namei.h>
#include <linux/quotaops.h>
#include <asm/uaccess.h>
-@@ -435,6 +437,9 @@ static void ext3_put_super (struct super
+@@ -83,7 +85,7 @@ handle_t *ext3_journal_start_sb(struct s
+ * take the FS itself readonly cleanly. */
+ journal = EXT3_SB(sb)->s_journal;
+ if (is_journal_aborted(journal)) {
+- ext3_abort(sb, __FUNCTION__,
++ ext3_abort(sb, __func__,
+ "Detected aborted journal");
+ return ERR_PTR(-EROFS);
+ }
+@@ -305,7 +307,7 @@ void ext3_update_dynamic_rev(struct supe
+ if (le32_to_cpu(es->s_rev_level) > EXT3_GOOD_OLD_REV)
+ return;
+
+- ext3_warning(sb, __FUNCTION__,
++ ext3_warning(sb, __func__,
+ "updating to rev %d because of new feature flag, "
+ "running e2fsck is recommended",
+ EXT3_DYNAMIC_REV);
+@@ -440,6 +442,8 @@ static void ext3_put_super (struct super
invalidate_bdev(sbi->journal_bdev, 0);
ext3_blkdev_remove(sbi);
}
+ if (sbi->s_mmp_tsk)
+ kthread_stop(sbi->s_mmp_tsk);
-+
- remove_proc_entry(sb->s_id, proc_root_ext3);
- sbi->s_dev_proc = NULL;
- sb->s_fs_info = NULL;
-@@ -1536,6 +1541,313 @@ static ext3_fsblk_t descriptor_loc(struc
+ if (sbi->s_dev_proc) {
+ remove_proc_entry(sbi->s_dev_proc->name, proc_root_ext3);
+ sbi->s_dev_proc = NULL;
+@@ -1395,7 +1399,7 @@ static int ext3_check_descriptors (struc
+ return 0;
+ }
+ if (!ext3_group_desc_csum_verify(sbi, i, gdp)) {
+- ext3_error(sb, __FUNCTION__,
++ ext3_error(sb, __func__,
+ "Checksum for group %d failed (%u!=%u)\n", i,
+ le16_to_cpu(ext3_group_desc_csum(sbi,i,gdp)),
+ le16_to_cpu(gdp->bg_checksum));
+@@ -1490,7 +1494,7 @@ static void ext3_orphan_cleanup (struct
+ if (inode->i_nlink) {
+ printk(KERN_DEBUG
+ "%s: truncating inode %lu to %Ld bytes\n",
+- __FUNCTION__, inode->i_ino, inode->i_size);
++ __func__, inode->i_ino, inode->i_size);
+ jbd_debug(2, "truncating inode %lu to %Ld bytes\n",
+ inode->i_ino, inode->i_size);
+ ext3_truncate(inode);
+@@ -1498,7 +1502,7 @@ static void ext3_orphan_cleanup (struct
+ } else {
+ printk(KERN_DEBUG
+ "%s: deleting unreferenced inode %lu\n",
+- __FUNCTION__, inode->i_ino);
++ __func__, inode->i_ino);
+ jbd_debug(2, "deleting unreferenced inode %lu\n",
+ inode->i_ino);
+ nr_orphans++;
+@@ -1568,6 +1572,355 @@ static ext3_fsblk_t descriptor_loc(struc
return (has_super + ext3_group_first_block_no(sb, bg));
}
+ if (*bh)
+ clear_buffer_uptodate(*bh);
+
++#if 0
+ brelse(*bh);
+
+ *bh = sb_bread(sb, mmp_block);
++#else
++ if (!*bh)
++ *bh = sb_getblk(sb, mmp_block);
++ if (*bh) {
++ get_bh(*bh);
++ lock_buffer(*bh);
++ (*bh)->b_end_io = end_buffer_read_sync;
++ submit_bh(READ_SYNC, *bh);
++ wait_on_buffer(*bh);
++ if (!buffer_uptodate(*bh)) {
++ brelse(*bh);
++ *bh = NULL;
++ }
++ }
++#endif
+ if (!*bh) {
-+ ext3_warning(sb, __FUNCTION__,
++ ext3_warning(sb, __func__,
+ "Error while reading MMP block %lu", mmp_block);
+ return -EIO;
+ }
+static void dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
+ const char *function, const char *msg)
+{
-+ ext3_warning(sb, function, msg);
++ ext3_warning(sb, function, "%s", msg);
+ ext3_warning(sb, function, "MMP failure info: last update time: %llu, "
+ "last update node: %s, last update device: %s\n",
-+ le64_to_cpu(mmp->mmp_time), mmp->mmp_nodename,
-+ mmp->mmp_bdevname);
++ (long long unsigned int)le64_to_cpu(mmp->mmp_time),
++ mmp->mmp_nodename, mmp->mmp_bdevname);
+}
+
+/*
+ */
+static int kmmpd(void *data)
+{
-+ struct super_block *sb = (struct super_block *) data;
++ struct super_block *sb = ((struct mmpd_data *) data)->sb;
++ struct buffer_head *bh = ((struct mmpd_data *) data)->bh;
+ struct ext3_super_block *es = EXT3_SB(sb)->s_es;
-+ struct buffer_head *bh = NULL;
+ struct mmp_struct *mmp;
+ unsigned long mmp_block;
+ u32 seq = 0;
+ int retval;
+
+ mmp_block = le64_to_cpu(es->s_mmp_block);
-+ retval = read_mmp_block(sb, &bh, mmp_block);
-+ if (retval)
-+ goto failed;
-+
+ mmp = (struct mmp_struct *)(bh->b_data);
+ mmp->mmp_time = cpu_to_le64(get_seconds());
+ /*
+ * Start with the higher mmp_check_interval and reduce it if
+ * the MMP block is being updated on time.
+ */
-+ mmp_check_interval = max(5 * mmp_update_interval,
++ mmp_check_interval = max(5UL * mmp_update_interval,
+ EXT3_MMP_MIN_CHECK_INTERVAL);
+ mmp->mmp_check_interval = cpu_to_le16(mmp_check_interval);
+ bdevname(bh->b_bdev, mmp->mmp_bdevname);
+ * (s_mmp_update_interval * 60) seconds.
+ */
+ if (retval && (failed_writes % 60) == 0) {
-+ ext3_error(sb, __FUNCTION__,
++ ext3_error(sb, __func__,
+ "Error writing to MMP block");
+ failed_writes++;
+ }
+
+ if (!(le32_to_cpu(es->s_feature_incompat) &
+ EXT3_FEATURE_INCOMPAT_MMP)) {
-+ ext3_warning(sb, __FUNCTION__, "kmmpd being stopped "
++ ext3_warning(sb, __func__, "kmmpd being stopped "
+ "since MMP feature has been disabled.");
-+ EXT3_SB(sb)->s_mmp_tsk = 0;
++ EXT3_SB(sb)->s_mmp_tsk = NULL;
+ goto failed;
+ }
+
+ if (sb->s_flags & MS_RDONLY) {
-+ ext3_warning(sb, __FUNCTION__, "kmmpd being stopped "
++ ext3_warning(sb, __func__, "kmmpd being stopped "
+ "since filesystem has been remounted as "
+ "readonly.");
-+ EXT3_SB(sb)->s_mmp_tsk = 0;
++ EXT3_SB(sb)->s_mmp_tsk = NULL;
+ goto failed;
+ }
+
+ diff = jiffies - last_update_time;
+ if (diff < mmp_update_interval * HZ)
-+ schedule_timeout_interruptible(EXT3_MMP_UPDATE_INTERVAL*
++ schedule_timeout_interruptible(mmp_update_interval*
+ HZ - diff);
+
+ /*
+
+ retval = read_mmp_block(sb, &bh_check, mmp_block);
+ if (retval) {
-+ EXT3_SB(sb)->s_mmp_tsk = 0;
++ ext3_error(sb, __func__, "error reading MMP"
++ "data: %d", retval);
++ EXT3_SB(sb)->s_mmp_tsk = NULL;
+ goto failed;
+ }
+
+ mmp_check = (struct mmp_struct *)(bh_check->b_data);
-+ if (mmp->mmp_time != mmp_check->mmp_time ||
++ if (mmp->mmp_seq != mmp_check->mmp_seq ||
+ memcmp(mmp->mmp_nodename, mmp_check->mmp_nodename,
-+ sizeof(mmp->mmp_nodename)))
-+ dump_mmp_msg(sb, mmp_check, __FUNCTION__,
++ sizeof(mmp->mmp_nodename))) {
++ dump_mmp_msg(sb, mmp_check, __func__,
+ "Error while updating MMP info. "
+ "The filesystem seems to have "
+ "been multiply mounted.");
-+
++ ext3_error(sb, __func__, "abort");
++ goto failed;
++ }
+ put_bh(bh_check);
+ }
+
+ * Adjust the mmp_check_interval depending on how much time
+ * it took for the MMP block to be written.
+ */
-+ mmp_check_interval = max(5 * diff / HZ,
-+ (unsigned long) EXT3_MMP_MIN_CHECK_INTERVAL);
++ mmp_check_interval = max(min(5 * diff / HZ,
++ EXT3_MMP_MAX_CHECK_INTERVAL),
++ EXT3_MMP_MIN_CHECK_INTERVAL);
+ mmp->mmp_check_interval = cpu_to_le16(mmp_check_interval);
+ }
+
+ struct ext3_super_block *es = EXT3_SB(sb)->s_es;
+ struct buffer_head *bh = NULL;
+ struct mmp_struct *mmp = NULL;
++ struct mmpd_data *mmpd_data;
+ u32 seq;
+ unsigned int mmp_check_interval = le16_to_cpu(es->s_mmp_update_interval);
++ unsigned int wait_time = 0;
+ int retval;
+
+ if (mmp_block < le32_to_cpu(es->s_first_data_block) ||
+ mmp_block >= le32_to_cpu(es->s_blocks_count)) {
-+ ext3_warning(sb, __FUNCTION__,
++ ext3_warning(sb, __func__,
+ "Invalid MMP block in superblock");
+ goto failed;
+ }
+ goto skip;
+
+ if (seq == EXT3_MMP_SEQ_FSCK) {
-+ dump_mmp_msg(sb, mmp, __FUNCTION__,
++ dump_mmp_msg(sb, mmp, __func__,
+ "fsck is running on the filesystem");
+ goto failed;
+ }
+
-+ schedule_timeout_uninterruptible(HZ * (2 * mmp_check_interval + 1));
++ wait_time = min(mmp_check_interval * 2 + 1,
++ mmp_check_interval + 60);
++
++ /* Print MMP interval if more than 20 secs. */
++ if (wait_time > EXT3_MMP_MIN_CHECK_INTERVAL * 4)
++ ext3_warning(sb, __func__, "MMP interval %u higher than "
++ "expected, please wait.\n", wait_time * 2);
++
++ if (schedule_timeout_interruptible(HZ * wait_time) != 0) {
++ ext3_warning(sb, __func__, "MMP startup interrupted, failing "
++ "mount\n");
++ goto failed;
++ }
+
+ retval = read_mmp_block(sb, &bh, mmp_block);
+ if (retval)
+ goto failed;
+ mmp = (struct mmp_struct *)(bh->b_data);
+ if (seq != le32_to_cpu(mmp->mmp_seq)) {
-+ dump_mmp_msg(sb, mmp, __FUNCTION__,
++ dump_mmp_msg(sb, mmp, __func__,
+ "Device is already active on another node.");
+ goto failed;
+ }
+ /*
+ * wait for MMP interval and check mmp_seq.
+ */
-+ schedule_timeout_uninterruptible(HZ * (2 * mmp_check_interval + 1));
++ if (schedule_timeout_interruptible(HZ * wait_time) != 0) {
++ ext3_warning(sb, __func__, "MMP startup interrupted, failing "
++ "mount\n");
++ goto failed;
++ }
+
+ retval = read_mmp_block(sb, &bh, mmp_block);
+ if (retval)
+ goto failed;
+ mmp = (struct mmp_struct *)(bh->b_data);
+ if (seq != le32_to_cpu(mmp->mmp_seq)) {
-+ dump_mmp_msg(sb, mmp, __FUNCTION__,
++ dump_mmp_msg(sb, mmp, __func__,
+ "Device is already active on another node.");
+ goto failed;
+ }
+
++ mmpd_data = kmalloc(sizeof(struct mmpd_data *), GFP_KERNEL);
++ if (!mmpd_data) {
++ ext3_warning(sb, KERN_ERR, "not enough memory for mmpd_data");
++ goto failed;
++ }
++ mmpd_data->sb = sb;
++ mmpd_data->bh = bh;
++
+ /*
+ * Start a kernel thread to update the MMP block periodically.
+ */
-+ EXT3_SB(sb)->s_mmp_tsk = kthread_run(kmmpd, sb, "kmmpd-%02x:%02x",
-+ MAJOR(sb->s_dev),
-+ MINOR(sb->s_dev));
++ EXT3_SB(sb)->s_mmp_tsk = kthread_run(kmmpd, mmpd_data, "kmmpd-%s",
++ bdevname(bh->b_bdev,
++ mmp->mmp_bdevname));
+ if (IS_ERR(EXT3_SB(sb)->s_mmp_tsk)) {
-+ EXT3_SB(sb)->s_mmp_tsk = 0;
-+ ext3_warning(sb, __FUNCTION__, "Unable to create kmmpd thread "
++ EXT3_SB(sb)->s_mmp_tsk = NULL;
++ ext3_warning(sb, __func__, "Unable to create kmmpd thread "
+ "for %s.", sb->s_id);
+ goto failed;
+ }
+
-+ brelse(bh);
+ return 0;
+
+failed:
static int ext3_fill_super (struct super_block *sb, void *data, int silent)
{
-@@ -1844,6 +2156,11 @@ static int ext3_fill_super (struct super
+@@ -1901,6 +2254,11 @@ static int ext3_fill_super (struct super
EXT3_HAS_INCOMPAT_FEATURE(sb,
EXT3_FEATURE_INCOMPAT_RECOVER));
/*
* The first inode we look at is the journal inode. Don't try
* root first: it may be modified in the journal!
-@@ -2446,7 +2763,7 @@ static int ext3_remount (struct super_bl
+@@ -2033,6 +2391,8 @@ cantfind_ext3:
+ failed_mount4:
+ journal_destroy(sbi->s_journal);
+ failed_mount3:
++ if (sbi->s_mmp_tsk)
++ kthread_stop(sbi->s_mmp_tsk);
+ percpu_counter_destroy(&sbi->s_freeblocks_counter);
+ percpu_counter_destroy(&sbi->s_freeinodes_counter);
+ percpu_counter_destroy(&sbi->s_dirs_counter);
+@@ -2409,9 +2769,9 @@ static void ext3_clear_journal_err(struc
+ char nbuf[16];
+
+ errstr = ext3_decode_error(sb, j_errno, nbuf);
+- ext3_warning(sb, __FUNCTION__, "Filesystem error recorded "
++ ext3_warning(sb, __func__, "Filesystem error recorded "
+ "from previous mount: %s", errstr);
+- ext3_warning(sb, __FUNCTION__, "Marking fs in need of "
++ ext3_warning(sb, __func__, "Marking fs in need of "
+ "filesystem check.");
+
+ EXT3_SB(sb)->s_mount_state |= EXT3_ERROR_FS;
+@@ -2531,7 +2891,7 @@ static int ext3_remount (struct super_bl
ext3_fsblk_t n_blocks_count = 0;
unsigned long old_sb_flags;
struct ext3_mount_options old_opts;
#ifdef CONFIG_QUOTA
int i;
#endif
-@@ -2530,6 +2847,11 @@ static int ext3_remount (struct super_bl
+@@ -2557,7 +2917,7 @@ static int ext3_remount (struct super_bl
+ }
+
+ if (sbi->s_mount_opt & EXT3_MOUNT_ABORT)
+- ext3_abort(sb, __FUNCTION__, "Abort forced by user");
++ ext3_abort(sb, __func__, "Abort forced by user");
+
+ sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
+ ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
+@@ -2630,6 +2990,13 @@ static int ext3_remount (struct super_bl
}
if (!ext3_setup_super (sb, es, 0))
sb->s_flags &= ~MS_RDONLY;
+ if (EXT3_HAS_INCOMPAT_FEATURE(sb,
+ EXT3_FEATURE_INCOMPAT_MMP))
+ if (ext3_multi_mount_protect(sb,
-+ le64_to_cpu(es->s_mmp_block)))
++ le64_to_cpu(es->s_mmp_block))) {
++ err = -EROFS;
+ goto restore_opts;
++ }
}
}
#ifdef CONFIG_QUOTA
-Index: linux-2.6.18/include/linux/ext3_fs.h
+Index: linux-stage/include/linux/ext3_fs.h
===================================================================
---- linux-2.6.18.orig/include/linux/ext3_fs.h
-+++ linux-2.6.18/include/linux/ext3_fs.h
-@@ -593,13 +593,17 @@ struct ext3_super_block {
+--- linux-stage.orig/include/linux/ext3_fs.h
++++ linux-stage/include/linux/ext3_fs.h
+@@ -594,13 +594,17 @@ struct ext3_super_block {
__le32 s_first_meta_bg; /* First metablock block group */
__le32 s_mkfs_time; /* When the filesystem was created */
__le32 s_jnl_blocks[17]; /* Backup of the journal inode */
};
#ifdef __KERNEL__
-@@ -702,12 +706,14 @@ static inline int ext3_valid_inum(struct
+@@ -703,12 +707,14 @@ static inline int ext3_valid_inum(struct
#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */
#define EXT3_FEATURE_INCOMPAT_META_BG 0x0010
#define EXT3_FEATURE_INCOMPAT_EXTENTS 0x0040 /* extents support */
#define EXT3_FEATURE_RO_COMPAT_SUPP (EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER| \
EXT3_FEATURE_RO_COMPAT_LARGE_FILE| \
EXT4_FEATURE_RO_COMPAT_GDT_CSUM| \
-@@ -870,6 +876,39 @@ ext3_group_first_block_no(struct super_b
+@@ -871,6 +877,50 @@ ext3_group_first_block_no(struct super_b
#define ERR_BAD_DX_DIR -75000
/*
+ __le32 mmp_pad2[227];
+};
+
++/* arguments passed to the mmp thread */
++struct mmpd_data {
++ struct buffer_head *bh; /* bh from initial read_mmp_block() */
++ struct super_block *sb; /* super block of the fs */
++};
++
+/*
+ * Default interval in seconds to update the MMP sequence number.
+ */
+/*
+ * Minimum interval for MMP checking in seconds.
+ */
-+#define EXT3_MMP_MIN_CHECK_INTERVAL 5
++#define EXT3_MMP_MIN_CHECK_INTERVAL 5UL
++
++/*
++ * Maximum interval for MMP checking in seconds.
++ */
++#define EXT3_MMP_MAX_CHECK_INTERVAL 300UL
+
+/*
* Function prototypes
*/
-Index: linux-2.6.18/include/linux/ext3_fs_sb.h
+Index: linux-stage/include/linux/ext3_fs_sb.h
===================================================================
---- linux-2.6.18.orig/include/linux/ext3_fs_sb.h
-+++ linux-2.6.18/include/linux/ext3_fs_sb.h
-@@ -151,6 +151,7 @@ struct ext3_sb_info {
+--- linux-stage.orig/include/linux/ext3_fs_sb.h
++++ linux-stage/include/linux/ext3_fs_sb.h
+@@ -157,6 +157,8 @@ struct ext3_sb_info {
/* locality groups */
struct ext3_locality_group *s_locality_groups;
-+ struct task_struct *s_mmp_tsk; /* Kernel thread for multiple mount protection */
++ /* Kernel thread for multiple mount protection */
++ struct task_struct *s_mmp_tsk;
};
#define EXT3_GROUP_INFO(sb, group) \