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 <afs/param.h>
11 #include <sys/types.h>
17 #include <sys/param.h>
18 #include <netinet/in.h>
29 #define UBIK_INTERNALS
33 extern struct hostent *hostutil_GetHostByName();
35 static short PortNumber(aport)
36 register char *aport; {
38 register afs_int32 total;
41 while (tc = *aport++) {
42 if (tc < '0' || tc > '9') return -1; /* bad port number */
44 total += tc - (int) '0';
49 static short PortName(aname)
55 ts = getservbyname(aname, (char *) 0);
58 return ntohs(ts->s_port); /* returns it in host byte order */
61 if (strncmp(aname,"vlserver",len) == 0) {
63 } else if (strncmp(aname,"ptserver",len) == 0) {
65 } else if (strncmp(aname,"kaserver",len) == 0) {
67 } else if (strncmp(aname,"buserver",len) == 0) {
73 static CommandProc(as, arock)
75 struct cmd_syndesc *as; {
76 char *hostName, *portName, *times;
78 struct in_addr inhostAddr;
79 register afs_int32 i, j, code;
82 afs_int32 now, diff, newtime;
84 struct rx_connection *tconn;
85 struct rx_securityClass *sc;
86 struct ubik_debug udebug;
87 struct ubik_sdebug usdebug;
88 int oldServer =0; /* are we talking to a pre 3.5 server? */
90 int32p = (as->parms[2].items ? 1 : 0);
92 if (as->parms[0].items)
93 hostName = as->parms[0].items->data;
95 hostName = (char *) 0;
97 if (as->parms[1].items)
98 portName = as->parms[1].items->data;
100 portName = (char *) 0;
104 th = hostutil_GetHostByName(hostName);
106 printf("udebug: host %s not found in host table\n", hostName);
109 bcopy(th->h_addr, &hostAddr, sizeof(afs_int32));
111 else hostAddr = htonl(0x7f000001); /* IP localhost */
114 port = htons(3000); /* default */
116 port = PortNumber(portName);
118 port = PortName(portName);
120 printf("udebug: can't resolve port name %s\n", portName);
127 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
128 tconn = rx_NewConnection(hostAddr, port, VOTE_SERVICE_ID, sc, 0);
130 /* now do the main call */
131 code = VOTE_Debug(tconn, &udebug);
132 if ( code == RXGEN_OPCODE )
134 oldServer = 1; /* talking to a pre 3.5 server */
135 memset(&udebug, 0, sizeof(udebug));
136 code = VOTE_DebugOld(tconn, &udebug);
140 printf("return code %d from VOTE_Debug\n", code);
145 /* now print the main info */
146 times = ctime((time_t *)&udebug.now); times[24] = 0;
147 inhostAddr.s_addr = hostAddr;
150 printf("Host's addresses are: ");
151 for ( j=0; udebug.interfaceAddr[j] && ( j<UBIK_MAX_INTERFACE_ADDR );j++)
152 printf("%s ", afs_inet_ntoa(htonl(udebug.interfaceAddr[j])));
155 printf("Host's %s time is %s\n", inet_ntoa(inhostAddr), times);
157 times = ctime(&now); times[24] = 0;
158 diff = now - udebug.now;
159 printf("Local time is %s (time differential %d secs)\n", times, diff);
160 if (abs(diff) >= MAXSKEW)
161 printf("****clock may be bad\n");
163 /* UBIK skips the voting if 1 server - so we fudge it here */
164 if (udebug.amSyncSite && (udebug.nServers == 1)) {
165 udebug.lastYesHost = hostAddr;
166 udebug.lastYesTime = udebug.now;
167 udebug.lastYesState = 1;
168 udebug.lastYesClaim = udebug.now;
169 udebug.syncVersion.epoch = udebug.localVersion.epoch;
170 udebug.syncVersion.counter = udebug.localVersion.counter;
173 /* sockaddr is always in net-order */
174 if (udebug.lastYesHost == 0xffffffff) {
175 printf("Last yes vote not cast yet \n");
177 inhostAddr.s_addr = htonl(udebug.lastYesHost);
178 diff = udebug.now - udebug.lastYesTime;
179 printf("Last yes vote for %s was %d secs ago (%ssync site); \n",
180 inet_ntoa(inhostAddr), diff, ((udebug.lastYesState)?"":"not "));
182 diff = udebug.now - udebug.lastYesClaim;
183 newtime = now - diff;
184 times = ctime(&newtime); times[24] = 0;
185 printf("Last vote started %d secs ago (at %s)\n", diff, times);
188 printf("Local db version is %d.%d\n", udebug.localVersion.epoch, udebug.localVersion.counter);
190 if (udebug.amSyncSite) {
191 if (udebug.syncSiteUntil == 0x7fffffff) {
192 printf("I am sync site forever (%d server%s)\n",
193 udebug.nServers, ((udebug.nServers>1)?"s":""));
195 diff = udebug.syncSiteUntil - udebug.now;
196 newtime = now + diff;
197 times = ctime(&newtime); times[24] = 0;
198 printf("I am sync site until %d secs from now (at %s) (%d server%s)\n",
199 diff, times, udebug.nServers,
200 ((udebug.nServers>1)?"s":""));
202 printf("Recovery state %x\n", udebug.recoveryState);
203 if (udebug.activeWrite) {
204 printf("I am currently managing write trans %d.%d\n",
205 udebug.epochTime, udebug.tidCounter);
208 printf("I am not sync site\n");
209 inhostAddr.s_addr = htonl(udebug.lowestHost);
210 diff = udebug.now - udebug.lowestTime;
211 printf("Lowest host %s was set %d secs ago\n", inet_ntoa(inhostAddr), diff);
213 inhostAddr.s_addr = htonl(udebug.syncHost);
214 diff = udebug.now - udebug.syncTime;
215 printf("Sync host %s was set %d secs ago\n", inet_ntoa(inhostAddr), diff);
218 printf("Sync site's db version is %d.%d\n",
219 udebug.syncVersion.epoch, udebug.syncVersion.counter);
220 printf("%d locked pages, %d of them for write\n",
221 udebug.lockedPages, udebug.writeLockedPages);
223 if (udebug.anyReadLocks) printf("There are read locks held\n");
224 if (udebug.anyWriteLocks) printf("There are write locks held\n");
226 if (udebug.currentTrans) {
227 if (udebug.writeTrans) printf("There is an active write transaction\n");
228 else printf("There is at least one active read transaction\n");
229 printf("Transaction tid is %d.%d\n", udebug.syncTid.epoch, udebug.syncTid.counter);
231 if (udebug.epochTime) {
232 diff = udebug.now - udebug.epochTime;
233 newtime = now - diff;
234 times = ctime(&newtime); times[24] = 0;
235 printf("Last time a new db version was labelled was:\n\t %d secs ago (at %s)\n",
239 if (int32p || udebug.amSyncSite) {
240 /* now do the subcalls */
243 { /* pre 3.5 server */
244 memset(&usdebug, 0, sizeof(usdebug));
245 code = VOTE_SDebugOld(tconn, i, &usdebug);
248 code = VOTE_SDebug(tconn, i, &usdebug);
249 if (code > 0) break; /* done */
251 printf("error code %d from VOTE_SDebug\n", code);
254 inhostAddr.s_addr = htonl(usdebug.addr);
255 /* otherwise print the structure */
256 printf("\nServer( %s", afs_inet_ntoa(htonl(usdebug.addr)));
257 for ( j=0;((usdebug.altAddr[j]) &&
258 (j<UBIK_MAX_INTERFACE_ADDR-1)); j++)
259 printf(" %s", afs_inet_ntoa(htonl(usdebug.altAddr[j])));
260 printf(" ): (db %d.%d)\n",
261 usdebug.remoteVersion.epoch, usdebug.remoteVersion.counter);
263 if (usdebug.lastVoteTime == 0) {
264 printf(" last vote never rcvd \n");
266 diff = udebug.now - usdebug.lastVoteTime;
267 newtime = now - diff;
268 times = ctime(&newtime); times[24] = 0;
269 printf(" last vote rcvd %d secs ago (at %s),\n", diff, times);
272 if (usdebug.lastBeaconSent == 0) {
273 printf(" last beacon never sent \n");
275 diff = udebug.now - usdebug.lastBeaconSent;
276 newtime = now - diff;
277 times = ctime(&newtime); times[24] = 0;
278 printf(" last beacon sent %d secs ago (at %s), last vote was %s\n",
279 diff, times, ((usdebug.lastVote)?"yes":"no"));
282 printf(" dbcurrent=%d, up=%d beaconSince=%d\n",
283 usdebug.currentDB, usdebug.up, usdebug.beaconSinceDown);
288 #include "AFS_component_version_number.c"
293 struct cmd_syndesc *ts;
297 * The following signal action for AIX is necessary so that in case of a
298 * crash (i.e. core is generated) we can include the user's data section
299 * in the core dump. Unfortunately, by default, only a partial core is
300 * generated which, in many cases, isn't too useful.
302 struct sigaction nsa;
304 sigemptyset(&nsa.sa_mask);
305 nsa.sa_handler = SIG_DFL;
306 nsa.sa_flags = SA_FULLDUMP;
307 sigaction(SIGSEGV, &nsa, NULL);
309 ts = cmd_CreateSyntax((char *) 0, CommandProc, 0, "probe ubik server");
310 cmd_AddParm(ts, "-servers", CMD_SINGLE, CMD_REQUIRED, "server machine");
311 cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "IP port");
312 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "print all info");
314 cmd_Dispatch(argc, argv);