mirror of
https://github.com/reactos/reactos.git
synced 2025-06-13 09:18:30 +00:00
[NTOS:CC] Simplify CcRosDeleteFileCache
This commit is contained in:
parent
a9193b5cc2
commit
33cde28312
1 changed files with 70 additions and 81 deletions
|
@ -974,105 +974,94 @@ CcRosDeleteFileCache (
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
PLIST_ENTRY current_entry;
|
PLIST_ENTRY current_entry;
|
||||||
PROS_VACB current;
|
|
||||||
LIST_ENTRY FreeList;
|
|
||||||
|
|
||||||
ASSERT(SharedCacheMap);
|
ASSERT(SharedCacheMap);
|
||||||
|
ASSERT(SharedCacheMap == FileObject->SectionObjectPointer->SharedCacheMap);
|
||||||
|
ASSERT(SharedCacheMap->OpenCount == 0);
|
||||||
|
|
||||||
SharedCacheMap->OpenCount++;
|
/* Remove all VACBs from the global lists */
|
||||||
|
KeAcquireSpinLockAtDpcLevel(&SharedCacheMap->CacheMapLock);
|
||||||
|
current_entry = SharedCacheMap->CacheMapVacbListHead.Flink;
|
||||||
|
while (current_entry != &SharedCacheMap->CacheMapVacbListHead)
|
||||||
|
{
|
||||||
|
PROS_VACB Vacb = CONTAINING_RECORD(current_entry, ROS_VACB, CacheMapVacbListEntry);
|
||||||
|
|
||||||
|
RemoveEntryList(&Vacb->VacbLruListEntry);
|
||||||
|
InitializeListHead(&Vacb->VacbLruListEntry);
|
||||||
|
|
||||||
|
if (Vacb->Dirty)
|
||||||
|
{
|
||||||
|
CcRosUnmarkDirtyVacb(Vacb, FALSE);
|
||||||
|
/* Mark it as dirty again so we know that we have to flush before freeing it */
|
||||||
|
Vacb->Dirty = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
current_entry = current_entry->Flink;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make sure there is no trace anymore of this map */
|
||||||
|
FileObject->SectionObjectPointer->SharedCacheMap = NULL;
|
||||||
|
RemoveEntryList(&SharedCacheMap->SharedCacheMapLinks);
|
||||||
|
|
||||||
|
KeReleaseSpinLockFromDpcLevel(&SharedCacheMap->CacheMapLock);
|
||||||
KeReleaseQueuedSpinLock(LockQueueMasterLock, *OldIrql);
|
KeReleaseQueuedSpinLock(LockQueueMasterLock, *OldIrql);
|
||||||
|
|
||||||
CcFlushCache(FileObject->SectionObjectPointer, NULL, 0, NULL);
|
/* Now that we're out of the locks, free everything for real */
|
||||||
|
while (!IsListEmpty(&SharedCacheMap->CacheMapVacbListHead))
|
||||||
*OldIrql = KeAcquireQueuedSpinLock(LockQueueMasterLock);
|
|
||||||
SharedCacheMap->OpenCount--;
|
|
||||||
if (SharedCacheMap->OpenCount == 0)
|
|
||||||
{
|
{
|
||||||
FileObject->SectionObjectPointer->SharedCacheMap = NULL;
|
PROS_VACB Vacb = CONTAINING_RECORD(RemoveHeadList(&SharedCacheMap->CacheMapVacbListHead), ROS_VACB, CacheMapVacbListEntry);
|
||||||
|
ULONG RefCount;
|
||||||
|
|
||||||
/*
|
InitializeListHead(&Vacb->CacheMapVacbListEntry);
|
||||||
* Release all VACBs
|
|
||||||
*/
|
/* Flush to disk, if needed */
|
||||||
InitializeListHead(&FreeList);
|
if (Vacb->Dirty)
|
||||||
KeAcquireSpinLockAtDpcLevel(&SharedCacheMap->CacheMapLock);
|
|
||||||
while (!IsListEmpty(&SharedCacheMap->CacheMapVacbListHead))
|
|
||||||
{
|
{
|
||||||
current_entry = RemoveTailList(&SharedCacheMap->CacheMapVacbListHead);
|
SIZE_T FlushSize = min(VACB_MAPPING_GRANULARITY, Vacb->SharedCacheMap->SectionSize.QuadPart - Vacb->FileOffset.QuadPart);
|
||||||
KeReleaseSpinLockFromDpcLevel(&SharedCacheMap->CacheMapLock);
|
IO_STATUS_BLOCK Iosb;
|
||||||
|
NTSTATUS Status;
|
||||||
|
|
||||||
current = CONTAINING_RECORD(current_entry, ROS_VACB, CacheMapVacbListEntry);
|
Status = MmFlushVirtualMemory(NULL, &Vacb->BaseAddress, &FlushSize, &Iosb);
|
||||||
RemoveEntryList(¤t->VacbLruListEntry);
|
if (!NT_SUCCESS(Status))
|
||||||
InitializeListHead(¤t->VacbLruListEntry);
|
|
||||||
if (current->Dirty)
|
|
||||||
{
|
{
|
||||||
KeAcquireSpinLockAtDpcLevel(&SharedCacheMap->CacheMapLock);
|
/* Complain. There's not much we can do */
|
||||||
CcRosUnmarkDirtyVacb(current, FALSE);
|
DPRINT1("Failed to flush VACB to disk while deleting the cache entry. Status: 0x%08x\n", Status);
|
||||||
KeReleaseSpinLockFromDpcLevel(&SharedCacheMap->CacheMapLock);
|
|
||||||
DPRINT1("Freeing dirty VACB\n");
|
|
||||||
}
|
}
|
||||||
if (current->MappedCount != 0)
|
Vacb->Dirty = FALSE;
|
||||||
{
|
|
||||||
current->MappedCount = 0;
|
|
||||||
NT_VERIFY(CcRosVacbDecRefCount(current) > 0);
|
|
||||||
DPRINT1("Freeing mapped VACB\n");
|
|
||||||
}
|
|
||||||
InsertHeadList(&FreeList, ¤t->CacheMapVacbListEntry);
|
|
||||||
|
|
||||||
KeAcquireSpinLockAtDpcLevel(&SharedCacheMap->CacheMapLock);
|
|
||||||
}
|
}
|
||||||
#if DBG
|
|
||||||
SharedCacheMap->Trace = FALSE;
|
|
||||||
#endif
|
|
||||||
KeReleaseSpinLockFromDpcLevel(&SharedCacheMap->CacheMapLock);
|
|
||||||
|
|
||||||
KeReleaseQueuedSpinLock(LockQueueMasterLock, *OldIrql);
|
RefCount = CcRosVacbDecRefCount(Vacb);
|
||||||
if(SharedCacheMap->Section)
|
|
||||||
ObDereferenceObject(SharedCacheMap->Section);
|
|
||||||
ObDereferenceObject(SharedCacheMap->FileObject);
|
|
||||||
|
|
||||||
while (!IsListEmpty(&FreeList))
|
|
||||||
{
|
|
||||||
ULONG Refs;
|
|
||||||
|
|
||||||
current_entry = RemoveTailList(&FreeList);
|
|
||||||
current = CONTAINING_RECORD(current_entry, ROS_VACB, CacheMapVacbListEntry);
|
|
||||||
InitializeListHead(¤t->CacheMapVacbListEntry);
|
|
||||||
Refs = CcRosVacbDecRefCount(current);
|
|
||||||
#if DBG // CORE-14578
|
#if DBG // CORE-14578
|
||||||
if (Refs != 0)
|
if (RefCount != 0)
|
||||||
|
{
|
||||||
|
DPRINT1("Leaking VACB %p attached to %p (%I64d)\n", Vacb, FileObject, Vacb->FileOffset.QuadPart);
|
||||||
|
DPRINT1("There are: %d references left\n", RefCount);
|
||||||
|
DPRINT1("Map: %d\n", Vacb->MappedCount);
|
||||||
|
DPRINT1("Dirty: %d\n", Vacb->Dirty);
|
||||||
|
if (FileObject->FileName.Length != 0)
|
||||||
{
|
{
|
||||||
DPRINT1("Leaking VACB %p attached to %p (%I64d)\n", current, FileObject, current->FileOffset.QuadPart);
|
DPRINT1("File was: %wZ\n", &FileObject->FileName);
|
||||||
DPRINT1("There are: %d references left\n", Refs);
|
}
|
||||||
DPRINT1("Map: %d\n", current->MappedCount);
|
else
|
||||||
DPRINT1("Dirty: %d\n", current->Dirty);
|
{
|
||||||
if (FileObject->FileName.Length != 0)
|
DPRINT1("No name for the file\n");
|
||||||
{
|
|
||||||
DPRINT1("File was: %wZ\n", &FileObject->FileName);
|
|
||||||
}
|
|
||||||
else if (FileObject->FsContext != NULL &&
|
|
||||||
((PFSRTL_COMMON_FCB_HEADER)(FileObject->FsContext))->NodeTypeCode == 0x0502 &&
|
|
||||||
((PFSRTL_COMMON_FCB_HEADER)(FileObject->FsContext))->NodeByteSize == 0x1F8 &&
|
|
||||||
((PUNICODE_STRING)(((PUCHAR)FileObject->FsContext) + 0x100))->Length != 0)
|
|
||||||
{
|
|
||||||
DPRINT1("File was: %wZ (FastFAT)\n", (PUNICODE_STRING)(((PUCHAR)FileObject->FsContext) + 0x100));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DPRINT1("No name for the file\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
ASSERT(Refs == 0);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
*OldIrql = KeAcquireQueuedSpinLock(LockQueueMasterLock);
|
(void)RefCount;
|
||||||
RemoveEntryList(&SharedCacheMap->SharedCacheMapLinks);
|
#endif
|
||||||
KeReleaseQueuedSpinLock(LockQueueMasterLock, *OldIrql);
|
|
||||||
|
|
||||||
ExFreeToNPagedLookasideList(&SharedCacheMapLookasideList, SharedCacheMap);
|
|
||||||
*OldIrql = KeAcquireQueuedSpinLock(LockQueueMasterLock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Release the references we own */
|
||||||
|
if(SharedCacheMap->Section)
|
||||||
|
ObDereferenceObject(SharedCacheMap->Section);
|
||||||
|
ObDereferenceObject(SharedCacheMap->FileObject);
|
||||||
|
|
||||||
|
ExFreeToNPagedLookasideList(&SharedCacheMapLookasideList, SharedCacheMap);
|
||||||
|
|
||||||
|
/* Acquire the lock again for our caller */
|
||||||
|
*OldIrql = KeAcquireQueuedSpinLock(LockQueueMasterLock);
|
||||||
|
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue