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
12 * Implementation of the client side of the AFS File Server extended
13 * statistics facility.
15 *------------------------------------------------------------------------*/
17 #include <afsconfig.h>
18 #include <afs/param.h>
23 #include "xstat_fs.h" /*Interface for this module */
26 #include <afs/afsutil.h>
27 #include <afs/afscbint.h>
32 int xstat_fs_numServers; /*Num connected servers */
33 struct xstat_fs_ConnectionInfo
34 *xstat_fs_ConnInfo; /*Ptr to connection array */
35 int numCollections; /*Number of data collections */
36 struct xstat_fs_ProbeResults xstat_fs_Results; /*Latest probe results */
37 char terminationEvent; /*One-shot termination event */
39 afs_int32 xstat_fsData[AFS_MAX_XSTAT_LONGS]; /*Buffer for collected data */
44 static int xstat_fs_ProbeFreqInSecs; /*Probe freq. in seconds */
45 static int xstat_fs_initflag = 0; /*Was init routine called? */
46 static int xstat_fs_debug = 0; /*Debugging output enabled? */
47 static int xstat_fs_oneShot = 0; /*One-shot operation? */
48 static int (*xstat_fs_Handler) (void); /*Probe handler routine */
49 static pthread_t xstat_fs_thread; /*Probe thread */
50 static int xstat_fs_numCollections; /*Number of desired collections */
51 static afs_int32 *xstat_fs_collIDP; /*Ptr to collection IDs desired */
52 static opr_mutex_t xstat_fs_force_lock; /*Lock to wakeup probe */
53 static opr_cv_t xstat_fs_force_cv; /*Condvar to wakeup probe */
56 /*------------------------------------------------------------------------
57 * [private] xstat_fs_CleanupInit
60 * Set up for recovery after an error in initialization (i.e.,
61 * during a call to xstat_fs_Init.
68 * Error value otherwise.
71 * This routine is private to the module.
74 * Zeros out basic data structures.
75 *------------------------------------------------------------------------*/
78 xstat_fs_CleanupInit(void)
80 afs_int32 code; /*Return code from callback stubs */
81 struct rx_call *rxcall; /*Bogus param */
82 AFSCBFids *Fids_Array; /*Bogus param */
83 AFSCBs *CallBack_Array; /*Bogus param */
85 xstat_fs_ConnInfo = (struct xstat_fs_ConnectionInfo *)0;
86 xstat_fs_Results.probeNum = 0;
87 xstat_fs_Results.probeTime = 0;
88 xstat_fs_Results.connP = (struct xstat_fs_ConnectionInfo *)0;
89 xstat_fs_Results.collectionNumber = 0;
90 xstat_fs_Results.data.AFS_CollData_len = AFS_MAX_XSTAT_LONGS;
91 xstat_fs_Results.data.AFS_CollData_val = (afs_int32 *) xstat_fsData;
92 xstat_fs_Results.probeOK = 0;
94 rxcall = (struct rx_call *)0;
95 Fids_Array = (AFSCBFids *) 0;
96 CallBack_Array = (AFSCBs *) 0;
99 * Call each of the callback routines our module provides (in
100 * xstat_fs_callback.c) to make sure they're all there.
102 code = SRXAFSCB_CallBack(rxcall, Fids_Array, CallBack_Array);
105 code = SRXAFSCB_InitCallBackState3(rxcall, (afsUUID *) 0);
108 code = SRXAFSCB_Probe(rxcall);
113 /*------------------------------------------------------------------------
114 * [exported] xstat_fs_Cleanup
117 * Clean up our memory and connection state.
120 * int a_releaseMem : Should we free up malloc'ed areas?
123 * 0 on total success,
124 * -1 if the module was never initialized, or there was a problem
125 * with the xstat_fs connection array.
128 * xstat_fs_numServers should be properly set. We don't do anything
129 * unless xstat_fs_Init() has already been called.
132 * Shuts down Rx connections gracefully, frees allocated space
134 *------------------------------------------------------------------------*/
137 xstat_fs_Cleanup(int a_releaseMem)
139 static char rn[] = "xstat_fs_Cleanup"; /*Routine name */
140 int code; /*Return code */
141 int conn_idx; /*Current connection index */
142 struct xstat_fs_ConnectionInfo *curr_conn; /*Ptr to xstat_fs connection */
145 * Assume the best, but check the worst.
147 if (!xstat_fs_initflag) {
148 fprintf(stderr, "[%s] Refused; module not initialized\n", rn);
154 * Take care of all Rx connections first. Check to see that the
155 * server count is a legal value.
157 if (xstat_fs_numServers <= 0) {
159 "[%s] Illegal number of servers (xstat_fs_numServers = %d)\n",
160 rn, xstat_fs_numServers);
163 if (xstat_fs_ConnInfo != (struct xstat_fs_ConnectionInfo *)0) {
165 * The xstat_fs connection structure array exists. Go through
166 * it and close up any Rx connections it holds.
168 curr_conn = xstat_fs_ConnInfo;
169 for (conn_idx = 0; conn_idx < xstat_fs_numServers; conn_idx++) {
170 if (curr_conn->rxconn != (struct rx_connection *)0) {
171 rx_DestroyConnection(curr_conn->rxconn);
172 curr_conn->rxconn = (struct rx_connection *)0;
175 } /*for each xstat_fs connection */
176 } /*xstat_fs connection structure exists */
177 } /*Legal number of servers */
180 * If asked to, release the space we've allocated.
183 if (xstat_fs_ConnInfo != (struct xstat_fs_ConnectionInfo *)0)
184 free(xstat_fs_ConnInfo);
188 * Return the news, whatever it is.
194 /*------------------------------------------------------------------------
195 * [private] xstat_fs_LWP
198 * This thread iterates over the server connections and gathers up
199 * the desired statistics from each one on a regular basis. When
200 * the sweep is done, the associated handler function is called
201 * to process the new data.
210 * Started by xstat_fs_Init(), uses global structures and the
211 * global private xstat_fs_oneShot variable.
214 * Nothing interesting.
215 *------------------------------------------------------------------------*/
218 xstat_fs_LWP(void *unused)
220 static char rn[] = "xstat_fs_thread"; /*Routine name */
221 afs_int32 code; /*Results of calls */
222 struct timeval tv; /*Time structure */
223 struct timespec wait; /*Time to wait */
224 int conn_idx; /*Connection index */
225 struct xstat_fs_ConnectionInfo *curr_conn; /*Current connection */
226 afs_int32 srvVersionNumber; /*Xstat version # */
227 afs_int32 clientVersionNumber; /*Client xstat version */
228 afs_int32 numColls; /*Number of collections to get */
229 afs_int32 *currCollIDP; /*Curr collection ID desired */
232 * Set up some numbers we'll need.
234 clientVersionNumber = AFS_XSTAT_VERSION;
236 while (1) { /*Service loop */
238 * Iterate through the server connections, gathering data.
239 * Don't forget to bump the probe count and zero the statistics
240 * areas before calling the servers.
243 printf("[%s] Waking up, getting data from %d server(s)\n", rn,
244 xstat_fs_numServers);
245 curr_conn = xstat_fs_ConnInfo;
246 xstat_fs_Results.probeNum++;
248 for (conn_idx = 0; conn_idx < xstat_fs_numServers; conn_idx++) {
250 * Grab the statistics for the current File Server, if the
251 * connection is valid.
254 printf("[%s] Getting collections from File Server '%s'\n", rn,
255 curr_conn->hostName);
256 if (curr_conn->rxconn != (struct rx_connection *)0) {
258 printf("[%s] Connection OK, calling RXAFS_GetXStats\n",
261 currCollIDP = xstat_fs_collIDP;
262 for (numColls = 0; numColls < xstat_fs_numCollections;
263 numColls++, currCollIDP++) {
265 * Initialize the per-probe values.
268 printf("[%s] Asking for data collection %d\n", rn,
270 xstat_fs_Results.collectionNumber = *currCollIDP;
271 xstat_fs_Results.data.AFS_CollData_len =
273 memset(xstat_fs_Results.data.AFS_CollData_val, 0,
274 AFS_MAX_XSTAT_LONGS * 4);
276 xstat_fs_Results.connP = curr_conn;
278 if (xstat_fs_debug) {
280 ("%s: Calling RXAFS_GetXStats, conn=%" AFS_PTR_FMT ", clientVersionNumber=%d, collectionNumber=%d, srvVersionNumberP=%" AFS_PTR_FMT ", timeP=%" AFS_PTR_FMT ", dataP=%" AFS_PTR_FMT "\n",
281 rn, curr_conn->rxconn, clientVersionNumber,
282 *currCollIDP, &srvVersionNumber,
283 &(xstat_fs_Results.probeTime),
284 &(xstat_fs_Results.data));
285 printf("%s: [bufflen=%d, buffer at %" AFS_PTR_FMT "]\n", rn,
286 xstat_fs_Results.data.AFS_CollData_len,
287 xstat_fs_Results.data.AFS_CollData_val);
290 xstat_fs_Results.probeOK =
291 RXAFS_GetXStats(curr_conn->rxconn,
292 clientVersionNumber, *currCollIDP,
294 &(xstat_fs_Results.probeTime),
295 &(xstat_fs_Results.data));
298 * Now that we (may) have the data for this connection,
299 * call the associated handler function. The handler does
300 * not take any explicit parameters, but rather gets to the
301 * goodies via some of the objects exported by this module.
304 printf("[%s] Calling handler routine.\n", rn);
305 code = xstat_fs_Handler();
308 "[%s] Handler returned error code %d\n", rn,
311 } /*For each collection */
314 /*Valid Rx connection */
316 * Advance the xstat_fs connection pointer.
320 } /*For each xstat_fs connection */
323 * All (valid) connections have been probed. Fall asleep for the
324 * prescribed number of seconds, unless we're a one-shot. In
325 * that case, we need to signal our caller that we're done.
328 printf("[%s] Polling complete for probe round %d.\n", rn,
329 xstat_fs_Results.probeNum);
331 if (xstat_fs_oneShot) {
333 * One-shot execution desired.
338 * Continuous execution desired. Sleep for the required
339 * number of seconds or wakeup sooner if forced.
341 gettimeofday(&tv, NULL);
342 wait.tv_sec = tv.tv_sec + xstat_fs_ProbeFreqInSecs;
343 wait.tv_nsec = tv.tv_usec * 1000;
344 opr_mutex_enter(&xstat_fs_force_lock);
345 code = opr_cv_timedwait(&xstat_fs_force_cv, &xstat_fs_force_lock, &wait);
346 opr_Verify(code == 0 || code == ETIMEDOUT);
347 opr_mutex_exit(&xstat_fs_force_lock);
348 } /*Continuous execution */
353 /*------------------------------------------------------------------------
354 * [exported] xstat_fs_Init
357 * Initialize the xstat_fs module: set up Rx connections to the
358 * given set of File Servers, start up the probe and callback threads,
359 * and associate the routine to be called when a probe completes.
360 * Also, let it know which collections you're interested in.
363 * int a_numServers : Num. servers to connect to.
364 * struct sockaddr_in *a_socketArray : Array of server sockets.
365 * int a_ProbeFreqInSecs : Probe frequency in seconds.
366 * int (*a_ProbeHandler)() : Ptr to probe handler fcn.
367 * int a_flags : Various flags.
368 * int a_numCollections : Number of collections desired.
369 * afs_int32 *a_collIDP : Ptr to collection IDs.
373 * -2 for (at least one) connection error,
374 * LWP process creation code, if it failed,
375 * -1 for other fatal errors.
378 * *** MUST BE THE FIRST ROUTINE CALLED FROM THIS PACKAGE ***
379 * Also, the server security object CBsecobj MUST be a static,
380 * since it has to stick around after this routine exits.
383 * Sets up just about everything.
384 *------------------------------------------------------------------------*/
387 xstat_fs_Init(int a_numServers, struct sockaddr_in *a_socketArray,
388 int a_ProbeFreqInSecs, int (*a_ProbeHandler) (void), int a_flags,
389 int a_numCollections, afs_int32 * a_collIDP)
391 static char rn[] = "xstat_fs_Init"; /*Routine name */
392 afs_int32 code; /*Return value */
393 static struct rx_securityClass *CBsecobj; /*Callback security object */
394 struct rx_securityClass *secobj; /*Client security object */
395 struct rx_service *rxsrv_afsserver; /*Server for AFS */
396 int arg_errfound; /*Argument error found? */
397 int curr_srv; /*Current server idx */
398 struct xstat_fs_ConnectionInfo *curr_conn; /*Ptr to current conn */
399 char *hostNameFound; /*Ptr to returned host name */
400 int conn_err; /*Connection error? */
401 int collIDBytes; /*Num bytes in coll ID array */
405 * If we've already been called, snicker at the bozo, gently
406 * remind him of his doubtful heritage, and return success.
408 if (xstat_fs_initflag) {
409 fprintf(stderr, "[%s] Called multiple times!\n", rn);
412 xstat_fs_initflag = 1;
414 opr_mutex_init(&xstat_fs_force_lock);
415 opr_cv_init(&xstat_fs_force_cv);
418 * Check the parameters for bogosities.
421 if (a_numServers <= 0) {
422 fprintf(stderr, "[%s] Illegal number of servers: %d\n", rn,
426 if (a_socketArray == (struct sockaddr_in *)0) {
427 fprintf(stderr, "[%s] Null server socket array argument\n", rn);
430 if (a_ProbeFreqInSecs <= 0) {
431 fprintf(stderr, "[%s] Illegal probe frequency: %d\n", rn,
435 if (a_ProbeHandler == NULL) {
436 fprintf(stderr, "[%s] Null probe handler function argument\n", rn);
439 if (a_numCollections <= 0) {
440 fprintf(stderr, "[%s] Illegal collection count argument: %d\n", rn,
444 if (a_collIDP == NULL) {
445 fprintf(stderr, "[%s] Null collection ID array argument\n", rn);
452 * Record our passed-in info.
454 xstat_fs_debug = (a_flags & XSTAT_FS_INITFLAG_DEBUGGING);
455 xstat_fs_oneShot = (a_flags & XSTAT_FS_INITFLAG_ONE_SHOT);
456 xstat_fs_numServers = a_numServers;
457 xstat_fs_Handler = a_ProbeHandler;
458 xstat_fs_ProbeFreqInSecs = a_ProbeFreqInSecs;
459 xstat_fs_numCollections = a_numCollections;
460 collIDBytes = xstat_fs_numCollections * sizeof(afs_int32);
461 xstat_fs_collIDP = malloc(collIDBytes);
462 memcpy(xstat_fs_collIDP, a_collIDP, collIDBytes);
463 if (xstat_fs_debug) {
464 printf("[%s] Asking for %d collection(s): ", rn,
465 xstat_fs_numCollections);
466 for (curr_srv = 0; curr_srv < xstat_fs_numCollections; curr_srv++)
467 printf("%d ", *(xstat_fs_collIDP + curr_srv));
472 * Get ready in case we have to do a cleanup - basically, zero
475 code = xstat_fs_CleanupInit();
480 * Allocate the necessary data structures and initialize everything
483 xstat_fs_ConnInfo = malloc(a_numServers
484 * sizeof(struct xstat_fs_ConnectionInfo));
485 if (xstat_fs_ConnInfo == (struct xstat_fs_ConnectionInfo *)0) {
487 "[%s] Can't allocate %d connection info structs (%" AFS_SIZET_FMT " bytes)\n",
489 (a_numServers * sizeof(struct xstat_fs_ConnectionInfo)));
490 return (-1); /*No cleanup needs to be done yet */
494 * Initialize the Rx subsystem, just in case nobody's done it.
497 printf("[%s] Initializing Rx\n", rn);
500 fprintf(stderr, "[%s] Fatal error in rx_Init()\n", rn);
504 printf("[%s] Rx initialized\n", rn);
507 * Create a null Rx server security object, to be used by the
510 CBsecobj = (struct rx_securityClass *)
511 rxnull_NewServerSecurityObject();
512 if (CBsecobj == (struct rx_securityClass *)0) {
514 "[%s] Can't create callback listener's security object.\n",
516 xstat_fs_Cleanup(1); /*Delete already-malloc'ed areas */
520 printf("[%s] Callback server security object created\n", rn);
523 * Create a null Rx client security object, to be used by the
526 secobj = rxnull_NewClientSecurityObject();
527 if (secobj == (struct rx_securityClass *)0) {
529 "[%s] Can't create probe thread client security object.\n", rn);
530 xstat_fs_Cleanup(1); /*Delete already-malloc'ed areas */
534 printf("[%s] Probe thread client security object created\n", rn);
536 curr_conn = xstat_fs_ConnInfo;
538 for (curr_srv = 0; curr_srv < a_numServers; curr_srv++) {
540 * Copy in the socket info for the current server, resolve its
541 * printable name if possible.
543 if (xstat_fs_debug) {
545 printf("[%s] Copying in the following socket info:\n", rn);
546 printf("[%s] IP addr %s, port %d\n", rn,
547 afs_inet_ntoa_r((a_socketArray + curr_srv)->sin_addr.s_addr,hoststr),
548 ntohs((a_socketArray + curr_srv)->sin_port));
550 memcpy(&(curr_conn->skt), a_socketArray + curr_srv,
551 sizeof(struct sockaddr_in));
554 hostutil_GetNameByINet(curr_conn->skt.sin_addr.s_addr);
555 if (hostNameFound == NULL) {
557 "[%s] Can't map Internet address %s to a string name\n",
558 rn, afs_inet_ntoa_r(curr_conn->skt.sin_addr.s_addr,hoststr));
559 curr_conn->hostName[0] = '\0';
561 strcpy(curr_conn->hostName, hostNameFound);
563 printf("[%s] Host name for server index %d is %s\n", rn,
564 curr_srv, curr_conn->hostName);
568 * Make an Rx connection to the current server.
572 ("[%s] Connecting to srv idx %d, IP addr %s, port %d, service 1\n",
573 rn, curr_srv, afs_inet_ntoa_r(curr_conn->skt.sin_addr.s_addr,hoststr),
574 ntohs(curr_conn->skt.sin_port));
576 curr_conn->rxconn = rx_NewConnection(curr_conn->skt.sin_addr.s_addr, /*Server addr */
577 curr_conn->skt.sin_port, /*Server port */
578 1, /*AFS service # */
579 secobj, /*Security obj */
581 if (curr_conn->rxconn == (struct rx_connection *)0) {
583 "[%s] Can't create Rx connection to server '%s' (%s)\n",
584 rn, curr_conn->hostName, afs_inet_ntoa_r(curr_conn->skt.sin_addr.s_addr,hoststr));
588 printf("[%s] New connection at %" AFS_PTR_FMT "\n", rn, curr_conn->rxconn);
591 * Bump the current xstat_fs connection to set up.
598 * Create the AFS callback service (listener).
601 printf("[%s] Creating AFS callback listener\n", rn);
602 rxsrv_afsserver = rx_NewService(0, /*Use default port */
604 "afs", /*Service name */
605 &CBsecobj, /*Ptr to security object(s) */
606 1, /*# of security objects */
607 RXAFSCB_ExecuteRequest); /*Dispatcher */
608 if (rxsrv_afsserver == (struct rx_service *)0) {
609 fprintf(stderr, "[%s] Can't create callback Rx service/listener\n",
611 xstat_fs_Cleanup(1); /*Delete already-malloc'ed areas */
615 printf("[%s] Callback listener created\n", rn);
618 * Start up the AFS callback service.
621 printf("[%s] Starting up callback listener.\n", rn);
622 rx_StartServer(0); /*Don't donate yourself to LWP pool */
625 * Start up the probe LWP.
628 printf("[%s] Creating the probe thread\n", rn);
629 code = pthread_create(&xstat_fs_thread, NULL, xstat_fs_LWP, NULL);
631 fprintf(stderr, "[%s] Can't create xstat_fs thread! Error is %d\n", rn,
633 xstat_fs_Cleanup(1); /*Delete already-malloc'ed areas */
638 * Return the final results.
647 /*------------------------------------------------------------------------
648 * [exported] xstat_fs_ForceProbeNow
651 * Wake up the probe thread, forcing it to execute a probe immediately.
658 * Error value otherwise.
661 * The module must have been initialized.
665 *------------------------------------------------------------------------*/
668 xstat_fs_ForceProbeNow(void)
670 static char rn[] = "xstat_fs_ForceProbeNow"; /*Routine name */
673 * There isn't a prayer unless we've been initialized.
675 if (!xstat_fs_initflag) {
676 fprintf(stderr, "[%s] Must call xstat_fs_Init first!\n", rn);
681 * Kick the sucker in the side.
683 opr_mutex_enter(&xstat_fs_force_lock);
684 opr_cv_signal(&xstat_fs_force_cv);
685 opr_mutex_exit(&xstat_fs_force_lock);
688 * We did it, so report the happy news.
694 * Fill the xstat full perf data structure from the data collection array.
696 * This function is a client-side decoding of the non-portable xstat_fs full
697 * performance data. The full perf structure includes timeval structures,
698 * which have platform dependent size.
700 * To make things even more interesting, the word ordering of the time
701 * values on hosts with 64-bit time depend on endianess. The ordering
702 * within a given afs_int32 is handled by xdr.
704 * @param[out] aout an address to a stats structure pointer
705 * @param[in] ain array of int32s received
706 * @param[in] alen length of ain
707 * @param[inout] abuf a buffer provided by the caller
709 * @return 0 on success
712 xstat_fs_DecodeFullPerfStats(struct fs_stats_FullPerfStats **aout,
715 struct fs_stats_FullPerfStats *abuf)
719 int snbo = -2; /* detected remote site has network-byte ordering */
721 static const int XSTAT_FPS_LEN = sizeof(struct fs_stats_FullPerfStats) / sizeof(afs_int32); /* local size of fps */
722 static const int XSTAT_FPS_SMALL = 424; /**< fps size when sizeof(timeval) is 2*sizeof(afs_int32) */
723 static const int XSTAT_FPS_LARGE = 666; /**< fps size when sizeof(timeval) is 2*sizeof(afs_int64) */
725 #define DECODE_TV(t) \
727 if (alen == XSTAT_FPS_SMALL) { \
729 (t).tv_usec = *p++; \
735 (t).tv_usec = *p++; \
739 (t).tv_usec = *p++; \
745 if (alen != XSTAT_FPS_SMALL && alen != XSTAT_FPS_LARGE) {
746 return -1; /* unrecognized size */
749 if (alen == XSTAT_FPS_LEN && alen == XSTAT_FPS_SMALL) {
750 /* Same size, and xdr dealt with byte ordering; no decoding needed. */
751 *aout = (struct fs_stats_FullPerfStats *)ain;
755 if (alen == XSTAT_FPS_LARGE) {
756 /* Attempt to detect the word ordering of the time values. */
757 struct fs_stats_FullPerfStats *fps =
758 (struct fs_stats_FullPerfStats *)ain;
759 afs_int32 *epoch = (afs_int32 *) & (fps->det.epoch);
760 if (epoch[0] == 0 && epoch[1] != 0) {
762 } else if (epoch[0] != 0 && epoch[1] == 0) {
765 return -2; /* failed to detect server word ordering */
769 if (alen == XSTAT_FPS_LEN && alen == XSTAT_FPS_LARGE
770 #if defined(WORDS_BIGENDIAN)
772 #else /* WORDS_BIGENDIAN */
774 #endif /* WORDS_BIGENDIAN */
776 /* Same size and order; no decoding needed. */
777 *aout = (struct fs_stats_FullPerfStats *)ain;
781 /* Either different sizes, or different ordering, or both. Schlep over
782 * each field, decoding time values. The fields up to the first time value
783 * can be copied in bulk. */
784 if (xstat_fs_debug) {
785 printf("debug: Decoding xstat full perf stats; length=%d", alen);
786 if (alen == XSTAT_FPS_LARGE) {
787 printf(", order='%s'", (snbo ? "big-endian" : "little-endian"));
793 memset(abuf, 0, sizeof(struct fs_stats_FullPerfStats));
794 memcpy(abuf, p, sizeof(struct afs_PerfStats));
795 p += sizeof(struct afs_PerfStats) / sizeof(afs_int32);
797 DECODE_TV(abuf->det.epoch);
798 for (i = 0; i < FS_STATS_NUM_RPC_OPS; i++) {
799 struct fs_stats_opTimingData *td = abuf->det.rpcOpTimes + i;
801 td->numSuccesses = *p++;
802 DECODE_TV(td->sumTime);
803 DECODE_TV(td->sqrTime);
804 DECODE_TV(td->minTime);
805 DECODE_TV(td->maxTime);
807 for (i = 0; i < FS_STATS_NUM_XFER_OPS; i++) {
808 struct fs_stats_xferData *xd = abuf->det.xferOpTimes + i;
810 xd->numSuccesses = *p++;
811 DECODE_TV(xd->sumTime);
812 DECODE_TV(xd->sqrTime);
813 DECODE_TV(xd->minTime);
814 DECODE_TV(xd->maxTime);
818 memcpy((void *)xd->count, (void *)p,
819 sizeof(afs_int32) * FS_STATS_NUM_XFER_BUCKETS);
820 p += FS_STATS_NUM_XFER_BUCKETS;
828 * Wait for the collection to complete. Returns after one cycle if running in
829 * one-shot mode, otherwise wait for a given amount of time.
832 * int sleep_secs : time to wait in seconds when running
833 * in continuous mode. 0 means wait forever.
839 xstat_fs_Wait(int sleep_secs)
841 static char rn[] = "xstat_fs_Wait"; /*Routine name */
843 struct timeval tv; /*Time structure */
845 if (xstat_fs_oneShot) {
847 * One-shot operation; just wait for the collection to be done.
850 printf("[%s] Calling pthread_join\n", rn);
851 code = pthread_join(xstat_fs_thread, NULL);
853 printf("[%s] Returned from pthread_join()\n", rn);
856 "[%s] Error %d encountered by pthread_join()\n",
859 } else if (sleep_secs == 0) {
864 fprintf(stderr, "[ %s ] going to sleep ...\n", rn);
866 code = select(0, /*Num fds */
867 0, /*Descriptors ready for reading */
868 0, /*Descriptors ready for writing */
869 0, /*Descriptors with exceptional conditions */
870 &tv); /*Timeout structure */
872 fprintf(stderr, "[%s] select() error %d\n", rn, errno);
877 /* Let's just fall asleep while. */
880 ("xstat_fs service started, main thread sleeping for %d secs.\n",
882 tv.tv_sec = sleep_secs;
884 code = select(0, /*Num fds */
885 0, /*Descriptors ready for reading */
886 0, /*Descriptors ready for writing */
887 0, /*Descriptors with exceptional conditions */
888 &tv); /*Timeout structure */
890 fprintf(stderr, "[%s] select() error %d\n", rn, errno);