Whamcloud - gitweb
Reserve superblock fields for multiple mount protection feature
authorAndreas Dilger <adilger@clusterfs.com>
Thu, 31 May 2007 16:25:46 +0000 (12:25 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 31 May 2007 16:25:46 +0000 (12:25 -0400)
There have been reported instances of a filesystem having been mounted
at 2 places at the same time causing a lot of damage to the
filesystem. This patch reserves superblock fields and an INCOMPAT flag
for adding multiple mount protection(MMP) support within the ext4
filesystem itself. The superblock will have a block number
(s_mmp_block) which will hold a MMP structure which has a sequence
number which will be periodically updated every 5 seconds by a mounted
filesystem. Whenever a filesystem will be mounted it will wait for
s_mmp_interval seconds to make sure that the MMP sequence does not
change. To further make sure, we write a random sequence number into
the MMP block and wait for another s_mmp_interval secs. If the
sequence no. doesn't change then the mount will succeed. In case of
failure, the nodename, bdevname and the time at which the MMP block
was last updated will be displayed. tune2fs can be used to set
s_mmp_interval as desired.

Signed-off-by: Andreas Dilger <adilger@clusterfs.com>
Signed-off-by: Kalpak Shah <kalpak@clusterfs.com>
lib/ext2fs/ChangeLog
lib/ext2fs/ext2_fs.h

index def7b2a..3f53df7 100644 (file)
@@ -1,3 +1,8 @@
+2007-05-31  Kalpak Shah <kalpak@clusterfs.com>
+
+       * ext2_fs.h: Reserve superblock fields and INCOMPAT feature flag
+               for multiple mount protection protection.
+
 2007-05-23  Theodore Tso  <tytso@mit.edu>
 
        * icount.c (ext2fs_icount_fetch, ext2fs_icount_increment, setup):
index 98f34fc..81bd190 100644 (file)
@@ -574,8 +574,9 @@ struct ext2_super_block {
        __u16   s_want_extra_isize;     /* New inodes should reserve # bytes */
        __u32   s_flags;                /* Miscellaneous flags */
        __u16   s_raid_stride;          /* RAID stride */
-       __u16   s_pad;                  /* Padding */
-       __u32   s_reserved[166];        /* Padding to the end of the block */
+       __u16   s_mmp_interval;         /* # seconds to wait in MMP checking */
+       __u64   s_mmp_block;            /* Block for multi-mount protection */
+       __u32   s_reserved[164];        /* Padding to the end of the block */
 };
 
 /*
@@ -637,6 +638,7 @@ struct ext2_super_block {
 #define EXT2_FEATURE_INCOMPAT_META_BG          0x0010
 #define EXT3_FEATURE_INCOMPAT_EXTENTS          0x0040
 #define EXT4_FEATURE_INCOMPAT_64BIT            0x0080
+#define EXT4_FEATURE_INCOMPAT_MMP              0x0100
 
 
 #define EXT2_FEATURE_COMPAT_SUPP       0
@@ -715,4 +717,29 @@ struct ext2_dir_entry_2 {
 #define EXT2_DIR_REC_LEN(name_len)     (((name_len) + 8 + EXT2_DIR_ROUND) & \
                                         ~EXT2_DIR_ROUND)
 
+/*
+ * This structure will be used for multiple mount protection. It will be
+ * written into the block number saved in the s_mmp_block field in the
+ * superblock.
+ */
+#define        EXT2_MMP_MAGIC    0x004D4D50 /* ASCII for MMP */
+#define        EXT2_MMP_CLEAN    0xFF4D4D50 /* Value of mmp_seq for clean unmount */
+#define        EXT2_MMP_FSCK_ON  0xE24D4D50 /* Value of mmp_seq when being fscked */
+
+struct mmp_struct {
+       __u32   mmp_magic;
+       __u32   mmp_seq;
+       __u64   mmp_time;
+       char    mmp_nodename[64];
+       char    mmp_bdevname[32];
+       __u16   mmp_interval;
+       __u16   mmp_pad1;
+       __u32   mmp_pad2;
+};
+
+/*
+ * Interval in number of seconds to update the MMP sequence number.
+ */
+#define EXT2_MMP_DEF_INTERVAL  5
+
 #endif /* _LINUX_EXT2_FS_H */