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

(cherry picked from commit e8ad124c1622ab8a128b801a662db57ef587af68)

src/WINNT/afsd/cm_vnodeops.c

index c752c1870c404fca1cce1e5fc42cd2af08ba052e..b8ff5cf858f02bc2bc997fc4a05d21ad27b13d75 100644 (file)
@@ -3861,7 +3861,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 */
@@ -3869,13 +3870,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);
 
     /*
@@ -3884,6 +3878,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);
@@ -4065,6 +4067,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;
         }
     }
@@ -4351,7 +4358,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 && 
@@ -4368,8 +4384,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,