Windows: Skip Extent operations if Direct IO
[openafs.git] / src / WINNT / afsrdr / kernel / lib / AFSClose.cpp
index 1dd061f..d290eee 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2008, 2009, 2010, 2011 Kernel Drivers, LLC.
- * Copyright (c) 2009, 2010, 2011 Your File System, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Kernel Drivers, LLC.
+ * Copyright (c) 2009, 2010, 2011, 2012, 2013 Your File System, Inc.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * - Redistributions of source code must retain the above copyright notice,
  *   this list of conditions and the following disclaimer.
  * - Redistributions in binary form must reproduce the above copyright
- *   notice,
- *   this list of conditions and the following disclaimer in the
- *   documentation
- *   and/or other materials provided with the distribution.
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
  * - Neither the names of Kernel Drivers, LLC and Your File System, Inc.
  *   nor the names of their contributors may be used to endorse or promote
  *   products derived from this software without specific prior written
@@ -115,6 +113,8 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
 
                 pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
 
+               pIrpSp->FileObject->FsContext2 = NULL;
+
                 //
                 // Send the close to the CM
                 //
@@ -162,7 +162,8 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
                 {
 
                     pParentObjectInfo = AFSFindObjectInfo( pObjectInfo->VolumeCB,
-                                                           &pObjectInfo->ParentFileId);
+                                                           &pObjectInfo->ParentFileId,
+                                                           FALSE);
                 }
 
                 if( pParentObjectInfo != NULL &&
@@ -180,6 +181,8 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
 
                 AFSReleaseResource( &pFcb->NPFcb->Resource);
 
+               pIrpSp->FileObject->FsContext = NULL;
+
                 lCount = InterlockedDecrement( &pFcb->OpenReferenceCount);
 
                 AFSDbgTrace(( AFS_SUBSYSTEM_FCB_REF_COUNTING,
@@ -207,6 +210,8 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
 
                 pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
 
+               pIrpSp->FileObject->FsContext2;
+
                 //
                 // Remove the Ccb and de-allocate it
                 //
@@ -216,6 +221,8 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
 
                 AFSReleaseResource( &pFcb->NPFcb->Resource);
 
+               pIrpSp->FileObject->FsContext = NULL;
+
                 lCount = InterlockedDecrement( &pFcb->OpenReferenceCount);
 
                 AFSDbgTrace(( AFS_SUBSYSTEM_FCB_REF_COUNTING,
@@ -244,6 +251,8 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
 
                 pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
 
+               pIrpSp->FileObject->FsContext2 = NULL;
+
                 //
                 // We may be performing some cleanup on the Fcb so grab it exclusive to ensure no collisions
                 //
@@ -265,51 +274,60 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
 
                     SetFlag( pFcb->Flags, AFS_FCB_FILE_CLOSED);
 
-                    //
-                    // Attempt to tear down our extent list for the file
-                    // If there are remaining dirty extents then attempt to
-                    // flush them as well
-                    //
+                   if( !BooleanFlagOn( pDeviceExt->DeviceFlags, AFS_DEVICE_FLAG_DIRECT_SERVICE_IO))
+                   {
 
-                    if( pFcb->Specific.File.ExtentsDirtyCount)
-                    {
+                       //
+                       // Attempt to tear down our extent list for the file
+                       // If there are remaining dirty extents then attempt to
+                       // flush them as well
+                       //
 
-                        AFSFlushExtents( pFcb,
-                                         &pCcb->AuthGroup);
-                    }
+                       if( pFcb->Specific.File.ExtentsDirtyCount)
+                       {
 
-                    //
-                    // Wait for any outstanding queued flushes to complete
-                    //
+                           AFSFlushExtents( pFcb,
+                                            &pCcb->AuthGroup);
+                       }
 
-                    AFSWaitOnQueuedFlushes( pFcb);
+                       //
+                       // Wait for any outstanding queued flushes to complete
+                       //
 
-                    ASSERT( pFcb->Specific.File.ExtentsDirtyCount == 0 &&
-                            pFcb->Specific.File.QueuedFlushCount == 0);
+                       AFSWaitOnQueuedFlushes( pFcb);
 
-                    AFSReleaseResource( &pFcb->NPFcb->Resource);
+                       ASSERT( pFcb->Specific.File.ExtentsDirtyCount == 0 &&
+                               pFcb->Specific.File.QueuedFlushCount == 0);
 
-                    //
-                    // Tear 'em down, we'll not be needing them again
-                    //
+                       AFSReleaseResource( &pFcb->NPFcb->Resource);
 
-                    AFSTearDownFcbExtents( pFcb,
-                                           &pCcb->AuthGroup);
-                }
-                else
-                {
+                       //
+                       // Tear 'em down, we'll not be needing them again
+                       //
 
-                    if( pFcb->Header.NodeTypeCode == AFS_FILE_FCB &&
-                        pFcb->Specific.File.ExtentsDirtyCount &&
-                        (pCcb->GrantedAccess & FILE_WRITE_DATA))
-                    {
+                       AFSTearDownFcbExtents( pFcb,
+                                              &pCcb->AuthGroup);
+                   }
+                   else
+                   {
 
-                        AFSFlushExtents( pFcb,
-                                         &pCcb->AuthGroup);
-                    }
+                       if( pFcb->Header.NodeTypeCode == AFS_FILE_FCB &&
+                           pFcb->Specific.File.ExtentsDirtyCount &&
+                           (pCcb->GrantedAccess & FILE_WRITE_DATA))
+                       {
 
-                    AFSReleaseResource( &pFcb->NPFcb->Resource);
-                }
+                           AFSFlushExtents( pFcb,
+                                            &pCcb->AuthGroup);
+                       }
+
+                       AFSReleaseResource( &pFcb->NPFcb->Resource);
+                   }
+               }
+               else
+               {
+
+                   AFSReleaseResource( &pFcb->NPFcb->Resource);
+               }
 
                 pDirCB = pCcb->DirectoryCB;
 
@@ -327,7 +345,8 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
                 {
 
                     pParentObjectInfo = AFSFindObjectInfo( pObjectInfo->VolumeCB,
-                                                           &pObjectInfo->ParentFileId);
+                                                           &pObjectInfo->ParentFileId,
+                                                           FALSE);
                 }
 
                 //
@@ -418,7 +437,7 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
                             //
 
                             AFSDeleteDirEntry( pParentObjectInfo,
-                                               pDirCB);
+                                               &pDirCB);
 
                             AFSAcquireShared( &pObjectInfo->NonPagedInfo->ObjectInfoLock,
                                               TRUE);
@@ -483,6 +502,8 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
                                   pParentObjectInfo->Specific.Directory.ChildOpenReferenceCount));
                 }
 
