Windows: Fcb sectionObjectResource
authorJeffrey Altman <jaltman@your-file-system.com>
Wed, 28 Nov 2012 07:48:48 +0000 (02:48 -0500)
committerJeffrey Altman <jaltman@your-file-system.com>
Mon, 3 Dec 2012 22:03:31 +0000 (14:03 -0800)
Add a SectionObjectResource to the AFS_FCB structure.  This lock
replaces the Fcb.Resource in protecting the SectionObjectPointers.

The new resource is being added to assist in avoiding deadlocks
caused by Trend Micro and perhaps other AV products when
CcPurgeCacheSection() is called while holding the Fcb.Resource
which is required in AFSProcessOpen().

Change-Id: I738c175512e97e1ec153be52ab874f16389d4c95
Reviewed-on: http://gerrit.openafs.org/8563
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
Tested-by: Jeffrey Altman <jaltman@your-file-system.com>

13 files changed:
src/WINNT/afsrdr/common/AFSRedirCommonStructs.h
src/WINNT/afsrdr/kernel/fs/AFSFastIoSupport.cpp
src/WINNT/afsrdr/kernel/fs/AFSGeneric.cpp
src/WINNT/afsrdr/kernel/lib/AFSCleanup.cpp
src/WINNT/afsrdr/kernel/lib/AFSCreate.cpp
src/WINNT/afsrdr/kernel/lib/AFSExtentsSupport.cpp
src/WINNT/afsrdr/kernel/lib/AFSFcbSupport.cpp
src/WINNT/afsrdr/kernel/lib/AFSFileInfo.cpp
src/WINNT/afsrdr/kernel/lib/AFSFlushBuffers.cpp
src/WINNT/afsrdr/kernel/lib/AFSGeneric.cpp
src/WINNT/afsrdr/kernel/lib/AFSLockControl.cpp
src/WINNT/afsrdr/kernel/lib/AFSRead.cpp
src/WINNT/afsrdr/kernel/lib/AFSWrite.cpp

index adbabfc..a01c065 100644 (file)
@@ -163,13 +163,16 @@ typedef struct _AFS_NONPAGED_FCB
     USHORT          Type;
 
     //
-    // Ranking - File Resource first, then Paging Resource
+    // Ranking - File Resource, Paging Resource,
+    //           then SectionObject Resource
     //
 
     ERESOURCE       Resource;
 
     ERESOURCE       PagingResource;
 
+    ERESOURCE       SectionObjectResource;
+
     //
     // The section object pointer
     //
index 9fe9436..ea87c14 100644 (file)
@@ -194,11 +194,11 @@ AFSFastIoAcquireFile( IN struct _FILE_OBJECT *FileObject)
 
     AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
                   AFS_TRACE_LEVEL_VERBOSE,
-                  "AFSFastIoAcquireFile Acquiring Fcb lock %08lX EXCL %08lX\n",
-                  &pFcb->NPFcb->Resource,
+                  "AFSFastIoAcquireFile Acquiring Fcb SectionObject lock %08lX EXCL %08lX\n",
+                  &pFcb->NPFcb->SectionObjectResource,
                   PsGetCurrentThread());
 
-    AFSAcquireExcl( &pFcb->NPFcb->Resource,
+    AFSAcquireExcl( &pFcb->NPFcb->SectionObjectResource,
                     TRUE);
 
     return;
@@ -210,10 +210,16 @@ AFSFastIoReleaseFile( IN struct _FILE_OBJECT *FileObject)
 
     AFSFcb *pFcb = (AFSFcb *)FileObject->FsContext;
 
-    if( ExIsResourceAcquiredExclusiveLite( &pFcb->NPFcb->Resource))
+    if( ExIsResourceAcquiredExclusiveLite( &pFcb->NPFcb->SectionObjectResource))
     {
 
-        AFSReleaseResource( &pFcb->NPFcb->Resource);
+        AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                      AFS_TRACE_LEVEL_VERBOSE,
+                      "AFSFastIoReleaseFile Releasing Fcb SectionObject lock %08lX EXCL %08lX\n",
+                      &pFcb->NPFcb->SectionObjectResource,
+                      PsGetCurrentThread());
+
+        AFSReleaseResource( &pFcb->NPFcb->SectionObjectResource);
     }
 
     return;
@@ -312,13 +318,13 @@ AFSFastIoAcquireForModWrite( IN struct _FILE_OBJECT *FileObject,
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
                           AFS_TRACE_LEVEL_VERBOSE,
-                          "AFSFastIoAcquireForModWrite Acquired Fcb lock %08lX EXCL %08lX\n",
-                          &pFcb->NPFcb->Resource,
+                          "AFSFastIoAcquireForModWrite Acquired Fcb SectionObject lock %08lX EXCL %08lX\n",
+                          &pFcb->NPFcb->SectionObjectResource,
                           PsGetCurrentThread());
 
             ntStatus = STATUS_SUCCESS;
 
-            *ResourceToRelease = &pFcb->NPFcb->Resource;
+            *ResourceToRelease = &pFcb->NPFcb->SectionObjectResource;
         }
     }
 
@@ -333,6 +339,12 @@ AFSFastIoReleaseForModWrite( IN struct _FILE_OBJECT *FileObject,
 
     NTSTATUS ntStatus = STATUS_SUCCESS;
 
+    AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                  AFS_TRACE_LEVEL_VERBOSE,
+                  "AFSFastIoReleaseForModWrite Releasing lock %08lX EXCL %08lX\n",
+                  ResourceToRelease,
+                  PsGetCurrentThread());
+
     AFSReleaseResource( ResourceToRelease);
 
     return ntStatus;
@@ -346,16 +358,25 @@ AFSFastIoAcquireForCCFlush( IN struct _FILE_OBJECT *FileObject,
     NTSTATUS ntStatus = STATUS_FILE_LOCK_CONFLICT;
     AFSFcb *pFcb = (AFSFcb *)FileObject->FsContext;
 
-    if( !ExIsResourceAcquiredSharedLite( &pFcb->NPFcb->Resource))
+    AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                  AFS_TRACE_LEVEL_VERBOSE,
+                  "AFSFastIoAcquireForCCFlush Acquiring Fcb PagingIo lock %08lX SHARED %08lX\n",
+                  &pFcb->NPFcb->PagingResource,
+                  PsGetCurrentThread());
+
+    AFSAcquireShared( &pFcb->NPFcb->PagingResource,
+                      TRUE);
+
+    if( !ExIsResourceAcquiredSharedLite( &pFcb->NPFcb->SectionObjectResource))
     {
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
-                      "AFSFastIoAcquireForCCFlush Acquiring Fcb lock %08lX EXCL %08lX\n",
-                      &pFcb->NPFcb->Resource,
+                      "AFSFastIoAcquireForCCFlush Acquiring Fcb SectionObject lock %08lX EXCL %08lX\n",
+                      &pFcb->NPFcb->SectionObjectResource,
                       PsGetCurrentThread());
 
-        AFSAcquireExcl( &pFcb->NPFcb->Resource,
+        AFSAcquireExcl( &pFcb->NPFcb->SectionObjectResource,
                         TRUE);
     }
     else
@@ -363,25 +384,16 @@ AFSFastIoAcquireForCCFlush( IN struct _FILE_OBJECT *FileObject,
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
-                      "AFSFastIoAcquireForCCFlush Acquiring Fcb lock %08lX SHARED %08lX\n",
-                      &pFcb->NPFcb->Resource,
+                      "AFSFastIoAcquireForCCFlush Acquiring Fcb SectionObject lock %08lX SHARED %08lX\n",
+                      &pFcb->NPFcb->SectionObjectResource,
                       PsGetCurrentThread());
 
-        AFSAcquireShared( &pFcb->NPFcb->Resource,
+        AFSAcquireShared( &pFcb->NPFcb->SectionObjectResource,
                           TRUE);
     }
 
     ntStatus = STATUS_SUCCESS;
 
-    AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
-                  AFS_TRACE_LEVEL_VERBOSE,
-                  "AFSFastIoAcquireForCCFlush Acquiring Fcb PagingIo lock %08lX SHARED %08lX\n",
-                  &pFcb->NPFcb->PagingResource,
-                  PsGetCurrentThread());
-
-    AFSAcquireShared( &pFcb->NPFcb->PagingResource,
-                      TRUE);
-
     //
     // Set the TopLevelIrp field for this caller
     //
@@ -409,31 +421,31 @@ AFSFastIoReleaseForCCFlush( IN struct _FILE_OBJECT *FileObject,
         IoSetTopLevelIrp( NULL);
     }
 
-    if( ExIsResourceAcquiredExclusiveLite( &pFcb->NPFcb->Resource) ||
-        ExIsResourceAcquiredSharedLite( &pFcb->NPFcb->Resource))
+    if( ExIsResourceAcquiredSharedLite( &pFcb->NPFcb->PagingResource))
     {
 
-        AFSReleaseResource( &pFcb->NPFcb->Resource);
+        AFSReleaseResource( &pFcb->NPFcb->PagingResource);
     }
     else
     {
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
                       AFS_TRACE_LEVEL_ERROR,
-                      "AFSFastIoReleaseForCCFlush Called for non-acquired main resource Fcb\n");
+                      "AFSFastIoReleaseForCCFlush Called for non-acquired paging resource Fcb\n");
     }
 
