IRP_MJ_QUERY_REMOVE_DEVICE and pending IRP

My driver has a pending IRP_MJ_READ IRP (waiting for a data).
What should I do in IRP_MN_QUERY_REMOVE_DEVICE handler ?

  1. Cancel IRP_MJ_READ IRP;
  2. Wait for its completion (forever?);
  3. Fail IRP_MN_QUERY_REMOVE_DEVICE.

Thanks.

Just process requests normally, except for IRP_MJ_CREATE, until you receive
the remove request. Note that your application, the one with the
infinite-wait IRP, ought to be monitoring PNP state change requests so that
it can cancel the read and allow the remove to proceed. The problem with
failing requests is that the device may not actually be removed, and
instead, some time later, a cancel remove will arrive and now you’ve failed
a bunch of IO that should have completed without error.

=====================
Mark Roddy

-----Original Message-----
From: Max Woo [mailto:xxxxx@hotmail.com]
Sent: Saturday, February 21, 2004 1:37 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] IRP_MJ_QUERY_REMOVE_DEVICE and pending IRP

My driver has a pending IRP_MJ_READ IRP (waiting for a data).
What should I do in IRP_MN_QUERY_REMOVE_DEVICE handler ?

  1. Cancel IRP_MJ_READ IRP;
  2. Wait for its completion (forever?);
  3. Fail IRP_MN_QUERY_REMOVE_DEVICE.

Thanks.


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as:
xxxxx@stratus.com To unsubscribe send a blank email to
xxxxx@lists.osr.com

If it waits for external data, possibly forever - then cancellation is a
good thing.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Max Woo”
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”
Sent: Saturday, February 21, 2004 9:37 AM
Subject: [ntdev] IRP_MJ_QUERY_REMOVE_DEVICE and pending IRP

> My driver has a pending IRP_MJ_READ IRP (waiting for a data).
> What should I do in IRP_MN_QUERY_REMOVE_DEVICE handler ?
> 1. Cancel IRP_MJ_READ IRP;
> 2. Wait for its completion (forever?);
> 3. Fail IRP_MN_QUERY_REMOVE_DEVICE.
>
> Thanks.
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com

  1. stop accepting further IRPs.
  2. keep on processing queued (pending) IRPs normally until you get remove
    IRP.
  3. On getting remove IRP, Cancel IRP_MJ_READ IRP.

Hope this help.

Dev

-----Original Message-----
From: Max Woo [mailto:xxxxx@hotmail.com]
Sent: Saturday, February 21, 2004 12:07 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] IRP_MJ_QUERY_REMOVE_DEVICE and pending IRP

My driver has a pending IRP_MJ_READ IRP (waiting for a data).
What should I do in IRP_MN_QUERY_REMOVE_DEVICE handler ?

  1. Cancel IRP_MJ_READ IRP;
  2. Wait for its completion (forever?);
  3. Fail IRP_MN_QUERY_REMOVE_DEVICE.

Thanks.


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: dsingh@in.rainbow.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

This is slightly incorrect

  1. stop accepting further irps, EXCEPT for IRP_MJ_CLEANUP and IRP_MN_CLOSE
  2. upon reception of the cleanup irp, complete with error (STATUS_NO_SUCH_DEVICE) any pended i/o on the handle being closed. The i/o subsystem will not always cancel pended i/o on behalf of the driver.

You will never get a remove device if there is an open handle against your device. If you are attempting to query remove your device, the driver is asked first, then the applications are notified. If all of the apps close their handles, you get a remove. Otherwise, if there are open handles or some other kind of veto, you will get a cancel remove irp.

D

This posting is provided “AS IS” with no warranties, and confers no rights.


From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of dsingh@IN.rainbow.com
Sent: Friday, February 20, 2004 8:30 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] IRP_MJ_QUERY_REMOVE_DEVICE and pending IRP

  1. stop accepting further Rips.
  2. keep on processing queued (pending) IRPs normally until you get remove IRP.
  3. On getting remove IRP, Cancel IRP_MJ_READ? IRP.
    Hope this help.
    Dev
    -----Original Message-----
    From: Max Woo [mailto:xxxxx@hotmail.com]
    Sent: Saturday, February 21, 2004 12:07 PM
    To: Windows System Software Devs Interest List
    Subject: [ntdev] IRP_MJ_QUERY_REMOVE_DEVICE and pending IRP

