1.发起request的线程或进程取消或离开
2.PnP和Power事件,例如睡眠
3.设备移除
驱动在收到请求时对请求取消(STATUS_CANCELLED)或完成error。
驱动应该为需要很长时间或不定时间的请求提供回调,比如非同步的input请求。
Request cancellation
WDF取消请求的行为取决于请求是否被传递给target driver
1.若请求还没被queue或任在queue中,framework自动cancel或suspend
2.若请求被传递,但只被传递给另一个queue,framework自动cancel或suspend
驱动注册EvtIoCanceledOnQueue可以获得通知
3.若请求被驱动获得,则framework不取消,但驱动可以标记请求是可取消的,并注册一个cancellation callback
标记请求可取消:
UMDF:===
KMDF:WdfRequestMarkCancelable/WdfRequestUnmarkCancelable
* 标记成可取消的请求无法被传递给另一个queue
驱动不允许让请求在uncancellable状态停留过长时间:长时间操作或不一定成功的操作。
KMDF:
使用WdfRequestIsCancelled查看是否I/O manager或requester在取消请求。
下表总结了当request取消时的framework动作。
When cancellation occurs… | The framework … |
---|---|
Before the request has ever been delivered to the driver | Cancels the request. No driver code is required, and no notification is sent to the driver. |
While the request is in a queue but after it has been delivered to the driver, which could occur if the driver receives an I/O request and then requeues it | Cancels the request. No driver code is required, and no notification is sent to the driver. If a KMDF driver has registered an EvtIoCanceledOnQueue callback for the queue, invokes this callback, and then cancels the request; otherwise, cancels the request as described above. (KMDF only) |
While the driver owns the request | If the driver has marked the request cancelable, calls the cancel callback that the driver registered for the request. If the driver has not marked the request cancelable, does nothing. The driver can call WdfRequestIsCanceled to find out whether the request has been canceled. (KMDF only) |
Request Suspension
UMDF:
KMDF:为请求注册EvtIoStop,包含flag指示queue停止的原因和请求是否是能取消的
驱动可以:
1.完成请求
2.requeue请求
3.若请求可以很快完成则忽略通知
4.承认通知但仍保持请求
驱动应该为任何需要长时间完成的请求注册stop callback