An IRP_MN_QUERY_STOP_DEVICE request is handled first by the top driver in the device stack and then by each next lower driver. A driver handles stop IRPs in its DispatchPnP routine.
In response to an IRP_MN_QUERY_STOP_DEVICE, a driver must do the following:
A driver must fail a query-stop IRP if any of the following are true:
A driver might fail a query-stop IRP if the following is true:
Set Irp->IoStatus.Status to an appropriate error status, call IoCompleteRequest with IO_NO_INCREMENT, and return from the driver's DispatchPnP routine. Do not pass the IRP to the next lower driver.
Alternatively, the drivers for a device can defer completely pausing the device until the drivers receive the subsequent IRP_MN_STOP_DEVICE request. Such drivers, however, should disable and deregister their user-mode interfaces while handling the query-stop request to prevent the opening of any additional handles to the device.
Furthermore, such drivers must fail any requests that would prevent them from immediately succeeding the stop IRP when it arrives. Until the device is restarted, such drivers must fail requests such as the following:
One way that a driver can achieve this is to use a reference count and an event to ensure that all requests have been completed:
The driver decrements the reference count in the IoCompletion routine, if the request has one, or immediately after the call to IoCallDriver if the driver uses no IoCompletion routine for the request.
As an alternative to the above procedure, a driver can serialize the IRP_MN_QUERY_STOP_DEVICE IRP behind any IRPs in progress.
After a driver succeeds a query-stop IRP, it must be ready to succeed an IRP_MN_STOP_DEVICE.
In a function or filter driver:
In a bus driver:
If, however, the devices on the bus use hardware resources, re-evaluate the resource requirements of the bus and the child devices. If any of the requirements have changed, return STATUS_RESOURCE_REQUIREMENTS_CHANGED instead of STATUS_SUCCESS. This status indicates success but requests that the PnP Manager requery your resources before sending the stop IRP.
If any driver in the device stack fails the IRP_MN_QUERY_STOP_DEVICE, the PnP Manager sends an IRP_MN_CANCEL_STOP_DEVICE to the device stack. This prevents drivers from requiring an IoCompletion routine for a query-stop IRP to detect whether a lower driver failed the IRP.