← Documents Documentation/filesystems/nilfs2.rst GitHub 원문 ↗

Linux 6.18.37 · Filesystems

NILFS2

NILFS2 checkpoint·snapshot, mount option, ioctl, 사용법과 disk format의 전문 번역입니다.

Source pathDocumentation/filesystems/nilfs2.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

nilfs2.rst:1-286

NILFS2는 checkpoint를 연속 생성하고 선택한 checkpoint를 보존 snapshot으로 전환하는 LFS입니다. Writable mount와 read-only snapshot을 동시에 사용할 수 있으며 `nilfs_cleanerd`가 log segment의 garbage collection을 담당합니다.

Disk는 segment와 log로 구성되고 summary block이 file별 `finfo`, block별 `binfo`를 기록합니다. Checkpoint의 super root는 DAT·sufile·cpfile을, cpfile은 checkpoint별 ifile을, ifile은 실제 file inode를 연결합니다.

NILFS2 핵심 구조
변경 block을 log에 appendSummary가 file/block organization 기록Checkpoint마다 super root 삽입Checkpoint를 보존 snapshot으로 전환Cleaner가 사용하지 않는 segment 회수

Continuous checkpoint와 on-disk metadata 계층을 연결합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

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

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

Continuous snapshot LFS와 userland tool

1-34

NILFS2는 continuous snapshot을 지원하는 log-structured filesystem(LFS)입니다. Filesystem 전체를 versioning할 뿐 아니라 몇 초 전에 잘못 덮어쓰거나 삭제한 file도 복원할 수 있습니다. 전통적 LFS처럼 consistency를 유지하므로 system crash 뒤 빠르게 복구합니다.

변경이 있는 동안 NILFS2는 수 초마다 또는 synchronous write마다 checkpoint를 만듭니다. 사용자는 연속 checkpoint 중 중요한 version을 snapshot으로 바꿀 수 있으며 다시 checkpoint로 되돌리기 전까지 보존됩니다.

Volume이 가득 차기 전까지 snapshot 수에 별도 제한은 없습니다. 각 snapshot은 writable mount와 동시에 read-only filesystem으로 mount할 수 있어 online backup에 편리합니다.

Userland tool은 `nilfs-utils` package에 들어 있습니다. 최소한 `mkfs.nilfs2`, `mount.nilfs2`, `umount.nilfs2`, cleaner 또는 garbage collector인 `nilfs_cleanerd`가 필요하며 자세한 내용은 package의 man page를 참조합니다.

원문은 NILFS project web page, download page와 linux-nilfs mailing-list 정보를 제공합니다.

NILFS2 continuous snapshot
File과 metadata 변경수 초 또는 synchronous write마다 checkpoint중요 checkpoint 선택Snapshot으로 mode 변경Writable mount와 동시에 read-only mount필요 시 checkpoint로 되돌려 수명 종료

변경 기록에서 보존 가능한 read-only snapshot으로 이어집니다.

.. SPDX-License-Identifier: GPL-2.0

======
NILFS2
======

NILFS2 is a log-structured file system (LFS) supporting continuous
snapshotting.  In addition to versioning capability of the entire file
system, users can even restore files mistakenly overwritten or
destroyed just a few seconds ago.  Since NILFS2 can keep consistency
like conventional LFS, it achieves quick recovery after system
crashes.

NILFS2 creates a number of checkpoints every few seconds or per
synchronous write basis (unless there is no change).  Users can select
significant versions among continuously created checkpoints, and can
change them into snapshots which will be preserved until they are
changed back to checkpoints.

There is no limit on the number of snapshots until the volume gets
full.  Each snapshot is mountable as a read-only file system
concurrently with its writable mount, and this feature is convenient
for online backup.

The userland tools are included in nilfs-utils package, which is
available from the following download page.  At least "mkfs.nilfs2",
"mount.nilfs2", "umount.nilfs2", and "nilfs_cleanerd" (so called
cleaner or garbage collector) are required.  Details on the tools are
described in the man pages included in the package.

:Project web page:    https://nilfs.sourceforge.io/
:Download page:       https://nilfs.sourceforge.io/en/download.html
:List info:           http://vger.kernel.org/vger-lists.html#linux-nilfs

현재 지원하지 않는 기능

35-46

