Stage 1 of PHPTR Edits.
[Samba/gebeck_regimport.git] / docs / Samba3-HOWTO / TOSHARG-locking.xml
blob4e0c993c56a6d69e5ba19c45e0c4b7bcbddec935
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 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
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 implement 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 to 2^31, Samba hands this request down to the UNIX system.
81 No other locks can 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 because 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 CD-ROMs). 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 the following:
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 Four 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 "breaks" 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 oplocks 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 oplocks 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 counterproductive.
228 </para>
230 <para>
231 Oplocks 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 oplocks may be effectively configured.
236 </para>
238 <para>
239 Windows oplocks is a lightweight performance-enhancing
240 feature. It is not a robust and reliable protocol. Every
241 implementation of oplocks should be evaluated as a
242 trade-off 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 multiuser 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 oplocks 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 oplocks 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 failover replacement will be available immediately to provide
262 continuous data availability.
263 </para>
265 <para>
266 Windows client failover 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 failover &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 oplocks, 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 failover 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 oplocks. 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 Oplocks 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 oplocks 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 oplocks 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 oplocks
318 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 oplocks off.
349 </para>
351 </sect3>
353 <sect3>
354 <title>Slow and/or Unreliable Networks</title>
356 <para>
357 The biggest potential performance improvement for oplocks
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 in which to utilize oplocks.
367 </para>
369 <para>
370 If the network is slow, unreliable, or a WAN, then do not configure
371 oplocks if there is any chance of multiple users
372 regularly opening the same file.
373 </para>
375 </sect3>
377 <sect3>
378 <title>Multiuser Databases</title>
380 <para>
381 Multiuser 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 oplocks
384 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 oplocks 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 with SMB datastores. PDM applications manage multiuser
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 oplocks management, by disabling oplocks 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 oplocks 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         Oplocks enabled.
443         </para></listitem>
444 </itemizedlist>
446 </sect3>
448 <sect3>
449 <title>Advanced Samba Oplocks Parameters</title>
451 <para>
452 Samba provides oplocks 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"/>, and
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 failover replacement will be available immediately to provide
479 continuous data availability.
480 </para>
482 <para>
483 Windows client failover behavior is more at risk of application
484 interruption than other platforms because it is dependent upon an
485 established TCP transport connection. If the connection is interrupted
486 &smbmdash; as in a file server failover &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 oplocks, 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, if the client was writing data to the file server
501 real-time, then the failover 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 oplocks. Ideally, comprehensive
508 testing should be done with all affected applications with oplocks
509 enabled and disabled.
510 </para>
512 </sect3>
513 </sect2>
514 </sect1>
516 <sect1>
517 <title>Samba Oplocks Control</title>
519 <para>
520 Oplocks 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 Oplocks 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 oplocks 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 oplocks 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 Oplocks essentially means that the client is allowed to download and cache
540 a file on its 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, because 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 name="[acctdata]"/>
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 <emphasis>Veto oplocks</emphasis> 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 <example id="far1">
671 <title>Share with Some Files Oplocked</title>
672 <smbconfblock>
673 <smbconfsection name="[global]"/>
674 <smbconfoption name="veto oplock files">/filename.htm/*.txt/</smbconfoption>
676 <smbconfsection name="[share_name]"/>
677 <smbconfoption name="veto oplock files">/*.exe/filename.ext/</smbconfoption>
678 </smbconfblock>
679 </example>
680 </para>
682 <para>
683 <smbconfoption name="oplock break wait time"/> is an &smb.conf; parameter
684 that adjusts the time interval for Samba to reply to an oplock break request. Samba recommends:
685 <quote>Do not change this parameter unless you have read and understood the Samba oplock code.</quote>
686 Oplock break wait time can only be configured globally in the &smb.conf; file as shown:
687 </para>
689 <para>
690         <smbconfblock>
691 <smbconfoption name="oplock break wait time"> 0 (default)</smbconfoption>
692 </smbconfblock>
693 </para>
695 <para>
696 <emphasis>Oplock break contention limit</emphasis> is an &smb.conf; parameter that limits the
697 response of the Samba server to grant an oplock if the configured
698 number of contending clients reaches the limit specified by the parameter. Samba recommends
699 <quote>Do not change this parameter unless you have read and understood the Samba oplock code.</quote>
700 Oplock break contention limit can be enabled on a per-share basis, or globally for
701 the entire server, in the &smb.conf; file as shown in <link linkend="far3"/>.
702 </para>
704 <para>
705 <example id="far3">
706 <title>Configuration with Oplock Break Contention Limit</title>
707 <smbconfblock>
708 <smbconfsection name="[global]"/>
709 <smbconfoption name="oplock break contention limit"> 2 (default)</smbconfoption>
711 <smbconfsection name="[share_name]"/>
712 <smbconfoption name="oplock break contention limit"> 2 (default)</smbconfoption>
713 </smbconfblock>
714 </example>
715 </para>
717 </sect3>
718 </sect2>
720 </sect1>
722 <sect1>
723 <title>MS Windows Oplocks and Caching Controls</title>
725 <para>
726 There is a known issue when running applications (like Norton Antivirus) on a Windows 2000/ XP
727 workstation computer that can affect any application attempting to access shared database files
728 across a network. This is a result of a default setting configured in the Windows 2000/XP
729 operating system. When a workstation
730 attempts to access shared data files located on another Windows 2000/XP computer,
731 the Windows 2000/XP operating system will attempt to increase performance by locking the
732 files and caching information locally. When this occurs, the application is unable to
733 properly function, which results in an <quote>Access Denied</quote>
734  error message being displayed during network operations.
735 </para>
737 <para>
738 All Windows operating systems in the NT family that act as database servers for data files
739 (meaning that data files are stored there and accessed by other Windows PCs) may need to
740 have oplocks disabled in order to minimize the risk of data file corruption.
741 This includes Windows 9x/Me, Windows NT, Windows 200x, and Windows XP.
742 <footnote><para>Microsoft has documented this in Knowledge Base article 300216.</para></footnote>
743 </para>
745 <para>
746 If you are using a Windows NT family workstation in place of a server, you must also
747 disable oplocks on that workstation. For example, if you use a
748 PC with the Windows NT Workstation operating system instead of Windows NT Server, and you
749 have data files located on it that are accessed from other Windows PCs, you may need to
750 disable oplocks on that system.
751 </para>
753 <para>
754 The major difference is the location in the Windows registry where the values for disabling
755 oplocks are entered. Instead of the LanManServer location, the LanManWorkstation location
756 may be used.
757 </para>
759 <para>
760 You can verify (change or add, if necessary) this registry value using the Windows
761 Registry Editor. When you change this registry value, you will have to reboot the PC
762 to ensure that the new setting goes into effect.
763 </para>
765 <para>
766 The location of the client registry entry for oplocks has changed in
767 Windows 2000 from the earlier location in Microsoft Windows NT.
768 </para>
770 <note><para>
771 Windows 2000 will still respect the EnableOplocks registry value used to disable oplocks
772 in earlier versions of Windows.
773 </para></note>
775 <para>
776 You can also deny the granting of oplocks by changing the following registry entries:
777 </para>
779 <para>
780 <programlisting>
781         HKEY_LOCAL_MACHINE\System\
782                 CurrentControlSet\Services\MRXSmb\Parameters\
784                 OplocksDisabled REG_DWORD 0 or 1
785                 Default: 0 (not disabled)
786 </programlisting>
787 </para>
789 <note><para>
790 The OplocksDisabled registry value configures Windows clients to either request or not
791 request oplocks on a remote file. To disable oplocks, the value of
792  OplocksDisabled must be set to 1.
793 </para></note>
795 <para>
796 <programlisting>
797         HKEY_LOCAL_MACHINE\System\
798                 CurrentControlSet\Services\LanmanServer\Parameters
800                 EnableOplocks REG_DWORD 0 or 1
801                 Default: 1 (Enabled by Default)
803                 EnableOpLockForceClose REG_DWORD 0 or 1
804                 Default: 0 (Disabled by Default)
805 </programlisting>
806 </para>
808 <note><para>
809 The EnableOplocks value configures Windows-based servers (including Workstations sharing
810 files) to allow or deny oplocks on local files.
811 </para></note>
813 <para>
814 To force closure of open oplocks on close or program exit, EnableOpLockForceClose must be set to 1.
815 </para>
817 <para>
818 An illustration of how Level2 oplocks work follows:
819 </para>
821 <itemizedlist>
822         <listitem><para>
823         Station 1 opens the file requesting oplock.
824         </para></listitem>
825         <listitem><para>
826         Since no other station has the file open, the server grants station 1 exclusive oplock.
827         </para></listitem>
828         <listitem><para>
829         Station 2 opens the file requesting oplock.
830         </para></listitem>
831         <listitem><para>
832         Since station 1 has not yet written to the file, the server asks station 1 to break
833         to Level2 oplock.
834         </para></listitem>
835         <listitem><para>
836         Station 1 complies by flushing locally buffered lock information to the server.
837         </para></listitem>
838         <listitem><para>
839         Station 1 informs the server that it has broken to level2 Oplock (alternately,
840         station 1 could have closed the file).
841         </para></listitem>
842         <listitem><para>
843         The server responds to station 2's open request, granting it Level2 oplock.
844         Other stations can likewise open the file and obtain Level2 oplock.
845         </para></listitem>
846         <listitem><para>
847         Station 2 (or any station that has the file open) sends a write request SMB.
848         The server returns the write response.
849         </para></listitem>
850         <listitem><para>
851         The server asks all stations that have the file open to break to none, meaning no
852         station holds any oplock on the file. Because the workstations can have no cached
853         writes or locks at this point, they need not respond to the break-to-none advisory;
854         all they need do is invalidate locally cashed read-ahead data.
855         </para></listitem>
856 </itemizedlist>
858 <sect2>
859 <title>Workstation Service Entries</title>
861 <para><programlisting>
862         \HKEY_LOCAL_MACHINE\System\
863                 CurrentControlSet\Services\LanmanWorkstation\Parameters
865         UseOpportunisticLocking   REG_DWORD   0 or 1
866         Default: 1 (true)
867 </programlisting></para>
869 <para>
870 This indicates whether the redirector should use oplocks performance
871 enhancement. This parameter should be disabled only to isolate problems.
872 </para>
874 </sect2>
875 <sect2>
876 <title>Server Service Entries</title>
878 <para><programlisting>
879         \HKEY_LOCAL_MACHINE\System\
880                 CurrentControlSet\Services\LanmanServer\Parameters
882         EnableOplocks   REG_DWORD   0 or 1
883         Default: 1 (true)
884 </programlisting></para>
886 <para>
887 This specifies whether the server allows clients to use oplocks on files. Oplocks are a
888 significant performance enhancement, but have the potential to cause lost cached
889 data on some networks, particularly WANs.
890 </para>
892 <para><programlisting>
893         MinLinkThroughput   REG_DWORD   0 to infinite bytes per second
894         Default: 0
895 </programlisting></para>
897 <para>
898 This specifies the minimum link throughput allowed by the server before it disables
899 raw I/O and oplocks for this connection.
900 </para>
902 <para><programlisting>
903         MaxLinkDelay   REG_DWORD   0 to 100,000 seconds
904         Default: 60
905 </programlisting></para>
907 <para>
908 This specifies the maximum time allowed for a link delay. If delays exceed this number,
909 the server disables raw I/O and oplocks for this connection.
910 </para>
912 <para><programlisting>
913         OplockBreakWait   REG_DWORD   10 to 180 seconds
914         Default: 35
915 </programlisting></para>
917 <para>
918 This specifies the time that the server waits for a client to respond to an oplock break
919 request. Smaller values can allow detection of crashed clients more quickly but can
920 potentially cause loss of cached data.
921 </para>
923 </sect2>
924 </sect1>
926 <sect1>
927 <title>Persistent Data Corruption</title>
929 <para>
930 If you have applied all of the settings discussed in this chapter but data corruption problems
931 and other symptoms persist, here are some additional things to check out.
932 </para>
934 <para>
935 We have credible reports from developers that faulty network hardware, such as a single
936 faulty network card, can cause symptoms similar to read caching and data corruption.
937 If you see persistent data corruption even after repeated re-indexing, you may have to
938 rebuild the data files in question. This involves creating a new data file with the
939 same definition as the file to be rebuilt and transferring the data from the old file
940 to the new one. There are several known methods for doing this that can be found in
941 our knowledge base.
942 </para>
944 </sect1>
946 <sect1>
947 <title>Common Errors</title>
949 <para>
950 In some sites locking problems surface as soon as a server is installed; in other sites
951 locking problems may not surface for a long time. Almost without exception, when a locking
952 problem does surface, it will cause embarrassment and potential data corruption.
953 </para>
955 <para>
956 Over the past few years there have been a number of complaints on the Samba mailing lists
957 that have claimed that Samba caused data corruption. Three causes have been identified
958 so far:
959 </para>
961 <itemizedlist>
962         <listitem><para>
963         Incorrect configuration of oplocks (incompatible with the application
964         being used). This is a common problem even where MS Windows NT4 or MS Windows
965         200x-based servers were in use. It is imperative that the software application vendors'
966         instructions for configuration of file locking should be followed. If in doubt,
967         disable oplocks on both the server and the client. Disabling of all forms of file
968         caching on the MS Windows client may be necessary also.
969         </para></listitem>
971         <listitem><para>
972         Defective network cards, cables, or hubs/switches. This is generally a more
973         prevalent factor with low-cost networking hardware, although occasionally there
974         have also been problems with incompatibilities in more up-market hardware.
975         </para></listitem>
977         <listitem><para>
978         There have been some random reports of Samba log files being written over data
979         files. This has been reported by very few sites (about five in the past 3 years)
980         and all attempts to reproduce the problem have failed. The Samba Team has been
981         unable to catch this happening and thus unable to isolate any particular
982         cause. Considering the millions of systems that use Samba, for the sites that have
983         been affected by this as well as for the Samba Team, this is a frustrating and
984         vexing challenge. If you see this type of thing happening, please create a bug
985         report on Samba <ulink url="https://bugzilla.samba.org">Bugzilla</ulink> without delay.
986         Make sure that you give as much information as you possibly can to help isolate the
987         cause and to allow replication of the problem (an essential step in problem isolation and correction).
988         </para></listitem>
989 </itemizedlist>
991         <sect2>
992         <title>locking.tdb Error Messages</title>
994         <para>
995                 <quote>
996                         We are seeing lots of errors in the Samba logs, like:
997                 </quote>
998 <programlisting>
999 tdb(/usr/local/samba_2.2.7/var/locks/locking.tdb): rec_read bad magic
1000  0x4d6f4b61 at offset=36116
1001 </programlisting>
1003                 <quote>
1004                         What do these mean?
1005                 </quote>
1006         </para>
1008         <para>
1009         This error indicates a corrupted tdb. Stop all instances of smbd, delete locking.tdb, and restart smbd.
1010         </para>
1012         </sect2>
1014         <sect2>
1015                 <title>Problems Saving Files in MS Office on Windows XP</title>
1017                 <para>This is a bug in Windows XP. More information can be 
1018                 found in <ulink url="http://support.microsoft.com/?id=812937">Microsoft Knowledge Base article 812937</ulink></para>.
1020         </sect2>
1022         <sect2>
1024                 <title>Long Delays Deleting Files over Network with XP SP1</title>
1025                 
1026                 <para><quote>It sometimes takes approximately 35 seconds to delete files over the network after XP SP1 has been applied.</quote></para>
1028                 <para>This is a bug in Windows XP. More information can be found in <ulink url="http://support.microsoft.com/?id=811492">
1029                                 Microsoft Knowledge Base article 811492</ulink></para>.
1030         </sect2>
1032 </sect1>
1034 <sect1>
1035 <title>Additional Reading</title>
1037 <para>
1038 You may want to check for an updated version of this white paper on our Web site from
1039 time to time. Many of our white papers are updated as information changes. For those papers,
1040 the last edited date is always at the top of the paper.
1041 </para>
1043 <para>
1044 Section of the Microsoft MSDN Library on opportunistic locking: 
1045 </para>
1047 <para>
1048 Opportunistic Locks, Microsoft Developer Network (MSDN), Windows Development &gt;
1049 Windows Base Services &gt; Files and I/O &gt; SDK Documentation &gt; File Storage &gt; File Systems
1050 &gt; About File Systems &gt; Opportunistic Locks, Microsoft Corporation
1051 <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>.
1052 </para>
1054 <para>
1055         Microsoft Knowledge Base Article Q224992, <?latex \linebreak ?><quote>Maintaining Transactional Integrity 
1056 with OPLOCKS</quote>,
1057 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>.
1058 </para>
1060 <para>
1061 Microsoft Knowledge Base Article Q296264, <quote>Configuring Opportunistic Locking in Windows 2000</quote>,
1062 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>.
1063 </para>
1065 <para>
1066 Microsoft Knowledge Base Article Q129202, <quote>PC Ext: Explanation of Opportunistic Locking on Windows NT</quote>,
1067 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>.
1068 </para>
1070 </sect1>
1071 </chapter>