brintos

brintos / linux-shallow public Read only

0
0
Text · 2.4 KiB · 03cca17 Raw
43 lines · plain
1.. SPDX-License-Identifier: GPL-2.02 3Orphan file4-----------5 6In unix there can inodes that are unlinked from directory hierarchy but that7are still alive because they are open. In case of crash the filesystem has to8clean up these inodes as otherwise they (and the blocks referenced from them)9would leak. Similarly if we truncate or extend the file, we need not be able10to perform the operation in a single journalling transaction. In such case we11track the inode as orphan so that in case of crash extra blocks allocated to12the file get truncated.13 14Traditionally ext4 tracks orphan inodes in a form of single linked list where15superblock contains the inode number of the last orphan inode (s_last_orphan16field) and then each inode contains inode number of the previously orphaned17inode (we overload i_dtime inode field for this). However this filesystem18global single linked list is a scalability bottleneck for workloads that result19in heavy creation of orphan inodes. When orphan file feature20(COMPAT_ORPHAN_FILE) is enabled, the filesystem has a special inode21(referenced from the superblock through s_orphan_file_inum) with several22blocks. Each of these blocks has a structure:23 24============= ================ =============== ===============================25Offset        Type             Name            Description26============= ================ =============== ===============================270x0           Array of         Orphan inode    Each __le32 entry is either28              __le32 entries   entries         empty (0) or it contains29	                                       inode number of an orphan30					       inode.31blocksize-8   __le32           ob_magic        Magic value stored in orphan32                                               block tail (0x0b10ca04)33blocksize-4   __le32           ob_checksum     Checksum of the orphan block.34============= ================ =============== ===============================35 36When a filesystem with orphan file feature is writeably mounted, we set37RO_COMPAT_ORPHAN_PRESENT feature in the superblock to indicate there may38be valid orphan entries. In case we see this feature when mounting the39filesystem, we read the whole orphan file and process all orphan inodes found40there as usual. When cleanly unmounting the filesystem we remove the41RO_COMPAT_ORPHAN_PRESENT feature to avoid unnecessary scanning of the orphan42file and also make the filesystem fully compatible with older kernels.43