Windows: Decr. used buf count flush and deleted files
authorJeffrey Altman <jaltman@your-file-system.com>
Sat, 1 Dec 2012 12:54:59 +0000 (07:54 -0500)
committerJeffrey Altman <jaltman@your-file-system.com>
Mon, 3 Dec 2012 22:07:11 +0000 (14:07 -0800)
When flushing the cache (fs flush*) or when deleting files or
when a file server reported error indicates that the buffer is
bad, decrement the used cache count so "fs getcacheparms" now
indicates a floating value based upon the number of buffers
containing potentially valid data.

Change-Id: I1bfb7b64ff36832526a02e9374ab87baf679f100
Reviewed-on: http://gerrit.openafs.org/8579
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
Tested-by: Jeffrey Altman <jaltman@your-file-system.com>

src/WINNT/afsd/cm_buf.c

index 77de7e3..2b9cfcf 100644 (file)
@@ -537,6 +537,7 @@ long buf_Init(int newFile, cm_buf_ops_t *opsp, afs_uint64 nbuffers)
                     bp->redirLastAccess = 0;
                     bp->redirReleaseRequested = 0;
                     buf_ReleaseLocked(bp, TRUE);
+                    InterlockedDecrement(&cm_data.buf_usedCount);
                 }
                 bp++;
             }
@@ -559,6 +560,7 @@ long buf_Init(int newFile, cm_buf_ops_t *opsp, afs_uint64 nbuffers)
                 bp->redirLastAccess = 0;
                 bp->redirReleaseRequested = 0;
                 buf_ReleaseLocked(bp, TRUE);
+                InterlockedDecrement(&cm_data.buf_usedCount);
             }
             lock_ReleaseWrite(&buf_globalLock);
         }
@@ -833,6 +835,7 @@ afs_uint32 buf_CleanLocked(cm_scache_t *scp, cm_buf_t *bp, cm_req_t *reqp,
         bp->error = code;
         bp->dataVersion = CM_BUF_VERSION_BAD;
         bp->dirtyCounter++;
+        InterlockedDecrement(&cm_data.buf_usedCount);
     }
 
     while ((bp->flags & CM_BUF_DIRTY) == CM_BUF_DIRTY) {
@@ -879,6 +882,7 @@ afs_uint32 buf_CleanLocked(cm_scache_t *scp, cm_buf_t *bp, cm_req_t *reqp,
            bp->error = code;
            bp->dataVersion = CM_BUF_VERSION_BAD;
            bp->dirtyCounter++;
+            InterlockedDecrement(&cm_data.buf_usedCount);
             break;
        }
 
@@ -1995,6 +1999,7 @@ long buf_Truncate(cm_scache_t *scp, cm_user_t *userp, cm_req_t *reqp,
                 bufp->dirty_length = 0;
                 bufp->dataVersion = CM_BUF_VERSION_BAD;        /* known bad */
                 bufp->dirtyCounter++;
+                InterlockedDecrement(&cm_data.buf_usedCount);
             }
             else {
                 /* don't set dirty, since dirty implies
@@ -2093,6 +2098,7 @@ long buf_FlushCleanPages(cm_scache_t *scp, cm_user_t *userp, cm_req_t *reqp)
                 bp->dataVersion = CM_BUF_VERSION_BAD;  /* known bad */
                 bp->dirtyCounter++;
                 lock_ReleaseMutex(&bp->mx);
+                InterlockedDecrement(&cm_data.buf_usedCount);
             } else if (!(scp->flags & CM_SCACHEFLAG_RO)) {
                 if (code) {
                     goto skip;
@@ -2119,6 +2125,8 @@ long buf_FlushCleanPages(cm_scache_t *scp, cm_user_t *userp, cm_req_t *reqp)
                             buf_HoldLocked(nbp);
                         buf_ReleaseLocked(bp, TRUE);
                         didRelease = 1;
+                        if (bp->dataVersion != CM_BUF_VERSION_BAD)
+                            InterlockedDecrement(&cm_data.buf_usedCount);
                         buf_Recycle(bp);
                     }
                 }
@@ -2164,6 +2172,7 @@ long buf_InvalidateBuffers(cm_scache_t * scp)
     for (bp = cm_data.buf_fileHashTablepp[i]; bp; bp = bp->fileHashp) {
         if (cm_FidCmp(&bp->fid, &scp->fid) == 0) {
             bp->dataVersion = CM_BUF_VERSION_BAD;
+            InterlockedDecrement(&cm_data.buf_usedCount);
             found = 1;
         }
     }
@@ -2274,6 +2283,7 @@ long buf_CleanVnode(struct cm_scache *scp, cm_user_t *userp, cm_req_t *reqp)
                     bp->error = code;
                     bp->dataVersion = CM_BUF_VERSION_BAD;
                     bp->dirtyCounter++;
+                    InterlockedDecrement(&cm_data.buf_usedCount);
                     break;
                 case CM_ERROR_TIMEDOUT:
                 case CM_ERROR_ALLDOWN:
@@ -2557,6 +2567,7 @@ long buf_CleanDirtyBuffers(cm_scache_t *scp)
            }
            lock_ReleaseMutex(&bp->mx);
            buf_Release(bp);
+            InterlockedDecrement(&cm_data.buf_usedCount);
        }
     }
     return 0;