Crash while copy of a write IRP

Hi,

I am trying to write a driver that copys all the data intended for a particular disk to a specified backup disk. I’ve done this using a upper filter driver based on the diskperf example. In the write dispatch function of my driver I’ve tried to make a clone of the original IRP and send it to the backup disk. To do this I’ve taken the following steps:

  • Add a completion routine to the original IRP
  • In the completion routine create a new IRP (IoBuildSynchronousFsdRequest)
  • MmGetSystemAddressForMdlSafe and Parameters.Read.Length to get the paramters for the IoBuildSynchronousFsdRequest
  • I’ve set a completion routine for the new IRP which set a kernel event
  • I call the partition manger filter driver for the backup disk and wait till the request is processed
  • I free the new IRP and return the status to the original driver

All my attempts have lead to the dreaded “BSOD” :). The WinDbg console says “IRQL_NOT_LESS_OR_EQUAL” and points me to line where I’ve called the IoBuildSynchronousFsdRequest function. I’ve tried replacing the SynchronousFsdRequest with IoAllocateIRP (copying values from one I/O stack to another and using the IoBuildPartialIrp calls), but even this leads to the same error.
Can you please tell me what I am doing wrong and any open source reference code that manuplates IRP like this.

Thank you.

Well since the path you are in runs a lot of the time at DISPATCH_LEVEL
you have a problem. Create a pool of IRP’s (or better yet do this in
KMDF and use a pool of requests), to handle this.

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

xxxxx@coventry.ac.uk” wrote in message
news:xxxxx@ntdev:

> Hi,
>
> I am trying to write a driver that copys all the data intended for a particular disk to a specified backup disk. I’ve done this using a upper filter driver based on the diskperf example. In the write dispatch function of my driver I’ve tried to make a clone of the original IRP and send it to the backup disk. To do this I’ve taken the following steps:
> - Add a completion routine to the original IRP
> - In the completion routine create a new IRP (IoBuildSynchronousFsdRequest)
> - MmGetSystemAddressForMdlSafe and Parameters.Read.Length to get the paramters for the IoBuildSynchronousFsdRequest
> - I’ve set a completion routine for the new IRP which set a kernel event
> - I call the partition manger filter driver for the backup disk and wait till the request is processed
> - I free the new IRP and return the status to the original driver
>
> All my attempts have lead to the dreaded “BSOD” :). The WinDbg console says “IRQL_NOT_LESS_OR_EQUAL” and points me to line where I’ve called the IoBuildSynchronousFsdRequest function. I’ve tried replacing the SynchronousFsdRequest with IoAllocateIRP (copying values from one I/O stack to another and using the IoBuildPartialIrp calls), but even this leads to the same error.
> Can you please tell me what I am doing wrong and any open source reference code that manuplates IRP like this.
>
> Thank you.

Hi Don,

Thank you for your reply. I have just recently started developing on Windows so I apolgize if I am a little slow on the uptake. I have the following questions regarding your reply
The driver I am developing is like diskperf which I believe is WDM based, would you recomend transiton to KMDF for this feature. I was thinking of making a call to initalize around 10 IRP in DriverEntry.

In general KMDF is easier and better for any sort of Plug and Play
driver. A large amount of the pain is reduced since most of the PnP and
Power support is provided for you. Microsoft has been moving drivers in
the storage stack this way for a large number of years. So I would make
this a KMDF filter. For the IRP pool, for each device I would allocate
N IRP’s (i.e. in AddDevice I would add to the IRP pool), where N is a
registry setting that can be adjusted as needed.

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

xxxxx@coventry.ac.uk” wrote in message
news:xxxxx@ntdev:

> Hi Don,
>
> Thank you for your reply. I have just recently started developing on Windows so I apolgize if I am a little slow on the uptake. I have the following questions regarding your reply
> The driver I am developing is like diskperf which I believe is WDM based, would you recomend transiton to KMDF for this feature. I was thinking of making a call to initalize around 10 IRP in DriverEntry.

Hi Don,

Thank you for your reply. It cleared up a lot of things. I’ll change my driver as per your suggestion. Just to clarify, the sequence of event in the completion routine would now be

  • re-initialize the allocated IRP
  • Copy the original MDL using IoAllocateMDL and IoBuildPartialMDL
  • Initilize the Length and Offsets, Function and DeviceObject in the I/O Stack’s parameter
  • Call the target disk’s driver and wait for its completion

Thank you.

> - Add a completion routine to the original IRP

  • In the completion routine create a new IRP (IoBuildSynchronousFsdRequest)

Bad idea.

IoBuildSynchronousFsdRequest creates a threaded IRP and thus requires a thread and <dispatch.>
Completion routine runs on DISPATCH (usually) and in arbitrary thread.

So, get rid of this call and use IoAllocateIrp or IoBuildAsynchronousFsdRequest.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com</dispatch.>

> you have a problem. Create a pool of IRP’s

What is the need of this?

Is IoAllocateIrp gone?


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com