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:
Oplock FSCTRL routines:
- Minifilters: FltOplockFsctrl, FltOplockFsctrlEx
- Legacy filters and file systems: FsRtlOplockFsctrl, FsRtlOplockFsctrlEx, FsRtlUpperOplockFsctrl
Oplock check-break routines:
- Minifilters: FltCheckOplock, FltCheckOplockEx
- Legacy filters and file systems: FsRtlCheckOplock, FsRtlCheckOplockEx, FsRtlCheckOplockEx2, FsRtlOplockBreakH
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:
- IRP_MJ_CREATE with the FILE_OPEN_REQUIRING_OPLOCK bit set in Create.Options
- IRP_MJ_FILE_SYSTEM_CONTROL with oplock controls
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.