Windows: AFSCleanup extent processing
[openafs.git] / src / WINNT / afsrdr / kernel / lib / AFSCleanup.cpp
index 554b1aa..e51ca8c 100644 (file)
@@ -108,6 +108,8 @@ AFSCleanup( IN PDEVICE_OBJECT LibDeviceObject,
 
         stFileCleanup.ProcessId = (ULONGLONG)PsGetCurrentProcessId();
 
+        stFileCleanup.Identifier = (ULONGLONG)pFileObject;
+
         //
         // Perform the cleanup functionality depending on the type of node it is
         //
@@ -215,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.
                 //
 
@@ -352,19 +394,26 @@ AFSCleanup( IN PDEVICE_OBJECT LibDeviceObject,
                     // the file
                     //
 
-                    AFSTearDownFcbExtents( pFcb);
+                    AFSTearDownFcbExtents( pFcb,
+                                           &pCcb->AuthGroup);
 
                     ntStatus = STATUS_SUCCESS;
 
                     ulNotificationFlags |= AFS_REQUEST_FLAG_FILE_DELETED;
 
                     //
+                    // Indicate the file access mode that is being released
+                    //
+
+                    stFileCleanup.FileAccess = pCcb->FileAccess;
+
+                    //
                     // Push the request to the service
                     //
 
                     ntStatus = AFSProcessRequest( AFS_REQUEST_TYPE_CLEANUP_PROCESSING,
                                                   ulNotificationFlags | AFS_REQUEST_FLAG_SYNCHRONOUS,
-                                                  &pFcb->AuthGroup,
+                                                  &pCcb->AuthGroup,
                                                   &pCcb->DirectoryCB->NameInformation.FileName,
                                                   &pObjectInfo->FileId,
                                                   &stFileCleanup,
@@ -417,6 +466,12 @@ AFSCleanup( IN PDEVICE_OBJECT LibDeviceObject,
                             AFSAcquireExcl( pObjectInfo->ParentObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock,
                                             TRUE);
 
+                            AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+                                          AFS_TRACE_LEVEL_VERBOSE,
+                                          "AFSCleanup DE %p for %wZ removing entry\n",
+                                          pCcb->DirectoryCB,
+                                          &pCcb->DirectoryCB->NameInformation.FileName);
+
                             AFSRemoveNameEntry( pObjectInfo->ParentObjectInformation,
                                                 pCcb->DirectoryCB);
 
@@ -452,54 +507,17 @@ 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);
+                        AFSFlushExtents( pFcb,
+                                         &pCcb->AuthGroup);
                     }
 
                     if( pFcb->OpenHandleCount == 0)
@@ -515,12 +533,18 @@ AFSCleanup( IN PDEVICE_OBJECT LibDeviceObject,
                     }
 
                     //
+                    // Indicate the file access mode that is being released
+                    //
+
+                    stFileCleanup.FileAccess = pCcb->FileAccess;
+
+                    //
                     // Push the request to the service
                     //
 
                     AFSProcessRequest( AFS_REQUEST_TYPE_CLEANUP_PROCESSING,
                                        ulNotificationFlags | AFS_REQUEST_FLAG_SYNCHRONOUS,
-                                       &pFcb->AuthGroup,
+                                       &pCcb->AuthGroup,
                                        &pCcb->DirectoryCB->NameInformation.FileName,
                                        &pObjectInfo->FileId,
                                        &stFileCleanup,
@@ -677,12 +701,18 @@ AFSCleanup( IN PDEVICE_OBJECT LibDeviceObject,
                     ulNotificationFlags |= AFS_REQUEST_FLAG_FILE_DELETED;
 
                     //
+                    // Indicate the file access mode that is being released
+                    //
+
+                    stFileCleanup.FileAccess = pCcb->FileAccess;
+
+                    //
                     // Push the request to the service
                     //
 
                     ntStatus = AFSProcessRequest( AFS_REQUEST_TYPE_CLEANUP_PROCESSING,
                                                   ulNotificationFlags | AFS_REQUEST_FLAG_SYNCHRONOUS,
-                                                  &pFcb->AuthGroup,
+                                                  &pCcb->AuthGroup,
                                                   &pCcb->DirectoryCB->NameInformation.FileName,
                                                   &pObjectInfo->FileId,
                                                   &stFileCleanup,
@@ -779,9 +809,15 @@ AFSCleanup( IN PDEVICE_OBJECT LibDeviceObject,
                         }
                     }
 
+                    //
+                    // Indicate the file access mode that is being released
+                    //
+
+                    stFileCleanup.FileAccess = pCcb->FileAccess;
+
                     AFSProcessRequest( AFS_REQUEST_TYPE_CLEANUP_PROCESSING,
                                        ulNotificationFlags | AFS_REQUEST_FLAG_SYNCHRONOUS,
-                                       &pFcb->AuthGroup,
+                                       &pCcb->AuthGroup,
                                        &pCcb->DirectoryCB->NameInformation.FileName,
                                        &pObjectInfo->FileId,
                                        &stFileCleanup,
@@ -930,12 +966,18 @@ AFSCleanup( IN PDEVICE_OBJECT LibDeviceObject,
                     ulNotificationFlags |= AFS_REQUEST_FLAG_FILE_DELETED;
 
                     //
+                    // Indicate the file access mode that is being released
+                    //
+
+                    stFileCleanup.FileAccess = pCcb->FileAccess;
+
+                    //
                     // Push the request to the service
                     //
 
                     ntStatus = AFSProcessRequest( AFS_REQUEST_TYPE_CLEANUP_PROCESSING,
                                                   ulNotificationFlags | AFS_REQUEST_FLAG_SYNCHRONOUS,
-                                                  &pFcb->AuthGroup,
+                                                  &pCcb->AuthGroup,
                                                   &pCcb->DirectoryCB->NameInformation.FileName,
                                                   &pObjectInfo->FileId,
                                                   &stFileCleanup,
@@ -1032,9 +1074,15 @@ AFSCleanup( IN PDEVICE_OBJECT LibDeviceObject,
                         }
                     }
 
+                    //
+                    // Indicate the file access mode that is being released
+                    //
+
+                    stFileCleanup.FileAccess = pCcb->FileAccess;
+
                     AFSProcessRequest( AFS_REQUEST_TYPE_CLEANUP_PROCESSING,
                                        ulNotificationFlags | AFS_REQUEST_FLAG_SYNCHRONOUS,
-                                       &pFcb->AuthGroup,
+                                       &pCcb->AuthGroup,
                                        &pCcb->DirectoryCB->NameInformation.FileName,
                                        &pObjectInfo->FileId,
                                        &stFileCleanup,