xstat: Set but not used variables
[openafs.git] / src / xstat / xstat_fs_test.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
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
8  */
9
10 /*
11  * Description:
12  *      Test of the xstat_fs module.
13  *
14  *------------------------------------------------------------------------*/
15
16 #include <afsconfig.h>
17 #include <afs/param.h>
18
19
20 #include "xstat_fs.h"           /*Interface for xstat_fs module */
21 #include <afs/cmd.h>            /*Command line interpreter */
22 #include <time.h>
23 #include <string.h>
24 #include <afs/afsutil.h>
25
26 /*
27  * Command line parameter indices.
28  *      P_FS_NAMES : List of FileServer names.
29  *      P_COLL_IDS : List of collection IDs to pick up.
30  *      P_ONESHOT  : Are we gathering exactly one round of data?
31  *      P_DEBUG    : Enable debugging output?
32  */
33 #define P_FS_NAMES      0
34 #define P_COLL_IDS      1
35 #define P_ONESHOT       2
36 #define P_FREQUENCY     3
37 #define P_PERIOD        4
38 #define P_DEBUG         5
39
40 /*
41  * Private globals.
42  */
43 static int debugging_on = 0;    /*Are we debugging? */
44 static int one_shot = 0;        /*Single round of data collection? */
45
46 static char *opNames[] = {
47     "FetchData",
48     "FetchACL",
49     "FetchStatus",
50     "StoreData",
51     "StoreACL",
52     "StoreStatus",
53     "RemoveFile",
54     "CreateFile",
55     "Rename",
56     "Symlink",
57     "Link",
58     "MakeDir",
59     "RemoveDir",
60     "SetLock",
61     "ExtendLock",
62     "ReleaseLock",
63     "GetStatistics",
64     "GiveUpCallbacks",
65     "GetVolumeInfo",
66     "GetVolumeStatus",
67     "SetVolumeStatus",
68     "GetRootVolume",
69     "CheckToken",
70     "GetTime",
71     "NGetVolumeInfo",
72     "BulkStatus",
73     "XStatsVersion",
74     "GetXStats"
75 };
76
77 static char *xferOpNames[] = {
78     "FetchData",
79     "StoreData"
80 };
81
82
83 /*------------------------------------------------------------------------
84  * PrintCallInfo
85  *
86  * Description:
87  *      Print out the AFS_XSTATSCOLL_CALL_INFO collection we just
88  *      received.
89  *
90  * Arguments:
91  *      None.
92  *
93  * Returns:
94  *      Nothing.
95  *
96  * Environment:
97  *      All the info we need is nestled into xstat_fs_Results.
98  *
99  * Side Effects:
100  *      As advertised.
101  *------------------------------------------------------------------------*/
102
103 void
104 PrintCallInfo(void)
105 {                               /*PrintCallInfo */
106     int i;              /*Loop variable */
107     int numInt32s;              /*# int32words returned */
108     afs_int32 *currInt32;       /*Ptr to current afs_int32 value */
109     char *printableTime;        /*Ptr to printable time string */
110     time_t probeTime = xstat_fs_Results.probeTime;
111
112     /*
113      * Just print out the results of the particular probe.
114      */
115     numInt32s = xstat_fs_Results.data.AFS_CollData_len;
116     currInt32 = (afs_int32 *) (xstat_fs_Results.data.AFS_CollData_val);
117     printableTime = ctime(&probeTime);
118     printableTime[strlen(printableTime) - 1] = '\0';
119
120     printf("AFS_XSTATSCOLL_CALL_INFO (coll %d) for FS %s\n[Probe %u, %s]\n\n",
121            xstat_fs_Results.collectionNumber,
122            xstat_fs_Results.connP->hostName, xstat_fs_Results.probeNum,
123            printableTime);
124
125     if (debugging_on)
126         printf("\n[%u entries returned at %" AFS_PTR_FMT "]\n\n", numInt32s, currInt32);
127
128     for (i = 0; i < numInt32s; i++)
129         printf("%u ", *currInt32++);
130     printf("\n");
131
132 }                               /*PrintCallInfo */
133
134
135 /*------------------------------------------------------------------------
136  * PrintOverallPerfInfo
137  *
138  * Description:
139  *      Print out overall performance numbers.
140  *
141  * Arguments:
142  *      a_ovP : Ptr to the overall performance numbers.
143  *
144  * Returns:
145  *      Nothing.
146  *
147  * Environment:
148  *      Nothing interesting.
149  *
150  * Side Effects:
151  *      As advertised.
152  *------------------------------------------------------------------------*/
153
154 void
155 PrintOverallPerfInfo(struct afs_PerfStats *a_ovP)
156 {
157     printf("\t%10u numPerfCalls\n\n", a_ovP->numPerfCalls);
158
159     /*
160      * Vnode cache section.
161      */
162     printf("\t%10u vcache_L_Entries\n", a_ovP->vcache_L_Entries);
163     printf("\t%10u vcache_L_Allocs\n", a_ovP->vcache_L_Allocs);
164     printf("\t%10u vcache_L_Gets\n", a_ovP->vcache_L_Gets);
165     printf("\t%10u vcache_L_Reads\n", a_ovP->vcache_L_Reads);
166     printf("\t%10u vcache_L_Writes\n\n", a_ovP->vcache_L_Writes);
167
168     printf("\t%10u vcache_S_Entries\n", a_ovP->vcache_S_Entries);
169     printf("\t%10u vcache_S_Allocs\n", a_ovP->vcache_S_Allocs);
170     printf("\t%10u vcache_S_Gets\n", a_ovP->vcache_S_Gets);
171     printf("\t%10u vcache_S_Reads\n", a_ovP->vcache_S_Reads);
172     printf("\t%10u vcache_S_Writes\n\n", a_ovP->vcache_S_Writes);
173
174     printf("\t%10u vcache_H_Entries\n", a_ovP->vcache_H_Entries);
175     printf("\t%10u vcache_H_Gets\n", a_ovP->vcache_H_Gets);
176     printf("\t%10u vcache_H_Replacements\n\n", a_ovP->vcache_H_Replacements);
177
178     /*
179      * Directory package section.
180      */
181     printf("\t%10u dir_Buffers\n", a_ovP->dir_Buffers);
182     printf("\t%10u dir_Calls\n", a_ovP->dir_Calls);
183     printf("\t%10u dir_IOs\n\n", a_ovP->dir_IOs);
184
185     /*
186      * Rx section.
187      */
188     printf("\t%10u rx_packetRequests\n", a_ovP->rx_packetRequests);
189     printf("\t%10u rx_noPackets_RcvClass\n", a_ovP->rx_noPackets_RcvClass);
190     printf("\t%10u rx_noPackets_SendClass\n", a_ovP->rx_noPackets_SendClass);
191     printf("\t%10u rx_noPackets_SpecialClass\n",
192            a_ovP->rx_noPackets_SpecialClass);
193     printf("\t%10u rx_socketGreedy\n", a_ovP->rx_socketGreedy);
194     printf("\t%10u rx_bogusPacketOnRead\n", a_ovP->rx_bogusPacketOnRead);
195     printf("\t%10u rx_bogusHost\n", a_ovP->rx_bogusHost);
196     printf("\t%10u rx_noPacketOnRead\n", a_ovP->rx_noPacketOnRead);
197     printf("\t%10u rx_noPacketBuffersOnRead\n",
198            a_ovP->rx_noPacketBuffersOnRead);
199     printf("\t%10u rx_selects\n", a_ovP->rx_selects);
200     printf("\t%10u rx_sendSelects\n", a_ovP->rx_sendSelects);
201     printf("\t%10u rx_packetsRead_RcvClass\n",
202            a_ovP->rx_packetsRead_RcvClass);
203     printf("\t%10u rx_packetsRead_SendClass\n",
204            a_ovP->rx_packetsRead_SendClass);
205     printf("\t%10u rx_packetsRead_SpecialClass\n",
206            a_ovP->rx_packetsRead_SpecialClass);
207     printf("\t%10u rx_dataPacketsRead\n", a_ovP->rx_dataPacketsRead);
208     printf("\t%10u rx_ackPacketsRead\n", a_ovP->rx_ackPacketsRead);
209     printf("\t%10u rx_dupPacketsRead\n", a_ovP->rx_dupPacketsRead);
210     printf("\t%10u rx_spuriousPacketsRead\n", a_ovP->rx_spuriousPacketsRead);
211     printf("\t%10u rx_packetsSent_RcvClass\n",
212            a_ovP->rx_packetsSent_RcvClass);
213     printf("\t%10u rx_packetsSent_SendClass\n",
214            a_ovP->rx_packetsSent_SendClass);
215     printf("\t%10u rx_packetsSent_SpecialClass\n",
216            a_ovP->rx_packetsSent_SpecialClass);
217     printf("\t%10u rx_ackPacketsSent\n", a_ovP->rx_ackPacketsSent);
218     printf("\t%10u rx_pingPacketsSent\n", a_ovP->rx_pingPacketsSent);
219     printf("\t%10u rx_abortPacketsSent\n", a_ovP->rx_abortPacketsSent);
220     printf("\t%10u rx_busyPacketsSent\n", a_ovP->rx_busyPacketsSent);
221     printf("\t%10u rx_dataPacketsSent\n", a_ovP->rx_dataPacketsSent);
222     printf("\t%10u rx_dataPacketsReSent\n", a_ovP->rx_dataPacketsReSent);
223     printf("\t%10u rx_dataPacketsPushed\n", a_ovP->rx_dataPacketsPushed);
224     printf("\t%10u rx_ignoreAckedPacket\n", a_ovP->rx_ignoreAckedPacket);
225     printf("\t%10u rx_totalRtt_Sec\n", a_ovP->rx_totalRtt_Sec);
226     printf("\t%10u rx_totalRtt_Usec\n", a_ovP->rx_totalRtt_Usec);
227     printf("\t%10u rx_minRtt_Sec\n", a_ovP->rx_minRtt_Sec);
228     printf("\t%10u rx_minRtt_Usec\n", a_ovP->rx_minRtt_Usec);
229     printf("\t%10u rx_maxRtt_Sec\n", a_ovP->rx_maxRtt_Sec);
230     printf("\t%10u rx_maxRtt_Usec\n", a_ovP->rx_maxRtt_Usec);
231     printf("\t%10u rx_nRttSamples\n", a_ovP->rx_nRttSamples);
232     printf("\t%10u rx_nServerConns\n", a_ovP->rx_nServerConns);
233     printf("\t%10u rx_nClientConns\n", a_ovP->rx_nClientConns);
234     printf("\t%10u rx_nPeerStructs\n", a_ovP->rx_nPeerStructs);
235     printf("\t%10u rx_nCallStructs\n", a_ovP->rx_nCallStructs);
236     printf("\t%10u rx_nFreeCallStructs\n", a_ovP->rx_nFreeCallStructs);
237     printf("\t%10u rx_nBusies\n\n", a_ovP->rx_nBusies);
238
239     printf("\t%10u fs_nBusies\n", a_ovP->fs_nBusies);
240     printf("\t%10u fs_GetCapabilities\n\n", a_ovP->fs_nGetCaps);
241     /*
242      * Host module fields.
243      */
244     printf("\t%10u host_NumHostEntries\n", a_ovP->host_NumHostEntries);
245     printf("\t%10u host_HostBlocks\n", a_ovP->host_HostBlocks);
246     printf("\t%10u host_NonDeletedHosts\n", a_ovP->host_NonDeletedHosts);
247     printf("\t%10u host_HostsInSameNetOrSubnet\n",
248            a_ovP->host_HostsInSameNetOrSubnet);
249     printf("\t%10u host_HostsInDiffSubnet\n", a_ovP->host_HostsInDiffSubnet);
250     printf("\t%10u host_HostsInDiffNetwork\n",
251            a_ovP->host_HostsInDiffNetwork);
252     printf("\t%10u host_NumClients\n", a_ovP->host_NumClients);
253     printf("\t%10u host_ClientBlocks\n\n", a_ovP->host_ClientBlocks);
254
255     printf("\t%10u sysname_ID\n", a_ovP->sysname_ID);
256 }
257
258
259 /*------------------------------------------------------------------------
260  * PrintOpTiming
261  *
262  * Description:
263  *      Print out the contents of an RPC op timing structure.
264  *
265  * Arguments:
266  *      a_opIdx   : Index of the AFS operation we're printing number on.
267  *      a_opTimeP : Ptr to the op timing structure to print.
268  *
269  * Returns:
270  *      Nothing.
271  *
272  * Environment:
273  *      Nothing interesting.
274  *
275  * Side Effects:
276  *      As advertised.
277  *------------------------------------------------------------------------*/
278
279 void
280 PrintOpTiming(int a_opIdx, struct fs_stats_opTimingData *a_opTimeP)
281 {
282     printf
283         ("%15s: %u ops (%u OK); sum=%lu.%06lu, sqr=%lu.%06lu, min=%lu.%06lu, max=%lu.%06lu\n",
284          opNames[a_opIdx], a_opTimeP->numOps, a_opTimeP->numSuccesses,
285          (long)a_opTimeP->sumTime.tv_sec, (long)a_opTimeP->sumTime.tv_usec,
286          (long)a_opTimeP->sqrTime.tv_sec, (long)a_opTimeP->sqrTime.tv_usec,
287          (long)a_opTimeP->minTime.tv_sec, (long)a_opTimeP->minTime.tv_usec,
288          (long)a_opTimeP->maxTime.tv_sec, (long)a_opTimeP->maxTime.tv_usec);
289 }
290
291
292 /*------------------------------------------------------------------------
293  * PrintXferTiming
294  *
295  * Description:
296  *      Print out the contents of a data transfer structure.
297  *
298  * Arguments:
299  *      a_opIdx : Index of the AFS operation we're printing number on.
300  *      a_xferP : Ptr to the data transfer structure to print.
301  *
302  * Returns:
303  *      Nothing.
304  *
305  * Environment:
306  *      Nothing interesting.
307  *
308  * Side Effects:
309  *      As advertised.
310  *------------------------------------------------------------------------*/
311
312 void
313 PrintXferTiming(int a_opIdx, struct fs_stats_xferData *a_xferP)
314 {
315     printf
316         ("%s: %u xfers (%u OK), time sum=%lu.%06lu, sqr=%lu.%06lu, min=%lu.%06lu, max=%lu.%06lu\n",
317          xferOpNames[a_opIdx], a_xferP->numXfers, a_xferP->numSuccesses,
318          (long)a_xferP->sumTime.tv_sec, (long)a_xferP->sumTime.tv_usec,
319          (long)a_xferP->sqrTime.tv_sec, (long)a_xferP->sqrTime.tv_usec,
320          (long)a_xferP->minTime.tv_sec, (long)a_xferP->minTime.tv_usec,
321          (long)a_xferP->maxTime.tv_sec, (long)a_xferP->maxTime.tv_usec);
322     printf("\t[bytes: sum=%u, min=%u, max=%u]\n", a_xferP->sumBytes,
323            a_xferP->minBytes, a_xferP->maxBytes);
324     printf
325         ("\t[buckets: 0: %u, 1: %u, 2: %u, 3: %u, 4: %u, 5: %u, 6: %u, 7: %u, 8: %u]\n",
326          a_xferP->count[0], a_xferP->count[1], a_xferP->count[2],
327          a_xferP->count[3], a_xferP->count[4], a_xferP->count[5],
328          a_xferP->count[6], a_xferP->count[7], a_xferP->count[8]);
329 }
330
331
332 /*------------------------------------------------------------------------
333  * PrintDetailedPerfInfo
334  *
335  * Description:
336  *      Print out a set of detailed performance numbers.
337  *
338  * Arguments:
339  *      a_detP : Ptr to detailed perf numbers to print.
340  *
341  * Returns:
342  *      Nothing.
343  *
344  * Environment:
345  *      Nothing interesting.
346  *
347  * Side Effects:
348  *      As advertised.
349  *------------------------------------------------------------------------*/
350
351 void
352 PrintDetailedPerfInfo(struct fs_stats_DetailedStats *a_detP)
353 {
354     int currIdx;                /*Loop variable */
355
356     printf("\t%10lu epoch\n", (long) a_detP->epoch.tv_sec);
357
358     for (currIdx = 0; currIdx < FS_STATS_NUM_RPC_OPS; currIdx++)
359         PrintOpTiming(currIdx, &(a_detP->rpcOpTimes[currIdx]));
360
361     for (currIdx = 0; currIdx < FS_STATS_NUM_XFER_OPS; currIdx++)
362         PrintXferTiming(currIdx, &(a_detP->xferOpTimes[currIdx]));
363 }
364
365
366 /*------------------------------------------------------------------------
367  * PrintFullPerfInfo
368  *
369  * Description:
370  *      Print out the AFS_XSTATSCOLL_FULL_PERF_INFO collection we just
371  *      received.
372  *
373  * Arguments:
374  *      None.
375  *
376  * Returns:
377  *      Nothing.
378  *
379  * Environment:
380  *      All the info we need is nestled into xstat_fs_Results.
381  *
382  * Side Effects:
383  *      As advertised.
384  *------------------------------------------------------------------------*/
385
386 void
387 PrintFullPerfInfo(void)
388 {
389
390     static afs_int32 fullPerfInt32s = (sizeof(struct fs_stats_FullPerfStats) >> 2);     /*Correct # int32s to rcv */
391     afs_int32 numInt32s;        /*# int32words received */
392     struct fs_stats_FullPerfStats *fullPerfP;   /*Ptr to full perf stats */
393     char *printableTime;        /*Ptr to printable time
394                                  * string */
395     time_t probeTime = xstat_fs_Results.probeTime;
396
397     numInt32s = xstat_fs_Results.data.AFS_CollData_len;
398     if (numInt32s != fullPerfInt32s) {
399         printf("** Data size mismatch in full performance collection!");
400         printf("** Expecting %u, got %u\n", fullPerfInt32s, numInt32s);
401         return;
402     }
403
404     printableTime = ctime(&probeTime);
405     printableTime[strlen(printableTime) - 1] = '\0';
406     fullPerfP = (struct fs_stats_FullPerfStats *)
407         (xstat_fs_Results.data.AFS_CollData_val);
408
409     printf
410         ("AFS_XSTATSCOLL_FULL_PERF_INFO (coll %d) for FS %s\n[Probe %u, %s]\n\n",
411          xstat_fs_Results.collectionNumber, xstat_fs_Results.connP->hostName,
412          xstat_fs_Results.probeNum, printableTime);
413
414     PrintOverallPerfInfo(&(fullPerfP->overall));
415     PrintDetailedPerfInfo(&(fullPerfP->det));
416 }
417
418
419 /*------------------------------------------------------------------------
420  * PrintPerfInfo
421  *
422  * Description:
423  *      Print out the AFS_XSTATSCOLL_PERF_INFO collection we just
424  *      received.
425  *
426  * Arguments:
427  *      None.
428  *
429  * Returns:
430  *      Nothing.
431  *
432  * Environment:
433  *      All the info we need is nestled into xstat_fs_Results.
434  *
435  * Side Effects:
436  *      As advertised.
437  *------------------------------------------------------------------------*/
438
439 void
440 PrintPerfInfo(void)
441 {
442     static afs_int32 perfInt32s = (sizeof(struct afs_PerfStats) >> 2);  /*Correct # int32s to rcv */
443     afs_int32 numInt32s;        /*# int32words received */
444     struct afs_PerfStats *perfP;        /*Ptr to performance stats */
445     char *printableTime;        /*Ptr to printable time string */
446     time_t probeTime = xstat_fs_Results.probeTime;
447
448     numInt32s = xstat_fs_Results.data.AFS_CollData_len;
449     if (numInt32s != perfInt32s) {
450         printf("** Data size mismatch in performance collection!");
451         printf("** Expecting %u, got %u\n", perfInt32s, numInt32s);
452         return;
453     }
454
455     printableTime = ctime(&probeTime);
456     printableTime[strlen(printableTime) - 1] = '\0';
457     perfP = (struct afs_PerfStats *)
458         (xstat_fs_Results.data.AFS_CollData_val);
459
460     printf("AFS_XSTATSCOLL_PERF_INFO (coll %d) for FS %s\n[Probe %u, %s]\n\n",
461            xstat_fs_Results.collectionNumber,
462            xstat_fs_Results.connP->hostName, xstat_fs_Results.probeNum,
463            printableTime);
464
465     PrintOverallPerfInfo(perfP);
466 }
467
468 static char *CbCounterStrings[] = {
469     "DeleteFiles",
470     "DeleteCallBacks",
471     "BreakCallBacks",
472     "AddCallBack",
473     "GotSomeSpaces",
474     "DeleteAllCallBacks",
475     "nFEs", "nCBs", "nblks",
476     "CBsTimedOut",
477     "nbreakers",
478     "GSS1", "GSS2", "GSS3", "GSS4", "GSS5"
479 };
480
481
482 void
483 PrintCbCounters(void) {
484     int numInt32s = sizeof(CbCounterStrings)/sizeof(char *);
485     int i;
486     afs_int32 *val=xstat_fs_Results.data.AFS_CollData_val;
487
488     if (numInt32s > xstat_fs_Results.data.AFS_CollData_len)
489         numInt32s = xstat_fs_Results.data.AFS_CollData_len;
490
491     for (i=0; i<numInt32s; i++) {
492         printf("\t%10u %s\n", val[i], CbCounterStrings[i]);
493     }
494 }
495
496
497 /*------------------------------------------------------------------------
498  * FS_Handler
499  *
500  * Description:
501  *      Handler routine passed to the xstat_fs module.  This handler is
502  *      called immediately after a poll of one of the File Servers has
503  *      taken place.  All it needs to know is exported by the xstat_fs
504  *      module, namely the data structure where the probe results are
505  *      stored.
506  *
507  * Arguments:
508  *      None.
509  *
510  * Returns:
511  *      0 on success,
512  *      -1 otherwise.
513  *
514  * Environment:
515  *      See above.  All we do now is print out what we got.
516  *
517  * Side Effects:
518  *      As advertised.
519  *------------------------------------------------------------------------*/
520
521 int
522 FS_Handler(void)
523 {
524     static char rn[] = "FS_Handler";    /*Routine name */
525
526     printf
527         ("\n------------------------------------------------------------\n");
528
529     /*
530      * If the probe failed, there isn't much we can do except gripe.
531      */
532     if (xstat_fs_Results.probeOK) {
533         printf("%s: Probe %u to File Server '%s' failed, code=%d\n", rn,
534                xstat_fs_Results.probeNum, xstat_fs_Results.connP->hostName,
535                xstat_fs_Results.probeOK);
536         return (0);
537     }
538
539     switch (xstat_fs_Results.collectionNumber) {
540     case AFS_XSTATSCOLL_CALL_INFO:
541         PrintCallInfo();
542         break;
543
544     case AFS_XSTATSCOLL_PERF_INFO:
545         PrintPerfInfo();
546         break;
547
548     case AFS_XSTATSCOLL_FULL_PERF_INFO:
549         PrintFullPerfInfo();
550         break;
551
552     case AFS_XSTATSCOLL_CBSTATS:
553         PrintCbCounters();
554         break;
555
556     default:
557         printf("** Unknown collection: %d\n",
558                xstat_fs_Results.collectionNumber);
559     }
560
561     /*
562      * Return the happy news.
563      */
564     return (0);
565 }
566
567
568 /*------------------------------------------------------------------------
569  * CountListItems
570  *
571  * Description:
572  *      Given a pointer to the list of File Servers we'll be polling
573  *      (or, in fact, any list at all), compute the length of the list.
574  *
575  * Arguments:
576  *      struct cmd_item *a_firstItem : Ptr to first item in list.
577  *
578  * Returns:
579  *      Length of the above list.
580  *
581  * Environment:
582  *      Nothing interesting.
583  *
584  * Side Effects:
585  *      As advertised.
586  *------------------------------------------------------------------------*/
587
588 static int
589 CountListItems(struct cmd_item *a_firstItem)
590 {
591
592     int list_len;               /*List length */
593     struct cmd_item *curr_item; /*Ptr to current item */
594
595     list_len = 0;
596     curr_item = a_firstItem;
597
598     /*
599      * Count 'em up.
600      */
601     while (curr_item) {
602         list_len++;
603         curr_item = curr_item->next;
604     }
605
606     /*
607      * Return our tally.
608      */
609     return (list_len);
610 }
611
612
613 /*------------------------------------------------------------------------
614  * RunTheTest
615  *
616  * Description:
617  *      Routine called by the command line interpreter to execute the
618  *      meat of the program.  We count the number of File Servers
619  *      to watch, allocate enough space to remember all the connection
620  *      info for them, then go for it.
621  *
622  *
623  * Arguments:
624  *      a_s : Ptr to the command line syntax descriptor.
625  *
626  * Returns:
627  *      0, but may exit the whole program on an error!
628  *
629  * Environment:
630  *      Nothing interesting.
631  *
632  * Side Effects:
633  *      As advertised.
634  *------------------------------------------------------------------------*/
635
636 int
637 RunTheTest(struct cmd_syndesc *a_s, void *dummy)
638 {
639     static char rn[] = "RunTheTest";    /*Routine name */
640     int code;                   /*Return code */
641     int numFSs;                 /*# File Servers to monitor */
642     int numCollIDs;             /*# collections to fetch */
643     int currFS;                 /*Loop index */
644     int currCollIDIdx;          /*Index of current collection ID */
645     afs_int32 *collIDP;         /*Ptr to array of collection IDs */
646     afs_int32 *currCollIDP;     /*Ptr to current collection ID */
647     struct cmd_item *curr_item; /*Current FS cmd line record */
648     struct sockaddr_in FSSktArray[20];  /*File Server socket array - FIX! */
649     struct hostent *he;         /*Host entry */
650     struct timeval tv;          /*Time structure */
651     int sleep_secs;             /*Number of seconds to sleep */
652     int initFlags;              /*Flags passed to the init fcn */
653     int waitCode;               /*Result of LWP_WaitProcess() */
654     int freq;                   /*Frequency of polls */
655     int period;                 /*Time in minutes of data collection */
656
657     /*
658      * Are we doing one-shot measurements?
659      */
660     if (a_s->parms[P_ONESHOT].items != 0)
661         one_shot = 1;
662
663     /*
664      * Are we doing debugging output?
665      */
666     if (a_s->parms[P_DEBUG].items != 0)
667         debugging_on = 1;
668
669     /*
670      * Pull out the number of File Servers to watch and the number of
671      * collections to get.
672      */
673     numFSs = CountListItems(a_s->parms[P_FS_NAMES].items);
674     numCollIDs = CountListItems(a_s->parms[P_COLL_IDS].items);
675
676     /* Get the polling frequency */
677     if (a_s->parms[P_FREQUENCY].items != 0)
678         freq = atoi(a_s->parms[P_FREQUENCY].items->data);
679     else
680         freq = 30;              /* default to 30 seconds */
681
682     /* Get the time duration to run the tests */
683     if (a_s->parms[P_PERIOD].items != 0)
684         period = atoi(a_s->parms[P_PERIOD].items->data);
685     else
686         period = 10;            /* default to 10 minutes */
687
688
689     /*
690      * Fill in the socket array for each of the File Servers listed.
691      */
692     curr_item = a_s->parms[P_FS_NAMES].items;
693     for (currFS = 0; currFS < numFSs; currFS++) {
694         FSSktArray[currFS].sin_family = AF_INET;
695         FSSktArray[currFS].sin_port = htons(7000);      /* FileServer port */
696         he = hostutil_GetHostByName(curr_item->data);
697         if (he == NULL) {
698             fprintf(stderr, "[%s] Can't get host info for '%s'\n", rn,
699                     curr_item->data);
700             exit(-1);
701         }
702         memcpy(&(FSSktArray[currFS].sin_addr.s_addr), he->h_addr, 4);
703
704         /*
705          * Move to the next File Server name.
706          */
707         curr_item = curr_item->next;
708
709     }                           /*Get socket info for each File Server */
710
711     /*
712      * Create and fill up the array of desired collection IDs.
713      */
714     if (debugging_on)
715         printf("Allocating %d long(s) for coll ID\n", numCollIDs);
716     collIDP = (afs_int32 *) (malloc(numCollIDs * sizeof(afs_int32)));
717     currCollIDP = collIDP;
718     curr_item = a_s->parms[P_COLL_IDS].items;
719     for (currCollIDIdx = 0; currCollIDIdx < numCollIDs; currCollIDIdx++) {
720         *currCollIDP = (afs_int32) (atoi(curr_item->data));
721         if (debugging_on)
722             printf("CollID at index %d is %d\n", currCollIDIdx, *currCollIDP);
723         curr_item = curr_item->next;
724         currCollIDP++;
725     };
726
727     /*
728      * Crank up the File Server prober, then sit back and have fun.
729      */
730     printf("\nStarting up the xstat_fs service, ");
731     initFlags = 0;
732     if (debugging_on) {
733         initFlags |= XSTAT_FS_INITFLAG_DEBUGGING;
734         printf("debugging enabled, ");
735     } else
736         printf("no debugging, ");
737     if (one_shot) {
738         initFlags |= XSTAT_FS_INITFLAG_ONE_SHOT;
739         printf("one-shot operation\n");
740     } else
741         printf("continuous operation\n");
742
743     code = xstat_fs_Init(numFSs,        /*Num servers */
744                          FSSktArray,    /*File Server socket array */
745                          freq,  /*Probe frequency */
746                          FS_Handler,    /*Handler routine */
747                          initFlags,     /*Initialization flags */
748                          numCollIDs,    /*Number of collection IDs */
749                          collIDP);      /*Ptr to collection ID array */
750     if (code) {
751         fprintf(stderr, "[%s] Error returned by xstat_fs_Init: %d\n", rn,
752                 code);
753         xstat_fs_Cleanup(1);    /*Get rid of malloc'ed structures */
754         exit(-1);
755     }
756
757     if (one_shot) {
758         /*
759          * One-shot operation; just wait for the collection to be done.
760          */
761         if (debugging_on)
762             printf("[%s] Calling LWP_WaitProcess() on event %" AFS_PTR_FMT "\n", rn,
763                    &terminationEvent);
764         waitCode = LWP_WaitProcess(&terminationEvent);
765         if (debugging_on)
766             printf("[%s] Returned from LWP_WaitProcess()\n", rn);
767         if (waitCode) {
768             if (debugging_on)
769                 fprintf(stderr,
770                         "[%s] Error %d encountered by LWP_WaitProcess()\n",
771                         rn, waitCode);
772         }
773     } else {
774         /*
775          * Continuous operation.
776          */
777         sleep_secs = 60 * period;       /*length of data collection */
778         printf
779             ("xstat_fs service started, main thread sleeping for %d secs.\n",
780              sleep_secs);
781
782         /*
783          * Let's just fall asleep for a while, then we'll clean up.
784          */
785         tv.tv_sec = sleep_secs;
786         tv.tv_usec = 0;
787         code = IOMGR_Select(0,  /*Num fds */
788                             0,  /*Descriptors ready for reading */
789                             0,  /*Descriptors ready for writing */
790                             0,  /*Descriptors with exceptional conditions */
791                             &tv);       /*Timeout structure */
792         if (code) {
793             fprintf(stderr,
794                     "[%s] IOMGR_Select() returned non-zero value: %d\n", rn,
795                     code);
796         }
797     }
798
799     /*
800      * We're all done.  Clean up, put the last nail in Rx, then
801      * exit happily.
802      */
803     if (debugging_on)
804         printf("\nYawn, main thread just woke up.  Cleaning things out...\n");
805
806     code = xstat_fs_Cleanup(1); /*Get rid of malloc'ed data */
807     rx_Finalize();
808     return (0);
809 }
810
811
812 #include "AFS_component_version_number.c"
813
814 int
815 main(int argc, char **argv)
816 {
817     static char rn[] = "xstat_fs_test"; /*Routine name */
818     afs_int32 code;     /*Return code */
819     struct cmd_syndesc *ts;     /*Ptr to cmd line syntax desc */
820
821     /*
822      * Set up the commands we understand.
823      */
824     ts = cmd_CreateSyntax("initcmd", RunTheTest, 0, "initialize the program");
825     cmd_AddParm(ts, "-fsname", CMD_LIST, CMD_REQUIRED,
826                 "File Server name(s) to monitor");
827     cmd_AddParm(ts, "-collID", CMD_LIST, CMD_REQUIRED,
828                 "Collection(s) to fetch");
829     cmd_AddParm(ts, "-onceonly", CMD_FLAG, CMD_OPTIONAL,
830                 "Collect results exactly once, then quit");
831     cmd_AddParm(ts, "-frequency", CMD_SINGLE, CMD_OPTIONAL,
832                 "poll frequency, in seconds");
833     cmd_AddParm(ts, "-period", CMD_SINGLE, CMD_OPTIONAL,
834                 "data collection time, in minutes");
835     cmd_AddParm(ts, "-debug", CMD_FLAG, CMD_OPTIONAL,
836                 "turn on debugging output");
837
838     /*
839      * Parse command-line switches & execute the test, then get the
840      * heck out of here.
841      */
842     code = cmd_Dispatch(argc, argv);
843     if (code) {
844         fprintf(stderr, "[%s] Call to cmd_Dispatch() failed; code is %d\n",
845                 rn, code);
846     }
847
848     exit(code);
849 }