Windows: Correctly mark extents dirty when using the non-persistent AFS
authorPeter Scott <pscott@kerneldrivers.com>
Wed, 18 Jan 2012 19:04:29 +0000 (12:04 -0700)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Wed, 18 Jan 2012 22:54:02 +0000 (14:54 -0800)
cache

Change-Id: I9e03264bb94fe6494f1ca3721e4d7c7faf469fb5
Reviewed-on: http://gerrit.openafs.org/6571
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@secure-endpoints.com>
Tested-by: Jeffrey Altman <jaltman@secure-endpoints.com>

src/WINNT/afsrdr/kernel/lib/AFSExtentsSupport.cpp
src/WINNT/afsrdr/kernel/lib/AFSWrite.cpp
src/WINNT/afsrdr/kernel/lib/Include/AFSCommon.h

index f64381c..2882409 100644 (file)
@@ -3430,7 +3430,8 @@ VOID
 AFSMarkDirty( IN AFSFcb *Fcb,
               IN AFSExtent *StartExtent,
               IN ULONG ExtentsCount,
-              IN LARGE_INTEGER *StartingByte)
+              IN LARGE_INTEGER *StartingByte,
+              IN BOOLEAN DerefExtents)
 {
 
     AFSNonPagedFcb *pNPFcb = Fcb->NPFcb;
@@ -3439,6 +3440,7 @@ AFSMarkDirty( IN AFSFcb *Fcb,
     ULONG ulCount = 0;
     BOOLEAN bInsertTail = FALSE, bInsertHead = FALSE;
     LONG lCount;
+    BOOLEAN bLocked = FALSE;
 
     AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
                   AFS_TRACE_LEVEL_VERBOSE,
@@ -3446,7 +3448,11 @@ AFSMarkDirty( IN AFSFcb *Fcb,
                   &Fcb->NPFcb->Specific.File.ExtentsResource,
                   PsGetCurrentThread());
 
-    AFSAcquireShared( &Fcb->NPFcb->Specific.File.ExtentsResource, TRUE);
+    if( !ExIsResourceAcquiredLite( &Fcb->NPFcb->Specific.File.ExtentsResource))
+    {
+        AFSAcquireShared( &Fcb->NPFcb->Specific.File.ExtentsResource, TRUE);
+        bLocked = TRUE;
+    }
 
     AFSAcquireExcl( &pNPFcb->Specific.File.DirtyExtentsListLock,
                     TRUE);
@@ -3576,9 +3582,11 @@ AFSMarkDirty( IN AFSFcb *Fcb,
                       pExtent,
                       pExtent->ActiveCount);
 
-        ASSERT( pExtent->ActiveCount > 0);
-
-        lCount = InterlockedDecrement( &pExtent->ActiveCount);
+        if( DerefExtents)
+        {
+            ASSERT( pExtent->ActiveCount > 0);
+            lCount = InterlockedDecrement( &pExtent->ActiveCount);
+        }
 
         pExtent = pNextExtent;
 
@@ -3593,7 +3601,10 @@ AFSMarkDirty( IN AFSFcb *Fcb,
                   &Fcb->NPFcb->Specific.File.ExtentsResource,
                   PsGetCurrentThread());
 
-    AFSReleaseResource( &Fcb->NPFcb->Specific.File.ExtentsResource );
+    if( bLocked)
+    {
+        AFSReleaseResource( &Fcb->NPFcb->Specific.File.ExtentsResource );
+    }
 
     return;
 }
index 84b0063..5a94875 100644 (file)
@@ -836,6 +836,7 @@ AFSNonCachedWrite( IN PDEVICE_OBJECT DeviceObject,
     LARGE_INTEGER      liCurrentTime, liLastRequestTime;
     AFSDeviceExt      *pControlDevExt = (AFSDeviceExt *)AFSControlDeviceObject->DeviceExtension;
     PFILE_OBJECT       pCacheFileObject = NULL;
+    BOOLEAN            bDerefExtents = FALSE;
 
     __Enter
     {
@@ -1164,6 +1165,8 @@ AFSNonCachedWrite( IN PDEVICE_OBJECT DeviceObject,
         AFSReferenceActiveExtents( pStartExtent,
                                    extentsCount);
 
+        bDerefExtents = TRUE;
+
         AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSNonCachedWrite Releasing(2) Fcb extents lock %08lX SHARED %08lX\n",
@@ -1307,31 +1310,34 @@ AFSNonCachedWrite( IN PDEVICE_OBJECT DeviceObject,
             try_return( ntStatus);
         }
 
-        //
-        // Since this is dirty we can mark the extents dirty now.
-        // AFSMarkDirty will dereference the extents.  Do not call
-        // AFSDereferenceActiveExtents() in this code path.
-        //
-
-        AFSMarkDirty( pFcb,
-                      pStartExtent,
-                      extentsCount,
-                      &StartingByte);
+try_exit:
 
-        if (!bPagingIo)
+        if( NT_SUCCESS( ntStatus) &&
+            pStartExtent != NULL &&
+            Irp->IoStatus.Information > 0)
         {
+
             //
-            // This was an uncached user write - tell the server to do
-            // the flush when the worker thread next wakes up
+            // Since this is dirty we can mark the extents dirty now.
+            // AFSMarkDirty will dereference the extents.  Do not call
+            // AFSDereferenceActiveExtents() in this code path.
             //
-            pFcb->Specific.File.LastServerFlush.QuadPart = 0;
-        }
 
-        //
-        // All done
-        //
+            AFSMarkDirty( pFcb,
+                          pStartExtent,
+                          extentsCount,
+                          &StartingByte,
+                          bDerefExtents);
 
-try_exit:
+            if (!bPagingIo)
+            {
+                //
+                // This was an uncached user write - tell the server to do
+                // the flush when the worker thread next wakes up
+                //
+                pFcb->Specific.File.LastServerFlush.QuadPart = 0;
+            }
+        }
 
         if( pCacheFileObject != NULL)
         {
index ba92d97..9b57ff9 100644 (file)
@@ -399,7 +399,8 @@ VOID
 AFSMarkDirty( IN AFSFcb *pFcb,
               IN AFSExtent *StartExtent,
               IN ULONG ExtentsCount,
-              IN LARGE_INTEGER *StartingByte);
+              IN LARGE_INTEGER *StartingByte,
+              IN BOOLEAN DerefExtents);
 
 BOOLEAN
 AFSTearDownFcbExtents( IN AFSFcb *Fcb,