Author: arty
Date: Mon Sep 1 10:19:13 2008
New Revision: 35859
URL:
http://svn.reactos.org/svn/reactos?rev=35859&view=rev
Log:
Enable and fix up lazy write thread, reattach completion routine for
simple read and write functions. Fat write works, and produces a correct
volume.
Modified:
branches/arty-newcc/ntoskrnl/cache/cachesub.c
branches/arty-newcc/ntoskrnl/cache/fssup.c
branches/arty-newcc/ntoskrnl/cache/lazyrite.c
branches/arty-newcc/ntoskrnl/cache/pinsup.c
branches/arty-newcc/ntoskrnl/mm/section.c
Modified: branches/arty-newcc/ntoskrnl/cache/cachesub.c
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/cache/cache…
==============================================================================
--- branches/arty-newcc/ntoskrnl/cache/cachesub.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/cache/cachesub.c [iso-8859-1] Mon Sep 1 10:19:13 2008
@@ -23,6 +23,32 @@
NTSTATUS
NTAPI
+CcpSimpleWriteComplete
+(PDEVICE_OBJECT DeviceObject,
+ PIRP Irp,
+ PVOID Context)
+{
+ /* Unlock MDL Pages, page 167. */
+ PMDL Mdl = Irp->MdlAddress;
+ while (Mdl)
+ {
+ MmUnlockPages(Mdl);
+ Mdl = Mdl->Next;
+ }
+
+ /* Check if there's an MDL */
+ while ((Mdl = Irp->MdlAddress))
+ {
+ /* Clear all of them */
+ Irp->MdlAddress = Mdl->Next;
+ IoFreeMdl(Mdl);
+ }
+
+ return STATUS_SUCCESS;
+}
+
+NTSTATUS
+NTAPI
CcpSimpleWrite
(PFILE_OBJECT FileObject,
PLARGE_INTEGER FileOffset,
@@ -71,12 +97,13 @@
Irp->Flags |= IRP_PAGING_IO | IRP_SYNCHRONOUS_PAGING_IO | IRP_NOCACHE;
ObReferenceObject(FileObject);
-
+
Irp->UserEvent = &ReadWait;
Irp->Tail.Overlay.OriginalFileObject = FileObject;
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
IrpSp = IoGetNextIrpStackLocation(Irp);
IrpSp->FileObject = FileObject;
+ IrpSp->CompletionRoutine = CcpSimpleWriteComplete;
Status = IoCallDriver(DeviceObject, Irp);
if (Status == STATUS_PENDING)
@@ -182,6 +209,7 @@
PNOCC_BCB Bcb;
LARGE_INTEGER ToWrite = *FileOffset;
IO_STATUS_BLOCK IOSB;
+ PNOCC_CACHE_MAP Map = (PNOCC_CACHE_MAP)SectionObjectPointer->SharedCacheMap;
if (!SectionObjectPointer->SharedCacheMap)
{
@@ -194,15 +222,17 @@
}
BOOLEAN Result = CcpMapData
- ((PNOCC_CACHE_MAP)SectionObjectPointer->SharedCacheMap,
+ (Map,
FileOffset,
Length,
PIN_WAIT,
(PVOID *)&Bcb,
&Buffer);
- if (!Result) return;
-
+ /* Don't flush a pinned bcb, because we'll disturb the locked-ness
+ * of the pages. Figured out how to do this right. */
+ if (!Result || Bcb->Pinned || !Bcb->Dirty) return;
+
BufStart = (PCHAR)PAGE_ROUND_DOWN(((ULONG_PTR)Buffer));
ToWrite.LowPart = PAGE_ROUND_DOWN(FileOffset->LowPart);
@@ -220,20 +250,19 @@
ToWrite.QuadPart += PAGE_SIZE;
}
- DPRINT
- ("Page Write: %08x\n", IOSB.Status);
-
- CcUnpinData(Bcb);
+ Bcb->Dirty = FALSE;
+
+ DPRINT("Page Write: %08x\n", IOSB.Status);
if (IoStatus && NT_SUCCESS(IOSB.Status))
{
- IoStatus->Status = STATUS_SUCCESS;
- IoStatus->Information = Length;
+ IoStatus->Status = STATUS_SUCCESS;
+ IoStatus->Information = Length;
}
else if (IoStatus)
{
- IoStatus->Status = IOSB.Status;
- IoStatus->Information = 0;
+ IoStatus->Status = IOSB.Status;
+ IoStatus->Information = 0;
}
}
Modified: branches/arty-newcc/ntoskrnl/cache/fssup.c
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/cache/fssup…
==============================================================================
--- branches/arty-newcc/ntoskrnl/cache/fssup.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/cache/fssup.c [iso-8859-1] Mon Sep 1 10:19:13 2008
@@ -59,7 +59,6 @@
KEBUGCHECK(0);
}
-#if 0
Status = PsCreateSystemThread
(&CcLazyWriteThreadHandle,
THREAD_ALL_ACCESS,
@@ -68,7 +67,6 @@
&CcLazyWriteThreadId,
(PKSTART_ROUTINE) CcpLazyWriteThread,
NULL);
-#endif
if (!NT_SUCCESS(Status))
{
Modified: branches/arty-newcc/ntoskrnl/cache/lazyrite.c
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/cache/lazyr…
==============================================================================
--- branches/arty-newcc/ntoskrnl/cache/lazyrite.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/cache/lazyrite.c [iso-8859-1] Mon Sep 1 10:19:13 2008
@@ -22,7 +22,7 @@
CcpLazyWriteThread(PVOID Unused)
{
ULONG i;
- BOOLEAN GotLock;
+ BOOLEAN GotLock, WasAlloc;
PNOCC_BCB RealBcb;
LARGE_INTEGER Interval;
IO_STATUS_BLOCK IoStatus;
@@ -34,7 +34,12 @@
RealBcb = &CcCacheSections[i];
CcpLock(&CcMutex);
GotLock = RealBcb->RefCount == 1;
- if (GotLock) RealBcb->RefCount++;
+ WasAlloc = RtlTestBit(CcCacheBitmap, i);
+ if (GotLock)
+ {
+ RtlSetBit(CcCacheBitmap, i);
+ RealBcb->RefCount++;
+ }
CcpUnlock(&CcMutex);
// Pinned (temporarily)
if (GotLock)
@@ -51,12 +56,15 @@
IoStatus.Status,
IoStatus.Information);
- CcUnpinData(RealBcb);
+ CcpLock(&CcMutex);
+ RealBcb->RefCount--;
+ if (!WasAlloc) RtlClearBit(CcCacheBitmap, i);
+ CcpUnlock(&CcMutex);
DPRINT("CcpLazyWrite: done #%x\n", i);
}
}
KeSetEvent(&CcpLazyWriteEvent, IO_DISK_INCREMENT, TRUE);
- Interval.QuadPart = -1000000L;
+ Interval.QuadPart = -100000000L;
KeDelayExecutionThread(KernelMode, FALSE, &Interval);
}
}
Modified: branches/arty-newcc/ntoskrnl/cache/pinsup.c
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/cache/pinsu…
==============================================================================
--- branches/arty-newcc/ntoskrnl/cache/pinsup.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/cache/pinsup.c [iso-8859-1] Mon Sep 1 10:19:13 2008
@@ -691,6 +691,7 @@
{
IoFreeMdl(TheBcb->Pinned);
TheBcb->Pinned = NULL;
+ TheBcb->Dirty = TRUE;
Result = FALSE;
}
_SEH_END;
Modified: branches/arty-newcc/ntoskrnl/mm/section.c
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/mm/section.…
==============================================================================
--- branches/arty-newcc/ntoskrnl/mm/section.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/mm/section.c [iso-8859-1] Mon Sep 1 10:19:13 2008
@@ -183,6 +183,7 @@
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
IrpSp = IoGetNextIrpStackLocation(Irp);
IrpSp->FileObject = FileObject;
+ IrpSp->CompletionRoutine = MiSimpleReadComplete;
Status = IoCallDriver(DeviceObject, Irp);
if (Status == STATUS_PENDING)
@@ -267,6 +268,7 @@
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
IrpSp = IoGetNextIrpStackLocation(Irp);
IrpSp->FileObject = FileObject;
+ IrpSp->CompletionRoutine = MiSimpleReadComplete;
Status = IoCallDriver(DeviceObject, Irp);
if (Status == STATUS_PENDING)