]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
windows-lock-count-fix-20051006
authorAsanka Herath <asanka@secure-endpoints.com>
Thu, 6 Oct 2005 18:29:44 +0000 (18:29 +0000)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Thu, 6 Oct 2005 18:29:44 +0000 (18:29 +0000)
lock counts were not being reduced on file close when the lock was lost.

src/WINNT/afsd/cm_vnodeops.c

index 9cd5ec27e6888165b07e71445394c9eee6d4aa6d..11336d24912f187bf7654f36d24e072ded092360 100644 (file)
@@ -3878,7 +3878,8 @@ long cm_Unlock(cm_scache_t *scp,
         
         lock_ReleaseRead(&cm_scacheLock);
 
-        return CM_ERROR_WOULDBLOCK; /* how is this an appropriate error code? */
+        /* The lock didn't exist anyway. *shrug* */
+        return 0;
     }
 
     /* discard lock record */
@@ -3886,13 +3887,6 @@ long cm_Unlock(cm_scache_t *scp,
         scp->fileLocksT = osi_QPrev(q);
     osi_QRemove(&scp->fileLocksH, q);
 
-    if(IS_LOCK_ACCEPTED(fileLock)) {
-        if(fileLock->lockType == LockRead)
-            scp->sharedLocks--;
-        else
-            scp->exclusiveLocks--;
-    }
-
     lock_ReleaseRead(&cm_scacheLock);
 
     /*
@@ -3901,6 +3895,14 @@ long cm_Unlock(cm_scache_t *scp,
      */
 
     lock_ObtainWrite(&cm_scacheLock);
+
+    if(IS_LOCK_ACCEPTED(fileLock)) {
+        if(fileLock->lockType == LockRead)
+            scp->sharedLocks--;
+        else
+            scp->exclusiveLocks--;
+    }
+
     fileLock->flags |= CM_FILELOCK_FLAG_DELETED;
     if (userp != NULL) {
         cm_ReleaseUser(fileLock->userp);
@@ -4082,6 +4084,11 @@ static void cm_LockMarkSCacheLost(cm_scache_t * scp)
             (cm_file_lock_t *)((char *) q - offsetof(cm_file_lock_t, fileq));
 
         if(IS_LOCK_ACTIVE(fileLock)) {
+            if (fileLock->lockType == LockRead)
+                scp->sharedLocks--;
+            else
+                scp->exclusiveLocks--;
+
             fileLock->flags |= CM_FILELOCK_FLAG_LOST;
         }
     }
@@ -4368,7 +4375,16 @@ long cm_RetryLock(cm_file_lock_t *oldFileLock, int client_is_dead)
        the lock as either ACTIVE or WAITLOCK depending on the
        serverLock. */
 
-    oldFileLock->flags &= ~CM_FILELOCK_FLAG_WAITUNLOCK;
+    /* First, promote the WAITUNLOCK to a WAITLOCK */
+    if (IS_LOCK_WAITUNLOCK(oldFileLock)) {
+        if (oldFileLock->lockType == LockRead)
+            scp->sharedLocks++;
+        else
+            scp->exclusiveLocks++;
+
+        oldFileLock->flags &= ~CM_FILELOCK_FLAG_WAITUNLOCK;
+        oldFileLock->flags |= CM_FILELOCK_FLAG_WAITLOCK;
+    }
 
     if (scp->serverLock == oldFileLock->lockType ||
         (oldFileLock->lockType == LockRead && 
@@ -4385,8 +4401,6 @@ long cm_RetryLock(cm_file_lock_t *oldFileLock, int client_is_dead)
         cm_fid_t cfid;
         cm_user_t * userp;
 
-        oldFileLock->flags |= CM_FILELOCK_FLAG_WAITLOCK;
-
         cm_InitReq(&req);
 
         code = cm_SyncOp(scp, NULL, oldFileLock->userp, &req, 0,