[NTOSKRNL]
authorPierre Schweitzer <pierre@reactos.org>
Mon, 23 May 2016 19:47:39 +0000 (19:47 +0000)
committerPierre Schweitzer <pierre@reactos.org>
Mon, 23 May 2016 19:47:39 +0000 (19:47 +0000)
In Cc, replace the Vacb mutex by a Bcb resource.
Note that the resource is still placed in the Vacb by it belongs to the Bcb.
This is required to really implement CcSetBcbOwnerPointer().

CORE-11310

svn path=/trunk/; revision=71387

reactos/ntoskrnl/cc/pin.c
reactos/ntoskrnl/cc/view.c
reactos/ntoskrnl/include/internal/cc.h
reactos/ntoskrnl/mm/section.c

index ebde601..0c8b672 100644 (file)
@@ -290,11 +290,7 @@ CcUnpinRepinnedBcb (
         IoStatus->Information = 0;
         if (WriteThrough)
         {
-            KeWaitForSingleObject(&iBcb->Vacb->Mutex,
-                                  Executive,
-                                  KernelMode,
-                                  FALSE,
-                                  NULL);
+            ExAcquireResourceExclusiveLite(&iBcb->Vacb->Lock, TRUE);
             if (iBcb->Vacb->Dirty)
             {
                 IoStatus->Status = CcRosFlushVacb(iBcb->Vacb);
@@ -303,7 +299,7 @@ CcUnpinRepinnedBcb (
             {
                 IoStatus->Status = STATUS_SUCCESS;
             }
-            KeReleaseMutex(&iBcb->Vacb->Mutex, FALSE);
+            ExReleaseResourceLite(&iBcb->Vacb->Lock);
         }
         else
         {
index fb8e8f1..70fb7ce 100644 (file)
@@ -166,12 +166,10 @@ CcRosFlushDirtyPages (
     PROS_VACB current;
     BOOLEAN Locked;
     NTSTATUS Status;
-    LARGE_INTEGER ZeroTimeout;
 
     DPRINT("CcRosFlushDirtyPages(Target %lu)\n", Target);
 
     (*Count) = 0;
-    ZeroTimeout.QuadPart = 0;
 
     KeEnterCriticalRegion();
     KeAcquireGuardedMutex(&ViewLock);
@@ -199,12 +197,8 @@ CcRosFlushDirtyPages (
             continue;
         }
 
-        Status = KeWaitForSingleObject(&current->Mutex,
-                                       Executive,
-                                       KernelMode,
-                                       FALSE,
-                                       Wait ? NULL : &ZeroTimeout);
-        if (Status != STATUS_SUCCESS)
+        Locked = ExAcquireResourceExclusiveLite(&current->Lock, Wait);
+        if (!Locked)
         {
             current->SharedCacheMap->Callbacks->ReleaseFromLazyWrite(
                 current->SharedCacheMap->LazyWriteContext);
@@ -217,7 +211,7 @@ CcRosFlushDirtyPages (
         /* One reference is added above */
         if (current->ReferenceCount > 2)
         {
-            KeReleaseMutex(&current->Mutex, FALSE);
+            ExReleaseResourceLite(&current->Lock);
             current->SharedCacheMap->Callbacks->ReleaseFromLazyWrite(
                 current->SharedCacheMap->LazyWriteContext);
             CcRosVacbDecRefCount(current);
@@ -228,7 +222,7 @@ CcRosFlushDirtyPages (
 
         Status = CcRosFlushVacb(current);
 
-        KeReleaseMutex(&current->Mutex, FALSE);
+        ExReleaseResourceLite(&current->Lock);
         current->SharedCacheMap->Callbacks->ReleaseFromLazyWrite(
             current->SharedCacheMap->LazyWriteContext);
 
@@ -425,7 +419,7 @@ CcRosReleaseVacb (
 
     KeReleaseSpinLock(&SharedCacheMap->CacheMapLock, oldIrql);
     KeReleaseGuardedMutex(&ViewLock);
-    KeReleaseMutex(&Vacb->Mutex, FALSE);
+    ExReleaseResourceLite(&Vacb->Lock);
 
     return STATUS_SUCCESS;
 }
@@ -462,11 +456,7 @@ CcRosLookupVacb (
             CcRosVacbIncRefCount(current);
             KeReleaseSpinLock(&SharedCacheMap->CacheMapLock, oldIrql);
             KeReleaseGuardedMutex(&ViewLock);
-            KeWaitForSingleObject(&current->Mutex,
-                                  Executive,
-                                  KernelMode,
-                                  FALSE,
-                                  NULL);
+            ExAcquireResourceExclusiveLite(&current->Lock, TRUE);
             return current;
         }
         if (current->FileOffset.QuadPart > FileOffset)
@@ -521,7 +511,7 @@ CcRosMarkDirtyVacb (
 
     KeReleaseSpinLock(&SharedCacheMap->CacheMapLock, oldIrql);
     KeReleaseGuardedMutex(&ViewLock);
-    KeReleaseMutex(&Vacb->Mutex, FALSE);
+    ExReleaseResourceLite(&Vacb->Lock);
 
     return STATUS_SUCCESS;
 }
@@ -574,7 +564,7 @@ CcRosUnmapVacb (
 
     KeReleaseSpinLock(&SharedCacheMap->CacheMapLock, oldIrql);
     KeReleaseGuardedMutex(&ViewLock);
-    KeReleaseMutex(&Vacb->Mutex, FALSE);
+    ExReleaseResourceLite(&Vacb->Lock);
 
     return STATUS_SUCCESS;
 }
@@ -675,12 +665,8 @@ CcRosCreateVacb (
     current->DirtyVacbListEntry.Flink = NULL;
     current->DirtyVacbListEntry.Blink = NULL;
     current->ReferenceCount = 1;
-    KeInitializeMutex(&current->Mutex, 0);
-    KeWaitForSingleObject(&current->Mutex,
-                          Executive,
-                          KernelMode,
-                          FALSE,
-                          NULL);
+    ExInitializeResourceLite(&current->Lock);
+    ExAcquireResourceExclusiveLite(&current->Lock, TRUE);
     KeAcquireGuardedMutex(&ViewLock);
 
     *Vacb = current;
@@ -712,15 +698,11 @@ CcRosCreateVacb (
                         current);
             }
 #endif
-            KeReleaseMutex(&(*Vacb)->Mutex, FALSE);
+            ExReleaseResourceLite(&(*Vacb)->Lock);
             KeReleaseGuardedMutex(&ViewLock);
             ExFreeToNPagedLookasideList(&VacbLookasideList, *Vacb);
             *Vacb = current;
-            KeWaitForSingleObject(&current->Mutex,
-                                  Executive,
-                                  KernelMode,
-                                  FALSE,
-                                  NULL);
+            ExAcquireResourceExclusiveLite(&current->Lock, TRUE);
             return STATUS_SUCCESS;
         }
         if (current->FileOffset.QuadPart < FileOffset)
@@ -886,6 +868,7 @@ CcRosInternalFreeVacb (
                      CcFreeCachePage,
                      NULL);
     MmUnlockAddressSpace(MmGetKernelAddressSpace());
+    ExDeleteResourceLite(&Vacb->Lock);
 
     ExFreeToNPagedLookasideList(&VacbLookasideList, Vacb);
     return STATUS_SUCCESS;
@@ -949,7 +932,7 @@ CcFlushCache (
                         IoStatus->Status = Status;
                     }
                 }
-                KeReleaseMutex(&current->Mutex, FALSE);
+                ExReleaseResourceLite(&current->Lock);
 
                 KeAcquireGuardedMutex(&ViewLock);
                 KeAcquireSpinLock(&SharedCacheMap->CacheMapLock, &oldIrql);
index 5d95e6a..f0e28c0 100644 (file)
@@ -164,6 +164,8 @@ typedef struct _ROS_VACB
     PVOID BaseAddress;
     /* Memory area representing the region where the view's data is mapped. */
     struct _MEMORY_AREA* MemoryArea;
+    /* Lock */
+    ERESOURCE Lock;
     /* Are the contents of the view valid. */
     BOOLEAN Valid;
     /* Are the contents of the view newer than those on disk. */
@@ -179,8 +181,6 @@ typedef struct _ROS_VACB
     LIST_ENTRY VacbLruListEntry;
     /* Offset in the file which this view maps. */
     LARGE_INTEGER FileOffset;
-    /* Mutex */
-    KMUTEX Mutex;
     /* Number of references. */
     ULONG ReferenceCount;
     /* Pointer to the shared cache map for the file which this view maps data for. */
index 7ece609..4943dab 100644 (file)
@@ -1110,6 +1110,7 @@ MiReadPage(PMEMORY_AREA MemoryArea,
          * filesystems do because it is safe for us to use an offset with an
          * alignment less than the file system block size.
          */
+        KeEnterCriticalRegion();
         Status = CcRosGetVacb(SharedCacheMap,
                               FileOffset,
                               &BaseOffset,
@@ -1118,6 +1119,7 @@ MiReadPage(PMEMORY_AREA MemoryArea,
                               &Vacb);
         if (!NT_SUCCESS(Status))
         {
+            KeLeaveCriticalRegion();
             return(Status);
         }
         if (!UptoDate)
@@ -1130,6 +1132,7 @@ MiReadPage(PMEMORY_AREA MemoryArea,
             if (!NT_SUCCESS(Status))
             {
                 CcRosReleaseVacb(SharedCacheMap, Vacb, FALSE, FALSE, FALSE);
+                KeLeaveCriticalRegion();
                 return Status;
             }
         }
@@ -1144,6 +1147,7 @@ MiReadPage(PMEMORY_AREA MemoryArea,
                                        FileOffset - BaseOffset).LowPart >> PAGE_SHIFT;
 
         CcRosReleaseVacb(SharedCacheMap, Vacb, TRUE, FALSE, TRUE);
+        KeLeaveCriticalRegion();
     }
     else
     {
@@ -1163,6 +1167,7 @@ MiReadPage(PMEMORY_AREA MemoryArea,
         {
             return(Status);
         }
+        KeEnterCriticalRegion();
         Status = CcRosGetVacb(SharedCacheMap,
                               FileOffset,
                               &BaseOffset,
@@ -1171,6 +1176,7 @@ MiReadPage(PMEMORY_AREA MemoryArea,
                               &Vacb);
         if (!NT_SUCCESS(Status))
         {
+            KeLeaveCriticalRegion();
             return(Status);
         }
         if (!UptoDate)
@@ -1183,6 +1189,7 @@ MiReadPage(PMEMORY_AREA MemoryArea,
             if (!NT_SUCCESS(Status))
             {
                 CcRosReleaseVacb(SharedCacheMap, Vacb, FALSE, FALSE, FALSE);
+                KeLeaveCriticalRegion();
                 return Status;
             }
         }
@@ -1212,6 +1219,7 @@ MiReadPage(PMEMORY_AREA MemoryArea,
                                   &Vacb);
             if (!NT_SUCCESS(Status))
             {
+                KeLeaveCriticalRegion();
                 return(Status);
             }
             if (!UptoDate)
@@ -1224,6 +1232,7 @@ MiReadPage(PMEMORY_AREA MemoryArea,
                 if (!NT_SUCCESS(Status))
                 {
                     CcRosReleaseVacb(SharedCacheMap, Vacb, FALSE, FALSE, FALSE);
+                    KeLeaveCriticalRegion();
                     return Status;
                 }
             }
@@ -1239,6 +1248,7 @@ MiReadPage(PMEMORY_AREA MemoryArea,
         }
         MiUnmapPageInHyperSpace(Process, PageAddr, Irql);
         CcRosReleaseVacb(SharedCacheMap, Vacb, TRUE, FALSE, FALSE);
+        KeLeaveCriticalRegion();
     }
     return(STATUS_SUCCESS);
 }
@@ -3232,10 +3242,12 @@ ExeFmtpReadFile(IN PVOID File,
     BufferSize = PAGE_ROUND_UP(BufferSize);
 
     /* Flush data since we're about to perform a non-cached read */
+    KeEnterCriticalRegion();
     CcFlushCache(FileObject->SectionObjectPointer,
                  &FileOffset,
                  BufferSize,
                  &Iosb);
+    KeLeaveCriticalRegion();
 
     /*
      * It's ok to use paged pool, because this is a temporary buffer only used in