Windows: AFSInitCcb redefinition
authorJeffrey Altman <jaltman@your-file-system.com>
Sat, 29 Dec 2012 05:17:59 +0000 (00:17 -0500)
committerJeffrey Altman <jaltman@your-file-system.com>
Thu, 31 Jan 2013 19:18:11 +0000 (11:18 -0800)
The new AFSInitCcb() allocates its own DirOpenReferenceCount to
associate with the AFSCcb.DirectoryCB.

It also accepts the GrantedAccess mask and the FileAccess values
which are stored in the AFSCcb.

These changes simplify the callers and remove responsibility of
tracking whether or not the DirOpenReferenceCount was successfully
associated with the AFSCcb.

The allocated DirOpenReferenceCount is always released by
AFSRemoveCcb().

Change-Id: Ib475310d934830974c553e0eeff96b114a56541b
Reviewed-on: http://gerrit.openafs.org/8852
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/AFSCreate.cpp
src/WINNT/afsrdr/kernel/lib/AFSFcbSupport.cpp
src/WINNT/afsrdr/kernel/lib/Include/AFSCommon.h

index 61eaa22..ba1e642 100644 (file)
@@ -1314,7 +1314,10 @@ AFSOpenAFSRoot( IN PIRP Irp,
         // Initialize the Ccb for the file.
         //
 
-        ntStatus = AFSInitCcb( Ccb);
+        ntStatus = AFSInitCcb( Ccb,
+                               AFSGlobalRoot->DirectoryCB,
+                               0,
+                               0);
 
         if( !NT_SUCCESS( ntStatus))
         {
@@ -1328,12 +1331,6 @@ AFSOpenAFSRoot( IN PIRP Irp,
         }
 
         //
-        // Setup the Ccb
-        //
-
-        (*Ccb)->DirectoryCB = AFSGlobalRoot->DirectoryCB;
-
-        //
         // Increment the open count on this Fcb
         //
 
@@ -1584,7 +1581,10 @@ AFSOpenRoot( IN PIRP Irp,
         // Initialize the Ccb for the file.
         //
 
-        ntStatus = AFSInitCcb( Ccb);
+        ntStatus = AFSInitCcb( Ccb,
+                               VolumeCB->DirectoryCB,
+                               *pDesiredAccess,
+                               0);
 
         if( !NT_SUCCESS( ntStatus))
         {
@@ -1601,14 +1601,6 @@ AFSOpenRoot( IN PIRP Irp,
         bAllocatedCcb = TRUE;
 
         //
-        // Setup the ccb
-        //
-
-        (*Ccb)->DirectoryCB = VolumeCB->DirectoryCB;
-
-        (*Ccb)->GrantedAccess = *pDesiredAccess;
-
-        //
         // OK, update the share access on the fileobject
         //
 
@@ -1944,7 +1936,10 @@ AFSProcessCreate( IN PIRP               Irp,
         // Initialize the Ccb for the file.
         //
 
-        ntStatus = AFSInitCcb( Ccb);
+        ntStatus = AFSInitCcb( Ccb,
+                               pDirEntry,
+                               *pDesiredAccess,
+                               0);
 
         if( !NT_SUCCESS( ntStatus))
         {
@@ -1962,14 +1957,6 @@ AFSProcessCreate( IN PIRP               Irp,
         bAllocatedCcb = TRUE;
 
         //
-        // Initialize the Ccb
-        //
-
-        (*Ccb)->DirectoryCB = pDirEntry;
-
-        (*Ccb)->GrantedAccess = *pDesiredAccess;
-
-        //
         // If this is a file, update the headers filesizes.
         //
 
@@ -2328,7 +2315,10 @@ AFSOpenTargetDirectory( IN PIRP Irp,
         // Initialize the Ccb for the file.
         //
 
-        ntStatus = AFSInitCcb( Ccb);
+        ntStatus = AFSInitCcb( Ccb,
+                               ParentDirectoryCB,
+                               *pDesiredAccess,
+                               0);
 
         if( !NT_SUCCESS( ntStatus))
         {
@@ -2345,14 +2335,6 @@ AFSOpenTargetDirectory( IN PIRP Irp,
 
         bAllocatedCcb = TRUE;
 
-        //
-        // Initialize the Ccb
-        //
-
-        (*Ccb)->DirectoryCB = ParentDirectoryCB;
-
-        (*Ccb)->GrantedAccess = *pDesiredAccess;
-
         if( TargetDirectoryCB != NULL &&
             FsRtlAreNamesEqual( &TargetDirectoryCB->NameInformation.FileName,
                                 TargetName,
@@ -2838,7 +2820,10 @@ AFSProcessOpen( IN PIRP Irp,
         // Initialize the Ccb for the file.
         //
 
-        ntStatus = AFSInitCcb( Ccb);
+        ntStatus = AFSInitCcb( Ccb,
+                               DirectoryCB,
+                               *pDesiredAccess,
+                               ulFileAccess);
 
         if( !NT_SUCCESS( ntStatus))
         {
@@ -2855,12 +2840,6 @@ AFSProcessOpen( IN PIRP Irp,
 
         bAllocatedCcb = TRUE;
 
-        (*Ccb)->DirectoryCB = DirectoryCB;
-
-        (*Ccb)->FileAccess = ulFileAccess;
-
-        (*Ccb)->GrantedAccess = *pDesiredAccess;
-
         //
         // Perform the access check on the target if this is a mount point or symlink
         //
@@ -3197,7 +3176,10 @@ AFSProcessOverwriteSupersede( IN PDEVICE_OBJECT DeviceObject,
         // Initialize the Ccb for the file.
         //
 
-        ntStatus = AFSInitCcb( Ccb);
+        ntStatus = AFSInitCcb( Ccb,
+                               DirectoryCB,
+                               *pDesiredAccess,
+                               0);
 
         if( !NT_SUCCESS( ntStatus))
         {
@@ -3215,14 +3197,6 @@ AFSProcessOverwriteSupersede( IN PDEVICE_OBJECT DeviceObject,
         bAllocatedCcb = TRUE;
 
         //
-        // Initialize the Ccb
-        //
-
-        (*Ccb)->DirectoryCB = DirectoryCB;
-
-        (*Ccb)->GrantedAccess = *pDesiredAccess;
-
-        //
         // Set the file length to zero
         //
 
@@ -3552,7 +3526,10 @@ AFSOpenIOCtlFcb( IN PIRP Irp,
         // Initialize the Ccb for the file.
         //
 
-        ntStatus = AFSInitCcb( Ccb);
+        ntStatus = AFSInitCcb( Ccb,
+                               pParentObjectInfo->Specific.Directory.PIOCtlDirectoryCB,
+                               0,
+                               0);
 
         if( !NT_SUCCESS( ntStatus))
         {
@@ -3569,12 +3546,6 @@ AFSOpenIOCtlFcb( IN PIRP Irp,
         bAllocatedCcb = TRUE;
 
         //
-        // Setup the Ccb
-        //
-
-        (*Ccb)->DirectoryCB = pParentObjectInfo->Specific.Directory.PIOCtlDirectoryCB;
-
-        //
         // Set the PIOCtl index
         //
 
@@ -3828,7 +3799,10 @@ AFSOpenSpecialShareFcb( IN PIRP Irp,
         // Initialize the Ccb for the file.
         //
 
-        ntStatus = AFSInitCcb( Ccb);
+        ntStatus = AFSInitCcb( Ccb,
+                               DirectoryCB,
+                               0,
+                               0);
 
         if( !NT_SUCCESS( ntStatus))
         {
@@ -3845,12 +3819,6 @@ AFSOpenSpecialShareFcb( IN PIRP Irp,
         bAllocatedCcb = TRUE;
 
         //
-        // Setup the Ccb
-        //
-
-        (*Ccb)->DirectoryCB = DirectoryCB;
-
-        //
         // Call the service to open the share
         //
 
index 25dc993..0546781 100644 (file)
@@ -1141,11 +1141,15 @@ AFSRemoveFcb( IN AFSFcb **ppFcb)
 }
 
 NTSTATUS
-AFSInitCcb( IN OUT AFSCcb **Ccb)
+AFSInitCcb( IN OUT AFSCcb **Ccb,
+            IN     AFSDirectoryCB *DirectoryCB,
+            IN     ACCESS_MASK     GrantedAccess,
+            IN     ULONG           FileAccess)
 {
 
     NTSTATUS Status = STATUS_SUCCESS;
     AFSCcb *pCcb = NULL;
+    LONG lCount;
 
     __Enter
     {
@@ -1191,6 +1195,22 @@ AFSInitCcb( IN OUT AFSCcb **Ccb)
 
         ExInitializeResourceLite( &pCcb->NPCcb->CcbLock);
 
+        pCcb->DirectoryCB = DirectoryCB;
+
+        lCount = InterlockedIncrement( &pCcb->DirectoryCB->DirOpenReferenceCount);
+
+        AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                      AFS_TRACE_LEVEL_VERBOSE,
+                      "AFSInitCcb Increment count on %wZ DE %p Ccb %p Cnt %d\n",
+                      &pCcb->DirectoryCB->NameInformation.FileName,
+                      pCcb->DirectoryCB,
+                      pCcb,
+                      lCount);
+
+        pCcb->GrantedAccess = GrantedAccess;
+
+        pCcb->FileAccess = FileAccess;
+
         //
         // Return the Ccb
         //
@@ -1238,6 +1258,8 @@ AFSRemoveCcb( IN AFSFcb *Fcb,
               IN AFSCcb *Ccb)
 {
 
+    LONG lCount;
+
     AFSAcquireExcl( &Ccb->NPCcb->CcbLock,
                     TRUE);
 
@@ -1319,6 +1341,22 @@ AFSRemoveCcb( IN AFSFcb *Fcb,
         AFSExFreePoolWithTag( Ccb->NotifyMask.Buffer, AFS_GENERIC_MEMORY_7_TAG);
     }
 
+    if ( Ccb->DirectoryCB != NULL)
+    {
+
+        lCount = InterlockedDecrement( &Ccb->DirectoryCB->DirOpenReferenceCount);
+
+        AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                      AFS_TRACE_LEVEL_VERBOSE,
+                      "AFSRemoveCcb Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
+                      &Ccb->DirectoryCB->NameInformation.FileName,
+                      Ccb->DirectoryCB,
+                      Ccb,
+                      lCount);
+
+        ASSERT( lCount >= 0);
+    }
+
     AFSReleaseResource( &Ccb->NPCcb->CcbLock);
 
     //
index ee25a3c..c44585d 100644 (file)
@@ -540,7 +540,10 @@ void
 AFSRemoveRootFcb( IN AFSFcb *RootFcb);
 
 NTSTATUS
-AFSInitCcb( IN OUT AFSCcb **Ccb);
+AFSInitCcb( IN OUT AFSCcb **Ccb,
+            IN     AFSDirectoryCB *DirectoryCB,
+            IN     ACCESS_MASK     GrantedAccess,
+            IN     ULONG           FileAccess);
 
 void
 AFSRemoveFcb( IN AFSFcb **Fcb);