Windows: DE Reference count added during create
authorPeter Scott <pscott@kerneldrivers.com>
Tue, 1 Nov 2011 14:55:37 +0000 (08:55 -0600)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Tue, 1 Nov 2011 17:28:28 +0000 (10:28 -0700)
A reference count is added under lock to a newly created DE to
ensure it is not removed through deletion while in flight.

Change-Id: If0955c4a6c4cf197a4e071f9c6022875aabb70bb
Reviewed-on: http://gerrit.openafs.org/5775
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Tested-by: Jeffrey Altman <jaltman@secure-endpoints.com>
Reviewed-by: Jeffrey Altman <jaltman@secure-endpoints.com>

src/WINNT/afsrdr/kernel/lib/AFSCommSupport.cpp
src/WINNT/afsrdr/kernel/lib/AFSCreate.cpp
src/WINNT/afsrdr/kernel/lib/AFSNameSupport.cpp

index df5ce4b..51311ab 100644 (file)
@@ -1325,8 +1325,6 @@ AFSNotifyFileCreate( IN GUID            *AuthGroup,
                                             ulCRC,
                                             &pDirNode);
 
-            AFSReleaseResource( ParentObjectInfo->Specific.Directory.DirectoryNodeHdr.TreeLock);
-
             if( pDirNode != NULL)
             {
 
@@ -1335,11 +1333,24 @@ AFSNotifyFileCreate( IN GUID            *AuthGroup,
                               "AFSNotifyFileCreate Located dir entry for file %wZ\n",
                               FileName);
 
+                InterlockedIncrement( &pDirNode->OpenReferenceCount);
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSNotifyFileCreate Increment count on %wZ DE %p Cnt %d\n",
+                              &pDirNode->NameInformation.FileName,
+                              pDirNode,
+                              pDirNode->OpenReferenceCount);
+
                 *DirNode = pDirNode;
 
+                AFSReleaseResource( ParentObjectInfo->Specific.Directory.DirectoryNodeHdr.TreeLock);
+
                 try_return( ntStatus = STATUS_REPARSE);
             }
 
+            AFSReleaseResource( ParentObjectInfo->Specific.Directory.DirectoryNodeHdr.TreeLock);
+
             //
             // We are unsure of our current data so set the verify flag. It may already be set
             // but no big deal to reset it
index 0143aed..bc1358f 100644 (file)
@@ -739,23 +739,6 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                               &pParentDirectoryCB->NameInformation.FileName,
                               ntStatus);
             }
-            else
-            {
-
-                //
-                // Reference the new dir entry
-                //
-
-                InterlockedIncrement( &pCcb->DirectoryCB->OpenReferenceCount);
-
-                AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
-                              AFS_TRACE_LEVEL_VERBOSE,
-                              "AFSCreate Increment (Create) count on %wZ DE %p Ccb %p Cnt %d\n",
-                              &pCcb->DirectoryCB->NameInformation.FileName,
-                              pCcb->DirectoryCB,
-                              pCcb,
-                              pCcb->DirectoryCB->OpenReferenceCount);
-            }
 
             //
             // Dereference the parent entry
@@ -2070,6 +2053,19 @@ try_exit:
                 SetFlag( pDirEntry->Flags, AFS_DIR_ENTRY_DELETED);
 
                 //
+                // Decrement the reference added during initialization of the DE
+                //
+
+                InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSProcessCreate Decrement count on %wZ DE %p Cnt %d\n",
+                              &pDirEntry->NameInformation.FileName,
+                              pDirEntry,
+                              pDirEntry->OpenReferenceCount);
+
+                //
                 // Pull the directory entry from the parent
                 //
 
index 26b6e51..7e16890 100644 (file)
@@ -2060,6 +2060,15 @@ AFSCreateDirEntry( IN GUID            *AuthGroup,
             AFSDeleteDirEntry( ParentObjectInfo,
                                pDirNode);
 
+            InterlockedIncrement( &pExistingDirNode->OpenReferenceCount);
+
+            AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSCreateDirEntry Increment count on %wZ DE %p Cnt %d\n",
+                          &pExistingDirNode->NameInformation.FileName,
+                          pExistingDirNode,
+                          pExistingDirNode->OpenReferenceCount);
+
             *DirEntry = pExistingDirNode;
 
             AFSReleaseResource( ParentObjectInfo->Specific.Directory.DirectoryNodeHdr.TreeLock);
@@ -2085,6 +2094,15 @@ AFSCreateDirEntry( IN GUID            *AuthGroup,
                                 pDirNode,
                                 TRUE);
 
+        InterlockedIncrement( &pDirNode->OpenReferenceCount);
+
+        AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                      AFS_TRACE_LEVEL_VERBOSE,
+                      "AFSCreateDirEntry Increment2 count on %wZ DE %p Cnt %d\n",
+                      &pDirNode->NameInformation.FileName,
+                      pDirNode,
+                      pDirNode->OpenReferenceCount);
+
         //
         // Pass back the dir entry
         //