Another set of validation updates
[Samba.git] / docs / Samba-HOWTO-Collection / locking.xml
blobabf87479686d743c0c7083f97a533bd21c4657e2
1 <?xml version="1.0" encoding="iso-8859-1"?>
2 <!DOCTYPE chapter PUBLIC "-//Samba-Team//DTD DocBook V4.2-Based Variant V1.0//EN" "http://www.samba.org/samba/DTD/samba-doc">
3 <chapter id="locking">
4 <chapterinfo>
5         &author.jeremy;
6         &author.jelmer;
7         &author.jht;
8         &author.eroseme;
9 </chapterinfo>
10 <title>File and Record Locking</title>
12 <para>
13 One area that causes trouble for many network administrators is locking.
14 The extent of the problem is readily evident from searches over the Internet.
15 </para>
17 <sect1>
18 <title>Features and Benefits</title>
20 <para>
21 Samba provides all the same locking semantics that MS Windows clients expect
22 and that MS Windows NT4/200x servers also provide.
23 </para>
25 <para>
26 The term <emphasis>locking</emphasis> has exceptionally broad meaning and covers
27 a range of functions that are all categorized under this one term.
28 </para>
30 <para>
31 Opportunistic locking is a desirable feature when it can enhance the
32 perceived performance of applications on a networked client. However, the
33 opportunistic locking protocol is not robust and, therefore, can
34 encounter problems when invoked beyond a simplistic configuration or
35 on extended slow or faulty networks. In these cases, operating
36 system management of opportunistic locking and/or recovering from
37 repetitive errors can offset the perceived performance advantage that
38 it is intended to provide.
39 </para>
41 <para>
42 The MS Windows network administrator needs to be aware that file and record
43 locking semantics (behavior) can be controlled either in Samba or by way of registry
44 settings on the MS Windows client.
45 </para>
47 <note>
48 <para>
49 Sometimes it is necessary to disable locking control settings on both the Samba
50 server as well as on each MS Windows client!
51 </para>
52 </note>
54 </sect1>
56 <sect1>
57 <title>Discussion</title>
59 <para>
60 There are two types of locking that need to be performed by an SMB server.
61 The first is <emphasis>record locking</emphasis> that allows a client to lock
62 a range of bytes in a open file. The second is the <emphasis>deny modes</emphasis>
63 that are specified when a file is open.
64 </para>
66 <para>
67 Record locking semantics under UNIX are very different from record locking under
68 Windows. Versions of Samba before 2.2 have tried to use the native fcntl() UNIX
69 system call to implement proper record locking between different Samba clients.
70 This cannot be fully correct for several reasons. The simplest is the fact
71 that a Windows client is allowed to lock a byte range up to 2^32 or 2^64,
72 depending on the client OS. The UNIX locking only supports byte ranges up to 2^31.
73 So it is not possible to correctly satisfy a lock request above 2^31. There are
74 many more differences, too many to be listed here.
75 </para>
77 <para>
78 Samba 2.2 and above implements record locking completely independent of the
79 underlying UNIX system. If a byte range lock that the client requests happens
80 to fall into the range of 0-2^31, Samba hands this request down to the UNIX system.
81 All other locks cannot be seen by UNIX, anyway.
82 </para>
84 <para>
85 Strictly speaking, an SMB server should check for locks before every read and write call on
86 a file. Unfortunately with the way fcntl() works, this can be slow and may overstress
87 the <command>rpc.lockd</command>. This is almost always unnecessary as clients are supposed to
88 independently make locking calls before reads and writes if locking is
89 important to them. By default, Samba only makes locking calls when explicitly asked
90 to by a client, but if you set <smbconfoption name="strict locking">yes</smbconfoption>, it
91 will make lock checking calls on <emphasis>every</emphasis> read and write call.
92 </para>
94 <para>
95 You can also disable byte range locking completely by using
96 <smbconfoption name="locking">no</smbconfoption>.
97 This is useful for those shares that do not support locking or do not need it
98 (such as CDROMs). In this case, Samba fakes the return codes of locking calls to
99 tell clients that everything is okay.
100 </para>
102 <para>
103 The second class of locking is the <emphasis>deny modes</emphasis>. These 
104 are set by an application when it opens a file to determine what types of
105 access should be allowed simultaneously with its open. A client may ask for
106 <constant>DENY_NONE</constant>, <constant>DENY_READ</constant>, 
107 <constant>DENY_WRITE</constant>, or <constant>DENY_ALL</constant>. There are also special compatibility
108 modes called <constant>DENY_FCB</constant> and <constant>DENY_DOS</constant>.
109 </para>
111 <sect2>
112 <title>Opportunistic Locking Overview</title>
114 <para>
115 Opportunistic locking (Oplocks) is invoked by the Windows file system
116 (as opposed to an API) via registry entries (on the server and the client)
117 for the purpose of enhancing network performance when accessing a file
118 residing on a server. Performance is enhanced by caching the file
119 locally on the client that allows:
120 </para>
122 <variablelist>
123         <varlistentry><term>Read-ahead:</term>
124                 <listitem><para>
125                 The client reads the local copy of the file, eliminating network latency.
126                 </para></listitem>
127         </varlistentry>
129         <varlistentry><term>Write caching:</term>
130                 <listitem><para>
131                 The client writes to the local copy of the file, eliminating network latency.
132                 </para></listitem>
133         </varlistentry>
135         <varlistentry><term>Lock caching:</term>
136         <listitem><para>
137                 The client caches application locks locally, eliminating network latency.
138                 </para></listitem>
139         </varlistentry>
140 </variablelist>
142 <para>
143 The performance enhancement of oplocks is due to the opportunity of
144 exclusive access to the file &smbmdash; even if it is opened with deny-none &smbmdash;
145 because Windows monitors the file's status for concurrent access from
146 other processes.
147 </para>
149 <variablelist>
150 <title>Windows defines 4 kinds of Oplocks:</title>
152         <varlistentry><term>Level1 Oplock</term>
153                 <listitem><para>
154                 The redirector sees that the file was opened with deny
155                 none (allowing concurrent access), verifies that no
156                 other process is accessing the file, checks that
157                 oplocks are enabled, then grants deny-all/read-write/exclusive
158                 access to the file. The client now performs
159                 operations on the cached local file.
160                 </para>
162                 <para>
163                 If a second process attempts to open the file, the open
164                 is deferred while the redirector <quote>breaks</quote> the original
165                 oplock. The oplock break signals the caching client to
166                 write the local file back to the server, flush the
167                 local locks and discard read-ahead data. The break is
168                 then complete, the deferred open is granted, and the
169                 multiple processes can enjoy concurrent file access as
170                 dictated by mandatory or byte-range locking options.
171                 However, if the original opening process opened the
172                 file with a share mode other than deny-none, then the
173                 second process is granted limited or no access, despite
174                 the oplock break.
175                 </para></listitem>
176         </varlistentry>
178         <varlistentry><term>Level2 Oplock</term>
179                 <listitem><para>
180                 Performs like a Level1 oplock, except caching is only
181                 operative for reads. All other operations are performed
182                 on the server disk copy of the file.
183                 </para></listitem>
184         </varlistentry>
186         <varlistentry><term>Filter Oplock</term>
187                 <listitem><para>
188                 Does not allow write or delete file access.
189                 </para></listitem>
190         </varlistentry>
192         <varlistentry><term>Batch Oplock</term>
193                 <listitem><para>
194                 Manipulates file openings and closings and allows caching
195                 of file attributes.
196                 </para></listitem>
197         </varlistentry>
198 </variablelist>
200 <para>
201 An important detail is that oplocks are invoked by the file system, not
202 an application API. Therefore, an application can close an oplocked
203 file, but the file system does not relinquish the oplock. When the
204 oplock break is issued, the file system then simply closes the file in
205 preparation for the subsequent open by the second process.
206 </para>
208 <para>
209 <emphasis>Opportunistic locking</emphasis> is actually an improper name for this feature.
210 The true benefit of this feature is client-side data caching, and
211 oplocks is merely a notification mechanism for writing data back to the
212 networked storage disk. The limitation of opportunistic locking is the
213 reliability of the mechanism to process an oplock break (notification)
214 between the server and the caching client. If this exchange is faulty
215 (usually due to timing out for any number of reasons), then the
216 client-side caching benefit is negated.
217 </para>
219 <para>
220 The actual decision that a user or administrator should consider is
221 whether it is sensible to share among multiple users data that will
222 be cached locally on a client. In many cases the answer is no.
223 Deciding when to cache or not cache data is the real question, and thus
224 <quote>opportunistic locking</quote> should be treated as a toggle for client-side
225 caching. Turn it <quote>on</quote> when client-side caching is desirable and
226 reliable. Turn it <quote>off</quote> when client-side caching is redundant,
227 unreliable or counter-productive.
228 </para>
230 <para>
231 Opportunistic locking is by default set to <quote>on</quote> by Samba on all
232 configured shares, so careful attention should be given to each case to
233 determine if the potential benefit is worth the potential for delays.
234 The following recommendations will help to characterize the environment
235 where opportunistic locking may be effectively configured.
236 </para>
238 <para>
239 Windows opportunistic locking is a lightweight performance-enhancing
240 feature. It is not a robust and reliable protocol. Every
241 implementation of opportunistic locking should be evaluated as a
242 tradeoff between perceived performance and reliability. Reliability
243 decreases as each successive rule above is not enforced. Consider a
244 share with oplocks enabled, over a wide area network, to a client on a
245 South Pacific atoll, on a high-availability server, serving a
246 mission-critical multi-user corporate database during a tropical
247 storm. This configuration will likely encounter problems with oplocks.
248 </para>
250 <para>
251 Oplocks can be beneficial to perceived client performance when treated
252 as a configuration toggle for client-side data caching. If the data
253 caching is likely to be interrupted, then oplock usage should be
254 reviewed. Samba enables opportunistic locking by default on all
255 shares. Careful attention should be given to the client usage of
256 shared data on the server, the server network reliability and the
257 opportunistic locking configuration of each share.
258 In mission critical high availability environments, data integrity is
259 often a priority. Complex and expensive configurations are implemented
260 to ensure that if a client loses connectivity with a file server, a
261 fail-over replacement will be available immediately to provide
262 continuous data availability.
263 </para>
265 <para>
266 Windows client fail-over behavior is more at risk of application
267 interruption than other platforms because it is dependent upon an
268 established TCP transport connection. If the connection is interrupted
269 &smbmdash; as in a file server fail-over &smbmdash; a new session must be established.
270 It is rare for Windows client applications to be coded to recover
271 correctly from a transport connection loss, therefore, most applications
272 will experience some sort of interruption &smbmdash; at worst, abort and
273 require restarting.
274 </para>
276 <para>
277 If a client session has been caching writes and reads locally due to
278 opportunistic locking, it is likely that the data will be lost when the
279 application restarts or recovers from the TCP interrupt. When the TCP
280 connection drops, the client state is lost. When the file server
281 recovers, an oplock break is not sent to the client. In this case, the
282 work from the prior session is lost. Observing this scenario with
283 oplocks disabled and with the client writing data to the file server
284 real-time,  the fail-over will provide the data on disk as it
285 existed at the time of the disconnect.
286 </para>
288 <para>
289 In mission-critical high-availability environments, careful attention
290 should be given to opportunistic locking. Ideally, comprehensive
291 testing should be done with all affected applications with oplocks
292 enabled and disabled.
293 </para>
295 <sect3>
296 <title>Exclusively Accessed Shares</title>
298 <para>
299 Opportunistic locking is most effective when it is confined to shares
300 that are exclusively accessed by a single user, or by only one user at
301 a time. Because the true value of opportunistic locking is the local
302 client caching of data, any operation that interrupts the caching
303 mechanism will cause a delay.
304 </para>
306 <para>
307 Home directories are the most obvious examples of where the performance
308 benefit of opportunistic locking can be safely realized.
309 </para>
311 </sect3>
313 <sect3>
314 <title>Multiple-Accessed Shares or Files</title>
316 <para>
317 As each additional user accesses a file in a share with opportunistic
318 locking enabled, the potential for delays and resulting perceived poor
319 performance increases. When multiple users are accessing a file on a
320 share that has oplocks enabled, the management impact of sending and
321 receiving oplock breaks and the resulting latency while other clients
322 wait for the caching client to flush data offset the performance gains
323 of the caching user.
324 </para>
326 <para>
327 As each additional client attempts to access a file with oplocks set,
328 the potential performance improvement is negated and eventually results
329 in a performance bottleneck.
330 </para>
332 </sect3>
334 <sect3>
335 <title>UNIX or NFS Client-Accessed Files</title>
337 <para>
338 Local UNIX and NFS clients access files without a mandatory
339 file-locking mechanism. Thus, these client platforms are incapable of
340 initiating an oplock break request from the server to a Windows client
341 that has a file cached. Local UNIX or NFS file access can therefore
342 write to a file that has been cached by a Windows client, which
343 exposes the file to likely data corruption.
344 </para>
346 <para>
347 If files are shared between Windows clients, and either local UNIX 
348 or NFS users, turn opportunistic locking off.
349 </para>
351 </sect3>
353 <sect3>
354 <title>Slow and/or Unreliable Networks</title>
356 <para>
357 The biggest potential performance improvement for opportunistic locking
358 occurs when the client-side caching of reads and writes delivers the
359 most differential over sending those reads and writes over the wire.
360 This is most likely to occur when the network is extremely slow,
361 congested, or distributed (as in a WAN). However, network latency also
362 has a high impact on the reliability of the oplock break
363 mechanism, and thus increases the likelihood of encountering oplock
364 problems that more than offset the potential perceived performance
365 gain. Of course, if an oplock break never has to be sent, then this is
366 the most advantageous scenario to utilize opportunistic locking.
367 </para>
369 <para>
370 If the network is slow, unreliable, or a WAN, then do not configure
371 opportunistic locking if there is any chance of multiple users
372 regularly opening the same file.
373 </para>
375 </sect3>
377 <sect3>
378 <title>Multi-User Databases</title>
380 <para>
381 Multi-user databases clearly pose a risk due to their very nature &smbmdash;
382 they are typically heavily accessed by numerous users at random
383 intervals. Placing a multi-user database on a share with opportunistic
384 locking enabled will likely result in a locking management bottleneck
385 on the Samba server. Whether the database application is developed
386 in-house or a commercially available product, ensure that the share
387 has opportunistic locking disabled.
388 </para>
390 </sect3>
392 <sect3>
393 <title>PDM Data Shares</title>
395 <para>
396 Process Data Management (PDM) applications such as IMAN, Enovia and
397 Clearcase are increasing in usage with Windows client platforms, and
398 therefore SMB data-stores. PDM applications manage multi-user
399 environments for critical data security and access. The typical PDM
400 environment is usually associated with sophisticated client design
401 applications that will load data locally as demanded. In addition, the
402 PDM application will usually monitor the data-state of each client.
403 In this case, client-side data caching is best left to the local
404 application and PDM server to negotiate and maintain. It is
405 appropriate to eliminate the client OS from any caching tasks, and the
406 server from any oplock management, by disabling opportunistic locking on
407 the share.
408 </para>
410 </sect3>
412 <sect3>
413 <title>Beware of Force User</title>
415 <para>
416 Samba includes an &smb.conf; parameter called 
417 <smbconfoption name="force user"/> that changes
418 the user accessing a share from the incoming user to whatever user is
419 defined by the smb.conf variable. If opportunistic locking is enabled
420 on a share, the change in user access causes an oplock break to be sent
421 to the client, even if the user has not explicitly loaded a file. In
422 cases where the network is slow or unreliable, an oplock break can
423 become lost without the user even accessing a file. This can cause
424 apparent performance degradation as the client continually reconnects
425 to overcome the lost oplock break.
426 </para>
428 <para>
429 Avoid the combination of the following: 
430 </para>
432 <itemizedlist>
433         <listitem><para>
434         <smbconfoption name="force user"/> in the &smb.conf; share configuration.
435         </para></listitem>
437         <listitem><para>
438         Slow or unreliable networks
439         </para></listitem>
441         <listitem><para>
442         Opportunistic locking enabled
443         </para></listitem>
444 </itemizedlist>
446 </sect3>
448 <sect3>
449 <title>Advanced Samba Opportunistic Locking Parameters</title>
451 <para>
452 Samba provides opportunistic locking parameters that allow the
453 administrator to adjust various properties of the oplock mechanism to
454 account for timing and usage levels. These parameters provide good
455 versatility for implementing oplocks in environments where they would
456 likely cause problems. The parameters are: 
457 <smbconfoption name="oplock break wait time"/>,
458 <smbconfoption name="oplock contention limit"/>.
459 </para>
461 <para>
462 For most users, administrators and environments, if these parameters
463 are required, then the better option is to simply turn oplocks off.
464 The Samba SWAT help text for both parameters reads: <quote>Do not change
465 this parameter unless you have read and understood the Samba oplock code.</quote>
466 This is good advice.
467 </para>
469 </sect3>
471 <sect3>
472 <title>Mission-Critical High-Availability</title>
474 <para>
475 In mission-critical high-availability environments, data integrity is
476 often a priority. Complex and expensive configurations are implemented
477 to ensure that if a client loses connectivity with a file server, a
478 fail-over replacement will be available immediately to provide
479 continuous data availability.
480 </para>
482 <para>
483 Windows client fail-over behavior is more at risk of application
484 interruption than other platforms because it is dependant upon an
485 established TCP transport connection. If the connection is interrupted
486 &smbmdash; as in a file server fail-over &smbmdash; a new session must be established.
487 It is rare for Windows client applications to be coded to recover
488 correctly from a transport connection loss, therefore, most applications
489 will experience some sort of interruption &smbmdash; at worst, abort and
490 require restarting.
491 </para>
493 <para>
494 If a client session has been caching writes and reads locally due to
495 opportunistic locking, it is likely that the data will be lost when the
496 application restarts, or recovers from the TCP interrupt. When the TCP
497 connection drops, the client state is lost. When the file server
498 recovers, an oplock break is not sent to the client. In this case, the
499 work from the prior session is lost. Observing this scenario with
500 oplocks disabled, and the client was writing data to the file server
501 real-time, then the fail-over will provide the data on disk as it
502 existed at the time of the disconnect.
503 </para>
505 <para>
506 In mission-critical high-availability environments, careful attention
507 should be given to opportunistic locking. Ideally, comprehensive
508 testing should be done with all effected applications with oplocks
509 enabled and disabled.
510 </para>
512 </sect3>
513 </sect2>
514 </sect1>
516 <sect1>
517 <title>Samba Opportunistic Locking Control</title>
519 <para>
520 Opportunistic locking is a unique Windows file locking feature. It is
521 not really file locking, but is included in most discussions of Windows
522 file locking, so is considered a de facto locking feature.
523 Opportunistic locking is actually part of the Windows client file
524 caching mechanism. It is not a particularly robust or reliable feature
525 when implemented on the variety of customized networks that exist in
526 enterprise computing.
527 </para>
529 <para>
530 Like Windows, Samba implements opportunistic locking as a server-side
531 component of the client caching mechanism. Because of the lightweight
532 nature of the Windows feature design, effective configuration of
533 opportunistic locking requires a good understanding of its limitations,
534 and then applying that understanding when configuring data access for
535 each particular customized network and client usage state.
536 </para>
538 <para>
539 Opportunistic locking essentially means that the client is allowed to download and cache
540 a file on their hard drive while making changes; if a second client wants to access the
541 file, the first client receives a break and must synchronize the file back to the server.
542 This can give significant performance gains in some cases; some programs insist on
543 synchronizing the contents of the entire file back to the server for a single change.
544 </para>
546 <para>
547 Level1 Oplocks (also known as just plain <quote>oplocks</quote>) is another term for opportunistic locking.
548 </para>
550 <para>
551 Level2 Oplocks provides opportunistic locking for a file that will be treated as
552 <emphasis>read only</emphasis>. Typically this is used on files that are read-only or
553 on files that the client has no initial intention to write to at time of opening the file.
554 </para>
556 <para>
557 Kernel Oplocks are essentially a method that allows the Linux kernel to co-exist with
558 Samba's oplocked files, although this has provided better integration of MS Windows network
559 file locking with the underlying OS, SGI IRIX and Linux are the only two OSs that are
560 oplock-aware at this time.
561 </para>
563 <para>
564 Unless your system supports kernel oplocks, you should disable oplocks if you are
565 accessing the same files from both UNIX/Linux and SMB clients. Regardless, oplocks should
566 always be disabled if you are sharing a database file (e.g., Microsoft Access) between
567 multiple clients, as any break the first client receives will affect synchronization of
568 the entire file (not just the single record), which will result in a noticeable performance
569 impairment and, more likely, problems accessing the database in the first place. Notably,
570 Microsoft Outlook's personal folders (*.pst) react quite badly to oplocks. If in doubt,
571 disable oplocks and tune your system from that point.
572 </para>
574 <para>
575 If client-side caching is desirable and reliable on your network, you will benefit from
576 turning on oplocks. If your network is slow and/or unreliable, or you are sharing your
577 files among other file sharing mechanisms (e.g., NFS) or across a WAN, or multiple people
578 will be accessing the same files frequently, you probably will not benefit from the overhead
579 of your client sending oplock breaks and will instead want to disable oplocks for the share.
580 </para>
582 <para>
583 Another factor to consider is the perceived performance of file access. If oplocks provide no
584 measurable speed benefit on your network, it might not be worth the hassle of dealing with them.
585 </para>
587 <sect2>
588 <title>Example Configuration</title>
590 <para>
591 In the following section we examine two distinct aspects of Samba locking controls.
592 </para>
594 <sect3>
595 <title>Disabling Oplocks</title>
597 <para>
598 You can disable oplocks on a per-share basis with the following:
599 </para>
601 <para>
602 <smbconfblock>
603 <smbconfsection>[acctdata]</smbconfsection>
604 <smbconfoption name="oplocks">False</smbconfoption>
605 <smbconfoption name="level2 oplocks">False</smbconfoption>
606 </smbconfblock>
607 </para>
609 <para>
610 The default oplock type is Level1. Level2 oplocks are enabled on a per-share basis
611 in the &smb.conf; file.
612 </para>
614 <para>
615 Alternately, you could disable oplocks on a per-file basis within the share:
616 </para>
618 <para>
619         <smbconfblock>
620 <smbconfoption name="veto oplock files">/*.mdb/*.MDB/*.dbf/*.DBF/</smbconfoption>
621 </smbconfblock>
622 </para>
624 <para>
625 If you are experiencing problems with oplocks as apparent from Samba's log entries,
626 you may want to play it safe and disable oplocks and Level2 oplocks.
627 </para>
629 </sect3>
631 <sect3>
632 <title>Disabling Kernel Oplocks</title>
634 <para>
635 Kernel oplocks is an &smb.conf; parameter that notifies Samba (if
636 the UNIX kernel has the capability to send a Windows client an oplock
637 break) when a UNIX process is attempting to open the file that is
638 cached. This parameter addresses sharing files between UNIX and
639 Windows with oplocks enabled on the Samba server: the UNIX process
640 can open the file that is Oplocked (cached) by the Windows client and
641 the smbd process will not send an oplock break, which exposes the file
642 to the risk of data corruption. If the UNIX kernel has the ability to
643 send an oplock break, then the kernel oplocks parameter enables Samba
644 to send the oplock break. Kernel oplocks are enabled on a per-server
645 basis in the &smb.conf; file.
646 </para>
648 <para>
649 <smbconfblock>
650 <smbconfoption name="kernel oplocks">yes</smbconfoption>
651 </smbconfblock>
652 The default is no.
653 </para>
655 <para>
656 Veto opLocks is an &smb.conf; parameter that identifies specific files for
657 which oplocks are disabled. When a Windows client opens a file that
658 has been configured for veto oplocks, the client will not be granted
659 the oplock, and all operations will be executed on the original file on
660 disk instead of a client-cached file copy. By explicitly identifying
661 files that are shared with UNIX processes and disabling oplocks for
662 those files, the server-wide Oplock configuration can be enabled to
663 allow Windows clients to utilize the performance benefit of file
664 caching without the risk of data corruption. Veto Oplocks can be
665 enabled on a per-share basis, or globally for the entire server, in the
666 &smb.conf; file as shown in <link linkend="far1"/>.
667 </para>
669 <para>
670 <smbconfexample id="far1">
671 <title>Share with some files oplocked</title>
672 <smbconfsection>[global]</smbconfsection>
673 <smbconfoption name="veto oplock files">/filename.htm/*.txt/</smbconfoption>
675 <smbconfsection>[share_name]</smbconfsection>
676 <smbconfoption name="veto oplock files">/*.exe/filename.ext/</smbconfoption>
677 </smbconfexample>
678 </para>
680 <para>
681 <smbconfoption name="oplock break wait time"/> is an &smb.conf; parameter
682 that adjusts the time interval for Samba to reply to an oplock break request. Samba recommends:
683 <quote>Do not change this parameter unless you have read and understood the Samba oplock code.</quote>
684 Oplock break Wait Time can only be configured globally in the &smb.conf; file as shown below.
685 </para>
687 <para>
688         <smbconfblock>
689 <smbconfoption name="oplock break wait time"> 0 (default)</smbconfoption>
690 </smbconfblock>
691 </para>
693 <para>
694 <emphasis>Oplock break contention limit</emphasis> is an &smb.conf; parameter that limits the
695 response of the Samba server to grant an oplock if the configured
696 number of contending clients reaches the limit specified by the parameter. Samba recommends
697 <quote>Do not change this parameter unless you have read and understood the Samba oplock code.</quote>
698 Oplock break Contention Limit can be enable on a per-share basis, or globally for
699 the entire server, in the &smb.conf; file as shown in <link linkend="far3"/>.
700 </para>
702 <para>
703 <smbconfexample id="far3">
704         <title>Configuration with oplock break contention limit</title>
705 <smbconfsection>[global]</smbconfsection>
706 <smbconfoption name="oplock break contention limit"> 2 (default)</smbconfoption>
708 <smbconfsection>[share_name]</smbconfsection>
709 <smbconfoption name="oplock break contention limit"> 2 (default)</smbconfoption>
710 </smbconfexample>
711 </para>
713 </sect3>
714 </sect2>
716 </sect1>
718 <sect1>
719 <title>MS Windows Opportunistic Locking and Caching Controls</title>
721 <para>
722 There is a known issue when running applications (like Norton Anti-Virus) on a Windows 2000/ XP
723 workstation computer that can affect any application attempting to access shared database files
724 across a network. This is a result of a default setting configured in the Windows 2000/XP
725 operating system known as <emphasis>opportunistic locking</emphasis>. When a workstation
726 attempts to access shared data files located on another Windows 2000/XP computer,
727 the Windows 2000/XP operating system will attempt to increase performance by locking the
728 files and caching information locally. When this occurs, the application is unable to
729 properly function, which results in an <quote>Access Denied</quote>
730  error message being displayed during network operations.
731 </para>
733 <para>
734 All Windows operating systems in the NT family that act as database servers for data files
735 (meaning that data files are stored there and accessed by other Windows PCs) may need to
736 have opportunistic locking disabled in order to minimize the risk of data file corruption.
737 This includes Windows 9x/Me, Windows NT, Windows 200x, and Windows XP.
738 <footnote><para>Microsoft has documented this in Knowledge Base article 300216.</para></footnote>
739 </para>
741 <para>
742 If you are using a Windows NT family workstation in place of a server, you must also
743 disable opportunistic locking (oplocks) on that workstation. For example, if you use a
744 PC with the Windows NT Workstation operating system instead of Windows NT Server, and you
745 have data files located on it that are accessed from other Windows PCs, you may need to
746 disable oplocks on that system.
747 </para>
749 <para>
750 The major difference is the location in the Windows registry where the values for disabling
751 oplocks are entered. Instead of the LanManServer location, the LanManWorkstation location
752 may be used.
753 </para>
755 <para>
756 You can verify (change or add, if necessary) this registry value using the Windows
757 Registry Editor. When you change this registry value, you will have to reboot the PC
758 to ensure that the new setting goes into effect.
759 </para>
761 <para>
762 The location of the client registry entry for opportunistic locking has changed in
763 Windows 2000 from the earlier location in Microsoft Windows NT.
764 </para>
766 <note><para>
767 Windows 2000 will still respect the EnableOplocks registry value used to disable oplocks
768 in earlier versions of Windows.
769 </para></note>
771 <para>
772 You can also deny the granting of opportunistic locks by changing the following registry entries:
773 </para>
775 <para>
776 <programlisting>
777         HKEY_LOCAL_MACHINE\System\
778                 CurrentControlSet\Services\MRXSmb\Parameters\
780                 OplocksDisabled REG_DWORD 0 or 1
781                 Default: 0 (not disabled)
782 </programlisting>
783 </para>
785 <note><para>
786 The OplocksDisabled registry value configures Windows clients to either request or not
787 request opportunistic locks on a remote file. To disable oplocks, the value of
788  OplocksDisabled must be set to 1.
789 </para></note>
791 <para>
792 <programlisting>
793         HKEY_LOCAL_MACHINE\System\
794                 CurrentControlSet\Services\LanmanServer\Parameters
796                 EnableOplocks REG_DWORD 0 or 1
797                 Default: 1 (Enabled by Default)
799                 EnableOpLockForceClose REG_DWORD 0 or 1
800                 Default: 0 (Disabled by Default)
801 </programlisting>
802 </para>
804 <note><para>
805 The EnableOplocks value configures Windows-based servers (including Workstations sharing
806 files) to allow or deny opportunistic locks on local files.
807 </para></note>
809 <para>
810 To force closure of open oplocks on close or program exit, EnableOpLockForceClose must be set to 1.
811 </para>
813 <para>
814 An illustration of how Level2 oplocks work:
815 </para>
817 <itemizedlist>
818         <listitem><para>
819         Station 1 opens the file requesting oplock.
820         </para></listitem>
821         <listitem><para>
822         Since no other station has the file open, the server grants station 1 exclusive oplock.
823         </para></listitem>
824         <listitem><para>
825         Station 2 opens the file requesting oplock.
826         </para></listitem>
827         <listitem><para>
828         Since station 1 has not yet written to the file, the server asks station 1 to break
829         to Level2 oplock.
830         </para></listitem>
831         <listitem><para>
832         Station 1 complies by flushing locally buffered lock information to the server.
833         </para></listitem>
834         <listitem><para>
835         Station 1 informs the server that it has Broken to Level2 Oplock (alternately,
836         station 1 could have closed the file).
837         </para></listitem>
838         <listitem><para>
839         The server responds to station 2's open request, granting it Level2 oplock.
840         Other stations can likewise open the file and obtain Level2 oplock.
841         </para></listitem>
842         <listitem><para>
843         Station 2 (or any station that has the file open) sends a write request SMB.
844         The server returns the write response.
845         </para></listitem>
846         <listitem><para>
847         The server asks all stations that have the file open to break to none, meaning no
848         station holds any oplock on the file. Because the workstations can have no cached
849         writes or locks at this point, they need not respond to the break-to-none advisory;
850         all they need do is invalidate locally cashed read-ahead data.
851         </para></listitem>
852 </itemizedlist>
854 <sect2>
855 <title>Workstation Service Entries</title>
857 <para><programlisting>
858         \HKEY_LOCAL_MACHINE\System\
859                 CurrentControlSet\Services\LanmanWorkstation\Parameters
861         UseOpportunisticLocking   REG_DWORD   0 or 1
862         Default: 1 (true)
863 </programlisting></para>
865 <para>
866 This indicates whether the redirector should use opportunistic-locking (oplock) performance
867 enhancement. This parameter should be disabled only to isolate problems.
868 </para>
870 </sect2>
871 <sect2>
872 <title>Server Service Entries</title>
874 <para><programlisting>
875         \HKEY_LOCAL_MACHINE\System\
876                 CurrentControlSet\Services\LanmanServer\Parameters
878         EnableOplocks   REG_DWORD   0 or 1
879         Default: 1 (true)
880 </programlisting></para>
882 <para>
883 This specifies whether the server allows clients to use oplocks on files. Oplocks are a
884 significant performance enhancement, but have the potential to cause lost cached
885 data on some networks, particularly wide area networks.
886 </para>
888 <para><programlisting>
889         MinLinkThroughput   REG_DWORD   0 to infinite bytes per second
890         Default: 0
891 </programlisting></para>
893 <para>
894 This specifies the minimum link throughput allowed by the server before it disables
895 raw and opportunistic locks for this connection.
896 </para>
898 <para><programlisting>
899         MaxLinkDelay   REG_DWORD   0 to 100,000 seconds
900         Default: 60
901 </programlisting></para>
903 <para>
904 This specifies the maximum time allowed for a link delay. If delays exceed this number,
905 the server disables raw I/O and opportunistic locking for this connection.
906 </para>
908 <para><programlisting>
909         OplockBreakWait   REG_DWORD   10 to 180 seconds
910         Default: 35
911 </programlisting></para>
913 <para>
914 This specifies the time that the server waits for a client to respond to an oplock break
915 request. Smaller values can allow detection of crashed clients more quickly but can
916 potentially cause loss of cached data.
917 </para>
919 </sect2>
920 </sect1>
922 <sect1>
923 <title>Persistent Data Corruption</title>
925 <para>
926 If you have applied all of the settings discussed in this chapter but data corruption problems
927 and other symptoms persist, here are some additional things to check out.
928 </para>
930 <para>
931 We have credible reports from developers that faulty network hardware, such as a single
932 faulty network card, can cause symptoms similar to read caching and data corruption.
933 If you see persistent data corruption even after repeated re-indexing, you may have to
934 rebuild the data files in question. This involves creating a new data file with the
935 same definition as the file to be rebuilt and transferring the data from the old file
936 to the new one. There are several known methods for doing this that can be found in
937 our Knowledge Base.
938 </para>
940 </sect1>
942 <sect1>
943 <title>Common Errors</title>
945 <para>
946 In some sites, locking problems surface as soon as a server is installed; in other sites
947 locking problems may not surface for a long time. Almost without exception, when a locking
948 problem does surface it will cause embarrassment and potential data corruption.
949 </para>
951 <para>
952 Over the past few years there have been a number of complaints on the Samba mailing lists
953 that have claimed that Samba caused data corruption. Three causes have been identified
954 so far:
955 </para>
957 <itemizedlist>
958         <listitem><para>
959         Incorrect configuration of opportunistic locking (incompatible with the application
960         being used. This is a common problem even where MS Windows NT4 or MS Windows
961         200x-based servers were in use. It is imperative that the software application vendors'
962         instructions for configuration of file locking should be followed. If in doubt,
963         disable oplocks on both the server and the client. Disabling of all forms of file
964         caching on the MS Windows client may be necessary also.
965         </para></listitem>
967         <listitem><para>
968         Defective network cards, cables, or HUBs/Switched. This is generally a more
969         prevalent factor with low cost networking hardware, although occasionally there
970         have also been problems with incompatibilities in more up-market hardware.
971         </para></listitem>
973         <listitem><para>
974         There have been some random reports of Samba log files being written over data
975         files. This has been reported by very few sites (about five in the past three years)
976         and all attempts to reproduce the problem have failed. The Samba Team has been
977         unable to catch this happening and thus has not been able to isolate any particular
978         cause. Considering the millions of systems that use Samba, for the sites that have
979         been affected by this as well as for the Samba Team this is a frustrating and
980         a vexing challenge. If you see this type of thing happening, please create a bug
981         report on Samba <ulink url="https://bugzilla.samba.org">Bugzilla</ulink> without delay.
982         Make sure that you give as much information as you possibly can help isolate the
983         cause and to allow replication of the problem (an essential step in problem isolation and correction).
984         </para></listitem>
985 </itemizedlist>
987         <sect2>
988         <title>locking.tdb Error Messages</title>
990         <para>
991                 <quote>
992                         We are seeing lots of errors in the Samba logs, like:
993                 </quote>
994 <programlisting>
995 tdb(/usr/local/samba_2.2.7/var/locks/locking.tdb): rec_read bad magic
996  0x4d6f4b61 at offset=36116
997 </programlisting>
999                 <quote>
1000                         What do these mean?
1001                 </quote>
1002         </para>
1004         <para>
1005         This error indicated a corrupted tdb. Stop all instances of smbd, delete locking.tdb, and restart smbd.
1006         </para>
1008         </sect2>
1010         <sect2>
1011                 <title>Problems Saving Files in MS Office on Windows XP</title>
1013                 <para>This is a bug in Windows XP. More information can be 
1014                 found in <ulink url="http://support.microsoft.com/?id=812937">Microsoft Knowledge Base article 812937.</ulink></para>
1016         </sect2>
1018         <sect2>
1020                 <title>Long Delays Deleting Files Over Network with XP SP1</title>
1021                 
1022                 <para><quote>It sometimes takes approximately 35 seconds to delete files over the network after XP SP1 has been applied.</quote></para>
1024                 <para>This is a bug in Windows XP. More information can be found in <ulink url="http://support.microsoft.com/?id=811492">
1025                                 Microsoft Knowledge Base article 811492.</ulink></para>
1026         </sect2>
1028 </sect1>
1030 <sect1>
1031 <title>Additional Reading</title>
1033 <para>
1034 You may want to check for an updated version of this white paper on our Web site from
1035 time to time. Many of our white papers are updated as information changes. For those papers,
1036 the last edited date is always at the top of the paper.
1037 </para>
1039 <para>
1040 Section of the Microsoft MSDN Library on opportunistic locking: 
1041 </para>
1043 <para>
1044 Opportunistic Locks, Microsoft Developer Network (MSDN), Windows Development &gt;
1045 Windows Base Services &gt; Files and I/O &gt; SDK Documentation &gt; File Storage &gt; File Systems
1046 &gt; About File Systems &gt; Opportunistic Locks, Microsoft Corporation.
1047 <ulink noescape="1" url="http://msdn.microsoft.com/library/en-us/fileio/storage_5yk3.asp">http://msdn.microsoft.com/library/en-us/fileio/storage_5yk3.asp</ulink>
1048 </para>
1050 <para>
1051         Microsoft Knowledge Base Article Q224992 <?latex \linebreak ?><quote>Maintaining Transactional Integrity 
1052 with OPLOCKS</quote>,
1053 Microsoft Corporation, April 1999, <ulink noescape="1" url="http://support.microsoft.com/default.aspx?scid=kb;en-us;Q224992">http://support.microsoft.com/default.aspx?scid=kb;en-us;Q224992</ulink>.
1054 </para>
1056 <para>
1057 Microsoft Knowledge Base Article Q296264 <quote>Configuring Opportunistic Locking in Windows 2000</quote>,
1058 Microsoft Corporation, April 2001, <ulink noescape="1" url="http://support.microsoft.com/default.aspx?scid=kb;en-us;Q296264">http://support.microsoft.com/default.aspx?scid=kb;en-us;Q296264</ulink>.
1059 </para>
1061 <para>
1062 Microsoft Knowledge Base Article Q129202 <quote>PC Ext: Explanation of Opportunistic Locking on Windows NT</quote>,
1063 Microsoft Corporation, April 1995, <ulink noescape="1" url="http://support.microsoft.com/default.aspx?scid=kb;en-us;Q129202">http://support.microsoft.com/default.aspx?scid=kb;en-us;Q129202</ulink>.
1064 </para>
1066 </sect1>
1067 </chapter>