Windows: AFSClose() DirOpenReferenceCount handling
authorJeffrey Altman <jaltman@your-file-system.com>
Sat, 29 Dec 2012 05:29:45 +0000 (00:29 -0500)
committerJeffrey Altman <jaltman@your-file-system.com>
Thu, 31 Jan 2013 19:19:26 +0000 (11:19 -0800)
Unless the caller of AFSRemoveCcb() steals the DirectoryCB object
from the AFSCcb before calling AFSRemoveCcb(), AFSRemoveCcb() will
release the reference count.

In all but one case where the DirectoryCB must be accessed after
the AFSCcb is destroyed AFSClose() can now let AFSRemoveCcb() do the
work.

Change-Id: I8d631d79b2465cd6f2e31444fd052270b078915c
Reviewed-on: http://gerrit.openafs.org/8854
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
Tested-by: Jeffrey Altman <jaltman@your-file-system.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>

src/WINNT/afsrdr/kernel/lib/AFSClose.cpp

index 2c19d7d..d095302 100644 (file)
@@ -144,8 +144,6 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
                                    NULL,
                                    NULL);
 
-                pDirCB = pCcb->DirectoryCB;
-
                 //
                 // Remove the Ccb and de-allocate it
                 //
@@ -153,18 +151,6 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
                 AFSRemoveCcb( pFcb,
                               pCcb);
 
-                lCount = InterlockedDecrement( &pDirCB->DirOpenReferenceCount);
-
-                AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
-                              AFS_TRACE_LEVEL_VERBOSE,
-                              "AFSClose (IOCtl) Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
-                              &pDirCB->NameInformation.FileName,
-                              pDirCB,
-                              pCcb,
-                              lCount);
-
-                ASSERT( lCount >= 0);
-
                 //
                 // If this is not the root then decrement the open child reference count
                 //
@@ -211,8 +197,6 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
 
                 pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
 
-                pDirCB = pCcb->DirectoryCB;
-
                 //
                 // Remove the Ccb and de-allocate it
                 //
@@ -220,18 +204,6 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
                 AFSRemoveCcb( pFcb,
                               pCcb);
 
-                lCount = InterlockedDecrement( &pDirCB->DirOpenReferenceCount);
-
-                AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
-                              AFS_TRACE_LEVEL_VERBOSE,
-                              "AFSClose Decrement (Root ALL) count on %wZ DE %p Ccb %p Cnt %d\n",
-                              &pDirCB->NameInformation.FileName,
-                              pDirCB,
-                              pCcb,
-                              lCount);
-
-                ASSERT( lCount >= 0);
-
                 AFSReleaseResource( &pFcb->NPFcb->Resource);
 
                 lCount = InterlockedDecrement( &pFcb->OpenReferenceCount);
@@ -332,6 +304,12 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
                 pDirCB = pCcb->DirectoryCB;
 
                 //
+                // Steal the DirOpenReferenceCount from the Ccb
+                //
+
+                pCcb->DirectoryCB = NULL;
+
+                //
                 // Remove the Ccb and de-allocate it
                 //
 
@@ -534,8 +512,6 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
                                    NULL);
                 */
 
-                pDirCB = pCcb->DirectoryCB;
-
                 //
                 // Remove the Ccb and de-allocate it
                 //
@@ -543,18 +519,6 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
                 AFSRemoveCcb( pFcb,
                               pCcb);
 
-                lCount = InterlockedDecrement( &pDirCB->DirOpenReferenceCount);
-
-                AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
-                              AFS_TRACE_LEVEL_VERBOSE,
-                              "AFSClose (Share) Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
-                              &pDirCB->NameInformation.FileName,
-                              pDirCB,
-                              pCcb,
-                              lCount);
-
-                ASSERT( lCount >= 0);
-
                 //
                 // If this is not the root then decrement the open child reference count
                 //