2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
15 #include <sys/types.h>
20 #ifdef HAVE_NETINET_IN_H
21 #include <netinet/in.h>
23 #include <sys/socket.h>
31 #include <afs/afscbint.h>
35 #include <afs/afs_args.h>
36 #include <afs/afsutil.h>
37 #include <afs/com_err.h>
39 static int print_ctime = 0;
42 PrintCacheConfig(struct rx_connection *aconn)
45 afs_uint32 srv_ver, conflen;
48 c.cacheConfig_len = 0;
49 c.cacheConfig_val = NULL;
50 code = RXAFSCB_GetCacheConfig(aconn, 1, &srv_ver, &conflen, &c);
52 printf("cmdebug: error checking cache config: %s\n",
53 afs_error_message(code));
57 if (srv_ver == AFS_CLIENT_RETRIEVAL_FIRST_EDITION) {
58 struct cm_initparams_v1 *c1;
60 if (c.cacheConfig_len != sizeof(*c1) / sizeof(afs_uint32)) {
61 printf("cmdebug: configuration data size mismatch (%d != %" AFS_SIZET_FMT ")\n",
62 c.cacheConfig_len, sizeof(*c1) / sizeof(afs_uint32));
66 c1 = (struct cm_initparams_v1 *)c.cacheConfig_val;
67 printf("Chunk files: %d\n", c1->nChunkFiles);
68 printf("Stat caches: %d\n", c1->nStatCaches);
69 printf("Data caches: %d\n", c1->nDataCaches);
70 printf("Volume caches: %d\n", c1->nVolumeCaches);
71 printf("Chunk size: %d", c1->otherChunkSize);
72 if (c1->firstChunkSize != c1->otherChunkSize)
73 printf(" (first: %d)", c1->firstChunkSize);
75 printf("Cache size: %d kB\n", c1->cacheSize);
76 printf("Set time: %s\n", c1->setTime ? "yes" : "no");
77 printf("Cache type: %s\n", c1->memCache ? "memory" : "disk");
79 printf("cmdebug: unsupported server version %d\n", srv_ver);
84 #ifndef CAPABILITY_BITS
85 #define CAPABILITY_ERRORTRANS (1<<0)
86 #define CAPABILITY_BITS 1
90 PrintInterfaces(struct rx_connection *aconn)
93 struct interfaceAddr addr;
102 caps.Capabilities_val = NULL;
103 caps.Capabilities_len = 0;
105 code = RXAFSCB_TellMeAboutYourself(aconn, &addr, &caps);
106 if (code == RXGEN_OPCODE)
107 code = RXAFSCB_WhoAreYou(aconn, &addr);
109 printf("cmdebug: error checking interfaces: %s\n",
110 afs_error_message(code));
115 UuidToString((UUID *)&addr.uuid, &p);
116 printf("UUID: %s\n",p);
119 afsUUID_to_string(&addr.uuid, uuidstr, sizeof(uuidstr));
120 printf("UUID: %s\n",uuidstr);
123 printf("Host interfaces:\n");
124 for (i = 0; i < addr.numberOfInterfaces; i++) {
125 printf("%s", afs_inet_ntoa_r(htonl(addr.addr_in[i]), hoststr));
126 if (addr.subnetmask[i])
127 printf(", netmask %s", afs_inet_ntoa_r(htonl(addr.subnetmask[i]), hoststr));
129 printf(", MTU %d", addr.mtu[i]);
133 if (caps.Capabilities_val) {
134 printf("Capabilities:\n");
135 if (caps.Capabilities_val[0] & CAPABILITY_ERRORTRANS) {
136 printf("Error Translation\n");
141 if (caps.Capabilities_val)
142 free(caps.Capabilities_val);
143 caps.Capabilities_val = NULL;
144 caps.Capabilities_len = 0;
150 IsLocked(struct AFSDBLockDesc *alock)
152 if (alock->waitStates || alock->exclLocked || alock->numWaiting
153 || alock->readersReading)
159 PrintLock(struct AFSDBLockDesc *alock)
162 if (alock->waitStates) {
163 if (alock->waitStates & READ_LOCK)
164 printf("reader_waiting");
165 if (alock->waitStates & WRITE_LOCK)
166 printf("writer_waiting");
167 if (alock->waitStates & SHARED_LOCK)
168 printf("upgrade_waiting");
170 printf("none_waiting");
171 if (alock->exclLocked) {
172 if (alock->exclLocked & WRITE_LOCK)
173 printf(", write_locked");
174 if (alock->exclLocked & SHARED_LOCK)
175 printf(", upgrade_locked");
176 printf("(pid:%d at:%d)", alock->pid_writer, alock->src_indicator);
178 if (alock->readersReading)
179 printf(", %d read_locks(pid:%d)", alock->readersReading,
180 alock->pid_last_reader);
181 if (alock->numWaiting)
182 printf(", %d waiters", alock->numWaiting);
188 PrintLocks(struct rx_connection *aconn, int aint32)
191 struct AFSDBLock lock;
194 for (i = 0; i < 1000; i++) {
195 code = RXAFSCB_GetLock(aconn, i, &lock);
199 /* otherwise we have an unrecognized error */
200 printf("cmdebug: error checking locks: %s\n",
201 afs_error_message(code));
204 /* here we have the lock information, so display it, perhaps */
205 if (aint32 || IsLocked(&lock.lock)) {
206 printf("Lock %s status: ", lock.name);
207 PrintLock(&lock.lock);
217 struct cell_cache *next;
221 GetCellName(struct rx_connection *aconn, afs_int32 cellnum)
223 static int no_getcellbynum;
224 static struct cell_cache *cache;
225 struct cell_cache *tcp;
233 for (tcp = cache; tcp; tcp = tcp->next)
234 if (tcp->cellnum == cellnum)
235 return tcp->cellname;
238 sl.serverList_len = 0;
239 sl.serverList_val = NULL;
240 code = RXAFSCB_GetCellByNum(aconn, cellnum, &cellname, &sl);
242 if (code == RXGEN_OPCODE)
247 if (sl.serverList_val)
248 free(sl.serverList_val);
249 tcp = malloc(sizeof(struct cell_cache));
251 tcp->cellnum = cellnum;
252 tcp->cellname = cellname;
259 PrintCacheEntries32(struct rx_connection *aconn, int aint32)
263 struct AFSDBCacheEntry centry;
266 for (i = 0; i < 1000000; i++) {
267 code = RXAFSCB_GetCE(aconn, i, ¢ry);
271 printf("cmdebug: failed to get cache entry %d (%s)\n", i,
272 afs_error_message(code));
276 if (centry.addr == 0) {
278 printf("Proc %4d sleeping at %08x, pri %3d\n",
279 centry.netFid.Vnode, centry.netFid.Volume,
280 centry.netFid.Unique - 25);
284 if ((aint32 == 0 && !IsLocked(¢ry.lock)) ||
285 (aint32 == 2 && centry.refCount == 0) ||
286 (aint32 == 4 && centry.callback == 0))
289 /* otherwise print this entry */
290 printf("** Cache entry @ 0x%08x for %d.%d.%d.%d", centry.addr,
291 centry.cell, centry.netFid.Volume, centry.netFid.Vnode,
292 centry.netFid.Unique);
294 cellname = GetCellName(aconn, centry.cell);
296 printf(" [%s]\n", cellname);
300 if (IsLocked(¢ry.lock)) {
302 PrintLock(¢ry.lock);
305 printf(" %12d bytes DV %12d refcnt %5d\n", centry.Length,
306 centry.DataVersion, centry.refCount);
308 time_t t = centry.cbExpires;
309 printf(" callback %08x\texpires %s\n", centry.callback,
312 printf(" callback %08x\texpires %u\n", centry.callback,
314 printf(" %d opens\t%d writers\n", centry.opens, centry.writers);
316 /* now display states */
318 if (centry.mvstat == 0)
319 printf("normal file");
320 else if (centry.mvstat == 1)
321 printf("mount point");
322 else if (centry.mvstat == 2)
323 printf("volume root");
324 else if (centry.mvstat == 3) /* windows */
326 else if (centry.mvstat == 4) /* windows */
328 else if (centry.mvstat == 5) /* windows */
329 printf("microsoft dfs link");
330 else if (centry.mvstat == 6) /* windows */
331 printf("invalid link");
333 printf("bogus mvstat %d", centry.mvstat);
334 printf("\n states (0x%x)", centry.states);
335 if (centry.states & 1)
337 if (centry.states & 2)
339 if (centry.states & 4)
340 printf(", read-only");
341 if (centry.states & 8)
342 printf(", mt pt valid");
343 if (centry.states & 0x10)
344 printf(", pending core");
345 if (centry.states & 0x40)
346 printf(", wait-for-store");
347 if (centry.states & 0x80)
355 PrintCacheEntries64(struct rx_connection *aconn, int aint32)
359 struct AFSDBCacheEntry64 centry;
362 for (i = 0; i < 1000000; i++) {
363 code = RXAFSCB_GetCE64(aconn, i, ¢ry);
367 printf("cmdebug: failed to get cache entry %d (%s)\n", i,
368 afs_error_message(code));
372 if (centry.addr == 0) {
374 printf("Proc %4d sleeping at %08x, pri %3d\n",
375 centry.netFid.Vnode, centry.netFid.Volume,
376 centry.netFid.Unique - 25);
380 if ((aint32 == 0 && !IsLocked(¢ry.lock)) ||
381 (aint32 == 2 && centry.refCount == 0) ||
382 (aint32 == 4 && centry.callback == 0))
385 /* otherwise print this entry */
386 printf("** Cache entry @ 0x%08x for %d.%d.%d.%d", centry.addr,
387 centry.cell, centry.netFid.Volume, centry.netFid.Vnode,
388 centry.netFid.Unique);
390 cellname = GetCellName(aconn, centry.cell);
392 printf(" [%s]\n", cellname);
396 if (IsLocked(¢ry.lock)) {
398 PrintLock(¢ry.lock);
402 printf(" %12I64d bytes DV %12d refcnt %5d\n", centry.Length,
403 centry.DataVersion, centry.refCount);
405 printf(" %12llu bytes DV %12d refcnt %5d\n", centry.Length,
406 centry.DataVersion, centry.refCount);
409 time_t t = centry.cbExpires;
410 printf(" callback %08x\texpires %s\n", centry.callback,
413 printf(" callback %08x\texpires %u\n", centry.callback,
415 printf(" %d opens\t%d writers\n", centry.opens, centry.writers);
417 /* now display states */
419 if (centry.mvstat == 0)
420 printf("normal file");
421 else if (centry.mvstat == 1)
422 printf("mount point");
423 else if (centry.mvstat == 2)
424 printf("volume root");
425 else if (centry.mvstat == 3)
427 else if (centry.mvstat == 4)
429 else if (centry.mvstat == 5)
430 printf("microsoft dfs link");
431 else if (centry.mvstat == 6)
432 printf("invalid link");
434 printf("bogus mvstat %d", centry.mvstat);
435 printf("\n states (0x%x)", centry.states);
436 if (centry.states & 1)
438 if (centry.states & 2)
440 if (centry.states & 4)
441 printf(", read-only");
442 if (centry.states & 8)
443 printf(", mt pt valid");
444 if (centry.states & 0x10)
445 printf(", pending core");
446 if (centry.states & 0x40)
447 printf(", wait-for-store");
448 if (centry.states & 0x80)
456 PrintCacheEntries(struct rx_connection *aconn, int aint32)
459 struct AFSDBCacheEntry64 centry64;
461 code = RXAFSCB_GetCE64(aconn, 0, ¢ry64);
462 if (code != RXGEN_OPCODE)
463 return PrintCacheEntries64(aconn, aint32);
465 return PrintCacheEntries32(aconn, aint32);
469 PrintCellServDBEntry(struct rx_connection *aconn, afs_int32 cellnum)
478 sl.serverList_len = 0;
479 sl.serverList_val = NULL;
480 code = RXAFSCB_GetCellServDB(aconn, cellnum, &cellname, &sl);
484 if ( !cellname || !cellname[0] )
488 printf(">%-23s#%s\n", cellname, cellname);
490 if (sl.serverList_val) {
492 for ( n=0; n<sl.serverList_len; n++) {
493 struct hostent *host;
494 afs_uint32 addr = ntohl(sl.serverList_val[n]);
496 host = gethostbyaddr((const char *)&addr, sizeof(afs_uint32), AF_INET);
497 printf("%-28s#%s\n", afs_inet_ntoa_r(addr, hoststr),
498 host ? host->h_name : "");
506 if (sl.serverList_val)
507 free(sl.serverList_val);
513 PrintCellServDB(struct rx_connection *aconn)
517 for ( index = 0 ; PrintCellServDBEntry(aconn, index); index++ );
521 CommandProc(struct cmd_syndesc *as, void *arock)
523 struct rx_connection *conn;
527 struct rx_securityClass *secobj;
531 hostName = as->parms[0].items->data;
532 if (as->parms[1].items)
533 port = atoi(as->parms[1].items->data);
536 thp = hostutil_GetHostByName(hostName);
538 printf("cmdebug: can't resolve address for host %s.\n", hostName);
541 memcpy(&addr, thp->h_addr, sizeof(afs_int32));
542 secobj = rxnull_NewServerSecurityObject();
543 conn = rx_NewConnection(addr, htons(port), 1, secobj, 0);
545 printf("cmdebug: failed to create connection for host %s\n",
550 if (as->parms[6].items) {
552 PrintInterfaces(conn);
555 if (as->parms[7].items) {
557 PrintCacheConfig(conn);
561 if (as->parms[8].items) {
563 PrintCellServDB(conn);
567 if (as->parms[5].items)
570 if (as->parms[2].items)
573 else if (as->parms[3].items)
576 else if (as->parms[4].items)
582 if (int32p == 0 || int32p == 1)
583 PrintLocks(conn, int32p);
584 if (int32p >= 0 || int32p <= 4)
585 PrintCacheEntries(conn, int32p);
590 #include "AFS_component_version_number.c"
594 main(int argc, char **argv)
596 struct cmd_syndesc *ts;
600 * The following signal action for AIX is necessary so that in case of a
601 * crash (i.e. core is generated) we can include the user's data section
602 * in the core dump. Unfortunately, by default, only a partial core is
603 * generated which, in many cases, isn't too useful.
605 struct sigaction nsa;
607 sigemptyset(&nsa.sa_mask);
608 nsa.sa_handler = SIG_DFL;
609 nsa.sa_flags = SA_FULLDUMP;
610 sigaction(SIGSEGV, &nsa, NULL);
614 if (afs_winsockInit() < 0) {
615 printf("%s: Couldn't initialize winsock. Exiting...\n", argv[0]);
622 ts = cmd_CreateSyntax(NULL, CommandProc, NULL, "query afs cache manager");
623 cmd_AddParm(ts, "-servers", CMD_SINGLE, CMD_REQUIRED, "server machine");
624 cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "IP port");
625 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "print all info");
626 cmd_AddParm(ts, "-refcounts", CMD_FLAG, CMD_OPTIONAL,
627 "print only cache entries with positive reference counts");
628 cmd_AddParm(ts, "-callbacks", CMD_FLAG, CMD_OPTIONAL,
629 "print only cache entries with callbacks");
630 cmd_AddParm(ts, "-ctime", CMD_FLAG, CMD_OPTIONAL,
631 "print human readable expiration time");
634 cmd_AddParm(ts, "-addrs", CMD_FLAG, CMD_OPTIONAL,
635 "print only host interfaces");
636 cmd_AddParm(ts, "-cache", CMD_FLAG, CMD_OPTIONAL,
637 "print only cache configuration");
638 cmd_AddParm(ts, "-cellservdb", CMD_FLAG, CMD_OPTIONAL,
639 "print only cellservdb info");
641 cmd_Dispatch(argc, argv);