Windows: AFSPrimaryVolumeWorkerThread reorg
[openafs.git] / src / WINNT / afsrdr / kernel / lib / AFSGeneric.cpp
index 060b3bb..3524907 100644 (file)
@@ -5348,7 +5348,7 @@ AFSInitPIOCtlDirectoryCB( IN AFSObjectInfoCB *ParentObjectInfo)
         }
 
         lCount = AFSObjectInfoIncrement( pObjectInfoCB,
-                                         AFS_OBJECT_REFERENCE_DIRENTRY);
+                                         AFS_OBJECT_REFERENCE_PIOCTL);
 
         AFSDbgTrace(( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
@@ -5460,7 +5460,7 @@ try_exit:
             {
 
                 lCount = AFSObjectInfoDecrement( pObjectInfoCB,
-                                                 AFS_OBJECT_REFERENCE_DIRENTRY);
+                                                 AFS_OBJECT_REFERENCE_PIOCTL);
 
                 AFSDbgTrace(( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -6234,157 +6234,169 @@ AFSReleaseObjectInfo( IN AFSObjectInfoCB **ppObjectInfo)
 void
 AFSDeleteObjectInfo( IN AFSObjectInfoCB **ppObjectInfo)
 {
-
     BOOLEAN bAcquiredTreeLock = FALSE;
     AFSObjectInfoCB *pObjectInfo = NULL;
+    AFSVolumeCB * pVolume = NULL;
     BOOLEAN bHeldInService;
     AFSObjectInfoCB * pParentObjectInfo = NULL;
     AFSFileID FileId;
     LONG lCount;
 
-    if ( BooleanFlagOn( (*ppObjectInfo)->Flags, AFS_OBJECT_ROOT_VOLUME))
+    __Enter
     {
+        if ( BooleanFlagOn( (*ppObjectInfo)->Flags, AFS_OBJECT_ROOT_VOLUME))
+        {
 
-        //
-        // AFSDeleteObjectInfo should never be called on the ObjectInformationCB
-        // embedded in the VolumeCB.
-        //
-
-        ASSERT( FALSE);
-
-        return;
-    }
+            //
+            // AFSDeleteObjectInfo should never be called on the ObjectInformationCB
+            // embedded in the VolumeCB.
+            //
 
-    pObjectInfo = (AFSObjectInfoCB *) InterlockedCompareExchangePointer( (PVOID *)ppObjectInfo,
-                                                                         NULL,
-                                                                         *ppObjectInfo);
+            ASSERT( FALSE);
 
-    if ( pObjectInfo == NULL)
-    {
+            return;
+        }
 
-        return;
-    }
+        pVolume = (*ppObjectInfo)->VolumeCB;
 
-    ASSERT( *ppObjectInfo == NULL);
+        if( !ExIsResourceAcquiredExclusiveLite( pVolume->ObjectInfoTree.TreeLock))
+        {
 
-    if( !ExIsResourceAcquiredExclusiveLite( pObjectInfo->VolumeCB->ObjectInfoTree.TreeLock))
-    {
+            ASSERT( !ExIsResourceAcquiredLite( pVolume->ObjectInfoTree.TreeLock));
 
-        ASSERT( !ExIsResourceAcquiredLite( pObjectInfo->VolumeCB->ObjectInfoTree.TreeLock));
+            AFSAcquireExcl( pVolume->ObjectInfoTree.TreeLock,
+                            TRUE);
 
-        AFSAcquireExcl( pObjectInfo->VolumeCB->ObjectInfoTree.TreeLock,
-                        TRUE);
+            bAcquiredTreeLock = TRUE;
+        }
 
-        bAcquiredTreeLock = TRUE;
-    }
+        for ( lCount = 0; lCount < AFS_OBJECT_REFERENCE_MAX; lCount++)
+        {
 
-    ASSERT( pObjectInfo->ObjectReferenceCount == 0);
+            ASSERT( (*ppObjectInfo)->ObjectReferences[ lCount] >= 0);
+        }
 
-    bHeldInService = BooleanFlagOn( pObjectInfo->Flags, AFS_OBJECT_HELD_IN_SERVICE);
+        ASSERT( (*ppObjectInfo)->ObjectReferenceCount == 0);
 
-    if ( BooleanFlagOn( pObjectInfo->Flags, AFS_OBJECT_FLAGS_PARENT_FID))
-    {
+        pObjectInfo = (AFSObjectInfoCB *) InterlockedCompareExchangePointer( (PVOID *)ppObjectInfo,
+                                                                             NULL,
+                                                                             *ppObjectInfo);
 
-        pParentObjectInfo = AFSFindObjectInfo( pObjectInfo->VolumeCB,
-                                               &pObjectInfo->ParentFileId);
-    }
+        if ( pObjectInfo == NULL)
+        {
 
-    //
-    // Remove it from the tree and list if it was inserted
-    //
+            try_return( NOTHING);
+        }
 
-    if( BooleanFlagOn( pObjectInfo->Flags, AFS_OBJECT_INSERTED_HASH_TREE))
-    {
+        ASSERT( *ppObjectInfo == NULL);
 
-        AFSRemoveHashEntry( &pObjectInfo->VolumeCB->ObjectInfoTree.TreeHead,
-                            &pObjectInfo->TreeEntry);
-    }
+        if ( BooleanFlagOn( pObjectInfo->Flags, AFS_OBJECT_FLAGS_PARENT_FID))
+        {
 
-    if( BooleanFlagOn( pObjectInfo->Flags, AFS_OBJECT_INSERTED_VOLUME_LIST))
-    {
+            pParentObjectInfo = AFSFindObjectInfo( pVolume,
+                                                   &pObjectInfo->ParentFileId);
+            if( pParentObjectInfo != NULL)
+            {
 
-        if( pObjectInfo->ListEntry.fLink == NULL)
-        {
+                ClearFlag( pObjectInfo->Flags, AFS_OBJECT_FLAGS_PARENT_FID);
 
-            pObjectInfo->VolumeCB->ObjectInfoListTail = (AFSObjectInfoCB *)pObjectInfo->ListEntry.bLink;
+                lCount = AFSObjectInfoDecrement( pParentObjectInfo,
+                                                 AFS_OBJECT_REFERENCE_CHILD);
 
-            if( pObjectInfo->VolumeCB->ObjectInfoListTail != NULL)
-            {
+                AFSDbgTrace(( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSDeleteObjectInfo Decrement count on parent object %p Cnt %d\n",
+                              pParentObjectInfo,
+                              lCount));
 
-                pObjectInfo->VolumeCB->ObjectInfoListTail->ListEntry.fLink = NULL;
+                AFSReleaseObjectInfo( &pParentObjectInfo);
             }
         }
-        else
+
+        //
+        // Remove it from the tree and list if it was inserted
+        //
+
+        if( BooleanFlagOn( pObjectInfo->Flags, AFS_OBJECT_INSERTED_HASH_TREE))
         {
 
-            ((AFSObjectInfoCB *)(pObjectInfo->ListEntry.fLink))->ListEntry.bLink = pObjectInfo->ListEntry.bLink;
+            AFSRemoveHashEntry( &pVolume->ObjectInfoTree.TreeHead,
+                                &pObjectInfo->TreeEntry);
         }
 
-        if( pObjectInfo->ListEntry.bLink == NULL)
+        if( BooleanFlagOn( pObjectInfo->Flags, AFS_OBJECT_INSERTED_VOLUME_LIST))
         {
 
-            pObjectInfo->VolumeCB->ObjectInfoListHead = (AFSObjectInfoCB *)pObjectInfo->ListEntry.fLink;
+            if( pObjectInfo->ListEntry.fLink == NULL)
+            {
+
+                pVolume->ObjectInfoListTail = (AFSObjectInfoCB *)pObjectInfo->ListEntry.bLink;
 
-            if( pObjectInfo->VolumeCB->ObjectInfoListHead != NULL)
+                if( pVolume->ObjectInfoListTail != NULL)
+                {
+
+                    pVolume->ObjectInfoListTail->ListEntry.fLink = NULL;
+                }
+            }
+            else
             {
 
-                pObjectInfo->VolumeCB->ObjectInfoListHead->ListEntry.bLink = NULL;
+                ((AFSObjectInfoCB *)(pObjectInfo->ListEntry.fLink))->ListEntry.bLink = pObjectInfo->ListEntry.bLink;
             }
-        }
-        else
-        {
 
-            ((AFSObjectInfoCB *)(pObjectInfo->ListEntry.bLink))->ListEntry.fLink = pObjectInfo->ListEntry.fLink;
-        }
-    }
+            if( pObjectInfo->ListEntry.bLink == NULL)
+            {
 
-    if( pParentObjectInfo != NULL)
-    {
+                pVolume->ObjectInfoListHead = (AFSObjectInfoCB *)pObjectInfo->ListEntry.fLink;
 
-        ClearFlag( pObjectInfo->Flags, AFS_OBJECT_FLAGS_PARENT_FID);
+                if( pVolume->ObjectInfoListHead != NULL)
+                {
 
-        lCount = AFSObjectInfoDecrement( pParentObjectInfo,
-                                         AFS_OBJECT_REFERENCE_CHILD);
+                    pVolume->ObjectInfoListHead->ListEntry.bLink = NULL;
+                }
+            }
+            else
+            {
 
-        AFSDbgTrace(( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
-                      AFS_TRACE_LEVEL_VERBOSE,
-                      "AFSDeleteObjectInfo Decrement count on parent object %p Cnt %d\n",
-                      pParentObjectInfo,
-                      lCount));
+                ((AFSObjectInfoCB *)(pObjectInfo->ListEntry.bLink))->ListEntry.fLink = pObjectInfo->ListEntry.fLink;
+            }
+        }
 
-        AFSReleaseObjectInfo( &pParentObjectInfo);
-    }
+        bHeldInService = BooleanFlagOn( pObjectInfo->Flags, AFS_OBJECT_HELD_IN_SERVICE);
 
-    if( bAcquiredTreeLock)
-    {
+        if( bHeldInService)
+        {
 
-        AFSReleaseResource( pObjectInfo->VolumeCB->ObjectInfoTree.TreeLock);
-    }
+            FileId = pObjectInfo->FileId;
+        }
 
-    if( bHeldInService)
-    {
+        ASSERT( pObjectInfo->ObjectReferenceCount == 0);
 
-        FileId = pObjectInfo->FileId;
-    }
+        ExDeleteResourceLite( &pObjectInfo->NonPagedInfo->ObjectInfoLock);
 
-    ASSERT( pObjectInfo->ObjectReferenceCount == 0);
+        ExDeleteResourceLite( &pObjectInfo->NonPagedInfo->DirectoryNodeHdrLock);
 
-    ExDeleteResourceLite( &pObjectInfo->NonPagedInfo->ObjectInfoLock);
+        AFSExFreePoolWithTag( pObjectInfo->NonPagedInfo, AFS_NP_OBJECT_INFO_TAG);
 
-    ExDeleteResourceLite( &pObjectInfo->NonPagedInfo->DirectoryNodeHdrLock);
+        AFSExFreePoolWithTag( pObjectInfo, AFS_OBJECT_INFO_TAG);
 
-    AFSExFreePoolWithTag( pObjectInfo->NonPagedInfo, AFS_NP_OBJECT_INFO_TAG);
+try_exit:
 
-    AFSExFreePoolWithTag( pObjectInfo, AFS_OBJECT_INFO_TAG);
+        if( bAcquiredTreeLock)
+        {
 
-    //
-    // Release the fid in the service
-    //
+            AFSReleaseResource( pVolume->ObjectInfoTree.TreeLock);
+        }
 
-    if( bHeldInService)
-    {
+        //
+        // Release the fid in the service
+        //
 
-        AFSReleaseFid( &FileId);
+        if( bHeldInService)
+        {
+
+            AFSReleaseFid( &FileId);
+        }
     }
 
     return;