Have a physical storport miniport driver.
Driver creates a thread in StorportInitialize routine (at PASSIVE_LEVEL) and some other structures.
The thread can be destroyed by setting an event.
I am confused as to the best place to destroy the thread and its resources.
Is ScsiStopAdapter the best place to intercept this?. This is called at DIRQL and I cannot call KeSetEvent at this level. So I queue a DPC which queues a work item which then destroys the thread by setting the event. But the ScsiStopAdapter has to wait for the thread to be destroyed which means polling.
If I implement it in ScsiStopAdapter, I have to recreate the resources in ReStartAdapter which is also called at DIRQL. The same problem arises.
Should I handle SRB_SHUTDOWN_FUNCTION in BuildIo or StartIO?. We do not set Caches to TRUE. If I set to TRUE, is this SRB guaranteed to be sent.
Hey srk, jumping in here, you're right that ScsiStopAdapter being called at DIRQL complicates things. One approach I've seen is to initiate the cleanup from ScsiStopAdapter using a DPC+work item (like you mentioned), but let the actual resource teardown complete asynchronously, then use a state check in ScsiRestartAdapter to defer reinitialization until cleanup is confirmed. Also, handling SRB_FUNCTION_SHUTDOWN in StartIO can help with orderly shutdowns at PASSIVE_LEVEL if caching is enabled. Just make sure HwInitializationData.CachesData is set to TRUE, otherwise it won't be sent.
Thank you for the reply. I do not think I can wait in restartAdapter because ScsiStopAdapter may be issued and then the driver is unloaded. I need to make sure that the thread is destroyed before the driver is unloaded (and the image is removed from memory)