-    if( ExIsResourceAcquiredSharedLite( &pFcb->NPFcb->PagingResource))
+    if( ExIsResourceAcquiredExclusiveLite( &pFcb->NPFcb->SectionObjectResource) ||
+        ExIsResourceAcquiredSharedLite( &pFcb->NPFcb->SectionObjectResource))
     {
 
-        AFSReleaseResource( &pFcb->NPFcb->PagingResource);
+        AFSReleaseResource( &pFcb->NPFcb->SectionObjectResource);
     }
     else
     {
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
                       AFS_TRACE_LEVEL_ERROR,
-                      "AFSFastIoReleaseForCCFlush Called for non-acquired paging resource Fcb\n");
+                      "AFSFastIoReleaseForCCFlush Called for non-acquired SectionObject resource Fcb\n");
     }
 
     return ntStatus;
index 8931992..7fed71c 100644 (file)
@@ -1643,7 +1643,7 @@ AFSAcquireFcbForLazyWrite( IN PVOID Fcb,
 
     BOOLEAN bStatus = FALSE;
     AFSFcb *pFcb = (AFSFcb *)Fcb;
-    BOOLEAN bReleaseMain = FALSE, bReleasePaging = FALSE;
+    BOOLEAN bReleaseSectionObject = FALSE, bReleasePaging = FALSE;
 
     //
     // Try and acquire the Fcb resource
@@ -1654,45 +1654,45 @@ AFSAcquireFcbForLazyWrite( IN PVOID Fcb,
                   "AFSAcquireFcbForLazyWrite Acquiring Fcb %08lX\n",
                   Fcb);
 
+    //
+    // Try and grab the paging
+    //
+
     AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
                   AFS_TRACE_LEVEL_VERBOSE,
-                  "AFSAcquireFcbForLazyWrite Attempt to acquire Fcb lock %08lX SHARED %08lX\n",
-                  &pFcb->NPFcb->Resource,
+                  "AFSAcquireFcbForLazyWrite Attempt to acquire Fcb PagingIo lock %08lX SHARED %08lX\n",
+                  &pFcb->NPFcb->PagingResource,
                   PsGetCurrentThread());
 
-    if( AFSAcquireShared( &pFcb->NPFcb->Resource,
+    if( AFSAcquireShared( &pFcb->NPFcb->PagingResource,
                           Wait))
     {
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
-                      "AFSAcquireFcbForLazyWrite Acquired Fcb lock %08lX SHARED %08lX\n",
-                      &pFcb->NPFcb->Resource,
+                      "AFSAcquireFcbForLazyWrite Acquired Fcb PagingIo lock %08lX SHARED %08lX\n",
+                      &pFcb->NPFcb->PagingResource,
                       PsGetCurrentThread());
 
-        bReleaseMain = TRUE;
-
-        //
-        // Try and grab the paging
-        //
+        bReleasePaging = TRUE;
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
-                      "AFSAcquireFcbForLazyWrite Attempt to acquire Fcb PagingIo lock %08lX SHARED %08lX\n",
-                      &pFcb->NPFcb->PagingResource,
+                      "AFSAcquireFcbForLazyWrite Attempt to acquire Fcb SectionObject lock %08lX SHARED %08lX\n",
+                      &pFcb->NPFcb->SectionObjectResource,
                       PsGetCurrentThread());
 
-        if( AFSAcquireShared( &pFcb->NPFcb->PagingResource,
+        if( AFSAcquireShared( &pFcb->NPFcb->SectionObjectResource,
                               Wait))
         {
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
                           AFS_TRACE_LEVEL_VERBOSE,
-                          "AFSAcquireFcbForLazyWrite Acquired Fcb PagingIo lock %08lX SHARED %08lX\n",
-                          &pFcb->NPFcb->PagingResource,
+                          "AFSAcquireFcbForLazyWrite Acquired Fcb SectionObject lock %08lX SHARED %08lX\n",
+                          &pFcb->NPFcb->SectionObjectResource,
                           PsGetCurrentThread());
 
-            bReleasePaging = TRUE;
+            bReleaseSectionObject = TRUE;
 
             //
             // All is well ...
@@ -1707,10 +1707,10 @@ AFSAcquireFcbForLazyWrite( IN PVOID Fcb,
     if( !bStatus)
     {
 
-        if( bReleaseMain)
+        if( bReleaseSectionObject)
         {
 
-            AFSReleaseResource( &pFcb->NPFcb->Resource);
+            AFSReleaseResource( &pFcb->NPFcb->SectionObjectResource);
         }
 
         if( bReleasePaging)
@@ -1736,9 +1736,9 @@ AFSReleaseFcbFromLazyWrite( IN PVOID Fcb)
 
     IoSetTopLevelIrp( NULL);
 
-    AFSReleaseResource( &pFcb->NPFcb->PagingResource);
+    AFSReleaseResource( &pFcb->NPFcb->SectionObjectResource);
 
-    AFSReleaseResource( &pFcb->NPFcb->Resource);
+    AFSReleaseResource( &pFcb->NPFcb->PagingResource);
 
     return;
 }
@@ -1753,18 +1753,18 @@ AFSAcquireFcbForReadAhead( IN PVOID Fcb,
 
     AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
                   AFS_TRACE_LEVEL_VERBOSE,
-                  "AFSAcquireFcbForReadAhead Attempt to acquire Fcb lock %08lX SHARED %08lX\n",
-                  &pFcb->NPFcb->Resource,
+                  "AFSAcquireFcbForReadAhead Attempt to acquire Fcb SectionObject lock %08lX SHARED %08lX\n",
+                  &pFcb->NPFcb->SectionObjectResource,
                   PsGetCurrentThread());
 
-    if( AFSAcquireShared( &pFcb->NPFcb->Resource,
+    if( AFSAcquireShared( &pFcb->NPFcb->SectionObjectResource,
                           Wait))
     {
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
-                      "AFSAcquireFcbForReadAhead Acquired Fcb lock %08lX SHARED %08lX\n",
-                      &pFcb->NPFcb->Resource,
+                      "AFSAcquireFcbForReadAhead Acquired Fcb SectionObject lock %08lX SHARED %08lX\n",
+                      &pFcb->NPFcb->SectionObjectResource,
                       PsGetCurrentThread());
 
         bStatus = TRUE;
@@ -1783,7 +1783,7 @@ AFSReleaseFcbFromReadAhead( IN PVOID Fcb)
 
     IoSetTopLevelIrp( NULL);
 
-    AFSReleaseResource( &pFcb->NPFcb->Resource);
+    AFSReleaseResource( &pFcb->NPFcb->SectionObjectResource);
 
     return;
 }
index f8945ec..52a63d7 100644 (file)
@@ -230,18 +230,18 @@ AFSCleanup( IN PDEVICE_OBJECT LibDeviceObject,
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
                               AFS_TRACE_LEVEL_VERBOSE,
-                              "AFSCleanup Acquiring Fcb lock %08lX EXCL %08lX\n",
-                              &pFcb->NPFcb->Resource,
+                              "AFSCleanup Acquiring Fcb SectionObject lock %08lX EXCL %08lX\n",
+                              &pFcb->NPFcb->SectionObjectResource,
                               PsGetCurrentThread());
 
-                AFSAcquireExcl( &pFcb->NPFcb->Resource,
+                AFSAcquireExcl( &pFcb->NPFcb->SectionObjectResource,
                                 TRUE);
 
                 //
                 // If the handle has write permission ...
                 //
 
-                if( (pCcb->GrantedAccess & FILE_WRITE_DATA) &&
+                if( ((pCcb->GrantedAccess & FILE_WRITE_DATA) || pFcb->OpenHandleCount == 1) &&
                     CcIsFileCached( pIrpSp->FileObject))
                 {
 
@@ -269,11 +269,49 @@ AFSCleanup( IN PDEVICE_OBJECT LibDeviceObject,
 
                             ntStatus = stIoSB.Status;
                         }
+
+                        if ( ( pFcb->OpenHandleCount == 1 ||
+                               BooleanFlagOn( pFcb->Flags, AFS_FCB_FLAG_PURGE_ON_CLOSE)) &&
+                             pFcb->NPFcb->SectionObjectPointers.DataSectionObject != NULL)
+                        {
+
+                            if ( !CcPurgeCacheSection( &pFcb->NPFcb->SectionObjectPointers,
+                                                       NULL,
+                                                       0,
+                                                       FALSE))
+                            {
+
+                                AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
+                                              AFS_TRACE_LEVEL_WARNING,
+                                              "AFSCleanup CcPurgeCacheSection failure FID %08lX-%08lX-%08lX-%08lX\n",
+                                              pObjectInfo->FileId.Cell,
+                                              pObjectInfo->FileId.Volume,
+                                              pObjectInfo->FileId.Vnode,
+                                              pObjectInfo->FileId.Unique);
+
+                                SetFlag( pObjectInfo->Fcb->Flags, AFS_FCB_FLAG_PURGE_ON_CLOSE);
+                            }
+                            else
+                            {
+                                ClearFlag( pObjectInfo->Fcb->Flags, AFS_FCB_FLAG_PURGE_ON_CLOSE);
+                            }
+                        }
                     }
                     __except( EXCEPTION_EXECUTE_HANDLER)
                     {
 
                         ntStatus = GetExceptionCode();
+
+                        AFSDbgLogMsg( 0,
+                                      0,
+                                      "EXCEPTION - AFSCleanup Cc FID %08lX-%08lX-%08lX-%08lX Status 0x%08lX\n",
+                                      pObjectInfo->FileId.Cell,
+                                      pObjectInfo->FileId.Volume,
+                                      pObjectInfo->FileId.Vnode,
+                                      pObjectInfo->FileId.Unique,
+                                      ntStatus);
+
+                        SetFlag( pObjectInfo->Fcb->Flags, AFS_FCB_FLAG_PURGE_ON_CLOSE);
                     }
                 }
 
@@ -291,6 +329,24 @@ AFSCleanup( IN PDEVICE_OBJECT LibDeviceObject,
                                         NULL,
                                         NULL);
 
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSCleanup Releasing Fcb SectionObject lock %08lX EXCL %08lX\n",
+                              &pFcb->NPFcb->SectionObjectResource,
+                              PsGetCurrentThread());
+
+                AFSReleaseResource( &pFcb->NPFcb->SectionObjectResource);
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSCleanup Acquiring Fcb lock %08lX EXCL %08lX\n",
+                              &pFcb->NPFcb->Resource,
+                              PsGetCurrentThread());
+
+                AFSAcquireExcl( &pFcb->NPFcb->Resource,
+                                TRUE);
+
                 //
                 // Unlock all outstanding locks on the file, again, unconditionally
                 //
index 0fbf686..34ee237 100644 (file)
@@ -2679,6 +2679,15 @@ AFSProcessOpen( IN PIRP Irp,
                 BooleanFlagOn(ulOptions, FILE_DELETE_ON_CLOSE))
             {
 
+                AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSProcessOpen Acquiring Fcb SectionObject lock %08lX EXCL %08lX\n",
+                              &pObjectInfo->Fcb->NPFcb->SectionObjectResource,
+                              PsGetCurrentThread());
+
+                AFSAcquireExcl( &pObjectInfo->Fcb->NPFcb->SectionObjectResource,
+                                TRUE);
+
                 if( !MmFlushImageSection( &pObjectInfo->Fcb->NPFcb->SectionObjectPointers,
                                           MmFlushForWrite))
                 {
@@ -2695,6 +2704,14 @@ AFSProcessOpen( IN PIRP Irp,
 
                     try_return( ntStatus);
                 }
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSProcessOpen Releasing Fcb SectionObject lock %08lX EXCL %08lX\n",
+                              &pObjectInfo->Fcb->NPFcb->SectionObjectResource,
+                              PsGetCurrentThread());
+
+                AFSReleaseResource( &pObjectInfo->Fcb->NPFcb->SectionObjectResource);
             }
 
             if( BooleanFlagOn( ulOptions, FILE_DIRECTORY_FILE))
@@ -3011,6 +3028,7 @@ AFSProcessOverwriteSupersede( IN PDEVICE_OBJECT DeviceObject,
     LARGE_INTEGER liTime;
     ULONG ulCreateDisposition = 0;
     BOOLEAN bAllocatedCcb = FALSE;
+    BOOLEAN bUserMapped = FALSE;
     PACCESS_MASK pDesiredAccess = NULL;
     USHORT usShareAccess;
     AFSObjectInfoCB *pParentObjectInfo = NULL;
@@ -3135,13 +3153,32 @@ AFSProcessOverwriteSupersede( IN PDEVICE_OBJECT DeviceObject,
             }
         }
 
+        AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                      AFS_TRACE_LEVEL_VERBOSE,
+                      "AFSProcessOverwriteSupercede Acquiring Fcb SectionObject lock %08lX EXCL %08lX\n",
+                      &pObjectInfo->Fcb->NPFcb->SectionObjectResource,
+                      PsGetCurrentThread());
+
+        AFSAcquireExcl( &pObjectInfo->Fcb->NPFcb->SectionObjectResource,
+                        TRUE);
+
         //
         //  Before we actually truncate, check to see if the purge
         //  is going to fail.
         //
 
-        if( !MmCanFileBeTruncated( &pObjectInfo->Fcb->NPFcb->SectionObjectPointers,
-                                   &liZero))
+        bUserMapped = !MmCanFileBeTruncated( &pObjectInfo->Fcb->NPFcb->SectionObjectPointers,
+                                             &liZero);
+
+        AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                      AFS_TRACE_LEVEL_VERBOSE,
+                      "AFSProcessOverwriteSupercede Releasing Fcb SectionObject lock %08lX EXCL %08lX\n",
+                      &pObjectInfo->Fcb->NPFcb->SectionObjectResource,
+                      PsGetCurrentThread());
+
+        AFSReleaseResource( &pObjectInfo->Fcb->NPFcb->SectionObjectResource);
+
+        if( bUserMapped)
         {
 
             ntStatus = STATUS_USER_MAPPED_FILE;
index 74b328f..60d0e50 100644 (file)
@@ -1197,29 +1197,6 @@ AFSProcessExtentsResult( IN AFSFcb *Fcb,
                 //
                 le = &pExtent->Lists[AFS_EXTENTS_LIST];
 
-                /*
-                //
-                // Then the check the skip lists cursors
-                //
-                for (ULONG i = AFS_NUM_EXTENT_LISTS-1; i > AFS_EXTENTS_LIST; i--)
-                {
-                    if (0 == (pFileExtents->FileOffset.LowPart & ExtentsMasks[i]))
-                    {
-                        //
-                        // Three options:
-                        //    - empty list (pSkipEntries[i]->Flink == pSkipEntries[i]->Flink == fcb->lists[i]
-                        //    - We are the last on the list (pSkipEntries[i]->Flink == fcb->lists[i])
-                        //    - We are not the last on the list.  In that case we have to be strictly less than
-                        //      that extent.
-                        if (pSkipEntries[i]->Flink != &Fcb->Specific.File.ExtentsLists[i]) {
-
-                            AFSExtent *otherExtent = ExtentFor(pSkipEntries[i]->Flink, i);
-                            ASSERT(pFileExtents->FileOffset.QuadPart < otherExtent->FileOffset.QuadPart);
-                        }
-                    }
-                }
-                */
-
                 //
                 // setup pExtent if there is one
                 //
@@ -2853,6 +2830,7 @@ AFSFlushExtents( IN AFSFcb *Fcb,
                               ntStatus);
 
             }
+
             AFSLockForExtentsTrim( Fcb);
 
             bExtentsLocked = TRUE;
index 8389376..6baf372 100644 (file)
@@ -154,6 +154,8 @@ AFSInitFcb( IN AFSDirectoryCB  *DirEntry)
 
         ExInitializeResourceLite( &pNPFcb->PagingResource);
 
+        ExInitializeResourceLite( &pNPFcb->SectionObjectResource);
+
         ExInitializeResourceLite( &pNPFcb->CcbListLock);
 
         pFcb->Header.Resource = &pNPFcb->Resource;
@@ -344,6 +346,8 @@ try_exit:
                         ExDeleteResourceLite( &pNPFcb->Specific.File.DirtyExtentsListLock);
                     }
 
