KMDF upper filter and completing i/o requests...

I have a KMDF filter driver that is installed as an upper filter for
the disk class. I’m TRYING to complete a specific read request and
prevent it from continuing down the stack. My code isn’t generating
any errors but is IS NOT completing the request. The request still
flows down the stack to the disk. In my read event code I get the
output buffer, populated it, and then attempt to complete the request.

What am I doing wrong here? Why does the request continue to head
down the stack?

code snippet

NTSTATUS status = WdfRequestRetrieveOutputBuffer(Request, Length,
(PVOID *)&OutputDataBuffer, &OutputDataBufferSize);

WdfRequestFormatRequestUsingCurrentType(Request);
WdfRequestCompleteWithInformation(Request, STATUS_SUCCESS, Length);

Is there more to completing the request or less? Does the call to
WdfRequestFormatRequestUsingCurrentType imply some later behavior?
I’m stumped. I hate the idea of having to rewrite this thing in the
non-KMDF world but I’m getting to that point…

I’m feeling both naive and stupid at the moment…

TIA,
Robert.

Robert Randall | xxxxx@gmail.com

WdfRequestFormatRequestUsingCurrentType(Request); is not what you want, that is only for sending the request down the stack or somewhere else. Where are you filling in OutputDataBuffer? Where is Length coming from? Did WdfRequestRetrieveOutputBuffer return success?

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Robert Randall
Sent: Friday, May 28, 2010 9:46 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] KMDF upper filter and completing i/o requests…

I have a KMDF filter driver that is installed as an upper filter for the disk class. I’m TRYING to complete a specific read request and prevent it from continuing down the stack. My code isn’t generating any errors but is IS NOT completing the request. The request still flows down the stack to the disk. In my read event code I get the output buffer, populated it, and then attempt to complete the request.

What am I doing wrong here? Why does the request continue to head down the stack?

code snippet

NTSTATUS status = WdfRequestRetrieveOutputBuffer(Request, Length, (PVOID *)&OutputDataBuffer, &OutputDataBufferSize);

WdfRequestFormatRequestUsingCurrentType(Request);
WdfRequestCompleteWithInformation(Request, STATUS_SUCCESS, Length);

Is there more to completing the request or less? Does the call to WdfRequestFormatRequestUsingCurrentType imply some later behavior?
I’m stumped. I hate the idea of having to rewrite this thing in the non-KMDF world but I’m getting to that point…

I’m feeling both naive and stupid at the moment…

TIA,
Robert.

Robert Randall | xxxxx@gmail.com


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other 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

WdfRequestRetrieveOutputBuffer does return success and I populate the
buffer shortly after that in the code. I simply write to the pointer
returned by the WdfRequestRetrieveOutputBuffer. That seems to work
fine and doesn’t cause any troubles. The Length is coming in as part
of the args passed into the event
dispatch routine. I compare it to the length returned from
WdfRequestRetrieveOutputBuffer to verify that they are the same (and
they are).

I’ve tried removing the call to
WdfRequestFormatRequestUsingCurrentType and calling WdfRequestComplete
and passing a STATUS_SUCCESS.

Still no luck. No BSOD, no indication of a problem but I can still
see the I/O flowing down the stack to the disk.

-Robert.

On Fri, May 28, 2010 at 12:05 PM, Doron Holan wrote:
> ? ?WdfRequestFormatRequestUsingCurrentType(Request); is not what you want, that is only for sending the request down the stack or somewhere else. ?Where are you filling in OutputDataBuffer? ?Where is Length coming from? ?Did WdfRequestRetrieveOutputBuffer return success?
>
> -----Original Message-----
> From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Robert Randall
> Sent: Friday, May 28, 2010 9:46 AM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] KMDF upper filter and completing i/o requests…
>
> I have a KMDF filter driver that is installed as an upper filter for the disk class. ?I’m TRYING to complete a specific read request and prevent it from continuing down the stack. ?My code isn’t generating any errors but is IS NOT completing the request. ?The request still flows down the stack to the disk. ?In my read event code I get the output buffer, populated it, and then attempt to complete the request.
>
> What am I doing wrong here? ?Why does the request continue to head down the stack?
>
> code snippet
>
> ? ?NTSTATUS ?status = WdfRequestRetrieveOutputBuffer(Request, Length, (PVOID *)&OutputDataBuffer, &OutputDataBufferSize);
>
> ? ?WdfRequestFormatRequestUsingCurrentType(Request);
> ? ?WdfRequestCompleteWithInformation(Request, STATUS_SUCCESS, Length);
>
> Is there more to completing the request or less? ?Does the call to WdfRequestFormatRequestUsingCurrentType imply some later behavior?
> I’m stumped. ?I hate the idea of having to rewrite this thing in the non-KMDF world but I’m getting to that point…
>
> I’m feeling both naive and stupid at the moment…
>
> TIA,
> Robert.
> –
> Robert Randall | xxxxx@gmail.com
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other 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
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other 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
>


