Author: tfaber Date: Sun Sep 29 20:52:23 2013 New Revision: 60456
URL: http://svn.reactos.org/svn/reactos?rev=60456&view=rev Log: [NTOS:CC] - Simplify cache segment range checks - Remove unused function CcRosFreeCacheSegment - Minor style fixes CORE-7491
Modified: trunk/reactos/ntoskrnl/cc/copy.c trunk/reactos/ntoskrnl/cc/fs.c trunk/reactos/ntoskrnl/cc/pin.c trunk/reactos/ntoskrnl/cc/view.c trunk/reactos/ntoskrnl/include/internal/cc.h
Modified: trunk/reactos/ntoskrnl/cc/copy.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/cc/copy.c?rev=6045... ============================================================================== --- trunk/reactos/ntoskrnl/cc/copy.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/cc/copy.c [iso-8859-1] Sun Sep 29 20:52:23 2013 @@ -355,13 +355,16 @@ if (!Wait) { KeAcquireSpinLock(&Bcb->BcbLock, &oldirql); + /* FIXME: this loop doesn't take into account areas that don't have + * a segment in the list yet */ current_entry = Bcb->BcbSegmentListHead.Flink; while (current_entry != &Bcb->BcbSegmentListHead) { current = CONTAINING_RECORD(current_entry, CACHE_SEGMENT, BcbSegmentListEntry); - if (!current->Valid && current->FileOffset < ReadOffset + Length - && current->FileOffset + Bcb->CacheSegmentSize > ReadOffset) + if (!current->Valid && + DoSegmentsIntersect(current->FileOffset, Bcb->CacheSegmentSize, + ReadOffset, Length)) { KeReleaseSpinLock(&Bcb->BcbLock, oldirql); IoStatus->Status = STATUS_UNSUCCESSFUL; @@ -466,23 +469,20 @@ { /* testing, if the requested datas are available */ KeAcquireSpinLock(&Bcb->BcbLock, &oldirql); + /* FIXME: this loop doesn't take into account areas that don't have + * a segment in the list yet */ current_entry = Bcb->BcbSegmentListHead.Flink; while (current_entry != &Bcb->BcbSegmentListHead) { CacheSeg = CONTAINING_RECORD(current_entry, CACHE_SEGMENT, BcbSegmentListEntry); - if (!CacheSeg->Valid) - { - if (((WriteOffset >= CacheSeg->FileOffset) && - (WriteOffset < CacheSeg->FileOffset + Bcb->CacheSegmentSize)) - || ((WriteOffset + Length > CacheSeg->FileOffset) && - (WriteOffset + Length <= CacheSeg->FileOffset + - Bcb->CacheSegmentSize))) - { - KeReleaseSpinLock(&Bcb->BcbLock, oldirql); - /* datas not available */ - return FALSE; - } + if (!CacheSeg->Valid && + DoSegmentsIntersect(CacheSeg->FileOffset, Bcb->CacheSegmentSize, + WriteOffset, Length)) + { + KeReleaseSpinLock(&Bcb->BcbLock, oldirql); + /* datas not available */ + return FALSE; } current_entry = current_entry->Flink; } @@ -687,23 +687,20 @@ { /* testing, if the requested datas are available */ KeAcquireSpinLock(&Bcb->BcbLock, &oldirql); + /* FIXME: this loop doesn't take into account areas that don't have + * a segment in the list yet */ current_entry = Bcb->BcbSegmentListHead.Flink; while (current_entry != &Bcb->BcbSegmentListHead) { CacheSeg = CONTAINING_RECORD(current_entry, CACHE_SEGMENT, BcbSegmentListEntry); - if (!CacheSeg->Valid) + if (!CacheSeg->Valid && + DoSegmentsIntersect(CacheSeg->FileOffset, Bcb->CacheSegmentSize, + WriteOffset.u.LowPart, Length)) { - if (((WriteOffset.u.LowPart >= CacheSeg->FileOffset) && - (WriteOffset.u.LowPart < CacheSeg->FileOffset + Bcb->CacheSegmentSize)) - || ((WriteOffset.u.LowPart + Length > CacheSeg->FileOffset) && - (WriteOffset.u.LowPart + Length <= - CacheSeg->FileOffset + Bcb->CacheSegmentSize))) - { - KeReleaseSpinLock(&Bcb->BcbLock, oldirql); - /* datas not available */ - return FALSE; - } + KeReleaseSpinLock(&Bcb->BcbLock, oldirql); + /* datas not available */ + return FALSE; } current_entry = current_entry->Flink; }
Modified: trunk/reactos/ntoskrnl/cc/fs.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/cc/fs.c?rev=60456&... ============================================================================== --- trunk/reactos/ntoskrnl/cc/fs.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/cc/fs.c [iso-8859-1] Sun Sep 29 20:52:23 2013 @@ -159,7 +159,9 @@ current_entry = Bcb->BcbSegmentListHead.Flink; while (current_entry != &Bcb->BcbSegmentListHead) { - current = CONTAINING_RECORD(current_entry, CACHE_SEGMENT, BcbSegmentListEntry); + current = CONTAINING_RECORD(current_entry, + CACHE_SEGMENT, + BcbSegmentListEntry); current_entry = current_entry->Flink; if (current->FileOffset > FileSizes->AllocationSize.QuadPart || (current->FileOffset == 0 && FileSizes->AllocationSize.QuadPart == 0))
Modified: trunk/reactos/ntoskrnl/cc/pin.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/cc/pin.c?rev=60456... ============================================================================== --- trunk/reactos/ntoskrnl/cc/pin.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/cc/pin.c [iso-8859-1] Sun Sep 29 20:52:23 2013 @@ -261,7 +261,7 @@ { IoStatus->Status = STATUS_SUCCESS; } - KeReleaseMutex(&iBcb->CacheSegment->Mutex, 0); + KeReleaseMutex(&iBcb->CacheSegment->Mutex, FALSE); } else {
Modified: trunk/reactos/ntoskrnl/cc/view.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/cc/view.c?rev=6045... ============================================================================== --- trunk/reactos/ntoskrnl/cc/view.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/cc/view.c [iso-8859-1] Sun Sep 29 20:52:23 2013 @@ -236,7 +236,7 @@ /* One reference is added above */ if (current->ReferenceCount > 2) { - KeReleaseMutex(¤t->Mutex, 0); + KeReleaseMutex(¤t->Mutex, FALSE); current->Bcb->Callbacks->ReleaseFromLazyWrite( current->Bcb->LazyWriteContext); CcRosCacheSegmentDecRefCount(current); @@ -249,7 +249,7 @@
Status = CcRosFlushCacheSegment(current);
- KeReleaseMutex(¤t->Mutex, 0); + KeReleaseMutex(¤t->Mutex, FALSE); current->Bcb->Callbacks->ReleaseFromLazyWrite( current->Bcb->LazyWriteContext);
@@ -446,7 +446,7 @@
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql); KeReleaseGuardedMutex(&ViewLock); - KeReleaseMutex(&CacheSeg->Mutex, 0); + KeReleaseMutex(&CacheSeg->Mutex, FALSE);
return(STATUS_SUCCESS); } @@ -474,8 +474,8 @@ { current = CONTAINING_RECORD(current_entry, CACHE_SEGMENT, BcbSegmentListEntry); - if ((current->FileOffset <= FileOffset) && - ((current->FileOffset + Bcb->CacheSegmentSize) > FileOffset)) + if (IsPointInSegment(current->FileOffset, Bcb->CacheSegmentSize, + FileOffset)) { CcRosCacheSegmentIncRefCount(current); KeReleaseSpinLock(&Bcb->BcbLock, oldIrql); @@ -485,7 +485,7 @@ KernelMode, FALSE, NULL); - return(current); + return current; } current_entry = current_entry->Flink; } @@ -493,7 +493,7 @@ KeReleaseSpinLock(&Bcb->BcbLock, oldIrql); KeReleaseGuardedMutex(&ViewLock);
- return(NULL); + return NULL; }
NTSTATUS @@ -536,7 +536,7 @@
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql); KeReleaseGuardedMutex(&ViewLock); - KeReleaseMutex(&CacheSeg->Mutex, 0); + KeReleaseMutex(&CacheSeg->Mutex, FALSE);
return(STATUS_SUCCESS); } @@ -589,7 +589,7 @@
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql); KeReleaseGuardedMutex(&ViewLock); - KeReleaseMutex(&CacheSeg->Mutex, 0); + KeReleaseMutex(&CacheSeg->Mutex, FALSE);
return(STATUS_SUCCESS); } @@ -659,8 +659,8 @@ { current = CONTAINING_RECORD(current_entry, CACHE_SEGMENT, BcbSegmentListEntry); - if (current->FileOffset <= FileOffset && - (current->FileOffset + Bcb->CacheSegmentSize) > FileOffset) + if (IsPointInSegment(current->FileOffset, Bcb->CacheSegmentSize, + FileOffset)) { CcRosCacheSegmentIncRefCount(current); KeReleaseSpinLock(&Bcb->BcbLock, oldIrql); @@ -673,7 +673,7 @@ current ); } #endif - KeReleaseMutex(&(*CacheSeg)->Mutex, 0); + KeReleaseMutex(&(*CacheSeg)->Mutex, FALSE); KeReleaseGuardedMutex(&ViewLock); ExFreeToNPagedLookasideList(&CacheSegLookasideList, *CacheSeg); *CacheSeg = current; @@ -996,38 +996,6 @@ return(STATUS_SUCCESS); }
-NTSTATUS -NTAPI -CcRosFreeCacheSegment ( - PBCB Bcb, - PCACHE_SEGMENT CacheSeg) -{ - NTSTATUS Status; - KIRQL oldIrql; - - ASSERT(Bcb); - - DPRINT("CcRosFreeCacheSegment(Bcb 0x%p, CacheSeg 0x%p)\n", - Bcb, CacheSeg); - - KeAcquireGuardedMutex(&ViewLock); - KeAcquireSpinLock(&Bcb->BcbLock, &oldIrql); - RemoveEntryList(&CacheSeg->BcbSegmentListEntry); - RemoveEntryList(&CacheSeg->CacheSegmentListEntry); - RemoveEntryList(&CacheSeg->CacheSegmentLRUListEntry); - if (CacheSeg->Dirty) - { - RemoveEntryList(&CacheSeg->DirtySegmentListEntry); - DirtyPageCount -= Bcb->CacheSegmentSize / PAGE_SIZE; - - } - KeReleaseSpinLock(&Bcb->BcbLock, oldIrql); - KeReleaseGuardedMutex(&ViewLock); - - Status = CcRosInternalFreeCacheSegment(CacheSeg); - return(Status); -} - /* * @implemented */ @@ -1081,7 +1049,7 @@ IoStatus->Status = Status; } } - KeReleaseMutex(¤t->Mutex, 0); + KeReleaseMutex(¤t->Mutex, FALSE);
KeAcquireGuardedMutex(&ViewLock); KeAcquireSpinLock(&Bcb->BcbLock, &oldIrql); @@ -1148,7 +1116,6 @@ */ InitializeListHead(&FreeList); KeAcquireSpinLock(&Bcb->BcbLock, &oldIrql); - current_entry = Bcb->BcbSegmentListHead.Flink; while (!IsListEmpty(&Bcb->BcbSegmentListHead)) { current_entry = RemoveTailList(&Bcb->BcbSegmentListHead);
Modified: trunk/reactos/ntoskrnl/include/internal/cc.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/c... ============================================================================== --- trunk/reactos/ntoskrnl/include/internal/cc.h [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/include/internal/cc.h [iso-8859-1] Sun Sep 29 20:52:23 2013 @@ -205,13 +205,6 @@
NTSTATUS NTAPI -CcRosFreeCacheSegment( - PBCB, - PCACHE_SEGMENT -); - -NTSTATUS -NTAPI ReadCacheSegment(PCACHE_SEGMENT CacheSeg);
NTSTATUS @@ -315,3 +308,28 @@ NTSTATUS NTAPI CcTryToInitializeFileCache(PFILE_OBJECT FileObject); + +FORCEINLINE +BOOLEAN +DoSegmentsIntersect( + _In_ ULONG Offset1, + _In_ ULONG Length1, + _In_ ULONG Offset2, + _In_ ULONG Length2) +{ + if (Offset1 + Length1 <= Offset2) + return FALSE; + if (Offset2 + Length2 <= Offset1) + return FALSE; + return TRUE; +} + +FORCEINLINE +BOOLEAN +IsPointInSegment( + _In_ ULONG Offset1, + _In_ ULONG Length1, + _In_ ULONG Point) +{ + return DoSegmentsIntersect(Offset1, Length1, Point, 1); +}