+                    ExDeleteResourceLite( &pNPFcb->SectionObjectResource);
+
                     ExDeleteResourceLite( &pNPFcb->PagingResource);
 
                     ExDeleteResourceLite( &pNPFcb->CcbListLock);
@@ -1126,6 +1130,8 @@ AFSRemoveFcb( IN AFSFcb **ppFcb)
 
     ExDeleteResourceLite( &pFcb->NPFcb->PagingResource);
 
+    ExDeleteResourceLite( &pFcb->NPFcb->SectionObjectResource);
+
     ExDeleteResourceLite( &pFcb->NPFcb->CcbListLock);
 
     //
index 6ee14cd..2935d17 100644 (file)
@@ -2093,6 +2093,15 @@ AFSSetDispositionInfo( IN PIRP Irp,
             else if( pFcb->Header.NodeTypeCode == AFS_FILE_FCB)
             {
 
+                AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSSetDispositionInfo Acquiring Fcb SectionObject lock %08lX EXCL %08lX\n",
+                              &pFcb->NPFcb->SectionObjectResource,
+                              PsGetCurrentThread());
+
+                AFSAcquireExcl( &pFcb->NPFcb->SectionObjectResource,
+                                TRUE);
+
                 //
                 // Attempt to flush any outstanding data
                 //
@@ -2139,6 +2148,14 @@ AFSSetDispositionInfo( IN PIRP Irp,
                         SetFlag( pFcb->Flags, AFS_FCB_FLAG_PURGE_ON_CLOSE);
                     }
                 }
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSSetDispositionInfo Releasing Fcb SectionObject lock %08lX EXCL %08lX\n",
+                              &pFcb->NPFcb->SectionObjectResource,
+                              PsGetCurrentThread());
+
+                AFSReleaseResource( &pFcb->NPFcb->SectionObjectResource);
             }
         }
         else
@@ -3120,7 +3137,13 @@ AFSSetRenameInfo( IN PIRP Irp)
 
                 pTargetFcb = pTargetDirEntry->ObjectInformation->Fcb;
 
-                AFSAcquireExcl( &pTargetFcb->NPFcb->Resource,
+                AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSSetRenameInfo Acquiring Fcb SectionObject lock %08lX EXCL %08lX\n",
+                              &pTargetFcb->NPFcb->SectionObjectResource,
+                              PsGetCurrentThread());
+
+                AFSAcquireExcl( &pTargetFcb->NPFcb->SectionObjectResource,
                                 TRUE);
 
                 //
@@ -3137,7 +3160,13 @@ AFSSetRenameInfo( IN PIRP Irp)
                                   &pTargetDirEntry->NameInformation.FileName);
                 }
 
-                AFSReleaseResource( &pTargetFcb->NPFcb->Resource);
+                AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSSetRenameInfo Releasing Fcb SectionObject lock %08lX EXCL %08lX\n",
+                              &pTargetFcb->NPFcb->SectionObjectResource,
+                              PsGetCurrentThread());
+
+                AFSReleaseResource( &pTargetFcb->NPFcb->SectionObjectResource);
             }
 
             ASSERT( pTargetDirEntry->DirOpenReferenceCount > 0);
