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
11 * Scout: A quick and (semi-)dirty attempt at the old CMU vopcon.
12 *------------------------------------------------------------------------*/
14 #include <afsconfig.h>
15 #include <afs/param.h>
26 #include <gtxwindows.h> /*Generic window package */
27 #include <gtxobjects.h> /*Object definitions */
28 #include <gtxtextobj.h> /*Text object interface */
29 #include <gtxlightobj.h> /*Light object interface */
30 #include <gtxcurseswin.h> /*Curses window package */
31 #include <gtxdumbwin.h> /*Dumb terminal window package */
32 #include <gtxX11win.h> /*X11 window package */
33 #include <gtxframe.h> /*Frame package */
35 #include <stdio.h> /*Standard I/O stuff */
36 #include <cmd.h> /*Command interpretation library */
37 #include <fsprobe.h> /*Interface for fsprobe module */
39 #include <afs/afsutil.h>
43 * Command line parameter indicies.
56 * Define the width in chars for each light object on the mini-line.
58 #define LIGHTOBJ_CONN_WIDTH 5
59 #define LIGHTOBJ_FETCH_WIDTH 10
60 #define LIGHTOBJ_STORE_WIDTH 10
61 #define LIGHTOBJ_WK_WIDTH 5
62 #define LIGHTOBJ_SRVNAME_WIDTH 13
63 #define LIGHTOBJ_DISK_WIDTH 12
66 * Define the types of justification we can perform.
68 #define SCOUT_RIGHT_JUSTIFY 0
69 #define SCOUT_LEFT_JUSTIFY 1
70 #define SCOUT_CENTER 2
73 * Define the types of truncation we can perform.
75 #define SCOUT_LEFT_TRUNC 0
76 #define SCOUT_RIGHT_TRUNC 1
79 * Define whether the value passed is a labeled disk quantity.
81 #define SCOUT_ISNT_LDISK 0
82 #define SCOUT_IS_LDISK 1
85 * We sometimes use index-base pointers, so we need a distinguished
88 #define SCOUT_NIL (-1)
91 * Structure describing everything you want to know about a FileServer
95 int prev; /*Index of previous list entry */
96 int next; /*Index of next list entry */
97 int active; /*Is this disk known to exist? */
98 char *name; /*Single-letter disk name */
99 struct onode *disk_lp; /*Ptr to disk light object */
103 * Structure defining all the objects in the Scout line (or lines)
104 * for each server being watched. Note that scout_disk linked list
105 * for used disks is ordered alphabetically.
109 * Information on server location & configuration.
111 struct sockaddr_in skt; /*Server's socket info */
112 int numDisks; /*Number of disks used */
114 * Screen location info.
116 int base_line; /*Line number on the screen */
117 int num_lines; /*Number of lines of info */
119 * Associated light objects.
121 struct onode *currConns_lp; /*Number of current connections */
122 struct onode *fetches_lp; /*Number of data fetches */
123 struct onode *stores_lp; /*Number of data stores */
124 struct onode *workstations_lp; /*Workstation info */
125 struct onode *srvName_lp; /*Server name */
126 struct scout_disk disks[VOLMAXPARTS]; /*Info on all the disks */
127 int used_head; /*Index of first used disk struct */
128 int used_tail; /*Index of last used disk struct */
129 int free_head; /*Index of first free disk struct */
130 int free_tail; /*Index of last free disk struct */
134 * Structure defining the contents of the Scout screen.
137 int numServers; /*Number of servers being watched */
138 int base_line_num; /*Base mini-line number */
139 struct mini_line *line; /*Array of screen lines */
142 static char pn[] = "scout"; /*Program name */
143 static int scout_debug = 0; /*Is debugging turned on? */
144 static FILE *scout_debugfd; /*Debugging file descriptor */
145 static int scout_gtx_initialized = 0; /*Has gtx been initialized? */
146 static struct mini_screen scout_screen; /*Mini-screen itself */
147 static int scout_probefreq; /*Probe frequency in seconds */
148 static char scout_basename[64]; /*Base server name */
149 static char scout_hostname[128]; /*Name of machine we're running on */
150 static int scout_showhostname = 0; /*Show name of machine we're on? */
151 static char scout_blankline[256]; /*Blank line */
152 static struct gwin *scout_gwin; /*Window to use */
153 static struct gtx_frame *scout_frame; /*Frame to use */
154 static struct onode *scout_banner0_lp; /*Banner light, line 0 */
155 static struct onode *scout_banner1_lp; /*Banner light, line 1 */
156 static struct onode *scout_banner2_lp; /*Banner light, line 2 */
157 static int scout_DiskLightLeftCol = 0; /*Column for leftmost disk light */
158 static struct gwin_sizeparams scout_frameDims; /*Frame dimensions */
161 * Attention thresholds & modes.
163 #define SCOUT_ATTN_NOTUSED (-1)
164 #define SCOUT_DISKM_PCUSED 0
165 #define SCOUT_DISKM_MINFREE 1
167 static int scout_attn_conn = SCOUT_ATTN_NOTUSED;
168 static int scout_attn_fetch = SCOUT_ATTN_NOTUSED;
169 static int scout_attn_store = SCOUT_ATTN_NOTUSED;
170 static int scout_attn_workstations = SCOUT_ATTN_NOTUSED;
171 static int scout_attn_disk_mode = SCOUT_DISKM_PCUSED;
172 static int scout_attn_disk_minfree = 1000;
173 static float scout_attn_disk_pcused = 0.95;
174 static char scout_attn_disk_pcusedstr[8] = "95";
177 * Some strings we'll be using over and over again.
179 static char scout_Banner[256];
180 static char scout_LightLabels[] =
181 "Conn Fetch Store Ws Disk attn:";
182 static char scout_LightLabelUnd[] =
183 "---- -------- -------- ----- ----------";
186 /*------------------------------------------------------------------------
190 * Exits cleanly from the Scout. If gtx has not yet been initialized,
191 * then we simply call exit() with the value provided. Otherwise,
192 * we call the appropriate gtx routine to exit cleanly from gtx, which
193 * must reset the terminal or window. We also close the debugging
194 * file descriptor, if one has been opened.
197 * int a_exitval : Value with which to exit the program.
203 * Actions depend on scout_gtx_initialized.
206 * This routine will always exit Scout.
207 *------------------------------------------------------------------------*/
210 scout_CleanExit(int a_exitval)
211 { /*scout_CleanExit */
213 static char rn[] = "scout_CleanExit"; /*Routine name */
215 if (scout_debugfd != (FILE *) 0) {
216 fprintf(scout_debugfd, "[%s] Closing debugging file\n", rn);
217 fclose(scout_debugfd);
220 if (scout_gtx_initialized) {
221 gtxframe_exitValue = a_exitval;
222 gtxframe_ExitCmd((void *)(>xframe_exitValue), NULL);
226 } /*scout_CleanExit */
228 /*------------------------------------------------------------------------
229 * mini_initLightObject
232 * Create and initialize a light onode according to the given
236 * char *a_name : Ptr to the light's string name.
237 * int a_x : X offset.
238 * int a_y : Y offset.
239 * int a_width : Width in chars.
240 * struct gwin *a_win : Ptr to window structure.
243 * Ptr to new light onode on success,
244 * A null pointer otherwise.
251 *------------------------------------------------------------------------*/
253 static struct onode *
254 mini_initLightObject(char *a_name, int a_x, int a_y, int a_width, struct gwin *a_win)
255 { /*mini_initLightObject */
257 static char rn[] = "mini_initLightObject"; /*Routine name */
258 struct onode *newlightp; /*Ptr to new light onode */
259 /*We only support curses right now */
260 struct gator_light_crparams light_crparams; /*Light creation params */
261 char *truncname; /*Truncated name, if needed */
262 int name_len; /*True length of name */
265 fprintf(scout_debugfd,
266 "[%s] Called for name '%s', [%d, %d], %d-char field\n", rn,
267 a_name, a_x, a_y, a_width);
268 fflush(scout_debugfd);
273 * Set up the creation parameters according to the information we've
276 light_crparams.onode_params.cr_type = GATOR_OBJ_LIGHT;
277 name_len = strlen(a_name);
279 fprintf(scout_debugfd, "[%s] Name '%s' has %d chars\n", rn, a_name,
281 if (name_len <= a_width)
282 sprintf(light_crparams.onode_params.cr_name, "%s", a_name);
285 * We need to truncate the given name, leaving a `*' at the end to
286 * show us it's been truncated.
288 truncname = light_crparams.onode_params.cr_name;
289 strncpy(truncname, a_name, a_width - 1);
290 truncname[a_width - 1] = '*';
291 truncname[a_width] = 0;
293 light_crparams.onode_params.cr_x = a_x;
294 light_crparams.onode_params.cr_y = a_y;
295 light_crparams.onode_params.cr_width = a_width;
296 light_crparams.onode_params.cr_height = 1;
297 light_crparams.onode_params.cr_window = a_win;
298 light_crparams.onode_params.cr_home_obj = NULL;
299 light_crparams.onode_params.cr_prev_obj = NULL;
300 light_crparams.onode_params.cr_parent_obj = NULL;
301 light_crparams.onode_params.cr_helpstring = NULL;
303 light_crparams.appearance = 0;
304 light_crparams.flashfreq = 0;
305 sprintf(light_crparams.label, "%s", a_name);
306 light_crparams.label_x = 0;
307 light_crparams.label_y = 0;
310 gator_objects_create((struct onode_createparams *)(&light_crparams));
313 * Return the news, happy or not.
317 } /*mini_initLightObject */
319 /*------------------------------------------------------------------------
320 * scout_initDiskLightObjects
323 * Create and initialize all Scout light objects for a server's
327 * struct scout_disk *a_line : Ptr to the server object line.
328 * struct gwin *a_win : Ptr to window structure.
339 *------------------------------------------------------------------------*/
342 scout_initDiskLightObjects(struct mini_line *a_line, struct gwin *a_win)
343 { /*scout_initDiskLightObjects */
345 static char rn[] = "scout_initDiskLightObjects"; /*Routine name */
346 struct scout_disk *curr_disk; /*Ptr to current disk being set up */
347 int i; /*Loop variable */
350 fprintf(scout_debugfd, "[%s] Called\n", rn);
351 fflush(scout_debugfd);
355 * Set up the base linked list fields.
357 a_line->used_head = SCOUT_NIL;
358 a_line->used_tail = SCOUT_NIL;
359 a_line->free_head = 0;
360 a_line->free_tail = VOLMAXPARTS - 1;
363 * Sweep through the disk structures, creating the light objects and
364 * marking them all as free.
366 curr_disk = a_line->disks;
367 for (i = 0; i < VOLMAXPARTS; i++) {
369 * Create the disk light object.
371 if ((curr_disk->disk_lp = mini_initLightObject("Disk", /*Object name */
374 LIGHTOBJ_DISK_WIDTH, /*Width */
377 fprintf(stderr, "[%s:%s] Can't create disk %d light object\n", pn,
383 * Set the other fields in the disk records; Note that in the
384 * fencepost cases, the prev and next pointers will have to be
387 curr_disk->prev = i - 1;
388 curr_disk->next = i + 1;
389 curr_disk->active = 0;
390 curr_disk->name = '\0';
393 * Bump up to the next disk structure.
397 } /*for each disk structure */
400 * We made it all the way through. Fix the fencepost pointers, set
401 * the overall pointers, then return success.
403 a_line->disks[0].prev = SCOUT_NIL;
404 a_line->disks[VOLMAXPARTS - 1].next = SCOUT_NIL;
408 } /*scout_initDiskLightObjects */
411 /*------------------------------------------------------------------------
415 * Place the chars in the source buffer into the target buffer
416 * with the desired justification, either centered, left-justified
417 * or right-justified. Also, support inidication of truncation
418 * with a star (*), either on the left or right of the string,
419 * and whether we're justifying a labeled disk quantity.
422 * char *a_srcbuff : Ptr to source char buffer.
423 * char *a_dstbuff : Ptr to dest char buffer.
424 * int a_dstwidth : Width of dest buffer in chars.
425 * int a_justification : Kind of justification.
426 * int a_rightTrunc : If non-zero, place the truncation char
427 * on the right of the string. Otherwise,
428 * place it on the left.
429 * int a_isLabeledDisk : Is this a labeled disk quantity?
436 * All it needs to know is exported by the fsprobe module, namely
437 * the data structure where the probe results are stored.
441 *------------------------------------------------------------------------*/
444 mini_justify(char *a_srcbuff, char *a_dstbuff, int a_dstwidth,
445 int a_justification, int a_rightTrunc,
449 static char rn[] = "mini_justify"; /*Routine name */
450 int leftpad_chars; /*# of chars for left-padding */
451 int num_src_chars; /*# of chars in source */
452 int true_num_src_chars; /*# src chars before truncation */
453 int trunc_needed; /*Is truncation needed? */
454 char diskChar = 0; /*Disk name prefix */
457 fprintf(scout_debugfd, "[%s] Called with '%s', dest width=%d\n", rn,
458 a_srcbuff, a_dstwidth);
459 fflush(scout_debugfd);
463 * Remember the disk label, if we've been passed such a thing.
466 diskChar = *a_srcbuff;
469 * If the destination width will overrun the gtx string storage,
470 * we automatically shorten up.
472 if (a_dstwidth > GATOR_LABEL_CHARS) {
474 fprintf(scout_debugfd,
475 "[%s] Dest width (%d) > gtx buflen (%d), shrinking dest width\n",
476 rn, a_dstwidth, GATOR_LABEL_CHARS);
477 fflush(scout_debugfd);
479 a_dstwidth = GATOR_LABEL_CHARS;
483 * If our source string is too long, prepare for truncation.
485 true_num_src_chars = strlen(a_srcbuff);
486 if (true_num_src_chars >= a_dstwidth) {
488 num_src_chars = a_dstwidth - 1;
491 a_srcbuff += (true_num_src_chars - num_src_chars);
494 num_src_chars = true_num_src_chars;
497 * Compute the necessary left-padding.
499 switch (a_justification) {
501 case SCOUT_RIGHT_JUSTIFY:
502 leftpad_chars = (a_dstwidth - 1) - num_src_chars;
505 case SCOUT_LEFT_JUSTIFY:
507 * This is the really easy one.
513 leftpad_chars = ((a_dstwidth - 1) - num_src_chars) / 2;
517 fprintf(stderr, "[%s] Illegal justification command: %d", rn,
520 } /*Switch on justification type */
524 * Clear out the dest buffer, then place the source string at the
525 * appropriate padding location. Remember to place a string
526 * terminator at the end of the dest buffer, plus whatever truncation
527 * may be needed. If we're left-truncating, we've already shifted
528 * the src buffer appropriately.
530 strncpy(a_dstbuff, scout_blankline, a_dstwidth);
531 strncpy(a_dstbuff + leftpad_chars, a_srcbuff, num_src_chars);
532 *(a_dstbuff + a_dstwidth - 1) = '\0';
535 *(a_dstbuff + a_dstwidth - 2) = '*'; /*Truncate on the right */
537 if (a_isLabeledDisk) {
538 *a_dstbuff = diskChar;
539 *(a_dstbuff + 1) = ':';
540 *(a_dstbuff + 2) = '*'; /*Truncate on the left, disk */
542 *a_dstbuff = '*'; /*Truncate on the left, non-disk */
546 /*Handle truncations */
548 * Return the good news.
554 /*------------------------------------------------------------------------
555 * scout_SetNonDiskLightLine
558 * Given a mini-line and a line number, place all non-disk lights
562 * struct mini_line *a_srvline : Ptr to server descriptor.
563 * int a_linenum : Line number to move to.
569 * The light's location is stored not only in the onode, but in
570 * the light's rock, so we have to change both sets of value.
574 *------------------------------------------------------------------------*/
577 scout_SetNonDiskLightLine(struct mini_line *a_srvline, int a_linenum)
578 { /*scout_SetNonDiskLightLine */
580 struct gator_lightobj *nondisk_lightdata; /*Non-disk light data field */
581 struct gwin_strparams *nondisk_strparams; /*Associated string params */
584 * Do the exact same operation for each non-disk light in the record.
586 a_srvline->currConns_lp->o_y = a_linenum;
588 (struct gator_lightobj *)(a_srvline->currConns_lp->o_data);
589 nondisk_strparams = (struct gwin_strparams *)(nondisk_lightdata->llrock);
590 nondisk_strparams->y = a_linenum;
592 a_srvline->fetches_lp->o_y = a_linenum;
594 (struct gator_lightobj *)(a_srvline->fetches_lp->o_data);
595 nondisk_strparams = (struct gwin_strparams *)(nondisk_lightdata->llrock);
596 nondisk_strparams->y = a_linenum;
598 a_srvline->stores_lp->o_y = a_linenum;
600 (struct gator_lightobj *)(a_srvline->stores_lp->o_data);
601 nondisk_strparams = (struct gwin_strparams *)(nondisk_lightdata->llrock);
602 nondisk_strparams->y = a_linenum;
604 a_srvline->workstations_lp->o_y = a_linenum;
606 (struct gator_lightobj *)(a_srvline->workstations_lp->o_data);
607 nondisk_strparams = (struct gwin_strparams *)(nondisk_lightdata->llrock);
608 nondisk_strparams->y = a_linenum;
610 a_srvline->srvName_lp->o_y = a_linenum;
612 (struct gator_lightobj *)(a_srvline->srvName_lp->o_data);
613 nondisk_strparams = (struct gwin_strparams *)(nondisk_lightdata->llrock);
614 nondisk_strparams->y = a_linenum;
616 } /*scout_SetNonDiskLightLine */
618 /*------------------------------------------------------------------------
619 * scout_RecomputeLightLocs
622 * Given a pointer to a server record, recompute its disk light
623 * locations (and keep proper track of the number of screen lines
624 * required for the server record).
627 * struct mini_line *a_srvline : Ptr to server descriptor.
630 * 0 if anything went wrong,
631 * else the number of lines used by this server record.
634 * One or more records have joined or left the used light list
635 * for this server. We're not sure which ones, so we recompute
636 * them all. We may also have had a width change in the gtx
637 * frame. The base_line field in the server record is guaranteed
638 * to be correct at this point.
642 *------------------------------------------------------------------------*/
645 scout_RecomputeLightLocs(struct mini_line *a_srvline)
646 { /*scout_RecomputeLightLocs */
648 static char rn[] = "scout_RecomputeLightLocs"; /*Routine name */
649 int lights_per_line; /*# lights/line */
650 int lights_this_line; /*# lights on cur line */
651 int curr_idx; /*Current disk light idx */
652 struct scout_disk *sc_disk; /*Ptr to disk record array */
653 int lines_for_server; /*Num lines in server record */
654 int curr_line; /*Current line being filled */
655 int curr_x; /*Current x value for light */
656 struct gator_lightobj *disk_lightdata; /*Disk light data field */
657 struct gwin_strparams *disk_strparams; /*String params for disk light */
660 fprintf(scout_debugfd, "[%s] Called\n", rn);
661 fflush(scout_debugfd);
665 * If we haven't yet computed the column for the leftmost disk light,
668 if (scout_DiskLightLeftCol == 0)
669 scout_DiskLightLeftCol =
670 LIGHTOBJ_CONN_WIDTH + LIGHTOBJ_FETCH_WIDTH +
671 LIGHTOBJ_STORE_WIDTH + LIGHTOBJ_WK_WIDTH +
672 LIGHTOBJ_SRVNAME_WIDTH + 5;
675 * Calculate how many disk light objects can fit in one line.
678 (scout_frameDims.maxx -
679 scout_DiskLightLeftCol) / (LIGHTOBJ_DISK_WIDTH + 1);
681 fprintf(scout_debugfd, "[%s] %d lights per line\n", rn,
683 fflush(scout_debugfd);
687 * Sweep through the used disk light list, computing the location
690 lights_this_line = 0;
691 curr_idx = a_srvline->used_head;
692 lines_for_server = 1;
693 curr_line = a_srvline->base_line;
694 curr_x = scout_DiskLightLeftCol;
696 while (curr_idx != SCOUT_NIL) {
698 * Bump the number of lines for the server if we've already
699 * filled up the current line.
701 if (lights_this_line >= lights_per_line) {
702 lights_this_line = 0;
705 curr_x = scout_DiskLightLeftCol;
708 /*Current line filled up */
710 * Set the current disk light's location.
712 sc_disk = a_srvline->disks;
713 sc_disk[curr_idx].disk_lp->o_x = curr_x;
714 sc_disk[curr_idx].disk_lp->o_y = curr_line;
716 (struct gator_lightobj *)(sc_disk[curr_idx].disk_lp->o_data);
717 disk_strparams = (struct gwin_strparams *)(disk_lightdata->llrock);
718 disk_strparams->x = curr_x;
719 disk_strparams->y = curr_line;
721 fprintf(scout_debugfd,
722 "[%s] Disk light at index %d located at [%d, %d]\n", rn,
723 curr_idx, curr_x, curr_line);
724 fflush(scout_debugfd);
728 * Record the inclusion of the light and move on to the next
732 curr_x += LIGHTOBJ_DISK_WIDTH + 1;
733 curr_idx = sc_disk[curr_idx].next;
735 } /*Update each used disk light */
738 * Remember to record the (possibly new) number of lines in the
739 * server record before returning the value of that field.
741 if (a_srvline->num_lines != lines_for_server) {
743 fprintf(scout_debugfd,
744 "[%s] Server previously had %d screen lines; now changed\n",
745 rn, a_srvline->num_lines);
746 fflush(scout_debugfd);
748 a_srvline->num_lines = lines_for_server;
752 fprintf(scout_debugfd, "[%s] Server has %d screen lines\n", rn,
753 a_srvline->num_lines);
754 fflush(scout_debugfd);
756 return (a_srvline->num_lines);
758 } /*scout_RecomputeLightLocs */
760 /*------------------------------------------------------------------------
764 * Given a single-letter disk name and a pointer to the current server
765 * record, look for a used disk record with that name within the server.
766 * If we can't find one, we create and incorporate one, and return that
767 * fact to our caller.
770 * char a_diskname : Single-char disk name.
771 * struct mini_line *a_srvline : Ptr to server descriptor.
772 * int *a_record_added : Was a new record added?
775 * Index of matching used disk record,
776 * SCOUT_NIL otherwise.
778 * Return via parameter:
779 * a_record_added set to 1 iff record was added to the used disk list.
782 * Used disk records are kept in alphabetical order by the single-char
783 * disk name. Should a matching used disk record not be found, one is
784 * pulled from the free pool.
787 * An entry may be pulled off the free list and inserted into the
788 * used list. This entry is placed in the update list for the
789 * current gtx frame (at least not by this routine).
790 *------------------------------------------------------------------------*/
793 scout_FindUsedDisk(char *a_diskname, struct mini_line *a_srvline, int *a_record_added)
794 { /*scout_FindUsedDisk */
796 static char rn[] = "scout_FindUsedDisk"; /*Routine name */
797 int curr_idx; /*Disk record index */
798 int append_idx; /*Index to append after */
799 int new_idx; /*Index of new used record */
800 struct scout_disk *sc_disk; /*Ptr to disk record */
801 int code; /*Function return value */
804 fprintf(scout_debugfd, "[%s] Called\n", rn);
805 fflush(scout_debugfd);
809 * Sweep through the used disk records, looking for a match.
811 curr_idx = a_srvline->used_head;
812 append_idx = SCOUT_NIL;
813 sc_disk = a_srvline->disks;
815 fprintf(scout_debugfd,
816 "[%s] Scanning existing used disk entries for disk '%s'\n",
818 fflush(scout_debugfd);
820 while (curr_idx != SCOUT_NIL) {
822 fprintf(scout_debugfd, "[%s] Disk %d is named '%s'\n", rn,
823 curr_idx, sc_disk[curr_idx].name);
824 fflush(scout_debugfd);
826 if (strcmp(sc_disk[curr_idx].name, a_diskname) == 0) {
828 * We found it! Bug out.
831 fprintf(scout_debugfd, "[%s] Match found\n", rn);
832 fflush(scout_debugfd);
838 * If we are alphabetically past the given disk name, we
839 * know that we won't find it in the used disk list; we
840 * also have the append index set correctly.
842 if (strcmp(a_diskname, sc_disk[curr_idx].name) < 0) {
844 fprintf(scout_debugfd, "[%s] Disk '%s' can't be here\n", rn,
846 fflush(scout_debugfd);
852 * There's still hope we'll find it. Move on to the next used
853 * disk record, keeping this index as the best candidate so far
854 * for appending a missing entry.
856 append_idx = curr_idx;
857 curr_idx = sc_disk[curr_idx].next;
858 } /*Look for match */
861 * We didn't find the record we wanted, which means we'll pull a
862 * record out of the free pool for it. If we didn't find a place
863 * to append it, we then insert it at the beginning of the queue.
865 if (a_srvline->free_head == SCOUT_NIL)
868 new_idx = a_srvline->free_head;
870 fprintf(scout_debugfd, "[%s] Choosing free index %d for new entry\n",
872 fflush(scout_debugfd);
874 a_srvline->free_head = sc_disk[new_idx].next;
875 if (a_srvline->free_head == SCOUT_NIL)
876 a_srvline->free_tail = SCOUT_NIL;
879 * Fill in the new record.
881 sc_disk[new_idx].active = 0;
882 sc_disk[new_idx].name = a_diskname;
885 * Insert the new record where it belongs on the used disk list.
887 if (append_idx == SCOUT_NIL) {
889 * It belongs at the beginning of the list.
892 fprintf(scout_debugfd, "[%s] Inserted at used disk head\n", rn);
893 fflush(scout_debugfd);
895 sc_disk[new_idx].next = a_srvline->used_head;
896 sc_disk[new_idx].prev = SCOUT_NIL;
897 a_srvline->used_head = new_idx;
898 if (a_srvline->used_tail == SCOUT_NIL)
899 a_srvline->used_tail = new_idx;
902 fprintf(scout_debugfd, "[%s] Entry appended after index %d\n", rn,
904 fflush(scout_debugfd);
906 sc_disk[new_idx].prev = append_idx;
907 sc_disk[new_idx].next = sc_disk[append_idx].next;
908 sc_disk[append_idx].next = new_idx;
909 if (sc_disk[new_idx].next == SCOUT_NIL)
910 a_srvline->used_tail = new_idx;
912 sc_disk[sc_disk[new_idx].next].prev = new_idx;
916 * Add the new used disk light object to the display list for
920 fprintf(scout_debugfd,
921 "[%s] Adding disk light at index %d to display list\n", rn,
923 fflush(scout_debugfd);
925 code = gtxframe_AddToList(scout_frame, sc_disk[new_idx].disk_lp);
928 fprintf(scout_debugfd,
929 "[%s] Can't add to display list, code is %d\n", rn, code);
930 fflush(scout_debugfd);
935 } /*scout_FindUsedDisk */
937 /*------------------------------------------------------------------------
938 * scout_RemoveInactiveDisk
941 * Given a server record and a used disk index, remove the disk
942 * record from the used list, put it on the free list, and remove
943 * it from the gtx frame update list.
946 * struct mini_line *a_srvline : Ptr to server descriptor.
947 * int a_used_idx : Index of used disk record.
953 * Formerly-used disk records are returned to the free pool.
956 * Free and used disk record lists are modified for this server.
957 * The disk record in question is pulled off the gtx update list
959 *------------------------------------------------------------------------*/
962 scout_RemoveInactiveDisk(struct mini_line *a_srvline, int a_used_idx)
963 { /*scout_RemoveInactiveDisk */
965 static char rn[] = "scout_RemoveInactiveDisk"; /*Routine name */
968 fprintf(scout_debugfd, "[%s] Called\n", rn);
969 fflush(scout_debugfd);
972 /*code = gtxframe_RemoveFromList(scout_frame->window, lightobj); */
974 } /*scout_RemoveInactiveDisk */
976 /*------------------------------------------------------------------------
977 * mini_PrintDiskStats
980 * Given server indexing and light object information, a pointer
981 * to a set of statistics, and whether the probe that produced these
982 * stats succeeded or not, print out the stats in a nice way.
985 * struct mini_line *a_srvline : Ptr to server descriptor.
986 * struct ProbeViceStatistics *a_stats : Ptr to current stats.
987 * int a_probeOK : Was the probe OK?
988 * int a_width_changed : Has the frame width changed?
989 * int a_fix_line_num : Is the line number wrong?
990 * int a_delta_line_num : Change in line number.
993 * 0 if something went wrong,
994 * else the number of lines taken up by this server record.
997 * Nothing interesting.
1001 *------------------------------------------------------------------------*/
1004 mini_PrintDiskStats(struct mini_line *a_srvline,
1005 struct ProbeViceStatistics *a_stats,
1006 int a_probeOK, int a_width_changed,
1007 int a_fix_line_num, int a_delta_line_num)
1008 { /*mini_PrintDiskStats */
1010 static char rn[] = "mini_PrintDiskStats"; /*Routine name */
1011 int code; /*Return code */
1012 char s[128]; /*String buffer */
1013 struct onode *curr_disklight; /*Ptr to current disk light */
1014 struct onode *srvname_light; /*Ptr to server name light */
1015 ViceDisk *curr_diskstat; /*Ptr to current disk stat */
1016 int curr_disk; /*Current disk stat number */
1017 int used_disk_idx; /*Used disk index */
1018 int next_used_idx; /*Ditto */
1019 int pastthreshold; /*Was disk past threshold? */
1020 struct gator_lightobj *diskdata; /*Private light data */
1021 struct gwin_strparams *disk_strparams; /*String params for disk light */
1022 char *diskname = 0; /*Name of disk */
1023 int found_idx; /*Idx of matching disk */
1024 char *srv_name; /*Server name */
1025 struct scout_disk *sc_disk; /*Ptr to scout disk desc */
1026 int fix_light_locs; /*Recompute disk light locs? */
1029 fprintf(scout_debugfd, "[%s] Called\n", rn);
1030 fflush(scout_debugfd);
1034 * Remember the current server's print name, don't recompute light
1037 srvname_light = a_srvline->srvName_lp;
1038 srv_name = ((struct gator_lightobj *)(srvname_light->o_data))->label;
1041 fprintf(scout_debugfd, "[%s] Value of a_delta_line_num is %d\n", rn,
1043 fflush(scout_debugfd);
1047 * If the probe failed, we simply blank out all the used disk
1048 * objects. Note: a NON-ZERO value of a_probeOK implies failure.
1051 used_disk_idx = a_srvline->used_head;
1052 while (used_disk_idx != SCOUT_NIL) {
1054 * Point to the current used disk's light, blank out its
1055 * contents, and make sure highlighting is turned off. We
1056 * also take this opportunity to fix the line numbers if
1059 curr_disklight = a_srvline->disks[used_disk_idx].disk_lp;
1060 diskdata = (struct gator_lightobj *)(curr_disklight->o_data);
1062 fprintf(scout_debugfd,
1063 "[%s] Prev value of disk light %d: '%s'\n", rn,
1064 used_disk_idx, diskdata->label);
1065 fflush(scout_debugfd);
1067 code = mini_justify(" ", /*Src buffer */
1068 diskdata->label, /*Dest buffer */
1069 LIGHTOBJ_DISK_WIDTH, /*Dest's width */
1070 SCOUT_RIGHT_JUSTIFY, /*Right-justify */
1071 SCOUT_LEFT_TRUNC, /*Left-truncate */
1072 SCOUT_ISNT_LDISK); /*Not a labeled disk */
1073 code = gator_light_set(curr_disklight, 0);
1074 if (a_fix_line_num) {
1075 curr_disklight->o_y += a_delta_line_num;
1076 disk_strparams = (struct gwin_strparams *)(diskdata->llrock);
1077 disk_strparams->y += a_delta_line_num;
1081 * Advance to next used disk, if any.
1083 used_disk_idx = a_srvline->disks[used_disk_idx].next;
1085 } /*Blank out disk name field */
1088 * If the frame width has changed, we have to recompute all disk
1089 * light locations. After that, the number of lines in the server
1090 * record will be accurate, and we return them.
1092 if (a_width_changed)
1093 scout_RecomputeLightLocs(a_srvline);
1095 return (a_srvline->num_lines);
1099 /*Probe failed for the server */
1101 * Probe was successful. Sweep through the statistics records,
1102 * and put up all values having to do with AFS partitions. First,
1103 * mark all used disk objects for this server as inactive and fix
1104 * their line numbers if needed.
1106 sc_disk = a_srvline->disks;
1107 used_disk_idx = a_srvline->used_head;
1108 while (used_disk_idx != SCOUT_NIL) {
1110 fprintf(scout_debugfd, "[%s] Marking used disk %d inactive\n", rn,
1112 fflush(scout_debugfd);
1114 sc_disk = (a_srvline->disks) + used_disk_idx;
1115 sc_disk->active = 0;
1116 used_disk_idx = sc_disk->next;
1117 if (a_fix_line_num) {
1118 sc_disk->disk_lp->o_y += a_delta_line_num;
1119 diskdata = (struct gator_lightobj *)(sc_disk->disk_lp->o_data);
1120 disk_strparams = (struct gwin_strparams *)(diskdata->llrock);
1121 disk_strparams->y += a_delta_line_num;
1123 } /*Mark used disks inactive */
1125 curr_diskstat = (ViceDisk *) a_stats->Disk;
1126 for (curr_disk = 0; curr_disk < VOLMAXPARTS; curr_disk++) {
1128 * An AFS partition name must be prefixed by `/vicep`.
1131 fprintf(scout_debugfd, "[%s] Disk stats at %p for disk '%s'\n",
1132 rn, curr_diskstat, curr_diskstat->Name);
1133 fflush(scout_debugfd);
1135 if (strncmp("/vice", curr_diskstat->Name, 5) == 0) {
1137 * Pull out the single-letter name (actually, abbreviation)
1138 * of the disk and look for such an entry in the used disks.
1140 diskname = &curr_diskstat->Name[6];
1141 found_idx = scout_FindUsedDisk(diskname, /*1-char name */
1142 a_srvline, /*Server record */
1143 &fix_light_locs); /*Recompute? */
1144 if (found_idx == SCOUT_NIL) {
1146 "[%s] Can't display /vicep%s on server '%s'\n", rn,
1147 diskname, srv_name);
1150 * Found (or created) record for this disk. Fill in the single-
1151 * letter name of the disk followed by the number of free blocks.
1152 * Turn the disk light on if the number of free blocks exceeds
1153 * the threshold the user set, either % used or min free blocks.
1155 sprintf(s, "%s:%d", diskname, curr_diskstat->BlocksAvailable);
1156 if (scout_attn_disk_mode == SCOUT_DISKM_PCUSED) {
1158 (curr_diskstat->TotalBlocks -
1159 curr_diskstat->BlocksAvailable) /
1160 (float)(curr_diskstat->TotalBlocks) >
1161 scout_attn_disk_pcused)
1167 (curr_diskstat->BlocksAvailable <
1168 scout_attn_disk_minfree) ? 1 : 0;
1169 sc_disk = (a_srvline->disks) + found_idx;
1170 sc_disk->active = 1;
1172 (struct gator_lightobj *)(sc_disk->disk_lp->o_data);
1174 fprintf(scout_debugfd,
1175 "[%s] Justifying %s for disk idx %d (prev value: '%s')\n",
1176 rn, s, found_idx, diskdata->label);
1177 fflush(scout_debugfd);
1179 code = mini_justify(s, /*Src buffer */
1180 diskdata->label, /*Dest buffer */
1181 LIGHTOBJ_DISK_WIDTH, /*Dest's width */
1182 SCOUT_LEFT_JUSTIFY, /*Left-justify */
1183 SCOUT_LEFT_TRUNC, /*Left-truncate */
1184 SCOUT_IS_LDISK); /*Labeled disk */
1186 code = gator_light_set(sc_disk->disk_lp, pastthreshold);
1188 } /*Found disk record */
1191 /*Found AFS disk name */
1193 * Advance to the next disk statistics record.
1196 } /*For each statistics record */
1199 * We've now pulled out all the disk statistics from the probe.
1200 * See if any used disks that were there from the last time are
1201 * now gone. If so, we remove them.
1204 fprintf(scout_debugfd,
1205 "[%s] Scanning used disk records for inactive entries\n", rn);
1206 fflush(scout_debugfd);
1208 used_disk_idx = a_srvline->used_head;
1209 while (used_disk_idx != SCOUT_NIL) {
1211 fprintf(scout_debugfd, "[%s] Examining entry at index %d\n", rn,
1213 fflush(scout_debugfd);
1215 sc_disk = (a_srvline->disks) + used_disk_idx;
1216 next_used_idx = sc_disk->next;
1217 if (!(sc_disk->active)) {
1218 scout_RemoveInactiveDisk(a_srvline, /*Server record */
1219 used_disk_idx); /*Disk index to nuke */
1222 used_disk_idx = next_used_idx;
1224 } /*Remove inactive used disks */
1227 * If we've had to add or remove disks to/from the used list,
1228 * or if the frame width has changed, we recompute the light
1229 * locations before returning.
1231 if (fix_light_locs || a_width_changed)
1232 scout_RecomputeLightLocs(a_srvline);
1235 * Return the (possibly new) size of the current server record.
1237 return (a_srvline->num_lines);
1239 } /*mini_PrintDiskStats */
1241 /*------------------------------------------------------------------------
1245 * Handler routine passed to the fsprobe module. This handler is
1246 * called immediately after a poll of all the FileServers has taken
1247 * place. Its job is to write out selected data to the scout
1258 * All it needs to know is exported by the fsprobe module, namely
1259 * the data structure where the probe results are stored.
1262 * Recomputes disk light locations in response to reshaping the
1263 * scout window or from adding/deleting disk lights to/from
1264 * individual servers.
1265 *------------------------------------------------------------------------*/
1271 static char rn[] = "FS_Handler"; /*Routine name */
1272 int code; /*Return code */
1273 struct ProbeViceStatistics *curr_stats; /*Ptr to current stats */
1274 int *curr_probeOK; /*Ptr to current probeOK field */
1275 int curr_srvidx; /*Current server index */
1276 char s[128]; /*String buffer */
1277 static char sblank[] = " "; /*Blank string buffer */
1278 char *sp; /*Ptr to string buffer */
1279 struct mini_line *curr_line; /*Current mini-line */
1280 int curr_line_num; /*Current line number */
1281 struct gator_lightobj *lightdata; /*Private light data */
1282 int setting; /*Light setting (on or off) */
1283 int old_width; /*Keep the old width value */
1284 int width_changed; /*Has the frame width changed? */
1285 int fix_line_num; /*Line number needs fixing */
1286 int delta_line_num; /*Change in line number */
1289 * See if the size of the scout frame has changed since the last
1292 old_width = scout_frameDims.maxx;
1294 fprintf(scout_debugfd, "[%s] Calling wop_getdimensions\n", rn);
1295 fflush(scout_debugfd);
1297 WOP_GETDIMENSIONS(scout_frame->window, &scout_frameDims);
1298 width_changed = (old_width == scout_frameDims.maxx) ? 0 : 1;
1300 fprintf(scout_debugfd,
1301 "[%s] Frame dimensions are %d rows, %d columns\n", rn,
1302 scout_frameDims.maxy, scout_frameDims.maxx);
1304 fprintf(scout_debugfd, "[%s] Width has changed from %d columns\n",
1306 fflush(scout_debugfd);
1310 * Print out the selected fields for each server. We actually change
1311 * the light's label to the new data.
1313 curr_line = scout_screen.line;
1314 curr_stats = fsprobe_Results.stats;
1315 curr_probeOK = fsprobe_Results.probeOK;
1316 curr_line_num = curr_line->base_line;
1319 for (curr_srvidx = 0; curr_srvidx < scout_screen.numServers;
1322 * If the current server record is set up on the wrong line, fix
1323 * the non-disk light objects directly, and remember to fix the
1324 * disk light objects later on.
1326 if (curr_line->base_line != curr_line_num) {
1328 delta_line_num = curr_line_num - curr_line->base_line;
1329 curr_line->base_line = curr_line_num;
1330 scout_SetNonDiskLightLine(curr_line, curr_line_num);
1337 (struct gator_lightobj *)(curr_line->currConns_lp->o_data);
1338 if (*curr_probeOK == 0) {
1340 sprintf(sp, "%d", curr_stats->CurrentConnections);
1343 code = mini_justify(sp, /*Src buffer */
1344 lightdata->label, /*Dest buffer */
1345 LIGHTOBJ_CONN_WIDTH, /*Dest's width */
1346 SCOUT_RIGHT_JUSTIFY, /*Right-justify */
1347 SCOUT_LEFT_TRUNC, /*Left-truncate */
1348 SCOUT_ISNT_LDISK); /*Not a labeled disk */
1349 if (scout_attn_conn != SCOUT_ATTN_NOTUSED
1350 && curr_stats->CurrentConnections >= scout_attn_conn)
1354 code = gator_light_set(curr_line->currConns_lp, setting);
1356 lightdata = (struct gator_lightobj *)(curr_line->fetches_lp->o_data);
1357 if (*curr_probeOK == 0) {
1359 sprintf(sp, "%d", curr_stats->TotalFetchs);
1362 code = mini_justify(sp, /*Src buffer */
1363 lightdata->label, /*Dest buffer */
1364 LIGHTOBJ_FETCH_WIDTH, /*Dest's width */
1365 SCOUT_RIGHT_JUSTIFY, /*Right-justify */
1366 SCOUT_LEFT_TRUNC, /*Left-truncate */
1367 SCOUT_ISNT_LDISK); /*Not a labeled disk */
1368 if (scout_attn_fetch != SCOUT_ATTN_NOTUSED
1369 && curr_stats->TotalFetchs >= scout_attn_fetch)
1373 code = gator_light_set(curr_line->fetches_lp, setting);
1375 lightdata = (struct gator_lightobj *)(curr_line->stores_lp->o_data);
1376 if (*curr_probeOK == 0) {
1378 sprintf(sp, "%d", curr_stats->TotalStores);
1381 code = mini_justify(sp, /*Src buffer */
1382 lightdata->label, /*Dest buffer */
1383 LIGHTOBJ_STORE_WIDTH, /*Dest's width */
1384 SCOUT_RIGHT_JUSTIFY, /*Right-justify */
1385 SCOUT_LEFT_TRUNC, /*Left-truncate */
1386 SCOUT_ISNT_LDISK); /*Not a labeled disk */
1387 if (scout_attn_store != SCOUT_ATTN_NOTUSED
1388 && curr_stats->TotalStores >= scout_attn_store)
1392 code = gator_light_set(curr_line->stores_lp, setting);
1395 (struct gator_lightobj *)(curr_line->workstations_lp->o_data);
1396 if (*curr_probeOK == 0) {
1398 sprintf(sp, "%d", curr_stats->WorkStations);
1401 code = mini_justify(sp, /*Src buffer */
1402 lightdata->label, /*Dest buffer */
1403 LIGHTOBJ_WK_WIDTH, /*Dest's width */
1404 SCOUT_RIGHT_JUSTIFY, /*Right-justify */
1405 SCOUT_LEFT_TRUNC, /*Left-truncate */
1406 SCOUT_ISNT_LDISK); /*Not a labeled disk */
1407 if (scout_attn_workstations != SCOUT_ATTN_NOTUSED
1408 && curr_stats->WorkStations >= scout_attn_workstations)
1412 code = gator_light_set(curr_line->workstations_lp, setting);
1415 * We turn the server light on if there was an error in the
1416 * current probe (e.g., if the curr_probeOK field is non-zero.
1417 * (Don't forget to fix the light's line if it needs it).
1419 setting = (*curr_probeOK) ? 1 : 0;
1420 code = gator_light_set(curr_line->srvName_lp, setting);
1423 * Print out the disk statistics. The value returned is the
1424 * number of lines taken up by the server record (or 0 if
1425 * something went wrong).
1427 code = mini_PrintDiskStats(curr_line, /*Ptr to server line */
1428 curr_stats, /*Fresh disk stats */
1429 *curr_probeOK, /*Was probe OK? */
1430 width_changed, /*Has the width changed? */
1431 fix_line_num, /*Fix the line number? */
1432 delta_line_num); /*Change in line number */
1434 fprintf(stderr, "[%s] Error in printing out disk statistics\n",
1438 curr_line_num += code;
1441 * Advance the current mini_line, stats source, and probe success
1448 } /*for each server probed */
1451 * Display the scout frame.
1453 sprintf(s, "Probe %d results", fsprobe_Results.probeNum);
1454 gtxframe_DisplayString(scout_frame, s);
1455 WOP_DISPLAY(scout_gwin);
1458 * Return the happy news.
1464 /*------------------------------------------------------------------------
1468 * Initialize each line in the mini_screen.
1471 * struct sockaddr_in *a_skt : Ptr to server socket info.
1472 * int a_lineNum; : Line number being created.
1473 * struct mini_line *a_line : Ptr to mini_line to set up.
1474 * char *a_srvname : Printable server name.
1478 * Error value otherwise.
1481 * Nothing interesting.
1485 *------------------------------------------------------------------------*/
1488 init_mini_line(struct sockaddr_in *a_skt, int a_lineNum,
1489 struct mini_line *a_line, char *a_srvname)
1490 { /*init_mini_line */
1492 static char rn[] = "init_mini_line"; /*Routine name */
1493 int curr_x; /*Current X position */
1494 int curr_y; /*Current Y position */
1495 char s[128]; /*Scratch buffer */
1496 int code; /*Return code */
1497 struct gator_lightobj *lightdata; /*Private light data */
1500 fprintf(scout_debugfd, "[%s] Called for base line %d\n", rn,
1502 fflush(scout_debugfd);
1506 * Fill in the top fields (except the disk fields, which will be
1507 * done elsewhere), then create the light onodes.
1509 memcpy((char *)&(a_line->skt), (char *)a_skt, sizeof(struct sockaddr_in));
1510 a_line->numDisks = 0;
1511 a_line->base_line = a_lineNum + scout_screen.base_line_num;
1512 a_line->num_lines = 1;
1515 curr_y = a_line->base_line;
1516 if ((a_line->currConns_lp =
1517 mini_initLightObject("Conns", curr_x, curr_y, LIGHTOBJ_CONN_WIDTH,
1520 fprintf(stderr, "[%s:%s] Can't create currConns light object\n", pn,
1524 curr_x += LIGHTOBJ_CONN_WIDTH + 1;
1526 if ((a_line->fetches_lp =
1527 mini_initLightObject("Fetches", curr_x, curr_y, LIGHTOBJ_FETCH_WIDTH,
1528 scout_frame->window))
1530 fprintf(stderr, "[%s:%s] Can't create fetches light object\n", pn,
1534 curr_x += LIGHTOBJ_FETCH_WIDTH + 1;
1536 if ((a_line->stores_lp =
1537 mini_initLightObject("Stores", curr_x, curr_y, LIGHTOBJ_STORE_WIDTH,
1538 scout_frame->window))
1540 fprintf(stderr, "[%s:%s] Can't create stores light object\n", pn, rn);
1543 curr_x += LIGHTOBJ_STORE_WIDTH + 1;
1545 if ((a_line->workstations_lp =
1546 mini_initLightObject("WrkStn", curr_x, curr_y, LIGHTOBJ_WK_WIDTH,
1547 scout_frame->window))
1549 fprintf(stderr, "[%s:%s] Can't create workstations light object\n",
1553 curr_x += LIGHTOBJ_WK_WIDTH + 1;
1555 if ((a_line->srvName_lp =
1556 mini_initLightObject(a_srvname, curr_x, curr_y,
1557 LIGHTOBJ_SRVNAME_WIDTH, scout_frame->window))
1559 fprintf(stderr, "[%s:%s] Can't create server name light object\n", pn,
1563 sprintf(s, "%s", a_srvname);
1564 lightdata = (struct gator_lightobj *)(a_line->srvName_lp->o_data);
1565 code = mini_justify(s, /*Src buffer */
1566 lightdata->label, /*Dest buffer */
1567 LIGHTOBJ_SRVNAME_WIDTH, /*Dest's width */
1568 SCOUT_CENTER, /*Centered */
1569 SCOUT_RIGHT_TRUNC, /*Right-truncate */
1570 SCOUT_ISNT_LDISK); /*Not a labeled disk */
1573 "[%s] Can't center server name inside of light object\n", rn);
1576 curr_x += LIGHTOBJ_SRVNAME_WIDTH + 1;
1578 if (scout_initDiskLightObjects(a_line, scout_frame->window)) {
1579 fprintf(stderr, "[%s:%s] Can't create disk light objects\n", pn, rn);
1584 * Finally, return the happy news.
1588 } /*init_mini_line */
1590 /*------------------------------------------------------------------------
1594 * Workhorse routine that starts up the FileServer probe.
1597 * int a_numservers : Length of above list.
1598 * struct cmd_item *a_srvname : List of FileServer machines to
1600 * int a_pkg : Window package to use.
1604 * Error value otherwise.
1607 * Nothing interesting.
1611 *------------------------------------------------------------------------*/
1614 execute_scout(int a_numservers, struct cmd_item *a_srvname, int a_pkg)
1615 { /*execute_scout */
1617 static char rn[] = "execute_scout"; /*Routine name */
1618 static char fullsrvname[128]; /*Full server name */
1619 register int code; /*Return code */
1620 struct sockaddr_in *FSSktArray; /*Server socket array */
1621 int sktbytes; /*Num bytes in above */
1622 struct sockaddr_in *curr_skt; /*Ptr to current socket */
1623 struct cmd_item *curr_item; /*Ptr to current cmd item */
1624 struct hostent *he; /*Host entry */
1625 struct mini_line *mini_lines; /*Ptr to all mini-lines */
1626 struct mini_line *curr_line; /*Ptr to current line */
1627 int i; /*Generic loop variable */
1628 int mini_line_bytes; /*Num bytes in mini_lines */
1629 struct timeval tv; /*Time structure */
1630 int linenum; /*Current mini-line number */
1632 PROCESS pid; /*Main LWP process ID */
1633 PROCESS gxlistener_ID; /*Input Server LWP process ID */
1635 struct gator_lightobj *lightdata; /*Private light data */
1638 fprintf(scout_debugfd, "[%s] Called\n", rn);
1639 fflush(scout_debugfd);
1643 * We have to initialize LWP support before we start up any of
1647 code = LWP_InitializeProcessSupport(LWP_NORMAL_PRIORITY, &pid);
1649 fprintf(stderr, "[%s:%s] Can't initialize LWP\n", pn, rn);
1650 scout_CleanExit(code);
1655 * Initialize the gtx package.
1658 fprintf(stderr, "[%s:%s] Starting up gtx package\n", pn, rn);
1660 scout_gwin = gtx_Init(0, /*Don't start up InputServer yet */
1661 -1); /*Type of window package */
1662 if (scout_gwin == NULL) {
1663 fprintf(stderr, "[%s:%s] Call to gtx_Init() failed!\n", pn, rn);
1668 * Remember we've set up gtx so we can exit cleanly from now on.
1670 scout_gtx_initialized = 1;
1673 * Create the frame everything will go into, set it up as our only
1674 * frame for this window.
1676 scout_frame = gtxframe_Create();
1677 if (scout_frame == (struct gtx_frame *)0) {
1678 fprintf(stderr, "[%s:%s] Call to gtxframe_Create() failed!\n", pn,
1682 gtxframe_SetFrame(scout_gwin, scout_frame);
1683 WOP_GETDIMENSIONS(scout_frame->window, &scout_frameDims);
1686 * Allocate an array of sockets to describe each FileServer we'll be
1689 sktbytes = a_numservers * sizeof(struct sockaddr_in);
1690 FSSktArray = (struct sockaddr_in *)malloc(sktbytes);
1691 if (FSSktArray == (struct sockaddr_in *)0) {
1693 "[%s] Can't malloc() %d sockaddrs (%d bytes) for the given servers\n",
1694 rn, a_numservers, sktbytes);
1695 scout_CleanExit(-1);
1697 memset(FSSktArray, 0, sktbytes);
1700 * Sweep through the server names provided, filling in the socket
1701 * info for each. Take into account the fact that we may have a
1702 * base name associated for each.
1704 curr_item = a_srvname;
1705 curr_skt = FSSktArray;
1707 if (*scout_basename == '\0')
1708 sprintf(fullsrvname, "%s", curr_item->data);
1710 sprintf(fullsrvname, "%s.%s", curr_item->data, scout_basename);
1711 he = hostutil_GetHostByName(fullsrvname);
1713 fprintf(stderr, "[%s] Can't get host info for '%s'\n", rn,
1717 memcpy(&(curr_skt->sin_addr.s_addr), he->h_addr, 4);
1718 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1719 curr_skt->sin_family = AF_INET; /*Internet family */
1721 curr_skt->sin_family = htons(AF_INET); /*Internet family */
1723 curr_skt->sin_port = htons(7000); /*FileServer port */
1726 * Bump our pointers.
1728 curr_item = curr_item->next;
1731 } /*Build socket entry for each server */
1734 * Create the set of mini-lines, one per server.
1736 mini_line_bytes = a_numservers * sizeof(struct mini_line);
1737 mini_lines = (struct mini_line *)malloc(mini_line_bytes);
1738 if (mini_lines == (struct mini_line *)0) {
1739 fprintf(stderr, "[%s] Can't malloc() %d bytes for %d screen lines\n",
1740 rn, mini_line_bytes, a_numservers);
1743 memset(mini_lines, 0, mini_line_bytes);
1746 * Set up each line in the mini_lines, creating and initializing
1747 * its light objects.
1749 scout_screen.base_line_num = 4;
1750 curr_line = mini_lines;
1751 curr_skt = FSSktArray;
1753 curr_item = a_srvname;
1754 gtxframe_ClearList(scout_frame);
1757 * Create the light objects that server as banner lines. Remember
1758 * to take into account the server basename, if any, and the name
1759 * of the host that scout if running on, if that's wanted.
1761 if (scout_showhostname) {
1762 if (*scout_basename == '\0')
1763 sprintf(scout_Banner, "[%s] %s", scout_hostname, "Scout");
1765 sprintf(scout_Banner, "[%s] Scout for %s", scout_hostname,
1768 if (*scout_basename == '\0')
1769 sprintf(scout_Banner, "%s", " Scout");
1771 sprintf(scout_Banner, " Scout for %s", scout_basename);
1773 scout_banner0_lp = mini_initLightObject("Banner 0", /*Light name */
1774 0, /*X*/ 0, /*Y*/ scout_frameDims.maxx, /*Width */
1775 scout_gwin); /*Window */
1776 if (scout_banner0_lp != NULL) {
1777 lightdata = (struct gator_lightobj *)(scout_banner0_lp->o_data);
1779 mini_justify(scout_Banner, lightdata->label, scout_frameDims.maxx,
1780 SCOUT_CENTER, SCOUT_RIGHT_TRUNC, SCOUT_ISNT_LDISK);
1781 code = gator_light_set(scout_banner0_lp, 1);
1782 code = gtxframe_AddToList(scout_frame, scout_banner0_lp);
1786 fprintf(scout_debugfd, "[%s] Scout label is '%s', %lu chars\n", rn,
1787 lightdata->label, strlen(lightdata->label));
1790 scout_banner1_lp = mini_initLightObject("Banner 1", /*Light name */
1791 0, /*X*/ 2, /*Y*/ scout_frameDims.maxx, /*Width */
1792 scout_gwin); /*Window */
1793 if (scout_banner1_lp != NULL) {
1794 if (scout_attn_disk_mode == SCOUT_DISKM_PCUSED) {
1795 sprintf(scout_Banner, "%s > %s%% used", scout_LightLabels,
1796 scout_attn_disk_pcusedstr);
1798 sprintf(scout_Banner, "%s < %d blocks free", scout_LightLabels,
1799 scout_attn_disk_minfree);
1801 lightdata = (struct gator_lightobj *)(scout_banner1_lp->o_data);
1803 mini_justify(scout_Banner, lightdata->label, scout_frameDims.maxx,
1804 SCOUT_LEFT_JUSTIFY, SCOUT_RIGHT_TRUNC,
1807 code = gtxframe_AddToList(scout_frame, scout_banner1_lp);
1810 scout_banner2_lp = mini_initLightObject("Banner 2", /*Light name */
1811 0, /*X*/ 3, /*Y*/ scout_frameDims.maxx, /*Width */
1812 scout_gwin); /*Window */
1813 if (scout_banner2_lp != NULL) {
1814 lightdata = (struct gator_lightobj *)(scout_banner2_lp->o_data);
1816 mini_justify(scout_LightLabelUnd, lightdata->label,
1817 scout_frameDims.maxx, SCOUT_LEFT_JUSTIFY,
1818 SCOUT_RIGHT_TRUNC, SCOUT_ISNT_LDISK);
1819 code = gtxframe_AddToList(scout_frame, scout_banner2_lp);
1822 for (i = 0; i < a_numservers; i++) {
1823 code = init_mini_line(curr_skt, linenum, curr_line, curr_item->data);
1825 fprintf(stderr, "[%s] Can't initialize line for server %d\n", rn,
1832 curr_item = curr_item->next;
1836 * Now that all lines have been set up, we feed in the light items
1837 * created. Note: the disk lights are entered at a later time,
1838 * as they enter the used disk list for each server.
1840 curr_line = mini_lines;
1841 for (i = 0; i < a_numservers; i++) {
1842 code = gtxframe_AddToList(scout_frame, curr_line->currConns_lp);
1845 "[%s] Can't add client connections light to display list\n",
1850 code = gtxframe_AddToList(scout_frame, curr_line->fetches_lp);
1853 "[%s] Can't add fetches light to frame display list\n",
1858 code = gtxframe_AddToList(scout_frame, curr_line->stores_lp);
1861 "[%s] Can't add stores light to frame display list\n",
1866 code = gtxframe_AddToList(scout_frame, curr_line->workstations_lp);
1869 "[%s] Can't add workstation light to display list\n", rn);
1873 code = gtxframe_AddToList(scout_frame, curr_line->srvName_lp);
1876 "[%s] Can't add server name light to display list\n", rn);
1881 * Move down to the next server record.
1885 } /*Add lights in server records to display list */
1889 * Set up the minimal keymap.
1891 code = keymap_BindToString(scout_frame->keymap, /*Ptr to keymap */
1892 "e", /*Key to bind */
1893 ExitCmd, /*Cmd to execute */
1895 NULL); /*Ptr to rock */
1897 fprintf(stderr, "[%s] Can't bind key `e', code is %d\n", rn, code);
1903 * Finish setting up the overall mini_screen structure.
1905 scout_screen.numServers = a_numservers;
1906 scout_screen.line = mini_lines;
1907 WOP_GETDIMENSIONS(scout_frame->window, &scout_frameDims);
1910 * Start up the fsprobe package, which will gather FileServer
1911 * statistics for us on a regular basis.
1913 gtxframe_DisplayString(scout_frame,
1914 "Establishing File Server connection(s)...");
1915 code = fsprobe_Init(a_numservers, /*Num FileServers to probe */
1916 FSSktArray, /*FileServer socket array */
1917 scout_probefreq, /*Probe frequency */
1918 FS_Handler, /*Handler routine */
1919 0); /*Turn debugging output off */
1921 scout_debug); /*Turn debugging output off */
1924 fprintf(stderr, "[%s] Error returned by fsprobe_Init: %d\n", rn,
1931 * Start up the input server LWP for our window.
1934 code = LWP_CreateProcess(gtx_InputServer, /*Fcn to start up */
1935 8192, /*Stack size in bytes */
1936 LWP_NORMAL_PRIORITY, /*Priority */
1937 (void *)scout_gwin, /*Params: Ptr to window */
1938 "gx-listener", /*Name to use */
1939 &gxlistener_ID); /*Returned LWP process ID */
1942 code = (int) gtx_InputServer(scout_gwin);
1945 "[%s] Error exit from gtx_InputServer(), error is %d\n", rn,
1947 scout_CleanExit(code);
1951 * We fall into a loop, sleeping forever.
1954 tv.tv_sec = 60 * 60; /*Sleep for an hour at a time */
1956 code = select(0, /*Num fds */
1957 0, /*Descriptors ready for reading */
1958 0, /*Descriptors ready for writing */
1959 0, /*Descriptors with exceptional conditions */
1960 &tv); /*Timeout structure */
1961 } /*Sleep forever */
1965 * How did we get here? Oh, well, clean up our windows and
1966 * return sweetness and light anyway.
1968 WOP_CLEANUP(&scout_gwin);
1972 } /*execute_scout */
1974 /*------------------------------------------------------------------------
1978 * Given a pointer to the list of servers we'll be polling,
1979 * compute the length of the list.
1982 * struct cmd_item *a_firstItem : Ptr to first item in list.
1985 * Length of the above list.
1988 * Nothing interesting.
1992 *------------------------------------------------------------------------*/
1994 static int countServers(struct cmd_item *a_firstItem)
1997 int list_len; /*List length */
1998 struct cmd_item *curr_item; /*Ptr to current item */
2001 curr_item = a_firstItem;
2008 curr_item = curr_item->next;
2018 /*------------------------------------------------------------------------
2019 * scout_AdoptThresholds
2022 * Parse and adopt one or more threshold values, as read off the
2026 * struct cmd_item *a_thresh_item : Ptr to item on command-line
2030 * Nothing (but may exit the entire program on error!)
2033 * Valid keywords are:
2034 * conn, disk, fetch, store, ws
2035 * The disk value, if it has a % sign, signifies that attention
2036 * will be triggered when the disk is more than that percentage
2037 * full; otherwise, it will specify the minimum number of free
2042 *------------------------------------------------------------------------*/
2044 static void scout_AdoptThresholds(struct cmd_item *a_thresh_item)
2045 { /*scout_AdoptThresholds */
2047 static char rn[] = "scout_AdoptThresholds"; /*Routine name */
2048 struct cmd_item *curr_item; /*Current item */
2049 char *curr_name; /*Current name half of pair */
2050 char *curr_value; /*Current value half of pair */
2051 int diskval_len; /*Length of disk attn value */
2053 curr_item = a_thresh_item;
2056 * If there isn't a corresponding value for the current
2057 * attention field, bitch & die.
2059 if (curr_item->next == (struct cmd_item *)0) {
2060 printf("[%s] No threshold value given for '%s'\n", rn,
2062 scout_CleanExit(-1);
2065 curr_name = curr_item->data;
2066 curr_value = curr_item->next->data;
2068 if (strcmp(curr_name, "conn") == 0) {
2070 fprintf(scout_debugfd,
2071 "[%s] Setting conn attn value to %d (default %d)\n",
2072 rn, atoi(curr_value), scout_attn_conn);
2073 fflush(scout_debugfd);
2075 scout_attn_conn = atoi(curr_value);
2076 } else if (strcmp(curr_name, "disk") == 0) {
2078 * If there's a '%' as the last character in the value,
2079 * we use percentage mode.
2081 diskval_len = strlen(curr_value);
2082 if (curr_value[diskval_len - 1] == '%') {
2083 curr_value[diskval_len - 1] = '\0';
2085 fprintf(scout_debugfd,
2086 "[%s] New disk attn value: 0.%s used (default %f)\n",
2087 rn, curr_value, scout_attn_disk_pcused);
2088 fflush(scout_debugfd);
2090 sprintf(scout_attn_disk_pcusedstr, "%s", curr_value);
2091 scout_attn_disk_pcused =
2092 ((float)(atoi(curr_value))) / ((float)(100));
2093 } /*Percentage mode */
2096 fprintf(scout_debugfd,
2097 "[%s] New disk attn value: %s min free (default %f)\n",
2098 rn, curr_value, scout_attn_disk_pcused);
2099 fflush(scout_debugfd);
2101 scout_attn_disk_mode = SCOUT_DISKM_MINFREE;
2102 scout_attn_disk_minfree = atoi(curr_value);
2103 } /*Min free blocks mode */
2104 } else if (strcmp(curr_name, "fetch") == 0) {
2106 fprintf(scout_debugfd,
2107 "[%s] Setting fetch attn value to %d (default %d)\n",
2108 rn, atoi(curr_value), scout_attn_fetch);
2109 fflush(scout_debugfd);
2111 scout_attn_fetch = atoi(curr_value);
2112 } else if (strcmp(curr_name, "store") == 0) {
2114 fprintf(scout_debugfd,
2115 "[%s] Setting store attn value to %d (default %d)\n",
2116 rn, atoi(curr_value), scout_attn_store);
2117 fflush(scout_debugfd);
2119 scout_attn_store = atoi(curr_value);
2120 } else if (strcmp(curr_name, "ws") == 0) {
2122 fprintf(scout_debugfd,
2123 "[%s] Setting workstation attn value to %d (default %d)\n",
2124 rn, atoi(curr_value), scout_attn_workstations);
2125 fflush(scout_debugfd);
2127 scout_attn_workstations = atoi(curr_value);
2129 printf("[%s] Unknown attention item: '%s'\n", rn,
2131 scout_CleanExit(-1);
2135 * Advance past the just-processed pair.
2137 curr_item = curr_item->next->next;
2139 } /*Interpret each name-value pair */
2141 } /*scout_AdoptThresholds */
2143 /*------------------------------------------------------------------------
2147 * Routine called when Scout is invoked, responsible for basic
2148 * initialization, command line parsing, and calling the
2149 * routine that does all the work.
2152 * as : Command syntax descriptor.
2153 * arock : Associated rock (not used here).
2156 * Zero (but may exit the entire program on error!)
2159 * Nothing interesting.
2162 * Initializes this program.
2163 *------------------------------------------------------------------------*/
2165 static int scoutInit(struct cmd_syndesc *as, void *arock)
2168 static char rn[] = "scoutInit"; /*Routine name */
2169 int code; /*Return code */
2170 int wpkg_to_use; /*Window package to use */
2171 int server_count; /*Number of servers to watch */
2172 char *debug_filename; /*Name of debugging output file */
2175 fprintf(scout_debugfd, "[%s] Called\n", rn);
2176 fflush(scout_debugfd);
2179 if (as->parms[P_DEBUG].items != 0) {
2181 debug_filename = as->parms[P_DEBUG].items->data;
2182 scout_debugfd = fopen(debug_filename, "w");
2183 if (scout_debugfd == (FILE *) 0) {
2184 printf("[%s] Can't open debugging file '%s'!\n", rn,
2186 scout_CleanExit(-1);
2188 fprintf(scout_debugfd, "[%s] Writing to Scout debugging file '%s'\n",
2189 rn, debug_filename);
2192 wpkg_to_use = atoi(as->parms[P_PACKAGE].items->data);
2194 wpkg_to_use = 2; /*Always use curses for now */
2196 fprintf(stderr, "[%s:%s] Using graphics package %d: ", pn, rn,
2198 switch (wpkg_to_use) {
2199 case GATOR_WIN_CURSES:
2200 fprintf(stderr, "curses\n");
2202 case GATOR_WIN_DUMB:
2203 fprintf(stderr, "dumb terminal\n");
2206 fprintf(stderr, "X11\n");
2209 fprintf(stderr, "Illegal graphics package: %d\n", wpkg_to_use);
2210 scout_CleanExit(-1);
2211 } /*end switch (wpkg_to_use) */
2214 if (as->parms[P_FREQ].items != 0)
2215 scout_probefreq = atoi(as->parms[P_FREQ].items->data);
2217 scout_probefreq = 60;
2220 * See if we've been fed a base server name.
2222 if (as->parms[P_BASE].items != 0)
2223 sprintf(scout_basename, "%s", as->parms[P_BASE].items->data);
2225 *scout_basename = '\0';
2228 * Count the number of servers we've been asked to monitor.
2230 server_count = countServers(as->parms[P_SERVER].items);
2233 * Create a line of blanks, a generally-useful thing.
2235 sprintf(scout_blankline, "%255s", " ");
2238 * Pull in the name of the host we're executing on if we've been
2239 * asked to. If we can't get the name, we provide a default.
2241 if (as->parms[P_HOST].items != 0) {
2242 scout_showhostname = 1;
2243 *scout_hostname = '\0';
2244 code = gethostname(scout_hostname, 128);
2246 sprintf(scout_hostname, "%s", "*No Hostname*");
2250 * Pull in any and all attention/highlighting thresholds.
2252 if (as->parms[P_ATTENTION].items != 0)
2253 scout_AdoptThresholds(as->parms[P_ATTENTION].items);
2256 * Now, drive the sucker.
2258 code = execute_scout(server_count, /*Num servers */
2259 as->parms[P_SERVER].items, /*Ptr to srv names */
2260 wpkg_to_use); /*Graphics pkg */
2262 fprintf(stderr, "[%s] Error executing scout: %d\n", rn, code);
2263 scout_CleanExit(-1);
2267 * We initialized (and ran) correctly, so return the good news.
2273 #include "AFS_component_version_number.c"
2276 main(int argc, char **argv)
2279 register afs_int32 code; /*Return code */
2280 register struct cmd_syndesc *ts; /*Ptr to cmd line syntax descriptor */
2282 #ifdef AFS_AIX32_ENV
2284 * The following signal action for AIX is necessary so that in case of a
2285 * crash (i.e. core is generated) we can include the user's data section
2286 * in the core dump. Unfortunately, by default, only a partial core is
2287 * generated which, in many cases, isn't too useful.
2289 struct sigaction nsa;
2291 sigemptyset(&nsa.sa_mask);
2292 nsa.sa_handler = SIG_DFL;
2293 nsa.sa_flags = SA_FULLDUMP;
2294 sigaction(SIGSEGV, &nsa, NULL);
2297 * Set up the commands we understand.
2299 ts = cmd_CreateSyntax("initcmd", scoutInit, NULL, "initialize the program");
2300 cmd_AddParm(ts, "-server", CMD_LIST, CMD_REQUIRED,
2301 "FileServer name(s) to monitor");
2302 cmd_AddParm(ts, "-basename", CMD_SINGLE, CMD_OPTIONAL,
2303 "base server name");
2305 cmd_AddParm(ts, "-package", CMD_SINGLE, CMD_REQUIRED,
2306 "Graphics package to use");
2308 cmd_AddParm(ts, "-frequency", CMD_SINGLE, CMD_OPTIONAL,
2309 "poll frequency, in seconds");
2310 cmd_AddParm(ts, "-host", CMD_FLAG, CMD_OPTIONAL,
2311 "show name of host you're running on");
2312 cmd_AddParm(ts, "-attention", CMD_LIST, CMD_OPTIONAL,
2313 "specify attention (highlighting) level");
2314 cmd_AddParm(ts, "-debug", CMD_SINGLE, CMD_OPTIONAL,
2315 "turn debugging output on to the named file");
2318 * Parse command-line switches & execute the test, then get the heck
2321 code = cmd_Dispatch(argc, argv);
2324 fprintf(stderr, "[%s:%s] Call to cmd_Dispatch() failed; code is %d\n",
2331 return 0; /* not reachable */