none
Creating a new request in a KMDF based filter driver and send it to another device stack. RRS feed

  • Question

  • I am writing a KMDF based filter driver which will filter the request for disk type devices.

    Suppose there are 2 disks : disk0 and disk1.

    disk0 is a slow disk and disk1 is a fast disk. I am using disk1 as a cache.

    Currently I am working only on filtering read request.

    Till now I have written a simple filter driver which will forward the request down without altering.

    I debugged my filter driver at boot time. like I looked for my WdfFltrEvtDeviceAdd, it was called twice during boot up time. This means Ist time for disk0 and 2nd time disk1 device.

    My questions are :

    1. Is it mean that there are 2 instances of my filter driver running in system as WdfFltrEvtDeviceAdd was called twice and device objects were created 2 times and it was attached to both the devices?

    2. Suppose a read request comes for disk0 and I already have same data present at disk1. So instead of reading it from disk0 I want to read request from disk1. So in this case I will not forward my request to default target which is disk0. What I will do is , when I catch the read request for disk0 then I will  create a new request in my filter driver for disk1 and I will forward this request to read it from disk1. How I will create a new request for disk1 type device and then to forward to it. Please help me How would I implement it?

    Tuesday, November 26, 2013 12:35 PM

Answers

  • Yes the two calls to WdfFltrEvtDeviceAdd indicate that the driver is now attached to two devices.  Assuming these are the only disks, then it is attaching to disk0 and disk1.

    For the request you do not need to create a second request, simply have the WDFIOTARGET for disk1 avaiable to the disk0 filtering path, and use WdfRequestSend with the disk1 target instead of the disk0 target.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Tuesday, November 26, 2013 12:43 PM
  • Why do you need the IRP?  You can modify the request going down if need be.  Just as if this was a single disk your WdfFltrEvtDeviceAdd should get the target for each device called.  In this case determine in that routine that disk1 is the cache and store the disk1 target in a global variable for use by disk0.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Tuesday, November 26, 2013 1:43 PM

All replies

  • Yes the two calls to WdfFltrEvtDeviceAdd indicate that the driver is now attached to two devices.  Assuming these are the only disks, then it is attaching to disk0 and disk1.

    For the request you do not need to create a second request, simply have the WDFIOTARGET for disk1 avaiable to the disk0 filtering path, and use WdfRequestSend with the disk1 target instead of the disk0 target.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Tuesday, November 26, 2013 12:43 PM
  • For this I need to change in IRP as I will get through WdfRequestWdmGetIrp() ?

    This thing is confusing me, what are the parameters that I need to change in IRP for changing my target from disk0 to disk1. From where I will get the target device object for disk1 in WdfRequestSend() .

    Tuesday, November 26, 2013 1:15 PM
  • Why do you need the IRP?  You can modify the request going down if need be.  Just as if this was a single disk your WdfFltrEvtDeviceAdd should get the target for each device called.  In this case determine in that routine that disk1 is the cache and store the disk1 target in a global variable for use by disk0.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Tuesday, November 26, 2013 1:43 PM
  • Yes I think you are right. What I was thinking if I get the target device and store it in device context private structure then I would not be having access to another device context structure and there are 2 instances running with their different device context structure.
    Tuesday, November 26, 2013 1:49 PM
  • I want to modify request only when it is coming from disk0. I have target device information in global variable as you suggested. So my questions are :

    1. How would I compare WDFIOTARGET type value that whether it is coming from disk0 or any other disk?

    2. Suppose there are many disks like disk0,disk1,disk2,disk then WdfFltrEvtDeviceAdd will be called first for disk0 then for disk1 then for disk2 and so on. Is it so?

    Wednesday, November 27, 2013 8:16 AM
  • There is no gurantee that the disks are started in sequence, thus no guarantee that your AddDevice routine is called in the order of the disk numbering. Furthermore even if they did, you would need to handle the disk being disabled and restarted afterwards which forces out of order. You nerd to identify the disk in another way, perhaps by serial.number

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Wednesday, November 27, 2013 3:56 PM
  • you mean to say that in my filter driver I should save wdfiotarget object according to serial number in WdfFltrEvtDeviceAdd routine ?
    Thursday, November 28, 2013 11:24 AM
  • Not always the serial number, but you have to have a criteria that says you are redirecting from disk A to disk B.  Whatever that criteria is, you need to use it to save B's io target.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Thursday, November 28, 2013 12:11 PM
  • As you suggested I tried to change the request target during read request from disk0 to disk1 but at boot up time a fatal error is generating due to this, as I am changing the target and it requires the target to be disk0. So what do I do ? Is there any way so that I can get to know during boot up do not change the request target or change target at some time when user actually write or read to/from disk
    Friday, November 29, 2013 10:45 AM
  • If you have seen disk1 then it should be available to write to.  Something else is going on in you driver.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Friday, November 29, 2013 1:44 PM
  • Yes there was some problem in my driver and I solved it. I want to know that is there any way we can get to know where would the data be written on disk or sector address where the data will be written or any field in IRP which tells about it and I can change it to write to some other address from disk1 to disk2.
    Tuesday, December 3, 2013 5:51 AM