@@ -3243,6 +3272,7 @@ AFSSetAllocationInfo( IN PIRP Irp,
     BOOLEAN bReleasePaging = FALSE;
     BOOLEAN bTellCc = FALSE;
     BOOLEAN bTellService = FALSE;
+    BOOLEAN bUserMapped = FALSE;
     PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation( Irp);
     PFILE_OBJECT pFileObject = pIrpSp->FileObject;
     AFSFcb *pFcb = NULL;
@@ -3272,17 +3302,38 @@ AFSSetAllocationInfo( IN PIRP Irp,
 
     if( pFcb->Header.AllocationSize.QuadPart > pBuffer->AllocationSize.QuadPart)
     {
+
+        AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                      AFS_TRACE_LEVEL_VERBOSE,
+                      "AFSSetAllocationInfo Acquiring Fcb SectionObject lock %08lX EXCL %08lX\n",
+                      &pFcb->NPFcb->SectionObjectResource,
+                      PsGetCurrentThread());
+
+        AFSAcquireExcl( &pFcb->NPFcb->SectionObjectResource,
+                        TRUE);
+
+        bUserMapped = !MmCanFileBeTruncated( pFileObject->SectionObjectPointer,
+                                             &pBuffer->AllocationSize);
+
+        AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                      AFS_TRACE_LEVEL_VERBOSE,
+                      "AFSSetAllocationInfo Releasing Fcb SectionObject lock %08lX EXCL %08lX\n",
+                      &pFcb->NPFcb->SectionObjectResource,
+                      PsGetCurrentThread());
+
+        AFSReleaseResource( &pFcb->NPFcb->SectionObjectResource);
+
         //
         // Truncating the file
         //
-        if( !MmCanFileBeTruncated( pFileObject->SectionObjectPointer,
-                                   &pBuffer->AllocationSize))
+        if ( bUserMapped)
         {
 
             ntStatus = STATUS_USER_MAPPED_FILE ;
         }
         else
         {
+
             //
             // If this is a truncation we need to grab the paging IO resource.
             //
@@ -3433,6 +3484,7 @@ AFSSetEndOfFileInfo( IN PIRP Irp,
     BOOLEAN bModified = FALSE;
     BOOLEAN bReleasePaging = FALSE;
     BOOLEAN bTruncated = FALSE;
+    BOOLEAN bUserMapped = FALSE;
     AFSFcb *pFcb = NULL;
     AFSCcb *pCcb = NULL;
 
@@ -3453,9 +3505,28 @@ AFSSetEndOfFileInfo( IN PIRP Irp,
         if( pBuffer->EndOfFile.QuadPart < pFcb->Header.FileSize.QuadPart)
         {
 
+            AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSSetEndOfFileInfo Acquiring Fcb SectionObject lock %08lX EXCL %08lX\n",
+                          &pFcb->NPFcb->SectionObjectResource,
+                          PsGetCurrentThread());
+
+            AFSAcquireExcl( &pFcb->NPFcb->SectionObjectResource,
+                            TRUE);
+
+            bUserMapped = !MmCanFileBeTruncated( pFileObject->SectionObjectPointer,
+                                                 &pBuffer->EndOfFile);
+
+            AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSSetEndOfFileInfo Releasing Fcb SectionObject lock %08lX EXCL %08lX\n",
+                          &pFcb->NPFcb->SectionObjectResource,
+                          PsGetCurrentThread());
+
+            AFSReleaseResource( &pFcb->NPFcb->SectionObjectResource);
+
             // Truncating the file
-            if( !MmCanFileBeTruncated( pFileObject->SectionObjectPointer,
-                                       &pBuffer->EndOfFile))
+            if ( bUserMapped)
             {
 
                 ntStatus = STATUS_USER_MAPPED_FILE;
index eedfd9a..0028383 100644 (file)
@@ -49,6 +49,7 @@ AFSFlushBuffers( IN PDEVICE_OBJECT LibDeviceObject,
     AFSFcb            *pFcb = (AFSFcb *)pFileObject->FsContext;
     AFSCcb            *pCcb = (AFSCcb *)pFileObject->FsContext2;
     IO_STATUS_BLOCK    iosb = {0};
+    BOOLEAN            bReleaseSectionObject = FALSE;
 
     pIrpSp = IoGetCurrentIrpStackLocation( Irp);
 
@@ -84,6 +85,18 @@ AFSFlushBuffers( IN PDEVICE_OBJECT LibDeviceObject,
             //
             try_return( ntStatus = STATUS_INVALID_PARAMETER);
         }
+
+        AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                      AFS_TRACE_LEVEL_VERBOSE,
+                      "AFSFlushBuffers Acquiring Fcb SectionObject lock %08lX SHARED %08lX\n",
+                      &pFcb->NPFcb->SectionObjectResource,
+                      PsGetCurrentThread());
+
+        AFSAcquireShared( &pFcb->NPFcb->SectionObjectResource,
+                          TRUE);
+
+        bReleaseSectionObject = TRUE;
+
         //
         // The flush consists of two parts.  We firstly flush our
         // cache (if we have one), then we tell the service to write
@@ -115,6 +128,17 @@ AFSFlushBuffers( IN PDEVICE_OBJECT LibDeviceObject,
 
             try_return( ntStatus = GetExceptionCode());
         }
+
+        AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                      AFS_TRACE_LEVEL_VERBOSE,
+                      "AFSFlushBuffers Releasing Fcb SectionObject lock %08lX SHARED %08lX\n",
+                      &pFcb->NPFcb->SectionObjectResource,
+                      PsGetCurrentThread());
+
+        AFSReleaseResource( &pFcb->NPFcb->SectionObjectResource);
+
+        bReleaseSectionObject = FALSE;
+
         //
         // Now, flush to the server - if there is stuff to do
         //
@@ -134,6 +158,18 @@ AFSFlushBuffers( IN PDEVICE_OBJECT LibDeviceObject,
 
 try_exit:
 
+        if ( bReleaseSectionObject)
+        {
+
+            AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSFlushBuffers Releasing Fcb SectionObject lock %08lX SHARED %08lX\n",
+                          &pFcb->NPFcb->SectionObjectResource,
+                          PsGetCurrentThread());
+
+            AFSReleaseResource( &pFcb->NPFcb->SectionObjectResource);
+        }
+
         AFSCompleteRequest( Irp, ntStatus);
     }
 
index a3556c4..15af3e2 100644 (file)
@@ -1726,7 +1726,7 @@ AFSInvalidateObject( IN OUT AFSObjectInfoCB **ppObjectInfo,
                               (*ppObjectInfo)->FileId.Vnode,
                               (*ppObjectInfo)->FileId.Unique);
 
-                AFSAcquireExcl( &(*ppObjectInfo)->Fcb->NPFcb->Resource,
+                AFSAcquireExcl( &(*ppObjectInfo)->Fcb->NPFcb->SectionObjectResource,
                                 TRUE);
 
                 __try
@@ -1792,7 +1792,7 @@ AFSInvalidateObject( IN OUT AFSObjectInfoCB **ppObjectInfo,
                     SetFlag( (*ppObjectInfo)->Fcb->Flags, AFS_FCB_FLAG_PURGE_ON_CLOSE);
                 }
 
-                AFSReleaseResource( &(*ppObjectInfo)->Fcb->NPFcb->Resource);
+                AFSReleaseResource( &(*ppObjectInfo)->Fcb->NPFcb->SectionObjectResource);
 
                 //
                 // Clear out the extents
@@ -2876,7 +2876,7 @@ AFSVerifyEntry( IN GUID *AuthGroup,
                                   pObjectInfo->FileId.Vnode,
                                   pObjectInfo->FileId.Unique);
 
-                    AFSAcquireExcl( &pObjectInfo->Fcb->NPFcb->Resource,
+                    AFSAcquireExcl( &pObjectInfo->Fcb->NPFcb->SectionObjectResource,
                                     TRUE);
 
                     __try
@@ -2944,7 +2944,7 @@ AFSVerifyEntry( IN GUID *AuthGroup,
                         SetFlag( pObjectInfo->Fcb->Flags, AFS_FCB_FLAG_PURGE_ON_CLOSE);
                     }
 
-                    AFSReleaseResource( &pObjectInfo->Fcb->NPFcb->Resource);
+                    AFSReleaseResource( &pObjectInfo->Fcb->NPFcb->SectionObjectResource);
 
                     if ( bPurgeExtents)
                     {
@@ -2996,6 +2996,15 @@ AFSVerifyEntry( IN GUID *AuthGroup,
                     pObjectInfo->Fcb->Header.FileSize.QuadPart        = pObjectInfo->EndOfFile.QuadPart;
                     pObjectInfo->Fcb->Header.ValidDataLength.QuadPart = pObjectInfo->EndOfFile.QuadPart;
 
+                    AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                                  AFS_TRACE_LEVEL_VERBOSE,
+                                  "AFSVerifyEntry Acquiring Fcb SectionObject lock %08lX EXCL %08lX\n",
+                                  &pObjectInfo->Fcb->NPFcb->SectionObjectResource,
+                                  PsGetCurrentThread());
+
+                    AFSAcquireExcl( &pObjectInfo->Fcb->NPFcb->SectionObjectResource,
+                                    TRUE);
+
                     pCCFileObject = CcGetFileObjectFromSectionPtrs( &pObjectInfo->Fcb->NPFcb->SectionObjectPointers);
 
                     if ( pCCFileObject != NULL)
@@ -3004,6 +3013,14 @@ AFSVerifyEntry( IN GUID *AuthGroup,
                                         (PCC_FILE_SIZES)&pObjectInfo->Fcb->Header.AllocationSize);
                     }
 
+                    AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                                  AFS_TRACE_LEVEL_VERBOSE,
+                                  "AFSVerifyEntry Releasing Fcb SectionObject lock %08lX EXCL %08lX\n",
+                                  &pObjectInfo->Fcb->NPFcb->SectionObjectResource,
+                                  PsGetCurrentThread());
+
+                    AFSReleaseResource( &pObjectInfo->Fcb->NPFcb->SectionObjectResource);
+
                     AFSReleaseResource( &pObjectInfo->Fcb->NPFcb->Resource);
                 }
                 else
@@ -4067,6 +4084,21 @@ AFSValidateEntry( IN AFSDirectoryCB *DirEntry,
                                 ClearFlag( pObjectInfo->Flags, AFS_OBJECT_FLAGS_VERIFY_DATA);
                             }
 
+                            AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                                          AFS_TRACE_LEVEL_VERBOSE,
+                                          "AFSValidateEntry Acquiring Fcb SectionObject lock %08lX EXCL %08lX\n",
+                                          &pObjectInfo->Fcb->NPFcb->SectionObjectResource,
+                                          PsGetCurrentThread());
+
+                            AFSAcquireExcl( &pObjectInfo->Fcb->NPFcb->SectionObjectResource,
+                                            TRUE);
+
+                            //
+                            // Release Fcb->Resource to avoid Trend Micro deadlock
+                            //
+
+                            AFSReleaseResource( &pObjectInfo->Fcb->NPFcb->Resource);
+
                             __try
                             {
 
@@ -4131,6 +4163,17 @@ AFSValidateEntry( IN AFSDirectoryCB *DirEntry,
 
                                 SetFlag( pObjectInfo->Fcb->Flags, AFS_FCB_FLAG_PURGE_ON_CLOSE);
                             }
+
+                            AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                                          AFS_TRACE_LEVEL_VERBOSE,
+                                          "AFSValidateEntry Acquiring Fcb SectionObject lock %08lX EXCL %08lX\n",
+                                          &pObjectInfo->Fcb->NPFcb->SectionObjectResource,
+                                          PsGetCurrentThread());
+
+                            AFSReleaseResource( &pObjectInfo->Fcb->NPFcb->SectionObjectResource);
+
+                            AFSAcquireExcl( &pObjectInfo->Fcb->NPFcb->Resource,
+                                            TRUE);
                         }
                         else
                         {
@@ -4195,7 +4238,18 @@ AFSValidateEntry( IN AFSDirectoryCB *DirEntry,
 
                     if( pObjectInfo->Fcb != NULL)
                     {
-                        FILE_OBJECT *pCCFileObject = CcGetFileObjectFromSectionPtrs( &pObjectInfo->Fcb->NPFcb->SectionObjectPointers);
+                        FILE_OBJECT *pCCFileObject;
+
+                        AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                                      AFS_TRACE_LEVEL_VERBOSE,
+                                      "AFSValidateEntry Acquiring Fcb SectionObject lock %08lX EXCL %08lX\n",
+                                      &pObjectInfo->Fcb->NPFcb->SectionObjectResource,
+                                      PsGetCurrentThread());
+
+                        AFSAcquireExcl( &pObjectInfo->Fcb->NPFcb->SectionObjectResource,
+                                        TRUE);
+
+                        pCCFileObject = CcGetFileObjectFromSectionPtrs( &pObjectInfo->Fcb->NPFcb->SectionObjectPointers);
 
                         pObjectInfo->Fcb->Header.AllocationSize.QuadPart  = pObjectInfo->AllocationSize.QuadPart;
                         pObjectInfo->Fcb->Header.FileSize.QuadPart        = pObjectInfo->EndOfFile.QuadPart;
@@ -4206,6 +4260,14 @@ AFSValidateEntry( IN AFSDirectoryCB *DirEntry,
                             CcSetFileSizes( pCCFileObject,
                                             (PCC_FILE_SIZES)&pObjectInfo->Fcb->Header.AllocationSize);
                         }
+
+                        AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                                      AFS_TRACE_LEVEL_VERBOSE,
+                                      "AFSValidateEntry Releasing Fcb SectionObject lock %08lX EXCL %08lX\n",
+                                      &pObjectInfo->Fcb->NPFcb->SectionObjectResource,
+                                      PsGetCurrentThread());
+
+                        AFSReleaseResource( &pObjectInfo->Fcb->NPFcb->SectionObjectResource);
                     }
                 }
                 break;
