X-Git-Url: https://git.openafs.org/?p=openafs.git;a=blobdiff_plain;f=src%2Fvenus%2Fcmdebug.c;h=4b16affa30b3e3ba262ce7fcbaa6de6af6bb099f;hp=fd5e6af99eee2bf25547cd2092af7d31934622e6;hb=e240c805e238e803ae910487c9f87ee98f508414;hpb=a093138a6d8f91068bec2cff1adcfafbacf7b65f diff --git a/src/venus/cmdebug.c b/src/venus/cmdebug.c index fd5e6af..4b16aff 100644 --- a/src/venus/cmdebug.c +++ b/src/venus/cmdebug.c @@ -10,14 +10,29 @@ #include #include -RCSID("$Header$"); +RCSID + ("$Header$"); #include +#ifdef AFS_NT40_ENV +#include +#include +#else +#ifdef HAVE_NETINET_IN_H #include +#endif #include #include +#endif #include +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif #ifdef AFS_AIX32_ENV #include #endif @@ -27,17 +42,17 @@ RCSID("$Header$"); #include #include -extern struct rx_securityClass *rxnull_NewServerSecurityObject(); extern struct hostent *hostutil_GetHostByName(); -static PrintCacheConfig(aconn) - struct rx_connection *aconn; +static int +PrintCacheConfig(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", @@ -54,7 +69,7 @@ static PrintCacheConfig(aconn) return 0; } - c1 = (struct cm_initparams_v1 *) c.cacheConfig_val; + 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); @@ -71,41 +86,82 @@ static PrintCacheConfig(aconn) } } -static PrintInterfaces(aconn) - struct rx_connection *aconn; +#ifndef CAPABILITY_BITS +#define CAPABILITY_ERRORTRANS (1<<0) +#define CAPABILITY_BITS 1 +#endif + +static int +PrintInterfaces(struct rx_connection *aconn) { + Capabilities caps; struct interfaceAddr addr; +#ifdef AFS_NT40_ENV + char * p; +#else + char uuidstr[128]; +#endif int i, code; - code = RXAFSCB_WhoAreYou(aconn, &addr); + caps.Capabilities_val = NULL; + caps.Capabilities_len = 0; + + code = RXAFSCB_TellMeAboutYourself(aconn, &addr, &caps); + if (code == RXGEN_OPCODE) + code = RXAFSCB_WhoAreYou(aconn, &addr); if (code) { - printf("cmdebug: error checking interfaces: %s\n", error_message(code)); + printf("cmdebug: error checking interfaces: %s\n", + error_message(code)); return 0; } +#ifdef AFS_NT40_ENV + UuidToString((UUID *)&addr.uuid, &p); + printf("UUID: %s\n",p); + RpcStringFree(&p); +#else + afsUUID_to_string(&addr.uuid, uuidstr, sizeof(uuidstr)); + printf("UUID: %s\n",uuidstr); +#endif + printf("Host interfaces:\n"); - for (i=0; iwaitStates || alock->exclLocked - || alock->numWaiting || alock->readersReading) +static int +IsLocked(register struct AFSDBLockDesc *alock) +{ + if (alock->waitStates || alock->exclLocked || alock->numWaiting + || alock->readersReading) return 1; return 0; } -static PrintLock(alock) -register struct AFSDBLockDesc *alock; { +static int +PrintLock(register struct AFSDBLockDesc *alock) +{ printf("("); if (alock->waitStates) { if (alock->waitStates & READ_LOCK) @@ -114,36 +170,39 @@ register struct AFSDBLockDesc *alock; { printf("writer_waiting"); if (alock->waitStates & SHARED_LOCK) printf("upgrade_waiting"); - } - else + } else printf("none_waiting"); if (alock->exclLocked) { if (alock->exclLocked & WRITE_LOCK) printf(", write_locked"); if (alock->exclLocked & SHARED_LOCK) printf(", upgrade_locked"); - printf("(pid:%d at:%d)", alock->pid_writer, alock->src_indicator); + printf("(pid:%d at:%d)", alock->pid_writer, alock->src_indicator); } if (alock->readersReading) - printf(", %d read_locks(pid:%d)", alock->readersReading,alock->pid_last_reader); - if (alock->numWaiting) printf(", %d waiters", alock->numWaiting); + printf(", %d read_locks(pid:%d)", alock->readersReading, + alock->pid_last_reader); + if (alock->numWaiting) + printf(", %d waiters", alock->numWaiting); printf(")"); return 0; } -static PrintLocks(aconn, aint32) -int aint32; -register struct rx_connection *aconn; { +static int +PrintLocks(register struct rx_connection *aconn, int aint32) +{ register int i; struct AFSDBLock lock; afs_int32 code; - for(i=0;i<1000;i++) { + for (i = 0; i < 1000; i++) { code = RXAFSCB_GetLock(aconn, i, &lock); if (code) { - if (code == 1) break; + if (code == 1) + break; /* otherwise we have an unrecognized error */ - printf("cmdebug: error checking locks: %s\n", error_message(code)); + printf("cmdebug: error checking locks: %s\n", + error_message(code)); return code; } /* here we have the lock information, so display it, perhaps */ @@ -156,17 +215,155 @@ 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++) { + for (i = 0; i < 10000; i++) { code = RXAFSCB_GetCE(aconn, i, ¢ry); if (code) { - if (code == 1) break; + 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 == 0 && !IsLocked(¢ry.lock) || + aint32 == 2 && centry.refCount == 0 || + aint32 == 4 && centry.callback == 0) + 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(¢ry.lock)) { + printf(" locks: "); + PrintLock(¢ry.lock); + printf("\n"); + } + printf(" %012d bytes DV %012d refcnt %05d\n", centry.Length, + centry.DataVersion, centry.refCount); + 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 if (centry.mvstat == 3) /* windows */ + printf("directory"); + else if (centry.mvstat == 4) /* windows */ + printf("symlink"); + else if (centry.mvstat == 5) /* windows */ + printf("microsoft dfs link"); + else if (centry.mvstat == 6) /* windows */ + printf("invalid link"); + 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 +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, ¢ry); + if (code) { + if (code == 1) + break; printf("cmdebug: failed to get cache entry %d (%s)\n", i, error_message(code)); return code; @@ -175,45 +372,101 @@ register struct rx_connection *aconn; { 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); + centry.netFid.Vnode, centry.netFid.Volume, + centry.netFid.Unique - 25); continue; } - if (!aint32 && !IsLocked(¢ry.lock)) continue; + if (aint32 == 0 && !IsLocked(¢ry.lock) || + aint32 == 2 && centry.refCount == 0 || + aint32 == 4 && centry.callback == 0) + 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(¢ry.lock)) { printf(" locks: "); PrintLock(¢ry.lock); printf("\n"); } - printf(" %d bytes\tDV %d refcnt %d\n", centry.Length, centry.DataVersion, centry.refCount); - printf(" callback %08x\texpires %u\n", centry.callback, centry.cbExpires); +#ifdef AFS_64BIT_ENV + printf(" %012I64d bytes DV %012d refcnt %05d\n", centry.Length, + centry.DataVersion, centry.refCount); +#else + printf(" %012d bytes DV %012d refcnt %05d\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); + if (centry.mvstat == 0) + printf("normal file"); + else if (centry.mvstat == 1) + printf("mount point"); + else if (centry.mvstat == 2) + printf("volume root"); + else if (centry.mvstat == 3) + printf("directory"); + else if (centry.mvstat == 4) + printf("symlink"); + else if (centry.mvstat == 5) + printf("microsoft dfs link"); + else if (centry.mvstat == 6) + printf("invalid link"); + 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"); + 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 CommandProc(as) -struct cmd_syndesc *as; { +static int +PrintCacheEntries(struct rx_connection *aconn, int aint32) +{ + register afs_int32 code; + struct AFSDBCacheEntry64 centry64; + +#ifdef AFS_OBSD_ENV + return PrintCacheEntries32(aconn, aint32); +#else + code = RXAFSCB_GetCE64(aconn, 0, ¢ry64); + if (code != RXGEN_OPCODE) + return PrintCacheEntries64(aconn, aint32); + else + return PrintCacheEntries32(aconn, aint32); +#endif +} + +int +CommandProc(struct cmd_syndesc *as, char *arock) +{ struct rx_connection *conn; register char *hostName; register struct hostent *thp; @@ -236,31 +489,46 @@ struct cmd_syndesc *as; { secobj = rxnull_NewServerSecurityObject(); conn = rx_NewConnection(addr, htons(port), 1, secobj, 0); if (!conn) { - printf("cmdebug: failed to create connection for host %s\n", hostName); + printf("cmdebug: failed to create connection for host %s\n", + hostName); exit(1); } - if (as->parms[3].items) { + if (as->parms[5].items) { /* -addrs */ PrintInterfaces(conn); return 0; } - if (as->parms[4].items) { + if (as->parms[6].items) { /* -cache */ PrintCacheConfig(conn); return 0; } - if (as->parms[2].items) int32p = 1; - else int32p = 0; - PrintLocks(conn, int32p); - PrintCacheEntries(conn, int32p); + if (as->parms[2].items) + /* -long */ + int32p = 1; + else if (as->parms[3].items) + /* -refcounts */ + int32p = 2; + else if (as->parms[4].items) + /* -callbacks */ + int32p = 4; + else + int32p = 0; + + if (int32p == 0 || int32p == 1) + PrintLocks(conn, int32p); + if (int32p >= 0 || int32p <= 4) + PrintCacheEntries(conn, int32p); return 0; } +#ifndef AFS_NT40_ENV #include "AFS_component_version_number.c" +#endif -main(argc, argv) -int argc; -char **argv; { +int +main(int argc, char **argv) +{ register struct cmd_syndesc *ts; #ifdef AFS_AIX32_ENV @@ -271,20 +539,34 @@ char **argv; { * generated which, in many cases, isn't too useful. */ struct sigaction nsa; - + sigemptyset(&nsa.sa_mask); nsa.sa_handler = SIG_DFL; nsa.sa_flags = SA_FULLDUMP; sigaction(SIGSEGV, &nsa, NULL); #endif + +#ifdef AFS_NT40_ENV + if (afs_winsockInit() < 0) { + printf("%s: Couldn't initialize winsock. Exiting...\n", argv[0]); + return 1; + } +#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_AddParm(ts, "-refcounts", CMD_FLAG, CMD_OPTIONAL, + "print only cache entries with positive reference counts"); + cmd_AddParm(ts, "-callbacks", CMD_FLAG, CMD_OPTIONAL, + "print only cache entries with callbacks"); + 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);