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

Linux 6.18.37 · Filesystems

Linux Directory Notification

dnotify event mask, signal delivery, remote·hard-link 한계와 inotify 대체를 다룬 전문 번역입니다.

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

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

1. 요약·해설

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

요약·해설

dnotify.rst:1-75

dnotify는 directory fd에 `fcntl(F_NOTIFY)`를 등록하고 signal로 child 변화를 알리는 legacy interface입니다. realtime signal과 `DN_MULTISHOT`을 지원하지만 hard-link alias 추적에 한계가 있으며 Linux 2.6.13부터 inotify로 대체되었습니다.

dnotify lifetime
directory fd openevent mask와 `F_NOTIFY` 등록선택적으로 `F_SETSIG` 설정signal과 `si_fd` 수신single-shot 재등록 또는 multishot 유지

등록부터 signal 수신과 재등록·해제까지의 흐름입니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 ============================
4 Linux Directory Notification
5 ============================
6
7 Stephen Rothwell <[email protected]>
8
9 The intention of directory notification is to allow user applications
10 to be notified when a directory, or any of the files in it, are changed.
11 The basic mechanism involves the application registering for notification
12 on a directory using a fcntl(2) call and the notifications themselves
13 being delivered using signals.
14
15 The application decides which "events" it wants to be notified about.
16 The currently defined events are:
17
18 ========= =====================================================
19 DN_ACCESS A file in the directory was accessed (read)
20 DN_MODIFY A file in the directory was modified (write,truncate)
21 DN_CREATE A file was created in the directory
22 DN_DELETE A file was unlinked from directory
23 DN_RENAME A file in the directory was renamed
24 DN_ATTRIB A file in the directory had its attributes
25 changed (chmod,chown)
26 ========= =====================================================
27
28 Usually, the application must reregister after each notification, but
29 if DN_MULTISHOT is or'ed with the event mask, then the registration will
30 remain until explicitly removed (by registering for no events).
31
32 By default, SIGIO will be delivered to the process and no other useful
33 information. However, if the F_SETSIG fcntl(2) call is used to let the
34 kernel know which signal to deliver, a siginfo structure will be passed to
35 the signal handler and the si_fd member of that structure will contain the
36 file descriptor associated with the directory in which the event occurred.
37
38 Preferably the application will choose one of the real time signals
39 (SIGRTMIN + <n>) so that the notifications may be queued. This is
40 especially important if DN_MULTISHOT is specified. Note that SIGRTMIN
41 is often blocked, so it is better to use (at least) SIGRTMIN + 1.
42
43 Implementation expectations (features and bugs :-))
44 ---------------------------------------------------
45
46 The notification should work for any local access to files even if the
47 actual file system is on a remote server. This implies that remote
48 access to files served by local user mode servers should be notified.
49 Also, remote accesses to files served by a local kernel NFS server should
50 be notified.
51
52 In order to make the impact on the file system code as small as possible,
53 the problem of hard links to files has been ignored. So if a file (x)
54 exists in two directories (a and b) then a change to the file using the
55 name "a/x" should be notified to a program expecting notifications on
56 directory "a", but will not be notified to one expecting notifications on
57 directory "b".
58
59 Also, files that are unlinked, will still cause notifications in the
60 last directory that they were linked to.
61
62 Configuration
63 -------------
64
65 Dnotify is controlled via the CONFIG_DNOTIFY configuration option. When
66 disabled, fcntl(fd, F_NOTIFY, ...) will return -EINVAL.
67
68 Example
69 -------
70 See tools/testing/selftests/filesystems/dnotify_test.c for an example.
71
72 NOTE
73 ----
74 Beginning with Linux 2.6.13, dnotify has been replaced by inotify.
75 See Documentation/filesystems/inotify.rst for more information on it.
76

3. 한국어 전문 번역

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

등록 방식, event mask와 multishot

1-30

directory notification은 directory 자체나 그 안의 file이 바뀔 때 userspace application에 알리기 위한 기능입니다. application은 `fcntl(2)`로 directory notification을 등록하고 kernel은 signal로 알림을 전달합니다.

`DN_ACCESS`는 directory 안 file의 read 접근, `DN_MODIFY`는 write 또는 truncate, `DN_CREATE`는 생성, `DN_DELETE`는 unlink, `DN_RENAME`은 이름 변경, `DN_ATTRIB`는 `chmod`나 `chown`에 따른 attribute 변경을 나타냅니다.

보통 application은 notification을 받을 때마다 다시 등록해야 합니다. event mask에 `DN_MULTISHOT`을 OR하면 event를 하나도 등록하지 않는 방식으로 명시적으로 제거할 때까지 등록이 유지됩니다.

dnotify event mask
Event의미
`DN_ACCESS`file read
`DN_MODIFY`file write 또는 truncate
`DN_CREATE`directory 안 file 생성
`DN_DELETE`directory에서 file unlink
`DN_RENAME`file rename
`DN_ATTRIB``chmod`·`chown` attribute 변경
`DN_MULTISHOT`명시적 해제까지 등록 유지

directory 아래에서 감시할 수 있는 변화 종류입니다.

.. SPDX-License-Identifier: GPL-2.0

============================
Linux Directory Notification
============================

           Stephen Rothwell <[email protected]>

The intention of directory notification is to allow user applications
to be notified when a directory, or any of the files in it, are changed.
The basic mechanism involves the application registering for notification
on a directory using a fcntl(2) call and the notifications themselves
being delivered using signals.

