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>
19 #include <afs/afsutil.h>
21 #define UBIK_INTERNALS
25 static_inline
int afs_cast_time_t(time_t d
) { return (int) d
; }
28 PortNumber(char *aport
)
34 while ((tc
= *aport
++)) {
35 if (tc
< '0' || tc
> '9')
36 return -1; /* bad port number */
38 total
+= tc
- (int)'0';
49 ts
= getservbyname(aname
, NULL
);
52 return ntohs(ts
->s_port
); /* returns it in host byte order */
55 if (strncmp(aname
, "vlserver", len
) == 0) {
57 } else if (strncmp(aname
, "ptserver", len
) == 0) {
59 } else if (strncmp(aname
, "kaserver", len
) == 0) {
61 } else if (strncmp(aname
, "buserver", len
) == 0) {
68 CommandProc(struct cmd_syndesc
*as
, void *arock
)
70 char *hostName
, *portName
, *times
;
75 time_t now
, then
, diff
, newtime
;
77 struct rx_connection
*tconn
;
78 struct rx_securityClass
*sc
;
79 struct ubik_debug udebug
;
80 struct ubik_sdebug usdebug
;
81 int oldServer
= 0; /* are we talking to a pre 3.5 server? */
82 afs_int32 isClone
= 0;
85 int32p
= (as
->parms
[2].items
? 1 : 0);
87 if (as
->parms
[0].items
)
88 hostName
= as
->parms
[0].items
->data
;
92 if (as
->parms
[1].items
)
93 portName
= as
->parms
[1].items
->data
;
99 th
= hostutil_GetHostByName(hostName
);
101 printf("udebug: host %s not found in host table\n", hostName
);
104 memcpy(&hostAddr
, th
->h_addr
, sizeof(afs_int32
));
106 hostAddr
= htonl(0x7f000001); /* IP localhost */
109 port
= htons(3000); /* default */
111 port
= PortNumber(portName
);
113 port
= PortName(portName
);
115 printf("udebug: can't resolve port name %s\n", portName
);
122 sc
= rxnull_NewClientSecurityObject();
123 tconn
= rx_NewConnection(hostAddr
, port
, VOTE_SERVICE_ID
, sc
, 0);
125 /* now do the main call */
126 code
= VOTE_XDebug(tconn
, &udebug
, &isClone
);
128 code
= VOTE_Debug(tconn
, &udebug
);
129 if (code
== RXGEN_OPCODE
) {
130 oldServer
= 1; /* talking to a pre 3.5 server */
131 memset(&udebug
, 0, sizeof(udebug
));
132 code
= VOTE_DebugOld(tconn
, (ubik_debug_old
*)&udebug
);
136 printf("return code %d from VOTE_Debug\n", code
);
142 /* now print the main info */
143 times
= ctime(&then
);
146 printf("Host's addresses are: ");
147 for (j
= 0; (j
< UBIK_MAX_INTERFACE_ADDR
) && udebug
.interfaceAddr
[j
];
149 printf("%s ", afs_inet_ntoa_r(htonl(udebug
.interfaceAddr
[j
]), hoststr
));
152 printf("Host's %s time is %s\n", afs_inet_ntoa_r(hostAddr
, hoststr
), times
);
156 diff
= now
- udebug
.now
;
157 printf("Local time is %s (time differential %d secs)\n", times
, afs_cast_time_t(diff
));
158 if (abs((int)diff
) >= MAXSKEW
)
159 printf("****clock may be bad\n");
161 /* UBIK skips the voting if 1 server - so we fudge it here */
162 if (udebug
.amSyncSite
&& (udebug
.nServers
== 1)) {
163 udebug
.lastYesHost
= ntohl(hostAddr
);
164 udebug
.lastYesTime
= udebug
.now
;
165 udebug
.lastYesState
= 1;
166 udebug
.lastYesClaim
= udebug
.now
;
167 udebug
.syncVersion
.epoch
= udebug
.localVersion
.epoch
;
168 udebug
.syncVersion
.counter
= udebug
.localVersion
.counter
;
171 /* XDR converts addresses for us, so all addresses are in HBO */
172 if (udebug
.lastYesHost
== 0xffffffff) {
173 printf("Last yes vote not cast yet \n");
175 diff
= udebug
.now
- udebug
.lastYesTime
;
176 printf("Last yes vote for %s was %d secs ago (%ssync site); \n",
177 afs_inet_ntoa_r(htonl(udebug
.lastYesHost
), hoststr
),
178 afs_cast_time_t(diff
),
179 ((udebug
.lastYesState
) ? "" : "not "));
181 diff
= udebug
.now
- udebug
.lastYesClaim
;
182 newtime
= now
- diff
;
183 times
= ctime(&newtime
);
185 printf("Last vote started %d secs ago (at %s)\n",
186 afs_cast_time_t(diff
), times
);
189 printf("Local db version is %d.%d\n", udebug
.localVersion
.epoch
,
190 udebug
.localVersion
.counter
);
192 if (udebug
.amSyncSite
) {
193 if (udebug
.syncSiteUntil
== 0x7fffffff) {
194 printf("I am sync site forever (%d server%s)\n", udebug
.nServers
,
195 ((udebug
.nServers
> 1) ? "s" : ""));
197 diff
= udebug
.syncSiteUntil
- udebug
.now
;
198 newtime
= now
+ diff
;
199 times
= ctime(&newtime
);
202 ("I am sync site until %d secs from now (at %s) (%d server%s)\n",
203 afs_cast_time_t(diff
), times
, udebug
.nServers
,
204 ((udebug
.nServers
> 1) ? "s" : ""));
206 printf("Recovery state %x\n", udebug
.recoveryState
);
209 printf("I am a clone and never can become sync site\n");
211 printf("I am not sync site\n");
212 diff
= udebug
.now
- udebug
.lowestTime
;
213 printf("Lowest host %s was set %d secs ago\n",
214 afs_inet_ntoa_r(htonl(udebug
.lowestHost
), hoststr
),
215 afs_cast_time_t(diff
));
217 diff
= udebug
.now
- udebug
.syncTime
;
218 printf("Sync host %s was set %d secs ago\n",
219 afs_inet_ntoa_r(htonl(udebug
.syncHost
), hoststr
),
220 afs_cast_time_t(diff
));
223 if (udebug
.activeWrite
) {
224 printf("I am currently managing write trans %d.%d\n",
225 udebug
.epochTime
, udebug
.tidCounter
);
227 printf("The last trans I handled was %d.%d\n",
228 udebug
.epochTime
, udebug
.tidCounter
);
231 printf("Sync site's db version is %d.%d\n", udebug
.syncVersion
.epoch
,
232 udebug
.syncVersion
.counter
);
233 printf("%d locked pages, %d of them for write\n", udebug
.lockedPages
,
234 udebug
.writeLockedPages
);
236 if (udebug
.anyReadLocks
)
237 printf("There are read locks held\n");
238 if (udebug
.anyWriteLocks
)
239 printf("There are write locks held\n");
241 if (udebug
.currentTrans
) {
242 if (udebug
.writeTrans
)
243 printf("There is an active write transaction\n");
245 printf("There is at least one active read transaction\n");
246 printf("Transaction tid is %d.%d\n", udebug
.syncTid
.epoch
,
247 udebug
.syncTid
.counter
);
249 if (udebug
.epochTime
) {
250 diff
= udebug
.now
- udebug
.epochTime
;
251 newtime
= now
- diff
;
252 times
= ctime(&newtime
);
255 ("Last time a new db version was labelled was:\n\t %d secs ago (at %s)\n",
256 afs_cast_time_t(diff
), times
);
259 if (int32p
|| udebug
.amSyncSite
) {
260 /* now do the subcalls */
263 code
= VOTE_XSDebug(tconn
, i
, &usdebug
, &isClone
);
265 if (oldServer
) { /* pre 3.5 server */
266 memset(&usdebug
, 0, sizeof(usdebug
));
267 code
= VOTE_SDebugOld(tconn
, i
, (ubik_sdebug_old
*)&usdebug
);
269 code
= VOTE_SDebug(tconn
, i
, &usdebug
);
274 printf("error code %d from VOTE_SDebug\n", code
);
277 /* otherwise print the structure */
278 printf("\nServer (%s", afs_inet_ntoa_r(htonl(usdebug
.addr
), hoststr
));
280 ((j
< UBIK_MAX_INTERFACE_ADDR
- 1) && (usdebug
.altAddr
[j
]));
282 printf(" %s", afs_inet_ntoa_r(htonl(usdebug
.altAddr
[j
]), hoststr
));
283 printf("): (db %d.%d)", usdebug
.remoteVersion
.epoch
,
284 usdebug
.remoteVersion
.counter
);
286 printf(" is only a clone!");
289 if (usdebug
.lastVoteTime
== 0) {
290 printf(" last vote never rcvd \n");
292 diff
= udebug
.now
- usdebug
.lastVoteTime
;
293 newtime
= now
- diff
;
294 times
= ctime(&newtime
);
296 printf(" last vote rcvd %d secs ago (at %s),\n",
297 afs_cast_time_t(diff
),
301 if (usdebug
.lastBeaconSent
== 0) {
302 printf(" last beacon never sent \n");
304 diff
= udebug
.now
- usdebug
.lastBeaconSent
;
305 newtime
= now
- diff
;
306 times
= ctime(&newtime
);
309 (" last beacon sent %d secs ago (at %s), last vote was %s\n",
310 afs_cast_time_t(diff
), times
, ((usdebug
.lastVote
) ? "yes" : "no"));
313 printf(" dbcurrent=%d, up=%d beaconSince=%d\n",
314 usdebug
.currentDB
, usdebug
.up
, usdebug
.beaconSinceDown
);
320 #include "AFS_component_version_number.c"
323 main(int argc
, char **argv
)
325 struct cmd_syndesc
*ts
;
329 * The following signal action for AIX is necessary so that in case of a
330 * crash (i.e. core is generated) we can include the user's data section
331 * in the core dump. Unfortunately, by default, only a partial core is
332 * generated which, in many cases, isn't too useful.
334 struct sigaction nsa
;
336 sigemptyset(&nsa
.sa_mask
);
337 nsa
.sa_handler
= SIG_DFL
;
338 nsa
.sa_flags
= SA_FULLDUMP
;
339 sigaction(SIGSEGV
, &nsa
, NULL
);
341 ts
= cmd_CreateSyntax(NULL
, CommandProc
, NULL
, 0, "probe ubik server");
342 cmd_AddParm(ts
, "-server", CMD_SINGLE
, CMD_REQUIRED
, "server machine");
343 cmd_AddParm(ts
, "-port", CMD_SINGLE
, CMD_OPTIONAL
, "IP port");
344 cmd_AddParm(ts
, "-long", CMD_FLAG
, CMD_OPTIONAL
, "print all info");
346 cmd_Dispatch(argc
, argv
);