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>
28 #include <sys/param.h>
29 #include <netinet/in.h>
43 #define UBIK_INTERNALS
47 extern struct hostent *hostutil_GetHostByName();
49 static short PortNumber(register char *aport)
52 register afs_int32 total;
55 while ((tc = *aport++)) {
56 if (tc < '0' || tc > '9') return -1; /* bad port number */
58 total += tc - (int) '0';
63 static short PortName(char *aname)
68 ts = getservbyname(aname, NULL);
71 return ntohs(ts->s_port); /* returns it in host byte order */
74 if (strncmp(aname,"vlserver",len) == 0) {
76 } else if (strncmp(aname,"ptserver",len) == 0) {
78 } else if (strncmp(aname,"kaserver",len) == 0) {
80 } else if (strncmp(aname,"buserver",len) == 0) {
86 static int CommandProc(struct cmd_syndesc *as, char *arock)
88 char *hostName, *portName, *times;
90 struct in_addr inhostAddr;
91 register afs_int32 i, j, code;
94 afs_int32 now, diff, newtime;
96 struct rx_connection *tconn;
97 struct rx_securityClass *sc;
98 struct ubik_debug udebug;
99 struct ubik_sdebug usdebug;
100 int oldServer =0; /* are we talking to a pre 3.5 server? */
101 afs_int32 isClone = 0;
103 int32p = (as->parms[2].items ? 1 : 0);
105 if (as->parms[0].items)
106 hostName = as->parms[0].items->data;
110 if (as->parms[1].items)
111 portName = as->parms[1].items->data;
117 th = hostutil_GetHostByName(hostName);
119 printf("udebug: host %s not found in host table\n", hostName);
122 memcpy(&hostAddr, th->h_addr, sizeof(afs_int32));
124 else hostAddr = htonl(0x7f000001); /* IP localhost */
127 port = htons(3000); /* default */
129 port = PortNumber(portName);
131 port = PortName(portName);
133 printf("udebug: can't resolve port name %s\n", portName);
140 sc = rxnull_NewClientSecurityObject();
141 tconn = rx_NewConnection(hostAddr, port, VOTE_SERVICE_ID, sc, 0);
143 /* now do the main call */
144 code = VOTE_XDebug(tconn, &udebug, &isClone);
145 if (code) code = VOTE_Debug(tconn, &udebug);
146 if ( code == RXGEN_OPCODE )
148 oldServer = 1; /* talking to a pre 3.5 server */
149 memset(&udebug, 0, sizeof(udebug));
150 code = VOTE_DebugOld(tconn, &udebug);
154 printf("return code %d from VOTE_Debug\n", code);
159 /* now print the main info */
160 times = ctime((time_t *)&udebug.now); times[24] = 0;
161 inhostAddr.s_addr = hostAddr;
164 printf("Host's addresses are: ");
165 for ( j=0; udebug.interfaceAddr[j] && ( j<UBIK_MAX_INTERFACE_ADDR );j++)
166 printf("%s ", afs_inet_ntoa(htonl(udebug.interfaceAddr[j])));
169 printf("Host's %s time is %s\n", inet_ntoa(inhostAddr), times);
171 times = ctime(&now); times[24] = 0;
172 diff = now - udebug.now;
173 printf("Local time is %s (time differential %d secs)\n", times, diff);
174 if (abs(diff) >= MAXSKEW)
175 printf("****clock may be bad\n");
177 /* UBIK skips the voting if 1 server - so we fudge it here */
178 if (udebug.amSyncSite && (udebug.nServers == 1)) {
179 udebug.lastYesHost = hostAddr;
180 udebug.lastYesTime = udebug.now;
181 udebug.lastYesState = 1;
182 udebug.lastYesClaim = udebug.now;
183 udebug.syncVersion.epoch = udebug.localVersion.epoch;
184 udebug.syncVersion.counter = udebug.localVersion.counter;
187 /* sockaddr is always in net-order */
188 if (udebug.lastYesHost == 0xffffffff) {
189 printf("Last yes vote not cast yet \n");
191 inhostAddr.s_addr = htonl(udebug.lastYesHost);
192 diff = udebug.now - udebug.lastYesTime;
193 printf("Last yes vote for %s was %d secs ago (%ssync site); \n",
194 inet_ntoa(inhostAddr), diff, ((udebug.lastYesState)?"":"not "));
196 diff = udebug.now - udebug.lastYesClaim;
197 newtime = now - diff;
198 times = ctime(&newtime); times[24] = 0;
199 printf("Last vote started %d secs ago (at %s)\n", diff, times);
202 printf("Local db version is %d.%d\n", udebug.localVersion.epoch, udebug.localVersion.counter);
204 if (udebug.amSyncSite) {
205 if (udebug.syncSiteUntil == 0x7fffffff) {
206 printf("I am sync site forever (%d server%s)\n",
207 udebug.nServers, ((udebug.nServers>1)?"s":""));
209 diff = udebug.syncSiteUntil - udebug.now;
210 newtime = now + diff;
211 times = ctime(&newtime); times[24] = 0;
212 printf("I am sync site until %d secs from now (at %s) (%d server%s)\n",
213 diff, times, udebug.nServers,
214 ((udebug.nServers>1)?"s":""));
216 printf("Recovery state %x\n", udebug.recoveryState);
217 if (udebug.activeWrite) {
218 printf("I am currently managing write trans %d.%d\n",
219 udebug.epochTime, udebug.tidCounter);
223 printf("I am a clone and never can become sync site\n");
225 printf("I am not sync site\n");
226 inhostAddr.s_addr = htonl(udebug.lowestHost);
227 diff = udebug.now - udebug.lowestTime;
228 printf("Lowest host %s was set %d secs ago\n", inet_ntoa(inhostAddr), diff);
230 inhostAddr.s_addr = htonl(udebug.syncHost);
231 diff = udebug.now - udebug.syncTime;
232 printf("Sync host %s was set %d secs ago\n", inet_ntoa(inhostAddr), diff);
235 printf("Sync site's db version is %d.%d\n",
236 udebug.syncVersion.epoch, udebug.syncVersion.counter);
237 printf("%d locked pages, %d of them for write\n",
238 udebug.lockedPages, udebug.writeLockedPages);
240 if (udebug.anyReadLocks) printf("There are read locks held\n");
241 if (udebug.anyWriteLocks) printf("There are write locks held\n");
243 if (udebug.currentTrans) {
244 if (udebug.writeTrans) printf("There is an active write transaction\n");
245 else printf("There is at least one active read transaction\n");
246 printf("Transaction tid is %d.%d\n", udebug.syncTid.epoch, udebug.syncTid.counter);
248 if (udebug.epochTime) {
249 diff = udebug.now - udebug.epochTime;
250 newtime = now - diff;
251 times = ctime(&newtime); times[24] = 0;
252 printf("Last time a new db version was labelled was:\n\t %d secs ago (at %s)\n",
256 if (int32p || udebug.amSyncSite) {
257 /* now do the subcalls */
260 code = VOTE_XSDebug(tconn, i, &usdebug, &isClone);
262 if ( oldServer ) { /* pre 3.5 server */
263 memset(&usdebug, 0, sizeof(usdebug));
264 code = VOTE_SDebugOld(tconn, i, &usdebug);
267 code = VOTE_SDebug(tconn, i, &usdebug);
269 if (code > 0) break; /* done */
271 printf("error code %d from VOTE_SDebug\n", code);
274 inhostAddr.s_addr = htonl(usdebug.addr);
275 /* otherwise print the structure */
276 printf("\nServer (%s", afs_inet_ntoa(htonl(usdebug.addr)));
277 for ( j=0;((usdebug.altAddr[j]) &&
278 (j<UBIK_MAX_INTERFACE_ADDR-1)); j++)
279 printf(" %s", afs_inet_ntoa(htonl(usdebug.altAddr[j])));
280 printf("): (db %d.%d)",
281 usdebug.remoteVersion.epoch, usdebug.remoteVersion.counter);
283 printf(" is only a clone!");
286 if (usdebug.lastVoteTime == 0) {
287 printf(" last vote never rcvd \n");
289 diff = udebug.now - usdebug.lastVoteTime;
290 newtime = now - diff;
291 times = ctime(&newtime); times[24] = 0;
292 printf(" last vote rcvd %d secs ago (at %s),\n", diff, times);
295 if (usdebug.lastBeaconSent == 0) {
296 printf(" last beacon never sent \n");
298 diff = udebug.now - usdebug.lastBeaconSent;
299 newtime = now - diff;
300 times = ctime(&newtime); times[24] = 0;
301 printf(" last beacon sent %d secs ago (at %s), last vote was %s\n",
302 diff, times, ((usdebug.lastVote)?"yes":"no"));
305 printf(" dbcurrent=%d, up=%d beaconSince=%d\n",
306 usdebug.currentDB, usdebug.up, usdebug.beaconSinceDown);
312 #include "AFS_component_version_number.c"
314 int main(int argc, char **argv)
316 struct cmd_syndesc *ts;
320 * The following signal action for AIX is necessary so that in case of a
321 * crash (i.e. core is generated) we can include the user's data section
322 * in the core dump. Unfortunately, by default, only a partial core is
323 * generated which, in many cases, isn't too useful.
325 struct sigaction nsa;
327 sigemptyset(&nsa.sa_mask);
328 nsa.sa_handler = SIG_DFL;
329 nsa.sa_flags = SA_FULLDUMP;
330 sigaction(SIGSEGV, &nsa, NULL);
332 ts = cmd_CreateSyntax(NULL, CommandProc, 0, "probe ubik server");
333 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "server machine");
334 cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "IP port");
335 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "print all info");
337 cmd_Dispatch(argc, argv);