현재 NILFS2가 아직 지원하지 않는 기능은 access time 갱신인 `atime`, extended attribute, POSIX ACL, quota, `fsck`, defragmentation입니다.

따라서 deployment 전에 application이 xattr·ACL·quota에 의존하는지 확인해야 하며, conventional offline fsck나 defragmentation tool을 기대해서는 안 됩니다.

NILFS2 미지원 기능
기능상태
`atime`미지원
Extended attributes미지원
POSIX ACLs미지원
Quotas미지원
`fsck`미지원
Defragmentation미지원

원문이 명시한 현재 기능 공백입니다.

Caveats
=======

Features which NILFS2 does not support yet:

        - atime
        - extended attributes
        - POSIX ACLs
        - quotas
        - fsck
        - defragmentation

NILFS2 mount option

47-87

표에서 `(*)`는 default를 뜻합니다. 기본 `barrier`는 write barrier를 사용하고 `nobarrier`는 끕니다. I/O stack이 barrier를 지원해야 하며 barrier write에서 error가 발생하면 NILFS2는 warning을 내고 barrier를 다시 비활성화합니다.

Filesystem error 대응은 `errors=continue`, 기본 `errors=remount-ro`, `errors=panic` 가운데 선택합니다. 각각 계속 진행, read-only remount, machine panic과 halt를 의미합니다.

`cp=n`은 mount할 snapshot의 checkpoint number를 지정합니다. `lscp`로 checkpoint와 snapshot을 확인하며 snapshot 표시가 된 checkpoint만 이 option으로 mount할 수 있습니다. Snapshot은 read-only이므로 read-only mount option도 함께 지정해야 합니다.

기본 `order=relaxed`는 metadata update가 없을 때 checkpoint를 만들지 않고 modified data block을 disk에 쓸 수 있습니다. Ext3 ordered data mode와 비슷하지만 data-block update atomicity는 보존하며 overwrite synchronous-write 성능을 높입니다.

`order=strict`는 data overwrite를 포함한 모든 file operation 순서를 보존해 crash recovery 뒤 event overtaking이 없음을 보장합니다. `norecovery`는 mount 시 recovery를 끄고 read-only mount나 snapshot의 device write를 모두 막지만, unclean volume의 read/write mount에서는 실패합니다.

`discard`는 block을 해제할 때 underlying block device에 discard/TRIM을 보내 SSD와 sparse/thin-provisioned LUN에 유용합니다. 기본 `nodiscard`는 이를 보내지 않습니다.

NILFS2 mount option
OptionDefault동작
`barrier` / `nobarrier`barrierWrite barrier 사용 여부
`errors=continue`아니요Filesystem error 뒤 계속
`errors=remount-ro`Error 시 read-only remount
`errors=panic`아니요Error 시 panic/halt
`cp=n`없음지정 snapshot checkpoint를 read-only mount
`order=relaxed`Metadata update가 없으면 checkpoint 없이 data write
`order=strict`아니요모든 file operation 순서 보존
`norecovery`아니요Mount recovery와 device write 비활성화
`discard` / `nodiscard`nodiscardBlock free 시 discard/TRIM 사용 여부

Default와 핵심 동작을 한 표로 정리합니다.

Mount options
=============

NILFS2 supports the following mount options:
(*) == default

======================= =======================================================
barrier(*)                This enables/disables the use of write barriers.  This
nobarrier                requires an IO stack which can support barriers, and
                        if nilfs gets an error on a barrier write, it will
                        disable again with a warning.
errors=continue                Keep going on a filesystem error.
errors=remount-ro(*)        Remount the filesystem read-only on an error.
errors=panic                Panic and halt the machine if an error occurs.
cp=n                        Specify the checkpoint-number of the snapshot to be
                        mounted.  Checkpoints and snapshots are listed by lscp
                        user command.  Only the checkpoints marked as snapshot
                        are mountable with this option.  Snapshot is read-only,
                        so a read-only mount option must be specified together.
order=relaxed(*)        Apply relaxed order semantics that allows modified data
                        blocks to be written to disk without making a
                        checkpoint if no metadata update is going.  This mode
                        is equivalent to the ordered data mode of the ext3
                        filesystem except for the updates on data blocks still
                        conserve atomicity.  This will improve synchronous
                        write performance for overwriting.
