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

Linux 6.18.37 · Filesystems

File Locking Release Notes

flock emulation, fcntl 혼용 deadlock, mandatory locking 폐기의 역사적 release note 전문 번역입니다.

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

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

1. 요약·해설

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

요약·해설

locks.rst:1-65

이 문서는 현대 API 설명보다 Linux file locking 정책이 형성된 배경을 기록합니다. BSD 호환 `flock(2)`으로 전환한 뒤 `flock()`과 `fcntl()`을 의도적으로 독립시켜 혼용 deadlock을 피했고, 위험한 mandatory locking mount option은 v5.14에서 제거했습니다.

파일 잠금 정책 변화
결정현재 의미
BSD 호환 flock구형 emulation 제거
flock·fcntl 독립서로의 lock에 영향을 주지 않음
mandatory option 제거v5.14 이후 mount option 없음

세 가지 역사적 결정과 현재 의미입니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 ==========================
4 File Locking Release Notes
5 ==========================
6
7 Andy Walker <andy@lysaker.kvaerner.no>
8
9 12 May 1997
10
11
12 1. What's New?
13 ==============
14
15 1.1 Broken Flock Emulation
16 --------------------------
17
18 The old flock(2) emulation in the kernel was swapped for proper BSD
19 compatible flock(2) support in the 1.3.x series of kernels. With the
20 release of the 2.1.x kernel series, support for the old emulation has
21 been totally removed, so that we don't need to carry this baggage
22 forever.
23
24 This should not cause problems for anybody, since everybody using a
25 2.1.x kernel should have updated their C library to a suitable version
26 anyway (see the file "Documentation/process/changes.rst".)
27
28 1.2 Allow Mixed Locks Again
29 ---------------------------
30
31 1.2.1 Typical Problems - Sendmail
32 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
33 Because sendmail was unable to use the old flock() emulation, many sendmail
34 installations use fcntl() instead of flock(). This is true of Slackware 3.0
35 for example. This gave rise to some other subtle problems if sendmail was
36 configured to rebuild the alias file. Sendmail tried to lock the aliases.dir
37 file with fcntl() at the same time as the GDBM routines tried to lock this
38 file with flock(). With pre 1.3.96 kernels this could result in deadlocks that,
39 over time, or under a very heavy mail load, would eventually cause the kernel
40 to lock solid with deadlocked processes.
41
42
43 1.2.2 The Solution
44 ^^^^^^^^^^^^^^^^^^
45 The solution I have chosen, after much experimentation and discussion,
46 is to make flock() and fcntl() locks oblivious to each other. Both can
47 exists, and neither will have any effect on the other.
48
49 I wanted the two lock styles to be cooperative, but there were so many
50 race and deadlock conditions that the current solution was the only
51 practical one. It puts us in the same position as, for example, SunOS
52 4.1.x and several other commercial Unices. The only OS's that support
53 cooperative flock()/fcntl() are those that emulate flock() using
54 fcntl(), with all the problems that implies.
55
56
57 1.3 Mandatory Locking As A Mount Option
58 ---------------------------------------
59
60 Mandatory locking was prior to this release a general configuration option
61 that was valid for all mounted filesystems. This had a number of inherent
62 dangers, not the least of which was the ability to freeze an NFS server by
63 asking it to read a file for which a mandatory lock existed.
64
65 Such option was dropped in Kernel v5.14.
66

3. 한국어 전문 번역

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

BSD 호환 flock으로의 전환

1-27

이 GPL-2.0 문서는 Andy Walker가 1997년 5월 12일 작성한 파일 잠금 release note입니다. 역사적 kernel series에서 `flock(2)` 구현이 어떻게 바뀌었는지와 이후 정책을 기록합니다.

기존 커널의 `flock(2)` emulation은 1.3.x kernel series에서 올바른 BSD 호환 `flock(2)` 지원으로 교체되었습니다. 2.1.x series가 출시되면서 오래된 emulation 지원은 완전히 제거되었고, 더는 그 호환성 부담을 계속 유지하지 않게 되었습니다.

2.1.x kernel 사용자는 적절한 버전으로 C library를 이미 갱신했어야 하므로 이 제거가 사용자에게 문제를 일으키지는 않을 것으로 보았습니다. 관련 요구 버전은 `Documentation/process/changes.rst`를 참고합니다.

`flock(2)` 구현 전환
기존 kernel의 flock emulation1.3.x: BSD 호환 `flock(2)` 도입2.1.x: 구형 emulation 완전 제거C library 갱신을 전제로 호환성 부담 종료

오래된 emulation에서 BSD 호환 구현으로 이동한 역사입니다.

.. SPDX-License-Identifier: GPL-2.0