Robert Randall | xxxxx@gmail.com

Do you return after the WdfRequestComplete or do you continue executing in the io dispatch routine and that happens to also send the request down the stack?

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Robert Randall
Sent: Friday, May 28, 2010 10:23 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] KMDF upper filter and completing i/o requests…

WdfRequestRetrieveOutputBuffer does return success and I populate the buffer shortly after that in the code. I simply write to the pointer returned by the WdfRequestRetrieveOutputBuffer. That seems to work fine and doesn’t cause any troubles. The Length is coming in as part of the args passed into the event dispatch routine. I compare it to the length returned from WdfRequestRetrieveOutputBuffer to verify that they are the same (and they are).

I’ve tried removing the call to
WdfRequestFormatRequestUsingCurrentType and calling WdfRequestComplete and passing a STATUS_SUCCESS.

Still no luck. No BSOD, no indication of a problem but I can still see the I/O flowing down the stack to the disk.

-Robert.

On Fri, May 28, 2010 at 12:05 PM, Doron Holan wrote:
> ? ?WdfRequestFormatRequestUsingCurrentType(Request); is not what you want, that is only for sending the request down the stack or somewhere else. ?Where are you filling in OutputDataBuffer? ?Where is Length coming from? ?Did WdfRequestRetrieveOutputBuffer return success?
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Robert Randall
> Sent: Friday, May 28, 2010 9:46 AM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] KMDF upper filter and completing i/o requests…
>
> I have a KMDF filter driver that is installed as an upper filter for the disk class. ?I’m TRYING to complete a specific read request and prevent it from continuing down the stack. ?My code isn’t generating any errors but is IS NOT completing the request. ?The request still flows down the stack to the disk. ?In my read event code I get the output buffer, populated it, and then attempt to complete the request.
>
> What am I doing wrong here? ?Why does the request continue to head down the stack?
>
> code snippet
>
> ? ?NTSTATUS ?status = WdfRequestRetrieveOutputBuffer(Request, Length,
> (PVOID *)&OutputDataBuffer, &OutputDataBufferSize);
>
> ? ?WdfRequestFormatRequestUsingCurrentType(Request);
> ? ?WdfRequestCompleteWithInformation(Request, STATUS_SUCCESS, Length);
>
> Is there more to completing the request or less? ?Does the call to WdfRequestFormatRequestUsingCurrentType imply some later behavior?
> I’m stumped. ?I hate the idea of having to rewrite this thing in the non-KMDF world but I’m getting to that point…
>
> I’m feeling both naive and stupid at the moment…
>
> TIA,
> Robert.
> –
> Robert Randall | xxxxx@gmail.com
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other 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
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other 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
>


Robert Randall | xxxxx@gmail.com


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other 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

I return and get out of the routine.

