18a98ec7cSDarrick J. Wong.. SPDX-License-Identifier: GPL-2.0 28a98ec7cSDarrick J. Wong 38a98ec7cSDarrick J. WongMultiple Mount Protection 48a98ec7cSDarrick J. Wong------------------------- 58a98ec7cSDarrick J. Wong 68a98ec7cSDarrick J. WongMultiple mount protection (MMP) is a feature that protects the 78a98ec7cSDarrick J. Wongfilesystem against multiple hosts trying to use the filesystem 88a98ec7cSDarrick J. Wongsimultaneously. When a filesystem is opened (for mounting, or fsck, 98a98ec7cSDarrick J. Wongetc.), the MMP code running on the node (call it node A) checks a 10*3103084aSWang Jianjiansequence number. If the sequence number is EXT4_MMP_SEQ_CLEAN, the 11*3103084aSWang Jianjianopen continues. If the sequence number is EXT4_MMP_SEQ_FSCK, then 128a98ec7cSDarrick J. Wongfsck is (hopefully) running, and open fails immediately. Otherwise, the 138a98ec7cSDarrick J. Wongopen code will wait for twice the specified MMP check interval and check 148a98ec7cSDarrick J. Wongthe sequence number again. If the sequence number has changed, then the 158a98ec7cSDarrick J. Wongfilesystem is active on another machine and the open fails. If the MMP 168a98ec7cSDarrick J. Wongcode passes all of those checks, a new MMP sequence number is generated 178a98ec7cSDarrick J. Wongand written to the MMP block, and the mount proceeds. 188a98ec7cSDarrick J. Wong 198a98ec7cSDarrick J. WongWhile the filesystem is live, the kernel sets up a timer to re-check the 208a98ec7cSDarrick J. WongMMP block at the specified MMP check interval. To perform the re-check, 218a98ec7cSDarrick J. Wongthe MMP sequence number is re-read; if it does not match the in-memory 228a98ec7cSDarrick J. WongMMP sequence number, then another node (node B) has mounted the 238a98ec7cSDarrick J. Wongfilesystem, and node A remounts the filesystem read-only. If the 248a98ec7cSDarrick J. Wongsequence numbers match, the sequence number is incremented both in 258a98ec7cSDarrick J. Wongmemory and on disk, and the re-check is complete. 268a98ec7cSDarrick J. Wong 278a98ec7cSDarrick J. WongThe hostname and device filename are written into the MMP block whenever 288a98ec7cSDarrick J. Wongan open operation succeeds. The MMP code does not use these values; they 298a98ec7cSDarrick J. Wongare provided purely for informational purposes. 308a98ec7cSDarrick J. Wong 318a98ec7cSDarrick J. WongThe checksum is calculated against the FS UUID and the MMP structure. 328a98ec7cSDarrick J. WongThe MMP structure (``struct mmp_struct``) is as follows: 338a98ec7cSDarrick J. Wong 348a98ec7cSDarrick J. Wong.. list-table:: 358a98ec7cSDarrick J. Wong :widths: 8 12 20 40 368a98ec7cSDarrick J. Wong :header-rows: 1 378a98ec7cSDarrick J. Wong 388a98ec7cSDarrick J. Wong * - Offset 398a98ec7cSDarrick J. Wong - Type 408a98ec7cSDarrick J. Wong - Name 418a98ec7cSDarrick J. Wong - Description 428a98ec7cSDarrick J. Wong * - 0x0 43*3103084aSWang Jianjian - __le32 44*3103084aSWang Jianjian - mmp_magic 458a98ec7cSDarrick J. Wong - Magic number for MMP, 0x004D4D50 (“MMP”). 468a98ec7cSDarrick J. Wong * - 0x4 47*3103084aSWang Jianjian - __le32 48*3103084aSWang Jianjian - mmp_seq 498a98ec7cSDarrick J. Wong - Sequence number, updated periodically. 508a98ec7cSDarrick J. Wong * - 0x8 51*3103084aSWang Jianjian - __le64 52*3103084aSWang Jianjian - mmp_time 538a98ec7cSDarrick J. Wong - Time that the MMP block was last updated. 548a98ec7cSDarrick J. Wong * - 0x10 558a98ec7cSDarrick J. Wong - char[64] 56*3103084aSWang Jianjian - mmp_nodename 578a98ec7cSDarrick J. Wong - Hostname of the node that opened the filesystem. 588a98ec7cSDarrick J. Wong * - 0x50 598a98ec7cSDarrick J. Wong - char[32] 60*3103084aSWang Jianjian - mmp_bdevname 618a98ec7cSDarrick J. Wong - Block device name of the filesystem. 628a98ec7cSDarrick J. Wong * - 0x70 63*3103084aSWang Jianjian - __le16 64*3103084aSWang Jianjian - mmp_check_interval 658a98ec7cSDarrick J. Wong - The MMP re-check interval, in seconds. 668a98ec7cSDarrick J. Wong * - 0x72 67*3103084aSWang Jianjian - __le16 68*3103084aSWang Jianjian - mmp_pad1 698a98ec7cSDarrick J. Wong - Zero. 708a98ec7cSDarrick J. Wong * - 0x74 71*3103084aSWang Jianjian - __le32[226] 72*3103084aSWang Jianjian - mmp_pad2 738a98ec7cSDarrick J. Wong - Zero. 748a98ec7cSDarrick J. Wong * - 0x3FC 75*3103084aSWang Jianjian - __le32 76*3103084aSWang Jianjian - mmp_checksum 778a98ec7cSDarrick J. Wong - Checksum of the MMP block. 78