Skip to content

Commit

Permalink
[NTOS:CC] Fix usage of FsRtlAcquireFileForCcFlushEx
Browse files Browse the repository at this point in the history
CcRosFlushVacb: Also add a comment about the reason for calling CcRosUnmarkDirtyVacb before flush.
  • Loading branch information
TAN-Gaming committed Nov 22, 2024
1 parent e3c859e commit cb56cff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
36 changes: 16 additions & 20 deletions ntoskrnl/cc/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,33 +164,20 @@ CcRosFlushVacb (
_Out_opt_ PIO_STATUS_BLOCK Iosb)
{
NTSTATUS Status;
BOOLEAN HaveLock = FALSE;
PROS_SHARED_CACHE_MAP SharedCacheMap = Vacb->SharedCacheMap;

/* Unmark dirty first, and then write. This will avoid trying to flush
* twice a dirty VACB under high IOs pressure. */
CcRosUnmarkDirtyVacb(Vacb, TRUE);

/* Lock for flush, if we are not already the top-level */
if (IoGetTopLevelIrp() != (PIRP)FSRTL_CACHE_TOP_LEVEL_IRP)
{
Status = FsRtlAcquireFileForCcFlushEx(Vacb->SharedCacheMap->FileObject);
if (!NT_SUCCESS(Status))
goto quit;
HaveLock = TRUE;
}

Status = MmFlushSegment(SharedCacheMap->FileObject->SectionObjectPointer,
&Vacb->FileOffset,
VACB_MAPPING_GRANULARITY,
Iosb);

if (HaveLock)
{
FsRtlReleaseFileForCcFlush(Vacb->SharedCacheMap->FileObject);
}

quit:
if (!NT_SUCCESS(Status))
{
CcRosMarkDirtyVacb(Vacb);
}
else
{
/* Update VDL */
Expand Down Expand Up @@ -1108,6 +1095,7 @@ CcFlushCache (
PROS_SHARED_CACHE_MAP SharedCacheMap;
LONGLONG FlushStart, FlushEnd;
NTSTATUS Status;
BOOLEAN HaveFileLock = FALSE;

CCTRACE(CC_API_DEBUG, "SectionObjectPointers=%p FileOffset=0x%I64X Length=%lu\n",
SectionObjectPointers, FileOffset ? FileOffset->QuadPart : 0LL, Length);
Expand Down Expand Up @@ -1146,7 +1134,15 @@ CcFlushCache (
IoStatus->Information = 0;
}

KeAcquireGuardedMutex(&SharedCacheMap->FlushCacheLock);
/* Lock for flush, if we are not already the top-level */
if (IoGetTopLevelIrp() != (PIRP)FSRTL_CACHE_TOP_LEVEL_IRP)
{
Status = FsRtlAcquireFileForCcFlushEx(SharedCacheMap->FileObject);
if (!NT_SUCCESS(Status))
goto quit;

HaveFileLock = TRUE;
}

/*
* We flush the VACBs that we find here.
Expand Down Expand Up @@ -1217,7 +1213,8 @@ CcFlushCache (
FlushStart -= FlushStart % VACB_MAPPING_GRANULARITY;
}

KeReleaseGuardedMutex(&SharedCacheMap->FlushCacheLock);
if (HaveFileLock)
FsRtlReleaseFileForCcFlush(SharedCacheMap->FileObject);

quit:
if (IoStatus)
Expand Down Expand Up @@ -1327,7 +1324,6 @@ CcRosInitializeFileCache (
KeInitializeSpinLock(&SharedCacheMap->CacheMapLock);
InitializeListHead(&SharedCacheMap->CacheMapVacbListHead);
InitializeListHead(&SharedCacheMap->BcbList);
KeInitializeGuardedMutex(&SharedCacheMap->FlushCacheLock);

SharedCacheMap->Flags = SHARED_CACHE_MAP_IN_CREATION;

Expand Down
1 change: 0 additions & 1 deletion ntoskrnl/include/internal/cc.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ typedef struct _ROS_SHARED_CACHE_MAP
LIST_ENTRY CacheMapVacbListHead;
BOOLEAN PinAccess;
KSPIN_LOCK CacheMapLock;
KGUARDED_MUTEX FlushCacheLock;
#if DBG
BOOLEAN Trace; /* enable extra trace output for this cache map and it's VACBs */
#endif
Expand Down

0 comments on commit cb56cff

Please sign in to comment.