18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ciMultiple Mount Protection 48c2ecf20Sopenharmony_ci------------------------- 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ciMultiple mount protection (MMP) is a feature that protects the 78c2ecf20Sopenharmony_cifilesystem against multiple hosts trying to use the filesystem 88c2ecf20Sopenharmony_cisimultaneously. When a filesystem is opened (for mounting, or fsck, 98c2ecf20Sopenharmony_cietc.), the MMP code running on the node (call it node A) checks a 108c2ecf20Sopenharmony_cisequence number. If the sequence number is EXT4\_MMP\_SEQ\_CLEAN, the 118c2ecf20Sopenharmony_ciopen continues. If the sequence number is EXT4\_MMP\_SEQ\_FSCK, then 128c2ecf20Sopenharmony_cifsck is (hopefully) running, and open fails immediately. Otherwise, the 138c2ecf20Sopenharmony_ciopen code will wait for twice the specified MMP check interval and check 148c2ecf20Sopenharmony_cithe sequence number again. If the sequence number has changed, then the 158c2ecf20Sopenharmony_cifilesystem is active on another machine and the open fails. If the MMP 168c2ecf20Sopenharmony_cicode passes all of those checks, a new MMP sequence number is generated 178c2ecf20Sopenharmony_ciand written to the MMP block, and the mount proceeds. 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ciWhile the filesystem is live, the kernel sets up a timer to re-check the 208c2ecf20Sopenharmony_ciMMP block at the specified MMP check interval. To perform the re-check, 218c2ecf20Sopenharmony_cithe MMP sequence number is re-read; if it does not match the in-memory 228c2ecf20Sopenharmony_ciMMP sequence number, then another node (node B) has mounted the 238c2ecf20Sopenharmony_cifilesystem, and node A remounts the filesystem read-only. If the 248c2ecf20Sopenharmony_cisequence numbers match, the sequence number is incremented both in 258c2ecf20Sopenharmony_cimemory and on disk, and the re-check is complete. 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ciThe hostname and device filename are written into the MMP block whenever 288c2ecf20Sopenharmony_cian open operation succeeds. The MMP code does not use these values; they 298c2ecf20Sopenharmony_ciare provided purely for informational purposes. 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ciThe checksum is calculated against the FS UUID and the MMP structure. 328c2ecf20Sopenharmony_ciThe MMP structure (``struct mmp_struct``) is as follows: 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci.. list-table:: 358c2ecf20Sopenharmony_ci :widths: 8 12 20 40 368c2ecf20Sopenharmony_ci :header-rows: 1 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci * - Offset 398c2ecf20Sopenharmony_ci - Type 408c2ecf20Sopenharmony_ci - Name 418c2ecf20Sopenharmony_ci - Description 428c2ecf20Sopenharmony_ci * - 0x0 438c2ecf20Sopenharmony_ci - \_\_le32 448c2ecf20Sopenharmony_ci - mmp\_magic 458c2ecf20Sopenharmony_ci - Magic number for MMP, 0x004D4D50 (“MMP”). 468c2ecf20Sopenharmony_ci * - 0x4 478c2ecf20Sopenharmony_ci - \_\_le32 488c2ecf20Sopenharmony_ci - mmp\_seq 498c2ecf20Sopenharmony_ci - Sequence number, updated periodically. 508c2ecf20Sopenharmony_ci * - 0x8 518c2ecf20Sopenharmony_ci - \_\_le64 528c2ecf20Sopenharmony_ci - mmp\_time 538c2ecf20Sopenharmony_ci - Time that the MMP block was last updated. 548c2ecf20Sopenharmony_ci * - 0x10 558c2ecf20Sopenharmony_ci - char[64] 568c2ecf20Sopenharmony_ci - mmp\_nodename 578c2ecf20Sopenharmony_ci - Hostname of the node that opened the filesystem. 588c2ecf20Sopenharmony_ci * - 0x50 598c2ecf20Sopenharmony_ci - char[32] 608c2ecf20Sopenharmony_ci - mmp\_bdevname 618c2ecf20Sopenharmony_ci - Block device name of the filesystem. 628c2ecf20Sopenharmony_ci * - 0x70 638c2ecf20Sopenharmony_ci - \_\_le16 648c2ecf20Sopenharmony_ci - mmp\_check\_interval 658c2ecf20Sopenharmony_ci - The MMP re-check interval, in seconds. 668c2ecf20Sopenharmony_ci * - 0x72 678c2ecf20Sopenharmony_ci - \_\_le16 688c2ecf20Sopenharmony_ci - mmp\_pad1 698c2ecf20Sopenharmony_ci - Zero. 708c2ecf20Sopenharmony_ci * - 0x74 718c2ecf20Sopenharmony_ci - \_\_le32[226] 728c2ecf20Sopenharmony_ci - mmp\_pad2 738c2ecf20Sopenharmony_ci - Zero. 748c2ecf20Sopenharmony_ci * - 0x3FC 758c2ecf20Sopenharmony_ci - \_\_le32 768c2ecf20Sopenharmony_ci - mmp\_checksum 778c2ecf20Sopenharmony_ci - Checksum of the MMP block. 78