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
49 PortNumber(register char *aport)
52 register afs_int32 total;
55 while ((tc = *aport++)) {
56 if (tc < '0' || tc > '9')
57 return -1; /* bad port number */
59 total += tc - (int)'0';
70 ts = getservbyname(aname, NULL);
73 return ntohs(ts->s_port); /* returns it in host byte order */
76 if (strncmp(aname, "vlserver", len) == 0) {
78 } else if (strncmp(aname, "ptserver", len) == 0) {
80 } else if (strncmp(aname, "kaserver", len) == 0) {
82 } else if (strncmp(aname, "buserver", len) == 0) {
89 CommandProc(struct cmd_syndesc *as, char *arock)
91 char *hostName, *portName, *times;
93 struct in_addr inhostAddr;
94 register afs_int32 i, j, code;
97 afs_int32 now, diff, newtime;
99 struct rx_connection *tconn;
100 struct rx_securityClass *sc;
101 struct ubik_debug udebug;
102 struct ubik_sdebug usdebug;
103 int oldServer = 0; /* are we talking to a pre 3.5 server? */
104 afs_int32 isClone = 0;
106 int32p = (as->parms[2].items ? 1 : 0);
108 if (as->parms[0].items)
109 hostName = as->parms[0].items->data;
113 if (as->parms[1].items)
114 portName = as->parms[1].items->data;
120 th = hostutil_GetHostByName(hostName);
122 printf("udebug: host %s not found in host table\n", hostName);
125 memcpy(&hostAddr, th->h_addr, sizeof(afs_int32));
127 hostAddr = htonl(0x7f000001); /* IP localhost */
130 port = htons(3000); /* default */
132 port = PortNumber(portName);
134 port = PortName(portName);
136 printf("udebug: can't resolve port name %s\n", portName);
143 sc = rxnull_NewClientSecurityObject();
144 tconn = rx_NewConnection(hostAddr, port, VOTE_SERVICE_ID, sc, 0);
146 /* now do the main call */
147 code = VOTE_XDebug(tconn, &udebug, &isClone);
149 code = VOTE_Debug(tconn, &udebug);
150 if (code == RXGEN_OPCODE) {
151 oldServer = 1; /* talking to a pre 3.5 server */
152 memset(&udebug, 0, sizeof(udebug));
153 code = VOTE_DebugOld(tconn, &udebug);
157 printf("return code %d from VOTE_Debug\n", code);
162 /* now print the main info */
163 times = ctime((time_t *) & udebug.now);
165 inhostAddr.s_addr = hostAddr;
167 printf("Host's addresses are: ");
168 for (j = 0; udebug.interfaceAddr[j] && (j < UBIK_MAX_INTERFACE_ADDR);
170 printf("%s ", afs_inet_ntoa(htonl(udebug.interfaceAddr[j])));
173 printf("Host's %s time is %s\n", inet_ntoa(inhostAddr), times);
177 diff = now - udebug.now;
178 printf("Local time is %s (time differential %d secs)\n", times, diff);
179 if (abs(diff) >= MAXSKEW)
180 printf("****clock may be bad\n");
182 /* UBIK skips the voting if 1 server - so we fudge it here */
183 if (udebug.amSyncSite && (udebug.nServers == 1)) {
184 udebug.lastYesHost = hostAddr;
185 udebug.lastYesTime = udebug.now;
186 udebug.lastYesState = 1;
187 udebug.lastYesClaim = udebug.now;
188 udebug.syncVersion.epoch = udebug.localVersion.epoch;
189 udebug.syncVersion.counter = udebug.localVersion.counter;
192 /* sockaddr is always in net-order */
193 if (udebug.lastYesHost == 0xffffffff) {
194 printf("Last yes vote not cast yet \n");
196 inhostAddr.s_addr = htonl(udebug.lastYesHost);
197 diff = udebug.now - udebug.lastYesTime;
198 printf("Last yes vote for %s was %d secs ago (%ssync site); \n",
199 inet_ntoa(inhostAddr), diff,
200 ((udebug.lastYesState) ? "" : "not "));
202 diff = udebug.now - udebug.lastYesClaim;
203 newtime = now - diff;
204 times = ctime(&newtime);
206 printf("Last vote started %d secs ago (at %s)\n", 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 diff, times, udebug.nServers,
224 ((udebug.nServers > 1) ? "s" : ""));
226 printf("Recovery state %x\n", udebug.recoveryState);
227 if (udebug.activeWrite) {
228 printf("I am currently managing write trans %d.%d\n",
229 udebug.epochTime, udebug.tidCounter);
233 printf("I am a clone and never can become sync site\n");
235 printf("I am not sync site\n");
236 inhostAddr.s_addr = htonl(udebug.lowestHost);
237 diff = udebug.now - udebug.lowestTime;
238 printf("Lowest host %s was set %d secs ago\n", inet_ntoa(inhostAddr),
241 inhostAddr.s_addr = htonl(udebug.syncHost);
242 diff = udebug.now - udebug.syncTime;
243 printf("Sync host %s was set %d secs ago\n", inet_ntoa(inhostAddr),
247 printf("Sync site's db version is %d.%d\n", udebug.syncVersion.epoch,
248 udebug.syncVersion.counter);
249 printf("%d locked pages, %d of them for write\n", udebug.lockedPages,
250 udebug.writeLockedPages);
252 if (udebug.anyReadLocks)
253 printf("There are read locks held\n");
254 if (udebug.anyWriteLocks)
255 printf("There are write locks held\n");
257 if (udebug.currentTrans) {
258 if (udebug.writeTrans)
259 printf("There is an active write transaction\n");
261 printf("There is at least one active read transaction\n");
262 printf("Transaction tid is %d.%d\n", udebug.syncTid.epoch,
263 udebug.syncTid.counter);
265 if (udebug.epochTime) {
266 diff = udebug.now - udebug.epochTime;
267 newtime = now - diff;
268 times = ctime(&newtime);
271 ("Last time a new db version was labelled was:\n\t %d secs ago (at %s)\n",
275 if (int32p || udebug.amSyncSite) {
276 /* now do the subcalls */
279 code = VOTE_XSDebug(tconn, i, &usdebug, &isClone);
281 if (oldServer) { /* pre 3.5 server */
282 memset(&usdebug, 0, sizeof(usdebug));
283 code = VOTE_SDebugOld(tconn, i, &usdebug);
285 code = VOTE_SDebug(tconn, i, &usdebug);
290 printf("error code %d from VOTE_SDebug\n", code);
293 inhostAddr.s_addr = htonl(usdebug.addr);
294 /* otherwise print the structure */
295 printf("\nServer (%s", afs_inet_ntoa(htonl(usdebug.addr)));
297 ((usdebug.altAddr[j]) && (j < UBIK_MAX_INTERFACE_ADDR - 1));
299 printf(" %s", afs_inet_ntoa(htonl(usdebug.altAddr[j])));
300 printf("): (db %d.%d)", usdebug.remoteVersion.epoch,
301 usdebug.remoteVersion.counter);
303 printf(" is only a clone!");
306 if (usdebug.lastVoteTime == 0) {
307 printf(" last vote never rcvd \n");
309 diff = udebug.now - usdebug.lastVoteTime;
310 newtime = now - diff;
311 times = ctime(&newtime);
313 printf(" last vote rcvd %d secs ago (at %s),\n", diff,
317 if (usdebug.lastBeaconSent == 0) {
318 printf(" last beacon never sent \n");
320 diff = udebug.now - usdebug.lastBeaconSent;
321 newtime = now - diff;
322 times = ctime(&newtime);
325 (" last beacon sent %d secs ago (at %s), last vote was %s\n",
326 diff, times, ((usdebug.lastVote) ? "yes" : "no"));
329 printf(" dbcurrent=%d, up=%d beaconSince=%d\n",
330 usdebug.currentDB, usdebug.up, usdebug.beaconSinceDown);
336 #include "AFS_component_version_number.c"
339 main(int argc, char **argv)
341 struct cmd_syndesc *ts;
345 * The following signal action for AIX is necessary so that in case of a
346 * crash (i.e. core is generated) we can include the user's data section
347 * in the core dump. Unfortunately, by default, only a partial core is
348 * generated which, in many cases, isn't too useful.
350 struct sigaction nsa;
352 sigemptyset(&nsa.sa_mask);
353 nsa.sa_handler = SIG_DFL;
354 nsa.sa_flags = SA_FULLDUMP;
355 sigaction(SIGSEGV, &nsa, NULL);
357 ts = cmd_CreateSyntax(NULL, CommandProc, 0, "probe ubik server");
358 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "server machine");
359 cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "IP port");
360 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "print all info");
362 cmd_Dispatch(argc, argv);