From 9ef646f585ab4861c3702fa4c549d4e7ab98c596 Mon Sep 17 00:00:00 2001 From: Asanka Herath Date: Thu, 6 Oct 2005 18:30:46 +0000 Subject: [PATCH] STABLE14-windows-lock-count-fix-20051006 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 | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/WINNT/afsd/cm_vnodeops.c b/src/WINNT/afsd/cm_vnodeops.c index c752c1870..b8ff5cf85 100644 --- a/src/WINNT/afsd/cm_vnodeops.c +++ b/src/WINNT/afsd/cm_vnodeops.c @@ -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, -- 2.39.5