Tuesday, May 31, 2011

Windows: Opportunistic Locking

Client Registry


The location of the client registry entry for opportunistic locking has changed from the location in Microsoft Windows NT. In later versions of Windows, you can disable opportunistic locking by setting the following registry entry to 1:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\MRXSmb\Parameters
OplocksDisabled REG_DWORD 0 or 1
Default: 0 (not disabled)

Note The OplocksDisabled entry configures Windows clients to request or not to request opportunistic locks on a remote file.

Server Registry


You can also deny the granting of opportunistic locks by setting the following registry entry to 0:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\LanmanServer\Parameters
EnableOplocks REG_DWORD 0 or 1
Default: 1 (enabled)

Note The EnableOplocks entry configures Windows-based servers to allow or to deny opportunistic locks on local files. These servers include workstations that share files.

Windows Vista, 2008, Windows 7: Disabling Oplocks on SMB2


Oplocks cannot be turned off for SMB2. You can apparently disable SMB2 itself, but how to do so is not documented by Microsoft and was only mentioned in a Microsoft support forum post as a workaround for a bug.

According to that post, SMB2 can be disabled on Windows operating systems that support it (Vista, Server 2008).

To disable SMB2 on a Windows Server 2008 or Windows Vista PC hosting embedded database tables, change or add (dword) the following Registry value:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\LanmanServer\Parameters
SMB2 = 0

Once SMB2 is disabled, SMB1 will be used again and the methods described above applied to disable oplocks for SMB1.

How to Disable SMB 2.0 on Windows Vista/2008


So, for troubleshooting purposes, mostly in an environment that has mixes operating systems, you might want to consider disabling SMB 2.0. You need to do so on both the "client" and the "server" operating systems. To disable SMB 2.0 for Windows Vista or Windows Server 2008 systems that are the "client" systems run the following commands:

sc config lanmanworkstation depend= bowser/mrxsmb10/nsi
sc config mrxsmb20 start= disabled

Note there's an extra " " (space) after the "=" sign.

To enable back SMB 2.0 for Windows Vista or Windows Server 2008 systems that are the “client” systems run the following commands:

sc config lanmanworkstation depend= bowser/mrxsmb10/mrxsmb20/nsi
sc config mrxsmb20 start= auto

Again, note there's an extra " " (space) after the "=" sign.

In order to disable SMB 2.0 on the server-side computer, follow these steps:
  1. Run "regedit" on Windows Server 2008 based computer.
  2. Expand and locate the sub tree as follows.
    HKLM\System\CurrentControlSet\Services\LanmanServer\Parameters
  3. Add a new REG_DWORD key with the name of "Smb2" (without quotation mark)
    Value name: Smb2
    Value type: REG_DWORD
    0 = disabled
    1 = enabled
  4. Set the value to 0 to disable SMB 2.0, or set it to 1 to re-enable SMB 2.0.
  5. Reboot the server.

References


Configuring opportunistic locking in Windows Microsoft Support Article ID: 296264 Last Review: April 4, 2011 - Revision: 11.0
Opportunistic Locking and Read Caching on Microsoft Windows Networks A Data Access Worldwide White Paper Last Edited: July 9, 2009
Computer & Network Troubleshooting Rees Software
Chapter 17. File and Record Locking The Official Samba 3.5.x HOWTO and Reference Guide
Major bug in Vista File Sharing (Peer-to-Peer)? Microsoft Support Forum
How to Disable SMB 2.0 on Windows Vista/2008 Daniel Petri - January 8, 2009
Windows 7 corruption network comp.lang.clipper.visual-objects
Major bug in Vista File Sharing (Peer-to-Peer)?
Data corruption when multiple users perform read and write operations to a shared file in the SMB2 environment Microsoft Support Article ID: 2028965 - Last Review: June 10, 2011 - Revision: 4.1