Windows: AFSCleanup re-organization
authorJeffrey Altman <jaltman@your-file-system.com>
Thu, 25 Oct 2012 18:33:29 +0000 (14:33 -0400)
committerJeffrey Altman <jaltman@your-file-system.com>
Sun, 28 Oct 2012 01:54:51 +0000 (18:54 -0700)
Reorganize the activities of the AFSCleanup() for File FCBs
so that the Fcb Resource can be dropped prior to issuing the
cleanup request to the cache manager.   The cache manager can
block for a long period of time while flushing data and holding
the Fcb resource blocks all subsequent CreateFile requests.

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

src/WINNT/afsrdr/kernel/lib/AFSCleanup.cpp

index 3e370ab..43ac6ab 100644 (file)
@@ -574,6 +574,34 @@ AFSCleanup( IN PDEVICE_OBJECT LibDeviceObject,
                     stFileCleanup.FileAccess = pCcb->FileAccess;
 
                     //
+                    // Remove the share access at this time since we may not get the close for sometime on this FO.
+                    //
+
+                    IoRemoveShareAccess( pFileObject,
+                                         &pFcb->ShareAccess);
+
+
+                    //
+                    // We don't need the name array after the user closes the handle on the file
+                    //
+
+                    if( pCcb->NameArray != NULL)
+                    {
+
+                        AFSFreeNameArray( pCcb->NameArray);
+
+                        pCcb->NameArray = NULL;
+                    }
+
+                    //
+                    // Release the Fcb Resource across the call to the service
+                    // which may block for quite a while if flushing of the
+                    // data is required.
+                    //
+
+                    AFSReleaseResource( &pFcb->NPFcb->Resource);
+
+                    //
                     // Push the request to the service
                     //
 
@@ -587,6 +615,13 @@ AFSCleanup( IN PDEVICE_OBJECT LibDeviceObject,
                                                   pResultCB,
                                                   &ulResultLen);
 
+                    //
+                    // Regain exclusive access to the Fcb
+                    //
+
+                    AFSAcquireExcl( &pFcb->NPFcb->Resource,
+                                    TRUE);
+
                     if ( NT_SUCCESS( ntStatus))
                     {
 
@@ -614,25 +649,6 @@ AFSCleanup( IN PDEVICE_OBJECT LibDeviceObject,
                 }
 
                 //
-                // Remove the share access at this time since we may not get the close for sometime on this FO.
-                //
-
-                IoRemoveShareAccess( pFileObject,
-                                     &pFcb->ShareAccess);
-
-                //
-                // We don't need the name array after the user closes the handle on the file
-                //
-
-                if( pCcb->NameArray != NULL)
-                {
-
-                    AFSFreeNameArray( pCcb->NameArray);
-
-                    pCcb->NameArray = NULL;
-                }
-
-                //
                 // Decrement the open child handle count
                 //
 
@@ -652,7 +668,14 @@ AFSCleanup( IN PDEVICE_OBJECT LibDeviceObject,
                                   lCount);
                 }
 
-                AFSReleaseResource( &pFcb->NPFcb->Resource);
+
+                lCount = InterlockedDecrement( &pFcb->OpenHandleCount);
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSCleanup (File) Decrement handle count on Fcb %08lX Cnt %d\n",
+                              pFcb,
+                              lCount);
 
                 if( BooleanFlagOn( pFcb->Flags, AFS_FCB_FLAG_PURGE_ON_CLOSE))
                 {
@@ -664,17 +687,16 @@ AFSCleanup( IN PDEVICE_OBJECT LibDeviceObject,
 
                     ClearFlag( pFcb->Flags, AFS_FCB_FLAG_PURGE_ON_CLOSE);
 
+                    AFSReleaseResource( &pFcb->NPFcb->Resource);
+
                     AFSPerformObjectInvalidate( pObjectInfo,
                                                 AFS_INVALIDATE_DATA_VERSION);
                 }
+                else
+                {
 
-                lCount = InterlockedDecrement( &pFcb->OpenHandleCount);
-
-                AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
-                              AFS_TRACE_LEVEL_VERBOSE,
-                              "AFSCleanup (File) Decrement handle count on Fcb %08lX Cnt %d\n",
-                              pFcb,
-                              lCount);
+                    AFSReleaseResource( &pFcb->NPFcb->Resource);
+                }
 
                 break;
             }