Cancellation of IRP's

Hi all

I got some doubt about implementing Device Queue managed by driver and
cancellation of IRP’s . I have gone through the articles, documentation and
other Device driver books by Peter Viscorola and Walter Oney but I could not
find the information I am looking for . Hope somebody can help me.

I wanted to maintain a Device Queue for all IO requests that comes from the
Application . All IRP requests are sent to next level driver with completion
routine set . Here I am not setting any cancel routine and hoping to return
to completion routine in case of IRP cancel or success . Before sending the
requests to next level driver the IRP is queued in to Driver managed queue .

As per the DDk or any articles what I read , Any IRP that is queued
must be having a cancel routine and set IRP as Pending with
IoMarkIrpPending() call . As I said before in case of IRP failure I wanted
to return back to completion routine . The reason why I wanted to come back
to completion routine is to release the memory allocated for URB request and
context structure . I have no Idea how can I release this memory if I set a
cancel routine . I could not find any method to do it . though I am queueing
IRP into the Driver managed queue I am not setting the IRP as pending ,
because the IO manager can complete the request immediatley and calls the
Completion routine , in the completion routine if Pending flag is set then
that time I am marking the IRP as pending. Can I do this ?

When application is closed , the terminating thread issues DispatchCleanUp
call to clean the IRP’s that are pending . In the DispatchCleanUp routine ,
I wanted to clear all the pending IRP’s with out depending on IO Manager .
Since the IRP that are queued are generated by IO manager I cannot call
IoCancelIrp and I cannot complete the request because I needed to release
the context memory that is allocated for sending the request . How do we
need to tackle this situation ?

do we really need a IRP queue for the IRP’s generated by IO manager and
depend on IO manager cancellation of IRP’s for all Pending IRP’s ?

If not can anybody suggest me some good way of handling this ?

The articles what I read does not deal with the situation like context
memory for URB request . In the cancel routines the IRP is just completed
with STATUS_CANCELLED but never discussed about a situation like releasing
context memory allocated for URB structure .

Could anybody point me to some information or give me some idea of how to
implement what I needed .

Thanks in advance
srinivas


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

There was an MS note on IRP cancellation. Try to find it on MS’s site.
I will send you it by email if you will not find it on the MS’s web.

Max

----- Original Message -----
From: “Srinivasa Rao Deevi”
To: “NT Developers Interest List”
Sent: Saturday, September 01, 2001 1:12 AM
Subject: [ntdev] Cancellation of IRP’s

> Hi all
>
> I got some doubt about implementing Device Queue managed by driver and
> cancellation of IRP’s . I have gone through the articles, documentation
and
> other Device driver books by Peter Viscorola and Walter Oney but I could
not
> find the information I am looking for . Hope somebody can help me.
>
> I wanted to maintain a Device Queue for all IO requests that comes from
the
> Application . All IRP requests are sent to next level driver with
completion
> routine set . Here I am not setting any cancel routine and hoping to
return
> to completion routine in case of IRP cancel or success . Before sending
the
> requests to next level driver the IRP is queued in to Driver managed queue
.
>
> As per the DDk or any articles what I read , Any IRP that is queued
> must be having a cancel routine and set IRP as Pending with
> IoMarkIrpPending() call . As I said before in case of IRP failure I
wanted
> to return back to completion routine . The reason why I wanted to come
back
> to completion routine is to release the memory allocated for URB request
and
> context structure . I have no Idea how can I release this memory if I set
a
> cancel routine . I could not find any method to do it . though I am
queueing
> IRP into the Driver managed queue I am not setting the IRP as pending ,
> because the IO manager can complete the request immediatley and calls the
> Completion routine , in the completion routine if Pending flag is set then
> that time I am marking the IRP as pending. Can I do this ?
>
> When application is closed , the terminating thread issues DispatchCleanUp
> call to clean the IRP’s that are pending . In the DispatchCleanUp routine
,
> I wanted to clear all the pending IRP’s with out depending on IO Manager .
> Since the IRP that are queued are generated by IO manager I cannot call
> IoCancelIrp and I cannot complete the request because I needed to release
> the context memory that is allocated for sending the request . How do we
> need to tackle this situation ?
>
> do we really need a IRP queue for the IRP’s generated by IO manager and
> depend on IO manager cancellation of IRP’s for all Pending IRP’s ?
>
> If not can anybody suggest me some good way of handling this ?
>
> The articles what I read does not deal with the situation like context
> memory for URB request . In the cancel routines the IRP is just completed
> with STATUS_CANCELLED but never discussed about a situation like releasing
> context memory allocated for URB structure .
>
> Could anybody point me to some information or give me some idea of how to
> implement what I needed .
>
> Thanks in advance
> srinivas
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Hi all

Thanks for the reply Max.

I found the article on the web from Microsoft but it is not answering what I
am looking for . I hope you are refering the same site
http://support.microsoft.com/support/kb/articles/q120/1/71.asp