order=strict                Apply strict in-order semantics that preserves sequence
                        of all file operations including overwriting of data
                        blocks.  That means, it is guaranteed that no
                        overtaking of events occurs in the recovered file
                        system after a crash.
norecovery                Disable recovery of the filesystem on mount.
                        This disables every write access on the device for
                        read-only mounts or snapshots.  This option will fail
                        for r/w mounts on an unclean volume.
discard                        This enables/disables the use of discard/TRIM commands.
nodiscard(*)                The discard/TRIM commands are sent to the underlying
                        block device when blocks are freed.  This is useful
                        for SSD devices and sparse/thinly-provisioned LUNs.
======================= =======================================================

NILFS2 전용 ioctl

88-153

Application은 system-call interface를 통해 NILFS2 고유 기능을 사용할 수 있습니다. Checkpoint mode·삭제·조회, segment usage, virtual/block address, garbage collection, sync, resize와 allocation range를 전용 ioctl로 제어합니다.

`NILFS_IOCTL_CHANGE_CPMODE`는 checkpoint와 snapshot mode를 전환하며 `chcp`, `mkcp`가 사용합니다. `NILFS_IOCTL_DELETE_CHECKPOINT`는 checkpoint를 제거하며 `rmcp`가 사용합니다.

`NILFS_IOCTL_GET_CPINFO`와 `NILFS_IOCTL_GET_CPSTAT`은 checkpoint 정보와 통계를 반환합니다. `lscp`, `rmcp`, `nilfs_cleanerd`가 목적에 따라 사용합니다.

Segment 관련 `GET_SUINFO`, `SET_SUINFO`, `GET_SUSTAT`은 segment usage 정보·통계를 조회하거나 수정합니다. `SET_SUINFO`는 cleaner가 불필요한 segment cleaning을 건너뛰어 in-use block의 중복 이동으로 인한 성능 저하와 flash wear를 줄이게 합니다.

`GET_VINFO`는 virtual block address 정보, `GET_BDESCS`는 disk block number descriptor 정보를 반환합니다. `CLEAN_SEGMENTS`는 user-space parameter로 garbage collection을 수행합니다.

`NILFS_IOCTL_SYNC`는 checkpoint를 만들고, `NILFS_IOCTL_RESIZE`는 volume을 resize합니다. `NILFS_IOCTL_SET_ALLOC_RANGE`는 segment lower·upper limit를 byte 단위로 지정합니다.

NILFS2 ioctl
Ioctl기능사용자
`NILFS_IOCTL_CHANGE_CPMODE`Checkpoint/snapshot 전환`chcp`, `mkcp`
`NILFS_IOCTL_DELETE_CHECKPOINT`Checkpoint 제거`rmcp`
`NILFS_IOCTL_GET_CPINFO`Checkpoint 정보`lscp`, nilfs_cleanerd`
`NILFS_IOCTL_GET_CPSTAT`Checkpoint 통계`lscp`, `rmcp`, nilfs_cleanerd`
`NILFS_IOCTL_GET_SUINFO`Segment usage 정보`lssu`, `nilfs_resize`, nilfs_cleanerd`
`NILFS_IOCTL_SET_SUINFO`Segment usage 수정`nilfs_cleanerd`
`NILFS_IOCTL_GET_SUSTAT`Segment usage 통계`lssu`, `nilfs_resize`, nilfs_cleanerd`
`NILFS_IOCTL_GET_VINFO`Virtual block address 정보`nilfs_cleanerd`
`NILFS_IOCTL_GET_BDESCS`Disk block descriptor 정보`nilfs_cleanerd`
`NILFS_IOCTL_CLEAN_SEGMENTS`Garbage collection`nilfs_cleanerd`
`NILFS_IOCTL_SYNC`Checkpoint 생성`mkcp`
`NILFS_IOCTL_RESIZE`Volume resize`nilfs_resize`
`NILFS_IOCTL_SET_ALLOC_RANGE`Segment byte range 지정`nilfs_resize`

전용 ioctl과 대표 user-space consumer입니다.

Ioctls
======

There is some NILFS2 specific functionality which can be accessed by applications
through the system call interfaces. The list of all NILFS2 specific ioctls are
shown in the table below.

