Windows: Refactor AFSVerifyEntry AFSValidateEntry
authorJeffrey Altman <jaltman@your-file-system.com>
Thu, 22 Aug 2013 21:50:39 +0000 (17:50 -0400)
committerJeffrey Altman <jaltman@your-file-system.com>
Fri, 30 Aug 2013 19:10:15 +0000 (12:10 -0700)
Inside a big switch statement it is hard to follow when there
are multiple 'break' exits within a 'case'.   Reorganize the code
so that there is only a single exit for the FILE type.  Unnecessary
blocks are removed as well.

Change-Id: I7ae0ae4592a15a23e8526f18a96a9ded9a1d135c
Reviewed-on: http://gerrit.openafs.org/10183
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>

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

index 8ae2def..699e835 100644 (file)
@@ -3192,61 +3192,68 @@ AFSVerifyEntry( IN GUID *AuthGroup,
                                       pObjectInfo->FileId.Vnode,
                                       pObjectInfo->FileId.Unique,
                                       ntStatus));
-
-                        break;
                     }
+                   else
+                   {
 
-                    //
-                    // Update file sizes
-                    //
+                       //
+                       // Update file sizes
+                       //
 
-                    pObjectInfo->Fcb->Header.AllocationSize.QuadPart  = pObjectInfo->AllocationSize.QuadPart;
-                    pObjectInfo->Fcb->Header.FileSize.QuadPart        = pObjectInfo->EndOfFile.QuadPart;
-                    pObjectInfo->Fcb->Header.ValidDataLength.QuadPart = pObjectInfo->EndOfFile.QuadPart;
+                       pObjectInfo->Fcb->Header.AllocationSize.QuadPart  = pObjectInfo->AllocationSize.QuadPart;
+                       pObjectInfo->Fcb->Header.FileSize.QuadPart        = pObjectInfo->EndOfFile.QuadPart;
+                       pObjectInfo->Fcb->Header.ValidDataLength.QuadPart = pObjectInfo->EndOfFile.QuadPart;
 
-                    AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
-                                  AFS_TRACE_LEVEL_VERBOSE,
-                                  "AFSVerifyEntry Acquiring Fcb SectionObject lock %p EXCL %08lX\n",
-                                  &pObjectInfo->Fcb->NPFcb->SectionObjectResource,
-                                  PsGetCurrentThread()));
+                       AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING|AFS_SUBSYSTEM_SECTION_OBJECT,
+                                     AFS_TRACE_LEVEL_VERBOSE,
+                                     "AFSVerifyEntry Acquiring Fcb SectionObject lock %p EXCL %08lX\n",
+                                     &pObjectInfo->Fcb->NPFcb->SectionObjectResource,
+                                     PsGetCurrentThread()));
 
-                    AFSAcquireExcl( &pObjectInfo->Fcb->NPFcb->SectionObjectResource,
-                                    TRUE);
+                       AFSAcquireExcl( &pObjectInfo->Fcb->NPFcb->SectionObjectResource,
+                                       TRUE);
 
-                   __try
-                   {
+                       __try
+                       {
 
-                       pCCFileObject = CcGetFileObjectFromSectionPtrs( &pObjectInfo->Fcb->NPFcb->SectionObjectPointers);
+                           pCCFileObject = CcGetFileObjectFromSectionPtrs( &pObjectInfo->Fcb->NPFcb->SectionObjectPointers);
 
-                       if ( pCCFileObject != NULL)
+                           if ( pCCFileObject != NULL)
+                           {
+                               CcSetFileSizes( pCCFileObject,
+                                               (PCC_FILE_SIZES)&pObjectInfo->Fcb->Header.AllocationSize);
+                           }
+                       }
+                       __except( AFSExceptionFilter( __FUNCTION__, GetExceptionCode(), GetExceptionInformation()))
                        {
-                           CcSetFileSizes( pCCFileObject,
-                                           (PCC_FILE_SIZES)&pObjectInfo->Fcb->Header.AllocationSize);
+
+                           ntStatus = GetExceptionCode();
+
+                           AFSDbgTrace(( 0,
+                                         0,
+                                         "EXCEPTION - AFSVerifyEntry CcSetFileSized failed FID %08lX-%08lX-%08lX-%08lX Status 0x%08lX\n",
+                                         pObjectInfo->FileId.Cell,
+                                         pObjectInfo->FileId.Volume,
+                                         pObjectInfo->FileId.Vnode,
+                                         pObjectInfo->FileId.Unique,
+                                         ntStatus));
                        }
-                   }
-                   __except( AFSExceptionFilter( __FUNCTION__, GetExceptionCode(), GetExceptionInformation()))
-                    {
 
-                       ntStatus = GetExceptionCode();
+                       AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING|AFS_SUBSYSTEM_SECTION_OBJECT,
+                                     AFS_TRACE_LEVEL_VERBOSE,
+                                     "AFSVerifyEntry Releasing Fcb SectionObject lock %p EXCL %08lX\n",
+                                     &pObjectInfo->Fcb->NPFcb->SectionObjectResource,
+                                     PsGetCurrentThread()));
 
