irp_mj_create cancellation

My file system driver hands off requests, including IRP_MJ_CREATE, to a user
space process and marks them pending. I support cancellation on these
requests, but it would appear that Windows XP simply doesn’t bother trying
to cancel them. This was fairly confusing until I finally stumbled on some
references talking about how Vista added support for IRP_MJ_CREATE
cancellation: http://www.microsoft.com/whdc/driver/kernel/iocancel.mspx
Questions:

  1. Is there a particular reason why IRP_MJ_CREATE cancellation functions
    aren’t called on earlier OSs? Is there any more detailed explanation of
    what exactly was changed here in Vista?
  2. If I do want to support cancellation of CREATE requests on earlier OS’s,
    I suppose I have to use


Matt Craighead
Founder/CEO, Conifer Systems LLC
http://www.conifersystems.com
512-772-1834

My apologies, I hit send too early. That should have been:

  1. If I do want to support cancellation of CREATE requests on earlier,
    non-Vista OS’s, I suppose I have to use a KTIMER and implement my own
    timeouts on creates? Of course this begs the question of how long a timeout
    I should pick…

On Tue, Sep 16, 2008 at 5:13 PM, Matt Craighead <
xxxxx@conifersystems.com> wrote:

My file system driver hands off requests, including IRP_MJ_CREATE, to a
user space process and marks them pending. I support cancellation on these
requests, but it would appear that Windows XP simply doesn’t bother trying
to cancel them. This was fairly confusing until I finally stumbled on some
references talking about how Vista added support for IRP_MJ_CREATE
cancellation: http://www.microsoft.com/whdc/driver/kernel/iocancel.mspx
Questions:

  1. Is there a particular reason why IRP_MJ_CREATE cancellation functions
    aren’t called on earlier OSs? Is there any more detailed explanation of
    what exactly was changed here in Vista?
  2. If I do want to support cancellation of CREATE requests on earlier OS’s,
    I suppose I have to use


Matt Craighead
Founder/CEO, Conifer Systems LLC
http://www.conifersystems.com
512-772-1834


Matt Craighead
Founder/CEO, Conifer Systems LLC
http://www.conifersystems.com
512-772-1834

You may find that if you return pending, some filters may not be able to handle that on creates. I hope most are fixed now, but I think I remember having some problems with that in earlier OS versions.

I would say that for most cases anything over a few seconds would be excessive but definitely any wait measured in minutes would cause problems. I also assume you can handle creates while the system is booting so you won’t have to wait for the user subsystem to become available.

“Matt Craighead” wrote in message news:xxxxx@ntfsd…
My apologies, I hit send too early. That should have been:

2. If I do want to support cancellation of CREATE requests on earlier, non-Vista OS’s, I suppose I have to use a KTIMER and implement my own timeouts on creates? Of course this begs the question of how long a timeout I should pick…

On Tue, Sep 16, 2008 at 5:13 PM, Matt Craighead wrote:

My file system driver hands off requests, including IRP_MJ_CREATE, to a user space process and marks them pending. I support cancellation on these requests, but it would appear that Windows XP simply doesn’t bother trying to cancel them. This was fairly confusing until I finally stumbled on some references talking about how Vista added support for IRP_MJ_CREATE cancellation: http://www.microsoft.com/whdc/driver/kernel/iocancel.mspx

Questions:

1. Is there a particular reason why IRP_MJ_CREATE cancellation functions aren’t called on earlier OSs? Is there any more detailed explanation of what exactly was changed here in Vista?
2. If I do want to support cancellation of CREATE requests on earlier OS’s, I suppose I have to use


Matt Craighead
Founder/CEO, Conifer Systems LLC
http://www.conifersystems.com
512-772-1834


Matt Craighead
Founder/CEO, Conifer Systems LLC
http://www.conifersystems.com
512-772-1834

If the service isn’t running, I just fail the creates. That’s easy. Also,
I shouldn’t be getting creates at that point anyway, because it’s the
service that is responsible for mapping the FSD to a drive letter.

