cmdebug-getce64-support-20030304
[openafs.git] / src / venus / cmdebug.c
index 182f5a4..97c5d0f 100644 (file)
@@ -18,6 +18,13 @@ RCSID("$Header$");
 #include <sys/socket.h>
 #include <netdb.h>
 #include <stdio.h>
+#ifdef HAVE_STRING_H
+#include <string.h>
+#else
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+#endif
 #ifdef AFS_AIX32_ENV
 #include <signal.h>
 #endif
@@ -25,10 +32,77 @@ RCSID("$Header$");
 #include <afs/cmd.h>
 #include <rx/rx.h>
 #include <lock.h>
+#include <afs/afs_args.h>
 
-extern struct rx_securityClass *rxnull_NewServerSecurityObject();
 extern struct hostent *hostutil_GetHostByName();
 
+static PrintCacheConfig(aconn)
+    struct rx_connection *aconn;
+{
+    struct cacheConfig c;
+    afs_uint32 srv_ver, conflen;
+    int code;
+
+    c.cacheConfig_len = 0;
+    c.cacheConfig_val = NULL;
+    code = RXAFSCB_GetCacheConfig(aconn, 1, &srv_ver, &conflen, &c);
+    if (code) {
+       printf("cmdebug: error checking cache config: %s\n",
+              error_message(code));
+       return 0;
+    }
+
+    if (srv_ver == AFS_CLIENT_RETRIEVAL_FIRST_EDITION) {
+       struct cm_initparams_v1 *c1;
+
+       if (c.cacheConfig_len != sizeof(*c1) / sizeof(afs_uint32)) {
+           printf("cmdebug: configuration data size mismatch (%d != %d)\n",
+                  c.cacheConfig_len, sizeof(*c1) / sizeof(afs_uint32));
+           return 0;
+       }
+
+       c1 = (struct cm_initparams_v1 *) c.cacheConfig_val;
+       printf("Chunk files:   %d\n", c1->nChunkFiles);
+       printf("Stat caches:   %d\n", c1->nStatCaches);
+       printf("Data caches:   %d\n", c1->nDataCaches);
+       printf("Volume caches: %d\n", c1->nVolumeCaches);
+       printf("Chunk size:    %d", c1->otherChunkSize);
+       if (c1->firstChunkSize != c1->otherChunkSize)
+           printf(" (first: %d)", c1->firstChunkSize);
+       printf("\n");
+       printf("Cache size:    %d kB\n", c1->cacheSize);
+       printf("Set time:      %s\n", c1->setTime ? "yes" : "no");
+       printf("Cache type:    %s\n", c1->memCache ? "memory" : "disk");
+    } else {
+       printf("cmdebug: unsupported server version %d\n", srv_ver);
+    }
+}
+
+static PrintInterfaces(aconn)
+    struct rx_connection *aconn;
+{
+    struct interfaceAddr addr;
+    int i, code;
+
+    code = RXAFSCB_WhoAreYou(aconn, &addr);
+    if (code) {
+       printf("cmdebug: error checking interfaces: %s\n", error_message(code));
+       return 0;
+    }
+
+    printf("Host interfaces:\n");
+    for (i=0; i<addr.numberOfInterfaces; i++) {
+       printf("%s", afs_inet_ntoa(htonl(addr.addr_in[i])));
+       if (addr.subnetmask[i])
+           printf(", netmask %s", afs_inet_ntoa(htonl(addr.subnetmask[i])));
+       if (addr.mtu[i])
+           printf(", MTU %d", addr.mtu[i]);
+       printf("\n");
+    }
+
+    return 0;
+}
+
 static IsLocked(alock)
 register struct AFSDBLockDesc *alock; {
     if (alock->waitStates || alock->exclLocked
@@ -89,13 +163,56 @@ register struct rx_connection *aconn; {
     return 0;
 }
 
-static PrintCacheEntries(aconn, aint32)
-int aint32;
-register struct rx_connection *aconn; {
+struct cell_cache {
+    afs_int32 cellnum;
+    char *cellname;
+    struct cell_cache *next;
+};
+
+static char *GetCellName(struct rx_connection *aconn, afs_int32 cellnum)
+{
+    static int no_getcellbynum;
+    static struct cell_cache *cache;
+    struct cell_cache *tcp;
+    int code;
+    char *cellname;
+    serverList sl;
+
+    if (no_getcellbynum)
+       return NULL;
+
+    for (tcp = cache; tcp; tcp = tcp->next)
+       if (tcp->cellnum == cellnum)
+           return tcp->cellname;
+
+    cellname = NULL;
+    sl.serverList_len = 0;
+    sl.serverList_val = NULL;
+    code = RXAFSCB_GetCellByNum(aconn, cellnum, &cellname, &sl);
+    if (code) {
+       if (code == RXGEN_OPCODE)
+           no_getcellbynum = 1;
+       return NULL;
+    }
+
+    if (sl.serverList_val)
+       free (sl.serverList_val);
+    tcp = malloc(sizeof(struct cell_cache));
+    tcp->next = cache;
+    tcp->cellnum = cellnum;
+    tcp->cellname = cellname;
+    cache = tcp;
+
+    return cellname;
+}
+
+static int PrintCacheEntries32(struct rx_connection *aconn, int aint32)
+{
     register int i;
     register afs_int32 code;
     struct AFSDBCacheEntry centry;
-
+    char *cellname;
+    
     for(i=0;i<10000;i++) {
        code = RXAFSCB_GetCE(aconn, i, &centry);
        if (code) {
@@ -115,8 +232,16 @@ register struct rx_connection *aconn; {
        if (!aint32 && !IsLocked(&centry.lock)) continue;
 
        /* otherwise print this entry */
-       printf("** Cache entry @ 0x%08x for %d.%d.%d.%d\n", centry.addr, centry.cell,
-              centry.netFid.Volume, centry.netFid.Vnode, centry.netFid.Unique);
+       printf("** Cache entry @ 0x%08x for %d.%d.%d.%d", centry.addr,
+              centry.cell, centry.netFid.Volume, centry.netFid.Vnode,
+              centry.netFid.Unique);
+
+       cellname = GetCellName(aconn, centry.cell);
+       if (cellname)
+           printf(" [%s]\n", cellname);
+       else
+           printf("\n");
+
        if (IsLocked(&centry.lock)) {
            printf("    locks: ");
            PrintLock(&centry.lock);
@@ -145,6 +270,87 @@ register struct rx_connection *aconn; {
     return 0;
 }
 
+static int PrintCacheEntries64(struct rx_connection *aconn, int aint32)
+{
+    register int i;
+    register afs_int32 code;
+    struct AFSDBCacheEntry64 centry;
+    char *cellname;
+    int ce64 = 0;
+    
+    for(i=0;i<10000;i++) {
+       code = RXAFSCB_GetCE64(aconn, i, &centry);
+       if (code) {
+           if (code == 1) break;
+           printf("cmdebug: failed to get cache entry %d (%s)\n", i,
+                  error_message(code));
+           return code;
+       }
+
+       if (centry.addr == 0) {
+           /* PS output */
+           printf("Proc %4d sleeping at %08x, pri %3d\n",
+                  centry.netFid.Vnode, centry.netFid.Volume, centry.netFid.Unique-25);
+           continue;
+       }
+
+       if (!aint32 && !IsLocked(&centry.lock)) continue;
+
+       /* otherwise print this entry */
+       printf("** Cache entry @ 0x%08x for %d.%d.%d.%d", centry.addr,
+              centry.cell, centry.netFid.Volume, centry.netFid.Vnode,
+              centry.netFid.Unique);
+
+       cellname = GetCellName(aconn, centry.cell);
+       if (cellname)
+           printf(" [%s]\n", cellname);
+       else
+           printf("\n");
+
+       if (IsLocked(&centry.lock)) {
+           printf("    locks: ");
+           PrintLock(&centry.lock);
+           printf("\n");
+       }
+#ifdef AFS_64BIT_ENV
+       printf("    %lld bytes\tDV %d refcnt %d\n", centry.Length, centry.DataVersion, centry.refCount);
+#else
+       printf("    %d bytes\tDV %d refcnt %d\n", centry.Length, centry.DataVersion, centry.refCount);
+#endif
+       printf("    callback %08x\texpires %u\n", centry.callback, centry.cbExpires);
+       printf("    %d opens\t%d writers\n", centry.opens, centry.writers);
+
+       /* now display states */
+       printf("    ");
+       if (centry.mvstat == 0) printf("normal file");
+       else if (centry.mvstat == 1) printf("mount point");
+       else if (centry.mvstat == 2) printf("volume root");
+       else printf("bogus mvstat %d", centry.mvstat);
+       printf("\n    states (0x%x)", centry.states);
+       if (centry.states & 1) printf(", stat'd");
+       if (centry.states & 2) printf(", backup");
+       if (centry.states & 4) printf(", read-only");
+       if (centry.states & 8) printf(", mt pt valid");
+       if (centry.states & 0x10) printf(", pending core");
+       if (centry.states & 0x40) printf(", wait-for-store");
+       if (centry.states & 0x80) printf(", mapped");
+       printf("\n");
+    }
+    return 0;
+}
+
+static int PrintCacheEntries(struct rx_connection *aconn, int aint32)
+{
+    register afs_int32 code;
+    struct AFSDBCacheEntry64 centry64;
+    
+    code = RXAFSCB_GetCE64(aconn, 0, &centry64);
+    if (code != RXGEN_OPCODE) 
+       return PrintCacheEntries64(aconn, aint32);
+    else
+       return PrintCacheEntries32(aconn, aint32);
+}
+
 static CommandProc(as)
 struct cmd_syndesc *as; {
     struct rx_connection *conn;
@@ -172,6 +378,16 @@ struct cmd_syndesc *as; {
        printf("cmdebug: failed to create connection for host %s\n", hostName);
        exit(1);
     }
+    if (as->parms[3].items) {
+       /* -addrs */
+       PrintInterfaces(conn);
+       return 0;
+    }
+    if (as->parms[4].items) {
+       /* -cache */
+       PrintCacheConfig(conn);
+       return 0;
+    }
     if (as->parms[2].items) int32p = 1;
     else int32p = 0;
     PrintLocks(conn, int32p);
@@ -202,10 +418,12 @@ char **argv; {
 #endif
     rx_Init(0);
 
-    ts = cmd_CreateSyntax((char *) 0, CommandProc, 0, "probe unik server");
+    ts = cmd_CreateSyntax(NULL, CommandProc, 0, "probe unik server");
     cmd_AddParm(ts, "-servers", CMD_SINGLE, CMD_REQUIRED, "server machine");
     cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "IP port");
     cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "print all info");
+    cmd_AddParm(ts, "-addrs", CMD_FLAG, CMD_OPTIONAL, "print only host interfaces");
+    cmd_AddParm(ts, "-cache", CMD_FLAG, CMD_OPTIONAL, "print only cache configuration");
 
     cmd_Dispatch(argc, argv);
     exit(0);