@@ -7077,12 +7139,27 @@ AFSCleanupFcb( IN AFSFcb *Fcb,
                 !BooleanFlagOn( Fcb->ObjectInformation->Flags, AFS_OBJECT_FLAGS_DELETED))
             {
 
-                AFSAcquireExcl( &Fcb->NPFcb->Resource,
-                                TRUE);
+                AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSCleanupEntry Acquiring Fcb lock %08lX SHARED %08lX\n",
+                              &Fcb->NPFcb->Resource,
+                              PsGetCurrentThread());
+
+                AFSAcquireShared( &Fcb->NPFcb->Resource,
+                                  TRUE);
 
                 if( Fcb->OpenReferenceCount > 0)
                 {
 
+                    AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                                  AFS_TRACE_LEVEL_VERBOSE,
+                                  "AFSCleanupEntry Acquiring Fcb SectionObject lock %08lX EXCL %08lX\n",
+                                  &Fcb->NPFcb->SectionObjectResource,
+                                  PsGetCurrentThread());
+
+                    AFSAcquireExcl( &Fcb->NPFcb->SectionObjectResource,
+                                    TRUE);
+
                     __try
                     {
 
@@ -7144,8 +7221,22 @@ AFSCleanupFcb( IN AFSFcb *Fcb,
 
                         SetFlag( Fcb->Flags, AFS_FCB_FLAG_PURGE_ON_CLOSE);
                     }
+
+                    AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                                  AFS_TRACE_LEVEL_VERBOSE,
+                                  "AFSCleanupFcb Releasing Fcb SectionObject lock %08lX EXCL %08lX\n",
+                                  &Fcb->NPFcb->SectionObjectResource,
+                                  PsGetCurrentThread());
+
+                    AFSReleaseResource( &Fcb->NPFcb->SectionObjectResource);
                 }
 
+                AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSCleanupEntry Releasing Fcb lock %08lX SHARED %08lX\n",
+                              &Fcb->NPFcb->Resource,
+                              PsGetCurrentThread());
+
                 AFSReleaseResource( &Fcb->NPFcb->Resource);
 
                 //
@@ -7226,7 +7317,13 @@ AFSCleanupFcb( IN AFSFcb *Fcb,
                                         (AFS_SERVER_PURGE_SLEEP * pControlDeviceExt->Specific.Control.FcbPurgeTimeCount.QuadPart))))
         {
 
-            if ( AFSAcquireExcl( &Fcb->NPFcb->Resource, ForceFlush))
+            AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSCleanupFcb Acquiring Fcb SectionObject lock %08lX EXCL %08lX\n",
+                          &Fcb->NPFcb->SectionObjectResource,
+                          PsGetCurrentThread());
+
+            if ( AFSAcquireExcl( &Fcb->NPFcb->SectionObjectResource, ForceFlush))
             {
 
                 __try
@@ -7290,7 +7387,13 @@ AFSCleanupFcb( IN AFSFcb *Fcb,
                                   ntStatus);
                 }
 
