windows-syncop-20071228
authorJeffrey Altman <jaltman@secure-endpoints.com>
Fri, 28 Dec 2007 15:46:05 +0000 (15:46 +0000)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Fri, 28 Dec 2007 15:46:05 +0000 (15:46 +0000)
LICENSE MIT

avoid a race condition between cm_SyncOpCheckContinue and cm_SyncOpDone
that can leave a request on an scp stuck in the waiting state even though
there are no other requests to wake it up.

src/WINNT/afsd/cm_scache.c
src/WINNT/afsd/cm_scache.h

index 849bb10..36d41a5 100644 (file)
@@ -1276,22 +1276,19 @@ long cm_SyncOp(cm_scache_t *scp, cm_buf_t *bufp, cm_user_t *userp, cm_req_t *req
             scp->waitCount = scp->waitRequests = 1;
         }
 
-        if (bufLocked) 
-            lock_ReleaseMutex(&bufp->mx);
-
         cm_SyncOpAddToWaitQueue(scp, flags, bufp);
         wakeupCycle = 0;
         do {
-            if (wakeupCycle++ != 0)
-                lock_ObtainMutex(&scp->mx);
+            if (bufLocked) 
+                lock_ReleaseMutex(&bufp->mx);
             osi_SleepM((LONG_PTR) &scp->flags, &scp->mx);
+            if (bufLocked) 
+                lock_ObtainMutex(&bufp->mx);
+            lock_ObtainMutex(&scp->mx);
         } while (!cm_SyncOpCheckContinue(scp, flags, bufp));
 
        smb_UpdateServerPriority();
 
-        if (bufLocked) 
-            lock_ObtainMutex(&bufp->mx);
-        lock_ObtainMutex(&scp->mx);
         scp->waitCount--;
         osi_Log3(afsd_logp, "CM SyncOp woke! scp 0x%p; still waiting %d threads of %d requests", 
                  scp, scp->waitCount, scp->waitRequests);
index 1c23479..f353b5d 100644 (file)
@@ -315,18 +315,18 @@ typedef struct cm_scache {
                                    (fidp)->unique))    \
                                        % cm_data.scacheHashTableSize)
 
+#include "cm_conn.h"
+#include "cm_buf.h"
+
 typedef struct cm_scache_waiter {
     osi_queue_t q;
     afs_int32   threadId;
 
     cm_scache_t *scp;
     afs_int32   flags;
-    void        *bufp;
+    cm_buf_t    *bufp;
 } cm_scache_waiter_t;
 
-#include "cm_conn.h"
-#include "cm_buf.h"
-
 extern void cm_InitSCache(int, long);
 
 #ifdef DEBUG_REFCOUNT