From 66a5703463baad5739b6d47ed12d0a3a7b0c489a Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Sat, 1 Dec 2012 07:30:57 -0500 Subject: [PATCH] Windows: Restore "fs getcacheparms" used space 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 Reviewed-by: Jeffrey Altman Tested-by: Jeffrey Altman --- src/WINNT/afsd/cm_buf.c | 3 +++ src/WINNT/afsd/cm_ioctl.c | 2 +- src/WINNT/afsd/cm_memmap.c | 3 ++- src/WINNT/afsd/cm_memmap.h | 4 +++- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/WINNT/afsd/cm_buf.c b/src/WINNT/afsd/cm_buf.c index beeb30359..77de7e39f 100644 --- a/src/WINNT/afsd/cm_buf.c +++ b/src/WINNT/afsd/cm_buf.c @@ -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); diff --git a/src/WINNT/afsd/cm_ioctl.c b/src/WINNT/afsd/cm_ioctl.c index 55a4f73bb..d760ec8b0 100644 --- a/src/WINNT/afsd/cm_ioctl.c +++ b/src/WINNT/afsd/cm_ioctl.c @@ -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); diff --git a/src/WINNT/afsd/cm_memmap.c b/src/WINNT/afsd/cm_memmap.c index c94e4a768..e9fc2e92b 100644 --- a/src/WINNT/afsd/cm_memmap.c +++ b/src/WINNT/afsd/cm_memmap.c @@ -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)); diff --git a/src/WINNT/afsd/cm_memmap.h b/src/WINNT/afsd/cm_memmap.h index e271eb39e..6cd233202 100644 --- a/src/WINNT/afsd/cm_memmap.h +++ b/src/WINNT/afsd/cm_memmap.h @@ -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; -- 2.39.5