-                       AFSDbgTrace(( 0,
-                                     0,
-                                     "EXCEPTION - AFSVerifyEntry CcSetFileSized failed FID %08lX-%08lX-%08lX-%08lX Status 0x%08lX\n",
-                                     pObjectInfo->FileId.Cell,
-                                     pObjectInfo->FileId.Volume,
-                                     pObjectInfo->FileId.Vnode,
-                                     pObjectInfo->FileId.Unique,
-                                     ntStatus));
+                       AFSReleaseResource( &pObjectInfo->Fcb->NPFcb->SectionObjectResource);
                     }
 
                     AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
                                   AFS_TRACE_LEVEL_VERBOSE,
-                                  "AFSVerifyEntry Releasing Fcb SectionObject lock %p EXCL %08lX\n",
-                                  &pObjectInfo->Fcb->NPFcb->SectionObjectResource,
+                                 "AFSVerifyEntry Releasing Fcb lock %p EXCL %08lX\n",
+                                 &pObjectInfo->Fcb->NPFcb->Resource,
                                   PsGetCurrentThread()));
 
-                    AFSReleaseResource( &pObjectInfo->Fcb->NPFcb->SectionObjectResource);
-
                     AFSReleaseResource( &pObjectInfo->Fcb->NPFcb->Resource);
                 }
                 else
@@ -3271,22 +3278,26 @@ AFSVerifyEntry( IN GUID *AuthGroup,
                                       pObjectInfo->FileId.Vnode,
                                       pObjectInfo->FileId.Unique,
                                       ntStatus));
-
-                        break;
                     }
+                   else
+                   {
 
-                    AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
-                                  AFS_TRACE_LEVEL_WARNING,
-                                  "AFSVerifyEntry Fcb NULL %wZ FID %08lX-%08lX-%08lX-%08lX\n",
-                                  &DirEntry->NameInformation.FileName,
-                                  pObjectInfo->FileId.Cell,
-                                  pObjectInfo->FileId.Volume,
-                                  pObjectInfo->FileId.Vnode,
-                                  pObjectInfo->FileId.Unique));
+                       AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
+                                     AFS_TRACE_LEVEL_WARNING,
+                                     "AFSVerifyEntry Fcb NULL %wZ FID %08lX-%08lX-%08lX-%08lX\n",
+                                     &DirEntry->NameInformation.FileName,
+                                     pObjectInfo->FileId.Cell,
+                                     pObjectInfo->FileId.Volume,
+                                     pObjectInfo->FileId.Vnode,
+                                     pObjectInfo->FileId.Unique));
+                   }
                 }
 
-                ClearFlag( pObjectInfo->Flags, AFS_OBJECT_FLAGS_VERIFY);
+               if ( NT_SUCCESS( ntStatus))
+               {
 
+                   ClearFlag( pObjectInfo->Flags, AFS_OBJECT_FLAGS_VERIFY);
+               }
                 break;
             }
 
@@ -4172,173 +4183,167 @@ AFSValidateEntry( IN AFSDirectoryCB *DirEntry,
                         AFSAcquireExcl( &pCurrentFcb->NPFcb->Resource,
                                         TRUE);
 
-                        bReleaseFcb = TRUE;
-                    }
-
-                    if( pCurrentFcb != NULL)
-                    {
-
-                        IO_STATUS_BLOCK stIoStatus;
-
-                        AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
-                                      AFS_TRACE_LEVEL_VERBOSE_2,
-                                      "AFSValidateEntry Flush/purge entry %wZ FID %08lX-%08lX-%08lX-%08lX\n",
-                                      &DirEntry->NameInformation.FileName,
-                                      pObjectInfo->FileId.Cell,
-                                      pObjectInfo->FileId.Volume,
-                                      pObjectInfo->FileId.Vnode,
-                                      pObjectInfo->FileId.Unique));
-
-                        if ( pObjectInfo->DataVersion.QuadPart != pDirEnumEntry->DataVersion.QuadPart)
-                        {
+                       bReleaseFcb = TRUE;
+                   }
 