==========================
File Locking Release Notes
==========================

                Andy Walker <andy@lysaker.kvaerner.no>

                            12 May 1997


1. What's New?
==============

1.1 Broken Flock Emulation
--------------------------

The old flock(2) emulation in the kernel was swapped for proper BSD
compatible flock(2) support in the 1.3.x series of kernels. With the
release of the 2.1.x kernel series, support for the old emulation has
been totally removed, so that we don't need to carry this baggage
forever.

This should not cause problems for anybody, since everybody using a
2.1.x kernel should have updated their C library to a suitable version
anyway (see the file "Documentation/process/changes.rst".)

flock과 fcntl 혼용 문제 및 해결

28-56

Sendmail은 오래된 `flock()` emulation을 사용할 수 없었기 때문에 Slackware 3.0을 비롯한 많은 설치에서 `flock()` 대신 `fcntl()`을 사용했습니다. Sendmail이 alias 파일을 다시 만들도록 설정된 경우 이 선택이 미묘한 문제를 일으켰습니다.

Sendmail이 `aliases.dir` 파일을 `fcntl()`로 잠그는 동시에 GDBM routine이 같은 파일을 `flock()`으로 잠그려고 했습니다. 1.3.96 이전 kernel에서는 이것이 deadlock으로 이어질 수 있었으며, 시간이 지나거나 mail load가 매우 높을 때 deadlock된 process 때문에 결국 kernel 전체가 멈출 수 있었습니다.

많은 실험과 논의 끝에 채택한 해결책은 `flock()` lock과 `fcntl()` lock이 서로를 전혀 인식하지 않도록 만드는 것이었습니다. 두 방식은 동시에 존재할 수 있지만 어느 쪽도 다른 쪽에 영향을 주지 않습니다.

두 lock 방식을 협력하게 만들고 싶었지만 race와 deadlock 조건이 너무 많아 독립시키는 방법만이 실용적이었습니다. 이는 SunOS 4.1.x와 여러 상용 Unix의 동작과 같습니다. `flock()`과 `fcntl()`을 협력시키는 운영체제는 `fcntl()`로 `flock()`을 emulation하는 계열뿐이며, 그 방식에는 앞서 설명한 문제가 따릅니다.

혼합 lock의 최종 정책
항목정책
동시 존재허용
상호 영향없음
협력형 emulationrace·deadlock 때문에 채택하지 않음
비슷한 체계SunOS 4.1.x 및 여러 상용 Unix

`flock()`과 `fcntl()`은 같은 파일에서도 독립된 lock namespace처럼 동작합니다.

1.2 Allow Mixed Locks Again
---------------------------

1.2.1 Typical Problems - Sendmail
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Because sendmail was unable to use the old flock() emulation, many sendmail
installations use fcntl() instead of flock(). This is true of Slackware 3.0
for example. This gave rise to some other subtle problems if sendmail was
configured to rebuild the alias file. Sendmail tried to lock the aliases.dir
file with fcntl() at the same time as the GDBM routines tried to lock this
file with flock(). With pre 1.3.96 kernels this could result in deadlocks that,
over time, or under a very heavy mail load, would eventually cause the kernel
to lock solid with deadlocked processes.


1.2.2 The Solution
^^^^^^^^^^^^^^^^^^
The solution I have chosen, after much experimentation and discussion,
is to make flock() and fcntl() locks oblivious to each other. Both can
exists, and neither will have any effect on the other.

I wanted the two lock styles to be cooperative, but there were so many
race and deadlock conditions that the current solution was the only
practical one. It puts us in the same position as, for example, SunOS
4.1.x and several other commercial Unices. The only OS's that support
cooperative flock()/fcntl() are those that emulate flock() using
fcntl(), with all the problems that implies.

Mandatory locking mount option의 폐기

57-65

이 release 이전에는 mandatory locking이 모든 mounted filesystem에 유효한 전역 configuration option이었습니다. 이 설계에는 본질적인 위험이 여러 가지 있었습니다.

대표적인 위험은 mandatory lock이 걸린 파일을 NFS server에 읽도록 요청하여 server를 멈출 수 있다는 점입니다. 이러한 mount option은 Kernel v5.14에서 제거되었습니다.

Mandatory locking의 결론
모든 mount에 적용되는 전역 optionmandatory lock 파일 읽기 요청NFS server 정지 가능Kernel v5.14에서 option 제거

전역 설정이 만든 서비스 거부 위험 때문에 기능이 제거되었습니다.

1.3 Mandatory Locking As A Mount Option
---------------------------------------

Mandatory locking was prior to this release a general configuration option
that was valid for all mounted filesystems.  This had a number of inherent
dangers, not the least of which was the ability to freeze an NFS server by
asking it to read a file for which a mandatory lock existed.

Such option was dropped in Kernel v5.14.