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