Windows: DirOpenReferenceCount reorganizing completed
[openafs.git] / src / WINNT / afsrdr / kernel / lib / AFSNetworkProviderSupport.cpp
index 26d3a6c..5918a2c 100644 (file)
@@ -47,7 +47,6 @@ AFSAddConnection( IN AFSNetworkProviderConnectionCB *ConnectCB,
     NTSTATUS ntStatus = STATUS_SUCCESS;
     AFSProviderConnectionCB *pConnection = NULL, *pLastConnection = NULL;
     UNICODE_STRING uniRemoteName;
-    USHORT usIndex = 0;
     AFSDeviceExt *pRDRDevExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
 
     __Enter
@@ -55,7 +54,7 @@ AFSAddConnection( IN AFSNetworkProviderConnectionCB *ConnectCB,
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
-                      "AFSAddConnection Acquiring AFSProviderListLock lock %08lX EXCL %08lX\n",
+                      "AFSAddConnection Acquiring AFSProviderListLock lock %p EXCL %08lX\n",
                       &pRDRDevExt->Specific.RDR.ProviderListLock,
                       PsGetCurrentThread());
 
@@ -418,7 +417,7 @@ AFSCancelConnection( IN AFSNetworkProviderConnectionCB *ConnectCB,
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
-                      "AFSCancelConnection Acquiring AFSProviderListLock lock %08lX EXCL %08lX\n",
+                      "AFSCancelConnection Acquiring AFSProviderListLock lock %p EXCL %08lX\n",
                       &pRDRDevExt->Specific.RDR.ProviderListLock,
                       PsGetCurrentThread());
 
@@ -512,12 +511,12 @@ AFSCancelConnection( IN AFSNetworkProviderConnectionCB *ConnectCB,
         if( pConnection->Comment.Buffer != NULL)
         {
 
-            AFSExFreePool( pConnection->Comment.Buffer);
+            AFSExFreePoolWithTag( pConnection->Comment.Buffer, 0);
         }
 
         ConnectionResult->LocalName = pConnection->LocalName;
 
-        AFSExFreePool( pConnection);
+        AFSExFreePoolWithTag( pConnection, AFS_PROVIDER_CB);
 
         ConnectionResult->Status = WN_SUCCESS;
 
@@ -565,7 +564,7 @@ AFSGetConnection( IN AFSNetworkProviderConnectionCB *ConnectCB,
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
-                      "AFSGetConnection Acquiring AFSProviderListLock lock %08lX SHARED %08lX\n",
+                      "AFSGetConnection Acquiring AFSProviderListLock lock %p SHARED %08lX\n",
                       &pRDRDevExt->Specific.RDR.ProviderListLock,
                       PsGetCurrentThread());
 
@@ -776,7 +775,7 @@ AFSListConnections( IN OUT AFSNetworkProviderConnectionCB *ConnectCB,
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
-                      "AFSListConnections Acquiring AFSProviderListLock lock %08lX SHARED %08lX\n",
+                      "AFSListConnections Acquiring AFSProviderListLock lock %p SHARED %08lX\n",
                       &pRDRDevExt->Specific.RDR.ProviderListLock,
                       PsGetCurrentThread());
 
@@ -983,7 +982,7 @@ try_exit:
         if( uniRemoteName.Buffer != NULL)
         {
 
-            AFSExFreePool( uniRemoteName.Buffer);
+            AFSExFreePoolWithTag( uniRemoteName.Buffer, 0);
         }
     }
 
@@ -1184,7 +1183,7 @@ AFSLocateEnumRootEntry( IN UNICODE_STRING *RemoteName)
 {
 
     AFSProviderConnectionCB *pConnection = NULL;
-    UNICODE_STRING uniServerName, uniRemoteName = *RemoteName;
+    UNICODE_STRING uniRemoteName = *RemoteName;
     AFSDeviceExt *pRDRDevExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
 
     __Enter
@@ -1228,13 +1227,11 @@ AFSEnumerateConnection( IN OUT AFSNetworkProviderConnectionCB *ConnectCB,
 {
 
     NTSTATUS ntStatus = STATUS_SUCCESS;
-    AFSDeviceExt *pDeviceExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
     ULONG ulCRC = 0, ulCopiedLength = 0;
     AFSDirectoryCB *pShareDirEntry = NULL;
     AFSDirectoryCB *pDirEntry = NULL, *pTargetDirEntry = NULL;
     ULONG ulIndex = 0;
-    BOOLEAN bContinueProcessing = TRUE;
-    AFSFileInfoCB stFileInformation;
+    LONG lCount;
 
     __Enter
     {
@@ -1258,7 +1255,7 @@ AFSEnumerateConnection( IN OUT AFSNetworkProviderConnectionCB *ConnectCB,
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
-                      "AFSEnumerateConnection Acquiring GlobalRoot DirectoryNodeHdr.TreeLock lock %08lX SHARED %08lX\n",
+                      "AFSEnumerateConnection Acquiring GlobalRoot DirectoryNodeHdr.TreeLock lock %p SHARED %08lX\n",
                       AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.TreeLock,
                       PsGetCurrentThread());
 
@@ -1298,7 +1295,7 @@ AFSEnumerateConnection( IN OUT AFSNetworkProviderConnectionCB *ConnectCB,
             }
         }
 
-        InterlockedIncrement( &pShareDirEntry->OpenReferenceCount);
+        lCount = InterlockedIncrement( &pShareDirEntry->DirOpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
@@ -1306,12 +1303,13 @@ AFSEnumerateConnection( IN OUT AFSNetworkProviderConnectionCB *ConnectCB,
                       &pShareDirEntry->NameInformation.FileName,
                       pShareDirEntry,
                       NULL,
-                      pShareDirEntry->OpenReferenceCount);
+                      lCount);
 
         AFSReleaseResource( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.TreeLock);
 
         //
         // Setup the request to evaluate the entry
+        // On success, pTargetDirEntry has the DirOpenReferenceCount held
         //
 
         ntStatus = AFSEvaluateRootEntry( pShareDirEntry,
@@ -1394,15 +1392,21 @@ AFSEnumerateConnection( IN OUT AFSNetworkProviderConnectionCB *ConnectCB,
             pDirEntry = (AFSDirectoryCB *)pDirEntry->ListEntry.fLink;
         }
 
-        InterlockedDecrement( &pTargetDirEntry->OpenReferenceCount);
+        //
+        // Release the DirOpenReferenceCount obtained from AFSEvaluateRootEntry
+        //
+
+        lCount = InterlockedDecrement( &pTargetDirEntry->DirOpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSEnumerateConnection Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
-                                                    &pTargetDirEntry->NameInformation.FileName,
-                                                    pTargetDirEntry,
-                                                    NULL,
-                                                    pTargetDirEntry->OpenReferenceCount);
+                      &pTargetDirEntry->NameInformation.FileName,
+                      pTargetDirEntry,
+                      NULL,
+                      lCount);
+
+        ASSERT( lCount >= 0);
 
         *CopiedLength = ulCopiedLength;
 
@@ -1412,7 +1416,17 @@ try_exit:
 
         if( pShareDirEntry != NULL)
         {
-            InterlockedDecrement( &pShareDirEntry->OpenReferenceCount);
+            lCount = InterlockedDecrement( &pShareDirEntry->DirOpenReferenceCount);
+
+            AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSEnumerateConnection1 Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
+                          &pShareDirEntry->NameInformation.FileName,
+                          pShareDirEntry,
+                          NULL,
+                          lCount);
+
+            ASSERT( lCount >= 0);
         }
     }
 
@@ -1481,7 +1495,7 @@ AFSGetConnectionInfo( IN AFSNetworkProviderConnectionCB *ConnectCB,
             try_return( ntStatus = STATUS_DEVICE_NOT_READY);
         }
 
-               uniFullName = uniRemoteName;
+        uniFullName = uniRemoteName;
 
         if( uniRemoteName.Buffer[ 0] == L'\\' &&
             uniRemoteName.Buffer[ 1] == L'\\')
@@ -1565,7 +1579,7 @@ AFSGetConnectionInfo( IN AFSNetworkProviderConnectionCB *ConnectCB,
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
-                      "AFSGetConnectionInfo Acquiring AFSProviderListLock lock %08lX SHARED %08lX\n",
+                      "AFSGetConnectionInfo Acquiring AFSProviderListLock lock %p SHARED %08lX\n",
                       &pRDRDevExt->Specific.RDR.ProviderListLock,
                       PsGetCurrentThread());
 
@@ -1656,7 +1670,6 @@ AFSGetConnectionInfo( IN AFSNetworkProviderConnectionCB *ConnectCB,
         if( pConnection == NULL)
         {
             UNICODE_STRING uniFullName;
-            AFSFileID stFileID;
             AFSDirEnumEntry *pDirEnumEntry = NULL;
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
@@ -1670,17 +1683,11 @@ AFSGetConnectionInfo( IN AFSNetworkProviderConnectionCB *ConnectCB,
             AFSReleaseResource( &pRDRDevExt->Specific.RDR.ProviderListLock);
 
             //
-            // Perform a case insensitive search
-            //
-
-            //
             // OK, ask the CM about this component name
             //
 
-            stFileID = AFSGlobalRoot->ObjectInformation.FileId;
-
             ntStatus = AFSEvaluateTargetByName( NULL,
-                                                &stFileID,
+                                                &AFSGlobalRoot->ObjectInformation,
                                                 &uniShareName,
                                                 &pDirEnumEntry);
 
@@ -1700,7 +1707,7 @@ AFSGetConnectionInfo( IN AFSNetworkProviderConnectionCB *ConnectCB,
             // Don't need this
             //
 
-            AFSExFreePool( pDirEnumEntry);
+            AFSExFreePoolWithTag( pDirEnumEntry, AFS_GENERIC_MEMORY_3_TAG);
 
             //
             // The share name is valid
@@ -1753,11 +1760,11 @@ AFSGetConnectionInfo( IN AFSNetworkProviderConnectionCB *ConnectCB,
 
             AFSReleaseResource( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.TreeLock);
 
-            AFSExFreePool( uniFullName.Buffer);
+            AFSExFreePoolWithTag( uniFullName.Buffer, 0);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
                           AFS_TRACE_LEVEL_VERBOSE,
-                          "AFSGetConnectionInfo Acquiring AFSProviderListLock lock %08lX SHARED %08lX\n",
+                          "AFSGetConnectionInfo Acquiring AFSProviderListLock lock %p SHARED %08lX\n",
                           &pRDRDevExt->Specific.RDR.ProviderListLock,
                           PsGetCurrentThread());
 
@@ -1885,7 +1892,7 @@ try_exit:
         if ( uniRemainingPathLocal.Buffer )
         {
 
-            AFSExFreePool( uniRemainingPathLocal.Buffer);
+            AFSExFreePoolWithTag( uniRemainingPathLocal.Buffer, 0);
         }
     }