Table of NILFS2 specific ioctls:

 ============================== ===============================================
 Ioctl                                Description
 ============================== ===============================================
 NILFS_IOCTL_CHANGE_CPMODE      Change mode of given checkpoint between
                                checkpoint and snapshot state. This ioctl is
                                used in chcp and mkcp utilities.

 NILFS_IOCTL_DELETE_CHECKPOINT  Remove checkpoint from NILFS2 file system.
                                This ioctl is used in rmcp utility.

 NILFS_IOCTL_GET_CPINFO         Return info about requested checkpoints. This
                                ioctl is used in lscp utility and by
                                nilfs_cleanerd daemon.

 NILFS_IOCTL_GET_CPSTAT         Return checkpoints statistics. This ioctl is
                                used by lscp, rmcp utilities and by
                                nilfs_cleanerd daemon.

 NILFS_IOCTL_GET_SUINFO         Return segment usage info about requested
                                segments. This ioctl is used in lssu,
                                nilfs_resize utilities and by nilfs_cleanerd
                                daemon.

 NILFS_IOCTL_SET_SUINFO         Modify segment usage info of requested
                                segments. This ioctl is used by
                                nilfs_cleanerd daemon to skip unnecessary
                                cleaning operation of segments and reduce
                                performance penalty or wear of flash device
                                due to redundant move of in-use blocks.

 NILFS_IOCTL_GET_SUSTAT         Return segment usage statistics. This ioctl
                                is used in lssu, nilfs_resize utilities and
                                by nilfs_cleanerd daemon.

 NILFS_IOCTL_GET_VINFO          Return information on virtual block addresses.
                                This ioctl is used by nilfs_cleanerd daemon.

 NILFS_IOCTL_GET_BDESCS         Return information about descriptors of disk
                                block numbers. This ioctl is used by
                                nilfs_cleanerd daemon.

 NILFS_IOCTL_CLEAN_SEGMENTS     Do garbage collection operation in the
                                environment of requested parameters from
                                userspace. This ioctl is used by
                                nilfs_cleanerd daemon.

 NILFS_IOCTL_SYNC               Make a checkpoint. This ioctl is used in
                                mkcp utility.

 NILFS_IOCTL_RESIZE             Resize NILFS2 volume. This ioctl is used
                                by nilfs_resize utility.

 NILFS_IOCTL_SET_ALLOC_RANGE    Define lower limit of segments in bytes and
                                upper limit of segments in bytes. This ioctl
                                is used by nilfs_resize utility.
 ============================== ===============================================

생성, mount와 snapshot 관리

154-187

Local filesystem으로 사용하려면 block device에 NILFS2를 만들고 directory에 mount합니다. `mount.nilfs2` helper가 cleaner daemon도 함께 시작합니다.

# mkfs -t nilfs2 /dev/block_device
# mount -t nilfs2 /dev/block_device /dir

`lscp`는 checkpoint·snapshot 목록, `mkcp`는 checkpoint·snapshot 생성, `chcp`는 checkpoint와 snapshot의 상호 전환, `rmcp`는 지정 checkpoint invalidation에 사용합니다. 각 man page는 `nilfs-utils`에 포함됩니다.

Snapshot은 checkpoint number를 `cp=<cno>`로 지정하고 read-only `-r` option과 함께 mount합니다.

# mount -t nilfs2 -r -o cp=<cno> /dev/block_device /snap_dir

Writable mount나 snapshot을 `umount`하면 `umount.nilfs2` helper가 cleaner daemon을 자동으로 종료합니다.

# umount /dir
NILFS2 운영 흐름
mkfs.nilfs2로 volume 생성mount.nilfs2가 writable mount와 cleaner 시작lscp/mkcp/chcp/rmcp로 checkpoint 관리cp=<cno>와 -r로 snapshot 동시 mountumount.nilfs2가 mount 해제와 cleaner 종료

Filesystem 생성부터 snapshot mount와 cleaner 종료까지입니다.

NILFS2 usage
============

To use nilfs2 as a local file system, simply::

 # mkfs -t nilfs2 /dev/block_device
 # mount -t nilfs2 /dev/block_device /dir

This will also invoke the cleaner through the mount helper program
(mount.nilfs2).