-                            AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
-                                          AFS_TRACE_LEVEL_VERBOSE,
-                                          "AFSValidateEntry DV Change %wZ FID %08lX-%08lX-%08lX-%08lX (%08lX != %08lX)\n",
-                                          &DirEntry->NameInformation.FileName,
-                                          pObjectInfo->FileId.Cell,
-                                          pObjectInfo->FileId.Volume,
-                                          pObjectInfo->FileId.Vnode,
-                                          pObjectInfo->FileId.Unique,
-                                          pObjectInfo->DataVersion.LowPart,
-                                          pDirEnumEntry->DataVersion.LowPart));
+                   AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
+                                 AFS_TRACE_LEVEL_VERBOSE_2,
+                                 "AFSValidateEntry Flush/purge entry %wZ FID %08lX-%08lX-%08lX-%08lX\n",
+                                 &DirEntry->NameInformation.FileName,
+                                 pObjectInfo->FileId.Cell,
+                                 pObjectInfo->FileId.Volume,
+                                 pObjectInfo->FileId.Vnode,
+                                 pObjectInfo->FileId.Unique));
 
-                            bPurgeExtents = TRUE;
-                        }
+                   if ( pObjectInfo->DataVersion.QuadPart != pDirEnumEntry->DataVersion.QuadPart)
+                   {
 
-                        if ( bSafeToPurge)
-                        {
+                       AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
+                                     AFS_TRACE_LEVEL_VERBOSE,
+                                     "AFSValidateEntry DV Change %wZ FID %08lX-%08lX-%08lX-%08lX (%08lX != %08lX)\n",
+                                     &DirEntry->NameInformation.FileName,
+                                     pObjectInfo->FileId.Cell,
+                                     pObjectInfo->FileId.Volume,
+                                     pObjectInfo->FileId.Vnode,
+                                     pObjectInfo->FileId.Unique,
+                                     pObjectInfo->DataVersion.LowPart,
+                                     pDirEnumEntry->DataVersion.LowPart));
 
-                            if ( BooleanFlagOn( pObjectInfo->Flags, AFS_OBJECT_FLAGS_VERIFY_DATA))
-                            {
-                                bPurgeExtents = TRUE;
+                       bPurgeExtents = TRUE;
+                   }
 
-                                AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
-                                              AFS_TRACE_LEVEL_VERBOSE,
-                                              "AFSVerifyEntry Clearing VERIFY_DATA flag %wZ FID %08lX-%08lX-%08lX-%08lX\n",
-                                              &DirEntry->NameInformation.FileName,
-                                              pObjectInfo->FileId.Cell,
-                                              pObjectInfo->FileId.Volume,
-                                              pObjectInfo->FileId.Vnode,
-                                              pObjectInfo->FileId.Unique));
+                   if ( bSafeToPurge)
+                   {
 
-                                ClearFlag( pObjectInfo->Flags, AFS_OBJECT_FLAGS_VERIFY_DATA);
-                            }
+                       if ( BooleanFlagOn( pObjectInfo->Flags, AFS_OBJECT_FLAGS_VERIFY_DATA))
+                       {
+                           bPurgeExtents = TRUE;
 
-                            AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
-                                          AFS_TRACE_LEVEL_VERBOSE,
-                                          "AFSValidateEntry Acquiring Fcb SectionObject lock %p EXCL %08lX\n",
-                                          &pObjectInfo->Fcb->NPFcb->SectionObjectResource,
-                                          PsGetCurrentThread()));
+                           AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
+                                         AFS_TRACE_LEVEL_VERBOSE,
+                                         "AFSVerifyEntry Clearing VERIFY_DATA flag %wZ FID %08lX-%08lX-%08lX-%08lX\n",
+                                         &DirEntry->NameInformation.FileName,
+                                         pObjectInfo->FileId.Cell,
+                                         pObjectInfo->FileId.Volume,
+                                         pObjectInfo->FileId.Vnode,
+                                         pObjectInfo->FileId.Unique));
 
-                            AFSAcquireExcl( &pObjectInfo->Fcb->NPFcb->SectionObjectResource,
-                                            TRUE);
+                           ClearFlag( pObjectInfo->Flags, AFS_OBJECT_FLAGS_VERIFY_DATA);
+                       }
 
-                            //
-                            // Release Fcb->Resource to avoid Trend Micro deadlock
-                            //
+                       AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING|AFS_SUBSYSTEM_SECTION_OBJECT,
+                                     AFS_TRACE_LEVEL_VERBOSE,
+                                     "AFSValidateEntry Acquiring Fcb SectionObject lock %p EXCL %08lX\n",
+                                     &pCurrentFcb->NPFcb->SectionObjectResource,
+                                     PsGetCurrentThread()));
 
