To add or not to add oplock support into FileTest?

Hi,

I was thinking of adding few buttons into FileTest - in particular, to support oplocks (level_1, level_2, batch). However, when I tried to request oplocks programatically, it always failed. I can see oplocks being granted to SRV.SYS when a file is opened remotely, but when an application requests an oplock, it does not work.

Is it by design that oplocks are something to be exclusively used by network redirector(s) or am I doing something wrong?

Hi.

First of all, thank you for this great tool!

Several years ago I modified your FileTest tool to use oplocks for own test.
Oplocks were granted.
So maybe something is wrong with CreateFile flags, overlapped for example.

Oplocks can be also used from UM programmatically. There is an example in
MSDN where oplocks help to release file if someone wants to use it (but I
can’t find the link now).

Best regards,
Alexey Barabash

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@volny.cz
Sent: Wednesday, September 10, 2014 3:15 PM
To: Windows File Systems Devs Interest List
Subject: [ntfsd] To add or not to add oplock support into FileTest?

Hi,

I was thinking of adding few buttons into FileTest - in particular, to
support oplocks (level_1, level_2, batch). However, when I tried to request
oplocks programatically, it always failed. I can see oplocks being granted
to SRV.SYS when a file is opened remotely, but when an application requests
an oplock, it does not work.

Is it by design that oplocks are something to be exclusively used by network
redirector(s) or am I doing something wrong?


NTFSD is sponsored by OSR

OSR is hiring!! Info at http://www.osr.com/careers

For our schedule of debugging and file system seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Yet another thing.

When oplock request succeed, DeviceIoControl returns FALSE and last error is
ERROR_IO_PENDING .

Best regards,
Alexey Barabash

It sounds like an implementation issue. I couldn’t see any privileges required (not in FAT at least and it supports oplocks). I would note that we have written oplocks tests before that acquire oplocks from user mode, and there are public examples (e.g., http://royce-lu.blogspot.ca/2010/03/understanding-oplock-and-avoid-sharing.html ) that demonstrate oplock usage from use mode. Plus the WHCK tests also exercise oplocks (including filter oplocks) and as far as I know this is all done from user mode.

Tony
OSR

That’s because oplocks are a *real* asynchronous protocol. So the file object can’t be set up for synchronous I/O (for example) and if you are using the Win32 API (versus the native file system control API - it WILL fail if you use the native device control API) you’d have to set up the overlapped structure properly, as you get a callback when the oplocks is broken.

Tony
OSR

The example of UM oplocks is in SDK:

C:\Program Files\Microsoft SDKs\Windows\v7.1\Samples\winbase\io\Oplocks

Best regards,
Alexey Barabash

Thanks Tony and Alexey for the answers.

Several years ago I modified your FileTest tool to use oplocks for own test. Oplocks were granted.

You should have send me an e-mail, I would add the improvements into main code base :slight_smile:
Well, oplocks are going to get added there now, as soon as I implement an elegant way for the asynchronous stuff that oplocks are tied to.

So maybe something is wrong with CreateFile flags, overlapped for example.

No, but as I found, there is something wrong with the NtDeviceIoControlFile. It is NtFsControlFile that needs to be used for granting an oplock :slight_smile:

BTW, can I send a FSCTL to break my own oplock? Or must someone else to do it by CreateFile on that file?

Oplocks are typically broken via an unrelated operation: create or write. So I suspect it would require two copies of FileTest running (or alternatively, the ability to open multiple files within it).

Tony
OSR

Ok. New build of FileTest (2.6.0.468) is available. Sources on GitHub updated.

Changes:

  • Added support for testing oplocks
  • Added context menu to NtCreate page for quick selection of create options
  • Added “About” dialog
  • Added generic support for asynchronous, long-to-complete requests

Outstanding.

Thank you sir.

Mm
On Sep 12, 2014 11:26 PM, wrote:

> Ok. New build of FileTest (2.6.0.468) is available. Sources on GitHub
> updated.
>
> Changes:
>
> - Added support for testing oplocks
> - Added context menu to NtCreate page for quick selection of create
> options
> - Added “About” dialog
> - Added generic support for asynchronous, long-to-complete requests
>
>
> —
> NTFSD is sponsored by OSR
>
> OSR is hiring!! Info at http://www.osr.com/careers
>
> For our schedule of debugging and file system seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

+1
“Martin O’Brien” wrote in message news:xxxxx@ntfsd…
Outstanding.

Thank you sir.

Mm