Windows: Restore "fs getcacheparms" used space
authorJeffrey Altman <jaltman@your-file-system.com>
Sat, 1 Dec 2012 12:30:57 +0000 (07:30 -0500)
committerJeffrey Altman <jaltman@your-file-system.com>
Mon, 3 Dec 2012 22:06:43 +0000 (14:06 -0800)
buf_Init() adds all of the available buffers to the free queue
at startup and cm_data.buf_freeCount tracks the number of items
in the free queue.  So it cannot be used as a method of reporting
how much of the cache space has been used.   Add a new buf_usedCount
parameter to the cm_memmap data to track the number of cache blocks
that have been used up to the total number of allocated blocks.
buf_usedCount can then be used in cm_IoctlGetCacheParms to restore
the original behavior.

Change-Id: I3ecdfdbda1c423551b7e7691243696e0f1553edc
Reviewed-on: http://gerrit.openafs.org/8578
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
src/WINNT/afsd/cm_ioctl.c
src/WINNT/afsd/cm_memmap.c
src/WINNT/afsd/cm_memmap.h

index beeb303..77de7e3 100644 (file)
@@ -1480,6 +1480,9 @@ long buf_GetNewLocked(struct cm_scache *scp, osi_hyper_t *offsetp, cm_req_t *req
                osi_panic("buf_GetNewLocked: TryMutex failed",__FILE__,__LINE__);
            }
 
+            if ( cm_data.buf_usedCount < cm_data.buf_nbuffers)
+                InterlockedIncrement(&cm_data.buf_usedCount);
+
             lock_ReleaseWrite(&buf_globalLock);
             lock_ReleaseRead(&scp->bufCreateLock);
 
index 55a4f73..d760ec8 100644 (file)
@@ -1455,7 +1455,7 @@ cm_IoctlGetCacheParms(struct cm_ioctl *ioctlp, struct cm_user *userp)
      * so we report the entire cache in use since reporting 0 in use disturbs
      * many users.
      */
-    parms.parms[1] = cm_data.buf_nbuffers * (cm_data.buf_blockSize / 1024);
+    parms.parms[1] = cm_data.buf_usedCount * (cm_data.buf_blockSize / 1024);
 
     memcpy(ioctlp->outDatap, &parms, sizeof(parms));
     ioctlp->outDatap += sizeof(parms);
index c94e4a7..e9fc2e9 100644 (file)
@@ -895,7 +895,8 @@ cm_InitMappedMemory(DWORD virtualCache, char * cachePath, DWORD stats, DWORD max
         }
 
         cm_data.buf_nbuffers = cacheBlocks;
-        cm_data.buf_nOrigBuffers = 0;
+        cm_data.buf_nOrigBuffers = cacheBlocks;
+        cm_data.buf_usedCount = 0;
         cm_data.buf_blockSize = blockSize;
         cm_data.buf_hashSize = cm_NextHighestPowerOf2((afs_uint32)(cacheBlocks/7));
 
index e271eb3..6cd2332 100644 (file)
@@ -10,7 +10,7 @@
 #ifndef CM_MEMMAP_H
 #define CM_MEMMAP_H 1
 
-#define CM_CONFIG_DATA_VERSION  21
+#define CM_CONFIG_DATA_VERSION  22
 #define CM_CONFIG_DATA_MAGIC            ('A' | 'F'<<8 | 'S'<<16 | CM_CONFIG_DATA_VERSION<<24)
 
 typedef struct cm_config_data {
@@ -98,6 +98,7 @@ typedef struct cm_config_data {
     afs_uint32          buf_reserveWaiting;
     afs_uint32          buf_freeCount;
     afs_uint32          buf_redirCount;
+    afs_uint32          buf_usedCount;
 #else
     afs_uint64         buf_nbuffers;
     afs_uint64         buf_nOrigBuffers;
@@ -106,6 +107,7 @@ typedef struct cm_config_data {
     afs_uint64          buf_reserveWaiting;
     afs_uint64          buf_freeCount;
     afs_uint64          buf_redirCount;
+    afs_uint64          buf_usedCount;
 #endif
     time_t              mountRootGen;
     afsUUID             Uuid;