Windows: AFSCleanup extent processing
authorJeffrey Altman <jaltman@your-file-system.com>
Thu, 22 Dec 2011 02:47:56 +0000 (21:47 -0500)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Thu, 22 Dec 2011 15:11:42 +0000 (07:11 -0800)
1. Perform a CcFlushCache() any time the file is cached
   and the Context Control Block indicates that the handle
   has FILE_WRITE_DATA permission.

2. Perform an AFSFlushExtents() whenever there are dirty
   extents and the handle has FILE_WRITE_DATA permission.
   No point flushing the extents if the AuthGroup does not
   have write permission.  Another Ccb must exist that does
   have write permission.

Change-Id: I3ece011b484c12e7dc936b81c272ba6a42f6c7d6
Reviewed-on: http://gerrit.openafs.org/6399
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Peter Scott <pscott@kerneldrivers.com>
Tested-by: Jeffrey Altman <jaltman@secure-endpoints.com>
Reviewed-by: Jeffrey Altman <jaltman@secure-endpoints.com>

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

index 70e7f24..e51ca8c 100644 (file)
@@ -217,6 +217,46 @@ AFSCleanup( IN PDEVICE_OBJECT LibDeviceObject,
                                 TRUE);
 
                 //
+                // If the handle has write permission ...
+                //
+
+                if( (pCcb->GrantedAccess & FILE_WRITE_DATA) &&
+                    CcIsFileCached( pIrpSp->FileObject))
+                {
+
+                    __try
+                    {
+
+                        CcFlushCache( &pFcb->NPFcb->SectionObjectPointers,
+                                      NULL,
+                                      0,
+                                      &stIoSB);
+
+                        if( !NT_SUCCESS( stIoSB.Status))
+                        {
+
+                            AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
+                                          AFS_TRACE_LEVEL_ERROR,
+                                          "AFSCleanup CcFlushCache failure %wZ FID %08lX-%08lX-%08lX-%08lX Status 0x%08lX Bytes 0x%08lX\n",
+                                          &pCcb->FullFileName,
+                                          pObjectInfo->FileId.Cell,
+                                          pObjectInfo->FileId.Volume,
+                                          pObjectInfo->FileId.Vnode,
+                                          pObjectInfo->FileId.Unique,
+                                          stIoSB.Status,
+                                          stIoSB.Information);
+
+                            ntStatus = stIoSB.Status;
+                        }
+                    }
+                    __except( EXCEPTION_EXECUTE_HANDLER)
+                    {
+
+                        ntStatus = GetExceptionCode();
+                    }
+                }
+
+                //
                 // Uninitialize the cache map. This call is unconditional.
                 //
 
@@ -467,51 +507,13 @@ AFSCleanup( IN PDEVICE_OBJECT LibDeviceObject,
                     }
 
                     //
-                    // Flush out any dirty pages on every handle close to reduce strain on the afs cache
-                    //
-
-                    if( CcIsFileCached( pIrpSp->FileObject))
-                    {
-
-                        __try
-                        {
-
-                            CcFlushCache( &pFcb->NPFcb->SectionObjectPointers,
-                                          NULL,
-                                          0,
-                                          &stIoSB);
-
-                            if( !NT_SUCCESS( stIoSB.Status))
-                            {
-
-                                AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
-                                              AFS_TRACE_LEVEL_ERROR,
-                                              "AFSCleanup CcFlushCache failure %wZ FID %08lX-%08lX-%08lX-%08lX Status 0x%08lX Bytes 0x%08lX\n",
-                                              &pCcb->FullFileName,
-                                              pObjectInfo->FileId.Cell,
-                                              pObjectInfo->FileId.Volume,
-                                              pObjectInfo->FileId.Vnode,
-                                              pObjectInfo->FileId.Unique,
-                                              stIoSB.Status,
-                                              stIoSB.Information);
-
-                                ntStatus = stIoSB.Status;
-                            }
-                        }
-                        __except( EXCEPTION_EXECUTE_HANDLER)
-                        {
-
-                            ntStatus = GetExceptionCode();
-                        }
-                    }
-
-                    //
                     // Attempt to flush any dirty extents to the server. This may be a little
                     // aggressive, to flush whenever the handle is closed, but it ensures
                     // coherency.
                     //
 
-                    if( pFcb->Specific.File.ExtentsDirtyCount)
+                    if( (pCcb->GrantedAccess & FILE_WRITE_DATA) &&
+                        pFcb->Specific.File.ExtentsDirtyCount != 0)
                     {
 
                         AFSFlushExtents( pFcb,