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>
26 #include <sys/param.h>
27 #include <netinet/in.h>
39 #include <afs/afsutil.h>
41 #define UBIK_INTERNALS
45 static_inline int afs_cast_time_t(time_t d) { return (int) d; }
48 PortNumber(char *aport)
54 while ((tc = *aport++)) {
55 if (tc < '0' || tc > '9')
56 return -1; /* bad port number */
58 total += tc - (int)'0';
69 ts = getservbyname(aname, NULL);
72 return ntohs(ts->s_port); /* returns it in host byte order */
75 if (strncmp(aname, "vlserver", len) == 0) {
77 } else if (strncmp(aname, "ptserver", len) == 0) {
79 } else if (strncmp(aname, "kaserver", len) == 0) {
81 } else if (strncmp(aname, "buserver", len) == 0) {
88 CommandProc(struct cmd_syndesc *as, void *arock)
90 char *hostName, *portName, *times;
95 time_t now, then, diff, newtime;
97 struct rx_connection *tconn;
98 struct rx_securityClass *sc;
99 struct ubik_debug udebug;
100 struct ubik_sdebug usdebug;
101 int oldServer = 0; /* are we talking to a pre 3.5 server? */
102 afs_int32 isClone = 0;
105 int32p = (as->parms[2].items ? 1 : 0);
107 if (as->parms[0].items)
108 hostName = as->parms[0].items->data;
112 if (as->parms[1].items)
113 portName = as->parms[1].items->data;
119 th = hostutil_GetHostByName(hostName);
121 printf("udebug: host %s not found in host table\n", hostName);
124 memcpy(&hostAddr, th->h_addr, sizeof(afs_int32));
126 hostAddr = htonl(0x7f000001); /* IP localhost */
129 port = htons(3000); /* default */
131 port = PortNumber(portName);
133 port = PortName(portName);
135 printf("udebug: can't resolve port name %s\n", portName);
142 sc = rxnull_NewClientSecurityObject();
143 tconn = rx_NewConnection(hostAddr, port, VOTE_SERVICE_ID, sc, 0);
145 /* now do the main call */
146 code = VOTE_XDebug(tconn, &udebug, &isClone);
148 code = VOTE_Debug(tconn, &udebug);
149 if (code == RXGEN_OPCODE) {
150 oldServer = 1; /* talking to a pre 3.5 server */
151 memset(&udebug, 0, sizeof(udebug));
152 code = VOTE_DebugOld(tconn, (ubik_debug_old *)&udebug);
156 printf("return code %d from VOTE_Debug\n", code);
162 /* now print the main info */
163 times = ctime(&then);
166 printf("Host's addresses are: ");
167 for (j = 0; udebug.interfaceAddr[j] && (j < UBIK_MAX_INTERFACE_ADDR);
169 printf("%s ", afs_inet_ntoa_r(htonl(udebug.interfaceAddr[j]), hoststr));
172 printf("Host's %s time is %s\n", afs_inet_ntoa_r(hostAddr, hoststr), times);
176 diff = now - udebug.now;
177 printf("Local time is %s (time differential %d secs)\n", times, afs_cast_time_t(diff));
178 if (abs((int)diff) >= MAXSKEW)
179 printf("****clock may be bad\n");
181 /* UBIK skips the voting if 1 server - so we fudge it here */
182 if (udebug.amSyncSite && (udebug.nServers == 1)) {
183 udebug.lastYesHost = hostAddr;
184 udebug.lastYesTime = udebug.now;
185 udebug.lastYesState = 1;
186 udebug.lastYesClaim = udebug.now;
187 udebug.syncVersion.epoch = udebug.localVersion.epoch;
188 udebug.syncVersion.counter = udebug.localVersion.counter;
191 /* XDR converts addresses for us, so all addresses are in HBO */
192 if (udebug.lastYesHost == 0xffffffff) {
193 printf("Last yes vote not cast yet \n");
195 diff = udebug.now - udebug.lastYesTime;
196 printf("Last yes vote for %s was %d secs ago (%ssync site); \n",
197 afs_inet_ntoa_r(htonl(udebug.lastYesHost), hoststr),
198 afs_cast_time_t(diff),
199 ((udebug.lastYesState) ? "" : "not "));
201 diff = udebug.now - udebug.lastYesClaim;
202 newtime = now - diff;
203 times = ctime(&newtime);
205 printf("Last vote started %d secs ago (at %s)\n",
206 afs_cast_time_t(diff), times);
209 printf("Local db version is %d.%d\n", udebug.localVersion.epoch,
210 udebug.localVersion.counter);
212 if (udebug.amSyncSite) {
213 if (udebug.syncSiteUntil == 0x7fffffff) {
214 printf("I am sync site forever (%d server%s)\n", udebug.nServers,
215 ((udebug.nServers > 1) ? "s" : ""));
217 diff = udebug.syncSiteUntil - udebug.now;
218 newtime = now + diff;
219 times = ctime(&newtime);
222 ("I am sync site until %d secs from now (at %s) (%d server%s)\n",
223 afs_cast_time_t(diff), times, udebug.nServers,
224 ((udebug.nServers > 1) ? "s" : ""));
226 printf("Recovery state %x\n", udebug.recoveryState);
229 printf("I am a clone and never can become sync site\n");
231 printf("I am not sync site\n");
232 diff = udebug.now - udebug.lowestTime;
233 printf("Lowest host %s was set %d secs ago\n",
234 afs_inet_ntoa_r(htonl(udebug.lowestHost), hoststr),
235 afs_cast_time_t(diff));
237 diff = udebug.now - udebug.syncTime;
238 printf("Sync host %s was set %d secs ago\n",
239 afs_inet_ntoa_r(htonl(udebug.syncHost), hoststr),
240 afs_cast_time_t(diff));
243 if (udebug.activeWrite) {
244 printf("I am currently managing write trans %d.%d\n",
245 udebug.epochTime, udebug.tidCounter);
247 printf("The last trans I handled was %d.%d\n",
248 udebug.epochTime, udebug.tidCounter);
251 printf("Sync site's db version is %d.%d\n", udebug.syncVersion.epoch,
252 udebug.syncVersion.counter);
253 printf("%d locked pages, %d of them for write\n", udebug.lockedPages,
254 udebug.writeLockedPages);
256 if (udebug.anyReadLocks)
257 printf("There are read locks held\n");
258 if (udebug.anyWriteLocks)
259 printf("There are write locks held\n");
261 if (udebug.currentTrans) {
262 if (udebug.writeTrans)
263 printf("There is an active write transaction\n");
265 printf("There is at least one active read transaction\n");
266 printf("Transaction tid is %d.%d\n", udebug.syncTid.epoch,
267 udebug.syncTid.counter);
269 if (udebug.epochTime) {
270 diff = udebug.now - udebug.epochTime;
271 newtime = now - diff;
272 times = ctime(&newtime);
275 ("Last time a new db version was labelled was:\n\t %d secs ago (at %s)\n",
276 afs_cast_time_t(diff), times);
279 if (int32p || udebug.amSyncSite) {
280 /* now do the subcalls */
283 code = VOTE_XSDebug(tconn, i, &usdebug, &isClone);
285 if (oldServer) { /* pre 3.5 server */
286 memset(&usdebug, 0, sizeof(usdebug));
287 code = VOTE_SDebugOld(tconn, i, (ubik_sdebug_old *)&usdebug);
289 code = VOTE_SDebug(tconn, i, &usdebug);
294 printf("error code %d from VOTE_SDebug\n", code);
297 /* otherwise print the structure */
298 printf("\nServer (%s", afs_inet_ntoa_r(htonl(usdebug.addr), hoststr));
300 ((usdebug.altAddr[j]) && (j < UBIK_MAX_INTERFACE_ADDR - 1));
302 printf(" %s", afs_inet_ntoa_r(htonl(usdebug.altAddr[j]), hoststr));
303 printf("): (db %d.%d)", usdebug.remoteVersion.epoch,
304 usdebug.remoteVersion.counter);
306 printf(" is only a clone!");
309 if (usdebug.lastVoteTime == 0) {
310 printf(" last vote never rcvd \n");
312 diff = udebug.now - usdebug.lastVoteTime;
313 newtime = now - diff;
314 times = ctime(&newtime);
316 printf(" last vote rcvd %d secs ago (at %s),\n",
317 afs_cast_time_t(diff),
321 if (usdebug.lastBeaconSent == 0) {
322 printf(" last beacon never sent \n");
324 diff = udebug.now - usdebug.lastBeaconSent;
325 newtime = now - diff;
326 times = ctime(&newtime);
329 (" last beacon sent %d secs ago (at %s), last vote was %s\n",
330 afs_cast_time_t(diff), times, ((usdebug.lastVote) ? "yes" : "no"));
333 printf(" dbcurrent=%d, up=%d beaconSince=%d\n",
334 usdebug.currentDB, usdebug.up, usdebug.beaconSinceDown);
340 #include "AFS_component_version_number.c"
343 main(int argc, char **argv)
345 struct cmd_syndesc *ts;
349 * The following signal action for AIX is necessary so that in case of a
350 * crash (i.e. core is generated) we can include the user's data section
351 * in the core dump. Unfortunately, by default, only a partial core is
352 * generated which, in many cases, isn't too useful.
354 struct sigaction nsa;
356 sigemptyset(&nsa.sa_mask);
357 nsa.sa_handler = SIG_DFL;
358 nsa.sa_flags = SA_FULLDUMP;
359 sigaction(SIGSEGV, &nsa, NULL);
361 ts = cmd_CreateSyntax(NULL, CommandProc, NULL, "probe ubik server");
362 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "server machine");
363 cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "IP port");
364 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "print all info");
366 cmd_Dispatch(argc, argv);