Handling a GUID_TARGET_DEVICE_REMOVE_COMPLETE event.

Hi!

I wrote a driver for my devices.
In the other driver I have a PnP notification routine for my devices arrival. Then I open the device using the workitem queue and start working with it, sending it IOs.
I have to write the PnP notification routine in order to support the surprise remove of the device.
It is written in DDK, that a notification routine must not block and it should close any handles on the device and remove any outstanding references to the file object.

Do I have to wait for all the sent IOs completion when receiving GUID_TARGET_DEVICE_REMOVE_COMPLETE event?

Regards,
Dany

This mail was sent via storeage.com

************************************************************************************
This footnote confirms that this email message has been scanned by
PineApp Mail-SeCure for the presence of malicious code, vandals & computer viruses.
************************************************************************************

Hi Dany,
Seems your existing driver is an NT style driver. You should have complete
all your pending IOs in IRP_MN_SURPRISE_REMOVAL. Here you shouldn’t wait but
perform the cleanup task.

Hope this helps.

Dev

-----Original Message-----
From: Dany Polovets [mailto:xxxxx@storeage.com]
Sent: Tuesday, October 05, 2004 9:32 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Handling a GUID_TARGET_DEVICE_REMOVE_COMPLETE event.

Hi!

I wrote a driver for my devices.
In the other driver I have a PnP notification routine for my devices
arrival. Then I open the device using the workitem queue and start working
with it, sending it IOs.
I have to write the PnP notification routine in order to support the
surprise remove of the device.
It is written in DDK, that a notification routine must not block and it
should close any handles on the device and remove any outstanding references
to the file object.

Do I have to wait for all the sent IOs completion when receiving
GUID_TARGET_DEVICE_REMOVE_COMPLETE event?

Regards,
Dany

This mail was sent via storeage.com

****************************************************************************
********
This footnote confirms that this email message has been scanned by
PineApp Mail-SeCure for the presence of malicious code, vandals & computer
viruses.
****************************************************************************
********


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

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

Dev,

Thanks for an answer.
I would like to clarify my question and the potential problem I am thinking about.
There are two drivers: functional device driver and the second driver which receives the device pointer in notification callback and sends it IOs.
Let’s say that the second driver is going to call the IoCallDriver() with the device object parameter. Now the context switch happens and a
GUID_TARGET_DEVICE_REMOVE_COMPLETE event notification callback is called. The cleanup task is performed, the callback function
returns STATUS_SUCCESS and the device object is deleted in the first driver. Now IoCallDriver() is crashing the system.

How can I prevent it?
I cannot use a remove lock in the second driver since it must not block in the notification callback.
On the other hand I have to close all the handles.

Regards,
Dany

-----Original Message-----
From: Dsingh@in.safenet-inc.com [mailto:Dsingh@in.safenet-inc.com]
Sent: Wednesday, October 06, 2004 07:27
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Handling a GUID_TARGET_DEVICE_REMOVE_COMPLETE event.

Hi Dany,
Seems your existing driver is an NT style driver. You should have complete all your pending IOs in IRP_MN_SURPRISE_REMOVAL. Here you shouldn’t wait but perform the cleanup task.

Hope this helps.

Dev

-----Original Message-----
From: Dany Polovets [mailto:xxxxx@storeage.com]
Sent: Tuesday, October 05, 2004 9:32 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Handling a GUID_TARGET_DEVICE_REMOVE_COMPLETE event.

Hi!

I wrote a driver for my devices.
In the other driver I have a PnP notification routine for my devices arrival. Then I open the device using the workitem queue and start working with it, sending it IOs.

I have to write the PnP notification routine in order to support the surprise remove of the device.
It is written in DDK, that a notification routine must not block and it should close any handles on the device and remove any outstanding references to the file object.

Do I have to wait for all the sent IOs completion when receiving GUID_TARGET_DEVICE_REMOVE_COMPLETE event?

Regards,
Dany

This mail was sent via storeage.com

************************************************************************************
This footnote confirms that this email message has been scanned by
PineApp Mail-SeCure for the presence of malicious code, vandals & computer viruses.
************************************************************************************

Dany,

My assumption is second driver is too in the driver stack of first driver
i.e. second driver is sort of filter driver to first driver. If this
assumption is true then second driver should get IRP_MN_SURPRISE_REMOVAL
before getting GUID_TARGET_DEVICE_REMOVE_COMPLETE. When both of driver
completes the IRP_MN_SURPRISE_REMOVAL then only pnp will send
GUID_TARGET_DEVICE_REMOVE_COMPLETE to second driver.
If all above is true then you should complete IOs in IRP_MN_SURPRISE_REMOVAL
and in GUID_TARGET_DEVICE_REMOVE_COMPLETE just complete the remaining task.

Dev

-----Original Message-----
From: Dany Polovets [mailto:xxxxx@storeage.com]
Sent: Wednesday, October 06, 2004 2:28 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Handling a GUID_TARGET_DEVICE_REMOVE_COMPLETE event.

Dev,