Checkpoints and snapshots are managed by the following commands.
Their manpages are included in the nilfs-utils package above.

  ====     ===========================================================
  lscp     list checkpoints or snapshots.
  mkcp     make a checkpoint or a snapshot.
  chcp     change an existing checkpoint to a snapshot or vice versa.
  rmcp     invalidate specified checkpoint(s).
  ====     ===========================================================

To mount a snapshot::

 # mount -t nilfs2 -r -o cp=<cno> /dev/block_device /snap_dir

where <cno> is the checkpoint number of the snapshot.

To unmount the NILFS2 mount point or snapshot, simply::

 # umount /dir

Then, the cleaner daemon is automatically shut down by the umount
helper program (umount.nilfs2).

Segment, log와 file payload 배치

188-220

NILFS2 volume은 superblock(SB)과 segment 0 주변의 예외 영역을 제외하고 같은 크기의 segment로 나뉩니다. 원문의 4 KiB block 예에서는 SB가 1 KiB, segment 0이 4 KiB에서 시작하고 segment 경계는 8 MiB 간격으로 이어집니다.

Segment는 log container이며 각 log는 summary information block, payload block, 선택적인 super root block(SR)으로 구성됩니다.

NILFS2 volume과 log 계층
Volume: SB와 segment 0..N각 segment: log 1..m각 log: summary blocks이어지는 payload blocksCheckpoint log에는 optional super root(SR)

첫 ASCII 도식을 같은 containment 구조로 재구성했습니다.

Payload block은 file별로 묶이며 각 file은 data block과 B-tree node block으로 구성됩니다. Log에는 modified block만 기록하므로 어떤 file group에는 data block 또는 B-tree node block이 없을 수도 있습니다.

Log payload의 file별 배치
File groupData blocksB-tree blocks
File-A변경된 data block, 없을 수 있음변경된 B-tree node, 없을 수 있음
File-B변경된 data block, 없을 수 있음변경된 B-tree node, 없을 수 있음

둘째 ASCII 도식의 File-A와 File-B block 구성을 보존합니다.

Disk format
===========

A nilfs2 volume is equally divided into a number of segments except
for the super block (SB) and segment #0.  A segment is the container
of logs.  Each log is composed of summary information blocks, payload
blocks, and an optional super root block (SR)::

   ______________________________________________________
  | |SB| | Segment | Segment | Segment | ... | Segment | |
  |_|__|_|____0____|____1____|____2____|_____|____N____|_|
  0 +1K +4K       +8M       +16M      +24M  +(8MB x N)
       .             .            (Typical offsets for 4KB-block)
    .                  .
  .______________________.
  | log | log |... | log |
  |__1__|__2__|____|__m__|
        .       .
      .               .
    .                       .
  .______________________________.
  | Summary | Payload blocks  |SR|
  |_blocks__|_________________|__|

The payload blocks are organized per file, and each file consists of
data blocks and B-tree node blocks::

    |<---       File-A        --->|<---       File-B        --->|
   _______________________________________________________________
    | Data blocks | B-tree blocks | Data blocks | B-tree blocks | ...
   _|_____________|_______________|_____________|_______________|_

Summary block, metadata file과 atomic log

221-256

Block organization은 summary information block에 기록됩니다. Summary는 header `nilfs_segment_summary`, file별 `nilfs_finfo`, block별 `nilfs_binfo` structure를 포함합니다.

Summary metadata 배열
Summary blocks와 nilfs_segment_summary headerFile-A의 nilfs_finfoFile-A block 1..Na의 nilfs_binfoFile-B의 nilfs_finfoFile-B block 1..Nb의 nilfs_binfo

셋째 ASCII 도식의 file별 finfo와 block별 binfo 관계입니다.

Log에는 regular file, directory, symbolic link와 filesystem metadata를 유지하는 여러 metadata file이 포함됩니다. 현재 metadata file은 on-disk inode를 저장하는 inode file `ifile`, checkpoint를 저장하는 `cpfile`, segment allocation state를 저장하는 `sufile`, virtual block number를 일반 block number에 mapping해 on-disk block relocation을 가능하게 하는 `DAT`입니다.

NILFS2 log의 file 순서
순서/파일내용
SummaryLog header와 block organization
Regular file/directory사용자 data와 namespace
`ifile`On-disk inode
`cpfile`Checkpoint
`sufile`Segment allocation state
`DAT`Virtual-to-physical block mapping
SRCheckpoint의 super root

