[NTOS:CC]

- Simplify cache segment range checks
- Remove unused function CcRosFreeCacheSegment
- Minor style fixes
CORE-7491

svn path=/trunk/; revision=60456
This commit is contained in:
Thomas Faber 2013-09-29 20:52:23 +00:00
parent e0b9f8f6af
commit 0df89bb1e8
5 changed files with 63 additions and 79 deletions

View file

@ -355,13 +355,16 @@ CcCopyRead (
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 @@ CcCopyWrite (
{
/* 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, Length))
{
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;
}
KeReleaseSpinLock(&Bcb->BcbLock, oldirql);
/* datas not available */
return FALSE;
}
current_entry = current_entry->Flink;
}
@ -687,23 +687,20 @@ CcZeroData (
{
/* 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;
}

View file

@ -159,7 +159,9 @@ CcSetFileSizes (
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))

View file

@ -261,7 +261,7 @@ CcUnpinRepinnedBcb (
{
IoStatus->Status = STATUS_SUCCESS;
}
KeReleaseMutex(&iBcb->CacheSegment->Mutex, 0);
KeReleaseMutex(&iBcb->CacheSegment->Mutex, FALSE);
}
else
{

View file

@ -236,7 +236,7 @@ CcRosFlushDirtyPages (
/* One reference is added above */
if (current->ReferenceCount > 2)
{
KeReleaseMutex(&current->Mutex, 0);
KeReleaseMutex(&current->Mutex, FALSE);
current->Bcb->Callbacks->ReleaseFromLazyWrite(
current->Bcb->LazyWriteContext);
CcRosCacheSegmentDecRefCount(current);
@ -249,7 +249,7 @@ CcRosFlushDirtyPages (
Status = CcRosFlushCacheSegment(current);
KeReleaseMutex(&current->Mutex, 0);
KeReleaseMutex(&current->Mutex, FALSE);
current->Bcb->Callbacks->ReleaseFromLazyWrite(
current->Bcb->LazyWriteContext);
@ -446,7 +446,7 @@ CcRosReleaseCacheSegment (
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
KeReleaseGuardedMutex(&ViewLock);
KeReleaseMutex(&CacheSeg->Mutex, 0);
KeReleaseMutex(&CacheSeg->Mutex, FALSE);
return(STATUS_SUCCESS);
}
@ -474,8 +474,8 @@ CcRosLookupCacheSegment (
{
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 @@ CcRosLookupCacheSegment (
KernelMode,
FALSE,
NULL);
return(current);
return current;
}
current_entry = current_entry->Flink;
}
@ -493,7 +493,7 @@ CcRosLookupCacheSegment (
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
KeReleaseGuardedMutex(&ViewLock);
return(NULL);
return NULL;
}
NTSTATUS
@ -536,7 +536,7 @@ CcRosMarkDirtyCacheSegment (
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
KeReleaseGuardedMutex(&ViewLock);
KeReleaseMutex(&CacheSeg->Mutex, 0);
KeReleaseMutex(&CacheSeg->Mutex, FALSE);
return(STATUS_SUCCESS);
}
@ -589,7 +589,7 @@ CcRosUnmapCacheSegment (
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
KeReleaseGuardedMutex(&ViewLock);
KeReleaseMutex(&CacheSeg->Mutex, 0);
KeReleaseMutex(&CacheSeg->Mutex, FALSE);
return(STATUS_SUCCESS);
}
@ -659,8 +659,8 @@ CcRosCreateCacheSegment (
{
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 @@ CcRosCreateCacheSegment (
current );
}
#endif
KeReleaseMutex(&(*CacheSeg)->Mutex, 0);
KeReleaseMutex(&(*CacheSeg)->Mutex, FALSE);
KeReleaseGuardedMutex(&ViewLock);
ExFreeToNPagedLookasideList(&CacheSegLookasideList, *CacheSeg);
*CacheSeg = current;
@ -996,38 +996,6 @@ CcRosInternalFreeCacheSegment (
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 @@ CcFlushCache (
IoStatus->Status = Status;
}
}
KeReleaseMutex(&current->Mutex, 0);
KeReleaseMutex(&current->Mutex, FALSE);
KeAcquireGuardedMutex(&ViewLock);
KeAcquireSpinLock(&Bcb->BcbLock, &oldIrql);
@ -1148,7 +1116,6 @@ CcRosDeleteFileCache (
*/
InitializeListHead(&FreeList);
KeAcquireSpinLock(&Bcb->BcbLock, &oldIrql);
current_entry = Bcb->BcbSegmentListHead.Flink;
while (!IsListEmpty(&Bcb->BcbSegmentListHead))
{
current_entry = RemoveTailList(&Bcb->BcbSegmentListHead);

View file

@ -203,13 +203,6 @@ VOID
NTAPI
CcInitView(VOID);
NTSTATUS
NTAPI
CcRosFreeCacheSegment(
PBCB,
PCACHE_SEGMENT
);
NTSTATUS
NTAPI
ReadCacheSegment(PCACHE_SEGMENT CacheSeg);
@ -315,3 +308,28 @@ CcRosReleaseFileCache(
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);
}