Windows: remove dead code from cm_scache.c
[openafs.git] / src / WINNT / afsd / cm_scache.c
index 42cd5c7..db24b4f 100644 (file)
@@ -139,6 +139,9 @@ void cm_ResetSCacheDirectory(cm_scache_t *scp, afs_int32 dirlock)
 /* called with cm_scacheLock and scp write-locked; recycles an existing scp. */
 long cm_RecycleSCache(cm_scache_t *scp, afs_int32 flags)
 {
+    lock_AssertWrite(&cm_scacheLock);
+    lock_AssertWrite(&scp->rw);
+
     if (scp->refCount != 0) {
        return -1;
     }
@@ -151,64 +154,6 @@ long cm_RecycleSCache(cm_scache_t *scp, afs_int32 flags)
        return -1;
     }
 
-    cm_RemoveSCacheFromHashTable(scp);
-
-#if 0
-    if (flags & CM_SCACHE_RECYCLEFLAG_DESTROY_BUFFERS) {
-       osi_queueData_t *qdp;
-       cm_buf_t *bufp;
-
-       while(qdp = scp->bufWritesp) {
-            bufp = osi_GetQData(qdp);
-           osi_QRemove((osi_queue_t **) &scp->bufWritesp, &qdp->q);
-           osi_QDFree(qdp);
-           if (bufp) {
-               lock_ObtainMutex(&bufp->mx);
-               _InterlockedAnd(&bufp->cmFlags, ~CM_BUF_CMSTORING);
-               _InterlockedAnd(&bufp->flags, ~CM_BUF_DIRTY);
-                bufp->dirty_offset = 0;
-                bufp->dirty_length = 0;
-               _InterlockedOr(&bufp->flags, CM_BUF_ERROR);
-               bufp->error = VNOVNODE;
-               bufp->dataVersion = CM_BUF_VERSION_BAD; /* bad */
-               bufp->dirtyCounter++;
-               if (bufp->flags & CM_BUF_WAITING) {
-                   osi_Log2(afsd_logp, "CM RecycleSCache Waking [scp 0x%p] bufp 0x%x", scp, bufp);
-                   osi_Wakeup((long) &bufp);
-               }
-               lock_ReleaseMutex(&bufp->mx);
-               buf_Release(bufp);
-           }
-        }
-       while(qdp = scp->bufReadsp) {
-            bufp = osi_GetQData(qdp);
-           osi_QRemove((osi_queue_t **) &scp->bufReadsp, &qdp->q);
-           osi_QDFree(qdp);
-           if (bufp) {
-               lock_ObtainMutex(&bufp->mx);
-               _InterlockedAnd(&bufp->cmFlags, ~CM_BUF_CMFETCHING);
-               _InterlockedAnd(&bufp->flags, ~CM_BUF_DIRTY);
-                bufp->dirty_offset = 0;
-                bufp->dirty_length = 0;
-               _InterlockedOr(&bufp->flags, CM_BUF_ERROR);
-               bufp->error = VNOVNODE;
-               bufp->dataVersion = CM_BUF_VERSION_BAD; /* bad */
-               bufp->dirtyCounter++;
-               if (bufp->flags & CM_BUF_WAITING) {
-                   osi_Log2(afsd_logp, "CM RecycleSCache Waking [scp 0x%p] bufp 0x%x", scp, bufp);
-                   osi_Wakeup((long) &bufp);
-               }
-               lock_ReleaseMutex(&bufp->mx);
-               buf_Release(bufp);
-           }
-        }
-       buf_CleanDirtyBuffers(scp);
-    } else {
-       /* look for things that shouldn't still be set */
-       osi_assertx(scp->bufWritesp == NULL, "non-null cm_scache_t bufWritesp");
-       osi_assertx(scp->bufReadsp == NULL, "non-null cm_scache_t bufReadsp");
-    }
-#endif
 
     /* invalidate so next merge works fine;
      * also initialize some flags */