Thank you
srinivas

-----Original Message-----
From: Maxim S. Shatskih [mailto:xxxxx@storagecraft.com]
Sent: Saturday, September 01, 2001 4:06 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Cancellation of IRP’s

There was an MS note on IRP cancellation. Try to find it on MS’s site.
I will send you it by email if you will not find it on the MS’s web.

Max

----- Original Message -----
From: “Srinivasa Rao Deevi”
To: “NT Developers Interest List”
Sent: Saturday, September 01, 2001 1:12 AM
Subject: [ntdev] Cancellation of IRP’s

> Hi all
>
> I got some doubt about implementing Device Queue managed by driver and
> cancellation of IRP’s . I have gone through the articles, documentation
and
> other Device driver books by Peter Viscorola and Walter Oney but I could
not
> find the information I am looking for . Hope somebody can help me.
>
> I wanted to maintain a Device Queue for all IO requests that comes from
the
> Application . All IRP requests are sent to next level driver with
completion
> routine set . Here I am not setting any cancel routine and hoping to
return
> to completion routine in case of IRP cancel or success . Before sending
the
> requests to next level driver the IRP is queued in to Driver managed queue
.
>
> As per the DDk or any articles what I read , Any IRP that is queued
> must be having a cancel routine and set IRP as Pending with
> IoMarkIrpPending() call . As I said before in case of IRP failure I
wanted
> to return back to completion routine . The reason why I wanted to come
back
> to completion routine is to release the memory allocated for URB request
and
> context structure . I have no Idea how can I release this memory if I set
a
> cancel routine . I could not find any method to do it . though I am
queueing
> IRP into the Driver managed queue I am not setting the IRP as pending ,
> because the IO manager can complete the request immediatley and calls the
> Completion routine , in the completion routine if Pending flag is set then
> that time I am marking the IRP as pending. Can I do this ?
>
> When application is closed , the terminating thread issues DispatchCleanUp
> call to clean the IRP’s that are pending . In the DispatchCleanUp routine
,
> I wanted to clear all the pending IRP’s with out depending on IO Manager .
> Since the IRP that are queued are generated by IO manager I cannot call
> IoCancelIrp and I cannot complete the request because I needed to release
> the context memory that is allocated for sending the request . How do we
> need to tackle this situation ?
>
> do we really need a IRP queue for the IRP’s generated by IO manager and
> depend on IO manager cancellation of IRP’s for all Pending IRP’s ?
>
> If not can anybody suggest me some good way of handling this ?
>
> The articles what I read does not deal with the situation like context
> memory for URB request . In the cancel routines the IRP is just completed
> with STATUS_CANCELLED but never discussed about a situation like releasing
> context memory allocated for URB structure .
>
> Could anybody point me to some information or give me some idea of how to
> implement what I needed .
>
> Thanks in advance
> srinivas
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>


You are currently subscribed to ntdev as: xxxxx@transilica.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Hi Dan

Thank you verymuch for sending me the links . They are really useful . I
just want to know how to cancel an IRP at higer level with out cancel
routine and by using IoCompletion Routines with InvokeOnCancel Flag set to
TRUE. This is the article I found on Microsoft website. But this does not
mention about how to cancel the IRP’s at higher level with out depending on
termination of thread .

"
Synchronizing Cancellation in Higher-Level Drivers without Cancel Routines

A higher-level driver can make no assumptions about whether or how existing
lower-level drivers handle cancelable IRPs. As soon as any higher-level
driver calls IoCallDriver for an IRP, it no longer owns that IRP and it can
neither ascertain nor control processing of the IRP by lower-level drivers.

However, any higher-level driver can set an IoCompletion routine for an IRP
by calling IoSetCompletionRoutine before it calls IoCallDriver. The
higher-level driver can determine whether any pending IRP is canceled in a
lower driver by calling IoSetCompletionRoutine with the InvokeOnCancel
parameter set to TRUE before it passes the IRP on to lower drivers. Doing so
ensures that the driver’s IoCompletion routine will be called whether the
IRP is canceled or completed.

A higher-level driver can call IoCancelIrp with any pending IRP that the
driver has allocated. However, making this call does not ensure that the
driver-allocated IRP will be completed with its I/O status block set to
STATUS_CANCELLED; another thread might already be completing the IRP. To
check whether the IRP was canceled, the higher-level driver must call
IoSetCompletionRoutine with the InvokeOnCancel parameter set to TRUE before
passing the IRP on to the next lower driver. See Completing IRPs for more
information about completion routines.

A higher-level driver must not call IoCancelIrp with an IRP that it did not
allocate."

To cancel an IRP at higher level with out a cancel routine, I need to
terminate thread which inturn cancel’s the IRP ( since it is generated by it
)and the Completion routine set in the driver gets called which releases all
the context memory and completes the request .

I want to know is there any other way to cancel the pending IRP without
depending on thread termination .