On Fri, May 28, 2010 at 12:39 PM, Doron Holan wrote:
> Do you return after the WdfRequestComplete or do you continue executing in the io dispatch routine and that happens to also send the request down the stack?
>
> d
>
> -----Original Message-----
> From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Robert Randall
> Sent: Friday, May 28, 2010 10:23 AM
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] KMDF upper filter and completing i/o requests…
>
> WdfRequestRetrieveOutputBuffer does return success and I populate the buffer shortly after that in the code. ?I simply write to the pointer returned by the WdfRequestRetrieveOutputBuffer. ?That seems to work fine and doesn’t cause any troubles. ?The Length is coming in as part of the args passed into the event dispatch routine. ?I compare it to the length returned from WdfRequestRetrieveOutputBuffer to verify that they are the same (and they are).
>
> I’ve tried removing the call to
> WdfRequestFormatRequestUsingCurrentType and calling WdfRequestComplete and passing a STATUS_SUCCESS.
>
> Still no luck. ?No BSOD, no indication of a problem but I can still see the I/O flowing down the stack to the disk.
>
> -Robert.
>
>
> On Fri, May 28, 2010 at 12:05 PM, Doron Holan wrote:
>> ? ?WdfRequestFormatRequestUsingCurrentType(Request); is not what you want, that is only for sending the request down the stack or somewhere else. ?Where are you filling in OutputDataBuffer? ?Where is Length coming from? ?Did WdfRequestRetrieveOutputBuffer return success?
>>
>> -----Original Message-----
>> From: xxxxx@lists.osr.com
>> [mailto:xxxxx@lists.osr.com] On Behalf Of Robert Randall
>> Sent: Friday, May 28, 2010 9:46 AM
>> To: Windows System Software Devs Interest List
>> Subject: [ntdev] KMDF upper filter and completing i/o requests…
>>
>> I have a KMDF filter driver that is installed as an upper filter for the disk class. ?I’m TRYING to complete a specific read request and prevent it from continuing down the stack. ?My code isn’t generating any errors but is IS NOT completing the request. ?The request still flows down the stack to the disk. ?In my read event code I get the output buffer, populated it, and then attempt to complete the request.
>>
>> What am I doing wrong here? ?Why does the request continue to head down the stack?
>>
>> code snippet
>>
>> ? ?NTSTATUS ?status = WdfRequestRetrieveOutputBuffer(Request, Length,
>> (PVOID *)&OutputDataBuffer, &OutputDataBufferSize);
>>
>> ? ?WdfRequestFormatRequestUsingCurrentType(Request);
>> ? ?WdfRequestCompleteWithInformation(Request, STATUS_SUCCESS, Length);
>>
>> Is there more to completing the request or less? ?Does the call to WdfRequestFormatRequestUsingCurrentType imply some later behavior?
>> I’m stumped. ?I hate the idea of having to rewrite this thing in the non-KMDF world but I’m getting to that point…
>>
>> I’m feeling both naive and stupid at the moment…
>>
>> TIA,
>> Robert.
>> –
>> Robert Randall | xxxxx@gmail.com
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> For our schedule of WDF, WDM, debugging and other 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
>>
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> For our schedule of WDF, WDM, debugging and other 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
>>
>
>
>
> –
> Robert Randall | xxxxx@gmail.com
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other 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
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other 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
>


Robert Randall | xxxxx@gmail.com

No need to re-write this in the non-KMDF world. Believe me… if you can’t get it work in KMDF, you’re sooooo totally not going to get it to work in WDM.

For most things, WdfRequestComplete is really a pretty thing wrapper around IoCompleteRequest. If it’s not failing, it really HAS to be completing the request. Seriously.

Watch the IRPs in IrpTracker, or something similar that identifies the IRP instance, not just the IRP by the address of the IRP (note that IRP structures are very frequently cached and re-used).

Ensure that you’ve got KMDF verifier turned on, as well as Windows Driver Verifier.

Dump the In Flight Recorder log from KMDF and see what’s going on… that might help.

As a last resort, walk a ways into WdfRequetComplete. This can be annoying (because KMDF is written in C++) but it’s not quite as bad as you might think.

Just some ideas,

Peter
OSR

Thanks. I’ve repaired one problem and now I’m testing again. I’ll
see how far I get.

I’ve never used the “In Flight Recorder” for KMDF. Can you point the
naive at the doc so I can RTFM :wink:

On Fri, May 28, 2010 at 2:05 PM, wrote:
> No need to re-write this in the non-KMDF world. ?Believe me… if you can’t get it work in KMDF, you’re sooooo totally not going to get it to work in WDM.
>
> For most things, WdfRequestComplete is really a pretty thing wrapper around IoCompleteRequest. ?If it’s not failing, it really HAS to be completing the request. ?Seriously.
>
> Watch the IRPs in IrpTracker, or something similar that identifies the IRP instance, not just the IRP by the address of the IRP (note that IRP structures are very frequently cached and re-used).
>
> Ensure that you’ve got KMDF verifier turned on, as well as Windows Driver Verifier.
>
> Dump the In Flight Recorder log from KMDF and see what’s going on… that might help.
>
> As a last resort, walk a ways into WdfRequetComplete. ?This can be annoying (because KMDF is written in C++) but it’s not quite as bad as you might think.
>
> Just some ideas,
>
> Peter
> OSR
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other 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
>


Robert Randall | xxxxx@gmail.com

>I’ve never used the “In Flight Recorder” for KMDF.

Look at WinDbg docs related to KMDF.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

IFR, and a few other important KMDF hints:

http://www.osronline.com/article.cfm?article=496

Peter
OSR

Thanks for all of the feedback. My driver is now completing requests
properly and things appear to be working fine. BUT I still get a failure
when I try to format the disk that is beneath my upper filter. The driver
is processing read and write events and it does not register an event
callback for anything else. An hints would be appreciated.

-Robert.

On May 28, 2010, at 9:20 PM, xxxxx@osr.com wrote:

IFR, and a few other important KMDF hints:

http://www.osronline.com/article.cfm?article=496

Peter
OSR


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other 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