How to properly register a completion routine for an internal device control request?

I’m currently writing a lower filter disk driver to capture SCSI commands, and to measure the performance of each command. Currently, my driver is capable of capturing the SCSI request, and passing it down to the next driver. However, when I tried to register a completion routine, I get the following status: 0xc0000010(STATUS_INVALID_DEVICE_REQUEST).

Below is the working code without completion routine:

WDF_REQUEST_SEND_OPTIONS_INIT(&options, WDF_REQUEST_SEND_OPTION_SEND_AND_FORGET);
WdfRequestSend(Request, Target, &options);

Below is the failing code with completion routine:

WdfRequestFormatRequestUsingCurrentType(Request);
WdfRequestSetCompletionRoutine(Request, CompletionRoutine, CompletionContext);
WdfRequestSend(Request, Target, WDF_NO_SEND_OPTIONS);

NOTES:

  • WdfRequestSend() is the failing routine that returns STATUS_INVALID_DEVICE_REQUEST.
  • The code with the completion routine works when used in an upper filter disk driver.

Any help would be appreciated. Thanks.

You can try getting wdf logs for your driver using wdfkd

Read more on WDF_REQUEST_SEND_OPTION_SEND_AND_FORGET usage.

xxxxx@broadcom.com wrote:

Read more on WDF_REQUEST_SEND_OPTION_SEND_AND_FORGET usage.

Note that he included TWO code snippets: the one that worked, which
used SEND_AND_FORGET, and the one that didn’t, which used a completion
routine and did not set SEND_AND_FORGET.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Thank you everyone for your comments. I think I found the root caused for this issue, and a work around.

Root cause: The CompletionRoutine cannot be NULL for a lower disk filter.

Work around: Use the WDF_REQUEST_SEND_OPTION_SEND_AND_FORGET option when the CompletionRoutine is NULL.

Additional questions:

  1. Why does the upper disk filter not have this issue?
  2. Does it have anything to do with upper and lower filter, or is it specific to internal device control request?
  3. Is this issue specific to disk filter driver? I could answer this question myself through experimentation, but I was just curious if anyone have done the experiment.

xxxxx@gmail.com wrote:

Thank you everyone for your comments. I think I found the root caused for this issue, and a work around.

Root cause: The CompletionRoutine cannot be NULL for a lower disk filter.

Work around: Use the WDF_REQUEST_SEND_OPTION_SEND_AND_FORGET option when the CompletionRoutine is NULL.

Right. You basically have three choices:

  1. Set a completion routine, and call WdfRequestComplete there
  2. Use WDF_REQUEST_SEND_OPTION_SYNCHRONOUS, complete after WdfRequestSend
  3. Use WDF_REQUEST_SEND_OPTION_SEND_AND_FORGET

Additional questions:

  1. Why does the upper disk filter not have this issue?
  2. Does it have anything to do with upper and lower filter, or is it specific to internal device control request?
  3. Is this issue specific to disk filter driver?

The issue has to do with the request completion rules, which you were
not following.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

WdfRequestWdmFormatUsingStackLocation will let you to set a completion routine by WdfRequestSetCompletionRoutine. WdfRequestFormatRequestUsingCurrentType may not allow that.

WdfRequestFormatRequestUsingCurrentType allows you to set a CR

Sent from Outlook Mailhttp: for Windows 10

From: xxxxx@broadcom.com
Sent: Friday, June 19, 2015 3:14 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] How to properly register a completion routine for an internal device control request?

WdfRequestWdmFormatUsingStackLocation will let you to set a completion routine by WdfRequestSetCompletionRoutine. WdfRequestFormatRequestUsingCurrentType may not allow that.


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

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</http:>

I think Tim’s right. “The issue has to do with the request completion rule.” I wasn’t following the rule, and it just happened to work for my upper filter. In other words, I was asking all the wrong questions. Everything works great now. Thanks everyone.