|September 24, 1999 No. 89|
Opportunistic File Locking
Running a NPL Windows RunTime on a Windows NT server with Windows 95/98 or Windows NT workstations, it has been reported from a couple of sites that were having periodic problems with file sharing and locking, resulting in spurious I90's with associated "MS-DOS error code 21: Lock violation".
The process that causes the spurious I90's problem is called "Opportunistic File Locking" or Oplocks. With Exclusive Oplock, if a file is opened in a non-exclusive (deny none) mode, the redirector requests an opportunistic lock of the entire file. As long as no other process has the file open, the server will grant this oplock, giving the redirector exclusive access to the specified file. This will allow the redirector to perform read-ahead, write-behind, and lock caching, as long as no other process tries to open the file.
When a second process attempts to open the file, the original owner will be asked to Break Oplock or Break to Level II Oplock. At that point, the redirector must invalidate cached data, flush writes and locks, and release the oplock, or close the file. It is at this point that the file is re-opened in "shared" mode.
Note: For more information on this, and please see Microsoft TechNet Article Q129202.
Theoretically, the oplocks problem tends to only show up on networks that are very busy, or which have clients that do not reply in a timely manner to server oplock break requests. When using the standard default registry values, the server assumes that the client with an oplock has 'died' if it does not respond within 35 seconds to a break oplock request. An oplock break failure can result in data loss and possibly allowing two clients to simultaneously open a shared file in exclusive mode.
The following registry entries are used to enable or disable oplocks for Windows NT Workstation and Server. These registry keys may not exist by default. This registry setting change must be done on Windows NT Server and Workstations, and is not a requirement for Windows 95/98 since it does not use oplocks. To access the registry, run REGEDT32.EXE from the File menu, choose Run in Program Manager or File Manager. The settings are for changing the default setting from one (1) to zero (0).
WARNING: Using Registry Editor incorrectly can cause serious, system-wide problems that may require you to reinstall Windows NT to correct them. Microsoft and Niakwa cannot guarantee that any problems resulting from the use of Registry Editor can be solved. Use this tool at your own risk.
WARNING: Please note that there is a serious performance penalty paid for turning off Oplocks.
Note: On NT systems you need Administrative access to make the registry changes. After changing the registry settings, reboot the server or workstation for the settings to take effect. If your network needed the oplocks disabled when using NPL Revision 5.00.09, it would be advisable to leave it disabled for Revision 5.01.07.
UseOpportunisticLocking REG_DWORD 0 or 1
Default: 1 (True)
EnableOplocks REG_DWORD 0 or 1
Default: 1 (True)
Note: These entries are not usually in the registry as Microsoft assumes that you want to use this function.