Synchronous write operation in volume filter driver

I’ve scoured this site for a lead on what’s happening and can’t find what I
need. If someone can lend a hand, I’d really appreciate it.

The problem occurs in a storage volume upper-layer filter driver. The driver
creates its own IRP_MJ_WRITE IRPs and successfully sends them to the
underlying volume device. (Below is a code snippet.) No errors occur, the
IRPs complete normally, volumes can be loaded and removed dynamically, etc.

However, the rate at which these writes occur is exceedingly slow. No matter
how many of these IRPs are outstanding, each takes an *average* of 6 ms to
complete. I’ve measured the timing (including completion routine) and 99.9%
is spent in the underlying driver.

I suspect I am initializing the IRP incorrectly. Any comments, suggestions?

  • Sean

BOOLEAN
CreateAndSendReadWriteIrp(…) {

irp = IoAllocateIrp(volume->Self->StackSize, FALSE);
if (irp == NULL) {

return FALSE;
}

irpSp = IoGetNextIrpStackLocation(irp);
if (IsRead) {

irp->Flags |= IRP_READ_OPERATION | IRP_DEFER_IO_COMPLETION;

irpSp->MajorFunction = IRP_MJ_READ;
irpSp->Parameters.Read.ByteOffset.QuadPart = offset;
irpSp->Parameters.Read.Length = length;
}
else {

irp->Flags |= IRP_WRITE_OPERATION | IRP_DEFER_IO_COMPLETION;

irpSp->MajorFunction = IRP_MJ_WRITE;
irpSp->Parameters.Write.ByteOffset.QuadPart = offset;
irpSp->Parameters.Write.Length = length;
}

if (IoAllocateMdl(buffer,
length,
FALSE,
FALSE,
irp) == NULL) {

IoFreeIrp(irp);

return FALSE;
}

try {
MmProbeAndLockPages(irp->MdlAddress,
KernelMode,
IoModifyAccess);
}
except(EXCEPTION_EXECUTE_HANDLER) {

status = GetExceptionCode();

IoFreeMdl(irp->MdlAddress);
IoFreeIrp(irp);

return FALSE;
}

IoSetCompletionRoutine(irp,
IrpCompletionRoutine,
(PVOID)Context,
TRUE,
TRUE,
TRUE);

IoCallDriver(volume->UnderlyingPdo, irp);

return TRUE;
}


Don’t miss your chance to WIN 10 hours of private jet travel from Microsoft
Office Live http://clk.atdmt.com/MRT/go/mcrssaub0540002499mrt/direct/01/