@@ -276,7 +221,7 @@ long cm_RecycleSCache(cm_scache_t *scp, afs_int32 flags)
 /*
  * called with cm_scacheLock write-locked; find a vnode to recycle.
  * Can allocate a new one if desperate, or if below quota (cm_data.maxSCaches).
- * returns scp->mx held.
+ * returns scp->rw write-locked.
  */
 cm_scache_t *cm_GetNewSCache(void)
 {
@@ -284,52 +229,6 @@ cm_scache_t *cm_GetNewSCache(void)
     int retry = 0;
 
     lock_AssertWrite(&cm_scacheLock);
-#if 0
-    /* first pass - look for deleted objects */
-    for ( scp = cm_data.scacheLRULastp;
-         scp;
-         scp = (cm_scache_t *) osi_QPrev(&scp->q))
-    {
-       osi_assertx(scp >= cm_data.scacheBaseAddress && scp < (cm_scache_t *)cm_data.scacheHashTablep,
-                    "invalid cm_scache_t address");
-
-       if (scp->refCount == 0) {
-           if (scp->flags & CM_SCACHEFLAG_DELETED) {
-                if (!lock_TryWrite(&scp->rw))
-                    continue;
-
-               osi_Log1(afsd_logp, "GetNewSCache attempting to recycle deleted scp 0x%p", scp);
-               if (!cm_RecycleSCache(scp, CM_SCACHE_RECYCLEFLAG_DESTROY_BUFFERS)) {
-
-                   /* we found an entry, so return it */
-                   /* now remove from the LRU queue and put it back at the
-                    * head of the LRU queue.
-                    */
-                   cm_AdjustScacheLRU(scp);
-
-                   /* and we're done */
-                   return scp;
-               }
-                lock_ReleaseWrite(&scp->rw);
-               osi_Log1(afsd_logp, "GetNewSCache recycled failed scp 0x%p", scp);
-           } else if (!(scp->flags & CM_SCACHEFLAG_INHASH)) {
-                if (!lock_TryWrite(&scp->rw))
-                    continue;
-
-               /* we found an entry, so return it */
-               /* now remove from the LRU queue and put it back at the
-               * head of the LRU queue.
-               */
-               cm_AdjustScacheLRU(scp);
-
-               /* and we're done */
-               return scp;
-           }
-       }
-    }
-    osi_Log0(afsd_logp, "GetNewSCache no deleted or recycled entries available for reuse");
-#endif
-
     if (cm_data.currentSCaches >= cm_data.maxSCaches) {
        /* There were no deleted scache objects that we could use.  Try to find
         * one that simply hasn't been used in a while.
@@ -1290,7 +1189,7 @@ long cm_SyncOp(cm_scache_t *scp, cm_buf_t *bufp, cm_user_t *userp, cm_req_t *req
             if ((rights & (PRSFS_WRITE|PRSFS_DELETE)) && (scp->flags & CM_SCACHEFLAG_RO))
                 return CM_ERROR_READONLY;
 
-            if (cm_HaveAccessRights(scp, userp, rights, &outRights)) {
+            if (cm_HaveAccessRights(scp, userp, reqp, rights, &outRights)) {
                 if (~outRights & rights)
                    return CM_ERROR_NOACCESS;
             }
@@ -1530,6 +1429,8 @@ void cm_MergeStatus(cm_scache_t *dscp,
     struct cm_volume *volp = NULL;
     struct cm_cell *cellp = NULL;
 
+    lock_AssertWrite(&scp->rw);
+
     // yj: i want to create some fake status for the /afs directory and the
     // entries under that directory
 #ifdef AFS_FREELANCE_CLIENT
@@ -1686,7 +1587,9 @@ void cm_MergeStatus(cm_scache_t *dscp,
     /* and other stuff */
     scp->parentVnode = statusp->ParentVnode;
     scp->parentUnique = statusp->ParentUnique;
-    scp->fsLockCount = statusp->lockCount;
+
+    /* -1 is a write lock; any positive values are read locks */
+    scp->fsLockCount = (afs_int32)statusp->lockCount;
 
     /* and merge in the private acl cache info, if this is more than the public
      * info; merge in the public stuff in any case.