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>
31 #include <afs/afscbint.h>
35 #include <afs/afs_args.h>
37 extern struct hostent *hostutil_GetHostByName();
39 static PrintCacheConfig(aconn)
40 struct rx_connection *aconn;
43 afs_uint32 srv_ver, conflen;
46 c.cacheConfig_len = 0;
47 c.cacheConfig_val = NULL;
48 code = RXAFSCB_GetCacheConfig(aconn, 1, &srv_ver, &conflen, &c);
50 printf("cmdebug: error checking cache config: %s\n",
55 if (srv_ver == AFS_CLIENT_RETRIEVAL_FIRST_EDITION) {
56 struct cm_initparams_v1 *c1;
58 if (c.cacheConfig_len != sizeof(*c1) / sizeof(afs_uint32)) {
59 printf("cmdebug: configuration data size mismatch (%d != %d)\n",
60 c.cacheConfig_len, sizeof(*c1) / sizeof(afs_uint32));
64 c1 = (struct cm_initparams_v1 *) c.cacheConfig_val;
65 printf("Chunk files: %d\n", c1->nChunkFiles);
66 printf("Stat caches: %d\n", c1->nStatCaches);
67 printf("Data caches: %d\n", c1->nDataCaches);
68 printf("Volume caches: %d\n", c1->nVolumeCaches);
69 printf("Chunk size: %d", c1->otherChunkSize);
70 if (c1->firstChunkSize != c1->otherChunkSize)
71 printf(" (first: %d)", c1->firstChunkSize);
73 printf("Cache size: %d kB\n", c1->cacheSize);
74 printf("Set time: %s\n", c1->setTime ? "yes" : "no");
75 printf("Cache type: %s\n", c1->memCache ? "memory" : "disk");
77 printf("cmdebug: unsupported server version %d\n", srv_ver);
81 static PrintInterfaces(aconn)
82 struct rx_connection *aconn;
84 struct interfaceAddr addr;
87 code = RXAFSCB_WhoAreYou(aconn, &addr);
89 printf("cmdebug: error checking interfaces: %s\n", error_message(code));
93 printf("Host interfaces:\n");
94 for (i=0; i<addr.numberOfInterfaces; i++) {
95 printf("%s", inet_ntoa(&addr.addr_in[i]));
96 if (addr.subnetmask[i])
97 printf(", netmask %s", inet_ntoa(&addr.subnetmask[i]));
99 printf(", MTU %d", addr.mtu[i]);
106 static IsLocked(alock)
107 register struct AFSDBLockDesc *alock; {
108 if (alock->waitStates || alock->exclLocked
109 || alock->numWaiting || alock->readersReading)
114 static PrintLock(alock)
115 register struct AFSDBLockDesc *alock; {
117 if (alock->waitStates) {
118 if (alock->waitStates & READ_LOCK)
119 printf("reader_waiting");
120 if (alock->waitStates & WRITE_LOCK)
121 printf("writer_waiting");
122 if (alock->waitStates & SHARED_LOCK)
123 printf("upgrade_waiting");
126 printf("none_waiting");
127 if (alock->exclLocked) {
128 if (alock->exclLocked & WRITE_LOCK)
129 printf(", write_locked");
130 if (alock->exclLocked & SHARED_LOCK)
131 printf(", upgrade_locked");
132 printf("(pid:%d at:%d)", alock->pid_writer, alock->src_indicator);
134 if (alock->readersReading)
135 printf(", %d read_locks(pid:%d)", alock->readersReading,alock->pid_last_reader);
136 if (alock->numWaiting) printf(", %d waiters", alock->numWaiting);
141 static PrintLocks(aconn, aint32)
143 register struct rx_connection *aconn; {
145 struct AFSDBLock lock;
148 for(i=0;i<1000;i++) {
149 code = RXAFSCB_GetLock(aconn, i, &lock);
151 if (code == 1) break;
152 /* otherwise we have an unrecognized error */
153 printf("cmdebug: error checking locks: %s\n", error_message(code));
156 /* here we have the lock information, so display it, perhaps */
157 if (aint32 || IsLocked(&lock.lock)) {
158 printf("Lock %s status: ", lock.name);
159 PrintLock(&lock.lock);
166 static PrintCacheEntries(aconn, aint32)
168 register struct rx_connection *aconn; {
170 register afs_int32 code;
171 struct AFSDBCacheEntry centry;
173 for(i=0;i<10000;i++) {
174 code = RXAFSCB_GetCE(aconn, i, ¢ry);
176 if (code == 1) break;
177 printf("cmdebug: failed to get cache entry %d (%s)\n", i,
178 error_message(code));
182 if (centry.addr == 0) {
184 printf("Proc %4d sleeping at %08x, pri %3d\n",
185 centry.netFid.Vnode, centry.netFid.Volume, centry.netFid.Unique-25);
189 if (!aint32 && !IsLocked(¢ry.lock)) continue;
191 /* otherwise print this entry */
192 printf("** Cache entry @ 0x%08x for %d.%d.%d.%d\n", centry.addr, centry.cell,
193 centry.netFid.Volume, centry.netFid.Vnode, centry.netFid.Unique);
194 if (IsLocked(¢ry.lock)) {
196 PrintLock(¢ry.lock);
199 printf(" %d bytes\tDV %d refcnt %d\n", centry.Length, centry.DataVersion, centry.refCount);
200 printf(" callback %08x\texpires %u\n", centry.callback, centry.cbExpires);
201 printf(" %d opens\t%d writers\n", centry.opens, centry.writers);
203 /* now display states */
205 if (centry.mvstat == 0) printf("normal file");
206 else if (centry.mvstat == 1) printf("mount point");
207 else if (centry.mvstat == 2) printf("volume root");
208 else printf("bogus mvstat %d", centry.mvstat);
209 printf("\n states (0x%x)", centry.states);
210 if (centry.states & 1) printf(", stat'd");
211 if (centry.states & 2) printf(", backup");
212 if (centry.states & 4) printf(", read-only");
213 if (centry.states & 8) printf(", mt pt valid");
214 if (centry.states & 0x10) printf(", pending core");
215 if (centry.states & 0x40) printf(", wait-for-store");
216 if (centry.states & 0x80) printf(", mapped");
222 static CommandProc(as)
223 struct cmd_syndesc *as; {
224 struct rx_connection *conn;
225 register char *hostName;
226 register struct hostent *thp;
228 struct rx_securityClass *secobj;
232 hostName = as->parms[0].items->data;
233 if (as->parms[1].items)
234 port = atoi(as->parms[1].items->data);
237 thp = hostutil_GetHostByName(hostName);
239 printf("cmdebug: can't resolve address for host %s.\n", hostName);
242 memcpy(&addr, thp->h_addr, sizeof(afs_int32));
243 secobj = rxnull_NewServerSecurityObject();
244 conn = rx_NewConnection(addr, htons(port), 1, secobj, 0);
246 printf("cmdebug: failed to create connection for host %s\n", hostName);
249 if (as->parms[3].items) {
251 PrintInterfaces(conn);
254 if (as->parms[4].items) {
256 PrintCacheConfig(conn);
259 if (as->parms[2].items) int32p = 1;
261 PrintLocks(conn, int32p);
262 PrintCacheEntries(conn, int32p);
266 #include "AFS_component_version_number.c"
271 register struct cmd_syndesc *ts;
275 * The following signal action for AIX is necessary so that in case of a
276 * crash (i.e. core is generated) we can include the user's data section
277 * in the core dump. Unfortunately, by default, only a partial core is
278 * generated which, in many cases, isn't too useful.
280 struct sigaction nsa;
282 sigemptyset(&nsa.sa_mask);
283 nsa.sa_handler = SIG_DFL;
284 nsa.sa_flags = SA_FULLDUMP;
285 sigaction(SIGSEGV, &nsa, NULL);
289 ts = cmd_CreateSyntax(NULL, CommandProc, 0, "probe unik server");
290 cmd_AddParm(ts, "-servers", CMD_SINGLE, CMD_REQUIRED, "server machine");
291 cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "IP port");
292 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "print all info");
293 cmd_AddParm(ts, "-addrs", CMD_FLAG, CMD_OPTIONAL, "print only host interfaces");
294 cmd_AddParm(ts, "-cache", CMD_FLAG, CMD_OPTIONAL, "print only cache configuration");
296 cmd_Dispatch(argc, argv);