Windows: avoid race set/clear ExtentsRequestComplete
authorJeffrey Altman <jaltman@your-file-system.com>
Fri, 19 Oct 2012 12:37:25 +0000 (08:37 -0400)
committerJeffrey Altman <jaltman@your-file-system.com>
Fri, 19 Oct 2012 15:48:56 +0000 (08:48 -0700)
The FCB ExtentsRequestComplete KEVENT setting, clearing
and testing was racy.  Clear the event before issuing the
request to the service and if the request fails, set it in
case two threads issued requests for the same FCB in parallel
and one fails and the other succeeds.

We must ensure that a clear does not mask the event being set
prior to the request thread returning.

Change-Id: I6d496214a2621aeca2b9f6d2f50095ffd19b6c59
Reviewed-on: http://gerrit.openafs.org/8255
Reviewed-by: Rod Widdowson <rdw@steadingsoftware.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
Tested-by: Jeffrey Altman <jaltman@your-file-system.com>

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

index 06bd73c..c8c207b 100644 (file)
@@ -813,6 +813,8 @@ AFSRequestExtentsAsync( IN AFSFcb *Fcb,
                                        request.Length))
         {
 
+            KeClearEvent( &pNPFcb->Specific.File.ExtentsRequestComplete );
+
             AFSDbgLogMsg( AFS_SUBSYSTEM_EXTENT_PROCESSING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSRequestExtentsAsync Request extents for fid %08lX-%08lX-%08lX-%08lX Offset %08lX Len %08lX Thread %08lX\n",
@@ -862,17 +864,14 @@ AFSRequestExtentsAsync( IN AFSFcb *Fcb,
                 }
             }
 
-            if( NT_SUCCESS( ntStatus))
+            if( !NT_SUCCESS( ntStatus))
             {
 
-                KeClearEvent( &pNPFcb->Specific.File.ExtentsRequestComplete );
+                KeSetEvent( &pNPFcb->Specific.File.ExtentsRequestComplete,
+                            0,
+                            FALSE);
             }
         }
-        else
-        {
-
-            KeClearEvent( &pNPFcb->Specific.File.ExtentsRequestComplete );
-        }
 
 try_exit: