1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0 2*4882a593Smuzhiyun 3*4882a593SmuzhiyunMultiple Mount Protection 4*4882a593Smuzhiyun------------------------- 5*4882a593Smuzhiyun 6*4882a593SmuzhiyunMultiple mount protection (MMP) is a feature that protects the 7*4882a593Smuzhiyunfilesystem against multiple hosts trying to use the filesystem 8*4882a593Smuzhiyunsimultaneously. When a filesystem is opened (for mounting, or fsck, 9*4882a593Smuzhiyunetc.), the MMP code running on the node (call it node A) checks a 10*4882a593Smuzhiyunsequence number. If the sequence number is EXT4\_MMP\_SEQ\_CLEAN, the 11*4882a593Smuzhiyunopen continues. If the sequence number is EXT4\_MMP\_SEQ\_FSCK, then 12*4882a593Smuzhiyunfsck is (hopefully) running, and open fails immediately. Otherwise, the 13*4882a593Smuzhiyunopen code will wait for twice the specified MMP check interval and check 14*4882a593Smuzhiyunthe sequence number again. If the sequence number has changed, then the 15*4882a593Smuzhiyunfilesystem is active on another machine and the open fails. If the MMP 16*4882a593Smuzhiyuncode passes all of those checks, a new MMP sequence number is generated 17*4882a593Smuzhiyunand written to the MMP block, and the mount proceeds. 18*4882a593Smuzhiyun 19*4882a593SmuzhiyunWhile the filesystem is live, the kernel sets up a timer to re-check the 20*4882a593SmuzhiyunMMP block at the specified MMP check interval. To perform the re-check, 21*4882a593Smuzhiyunthe MMP sequence number is re-read; if it does not match the in-memory 22*4882a593SmuzhiyunMMP sequence number, then another node (node B) has mounted the 23*4882a593Smuzhiyunfilesystem, and node A remounts the filesystem read-only. If the 24*4882a593Smuzhiyunsequence numbers match, the sequence number is incremented both in 25*4882a593Smuzhiyunmemory and on disk, and the re-check is complete. 26*4882a593Smuzhiyun 27*4882a593SmuzhiyunThe hostname and device filename are written into the MMP block whenever 28*4882a593Smuzhiyunan open operation succeeds. The MMP code does not use these values; they 29*4882a593Smuzhiyunare provided purely for informational purposes. 30*4882a593Smuzhiyun 31*4882a593SmuzhiyunThe checksum is calculated against the FS UUID and the MMP structure. 32*4882a593SmuzhiyunThe MMP structure (``struct mmp_struct``) is as follows: 33*4882a593Smuzhiyun 34*4882a593Smuzhiyun.. list-table:: 35*4882a593Smuzhiyun :widths: 8 12 20 40 36*4882a593Smuzhiyun :header-rows: 1 37*4882a593Smuzhiyun 38*4882a593Smuzhiyun * - Offset 39*4882a593Smuzhiyun - Type 40*4882a593Smuzhiyun - Name 41*4882a593Smuzhiyun - Description 42*4882a593Smuzhiyun * - 0x0 43*4882a593Smuzhiyun - \_\_le32 44*4882a593Smuzhiyun - mmp\_magic 45*4882a593Smuzhiyun - Magic number for MMP, 0x004D4D50 (“MMP”). 46*4882a593Smuzhiyun * - 0x4 47*4882a593Smuzhiyun - \_\_le32 48*4882a593Smuzhiyun - mmp\_seq 49*4882a593Smuzhiyun - Sequence number, updated periodically. 50*4882a593Smuzhiyun * - 0x8 51*4882a593Smuzhiyun - \_\_le64 52*4882a593Smuzhiyun - mmp\_time 53*4882a593Smuzhiyun - Time that the MMP block was last updated. 54*4882a593Smuzhiyun * - 0x10 55*4882a593Smuzhiyun - char[64] 56*4882a593Smuzhiyun - mmp\_nodename 57*4882a593Smuzhiyun - Hostname of the node that opened the filesystem. 58*4882a593Smuzhiyun * - 0x50 59*4882a593Smuzhiyun - char[32] 60*4882a593Smuzhiyun - mmp\_bdevname 61*4882a593Smuzhiyun - Block device name of the filesystem. 62*4882a593Smuzhiyun * - 0x70 63*4882a593Smuzhiyun - \_\_le16 64*4882a593Smuzhiyun - mmp\_check\_interval 65*4882a593Smuzhiyun - The MMP re-check interval, in seconds. 66*4882a593Smuzhiyun * - 0x72 67*4882a593Smuzhiyun - \_\_le16 68*4882a593Smuzhiyun - mmp\_pad1 69*4882a593Smuzhiyun - Zero. 70*4882a593Smuzhiyun * - 0x74 71*4882a593Smuzhiyun - \_\_le32[226] 72*4882a593Smuzhiyun - mmp\_pad2 73*4882a593Smuzhiyun - Zero. 74*4882a593Smuzhiyun * - 0x3FC 75*4882a593Smuzhiyun - \_\_le32 76*4882a593Smuzhiyun - mmp\_checksum 77*4882a593Smuzhiyun - Checksum of the MMP block. 78