-                AFSReleaseResource( &Fcb->NPFcb->Resource);
+                AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSCleanupFcb Releasing Fcb SectionObject lock %08lX EXCL %08lX\n",
+                              &Fcb->NPFcb->SectionObjectResource,
+                              PsGetCurrentThread());
+
+                AFSReleaseResource( &Fcb->NPFcb->SectionObjectResource);
 
                 if( Fcb->OpenReferenceCount <= 0)
                 {
@@ -9193,12 +9296,12 @@ AFSPerformObjectInvalidate( IN AFSObjectInfoCB *ObjectInfo,
                         if ( ObjectInfo->Fcb->Specific.File.ExtentsDirtyCount == 0)
                         {
 
-                            if ( ObjectInfo->Fcb->OpenReferenceCount == 0)
-                            {
+                            AFSReleaseResource( &ObjectInfo->Fcb->NPFcb->Specific.File.ExtentsResource );
 
-                                AFSReleaseResource( &ObjectInfo->Fcb->NPFcb->Specific.File.ExtentsResource );
+                            bExtentsLocked = FALSE;
 
-                                bExtentsLocked = FALSE;
+                            if ( ObjectInfo->Fcb->OpenReferenceCount == 0)
+                            {
 
                                 AFSReleaseResource( &ObjectInfo->Fcb->NPFcb->Resource);
 
@@ -9210,12 +9313,21 @@ AFSPerformObjectInvalidate( IN AFSObjectInfoCB *ObjectInfo,
                             else
                             {
 
-                                __try
-                                {
+                                AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                                              AFS_TRACE_LEVEL_VERBOSE,
+                                              "AFSPerformObjectInvalidation Acquiring Fcb SectionObject lock %08lX EXCL %08lX\n",
+                                              &ObjectInfo->Fcb->NPFcb->SectionObjectResource,
+                                              PsGetCurrentThread());
+
+                                AFSAcquireExcl( &ObjectInfo->Fcb->NPFcb->SectionObjectResource,
+                                                TRUE);
+
+                                AFSReleaseResource( &ObjectInfo->Fcb->NPFcb->Resource);
 
-                                    AFSReleaseResource( &ObjectInfo->Fcb->NPFcb->Specific.File.ExtentsResource );
+                                bLocked = FALSE;
 
-                                    bExtentsLocked = FALSE;
+                                __try
+                                {
 
                                     if( ObjectInfo->Fcb->NPFcb->SectionObjectPointers.DataSectionObject != NULL &&
                                         !CcPurgeCacheSection( &ObjectInfo->Fcb->NPFcb->SectionObjectPointers,
@@ -9256,11 +9368,36 @@ AFSPerformObjectInvalidate( IN AFSObjectInfoCB *ObjectInfo,
 
                                     SetFlag( ObjectInfo->Fcb->Flags, AFS_FCB_FLAG_PURGE_ON_CLOSE);
                                 }
+
+                                AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                                              AFS_TRACE_LEVEL_VERBOSE,
+                                              "AFSPerformObjectInvalidation Releasing Fcb SectionObject lock %08lX EXCL %08lX\n",
+                                              &ObjectInfo->Fcb->NPFcb->SectionObjectResource,
+                                              PsGetCurrentThread());
+
+                                AFSReleaseResource( &ObjectInfo->Fcb->NPFcb->SectionObjectResource);
                             }
                         }
                         else
                         {
 
+                            AFSReleaseResource( &ObjectInfo->Fcb->NPFcb->Specific.File.ExtentsResource );
+
+                            bExtentsLocked = FALSE;
+
+                            AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                                          AFS_TRACE_LEVEL_VERBOSE,
+                                          "AFSPerformObjectInvalidation Acquiring Fcb SectionObject lock %08lX EXCL %08lX\n",
+                                          &ObjectInfo->Fcb->NPFcb->SectionObjectResource,
+                                          PsGetCurrentThread());
+
+                            AFSAcquireExcl( &ObjectInfo->Fcb->NPFcb->SectionObjectResource,
+                                            TRUE);
+
+                            AFSReleaseResource( &ObjectInfo->Fcb->NPFcb->Resource);
+
+                            bLocked = FALSE;
+
                             //
                             // Must build a list of non-dirty ranges from the beginning of the file
                             // to the end.  There can be at most (Fcb->Specific.File.ExtentsDirtyCount + 1)
@@ -9285,10 +9422,6 @@ AFSPerformObjectInvalidate( IN AFSObjectInfoCB *ObjectInfo,
                                      ulByteRangeCount == 0)
                                 {
 
-                                    AFSReleaseResource( &ObjectInfo->Fcb->NPFcb->Specific.File.ExtentsResource );
-
-                                    bExtentsLocked = FALSE;
-
                                     for ( ulIndex = 0; ulIndex < ulByteRangeCount; ulIndex++)
                                     {
 
@@ -9337,6 +9470,10 @@ AFSPerformObjectInvalidate( IN AFSObjectInfoCB *ObjectInfo,
                                     // This could deadlock but we do not have much choice.
                                     //
 
+                                    AFSAcquireExcl(  &ObjectInfo->Fcb->NPFcb->Specific.File.ExtentsResource,
+                                                    TRUE);
+                                    bExtentsLocked = TRUE;
+
                                     le = ObjectInfo->Fcb->Specific.File.ExtentsLists[AFS_EXTENTS_LIST].Flink;
 
                                     ulProcessCount = 0;
@@ -9471,6 +9608,14 @@ AFSPerformObjectInvalidate( IN AFSObjectInfoCB *ObjectInfo,
                                               ObjectInfo->FileId.Unique,
                                               ntStatus);
                             }
+
+                            AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                                          AFS_TRACE_LEVEL_VERBOSE,
+                                          "AFSPerformObjectInvalidation Releasing Fcb SectionObject lock %08lX EXCL %08lX\n",
+                                          &ObjectInfo->Fcb->NPFcb->SectionObjectResource,
+                                          PsGetCurrentThread());
+
+                            AFSReleaseResource( &ObjectInfo->Fcb->NPFcb->SectionObjectResource);
                         }
                     }
 
index 1545967..895476d 100644 (file)
@@ -166,6 +166,15 @@ AFSLockControl( IN PDEVICE_OBJECT LibDeviceObject,
                 // Flush data and then release the locks on the file server
                 //
 
+                AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSLockControl Acquiring Fcb SectionObject lock %08lX SHARED %08lX\n",
+                              &pFcb->NPFcb->SectionObjectResource,
+                              PsGetCurrentThread());
+
+                AFSAcquireShared( &pFcb->NPFcb->SectionObjectResource,
+                                  TRUE);
+
                 CcFlushCache( &pFcb->NPFcb->SectionObjectPointers,
                               NULL,
                               0,
@@ -187,6 +196,14 @@ AFSLockControl( IN PDEVICE_OBJECT LibDeviceObject,
                     ntStatus = stIoStatus.Status;
                 }
 
+                AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSLockControl Releasing Fcb SectionObject lock %08lX SHARED %08lX\n",
+                              &pFcb->NPFcb->SectionObjectResource,
+                              PsGetCurrentThread());
+
+                AFSReleaseResource( &pFcb->NPFcb->SectionObjectResource);
+
                 RtlZeroMemory( &stUnlockRequestCB,
                                sizeof( AFSByteRangeUnlockRequestCB));
 
@@ -215,11 +232,27 @@ AFSLockControl( IN PDEVICE_OBJECT LibDeviceObject,
                 // Flush the data and then release the file server locks
                 //
 
+                AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSLockControl Acquiring Fcb SectionObject lock %08lX SHARED %08lX\n",
+                              &pFcb->NPFcb->SectionObjectResource,
+                              PsGetCurrentThread());
+
+                AFSAcquireShared( &pFcb->NPFcb->SectionObjectResource,
+                                  TRUE);
                 CcFlushCache( &pFcb->NPFcb->SectionObjectPointers,
                               &pIrpSp->Parameters.LockControl.ByteOffset,
                               pIrpSp->Parameters.LockControl.Length->LowPart,
                               &stIoStatus);
 
+                AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSLockControl Releasing Fcb SectionObject lock %08lX SHARED %08lX\n",
+                              &pFcb->NPFcb->SectionObjectResource,
+                              PsGetCurrentThread());
+
+                AFSReleaseResource( &pFcb->NPFcb->SectionObjectResource);
+
                 if( !NT_SUCCESS( stIoStatus.Status))
                 {
 
index 5f2da9b..03c2966 100644 (file)
@@ -818,6 +818,7 @@ AFSCommonRead( IN PDEVICE_OBJECT DeviceObject,
     AFSFcb             *pFcb = NULL;
     AFSCcb             *pCcb = NULL;
     BOOLEAN             bReleaseMain = FALSE;
+    BOOLEAN             bReleaseSectionObject = FALSE;
     BOOLEAN             bReleasePaging = FALSE;
     BOOLEAN             bPagingIo = FALSE;
     BOOLEAN             bNonCachedIo = FALSE;
@@ -964,6 +965,17 @@ AFSCommonRead( IN PDEVICE_OBJECT DeviceObject,
         if ( FlagOn(pIrpSp->MinorFunction, IRP_MN_COMPLETE) )
         {
 
+            AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSCommonRead Acquiring Fcb SectionObject lock %08lX SHARED %08lX\n",
+                          &pFcb->NPFcb->SectionObjectResource,
+                          PsGetCurrentThread());
+
+            AFSAcquireShared( &pFcb->NPFcb->SectionObjectResource,
+                              TRUE);
+
+            bReleaseSectionObject = TRUE;
+
             AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSCommonRead (%08lX) IRP_MN_COMPLETE being processed\n",
@@ -1001,27 +1013,39 @@ AFSCommonRead( IN PDEVICE_OBJECT DeviceObject,
             AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSCommonRead Acquiring Fcb PagingIo lock %08lX SHARED %08lX\n",
-                                                              &pFcb->NPFcb->PagingResource,
-                                                              PsGetCurrentThread());
+                          &pFcb->NPFcb->PagingResource,
+                          PsGetCurrentThread());
 
             AFSAcquireShared( &pFcb->NPFcb->PagingResource,
                               TRUE);
 
             bReleasePaging = TRUE;
+
+            AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSCommonRead Acquiring Fcb SectionObject lock %08lX SHARED %08lX\n",
+                          &pFcb->NPFcb->SectionObjectResource,
+                          PsGetCurrentThread());
+
+            AFSAcquireShared( &pFcb->NPFcb->SectionObjectResource,
+                              TRUE);
+
+            bReleaseSectionObject = TRUE;
+
         }
         else
         {
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
                           AFS_TRACE_LEVEL_VERBOSE,
-                          "AFSCommonRead Acquiring Fcb lock %08lX SHARED %08lX\n",
-                                                              &pFcb->NPFcb->Resource,
-                                                              PsGetCurrentThread());
+                          "AFSCommonRead Acquiring Fcb SectionObject lock %08lX SHARED %08lX\n",
+                          &pFcb->NPFcb->SectionObjectResource,
+                          PsGetCurrentThread());
 
-            AFSAcquireShared( &pFcb->NPFcb->Resource,
+            AFSAcquireShared( &pFcb->NPFcb->SectionObjectResource,
                               TRUE);
 
-            bReleaseMain = TRUE;
+            bReleaseSectionObject = TRUE;
 
             //
             // Check the BR locks
@@ -1119,8 +1143,8 @@ AFSCommonRead( IN PDEVICE_OBJECT DeviceObject,
                     AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
                                   AFS_TRACE_LEVEL_VERBOSE,
                                   "AFSCommonRead Initialize caching on Fcb %08lX FO %08lX\n",
-                                      pFcb,
-                                      pFileObject);
+                                  pFcb,
+                                  pFileObject);
 
                     CcInitializeCacheMap( pFileObject,
                                           (PCC_FILE_SIZES)&pFcb->Header.AllocationSize,
@@ -1230,6 +1254,30 @@ AFSCommonRead( IN PDEVICE_OBJECT DeviceObject,
         else
         {
 
+            if( bReleasePaging)
+            {
+
+                AFSReleaseResource( &pFcb->NPFcb->PagingResource);
+
+                bReleasePaging = FALSE;
+            }
+
+            if( bReleaseSectionObject)
+            {
+
+                AFSReleaseResource( &pFcb->NPFcb->SectionObjectResource);
+
+                bReleaseSectionObject = FALSE;
+            }
+
+            if( bReleaseMain)
+            {
+
+                AFSReleaseResource( &pFcb->NPFcb->Resource);
+
+                bReleaseMain = FALSE;
+            }
+
             AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSCommonRead (%08lX) Processing NON-CACHED request Offset %I64X Len %08lX\n",
@@ -1254,6 +1302,12 @@ try_exit:
             AFSReleaseResource( &pFcb->NPFcb->PagingResource);
         }
 
+        if( bReleaseSectionObject)
+        {
+
+            AFSReleaseResource( &pFcb->NPFcb->SectionObjectResource);
+        }
+
         if( bReleaseMain)
         {
 
index b5232b4..f0d3f37 100644 (file)
@@ -108,6 +108,7 @@ AFSCommonWrite( IN PDEVICE_OBJECT DeviceObject,
     BOOLEAN            bPagingIo = FALSE;
     BOOLEAN            bNonCachedIo = FALSE;
     BOOLEAN            bReleaseMain = FALSE;
+    BOOLEAN            bReleaseSectionObject = FALSE;
     BOOLEAN            bReleasePaging = FALSE;
     BOOLEAN            bExtendingWrite = FALSE;
     BOOLEAN            bCompleteIrp = TRUE;
@@ -334,61 +335,86 @@ AFSCommonWrite( IN PDEVICE_OBJECT DeviceObject,
             bNonCachedIo = FALSE;
         }
 
-        if( (!bPagingIo && !bNonCachedIo))
-        {
+        if ( !bNonCachedIo) {
 
-            if( pFileObject->PrivateCacheMap == NULL)
+            if( !bPagingIo)
             {
 
-                __try
+                if( pFileObject->PrivateCacheMap == NULL)
                 {
 
-                    AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
+                    AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
                                   AFS_TRACE_LEVEL_VERBOSE,
-                                  "AFSCommonWrite Initialize caching on Fcb %08lX FileObject %08lX\n",
-                                  pFcb,
-                                  pFileObject);
+                                  "AFSCommonWrite Acquiring Fcb SectionObject lock %08lX EXCL %08lX\n",
+                                  &pNPFcb->SectionObjectResource,
+                                  PsGetCurrentThread());
 
-                    CcInitializeCacheMap( pFileObject,
-                                          (PCC_FILE_SIZES)&pFcb->Header.AllocationSize,
-                                          FALSE,
-                                          AFSLibCacheManagerCallbacks,
-                                          pFcb);
+                    AFSAcquireExcl( &pNPFcb->SectionObjectResource,
+                                    TRUE);
 
-                    CcSetReadAheadGranularity( pFileObject,
-                                               pDeviceExt->Specific.RDR.MaximumRPCLength);
+                    bReleaseSectionObject = TRUE;
 
-                    CcSetDirtyPageThreshold( pFileObject,
-                                             AFS_DIRTY_CHUNK_THRESHOLD * pDeviceExt->Specific.RDR.MaximumRPCLength);
-                }
-                __except( EXCEPTION_EXECUTE_HANDLER)
-                {
+                    __try
+                    {
 
-                    ntStatus = GetExceptionCode();
+                        AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
+                                      AFS_TRACE_LEVEL_VERBOSE,
+                                      "AFSCommonWrite Initialize caching on Fcb %08lX FileObject %08lX\n",
+                                      pFcb,
+                                      pFileObject);
 
-                    AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
-                                  AFS_TRACE_LEVEL_ERROR,
-                                  "AFSCommonWrite (%08lX) Exception thrown while initializing cache map Status %08lX\n",
-                                  Irp,
-                                  ntStatus);
-                }
+                        CcInitializeCacheMap( pFileObject,
+                                              (PCC_FILE_SIZES)&pFcb->Header.AllocationSize,
+                                              FALSE,
+                                              AFSLibCacheManagerCallbacks,
+                                              pFcb);
 
-                if( !NT_SUCCESS( ntStatus))
-                {
+                        CcSetReadAheadGranularity( pFileObject,
+                                                   pDeviceExt->Specific.RDR.MaximumRPCLength);
 
-                    try_return( ntStatus);
+                        CcSetDirtyPageThreshold( pFileObject,
+                                                 AFS_DIRTY_CHUNK_THRESHOLD * pDeviceExt->Specific.RDR.MaximumRPCLength);
+                    }
+                    __except( EXCEPTION_EXECUTE_HANDLER)
+                    {
+
+                        ntStatus = GetExceptionCode();
+
+                        AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
+                                      AFS_TRACE_LEVEL_ERROR,
+                                      "AFSCommonWrite (%08lX) Exception thrown while initializing cache map Status %08lX\n",
+                                      Irp,
+                                      ntStatus);
+                    }
+
+                    AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                                  AFS_TRACE_LEVEL_VERBOSE,
+                                  "AFSCommonWrite Releasing Fcb SectionObject lock %08lX EXCL %08lX\n",
+                                  &pNPFcb->SectionObjectResource,
+                                  PsGetCurrentThread());
+
+                    AFSReleaseResource( &pNPFcb->SectionObjectResource);
+
+                    bReleaseSectionObject = FALSE;
+
+
+                    if( !NT_SUCCESS( ntStatus))
+                    {
+
+                        try_return( ntStatus);
+                    }
                 }
             }
-        }
 
-        while (!bNonCachedIo && !CcCanIWrite( pFileObject,
-                                              ulByteCount,
-                                              FALSE,
-                                              bRetry))
-        {
-            static const LONGLONG llWriteDelay = (LONGLONG)-100000;
-            bRetry = TRUE;
-            KeDelayExecutionThread(KernelMode, FALSE, (PLARGE_INTEGER)&llWriteDelay);
+            while (!CcCanIWrite( pFileObject,
+                                 ulByteCount,
+                                 FALSE,
+                                 bRetry))
+            {
+                static const LONGLONG llWriteDelay = (LONGLONG)-100000;
+                bRetry = TRUE;
+                KeDelayExecutionThread(KernelMode, FALSE, (PLARGE_INTEGER)&llWriteDelay);
+            }
         }
 
         //
@@ -414,34 +440,9 @@ AFSCommonWrite( IN PDEVICE_OBJECT DeviceObject,
         }
 
         //
-        // We should be ready to go.  So first of all ask for the extents
-        // Provoke a get of the extents - if we need to.
-        //
-
-        /*
-        if( !bPagingIo && !bNonCachedIo)
-        {
-
-            ntStatus = AFSRequestExtentsAsync( pFcb, pCcb, &liStartingByte, ulByteCount);
-
-            if (!NT_SUCCESS(ntStatus))
-            {
-
-                AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
-                              AFS_TRACE_LEVEL_ERROR,
-                              "AFSCommonWrite (%08lX) Failed to request extents Status %08lX\n",
-                              Irp,
-                              ntStatus);
-
-                try_return( ntStatus );
-            }
-        }
-        */
-
-        //
         // Take locks
         //
-        //   - if Paging then we need to nothing (the precalls will
+        //   - if Paging then we need to do nothing (the precalls will
         //     have acquired the paging resource), for clarity we will collect
         //     the paging resource
         //   - If extending Write then take the fileresource EX (EOF will change, Allocation will only move out)
@@ -453,15 +454,6 @@ AFSCommonWrite( IN PDEVICE_OBJECT DeviceObject,
         do
         {
 
-            if( !bPagingIo)
-            {
-
-                bExtendingWrite = (((liStartingByte.QuadPart + ulByteCount) >=
-                                    pFcb->Header.FileSize.QuadPart) ||
-                                   (liStartingByte.LowPart == FILE_WRITE_TO_END_OF_FILE &&
-                                    liStartingByte.HighPart == -1)) ;
-            }
-
             if( bPagingIo)
             {
 
@@ -483,103 +475,139 @@ AFSCommonWrite( IN PDEVICE_OBJECT DeviceObject,
                 //
                 bLockOK = TRUE;
             }
-            else if( bExtendingWrite)
+            else
             {
-                //
-                // Check for lock inversion
-                //
 
-                ASSERT( !ExIsResourceAcquiredLite( &pNPFcb->PagingResource ));
+                bExtendingWrite = (((liStartingByte.QuadPart + ulByteCount) >=
+                                     pFcb->Header.FileSize.QuadPart) ||
+                                    (liStartingByte.LowPart == FILE_WRITE_TO_END_OF_FILE &&
+                                      liStartingByte.HighPart == -1)) ;
 
-                AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
-                              AFS_TRACE_LEVEL_VERBOSE,
-                              "AFSCommonWrite Acquiring Fcb lock %08lX EXCL %08lX\n",
-                              &pNPFcb->Resource,
-                              PsGetCurrentThread());
+                if( bExtendingWrite)
+                {
+                    //
+                    // Check for lock inversion
+                    //
 
-                AFSAcquireExcl( &pNPFcb->Resource,
-                                TRUE);
+                    ASSERT( !ExIsResourceAcquiredLite( &pNPFcb->PagingResource ));
 
-                if (liStartingByte.LowPart == FILE_WRITE_TO_END_OF_FILE &&
-                    liStartingByte.HighPart == -1)
-                {
-                    if (pFcb->Header.ValidDataLength.QuadPart > pFcb->Header.FileSize.QuadPart)
-                    {
-                        liStartingByte = pFcb->Header.ValidDataLength;
-                    }
-                    else
+                    AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                                  AFS_TRACE_LEVEL_VERBOSE,
+                                  "AFSCommonWrite Acquiring Fcb lock %08lX EXCL %08lX\n",
+                                  &pNPFcb->Resource,
+                                  PsGetCurrentThread());
+
+                    AFSAcquireExcl( &pNPFcb->Resource,
+                                    TRUE);
+
+                    bReleaseMain = TRUE;
+
+                    AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                                  AFS_TRACE_LEVEL_VERBOSE,
+                                  "AFSCommonWrite Acquiring Fcb SectionObject lock %08lX EXCL %08lX\n",
+                                  &pNPFcb->SectionObjectResource,
+                                  PsGetCurrentThread());
+
+                    AFSAcquireExcl( &pNPFcb->SectionObjectResource,
+                                    TRUE);
+
+                    bReleaseSectionObject = TRUE;
+
+                    if (liStartingByte.LowPart == FILE_WRITE_TO_END_OF_FILE &&
+                         liStartingByte.HighPart == -1)
                     {
-                        liStartingByte = pFcb->Header.FileSize;
+                        if (pFcb->Header.ValidDataLength.QuadPart > pFcb->Header.FileSize.QuadPart)
+                        {
+                            liStartingByte = pFcb->Header.ValidDataLength;
+                        }
+                        else
+                        {
+                            liStartingByte = pFcb->Header.FileSize;
+                        }
                     }
+
+                    //
+                    // We have the correct lock - even if we don't end up truncating
+                    //
+                    bLockOK = TRUE;
                 }
-                bReleaseMain = TRUE;
+                else
+                {
+                    ASSERT( !ExIsResourceAcquiredLite( &pNPFcb->PagingResource ));
 
-                //
-                // We have the correct lock - even if we don't end up truncating
-                //
-                bLockOK = TRUE;
-            }
-            else
-            {
-                ASSERT( !ExIsResourceAcquiredLite( &pNPFcb->PagingResource ));
+                    AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                                  AFS_TRACE_LEVEL_VERBOSE,
+                                  "AFSCommonWrite Acquiring Fcb lock %08lX SHARED %08lX\n",
+                                  &pNPFcb->Resource,
+                                  PsGetCurrentThread());
 
-                AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
-                              AFS_TRACE_LEVEL_VERBOSE,
-                              "AFSCommonWrite Acquiring Fcb lock %08lX SHARED %08lX\n",
-                              &pNPFcb->Resource,
-                              PsGetCurrentThread());
+                    AFSAcquireShared( &pNPFcb->Resource,
+                                      TRUE);
 
-                AFSAcquireShared( &pNPFcb->Resource,
-                                  TRUE);
+                    bReleaseMain = TRUE;
 
-                bReleaseMain = TRUE;
+                    AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                                  AFS_TRACE_LEVEL_VERBOSE,
+                                  "AFSCommonWrite Acquiring Fcb SectionObject lock %08lX SHARED %08lX\n",
+                                  &pNPFcb->SectionObjectResource,
+                                  PsGetCurrentThread());
 
-                //
-                // Have things moved?  Are we extending? If so, the the lock isn't OK
-                //
-                bLockOK = (liStartingByte.QuadPart + ulByteCount) < pFcb->Header.FileSize.QuadPart;
+                    AFSAcquireShared( &pNPFcb->SectionObjectResource,
+                                      TRUE);
 
-                if (!bLockOK)
-                {
-                    AFSReleaseResource( &pNPFcb->Resource);
-                    bReleaseMain = FALSE;
+                    bReleaseSectionObject = TRUE;
+
+                    //
+                    // Have things moved?  Are we extending? If so, the the lock isn't OK
+                    //
+                    bLockOK = (liStartingByte.QuadPart + ulByteCount) < pFcb->Header.FileSize.QuadPart;
+
+                    if (!bLockOK)
+                    {
+                        AFSReleaseResource( &pNPFcb->Resource);
+
+                        bReleaseMain = FALSE;
+                    }
                 }
             }
         }
         while (!bLockOK);
 
-        //
-        // Check the BR locks on the file.
-        //
-
-        if( !bPagingIo &&
-            !FsRtlCheckLockForWriteAccess( &pFcb->Specific.File.FileLock,
-                                           Irp))
+        if( !bPagingIo)
         {
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
-                          AFS_TRACE_LEVEL_ERROR,
-                          "AFSCommonWrite (%08lX) Request failed due to lock conflict\n",
-                          Irp);
+            //
+            // Check the BR locks on the file.
+            //
 
-            try_return( ntStatus = STATUS_FILE_LOCK_CONFLICT);
-        }
+            if ( !FsRtlCheckLockForWriteAccess( &pFcb->Specific.File.FileLock,
+                                                Irp))
+            {
 
-        if( bExtendingWrite)
-        {
+                AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
+                              AFS_TRACE_LEVEL_ERROR,
+                              "AFSCommonWrite (%08lX) Request failed due to lock conflict\n",
+                              Irp);
 
-            ntStatus = AFSExtendingWrite( pFcb, pFileObject, (liStartingByte.QuadPart + ulByteCount));
+                try_return( ntStatus = STATUS_FILE_LOCK_CONFLICT);
+            }
 