My driver has a pending IRP_MJ_READ IRP (waiting for a data).
What should I do in IRP_MN_QUERY_REMOVE_DEVICE handler ?

  1. Cancel IRP_MJ_READ? IRP;
  2. Wait for its completion (forever?);
  3. Fail IRP_MN_QUERY_REMOVE_DEVICE.
    Thanks.

Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: dsingh@in.rainbow.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

So you would say that the following paragraph in the 3790 DDK is incorrect?

“Once a driver succeeds an IRP_MN_QUERY_REMOVE_DEVICE and it considers the
device to be in the remove-pending state, the driver must fail any
subsequent create requests for the device. The driver processes all other
IRPs as usual, until the driver receives an IRP_MN_CANCEL_REMOVE_DEVICE or
an IRP_MN_REMOVE_DEVICE.”

I’d say that this is in fact the correct (or at least optimal) query-remove
policy. Consider the case where you get a cancel-remove rather than a
remove. Why exactly have you failed application IO?

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Saturday, February 21, 2004 12:18 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] IRP_MJ_QUERY_REMOVE_DEVICE and pending IRP

This is slightly incorrect

  1. stop accepting further irps, EXCEPT for IRP_MJ_CLEANUP
    and IRP_MN_CLOSE
  2. upon reception of the cleanup irp, complete with error
    (STATUS_NO_SUCH_DEVICE) any pended i/o on the handle being
    closed. The i/o subsystem will not always cancel pended i/o
    on behalf of the driver.

You will never get a remove device if there is an open handle
against your device. If you are attempting to query remove
your device, the driver is asked first, then the applications
are notified. If all of the apps close their handles, you
get a remove. Otherwise, if there are open handles or some
other kind of veto, you will get a cancel remove irp.

D

This posting is provided “AS IS” with no warranties, and
confers no rights.


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
dsingh@IN.rainbow.com
Sent: Friday, February 20, 2004 8:30 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] IRP_MJ_QUERY_REMOVE_DEVICE and pending IRP

  1. stop accepting further Rips.
  2. keep on processing queued (pending) IRPs normally until
    you get remove IRP.
  3. On getting remove IRP, Cancel IRP_MJ_READ? IRP.
    Hope this help.
    Dev
    -----Original Message-----
    From: Max Woo [mailto:xxxxx@hotmail.com]
    Sent: Saturday, February 21, 2004 12:07 PM
    To: Windows System Software Devs Interest List
    Subject: [ntdev] IRP_MJ_QUERY_REMOVE_DEVICE and pending IRP

My driver has a pending IRP_MJ_READ IRP (waiting for a data).
What should I do in IRP_MN_QUERY_REMOVE_DEVICE handler ?

  1. Cancel IRP_MJ_READ? IRP;
  2. Wait for its completion (forever?);
  3. Fail IRP_MN_QUERY_REMOVE_DEVICE.
    Thanks.

Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as:
dsingh@in.rainbow.com To unsubscribe send a blank email to
xxxxx@lists.osr.com

Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as:
xxxxx@windows.microsoft.com To unsubscribe send a blank
email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as:
xxxxx@hollistech.com To unsubscribe send a blank email to
xxxxx@lists.osr.com

I didn’t say to fail any io immediately. I said to fail io when you get a cleanup bound to the file handle that io was sent on. If you get the cleanup, the app has closed the handle and you should be doing this anyways regardless of the pnp state. Nor did I say not to fail creates. The point I was making is that you can’t fail *all* io in the q.r. state, some has to get through (like cleanup and close)

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Roddy
Sent: Sunday, February 22, 2004 5:11 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] IRP_MJ_QUERY_REMOVE_DEVICE and pending IRP

So you would say that the following paragraph in the 3790 DDK is incorrect?

