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>
31 #include <gtxwindows.h> /*Generic window package*/
32 #include <gtxobjects.h> /*Object definitions*/
33 #include <gtxtextobj.h> /*Text object interface*/
34 #include <gtxlightobj.h> /*Light object interface*/
35 #include <gtxcurseswin.h> /*Curses window package*/
36 #include <gtxdumbwin.h> /*Dumb terminal window package*/
37 #include <gtxX11win.h> /*X11 window package*/
38 #include <gtxframe.h> /*Frame package*/
39 #include <stdio.h> /*Standard I/O stuff*/
40 #include <cmd.h> /*Command interpretation library*/
41 #include <fsprobe.h> /*Interface for fsprobe module*/
44 extern struct hostent *hostutil_GetHostByName();
45 extern int gtx_InputServer();
46 extern int gethostname();
49 * Command line parameter indicies.
62 * Define the width in chars for each light object on the mini-line.
64 #define LIGHTOBJ_CONN_WIDTH 5
65 #define LIGHTOBJ_FETCH_WIDTH 10
66 #define LIGHTOBJ_STORE_WIDTH 10
67 #define LIGHTOBJ_WK_WIDTH 5
68 #define LIGHTOBJ_SRVNAME_WIDTH 13
69 #define LIGHTOBJ_DISK_WIDTH 12
72 * Define the types of justification we can perform.
74 #define SCOUT_RIGHT_JUSTIFY 0
75 #define SCOUT_LEFT_JUSTIFY 1
76 #define SCOUT_CENTER 2
79 * Define the types of truncation we can perform.
81 #define SCOUT_LEFT_TRUNC 0
82 #define SCOUT_RIGHT_TRUNC 1
85 * Define whether the value passed is a labeled disk quantity.
87 #define SCOUT_ISNT_LDISK 0
88 #define SCOUT_IS_LDISK 1
91 * We sometimes use index-base pointers, so we need a distinguished
94 #define SCOUT_NIL (-1)
97 * Structure describing everything you want to know about a FileServer
101 int prev; /*Index of previous list entry*/
102 int next; /*Index of next list entry*/
103 int active; /*Is this disk known to exist?*/
104 char *name; /*Single-letter disk name*/
105 struct onode *disk_lp; /*Ptr to disk light object*/
109 * Structure defining all the objects in the Scout line (or lines)
110 * for each server being watched. Note that scout_disk linked list
111 * for used disks is ordered alphabetically.
115 * Information on server location & configuration.
117 struct sockaddr_in skt; /*Server's socket info*/
118 int numDisks; /*Number of disks used*/
120 * Screen location info.
122 int base_line; /*Line number on the screen*/
123 int num_lines; /*Number of lines of info*/
125 * Associated light objects.
127 struct onode *currConns_lp; /*Number of current connections*/
128 struct onode *fetches_lp; /*Number of data fetches*/
129 struct onode *stores_lp; /*Number of data stores*/
130 struct onode *workstations_lp; /*Workstation info*/
131 struct onode *srvName_lp; /*Server name*/
132 struct scout_disk disks[VOLMAXPARTS]; /*Info on all the disks*/
133 int used_head; /*Index of first used disk struct*/
134 int used_tail; /*Index of last used disk struct*/
135 int free_head; /*Index of first free disk struct*/
136 int free_tail; /*Index of last free disk struct*/
140 * Structure defining the contents of the Scout screen.
143 int numServers; /*Number of servers being watched*/
144 int base_line_num; /*Base mini-line number*/
145 struct mini_line *line; /*Array of screen lines*/
148 static char pn[] = "scout"; /*Program name*/
149 static int scout_debug = 0; /*Is debugging turned on?*/
150 static FILE *scout_debugfd; /*Debugging file descriptor*/
151 static int scout_gtx_initialized = 0; /*Has gtx been initialized?*/
152 static struct mini_screen scout_screen; /*Mini-screen itself*/
153 static int scout_probefreq; /*Probe frequency in seconds*/
154 static char scout_basename[64]; /*Base server name*/
155 static char scout_hostname[128]; /*Name of machine we're running on*/
156 static int scout_showhostname = 0; /*Show name of machine we're on?*/
157 static char scout_blankline[256]; /*Blank line*/
158 static struct gwin *scout_gwin; /*Window to use*/
159 static struct gtx_frame *scout_frame; /*Frame to use*/
160 static struct onode *scout_banner0_lp; /*Banner light, line 0*/
161 static struct onode *scout_banner1_lp; /*Banner light, line 1*/
162 static struct onode *scout_banner2_lp; /*Banner light, line 2*/
163 static int scout_DiskLightLeftCol = 0; /*Column for leftmost disk light*/
164 static struct gwin_sizeparams scout_frameDims; /*Frame dimensions*/
167 * Attention thresholds & modes.
169 #define SCOUT_ATTN_NOTUSED (-1)
170 #define SCOUT_DISKM_PCUSED 0
171 #define SCOUT_DISKM_MINFREE 1
173 static int scout_attn_conn = SCOUT_ATTN_NOTUSED;
174 static int scout_attn_fetch = SCOUT_ATTN_NOTUSED;
175 static int scout_attn_store = SCOUT_ATTN_NOTUSED;
176 static int scout_attn_workstations = SCOUT_ATTN_NOTUSED;
177 static int scout_attn_disk_mode = SCOUT_DISKM_PCUSED;
178 static int scout_attn_disk_minfree = 1000;
179 static float scout_attn_disk_pcused = 0.95;
180 static char scout_attn_disk_pcusedstr[8] = "95";
183 * Some strings we'll be using over and over again.
185 static char scout_Banner[256];
186 static char scout_LightLabels[] =
187 "Conn Fetch Store Ws Disk attn:";
188 static char scout_LightLabelUnd[] =
189 "---- -------- -------- ----- ----------";
192 /*------------------------------------------------------------------------
196 * Exits cleanly from the Scout. If gtx has not yet been initialized,
197 * then we simply call exit() with the value provided. Otherwise,
198 * we call the appropriate gtx routine to exit cleanly from gtx, which
199 * must reset the terminal or window. We also close the debugging
200 * file descriptor, if one has been opened.
203 * int a_exitval : Value with which to exit the program.
209 * Actions depend on scout_gtx_initialized.
212 * This routine will always exit Scout.
213 *------------------------------------------------------------------------*/
215 static void scout_CleanExit(a_exitval)
218 { /*scout_CleanExit*/
220 static char rn[] = "scout_CleanExit"; /*Routine name*/
222 if (scout_debugfd != (FILE *)0) {
223 fprintf(scout_debugfd, "[%s] Closing debugging file\n", rn);
224 fclose(scout_debugfd);
227 if (scout_gtx_initialized) {
228 gtxframe_exitValue = a_exitval;
229 gtxframe_ExitCmd((char *)(>xframe_exitValue));
234 } /*scout_CleanExit*/
236 /*------------------------------------------------------------------------
237 * mini_initLightObject
240 * Create and initialize a light onode according to the given
244 * char *a_name : Ptr to the light's string name.
245 * int a_x : X offset.
246 * int a_y : Y offset.
247 * int a_width : Width in chars.
248 * struct gwin *a_win : Ptr to window structure.
251 * Ptr to new light onode on success,
252 * A null pointer otherwise.
259 *------------------------------------------------------------------------*/
261 static struct onode *mini_initLightObject(a_name, a_x, a_y, a_width, a_win)
268 { /*mini_initLightObject*/
270 static char rn[] = "mini_initLightObject"; /*Routine name*/
271 struct onode *newlightp; /*Ptr to new light onode*/
272 /*We only support curses right now*/
273 struct gator_light_crparams light_crparams; /*Light creation params*/
274 char *truncname; /*Truncated name, if needed*/
275 int name_len; /*True length of name*/
278 fprintf(scout_debugfd,
279 "[%s] Called for name '%s', [%d, %d], %d-char field\n",
280 rn, a_name, a_x, a_y, a_width);
281 fflush(scout_debugfd);
286 * Set up the creation parameters according to the information we've
289 light_crparams.onode_params.cr_type = GATOR_OBJ_LIGHT;
290 name_len = strlen(a_name);
292 fprintf(scout_debugfd, "[%s] Name '%s' has %d chars\n",
293 rn, a_name, name_len);
294 if (name_len <= a_width)
295 sprintf(light_crparams.onode_params.cr_name, "%s", a_name);
298 * We need to truncate the given name, leaving a `*' at the end to
299 * show us it's been truncated.
301 truncname = light_crparams.onode_params.cr_name;
302 strncpy(truncname, a_name, a_width-1);
303 truncname[a_width-1] = '*';
304 truncname[a_width] = 0;
306 light_crparams.onode_params.cr_x = a_x;
307 light_crparams.onode_params.cr_y = a_y;
308 light_crparams.onode_params.cr_width = a_width;
309 light_crparams.onode_params.cr_height = 1;
310 light_crparams.onode_params.cr_window = a_win;
311 light_crparams.onode_params.cr_home_obj = NULL;
312 light_crparams.onode_params.cr_prev_obj = NULL;
313 light_crparams.onode_params.cr_parent_obj = NULL;
314 light_crparams.onode_params.cr_helpstring = NULL;
316 light_crparams.appearance = 0;
317 light_crparams.flashfreq = 0;
318 sprintf(light_crparams.label, "%s", a_name);
319 light_crparams.label_x = 0;
320 light_crparams.label_y = 0;
323 gator_objects_create((struct onode_createparams *)(&light_crparams));
326 * Return the news, happy or not.
330 } /*mini_initLightObject*/
332 /*------------------------------------------------------------------------
333 * scout_initDiskLightObjects
336 * Create and initialize all Scout light objects for a server's
340 * struct scout_disk *a_line : Ptr to the server object line.
341 * struct gwin *a_win : Ptr to window structure.
352 *------------------------------------------------------------------------*/
354 static int scout_initDiskLightObjects(a_line, a_win)
355 struct mini_line *a_line;
358 { /*scout_initDiskLightObjects*/
361 "scout_initDiskLightObjects"; /*Routine name*/
362 struct scout_disk *curr_disk; /*Ptr to current disk being set up*/
363 int i; /*Loop variable*/
366 fprintf(scout_debugfd, "[%s] Called\n", rn);
367 fflush(scout_debugfd);
371 * Set up the base linked list fields.
373 a_line->used_head = SCOUT_NIL;
374 a_line->used_tail = SCOUT_NIL;
375 a_line->free_head = 0;
376 a_line->free_tail = VOLMAXPARTS - 1;
379 * Sweep through the disk structures, creating the light objects and
380 * marking them all as free.
382 curr_disk = a_line->disks;
383 for (i=0; i < VOLMAXPARTS; i++) {
385 * Create the disk light object.
387 if ((curr_disk->disk_lp =
388 mini_initLightObject("Disk", /*Object name*/
391 LIGHTOBJ_DISK_WIDTH, /*Width*/
394 fprintf(stderr, "[%s:%s] Can't create disk %d light object\n",
400 * Set the other fields in the disk records; Note that in the
401 * fencepost cases, the prev and next pointers will have to be
404 curr_disk->prev = i-1;
405 curr_disk->next = i+1;
406 curr_disk->active = 0;
407 curr_disk->name = '\0';
410 * Bump up to the next disk structure.
414 } /*for each disk structure*/
417 * We made it all the way through. Fix the fencepost pointers, set
418 * the overall pointers, then return success.
420 a_line->disks[0].prev = SCOUT_NIL;
421 a_line->disks[VOLMAXPARTS-1].next = SCOUT_NIL;
425 } /*scout_initDiskLightObjects*/
428 /*------------------------------------------------------------------------
432 * Place the chars in the source buffer into the target buffer
433 * with the desired justification, either centered, left-justified
434 * or right-justified. Also, support inidication of truncation
435 * with a star (*), either on the left or right of the string,
436 * and whether we're justifying a labeled disk quantity.
439 * char *a_srcbuff : Ptr to source char buffer.
440 * char *a_dstbuff : Ptr to dest char buffer.
441 * int a_dstwidth : Width of dest buffer in chars.
442 * int a_justification : Kind of justification.
443 * int a_rightTrunc : If non-zero, place the truncation char
444 * on the right of the string. Otherwise,
445 * place it on the left.
446 * int a_isLabeledDisk : Is this a labeled disk quantity?
453 * All it needs to know is exported by the fsprobe module, namely
454 * the data structure where the probe results are stored.
458 *------------------------------------------------------------------------*/
460 int mini_justify(a_srcbuff, a_dstbuff, a_dstwidth, a_justification, a_rightTrunc, a_isLabeledDisk)
470 static char rn[] = "mini_justify"; /*Routine name*/
471 int leftpad_chars; /*# of chars for left-padding*/
472 int num_src_chars; /*# of chars in source*/
473 int true_num_src_chars; /*# src chars before truncation*/
474 int trunc_needed; /*Is truncation needed?*/
475 char diskChar; /*Disk name prefix*/
478 fprintf(scout_debugfd, "[%s] Called with '%s', dest width=%d\n",
479 rn, a_srcbuff, a_dstwidth);
480 fflush(scout_debugfd);
484 * Remember the disk label, if we've been passed such a thing.
487 diskChar = *a_srcbuff;
490 * If the destination width will overrun the gtx string storage,
491 * we automatically shorten up.
493 if (a_dstwidth > GATOR_LABEL_CHARS) {
495 fprintf(scout_debugfd,
496 "[%s] Dest width (%d) > gtx buflen (%d), shrinking dest width\n",
497 rn, a_dstwidth, GATOR_LABEL_CHARS);
498 fflush(scout_debugfd);
500 a_dstwidth = GATOR_LABEL_CHARS;
504 * If our source string is too long, prepare for truncation.
506 true_num_src_chars = strlen(a_srcbuff);
507 if (true_num_src_chars >= a_dstwidth) {
509 num_src_chars = a_dstwidth - 1;
512 a_srcbuff += (true_num_src_chars - num_src_chars);
516 num_src_chars = true_num_src_chars;
519 * Compute the necessary left-padding.
521 switch (a_justification) {
523 case SCOUT_RIGHT_JUSTIFY:
524 leftpad_chars = (a_dstwidth - 1) - num_src_chars;
527 case SCOUT_LEFT_JUSTIFY:
529 * This is the really easy one.
535 leftpad_chars = ((a_dstwidth - 1) - num_src_chars) / 2;
539 fprintf(stderr, "[%s] Illegal justification command: %d",
540 rn, a_justification);
542 } /*Switch on justification type*/
546 * Clear out the dest buffer, then place the source string at the
547 * appropriate padding location. Remember to place a string
548 * terminator at the end of the dest buffer, plus whatever truncation
549 * may be needed. If we're left-truncating, we've already shifted
550 * the src buffer appropriately.
552 strncpy(a_dstbuff, scout_blankline, a_dstwidth);
553 strncpy(a_dstbuff+leftpad_chars, a_srcbuff, num_src_chars);
554 *(a_dstbuff+a_dstwidth-1) = '\0';
557 *(a_dstbuff+a_dstwidth-2) = '*'; /*Truncate on the right*/
559 if (a_isLabeledDisk) {
560 *a_dstbuff = diskChar;
561 *(a_dstbuff+1) = ':';
562 *(a_dstbuff+2) = '*'; /*Truncate on the left, disk*/
565 *a_dstbuff = '*'; /*Truncate on the left, non-disk*/
567 } /*Handle truncations*/
570 * Return the good news.
576 /*------------------------------------------------------------------------
577 * scout_SetNonDiskLightLine
580 * Given a mini-line and a line number, place all non-disk lights
584 * struct mini_line *a_srvline : Ptr to server descriptor.
585 * int a_linenum : Line number to move to.
591 * The light's location is stored not only in the onode, but in
592 * the light's rock, so we have to change both sets of value.
596 *------------------------------------------------------------------------*/
598 static void scout_SetNonDiskLightLine(a_srvline, a_linenum)
599 struct mini_line *a_srvline;
602 { /*scout_SetNonDiskLightLine*/
605 "scout_SetNonDiskLightLine"; /*Routine name*/
606 struct gator_lightobj *nondisk_lightdata; /*Non-disk light data field*/
607 struct gwin_strparams *nondisk_strparams; /*Associated string params*/
610 * Do the exact same operation for each non-disk light in the record.
612 a_srvline->currConns_lp->o_y = a_linenum;
614 (struct gator_lightobj *)(a_srvline->currConns_lp->o_data);
616 (struct gwin_strparams *)(nondisk_lightdata->llrock);
617 nondisk_strparams->y = a_linenum;
619 a_srvline->fetches_lp->o_y = a_linenum;
621 (struct gator_lightobj *)(a_srvline->fetches_lp->o_data);
623 (struct gwin_strparams *)(nondisk_lightdata->llrock);
624 nondisk_strparams->y = a_linenum;
626 a_srvline->stores_lp->o_y = a_linenum;
628 (struct gator_lightobj *)(a_srvline->stores_lp->o_data);
630 (struct gwin_strparams *)(nondisk_lightdata->llrock);
631 nondisk_strparams->y = a_linenum;
633 a_srvline->workstations_lp->o_y = a_linenum;
635 (struct gator_lightobj *)(a_srvline->workstations_lp->o_data);
637 (struct gwin_strparams *)(nondisk_lightdata->llrock);
638 nondisk_strparams->y = a_linenum;
640 a_srvline->srvName_lp->o_y = a_linenum;
642 (struct gator_lightobj *)(a_srvline->srvName_lp->o_data);
644 (struct gwin_strparams *)(nondisk_lightdata->llrock);
645 nondisk_strparams->y = a_linenum;
647 } /*scout_SetNonDiskLightLine*/
649 /*------------------------------------------------------------------------
650 * scout_RecomputeLightLocs
653 * Given a pointer to a server record, recompute its disk light
654 * locations (and keep proper track of the number of screen lines
655 * required for the server record).
658 * struct mini_line *a_srvline : Ptr to server descriptor.
661 * 0 if anything went wrong,
662 * else the number of lines used by this server record.
665 * One or more records have joined or left the used light list
666 * for this server. We're not sure which ones, so we recompute
667 * them all. We may also have had a width change in the gtx
668 * frame. The base_line field in the server record is guaranteed
669 * to be correct at this point.
673 *------------------------------------------------------------------------*/
675 static int scout_RecomputeLightLocs(a_srvline)
676 struct mini_line *a_srvline;
678 { /*scout_RecomputeLightLocs*/
681 "scout_RecomputeLightLocs"; /*Routine name*/
682 int lights_per_line; /*# lights/line*/
683 int lights_this_line; /*# lights on cur line*/
684 int curr_idx; /*Current disk light idx*/
685 struct scout_disk *sc_disk; /*Ptr to disk record array*/
686 int lines_for_server; /*Num lines in server record*/
687 int curr_line; /*Current line being filled*/
688 int curr_x; /*Current x value for light*/
689 struct gator_lightobj *disk_lightdata; /*Disk light data field*/
690 struct gwin_strparams *disk_strparams; /*String params for disk light*/
693 fprintf(scout_debugfd, "[%s] Called\n", rn);
694 fflush(scout_debugfd);
698 * If we haven't yet computed the column for the leftmost disk light,
701 if (scout_DiskLightLeftCol == 0)
702 scout_DiskLightLeftCol =
703 LIGHTOBJ_CONN_WIDTH +
704 LIGHTOBJ_FETCH_WIDTH +
705 LIGHTOBJ_STORE_WIDTH +
707 LIGHTOBJ_SRVNAME_WIDTH + 5;
710 * Calculate how many disk light objects can fit in one line.
713 (scout_frameDims.maxx - scout_DiskLightLeftCol)/(LIGHTOBJ_DISK_WIDTH + 1);
715 fprintf(scout_debugfd, "[%s] %d lights per line\n",
716 rn, lights_per_line);
717 fflush(scout_debugfd);
721 * Sweep through the used disk light list, computing the location
724 lights_this_line = 0;
725 curr_idx = a_srvline->used_head;
726 lines_for_server = 1;
727 curr_line = a_srvline->base_line;
728 curr_x = scout_DiskLightLeftCol;
730 while (curr_idx != SCOUT_NIL) {
732 * Bump the number of lines for the server if we've already
733 * filled up the current line.
735 if (lights_this_line >= lights_per_line) {
736 lights_this_line = 0;
739 curr_x = scout_DiskLightLeftCol;
740 } /*Current line filled up*/
743 * Set the current disk light's location.
745 sc_disk = a_srvline->disks;
746 sc_disk[curr_idx].disk_lp->o_x = curr_x;
747 sc_disk[curr_idx].disk_lp->o_y = curr_line;
749 (struct gator_lightobj *)(sc_disk[curr_idx].disk_lp->o_data);
751 (struct gwin_strparams *)(disk_lightdata->llrock);
752 disk_strparams->x = curr_x;
753 disk_strparams->y = curr_line;
755 fprintf(scout_debugfd,
756 "[%s] Disk light at index %d located at [%d, %d]\n",
757 rn, curr_idx, curr_x, curr_line);
758 fflush(scout_debugfd);
762 * Record the inclusion of the light and move on to the next
766 curr_x += LIGHTOBJ_DISK_WIDTH + 1;
767 curr_idx = sc_disk[curr_idx].next;
769 } /*Update each used disk light*/
772 * Remember to record the (possibly new) number of lines in the
773 * server record before returning the value of that field.
775 if (a_srvline->num_lines != lines_for_server) {
777 fprintf(scout_debugfd,
778 "[%s] Server previously had %d screen lines; now changed\n",
779 rn, a_srvline->num_lines);
780 fflush(scout_debugfd);
782 a_srvline->num_lines = lines_for_server;
786 fprintf(scout_debugfd, "[%s] Server has %d screen lines\n",
787 rn, a_srvline->num_lines);
788 fflush(scout_debugfd);
790 return(a_srvline->num_lines);
792 } /*scout_RecomputeLightLocs*/
794 /*------------------------------------------------------------------------
798 * Given a single-letter disk name and a pointer to the current server
799 * record, look for a used disk record with that name within the server.
800 * If we can't find one, we create and incorporate one, and return that
801 * fact to our caller.
804 * char a_diskname : Single-char disk name.
805 * struct mini_line *a_srvline : Ptr to server descriptor.
806 * int *a_record_added : Was a new record added?
809 * Index of matching used disk record,
810 * SCOUT_NIL otherwise.
812 * Return via parameter:
813 * a_record_added set to 1 iff record was added to the used disk list.
816 * Used disk records are kept in alphabetical order by the single-char
817 * disk name. Should a matching used disk record not be found, one is
818 * pulled from the free pool.
821 * An entry may be pulled off the free list and inserted into the
822 * used list. This entry is placed in the update list for the
823 * current gtx frame (at least not by this routine).
824 *------------------------------------------------------------------------*/
826 static int scout_FindUsedDisk(a_diskname, a_srvline, a_record_added)
828 struct mini_line *a_srvline;
831 { /*scout_FindUsedDisk*/
833 static char rn[] = "scout_FindUsedDisk"; /*Routine name*/
834 int curr_idx; /*Disk record index*/
835 int append_idx; /*Index to append after*/
836 int new_idx; /*Index of new used record*/
837 struct scout_disk *sc_disk; /*Ptr to disk record*/
838 int code; /*Function return value*/
841 fprintf(scout_debugfd, "[%s] Called\n", rn);
842 fflush(scout_debugfd);
846 * Sweep through the used disk records, looking for a match.
848 curr_idx = a_srvline->used_head;
849 append_idx = SCOUT_NIL;
850 sc_disk = a_srvline->disks;
852 fprintf(scout_debugfd, "[%s] Scanning existing used disk entries for disk '%s'\n", rn, a_diskname);
853 fflush(scout_debugfd);
855 while (curr_idx != SCOUT_NIL) {
857 fprintf(scout_debugfd, "[%s] Disk %d is named '%s'\n",
858 rn, curr_idx, sc_disk[curr_idx].name);
859 fflush(scout_debugfd);
861 if (strcmp(sc_disk[curr_idx].name, a_diskname) == 0) {
863 * We found it! Bug out.
866 fprintf(scout_debugfd, "[%s] Match found\n", rn);
867 fflush(scout_debugfd);
873 * If we are alphabetically past the given disk name, we
874 * know that we won't find it in the used disk list; we
875 * also have the append index set correctly.
877 if (strcmp(a_diskname, sc_disk[curr_idx].name) < 0) {
879 fprintf(scout_debugfd, "[%s] Disk '%s' can't be here\n",
881 fflush(scout_debugfd);
887 * There's still hope we'll find it. Move on to the next used
888 * disk record, keeping this index as the best candidate so far
889 * for appending a missing entry.
891 append_idx = curr_idx;
892 curr_idx = sc_disk[curr_idx].next;
896 * We didn't find the record we wanted, which means we'll pull a
897 * record out of the free pool for it. If we didn't find a place
898 * to append it, we then insert it at the beginning of the queue.
900 if (a_srvline->free_head == SCOUT_NIL)
903 new_idx = a_srvline->free_head;
905 fprintf(scout_debugfd, "[%s] Choosing free index %d for new entry\n",
907 fflush(scout_debugfd);
909 a_srvline->free_head = sc_disk[new_idx].next;
910 if (a_srvline->free_head == SCOUT_NIL)
911 a_srvline->free_tail = SCOUT_NIL;
914 * Fill in the new record.
916 sc_disk[new_idx].active = 0;
917 sc_disk[new_idx].name = a_diskname;
920 * Insert the new record where it belongs on the used disk list.
922 if (append_idx == SCOUT_NIL) {
924 * It belongs at the beginning of the list.
927 fprintf(scout_debugfd, "[%s] Inserted at used disk head\n", rn);
928 fflush(scout_debugfd);
930 sc_disk[new_idx].next = a_srvline->used_head;
931 sc_disk[new_idx].prev = SCOUT_NIL;
932 a_srvline->used_head = new_idx;
933 if (a_srvline->used_tail == SCOUT_NIL)
934 a_srvline->used_tail = new_idx;
938 fprintf(scout_debugfd, "[%s] Entry appended after index %d\n",
940 fflush(scout_debugfd);
942 sc_disk[new_idx].prev = append_idx;
943 sc_disk[new_idx].next = sc_disk[append_idx].next;
944 sc_disk[append_idx].next = new_idx;
945 if (sc_disk[new_idx].next == SCOUT_NIL)
946 a_srvline->used_tail = new_idx;
948 sc_disk[sc_disk[new_idx].next].prev = new_idx;
952 * Add the new used disk light object to the display list for
956 fprintf(scout_debugfd, "[%s] Adding disk light at index %d to display list\n", rn, new_idx);
957 fflush(scout_debugfd);
959 code = gtxframe_AddToList(scout_frame, sc_disk[new_idx].disk_lp);
962 fprintf(scout_debugfd, "[%s] Can't add to display list, code is %d\n",
964 fflush(scout_debugfd);
969 } /*scout_FindUsedDisk*/
971 /*------------------------------------------------------------------------
972 * scout_RemoveInactiveDisk
975 * Given a server record and a used disk index, remove the disk
976 * record from the used list, put it on the free list, and remove
977 * it from the gtx frame update list.
980 * struct mini_line *a_srvline : Ptr to server descriptor.
981 * int a_used_idx : Index of used disk record.
987 * Formerly-used disk records are returned to the free pool.
990 * Free and used disk record lists are modified for this server.
991 * The disk record in question is pulled off the gtx update list
993 *------------------------------------------------------------------------*/
995 static void scout_RemoveInactiveDisk(a_srvline, a_used_idx)
996 struct mini_line *a_srvline;
999 { /*scout_RemoveInactiveDisk*/
1001 static char rn[] = "scout_RemoveInactiveDisk"; /*Routine name*/
1004 fprintf(scout_debugfd, "[%s] Called\n", rn);
1005 fflush(scout_debugfd);
1008 /*code = gtxframe_RemoveFromList(scout_frame->window, lightobj);*/
1010 } /*scout_RemoveInactiveDisk*/
1012 /*------------------------------------------------------------------------
1013 * mini_PrintDiskStats
1016 * Given server indexing and light object information, a pointer
1017 * to a set of statistics, and whether the probe that produced these
1018 * stats succeeded or not, print out the stats in a nice way.
1021 * struct mini_line *a_srvline : Ptr to server descriptor.
1022 * struct ProbeViceStatistics *a_stats : Ptr to current stats.
1023 * int a_probeOK : Was the probe OK?
1024 * int a_width_changed : Has the frame width changed?
1025 * int a_fix_line_num : Is the line number wrong?
1026 * int a_delta_line_num : Change in line number.
1029 * 0 if something went wrong,
1030 * else the number of lines taken up by this server record.
1033 * Nothing interesting.
1037 *------------------------------------------------------------------------*/
1039 static int mini_PrintDiskStats(a_srvline, a_stats, a_probeOK, a_width_changed,
1040 a_fix_line_num, a_delta_line_num)
1041 struct mini_line *a_srvline;
1042 struct ProbeViceStatistics *a_stats;
1045 int a_delta_line_num;
1047 { /*mini_PrintDiskStats*/
1049 static char rn[] = "mini_PrintDiskStats"; /*Routine name*/
1050 int code; /*Return code*/
1051 char s[128]; /*String buffer*/
1052 struct onode *curr_disklight; /*Ptr to current disk light*/
1053 struct onode *srvname_light; /*Ptr to server name light*/
1054 ViceDisk *curr_diskstat; /*Ptr to current disk stat*/
1055 int curr_disk; /*Current disk stat number*/
1056 int used_disk_idx; /*Used disk index*/
1057 int next_used_idx; /*Ditto*/
1058 int pastthreshold; /*Was disk past threshold?*/
1059 struct gator_lightobj *diskdata; /*Private light data*/
1060 struct gwin_strparams *disk_strparams; /*String params for disk light*/
1061 char *diskname = 0; /*Name of disk*/
1062 int found_idx; /*Idx of matching disk*/
1063 char *srv_name; /*Server name*/
1064 struct scout_disk *sc_disk; /*Ptr to scout disk desc*/
1065 int fix_light_locs; /*Recompute disk light locs?*/
1068 fprintf(scout_debugfd, "[%s] Called\n", rn);
1069 fflush(scout_debugfd);
1073 * Remember the current server's print name, don't recompute light
1076 srvname_light = a_srvline->srvName_lp;
1077 srv_name = ((struct gator_lightobj *)(srvname_light->o_data))->label;
1080 fprintf(scout_debugfd, "[%s] Value of a_delta_line_num is %d\n",
1081 rn, a_delta_line_num);
1082 fflush(scout_debugfd);
1086 * If the probe failed, we simply blank out all the used disk
1087 * objects. Note: a NON-ZERO value of a_probeOK implies failure.
1090 used_disk_idx = a_srvline->used_head;
1091 while (used_disk_idx != SCOUT_NIL) {
1093 * Point to the current used disk's light, blank out its
1094 * contents, and make sure highlighting is turned off. We
1095 * also take this opportunity to fix the line numbers if
1098 curr_disklight = a_srvline->disks[used_disk_idx].disk_lp;
1099 diskdata = (struct gator_lightobj *)(curr_disklight->o_data);
1101 fprintf(scout_debugfd, "[%s] Prev value of disk light %d: '%s'\n",
1102 rn, used_disk_idx, diskdata->label);
1103 fflush(scout_debugfd);
1105 code = mini_justify(" ", /*Src buffer*/
1106 diskdata->label, /*Dest buffer*/
1107 LIGHTOBJ_DISK_WIDTH, /*Dest's width*/
1108 SCOUT_RIGHT_JUSTIFY, /*Right-justify*/
1109 SCOUT_LEFT_TRUNC, /*Left-truncate*/
1110 SCOUT_ISNT_LDISK); /*Not a labeled disk*/
1111 code = gator_light_set(curr_disklight, 0);
1112 if (a_fix_line_num) {
1113 curr_disklight->o_y += a_delta_line_num;
1115 (struct gwin_strparams *)(diskdata->llrock);
1116 disk_strparams->y += a_delta_line_num;
1120 * Advance to next used disk, if any.
1122 used_disk_idx = a_srvline->disks[used_disk_idx].next;
1124 } /*Blank out disk name field*/
1127 * If the frame width has changed, we have to recompute all disk
1128 * light locations. After that, the number of lines in the server
1129 * record will be accurate, and we return them.
1131 if (a_width_changed)
1132 scout_RecomputeLightLocs(a_srvline);
1134 return(a_srvline->num_lines);
1136 } /*Probe failed for the server*/
1139 * Probe was successful. Sweep through the statistics records,
1140 * and put up all values having to do with AFS partitions. First,
1141 * mark all used disk objects for this server as inactive and fix
1142 * their line numbers if needed.
1144 sc_disk = a_srvline->disks;
1145 used_disk_idx = a_srvline->used_head;
1146 while (used_disk_idx != SCOUT_NIL) {
1148 fprintf(scout_debugfd, "[%s] Marking used disk %d inactive\n",
1150 fflush(scout_debugfd);
1152 sc_disk = (a_srvline->disks) + used_disk_idx;
1153 sc_disk->active = 0;
1154 used_disk_idx = sc_disk->next;
1155 if (a_fix_line_num) {
1156 sc_disk->disk_lp->o_y += a_delta_line_num;
1158 (struct gator_lightobj *)(sc_disk->disk_lp->o_data);
1160 (struct gwin_strparams *)(diskdata->llrock);
1161 disk_strparams->y += a_delta_line_num;
1163 } /*Mark used disks inactive*/
1165 curr_diskstat = (ViceDisk *) a_stats->Disk;
1166 for (curr_disk = 0; curr_disk < VOLMAXPARTS; curr_disk++) {
1168 * An AFS partition name must be prefixed by `/vicep`.
1171 fprintf(scout_debugfd, "[%s] Disk stats at 0x%x for disk '%s'\n",
1172 rn, curr_diskstat, curr_diskstat->Name);
1173 fflush(scout_debugfd);
1175 if (strncmp("/vice", curr_diskstat->Name, 5) == 0) {
1177 * Pull out the single-letter name (actually, abbreviation)
1178 * of the disk and look for such an entry in the used disks.
1180 diskname = &curr_diskstat->Name[6];
1182 scout_FindUsedDisk(diskname, /*1-char name*/
1183 a_srvline, /*Server record*/
1184 &fix_light_locs); /*Recompute?*/
1185 if (found_idx == SCOUT_NIL) {
1187 "[%s] Can't display /vicep%s on server '%s'\n",
1188 rn, diskname, srv_name);
1192 * Found (or created) record for this disk. Fill in the single-
1193 * letter name of the disk followed by the number of free blocks.
1194 * Turn the disk light on if the number of free blocks exceeds
1195 * the threshold the user set, either % used or min free blocks.
1197 sprintf(s, "%s:%d", diskname, curr_diskstat->BlocksAvailable);
1198 if (scout_attn_disk_mode == SCOUT_DISKM_PCUSED) {
1199 if ((float)(curr_diskstat->TotalBlocks -
1200 curr_diskstat->BlocksAvailable) /
1201 (float)(curr_diskstat->TotalBlocks) > scout_attn_disk_pcused)
1208 (curr_diskstat->BlocksAvailable < scout_attn_disk_minfree) ?
1210 sc_disk = (a_srvline->disks) + found_idx;
1211 sc_disk->active = 1;
1212 diskdata = (struct gator_lightobj *)(sc_disk->disk_lp->o_data);
1214 fprintf(scout_debugfd,
1215 "[%s] Justifying %s for disk idx %d (prev value: '%s')\n",
1216 rn, s, found_idx, diskdata->label);
1217 fflush(scout_debugfd);
1219 code = mini_justify(s, /*Src buffer*/
1220 diskdata->label, /*Dest buffer*/
1221 LIGHTOBJ_DISK_WIDTH, /*Dest's width*/
1222 SCOUT_LEFT_JUSTIFY, /*Left-justify*/
1223 SCOUT_LEFT_TRUNC, /*Left-truncate*/
1224 SCOUT_IS_LDISK); /*Labeled disk*/
1226 code = gator_light_set(sc_disk->disk_lp, pastthreshold);
1228 } /*Found disk record*/
1229 } /*Found AFS disk name*/
1232 * Advance to the next disk statistics record.
1235 } /*For each statistics record*/
1238 * We've now pulled out all the disk statistics from the probe.
1239 * See if any used disks that were there from the last time are
1240 * now gone. If so, we remove them.
1243 fprintf(scout_debugfd, "[%s] Scanning used disk records for inactive entries\n", rn);
1244 fflush(scout_debugfd);
1246 used_disk_idx = a_srvline->used_head;
1247 while (used_disk_idx != SCOUT_NIL) {
1249 fprintf(scout_debugfd, "[%s] Examining entry at index %d\n",
1251 fflush(scout_debugfd);
1253 sc_disk = (a_srvline->disks) + used_disk_idx;
1254 next_used_idx = sc_disk->next;
1255 if (!(sc_disk->active)) {
1256 scout_RemoveInactiveDisk(a_srvline, /*Server record*/
1257 used_disk_idx); /*Disk index to nuke*/
1260 used_disk_idx = next_used_idx;
1262 } /*Remove inactive used disks*/
1265 * If we've had to add or remove disks to/from the used list,
1266 * or if the frame width has changed, we recompute the light
1267 * locations before returning.
1269 if (fix_light_locs || a_width_changed)
1270 scout_RecomputeLightLocs(a_srvline);
1273 * Return the (possibly new) size of the current server record.
1275 return(a_srvline->num_lines);
1277 } /*mini_PrintDiskStats*/
1279 /*------------------------------------------------------------------------
1283 * Handler routine passed to the fsprobe module. This handler is
1284 * called immediately after a poll of all the FileServers has taken
1285 * place. Its job is to write out selected data to the scout
1296 * All it needs to know is exported by the fsprobe module, namely
1297 * the data structure where the probe results are stored.
1300 * Recomputes disk light locations in response to reshaping the
1301 * scout window or from adding/deleting disk lights to/from
1302 * individual servers.
1303 *------------------------------------------------------------------------*/
1309 static char rn[] = "FS_Handler"; /*Routine name*/
1310 int code; /*Return code*/
1311 struct ProbeViceStatistics *curr_stats; /*Ptr to current stats*/
1312 int *curr_probeOK; /*Ptr to current probeOK field*/
1313 int curr_srvidx; /*Current server index*/
1314 char s[128]; /*String buffer*/
1315 static char sblank[] = " "; /*Blank string buffer*/
1316 char *sp; /*Ptr to string buffer*/
1317 struct mini_line *curr_line; /*Current mini-line*/
1318 int curr_line_num; /*Current line number*/
1319 struct gator_lightobj *lightdata; /*Private light data*/
1320 int setting; /*Light setting (on or off)*/
1321 int old_width; /*Keep the old width value*/
1322 int width_changed; /*Has the frame width changed?*/
1323 int fix_line_num; /*Line number needs fixing*/
1324 int delta_line_num; /*Change in line number*/
1327 * See if the size of the scout frame has changed since the last
1330 old_width = scout_frameDims.maxx;
1332 fprintf(scout_debugfd, "[%s] Calling wop_getdimensions\n", rn);
1333 fflush(scout_debugfd);
1335 WOP_GETDIMENSIONS(scout_frame->window, &scout_frameDims);
1336 width_changed = (old_width == scout_frameDims.maxx) ? 0 : 1;
1338 fprintf(scout_debugfd,
1339 "[%s] Frame dimensions are %d rows, %d columns\n",
1340 rn, scout_frameDims.maxy, scout_frameDims.maxx);
1342 fprintf(scout_debugfd,
1343 "[%s] Width has changed from %d columns\n", rn, old_width);
1344 fflush(scout_debugfd);
1348 * Print out the selected fields for each server. We actually change
1349 * the light's label to the new data.
1351 curr_line = scout_screen.line;
1352 curr_stats = fsprobe_Results.stats;
1353 curr_probeOK = fsprobe_Results.probeOK;
1354 curr_line_num = curr_line->base_line;
1357 for (curr_srvidx = 0;
1358 curr_srvidx < scout_screen.numServers;
1361 * If the current server record is set up on the wrong line, fix
1362 * the non-disk light objects directly, and remember to fix the
1363 * disk light objects later on.
1365 if (curr_line->base_line != curr_line_num) {
1367 delta_line_num = curr_line_num - curr_line->base_line;
1368 curr_line->base_line = curr_line_num;
1369 scout_SetNonDiskLightLine(curr_line, curr_line_num);
1376 lightdata = (struct gator_lightobj *)(curr_line->currConns_lp->o_data);
1377 if (*curr_probeOK == 0) {
1379 sprintf(sp, "%d", curr_stats->CurrentConnections);
1383 code = mini_justify(sp, /*Src buffer*/
1384 lightdata->label, /*Dest buffer*/
1385 LIGHTOBJ_CONN_WIDTH, /*Dest's width*/
1386 SCOUT_RIGHT_JUSTIFY, /*Right-justify*/
1387 SCOUT_LEFT_TRUNC, /*Left-truncate*/
1388 SCOUT_ISNT_LDISK); /*Not a labeled disk*/
1389 if (scout_attn_conn != SCOUT_ATTN_NOTUSED &&
1390 curr_stats->CurrentConnections >= scout_attn_conn)
1394 code = gator_light_set(curr_line->currConns_lp, setting);
1396 lightdata = (struct gator_lightobj *)(curr_line->fetches_lp->o_data);
1397 if (*curr_probeOK == 0) {
1399 sprintf(sp, "%d", curr_stats->TotalFetchs);
1403 code = mini_justify(sp, /*Src buffer*/
1404 lightdata->label, /*Dest buffer*/
1405 LIGHTOBJ_FETCH_WIDTH, /*Dest's width*/
1406 SCOUT_RIGHT_JUSTIFY, /*Right-justify*/
1407 SCOUT_LEFT_TRUNC, /*Left-truncate*/
1408 SCOUT_ISNT_LDISK); /*Not a labeled disk*/
1409 if (scout_attn_fetch != SCOUT_ATTN_NOTUSED &&
1410 curr_stats->TotalFetchs >= scout_attn_fetch)
1414 code = gator_light_set(curr_line->fetches_lp, setting);
1416 lightdata = (struct gator_lightobj *)(curr_line->stores_lp->o_data);
1417 if (*curr_probeOK == 0) {
1419 sprintf(sp, "%d", curr_stats->TotalStores);
1423 code = mini_justify(sp, /*Src buffer*/
1424 lightdata->label, /*Dest buffer*/
1425 LIGHTOBJ_STORE_WIDTH, /*Dest's width*/
1426 SCOUT_RIGHT_JUSTIFY, /*Right-justify*/
1427 SCOUT_LEFT_TRUNC, /*Left-truncate*/
1428 SCOUT_ISNT_LDISK); /*Not a labeled disk*/
1429 if (scout_attn_store != SCOUT_ATTN_NOTUSED &&
1430 curr_stats->TotalStores >= scout_attn_store)
1434 code = gator_light_set(curr_line->stores_lp, setting);
1436 lightdata = (struct gator_lightobj *)(curr_line->workstations_lp->o_data);
1437 if (*curr_probeOK == 0) {
1439 sprintf(sp, "%d", curr_stats->WorkStations);
1443 code = mini_justify(sp, /*Src buffer*/
1444 lightdata->label, /*Dest buffer*/
1445 LIGHTOBJ_WK_WIDTH, /*Dest's width*/
1446 SCOUT_RIGHT_JUSTIFY, /*Right-justify*/
1447 SCOUT_LEFT_TRUNC, /*Left-truncate*/
1448 SCOUT_ISNT_LDISK); /*Not a labeled disk*/
1449 if (scout_attn_workstations != SCOUT_ATTN_NOTUSED &&
1450 curr_stats->WorkStations >= scout_attn_workstations)
1454 code = gator_light_set(curr_line->workstations_lp, setting);
1457 * We turn the server light on if there was an error in the
1458 * current probe (e.g., if the curr_probeOK field is non-zero.
1459 * (Don't forget to fix the light's line if it needs it).
1461 setting = (*curr_probeOK) ? 1 : 0;
1462 code = gator_light_set(curr_line->srvName_lp, setting);
1465 * Print out the disk statistics. The value returned is the
1466 * number of lines taken up by the server record (or 0 if
1467 * something went wrong).
1470 mini_PrintDiskStats(curr_line, /*Ptr to server line*/
1471 curr_stats, /*Fresh disk stats*/
1472 *curr_probeOK, /*Was probe OK?*/
1473 width_changed, /*Has the width changed?*/
1474 fix_line_num, /*Fix the line number?*/
1475 delta_line_num);/*Change in line number*/
1477 fprintf(stderr, "[%s] Error in printing out disk statistics\n",
1482 curr_line_num += code;
1485 * Advance the current mini_line, stats source, and probe success
1492 } /*for each server probed*/
1495 * Display the scout frame.
1497 sprintf(s, "Probe %d results", fsprobe_Results.probeNum);
1498 gtxframe_DisplayString(scout_frame, s);
1499 WOP_DISPLAY(scout_gwin);
1502 * Return the happy news.
1508 /*------------------------------------------------------------------------
1512 * Initialize each line in the mini_screen.
1515 * struct sockaddr_in *a_skt : Ptr to server socket info.
1516 * int a_lineNum; : Line number being created.
1517 * struct mini_line *a_line : Ptr to mini_line to set up.
1518 * char *a_srvname : Printable server name.
1522 * Error value otherwise.
1525 * Nothing interesting.
1529 *------------------------------------------------------------------------*/
1531 static int init_mini_line(a_skt, a_lineNum, a_line, a_srvname)
1532 struct sockaddr_in *a_skt;
1534 struct mini_line *a_line;
1537 { /*init_mini_line*/
1539 static char rn[] = "init_mini_line"; /*Routine name*/
1540 int curr_x; /*Current X position*/
1541 int curr_y; /*Current Y position*/
1542 char s[128]; /*Scratch buffer*/
1543 int code; /*Return code*/
1544 struct gator_lightobj *lightdata; /*Private light data*/
1547 fprintf(scout_debugfd, "[%s] Called for base line %d\n",
1549 fflush(scout_debugfd);
1553 * Fill in the top fields (except the disk fields, which will be
1554 * done elsewhere), then create the light onodes.
1556 memcpy((char *)&(a_line->skt), (char *)a_skt, sizeof(struct sockaddr_in));
1557 a_line->numDisks = 0;
1558 a_line->base_line = a_lineNum + scout_screen.base_line_num;
1559 a_line->num_lines = 1;
1562 curr_y = a_line->base_line;
1563 if ((a_line->currConns_lp =
1564 mini_initLightObject("Conns",
1567 LIGHTOBJ_CONN_WIDTH,
1570 fprintf(stderr, "[%s:%s] Can't create currConns light object\n",
1574 curr_x += LIGHTOBJ_CONN_WIDTH + 1;
1576 if ((a_line->fetches_lp =
1577 mini_initLightObject("Fetches",
1580 LIGHTOBJ_FETCH_WIDTH,
1581 scout_frame->window))
1583 fprintf(stderr, "[%s:%s] Can't create fetches light object\n",
1587 curr_x += LIGHTOBJ_FETCH_WIDTH + 1;
1589 if ((a_line->stores_lp =
1590 mini_initLightObject("Stores",
1593 LIGHTOBJ_STORE_WIDTH,
1594 scout_frame->window))
1596 fprintf(stderr, "[%s:%s] Can't create stores light object\n",
1600 curr_x += LIGHTOBJ_STORE_WIDTH + 1;
1602 if ((a_line->workstations_lp =
1603 mini_initLightObject("WrkStn",
1607 scout_frame->window))
1609 fprintf(stderr, "[%s:%s] Can't create workstations light object\n",
1613 curr_x += LIGHTOBJ_WK_WIDTH + 1;
1615 if ((a_line->srvName_lp =
1616 mini_initLightObject(a_srvname,
1619 LIGHTOBJ_SRVNAME_WIDTH,
1620 scout_frame->window))
1622 fprintf(stderr, "[%s:%s] Can't create server name light object\n",
1626 sprintf(s, "%s", a_srvname);
1627 lightdata = (struct gator_lightobj *)(a_line->srvName_lp->o_data);
1628 code = mini_justify(s, /*Src buffer*/
1629 lightdata->label, /*Dest buffer*/
1630 LIGHTOBJ_SRVNAME_WIDTH, /*Dest's width*/
1631 SCOUT_CENTER, /*Centered*/
1632 SCOUT_RIGHT_TRUNC, /*Right-truncate*/
1633 SCOUT_ISNT_LDISK); /*Not a labeled disk*/
1635 fprintf(stderr, "[%s] Can't center server name inside of light object\n", rn);
1638 curr_x += LIGHTOBJ_SRVNAME_WIDTH + 1;
1640 if (scout_initDiskLightObjects(a_line, scout_frame->window)) {
1641 fprintf(stderr, "[%s:%s] Can't create disk light objects\n",
1647 * Finally, return the happy news.
1651 } /*init_mini_line*/
1653 /*------------------------------------------------------------------------
1657 * Workhorse routine that starts up the FileServer probe.
1660 * int a_numservers : Length of above list.
1661 * struct cmd_item *a_srvname : List of FileServer machines to
1663 * int a_pkg : Window package to use.
1667 * Error value otherwise.
1670 * Nothing interesting.
1674 *------------------------------------------------------------------------*/
1676 static int execute_scout(a_numservers, a_srvname, a_pkg)
1678 struct cmd_item *a_srvname;
1683 static char rn[] = "execute_scout"; /*Routine name*/
1684 static char fullsrvname[128]; /*Full server name*/
1685 register int code; /*Return code*/
1686 struct sockaddr_in *FSSktArray; /*Server socket array*/
1687 int sktbytes; /*Num bytes in above*/
1688 struct sockaddr_in *curr_skt; /*Ptr to current socket*/
1689 struct cmd_item *curr_item; /*Ptr to current cmd item*/
1690 struct hostent *he; /*Host entry*/
1691 struct mini_line *mini_lines; /*Ptr to all mini-lines*/
1692 struct mini_line *curr_line; /*Ptr to current line*/
1693 int i; /*Generic loop variable*/
1694 int mini_line_bytes; /*Num bytes in mini_lines*/
1695 struct timeval tv; /*Time structure*/
1696 int linenum; /*Current mini-line number*/
1698 PROCESS pid; /*Main LWP process ID*/
1699 PROCESS gxlistener_ID; /*Input Server LWP process ID*/
1701 struct gator_lightobj *lightdata; /*Private light data*/
1704 fprintf(scout_debugfd, "[%s] Called\n", rn);
1705 fflush(scout_debugfd);
1709 * We have to initialize LWP support before we start up any of
1713 code = LWP_InitializeProcessSupport(LWP_NORMAL_PRIORITY, &pid);
1715 fprintf(stderr, "[%s:%s] Can't initialize LWP\n", pn, rn);
1716 scout_CleanExit(code);
1721 * Initialize the gtx package.
1724 fprintf(stderr, "[%s:%s] Starting up gtx package\n", pn, rn);
1726 scout_gwin = gtx_Init(0, /*Don't start up InputServer yet*/
1727 -1); /*Type of window package*/
1728 if (scout_gwin == NULL) {
1729 fprintf(stderr, "[%s:%s] Call to gtx_Init() failed!\n", pn, rn);
1734 * Remember we've set up gtx so we can exit cleanly from now on.
1736 scout_gtx_initialized = 1;
1739 * Create the frame everything will go into, set it up as our only
1740 * frame for this window.
1742 scout_frame = gtxframe_Create();
1743 if (scout_frame == (struct gtx_frame *)0) {
1744 fprintf(stderr, "[%s:%s] Call to gtxframe_Create() failed!\n", pn, rn);
1747 gtxframe_SetFrame(scout_gwin, scout_frame);
1748 WOP_GETDIMENSIONS(scout_frame->window, &scout_frameDims);
1751 * Allocate an array of sockets to describe each FileServer we'll be
1754 sktbytes = a_numservers * sizeof(struct sockaddr_in);
1755 FSSktArray = (struct sockaddr_in *) malloc(sktbytes);
1756 if (FSSktArray == (struct sockaddr_in *)0) {
1758 "[%s] Can't malloc() %d sockaddrs (%d bytes) for the given servers\n",
1759 rn, a_numservers, sktbytes);
1760 scout_CleanExit(-1);
1762 memset(FSSktArray, 0, sktbytes);
1765 * Sweep through the server names provided, filling in the socket
1766 * info for each. Take into account the fact that we may have a
1767 * base name associated for each.
1769 curr_item = a_srvname;
1770 curr_skt = FSSktArray;
1772 if (*scout_basename == '\0')
1773 sprintf(fullsrvname, "%s", curr_item->data);
1775 sprintf(fullsrvname, "%s.%s", curr_item->data, scout_basename);
1776 he = hostutil_GetHostByName(fullsrvname);
1778 fprintf(stderr, "[%s] Can't get host info for '%s'\n",
1782 memcpy(&(curr_skt->sin_addr.s_addr), he->h_addr, 4);
1783 curr_skt->sin_family = htons(AF_INET); /*Internet family*/
1784 curr_skt->sin_port = htons(7000); /*FileServer port*/
1787 * Bump our pointers.
1789 curr_item = curr_item->next;
1792 } /*Build socket entry for each server*/
1795 * Create the set of mini-lines, one per server.
1797 mini_line_bytes = a_numservers * sizeof(struct mini_line);
1798 mini_lines = (struct mini_line *) malloc(mini_line_bytes);
1799 if (mini_lines == (struct mini_line *)0) {
1800 fprintf(stderr, "[%s] Can't malloc() %d bytes for %d screen lines\n",
1801 rn, mini_line_bytes, a_numservers);
1804 memset(mini_lines, 0, mini_line_bytes);
1807 * Set up each line in the mini_lines, creating and initializing
1808 * its light objects.
1810 scout_screen.base_line_num = 4;
1811 curr_line = mini_lines;
1812 curr_skt = FSSktArray;
1814 curr_item = a_srvname;
1815 gtxframe_ClearList(scout_frame);
1818 * Create the light objects that server as banner lines. Remember
1819 * to take into account the server basename, if any, and the name
1820 * of the host that scout if running on, if that's wanted.
1822 if (scout_showhostname) {
1823 if (*scout_basename == '\0')
1824 sprintf(scout_Banner, "[%s] %s", scout_hostname, "Scout");
1826 sprintf(scout_Banner, "[%s] Scout for %s",
1827 scout_hostname, scout_basename);
1830 if (*scout_basename == '\0')
1831 sprintf(scout_Banner, "%s", " Scout");
1833 sprintf(scout_Banner, " Scout for %s", scout_basename);
1836 mini_initLightObject("Banner 0", /*Light name*/
1839 scout_frameDims.maxx, /*Width*/
1840 scout_gwin); /*Window*/
1841 if (scout_banner0_lp != NULL) {
1842 lightdata = (struct gator_lightobj *)(scout_banner0_lp->o_data);
1843 code = mini_justify(scout_Banner,
1845 scout_frameDims.maxx,
1849 code = gator_light_set(scout_banner0_lp, 1);
1850 code = gtxframe_AddToList(scout_frame, scout_banner0_lp);
1854 fprintf(scout_debugfd, "[%s] Scout label is '%s', %d chars\n",
1855 rn, lightdata->label, strlen(lightdata->label));
1859 mini_initLightObject("Banner 1", /*Light name*/
1862 scout_frameDims.maxx, /*Width*/
1863 scout_gwin); /*Window*/
1864 if (scout_banner1_lp != NULL) {
1865 if (scout_attn_disk_mode == SCOUT_DISKM_PCUSED) {
1866 sprintf(scout_Banner, "%s > %s%% used",
1868 scout_attn_disk_pcusedstr);
1871 sprintf(scout_Banner, "%s < %d blocks free",
1872 scout_LightLabels, scout_attn_disk_minfree);
1874 lightdata = (struct gator_lightobj *)(scout_banner1_lp->o_data);
1875 code = mini_justify(scout_Banner,
1877 scout_frameDims.maxx,
1882 code = gtxframe_AddToList(scout_frame, scout_banner1_lp);
1886 mini_initLightObject("Banner 2", /*Light name*/
1889 scout_frameDims.maxx, /*Width*/
1890 scout_gwin); /*Window*/
1891 if (scout_banner2_lp != NULL) {
1892 lightdata = (struct gator_lightobj *)(scout_banner2_lp->o_data);
1893 code = mini_justify(scout_LightLabelUnd,
1895 scout_frameDims.maxx,
1899 code = gtxframe_AddToList(scout_frame, scout_banner2_lp);
1902 for (i=0; i < a_numservers; i++) {
1903 code = init_mini_line(curr_skt, linenum, curr_line, curr_item->data);
1905 fprintf(stderr, "[%s] Can't initialize line for server %d\n", rn, i);
1911 curr_item = curr_item->next;
1915 * Now that all lines have been set up, we feed in the light items
1916 * created. Note: the disk lights are entered at a later time,
1917 * as they enter the used disk list for each server.
1919 curr_line = mini_lines;
1920 for (i = 0; i < a_numservers; i++) {
1921 code = gtxframe_AddToList(scout_frame, curr_line->currConns_lp);
1924 "[%s] Can't add client connections light to display list\n",
1929 code = gtxframe_AddToList(scout_frame, curr_line->fetches_lp);
1931 fprintf(stderr, "[%s] Can't add fetches light to frame display list\n",
1936 code = gtxframe_AddToList(scout_frame, curr_line->stores_lp);
1938 fprintf(stderr, "[%s] Can't add stores light to frame display list\n",
1943 code = gtxframe_AddToList(scout_frame, curr_line->workstations_lp);
1945 fprintf(stderr, "[%s] Can't add workstation light to display list\n",
1950 code = gtxframe_AddToList(scout_frame, curr_line->srvName_lp);
1952 fprintf(stderr, "[%s] Can't add server name light to display list\n",
1958 * Move down to the next server record.
1962 } /*Add lights in server records to display list*/
1966 * Set up the minimal keymap.
1969 keymap_BindToString(scout_frame->keymap, /*Ptr to keymap*/
1970 "e", /*Key to bind*/
1971 ExitCmd, /*Cmd to execute*/
1973 NULL); /*Ptr to rock*/
1975 fprintf(stderr, "[%s] Can't bind key `e', code is %d\n", rn, code);
1981 * Finish setting up the overall mini_screen structure.
1983 scout_screen.numServers = a_numservers;
1984 scout_screen.line = mini_lines;
1985 WOP_GETDIMENSIONS(scout_frame->window, &scout_frameDims);
1988 * Start up the fsprobe package, which will gather FileServer
1989 * statistics for us on a regular basis.
1991 gtxframe_DisplayString(scout_frame, "Establishing File Server connection(s)...");
1992 code = fsprobe_Init(a_numservers, /*Num FileServers to probe*/
1993 FSSktArray, /*FileServer socket array*/
1994 scout_probefreq, /*Probe frequency*/
1995 FS_Handler, /*Handler routine*/
1996 0); /*Turn debugging output off*/
1998 scout_debug); /*Turn debugging output off*/
2001 fprintf(stderr, "[%s] Error returned by fsprobe_Init: %d\n", rn, code);
2007 * Start up the input server LWP for our window.
2011 LWP_CreateProcess(gtx_InputServer, /*Fcn to start up*/
2012 8192, /*Stack size in bytes*/
2013 LWP_NORMAL_PRIORITY, /*Priority*/
2014 scout_gwin, /*Params: Ptr to window*/
2015 "gx-listener", /*Name to use*/
2016 &gxlistener_ID); /*Returned LWP process ID*/
2019 code = gtx_InputServer(scout_gwin);
2021 fprintf(stderr, "[%s] Error exit from gtx_InputServer(), error is %d\n",
2023 scout_CleanExit(code);
2027 * We fall into a loop, sleeping forever.
2030 tv.tv_sec = 60*60; /*Sleep for an hour at a time*/
2032 code = select(0, /*Num fds*/
2033 0, /*Descriptors ready for reading*/
2034 0, /*Descriptors ready for writing*/
2035 0, /*Descriptors with exceptional conditions*/
2036 &tv); /*Timeout structure*/
2041 * How did we get here? Oh, well, clean up our windows and
2042 * return sweetness and light anyway.
2044 WOP_CLEANUP(&scout_gwin);
2050 /*------------------------------------------------------------------------
2054 * Given a pointer to the list of servers we'll be polling,
2055 * compute the length of the list.
2058 * struct cmd_item *a_firstItem : Ptr to first item in list.
2061 * Length of the above list.
2064 * Nothing interesting.
2068 *------------------------------------------------------------------------*/
2070 static int countServers(a_firstItem)
2071 struct cmd_item *a_firstItem;
2075 int list_len; /*List length*/
2076 struct cmd_item *curr_item; /*Ptr to current item*/
2079 curr_item = a_firstItem;
2086 curr_item = curr_item->next;
2096 /*------------------------------------------------------------------------
2097 * scout_AdoptThresholds
2100 * Parse and adopt one or more threshold values, as read off the
2104 * struct cmd_item *a_thresh_item : Ptr to item on command-line
2108 * Nothing (but may exit the entire program on error!)
2111 * Valid keywords are:
2112 * conn, disk, fetch, store, ws
2113 * The disk value, if it has a % sign, signifies that attention
2114 * will be triggered when the disk is more than that percentage
2115 * full; otherwise, it will specify the minimum number of free
2120 *------------------------------------------------------------------------*/
2122 static void scout_AdoptThresholds(a_thresh_item)
2123 struct cmd_item *a_thresh_item;
2125 { /*scout_AdoptThresholds*/
2128 "scout_AdoptThresholds"; /*Routine name*/
2129 struct cmd_item *curr_item; /*Current item*/
2130 char *curr_name; /*Current name half of pair*/
2131 char *curr_value; /*Current value half of pair*/
2132 int diskval_len; /*Length of disk attn value*/
2134 curr_item = a_thresh_item;
2137 * If there isn't a corresponding value for the current
2138 * attention field, bitch & die.
2140 if (curr_item->next == (struct cmd_item *)0) {
2141 printf("[%s] No threshold value given for '%s'\n",
2142 rn, curr_item->data);
2143 scout_CleanExit(-1);
2146 curr_name = curr_item->data;
2147 curr_value = curr_item->next->data;
2149 if (strcmp(curr_name, "conn") == 0) {
2151 fprintf(scout_debugfd,
2152 "[%s] Setting conn attn value to %d (default %d)\n",
2153 rn, curr_value, scout_attn_conn);
2154 fflush(scout_debugfd);
2156 scout_attn_conn = atoi(curr_value);
2158 else if (strcmp(curr_name, "disk") == 0) {
2160 * If there's a '%' as the last character in the value,
2161 * we use percentage mode.
2163 diskval_len = strlen(curr_value);
2164 if (curr_value[diskval_len-1] == '%') {
2165 curr_value[diskval_len-1] = '\0';
2167 fprintf(scout_debugfd,
2168 "[%s] New disk attn value: 0.%s used (default %f)\n",
2169 rn, curr_value, scout_attn_disk_pcused);
2170 fflush(scout_debugfd);
2172 sprintf(scout_attn_disk_pcusedstr, "%s", curr_value);
2173 scout_attn_disk_pcused =
2174 ((float)(atoi(curr_value)))/((float)(100));
2175 } /*Percentage mode*/
2178 fprintf(scout_debugfd,
2179 "[%s] New disk attn value: %s min free (default %d)\n",
2180 rn, atoi(curr_value), scout_attn_disk_pcused);
2181 fflush(scout_debugfd);
2183 scout_attn_disk_mode = SCOUT_DISKM_MINFREE;
2184 scout_attn_disk_minfree = atoi(curr_value);
2185 } /*Min free blocks mode*/
2187 else if (strcmp(curr_name, "fetch") == 0) {
2189 fprintf(scout_debugfd,
2190 "[%s] Setting fetch attn value to %d (default %d)\n",
2191 rn, curr_value, scout_attn_fetch);
2192 fflush(scout_debugfd);
2194 scout_attn_fetch = atoi(curr_value);
2196 else if (strcmp(curr_name, "store") == 0) {
2198 fprintf(scout_debugfd,
2199 "[%s] Setting store attn value to %d (default %d)\n",
2200 rn, curr_value, scout_attn_store);
2201 fflush(scout_debugfd);
2203 scout_attn_store = atoi(curr_value);
2205 else if (strcmp(curr_name, "ws") == 0) {
2207 fprintf(scout_debugfd,
2208 "[%s] Setting workstation attn value to %d (default %d)\n",
2209 rn, curr_value, scout_attn_workstations);
2210 fflush(scout_debugfd);
2212 scout_attn_workstations = atoi(curr_value);
2215 printf("[%s] Unknown attention item: '%s'\n", rn, curr_item->data);
2216 scout_CleanExit(-1);
2220 * Advance past the just-processed pair.
2222 curr_item = curr_item->next->next;
2224 } /*Interpret each name-value pair*/
2226 } /*scout_AdoptThresholds*/
2228 /*------------------------------------------------------------------------
2232 * Routine called when Scout is invoked, responsible for basic
2233 * initialization, command line parsing, and calling the
2234 * routine that does all the work.
2237 * as : Command syntax descriptor.
2238 * arock : Associated rock (not used here).
2241 * Zero (but may exit the entire program on error!)
2244 * Nothing interesting.
2247 * Initializes this program.
2248 *------------------------------------------------------------------------*/
2250 static int scoutInit(as, arock)
2251 struct cmd_syndesc *as;
2256 static char rn[] = "scoutInit"; /*Routine name*/
2257 int code; /*Return code*/
2258 int wpkg_to_use; /*Window package to use*/
2259 int server_count; /*Number of servers to watch*/
2260 char *debug_filename; /*Name of debugging output file*/
2263 fprintf(scout_debugfd, "[%s] Called\n", rn);
2264 fflush(scout_debugfd);
2267 if (as->parms[P_DEBUG].items != 0) {
2269 debug_filename = as->parms[P_DEBUG].items->data;
2270 scout_debugfd = fopen(debug_filename, "w");
2271 if (scout_debugfd == (FILE *)0) {
2272 printf("[%s] Can't open debugging file '%s'!\n", rn, debug_filename);
2273 scout_CleanExit(-1);
2275 fprintf(scout_debugfd, "[%s] Writing to Scout debugging file '%s'\n",
2276 rn, debug_filename);
2279 wpkg_to_use = atoi(as->parms[P_PACKAGE].items->data);
2281 wpkg_to_use = 2; /*Always use curses for now*/
2283 fprintf(stderr, "[%s:%s] Using graphics package %d: ", pn, rn, wpkg_to_use);
2284 switch (wpkg_to_use) {
2285 case GATOR_WIN_CURSES:
2286 fprintf(stderr, "curses\n");
2288 case GATOR_WIN_DUMB:
2289 fprintf(stderr, "dumb terminal\n");
2292 fprintf(stderr, "X11\n");
2295 fprintf(stderr, "Illegal graphics package: %d\n", wpkg_to_use);
2296 scout_CleanExit(-1);
2297 } /*end switch (wpkg_to_use)*/
2300 if (as->parms[P_FREQ].items != 0)
2301 scout_probefreq = atoi(as->parms[P_FREQ].items->data);
2303 scout_probefreq = 60;
2306 * See if we've been fed a base server name.
2308 if (as->parms[P_BASE].items != 0)
2309 sprintf(scout_basename, "%s", as->parms[P_BASE].items->data);
2311 *scout_basename = '\0';
2314 * Count the number of servers we've been asked to monitor.
2316 server_count = countServers(as->parms[P_SERVER].items);
2319 * Create a line of blanks, a generally-useful thing.
2321 sprintf(scout_blankline, "%255s", " ");
2324 * Pull in the name of the host we're executing on if we've been
2325 * asked to. If we can't get the name, we provide a default.
2327 if (as->parms[P_HOST].items != 0) {
2328 scout_showhostname = 1;
2329 *scout_hostname = '\0';
2330 code = gethostname(scout_hostname, 128);
2332 sprintf(scout_hostname, "%s", "*No Hostname*");
2336 * Pull in any and all attention/highlighting thresholds.
2338 if (as->parms[P_ATTENTION].items != 0)
2339 scout_AdoptThresholds(as->parms[P_ATTENTION].items);
2342 * Now, drive the sucker.
2344 code = execute_scout(server_count, /*Num servers*/
2345 as->parms[P_SERVER].items, /*Ptr to srv names*/
2346 wpkg_to_use); /*Graphics pkg*/
2348 fprintf(stderr, "[%s] Error executing scout: %d\n", rn, code);
2349 scout_CleanExit(-1);
2353 * We initialized (and ran) correctly, so return the good news.
2359 #include "AFS_component_version_number.c"
2367 register afs_int32 code; /*Return code*/
2368 register struct cmd_syndesc *ts; /*Ptr to cmd line syntax descriptor*/
2370 #ifdef AFS_AIX32_ENV
2372 * The following signal action for AIX is necessary so that in case of a
2373 * crash (i.e. core is generated) we can include the user's data section
2374 * in the core dump. Unfortunately, by default, only a partial core is
2375 * generated which, in many cases, isn't too useful.
2377 struct sigaction nsa;
2379 sigemptyset(&nsa.sa_mask);
2380 nsa.sa_handler = SIG_DFL;
2381 nsa.sa_flags = SA_FULLDUMP;
2382 sigaction(SIGSEGV, &nsa, NULL);
2385 * Set up the commands we understand.
2387 ts = cmd_CreateSyntax("initcmd", scoutInit, 0,
2388 "initialize the program");
2389 cmd_AddParm(ts, "-server", CMD_LIST, CMD_REQUIRED,
2390 "FileServer name(s) to monitor");
2391 cmd_AddParm(ts, "-basename", CMD_SINGLE, CMD_OPTIONAL,
2392 "base server name");
2394 cmd_AddParm(ts, "-package", CMD_SINGLE, CMD_REQUIRED,
2395 "Graphics package to use");
2397 cmd_AddParm(ts, "-frequency", CMD_SINGLE, CMD_OPTIONAL,
2398 "poll frequency, in seconds");
2399 cmd_AddParm(ts, "-host", CMD_FLAG, CMD_OPTIONAL,
2400 "show name of host you're running on");
2401 cmd_AddParm(ts, "-attention", CMD_LIST, CMD_OPTIONAL,
2402 "specify attention (highlighting) level");
2403 cmd_AddParm(ts, "-debug", CMD_SINGLE, CMD_OPTIONAL,
2404 "turn debugging output on to the named file");
2407 * Parse command-line switches & execute the test, then get the heck
2410 code = cmd_Dispatch(argc, argv);
2413 fprintf(stderr, "[%s:%s] Call to cmd_Dispatch() failed; code is %d\n", pn, rn, code);