It’s not clear to me that there is any way to get around returning PENDING
on a CREATE. Not only do I have to hand off the request to user space, but
I might also have to open a socket, wait for a reply from a server, etc.
It’s rather unfortunate that CREATE is the one IRP they chose not to do
cancellation on, because CREATE is one of the more likely IRPs to take
user-perceptible time in my implementation – sometimes it will be
instantaneous, sometimes it might legitimately need to wait for a long
time. Not being able to kill processes that are waiting on a CREATE is
troubling, while arbitrarily timing out long CREATEs could cause problems,
too.

I’ve never liked putting hardcoded timeouts in driver code for precisely
this reason: I’m not qualified to make the “what is an acceptable timeout”
decision on behalf of the user…

On Tue, Sep 16, 2008 at 7:00 PM, David Craig wrote:

> You may find that if you return pending, some filters may not be able to
> handle that on creates. I hope most are fixed now, but I think I remember
> having some problems with that in earlier OS versions.
>
> I would say that for most cases anything over a few seconds would be
> excessive but definitely any wait measured in minutes would cause problems.
> I also assume you can handle creates while the system is booting so you
> won’t have to wait for the user subsystem to become available.
>
>
> “Matt Craighead” wrote in message
> news:xxxxx@ntfsd…
> My apologies, I hit send too early. That should have been:
>
> 2. If I do want to support cancellation of CREATE requests on earlier,
> non-Vista OS’s, I suppose I have to use a KTIMER and implement my own
> timeouts on creates? Of course this begs the question of how long a timeout
> I should pick…
>
> On Tue, Sep 16, 2008 at 5:13 PM, Matt Craighead <
> xxxxx@conifersystems.com> wrote:
>
>> My file system driver hands off requests, including IRP_MJ_CREATE, to a
>> user space process and marks them pending. I support cancellation on these
>> requests, but it would appear that Windows XP simply doesn’t bother trying
>> to cancel them. This was fairly confusing until I finally stumbled on some
>> references talking about how Vista added support for IRP_MJ_CREATE
>> cancellation: http://www.microsoft.com/whdc/driver/kernel/iocancel.mspx
>> Questions:
>>
>> 1. Is there a particular reason why IRP_MJ_CREATE cancellation functions
>> aren’t called on earlier OSs? Is there any more detailed explanation of
>> what exactly was changed here in Vista?
>> 2. If I do want to support cancellation of CREATE requests on earlier
>> OS’s, I suppose I have to use
>>
>> –
>> Matt Craighead
>> Founder/CEO, Conifer Systems LLC
>> http://www.conifersystems.com
>> 512-772-1834
>>
>
>
>
> –
> Matt Craighead
> Founder/CEO, Conifer Systems LLC
> http://www.conifersystems.com
> 512-772-1834
>
>
> —
> NTFSD is sponsored by OSR
>
> For our schedule debugging and file system seminars
> (including our new fs mini-filter seminar) visit:
> http://www.osr.com/seminars
>
> You are currently subscribed to ntfsd as: unknown lmsubst tag argument: ‘’
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>


Matt Craighead
Founder/CEO, Conifer Systems LLC
http://www.conifersystems.com
512-772-1834

You could have a default timeout in the driver but allow your application to modify it when it decides your driver has something to do. In earlier versions of Windows, it was understandable that not allowing pending returns for creates was the best solution. I remember the days of a mainframe Sperry 1100/60 where the internal executive routine ‘fimain’ was not reentrant. They had been working on making it reentrant for decades, but a safe solution eluded them. The same issues occured in Windows in that the create IRP could cause massive changes in memory with the CacheManager and MemoryManager having to allocate memory for structures and read ahead buffers. All Windows subsystems could not use the file object until it was initialized completely by the FSD since the link to the specific file was not available until the FSD had completed it. With antivirus and antispam filesysem filters, the file may have required extensive reading and analysis before it could be allowed to complete. Also the win32 subsystem did not try and use the file object until it was prepared by the FSD as it had no way to permit an overlapped create. I believe that even with Vista the win32 subsystem won’t allow the calling program’s thread to proceed until the status of the create is available. Another issue to consider is off-line files where a file must be restored from external storage media, usually tape or infrequently optical.

