[NTOSKRNL] Add an helper for marking a VACB clean (ie, not dirty).
authorPierre Schweitzer <pierre@reactos.org>
Thu, 1 Feb 2018 07:35:27 +0000 (08:35 +0100)
committerPierre Schweitzer <pierre@reactos.org>
Thu, 1 Feb 2018 07:36:17 +0000 (08:36 +0100)
CORE-14263

ntoskrnl/cc/fs.c
ntoskrnl/cc/view.c
ntoskrnl/include/internal/cc.h

index 9e9ff1a..38c9ae5 100644 (file)
@@ -233,9 +233,7 @@ CcPurgeCacheSection (
         RemoveEntryList(&Vacb->VacbLruListEntry);
         if (Vacb->Dirty)
         {
-            RemoveEntryList(&Vacb->DirtyVacbListEntry);
-            CcTotalDirtyPages -= VACB_MAPPING_GRANULARITY / PAGE_SIZE;
-            Vacb->SharedCacheMap->DirtyPages -= VACB_MAPPING_GRANULARITY / PAGE_SIZE;
+            CcRosUnmarkDirtyVacb(Vacb, FALSE);
         }
         RemoveEntryList(&Vacb->CacheMapVacbListEntry);
         InsertHeadList(&FreeList, &Vacb->CacheMapVacbListEntry);
index 003c5d8..f66f230 100644 (file)
@@ -167,22 +167,11 @@ CcRosFlushVacb (
     PROS_VACB Vacb)
 {
     NTSTATUS Status;
-    KIRQL oldIrql;
 
     Status = CcWriteVirtualAddress(Vacb);
     if (NT_SUCCESS(Status))
     {
-        KeAcquireGuardedMutex(&ViewLock);
-        KeAcquireSpinLock(&Vacb->SharedCacheMap->CacheMapLock, &oldIrql);
-
-        Vacb->Dirty = FALSE;
-        RemoveEntryList(&Vacb->DirtyVacbListEntry);
-        CcTotalDirtyPages -= VACB_MAPPING_GRANULARITY / PAGE_SIZE;
-        Vacb->SharedCacheMap->DirtyPages -= VACB_MAPPING_GRANULARITY / PAGE_SIZE;
-        CcRosVacbDecRefCount(Vacb);
-
-        KeReleaseSpinLock(&Vacb->SharedCacheMap->CacheMapLock, oldIrql);
-        KeReleaseGuardedMutex(&ViewLock);
+        CcRosUnmarkDirtyVacb(Vacb, TRUE);
     }
 
     return Status;
@@ -619,6 +608,39 @@ CcRosMarkDirtyVacb (
     KeReleaseGuardedMutex(&ViewLock);
 }
 
+VOID
+NTAPI
+CcRosUnmarkDirtyVacb (
+    PROS_VACB Vacb,
+    BOOLEAN LockViews)
+{
+    KIRQL oldIrql;
+    PROS_SHARED_CACHE_MAP SharedCacheMap;
+
+    SharedCacheMap = Vacb->SharedCacheMap;
+
+    if (LockViews)
+    {
+        KeAcquireGuardedMutex(&ViewLock);
+        KeAcquireSpinLock(&SharedCacheMap->CacheMapLock, &oldIrql);
+    }
+
+    ASSERT(Vacb->Dirty);
+
+    Vacb->Dirty = FALSE;
+
+    RemoveEntryList(&Vacb->DirtyVacbListEntry);
+    CcTotalDirtyPages -= VACB_MAPPING_GRANULARITY / PAGE_SIZE;
+    Vacb->SharedCacheMap->DirtyPages -= VACB_MAPPING_GRANULARITY / PAGE_SIZE;
+    CcRosVacbDecRefCount(Vacb);
+
+    if (LockViews)
+    {
+        KeReleaseSpinLock(&SharedCacheMap->CacheMapLock, oldIrql);
+        KeReleaseGuardedMutex(&ViewLock);
+    }
+}
+
 NTSTATUS
 NTAPI
 CcRosMarkDirtyFile (
@@ -1132,9 +1154,9 @@ CcRosDeleteFileCache (
             RemoveEntryList(&current->VacbLruListEntry);
             if (current->Dirty)
             {
-                RemoveEntryList(&current->DirtyVacbListEntry);
-                CcTotalDirtyPages -= VACB_MAPPING_GRANULARITY / PAGE_SIZE;
-                current->SharedCacheMap->DirtyPages -= VACB_MAPPING_GRANULARITY / PAGE_SIZE;
+                KeAcquireSpinLock(&SharedCacheMap->CacheMapLock, &oldIrql);
+                CcRosUnmarkDirtyVacb(current, FALSE);
+                KeReleaseSpinLock(&SharedCacheMap->CacheMapLock, oldIrql);
                 DPRINT1("Freeing dirty VACB\n");
             }
             InsertHeadList(&FreeList, &current->CacheMapVacbListEntry);
index 949fe7d..3787563 100644 (file)
@@ -300,6 +300,12 @@ NTAPI
 CcRosMarkDirtyVacb(
     PROS_VACB Vacb);
 
+VOID
+NTAPI
+CcRosUnmarkDirtyVacb(
+    PROS_VACB Vacb,
+    BOOLEAN LockViews);
+
 NTSTATUS
 NTAPI
 CcRosFlushDirtyPages(