nilfs2.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. NILFS2
  2. ------
  3. NILFS2 is a log-structured file system (LFS) supporting continuous
  4. snapshotting. In addition to versioning capability of the entire file
  5. system, users can even restore files mistakenly overwritten or
  6. destroyed just a few seconds ago. Since NILFS2 can keep consistency
  7. like conventional LFS, it achieves quick recovery after system
  8. crashes.
  9. NILFS2 creates a number of checkpoints every few seconds or per
  10. synchronous write basis (unless there is no change). Users can select
  11. significant versions among continuously created checkpoints, and can
  12. change them into snapshots which will be preserved until they are
  13. changed back to checkpoints.
  14. There is no limit on the number of snapshots until the volume gets
  15. full. Each snapshot is mountable as a read-only file system
  16. concurrently with its writable mount, and this feature is convenient
  17. for online backup.
  18. The userland tools are included in nilfs-utils package, which is
  19. available from the following download page. At least "mkfs.nilfs2",
  20. "mount.nilfs2", "umount.nilfs2", and "nilfs_cleanerd" (so called
  21. cleaner or garbage collector) are required. Details on the tools are
  22. described in the man pages included in the package.
  23. Project web page: http://nilfs.sourceforge.net/
  24. Download page: http://nilfs.sourceforge.net/en/download.html
  25. List info: http://vger.kernel.org/vger-lists.html#linux-nilfs
  26. Caveats
  27. =======
  28. Features which NILFS2 does not support yet:
  29. - atime
  30. - extended attributes
  31. - POSIX ACLs
  32. - quotas
  33. - fsck
  34. - defragmentation
  35. Mount options
  36. =============
  37. NILFS2 supports the following mount options:
  38. (*) == default
  39. barrier(*) This enables/disables the use of write barriers. This
  40. nobarrier requires an IO stack which can support barriers, and
  41. if nilfs gets an error on a barrier write, it will
  42. disable again with a warning.
  43. errors=continue Keep going on a filesystem error.
  44. errors=remount-ro(*) Remount the filesystem read-only on an error.
  45. errors=panic Panic and halt the machine if an error occurs.
  46. cp=n Specify the checkpoint-number of the snapshot to be
  47. mounted. Checkpoints and snapshots are listed by lscp
  48. user command. Only the checkpoints marked as snapshot
  49. are mountable with this option. Snapshot is read-only,
  50. so a read-only mount option must be specified together.
  51. order=relaxed(*) Apply relaxed order semantics that allows modified data
  52. blocks to be written to disk without making a
  53. checkpoint if no metadata update is going. This mode
  54. is equivalent to the ordered data mode of the ext3
  55. filesystem except for the updates on data blocks still
  56. conserve atomicity. This will improve synchronous
  57. write performance for overwriting.
  58. order=strict Apply strict in-order semantics that preserves sequence
  59. of all file operations including overwriting of data
  60. blocks. That means, it is guaranteed that no
  61. overtaking of events occurs in the recovered file
  62. system after a crash.
  63. norecovery Disable recovery of the filesystem on mount.
  64. This disables every write access on the device for
  65. read-only mounts or snapshots. This option will fail
  66. for r/w mounts on an unclean volume.
  67. discard This enables/disables the use of discard/TRIM commands.
  68. nodiscard(*) The discard/TRIM commands are sent to the underlying
  69. block device when blocks are freed. This is useful
  70. for SSD devices and sparse/thinly-provisioned LUNs.
  71. Ioctls
  72. ======
  73. There is some NILFS2 specific functionality which can be accessed by applications
  74. through the system call interfaces. The list of all NILFS2 specific ioctls are
  75. shown in the table below.
  76. Table of NILFS2 specific ioctls
  77. ..............................................................................
  78. Ioctl Description
  79. NILFS_IOCTL_CHANGE_CPMODE Change mode of given checkpoint between
  80. checkpoint and snapshot state. This ioctl is
  81. used in chcp and mkcp utilities.
  82. NILFS_IOCTL_DELETE_CHECKPOINT Remove checkpoint from NILFS2 file system.
  83. This ioctl is used in rmcp utility.
  84. NILFS_IOCTL_GET_CPINFO Return info about requested checkpoints. This
  85. ioctl is used in lscp utility and by
  86. nilfs_cleanerd daemon.
  87. NILFS_IOCTL_GET_CPSTAT Return checkpoints statistics. This ioctl is
  88. used by lscp, rmcp utilities and by
  89. nilfs_cleanerd daemon.
  90. NILFS_IOCTL_GET_SUINFO Return segment usage info about requested
  91. segments. This ioctl is used in lssu,
  92. nilfs_resize utilities and by nilfs_cleanerd
  93. daemon.
  94. NILFS_IOCTL_SET_SUINFO Modify segment usage info of requested
  95. segments. This ioctl is used by
  96. nilfs_cleanerd daemon to skip unnecessary
  97. cleaning operation of segments and reduce
  98. performance penalty or wear of flash device
  99. due to redundant move of in-use blocks.
  100. NILFS_IOCTL_GET_SUSTAT Return segment usage statistics. This ioctl
  101. is used in lssu, nilfs_resize utilities and
  102. by nilfs_cleanerd daemon.
  103. NILFS_IOCTL_GET_VINFO Return information on virtual block addresses.
  104. This ioctl is used by nilfs_cleanerd daemon.
  105. NILFS_IOCTL_GET_BDESCS Return information about descriptors of disk
  106. block numbers. This ioctl is used by
  107. nilfs_cleanerd daemon.
  108. NILFS_IOCTL_CLEAN_SEGMENTS Do garbage collection operation in the
  109. environment of requested parameters from
  110. userspace. This ioctl is used by
  111. nilfs_cleanerd daemon.
  112. NILFS_IOCTL_SYNC Make a checkpoint. This ioctl is used in
  113. mkcp utility.
  114. NILFS_IOCTL_RESIZE Resize NILFS2 volume. This ioctl is used
  115. by nilfs_resize utility.
  116. NILFS_IOCTL_SET_ALLOC_RANGE Define lower limit of segments in bytes and
  117. upper limit of segments in bytes. This ioctl
  118. is used by nilfs_resize utility.
  119. NILFS2 usage
  120. ============
  121. To use nilfs2 as a local file system, simply:
  122. # mkfs -t nilfs2 /dev/block_device
  123. # mount -t nilfs2 /dev/block_device /dir
  124. This will also invoke the cleaner through the mount helper program
  125. (mount.nilfs2).
  126. Checkpoints and snapshots are managed by the following commands.
  127. Their manpages are included in the nilfs-utils package above.
  128. lscp list checkpoints or snapshots.
  129. mkcp make a checkpoint or a snapshot.
  130. chcp change an existing checkpoint to a snapshot or vice versa.
  131. rmcp invalidate specified checkpoint(s).
  132. To mount a snapshot,
  133. # mount -t nilfs2 -r -o cp=<cno> /dev/block_device /snap_dir
  134. where <cno> is the checkpoint number of the snapshot.
  135. To unmount the NILFS2 mount point or snapshot, simply:
  136. # umount /dir
  137. Then, the cleaner daemon is automatically shut down by the umount
  138. helper program (umount.nilfs2).
  139. Disk format
  140. ===========
  141. A nilfs2 volume is equally divided into a number of segments except
  142. for the super block (SB) and segment #0. A segment is the container
  143. of logs. Each log is composed of summary information blocks, payload
  144. blocks, and an optional super root block (SR):
  145. ______________________________________________________
  146. | |SB| | Segment | Segment | Segment | ... | Segment | |
  147. |_|__|_|____0____|____1____|____2____|_____|____N____|_|
  148. 0 +1K +4K +8M +16M +24M +(8MB x N)
  149. . . (Typical offsets for 4KB-block)
  150. . .
  151. .______________________.
  152. | log | log |... | log |
  153. |__1__|__2__|____|__m__|
  154. . .
  155. . .
  156. . .
  157. .______________________________.
  158. | Summary | Payload blocks |SR|
  159. |_blocks__|_________________|__|
  160. The payload blocks are organized per file, and each file consists of
  161. data blocks and B-tree node blocks:
  162. |<--- File-A --->|<--- File-B --->|
  163. _______________________________________________________________
  164. | Data blocks | B-tree blocks | Data blocks | B-tree blocks | ...
  165. _|_____________|_______________|_____________|_______________|_
  166. Since only the modified blocks are written in the log, it may have
  167. files without data blocks or B-tree node blocks.
  168. The organization of the blocks is recorded in the summary information
  169. blocks, which contains a header structure (nilfs_segment_summary), per
  170. file structures (nilfs_finfo), and per block structures (nilfs_binfo):
  171. _________________________________________________________________________
  172. | Summary | finfo | binfo | ... | binfo | finfo | binfo | ... | binfo |...
  173. |_blocks__|___A___|_(A,1)_|_____|(A,Na)_|___B___|_(B,1)_|_____|(B,Nb)_|___
  174. The logs include regular files, directory files, symbolic link files
  175. and several meta data files. The mata data files are the files used
  176. to maintain file system meta data. The current version of NILFS2 uses
  177. the following meta data files:
  178. 1) Inode file (ifile) -- Stores on-disk inodes
  179. 2) Checkpoint file (cpfile) -- Stores checkpoints
  180. 3) Segment usage file (sufile) -- Stores allocation state of segments
  181. 4) Data address translation file -- Maps virtual block numbers to usual
  182. (DAT) block numbers. This file serves to
  183. make on-disk blocks relocatable.
  184. The following figure shows a typical organization of the logs:
  185. _________________________________________________________________________
  186. | Summary | regular file | file | ... | ifile | cpfile | sufile | DAT |SR|
  187. |_blocks__|_or_directory_|_______|_____|_______|________|________|_____|__|
  188. To stride over segment boundaries, this sequence of files may be split
  189. into multiple logs. The sequence of logs that should be treated as
  190. logically one log, is delimited with flags marked in the segment
  191. summary. The recovery code of nilfs2 looks this boundary information
  192. to ensure atomicity of updates.
  193. The super root block is inserted for every checkpoints. It includes
  194. three special inodes, inodes for the DAT, cpfile, and sufile. Inodes
  195. of regular files, directories, symlinks and other special files, are
  196. included in the ifile. The inode of ifile itself is included in the
  197. corresponding checkpoint entry in the cpfile. Thus, the hierarchy
  198. among NILFS2 files can be depicted as follows:
  199. Super block (SB)
  200. |
  201. v
  202. Super root block (the latest cno=xx)
  203. |-- DAT
  204. |-- sufile
  205. `-- cpfile
  206. |-- ifile (cno=c1)
  207. |-- ifile (cno=c2) ---- file (ino=i1)
  208. : : |-- file (ino=i2)
  209. `-- ifile (cno=xx) |-- file (ino=i3)
  210. : :
  211. `-- file (ino=yy)
  212. ( regular file, directory, or symlink )
  213. For detail on the format of each file, please see include/linux/nilfs2_fs.h.