Thanks for an answer.
I would like to clarify my question and the potential problem I am thinking
about.
There are two drivers: functional device driver and the second driver which
receives the device pointer in notification callback and sends it IOs.
Let’s say that the second driver is going to call the IoCallDriver() with
the device object parameter. Now the context switch happens and a
GUID_TARGET_DEVICE_REMOVE_COMPLETE event notification callback is called.
The cleanup task is performed, the callback function
returns STATUS_SUCCESS and the device object is deleted in the first driver.
Now IoCallDriver() is crashing the system.

How can I prevent it?
I cannot use a remove lock in the second driver since it must not block in
the notification callback.
On the other hand I have to close all the handles.

Regards,
Dany

-----Original Message-----
From: Dsingh@in.safenet-inc.com [mailto:Dsingh@in.safenet-inc.com]
Sent: Wednesday, October 06, 2004 07:27
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Handling a GUID_TARGET_DEVICE_REMOVE_COMPLETE event.

Hi Dany,
Seems your existing driver is an NT style driver. You should have complete
all your pending IOs in IRP_MN_SURPRISE_REMOVAL. Here you shouldn’t wait but
perform the cleanup task.

Hope this helps.

Dev

-----Original Message-----
From: Dany Polovets [ mailto:xxxxx@storeage.com
mailto:xxxxx ]
Sent: Tuesday, October 05, 2004 9:32 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Handling a GUID_TARGET_DEVICE_REMOVE_COMPLETE event.

Hi!

I wrote a driver for my devices.
In the other driver I have a PnP notification routine for my devices
arrival. Then I open the device using the workitem queue and start working
with it, sending it IOs.

I have to write the PnP notification routine in order to support the
surprise remove of the device.
It is written in DDK, that a notification routine must not block and it
should close any handles on the device and remove any outstanding references
to the file object.

Do I have to wait for all the sent IOs completion when receiving
GUID_TARGET_DEVICE_REMOVE_COMPLETE event?

Regards,
Dany


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

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com This
mail was sent via storeage.com

********************************************************************

This footnote confirms that this email message has been scanned by
PineApp Mail-SeCure for the presence of malicious code, vandals & computer
viruses.
********************************************************************
</mailto:xxxxx>

You need to keep track of the outstanding I/Os you send to the 2ndary stack. The basic logic when sending i/o is this

Acquire spin lock
If (target state is open)
Increment pending i/o count
Else {
Fail request
}
Release spin lock

If (fail request) { fail PIRP internally)
Else return IoCallDriver(...);

In the completion routine for the sent PIRP

Acquire spin lock
Decrement i/o count
If (i/o count == 0)
Set event = TRUE
Release lock

If (set event) { KeSetEvent(...) }

And in the notification callback

Acquire spin lock
Set target state to closed
If i/o count > 0
Wait = TRUE
Release lock

If (wait) { KeWaitForSingleObject(...); }

d


From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Dany Polovets
Sent: Wednesday, October 06, 2004 1:58 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Handling a GUID_TARGET_DEVICE_REMOVE_COMPLETE event.

Dev,
?
Thanks for an answer.
I would like to clarify my question and the potential problem I am thinking about.
There are two drivers: functional device driver and the second driver which receives the device pointer in notification callback and sends it IOs.
Let's say that the second driver is going to call the IoCallDriver() with the device object parameter. Now the context switch happens and a
GUID_TARGET_DEVICE_REMOVE_COMPLETE event notification callback is called. The cleanup task is performed, the callback function
returns STATUS_SUCCESS and the device object is deleted in the first driver. Now? IoCallDriver() is crashing the system.
?
How can I prevent it?
I cannot use a?remove lock in the second driver since it must not block in the notification callback.
On the other hand I have to close all the handles.
?
Regards,
Dany
-----Original Message-----
From: Dsingh@in.safenet-inc.com [mailto:Dsingh@in.safenet-inc.com]
Sent: Wednesday, October 06, 2004 07:27
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Handling a GUID_TARGET_DEVICE_REMOVE_COMPLETE event.
Hi Dany,
Seems your existing driver is an NT style driver. You should have complete all your pending IOs in IRP_MN_SURPRISE_REMOVAL. Here you shouldn't wait but perform the cleanup task.
Hope this helps.
Dev
-----Original Message-----
From: Dany Polovets [mailto:xxxxx@storeage.com]
Sent: Tuesday, October 05, 2004 9:32 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Handling a GUID_TARGET_DEVICE_REMOVE_COMPLETE event.

Hi!
I wrote a driver for my devices.
In the other driver I have a PnP notification routine for my devices arrival. Then I open the device using the workitem queue and start working with it, sending it IOs.
I have to write the PnP notification routine in order to support the surprise remove of the device.
It is written in DDK, that a notification routine must not block and it should close any handles on the device and remove any outstanding references to the file object.
Do I have to wait for all the sent IOs completion when receiving GUID_TARGET_DEVICE_REMOVE_COMPLETE event?
Regards,
Dany

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

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ''
To unsubscribe send a blank email to xxxxx@lists.osr.com