Windows: More ObjectInformation RefCnt Protection
authorJeffrey Altman <jaltman@your-file-system.com>
Wed, 17 Apr 2013 22:35:36 +0000 (18:35 -0400)
committerJeffrey Altman <jaltman@your-file-system.com>
Fri, 26 Apr 2013 13:24:18 +0000 (06:24 -0700)
Protect addition ObjectInformation Reference count
transitions with the VolumeCB.ObjectInfoTree.TreeLock.

AFSProcessUserFsRequest
AFSSetRenameInfo
AFSInvalidateCache
AFSInvalidateVolume
AFSAllocateObjectInfo
AFSDeleteObjectInfo
AFSGetObjectStatus
AFSDeleteDirEntry

Change-Id: Icd108bb8253e5e84c673f3de04f882afea725274
Reviewed-on: http://gerrit.openafs.org/9799
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Rod Widdowson <rdw@steadingsoftware.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>

src/WINNT/afsrdr/kernel/lib/AFSFSControl.cpp
src/WINNT/afsrdr/kernel/lib/AFSFileInfo.cpp
src/WINNT/afsrdr/kernel/lib/AFSGeneric.cpp
src/WINNT/afsrdr/kernel/lib/AFSNameSupport.cpp

index dc14141..0557e1e 100644 (file)
@@ -1050,6 +1050,9 @@ AFSProcessUserFsRequest( IN PIRP Irp)
                                   pFcb->ObjectInformation->FileAttributes,
                                   ntStatus));
 
+                    AFSAcquireShared( pFcb->ObjectInformation->VolumeCB->ObjectInfoTree.TreeLock,
+                                      TRUE);
+
                     lCount = AFSObjectInfoDecrement( pParentObjectInfo,
                                                      AFS_OBJECT_REFERENCE_FS_REQ);
 
@@ -1058,6 +1061,8 @@ AFSProcessUserFsRequest( IN PIRP Irp)
                                   "AFSProcessUserFsRequest Decrement count on object %p Cnt %d\n",
                                   pParentObjectInfo,
                                   lCount));
+
+                    AFSReleaseResource( pFcb->ObjectInformation->VolumeCB->ObjectInfoTree.TreeLock);
                 }
 
                 break;
index 3846237..e604caf 100644 (file)
@@ -3295,6 +3295,14 @@ AFSSetRenameInfo( IN PIRP Irp)
 
             lCount = InterlockedIncrement( &pTargetParentObject->Specific.Directory.ChildOpenReferenceCount);
 
+
+            //
+            // Guaranteed to be in the same volume
+            //
+
+            AFSAcquireExcl( pSrcParentObject->VolumeCB->ObjectInfoTree.TreeLock,
+                            TRUE);
+
             lCount = AFSObjectInfoIncrement( pTargetParentObject,
                                              AFS_OBJECT_REFERENCE_CHILD);
 
@@ -3317,6 +3325,8 @@ AFSSetRenameInfo( IN PIRP Irp)
 
             SetFlag( pSrcFcb->ObjectInformation->Flags, AFS_OBJECT_FLAGS_PARENT_FID);
 
+            AFSReleaseResource( pSrcParentObject->VolumeCB->ObjectInfoTree.TreeLock);
+
             ulNotificationAction = FILE_ACTION_ADDED;
         }
         else
index 3bed1dc..8239fea 100644 (file)
@@ -2144,7 +2144,7 @@ AFSInvalidateCache( IN AFSInvalidateCacheCB *InvalidateCB)
             try_return( ntStatus);
         }
 
-        AFSAcquireShared( pVolumeCB->ObjectInfoTree.TreeLock,
+        AFSAcquireExcl( pVolumeCB->ObjectInfoTree.TreeLock,
                           TRUE);
 
         if ( AFSIsVolumeFID( &InvalidateCB->FileID))
@@ -2675,6 +2675,9 @@ AFSInvalidateVolume( IN AFSVolumeCB *VolumeCB,
             }
         }
 
+        AFSAcquireShared( VolumeCB->ObjectInfoTree.TreeLock,
+                          TRUE);
+
         //
         // Invalidate the volume root directory
         //
@@ -2693,9 +2696,14 @@ AFSInvalidateVolume( IN AFSVolumeCB *VolumeCB,
                           pCurrentObject,
                           lCount));
 
+            AFSReleaseResource( VolumeCB->ObjectInfoTree.TreeLock);
+
             AFSInvalidateObject( &pCurrentObject,
                                  Reason);
 
