Windows: adjust scache LRU postion upon deletion
authorJeffrey Altman <jaltman@your-file-system.com>
Thu, 4 Aug 2011 21:25:01 +0000 (17:25 -0400)
committerJeffrey Altman <jaltman@openafs.org>
Fri, 5 Aug 2011 02:03:07 +0000 (19:03 -0700)
If the object represented by a scache object is deleted,
update the LRU position of the scache object to make it
the first object in the LRU queue to be recycled.  This
preserves the cached objects for those that might prove
useful in the future.

Change-Id: I0e862b1270e10c31f20ecde06d208f4b8c405c3a
Reviewed-on: http://gerrit.openafs.org/5161
Reviewed-by: Jeffrey Altman <jaltman@openafs.org>
Tested-by: Jeffrey Altman <jaltman@openafs.org>

src/WINNT/afsd/cm_conn.c
src/WINNT/afsd/cm_scache.c
src/WINNT/afsd/cm_vnodeops.c

index 02b495f..141adb6 100644 (file)
@@ -670,11 +670,12 @@ cm_Analyze(cm_conn_t *connp, cm_user_t *userp, cm_req_t *reqp,
                    pscp = cm_FindSCacheParent(scp);
 
                lock_ObtainWrite(&scp->rw);
+               scp->flags |= CM_SCACHEFLAG_DELETED;
                lock_ObtainWrite(&cm_scacheLock);
-               cm_RemoveSCacheFromHashTable(scp);
+                cm_AdjustScacheLRU(scp);
+                cm_RemoveSCacheFromHashTable(scp);
                lock_ReleaseWrite(&cm_scacheLock);
                 cm_LockMarkSCacheLost(scp);
-               scp->flags |= CM_SCACHEFLAG_DELETED;
                lock_ReleaseWrite(&scp->rw);
                cm_ReleaseSCache(scp);
 
index 9ac9874..d835949 100644 (file)
@@ -66,7 +66,12 @@ void cm_AdjustScacheLRU(cm_scache_t *scp)
 {
     lock_AssertWrite(&cm_scacheLock);
     osi_QRemoveHT((osi_queue_t **) &cm_data.scacheLRUFirstp, (osi_queue_t **) &cm_data.scacheLRULastp, &scp->q);
-    osi_QAddH((osi_queue_t **) &cm_data.scacheLRUFirstp, (osi_queue_t **) &cm_data.scacheLRULastp, &scp->q);
+    if (scp->flags & CM_SCACHEFLAG_DELETED) {
+        /* Since it has been deleted make it the first to be recycled. */
+        osi_QAddT((osi_queue_t **) &cm_data.scacheLRUFirstp, (osi_queue_t **) &cm_data.scacheLRULastp, &scp->q);
+    } else {
+        osi_QAddH((osi_queue_t **) &cm_data.scacheLRUFirstp, (osi_queue_t **) &cm_data.scacheLRULastp, &scp->q);
+    }
 }
 
 /* call with cm_scacheLock write-locked and scp rw held */
index bd2ed1e..f45f59f 100644 (file)
@@ -1691,8 +1691,13 @@ long cm_Unlink(cm_scache_t *dscp, fschar_t *fnamep, clientchar_t * cnamep,
         cm_ReleaseSCache(scp);
         if (code == 0) {
            lock_ObtainWrite(&scp->rw);
-            if (--scp->linkCount == 0)
+            if (--scp->linkCount == 0) {
                 scp->flags |= CM_SCACHEFLAG_DELETED;
+               lock_ObtainWrite(&cm_scacheLock);
+                cm_AdjustScacheLRU(scp);
+                cm_RemoveSCacheFromHashTable(scp);
+               lock_ReleaseWrite(&cm_scacheLock);
+            }
             cm_DiscardSCache(scp);
            lock_ReleaseWrite(&scp->rw);
         }
@@ -3449,6 +3454,10 @@ long cm_RemoveDir(cm_scache_t *dscp, fschar_t *fnamep, clientchar_t *cnamep, cm_
         if (code == 0) {
            lock_ObtainWrite(&scp->rw);
             scp->flags |= CM_SCACHEFLAG_DELETED;
+            lock_ObtainWrite(&cm_scacheLock);
+            cm_AdjustScacheLRU(scp);
+            cm_RemoveSCacheFromHashTable(scp);
+            lock_ReleaseWrite(&cm_scacheLock);
            lock_ReleaseWrite(&scp->rw);
         }
     }