I do suspect that it was a significant modification to the IoManager and FSDs to allow creates to return pending without blocking. During much of the early Windows NT days, the filesystem stack was very undocumented and the IFS Kit ($1000) was not initially released until NT4. Even IoCancelFileOpen was very buggy in early implementations since it could not handle a file object where caching had been initialized during the create request. Of all the things in Windows keeping the filesystem stack stable was a must. I suspect when filesystem filters appeared there were so many variations in how they handled their processing, it inhibited some improvements to the filesystem stack. There may have been some communications issues with other groups at Microsoft dealing with the many various storage stacks from disk.sys, cdrom.sys, flpydisk.sys, and the network redirectors. I once wrote a storage driver that took media with files on it in a foreign format and mapped it into a FAT volume. I do know that when floppy.sys from NT4 was modified into flpydisk.sys and fdc.sys there was little expertise in the storage group for this driver and Microsoft went to outside consultants to get it done. It was done to support floppy controller based tape drives that mostly disappeared shortly (a year or two) thereafter.

“Matt Craighead” wrote in message news:xxxxx@ntfsd…
If the service isn’t running, I just fail the creates. That’s easy. Also, I shouldn’t be getting creates at that point anyway, because it’s the service that is responsible for mapping the FSD to a drive letter.

It’s not clear to me that there is any way to get around returning PENDING on a CREATE. Not only do I have to hand off the request to user space, but I might also have to open a socket, wait for a reply from a server, etc. It’s rather unfortunate that CREATE is the one IRP they chose not to do cancellation on, because CREATE is one of the more likely IRPs to take user-perceptible time in my implementation – sometimes it will be instantaneous, sometimes it might legitimately need to wait for a long time. Not being able to kill processes that are waiting on a CREATE is troubling, while arbitrarily timing out long CREATEs could cause problems, too.

I’ve never liked putting hardcoded timeouts in driver code for precisely this reason: I’m not qualified to make the “what is an acceptable timeout” decision on behalf of the user…

On Tue, Sep 16, 2008 at 7:00 PM, David Craig wrote:

You may find that if you return pending, some filters may not be able to handle that on creates. I hope most are fixed now, but I think I remember having some problems with that in earlier OS versions.

I would say that for most cases anything over a few seconds would be excessive but definitely any wait measured in minutes would cause problems. I also assume you can handle creates while the system is booting so you won’t have to wait for the user subsystem to become available.

“Matt Craighead” wrote in message news:xxxxx@ntfsd…
My apologies, I hit send too early. That should have been:

2. If I do want to support cancellation of CREATE requests on earlier, non-Vista OS’s, I suppose I have to use a KTIMER and implement my own timeouts on creates? Of course this begs the question of how long a timeout I should pick…

On Tue, Sep 16, 2008 at 5:13 PM, Matt Craighead wrote:

My file system driver hands off requests, including IRP_MJ_CREATE, to a user space process and marks them pending. I support cancellation on these requests, but it would appear that Windows XP simply doesn’t bother trying to cancel them. This was fairly confusing until I finally stumbled on some references talking about how Vista added support for IRP_MJ_CREATE cancellation: http://www.microsoft.com/whdc/driver/kernel/iocancel.mspx

Questions:

1. Is there a particular reason why IRP_MJ_CREATE cancellation functions aren’t called on earlier OSs? Is there any more detailed explanation of what exactly was changed here in Vista?
2. If I do want to support cancellation of CREATE requests on earlier OS’s, I suppose I have to use


Matt Craighead
Founder/CEO, Conifer Systems LLC
http://www.conifersystems.com
512-772-1834


Matt Craighead
Founder/CEO, Conifer Systems LLC
http://www.conifersystems.com
512-772-1834


NTFSD is sponsored by OSR

For our schedule debugging and file system seminars
(including our new fs mini-filter seminar) visit:
http://www.osr.com/seminars

You are currently subscribed to ntfsd as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Matt Craighead
Founder/CEO, Conifer Systems LLC
http://www.conifersystems.com
512-772-1834