+               pIrpSp->FileObject->FsContext = NULL;
+
                 //
                 // Decrement the reference count on the Fcb. this is protecting it from teardown.
                 //
@@ -507,6 +528,8 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
 
                 pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
 
+               pIrpSp->FileObject->FsContext2 = NULL;
+
                 //
                 // Object the Parent ObjectInformationCB
                 //
@@ -515,7 +538,8 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
                 {
 
                     pParentObjectInfo = AFSFindObjectInfo( pObjectInfo->VolumeCB,
-                                                           &pObjectInfo->ParentFileId);
+                                                           &pObjectInfo->ParentFileId,
+                                                           FALSE);
                 }
 
                 AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
@@ -535,24 +559,6 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
                 stPipeClose.RootId = pObjectInfo->VolumeCB->ObjectInformation.FileId;
 
                 //
-                // Issue the open request to the service
-                //
-
-                /*
-                AFSProcessRequest( AFS_REQUEST_TYPE_PIPE_CLOSE,
-                                   AFS_REQUEST_FLAG_SYNCHRONOUS,
-                                   &pFcb->AuthGroup,
-                                   &pDirCB->NameInformation.FileName,
-                                   NULL,
-                                   NULL,
-                                   0,
-                                   (void *)&stPipeClose,
-                                   sizeof( AFSPipeOpenCloseRequestCB),
-                                   NULL,
-                                   NULL);
-                */
-
-                //
                 // Remove the Ccb and de-allocate it
                 //
 
@@ -578,6 +584,8 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
 
                 AFSReleaseResource( &pFcb->NPFcb->Resource);
 
+               pIrpSp->FileObject->FsContext = NULL;
+
                 lCount = InterlockedDecrement( &pFcb->OpenReferenceCount);
 
                 AFSDbgTrace(( AFS_SUBSYSTEM_FCB_REF_COUNTING,
@@ -592,6 +600,7 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
             }
 
             default:
+           {
 
                 AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
                               AFS_TRACE_LEVEL_ERROR,
@@ -599,6 +608,7 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
                               pFcb->Header.NodeTypeCode));
 
                 break;
+           }
         }
 
 try_exit: