Windows: Pin the Cc FileObject during section create.
authorRod Widdowson <rdw@your-file-system.com>
Sun, 25 Aug 2013 16:16:39 +0000 (09:16 -0700)
committerJeffrey Altman <jaltman@your-file-system.com>
Fri, 30 Aug 2013 19:11:48 +0000 (12:11 -0700)
This means that if we purge the data cache while the section is being
created then the MJ_CLOSE will not happen until we unpin the FO.

Thus we can drop any embarsssing locks prior to the close and
meddling antivirus products can do odd stuff in the close path.

Note that there may not be a file object, but in that case there
will be no close on the purge since any CcInitialize operations
will wait on us dropping the SOP lock exe - hence the SOP cannot
be set up.

Also note that this only applies to the data section,
but we do not purge the image section.

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

src/WINNT/afsrdr/common/AFSRedirCommonStructs.h
src/WINNT/afsrdr/kernel/fs/AFSFastIoSupport.cpp

index bddd447..946b330 100644 (file)
@@ -391,6 +391,13 @@ typedef struct AFS_FCB
 
             LONG                ExtentLength; // in KBs
 
+           //
+           // We pin the Cc File Object between AcquireFileForNtCreateSection
+           // and ReleaseFileForNtCreateSection.  Protected by SOP lock
+           //
+
+           PFILE_OBJECT        SectionCreateFO;
+
         } File;
 
         struct
index 366a009..6ea1211 100644 (file)
@@ -271,6 +271,19 @@ AFSFastIoAcquireFile( IN struct _FILE_OBJECT *FileObject)
     AFSAcquireExcl( &pFcb->NPFcb->SectionObjectResource,
                     TRUE);
 
+    if( NULL == pFcb->Specific.File.SectionCreateFO )
+    {
+       //
+       // If not re-entrant then save and reference
+       //
+       pFcb->Specific.File.SectionCreateFO =
+         CcGetFileObjectFromSectionPtrs( &pFcb->NPFcb->SectionObjectPointers );
+       if( NULL !=  pFcb->Specific.File.SectionCreateFO )
+       {
+           ObReferenceObject( pFcb->Specific.File.SectionCreateFO);
+       }
+    }
+
     return;
 }
 
@@ -282,6 +295,8 @@ AFSFastIoReleaseFile( IN struct _FILE_OBJECT *FileObject)
 
     if( ExIsResourceAcquiredExclusiveLite( &pFcb->NPFcb->SectionObjectResource))
     {
+       PFILE_OBJECT fileObject = pFcb->Specific.File.SectionCreateFO;
+       pFcb->Specific.File.SectionCreateFO = NULL;
 
         AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
@@ -290,6 +305,15 @@ AFSFastIoReleaseFile( IN struct _FILE_OBJECT *FileObject)
                       PsGetCurrentThread()));
 
         AFSReleaseResource( &pFcb->NPFcb->SectionObjectResource);
+
+       //
+       // Now defer the Cc file object (if there was one) now that we are lock free
+       //
+
+       if( NULL != fileObject )
+       {
+           ObDereferenceObject( fileObject );
+       }
     }
 
     return;