[Samba] How important are oplocks?

Jay Ts jay at jayts.cx
Wed Dec 18 16:21:04 GMT 2002

Bob Puff at NLE wrote:
> If Samba is corrupting the data files,

It is not Samba that is corrupting the files, but the clients, which
fail to handle oplocks correctly.

> then why wouldn't this be turned OFF by
> default?  I would think data corruption would be a major, MAJOR problem, and
> reduce the usability of Samba.  Is this really true?

The main thing to watch out for is programs that are writing records to
files, as with database software. That is, when a program opens a file,
writes some data to it, and then closes it. This is actually not common,
since most applications write to files when saving documents. They don't
write directly to the old file, but create a new file, write out all the
data to it, then rename the new copy to the old copy's filename.

On the other hand, database software (and some other applications)
may have multiple users opening the _same_ file, writing to it
"concurrently", then closing it at different times. If there is
a miscommunication regarding oplocks (specifically, not responding
to oplock break requests) then the file can become corrupt.  BTW,
one cause of oplock failure is flaky network hardware (NICs, hubs),
which the Samba Team can not do much about.

The choice to have oplock support enabled or disabled by default is
not an easy one; enabling oplocks can result in a 30% performance
gain, and cases where corruption happens are relatively rare.

To disable oplocks, simply put the following in your smb.conf:

	oplocks = off

You may lose some performance, but maybe you will rest easier.
A more intelligent, although more complicated, approach is to
study contents of the directories you are sharing with your Samba
server, and determine if the oplock break issue affects those shares
at all. It seems that most of the problems are caused by one of two

1. Database software, with the database files served by Samba.
2. Microsoft Office applicatons, accessing files served by Samba.

There are others, but they are relatively rare. After analyzing your
system, perhaps you can enable oplocks on shares for which they are ok,
and maybe even for your whole server. If there are only a few problem
files, you may be able to use the veto oplock files parameter to turn
oplocks off for just those.

Jay Ts
author, Using Samba, 2nd edition (O'Reilly)

More information about the samba mailing list