Windows: Flush data and then drop locks
authorJeffrey Altman <jaltman@your-file-system.com>
Sat, 14 Apr 2012 00:17:48 +0000 (20:17 -0400)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Sun, 15 Apr 2012 00:58:01 +0000 (17:58 -0700)
The redirector must flush the data to the file server
and then drop the file locks.  Doing it the other way
creates races.

Change-Id: Ic3a48546ee9e0066df9d228fc4e57f52b43587c2
Reviewed-on: http://gerrit.openafs.org/7207
Reviewed-by: Derrick Brashear <shadow@dementix.org>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@secure-endpoints.com>
Tested-by: Jeffrey Altman <jaltman@secure-endpoints.com>

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

index 0d14d81..e54cb00 100644 (file)
@@ -162,6 +162,30 @@ AFSLockControl( IN PDEVICE_OBJECT LibDeviceObject,
             case IRP_MN_UNLOCK_ALL:
             case IRP_MN_UNLOCK_ALL_BY_KEY:
             {
+                //
+                // Flush data and then release the locks on the file server
+                //
+
+                CcFlushCache( &pFcb->NPFcb->SectionObjectPointers,
+                              NULL,
+                              0,
+                              &stIoStatus);
+
+                if( !NT_SUCCESS( stIoStatus.Status))
+                {
+
+                    AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
+                                  AFS_TRACE_LEVEL_ERROR,
+                                  "AFSLockControl CcFlushCache [1] failure FID %08lX-%08lX-%08lX-%08lX Status 0x%08lX Bytes 0x%08lX\n",
+                                  pFcb->ObjectInformation->FileId.Cell,
+                                  pFcb->ObjectInformation->FileId.Volume,
+                                  pFcb->ObjectInformation->FileId.Vnode,
+                                  pFcb->ObjectInformation->FileId.Unique,
+                                  stIoStatus.Status,
+                                  stIoStatus.Information);
+
+                    ntStatus = stIoStatus.Status;
+                }
 
                 RtlZeroMemory( &stUnlockRequestCB,
                                sizeof( AFSByteRangeUnlockRequestCB));
@@ -178,30 +202,6 @@ AFSLockControl( IN PDEVICE_OBJECT LibDeviceObject,
                                               NULL,
                                               NULL);
 
-                if( NT_SUCCESS( ntStatus))
-                {
-                    CcFlushCache( &pFcb->NPFcb->SectionObjectPointers,
-                                  NULL,
-                                  0,
-                                  &stIoStatus);
-
-                    if( !NT_SUCCESS( stIoStatus.Status))
-                    {
-
-                        AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
-                                      AFS_TRACE_LEVEL_ERROR,
-                                      "AFSLockControl CcFlushCache [1] failure FID %08lX-%08lX-%08lX-%08lX Status 0x%08lX Bytes 0x%08lX\n",
-                                      pFcb->ObjectInformation->FileId.Cell,
-                                      pFcb->ObjectInformation->FileId.Volume,
-                                      pFcb->ObjectInformation->FileId.Vnode,
-                                      pFcb->ObjectInformation->FileId.Unique,
-                                      stIoStatus.Status,
-                                      stIoStatus.Information);
-
-                        ntStatus = stIoStatus.Status;
-                    }
-                }
-
                 //
                 // Even on a failure we need to notify the rtl package of the unlock
                 //
@@ -211,6 +211,30 @@ AFSLockControl( IN PDEVICE_OBJECT LibDeviceObject,
 
             case IRP_MN_UNLOCK_SINGLE:
             {
+                //
+                // Flush the data and then release the file server locks
+                //
+
+                CcFlushCache( &pFcb->NPFcb->SectionObjectPointers,
+                              &pIrpSp->Parameters.LockControl.ByteOffset,
+                              pIrpSp->Parameters.LockControl.Length->LowPart,
+                              &stIoStatus);
+
+                if( !NT_SUCCESS( stIoStatus.Status))
+                {
+
+                    AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
+                                  AFS_TRACE_LEVEL_ERROR,
+                                  "AFSLockControl CcFlushCache [2] failure FID %08lX-%08lX-%08lX-%08lX Status 0x%08lX Bytes 0x%08lX\n",
+                                  pFcb->ObjectInformation->FileId.Cell,
+                                  pFcb->ObjectInformation->FileId.Volume,
+                                  pFcb->ObjectInformation->FileId.Vnode,
+                                  pFcb->ObjectInformation->FileId.Unique,
+                                  stIoStatus.Status,
+                                  stIoStatus.Information);
+
+                    ntStatus = stIoStatus.Status;
+                }
 
                 stUnlockRequestCB.Count = 1;
 
@@ -234,30 +258,6 @@ AFSLockControl( IN PDEVICE_OBJECT LibDeviceObject,
                                               (void *)&stUnlockResultCB,
                                               &ulResultLen);
 
-                if( NT_SUCCESS( ntStatus))
-                {
-                    CcFlushCache( &pFcb->NPFcb->SectionObjectPointers,
-                                  &pIrpSp->Parameters.LockControl.ByteOffset,
-                                  pIrpSp->Parameters.LockControl.Length->LowPart,
-                                  &stIoStatus);
-
-                    if( !NT_SUCCESS( stIoStatus.Status))
-                    {
-
-                        AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
-                                      AFS_TRACE_LEVEL_ERROR,
-                                      "AFSLockControl CcFlushCache [2] failure FID %08lX-%08lX-%08lX-%08lX Status 0x%08lX Bytes 0x%08lX\n",
-                                      pFcb->ObjectInformation->FileId.Cell,
-                                      pFcb->ObjectInformation->FileId.Volume,
-                                      pFcb->ObjectInformation->FileId.Vnode,
-                                      pFcb->ObjectInformation->FileId.Unique,
-                                      stIoStatus.Status,
-                                      stIoStatus.Information);
-
-                        ntStatus = stIoStatus.Status;
-                    }
-                }
-
                 break;
             }