xref: /OK3568_Linux_fs/kernel/Documentation/filesystems/locks.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun==========================
4*4882a593SmuzhiyunFile Locking Release Notes
5*4882a593Smuzhiyun==========================
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun		Andy Walker <andy@lysaker.kvaerner.no>
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun			    12 May 1997
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun
12*4882a593Smuzhiyun1. What's New?
13*4882a593Smuzhiyun==============
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun1.1 Broken Flock Emulation
16*4882a593Smuzhiyun--------------------------
17*4882a593Smuzhiyun
18*4882a593SmuzhiyunThe old flock(2) emulation in the kernel was swapped for proper BSD
19*4882a593Smuzhiyuncompatible flock(2) support in the 1.3.x series of kernels. With the
20*4882a593Smuzhiyunrelease of the 2.1.x kernel series, support for the old emulation has
21*4882a593Smuzhiyunbeen totally removed, so that we don't need to carry this baggage
22*4882a593Smuzhiyunforever.
23*4882a593Smuzhiyun
24*4882a593SmuzhiyunThis should not cause problems for anybody, since everybody using a
25*4882a593Smuzhiyun2.1.x kernel should have updated their C library to a suitable version
26*4882a593Smuzhiyunanyway (see the file "Documentation/process/changes.rst".)
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun1.2 Allow Mixed Locks Again
29*4882a593Smuzhiyun---------------------------
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun1.2.1 Typical Problems - Sendmail
32*4882a593Smuzhiyun^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
33*4882a593SmuzhiyunBecause sendmail was unable to use the old flock() emulation, many sendmail
34*4882a593Smuzhiyuninstallations use fcntl() instead of flock(). This is true of Slackware 3.0
35*4882a593Smuzhiyunfor example. This gave rise to some other subtle problems if sendmail was
36*4882a593Smuzhiyunconfigured to rebuild the alias file. Sendmail tried to lock the aliases.dir
37*4882a593Smuzhiyunfile with fcntl() at the same time as the GDBM routines tried to lock this
38*4882a593Smuzhiyunfile with flock(). With pre 1.3.96 kernels this could result in deadlocks that,
39*4882a593Smuzhiyunover time, or under a very heavy mail load, would eventually cause the kernel
40*4882a593Smuzhiyunto lock solid with deadlocked processes.
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun1.2.2 The Solution
44*4882a593Smuzhiyun^^^^^^^^^^^^^^^^^^
45*4882a593SmuzhiyunThe solution I have chosen, after much experimentation and discussion,
46*4882a593Smuzhiyunis to make flock() and fcntl() locks oblivious to each other. Both can
47*4882a593Smuzhiyunexists, and neither will have any effect on the other.
48*4882a593Smuzhiyun
49*4882a593SmuzhiyunI wanted the two lock styles to be cooperative, but there were so many
50*4882a593Smuzhiyunrace and deadlock conditions that the current solution was the only
51*4882a593Smuzhiyunpractical one. It puts us in the same position as, for example, SunOS
52*4882a593Smuzhiyun4.1.x and several other commercial Unices. The only OS's that support
53*4882a593Smuzhiyuncooperative flock()/fcntl() are those that emulate flock() using
54*4882a593Smuzhiyunfcntl(), with all the problems that implies.
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun1.3 Mandatory Locking As A Mount Option
58*4882a593Smuzhiyun---------------------------------------
59*4882a593Smuzhiyun
60*4882a593SmuzhiyunMandatory locking, as described in
61*4882a593Smuzhiyun'Documentation/filesystems/mandatory-locking.rst' was prior to this release a
62*4882a593Smuzhiyungeneral configuration option that was valid for all mounted filesystems.  This
63*4882a593Smuzhiyunhad a number of inherent dangers, not the least of which was the ability to
64*4882a593Smuzhiyunfreeze an NFS server by asking it to read a file for which a mandatory lock
65*4882a593Smuzhiyunexisted.
66*4882a593Smuzhiyun
67*4882a593SmuzhiyunFrom this release of the kernel, mandatory locking can be turned on and off
68*4882a593Smuzhiyunon a per-filesystem basis, using the mount options 'mand' and 'nomand'.
69*4882a593SmuzhiyunThe default is to disallow mandatory locking. The intention is that
70*4882a593Smuzhiyunmandatory locking only be enabled on a local filesystem as the specific need
71*4882a593Smuzhiyunarises.
72*4882a593Smuzhiyun
73