-                            AFSReleaseResource( &pObjectInfo->Fcb->NPFcb->Resource);
+                       AFSAcquireExcl( &pCurrentFcb->NPFcb->SectionObjectResource,
+                                       TRUE);
 
-                            __try
-                            {
+                       //
+                       // Release Fcb->Resource to avoid Trend Micro deadlock
+                       //
 
-                                CcFlushCache( &pCurrentFcb->NPFcb->SectionObjectPointers,
-                                              NULL,
-                                              0,
-                                              &stIoStatus);
+                       AFSReleaseResource( &pCurrentFcb->NPFcb->Resource);
 
-                                if( !NT_SUCCESS( stIoStatus.Status))
-                                {
+                       bReleaseFcb = FALSE;
 
-                                    AFSDbgTrace(( AFS_SUBSYSTEM_IO_PROCESSING,
-                                                  AFS_TRACE_LEVEL_ERROR,
-                                                  "AFSValidateEntry CcFlushCache failure %wZ FID %08lX-%08lX-%08lX-%08lX Status 0x%08lX Bytes 0x%08lX\n",
-                                                  &DirEntry->NameInformation.FileName,
-                                                  pObjectInfo->FileId.Cell,
-                                                  pObjectInfo->FileId.Volume,
-                                                  pObjectInfo->FileId.Vnode,
-                                                  pObjectInfo->FileId.Unique,
-                                                  stIoStatus.Status,
-                                                  stIoStatus.Information));
-
-                                    ntStatus = stIoStatus.Status;
-                                }
+                       __try
+                       {
 
-                                if ( bPurgeExtents &&
-                                     pObjectInfo->Fcb->NPFcb->SectionObjectPointers.DataSectionObject != NULL)
-                                {
+                           IO_STATUS_BLOCK stIoStatus;
 
-                                    if ( !CcPurgeCacheSection( &pObjectInfo->Fcb->NPFcb->SectionObjectPointers,
-                                                               NULL,
-                                                               0,
-                                                               FALSE))
-                                    {
+                           CcFlushCache( &pCurrentFcb->NPFcb->SectionObjectPointers,
+                                         NULL,
+                                         0,
+                                         &stIoStatus);
 
-                                        AFSDbgTrace(( AFS_SUBSYSTEM_IO_PROCESSING,
-                                                      AFS_TRACE_LEVEL_WARNING,
-                                                      "AFSValidateEntry CcPurgeCacheSection failure %wZ FID %08lX-%08lX-%08lX-%08lX\n",
-                                                      &DirEntry->NameInformation.FileName,
-                                                      pObjectInfo->FileId.Cell,
-                                                      pObjectInfo->FileId.Volume,
-                                                      pObjectInfo->FileId.Vnode,
-                                                      pObjectInfo->FileId.Unique));
+                           if( !NT_SUCCESS( stIoStatus.Status))
+                           {
 
-                                        SetFlag( pObjectInfo->Fcb->Flags, AFS_FCB_FLAG_PURGE_ON_CLOSE);
-                                    }
-                                }
-                            }
-                           __except( AFSExceptionFilter( __FUNCTION__, GetExceptionCode(), GetExceptionInformation()))
-                            {
-                                ntStatus = GetExceptionCode();
+                               AFSDbgTrace(( AFS_SUBSYSTEM_IO_PROCESSING,
+                                             AFS_TRACE_LEVEL_ERROR,
+                                             "AFSValidateEntry CcFlushCache failure %wZ FID %08lX-%08lX-%08lX-%08lX Status 0x%08lX Bytes 0x%08lX\n",
+                                             &DirEntry->NameInformation.FileName,
+                                             pObjectInfo->FileId.Cell,
+                                             pObjectInfo->FileId.Volume,
+                                             pObjectInfo->FileId.Vnode,
+                                             pObjectInfo->FileId.Unique,
+                                             stIoStatus.Status,
+                                             stIoStatus.Information));
+
+                               ntStatus = stIoStatus.Status;
+                           }
 
-                                AFSDbgTrace(( 0,
-                                              0,
-                                              "EXCEPTION - AFSValidateEntry CcFlushCache or CcPurgeCacheSection %wZ FID %08lX-%08lX-%08lX-%08lX Status 0x%08lX\n",
-                                              &DirEntry->NameInformation.FileName,
-                                              pObjectInfo->FileId.Cell,
-                                              pObjectInfo->FileId.Volume,
-                                              pObjectInfo->FileId.Vnode,
-                                              pObjectInfo->FileId.Unique,
-                                              ntStatus));
+                           if ( bPurgeExtents &&
+                                pCurrentFcb->NPFcb->SectionObjectPointers.DataSectionObject != NULL)
+                           {
 
-                                SetFlag( pObjectInfo->Fcb->Flags, AFS_FCB_FLAG_PURGE_ON_CLOSE);
-                            }
+                               if ( !CcPurgeCacheSection( &pCurrentFcb->NPFcb->SectionObjectPointers,
+                                                          NULL,
+                                                          0,
+                                                          FALSE))
+                               {
+
+                                   AFSDbgTrace(( AFS_SUBSYSTEM_IO_PROCESSING,
+                                                 AFS_TRACE_LEVEL_WARNING,
+                                                 "AFSValidateEntry CcPurgeCacheSection failure %wZ FID %08lX-%08lX-%08lX-%08lX\n",
+                                                 &DirEntry->NameInformation.FileName,
+                                                 pObjectInfo->FileId.Cell,
+                                                 pObjectInfo->FileId.Volume,
+                                                 pObjectInfo->FileId.Vnode,
+                                                 pObjectInfo->FileId.Unique));
+
+                                   SetFlag( pObjectInfo->Fcb->Flags, AFS_FCB_FLAG_PURGE_ON_CLOSE);
+                               }
+                           }
+                       }
+                       __except( AFSExceptionFilter( __FUNCTION__, GetExceptionCode(), GetExceptionInformation()))
+                       {
+                           ntStatus = GetExceptionCode();
 
-                            AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
-                                          AFS_TRACE_LEVEL_VERBOSE,
-                                          "AFSValidateEntry Acquiring Fcb SectionObject lock %p EXCL %08lX\n",
-                                          &pObjectInfo->Fcb->NPFcb->SectionObjectResource,
-                                          PsGetCurrentThread()));
+                           AFSDbgTrace(( 0,
+                                         0,
+                                         "EXCEPTION - AFSValidateEntry CcFlushCache or CcPurgeCacheSection %wZ FID %08lX-%08lX-%08lX-%08lX Status 0x%08lX\n",
+                                         &DirEntry->NameInformation.FileName,
+                                         pObjectInfo->FileId.Cell,
+                                         pObjectInfo->FileId.Volume,
+                                         pObjectInfo->FileId.Vnode,
+                                         pObjectInfo->FileId.Unique,
+                                         ntStatus));
 
