[OpenAFS-devel] Patch to allow fs getcache to show more info

Troy Benjegerdes hozer@hozed.org
Tue, 13 Jun 2006 13:09:25 -0500


This is a MIME-formatted message.  If you see this text it means that your
E-mail software does not support MIME-formatted messages.

--=_narn.hozed.org-8785-1150222165-0001-2
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

This patch against openafs-1.5.1 adds options to show more information
about how many cache files are used as well as how many cache blocks are
used.

There should be no change in default behavior.

http://source.scl.ameslab.gov/hg/openafs-dev-better-cachefiles-info?cmd=changeset;node=9fe7088be02e7c0454f62d635ab65cc30e6bef24



--=_narn.hozed.org-8785-1150222165-0001-2
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=openafs-dev-better-cachefiles-info

# HG changeset patch
# User troy@localhost.localdomain
# Date Fri May 26 00:13:57 2006
# Node ID 9fe7088be02e7c0454f62d635ab65cc30e6bef24
# parent: ff6d695570cee2c619449e2e97123618275ad5a3
Add two flags '-f' and '-e' to show more informative cache usage information


--- a/src/afs/afs_pioctl.c	Sun May 14 04:05:27 2006
+++ b/src/afs/afs_pioctl.c	Fri May 26 00:13:57 2006
@@ -2175,11 +2175,51 @@
 DECL_PIOCTL(PGetCacheSize)
 {
     afs_int32 results[MAXGCSTATS];
-
+    afs_int32 flags;
+    register struct dcache * tdc;
+    int i, size;
+    
     AFS_STATCNT(PGetCacheSize);
+
+    if (sizeof(afs_int32) == ainSize){
+	memcpy((char *)&flags, ain, sizeof(afs_int32));
+    } else if (0 == ainSize){ 
+	flags = 0;
+    } else {
+	return EINVAL;
+    }
+    
     memset((char *)results, 0, sizeof(results));
     results[0] = afs_cacheBlocks;
     results[1] = afs_blocksUsed;
+    results[2] = afs_cacheFiles;
+    
+    if (1 == flags){
+        for (i = 0; i < afs_cacheFiles; i++) {
+	    if (afs_indexFlags[i] & IFFree) results[3]++;
+	}
+    } else if (2 == flags){
+        for (i = 0; i < afs_cacheFiles; i++) {
+	    if (afs_indexFlags[i] & IFFree) results[3]++;
+	    if (afs_indexFlags[i] & IFEverUsed) results[4]++;
+	    if (afs_indexFlags[i] & IFDataMod) results[5]++;
+	    if (afs_indexFlags[i] & IFDirtyPages) results[6]++;
+	    if (afs_indexFlags[i] & IFAnyPages) results[7]++;
+	    if (afs_indexFlags[i] & IFDiscarded) results[8]++;
+
+	    tdc = afs_indexTable[i];
+	    if (tdc){
+	        results[9]++;
+	        size = tdc->validPos;
+	        if ( 0 < size && size < (1<<12) ) results[10]++;
+    	        else if (size < (1<<14) ) results[11]++;
+	        else if (size < (1<<16) ) results[12]++;
+	        else if (size < (1<<18) ) results[13]++;
+	        else if (size < (1<<20) ) results[14]++;
+	        else if (size >= (1<<20) ) results[15]++;
+	    }
+        }
+    }
     memcpy(aout, (char *)results, sizeof(results));
     *aoutSize = sizeof(results);
     return 0;
--- a/src/afsd/afsd.c	Sun May 14 04:05:27 2006
+++ b/src/afsd/afsd.c	Fri May 26 00:13:57 2006
@@ -2396,7 +2396,7 @@
 		param5, param6, param7);
 #endif
 
-    if (afsd_verbose)
+    if (afsd_debug)
 	printf("SScall(%d, %d, %d)=%d ", AFS_SYSCALL, AFSCALL_CALL, param1,
 	       error);
     return (error);
--- a/src/venus/fs.c	Sun May 14 04:05:27 2006
+++ b/src/venus/fs.c	Fri May 26 00:13:57 2006
@@ -1208,7 +1208,7 @@
         struct vcxstat2 stat;
         blob.out_size = sizeof(struct vcxstat2);
         blob.in_size = 0;