Thanks in advance
srinivas

-----Original Message-----
From: Daniel E. Germann [mailto:xxxxx@nospam.visi.com]
Sent: Wednesday, September 05, 2001 6:16 AM
To: Srinivasa Rao Deevi
Subject: Re: Cancellation of IRP’s

Dear Srinivasa,

There was an article in the May-June 2001 issue of The NT Insider about IRP
handling and completion routines: “Properly Pending IRPs – IRP Handling For
the Rest of Us”. Unfortunately, it’s not available on the OSR website yet.
There are some other good articles available: “How NT Handles I/O
Completion”, “IRP Cancel Operations (parts I and II)” and “A New View on I/O
Cancellation”. They discuss IRP completion and cancellation in detail.
Perhaps some of the information in these articles will be helpful to you.

http://www.osr.com/ntinsider/1997/iocomp/iocomp.htm
http://www.osr.com/ntinsider/1997/cancel_1.htm
http://www.osr.com/ntinsider/1998/Cancel2/cancel_2.htm
http://www.osr.com/ntinsider/2000/new_io_cancel.htm

You can also subscribe to The NT Insider. It’s a great publication for
driver writers – and it’s free!

http://www.osr.com/publications_ntinsider.shtml

Best regards,
-Dan

Dan Germann
xxxxx@nospam.visi.com

-----Original Message-----
Subject: Re: Cancellation of IRP’s
From: Srinivasa Rao Deevi
> Date: Tue, 4 Sep 2001 09:26:51 -0700
>
> Hi all
>
> Thanks for the reply Max.
>
> I found the article on the web from Microsoft but it is not answering what
I
> am looking for . I hope you are refering the same site
> http://support.microsoft.com/support/kb/articles/q120/1/71.asp
>
> Thank you
> srinivas
>
>
> -----Original Message-----
> From: Maxim S. Shatskih [mailto:xxxxx@storagecraft.com]
> Sent: Saturday, September 01, 2001 4:06 PM
> To: NT Developers Interest List
> Subject: [ntdev] Re: Cancellation of IRP’s
>
>
> There was an MS note on IRP cancellation. Try to find it on MS’s site.
> I will send you it by email if you will not find it on the MS’s web.
>
> Max
>
> ----- Original Message -----
> From: “Srinivasa Rao Deevi”
> To: “NT Developers Interest List”
> Sent: Saturday, September 01, 2001 1:12 AM
> Subject: [ntdev] Cancellation of IRP’s
>
>
> > Hi all
> >
> > I got some doubt about implementing Device Queue managed by driver and
> > cancellation of IRP’s . I have gone through the articles, documentation
> and
> > other Device driver books by Peter Viscorola and Walter Oney but I could
> not
> > find the information I am looking for . Hope somebody can help me.
> >
> > I wanted to maintain a Device Queue for all IO requests that comes from
> the
> > Application . All IRP requests are sent to next level driver with
> completion
> > routine set . Here I am not setting any cancel routine and hoping to
> return
> > to completion routine in case of IRP cancel or success . Before sending
> the
> > requests to next level driver the IRP is queued in to Driver managed
queue
> .
> >
> > As per the DDk or any articles what I read , Any IRP that is queued
> > must be having a cancel routine and set IRP as Pending with
> > IoMarkIrpPending() call . As I said before in case of IRP failure I
> wanted
> > to return back to completion routine . The reason why I wanted to come
> back
> > to completion routine is to release the memory allocated for URB request
> and
> > context structure . I have no Idea how can I release this memory if I
set
> a
> > cancel routine . I could not find any method to do it . though I am
> queueing
> > IRP into the Driver managed queue I am not setting the IRP as pending ,
> > because the IO manager can complete the request immediatley and calls
the
> > Completion routine , in the completion routine if Pending flag is set
then
> > that time I am marking the IRP as pending. Can I do this ?
> >
> > When application is closed , the terminating thread issues
DispatchCleanUp
> > call to clean the IRP’s that are pending . In the DispatchCleanUp
routine
> ,
> > I wanted to clear all the pending IRP’s with out depending on IO Manager
.
> > Since the IRP that are queued are generated by IO manager I cannot call
> > IoCancelIrp and I cannot complete the request because I needed to
release
> > the context memory that is allocated for sending the request . How do we
> > need to tackle this situation ?
> >
> > do we really need a IRP queue for the IRP’s generated by IO manager and
> > depend on IO manager cancellation of IRP’s for all Pending IRP’s ?
> >
> > If not can anybody suggest me some good way of handling this ?
> >
> > The articles what I read does not deal with the situation like context
> > memory for URB request . In the cancel routines the IRP is just
completed
> > with STATUS_CANCELLED but never discussed about a situation like
releasing
> > context memory allocated for URB structure .
> >
> > Could anybody point me to some information or give me some idea of how
to
> > implement what I needed .
> >
> > Thanks in advance
> > srinivas


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com