Ryusuke Konishi | 962281a | 2009-04-06 19:01:20 -0700 | [diff] [blame] | 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/ |
Ryusuke Konishi | 6aff43f | 2010-01-02 21:41:53 +0900 | [diff] [blame] | 31 | List info: http://vger.kernel.org/vger-lists.html#linux-nilfs |
Ryusuke Konishi | 962281a | 2009-04-06 19:01:20 -0700 | [diff] [blame] | 32 | |
| 33 | Caveats |
| 34 | ======= |
| 35 | |
| 36 | Features which NILFS2 does not support yet: |
| 37 | |
| 38 | - atime |
| 39 | - extended attributes |
| 40 | - POSIX ACLs |
| 41 | - quotas |
Ryusuke Konishi | fb6e711 | 2009-05-30 11:27:17 +0900 | [diff] [blame] | 42 | - fsck |
| 43 | - resize |
Ryusuke Konishi | 962281a | 2009-04-06 19:01:20 -0700 | [diff] [blame] | 44 | - defragmentation |
| 45 | |
| 46 | Mount options |
| 47 | ============= |
| 48 | |
| 49 | NILFS2 supports the following mount options: |
| 50 | (*) == default |
| 51 | |
Ryusuke Konishi | 773bc4f | 2010-07-05 13:00:08 +0900 | [diff] [blame] | 52 | barrier(*) This enables/disables the use of write barriers. This |
| 53 | nobarrier requires an IO stack which can support barriers, and |
| 54 | if nilfs gets an error on a barrier write, it will |
| 55 | disable again with a warning. |
Ryusuke Konishi | 277a6a3 | 2010-04-02 18:02:33 +0900 | [diff] [blame] | 56 | errors=continue Keep going on a filesystem error. |
| 57 | errors=remount-ro(*) Remount the filesystem read-only on an error. |
Ryusuke Konishi | 962281a | 2009-04-06 19:01:20 -0700 | [diff] [blame] | 58 | errors=panic Panic and halt the machine if an error occurs. |
| 59 | cp=n Specify the checkpoint-number of the snapshot to be |
| 60 | mounted. Checkpoints and snapshots are listed by lscp |
| 61 | user command. Only the checkpoints marked as snapshot |
| 62 | are mountable with this option. Snapshot is read-only, |
| 63 | so a read-only mount option must be specified together. |
| 64 | order=relaxed(*) Apply relaxed order semantics that allows modified data |
| 65 | blocks to be written to disk without making a |
| 66 | checkpoint if no metadata update is going. This mode |
| 67 | is equivalent to the ordered data mode of the ext3 |
| 68 | filesystem except for the updates on data blocks still |
| 69 | conserve atomicity. This will improve synchronous |
| 70 | write performance for overwriting. |
| 71 | order=strict Apply strict in-order semantics that preserves sequence |
| 72 | of all file operations including overwriting of data |
| 73 | blocks. That means, it is guaranteed that no |
| 74 | overtaking of events occurs in the recovered file |
| 75 | system after a crash. |
Ryusuke Konishi | 0234576 | 2009-11-20 03:28:01 +0900 | [diff] [blame] | 76 | norecovery Disable recovery of the filesystem on mount. |
| 77 | This disables every write access on the device for |
| 78 | read-only mounts or snapshots. This option will fail |
| 79 | for r/w mounts on an unclean volume. |
Ryusuke Konishi | 802d317 | 2010-07-05 14:27:04 +0900 | [diff] [blame] | 80 | discard This enables/disables the use of discard/TRIM commands. |
| 81 | nodiscard(*) The discard/TRIM commands are sent to the underlying |
| 82 | block device when blocks are freed. This is useful |
| 83 | for SSD devices and sparse/thinly-provisioned LUNs. |
Ryusuke Konishi | 962281a | 2009-04-06 19:01:20 -0700 | [diff] [blame] | 84 | |
| 85 | NILFS2 usage |
| 86 | ============ |
| 87 | |
| 88 | To use nilfs2 as a local file system, simply: |
| 89 | |
| 90 | # mkfs -t nilfs2 /dev/block_device |
| 91 | # mount -t nilfs2 /dev/block_device /dir |
| 92 | |
| 93 | This will also invoke the cleaner through the mount helper program |
| 94 | (mount.nilfs2). |
| 95 | |
| 96 | Checkpoints and snapshots are managed by the following commands. |
| 97 | Their manpages are included in the nilfs-utils package above. |
| 98 | |
| 99 | lscp list checkpoints or snapshots. |
| 100 | mkcp make a checkpoint or a snapshot. |
| 101 | chcp change an existing checkpoint to a snapshot or vice versa. |
| 102 | rmcp invalidate specified checkpoint(s). |
| 103 | |
| 104 | To mount a snapshot, |
| 105 | |
| 106 | # mount -t nilfs2 -r -o cp=<cno> /dev/block_device /snap_dir |
| 107 | |
| 108 | where <cno> is the checkpoint number of the snapshot. |
| 109 | |
| 110 | To unmount the NILFS2 mount point or snapshot, simply: |
| 111 | |
| 112 | # umount /dir |
| 113 | |
| 114 | Then, the cleaner daemon is automatically shut down by the umount |
| 115 | helper program (umount.nilfs2). |
| 116 | |
| 117 | Disk format |
| 118 | =========== |
| 119 | |
| 120 | A nilfs2 volume is equally divided into a number of segments except |
| 121 | for the super block (SB) and segment #0. A segment is the container |
| 122 | of logs. Each log is composed of summary information blocks, payload |
| 123 | blocks, and an optional super root block (SR): |
| 124 | |
| 125 | ______________________________________________________ |
| 126 | | |SB| | Segment | Segment | Segment | ... | Segment | | |
| 127 | |_|__|_|____0____|____1____|____2____|_____|____N____|_| |
| 128 | 0 +1K +4K +8M +16M +24M +(8MB x N) |
| 129 | . . (Typical offsets for 4KB-block) |
| 130 | . . |
| 131 | .______________________. |
| 132 | | log | log |... | log | |
| 133 | |__1__|__2__|____|__m__| |
| 134 | . . |
| 135 | . . |
| 136 | . . |
| 137 | .______________________________. |
| 138 | | Summary | Payload blocks |SR| |
| 139 | |_blocks__|_________________|__| |
| 140 | |
| 141 | The payload blocks are organized per file, and each file consists of |
| 142 | data blocks and B-tree node blocks: |
| 143 | |
| 144 | |<--- File-A --->|<--- File-B --->| |
| 145 | _______________________________________________________________ |
| 146 | | Data blocks | B-tree blocks | Data blocks | B-tree blocks | ... |
| 147 | _|_____________|_______________|_____________|_______________|_ |
| 148 | |
| 149 | |
| 150 | Since only the modified blocks are written in the log, it may have |
| 151 | files without data blocks or B-tree node blocks. |
| 152 | |
| 153 | The organization of the blocks is recorded in the summary information |
| 154 | blocks, which contains a header structure (nilfs_segment_summary), per |
| 155 | file structures (nilfs_finfo), and per block structures (nilfs_binfo): |
| 156 | |
| 157 | _________________________________________________________________________ |
| 158 | | Summary | finfo | binfo | ... | binfo | finfo | binfo | ... | binfo |... |
| 159 | |_blocks__|___A___|_(A,1)_|_____|(A,Na)_|___B___|_(B,1)_|_____|(B,Nb)_|___ |
| 160 | |
| 161 | |
| 162 | The logs include regular files, directory files, symbolic link files |
| 163 | and several meta data files. The mata data files are the files used |
| 164 | to maintain file system meta data. The current version of NILFS2 uses |
| 165 | the following meta data files: |
| 166 | |
| 167 | 1) Inode file (ifile) -- Stores on-disk inodes |
| 168 | 2) Checkpoint file (cpfile) -- Stores checkpoints |
| 169 | 3) Segment usage file (sufile) -- Stores allocation state of segments |
| 170 | 4) Data address translation file -- Maps virtual block numbers to usual |
| 171 | (DAT) block numbers. This file serves to |
| 172 | make on-disk blocks relocatable. |
Ryusuke Konishi | 962281a | 2009-04-06 19:01:20 -0700 | [diff] [blame] | 173 | |
| 174 | The following figure shows a typical organization of the logs: |
| 175 | |
| 176 | _________________________________________________________________________ |
| 177 | | Summary | regular file | file | ... | ifile | cpfile | sufile | DAT |SR| |
| 178 | |_blocks__|_or_directory_|_______|_____|_______|________|________|_____|__| |
| 179 | |
| 180 | |
| 181 | To stride over segment boundaries, this sequence of files may be split |
| 182 | into multiple logs. The sequence of logs that should be treated as |
| 183 | logically one log, is delimited with flags marked in the segment |
| 184 | summary. The recovery code of nilfs2 looks this boundary information |
| 185 | to ensure atomicity of updates. |
| 186 | |
| 187 | The super root block is inserted for every checkpoints. It includes |
| 188 | three special inodes, inodes for the DAT, cpfile, and sufile. Inodes |
| 189 | of regular files, directories, symlinks and other special files, are |
| 190 | included in the ifile. The inode of ifile itself is included in the |
| 191 | corresponding checkpoint entry in the cpfile. Thus, the hierarchy |
| 192 | among NILFS2 files can be depicted as follows: |
| 193 | |
| 194 | Super block (SB) |
| 195 | | |
| 196 | v |
| 197 | Super root block (the latest cno=xx) |
| 198 | |-- DAT |
| 199 | |-- sufile |
| 200 | `-- cpfile |
| 201 | |-- ifile (cno=c1) |
| 202 | |-- ifile (cno=c2) ---- file (ino=i1) |
| 203 | : : |-- file (ino=i2) |
| 204 | `-- ifile (cno=xx) |-- file (ino=i3) |
| 205 | : : |
| 206 | `-- file (ino=yy) |
| 207 | ( regular file, directory, or symlink ) |
| 208 | |
| 209 | For detail on the format of each file, please see include/linux/nilfs2_fs.h. |