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>
29 #include <sys/param.h>
30 #include <netinet/in.h>
44 #define UBIK_INTERNALS
48 extern struct hostent *hostutil_GetHostByName();
51 PortNumber(register char *aport)
54 register afs_int32 total;
57 while ((tc = *aport++)) {
58 if (tc < '0' || tc > '9')
59 return -1; /* bad port number */
61 total += tc - (int)'0';
72 ts = getservbyname(aname, NULL);
75 return ntohs(ts->s_port); /* returns it in host byte order */
78 if (strncmp(aname, "vlserver", len) == 0) {
80 } else if (strncmp(aname, "ptserver", len) == 0) {
82 } else if (strncmp(aname, "kaserver", len) == 0) {
84 } else if (strncmp(aname, "buserver", len) == 0) {
91 CommandProc(struct cmd_syndesc *as, char *arock)
93 char *hostName, *portName, *times;
95 struct in_addr inhostAddr;
96 register afs_int32 i, j, code;
99 afs_int32 now, diff, newtime;
101 struct rx_connection *tconn;
102 struct rx_securityClass *sc;
103 struct ubik_debug udebug;
104 struct ubik_sdebug usdebug;
105 int oldServer = 0; /* are we talking to a pre 3.5 server? */
106 afs_int32 isClone = 0;
108 int32p = (as->parms[2].items ? 1 : 0);
110 if (as->parms[0].items)
111 hostName = as->parms[0].items->data;
115 if (as->parms[1].items)
116 portName = as->parms[1].items->data;
122 th = hostutil_GetHostByName(hostName);
124 printf("udebug: host %s not found in host table\n", hostName);
127 memcpy(&hostAddr, th->h_addr, sizeof(afs_int32));
129 hostAddr = htonl(0x7f000001); /* IP localhost */
132 port = htons(3000); /* default */
134 port = PortNumber(portName);
136 port = PortName(portName);
138 printf("udebug: can't resolve port name %s\n", portName);
145 sc = rxnull_NewClientSecurityObject();
146 tconn = rx_NewConnection(hostAddr, port, VOTE_SERVICE_ID, sc, 0);
148 /* now do the main call */
149 code = VOTE_XDebug(tconn, &udebug, &isClone);
151 code = VOTE_Debug(tconn, &udebug);
152 if (code == RXGEN_OPCODE) {
153 oldServer = 1; /* talking to a pre 3.5 server */
154 memset(&udebug, 0, sizeof(udebug));
155 code = VOTE_DebugOld(tconn, &udebug);
159 printf("return code %d from VOTE_Debug\n", code);
164 /* now print the main info */
165 times = ctime((time_t *) & udebug.now);
167 inhostAddr.s_addr = hostAddr;
169 printf("Host's addresses are: ");
170 for (j = 0; udebug.interfaceAddr[j] && (j < UBIK_MAX_INTERFACE_ADDR);
172 printf("%s ", afs_inet_ntoa(htonl(udebug.interfaceAddr[j])));
175 printf("Host's %s time is %s\n", inet_ntoa(inhostAddr), times);
179 diff = now - udebug.now;
180 printf("Local time is %s (time differential %d secs)\n", times, diff);
181 if (abs(diff) >= MAXSKEW)
182 printf("****clock may be bad\n");
184 /* UBIK skips the voting if 1 server - so we fudge it here */
185 if (udebug.amSyncSite && (udebug.nServers == 1)) {
186 udebug.lastYesHost = hostAddr;
187 udebug.lastYesTime = udebug.now;
188 udebug.lastYesState = 1;
189 udebug.lastYesClaim = udebug.now;
190 udebug.syncVersion.epoch = udebug.localVersion.epoch;
191 udebug.syncVersion.counter = udebug.localVersion.counter;
194 /* sockaddr is always in net-order */
195 if (udebug.lastYesHost == 0xffffffff) {
196 printf("Last yes vote not cast yet \n");
198 inhostAddr.s_addr = htonl(udebug.lastYesHost);
199 diff = udebug.now - udebug.lastYesTime;
200 printf("Last yes vote for %s was %d secs ago (%ssync site); \n",
201 inet_ntoa(inhostAddr), diff,
202 ((udebug.lastYesState) ? "" : "not "));
204 diff = udebug.now - udebug.lastYesClaim;
205 newtime = now - diff;
206 times = ctime(&newtime);
208 printf("Last vote started %d secs ago (at %s)\n", diff, times);
211 printf("Local db version is %d.%d\n", udebug.localVersion.epoch,
212 udebug.localVersion.counter);
214 if (udebug.amSyncSite) {
215 if (udebug.syncSiteUntil == 0x7fffffff) {
216 printf("I am sync site forever (%d server%s)\n", udebug.nServers,
217 ((udebug.nServers > 1) ? "s" : ""));
219 diff = udebug.syncSiteUntil - udebug.now;
220 newtime = now + diff;
221 times = ctime(&newtime);
224 ("I am sync site until %d secs from now (at %s) (%d server%s)\n",
225 diff, times, udebug.nServers,
226 ((udebug.nServers > 1) ? "s" : ""));
228 printf("Recovery state %x\n", udebug.recoveryState);
229 if (udebug.activeWrite) {
230 printf("I am currently managing write trans %d.%d\n",
231 udebug.epochTime, udebug.tidCounter);
235 printf("I am a clone and never can become sync site\n");
237 printf("I am not sync site\n");
238 inhostAddr.s_addr = htonl(udebug.lowestHost);
239 diff = udebug.now - udebug.lowestTime;
240 printf("Lowest host %s was set %d secs ago\n", inet_ntoa(inhostAddr),
243 inhostAddr.s_addr = htonl(udebug.syncHost);
244 diff = udebug.now - udebug.syncTime;
245 printf("Sync host %s was set %d secs ago\n", inet_ntoa(inhostAddr),
249 printf("Sync site's db version is %d.%d\n", udebug.syncVersion.epoch,
250 udebug.syncVersion.counter);
251 printf("%d locked pages, %d of them for write\n", udebug.lockedPages,
252 udebug.writeLockedPages);
254 if (udebug.anyReadLocks)
255 printf("There are read locks held\n");
256 if (udebug.anyWriteLocks)
257 printf("There are write locks held\n");
259 if (udebug.currentTrans) {
260 if (udebug.writeTrans)
261 printf("There is an active write transaction\n");
263 printf("There is at least one active read transaction\n");
264 printf("Transaction tid is %d.%d\n", udebug.syncTid.epoch,
265 udebug.syncTid.counter);
267 if (udebug.epochTime) {
268 diff = udebug.now - udebug.epochTime;
269 newtime = now - diff;
270 times = ctime(&newtime);
273 ("Last time a new db version was labelled was:\n\t %d secs ago (at %s)\n",
277 if (int32p || udebug.amSyncSite) {
278 /* now do the subcalls */
281 code = VOTE_XSDebug(tconn, i, &usdebug, &isClone);
283 if (oldServer) { /* pre 3.5 server */
284 memset(&usdebug, 0, sizeof(usdebug));
285 code = VOTE_SDebugOld(tconn, i, &usdebug);
287 code = VOTE_SDebug(tconn, i, &usdebug);
292 printf("error code %d from VOTE_SDebug\n", code);
295 inhostAddr.s_addr = htonl(usdebug.addr);
296 /* otherwise print the structure */
297 printf("\nServer (%s", afs_inet_ntoa(htonl(usdebug.addr)));
299 ((usdebug.altAddr[j]) && (j < UBIK_MAX_INTERFACE_ADDR - 1));
301 printf(" %s", afs_inet_ntoa(htonl(usdebug.altAddr[j])));
302 printf("): (db %d.%d)", usdebug.remoteVersion.epoch,
303 usdebug.remoteVersion.counter);
305 printf(" is only a clone!");
308 if (usdebug.lastVoteTime == 0) {
309 printf(" last vote never rcvd \n");
311 diff = udebug.now - usdebug.lastVoteTime;
312 newtime = now - diff;
313 times = ctime(&newtime);
315 printf(" last vote rcvd %d secs ago (at %s),\n", diff,
319 if (usdebug.lastBeaconSent == 0) {
320 printf(" last beacon never sent \n");
322 diff = udebug.now - usdebug.lastBeaconSent;
323 newtime = now - diff;
324 times = ctime(&newtime);
327 (" last beacon sent %d secs ago (at %s), last vote was %s\n",
328 diff, times, ((usdebug.lastVote) ? "yes" : "no"));
331 printf(" dbcurrent=%d, up=%d beaconSince=%d\n",
332 usdebug.currentDB, usdebug.up, usdebug.beaconSinceDown);
338 #include "AFS_component_version_number.c"
341 main(int argc, char **argv)
343 struct cmd_syndesc *ts;
347 * The following signal action for AIX is necessary so that in case of a
348 * crash (i.e. core is generated) we can include the user's data section
349 * in the core dump. Unfortunately, by default, only a partial core is
350 * generated which, in many cases, isn't too useful.
352 struct sigaction nsa;
354 sigemptyset(&nsa.sa_mask);
355 nsa.sa_handler = SIG_DFL;
356 nsa.sa_flags = SA_FULLDUMP;
357 sigaction(SIGSEGV, &nsa, NULL);
359 ts = cmd_CreateSyntax(NULL, CommandProc, 0, "probe ubik server");
360 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "server machine");
361 cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "IP port");
362 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "print all info");
364 cmd_Dispatch(argc, argv);