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>
17 #include <sys/types.h>
22 #ifdef HAVE_NETINET_IN_H
23 #include <netinet/in.h>
25 #include <sys/socket.h>
39 #include <afs/afscbint.h>
43 #include <afs/afs_args.h>
45 extern struct hostent *hostutil_GetHostByName();
48 PrintCacheConfig(struct rx_connection *aconn)
51 afs_uint32 srv_ver, conflen;
54 c.cacheConfig_len = 0;
55 c.cacheConfig_val = NULL;
56 code = RXAFSCB_GetCacheConfig(aconn, 1, &srv_ver, &conflen, &c);
58 printf("cmdebug: error checking cache config: %s\n",
63 if (srv_ver == AFS_CLIENT_RETRIEVAL_FIRST_EDITION) {
64 struct cm_initparams_v1 *c1;
66 if (c.cacheConfig_len != sizeof(*c1) / sizeof(afs_uint32)) {
67 printf("cmdebug: configuration data size mismatch (%d != %d)\n",
68 c.cacheConfig_len, sizeof(*c1) / sizeof(afs_uint32));
72 c1 = (struct cm_initparams_v1 *)c.cacheConfig_val;
73 printf("Chunk files: %d\n", c1->nChunkFiles);
74 printf("Stat caches: %d\n", c1->nStatCaches);
75 printf("Data caches: %d\n", c1->nDataCaches);
76 printf("Volume caches: %d\n", c1->nVolumeCaches);
77 printf("Chunk size: %d", c1->otherChunkSize);
78 if (c1->firstChunkSize != c1->otherChunkSize)
79 printf(" (first: %d)", c1->firstChunkSize);
81 printf("Cache size: %d kB\n", c1->cacheSize);
82 printf("Set time: %s\n", c1->setTime ? "yes" : "no");
83 printf("Cache type: %s\n", c1->memCache ? "memory" : "disk");
85 printf("cmdebug: unsupported server version %d\n", srv_ver);
89 #ifndef CAPABILITY_BITS
90 #define CAPABILITY_ERRORTRANS (1<<0)
91 #define CAPABILITY_BITS 1
95 PrintInterfaces(struct rx_connection *aconn)
98 struct interfaceAddr addr;
106 caps.Capabilities_val = NULL;
107 caps.Capabilities_len = 0;
109 code = RXAFSCB_TellMeAboutYourself(aconn, &addr, &caps);
110 if (code == RXGEN_OPCODE)
111 code = RXAFSCB_WhoAreYou(aconn, &addr);
113 printf("cmdebug: error checking interfaces: %s\n",
114 error_message(code));
119 UuidToString((UUID *)&addr.uuid, &p);
120 printf("UUID: %s\n",p);
123 afsUUID_to_string(&addr.uuid, uuidstr, sizeof(uuidstr));
124 printf("UUID: %s\n",uuidstr);
127 printf("Host interfaces:\n");
128 for (i = 0; i < addr.numberOfInterfaces; i++) {
129 printf("%s", afs_inet_ntoa(htonl(addr.addr_in[i])));
130 if (addr.subnetmask[i])
131 printf(", netmask %s", afs_inet_ntoa(htonl(addr.subnetmask[i])));
133 printf(", MTU %d", addr.mtu[i]);
137 if (caps.Capabilities_val) {
138 printf("Capabilities:\n");
139 if (caps.Capabilities_val[0] & CAPABILITY_ERRORTRANS) {
140 printf("Error Translation\n");
145 if (caps.Capabilities_val)
146 free(caps.Capabilities_val);
147 caps.Capabilities_val = NULL;
148 caps.Capabilities_len = 0;
154 IsLocked(register struct AFSDBLockDesc *alock)
156 if (alock->waitStates || alock->exclLocked || alock->numWaiting
157 || alock->readersReading)
163 PrintLock(register struct AFSDBLockDesc *alock)
166 if (alock->waitStates) {
167 if (alock->waitStates & READ_LOCK)
168 printf("reader_waiting");
169 if (alock->waitStates & WRITE_LOCK)
170 printf("writer_waiting");
171 if (alock->waitStates & SHARED_LOCK)
172 printf("upgrade_waiting");
174 printf("none_waiting");
175 if (alock->exclLocked) {
176 if (alock->exclLocked & WRITE_LOCK)
177 printf(", write_locked");
178 if (alock->exclLocked & SHARED_LOCK)
179 printf(", upgrade_locked");
180 printf("(pid:%d at:%d)", alock->pid_writer, alock->src_indicator);
182 if (alock->readersReading)
183 printf(", %d read_locks(pid:%d)", alock->readersReading,
184 alock->pid_last_reader);
185 if (alock->numWaiting)
186 printf(", %d waiters", alock->numWaiting);
192 PrintLocks(register struct rx_connection *aconn, int aint32)
195 struct AFSDBLock lock;
198 for (i = 0; i < 1000; i++) {
199 code = RXAFSCB_GetLock(aconn, i, &lock);
203 /* otherwise we have an unrecognized error */
204 printf("cmdebug: error checking locks: %s\n",
205 error_message(code));
208 /* here we have the lock information, so display it, perhaps */
209 if (aint32 || IsLocked(&lock.lock)) {
210 printf("Lock %s status: ", lock.name);
211 PrintLock(&lock.lock);
221 struct cell_cache *next;
225 GetCellName(struct rx_connection *aconn, afs_int32 cellnum)
227 static int no_getcellbynum;
228 static struct cell_cache *cache;
229 struct cell_cache *tcp;
237 for (tcp = cache; tcp; tcp = tcp->next)
238 if (tcp->cellnum == cellnum)
239 return tcp->cellname;
242 sl.serverList_len = 0;
243 sl.serverList_val = NULL;
244 code = RXAFSCB_GetCellByNum(aconn, cellnum, &cellname, &sl);
246 if (code == RXGEN_OPCODE)
251 if (sl.serverList_val)
252 free(sl.serverList_val);
253 tcp = malloc(sizeof(struct cell_cache));
255 tcp->cellnum = cellnum;
256 tcp->cellname = cellname;
263 PrintCacheEntries32(struct rx_connection *aconn, int aint32)
266 register afs_int32 code;
267 struct AFSDBCacheEntry centry;
270 for (i = 0; i < 10000; i++) {
271 code = RXAFSCB_GetCE(aconn, i, ¢ry);
275 printf("cmdebug: failed to get cache entry %d (%s)\n", i,
276 error_message(code));
280 if (centry.addr == 0) {
282 printf("Proc %4d sleeping at %08x, pri %3d\n",
283 centry.netFid.Vnode, centry.netFid.Volume,
284 centry.netFid.Unique - 25);
288 if (aint32 == 0 && !IsLocked(¢ry.lock) ||
289 aint32 == 2 && centry.refCount == 0 ||
290 aint32 == 4 && centry.callback == 0)
293 /* otherwise print this entry */
294 printf("** Cache entry @ 0x%08x for %d.%d.%d.%d", centry.addr,
295 centry.cell, centry.netFid.Volume, centry.netFid.Vnode,
296 centry.netFid.Unique);
298 cellname = GetCellName(aconn, centry.cell);
300 printf(" [%s]\n", cellname);
304 if (IsLocked(¢ry.lock)) {
306 PrintLock(¢ry.lock);
309 printf(" %012d bytes DV %012d refcnt %05d\n", centry.Length,
310 centry.DataVersion, centry.refCount);
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;
362 for (i = 0; i < 10000; i++) {
363 code = RXAFSCB_GetCE64(aconn, i, ¢ry);
367 printf("cmdebug: failed to get cache entry %d (%s)\n", i,
368 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(" %012I64d bytes DV %012d refcnt %05d\n", centry.Length,
403 centry.DataVersion, centry.refCount);
405 printf(" %012d bytes DV %012d refcnt %05d\n", centry.Length,
406 centry.DataVersion, centry.refCount);
408 printf(" callback %08x\texpires %u\n", centry.callback,
410 printf(" %d opens\t%d writers\n", centry.opens, centry.writers);
412 /* now display states */
414 if (centry.mvstat == 0)
415 printf("normal file");
416 else if (centry.mvstat == 1)
417 printf("mount point");
418 else if (centry.mvstat == 2)
419 printf("volume root");
420 else if (centry.mvstat == 3)
422 else if (centry.mvstat == 4)
424 else if (centry.mvstat == 5)
425 printf("microsoft dfs link");
426 else if (centry.mvstat == 6)
427 printf("invalid link");
429 printf("bogus mvstat %d", centry.mvstat);
430 printf("\n states (0x%x)", centry.states);
431 if (centry.states & 1)
433 if (centry.states & 2)
435 if (centry.states & 4)
436 printf(", read-only");
437 if (centry.states & 8)
438 printf(", mt pt valid");
439 if (centry.states & 0x10)
440 printf(", pending core");
441 if (centry.states & 0x40)
442 printf(", wait-for-store");
443 if (centry.states & 0x80)
451 PrintCacheEntries(struct rx_connection *aconn, int aint32)
453 register afs_int32 code;
454 struct AFSDBCacheEntry64 centry64;
456 code = RXAFSCB_GetCE64(aconn, 0, ¢ry64);
457 if (code != RXGEN_OPCODE)
458 return PrintCacheEntries64(aconn, aint32);
460 return PrintCacheEntries32(aconn, aint32);
464 CommandProc(struct cmd_syndesc *as, char *arock)
466 struct rx_connection *conn;
467 register char *hostName;
468 register struct hostent *thp;
470 struct rx_securityClass *secobj;
474 hostName = as->parms[0].items->data;
475 if (as->parms[1].items)
476 port = atoi(as->parms[1].items->data);
479 thp = hostutil_GetHostByName(hostName);
481 printf("cmdebug: can't resolve address for host %s.\n", hostName);
484 memcpy(&addr, thp->h_addr, sizeof(afs_int32));
485 secobj = rxnull_NewServerSecurityObject();
486 conn = rx_NewConnection(addr, htons(port), 1, secobj, 0);
488 printf("cmdebug: failed to create connection for host %s\n",
492 if (as->parms[5].items) {
494 PrintInterfaces(conn);
497 if (as->parms[6].items) {
499 PrintCacheConfig(conn);
502 if (as->parms[2].items)
505 else if (as->parms[3].items)
508 else if (as->parms[4].items)
514 if (int32p == 0 || int32p == 1)
515 PrintLocks(conn, int32p);
516 if (int32p >= 0 || int32p <= 4)
517 PrintCacheEntries(conn, int32p);
522 #include "AFS_component_version_number.c"
526 main(int argc, char **argv)
528 register struct cmd_syndesc *ts;
532 * The following signal action for AIX is necessary so that in case of a
533 * crash (i.e. core is generated) we can include the user's data section
534 * in the core dump. Unfortunately, by default, only a partial core is
535 * generated which, in many cases, isn't too useful.
537 struct sigaction nsa;
539 sigemptyset(&nsa.sa_mask);
540 nsa.sa_handler = SIG_DFL;
541 nsa.sa_flags = SA_FULLDUMP;
542 sigaction(SIGSEGV, &nsa, NULL);
546 if (afs_winsockInit() < 0) {
547 printf("%s: Couldn't initialize winsock. Exiting...\n", argv[0]);
554 ts = cmd_CreateSyntax(NULL, CommandProc, 0, "probe unik server");
555 cmd_AddParm(ts, "-servers", CMD_SINGLE, CMD_REQUIRED, "server machine");
556 cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "IP port");
557 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "print all info");
558 cmd_AddParm(ts, "-refcounts", CMD_FLAG, CMD_OPTIONAL,
559 "print only cache entries with positive reference counts");
560 cmd_AddParm(ts, "-callbacks", CMD_FLAG, CMD_OPTIONAL,
561 "print only cache entries with callbacks");
562 cmd_AddParm(ts, "-addrs", CMD_FLAG, CMD_OPTIONAL,
563 "print only host interfaces");
564 cmd_AddParm(ts, "-cache", CMD_FLAG, CMD_OPTIONAL,
565 "print only cache configuration");
567 cmd_Dispatch(argc, argv);