SMB/CIFS Opportunistic Locks

来源:互联网 发布:php文件断点续传 编辑:程序博客网 时间:2024/05/18 02:15
SMB/CIFS Opportunistic Locks

An opportunistic lock (also called an oplock) is a lock placed by a client on a file residing on a server. In most cases, a client requests an opportunistic lock so it can cache data locally, thus reducing network traffic and improving apparent response time. Opportunistic locks are used by network redirectors on clients with remote servers, as well as by client applications on local servers.

Opportunistic locks coordinate data caching and coherency between clients and servers and among multiple clients. Data that is coherent is data that is the same across the network. In other words, if data is coherent, data on the server and all the clients is synchronized.

Opportunistic locks are not commands by the client to the server. They are requests from the client to the server. From the point of view of the client, they are opportunistic. In other words, the server grants such locks whenever other factors make the locks possible.

When a local application requests access to a remote file, the implementation of opportunistic locks is transparent to the application. The network redirector and the server involved open and close the opportunistic locks automatically. However, opportunistic locks can also be used when a local application requests access to a local file, and access by other applications and processes must be delegated to prevent corruption of the file. In this case, the local application directly requests an opportunistic lock from the local file system and caches the file locally. When used in this way, the opportunistic lock is effectively a semaphore managed by the local server, and is mainly used for the purposes of data coherency in the file and file access notification.

Before using opportunistic locks in your application, you should be familiar with the file access and sharing modes described in Creating and Opening Files.

The maximum number of concurrent opportunistic locks that you can create is limited only by the amount of available memory. For example, the maximum number created in test conditions with Windows 2000 and the NTFS file system is 359,000 locks.

Local applications should not attempt to request opportunistic locks from remote servers. An error will be returned by DeviceIoControl if an attempt is made to do this.

Opportunistic locks are of very limited use for applications. The only practical use is to test a network redirector or a server opportunistic lock handler. Typically, file systems implement support for opportunistic locks. Applications generally leave opportunistic lock management to the file system drivers. Anyone implementing a file system should use the Installable File System (IFS) Kit. Anyone developing a device driver other than an installable file system should use the Windows Driver Kit (WDK).

Opportunistic locks and the associated operations are a superset of the opportunistic lock portion of the Common Internet File System (CIFS) protocol, an Internet Draft. The CIFS protocol is an enhanced version of the Server Message Block (SMB) protocol. For more information, see Microsoft SMB Protocol and CIFS Protocol Overview. The CIFS Internet Draft explicitly identifies that a CIFS implementation may implement opportunistic locks by refusing to grant them.

The following topics identify opportunistic locks:

 

  • Local Caching
  • Data Coherency
  • How to Request an Opportunistic Lock
  • Server Response to Open Requests on Locked Files
  • Types of Opportunistic Locks
  • Breaking Opportunistic Locks
  • Opportunistic Lock Examples
  • Opportunistic Lock Operations

For additional information about opportunistic locks, see the CIFS Internet Draft document. Any discrepancies between this topic and the current CIFS Internet Draft should be resolved in favor of the CIFS Internet Draft.

 
原创粉丝点击