The application decides which "events" it wants to be notified about.
The currently defined events are:

        =========        =====================================================
        DN_ACCESS        A file in the directory was accessed (read)
        DN_MODIFY        A file in the directory was modified (write,truncate)
        DN_CREATE        A file was created in the directory
        DN_DELETE        A file was unlinked from directory
        DN_RENAME        A file in the directory was renamed
        DN_ATTRIB        A file in the directory had its attributes
                        changed (chmod,chown)
        =========        =====================================================

Usually, the application must reregister after each notification, but
if DN_MULTISHOT is or'ed with the event mask, then the registration will
remain until explicitly removed (by registering for no events).

SIGIO, F_SETSIG와 realtime queue

31-42

기본값은 process에 `SIGIO`만 전달하며 다른 유용한 정보는 없습니다. `F_SETSIG` `fcntl(2)` call로 전달할 signal을 kernel에 알려 주면 signal handler에 `siginfo` structure가 전달되고, `si_fd`에는 event가 발생한 directory의 file descriptor가 들어갑니다.

notification이 queue될 수 있도록 realtime signal인 `SIGRTMIN + <n>`을 선택하는 것이 좋습니다. `DN_MULTISHOT`을 쓸 때 특히 중요합니다. `SIGRTMIN` 자체는 흔히 block되어 있으므로 최소 `SIGRTMIN + 1`을 사용하는 편이 낫습니다.

dnotify signal delivery
application이 directory fd에 `F_NOTIFY` 등록필요하면 `F_SETSIG`로 realtime signal 선택directory 또는 child file event 발생kernel이 `siginfo`와 signal 전달handler가 `si_fd`로 event directory 식별

directory event에서 queue 가능한 signal과 fd 정보가 전달되는 과정입니다.


By default, SIGIO will be delivered to the process and no other useful
information.  However, if the F_SETSIG fcntl(2) call is used to let the
kernel know which signal to deliver, a siginfo structure will be passed to
the signal handler and the si_fd member of that structure will contain the
file descriptor associated with the directory in which the event occurred.

Preferably the application will choose one of the real time signals
(SIGRTMIN + <n>) so that the notifications may be queued.  This is
especially important if DN_MULTISHOT is specified.  Note that SIGRTMIN
is often blocked, so it is better to use (at least) SIGRTMIN + 1.

Remote access와 hard link 한계

43-60

실제 filesystem이 remote server에 있어도 local access로 발생한 변화에는 notification이 동작해야 합니다. local userspace server가 제공하는 file에 대한 remote access와 local kernel NFS server가 제공하는 file에 대한 remote access도 notification 대상이어야 합니다.

filesystem code에 미치는 영향을 줄이기 위해 hard link 문제는 무시합니다. file `x`가 directory `a`와 `b`에 함께 존재할 때 `a/x`라는 이름으로 변경하면 `a`를 감시하는 program에는 알리지만 `b`를 감시하는 program에는 알리지 않습니다.

unlink된 file도 마지막으로 연결되어 있던 directory에서 계속 notification을 발생시킵니다.

dnotify 관찰 범위
상황Notification
remote filesystem에 대한 local access발생
local userspace server가 제공한 file의 remote access발생 기대
local kernel NFS server의 remote access발생 기대
다른 hard-link 이름을 통한 변경그 이름의 directory에만 발생
unlink된 file의 후속 변화마지막 연결 directory에 발생

지원되는 local 관찰과 이름 기반 hard-link 한계를 비교합니다.

Implementation expectations (features and bugs :-))
---------------------------------------------------

The notification should work for any local access to files even if the
actual file system is on a remote server.  This implies that remote
access to files served by local user mode servers should be notified.
Also, remote accesses to files served by a local kernel NFS server should
be notified.

In order to make the impact on the file system code as small as possible,
the problem of hard links to files has been ignored.  So if a file (x)
exists in two directories (a and b) then a change to the file using the
name "a/x" should be notified to a program expecting notifications on
directory "a", but will not be notified to one expecting notifications on
directory "b".

Also, files that are unlinked, will still cause notifications in the
last directory that they were linked to.

CONFIG_DNOTIFY, test와 inotify 대체

61-75

dnotify는 `CONFIG_DNOTIFY` configuration option으로 제어합니다. 비활성화되어 있으면 `fcntl(fd, F_NOTIFY, ...)`가 `-EINVAL`을 반환합니다.

사용 예제는 source path `tools/testing/selftests/filesystems/dnotify_test.c`에 있습니다.

Linux 2.6.13부터 dnotify는 inotify로 대체되었습니다. 자세한 내용은 `Documentation/filesystems/inotify.rst`를 참고합니다.

dnotify 사용 판단
`CONFIG_DNOTIFY` 활성 여부 확인directory fd에 `F_NOTIFY` 등록selftest로 동작 검증새 application은 Linux 2.6.13 이후 inotify 우선 검토

kernel configuration과 대체 API를 확인하는 간단한 경로입니다.


Configuration
-------------

Dnotify is controlled via the CONFIG_DNOTIFY configuration option.  When
disabled, fcntl(fd, F_NOTIFY, ...) will return -EINVAL.

Example
-------
See tools/testing/selftests/filesystems/dnotify_test.c for an example.

NOTE
----
Beginning with Linux 2.6.13, dnotify has been replaced by inotify.
See Documentation/filesystems/inotify.rst for more information on it.