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 != %lu)\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;
101 caps.Capabilities_val = NULL;
102 caps.Capabilities_len = 0;
104 code = RXAFSCB_TellMeAboutYourself(aconn, &addr, &caps);
105 if (code == RXGEN_OPCODE)
106 code = RXAFSCB_WhoAreYou(aconn, &addr);
108 printf("cmdebug: error checking interfaces: %s\n",
109 afs_error_message(code));
114 UuidToString((UUID *)&addr.uuid, &p);
115 printf("UUID: %s\n",p);
118 afsUUID_to_string(&addr.uuid, uuidstr, sizeof(uuidstr));
119 printf("UUID: %s\n",uuidstr);
122 printf("Host interfaces:\n");
123 for (i = 0; i < addr.numberOfInterfaces; i++) {
124 printf("%s", afs_inet_ntoa(htonl(addr.addr_in[i])));
125 if (addr.subnetmask[i])
126 printf(", netmask %s", afs_inet_ntoa(htonl(addr.subnetmask[i])));
128 printf(", MTU %d", addr.mtu[i]);
132 if (caps.Capabilities_val) {
133 printf("Capabilities:\n");
134 if (caps.Capabilities_val[0] & CAPABILITY_ERRORTRANS) {
135 printf("Error Translation\n");
140 if (caps.Capabilities_val)
141 free(caps.Capabilities_val);
142 caps.Capabilities_val = NULL;
143 caps.Capabilities_len = 0;
149 IsLocked(register struct AFSDBLockDesc *alock)
151 if (alock->waitStates || alock->exclLocked || alock->numWaiting
152 || alock->readersReading)
158 PrintLock(register struct AFSDBLockDesc *alock)
161 if (alock->waitStates) {
162 if (alock->waitStates & READ_LOCK)
163 printf("reader_waiting");
164 if (alock->waitStates & WRITE_LOCK)
165 printf("writer_waiting");
166 if (alock->waitStates & SHARED_LOCK)
167 printf("upgrade_waiting");
169 printf("none_waiting");
170 if (alock->exclLocked) {
171 if (alock->exclLocked & WRITE_LOCK)
172 printf(", write_locked");
173 if (alock->exclLocked & SHARED_LOCK)
174 printf(", upgrade_locked");
175 printf("(pid:%d at:%d)", alock->pid_writer, alock->src_indicator);
177 if (alock->readersReading)
178 printf(", %d read_locks(pid:%d)", alock->readersReading,
179 alock->pid_last_reader);
180 if (alock->numWaiting)
181 printf(", %d waiters", alock->numWaiting);
187 PrintLocks(register struct rx_connection *aconn, int aint32)
190 struct AFSDBLock lock;
193 for (i = 0; i < 1000; i++) {
194 code = RXAFSCB_GetLock(aconn, i, &lock);
198 /* otherwise we have an unrecognized error */
199 printf("cmdebug: error checking locks: %s\n",
200 afs_error_message(code));
203 /* here we have the lock information, so display it, perhaps */
204 if (aint32 || IsLocked(&lock.lock)) {
205 printf("Lock %s status: ", lock.name);
206 PrintLock(&lock.lock);
216 struct cell_cache *next;
220 GetCellName(struct rx_connection *aconn, afs_int32 cellnum)
222 static int no_getcellbynum;
223 static struct cell_cache *cache;
224 struct cell_cache *tcp;
232 for (tcp = cache; tcp; tcp = tcp->next)
233 if (tcp->cellnum == cellnum)
234 return tcp->cellname;
237 sl.serverList_len = 0;
238 sl.serverList_val = NULL;
239 code = RXAFSCB_GetCellByNum(aconn, cellnum, &cellname, &sl);
241 if (code == RXGEN_OPCODE)
246 if (sl.serverList_val)
247 free(sl.serverList_val);
248 tcp = malloc(sizeof(struct cell_cache));
250 tcp->cellnum = cellnum;
251 tcp->cellname = cellname;
258 PrintCacheEntries32(struct rx_connection *aconn, int aint32)
261 register afs_int32 code;
262 struct AFSDBCacheEntry centry;
265 for (i = 0; i < 1000000; i++) {
266 code = RXAFSCB_GetCE(aconn, i, ¢ry);
270 printf("cmdebug: failed to get cache entry %d (%s)\n", i,
271 afs_error_message(code));
275 if (centry.addr == 0) {
277 printf("Proc %4d sleeping at %08x, pri %3d\n",
278 centry.netFid.Vnode, centry.netFid.Volume,
279 centry.netFid.Unique - 25);
283 if ((aint32 == 0 && !IsLocked(¢ry.lock)) ||
284 (aint32 == 2 && centry.refCount == 0) ||
285 (aint32 == 4 && centry.callback == 0))
288 /* otherwise print this entry */
289 printf("** Cache entry @ 0x%08x for %d.%d.%d.%d", centry.addr,
290 centry.cell, centry.netFid.Volume, centry.netFid.Vnode,
291 centry.netFid.Unique);
293 cellname = GetCellName(aconn, centry.cell);
295 printf(" [%s]\n", cellname);
299 if (IsLocked(¢ry.lock)) {
301 PrintLock(¢ry.lock);
304 printf(" %12d bytes DV %12d refcnt %5d\n", centry.Length,
305 centry.DataVersion, centry.refCount);
307 time_t t = centry.cbExpires;
308 printf(" callback %08x\texpires %s\n", centry.callback,
311 printf(" callback %08x\texpires %u\n", centry.callback,
313 printf(" %d opens\t%d writers\n", centry.opens, centry.writers);
315 /* now display states */
317 if (centry.mvstat == 0)
318 printf("normal file");
319 else if (centry.mvstat == 1)
320 printf("mount point");
321 else if (centry.mvstat == 2)
322 printf("volume root");
323 else if (centry.mvstat == 3) /* windows */
325 else if (centry.mvstat == 4) /* windows */
327 else if (centry.mvstat == 5) /* windows */
328 printf("microsoft dfs link");
329 else if (centry.mvstat == 6) /* windows */
330 printf("invalid link");
332 printf("bogus mvstat %d", centry.mvstat);
333 printf("\n states (0x%x)", centry.states);
334 if (centry.states & 1)
336 if (centry.states & 2)
338 if (centry.states & 4)
339 printf(", read-only");
340 if (centry.states & 8)
341 printf(", mt pt valid");
342 if (centry.states & 0x10)
343 printf(", pending core");
344 if (centry.states & 0x40)
345 printf(", wait-for-store");
346 if (centry.states & 0x80)
354 PrintCacheEntries64(struct rx_connection *aconn, int aint32)
357 register afs_int32 code;
358 struct AFSDBCacheEntry64 centry;
361 for (i = 0; i < 1000000; i++) {
362 code = RXAFSCB_GetCE64(aconn, i, ¢ry);
366 printf("cmdebug: failed to get cache entry %d (%s)\n", i,
367 afs_error_message(code));
371 if (centry.addr == 0) {
373 printf("Proc %4d sleeping at %08x, pri %3d\n",
374 centry.netFid.Vnode, centry.netFid.Volume,
375 centry.netFid.Unique - 25);
379 if ((aint32 == 0 && !IsLocked(¢ry.lock)) ||
380 (aint32 == 2 && centry.refCount == 0) ||
381 (aint32 == 4 && centry.callback == 0))
384 /* otherwise print this entry */
385 printf("** Cache entry @ 0x%08x for %d.%d.%d.%d", centry.addr,
386 centry.cell, centry.netFid.Volume, centry.netFid.Vnode,
387 centry.netFid.Unique);
389 cellname = GetCellName(aconn, centry.cell);
391 printf(" [%s]\n", cellname);
395 if (IsLocked(¢ry.lock)) {
397 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 printf(" %12d bytes DV %12d refcnt %5d\n", centry.Length,
410 centry.DataVersion, centry.refCount);
413 time_t t = centry.cbExpires;
414 printf(" callback %08x\texpires %s\n", centry.callback,
417 printf(" callback %08x\texpires %u\n", centry.callback,
419 printf(" %d opens\t%d writers\n", centry.opens, centry.writers);
421 /* now display states */
423 if (centry.mvstat == 0)
424 printf("normal file");
425 else if (centry.mvstat == 1)
426 printf("mount point");
427 else if (centry.mvstat == 2)
428 printf("volume root");
429 else if (centry.mvstat == 3)
431 else if (centry.mvstat == 4)
433 else if (centry.mvstat == 5)
434 printf("microsoft dfs link");
435 else if (centry.mvstat == 6)
436 printf("invalid link");
438 printf("bogus mvstat %d", centry.mvstat);
439 printf("\n states (0x%x)", centry.states);
440 if (centry.states & 1)
442 if (centry.states & 2)
444 if (centry.states & 4)
445 printf(", read-only");
446 if (centry.states & 8)
447 printf(", mt pt valid");
448 if (centry.states & 0x10)
449 printf(", pending core");
450 if (centry.states & 0x40)
451 printf(", wait-for-store");
452 if (centry.states & 0x80)
460 PrintCacheEntries(struct rx_connection *aconn, int aint32)
462 register afs_int32 code;
463 struct AFSDBCacheEntry64 centry64;
465 code = RXAFSCB_GetCE64(aconn, 0, ¢ry64);
466 if (code != RXGEN_OPCODE)
467 return PrintCacheEntries64(aconn, aint32);
469 return PrintCacheEntries32(aconn, aint32);
473 PrintCellServDBEntry(struct rx_connection *aconn, afs_int32 cellnum)
482 sl.serverList_len = 0;
483 sl.serverList_val = NULL;
484 code = RXAFSCB_GetCellServDB(aconn, cellnum, &cellname, &sl);
488 if ( !cellname || !cellname[0] )
492 printf(">%-23s#%s\n", cellname, cellname);
494 if (sl.serverList_val) {
495 for ( n=0; n<sl.serverList_len; n++) {
496 struct hostent *host;
497 afs_uint32 addr = ntohl(sl.serverList_val[n]);
499 host = gethostbyaddr((const char *)&addr, sizeof(afs_uint32), AF_INET);
500 printf("%-28s#%s\n", afs_inet_ntoa(addr),
501 host ? host->h_name : "");
509 if (sl.serverList_val)
510 free(sl.serverList_val);
516 PrintCellServDB(struct rx_connection *aconn)
520 for ( index = 0 ; PrintCellServDBEntry(aconn, index); index++ );
524 CommandProc(struct cmd_syndesc *as, void *arock)
526 struct rx_connection *conn;
527 register char *hostName;
528 register struct hostent *thp;
530 struct rx_securityClass *secobj;
534 hostName = as->parms[0].items->data;
535 if (as->parms[1].items)
536 port = atoi(as->parms[1].items->data);
539 thp = hostutil_GetHostByName(hostName);
541 printf("cmdebug: can't resolve address for host %s.\n", hostName);
544 memcpy(&addr, thp->h_addr, sizeof(afs_int32));
545 secobj = rxnull_NewServerSecurityObject();
546 conn = rx_NewConnection(addr, htons(port), 1, secobj, 0);
548 printf("cmdebug: failed to create connection for host %s\n",
553 if (as->parms[6].items) {
555 PrintInterfaces(conn);
558 if (as->parms[7].items) {
560 PrintCacheConfig(conn);
564 if (as->parms[8].items) {
566 PrintCellServDB(conn);
570 if (as->parms[5].items)
573 if (as->parms[2].items)
576 else if (as->parms[3].items)
579 else if (as->parms[4].items)
585 if (int32p == 0 || int32p == 1)
586 PrintLocks(conn, int32p);
587 if (int32p >= 0 || int32p <= 4)
588 PrintCacheEntries(conn, int32p);
593 #include "AFS_component_version_number.c"
597 main(int argc, char **argv)
599 register struct cmd_syndesc *ts;
603 * The following signal action for AIX is necessary so that in case of a
604 * crash (i.e. core is generated) we can include the user's data section
605 * in the core dump. Unfortunately, by default, only a partial core is
606 * generated which, in many cases, isn't too useful.
608 struct sigaction nsa;
610 sigemptyset(&nsa.sa_mask);
611 nsa.sa_handler = SIG_DFL;
612 nsa.sa_flags = SA_FULLDUMP;
613 sigaction(SIGSEGV, &nsa, NULL);
617 if (afs_winsockInit() < 0) {
618 printf("%s: Couldn't initialize winsock. Exiting...\n", argv[0]);
625 ts = cmd_CreateSyntax(NULL, CommandProc, NULL, "query afs cache manager");
626 cmd_AddParm(ts, "-servers", CMD_SINGLE, CMD_REQUIRED, "server machine");
627 cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "IP port");
628 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "print all info");
629 cmd_AddParm(ts, "-refcounts", CMD_FLAG, CMD_OPTIONAL,
630 "print only cache entries with positive reference counts");
631 cmd_AddParm(ts, "-callbacks", CMD_FLAG, CMD_OPTIONAL,
632 "print only cache entries with callbacks");
633 cmd_AddParm(ts, "-ctime", CMD_FLAG, CMD_OPTIONAL,
634 "print human readable expiration time");
637 cmd_AddParm(ts, "-addrs", CMD_FLAG, CMD_OPTIONAL,
638 "print only host interfaces");
639 cmd_AddParm(ts, "-cache", CMD_FLAG, CMD_OPTIONAL,
640 "print only cache configuration");
641 cmd_AddParm(ts, "-cellservdb", CMD_FLAG, CMD_OPTIONAL,
642 "print only cellservdb info");
644 cmd_Dispatch(argc, argv);