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