“Once a driver succeeds an IRP_MN_QUERY_REMOVE_DEVICE and it considers the
device to be in the remove-pending state, the driver must fail any
subsequent create requests for the device. The driver processes all other
IRPs as usual, until the driver receives an IRP_MN_CANCEL_REMOVE_DEVICE or
an IRP_MN_REMOVE_DEVICE.”

I’d say that this is in fact the correct (or at least optimal) query-remove
policy. Consider the case where you get a cancel-remove rather than a
remove. Why exactly have you failed application IO?

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Saturday, February 21, 2004 12:18 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] IRP_MJ_QUERY_REMOVE_DEVICE and pending IRP

This is slightly incorrect

  1. stop accepting further irps, EXCEPT for IRP_MJ_CLEANUP
    and IRP_MN_CLOSE
  2. upon reception of the cleanup irp, complete with error
    (STATUS_NO_SUCH_DEVICE) any pended i/o on the handle being
    closed. The i/o subsystem will not always cancel pended i/o
    on behalf of the driver.

You will never get a remove device if there is an open handle
against your device. If you are attempting to query remove
your device, the driver is asked first, then the applications
are notified. If all of the apps close their handles, you
get a remove. Otherwise, if there are open handles or some
other kind of veto, you will get a cancel remove irp.

D

This posting is provided “AS IS” with no warranties, and
confers no rights.


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
dsingh@IN.rainbow.com
Sent: Friday, February 20, 2004 8:30 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] IRP_MJ_QUERY_REMOVE_DEVICE and pending IRP

  1. stop accepting further Rips.
  2. keep on processing queued (pending) IRPs normally until
    you get remove IRP.
  3. On getting remove IRP, Cancel IRP_MJ_READ? IRP.
    Hope this help.
    Dev
    -----Original Message-----
    From: Max Woo [mailto:xxxxx@hotmail.com]
    Sent: Saturday, February 21, 2004 12:07 PM
    To: Windows System Software Devs Interest List
    Subject: [ntdev] IRP_MJ_QUERY_REMOVE_DEVICE and pending IRP

My driver has a pending IRP_MJ_READ IRP (waiting for a data).
What should I do in IRP_MN_QUERY_REMOVE_DEVICE handler ?

  1. Cancel IRP_MJ_READ? IRP;
  2. Wait for its completion (forever?);
  3. Fail IRP_MN_QUERY_REMOVE_DEVICE.
    Thanks.

Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as:
dsingh@in.rainbow.com To unsubscribe send a blank email to
xxxxx@lists.osr.com

Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as:
xxxxx@windows.microsoft.com To unsubscribe send a blank
email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as:
xxxxx@hollistech.com To unsubscribe send a blank email to
xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

OK, perhaps I misread your post. The issue I am getting at is what to do
with new IO requests for existing device handles (as in read/write requests)
while in pending-remove state. The ddk is quite clear that these ought to be
processed normally, and I think this is the optimally correct strategy.
Several posts in this thread, including I think yours, could be interpreted
as suggesting that such requests ought to be rejected.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Sunday, February 22, 2004 12:17 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] IRP_MJ_QUERY_REMOVE_DEVICE and pending IRP

I didn’t say to fail any io immediately. I said to fail io
when you get a cleanup bound to the file handle that io was
sent on. If you get the cleanup, the app has closed the
handle and you should be doing this anyways regardless of the
pnp state. Nor did I say not to fail creates. The point I
was making is that you can’t fail *all* io in the q.r. state,
some has to get through (like cleanup and close)

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Roddy
Sent: Sunday, February 22, 2004 5:11 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] IRP_MJ_QUERY_REMOVE_DEVICE and pending IRP

So you would say that the following paragraph in the 3790 DDK
is incorrect?

“Once a driver succeeds an IRP_MN_QUERY_REMOVE_DEVICE and it
considers the device to be in the remove-pending state, the
driver must fail any subsequent create requests for the
device. The driver processes all other IRPs as usual, until
the driver receives an IRP_MN_CANCEL_REMOVE_DEVICE or an
IRP_MN_REMOVE_DEVICE.”