-            if( !NT_SUCCESS(ntStatus))
+            if( bExtendingWrite)
             {
 
-                AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
-                              AFS_TRACE_LEVEL_ERROR,
-                              "AFSCommonWrite (%08lX) Failed extending write request Status %08lX\n",
-                              Irp,
-                              ntStatus);
+                ntStatus = AFSExtendingWrite( pFcb, pFileObject, (liStartingByte.QuadPart + ulByteCount));
+
+                if( !NT_SUCCESS(ntStatus))
+                {
 
-                try_return( ntStatus );
+                    AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
+                                  AFS_TRACE_LEVEL_ERROR,
+                                  "AFSCommonWrite (%08lX) Failed extending write request Status %08lX\n",
+                                  Irp,
+                                  ntStatus);
+
+                    try_return( ntStatus );
+                }
             }
         }
 
@@ -592,6 +620,10 @@ AFSCommonWrite( IN PDEVICE_OBJECT DeviceObject,
             !bNonCachedIo)
         {
 
+            //
+            // Main and SectionObject resources held Shared
+            //
+
             AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSCommonWrite (%08lX) Processing CACHED request Offset %I64X Len %08lX\n",
@@ -605,6 +637,35 @@ AFSCommonWrite( IN PDEVICE_OBJECT DeviceObject,
         else
         {
 
+            //
+            // if bPagingIo, Paging Resource held Shared
+            // else Main and SectionObject resources held Shared
+            //
+
+            if( bReleaseSectionObject)
+            {
+
+                AFSReleaseResource( &pNPFcb->SectionObjectResource);
+
+                bReleaseSectionObject = FALSE;
+            }
+
+            if( bReleasePaging)
+            {
+
+                AFSReleaseResource( &pNPFcb->PagingResource);
+
+                bReleasePaging = FALSE;
+            }
+
+            if( bReleaseMain)
+            {
+
+                AFSReleaseResource( &pNPFcb->Resource);
+
+                bReleaseMain = FALSE;
+            }
+
             AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSCommonWrite (%08lX) Processing NON-CACHED request Offset %I64X Len %08lX\n",
@@ -625,10 +686,10 @@ try_exit:
 
         ObDereferenceObject(pFileObject);
 
-        if( bReleaseMain)
+        if( bReleaseSectionObject)
         {
 
-            AFSReleaseResource( &pNPFcb->Resource);
+            AFSReleaseResource( &pNPFcb->SectionObjectResource);
         }
 
         if( bReleasePaging)
@@ -637,6 +698,12 @@ try_exit:
             AFSReleaseResource( &pNPFcb->PagingResource);
         }
 
+        if( bReleaseMain)
+        {
+
+            AFSReleaseResource( &pNPFcb->Resource);
+        }
+
         if( bCompleteIrp)
         {
 
@@ -1649,15 +1716,6 @@ AFSExtendingWrite( IN AFSFcb *Fcb,
     NTSTATUS      ntStatus = STATUS_SUCCESS;
     AFSCcb       *pCcb = (AFSCcb *)FileObject->FsContext2;
 
-    AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
-                  AFS_TRACE_LEVEL_VERBOSE,
-                  "AFSExtendingWrite Acquiring Fcb PagingIo lock %08lX EXCL %08lX\n",
-                  &Fcb->NPFcb->PagingResource,
-                  PsGetCurrentThread());
-
-    AFSAcquireExcl( &Fcb->NPFcb->PagingResource,
-                    TRUE);
-
     if( NewLength > Fcb->Header.AllocationSize.QuadPart)
     {
 
@@ -1705,8 +1763,6 @@ AFSExtendingWrite( IN AFSFcb *Fcb,
         Fcb->Header.AllocationSize = liSaveAllocation;
     }
 
-    AFSReleaseResource( &Fcb->NPFcb->PagingResource);
-
     //
     // DownConvert file resource to shared
     //