-        blob.out = &stat;
+        blob.out = (void *)&stat;
         code = pioctl(ti->data, VIOC_GETVCXSTATUS2, &blob, 1);
         if (code) {
             Die(errno, ti->data);
@@ -2006,13 +2006,28 @@
 static int
 GetCacheParmsCmd(struct cmd_syndesc *as, char *arock)
 {
-    afs_int32 code;
+    afs_int32 code, filesUsed;
     struct ViceIoctl blob;
     afs_int32 parms[MAXGCSIZE];
+    double percentFiles, percentBlocks;
+    afs_int32 flags = 0;
+
+    if (as->parms[0].items){ /* -files */
+	flags = 1;
+    } else if (as->parms[1].items){ /* -excessive */
+	flags = 2;
+    } else {
+	flags = 0;
+    }
 
     memset(parms, '\0', sizeof parms);	/* avoid Purify UMR error */
-    blob.in = NULL;
-    blob.in_size = 0;
+    if (flags){
+	blob.in = (char *)&flags;
+	blob.in_size = sizeof(afs_int32);
+    } else {	/* be backward compatible */
+	blob.in = NULL;
+	blob.in_size = 0;
+    }
     blob.out_size = sizeof(parms);
     blob.out = (char *)parms;
     code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
@@ -2020,11 +2035,45 @@
 	Die(errno, NULL);
 	return 1;
     }
-    printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
-	   parms[1], parms[0]);
-    if (parms[1] > parms[0])
-	printf
-	    ("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
+
+    if (!flags){
+	printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
+		parms[1], parms[0]);
+	if (parms[1] > parms[0])
+		printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
+	return 0;
+    }
+
+    percentBlocks = ((double)parms[1]/parms[0]) * 100;
+    printf("AFS using %5.0f%% of cache blocks (%d of %d 1k blocks)\n",
+	   percentBlocks, parms[1], parms[0]);
+
+    filesUsed = parms[2] - parms[3];
+    percentFiles = ((double)filesUsed/parms[2]) * 100;
+    printf("          %5.0f%% of the cache files (%d of %d files)\n",
+	    percentFiles, filesUsed, parms[2]);
+    if (flags == 2){
+	printf("	afs_cacheFiles: %10d\n", parms[2]);
+	printf("	IFFree:         %10d\n", parms[3]); 
+	printf("	IFEverUsed:     %10d\n", parms[4]); 
+	printf("	IFDataMod:      %10d\n", parms[5]); 
+	printf("	IFDirtyPages:   %10d\n", parms[6]);
+	printf("	IFAnyPages:     %10d\n", parms[7]); 
+	printf("	IFDiscarded:    %10d\n", parms[8]);
+	printf("	DCentries:  %10d\n", parms[9]);
+	printf("	  0k-   4K: %10d\n", parms[10]); 
+	printf("	  4k-  16k: %10d\n", parms[11]); 
+	printf("	 16k-  64k: %10d\n", parms[12]); 
+	printf("	 64k- 256k: %10d\n", parms[13]); 
+	printf("	256k-   1M: %10d\n", parms[14]); 
+	printf("	      >=1M: %10d\n", parms[15]); 
+    }
+
+    if (percentBlocks > 90)
+	printf("[cache size usage over 90%, consider increasing cache size]\n");
+    if (percentFiles > 90)
+	printf("[cache file usage over 90%, consider increasing '-files' argument to afsd]\n");
+	 
     return 0;
 }
 
@@ -3372,6 +3421,8 @@
 
     ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, 0,
 			  "get cache usage info");
+    cmd_AddParm(ts, "-files", CMD_FLAG, CMD_OPTIONAL, "Show cach files used as well");
+    cmd_AddParm(ts, "-excessive", CMD_FLAG, CMD_OPTIONAL, "excessively verbose cache stats");
 
     ts = cmd_CreateSyntax("listcells", ListCellsCmd, 0,
 			  "list configured cells");


--=_narn.hozed.org-8785-1150222165-0001-2--