標籤:磁碟類過濾驅動 do_power_pagable
The following explains why the DO_POWER_PAGABLE bit must be set on the way down and not on the way up:
The power requirements state that if any lower device object sets the DO_POWER_PAGABLE bit, all higher-level drivers must do the same. If the filter driver fails to set the DO_POWER_PAGABLE bit prior to sending the paging request IRP down the stack, it could violate this condition as follows:
Suppose the filter driver does not set the DO_POWER_PAGABLE bit in its Filter DO before forwarding the paging request IRP to the drivers beneath it in the driver stack. Next suppose that a lower driver sets the DO_POWER_PAGABLE bit in its own DO. Finally, suppose that prior to the completion of the IRP by the filter driver a power IRP occurs. At that point, the DO_POWER_PAGABLE bit would be cleared in the Filter DO but would be set in the DO of the lower-level driver, causing a system crash.
It is safe to set the DO_POWER_PAGABLE bit before forwarding a paging request down the stack, because there is no longer an active paging file on the filter driver‘s device, and therefore no more paging I/O will occur on it. If the request to remove this paging file succeeds, the filter driver will be done. If the request fails, the filter driver can restore the original state of its flags by simply clearing the DO_POWER_PAGABLE bit prior to completing the IRP. Because the paging file requests are serialized, there is no danger that some other thread will have modified this bit since the filter driver last altered it.
譯文為: 電源管理的需求規定了如果一個更低層的裝置對象設定了 DO_POWER_PAGABLE 位,那麼所有的更高層驅動也必須這麼做。如果過濾驅動沒有在下發分頁的 IRP 之前設定 DO_POWER_PAGABLE 位,它可能違反下面的這些條件: 假設過濾驅動沒有在下發分頁 IRP 之前設定 DO_POWER_PAGABLE 位, 再假設下層驅動設定了自己的裝置對象的 DO_POWER_PAGABLE 位。最後,假設在這個過濾驅動的 IRP 完成之前,一個電源 IRP 發生了。這個時候,DO_POWER_PAGABLE 位將被該過濾驅動清除,但它又被更低層的驅動設定了,就引起了一個系統崩潰。
在一個分頁請求下發之前設定 DO_POWER_PAGABLE 位是安全的,因為這裡不再有一個活躍的分頁檔案在這個過濾驅動的裝置上,因此也不會有分頁 I/O 在上面發生。如果移除這個分頁檔的請求成功執行,過濾驅動將會去做,如果請求失敗,過濾驅動能夠恢複它的標誌的原始狀態,只需要在完成這個 IRP 之前簡單地清除一下 DO_POWER_PAGABLE 位即可。因為分頁檔請求是序列化的。即使其它線程在過濾驅動最後改變它之後又修改了這個位,這也是沒有危險的。
原文連結: http://msdn.microsoft.com/zh-cn/ff554992