From 0132307d9b6ce2e5d30069e2e80ccc7e15321388 Mon Sep 17 00:00:00 2001 From: Aleksey Bragin Date: Sat, 8 Mar 2008 16:47:41 +0000 Subject: [PATCH] - Experimentally switch fastfat driver to non-Ros Cc functions, and thus no FSD in ReactOS are using CcRos-specific functions anymore. - Assume VACB_MAPPING_GRANULARITY as a default cache segment size. - Use FSD callbacks instead of direct accessing FCB's MainResource via FileObject/FsContext. This allows removing of ObReferenceObject(FileObject) which I had to add some time ago in order to keep FileObject alive for the lazy writer thread. - IMPORTANT: Testers should thoroughly try this revision in order to see if any new problems appear. If they do appear, this revision will most probably be reverted by me. svn path=/trunk/; revision=32612 --- reactos/drivers/filesystems/fastfat/cleanup.c | 8 -- reactos/drivers/filesystems/fastfat/fcb.c | 17 ---- reactos/drivers/filesystems/fastfat/fsctl.c | 17 +--- reactos/drivers/filesystems/fastfat/rw.c | 14 --- reactos/ntoskrnl/cc/fs.c | 3 +- reactos/ntoskrnl/cc/view.c | 89 ++++++++++--------- reactos/ntoskrnl/include/internal/cc.h | 2 + reactos/ntoskrnl/ntoskrnl_i386.def | 2 +- 8 files changed, 51 insertions(+), 101 deletions(-) diff --git a/reactos/drivers/filesystems/fastfat/cleanup.c b/reactos/drivers/filesystems/fastfat/cleanup.c index ed5298bcc27..466412cec81 100644 --- a/reactos/drivers/filesystems/fastfat/cleanup.c +++ b/reactos/drivers/filesystems/fastfat/cleanup.c @@ -78,11 +78,7 @@ VfatCleanupFile(PVFAT_IRP_CONTEXT IrpContext) if (tmpFileObject != NULL) { pFcb->FileObject = NULL; -#ifdef USE_ROS_CC_AND_FS - CcRosReleaseFileCache(tmpFileObject); -#else CcUninitializeCacheMap(tmpFileObject, NULL, NULL); -#endif ObDereferenceObject(tmpFileObject); } @@ -94,14 +90,10 @@ VfatCleanupFile(PVFAT_IRP_CONTEXT IrpContext) #endif } /* Uninitialize file cache if. */ -#ifdef USE_ROS_CC_AND_FS - CcRosReleaseFileCache (FileObject); -#else if (FileObject->SectionObjectPointer->SharedCacheMap) { CcUninitializeCacheMap (FileObject, &pFcb->RFCB.FileSize, NULL); } -#endif if (pFcb->OpenHandleCount != 0) { IoRemoveShareAccess(FileObject, &pFcb->FCBShareAccess); diff --git a/reactos/drivers/filesystems/fastfat/fcb.c b/reactos/drivers/filesystems/fastfat/fcb.c index 43f7d3c2368..f42d3a62b62 100644 --- a/reactos/drivers/filesystems/fastfat/fcb.c +++ b/reactos/drivers/filesystems/fastfat/fcb.c @@ -314,10 +314,6 @@ vfatGrabFCBFromTable(PDEVICE_EXTENSION pVCB, PUNICODE_STRING PathNameU) static NTSTATUS vfatFCBInitializeCacheFromVolume (PVCB vcb, PVFATFCB fcb) { -#ifdef USE_ROS_CC_AND_FS - NTSTATUS status; - ULONG fileCacheQuantum; -#endif PFILE_OBJECT fileObject; PVFATCCB newCCB; @@ -336,25 +332,12 @@ vfatFCBInitializeCacheFromVolume (PVCB vcb, PVFATFCB fcb) fcb->FileObject = fileObject; fcb->RefCount++; -#ifdef USE_ROS_CC_AND_FS - fileCacheQuantum = (vcb->FatInfo.BytesPerCluster >= PAGE_SIZE) ? - vcb->FatInfo.BytesPerCluster : PAGE_SIZE; - - status = CcRosInitializeFileCache (fileObject, - fileCacheQuantum); - if (!NT_SUCCESS (status)) - { - DbgPrint ("CcRosInitializeFileCache failed\n"); - KEBUGCHECK (0); - } -#else /* FIXME: Guard by SEH. */ CcInitializeCacheMap(fileObject, (PCC_FILE_SIZES)(&fcb->RFCB.AllocationSize), FALSE, &VfatGlobalData->CacheMgrCallbacks, fcb); -#endif fcb->Flags |= FCB_CACHE_INITIALIZED; return STATUS_SUCCESS; diff --git a/reactos/drivers/filesystems/fastfat/fsctl.c b/reactos/drivers/filesystems/fastfat/fsctl.c index 1684175646e..08a7cbd280d 100644 --- a/reactos/drivers/filesystems/fastfat/fsctl.c +++ b/reactos/drivers/filesystems/fastfat/fsctl.c @@ -534,28 +534,13 @@ VfatMount (PVFAT_IRP_CONTEXT IrpContext) Fcb->RFCB.ValidDataLength = Fcb->RFCB.FileSize; Fcb->RFCB.AllocationSize = Fcb->RFCB.FileSize; -#ifdef USE_ROS_CC_AND_FS - if (DeviceExt->FatInfo.FatType != FAT12) - { - Status = CcRosInitializeFileCache(DeviceExt->FATFileObject, CACHEPAGESIZE(DeviceExt)); - } - else - { - Status = CcRosInitializeFileCache(DeviceExt->FATFileObject, 2 * PAGE_SIZE); - } - if (!NT_SUCCESS (Status)) - { - DPRINT1 ("CcRosInitializeFileCache failed\n"); - goto ByeBye; - } -#else /* FIXME: Guard by SEH. */ CcInitializeCacheMap(DeviceExt->FATFileObject, (PCC_FILE_SIZES)(&Fcb->RFCB.AllocationSize), FALSE, &VfatGlobalData->CacheMgrCallbacks, Fcb); -#endif + DeviceExt->LastAvailableCluster = 2; ExInitializeResourceLite(&DeviceExt->DirResource); ExInitializeResourceLite(&DeviceExt->FatResource); diff --git a/reactos/drivers/filesystems/fastfat/rw.c b/reactos/drivers/filesystems/fastfat/rw.c index 0f806fe108b..dfb12ffe661 100644 --- a/reactos/drivers/filesystems/fastfat/rw.c +++ b/reactos/drivers/filesystems/fastfat/rw.c @@ -671,19 +671,12 @@ VfatRead(PVFAT_IRP_CONTEXT IrpContext) CHECKPOINT; if (IrpContext->FileObject->PrivateCacheMap == NULL) { -#ifdef USE_ROS_CC_AND_FS - ULONG CacheSize; - CacheSize = max(IrpContext->DeviceExt->FatInfo.BytesPerCluster, - 8 * PAGE_SIZE); - CcRosInitializeFileCache(IrpContext->FileObject, CacheSize); -#else /* FIXME: Guard by SEH. */ CcInitializeCacheMap(IrpContext->FileObject, (PCC_FILE_SIZES)(&Fcb->RFCB.AllocationSize), FALSE, &(VfatGlobalData->CacheMgrCallbacks), Fcb); -#endif } if (!CcCopyRead(IrpContext->FileObject, &ByteOffset, Length, (BOOLEAN)(IrpContext->Flags & IRPCONTEXT_CANWAIT), Buffer, @@ -972,19 +965,12 @@ NTSTATUS VfatWrite (PVFAT_IRP_CONTEXT IrpContext) if (IrpContext->FileObject->PrivateCacheMap == NULL) { -#ifdef USE_ROS_CC_AND_FS - ULONG CacheSize; - CacheSize = max(IrpContext->DeviceExt->FatInfo.BytesPerCluster, - 8 * PAGE_SIZE); - CcRosInitializeFileCache(IrpContext->FileObject, CacheSize); -#else /* FIXME: Guard by SEH. */ CcInitializeCacheMap(IrpContext->FileObject, (PCC_FILE_SIZES)(&Fcb->RFCB.AllocationSize), FALSE, &VfatGlobalData->CacheMgrCallbacks, Fcb); -#endif } if (ByteOffset.QuadPart > OldFileSize.QuadPart) { diff --git a/reactos/ntoskrnl/cc/fs.c b/reactos/ntoskrnl/cc/fs.c index a0e7c1c1ab4..8c32bf7adb0 100644 --- a/reactos/ntoskrnl/cc/fs.c +++ b/reactos/ntoskrnl/cc/fs.c @@ -92,7 +92,8 @@ CcInitializeCacheMap ( /* Call old ROS cache init function */ CcRosInitializeFileCache(FileObject, - PAGE_SIZE/*VACB_MAPPING_GRANULARITY*/); + /*PAGE_SIZE*/ VACB_MAPPING_GRANULARITY, CallBacks, + LazyWriterContext); } /* diff --git a/reactos/ntoskrnl/cc/view.c b/reactos/ntoskrnl/cc/view.c index c8a319803f5..6c034bb2fde 100644 --- a/reactos/ntoskrnl/cc/view.c +++ b/reactos/ntoskrnl/cc/view.c @@ -238,23 +238,19 @@ CcRosFlushDirtyPages(ULONG Target, PULONG Count) DirtySegmentListEntry); current_entry = current_entry->Flink; - /* This Ros-specific function needs FileObject to be referenced, - ohterwise it may be deleted while this function still works - with it */ - ObReferenceObject(current->Bcb->FileObject); - - Locked = ExTryToAcquireResourceExclusiveLite(((FSRTL_COMMON_FCB_HEADER*)(current->Bcb->FileObject->FsContext))->Resource); + Locked = current->Bcb->Callbacks->AcquireForLazyWrite( + current->Bcb->LazyWriteContext, FALSE); if (!Locked) { - ObDereferenceObject(current->Bcb->FileObject); continue; } Locked = ExTryToAcquirePushLockExclusive(¤t->Lock); if (!Locked) { - ExReleaseResourceLite(((FSRTL_COMMON_FCB_HEADER*)(current->Bcb->FileObject->FsContext))->Resource); - ObDereferenceObject(current->Bcb->FileObject); + current->Bcb->Callbacks->ReleaseFromLazyWrite( + current->Bcb->LazyWriteContext); + continue; } @@ -262,20 +258,20 @@ CcRosFlushDirtyPages(ULONG Target, PULONG Count) if (current->ReferenceCount > 1) { ExReleasePushLock(¤t->Lock); - ExReleaseResourceLite(((FSRTL_COMMON_FCB_HEADER*)(current->Bcb->FileObject->FsContext))->Resource); - ObDereferenceObject(current->Bcb->FileObject); + current->Bcb->Callbacks->ReleaseFromLazyWrite( + current->Bcb->LazyWriteContext); continue; } PagesPerSegment = current->Bcb->CacheSegmentSize / PAGE_SIZE; KeReleaseGuardedMutex(&ViewLock); - + Status = CcRosFlushCacheSegment(current); ExReleasePushLock(¤t->Lock); - ExReleaseResourceLite(((FSRTL_COMMON_FCB_HEADER*)(current->Bcb->FileObject->FsContext))->Resource); - ObDereferenceObject(current->Bcb->FileObject); + current->Bcb->Callbacks->ReleaseFromLazyWrite( + current->Bcb->LazyWriteContext); if (!NT_SUCCESS(Status) && (Status != STATUS_END_OF_FILE)) { @@ -711,7 +707,7 @@ CcRosCreateCacheSegment(PBCB Bcb, KEBUGCHECKCC; } #endif - Pfn = alloca(sizeof(PFN_TYPE) * (Bcb->CacheSegmentSize / PAGE_SIZE)); + Pfn = alloca(sizeof(PFN_TYPE) * ((Bcb->CacheSegmentSize / PAGE_SIZE))); for (i = 0; i < (Bcb->CacheSegmentSize / PAGE_SIZE); i++) { Status = MmRequestPageMemoryConsumer(MC_CACHE, TRUE, &Pfn[i]); @@ -729,6 +725,7 @@ CcRosCreateCacheSegment(PBCB Bcb, { KEBUGCHECKCC; } + return(STATUS_SUCCESS); } @@ -1259,9 +1256,11 @@ CcTryToInitializeFileCache(PFILE_OBJECT FileObject) } -NTSTATUS STDCALL +NTSTATUS NTAPI CcRosInitializeFileCache(PFILE_OBJECT FileObject, - ULONG CacheSegmentSize) + ULONG CacheSegmentSize, + PCACHE_MANAGER_CALLBACKS CallBacks, + PVOID LazyWriterContext) /* * FUNCTION: Initializes a BCB for a file object */ @@ -1275,39 +1274,41 @@ CcRosInitializeFileCache(PFILE_OBJECT FileObject, KeAcquireGuardedMutex(&ViewLock); if (Bcb == NULL) { - Bcb = ExAllocateFromNPagedLookasideList(&BcbLookasideList); - if (Bcb == NULL) - { - KeReleaseGuardedMutex(&ViewLock); - return(STATUS_UNSUCCESSFUL); - } - memset(Bcb, 0, sizeof(BCB)); - ObReferenceObjectByPointer(FileObject, - FILE_ALL_ACCESS, - NULL, - KernelMode); - Bcb->FileObject = FileObject; - Bcb->CacheSegmentSize = CacheSegmentSize; - if (FileObject->FsContext) - { - Bcb->AllocationSize = - ((PFSRTL_COMMON_FCB_HEADER)FileObject->FsContext)->AllocationSize; - Bcb->FileSize = - ((PFSRTL_COMMON_FCB_HEADER)FileObject->FsContext)->FileSize; - } - KeInitializeSpinLock(&Bcb->BcbLock); - InitializeListHead(&Bcb->BcbSegmentListHead); - FileObject->SectionObjectPointer->SharedCacheMap = Bcb; + Bcb = ExAllocateFromNPagedLookasideList(&BcbLookasideList); + if (Bcb == NULL) + { + KeReleaseGuardedMutex(&ViewLock); + return(STATUS_UNSUCCESSFUL); + } + memset(Bcb, 0, sizeof(BCB)); + ObReferenceObjectByPointer(FileObject, + FILE_ALL_ACCESS, + NULL, + KernelMode); + Bcb->FileObject = FileObject; + Bcb->CacheSegmentSize = CacheSegmentSize; + Bcb->Callbacks = CallBacks; + Bcb->LazyWriteContext = LazyWriterContext; + if (FileObject->FsContext) + { + Bcb->AllocationSize = + ((PFSRTL_COMMON_FCB_HEADER)FileObject->FsContext)->AllocationSize; + Bcb->FileSize = + ((PFSRTL_COMMON_FCB_HEADER)FileObject->FsContext)->FileSize; + } + KeInitializeSpinLock(&Bcb->BcbLock); + InitializeListHead(&Bcb->BcbSegmentListHead); + FileObject->SectionObjectPointer->SharedCacheMap = Bcb; } if (FileObject->PrivateCacheMap == NULL) { - FileObject->PrivateCacheMap = Bcb; - Bcb->RefCount++; + FileObject->PrivateCacheMap = Bcb; + Bcb->RefCount++; } if (Bcb->BcbRemoveListEntry.Flink != NULL) { - RemoveEntryList(&Bcb->BcbRemoveListEntry); - Bcb->BcbRemoveListEntry.Flink = NULL; + RemoveEntryList(&Bcb->BcbRemoveListEntry); + Bcb->BcbRemoveListEntry.Flink = NULL; } KeReleaseGuardedMutex(&ViewLock); diff --git a/reactos/ntoskrnl/include/internal/cc.h b/reactos/ntoskrnl/include/internal/cc.h index c5d74a68893..c1ab3cffbd9 100644 --- a/reactos/ntoskrnl/include/internal/cc.h +++ b/reactos/ntoskrnl/include/internal/cc.h @@ -112,6 +112,8 @@ typedef struct _BCB ULONG CacheSegmentSize; LARGE_INTEGER AllocationSize; LARGE_INTEGER FileSize; + PCACHE_MANAGER_CALLBACKS Callbacks; + PVOID LazyWriteContext; KSPIN_LOCK BcbLock; ULONG RefCount; #if defined(DBG) || defined(KDBG) diff --git a/reactos/ntoskrnl/ntoskrnl_i386.def b/reactos/ntoskrnl/ntoskrnl_i386.def index 229ce899b14..e5aa98234ea 100644 --- a/reactos/ntoskrnl/ntoskrnl_i386.def +++ b/reactos/ntoskrnl/ntoskrnl_i386.def @@ -5,7 +5,7 @@ ; ReactOS Operating System ; EXPORTS -CcRosInitializeFileCache@8 +CcRosInitializeFileCache CcRosReleaseFileCache@4 CcRosTraceCacheMap@8 CcCanIWrite@16