Oplock synchronization

Filters and file systems that request exclusive opportunistic locks (oplocks) must synchronize calls into the system-supplied oplock package. In particular, calls to oplock FSCTRL routines (to establish oplocks), must be synchronized against calls to oplock check-break routines. A list of both sets of routines include:

When processing an oplock request, filters and file systems must ensure the following:

  • I/O that might break an oplock cannot occur in parallel with processing the request.
  • Oplock requests cannot happen concurrently with oplock break acknowledgements.

IRP calls that request the creation of exclusive oplocks for the same file control block (FCB) are:

The following are some examples of oplock synchronization:

  • When processing an oplock request, a file system would acquire some resource exclusively, call FsRtlOplockFsctrlEx, and release the resource.

  • When processing an oplock break acknowledgment, the file system would acquire that same resource shared, call FsRtlOplockFsctrlEx, and release the resource.

  • When performing I/O, the file system would acquire that same resource shared, call FsRtlCheckOplockEx2, perform the I/O, and release the resource.

    Upper file systems should ensure that they synchronize between calls of FsRtlCheckUpperOplock and FsRtlUpperOplockFsctrl in a similar fashion.