Author: pschweitzer Date: Sat Oct 10 12:50:33 2015 New Revision: 69483
URL: http://svn.reactos.org/svn/reactos?rev=69483&view=rev Log: [MSFS] Fix a FIXME: properly reset timer when re-using a queued IRP for reading. Also fix a possible race condition between time out DPC and IRP re-use.
Thanks to Thomas for his help with DPC & timers.
CORE-10245
Modified: trunk/reactos/drivers/filesystems/msfs/msfs.h trunk/reactos/drivers/filesystems/msfs/msfssup.c trunk/reactos/drivers/filesystems/msfs/rw.c
Modified: trunk/reactos/drivers/filesystems/msfs/msfs.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/msfs/ms... ============================================================================== --- trunk/reactos/drivers/filesystems/msfs/msfs.h [iso-8859-1] (original) +++ trunk/reactos/drivers/filesystems/msfs/msfs.h [iso-8859-1] Sat Oct 10 12:50:33 2015 @@ -46,6 +46,7 @@ KTIMER Timer; KDPC Dpc; PIO_CSQ Csq; + KEVENT Event; IO_CSQ_IRP_CONTEXT CsqContext; } MSFS_DPC_CTX, *PMSFS_DPC_CTX;
Modified: trunk/reactos/drivers/filesystems/msfs/msfssup.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/msfs/ms... ============================================================================== --- trunk/reactos/drivers/filesystems/msfs/msfssup.c [iso-8859-1] (original) +++ trunk/reactos/drivers/filesystems/msfs/msfssup.c [iso-8859-1] Sat Oct 10 12:50:33 2015 @@ -117,14 +117,20 @@
Context = (PMSFS_DPC_CTX)DeferredContext;
+ /* Try to get the IRP */ Irp = IoCsqRemoveIrp(Context->Csq, &Context->CsqContext); if (Irp != NULL) { + /* It timed out, complete it (it's ours) and free context */ Irp->IoStatus.Status = STATUS_IO_TIMEOUT; IoCompleteRequest(Irp, IO_NO_INCREMENT); + ExFreePoolWithTag(Context, 'NFsM'); } - - ExFreePool(Context); + else + { + /* We were racing with writing and failed, signal we're done */ + KeSetEvent(&Context->Event, IO_NO_INCREMENT, FALSE); + } }
/* EOF */
Modified: trunk/reactos/drivers/filesystems/msfs/rw.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/msfs/rw... ============================================================================== --- trunk/reactos/drivers/filesystems/msfs/rw.c [iso-8859-1] (original) +++ trunk/reactos/drivers/filesystems/msfs/rw.c [iso-8859-1] Sat Oct 10 12:50:33 2015 @@ -107,10 +107,12 @@ return STATUS_INSUFFICIENT_RESOURCES; }
+ KeInitializeEvent(&Context->Event, SynchronizationEvent, FALSE); IoCsqInsertIrp(&Fcb->CancelSafeQueue, Irp, &Context->CsqContext); Timer = &Context->Timer; Dpc = &Context->Dpc; Context->Csq = &Fcb->CancelSafeQueue; + Irp->Tail.Overlay.DriverContext[0] = Context;
/* No timer for INFINITY_WAIT */ if (Timeout.QuadPart != -1) @@ -139,6 +141,7 @@ ULONG Length; PVOID Buffer; PIRP CsqIrp; + PMSFS_DPC_CTX Context;
DPRINT("MsfsWrite(DeviceObject %p Irp %p)\n", DeviceObject, Irp);
@@ -193,7 +196,16 @@ CsqIrp = IoCsqRemoveNextIrp(&Fcb->CancelSafeQueue, NULL); if (CsqIrp != NULL) { - /* FIXME: It is necessary to reset the timers. */ + /* Get the context */ + Context = CsqIrp->Tail.Overlay.DriverContext[0]; + /* DPC was queued, wait for it to fail (IRP is ours) */ + if (Fcb->TimeOut.QuadPart != -1 && !KeCancelTimer(&Context->Timer)) + { + KeWaitForSingleObject(&Context->Event, Executive, KernelMode, FALSE, NULL); + } + + /* Free context & attempt read */ + ExFreePoolWithTag(Context, 'NFsM'); MsfsRead(DeviceObject, CsqIrp); }