-                            AFSReleaseResource( &pObjectInfo->Fcb->NPFcb->SectionObjectResource);
+                           SetFlag( pCurrentFcb->Flags, AFS_FCB_FLAG_PURGE_ON_CLOSE);
+                       }
 
-                            AFSAcquireExcl( &pObjectInfo->Fcb->NPFcb->Resource,
-                                            TRUE);
-                        }
-                        else
-                        {
+                       AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING|AFS_SUBSYSTEM_SECTION_OBJECT,
+                                     AFS_TRACE_LEVEL_VERBOSE,
+                                     "AFSValidateEntry Releasing Fcb SectionObject lock %p EXCL %08lX\n",
+                                     &pCurrentFcb->NPFcb->SectionObjectResource,
+                                     PsGetCurrentThread()));
 
-                            if ( bPurgeExtents)
-                            {
+                       AFSReleaseResource( &pCurrentFcb->NPFcb->SectionObjectResource);
+                   }
+                   else
+                   {
 
-                                SetFlag( pObjectInfo->Flags, AFS_OBJECT_FLAGS_VERIFY_DATA);
-                            }
-                        }
+                       if ( bPurgeExtents)
+                       {
 
+                           SetFlag( pObjectInfo->Flags, AFS_OBJECT_FLAGS_VERIFY_DATA);
+                       }
 
-                        AFSReleaseResource( &pCurrentFcb->NPFcb->Resource);
+                       AFSReleaseResource( &pCurrentFcb->NPFcb->Resource);
 
-                        bReleaseFcb = FALSE;
+                       bReleaseFcb = FALSE;
+                   }
 
-                        if ( bPurgeExtents &&
-                             bSafeToPurge)
-                        {
-                            AFSFlushExtents( pCurrentFcb,
-                                             AuthGroup);
-                        }
-                    }
-                }
+                   if ( bPurgeExtents &&
+                        bSafeToPurge)
+                   {
+                       AFSFlushExtents( pCurrentFcb,
+                                        AuthGroup);
+                   }
+               }
 
                 //
                 // Update the metadata for the entry but only if it is safe to do so.