fs-getcache-show-more-20060615
[openafs.git] / src / venus / fs.c
index d7ba182..0520ce1 100644 (file)
@@ -69,7 +69,7 @@ static char tspace[1024];
 static struct ubik_client *uclient;
 
 static int GetClientAddrsCmd(), SetClientAddrsCmd(), FlushMountCmd();
-static int RxStatProcCmd(), RxStatPeerCmd();
+static int RxStatProcCmd(), RxStatPeerCmd(), GetFidCmd();
 
 extern char *hostutil_GetNameByINet();
 extern struct hostent *hostutil_GetHostByName();
@@ -112,6 +112,13 @@ struct AclEntry {
     afs_int32 rights;
 };
 
+struct vcxstat2 {
+    afs_int32 callerAccess;
+    afs_int32 cbExpires;
+    afs_int32 anyAccess;
+    char mvstat;
+};
+
 static void
 ZapAcl(acl)
      struct Acl *acl;
@@ -1189,6 +1196,33 @@ ListACLCmd(struct cmd_syndesc *as, char *arock)
 }
 
 static int
+GetCallerAccess(struct cmd_syndesc *as, char *arock)
+{
+    struct cmd_item *ti;
+    int error = 0;
+
+    SetDotDefault(&as->parms[0].items);
+    for (ti = as->parms[0].items; ti; ti = ti->next) {
+        afs_int32 code;
+        struct ViceIoctl blob;
+        struct vcxstat2 stat;
+        blob.out_size = sizeof(struct vcxstat2);
+        blob.in_size = 0;
+        blob.out = (void *)&stat;
+        code = pioctl(ti->data, VIOC_GETVCXSTATUS2, &blob, 1);
+        if (code) {
+            Die(errno, ti->data);
+            error = 1;
+            continue;
+        }
+        printf("Callers access to %s is ", ti->data);
+        PRights(stat.callerAccess, 0);
+        printf("\n");
+    }
+    return error;
+}
+
+static int
 FlushVolumeCmd(struct cmd_syndesc *as, char *arock)
 {
     afs_int32 code;
@@ -1972,13 +2006,28 @@ SetCacheSizeCmd(struct cmd_syndesc *as, char *arock)
 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);
@@ -1986,11 +2035,45 @@ GetCacheParmsCmd(struct cmd_syndesc *as, char *arock)
        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;
 }
 
@@ -3097,6 +3180,61 @@ GetCryptCmd(struct cmd_syndesc *as, char *arock)
     return 0;
 }
 
+#ifdef AFS_DISCON_ENV
+static char *modenames[] = {
+    "discon",
+    "fetchonly",
+    "partial",
+    "nat",
+    "full",
+    NULL
+};
+
+static afs_int32
+DisconCmd(struct cmd_syndesc *as, char *arock)
+{
+    struct cmd_item *ti;
+    char *modename;
+    int modelen;
+    afs_int32 mode, code;
+    struct ViceIoctl blob;
+
+    blob.in = NULL;
+    blob.in_size = 0;
+
+    ti = as->parms[0].items;
+    if (ti) {
+       modename = ti->data;
+       modelen = strlen(modename);
+       for (mode = 0; modenames[mode] != NULL; mode++)
+           if (!strncasecmp(modename, modenames[mode], modelen))
+               break;
+       if (modenames[mode] == NULL)
+           printf("Unknown discon mode \"%s\"\n", modename);
+       else {
+           memcpy(space, &mode, sizeof mode);
+           blob.in = space;
+           blob.in_size = sizeof mode;
+       }
+    }
+
+    blob.out_size = sizeof(mode);
+    blob.out = space;
+    code = pioctl(0, VIOC_DISCON, &blob, 1);
+    if (code)
+       Die(errno, NULL);
+    else {
+       memcpy(&mode, space, sizeof mode);
+       if (mode < sizeof modenames / sizeof (char *))
+           printf("Discon mode is now \"%s\"\n", modenames[mode]);
+       else
+           printf("Unknown discon mode %d\n", mode);
+    }
+
+    return 0;
+}
+#endif
+
 #include "AFS_component_version_number.c"
 
 int
@@ -3172,6 +3310,11 @@ main(int argc, char **argv)
     cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
     cmd_CreateAlias(ts, "la");
 
+    ts = cmd_CreateSyntax("getcalleraccess", GetCallerAccess, 0,
+            "list callers access");
+    cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
+    cmd_CreateAlias(ts, "gca");
+
     ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, 0,
                          "clean up access control list");
     cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
@@ -3278,6 +3421,8 @@ defect 3069
 
     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");
@@ -3381,7 +3526,7 @@ defect 3069
     cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
 
     ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, 0,
-                         "set cache manager encryption flag");
+                         "get cache manager encryption flag");
 
     ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, 0,
                          "Manage per process RX statistics");
@@ -3398,6 +3543,17 @@ defect 3069
     ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, 0, "configure callback connection address");
     cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
 
+    /* try to find volume location information */
+    ts = cmd_CreateSyntax("getfid", GetFidCmd, 0,
+                         "get fid for file(s)");
+    cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
+
+#ifdef AFS_DISCON_ENV
+    ts = cmd_CreateSyntax("discon", DisconCmd, 0,
+                         "disconnection mode");
+    cmd_AddParm(ts, "-mode", CMD_SINGLE, CMD_OPTIONAL, "nat | full");
+#endif
+
     code = cmd_Dispatch(argc, argv);
     if (rxInitDone)
        rx_Finalize();
@@ -3755,3 +3911,25 @@ RxStatPeerCmd(struct cmd_syndesc *as, char *arock)
     return 0;
 }
 
+static int
+GetFidCmd(struct cmd_syndesc *as, char *arock)
+{
+    struct ViceIoctl blob;
+    struct cmd_item *ti;
+    for (ti = as->parms[0].items; ti; ti = ti->next) {
+      struct VenusFid vfid;
+      
+      blob.out_size = sizeof(struct VenusFid);
+      blob.out = (char *) &vfid;
+      blob.in_size = 0;
+      
+      if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
+       printf("File %s (%u.%u.%u) contained in volume %u\n",
+              ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,
+              vfid.Fid.Volume);
+      }
+    }
+
+    return 0;
+}
+