Windows: do not leak cm_volume_t objects from LRU queue
authorJeffrey Altman <jaltman@your-file-system.com>
Tue, 5 Oct 2010 15:32:05 +0000 (11:32 -0400)
committerJeffrey Altman <jaltman@openafs.org>
Tue, 5 Oct 2010 21:18:40 +0000 (14:18 -0700)
The LRU queue is where volume objects are recycled from.
Therefore if they are removed then they must be put back.

Remove extraneous operations from cm_AdjustVolumeLRU().

LICENSE MIT

Change-Id: I1f6aadd0ffb7aeafa013087e4825b3c8d8252a2d
Reviewed-on: http://gerrit.openafs.org/2913
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@openafs.org>
Tested-by: Jeffrey Altman <jaltman@openafs.org>

src/WINNT/afsd/cm_volume.c

index 266b507..6a85c05 100644 (file)
@@ -968,13 +968,21 @@ long cm_FindVolumeByName(struct cm_cell *cellp, char *volumeNamep,
     if (code == 0) {
         *outVolpp = volp;
                
-        if (!(flags & CM_GETVOL_FLAG_NO_LRU_UPDATE)) {
+        if ((volp->flags & CM_VOLUMEFLAG_IN_LRU_QUEUE) &&
+            !(flags & CM_GETVOL_FLAG_NO_LRU_UPDATE)) {
             lock_ObtainWrite(&cm_volumeLock);
             cm_AdjustVolumeLRU(volp);
             lock_ReleaseWrite(&cm_volumeLock);
         }
     } else {
+        /*
+         * do not return it to the caller but do insert it in the LRU
+         * otherwise it will be lost
+         */
         lock_ObtainRead(&cm_volumeLock);
+        if (!(volp->flags & CM_VOLUMEFLAG_IN_LRU_QUEUE) ||
+             (flags & CM_GETVOL_FLAG_NO_LRU_UPDATE))
+            cm_AdjustVolumeLRU(volp);
         cm_PutVolume(volp);
         lock_ReleaseRead(&cm_volumeLock);
     }
@@ -1681,14 +1689,13 @@ void cm_RemoveVolumeFromIDHashTable(cm_volume_t *volp, afs_uint32 volType)
 /* must be called with cm_volumeLock write-locked! */
 void cm_AdjustVolumeLRU(cm_volume_t *volp)
 {
-    if (volp == cm_data.volumeLRULastp)
-        cm_data.volumeLRULastp = (cm_volume_t *) osi_QPrev(&volp->q);
+    if (volp == cm_data.volumeLRUFirstp)
+        return;
+
     if (volp->flags & CM_VOLUMEFLAG_IN_LRU_QUEUE)
         osi_QRemoveHT((osi_queue_t **) &cm_data.volumeLRUFirstp, (osi_queue_t **) &cm_data.volumeLRULastp, &volp->q);
-    osi_QAdd((osi_queue_t **) &cm_data.volumeLRUFirstp, &volp->q);
+    osi_QAddH((osi_queue_t **) &cm_data.volumeLRUFirstp, (osi_queue_t **) &cm_data.volumeLRULastp, &volp->q);
     volp->flags |= CM_VOLUMEFLAG_IN_LRU_QUEUE;
-    if (!cm_data.volumeLRULastp) 
-        cm_data.volumeLRULastp = volp;
 }
 
 /* must be called with cm_volumeLock write-locked! */
@@ -1697,22 +1704,16 @@ void cm_MoveVolumeToLRULast(cm_volume_t *volp)
     if (volp == cm_data.volumeLRULastp)
         return;
 
-    if (volp == cm_data.volumeLRUFirstp)
-        cm_data.volumeLRUFirstp = (cm_volume_t *) osi_QNext(&volp->q);
     if (volp->flags & CM_VOLUMEFLAG_IN_LRU_QUEUE)
         osi_QRemoveHT((osi_queue_t **) &cm_data.volumeLRUFirstp, (osi_queue_t **) &cm_data.volumeLRULastp, &volp->q);
     osi_QAddT((osi_queue_t **) &cm_data.volumeLRUFirstp, (osi_queue_t **) &cm_data.volumeLRULastp, &volp->q);
     volp->flags |= CM_VOLUMEFLAG_IN_LRU_QUEUE;
-    if (!cm_data.volumeLRULastp) 
-        cm_data.volumeLRULastp = volp;
 }
 
 /* must be called with cm_volumeLock write-locked! */
 void cm_RemoveVolumeFromLRU(cm_volume_t *volp)
 {
     if (volp->flags & CM_VOLUMEFLAG_IN_LRU_QUEUE) {
-        if (volp == cm_data.volumeLRULastp)
-            cm_data.volumeLRULastp = (cm_volume_t *) osi_QPrev(&volp->q);
         osi_QRemoveHT((osi_queue_t **) &cm_data.volumeLRUFirstp, (osi_queue_t **) &cm_data.volumeLRULastp, &volp->q);
         volp->flags &= ~CM_VOLUMEFLAG_IN_LRU_QUEUE;
     }