annotate docs/locking.txt @ 0:ada5e610ab86

imap-2007e
author yuuji@gentei.org
date Mon, 14 Sep 2009 15:17:45 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1 /* ========================================================================
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
2 * Copyright 1988-2006 University of Washington
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
3 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
4 * Licensed under the Apache License, Version 2.0 (the "License");
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
5 * you may not use this file except in compliance with the License.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
6 * You may obtain a copy of the License at
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
7 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
8 * http://www.apache.org/licenses/LICENSE-2.0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
9 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
10 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
11 * ========================================================================
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
12 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
13
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
14 UNIX Advisory File Locking Implications on c-client
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
15 Mark Crispin, 28 November 1995
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
16
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
17
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
18 THIS DOCUMENT HAS BEEN UPDATED TO REFLECT THE FACT THAT
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
19 LINUX SUPPORTS BOTH flock() AND fcntl() AND THAT OSF/1
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
20 HAS BEEN BROKEN SO THAT IT ONLY SUPPORTS fcntl().
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
21 -- JUNE 15, 2004
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
22
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
23 THIS DOCUMENT HAS BEEN UPDATED TO REFLECT THE CODE IN THE
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
24 IMAP-4 TOOLKIT AS OF NOVEMBER 28, 1995. SOME STATEMENTS
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
25 IN THIS DOCUMENT DO NOT APPLY TO EARLIER VERSIONS OF THE
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
26 IMAP TOOLKIT.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
27
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
28 INTRODUCTION
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
29
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
30 Advisory locking is a mechanism by which cooperating processes
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
31 can signal to each other their usage of a resource and whether or not
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
32 that usage is critical. It is not a mechanism to protect against
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
33 processes which do not cooperate in the locking.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
34
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
35 The most basic form of locking involves a counter. This counter
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
36 is -1 when the resource is available. If a process wants the lock, it
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
37 executes an atomic increment-and-test-if-zero. If the value is zero,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
38 the process has the lock and can execute the critical code that needs
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
39 exclusive usage of a resource. When it is finished, it sets the lock
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
40 back to -1. In C terms:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
41
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
42 while (++lock) /* try to get lock */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
43 invoke_other_threads (); /* failed, try again */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
44 .
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
45 . /* critical code here */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
46 .
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
47 lock = -1; /* release lock */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
48
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
49 This particular form of locking appears most commonly in
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
50 multi-threaded applications such as operating system kernels. It
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
51 makes several presumptions:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
52 (1) it is alright to keep testing the lock (no overflow)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
53 (2) the critical resource is single-access only
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
54 (3) there is shared writeable memory between the two threads
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
55 (4) the threads can be trusted to release the lock when finished
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
56
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
57 In applications programming on multi-user systems, most commonly
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
58 the other threads are in an entirely different process, which may even
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
59 be logged in as a different user. Few operating systems offer shared
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
60 writeable memory between such processes.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
61
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
62 A means of communicating this is by use of a file with a mutually
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
63 agreed upon name. A binary semaphore can be passed by means of the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
64 existance or non-existance of that file, provided that there is an
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
65 atomic means to create a file if and only if that file does not exist.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
66 In C terms:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
67
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
68 /* try to get lock */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
69 while ((fd = open ("lockfile",O_WRONLY|O_CREAT|O_EXCL,0666)) < 0)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
70 sleep (1); /* failed, try again */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
71 close (fd); /* got the lock */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
72 .
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
73 . /* critical code here */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
74 .
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
75 unlink ("lockfile"); /* release lock */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
76
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
77 This form of locking makes fewer presumptions, but it still is
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
78 guilty of presumptions (2) and (4) above. Presumption (2) limits the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
79 ability to have processes sharing a resource in a non-conflicting
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
80 fashion (e.g. reading from a file). Presumption (4) leads to
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
81 deadlocks should the process crash while it has a resource locked.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
82
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
83 Most modern operating systems provide a resource locking system
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
84 call that has none of these presumptions. In particular, a mechanism
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
85 is provided for identifying shared locks as opposed to exclusive
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
86 locks. A shared lock permits other processes to obtain a shared lock,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
87 but denies exclusive locks. In other words:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
88
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
89 current state want shared want exclusive
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
90 ------------- ----------- --------------
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
91 unlocked YES YES
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
92 locked shared YES NO
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
93 locked exclusive NO NO
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
94
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
95 Furthermore, the operating system automatically relinquishes all
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
96 locks held by that process when it terminates.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
97
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
98 A useful operation is the ability to upgrade a shared lock to
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
99 exclusive (provided there are no other shared users of the lock) and
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
100 to downgrade an exclusive lock to shared. It is important that at no
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
101 time is the lock ever removed; a process upgrading to exclusive must
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
102 not relenquish its shared lock.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
103
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
104 Most commonly, the resources being locked are files. Shared
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
105 locks are particularly important with files; multiple simultaneous
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
106 processes can read from a file, but only one can safely write at a
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
107 time. Some writes may be safer than others; an append to the end of
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
108 the file is safer than changing existing file data. In turn, changing
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
109 a file record in place is safer than rewriting the file with an
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
110 entirely different structure.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
111
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
112
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
113 FILE LOCKING ON UNIX
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
114
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
115 In the oldest versions of UNIX, the use of a semaphore lockfile
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
116 was the only available form of locking. Advisory locking system calls
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
117 were not added to UNIX until after the BSD vs. System V split. Both
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
118 of these system calls deal with file resources only.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
119
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
120 Most systems only have one or the other form of locking. AIX
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
121 and newer versions of OSF/1 emulate the BSD form of locking as a jacket
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
122 into the System V form. Ultrix and Linux implement both forms.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
123
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
124 BSD
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
125
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
126 BSD added the flock() system call. It offers capabilities to
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
127 acquire shared lock, acquire exclusive lock, and unlock. Optionally,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
128 the process can request an immediate error return instead of blocking
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
129 when the lock is unavailable.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
130
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
131
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
132 FLOCK() BUGS
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
133
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
134 flock() advertises that it permits upgrading of shared locks to
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
135 exclusive and downgrading of exclusive locks to shared, but it does so
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
136 by releasing the former lock and then trying to acquire the new lock.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
137 This creates a window of vulnerability in which another process can
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
138 grab the exclusive lock. Therefore, this capability is not useful,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
139 although many programmers have been deluded by incautious reading of
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
140 the flock() man page to believe otherwise. This problem can be
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
141 programmed around, once the programmer is aware of it.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
142
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
143 flock() always returns as if it succeeded on NFS files, when in
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
144 fact it is a no-op. There is no way around this.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
145
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
146 Leaving aside these two problems, flock() works remarkably well,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
147 and has shown itself to be robust and trustworthy.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
148
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
149 SYSTEM V/POSIX
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
150
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
151 System V added new functions to the fnctl() system call, and a
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
152 simple interface through the lockf() subroutine. This was
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
153 subsequently included in POSIX. Both offer the facility to apply the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
154 lock to a particular region of the file instead of to the entire file.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
155 lockf() only supports exclusive locks, and calls fcntl() internally;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
156 hence it won't be discussed further.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
157
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
158 Functionally, fcntl() locking is a superset of flock(); it is
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
159 possible to implement a flock() emulator using fcntl(), with one minor
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
160 exception: it is not possible to acquire an exclusive lock if the file
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
161 is not open for write.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
162
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
163 The fcntl() locking functions are: query lock station of a file
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
164 region, lock/unlock a region, and lock/unlock a region and block until
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
165 have the lock. The locks may be shared or exclusive. By means of the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
166 statd and lockd daemons, fcntl() locking is available on NFS files.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
167
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
168 When statd is started at system boot, it reads its /etc/state
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
169 file (which contains the number of times it has been invoked) and
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
170 /etc/sm directory (which contains a list of all remote sites which are
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
171 client or server locking with this site), and notifies the statd on
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
172 each of these systems that it has been restarted. Each statd then
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
173 notifies the local lockd of the restart of that system.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
174
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
175 lockd receives fcntl() requests for NFS files. It communicates
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
176 with the lockd at the server and requests it to apply the lock, and
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
177 with the statd to request it for notification when the server goes
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
178 down. It blocks until all these requests are completed.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
179
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
180 There is quite a mythos about fcntl() locking.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
181
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
182 One religion holds that fcntl() locking is the best thing since
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
183 sliced bread, and that programs which use flock() should be converted
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
184 to fcntl() so that NFS locking will work. However, as noted above,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
185 very few systems support both calls, so such an exercise is pointless
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
186 except on Ultrix and Linux.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
187
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
188 Another religion, which I adhere to, has the opposite viewpoint.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
189
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
190
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
191 FCNTL() BUGS
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
192
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
193 For all of the hairy code to do individual section locking of a
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
194 file, it's clear that the designers of fcntl() locking never
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
195 considered some very basic locking operations. It's as if all they
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
196 knew about locking they got out of some CS textbook with not
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
197 investigation of real-world needs.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
198
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
199 It is not possible to acquire an exclusive lock unless the file
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
200 is open for write. You could have append with shared read, and thus
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
201 you could have a case in which a read-only access may need to go
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
202 exclusive. This problem can be programmed around once the programmer
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
203 is aware of it.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
204
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
205 If the file is opened on another file designator in the same
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
206 process, the file is unlocked even if no attempt is made to do any
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
207 form of locking on the second designator. This is a very bad bug. It
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
208 means that an application must keep track of all the files that it has
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
209 opened and locked.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
210
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
211 If there is no statd/lockd on the NFS server, fcntl() will hang
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
212 forever waiting for them to appear. This is a bad bug. It means that
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
213 any attempt to lock on a server that doesn't run these daemons will
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
214 hang. There is no way for an application to request flock() style
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
215 ``try to lock, but no-op if the mechanism ain't there''.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
216
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
217 There is a rumor to the effect that fcntl() will hang forever on
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
218 local files too if there is no local statd/lockd. These daemons are
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
219 running on mailer.u, although they appear not to have much CPU time.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
220 A useful experiment would be to kill them and see if imapd is affected
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
221 in any way, but I decline to do so without an OK from UCS! ;-) If
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
222 killing statd/lockd can be done without breaking fcntl() on local
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
223 files, this would become one of the primary means of dealing with this
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
224 problem.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
225
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
226 The statd and lockd daemons have quite a reputation for extreme
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
227 fragility. There have been numerous reports about the locking
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
228 mechanism being wedged on a systemwide or even clusterwide basis,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
229 requiring a reboot to clear. It is rumored that this wedge, once it
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
230 happens, also blocks local locking. Presumably killing and restarting
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
231 statd would suffice to clear the wedge, but I haven't verified this.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
232
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
233 There appears to be a limit to how many locks may be in use at a
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
234 time on the system, although the documentation only mentions it in
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
235 passing. On some of their systems, UCS has increased lockd's ``size
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
236 of the socket buffer'', whatever that means.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
237
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
238 C-CLIENT USAGE
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
239
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
240 c-client uses flock(). On System V systems, flock() is simulated
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
241 by an emulator that calls fcntl().
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
242
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
243
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
244 BEZERK AND MMDF
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
245
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
246 Locking in the traditional UNIX formats was largely dictated by
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
247 the status quo in other applications; however, additional protection
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
248 is added against inadvertantly running multiple instances of a
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
249 c-client application on the same mail file.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
250
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
251 (1) c-client attempts to create a .lock file (mail file name with
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
252 ``.lock'' appended) whenever it reads from, or writes to, the mail
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
253 file. This is an exclusive lock, and is held only for short periods
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
254 of time while c-client is actually doing the I/O. There is a 5-minute
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
255 timeout for this lock, after which it is broken on the presumption
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
256 that it is a stale lock. If it can not create the .lock file due to
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
257 an EACCES (protection failure) error, it once silently proceeded
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
258 without this lock; this was for systems which protect /usr/spool/mail
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
259 from unprivileged processes creating files. Today, c-client reports
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
260 an error unless it is built otherwise. The purpose of this lock is to
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
261 prevent against unfavorable interactions with mail delivery.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
262
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
263 (2) c-client applies a shared flock() to the mail file whenever
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
264 it reads from the mail file, and an exclusive flock() whenever it
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
265 writes to the mail file. This lock is freed as soon as it finishes
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
266 reading. The purpose of this lock is to prevent against unfavorable
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
267 interactions with mail delivery.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
268
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
269 (3) c-client applies an exclusive flock() to a file on /tmp
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
270 (whose name represents the device and inode number of the file) when
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
271 it opens the mail file. This lock is maintained throughout the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
272 session, although c-client has a feature (called ``kiss of death'')
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
273 which permits c-client to forcibly and irreversibly seize the lock
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
274 from a cooperating c-client application that surrenders the lock on
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
275 demand. The purpose of this lock is to prevent against unfavorable
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
276 interactions with other instances of c-client (rewriting the mail
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
277 file).
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
278
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
279 Mail delivery daemons use lock (1), (2), or both. Lock (1) works
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
280 over NFS; lock (2) is the only one that works on sites that protect
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
281 /usr/spool/mail against unprivileged file creation. Prudent mail
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
282 delivery daemons use both forms of locking, and of course so does
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
283 c-client.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
284
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
285 If only lock (2) is used, then multiple processes can read from
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
286 the mail file simultaneously, although in real life this doesn't
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
287 really change things. The normal state of locks (1) and (2) is
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
288 unlocked except for very brief periods.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
289
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
290
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
291 TENEX AND MTX
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
292
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
293 The design of the locking mechanism of these formats was
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
294 motivated by a design to enable multiple simultaneous read/write
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
295 access. It is almost the reverse of how locking works with
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
296 bezerk/mmdf.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
297
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
298 (1) c-client applies a shared flock() to the mail file when it
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
299 opens the mail file. It upgrades this lock to exclusive whenever it
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
300 tries to expunge the mail file. Because of the flock() bug that
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
301 upgrading a lock actually releases it, it will not do so until it has
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
302 acquired an exclusive lock (2) first. The purpose of this lock is to
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
303 prevent against expunge taking place while some other c-client has the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
304 mail file open (and thus knows where all the messages are).
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
305
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
306 (2) c-client applies a shared flock() to a file on /tmp (whose
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
307 name represents the device and inode number of the file) when it
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
308 parses the mail file. It applies an exclusive flock() to this file
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
309 when it appends new mail to the mail file, as well as before it
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
310 attempts to upgrade lock (1) to exclusive. The purpose of this lock
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
311 is to prevent against data being appended while some other c-client is
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
312 parsing mail in the file (to prevent reading of incomplete messages).
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
313 It also protects against the lock-releasing timing race on lock (1).
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
314
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
315 OBSERVATIONS
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
316
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
317 In a perfect world, locking works. You are protected against
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
318 unfavorable interactions with the mailer and against your own mistake
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
319 by running more than one instance of your mail reader. In tenex/mtx
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
320 formats, you have the additional benefit that multiple simultaneous
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
321 read/write access works, with the sole restriction being that you
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
322 can't expunge if there are any sharers of the mail file.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
323
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
324 If the mail file is NFS-mounted, then flock() locking is a silent
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
325 no-op. This is the way BSD implements flock(), and c-client's
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
326 emulation of flock() through fcntl() tests for NFS files and
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
327 duplicates this functionality. There is no locking protection for
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
328 tenex/mtx mail files at all, and only protection against the mailer
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
329 for bezerk/mmdf mail files. This has been the accepted state of
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
330 affairs on UNIX for many sad years.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
331
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
332 If you can not create .lock files, it should not affect locking,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
333 since the flock() locks suffice for all protection. This is, however,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
334 not true if the mailer does not check for flock() locking, or if the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
335 the mail file is NFS-mounted.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
336
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
337 What this means is that there is *no* locking protection at all
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
338 in the case of a client using an NFS-mounted /usr/spool/mail that does
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
339 not permit file creation by unprivileged programs. It is impossible,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
340 under these circumstances, for an unprivileged program to do anything
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
341 about it. Worse, if EACCES errors on .lock file creation are no-op'ed
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
342 , the user won't even know about it. This is arguably a site
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
343 configuration error.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
344
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
345 The problem with not being able to create .lock files exists on
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
346 System V as well, but the failure modes for flock() -- which is
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
347 implemented via fcntl() -- are different.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
348
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
349 On System V, if the mail file is NFS-mounted and either the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
350 client or the server lacks a functioning statd/lockd pair, then the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
351 lock attempt would have hung forever if it weren't for the fact that
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
352 c-client tests for NFS and no-ops the flock() emulator in this case.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
353 Systemwide or clusterwide failures of statd/lockd have been known to
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
354 occur which cause all locks in all processes to hang (including
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
355 local?). Without the special NFS test made by c-client, there would
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
356 be no way to request BSD-style no-op behavior, nor is there any way to
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
357 determine that this is happening other than the system being hung.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
358
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
359 The additional locking introduced by c-client was shown to cause
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
360 much more stress on the System V locking mechanism than has
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
361 traditionally been placed upon it. If it was stressed too far, all
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
362 hell broke loose. Fortunately, this is now past history.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
363
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
364 TRADEOFFS
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
365
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
366 c-client based applications have a reasonable chance of winning
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
367 as long as you don't use NFS for remote access to mail files. That's
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
368 what IMAP is for, after all. It is, however, very important to
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
369 realize that you can *not* use the lock-upgrade feature by itself
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
370 because it releases the lock as an interim step -- you need to have
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
371 lock-upgrading guarded by another lock.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
372
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
373 If you have the misfortune of using System V, you are likely to
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
374 run into problems sooner or later having to do with statd/lockd. You
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
375 basically end up with one of three unsatisfactory choices:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
376 1) Grit your teeth and live with it.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
377 2) Try to make it work:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
378 a) avoid NFS access so as not to stress statd/lockd.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
379 b) try to understand the code in statd/lockd and hack it
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
380 to be more robust.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
381 c) hunt out the system limit of locks, if there is one,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
382 and increase it. Figure on at least two locks per
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
383 simultaneous imapd process and four locks per Pine
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
384 process. Better yet, make the limit be 10 times the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
385 maximum number of processes.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
386 d) increase the socket buffer (-S switch to lockd) if
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
387 it is offered. I don't know what this actually does,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
388 but giving lockd more resources to do its work can't
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
389 hurt. Maybe.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
390 3) Decide that it can't possibly work, and turn off the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
391 fcntl() calls in your program.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
392 4) If nuking statd/lockd can be done without breaking local
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
393 locking, then do so. This would make SVR4 have the same
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
394 limitations as BSD locking, with a couple of additional
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
395 bugs.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
396 5) Check for NFS, and don't do the fcntl() in the NFS case.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
397 This is what c-client does.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
398
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
399 Note that if you are going to use NFS to access files on a server
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
400 which does not have statd/lockd running, your only choice is (3), (4),
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
401 or (5). Here again, IMAP can bail you out.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
402
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
403 These problems aren't unique to c-client applications; they have
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
404 also been reported with Elm, Mediamail, and other email tools.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
405
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
406 Of the other two SVR4 locking bugs:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
407
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
408 Programmer awareness is necessary to deal with the bug that you
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
409 can not get an exclusive lock unless the file is open for write. I
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
410 believe that c-client has fixed all of these cases.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
411
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
412 The problem about opening a second designator smashing any
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
413 current locks on the file has not been addressed satisfactorily yet.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
414 This is not an easy problem to deal with, especially in c-client which
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
415 really doesn't know what other files/streams may be open by Pine.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
416
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
417 Aren't you so happy that you bought an System V system?

yatex.org