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>
16 #include <sys/types.h>
17 #include <netinet/in.h>
18 #include <sys/socket.h>
24 #include <afs/afscbint.h>
29 extern struct rx_securityClass *rxnull_NewServerSecurityObject();
30 extern struct hostent *hostutil_GetHostByName();
32 static IsLocked(alock)
33 register struct AFSDBLockDesc *alock; {
34 if (alock->waitStates || alock->exclLocked
35 || alock->numWaiting || alock->readersReading)
40 static PrintLock(alock)
41 register struct AFSDBLockDesc *alock; {
43 if (alock->waitStates) {
44 if (alock->waitStates & READ_LOCK)
45 printf("reader_waiting");
46 if (alock->waitStates & WRITE_LOCK)
47 printf("writer_waiting");
48 if (alock->waitStates & SHARED_LOCK)
49 printf("upgrade_waiting");
52 printf("none_waiting");
53 if (alock->exclLocked) {
54 if (alock->exclLocked & WRITE_LOCK)
55 printf(", write_locked");
56 if (alock->exclLocked & SHARED_LOCK)
57 printf(", upgrade_locked");
58 printf("(pid:%d at:%d)", alock->pid_writer, alock->src_indicator);
60 if (alock->readersReading)
61 printf(", %d read_locks(pid:%d)", alock->readersReading,alock->pid_last_reader);
62 if (alock->numWaiting) printf(", %d waiters", alock->numWaiting);
67 static PrintLocks(aconn, aint32)
69 register struct rx_connection *aconn; {
71 struct AFSDBLock lock;
75 code = RXAFSCB_GetLock(aconn, i, &lock);
78 /* otherwise we have an unrecognized error */
79 printf("cmdebug: error checking locks: %s\n", error_message(code));
82 /* here we have the lock information, so display it, perhaps */
83 if (aint32 || IsLocked(&lock.lock)) {
84 printf("Lock %s status: ", lock.name);
85 PrintLock(&lock.lock);
92 static PrintCacheEntries(aconn, aint32)
94 register struct rx_connection *aconn; {
96 register afs_int32 code;
97 struct AFSDBCacheEntry centry;
99 for(i=0;i<10000;i++) {
100 code = RXAFSCB_GetCE(aconn, i, ¢ry);
102 if (code == 1) break;
103 printf("cmdebug: failed to get cache entry %d (%s)\n", i,
104 error_message(code));
108 if (centry.addr == 0) {
110 printf("Proc %4d sleeping at %08x, pri %3d\n",
111 centry.netFid.Vnode, centry.netFid.Volume, centry.netFid.Unique-25);
115 if (!aint32 && !IsLocked(¢ry.lock)) continue;
117 /* otherwise print this entry */
118 printf("** Cache entry @ 0x%08x for %d.%d.%d.%d\n", centry.addr, centry.cell,
119 centry.netFid.Volume, centry.netFid.Vnode, centry.netFid.Unique);
120 if (IsLocked(¢ry.lock)) {
122 PrintLock(¢ry.lock);
125 printf(" %d bytes\tDV %d refcnt %d\n", centry.Length, centry.DataVersion, centry.refCount);
126 printf(" callback %08x\texpires %u\n", centry.callback, centry.cbExpires);
127 printf(" %d opens\t%d writers\n", centry.opens, centry.writers);
129 /* now display states */
131 if (centry.mvstat == 0) printf("normal file");
132 else if (centry.mvstat == 1) printf("mount point");
133 else if (centry.mvstat == 2) printf("volume root");
134 else printf("bogus mvstat %d", centry.mvstat);
135 printf("\n states (0x%x)", centry.states);
136 if (centry.states & 1) printf(", stat'd");
137 if (centry.states & 2) printf(", backup");
138 if (centry.states & 4) printf(", read-only");
139 if (centry.states & 8) printf(", mt pt valid");
140 if (centry.states & 0x10) printf(", pending core");
141 if (centry.states & 0x40) printf(", wait-for-store");
142 if (centry.states & 0x80) printf(", mapped");
148 static CommandProc(as)
149 struct cmd_syndesc *as; {
150 struct rx_connection *conn;
151 register char *hostName;
152 register struct hostent *thp;
154 struct rx_securityClass *secobj;
158 hostName = as->parms[0].items->data;
159 if (as->parms[1].items)
160 port = atoi(as->parms[1].items->data);
163 thp = hostutil_GetHostByName(hostName);
165 printf("cmdebug: can't resolve address for host %s.\n", hostName);
168 bcopy(thp->h_addr, &addr, sizeof(afs_int32));
169 secobj = rxnull_NewServerSecurityObject();
170 conn = rx_NewConnection(addr, htons(port), 1, secobj, 0);
172 printf("cmdebug: failed to create connection for host %s\n", hostName);
175 if (as->parms[2].items) int32p = 1;
177 PrintLocks(conn, int32p);
178 PrintCacheEntries(conn, int32p);
182 #include "AFS_component_version_number.c"
187 register struct cmd_syndesc *ts;
191 * The following signal action for AIX is necessary so that in case of a
192 * crash (i.e. core is generated) we can include the user's data section
193 * in the core dump. Unfortunately, by default, only a partial core is
194 * generated which, in many cases, isn't too useful.
196 struct sigaction nsa;
198 sigemptyset(&nsa.sa_mask);
199 nsa.sa_handler = SIG_DFL;
200 nsa.sa_flags = SA_FULLDUMP;
201 sigaction(SIGSEGV, &nsa, NULL);
205 ts = cmd_CreateSyntax((char *) 0, CommandProc, 0, "probe unik server");
206 cmd_AddParm(ts, "-servers", CMD_SINGLE, CMD_REQUIRED, "server machine");
207 cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "IP port");
208 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "print all info");
210 cmd_Dispatch(argc, argv);