Any filter that doesn’t handle STATUS_PENDING from IRP_MJ_CREATE is
broken. In earlier OS versions there are cases in which FAT and NTFS
will return STATUS_PENDING. It doesn’t happen *often* but it does
happen. Thus, they are broken. I’ve fought this fight before.

The problem/issue is that none of the file systems supported
interruptable waits (nor did the I/O Manager as I recall.) But that is
not the same as saying “IRP_MJ_CREATE had to be synchronous.” A driver
is allowed to return STATUS_PENDING to any request, the caller is free
to block and wait if they wish to do so (and previously, they did.)

Tony

OSR

> A driver is allowed to return STATUS_PENDING to any request

Except for IRP_MJ_CLOSE, right? (I would also think it would be unwise at
best to mark an IRP_MJ_CLEANUP pending, or to fail either one of these
IRPs.)

On Wed, Sep 17, 2008 at 9:51 PM, Tony Mason wrote:

> Any filter that doesn’t handle STATUS_PENDING from IRP_MJ_CREATE is
> broken. In earlier OS versions there are cases in which FAT and NTFS will
> return STATUS_PENDING. It doesn’t happen often but it does happen.
> Thus, they are broken. I’ve fought this fight before.
>
>
>
> The problem/issue is that none of the file systems supported interruptable
> waits (nor did the I/O Manager as I recall.) But that is not the same as
> saying “IRP_MJ_CREATE had to be synchronous.” A driver is allowed to
> return STATUS_PENDING to any request, the caller is free to block and wait
> if they wish to do so (and previously, they did.)
>
>
>
> Tony
>
> OSR
>
>
>
> —
> NTFSD is sponsored by OSR
>
> For our schedule debugging and file system seminars
> (including our new fs mini-filter seminar) visit:
> http://www.osr.com/seminars
>
> You are currently subscribed to ntfsd as: unknown lmsubst tag argument: ‘’
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>


Matt Craighead
Founder/CEO, Conifer Systems LLC
http://www.conifersystems.com
512-772-1834

Let me restate it then: “A driver is allowed to return STATUS_PENDING to
any request. There are no exceptions to this rule.” What the caller
does with STATUS_PENDING might depend upon the specific circumstances.

My experience is that most applications do not properly handle a failure
from NtClose, but that does not mean a driver has some restriction here,
except “conform or break applications.” But that is a far more general
“rule” that has nothing to do with the fundamental model Windows NT had
of a pure asynchronous I/O subsystem. Synchronous I/O is an
afterthought. Sadly, some OS platforms only provide synchronous I/O and
then force drivers (and users) to utilize cumbersome mechanisms (e.g.,
thread pools, select calls) to process asynchronous operations.

Tony

OSR

Hi,
I used to handle failure of NtClose (CloseHandle). But i just log and ignore that. Later just ignore (since win 2000). Is there any other proper way to handle failure of close?

Jan
“Tony Mason” wrote in message news:xxxxx@ntfsd…
Let me restate it then: “A driver is allowed to return STATUS_PENDING to any request. There are no exceptions to this rule.” What the caller does with STATUS_PENDING might depend upon the specific circumstances.

My experience is that most applications do not properly handle a failure from NtClose, but that does not mean a driver has some restriction here, except “conform or break applications.” But that is a far more general “rule” that has nothing to do with the fundamental model Windows NT had of a pure asynchronous I/O subsystem. Synchronous I/O is an afterthought. Sadly, some OS platforms only provide synchronous I/O and then force drivers (and users) to utilize cumbersome mechanisms (e.g., thread pools, select calls) to process asynchronous operations.

Tony

OSR

>My experience is that most applications do not properly handle a failure

from NtClose, but that does not mean a driver has some restriction here,
except “conform or break applications.”
IIRC the result of IRP_MJ_CLEANUP is not delegated from Object Manager, because callback for close doesn’t return NTSTATUS but void. It means that if driver returns any error from IRP_MJ_CLEANUP or/and IRP_MJ_CLOSE the native API and win32 API don’t get it.

-bg

