From: Daniel Knueven on
Is it possible to get a close event on a device that has outstanding IO
requests? If an application tries to close its handle to my driver, I'd like
my driver to cancel any pending IO requests and let the app close down
instead of hanging. I've added a close event handler with
WdfDeviceInitSetFileObjectConfig, but I only get that call when all the IO is
complete and the device handle is being closed. I want to get notification
even if IO is still pending so I can clean up for the bad app.

Thanks,
-Daniel
From: Doron Holan [MSFT] on
you want EvtFileCleanup. Cleanup is called in the context of the app while
io is still pending. Close is called onced the ref count of the file object
has reached zero which means no more pending io (since each takes a ref on
the PFILE_OBJECT when sent). Now, after EvtFileCleanup has been called (or
not been set) KMDF will purge/complete all pending io in all of the device's
queues for that file handle. if you are still seeing a hang, that means
that you are holding on a request (perhaps from a sequential or parallel
queue) and not completing it in time. you can be notified that the queues
are being purged by registering an EvtIoStop on the queue where you have
pended requests and it will be invoked for each request that is still in the
queue after a purge

d

--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.


"Daniel Knueven" <DanielKnueven(a)discussions.microsoft.com> wrote in message
news:0924173B-EA44-4CCD-AA66-6DDC40A65B14(a)microsoft.com...
> Is it possible to get a close event on a device that has outstanding IO
> requests? If an application tries to close its handle to my driver, I'd
> like
> my driver to cancel any pending IO requests and let the app close down
> instead of hanging. I've added a close event handler with
> WdfDeviceInitSetFileObjectConfig, but I only get that call when all the IO
> is
> complete and the device handle is being closed. I want to get notification
> even if IO is still pending so I can clean up for the bad app.
>
> Thanks,
> -Daniel

From: Daniel Knueven on
The cleanup event did the trick. The IO request isn't in the queue when the
app tries to close the handle. The IO has already been dequeued to my driver,
but the device doesn't have any data yet so it won't complete the read until
it has something to complete it with. Since the cleanup call gets made before
the IO is complete, it can cancel the IO and that allows the close to
complete.

Thanks for your help!
-Daniel

"Doron Holan [MSFT]" wrote:

> you want EvtFileCleanup. Cleanup is called in the context of the app while
> io is still pending. Close is called onced the ref count of the file object
> has reached zero which means no more pending io (since each takes a ref on
> the PFILE_OBJECT when sent). Now, after EvtFileCleanup has been called (or
> not been set) KMDF will purge/complete all pending io in all of the device's
> queues for that file handle. if you are still seeing a hang, that means
> that you are holding on a request (perhaps from a sequential or parallel
> queue) and not completing it in time. you can be notified that the queues
> are being purged by registering an EvtIoStop on the queue where you have
> pended requests and it will be invoked for each request that is still in the
> queue after a purge
>
> d
>
> --
> Please do not send e-mail directly to this alias. this alias is for
> newsgroup purposes only.
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
> "Daniel Knueven" <DanielKnueven(a)discussions.microsoft.com> wrote in message
> news:0924173B-EA44-4CCD-AA66-6DDC40A65B14(a)microsoft.com...
> > Is it possible to get a close event on a device that has outstanding IO
> > requests? If an application tries to close its handle to my driver, I'd
> > like
> > my driver to cancel any pending IO requests and let the app close down
> > instead of hanging. I've added a close event handler with
> > WdfDeviceInitSetFileObjectConfig, but I only get that call when all the IO
> > is
> > complete and the device handle is being closed. I want to get notification
> > even if IO is still pending so I can clean up for the bad app.
> >
> > Thanks,
> > -Daniel
>
>