I’d say that this is in fact the correct (or at least
optimal) query-remove policy. Consider the case where you get
a cancel-remove rather than a remove. Why exactly have you
failed application IO?

> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
> Sent: Saturday, February 21, 2004 12:18 PM
> To: Windows System Software Devs Interest List
> Subject: RE: [ntdev] IRP_MJ_QUERY_REMOVE_DEVICE and pending IRP
>
> This is slightly incorrect
> 1) stop accepting further irps, EXCEPT for IRP_MJ_CLEANUP and
> IRP_MN_CLOSE
> 2) upon reception of the cleanup irp, complete with error
> (STATUS_NO_SUCH_DEVICE) any pended i/o on the handle being closed.
> The i/o subsystem will not always cancel pended i/o on
behalf of the
> driver.
>
> You will never get a remove device if there is an open
handle against
> your device. If you are attempting to query remove your
device, the
> driver is asked first, then the applications are notified.
If all of
> the apps close their handles, you get a remove. Otherwise,
if there
> are open handles or some other kind of veto, you will get a cancel
> remove irp.
>
> D
>
> This posting is provided “AS IS” with no warranties, and confers no
> rights.
>
> ________________________________________
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of
> dsingh@IN.rainbow.com
> Sent: Friday, February 20, 2004 8:30 PM
> To: Windows System Software Devs Interest List
> Subject: RE: [ntdev] IRP_MJ_QUERY_REMOVE_DEVICE and pending IRP
>
> 1. stop accepting further Rips.
> 2. keep on processing queued (pending) IRPs normally until you get
> remove IRP.
> 3. On getting remove IRP, Cancel IRP_MJ_READ? IRP.
> Hope this help.
> Dev
> -----Original Message-----
> From: Max Woo [mailto:xxxxx@hotmail.com]
> Sent: Saturday, February 21, 2004 12:07 PM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] IRP_MJ_QUERY_REMOVE_DEVICE and pending IRP
>
> My driver has a pending IRP_MJ_READ IRP (waiting for a data).
> What should I do in IRP_MN_QUERY_REMOVE_DEVICE handler ?
> 1. Cancel IRP_MJ_READ? IRP;
> 2. Wait for its completion (forever?); 3. Fail
> IRP_MN_QUERY_REMOVE_DEVICE.
> Thanks.
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
> You are currently subscribed to ntdev as:
> dsingh@in.rainbow.com To unsubscribe send a blank email to
> xxxxx@lists.osr.com
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@windows.microsoft.com To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@hollistech.com To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as:
xxxxx@windows.microsoft.com To unsubscribe send a blank
email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as:
xxxxx@hollistech.com To unsubscribe send a blank email to
xxxxx@lists.osr.com

>be doing this anyways regardless of the pnp state. Nor did I say not to fail
creates. The point I

Won’t PnP fail CREATE itself if the devnode is in “query remove passed without
veto” state?

If not - then this is a problem. A stray CREATE can arrive, and delay the
REMOVE indefinitely. Also the created file object will not work and all its IO
requests will hang - since the FDO is in “query-removed” state.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

Once everyone involved in the stack has succeeded the q.r., creates are
blocked. When the stack is queried, the apps have not yet been asked,
so there is an indeterminant period of time between q.r. succeeding in
the driver and receiving a remove cancelled or removed where new io,
including creates, can arrive. For these creates, it would be up to the
driver to handle their success/failure based on the internally
maintained pnp state.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Maxim S. Shatskih
Sent: Sunday, February 22, 2004 12:05 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] IRP_MJ_QUERY_REMOVE_DEVICE and pending IRP

be doing this anyways regardless of the pnp state. Nor did I say not
to fail
creates. The point I

Won’t PnP fail CREATE itself if the devnode is in “query remove passed
without
veto” state?

If not - then this is a problem. A stray CREATE can arrive, and delay
the
REMOVE indefinitely. Also the created file object will not work and all
its IO
requests will hang - since the FDO is in “query-removed” state.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com