8 <title>File and Record Locking</title>
11 One area that causes trouble for many network administrators is locking.
12 The extent of the problem is readily evident from searches over the Internet.
16 <title>Features and Benefits</title>
19 Samba provides all the same locking semantics that MS Windows clients expect
20 and that MS Windows NT4/200x servers also provide.
24 The term <emphasis>locking</emphasis> has exceptionally broad meaning and covers
25 a range of functions that are all categorized under this one term.
29 Opportunistic locking is a desirable feature when it can enhance the
30 perceived performance of applications on a networked client. However, the
31 opportunistic locking protocol is not robust and, therefore, can
32 encounter problems when invoked beyond a simplistic configuration or
33 on extended slow or faulty networks. In these cases, operating
34 system management of opportunistic locking and/or recovering from
35 repetitive errors can offset the perceived performance advantage that
36 it is intended to provide.
40 The MS Windows network administrator needs to be aware that file and record
41 locking semantics (behavior) can be controlled either in Samba or by way of registry
42 settings on the MS Windows client.
47 Sometimes it is necessary to disable locking control settings on both the Samba
48 server as well as on each MS Windows client!
55 <title>Discussion</title>
58 There are two types of locking that need to be performed by an SMB server.
59 The first is <emphasis>record locking</emphasis> that allows a client to lock
60 a range of bytes in a open file. The second is the <emphasis>deny modes</emphasis>
61 that are specified when a file is open.
65 Record locking semantics under UNIX are very different from record locking under
66 Windows. Versions of Samba before 2.2 have tried to use the native fcntl() UNIX
67 system call to implement proper record locking between different Samba clients.
68 This cannot be fully correct for several reasons. The simplest is the fact
69 that a Windows client is allowed to lock a byte range up to 2^32 or 2^64,
70 depending on the client OS. The UNIX locking only supports byte ranges up to 2^31.
71 So it is not possible to correctly satisfy a lock request above 2^31. There are
72 many more differences, too many to be listed here.
76 Samba 2.2 and above implements record locking completely independent of the
77 underlying UNIX system. If a byte range lock that the client requests happens
78 to fall into the range of 0-2^31, Samba hands this request down to the UNIX system.
79 All other locks cannot be seen by UNIX, anyway.
83 Strictly speaking, an SMB server should check for locks before every read and write call on
84 a file. Unfortunately with the way fcntl() works, this can be slow and may overstress
85 the <command>rpc.lockd</command>. This is almost always unnecessary as clients are supposed to
86 independently make locking calls before reads and writes if locking is
87 important to them. By default, Samba only makes locking calls when explicitly asked
88 to by a client, but if you set <smbconfoption><name>strict locking</name><value>yes</value></smbconfoption>, it
89 will make lock checking calls on <emphasis>every</emphasis> read and write call.
93 You can also disable byte range locking completely by using
94 <smbconfoption><name>locking</name><value>no</value></smbconfoption>.
95 This is useful for those shares that do not support locking or do not need it
96 (such as CDROMs). In this case, Samba fakes the return codes of locking calls to
97 tell clients that everything is okay.
101 The second class of locking is the <emphasis>deny modes</emphasis>. These
102 are set by an application when it opens a file to determine what types of
103 access should be allowed simultaneously with its open. A client may ask for
104 <constant>DENY_NONE</constant>, <constant>DENY_READ</constant>,
105 <constant>DENY_WRITE</constant>, or <constant>DENY_ALL</constant>. There are also special compatibility
106 modes called <constant>DENY_FCB</constant> and <constant>DENY_DOS</constant>.
110 <title>Opportunistic Locking Overview</title>
113 Opportunistic locking (Oplocks) is invoked by the Windows file system
114 (as opposed to an API) via registry entries (on the server and the client)
115 for the purpose of enhancing network performance when accessing a file
116 residing on a server. Performance is enhanced by caching the file
117 locally on the client that allows:
121 <varlistentry><term>Read-ahead:</term>
123 The client reads the local copy of the file, eliminating network latency.
127 <varlistentry><term>Write caching:</term>
129 The client writes to the local copy of the file, eliminating network latency.
133 <varlistentry><term>Lock caching:</term>
135 The client caches application locks locally, eliminating network latency.
141 The performance enhancement of oplocks is due to the opportunity of
142 exclusive access to the file &smbmdash; even if it is opened with deny-none &smbmdash;
143 because Windows monitors the file's status for concurrent access from
148 <title>Windows defines 4 kinds of Oplocks:</title>
150 <varlistentry><term>Level1 Oplock</term>
152 The redirector sees that the file was opened with deny
153 none (allowing concurrent access), verifies that no
154 other process is accessing the file, checks that
155 oplocks are enabled, then grants deny-all/read-write/exclusive
156 access to the file. The client now performs
157 operations on the cached local file.
161 If a second process attempts to open the file, the open
162 is deferred while the redirector <quote>breaks</quote> the original
163 oplock. The oplock break signals the caching client to
164 write the local file back to the server, flush the
165 local locks and discard read-ahead data. The break is
166 then complete, the deferred open is granted, and the
167 multiple processes can enjoy concurrent file access as
168 dictated by mandatory or byte-range locking options.
169 However, if the original opening process opened the
170 file with a share mode other than deny-none, then the
171 second process is granted limited or no access, despite
176 <varlistentry><term>Level2 Oplock</term>
178 Performs like a Level1 oplock, except caching is only
179 operative for reads. All other operations are performed
180 on the server disk copy of the file.
184 <varlistentry><term>Filter Oplock</term>
186 Does not allow write or delete file access.
190 <varlistentry><term>Batch Oplock</term>
192 Manipulates file openings and closings and allows caching
199 An important detail is that oplocks are invoked by the file system, not
200 an application API. Therefore, an application can close an oplocked
201 file, but the file system does not relinquish the oplock. When the
202 oplock break is issued, the file system then simply closes the file in
203 preparation for the subsequent open by the second process.
207 <emphasis>Opportunistic locking</emphasis> is actually an improper name for this feature.
208 The true benefit of this feature is client-side data caching, and
209 oplocks is merely a notification mechanism for writing data back to the
210 networked storage disk. The limitation of opportunistic locking is the
211 reliability of the mechanism to process an oplock break (notification)
212 between the server and the caching client. If this exchange is faulty
213 (usually due to timing out for any number of reasons), then the
214 client-side caching benefit is negated.
218 The actual decision that a user or administrator should consider is
219 whether it is sensible to share among multiple users data that will
220 be cached locally on a client. In many cases the answer is no.
221 Deciding when to cache or not cache data is the real question, and thus
222 <quote>opportunistic locking</quote> should be treated as a toggle for client-side
223 caching. Turn it <quote>on</quote> when client-side caching is desirable and
224 reliable. Turn it <quote>off</quote> when client-side caching is redundant,
225 unreliable or counter-productive.
229 Opportunistic locking is by default set to <quote>on</quote> by Samba on all
230 configured shares, so careful attention should be given to each case to
231 determine if the potential benefit is worth the potential for delays.
232 The following recommendations will help to characterize the environment
233 where opportunistic locking may be effectively configured.
237 Windows opportunistic locking is a lightweight performance-enhancing
238 feature. It is not a robust and reliable protocol. Every
239 implementation of opportunistic locking should be evaluated as a
240 tradeoff between perceived performance and reliability. Reliability
241 decreases as each successive rule above is not enforced. Consider a
242 share with oplocks enabled, over a wide area network, to a client on a
243 South Pacific atoll, on a high-availability server, serving a
244 mission-critical multi-user corporate database during a tropical
245 storm. This configuration will likely encounter problems with oplocks.
249 Oplocks can be beneficial to perceived client performance when treated
250 as a configuration toggle for client-side data caching. If the data
251 caching is likely to be interrupted, then oplock usage should be
252 reviewed. Samba enables opportunistic locking by default on all
253 shares. Careful attention should be given to the client usage of
254 shared data on the server, the server network reliability and the
255 opportunistic locking configuration of each share.
256 In mission critical high availability environments, data integrity is
257 often a priority. Complex and expensive configurations are implemented
258 to ensure that if a client loses connectivity with a file server, a
259 failover replacement will be available immediately to provide
260 continuous data availability.
264 Windows client failover behavior is more at risk of application
265 interruption than other platforms because it is dependent upon an
266 established TCP transport connection. If the connection is interrupted
267 &smbmdash; as in a file server failover &smbmdash; a new session must be established.
268 It is rare for Windows client applications to be coded to recover
269 correctly from a transport connection loss, therefore, most applications
270 will experience some sort of interruption &smbmdash; at worst, abort and
275 If a client session has been caching writes and reads locally due to
276 opportunistic locking, it is likely that the data will be lost when the
277 application restarts or recovers from the TCP interrupt. When the TCP
278 connection drops, the client state is lost. When the file server
279 recovers, an oplock break is not sent to the client. In this case, the
280 work from the prior session is lost. Observing this scenario with
281 oplocks disabled and with the client writing data to the file server
282 real-time, the failover will provide the data on disk as it
283 existed at the time of the disconnect.
287 In mission-critical high-availability environments, careful attention
288 should be given to opportunistic locking. Ideally, comprehensive
289 testing should be done with all affected applications with oplocks
290 enabled and disabled.
294 <title>Exclusively Accessed Shares</title>
297 Opportunistic locking is most effective when it is confined to shares
298 that are exclusively accessed by a single user, or by only one user at
299 a time. Because the true value of opportunistic locking is the local
300 client caching of data, any operation that interrupts the caching
301 mechanism will cause a delay.
305 Home directories are the most obvious examples of where the performance
306 benefit of opportunistic locking can be safely realized.
312 <title>Multiple-Accessed Shares or Files</title>
315 As each additional user accesses a file in a share with opportunistic
316 locking enabled, the potential for delays and resulting perceived poor
317 performance increases. When multiple users are accessing a file on a
318 share that has oplocks enabled, the management impact of sending and
319 receiving oplock breaks and the resulting latency while other clients
320 wait for the caching client to flush data offset the performance gains
325 As each additional client attempts to access a file with oplocks set,
326 the potential performance improvement is negated and eventually results
327 in a performance bottleneck.
333 <title>UNIX or NFS Client-Accessed Files</title>
336 Local UNIX and NFS clients access files without a mandatory
337 file-locking mechanism. Thus, these client platforms are incapable of
338 initiating an oplock break request from the server to a Windows client
339 that has a file cached. Local UNIX or NFS file access can therefore
340 write to a file that has been cached by a Windows client, which
341 exposes the file to likely data corruption.
345 If files are shared between Windows clients, and either local UNIX
346 or NFS users, turn opportunistic locking off.
352 <title>Slow and/or Unreliable Networks</title>
355 The biggest potential performance improvement for opportunistic locking
356 occurs when the client-side caching of reads and writes delivers the
357 most differential over sending those reads and writes over the wire.
358 This is most likely to occur when the network is extremely slow,
359 congested, or distributed (as in a WAN). However, network latency also
360 has a high impact on the reliability of the oplock break
361 mechanism, and thus increases the likelihood of encountering oplock
362 problems that more than offset the potential perceived performance
363 gain. Of course, if an oplock break never has to be sent, then this is
364 the most advantageous scenario to utilize opportunistic locking.
368 If the network is slow, unreliable, or a WAN, then do not configure
369 opportunistic locking if there is any chance of multiple users
370 regularly opening the same file.
376 <title>Multi-User Databases</title>
379 Multi-user databases clearly pose a risk due to their very nature &smbmdash;
380 they are typically heavily accessed by numerous users at random
381 intervals. Placing a multi-user database on a share with opportunistic
382 locking enabled will likely result in a locking management bottleneck
383 on the Samba server. Whether the database application is developed
384 in-house or a commercially available product, ensure that the share
385 has opportunistic locking disabled.
391 <title>PDM Data Shares</title>
394 Process Data Management (PDM) applications such as IMAN, Enovia and
395 Clearcase are increasing in usage with Windows client platforms, and
396 therefore SMB datastores. PDM applications manage multi-user
397 environments for critical data security and access. The typical PDM
398 environment is usually associated with sophisticated client design
399 applications that will load data locally as demanded. In addition, the
400 PDM application will usually monitor the data-state of each client.
401 In this case, client-side data caching is best left to the local
402 application and PDM server to negotiate and maintain. It is
403 appropriate to eliminate the client OS from any caching tasks, and the
404 server from any oplock management, by disabling opportunistic locking on
411 <title>Beware of Force User</title>
414 Samba includes an &smb.conf; parameter called <smbconfoption><name>force user</name></smbconfoption> that changes
415 the user accessing a share from the incoming user to whatever user is
416 defined by the smb.conf variable. If opportunistic locking is enabled
417 on a share, the change in user access causes an oplock break to be sent
418 to the client, even if the user has not explicitly loaded a file. In
419 cases where the network is slow or unreliable, an oplock break can
420 become lost without the user even accessing a file. This can cause
421 apparent performance degradation as the client continually reconnects
422 to overcome the lost oplock break.
426 Avoid the combination of the following:
431 <smbconfoption><name>force user</name></smbconfoption> in the &smb.conf; share configuration.
435 Slow or unreliable networks
439 Opportunistic locking enabled
446 <title>Advanced Samba Opportunistic Locking Parameters</title>
449 Samba provides opportunistic locking parameters that allow the
450 administrator to adjust various properties of the oplock mechanism to
451 account for timing and usage levels. These parameters provide good
452 versatility for implementing oplocks in environments where they would
453 likely cause problems. The parameters are:
454 <smbconfoption><name>oplock break wait time</name></smbconfoption>,
455 <smbconfoption><name>oplock contention limit</name></smbconfoption>.
459 For most users, administrators and environments, if these parameters
460 are required, then the better option is to simply turn oplocks off.
461 The Samba SWAT help text for both parameters reads: <quote>Do not change
462 this parameter unless you have read and understood the Samba oplock code.</quote>
469 <title>Mission-Critical High-Availability</title>
472 In mission-critical high-availability environments, data integrity is
473 often a priority. Complex and expensive configurations are implemented
474 to ensure that if a client loses connectivity with a file server, a
475 failover replacement will be available immediately to provide
476 continuous data availability.
480 Windows client failover behavior is more at risk of application
481 interruption than other platforms because it is dependant upon an
482 established TCP transport connection. If the connection is interrupted
483 &smbmdash; as in a file server failover &smbmdash; a new session must be established.
484 It is rare for Windows client applications to be coded to recover
485 correctly from a transport connection loss, therefore, most applications
486 will experience some sort of interruption &smbmdash; at worst, abort and
491 If a client session has been caching writes and reads locally due to
492 opportunistic locking, it is likely that the data will be lost when the
493 application restarts, or recovers from the TCP interrupt. When the TCP
494 connection drops, the client state is lost. When the file server
495 recovers, an oplock break is not sent to the client. In this case, the
496 work from the prior session is lost. Observing this scenario with
497 oplocks disabled, and the client was writing data to the file server
498 real-time, then the failover will provide the data on disk as it
499 existed at the time of the disconnect.
503 In mission-critical high-availability environments, careful attention
504 should be given to opportunistic locking. Ideally, comprehensive
505 testing should be done with all effected applications with oplocks
506 enabled and disabled.
514 <title>Samba Opportunistic Locking Control</title>
517 Opportunistic locking is a unique Windows file locking feature. It is
518 not really file locking, but is included in most discussions of Windows
519 file locking, so is considered a de facto locking feature.
520 Opportunistic locking is actually part of the Windows client file
521 caching mechanism. It is not a particularly robust or reliable feature
522 when implemented on the variety of customized networks that exist in
523 enterprise computing.
527 Like Windows, Samba implements opportunistic locking as a server-side
528 component of the client caching mechanism. Because of the lightweight
529 nature of the Windows feature design, effective configuration of
530 opportunistic locking requires a good understanding of its limitations,
531 and then applying that understanding when configuring data access for
532 each particular customized network and client usage state.
536 Opportunistic locking essentially means that the client is allowed to download and cache
537 a file on their hard drive while making changes; if a second client wants to access the
538 file, the first client receives a break and must synchronize the file back to the server.
539 This can give significant performance gains in some cases; some programs insist on
540 synchronizing the contents of the entire file back to the server for a single change.
544 Level1 Oplocks (also known as just plain <quote>oplocks</quote>) is another term for opportunistic locking.
548 Level2 Oplocks provides opportunistic locking for a file that will be treated as
549 <emphasis>read only</emphasis>. Typically this is used on files that are read-only or
550 on files that the client has no initial intention to write to at time of opening the file.
554 Kernel Oplocks are essentially a method that allows the Linux kernel to co-exist with
555 Samba's oplocked files, although this has provided better integration of MS Windows network
556 file locking with the underlying OS, SGI IRIX and Linux are the only two OSs that are
557 oplock-aware at this time.
561 Unless your system supports kernel oplocks, you should disable oplocks if you are
562 accessing the same files from both UNIX/Linux and SMB clients. Regardless, oplocks should
563 always be disabled if you are sharing a database file (e.g., Microsoft Access) between
564 multiple clients, as any break the first client receives will affect synchronization of
565 the entire file (not just the single record), which will result in a noticeable performance
566 impairment and, more likely, problems accessing the database in the first place. Notably,
567 Microsoft Outlook's personal folders (*.pst) react quite badly to oplocks. If in doubt,
568 disable oplocks and tune your system from that point.
572 If client-side caching is desirable and reliable on your network, you will benefit from
573 turning on oplocks. If your network is slow and/or unreliable, or you are sharing your
574 files among other file sharing mechanisms (e.g., NFS) or across a WAN, or multiple people
575 will be accessing the same files frequently, you probably will not benefit from the overhead
576 of your client sending oplock breaks and will instead want to disable oplocks for the share.
580 Another factor to consider is the perceived performance of file access. If oplocks provide no
581 measurable speed benefit on your network, it might not be worth the hassle of dealing with them.
585 <title>Example Configuration</title>
588 In the following section we examine two distinct aspects of Samba locking controls.
592 <title>Disabling Oplocks</title>
595 You can disable oplocks on a per-share basis with the following:
600 <smbconfsection>[acctdata]</smbconfsection>
601 <smbconfoption><name>oplocks</name><value>False</value></smbconfoption>
602 <smbconfoption><name>level2 oplocks</name><value>False</value></smbconfoption>
607 The default oplock type is Level1. Level2 oplocks are enabled on a per-share basis
608 in the &smb.conf; file.
612 Alternately, you could disable oplocks on a per-file basis within the share:
617 <smbconfoption><name>veto oplock files</name><value>/*.mdb/*.MDB/*.dbf/*.DBF/</value></smbconfoption>
622 If you are experiencing problems with oplocks as apparent from Samba's log entries,
623 you may want to play it safe and disable oplocks and Level2 oplocks.
629 <title>Disabling Kernel Oplocks</title>
632 Kernel oplocks is an &smb.conf; parameter that notifies Samba (if
633 the UNIX kernel has the capability to send a Windows client an oplock
634 break) when a UNIX process is attempting to open the file that is
635 cached. This parameter addresses sharing files between UNIX and
636 Windows with oplocks enabled on the Samba server: the UNIX process
637 can open the file that is Oplocked (cached) by the Windows client and
638 the smbd process will not send an oplock break, which exposes the file
639 to the risk of data corruption. If the UNIX kernel has the ability to
640 send an oplock break, then the kernel oplocks parameter enables Samba
641 to send the oplock break. Kernel oplocks are enabled on a per-server
642 basis in the &smb.conf; file.
647 <smbconfoption><name>kernel oplocks</name><value>yes</value></smbconfoption>
653 Veto opLocks is an &smb.conf; parameter that identifies specific files for
654 which oplocks are disabled. When a Windows client opens a file that
655 has been configured for veto oplocks, the client will not be granted
656 the oplock, and all operations will be executed on the original file on
657 disk instead of a client-cached file copy. By explicitly identifying
658 files that are shared with UNIX processes and disabling oplocks for
659 those files, the server-wide Oplock configuration can be enabled to
660 allow Windows clients to utilize the performance benefit of file
661 caching without the risk of data corruption. Veto Oplocks can be
662 enabled on a per-share basis, or globally for the entire server, in the
663 &smb.conf; file as shown in <link linkend="far1"/>.
667 <smbconfexample id="far1">
668 <title>Share with some files oplocked</title>
669 <smbconfsection>[global]</smbconfsection>
670 <smbconfoption><name>veto oplock files</name><value>/filename.htm/*.txt/</value></smbconfoption>
672 <smbconfsection>[share_name]</smbconfsection>
673 <smbconfoption><name>veto oplock files</name><value>/*.exe/filename.ext/</value></smbconfoption>
678 <smbconfoption><name>oplock break wait time</name></smbconfoption> is an &smb.conf; parameter
679 that adjusts the time interval for Samba to reply to an oplock break request. Samba recommends:
680 <quote>Do not change this parameter unless you have read and understood the Samba oplock code.</quote>
681 Oplock break Wait Time can only be configured globally in the &smb.conf; file as shown below.
686 <smbconfoption><name>oplock break wait time</name><value> 0 (default)</value></smbconfoption>
691 <emphasis>Oplock break contention limit</emphasis> is an &smb.conf; parameter that limits the
692 response of the Samba server to grant an oplock if the configured
693 number of contending clients reaches the limit specified by the parameter. Samba recommends
694 <quote>Do not change this parameter unless you have read and understood the Samba oplock code.</quote>
695 Oplock break Contention Limit can be enable on a per-share basis, or globally for
696 the entire server, in the &smb.conf; file as shown in <link linkend="far3"/>.
700 <smbconfexample id="far3">
701 <title>Configuration with oplock break contention limit</title>
702 <smbconfsection>[global]</smbconfsection>
703 <smbconfoption><name>oplock break contention limit</name><value> 2 (default)</value></smbconfoption>
705 <smbconfsection>[share_name]</smbconfsection>
706 <smbconfoption><name>oplock break contention limit</name><value> 2 (default)</value></smbconfoption>
716 <title>MS Windows Opportunistic Locking and Caching Controls</title>
719 There is a known issue when running applications (like Norton Anti-Virus) on a Windows 2000/ XP
720 workstation computer that can affect any application attempting to access shared database files
721 across a network. This is a result of a default setting configured in the Windows 2000/XP
722 operating system known as <emphasis>opportunistic locking</emphasis>. When a workstation
723 attempts to access shared data files located on another Windows 2000/XP computer,
724 the Windows 2000/XP operating system will attempt to increase performance by locking the
725 files and caching information locally. When this occurs, the application is unable to
726 properly function, which results in an <quote>Access Denied</quote>
727 error message being displayed during network operations.
731 All Windows operating systems in the NT family that act as database servers for data files
732 (meaning that data files are stored there and accessed by other Windows PCs) may need to
733 have opportunistic locking disabled in order to minimize the risk of data file corruption.
734 This includes Windows 9x/Me, Windows NT, Windows 200x, and Windows XP.
738 If you are using a Windows NT family workstation in place of a server, you must also
739 disable opportunistic locking (oplocks) on that workstation. For example, if you use a
740 PC with the Windows NT Workstation operating system instead of Windows NT Server, and you
741 have data files located on it that are accessed from other Windows PCs, you may need to
742 disable oplocks on that system.
746 The major difference is the location in the Windows registry where the values for disabling
747 oplocks are entered. Instead of the LanManServer location, the LanManWorkstation location
752 You can verify (change or add, if necessary) this registry value using the Windows
753 Registry Editor. When you change this registry value, you will have to reboot the PC
754 to ensure that the new setting goes into effect.
758 The location of the client registry entry for opportunistic locking has changed in
759 Windows 2000 from the earlier location in Microsoft Windows NT.
763 Windows 2000 will still respect the EnableOplocks registry value used to disable oplocks
764 in earlier versions of Windows.
768 You can also deny the granting of opportunistic locks by changing the following registry entries:
773 HKEY_LOCAL_MACHINE\System\
774 CurrentControlSet\Services\MRXSmb\Parameters\
776 OplocksDisabled REG_DWORD 0 or 1
777 Default: 0 (not disabled)
782 The OplocksDisabled registry value configures Windows clients to either request or not
783 request opportunistic locks on a remote file. To disable oplocks, the value of
784 OplocksDisabled must be set to 1.
789 HKEY_LOCAL_MACHINE\System\
790 CurrentControlSet\Services\LanmanServer\Parameters
792 EnableOplocks REG_DWORD 0 or 1
793 Default: 1 (Enabled by Default)
795 EnableOpLockForceClose REG_DWORD 0 or 1
796 Default: 0 (Disabled by Default)
801 The EnableOplocks value configures Windows-based servers (including Workstations sharing
802 files) to allow or deny opportunistic locks on local files.
806 To force closure of open oplocks on close or program exit, EnableOpLockForceClose must be set to 1.
810 An illustration of how Level2 oplocks work:
815 Station 1 opens the file requesting oplock.
818 Since no other station has the file open, the server grants station 1 exclusive oplock.
821 Station 2 opens the file requesting oplock.
824 Since station 1 has not yet written to the file, the server asks station 1 to break
828 Station 1 complies by flushing locally buffered lock information to the server.
831 Station 1 informs the server that it has Broken to Level2 Oplock (alternately,
832 station 1 could have closed the file).
835 The server responds to station 2's open request, granting it Level2 oplock.
836 Other stations can likewise open the file and obtain Level2 oplock.
839 Station 2 (or any station that has the file open) sends a write request SMB.
840 The server returns the write response.
843 The server asks all stations that have the file open to break to none, meaning no
844 station holds any oplock on the file. Because the workstations can have no cached
845 writes or locks at this point, they need not respond to the break-to-none advisory;
846 all they need do is invalidate locally cashed read-ahead data.
851 <title>Workstation Service Entries</title>
853 <para><programlisting>
854 \HKEY_LOCAL_MACHINE\System\
855 CurrentControlSet\Services\LanmanWorkstation\Parameters
857 UseOpportunisticLocking REG_DWORD 0 or 1
859 </programlisting></para>
862 This indicates whether the redirector should use opportunistic-locking (oplock) performance
863 enhancement. This parameter should be disabled only to isolate problems.
868 <title>Server Service Entries</title>
870 <para><programlisting>
871 \HKEY_LOCAL_MACHINE\System\
872 CurrentControlSet\Services\LanmanServer\Parameters
874 EnableOplocks REG_DWORD 0 or 1
876 </programlisting></para>
879 This specifies whether the server allows clients to use oplocks on files. Oplocks are a
880 significant performance enhancement, but have the potential to cause lost cached
881 data on some networks, particularly wide area networks.
884 <para><programlisting>
885 MinLinkThroughput REG_DWORD 0 to infinite bytes per second
887 </programlisting></para>
890 This specifies the minimum link throughput allowed by the server before it disables
891 raw and opportunistic locks for this connection.
894 <para><programlisting>
895 MaxLinkDelay REG_DWORD 0 to 100,000 seconds
897 </programlisting></para>
900 This specifies the maximum time allowed for a link delay. If delays exceed this number,
901 the server disables raw I/O and opportunistic locking for this connection.
904 <para><programlisting>
905 OplockBreakWait REG_DWORD 10 to 180 seconds
907 </programlisting></para>
910 This specifies the time that the server waits for a client to respond to an oplock break
911 request. Smaller values can allow detection of crashed clients more quickly but can
912 potentially cause loss of cached data.
919 <title>Persistent Data Corruption</title>
922 If you have applied all of the settings discussed in this chapter but data corruption problems
923 and other symptoms persist, here are some additional things to check out.
927 We have credible reports from developers that faulty network hardware, such as a single
928 faulty network card, can cause symptoms similar to read caching and data corruption.
929 If you see persistent data corruption even after repeated reindexing, you may have to
930 rebuild the data files in question. This involves creating a new data file with the
931 same definition as the file to be rebuilt and transferring the data from the old file
932 to the new one. There are several known methods for doing this that can be found in
939 <title>Common Errors</title>
942 In some sites, locking problems surface as soon as a server is installed; in other sites
943 locking problems may not surface for a long time. Almost without exception, when a locking
944 problem does surface it will cause embarrassment and potential data corruption.
948 Over the past few years there have been a number of complaints on the Samba mailing lists
949 that have claimed that Samba caused data corruption. Three causes have been identified
955 Incorrect configuration of opportunistic locking (incompatible with the application
956 being used. This is a common problem even where MS Windows NT4 or MS Windows
957 200x-based servers were in use. It is imperative that the software application vendors'
958 instructions for configuration of file locking should be followed. If in doubt,
959 disable oplocks on both the server and the client. Disabling of all forms of file
960 caching on the MS Windows client may be necessary also.
964 Defective network cards, cables, or HUBs/Switched. This is generally a more
965 prevalent factor with low cost networking hardware, although occasionally there
966 have also been problems with incompatibilities in more up-market hardware.
970 There have been some random reports of Samba log files being written over data
971 files. This has been reported by very few sites (about five in the past three years)
972 and all attempts to reproduce the problem have failed. The Samba Team has been
973 unable to catch this happening and thus has not been able to isolate any particular
974 cause. Considering the millions of systems that use Samba, for the sites that have
975 been affected by this as well as for the Samba Team this is a frustrating and
976 a vexing challenge. If you see this type of thing happening, please create a bug
977 report on Samba <ulink url="https://bugzilla.samba.org">Bugzilla</ulink> without delay.
978 Make sure that you give as much information as you possibly can help isolate the
979 cause and to allow replication of the problem (an essential step in problem isolation and correction).
984 <title>locking.tdb Error Messages</title>
988 We are seeing lots of errors in the Samba logs, like:
991 tdb(/usr/local/samba_2.2.7/var/locks/locking.tdb): rec_read bad magic
992 0x4d6f4b61 at offset=36116
1001 This error indicated a corrupted tdb. Stop all instances of smbd, delete locking.tdb, and restart smbd.
1007 <title>Problems Saving Files in MS Office on Windows XP</title>
1009 <para>This is a bug in Windows XP. More information can be
1010 found in <ulink url="http://support.microsoft.com/?id=812937">Microsoft Knowledge Base article 812937.</ulink></para>
1016 <title>Long Delays Deleting Files Over Network with XP SP1</title>
1018 <para><quote>It sometimes takes approximately 35 seconds to delete files over the network after XP SP1 has been applied.</quote></para>
1020 <para>This is a bug in Windows XP. More information can be found in <ulink url="http://support.microsoft.com/?id=811492">
1021 Microsoft Knowledge Base article 811492.</ulink></para>
1027 <title>Additional Reading</title>
1030 You may want to check for an updated version of this white paper on our Web site from
1031 time to time. Many of our white papers are updated as information changes. For those papers,
1032 the last edited date is always at the top of the paper.
1036 Section of the Microsoft MSDN Library on opportunistic locking:
1040 Opportunistic Locks, Microsoft Developer Network (MSDN), Windows Development >
1041 Windows Base Services > Files and I/O > SDK Documentation > File Storage > File Systems
1042 > About File Systems > Opportunistic Locks, Microsoft Corporation.
1043 <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>
1047 Microsoft Knowledge Base Article Q224992 <?latex \linebreak ?><quote>Maintaining Transactional Integrity
1048 with OPLOCKS</quote>,
1049 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>.
1053 Microsoft Knowledge Base Article Q296264 <quote>Configuring Opportunistic Locking in Windows 2000</quote>,
1054 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>.
1058 Microsoft Knowledge Base Article Q129202 <quote>PC Ext: Explanation of Opportunistic Locking on Windows NT</quote>,
1059 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>.