+            AFSAcquireShared( VolumeCB->ObjectInfoTree.TreeLock,
+                              TRUE);
+
             if ( pCurrentObject)
             {
 
@@ -2714,9 +2722,6 @@ AFSInvalidateVolume( IN AFSVolumeCB *VolumeCB,
         // Apply invalidation to all other volume objects
         //
 
-        AFSAcquireShared( VolumeCB->ObjectInfoTree.TreeLock,
-                          TRUE);
-
         pCurrentObject = VolumeCB->ObjectInfoListHead;
 
         if ( pCurrentObject)
@@ -6023,6 +6028,9 @@ AFSAllocateObjectInfo( IN AFSObjectInfoCB *ParentObjectInfo,
 
             SetFlag( pObjectInfo->Flags, AFS_OBJECT_FLAGS_PARENT_FID);
 
+            AFSAcquireShared( ParentObjectInfo->VolumeCB->ObjectInfoTree.TreeLock,
+                              TRUE);
+
             lCount = AFSObjectInfoIncrement( ParentObjectInfo,
                                              AFS_OBJECT_REFERENCE_CHILD);
 
@@ -6031,6 +6039,8 @@ AFSAllocateObjectInfo( IN AFSObjectInfoCB *ParentObjectInfo,
                           "AFSAllocateObjectInfo Increment count on parent object %p Cnt %d\n",
                           ParentObjectInfo,
                           lCount));
+
+            AFSReleaseResource( ParentObjectInfo->VolumeCB->ObjectInfoTree.TreeLock);
         }
 
         //
@@ -6311,6 +6321,9 @@ AFSDeleteObjectInfo( IN AFSObjectInfoCB **ppObjectInfo)
 
                 ClearFlag( pObjectInfo->Flags, AFS_OBJECT_FLAGS_PARENT_FID);
 
+                AFSAcquireShared( pParentObjectInfo->VolumeCB->ObjectInfoTree.TreeLock,
+                                  TRUE);
+
                 lCount = AFSObjectInfoDecrement( pParentObjectInfo,
                                                  AFS_OBJECT_REFERENCE_CHILD);
 
@@ -6320,6 +6333,8 @@ AFSDeleteObjectInfo( IN AFSObjectInfoCB **ppObjectInfo)
                               pParentObjectInfo,
                               lCount));
 
+                AFSReleaseResource( pParentObjectInfo->VolumeCB->ObjectInfoTree.TreeLock);
+
                 AFSReleaseObjectInfo( &pParentObjectInfo);
             }
         }
@@ -8006,6 +8021,9 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
 
                 pObjectInfo = &pVolumeCB->ObjectInformation;
 
+                AFSAcquireShared( pVolumeCB->ObjectInfoTree.TreeLock,
+                                  TRUE);
+
                 lCount = AFSObjectInfoIncrement( pObjectInfo,
                                                  AFS_OBJECT_REFERENCE_STATUS);
 
@@ -8014,12 +8032,14 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
                               "AFSGetObjectStatus Increment1 count on object %p Cnt %d\n",
                               pObjectInfo,
                               lCount));
+
+                AFSReleaseResource( pVolumeCB->ObjectInfoTree.TreeLock);
             }
             else
             {
 
-                AFSAcquireShared( pVolumeCB->ObjectInfoTree.TreeLock,
-                                  TRUE);
+                AFSAcquireExcl( pVolumeCB->ObjectInfoTree.TreeLock,
+                                TRUE);
 
                 ullIndex = AFSCreateLowIndex( &GetStatusInfo->FileID);
 
@@ -8210,6 +8230,9 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
 
             pObjectInfo = pDirectoryEntry->ObjectInformation;
 
+            AFSAcquireExcl( pObjectInfo->VolumeCB->ObjectInfoTree.TreeLock,
+                            TRUE);
+
             lCount = AFSObjectInfoIncrement( pObjectInfo,
                                              AFS_OBJECT_REFERENCE_STATUS);
 
@@ -8218,6 +8241,8 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
                           "AFSGetObjectStatus Increment3 count on object %p Cnt %d\n",
                           pObjectInfo,
                           lCount));
+
+            AFSReleaseResource( pObjectInfo->VolumeCB->ObjectInfoTree.TreeLock);
         }
 
         //
@@ -8294,21 +8319,26 @@ try_exit:
             ASSERT( lCount >= 0);
         }
 
-        if( pObjectInfo != NULL)
+        if( pVolumeCB != NULL)
         {
 
-            lCount = AFSObjectInfoDecrement( pObjectInfo,
-                                             AFS_OBJECT_REFERENCE_STATUS);
+            if( pObjectInfo != NULL)
+            {
 
-            AFSDbgTrace(( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
-                          AFS_TRACE_LEVEL_VERBOSE,
-                          "AFSGetObjectStatus Decrement count on object %p Cnt %d\n",
-                          pObjectInfo,
-                          lCount));
-        }
+                AFSAcquireShared( pVolumeCB->ObjectInfoTree.TreeLock,
+                                  TRUE);
 
-        if( pVolumeCB != NULL)
-        {
+                lCount = AFSObjectInfoDecrement( pObjectInfo,
+                                                 AFS_OBJECT_REFERENCE_STATUS);
+
+                AFSDbgTrace(( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSGetObjectStatus Decrement count on object %p Cnt %d\n",
+                              pObjectInfo,
+                              lCount));
+
+                AFSReleaseResource( pVolumeCB->ObjectInfoTree.TreeLock);
+            }
 
             lCount = AFSVolumeDecrement( pVolumeCB,
                                          VolumeReferenceReason);
index 4bb0203..18c8a3d 100644 (file)
@@ -2820,6 +2820,9 @@ AFSDeleteDirEntry( IN AFSObjectInfoCB *ParentObjectInfo,
             // Dereference the object for this dir entry
             //
 
+            AFSAcquireShared( pDirEntry->ObjectInformation->VolumeCB->ObjectInfoTree.TreeLock,
+                              TRUE);
+
             lCount = AFSObjectInfoDecrement( pDirEntry->ObjectInformation,
                                              AFS_OBJECT_REFERENCE_DIRENTRY);
 
@@ -2828,6 +2831,8 @@ AFSDeleteDirEntry( IN AFSObjectInfoCB *ParentObjectInfo,
                           "AFSDeletepDirEntry Decrement count on object %p Cnt %d\n",
                           pDirEntry->ObjectInformation,
                           lCount));
+
+            AFSReleaseResource( pDirEntry->ObjectInformation->VolumeCB->ObjectInfoTree.TreeLock);
         }
 
         ExDeleteResourceLite( &pDirEntry->NonPaged->Lock);