넷째 ASCII 도식과 metadata file의 역할입니다.

File sequence가 segment boundary를 넘으면 여러 log로 분할될 수 있습니다. 논리적으로 하나로 취급해야 하는 log sequence는 segment summary의 flag로 경계를 표시하며 NILFS2 recovery code가 이를 읽어 update atomicity를 보장합니다.

Since only the modified blocks are written in the log, it may have
files without data blocks or B-tree node blocks.

The organization of the blocks is recorded in the summary information
blocks, which contains a header structure (nilfs_segment_summary), per
file structures (nilfs_finfo), and per block structures (nilfs_binfo)::

  _________________________________________________________________________
 | Summary | finfo | binfo | ... | binfo | finfo | binfo | ... | binfo |...
 |_blocks__|___A___|_(A,1)_|_____|(A,Na)_|___B___|_(B,1)_|_____|(B,Nb)_|___


The logs include regular files, directory files, symbolic link files
and several meta data files.  The meta data files are the files used
to maintain file system meta data.  The current version of NILFS2 uses
the following meta data files::

 1) Inode file (ifile)             -- Stores on-disk inodes
 2) Checkpoint file (cpfile)       -- Stores checkpoints
 3) Segment usage file (sufile)    -- Stores allocation state of segments
 4) Data address translation file  -- Maps virtual block numbers to usual
    (DAT)                             block numbers.  This file serves to
                                      make on-disk blocks relocatable.

The following figure shows a typical organization of the logs::

  _________________________________________________________________________
 | Summary | regular file | file  | ... | ifile | cpfile | sufile | DAT |SR|
 |_blocks__|_or_directory_|_______|_____|_______|________|________|_____|__|


To stride over segment boundaries, this sequence of files may be split
into multiple logs.  The sequence of logs that should be treated as
logically one log, is delimited with flags marked in the segment
summary.  The recovery code of nilfs2 looks this boundary information
to ensure atomicity of updates.

Super root와 checkpoint별 inode 계층

257-286

Super root block은 모든 checkpoint마다 삽입되며 `DAT`, `cpfile`, `sufile`의 special inode 세 개를 포함합니다.

Regular file, directory, symlink와 다른 special file의 inode는 `ifile`에 들어갑니다. `ifile` 자신의 inode는 해당 checkpoint의 `cpfile` entry에 포함됩니다.

NILFS2 on-disk hierarchy
Super block(SB)최신 checkpoint cno=xx의 super rootSuper root가 DAT·sufile·cpfile inode 보유cpfile이 c1, c2, xx checkpoint별 ifile inode 보유각 ifile이 ino=i1, i2, i3... file inode 보유File inode는 regular file·directory·symlink를 표현

다섯째 ASCII 도식의 SB부터 checkpoint별 file inode까지의 참조입니다.

각 on-disk file format의 상세 정의는 `include/uapi/linux/nilfs2_ondisk.h`를 참조합니다.

NILFS2 설계에는 보호하려는 patent나 다른 intellectual property가 없습니다. 다른 operating system도 이 format의 data를 mount·read·write할 수 있기를 바라며 설계를 복제하는 것을 허용합니다.


The super root block is inserted for every checkpoints.  It includes
three special inodes, inodes for the DAT, cpfile, and sufile.  Inodes
of regular files, directories, symlinks and other special files, are
included in the ifile.  The inode of ifile itself is included in the
corresponding checkpoint entry in the cpfile.  Thus, the hierarchy
among NILFS2 files can be depicted as follows::

  Super block (SB)
       |
       v
  Super root block (the latest cno=xx)
       |-- DAT
       |-- sufile
       `-- cpfile
              |-- ifile (cno=c1)
              |-- ifile (cno=c2) ---- file (ino=i1)
              :        :          |-- file (ino=i2)
              `-- ifile (cno=xx)  |-- file (ino=i3)
                                  :        :
                                  `-- file (ino=yy)
                                    ( regular file, directory, or symlink )

For detail on the format of each file, please see nilfs2_ondisk.h
located at include/uapi/linux directory.

There are no patents or other intellectual property that we protect
with regard to the design of NILFS2.  It is allowed to replicate the
design in hopes that other operating systems could share (mount, read,
write, etc.) data stored in this format.