IOMarkIrpPending

Hi All,
I have a question about IoMarkIrpPending. From the DDK

" Unless an IRP’s dispatch routine completes the IRP (by calling IoCompleteRequestms-help:) or passes the IRP on to lower drivers, it must call IoMarkIrpPending with the IRP. Otherwise, the I/O manager attempts to complete the IRP as soon as the dispatch routine returns control."

Does this mean that if I do not mark the Irp as pending and return status pending, the IO Manager will try to complete it even if I have not completed the IRP with IoCompleteRequest.

I do not want a particular type of IRP to be cancellable because I have a timer which takes care of cancellation. So I am doing the following:-

1. NOT Call IoMarkIrpPending.

2. Call IoSetCancelRoutine with NULL as completion routine.

3. Return status pending right now. When timer calls process the IRP from queue.

Please advice .

– Ajitabh.</ms-help:>

Yes, this can happen.

As described in the documentation, this sequence is DEFINITELY wrong.

You need to call IoMarkIrpPending(…)

You need to read:
http://www.osronline.com/article.cfm?id=83

Peter
OSR

>Does this mean that if I do not mark the Irp as pending and return status pending, the IO Manager will

try to complete it even if I have not completed the IRP with IoCompleteRequest.

Allowed combinations:

  1. IoMarkIrpPending, then put the IRP to some context like queue where it will be pended, then “return STATUS_PENDING”

  2. Fill Irp->IoStatus, call IoCompleteRequest, return the same status code as was put to Irp->IoStatus.Status. Note that a) you cannot touch the IRP after IoCompleteRequest and b) you cannot put STATUS_PENDING to Irp->IoStatus.Status.

  3. “return IoCallDriver”, without ever calling IoMarkIrpPending.


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

>I do not want a particular type of IRP to be cancellable because I have a timer which takes care of

cancellation.

Bad idea. Cancellation support is to allow the OS to kill the thread/process which submitted the IRP. In your case, this killing will wait for your timer to fire.

So, I would suggest to have both cancellation and timer.

KMDF queues are the good thing for this.


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

Ajitabh Saxena wrote:

Hi All,
I have a question about IoMarkIrpPending. From the DDK

" Unless an IRP’s dispatch routine completes the IRP (by calling
*IoCompleteRequest*
ms-help:)
> or passes the IRP on to lower drivers, it must call IoMarkIrpPending
> with the IRP. Otherwise, the I/O manager attempts to complete the IRP
> as soon as the dispatch routine returns control."
>
> Does this mean that if I do not mark the Irp as pending and return
> status pending, the IO Manager will try to complete it even if I have
> not completed the IRP with IoCompleteRequest.
>
> I do not want a particular type of IRP to be cancellable because I
> have a timer which takes care of cancellation. So I am doing the
> following:-
>
> 1. NOT Call IoMarkIrpPending.
>
> 2. Call IoSetCancelRoutine with NULL as completion routine.
>
> 3. Return status pending right now. When timer calls process the IRP
> from queue.
>

If you don’t have a cancel handler, then your IRP will not be
cancellable, regardless of your pending manipulation. Remember, IRP
cancellation is just a “suggestion”. It is entirely up to the driver
that currently owns the IRP to decide whether it wants to pay attention
to that suggestion, or ignore it. An IRP is never forcibly canceled.

However, as Max said, it would be better for the overall operation of
your system if you found a way to allow your IRPs to be canceled.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.</ms-help:>

As Max and Tom mention it is a good design to provide a cancellation support for an Irp. For example,
an application which issue an Irp for some reasons tries terminates itself ( or by OS or an user) before the Irp is completed. The application could not be terminated completely until the issued Irp is completed. If the Irp would have a cancellation routine this routine will be called during termination of the application. The driver in Irp cancellation routine completes Irp and allow to terminate application. Otherwise, without an cancellation function, the application will be terminated only when some drivers actions or OS watchdog completes Irp. OS watchdog could trigger completion Irp in couple minutes which is long time for user experience.