>I used to handle failure of NtClose (CloseHandle). But i just log and ignore

that. Later just ignore (since win 2000). Is there any other proper way to
handle failure of close?

Because of the fact that I have described in previous post, you will get only Object Manager’s errors, which can inform you that e.g. handle is invalid. You cannot get an I/O like error. That’s because of two facts. One of them is lazy writer. The second fact is that NtClose() invokes IRP_MJ_CLEANUP and mostly but not always IRP_MJ_CLOSE, but during cleanup the file might not be complete. Paging writes from mapped/cached file might come after IRP_MJ_CLEANUP but before IRP_MJ_CLOSE.

-bg

I am curious as to what you think would be a sane way to handle NtClose failing in a realistic scenario?

IMO, resource release calls must never fail except if the caller has a bug - and this means that all memory/other resources needed to close a particular resource must be preallocated, as a general design principle.

  • S

From: Tony Mason
Sent: Thursday, September 18, 2008 00:46
To: Windows File Systems Devs Interest List
Subject: RE: [ntfsd] irp_mj_create cancellation

Let me restate it then: ?A driver is allowed to return STATUS_PENDING to any request. There are no exceptions to this rule.? What the caller does with STATUS_PENDING might depend upon the specific circumstances.

My experience is that most applications do not properly handle a failure from NtClose, but that does not mean a driver has some restriction here, except ?conform or break applications.? But that is a far more general ?rule? that has nothing to do with the fundamental model Windows NT had of a pure asynchronous I/O subsystem. Synchronous I/O is an afterthought. Sadly, some OS platforms only provide synchronous I/O and then force drivers (and users) to utilize cumbersome mechanisms (e.g., thread pools, select calls) to process asynchronous operations.

Tony
OSR


NTFSD is sponsored by OSR

For our schedule debugging and file system seminars
(including our new fs mini-filter seminar) visit:
http://www.osr.com/seminars

You are currently subscribed to ntfsd as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

Agree – even if the system makes it theoretically possible to return
failure from a close or cleanup, if this ever actually happened in practice,
I would consider it exceedingly ill-behaved.

On Thu, Sep 18, 2008 at 9:07 AM, Skywing wrote:

> I am curious as to what you think would be a sane way to handle NtClose
> failing in a realistic scenario?
>
> IMO, resource release calls must never fail except if the caller has a bug
> - and this means that all memory/other resources needed to close a
> particular resource must be preallocated, as a general design principle.
>
> - S
>
> ------------------------------
> From: Tony Mason
> Sent: Thursday, September 18, 2008 00:46
> To: Windows File Systems Devs Interest List
> Subject: RE: [ntfsd] irp_mj_create cancellation
>
> Let me restate it then: “A driver is allowed to return STATUS_PENDING to
> any request. There are no exceptions to this rule.” What the caller does
> with STATUS_PENDING might depend upon the specific circumstances.
>
>
>
> My experience is that most applications do not properly handle a failure
> from NtClose, but that does not mean a driver has some restriction here,
> except “conform or break applications.” But that is a far more general
> “rule” that has nothing to do with the fundamental model Windows NT had of a
> pure asynchronous I/O subsystem. Synchronous I/O is an afterthought.
> Sadly, some OS platforms only provide synchronous I/O and then force drivers
> (and users) to utilize cumbersome mechanisms (e.g., thread pools, select
> calls) to process asynchronous operations.
>
>
>
> Tony
>
> OSR
>
>
>
> —
> NTFSD is sponsored by OSR
>
> For our schedule debugging and file system seminars
> (including our new fs mini-filter seminar) visit:
> http://www.osr.com/seminars
>
> You are currently subscribed to ntfsd as: unknown lmsubst tag argument: ‘’
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
> —
> NTFSD is sponsored by OSR
>
> For our schedule debugging and file system seminars
> (including our new fs mini-filter seminar) visit:
> http://www.osr.com/seminars
>
> You are currently subscribed to ntfsd as: unknown lmsubst tag argument: ‘’
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>


Matt Craighead
Founder/CEO, Conifer Systems LLC
http://www.conifersystems.com
512-772-1834