AFS-Monitor

 view release on metacpan or  search on metacpan

src/Monitor.xs  view on Meta::CPAN

/***********************************************************************
 *
 * AFS.xs - AFS extensions for Perl
 *
 * RCS-Id: @(#)$Id: Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $
 *
 * Copyright (c) 2003, International Business Machines Corporation and others.
 *
 * This software has been released under the terms of the IBM Public
 * License.  For details, see the IBM-LICENSE file in the LICENCES
 * directory or online at http://www.openafs.org/dl/license10.html
 *
 * Contributors
 *         2004-2006: Elizabeth Cassell <e_a_c@mailsnare.net>
 *                    Alf Wachsmann <alfw@slac.stanford.edu>
 *
 * The code for the original library were mainly taken from the AFS
 * source distribution, which comes with this message:
 *
 *    Copyright (C) 1989-1994 Transarc Corporation - All rights reserved
 *    P_R_P_Q_# (C) COPYRIGHT IBM CORPORATION 1987, 1988, 1989
 *
 ***********************************************************************/

#include "EXTERN.h"

#ifdef __sgi    /* needed to get a clean compile */
#include <setjmp.h>
#endif

#include <stdarg.h>

#include "perl.h"
#include "XSUB.h"
#include "ppport.h"

#include <afs/afsint.h>

#include <afs/kautils.h>

#include <afs/xstat_fs.h>
#include <afs/xstat_cm.h>
#include "afsmon-labels.h"  /* labels for afsmonitor variables */

#include <afs/fsprobe.h>

/* from volser/volser_prototypes.h */
extern void MapPartIdIntoName(afs_int32 partId, char *partName);


#if defined(AFS_3_4) || defined(AFS_3_5)
#else
#define int32 afs_int32
#define uint32 afs_uint32
#endif

const char *const xs_version = "Monitor.xs (Major Version 0.2 $Rev: 609 $)";

extern char *error_message();
extern struct hostent *hostutil_GetHostByName();
extern char *hostutil_GetNameByINet();

/* error handling macros */

#define SETCODE(code) set_code(code)
#define FSSETCODE(code) {if (code == -1) set_code(errno); else set_code(code);}
#define BSETCODE(code, msg) bv_set_code(code, msg)
#define VSETCODE(code, msg) bv_set_code(code, msg)

static int32 raise_exception = 0;


static void
bv_set_code(code, msg)
   int32 code;
   const char *msg;
{
   SV *sv = perl_get_sv("AFS::CODE", TRUE);
   sv_setiv(sv, (IV) code);
   if (code == 0) {
      sv_setpv(sv, "");
   }
   else {
      if (raise_exception) {
         char buffer[1024];
         sprintf(buffer, "AFS exception: %s (%d)", msg, code);
         croak(buffer);
      }
      sv_setpv(sv, (char *)msg);
   }
   SvIOK_on(sv);
}

static void
set_code(code)
   int32 code;
{
   SV *sv = perl_get_sv("AFS::CODE", TRUE);
   sv_setiv(sv, (IV) code);
   if (code == 0) {
      sv_setpv(sv, "");
   }
   else {
      if (raise_exception) {
         char buffer[1024];
         sprintf(buffer, "AFS exception: %s (%d)", error_message(code), code);
         croak(buffer);
      }
      sv_setpv(sv, (char *)error_message(code));
   }
   SvIOK_on(sv);
}

/* end of error handling macros */


/* start of rxdebug helper functions */


/*
 * from src/rxdebug/rxdebug.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

static short
rxdebug_PortNumber(aport)
   register char *aport;
{
   register int tc;
   register short total;

   total = 0;
   while ((tc = (*aport++))) {
      if (tc < '0' || tc > '9')
         return -1; /* bad port number */
      total *= 10;
      total += tc - (int)'0';
   }
   return htons(total);
}


/*
 * from src/rxdebug/rxdebug.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

static short
rxdebug_PortName(char *aname)
{
   register struct servent *ts;
   ts = getservbyname(aname, (char *) NULL);
   if (!ts)
      return -1;
   return ts->s_port;   /* returns it in network byte order */
}


/*
 * replaces rx_PrintTheseStats() in original c code.
 * places stats in RXSTATS instead of printing them
 * from src/rx/rx.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

static void
myPrintTheseStats(HV *RXSTATS, struct rx_statistics *rxstats)
{
   HV *PACKETS;
   HV *TYPE;
   HV *TOTALRTT;
   HV *MINRTT;
   HV *MAXRTT;
   int i;

src/Monitor.xs  view on Meta::CPAN

 * from src/afsmonitor/afsmonitor.c:
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_insert_CM(a_hostName, nameList, last_hostEntry)
   char *a_hostName;            /* name of cache manager to be inserted in list */
   struct afsmon_hostEntry **nameList;
   struct afsmon_hostEntry **last_hostEntry;
{
   static struct afsmon_hostEntry *curr_item;
   static struct afsmon_hostEntry *prev_item;

   if (*a_hostName == '\0')
      return (-1);

   curr_item = (struct afsmon_hostEntry *)
      malloc(sizeof(struct afsmon_hostEntry));
   if (curr_item == (struct afsmon_hostEntry *) NULL) {
      warn("Failed to allocate space for nameList\n");
      return (-1);
   }

   strncpy(curr_item->hostName, a_hostName, CFG_STR_LEN);
   curr_item->next = (struct afsmon_hostEntry *) NULL;
   curr_item->numThresh = 0;
   curr_item->thresh = NULL;

   if ((*nameList) == (struct afsmon_hostEntry *) NULL) {
      (*nameList) = curr_item;
   }
   else {
      prev_item->next = curr_item;
   }

   prev_item = curr_item;
   /*  record the address of this entry so that its threshold */
   /* count can be incremented during  the first pass of the config file */
   (*last_hostEntry) = curr_item;

   return (0);
}   /* my_insert_CM() */



/*
 * parses a threshold entry line in the config file.
 *
 * from src/afsmonitor/afsmonitor.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_parse_threshEntry(a_line, global_fsThreshCount, global_cmThreshCount,
                     last_hostEntry, lastHostType, buffer)
   char *a_line;                /* line that is being parsed */
   int *global_fsThreshCount;   /* count of global file server thresholds */
   int *global_cmThreshCount;   /* count of global cache manager thresholds */
   struct afsmon_hostEntry *last_hostEntry; /* a pointer to the last host entry */
   int lastHostType;            /* points to an integer specifying whether the last host was fs or cm */
   char *buffer;                /* to return error messages in */
{
   char opcode[CFG_STR_LEN];    /* junk characters */
   char arg1[CFG_STR_LEN];      /* hostname or qualifier (fs/cm?)  */
   char arg2[CFG_STR_LEN];      /* threshold variable */
   char arg3[CFG_STR_LEN];      /* threshold value */
   char arg4[CFG_STR_LEN];      /* user's handler  */
   char arg5[CFG_STR_LEN];      /* junk characters */


   /* break it up */
   opcode[0] = 0;
   arg1[0] = 0;
   arg2[0] = 0;
   arg3[0] = 0;
   arg4[0] = 0;
   arg5[0] = 0;
   sscanf(a_line, "%s %s %s %s %s %s", opcode, arg1, arg2, arg3, arg4, arg5);

   /* syntax is "thresh fs/cm variable_name threshold_value [handler] " */
   if (((strlen(arg1)) == 0) || ((strlen(arg2)) == 0)
       || ((strlen(arg3)) == 0)) {
      sprintf(buffer, "Incomplete line");
      return (-1);
   }
   if (strlen(arg3) > THRESH_VAR_LEN - 2) {
      sprintf(buffer, "threshold value too long");
      return (-1);
   }

   if ((strcasecmp(arg1, "fs")) == 0) {
      switch (lastHostType) {
        case 0:    /* its a global threshold */
           (*global_fsThreshCount)++;
           break;
        case 1:    /* inc thresh count of last file server */
           last_hostEntry->numThresh++;
           break;
        case 2:
           sprintf(buffer,
                   "A threshold for a File Server cannot be placed after a Cache Manager host entry in the config file");
           return (-1);
        default:
           sprintf(buffer, "Programming error 1");
           return (-1);
      }
   }
   else if ((strcasecmp(arg1, "cm")) == 0) {
      switch (lastHostType) {
        case 0:    /* its a global threshold */
           (*global_cmThreshCount)++;
           break;
        case 2:    /* inc thresh count of last cache manager */
           last_hostEntry->numThresh++;
           break;
        case 1:
           sprintf(buffer,
                   "A threshold for a Cache Manager cannot be placed after a File Server host entry in the config file");
           return (-1);
        default:
           sprintf(buffer, "Programming error 2");
           return (-1);
      }
   }
   else {
      sprintf(buffer,
              "Syntax error. Second argument should be \"fs\" or \"cm\"");
      return (-1);
   }

   return (0);
}   /* my_parse_threshEntry() */



/*
 * from src/afsmonitor/afsmonitor.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_parse_showEntry(a_line, fs_showDefault, cm_showDefault, fs_showFlags,
                   cm_showFlags, buffer)
   char *a_line;
   int *fs_showDefault;
   int *cm_showDefault;
   short *fs_showFlags;
   short *cm_showFlags;
   char *buffer;
{

   char opcode[CFG_STR_LEN];    /* specifies type of config entry */
   char arg1[CFG_STR_LEN];      /* show fs or cm entry ? */
   char arg2[CFG_STR_LEN];      /* what we gotta show  */
   char arg3[CFG_STR_LEN];      /* junk */
   char catName[CFG_STR_LEN];   /* for category names */
   int numGroups = 0;           /* number of groups in a section */
   int fromIdx = 0;
   int toIdx = 0;
   int found = 0;
   int idx = 0;                 /* index to fs_categories[] */
   int i = 0;
   int j = 0;

   extern char *fs_varNames[];
   extern char *cm_varNames[];
   extern char *fs_categories[];    /* file server data category names */
   extern char *cm_categories[];    /* cache manager data category names */

   opcode[0] = 0;
   arg1[0] = 0;
   arg2[0] = 0;
   arg3[0] = 0;
   sscanf(a_line, "%s %s %s %s", opcode, arg1, arg2, arg3);

   if (arg3[0] != '\0') {
      sprintf(buffer, "Extraneous characters at end of line");
      return (-1);
   }

   if ((strcasecmp(arg1, "fs") != 0) && (strcasecmp(arg1, "cm") != 0)) {
      sprintf(buffer,
              "Second argument of \"show\" directive should be \"fs\" or \"cm\"");
      return (-1);
   }

   /* Each entry can either be a variable name or a section/group name. Variable

src/Monitor.xs  view on Meta::CPAN

            found = 1;
            break;
         }
      }
      if (!found) {
         sprintf(buffer, "Unknown FS threshold variable name %s", a_varName);
         return (-1);
      }
   }
   else if (a_type == CM) { /* cm threshold */
      for (index = 0; index < NUM_CM_STAT_ENTRIES; index++) {
         if (strcasecmp(a_varName, cm_varNames[index]) == 0) {
            found = 1;
            break;
         }
      }
      if (!found) {
         sprintf(buffer, "Unknown CM threshold variable name %s", a_varName);
         return (-1);
      }
   }
   else
      return (-1);

   /* if the global thresh count is not zero, place this threshold on
    * all the host entries  */

   if (*global_TC) {
      tmp_host = Header;
      for (i = 0; i < srvCount; i++) {
         threshP = tmp_host->thresh;
         done = 0;
         for (j = 0; j < tmp_host->numThresh; j++) {
            if ((threshP->itemName[0] == '\0') ||
                (strcasecmp(threshP->itemName, a_varName) == 0)) {
               strncpy(threshP->itemName, a_varName, THRESH_VAR_NAME_LEN);
               strncpy(threshP->threshVal, a_value, THRESH_VAR_LEN);
               strcpy(threshP->handler, a_handler);
               threshP->index = index;
               done = 1;
               break;
            }
            threshP++;
         }
         if (!done) {
            sprintf(buffer,
                    "Could not insert threshold entry for %s in thresh list of host %s",
                    a_varName, tmp_host->hostName);
            return (-1);
         }
         tmp_host = tmp_host->next;
      }
      (*global_TC)--;
      return (0);
   }

   /* it is not a global threshold, insert it in the thresh list of this
    * host only. We overwrite the global threshold if it was already set */

   if (*hostname == '\0') {
      sprintf(buffer, "Programming error 3");
      return (-1);
   }

   /* get the hostEntry that this threshold belongs to */
   tmp_host = Header;
   found = 0;
   for (i = 0; i < srvCount; i++) {
      if (strcasecmp(tmp_host->hostName, hostname) == 0) {
         found = 1;
         break;
      }
      tmp_host = tmp_host->next;
   }
   if (!found) {
      sprintf(buffer, "Unable to find host %s in %s hostEntry list", hostname,
              (a_type - 1) ? "CM" : "FS");
      return (-1);
   }

   /* put this entry on the thresh list of this host, overwrite global value
    * if needed */

   threshP = tmp_host->thresh;
   done = 0;
   for (i = 0; i < tmp_host->numThresh; i++) {
      if ((threshP->itemName[0] == '\0') ||
          (strcasecmp(threshP->itemName, a_varName) == 0)) {
         strncpy(threshP->itemName, a_varName, THRESH_VAR_NAME_LEN);
         strncpy(threshP->threshVal, a_value, THRESH_VAR_LEN);
         strcpy(threshP->handler, a_handler);
         threshP->index = index;
         done = 1;
         break;
      }
      threshP++;
   }

   if (!done) {
      sprintf(buffer, "Unable to insert threshold %s for %s host %s",
              a_varName, (a_type - 1) ? "CM" : "FS", tmp_host->hostName);
      return (-1);
   }

   return (0);

}   /* my_store_threshold() */



/*
 * from /src/afsmonitor/afsmonitor.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 *
 * int
 * check_fs_thresholds(a_hostEntry, a_Data)
 * struct afsmon_hostEntry *a_hostEntry;
 * struct fs_Display_Data *a_Data;
 *
 * and
 *

src/Monitor.xs  view on Meta::CPAN

               break;
            }
         }
         if (found)
            break;
      }

      if (!found) {
         threshP++;
         continue;
      }

      if (pValue > tValue) {
         hv_store(VALUE, "overflow", 8, newSViv(1), 0);
         hv_store(VALUE, "threshold", 9, newSVnv(tValue), 0);

         if (threshP->handler[0] != '\0') {
            sprintf(strval, "%g", pValue);
            code = my_execute_thresh_handler(threshP->handler,
                                             a_hostEntry->hostName, type,
                                             threshP->itemName,
                                             threshP->threshVal, strval,
                                             VALUE, buffer);
            if (code) {
               return (code);
            }
         }

         count++;
      }
      threshP++;
   }

   return (0);
}   /* my_check_thresholds() */




/*
 * from src/afsmonitor/afsmonitor.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_process_config_file(a_config_filename, numFS, numCM, lastHostType,
                       last_hostEntry, fs_showDefault, cm_showDefault,
                       fs_showFlags, cm_showFlags, FSnameList, CMnameList)
   char *a_config_filename;
   int *numFS;
   int *numCM;
   int *lastHostType;
   struct afsmon_hostEntry **last_hostEntry;
   int *fs_showDefault;
   int *cm_showDefault;
   short *fs_showFlags;
   short *cm_showFlags;
   struct afsmon_hostEntry **FSnameList;
   struct afsmon_hostEntry **CMnameList;
{
   char buff1[256] = "";        /* for error messages */
   char buff2[256] = "";        /* for error messages returned from subroutines */
   FILE *configFD = 0;          /* config file descriptor */
   char line[4 * CFG_STR_LEN];  /* a line of config file */
   char opcode[CFG_STR_LEN];    /* specifies type of config entry */
   char arg1[CFG_STR_LEN];      /* hostname or qualifier (fs/cm?)  */
   char arg2[CFG_STR_LEN];      /* threshold variable */
   char arg3[CFG_STR_LEN];      /* threshold value */
   char arg4[CFG_STR_LEN];      /* user's handler  */
   struct afsmon_hostEntry *curr_host = 0;
   struct hostent *he = 0;      /* hostentry to resolve host name */
   char *handlerPtr = 0;        /* ptr to pass theresh handler string */
   int code = 0;                /* error code */
   int linenum = 0;             /* config file line number */
   int threshCount = 0;         /* count of thresholds for each server */
   int error_in_config = 0;     /* syntax errors in config file  ?? */
   int i = 0;
   int numBytes = 0;
   /* int global_ThreshFlag = 1; */
   int global_fsThreshCount = 0;
   int global_cmThreshCount = 0;
   static char last_fsHost[HOST_NAME_LEN];
   static char last_cmHost[HOST_NAME_LEN];

   /* open config file */
   configFD = fopen(a_config_filename, "r");
   if (configFD == (FILE *) NULL) {
      sprintf(buff1, "Failed to open config file %s", a_config_filename);
      BSETCODE(5, buff1);
      return (-1);
   }

   /* parse config file */

   /* First Pass - check syntax and count number of servers and thresholds to monitor */

   *numFS = 0;
   *numCM = 0;
   threshCount = 0;
   error_in_config = 0; /* flag to note if config file has syntax errors */

   while ((fgets(line, CFG_STR_LEN, configFD)) != NULL) {
      opcode[0] = 0;
      arg1[0] = 0;
      arg2[0] = 0;
      arg3[0] = 0;
      arg4[0] = 0;
      sscanf(line, "%s %s %s %s %s", opcode, arg1, arg2, arg3, arg4);
      linenum++;
      /* fprintf(STDERR, "Got line %d: \"%s %s %s %s %s\"\n",
       * linenum, opcode, arg1, arg2, arg3, arg4); */
      /* skip blank lines and comment lines */
      if ((strlen(opcode) == 0) || line[0] == '#') {
         /* fprintf(STDERR, " - skipping line %d\n", linenum); */
         continue;
      }
      if ((strcasecmp(opcode, "fs") == 0) || (strcasecmp(opcode, "cm")) == 0) {
         /* fprintf(STDERR, " - parsing host entry\n"); */
         code =
            my_parse_hostEntry(line, numFS, numCM, lastHostType,
                               last_hostEntry, FSnameList, CMnameList, buff2);
         /* thresholds are not global anymore */
         /* if (global_ThreshFlag) global_ThreshFlag = 0; */
      }
      else if ((strcasecmp(opcode, "thresh")) == 0) {
         /* fprintf(STDERR, " - parsing thresh entry\n"); */
         code =
            my_parse_threshEntry(line, &global_fsThreshCount,
                                 &global_cmThreshCount, *last_hostEntry,
                                 *lastHostType, buff2);
      }
      else if ((strcasecmp(opcode, "show")) == 0) {
         /* fprintf(STDERR, " - parsing show entry\n"); */
         code =
            my_parse_showEntry(line, fs_showDefault, cm_showDefault,
                               fs_showFlags, cm_showFlags, buff2);
      }
      else {
         /* fprintf(STDERR, " - unknown entry\n"); */
         sprintf(buff2, "Unknown opcode %s", opcode);
         code = 1;
      }

      if (code) {
         sprintf(buff1,
                 "Error processing config file line %d (\"%s %s %s %s %s\"). %s",
                 linenum, opcode, arg1, arg2, arg3, arg4, buff2);
         error_in_config = 1;
         BSETCODE(10, buff1);
         return (-1);
      }
   }
   /* fprintf(STDERR, "got to end of file.\n"); */

   if (error_in_config) {
      sprintf(buff1, "Error in config file. %s", buff2);
      BSETCODE(10, buff1);
      return (-1);
   }

   /* the threshold count of all hosts in increased by 1 for each global
    * threshold. If one of the hosts has a local threshold for the same
    * variable it would end up being counted twice. whats a few bytes of memory
    * wasted anyway ? */

   if (global_fsThreshCount) {
      curr_host = *FSnameList;
      for (i = 0; i < *numFS; i++) {
         curr_host->numThresh += global_fsThreshCount;
         curr_host = curr_host->next;
      }
   }
   if (global_cmThreshCount) {
      curr_host = *CMnameList;
      for (i = 0; i < *numCM; i++) {
         curr_host->numThresh += global_cmThreshCount;
         curr_host = curr_host->next;
      }
   }

   /* make sure we have something to monitor */
   if (*numFS == 0 && *numCM == 0) {
      sprintf(buff1,
              "Config file must specify atleast one File Server or Cache Manager host to monitor.");
      fclose(configFD);
      BSETCODE(15, buff1);
      return (-1);
   }

   /* Second Pass */

   fseek(configFD, 0, 0);   /* seek to the beginning */

   /* allocate memory for threshold lists */

   curr_host = *FSnameList;
   for (i = 0; i < *numFS; i++) {
      if (curr_host->hostName[0] == '\0') {
         sprintf(buff1, "Programming error 4");
         BSETCODE(20, buff1);
         return (-1);
      }
      if (curr_host->numThresh) {
         numBytes = curr_host->numThresh * sizeof(struct Threshold);
         curr_host->thresh = (struct Threshold *)malloc(numBytes);
         if (curr_host->thresh == (struct Threshold *) NULL) {
            sprintf(buff1, "Memory Allocation error 1");
            BSETCODE(25, buff1);
            return (-1);
         }
         memset(curr_host->thresh, 0, numBytes);
      }
      curr_host = curr_host->next;
   }

   curr_host = *CMnameList;
   for (i = 0; i < *numCM; i++) {
      if (curr_host->hostName[0] == '\0') {
         sprintf(buff1, "Programming error 5");
         BSETCODE(30, buff1);
         return (-1);
      }
      if (curr_host->numThresh) {
         numBytes = curr_host->numThresh * sizeof(struct Threshold);
         curr_host->thresh = (struct Threshold *)malloc(numBytes);
         if (curr_host->thresh == (struct Threshold *) NULL) {
            sprintf(buff1, "Memory Allocation error 2");
            BSETCODE(35, buff1);
            return (-1);
         }
         memset(curr_host->thresh, 0, numBytes);
      }
      curr_host = curr_host->next;
   }

   opcode[0] = 0;
   arg1[0] = 0;
   arg2[0] = 0;
   arg3[0] = 0;
   arg4[0] = 0;
   last_fsHost[0] = '\0';
   last_cmHost[0] = '\0';
   linenum = 0;
   while ((fgets(line, CFG_STR_LEN, configFD)) != NULL) {
      opcode[0] = 0;
      arg1[0] = 0;
      arg2[0] = 0;
      arg3[0] = 0;
      arg4[0] = 0;
      sscanf(line, "%s %s %s %s %s", opcode, arg1, arg2, arg3, arg4);
      linenum++;

      /* if we have a host entry, remember the host name */
      if (strcasecmp(opcode, "fs") == 0) {
         he = GetHostByName(arg1);
         strncpy(last_fsHost, he->h_name, HOST_NAME_LEN);
      }
      else if (strcasecmp(opcode, "cm") == 0) {
         he = GetHostByName(arg1);
         strncpy(last_cmHost, he->h_name, HOST_NAME_LEN);
      }
      else if (strcasecmp(opcode, "thresh") == 0) {
         /* if we have a threshold handler it may have arguments
          * and the sscanf() above would not get them, so do the
          * following */
         if (strlen(arg4)) {
            handlerPtr = line;
            /* now skip over 4 words - this is done by first
             * skipping leading blanks then skipping a word */
            for (i = 0; i < 4; i++) {
               while (isspace(*handlerPtr))
                  handlerPtr++;
               while (!isspace(*handlerPtr))
                  handlerPtr++;
            }
            while (isspace(*handlerPtr))
               handlerPtr++;
            /* we how have a pointer to the start of the handler
             * name & args */
         }
         else
            handlerPtr = arg4;  /* empty string */

         if (strcasecmp(arg1, "fs") == 0)
            code = my_store_threshold(1,    /* 1 = fs */
                                      arg2, arg3, handlerPtr,
                                      &global_fsThreshCount, *FSnameList,
                                      last_fsHost, *numFS, buff2);

         else if (strcasecmp(arg1, "cm") == 0)
            code = my_store_threshold(2,    /* 2 = cm */
                                      arg2, arg3, handlerPtr,
                                      &global_cmThreshCount, *CMnameList,
                                      last_cmHost, *numCM, buff2);

         else {
            sprintf(buff1, "Programming error 6");
            BSETCODE(40, buff1);
            return (-1);
         }
         if (code) {
            sprintf(buff1,
                    "Error processing config file line %d (\"%s %s %s %s %s\"): Failed to store threshold. %s",
                    linenum, opcode, arg1, arg2, arg3, arg4, buff2);
            BSETCODE(45, buff1);
            return (-1);
         }
      }
   }

   fclose(configFD);
   return (0);
}   /* my_process_config_file() */




/*
 * from src/afsmonitor/afsmon-output.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_Print_fs_OpTiming(a_opIdx, a_opTimeP, fs_outFD)
   int a_opIdx;
   struct fs_stats_opTimingData *a_opTimeP;
   FILE *fs_outFD;
{

   fprintf(fs_outFD,
           "%15s: %d ops (%d OK); sum=%d.%06d, min=%d.%06d, max=%d.%06d\n",
           fsOpNames[a_opIdx], a_opTimeP->numOps, a_opTimeP->numSuccesses,
           a_opTimeP->sumTime.tv_sec, a_opTimeP->sumTime.tv_usec,
           a_opTimeP->minTime.tv_sec, a_opTimeP->minTime.tv_usec,
           a_opTimeP->maxTime.tv_sec, a_opTimeP->maxTime.tv_usec);
}   /* my_Print_fs_OpTiming() */


/*
 * from src/afsmonitor/afsmon-output.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_Print_fs_XferTiming(a_opIdx, a_xferP, fs_outFD)
   int a_opIdx;
   struct fs_stats_xferData *a_xferP;
   FILE *fs_outFD;
{

   fprintf(fs_outFD,
           "%s: %d xfers (%d OK), time sum=%d.%06d, min=%d.%06d, max=%d.%06d\n",
           xferOpNames[a_opIdx], a_xferP->numXfers, a_xferP->numSuccesses,
           a_xferP->sumTime.tv_sec, a_xferP->sumTime.tv_usec,
           a_xferP->minTime.tv_sec, a_xferP->minTime.tv_usec,
           a_xferP->maxTime.tv_sec, a_xferP->maxTime.tv_usec);
   fprintf(fs_outFD, "\t[bytes: sum=%d, min=%d, max=%d]\n",

src/Monitor.xs  view on Meta::CPAN

   struct xstat_fs_ConnectionInfo *xstat_fs_ConnInfo;
   int xstat_fs_numServers;
   afs_int32 *xstat_fs_collIDP;
   int xstat_fs_numCollections;
   char *buffer;
   va_list argp;
{
   afs_int32 srvVersionNumber = 0;  /*Xstat version # */
   afs_int32 clientVersionNumber = AFS_XSTAT_VERSION;   /*Client xstat version */
   afs_int32 *currCollIDP = 0;
   int numColls = 0;
   int conn_idx = 0;
   struct xstat_fs_ConnectionInfo *curr_conn = 0;
   char buff2[256] = "";
   int code = 0;
   int index = 0;

   struct xstat_fs_ProbeResults xstat_fs_Results;
   afs_int32 xstat_fsData[AFS_MAX_XSTAT_LONGS];
   xstat_fs_Results.probeTime = 0;
   xstat_fs_Results.connP = (struct xstat_fs_ConnectionInfo *) NULL;
   xstat_fs_Results.collectionNumber = 0;
   xstat_fs_Results.data.AFS_CollData_len = AFS_MAX_XSTAT_LONGS;
   xstat_fs_Results.data.AFS_CollData_val = (afs_int32 *) xstat_fsData;
   xstat_fs_Results.probeOK = 0;

   curr_conn = xstat_fs_ConnInfo;
   for (conn_idx = 0; conn_idx < xstat_fs_numServers; conn_idx++) {
      /*
       * Grab the statistics for the current File Server, if the
       * connection is valid.
       */
      if (curr_conn->rxconn != (struct rx_connection *) NULL) {

         currCollIDP = xstat_fs_collIDP;
         for (numColls = 0;
              numColls < xstat_fs_numCollections; numColls++, currCollIDP++) {
            /*
             * Initialize the per-probe values.
             */
            xstat_fs_Results.collectionNumber = *currCollIDP;
            xstat_fs_Results.data.AFS_CollData_len = AFS_MAX_XSTAT_LONGS;
            memset(xstat_fs_Results.data.AFS_CollData_val, 0,
                   AFS_MAX_XSTAT_LONGS * 4);

            xstat_fs_Results.connP = curr_conn;

            xstat_fs_Results.probeOK =
               RXAFS_GetXStats(curr_conn->rxconn,
                               clientVersionNumber,
                               *currCollIDP,
                               &srvVersionNumber,
                               &(xstat_fs_Results.probeTime),
                               &(xstat_fs_Results.data));
            code =
               ProbeHandler(xstat_fs_Results, xstat_fs_numServers, index,
                            buff2, argp);
            index++;

            if (code) {
               sprintf(buffer, "Handler returned error code %d. %s",
                       code, buff2);
               return (code);
            }

         }  /* For each collection */
      } /*Valid Rx connection */

      /*
       * Advance the xstat_fs connection pointer.
       */
      curr_conn++;

   }    /* For each xstat_fs connection */
   return (0);
}   /* my_xstat_fs_LWP() */


/*
 * from src/xstat/xstat_fs.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_xstat_fs_Init(int (*ProbeHandler) (), int xstat_fs_numServers,
                 struct sockaddr_in *a_socketArray,
                 int xstat_fs_numCollections, afs_int32 * xstat_fs_collIDP,
                 char *buffer, ...)
{
   int curr_srv = 0;
   int conn_err = 0;
   char *hostNameFound = "";
   struct xstat_fs_ConnectionInfo *curr_conn = 0, *xstat_fs_ConnInfo = 0;
   struct rx_securityClass *secobj = 0; /*Client security object */
   char buff2[256] = "";
   int PortToUse = 0;
   int code = 0;
   va_list argp;

   xstat_fs_ConnInfo = (struct xstat_fs_ConnectionInfo *)
      malloc(xstat_fs_numServers * sizeof(struct xstat_fs_ConnectionInfo));
   if (xstat_fs_ConnInfo == (struct xstat_fs_ConnectionInfo *) NULL) {
      sprintf(buffer,
              "Can't allocate %d connection info structs (%d bytes)",
              xstat_fs_numServers,
              (xstat_fs_numServers * sizeof(struct xstat_fs_ConnectionInfo)));
      return (-1);  /*No cleanup needs to be done yet */
   }

   PortToUse = XSTAT_FS_CBPORT;

   do {
      code = rx_Init(htons(PortToUse));
      if (code) {
         if (code == RX_ADDRINUSE) {
            PortToUse++;
         }
         else {
            sprintf(buffer, "Fatal error in rx_Init()");
            return (-1);
         }
      }
   } while (code);

    /*
     * Create a null Rx client security object, to be used by the
     * probe LWP.
     */
   secobj = rxnull_NewClientSecurityObject();
   if (secobj == (struct rx_securityClass *) NULL) {
      /*Delete already-malloc'ed areas */
      my_xstat_fs_Cleanup(1, xstat_fs_numServers, xstat_fs_ConnInfo, buff2);
      sprintf(buffer, "Can't create probe LWP client security object. %s",
              buff2);
      return (-1);
   }

   curr_conn = xstat_fs_ConnInfo;
   conn_err = 0;
   for (curr_srv = 0; curr_srv < xstat_fs_numServers; curr_srv++) {
      /*
       * Copy in the socket info for the current server, resolve its
       * printable name if possible.
       */

      memcpy(&(curr_conn->skt), a_socketArray + curr_srv,
             sizeof(struct sockaddr_in));

      hostNameFound = hostutil_GetNameByINet(curr_conn->skt.sin_addr.s_addr);
      if (hostNameFound == NULL) {
         warn("Can't map Internet address %lu to a string name",
              curr_conn->skt.sin_addr.s_addr);
         curr_conn->hostName[0] = '\0';
      }
      else {
         strcpy(curr_conn->hostName, hostNameFound);
      }

      /*
       * Make an Rx connection to the current server.
       */

      curr_conn->rxconn = rx_NewConnection(curr_conn->skt.sin_addr.s_addr,  /*Server addr */
                                           curr_conn->skt.sin_port, /*Server port */
                                           1,   /*AFS service # */
                                           secobj,  /*Security obj */
                                           0);  /*# of above */
      if (curr_conn->rxconn == (struct rx_connection *) NULL) {
         sprintf(buffer,
                 "Can't create Rx connection to server '%s' (%lu)",
                 curr_conn->hostName, curr_conn->skt.sin_addr.s_addr);
         my_xstat_fs_Cleanup(1, xstat_fs_numServers, xstat_fs_ConnInfo,
                             buff2);
         return (-2);
      }
      /*
       * Bump the current xstat_fs connection to set up.
       */
      curr_conn++;

   }    /*for curr_srv */


   va_start(argp, buffer);
   code =
      my_xstat_fs_LWP(ProbeHandler, xstat_fs_ConnInfo, xstat_fs_numServers,
                      xstat_fs_collIDP, xstat_fs_numCollections, buffer,
                      argp);
   va_end(argp);

   if (code) {
      return (code);
   }
   my_xstat_fs_Cleanup(1, xstat_fs_numServers, xstat_fs_ConnInfo, buff2);
   return (0);
}   /* my_xstat_fs_Init() */


/*

src/Monitor.xs  view on Meta::CPAN


   fprintf(cm_outFD, "\t\tDowntime incident distribution:\n");
   fprintf(cm_outFD, "\t\t\t%8d: 0 times\n", a_upDownP->downIncidents[0]);
   fprintf(cm_outFD, "\t\t\t%8d: 1 time\n", a_upDownP->downIncidents[1]);
   fprintf(cm_outFD, "\t\t\t%8d: 2 .. 5 times\n",
           a_upDownP->downIncidents[2]);
   fprintf(cm_outFD, "\t\t\t%8d: 6 .. 10 times\n",
           a_upDownP->downIncidents[3]);
   fprintf(cm_outFD, "\t\t\t%8d: 10 .. 50 times\n",
           a_upDownP->downIncidents[4]);
   fprintf(cm_outFD, "\t\t\t%8d: > 50 times\n", a_upDownP->downIncidents[5]);

}   /* my_Print_cm_UpDownStats() */


/*
 * from src/afsmonitor/afsmon-output.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_Print_cm_XferTiming(a_opIdx, a_opNames, a_xferP, cm_outFD)
   int a_opIdx;
   char *a_opNames[];
   struct afs_stats_xferData *a_xferP;
   FILE *cm_outFD;
{   /*Print_cm_XferTiming */

   fprintf(cm_outFD,
           "%s: %d xfers (%d OK), time sum=%d.%06d, min=%d.%06d, max=%d.%06d\n",
           a_opNames[a_opIdx], a_xferP->numXfers, a_xferP->numSuccesses,
           a_xferP->sumTime.tv_sec, a_xferP->sumTime.tv_usec,
           a_xferP->minTime.tv_sec, a_xferP->minTime.tv_usec,
           a_xferP->maxTime.tv_sec, a_xferP->maxTime.tv_usec);
   fprintf(cm_outFD, "\t[bytes: sum=%d, min=%d, max=%d]\n", a_xferP->sumBytes,
           a_xferP->minBytes, a_xferP->maxBytes);
   fprintf(cm_outFD,
           "\t[buckets: 0: %d, 1: %d, 2: %d, 3: %d, 4: %d, 5: %d 6: %d, 7: %d, 8: %d]\n",
           a_xferP->count[0], a_xferP->count[1], a_xferP->count[2],
           a_xferP->count[3], a_xferP->count[4], a_xferP->count[5],
           a_xferP->count[6], a_xferP->count[7], a_xferP->count[8]);

}   /* my_Print_cm_XferTiming() */


/*
 * from src/afsmonitor/afsmon-output.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_Print_cm_ErrInfo(a_opIdx, a_opNames, a_opErrP, cm_outFD)
   int a_opIdx;
   char *a_opNames[];
   struct afs_stats_RPCErrors *a_opErrP;
   FILE *cm_outFD;
{   /*Print_cm_ErrInfo */

   fprintf(cm_outFD,
           "%15s: %d server, %d network, %d prot, %d vol, %d busies, %d other\n",
           a_opNames[a_opIdx], a_opErrP->err_Server, a_opErrP->err_Network,
           a_opErrP->err_Protection, a_opErrP->err_Volume,
           a_opErrP->err_VolumeBusies, a_opErrP->err_Other);

}   /* my_Print_cm_ErrInfo() */



/*
 * from src/afsmonitor/afsmon-output.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_Print_cm_OpTiming(a_opIdx, a_opNames, a_opTimeP, cm_outFD)
   int a_opIdx;
   char *a_opNames[];
   struct afs_stats_opTimingData *a_opTimeP;
   FILE *cm_outFD;
{   /*Print_cm_OpTiming */

   fprintf(cm_outFD,
           "%15s: %d ops (%d OK); sum=%d.%06d, min=%d.%06d, max=%d.%06d\n",
           a_opNames[a_opIdx], a_opTimeP->numOps, a_opTimeP->numSuccesses,
           a_opTimeP->sumTime.tv_sec, a_opTimeP->sumTime.tv_usec,
           a_opTimeP->minTime.tv_sec, a_opTimeP->minTime.tv_usec,
           a_opTimeP->maxTime.tv_sec, a_opTimeP->maxTime.tv_usec);

}   /* my_Print_cm_OpTiming() */



/*
 * from src/afsmonitor/afsmon-output.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_Print_cm_OverallPerfInfo(a_ovP, cm_outFD)
   struct afs_stats_CMPerf *a_ovP;
   FILE *cm_outFD;
{

   fprintf(cm_outFD, "\t%10d numPerfCalls\n", a_ovP->numPerfCalls);

   fprintf(cm_outFD, "\t%10d epoch\n", a_ovP->epoch);
   fprintf(cm_outFD, "\t%10d numCellsVisible\n", a_ovP->numCellsVisible);
   fprintf(cm_outFD, "\t%10d numCellsContacted\n", a_ovP->numCellsContacted);
   fprintf(cm_outFD, "\t%10d dlocalAccesses\n", a_ovP->dlocalAccesses);
   fprintf(cm_outFD, "\t%10d vlocalAccesses\n", a_ovP->vlocalAccesses);
   fprintf(cm_outFD, "\t%10d dremoteAccesses\n", a_ovP->dremoteAccesses);
   fprintf(cm_outFD, "\t%10d vremoteAccesses\n", a_ovP->vremoteAccesses);
   fprintf(cm_outFD, "\t%10d cacheNumEntries\n", a_ovP->cacheNumEntries);
   fprintf(cm_outFD, "\t%10d cacheBlocksTotal\n", a_ovP->cacheBlocksTotal);
   fprintf(cm_outFD, "\t%10d cacheBlocksInUse\n", a_ovP->cacheBlocksInUse);
   fprintf(cm_outFD, "\t%10d cacheBlocksOrig\n", a_ovP->cacheBlocksOrig);
   fprintf(cm_outFD, "\t%10d cacheMaxDirtyChunks\n",
           a_ovP->cacheMaxDirtyChunks);
   fprintf(cm_outFD, "\t%10d cacheCurrDirtyChunks\n",
           a_ovP->cacheCurrDirtyChunks);
   fprintf(cm_outFD, "\t%10d dcacheHits\n", a_ovP->dcacheHits);
   fprintf(cm_outFD, "\t%10d vcacheHits\n", a_ovP->vcacheHits);
   fprintf(cm_outFD, "\t%10d dcacheMisses\n", a_ovP->dcacheMisses);

src/Monitor.xs  view on Meta::CPAN

   hostname = xstat_cm_Results.connP->hostName;

   /* print "time hostname CM" prefix */
   fprintf(cm_outFD, "\n%s %s CM ", printTime, hostname);

   /* if probe failed print -1 and vanish */
   if (xstat_cm_Results.probeOK) {
      fprintf(cm_outFD, "-1\n");
      fclose(cm_outFD);
      return;
   }

   /* print out the probe information as  long words */
   numLongs = xstat_cm_Results.data.AFSCB_CollData_len;
   currLong = (afs_int32 *) (xstat_cm_Results.data.AFSCB_CollData_val);

   for (i = 0; i < numLongs; i++) {
      fprintf(cm_outFD, "%d ", *currLong++);
   }
   fprintf(cm_outFD, "\n\n");

   /* print detailed information */
   if (a_detOutput) {
      my_Print_cm_FullPerfInfo(xstat_cm_Results, cm_outFD);
      fflush(cm_outFD);
   }

   fclose(cm_outFD);

}   /* my_afsmon_cmOutput() */



/*
 * unchanged except for removing debugging print statements at beginning, and one
 * correction (replacing xstat_cm_Results with a_cmResults)
 *
 * from src/afsmonitor/afsmonitor.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_cm_Results_ltoa(a_cmData, a_cmResults)
   struct cm_Display_Data *a_cmData;    /* target buffer */
   struct xstat_cm_ProbeResults *a_cmResults;   /* ptr to xstat cm Results */
{
   struct afs_stats_CMFullPerf *fullP;  /* ptr to complete CM stats */
   afs_int32 *srcbuf;
   afs_int32 *tmpbuf;
   int i, j;
   int idx;
   afs_int32 numLongs;


   fullP = (struct afs_stats_CMFullPerf *)
      (a_cmResults->data.AFSCB_CollData_val);

   /* There are 4 parts to CM statistics
    * - Overall performance statistics (including up/down statistics)
    * - This CMs FS RPC operations info
    * - This CMs FS RPC errors info
    * - This CMs FS transfers info
    * - Authentication info
    * - [Un]Replicated access info
    */


   /* copy overall performance statistics */
   srcbuf = (afs_int32 *) & (fullP->perf);
   idx = 0;


   /* we skip the 19 entry, ProtServAddr, so the index must account for this */
   for (i = 0; i < NUM_AFS_STATS_CMPERF_LONGS + 1; i++) {
      if (i == 19) {
         srcbuf++;
         continue;  /* skip ProtServerAddr */
      }
      sprintf(a_cmData->data[idx], "%d", *srcbuf);
      idx++;
      srcbuf++;
   }

   /*printf("Ending index value = %d\n",idx-1); */

   /* server up/down statistics */
   /* copy file server up/down stats */
   srcbuf = (afs_int32 *) (fullP->perf.fs_UpDown);
   numLongs =
      2 * (sizeof(struct afs_stats_SrvUpDownInfo) / sizeof(afs_int32));
   for (i = 0; i < numLongs; i++) {
      sprintf(a_cmData->data[idx], "%d", *srcbuf);
      idx++;
      srcbuf++;
   }

   /*printf("Ending index value = %d\n",idx-1); */

   /* copy volume location  server up/down stats */
   srcbuf = (afs_int32 *) (fullP->perf.vl_UpDown);
   numLongs =
      2 * (sizeof(struct afs_stats_SrvUpDownInfo) / sizeof(afs_int32));
   for (i = 0; i < numLongs; i++) {
      sprintf(a_cmData->data[idx], "%d", *srcbuf);
      idx++;
      srcbuf++;
   }

   /*printf("Ending index value = %d\n",idx-1); */

   /* copy CMs individual FS RPC operations info */
   srcbuf = (afs_int32 *) (fullP->rpc.fsRPCTimes);
   for (i = 0; i < AFS_STATS_NUM_FS_RPC_OPS; i++) {
      sprintf(a_cmData->data[idx], "%d", *srcbuf);  /* numOps */
      idx++;
      srcbuf++;
      sprintf(a_cmData->data[idx], "%d", *srcbuf);  /* numSuccesses */
      idx++;
      srcbuf++;
      tmpbuf = srcbuf++;    /* sum time */
      sprintf(a_cmData->data[idx], "%d.%06d", *tmpbuf, *srcbuf);
      idx++;
      srcbuf++;
      tmpbuf = srcbuf++;    /* sqr time */
      sprintf(a_cmData->data[idx], "%d.%06d", *tmpbuf, *srcbuf);
      idx++;
      srcbuf++;
      tmpbuf = srcbuf++;    /* min time */
      sprintf(a_cmData->data[idx], "%d.%06d", *tmpbuf, *srcbuf);
      idx++;
      srcbuf++;
      tmpbuf = srcbuf++;    /* max time */
      sprintf(a_cmData->data[idx], "%d.%06d", *tmpbuf, *srcbuf);
      idx++;
      srcbuf++;
   }

   /*printf("Ending index value = %d\n",idx-1); */

   /* copy CMs individual FS RPC errors info */

   srcbuf = (afs_int32 *) (fullP->rpc.fsRPCErrors);
   for (i = 0; i < AFS_STATS_NUM_FS_RPC_OPS; i++) {
      sprintf(a_cmData->data[idx], "%d", *srcbuf);  /* server */
      idx++;
      srcbuf++;
      sprintf(a_cmData->data[idx], "%d", *srcbuf);  /* network */
      idx++;
      srcbuf++;
      sprintf(a_cmData->data[idx], "%d", *srcbuf);  /* prot */
      idx++;
      srcbuf++;
      sprintf(a_cmData->data[idx], "%d", *srcbuf);  /* vol */
      idx++;
      srcbuf++;
      sprintf(a_cmData->data[idx], "%d", *srcbuf);  /* busies */
      idx++;
      srcbuf++;
      sprintf(a_cmData->data[idx], "%d", *srcbuf);  /* other */
      idx++;
      srcbuf++;
   }

   /*printf("Ending index value = %d\n",idx-1); */

   /* copy CMs individual RPC transfers info */

   srcbuf = (afs_int32 *) (fullP->rpc.fsXferTimes);
   for (i = 0; i < AFS_STATS_NUM_FS_XFER_OPS; i++) {
      sprintf(a_cmData->data[idx], "%d", *srcbuf);  /* numOps */
      idx++;
      srcbuf++;
      sprintf(a_cmData->data[idx], "%d", *srcbuf);  /* numSuccesses */
      idx++;
      srcbuf++;
      tmpbuf = srcbuf++;    /* sum time */
      sprintf(a_cmData->data[idx], "%d.%06d", *tmpbuf, *srcbuf);
      idx++;
      srcbuf++;
      tmpbuf = srcbuf++;    /* sqr time */
      sprintf(a_cmData->data[idx], "%d.%06d", *tmpbuf, *srcbuf);
      idx++;
      srcbuf++;
      tmpbuf = srcbuf++;    /* min time */
      sprintf(a_cmData->data[idx], "%d.%06d", *tmpbuf, *srcbuf);
      idx++;
      srcbuf++;
      tmpbuf = srcbuf++;    /* max time */
      sprintf(a_cmData->data[idx], "%d.%06d", *tmpbuf, *srcbuf);
      idx++;
      srcbuf++;
      sprintf(a_cmData->data[idx], "%d", *srcbuf);  /* sum bytes */
      idx++;
      srcbuf++;
      sprintf(a_cmData->data[idx], "%d", *srcbuf);  /* min bytes */
      idx++;
      srcbuf++;
      sprintf(a_cmData->data[idx], "%d", *srcbuf);  /* max bytes */
      idx++;
      srcbuf++;

src/Monitor.xs  view on Meta::CPAN

   struct xstat_cm_ConnectionInfo *xstat_cm_ConnInfo;
   int xstat_cm_numServers;
   afs_int32 *xstat_cm_collIDP;
   int xstat_cm_numCollections;
   char *buffer;
   va_list argp;
{
   afs_int32 srvVersionNumber = 0;  /*Xstat version # */
   afs_int32 clientVersionNumber = AFSCB_XSTAT_VERSION; /*Client xstat version */
   afs_int32 *currCollIDP = 0;
   int numColls = 0;
   int conn_idx = 0;
   struct xstat_cm_ConnectionInfo *curr_conn = 0;
   char buff2[256] = "";
   int code = 0;
   int index = 0;

   struct xstat_cm_ProbeResults xstat_cm_Results;
   afs_int32 xstat_cmData[AFSCB_MAX_XSTAT_LONGS];
   xstat_cm_Results.probeTime = 0;
   xstat_cm_Results.connP = (struct xstat_cm_ConnectionInfo *) NULL;
   xstat_cm_Results.collectionNumber = 0;
   xstat_cm_Results.data.AFSCB_CollData_len = AFSCB_MAX_XSTAT_LONGS;
   xstat_cm_Results.data.AFSCB_CollData_val = (afs_int32 *) xstat_cmData;
   xstat_cm_Results.probeOK = 0;

   curr_conn = xstat_cm_ConnInfo;
   for (conn_idx = 0; conn_idx < xstat_cm_numServers; conn_idx++) {
      /*
       * Grab the statistics for the current File Server, if the
       * connection is valid.
       */
      if (curr_conn->rxconn != (struct rx_connection *) NULL) {

         currCollIDP = xstat_cm_collIDP;
         for (numColls = 0;
              numColls < xstat_cm_numCollections; numColls++, currCollIDP++) {
            /*
             * Initialize the per-probe values.
             */
            xstat_cm_Results.collectionNumber = *currCollIDP;
            xstat_cm_Results.data.AFSCB_CollData_len = AFSCB_MAX_XSTAT_LONGS;
            memset(xstat_cm_Results.data.AFSCB_CollData_val, 0,
                   AFSCB_MAX_XSTAT_LONGS * 4);

            xstat_cm_Results.connP = curr_conn;

            xstat_cm_Results.probeOK =
               RXAFSCB_GetXStats(curr_conn->rxconn,
                                 clientVersionNumber, *currCollIDP,
                                 &srvVersionNumber,
                                 &(xstat_cm_Results.probeTime),
                                 &(xstat_cm_Results.data));

            code =
               ProbeHandler(xstat_cm_Results, xstat_cm_numServers, index,
                            buff2, argp);
            index++;

            if (code) {
               sprintf(buffer, "Handler routine got error code %d. %s",
                       code, buff2);
               return (code);
            }

         }  /* For each collection */
      } /*Valid Rx connection */

      /*
       * Advance the xstat_fs connection pointer.
       */
      curr_conn++;

   }    /* For each xstat_cm connection */
   return (0);
}   /* my_xstat_cm_LWP() */



/*
 * from src/xstat/xstat_cm.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_xstat_cm_Init(int (*ProbeHandler) (), int xstat_cm_numServers,
                 struct sockaddr_in *a_socketArray,
                 int xstat_cm_numCollections, afs_int32 * xstat_cm_collIDP,
                 char *buffer, ...)
{
   int curr_srv = 0;
   int conn_err = 0;
   char *hostNameFound = "";
   struct xstat_cm_ConnectionInfo *curr_conn = 0, *xstat_cm_ConnInfo = 0;
   struct rx_securityClass *secobj = 0; /*Client security object */
   char buff2[256] = "";
   int code = 0;
   va_list argp;

   xstat_cm_ConnInfo = (struct xstat_cm_ConnectionInfo *)
      malloc(xstat_cm_numServers * sizeof(struct xstat_cm_ConnectionInfo));
   if (xstat_cm_ConnInfo == (struct xstat_cm_ConnectionInfo *) NULL) {
      sprintf(buffer,
              "Can't allocate %d connection info structs (%d bytes)",
              xstat_cm_numServers,
              (xstat_cm_numServers * sizeof(struct xstat_cm_ConnectionInfo)));
      return (-1);  /*No cleanup needs to be done yet */
   }

   code = rx_Init(htons(0));
   if (code) {
      sprintf(buffer, "Fatal error in rx_Init(), error=%d", code);
      return (-1);
   }

    /*
     * Create a null Rx client security object, to be used by the
     * probe LWP.
     */
   secobj = rxnull_NewClientSecurityObject();
   if (secobj == (struct rx_securityClass *) NULL) {
      /*Delete already-malloc'ed areas */
      my_xstat_cm_Cleanup(1, xstat_cm_numServers, xstat_cm_ConnInfo, buff2);
      sprintf(buffer, "Can't create probe LWP client security object. %s",
              buff2);
      return (-1);
   }

   curr_conn = xstat_cm_ConnInfo;
   conn_err = 0;
   for (curr_srv = 0; curr_srv < xstat_cm_numServers; curr_srv++) {
      /*
       * Copy in the socket info for the current server, resolve its
       * printable name if possible.
       */

      memcpy(&(curr_conn->skt), a_socketArray + curr_srv,
             sizeof(struct sockaddr_in));

      hostNameFound = hostutil_GetNameByINet(curr_conn->skt.sin_addr.s_addr);
      if (hostNameFound == NULL) {
         warn("Can't map Internet address %lu to a string name",
              curr_conn->skt.sin_addr.s_addr);
         curr_conn->hostName[0] = '\0';
      }
      else {
         strcpy(curr_conn->hostName, hostNameFound);
      }

      /*
       * Make an Rx connection to the current server.
       */

      curr_conn->rxconn = rx_NewConnection(curr_conn->skt.sin_addr.s_addr,  /*Server addr */
                                           curr_conn->skt.sin_port, /*Server port */
                                           1,   /*AFS service # */
                                           secobj,  /*Security obj */
                                           0);  /*# of above */
      if (curr_conn->rxconn == (struct rx_connection *) NULL) {
         sprintf(buffer,
                 "Can't create Rx connection to server '%s' (%lu)",
                 curr_conn->hostName, curr_conn->skt.sin_addr.s_addr);
         my_xstat_cm_Cleanup(1, xstat_cm_numServers, xstat_cm_ConnInfo,
                             buff2);
         return (-2);
      }
      /*
       * Bump the current xstat_fs connection to set up.
       */
      curr_conn++;

   }    /*for curr_srv */


   va_start(argp, buffer);
   code =
      my_xstat_cm_LWP(ProbeHandler, xstat_cm_ConnInfo, xstat_cm_numServers,
                      xstat_cm_collIDP, xstat_cm_numCollections, buffer,
                      argp);
   va_end(argp);

   if (code) {
      return (code);
   }
   my_xstat_cm_Cleanup(1, xstat_cm_numServers, xstat_cm_ConnInfo, buff2);
   return (0);


}   /* my_xstat_cm_Init() */

src/Monitor.xs  view on Meta::CPAN

   sl.serverList_len = 0;
   sl.serverList_val = NULL;
   code = RXAFSCB_GetCellByNum(aconn, cellnum, &cellname, &sl);
   if (code) {
      if (code == RXGEN_OPCODE)
         no_getcellbynum = 1;
      return NULL;
   }

   if (sl.serverList_val)
      free(sl.serverList_val);
   tcp = malloc(sizeof(struct cell_cache));
   tcp->next = cache;
   tcp->cellnum = cellnum;
   tcp->cellname = cellname;
   cache = tcp;

   return cellname;
}
#endif


/*
 * from src/venus/cmdebug.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_PrintLock(register struct AFSDBLockDesc *alock, HV *LOCK)
{
   hv_store(LOCK, "waitStates", 10, newSViv(alock->waitStates), 0);
   hv_store(LOCK, "exclLocked", 10, newSViv(alock->exclLocked), 0);
   hv_store(LOCK, "pid_writer", 10, newSViv(alock->pid_writer), 0);
   hv_store(LOCK, "src_indicator", 13, newSViv(alock->src_indicator), 0);
   hv_store(LOCK, "readersReading", 14, newSViv(alock->readersReading), 0);
   hv_store(LOCK, "pid_last_reader", 15, newSViv(alock->pid_last_reader), 0);
   hv_store(LOCK, "numWaiting", 10, newSViv(alock->numWaiting), 0);
}


/*
 * from src/venus/cmdebug.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_PrintLocks(register struct rx_connection *aconn, int aint32,
              AV *LOCKS, char *buffer)
{
   register int i;
   struct AFSDBLock lock;
   afs_int32 code;
   HV *LOCK;
   HV *LOCKDESC;

   for (i = 0; i < 1000; i++) {
      code = RXAFSCB_GetLock(aconn, i, &lock);
      if (code) {
         if (code == 1)
            break;
         /* otherwise we have an unrecognized error */
         sprintf(buffer, "cmdebug: error checking locks: %s",
                 error_message(code));
         return code;
      }
      /* here we have the lock information, so display it, perhaps */
      if (aint32 || IsLocked(&lock.lock)) {
         LOCK = newHV();
         hv_store(LOCK, "name", 4, newSVpv(lock.name, 0), 0);
         LOCKDESC = newHV();
         my_PrintLock(&lock.lock, LOCKDESC);
         hv_store(LOCK, "lock", 4, newRV_inc((SV *) LOCKDESC), 0);
         av_store(LOCKS, i, newRV_inc((SV *) LOCK));
      }
   }
   return 0;
}

#ifdef OpenAFS_1_2
int
my_PrintCacheEntries(aconn, aint32, CACHE_ENTRIES, buffer)
   register struct rx_connection *aconn;
   int aint32;
   AV *CACHE_ENTRIES;
   char *buffer;
{
   register int i;
   register afs_int32 code;
   struct AFSDBCacheEntry centry;
   char *cellname;
   HV *NETFID;
   HV *CENTRY;
   HV *LOCK;

   for (i = 0; i < 10000; i++) {
      code = RXAFSCB_GetCE(aconn, i, &centry);
      if (code) {
         if (code == 1)
            break;
         sprintf(buffer, "cmdebug: failed to get cache entry %d (%s)", i,
                 error_message(code));
         return code;
      }

      CENTRY = newHV();

      hv_store(CENTRY, "addr", 4, newSViv(centry.addr), 0);

      if (centry.addr == 0) {
         /* PS output */
         NETFID = newHV();
         hv_store(NETFID, "Vnode", 5, newSViv(centry.netFid.Vnode), 0);
         hv_store(NETFID, "Volume", 6, newSViv(centry.netFid.Volume), 0);
         hv_store(NETFID, "Unique", 6, newSViv(centry.netFid.Unique), 0);
         hv_store(CENTRY, "netFid", 6, newRV_inc((SV *) NETFID), 0);
         av_store(CACHE_ENTRIES, i, newRV_inc((SV *) CENTRY));
         continue;
      }

      if (!aint32 && !IsLocked(&centry.lock))
         continue;

      hv_store(CENTRY, "cell", 4, newSViv(centry.cell), 0);
      NETFID = newHV();
      hv_store(NETFID, "Vnode", 5, newSViv(centry.netFid.Vnode), 0);
      hv_store(NETFID, "Volume", 6, newSViv(centry.netFid.Volume), 0);
      hv_store(NETFID, "Unique", 6, newSViv(centry.netFid.Unique), 0);
      hv_store(CENTRY, "netFid", 6, newRV_inc((SV *) NETFID), 0);

#ifdef USE_GETCELLNAME
      cellname = GetCellName(aconn, centry.cell);
      if (cellname)
         hv_store(CENTRY, "cellname", 8, newSVpv(cellname, 0), 0);
#endif

      if (IsLocked(&centry.lock)) {
         LOCK = newHV();
         my_PrintLock(&centry.lock, LOCK);
         hv_store(CENTRY, "lock", 4, newRV_inc((SV *) LOCK), 0);
      }

      hv_store(CENTRY, "Length", 6, newSViv(centry.Length), 0);
      hv_store(CENTRY, "DataVersion", 11, newSViv(centry.DataVersion), 0);
      hv_store(CENTRY, "refCount", 8, newSViv(centry.refCount), 0);
      hv_store(CENTRY, "callback", 8, newSViv(centry.callback), 0);
      hv_store(CENTRY, "cbExpires", 9, newSViv(centry.cbExpires), 0);
      hv_store(CENTRY, "opens", 5, newSViv(centry.opens), 0);
      hv_store(CENTRY, "writers", 7, newSViv(centry.writers), 0);

      /* now display states */
      hv_store(CENTRY, "mvstat", 6, newSViv(centry.mvstat), 0);

      hv_store(CENTRY, "states", 6, newSViv(centry.states), 0);
      av_store(CACHE_ENTRIES, i, newRV_inc((SV *) CENTRY));
   }
   return 0;
}
#endif		/* ifdef OpenAFS_1_2 */



#ifdef OpenAFS_1_4
/*
 * from src/venus/cmdebug.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
PrintCacheEntries32(struct rx_connection *aconn, int aint32,
                    AV *CACHE_ENTRIES, char *buffer)
{
    register int i;
    register afs_int32 code;
    struct AFSDBCacheEntry centry;
    char *cellname;
    HV *NETFID;
    HV *CENTRY;
    HV *LOCK;

    for (i = 0; i < 10000; i++) {
        code = RXAFSCB_GetCE(aconn, i, &centry);
        if (code) {
            if (code == 1)
                break;
            sprintf(buffer, "cmdebug: failed to get cache entry %d (%s)\n", i,
                   error_message(code));
            return code;
        }

        CENTRY = newHV();

        hv_store(CENTRY, "addr", 4, newSViv(centry.addr), 0);

        if (centry.addr == 0) {
            /* PS output */
            printf("Proc %4d sleeping at %08x, pri %3d\n",
                   centry.netFid.Vnode, centry.netFid.Volume,
                   centry.netFid.Unique - 25);
            continue;
        }

        if (((aint32 == 0) && !IsLocked(&centry.lock)) ||
            ((aint32 == 2) && (centry.refCount == 0)) ||
            ((aint32 == 4) && (centry.callback == 0)))
            continue;

        /* otherwise print this entry */
        hv_store(CENTRY, "cell", 4, newSViv(centry.cell), 0);
        NETFID = newHV();
        hv_store(NETFID, "Vnode", 5, newSViv(centry.netFid.Vnode), 0);
        hv_store(NETFID, "Volume", 6, newSViv(centry.netFid.Volume), 0);
        hv_store(NETFID, "Unique", 6, newSViv(centry.netFid.Unique), 0);
        hv_store(CENTRY, "netFid", 6, newRV_inc((SV *) NETFID), 0);

#ifdef USE_GETCELLNAME
        cellname = GetCellName(aconn, centry.cell);
        if (cellname)
            hv_store(CENTRY, "cellname", 8, newSVpv(cellname, 0), 0);
#endif

        if (IsLocked(&centry.lock)) {
            LOCK = newHV();
            my_PrintLock(&centry.lock, LOCK);
            hv_store(CENTRY, "lock", 4, newRV_inc((SV *) LOCK), 0);
        }
        hv_store(CENTRY, "Length",       6, newSViv(centry.Length), 0);
        hv_store(CENTRY, "DataVersion", 11, newSViv(centry.DataVersion), 0);
        hv_store(CENTRY, "refCount",     8, newSViv(centry.refCount), 0);
        hv_store(CENTRY, "callback",     8, newSViv(centry.callback), 0);
        hv_store(CENTRY, "cbExpires",    9, newSViv(centry.cbExpires), 0);
        hv_store(CENTRY, "opens",        5, newSViv(centry.opens), 0);
        hv_store(CENTRY, "writers",      7, newSViv(centry.writers), 0);


        /* now display states */
        hv_store(CENTRY, "mvstat", 6, newSViv(centry.mvstat), 0);

        hv_store(CENTRY, "states", 6, newSViv(centry.states), 0);
        av_store(CACHE_ENTRIES, i, newRV_inc((SV *) CENTRY));
    }
    return 0;
}


/*
 * from src/venus/cmdebug.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
PrintCacheEntries64(struct rx_connection *aconn, int aint32,
                    AV *CACHE_ENTRIES, char *buffer)
{
    register int i;
    register afs_int32 code;
    struct AFSDBCacheEntry64 centry;
    char *cellname;
    char *data_name;
    HV *NETFID;
    HV *CENTRY;
    HV *LOCK;

    for (i = 0; i < 10000; i++) {
        code = RXAFSCB_GetCE64(aconn, i, &centry);
        if (code) {
            if (code == 1)
                break;
            sprintf(buffer, "cmdebug: failed to get cache entry %d (%s)\n", i,
                   error_message(code));
            return code;
        }

        CENTRY = newHV();

        hv_store(CENTRY, "addr", 4, newSViv(centry.addr), 0);

        if (centry.addr == 0) {
            /* PS output */
            NETFID = newHV();
            hv_store(NETFID, "Vnode", 5, newSViv(centry.netFid.Vnode), 0);
            hv_store(NETFID, "Volume", 6, newSViv(centry.netFid.Volume), 0);
            hv_store(NETFID, "Unique", 6, newSViv(centry.netFid.Unique-25), 0);
            hv_store(CENTRY, "netFid", 6, newRV_inc((SV *) NETFID), 0);
            av_store(CACHE_ENTRIES, i, newRV_inc((SV *) CENTRY));
            continue;
        }

        if (((aint32 == 0) && !IsLocked(&centry.lock)) ||
            ((aint32 == 2) && (centry.refCount == 0)) ||
            ((aint32 == 4) && (centry.callback == 0)))
            continue;

        /* otherwise print this entry */
        hv_store(CENTRY, "cell", 4, newSViv(centry.cell), 0);
        NETFID = newHV();
        hv_store(NETFID, "Vnode", 5, newSViv(centry.netFid.Vnode), 0);
        hv_store(NETFID, "Volume", 6, newSViv(centry.netFid.Volume), 0);
        hv_store(NETFID, "Unique", 6, newSViv(centry.netFid.Unique), 0);
        hv_store(CENTRY, "netFid", 6, newRV_inc((SV *) NETFID), 0);

#ifdef USE_GETCELLNAME
        cellname = GetCellName(aconn, centry.cell);
        if (cellname)
            hv_store(CENTRY, "cellname", 8, newSVpv(cellname, 0), 0);
#endif

        if (IsLocked(&centry.lock)) {
            LOCK = newHV();
            my_PrintLock(&centry.lock, LOCK);
            hv_store(CENTRY, "lock", 4, newRV_inc((SV *) LOCK), 0);
        }

        hv_store(CENTRY, "Length",       6, newSViv(centry.Length), 0);
        hv_store(CENTRY, "DataVersion", 11, newSViv(centry.DataVersion), 0);
        hv_store(CENTRY, "refCount",     8, newSViv(centry.refCount), 0);
        hv_store(CENTRY, "callback",     8, newSViv(centry.callback), 0);
        hv_store(CENTRY, "cbExpires",    9, newSViv(centry.cbExpires), 0);
        hv_store(CENTRY, "opens",        5, newSViv(centry.opens), 0);
        hv_store(CENTRY, "writers",      7, newSViv(centry.writers), 0);

        /* now display states */
        if (centry.mvstat == 0)
            data_name = "normal file";
        else if (centry.mvstat == 1)
            data_name = "mount point";
        else if (centry.mvstat == 2)
            data_name = "volume root";
        else if (centry.mvstat == 3)
            data_name = "directory";

src/Monitor.xs  view on Meta::CPAN

   else {
      if (fsprobe_ConnInfo != (struct fsprobe_ConnectionInfo *) NULL) {
         /*
          * The fsprobe connection structure array exists.  Go through it
          * and close up any Rx connections it holds.
          */
         curr_conn = fsprobe_ConnInfo;
         for (conn_idx = 0; conn_idx < fsprobe_numServers; conn_idx++) {
            if (curr_conn->rxconn != (struct rx_connection *) NULL) {
               rx_DestroyConnection(curr_conn->rxconn);
               curr_conn->rxconn = (struct rx_connection *) NULL;
            }
            if (curr_conn->rxVolconn != (struct rx_connection *) NULL) {
               rx_DestroyConnection(curr_conn->rxVolconn);
               curr_conn->rxVolconn = (struct rx_connection *) NULL;
            }
            curr_conn++;
         }  /*for each fsprobe connection */
      } /*fsprobe connection structure exists */
   }    /*Legal number of servers */

   /*
    * Now, release all the space we've allocated
    */
   if (fsprobe_ConnInfo != (struct fsprobe_ConnectionInfo *) NULL)
      free(fsprobe_ConnInfo);
   if (fsprobe_Results->stats != (struct ProbeViceStatistics *) NULL)
      free(fsprobe_Results->stats);
   if (fsprobe_Results->probeOK != (int *) NULL)
      free(fsprobe_Results->probeOK);

   /*
    * Return the news, whatever it is.
    */
   return (code);


}


/*
 * from src/fsprobe/fsprobe.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_fsprobe_Init(fsprobe_Results, fsprobe_ConnInfo, a_numServers,
                a_socketArray, RETVAL, scout_debugfd, buffer)
   struct fsprobe_ProbeResults *fsprobe_Results;    /*Latest probe results */
   struct fsprobe_ConnectionInfo **fsprobe_ConnInfo;    /*Ptr to connection array */
   int a_numServers;
   struct sockaddr_in *a_socketArray;
   AV *RETVAL;
   FILE *scout_debugfd;
   char *buffer;
{
   static char rn[] = "my_fsprobe_Init";
   struct fsprobe_ConnectionInfo *curr_conn;    /*Current connection */
   int fsprobe_statsBytes;      /*Num bytes in stats block */
   int fsprobe_probeOKBytes;    /*Num bytes in probeOK block */
   int conn_err = 0, code = 0;
   int curr_srv;
   char *hostNameFound;
   int PortToUse;
   struct rx_securityClass *secobj;
   struct rx_securityClass *CBsecobj;
   struct rx_service *rxsrv_afsserver;
   char buff2[256] = "";

   struct rx_call *rxcall;      /*Bogus param */
   AFSCBFids *Fids_Array;       /*Bogus param */
   AFSCBs *CallBack_Array;      /*Bogus param */
   struct interfaceAddr *interfaceAddr; /*Bogus param */


   if (scout_debugfd) {
      fprintf(scout_debugfd, "[%s] Called\n", rn);
      fflush(scout_debugfd);
   }
   if (a_numServers <= 0) {
      sprintf(buffer, "[%s] Illegal number of servers: %d", rn, a_numServers);
      return (-1);
   }
   if (a_socketArray == (struct sockaddr_in *) NULL) {
      sprintf(buffer, "[%s] Null server socket array argument", rn);
      return (-1);
   }

   memset(fsprobe_Results, 0, sizeof(struct fsprobe_ProbeResults));


   rxcall = (struct rx_call *) NULL;
   Fids_Array = (AFSCBFids *) NULL;
   CallBack_Array = (AFSCBs *) NULL;
   interfaceAddr = (struct interfaceAddr *) NULL;

   SRXAFSCB_CallBack(rxcall, Fids_Array, CallBack_Array);
   SRXAFSCB_InitCallBackState2(rxcall, interfaceAddr);
   SRXAFSCB_Probe(rxcall);



   *fsprobe_ConnInfo = (struct fsprobe_ConnectionInfo *)
      malloc(a_numServers * sizeof(struct fsprobe_ConnectionInfo));
   if (*fsprobe_ConnInfo == (struct fsprobe_ConnectionInfo *) NULL) {
      sprintf(buffer,
              "[%s] Can't allocate %d connection info structs (%d bytes)\n",
              rn, a_numServers,
              (a_numServers * sizeof(struct fsprobe_ConnectionInfo)));
      return (-1);  /*No cleanup needs to be done yet */
   }
   else if (scout_debugfd) {
      fprintf(scout_debugfd, "[%s] *fsprobe_ConnInfo allocated (%d bytes)\n",
              rn, a_numServers * sizeof(struct fsprobe_ConnectionInfo));
      fflush(scout_debugfd);
   }

   fsprobe_statsBytes = a_numServers * sizeof(struct ProbeViceStatistics);
   fsprobe_Results->stats = (struct ProbeViceStatistics *)
      malloc(fsprobe_statsBytes);
   if (fsprobe_Results->stats == (struct ProbeViceStatistics *) NULL) {
      /*Delete already-malloc'ed areas */
      my_fsprobe_Cleanup(fsprobe_Results, *fsprobe_ConnInfo, a_numServers,
                         scout_debugfd, buff2);
      sprintf(buffer,
              "[%s] Can't allocate %d statistics structs (%d bytes). %s", rn,
              a_numServers, fsprobe_statsBytes, buff2);
      return (-1);
   }
   else if (scout_debugfd) {
      fprintf(scout_debugfd,
              "[%s] fsprobe_Results->stats allocated (%d bytes)\n", rn,
              fsprobe_statsBytes);
      fflush(scout_debugfd);
   }

   fsprobe_probeOKBytes = a_numServers * sizeof(int);
   fsprobe_Results->probeOK = (int *)malloc(fsprobe_probeOKBytes);
   if (fsprobe_Results->probeOK == (int *) NULL) {
      /* Delete already-malloc'ed areas */
      my_fsprobe_Cleanup(fsprobe_Results, *fsprobe_ConnInfo, a_numServers,
                         scout_debugfd, buff2);
      sprintf(buffer,
              "[%s] Can't allocate %d probeOK array entries (%d bytes). %s",
              rn, a_numServers, fsprobe_probeOKBytes, buff2);
      return (-1);
   }
   else if (scout_debugfd) {
      fprintf(scout_debugfd,
              "[%s] fsprobe_Results->probeOK allocated (%d bytes)\n",
              rn, fsprobe_probeOKBytes);
      fflush(scout_debugfd);
   }
   fsprobe_Results->probeNum = 0;
   fsprobe_Results->probeTime = 0;
   memset(fsprobe_Results->stats, 0,
          (a_numServers * sizeof(struct ProbeViceStatistics)));

   if (scout_debugfd) {
      fprintf(scout_debugfd, "[%s] Initializing Rx\n", rn);
      fflush(scout_debugfd);
   }
   PortToUse = FSPROBE_CBPORT;
   do {
      code = rx_Init(htons(PortToUse));
      if (code) {
         if (code == RX_ADDRINUSE) {
            if (scout_debugfd) {
               fprintf(scout_debugfd,
                       "[%s] Callback port %d in use, advancing\n", rn,
                       PortToUse);
               fflush(scout_debugfd);
            }
            PortToUse++;
         }
         else {
            sprintf(buffer, "[%s] Fatal error in rx_Init()\n", rn);
            return (-1);
         }
      }
   } while (code);
   if (scout_debugfd) {
      fprintf(scout_debugfd, "[%s] Rx initialized on port %d\n", rn,
              PortToUse);
      fflush(scout_debugfd);
   }


   /*
    * Create a null Rx server security object, to be used by the
    * Callback listener.
    */
   CBsecobj = (struct rx_securityClass *)rxnull_NewServerSecurityObject();
   if (CBsecobj == (struct rx_securityClass *) NULL) {
      /*Delete already-malloc'ed areas */
      my_fsprobe_Cleanup(fsprobe_Results, *fsprobe_ConnInfo, a_numServers,
                         scout_debugfd, buff2);
      sprintf(buffer,
              "[%s] Can't create null security object for the callback listener. %s",
              rn, buff2);
      return (-1);
   }
   if (scout_debugfd)
      fprintf(scout_debugfd, "[%s] Callback server security object created\n",
              rn);


   /*
    * Create a null Rx client security object, to be used by the
    * probe LWP.
    */
   secobj = (struct rx_securityClass *)rxnull_NewClientSecurityObject();
   if (secobj == (struct rx_securityClass *) NULL) {
      /*Delete already-malloc'ed areas */
      my_fsprobe_Cleanup(fsprobe_Results, *fsprobe_ConnInfo, a_numServers,
                         scout_debugfd, buff2);
      sprintf(buffer,
              "[%s] Can't create client security object for probe LWP. %s",
              rn, buff2);
      return (-1);
   }
   if (scout_debugfd) {
      fprintf(scout_debugfd,
              "[%s] Probe LWP client security object created\n", rn);
      fflush(scout_debugfd);
   }


   curr_conn = *fsprobe_ConnInfo;
   conn_err = 0;
   for (curr_srv = 0; curr_srv < a_numServers; curr_srv++) {
      /*
       * Copy in the socket info for the current server, resolve its
       * printable name if possible.
       */
      if (scout_debugfd) {
         fprintf(scout_debugfd,
                 "[%s] Copying in the following socket info:\n", rn);
         fprintf(scout_debugfd, "[%s] IP addr 0x%lx, port %d\n", rn,
                 (a_socketArray + curr_srv)->sin_addr.s_addr,
                 (a_socketArray + curr_srv)->sin_port);
         fflush(scout_debugfd);
      }
      memcpy(&(curr_conn->skt), a_socketArray + curr_srv,
             sizeof(struct sockaddr_in));

      hostNameFound = hostutil_GetNameByINet(curr_conn->skt.sin_addr.s_addr);
      if (hostNameFound == (char *) NULL) {
         warn("Can't map Internet address %lu to a string name\n",
              curr_conn->skt.sin_addr.s_addr);
         curr_conn->hostName[0] = '\0';
      }
      else {
         strcpy(curr_conn->hostName, hostNameFound);
         if (scout_debugfd) {
            fprintf(scout_debugfd,
                    "[%s] Host name for server index %d is %s\n", rn,
                    curr_srv, curr_conn->hostName);
            fflush(scout_debugfd);
         }
      }

      /*
       * Make an Rx connection to the current server.
       */
      if (scout_debugfd) {
         fprintf(scout_debugfd,
                 "[%s] Connecting to srv idx %d, IP addr 0x%lx, port %d, service 1\n",
                 rn, curr_srv, curr_conn->skt.sin_addr.s_addr,
                 curr_conn->skt.sin_port);
         fflush(scout_debugfd);
      }

      curr_conn->rxconn = rx_NewConnection(curr_conn->skt.sin_addr.s_addr,  /*Server addr */
                                           curr_conn->skt.sin_port, /*Server port */
                                           1,   /*AFS service num */
                                           secobj,  /*Security object */
                                           0);  /*Number of above */
      if (curr_conn->rxconn == (struct rx_connection *) NULL) {
         sprintf(buffer,
                 "[%s] Can't create Rx connection to server %s (%lu)",
                 rn, curr_conn->hostName, curr_conn->skt.sin_addr.s_addr);
         conn_err = 1;
      }
      if (scout_debugfd) {
         fprintf(scout_debugfd, "[%s] New connection at 0x%lx\n",
                 rn, curr_conn->rxconn);
         fflush(scout_debugfd);
      }

      /*
       * Make an Rx connection to the current volume server.
       */
      if (scout_debugfd) {
         fprintf(scout_debugfd,
                 "[%s] Connecting to srv idx %d, IP addr 0x%lx, port %d, service 1\n",
                 rn, curr_srv, curr_conn->skt.sin_addr.s_addr, htons(7005));
         fflush(scout_debugfd);
      }
      curr_conn->rxVolconn = rx_NewConnection(curr_conn->skt.sin_addr.s_addr,   /*Server addr */
                                              htons(AFSCONF_VOLUMEPORT),    /*Volume Server port */
                                              VOLSERVICE_ID,    /*AFS service num */
                                              secobj,   /*Security object */
                                              0);   /*Number of above */
      if (curr_conn->rxVolconn == (struct rx_connection *) NULL) {
         sprintf(buffer,
                 "[%s] Can't create Rx connection to volume server %s (%lu)\n",
                 rn, curr_conn->hostName, curr_conn->skt.sin_addr.s_addr);
         conn_err = 1;
      }
      else {
         int i, cnt;

         memset(&curr_conn->partList, 0, sizeof(struct partList));
         curr_conn->partCnt = 0;
         i = my_XListPartitions(curr_conn->rxVolconn, &curr_conn->partList,
                                &cnt, scout_debugfd);
         if (!i) {
            curr_conn->partCnt = cnt;
         }
      }
      if (scout_debugfd) {
         fprintf(scout_debugfd, "[%s] New connection at 0x%lx\n",
                 rn, curr_conn->rxVolconn);
         fflush(scout_debugfd);
      }


      /*
       * Bump the current fsprobe connection to set up.
       */
      curr_conn++;
   }    /*for curr_srv */

   /*
    * Create the AFS callback service (listener).
    */
   if (scout_debugfd)
      fprintf(scout_debugfd, "[%s] Creating AFS callback listener\n", rn);
   rxsrv_afsserver = rx_NewService(0,   /*Use default port */
                                   1,   /*Service ID */
                                   "afs",   /*Service name */
                                   &CBsecobj,   /*Ptr to security object(s) */
                                   1,   /*Number of security objects */
                                   RXAFSCB_ExecuteRequest); /*Dispatcher */
   if (rxsrv_afsserver == (struct rx_service *) NULL) {
      /*Delete already-malloc'ed areas */
      my_fsprobe_Cleanup(fsprobe_Results, *fsprobe_ConnInfo, a_numServers,
                         scout_debugfd, buff2);
      sprintf(buffer, "[%s] Can't create callback Rx service/listener. %s",
              rn, buff2);
      return (-1);
   }
   if (scout_debugfd)
      fprintf(scout_debugfd, "[%s] Callback listener created\n", rn);

   /*
    * Start up the AFS callback service.
    */
   if (scout_debugfd)
      fprintf(scout_debugfd, "[%s] Starting up callback listener.\n", rn);
   rx_StartServer(0 /*Don't donate yourself to LWP pool */ );

   /* start probe */
   code = my_fsprobe_LWP(a_numServers, *fsprobe_ConnInfo, fsprobe_Results,
                         fsprobe_statsBytes, fsprobe_probeOKBytes,
                         scout_debugfd, RETVAL, buffer);
   if (code)
      return (code);

   if (conn_err)
      return (-2);
   else
      return (0);

}   /* my_fsprobe_Init() */


/*
 * from src/scout/scout.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_FS_Handler(fsprobe_Results, numServers, fsprobe_ConnInfo, scout_debugfd,
              RETVAL, buffer)
   struct fsprobe_ProbeResults fsprobe_Results;
   int numServers;
   struct fsprobe_ConnectionInfo *fsprobe_ConnInfo;
   FILE *scout_debugfd;
   AV *RETVAL;
   char *buffer;
{
   static char rn[] = "my_FS_Handler";  /*Routine name */
   int code;                    /*Return code */
   struct ProbeViceStatistics *curr_stats;  /*Ptr to current stats */
   struct fsprobe_ConnectionInfo *curr_conn;
   ViceDisk *curr_diskstat;
   int curr_disk;
   int *curr_probeOK;           /*Ptr to current probeOK field */
   int i = 0, j = 0;
   HV *RESULTS;
   HV *STATS;
   AV *DISKS;
   HV *DISK;

   if (scout_debugfd) {
      fprintf(scout_debugfd, "[%s] Called\n", rn);
      fflush(scout_debugfd);
   }

   curr_stats = fsprobe_Results.stats;
   curr_probeOK = fsprobe_Results.probeOK;
   curr_conn = fsprobe_ConnInfo;

   for (i = 0; i < numServers; i++) {
      RESULTS = newHV();

      hv_store(RESULTS, "probeOK", 7, newSViv((*curr_probeOK) ? 0 : 1), 0);
      hv_store(RESULTS, "probeTime", 9, newSViv(fsprobe_Results.probeTime),
               0);
      hv_store(RESULTS, "hostName", 8, newSVpv(curr_conn->hostName, 0), 0);

      if (*curr_probeOK == 0) {
         STATS = newHV();
         hv_store(STATS, "CurrentConnections", 18,
                  newSViv(curr_stats->CurrentConnections), 0);
         hv_store(STATS, "TotalFetchs", 11, newSViv(curr_stats->TotalFetchs),
                  0);
         hv_store(STATS, "TotalStores", 11, newSViv(curr_stats->TotalStores),
                  0);

src/Monitor.xs  view on Meta::CPAN


   my_cm_PrintUpDownStats(&(a_ovP->vl_UpDown[0]), VL_UPDOWN, 0);

   my_cm_PrintUpDownStats(&(a_ovP->vl_UpDown[1]), VL_UPDOWN, 1);

   hv_store(PERF, "fs_UpDown", 9, newRV_inc((SV *) FS_UPDOWN), 0);
   hv_store(PERF, "vl_UpDown", 9, newRV_inc((SV *) VL_UPDOWN), 0);

}


/*
 * from src/xstat/xstat_cm_test.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_cm_PrintOpTiming(a_opIdx, a_opNames, a_opTimeP, RPCTIMES)
   int a_opIdx;
   char *a_opNames[];
   struct afs_stats_opTimingData *a_opTimeP;
   HV *RPCTIMES;
{
   HV *TIMES = newHV();
   hv_store(TIMES, "numOps", 6, newSViv(a_opTimeP->numOps), 0);
   hv_store(TIMES, "numSuccesses", 12, newSViv(a_opTimeP->numSuccesses), 0);

   hv_store(TIMES, "sumTime", 7, newSVnv(a_opTimeP->sumTime.tv_sec
                                         +
                                         (a_opTimeP->sumTime.tv_usec /
                                          1000000.0)), 0);
   hv_store(TIMES, "sqrTime", 7,
            newSVnv(a_opTimeP->sqrTime.tv_sec +
                    (a_opTimeP->sqrTime.tv_usec / 1000000.0)), 0);
   hv_store(TIMES, "minTime", 7,
            newSVnv(a_opTimeP->minTime.tv_sec +
                    (a_opTimeP->minTime.tv_usec / 1000000.0)), 0);
   hv_store(TIMES, "maxTime", 7,
            newSVnv(a_opTimeP->maxTime.tv_sec +
                    (a_opTimeP->maxTime.tv_usec / 1000000.0)), 0);

   hv_store(RPCTIMES, a_opNames[a_opIdx], strlen(a_opNames[a_opIdx]),
            newRV_inc((SV *) TIMES), 0);
}


/*
 * from src/xstat/xstat_cm_test.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_cm_PrintErrInfo(a_opIdx, a_opNames, a_opErrP, RPCERRORS)
   int a_opIdx;
   char *a_opNames[];
   struct afs_stats_RPCErrors *a_opErrP;
   HV *RPCERRORS;
{
   HV *ERRORS = newHV();

   hv_store(ERRORS, "err_Server",       10, newSViv(a_opErrP->err_Server), 0);
   hv_store(ERRORS, "err_Network",      11, newSViv(a_opErrP->err_Network), 0);
   hv_store(ERRORS, "err_Protection",   14, newSViv(a_opErrP->err_Protection), 0);
   hv_store(ERRORS, "err_Volume",       10, newSViv(a_opErrP->err_Volume), 0);
   hv_store(ERRORS, "err_VolumeBusies", 16, newSViv(a_opErrP->err_VolumeBusies), 0);
   hv_store(ERRORS, "err_Other",         9, newSViv(a_opErrP->err_Other), 0);

   hv_store(RPCERRORS, a_opNames[a_opIdx], strlen(a_opNames[a_opIdx]),
            newRV_inc((SV *) ERRORS), 0);
}


/*
 * from src/xstat/xstat_cm_test.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_cm_PrintXferTiming(a_opIdx, a_opNames, a_xferP, XFERTIMES)
   int a_opIdx;
   char *a_opNames[];
   struct afs_stats_xferData *a_xferP;
   HV *XFERTIMES;
{
   HV *TIMES = newHV();
   AV *COUNT = newAV();
   int i;

   hv_store(TIMES, "numXfers", 8, newSViv(a_xferP->numXfers), 0);
   hv_store(TIMES, "numSuccesses", 12, newSViv(a_xferP->numSuccesses), 0);
   hv_store(TIMES, "sumTime", 7, newSVnv(a_xferP->sumTime.tv_sec
                                         +
                                         (a_xferP->sumTime.tv_usec /
                                          1000000.0)), 0);
   hv_store(TIMES, "sqrTime", 7, newSVnv(a_xferP->sqrTime.tv_sec +
                                 (a_xferP->sqrTime.tv_usec / 1000000.0)), 0);
   hv_store(TIMES, "minTime", 7, newSVnv(a_xferP->minTime.tv_sec +
                                 (a_xferP->minTime.tv_usec / 1000000.0)), 0);
   hv_store(TIMES, "maxTime", 7, newSVnv(a_xferP->maxTime.tv_sec +
                                 (a_xferP->maxTime.tv_usec / 1000000.0)), 0);
   hv_store(TIMES, "sumBytes", 8, newSViv(a_xferP->sumBytes), 0);
   hv_store(TIMES, "minBytes", 8, newSViv(a_xferP->minBytes), 0);
   hv_store(TIMES, "maxBytes", 8, newSViv(a_xferP->maxBytes), 0);


   for (i = 0; i <= 8; i++)
      av_store(COUNT, i, newSViv(a_xferP->count[i]));

   hv_store(TIMES, "count", 5, newRV_inc((SV *) COUNT), 0);

   hv_store(XFERTIMES, a_opNames[a_opIdx], strlen(a_opNames[a_opIdx]),
            newRV_inc((SV *) TIMES), 0);
}


/*
 * from src/xstat/xstat_cm_test.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_PrintRPCPerfInfo(struct afs_stats_RPCOpInfo *a_rpcP, HV *RPC)
{
   int currIdx;
   HV *FSRPCTIMES  = newHV();
   HV *FSRPCERRORS = newHV();

src/Monitor.xs  view on Meta::CPAN

my_xstat_CM_Handler(xstat_cm_Results, xstat_cm_numServers, index, buffer,
                    argp)
   struct xstat_cm_ProbeResults xstat_cm_Results;
   int xstat_cm_numServers;
   int index;
   char *buffer;
   va_list argp;
{
   AV *RETVAL = va_arg(argp, AV *);

   HV *HOSTINFO = newHV();

   hv_store(HOSTINFO, "probeOK", 7, newSViv(xstat_cm_Results.probeOK ? 0 : 1),
            0);
   hv_store(HOSTINFO, "hostName", 8,
            newSVpv(xstat_cm_Results.connP->hostName, 0), 0);
   hv_store(HOSTINFO, "collectionNumber", 16,
            newSViv(xstat_cm_Results.collectionNumber), 0);
   hv_store(HOSTINFO, "probeTime", 9, newSViv(xstat_cm_Results.probeTime), 0);

   if (xstat_cm_Results.probeOK == 0) {
      switch (xstat_cm_Results.collectionNumber) {
           /* Why are so many things commented out? -EC */
        case AFSCB_XSTATSCOLL_CALL_INFO:
           /* Why was this commented out in 3.3 ? */
           /* PrintCallInfo();  */
           my_print_cmCallStats(&xstat_cm_Results, HOSTINFO);
           break;

        case AFSCB_XSTATSCOLL_PERF_INFO:
           /* we will do nothing here */
           /* PrintPerfInfo(); */
           my_cm_PrintPerfInfo(&xstat_cm_Results, HOSTINFO);
           break;

        case AFSCB_XSTATSCOLL_FULL_PERF_INFO:
           my_cm_PrintFullPerfInfo(&xstat_cm_Results, HOSTINFO);
           break;

        default:
           sprintf(buffer, "** Unknown collection: %d",
                   xstat_cm_Results.collectionNumber);
           return (-1);
      }
   }


   av_store(RETVAL, index, newRV_inc((SV *) HOSTINFO));
   return (0);
}


/* end of xstat_cm_test helper functions */



MODULE = AFS::Monitor    PACKAGE = AFS::Monitor    PREFIX = afs_
PROTOTYPES: ENABLE

BOOT:
    initialize_rxk_error_table();


void
afs_do_xstat_cm_test(args)
    HV* args = (HV*) SvRV($arg);
  PREINIT:
  PPCODE:
  {
    SV *value;
    I32 keylen = 0;
    char *key;
    int num_args = 0;
    char buffer[256] = "";
    AV *host_array=0;
    AV *coll_array=0;
    int code;                          /*Return code*/
    int numCMs=0;                      /*# Cache Managers to monitor*/
    int numCollIDs=0;                  /*# collections to fetch*/
    int currCM;                        /*Loop index*/
    int currCollIDIdx;                 /*Index of current collection ID*/
    afs_int32 *collIDP;                /*Ptr to array of collection IDs*/
    afs_int32 *currCollIDP;            /*Ptr to current collection ID*/
    struct sockaddr_in *CMSktArray;    /*Cache Manager socket array */
    struct hostent *he;                /*Host entry*/

    AV *RETVAL = newAV();

    /* parse arguments */
    num_args = hv_iterinit(args);
    while (num_args--) {

      value = hv_iternextsv(args, &key, &keylen);

      if(strncmp(key, "collID", keylen) == 0 && keylen <= 6) {
        if (SvROK(value))
          coll_array = (AV*) SvRV(value);
        else {
          coll_array = av_make(1, &value);
          sv_2mortal((SV *) coll_array);
        }
        numCollIDs = av_len(coll_array) + 1;
      }
      else if(strncmp(key, "cmname", keylen) == 0 && keylen <= 6) {
        if (SvROK(value))
          host_array = (AV*) SvRV(value);
        else {
          host_array = av_make(1, &value);
          sv_2mortal((SV *) host_array);
        }
        numCMs = av_len(host_array) + 1;
      }
      else {
        sprintf(buffer, "Unrecognized flag: %s", key);
        BSETCODE(-1, buffer);
        XSRETURN_UNDEF;
      } /* end ifs */

    } /* end while */
    /* done parsing arguments */

src/Monitor.xs  view on Meta::CPAN

    }

    /* execute_scout */

    sktbytes = numservers * sizeof(struct sockaddr_in);
    FSSktArray = (struct sockaddr_in *) malloc(sktbytes);
    if (FSSktArray == (struct sockaddr_in *) NULL) {
      sprintf(buffer,
              "Can't malloc() %d sockaddrs (%d bytes) for the given servers",
              numservers, sktbytes);
      BSETCODE(-1, buffer);
      if (scout_debugfd != (FILE *) NULL) {
        fprintf(scout_debugfd, "[%s] Closing debugging file\n", rn);
        fclose(scout_debugfd);
      }
      XSRETURN_UNDEF;
    }
    memset(FSSktArray, 0, sktbytes);

    curr_skt = FSSktArray;
    for(i=0; i<numservers; i++) {
       if(*basename == '\0')
         sprintf(fullsrvname, "%s", (char *) SvPV(*av_fetch(host_array, i, 0), PL_na));
       else
         sprintf(fullsrvname, "%s.%s", (char *) SvPV(*av_fetch(host_array, i, 0), PL_na), basename);
       he = hostutil_GetHostByName(fullsrvname);
       if(he == (struct hostent *) NULL) {
         sprintf(buffer, "Can't get host info for '%s'", fullsrvname);
         BSETCODE(-1, buffer);
         if (scout_debugfd != (FILE *) NULL) {
           fprintf(scout_debugfd, "[%s] Closing debugging file\n", rn);
           fclose(scout_debugfd);
         }
         XSRETURN_UNDEF;
       }
       memcpy(&(curr_skt->sin_addr.s_addr), he->h_addr, 4);
#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
        curr_skt->sin_family = AF_INET;         /*Internet family */
#else
        curr_skt->sin_family = htons(AF_INET);  /*Internet family */
#endif
       curr_skt->sin_port   = htons(7000);       /* FileServer port */
       curr_skt++;
    }
    code = my_fsprobe_Init(&fsprobe_Results, &fsprobe_ConnInfo, numservers,
                           FSSktArray, RETVAL, scout_debugfd, buffer);
    if(code) {
      if(buffer == "") {
        sprintf(buffer, "Error returned by fsprobe_Init: %d", code);
      }
      BSETCODE(code, buffer);
      if (scout_debugfd != (FILE *) NULL) {
        fprintf(scout_debugfd, "[%s] Closing debugging file\n", rn);
        fclose(scout_debugfd);
      }
      XSRETURN_UNDEF;
    }
    code = my_FS_Handler(fsprobe_Results, numservers, fsprobe_ConnInfo,
                         scout_debugfd, RETVAL, buff2);
    if (code) {
      sprintf(buffer, "[%s] Handler routine returned error code %d. %s", rn, code, buff2);
      BSETCODE(code, buffer);
      if (scout_debugfd != (FILE *) NULL) {
        fprintf(scout_debugfd, "[%s] Closing debugging file\n", rn);
        fclose(scout_debugfd);
      }
      XSRETURN_UNDEF;
    }

    if (scout_debugfd != (FILE *) NULL) {
       fprintf(scout_debugfd, "[%s] Closing debugging file\n", rn);
       fclose(scout_debugfd);
    }

    ST(0) = sv_2mortal(newRV_inc((SV*)RETVAL));
    SETCODE(0);
    XSRETURN(1);
  }

void
afs_do_udebug(args)
    HV* args = (HV*) SvRV($arg);
  PREINIT:
  PPCODE:
  {

    SV *value;
    I32 keylen = 0;
    char *key;
    int num_args = 0;
    char buffer[256] = "";

    char *hostName = (char *) NULL;
    char *portName = (char *) NULL;
    afs_int32 hostAddr;
    struct in_addr inhostAddr;
    register afs_int32 i, j, code;
    short port;
    int int32p = 0;
    struct hostent *th;
    struct rx_connection *tconn;
    struct rx_securityClass *sc;
    struct ubik_debug udebug;
    struct ubik_sdebug usdebug;
    int oldServer = 0;   /* are we talking to a pre 3.5 server? */
    afs_int32 isClone = 0;

    HV *RETVAL = newHV();
    AV *ADDRESSES;
    HV *LOCALVERSION;
    HV *SYNCVERSION;
    HV *SYNCTID;
    AV *SERVERS;
    HV *USDEBUG;
    AV *ALTADDR;
    HV *REMOTEVERSION;

    /* parse arguments */
    num_args = hv_iterinit(args);
    while (num_args--) {

src/Monitor.xs  view on Meta::CPAN


       inhostAddr.s_addr = htonl(udebug.lowestHost);
       hv_store(RETVAL, "lowestHost", 10, newSVpv(inet_ntoa(inhostAddr), 0), 0);
       hv_store(RETVAL, "lowestTime", 10, newSViv(udebug.lowestTime), 0);

       inhostAddr.s_addr = htonl(udebug.syncHost);
       hv_store(RETVAL, "syncHost", 8, newSVpv(inet_ntoa(inhostAddr), 0), 0);
       hv_store(RETVAL, "syncTime", 8, newSViv(udebug.syncTime), 0);
    }

    SYNCVERSION = newHV();
    hv_store(SYNCVERSION, "epoch", 5, newSViv(udebug.syncVersion.epoch), 0);
    hv_store(SYNCVERSION, "counter", 7, newSViv(udebug.syncVersion.counter), 0);
    hv_store(RETVAL, "syncVersion", 11, newRV_inc((SV*)SYNCVERSION), 0);

    hv_store(RETVAL, "lockedPages", 11, newSViv(udebug.lockedPages), 0);
    hv_store(RETVAL, "writeLockedPages", 16, newSViv(udebug.writeLockedPages), 0);

    hv_store(RETVAL, "anyReadLocks", 12, newSViv(udebug.anyReadLocks), 0);
    hv_store(RETVAL, "anyWriteLocks", 13, newSViv(udebug.anyWriteLocks), 0);

    hv_store(RETVAL, "currentTrans", 12, newSViv(udebug.currentTrans), 0);
    if (udebug.currentTrans) {
       hv_store(RETVAL, "writeTrans", 10, newSViv(udebug.writeTrans), 0);
       SYNCTID = newHV();
       hv_store(SYNCTID, "epoch", 5, newSViv(udebug.syncTid.epoch), 0);
       hv_store(SYNCTID, "counter", 7, newSViv(udebug.syncTid.counter), 0);
       hv_store(RETVAL, "syncTid", 7, newRV_inc((SV*)SYNCTID), 0);
    }

    if (int32p || udebug.amSyncSite) {
       /* now do the subcalls */
       SERVERS = newAV();

       for ( i=0; ; i++ ) {
#ifdef USE_VOTEXDEBUG
          isClone = 0;
          code = VOTE_XSDebug(tconn, i, &usdebug, &isClone);
          if (code < 0) {
             if ( oldServer ) {                      /* pre 3.5 server */
                ubik_sdebug * ptr = &usdebug;
                memset(&usdebug, 0, sizeof(usdebug));
                code = VOTE_SDebugOld(tconn, i, (struct ubik_sdebug_old *) ptr);
             }
             else
                code = VOTE_SDebug(tconn, i, &usdebug);
          }
#else
          if ( oldServer ) {                      /* pre 3.5 server */
             ubik_sdebug * ptr = &usdebug;
             memset(&usdebug, 0, sizeof(usdebug));
             code = VOTE_SDebugOld(tconn, i, (struct ubik_sdebug_old *) ptr);
          }
          else
             code = VOTE_SDebug(tconn, i, &usdebug);
#endif

          if (code > 0)
                break;          /* done */
          if (code < 0) {
             warn("error code %d from VOTE_SDebug\n", code);
             break;
          }

          /* otherwise print the structure */
          USDEBUG = newHV();
          inhostAddr.s_addr = htonl(usdebug.addr);

          hv_store(USDEBUG, "addr", 4, newSVpv(afs_inet_ntoa(htonl(usdebug.addr)), 0), 0);

          ALTADDR = newAV();
          for ( j=0;((usdebug.altAddr[j]) && (j<UBIK_MAX_INTERFACE_ADDR-1)); j++) {
             av_store(ALTADDR, j, newSVpv(afs_inet_ntoa(htonl(usdebug.altAddr[j])), 0));
          }
          if (j) hv_store(USDEBUG, "altAddr", 7, newRV_inc((SV*)ALTADDR), 0);

          REMOTEVERSION = newHV();
          hv_store(REMOTEVERSION, "epoch", 5, newSViv(usdebug.remoteVersion.epoch), 0);
          hv_store(REMOTEVERSION, "counter", 7, newSViv(usdebug.remoteVersion.counter), 0);
          hv_store(USDEBUG, "remoteVersion", 13, newRV_inc((SV*)REMOTEVERSION), 0);

          hv_store(USDEBUG, "isClone", 7, newSViv(isClone), 0);

          hv_store(USDEBUG, "lastVoteTime", 12, newSViv(usdebug.lastVoteTime), 0);

          hv_store(USDEBUG, "lastBeaconSent", 14, newSViv(usdebug.lastBeaconSent), 0);
          hv_store(USDEBUG, "lastVote", 8, newSViv(usdebug.lastVote), 0);

          hv_store(USDEBUG, "currentDB", 9, newSViv(usdebug.currentDB), 0);
          hv_store(USDEBUG, "up", 2, newSViv(usdebug.up), 0);
          hv_store(USDEBUG, "beaconSinceDown", 15, newSViv(usdebug.beaconSinceDown), 0);

          av_store(SERVERS, i, newRV_inc((SV*)USDEBUG));
       }
       hv_store(RETVAL, "servers", 7, newRV_inc((SV*)SERVERS), 0);
    }

    /* return RETVAL */
    ST(0) = sv_2mortal(newRV_inc((SV*)RETVAL));
    SETCODE(0);
    XSRETURN(1);

  }

void
afs_do_cmdebug(args)
    HV* args = (HV*) SvRV($arg);
  PREINIT:
  PPCODE:
  {
    SV *value;
    I32 keylen = 0;
    char *key;
    int num_args = 0;
    int code = 0;
    int aint32 = 0;
    struct rx_connection *conn;
    register char *hostName = "";
    register struct hostent *thp;
    struct rx_securityClass *secobj;
    afs_int32 addr = 0;

src/Monitor.xs  view on Meta::CPAN

    struct hostent *he = 0;     /* host entry */
    afs_int32 *collIDP = 0;     /* ptr to collection ID */
    int numCollIDs = 0;         /* number of collection IDs */
    /* end of from afsmon_execute() */

    AV* FILESERV = newAV(); /* File Servers */
    AV* CACHEMAN = newAV(); /* Cache Managers */

    struct afsmon_hostEntry *FSnameList=0;
    struct afsmon_hostEntry *CMnameList=0;

    /* initialize showFlags for processing "show" directives in config file */
    for(i=0; i<NUM_FS_STAT_ENTRIES; i++)
      fs_showFlags[i] = 0;
    for(i=0; i<NUM_CM_STAT_ENTRIES; i++)
      cm_showFlags[i] = 0;

    /* parse arguments */
    num_args = hv_iterinit(args);
    /* fprintf(STDERR, "[afsmonitor] Parsing args now: %d\n", num_args); */
    while (num_args--) {
      value = hv_iternextsv(args, &key, &keylen);

      /* fprintf(STDERR, "got flag %s, size %d. %d remaining.\n", key, keylen, num_args); */

      switch (*key) {
        case 'c':
          if(keylen < 2) goto unrecognized;
          switch(key[1]) {
            case 'o':
              if(strncmp(key, "config", keylen) == 0 && keylen <= 6) {
                /* fprintf(STDERR, "flag %s recognized as config; value is %s\n",
                   key, (char *) SvPV(value, PL_na)); */
                config_filename = (char *) SvPV(value, PL_na);
              } else goto unrecognized;
            break;

            case 'm':
              if(keylen < 3) goto unrecognized;
              switch(key[2]) {
                case 'h':
                 if(strncmp(key, "cmhosts", keylen) == 0 && keylen <= 7) {
                   /* fprintf(STDERR, "flag %s recognized as cmhosts\n", key); */
                  if (SvROK(value))
                    host_array = (AV*) SvRV(value);
                  else {
                    host_array = av_make(1, &value);
                    sv_2mortal((SV *) host_array);
                  }
                   num = av_len(host_array);
                   /* fprintf(STDERR, "it has %d elements.\n", num+1); */
                   for(i=0; i<=num; i++) {
                     host = (char *) SvPV(*av_fetch(host_array, i, 0), PL_na);
                     sprintf(buffer,"cm %s",host);
                     code = my_parse_hostEntry(buffer, &numFS, &numCM, &lastHostType,
                                            &last_hostEntry, &FSnameList, &CMnameList, buff2);
                     /* fprintf(STDERR, "got host: %s\n", host); */
                     if (code) {
                       sprintf(buffer, "Could not parse cache manager %s. %s", host, buff2);
                       BSETCODE(180, buffer);
                       /* 180 is the exit code for this error in the original afsmonitor.c */
                       XSRETURN_UNDEF;
                     }
                   }
                 } else goto unrecognized;
                 break;
                case 's':
                 if(strncmp(key, "cmshow", keylen) == 0 && keylen <= 6) {
                   /* fprintf(STDERR, "flag %s recognized as cmshow\n", key); */
                   show_array = (AV*) SvRV(value);
                   num = av_len(show_array);
                   for (i=0; i<=num; i++) {
                     sprintf(buffer, "show cm %s", SvPV(*av_fetch(show_array, i, 0), PL_na));
                     code = my_parse_showEntry(buffer, &fs_showDefault, &cm_showDefault,
                                               fs_showFlags, cm_showFlags, buff2);
                     if(code) {
                       sprintf(buffer, "Error parsing cmshow flag. %s", buff2);
                       BSETCODE(-1, buffer);
                       XSRETURN_UNDEF;
                     }
                   }
                 } else goto unrecognized;
                 break;
                case 't':
                 if(strncmp(key, "cmthresh", keylen) == 0 && keylen <= 8) {
                   /* fprintf(STDERR, "flag %s recognized as cmthresh\n", key); */
                   cmthresh_array = (AV*) SvRV(value);
                 } else goto unrecognized;
                 break;
                default:
                 goto unrecognized;
              }
            break;

            default:
              goto unrecognized;
          }
          break;

        case 'd':
          if(strncmp(key, "detailed", keylen) == 0 && keylen <= 8) {
            /* fprintf(STDERR, "flag %s recognized as detailed; value is %d\n",
                       key, (int) SvIV(value)); */
            detailed = (int) SvIV(value);
          } else goto unrecognized;
        break;

        case 'f':
          if(keylen < 3 || key[1] != 's') goto unrecognized;
          switch(key[2]) {
            case 'h':
              if(strncmp(key, "fshosts", keylen) == 0 && keylen <= 7) {
                /* fprintf(STDERR, "flag %s recognized as fshosts\n", key); */
                if (SvROK(value))
                  host_array = (AV*) SvRV(value);
                else {
                  host_array = av_make(1, &value);
                  sv_2mortal((SV *) host_array);
                }
                num = av_len(host_array);
                /* fprintf(STDERR, "it has %d elements.\n", num+1); */

src/Monitor.xs  view on Meta::CPAN

                num = av_len(show_array);
                for (i=0; i<=num; i++) {
                  sprintf(buffer, "show fs %s", SvPV(*av_fetch(show_array, i, 0), PL_na));
                  code = my_parse_showEntry(buffer, &fs_showDefault, &cm_showDefault,
                                            fs_showFlags, cm_showFlags, buff2);
                  if(code) {
                    sprintf(buffer, "Error parsing fsshow flag. %s", buff2);
                    BSETCODE(-1, buffer);
                    XSRETURN_UNDEF;
                  }
                }
              } else goto unrecognized;
              break;
            case 't':
              if(strncmp(key, "fsthresh", keylen) == 0 && keylen <= 8) {
                /* fprintf(STDERR, "flag %s recognized as fsthresh\n", key); */
                fsthresh_array = (AV*) SvRV(value);
              } else goto unrecognized;
              break;
            default:
              goto unrecognized;
          }
        break;

        case 'o':
          if(strncmp(key, "output", keylen) == 0 && keylen <= 6) {
            /* fprintf(STDERR, "flag %s recognized as output; value is %s\n",
                       key, (char *) SvPV(value, PL_na)); */
            output_filename = (char *) SvPV(value, PL_na);
          } else goto unrecognized;
        break;

        default:
          unrecognized:
          /* fprintf(STDERR,
                     "flag not recognized. (key: %s) (value: %s)\n",
                     key, (char *) SvPV(value, PL_na)); */
          sprintf(buffer, "Unrecognized flag: %s", key);
          BSETCODE(-1, buffer);
          XSRETURN_UNDEF;
      } /* end switch */
    } /* end while */
    /* done parsing arguments */

    /* Open output file, if provided. */
    if (output_filename) {
      outputFD = fopen(output_filename,"a");
      if (outputFD == (FILE *) NULL) {
        sprintf(buffer, "Failed to open output file %s", output_filename);
        BSETCODE(160, buffer);
        XSRETURN_UNDEF;
      }
      fclose (outputFD);
    }

    /* cannot use 'detailed' without 'output' */
    if (detailed) {
      if (!output_filename) {
        sprintf(buffer, "detailed switch can be used only with output switch");
        BSETCODE(165, buffer);
        /* 165 is the exit code for this error in the original afsmonitor.c */
        XSRETURN_UNDEF;
      }
    }

    /* The config option is mutually exclusive with the fshosts,cmhosts options */
    if (config_filename) {
      if (numFS || numCM) {
        sprintf(buffer,"Cannot use config option with fshosts or cmhosts");
        BSETCODE(170, buffer);
        /* 170 is the exit code for this error in the original afsmonitor.c */
        XSRETURN_UNDEF;
      }
    }
    else {
      if (!numFS && !numCM) {
        sprintf(buffer,"Must specify either config or (fshosts and/or cmhosts) options");
        BSETCODE(175, buffer);
        /* 175 is the exit code for this error in the original afsmonitor.c */
        XSRETURN_UNDEF;
      }
    }

    if (fsthresh_array) {
      if(!numFS) {
        sprintf(buffer, "Cannot use fsthresh option without specifying fshosts");
        BSETCODE(-1, buffer);
        XSRETURN_UNDEF;
      }
      num = av_len(fsthresh_array);
      for (i=0; i<=num; i++) {
        thresh_host = 0;
        thresh_handler = "";
        thresh_entry = (HV*) SvRV(*av_fetch(fsthresh_array, i, 0));
        hv_iterinit(thresh_entry);
        while((value = hv_iternextsv(thresh_entry, &key, &keylen))) {
          if(strcmp(key, "host")==0) {
            thresh_host = (char *)SvPV(value, PL_na);
            he = GetHostByName(thresh_host);
            if(he == (struct hostent *) NULL) {
              sprintf(buffer,
                      "Couldn't parse fsthresh flag; unable to resolve hostname %s\n",
                      thresh_host);
              BSETCODE(-1, buffer);
              XSRETURN_UNDEF;
            }
            thresh_host = he->h_name;
          }
          else if(strcmp(key, "handler")==0) {
            thresh_handler = (char *) SvPV(value, PL_na);
          }
          else {
            thresh_name = key;
            thresh_value = (char *) SvPV(value, PL_na);
          }
        }
        sprintf(buffer, "thresh fs %s %s %s",
                thresh_name, thresh_value, thresh_handler);
        if(!thresh_host) {
          code = my_parse_threshEntry(buffer, &global_fsThreshCount,
                      &global_cmThreshCount, (struct afsmon_hostEntry *) NULL, 0, buff2);
          if (code) {
            sprintf(buffer, "Couldn't parse fsthresh entry. %s", buff2);
            BSETCODE(code, buffer);
            XSRETURN_UNDEF;
          }
        }
        else {
          temp_host = FSnameList;
          found = 0;
          for (j = 0; j < numFS; j++) {
            if(strcmp(thresh_host, temp_host->hostName) == 0) {
              found = 1;
              break;
            }
            temp_host = temp_host->next;
          }
          if(found) {
            code = my_parse_threshEntry(buffer, &global_fsThreshCount,
                                        &global_cmThreshCount, temp_host,
                                        1, buff2);
            if(code) {
              sprintf(buffer, "Couldn't parse fsthresh entry. %s", buff2);
              BSETCODE(code, buffer);
              XSRETURN_UNDEF;
            }
          }
          else {
            sprintf(buffer,
                    "Couldn't parse fsthresh entry for host %s; host not found",
                    thresh_host);
            BSETCODE(-1, buffer);
            XSRETURN_UNDEF;
          }
        }
      }
      if (global_fsThreshCount) {
        temp_host = FSnameList;
        for (i = 0; i < numFS; i++) {
          temp_host->numThresh += global_fsThreshCount;
          temp_host = temp_host->next;
        }
      }
      temp_host = FSnameList;
      for (i = 0; i < numFS; i++) {
        if (temp_host->numThresh) {
          numBytes = temp_host->numThresh * sizeof(struct Threshold);
          temp_host->thresh = (struct Threshold *)malloc(numBytes);
          if (temp_host->thresh == (struct Threshold *) NULL) {
            sprintf(buffer, "Memory Allocation error 1.5");
            BSETCODE(25, buffer);
            XSRETURN_UNDEF;
          }
          memset(temp_host->thresh, 0, numBytes);
        }
        temp_host = temp_host->next;
      }
      num = av_len(fsthresh_array);
      for (i=0; i<=num; i++) {
        thresh_host = 0;
        thresh_handler = "";
        thresh_entry = (HV*) SvRV(*av_fetch(fsthresh_array, i, 0));
        hv_iterinit(thresh_entry);
        while((value = hv_iternextsv(thresh_entry, &key, &keylen))) {
          if(strcmp(key, "host") == 0) {
            thresh_host = (char *)SvPV(value, PL_na);
            he = GetHostByName(thresh_host);
            if(he == (struct hostent *) NULL) {
              sprintf(buffer,
                      "Couldn't parse fsthresh flag; unable to resolve hostname %s\n",
                      thresh_host);
              BSETCODE(-1, buffer);
              XSRETURN_UNDEF;
            }
            thresh_host = he->h_name;
          }
          else if(strcmp(key, "handler")==0) {
            thresh_handler = (char *) SvPV(value, PL_na);
          }
          else {
            thresh_name = key;
            thresh_value = (char *) SvPV(value, PL_na);
          }
        }
        if(thresh_host) global_fsThreshCount = 0;
        else global_fsThreshCount = 1;
        code = my_store_threshold(1, thresh_name, thresh_value, thresh_handler,
                           &global_fsThreshCount, FSnameList, thresh_host,
                           numFS, buff2);
        if(code) {
          sprintf(buffer, "Unable to store threshold %s. %s", thresh_name, buff2);
          BSETCODE(code, buffer);
          XSRETURN_UNDEF;
        }
      }
    }

    if (cmthresh_array) {
      if(!numCM) {
        sprintf(buffer, "Cannot use cmthresh option without specifying cmhosts");
        BSETCODE(-1, buffer);
        XSRETURN_UNDEF;
      }
      num = av_len(cmthresh_array);
      for (i=0; i<=num; i++) {
        thresh_host = 0;
        thresh_handler = "";
        thresh_entry = (HV*) SvRV(*av_fetch(cmthresh_array, i, 0));
        hv_iterinit(thresh_entry);
        while((value = hv_iternextsv(thresh_entry, &key, &keylen))) {

src/Monitor.xs  view on Meta::CPAN

          else if(strcmp(key, "handler")==0) {
            thresh_handler = (char *) SvPV(value, PL_na);
          }
          else {
            thresh_name = key;
            thresh_value = (char *) SvPV(value, PL_na);
          }
        }
        sprintf(buffer, "thresh cm %s %s %s", thresh_name, thresh_value, thresh_handler);
        if(!thresh_host) {
          code = my_parse_threshEntry(buffer, &global_fsThreshCount,
                      &global_cmThreshCount, (struct afsmon_hostEntry *) NULL, 0, buff2);
          if (code) {
            sprintf(buffer, "Couldn't parse cmthresh entry. %s", buff2);
            BSETCODE(code, buffer);
            XSRETURN_UNDEF;
          }
        }
        else {
          temp_host = CMnameList;
          found = 0;
          for (j = 0; j < numCM; j++) {
            if(strcmp(thresh_host, temp_host->hostName) == 0) {
              found = 1;
              break;
            }
            temp_host = temp_host->next;
          }
          if(found) {
            code = my_parse_threshEntry(buffer, &global_fsThreshCount,
                                        &global_cmThreshCount, temp_host,
                                        2, buff2);
            if(code) {
              sprintf(buffer, "Couldn't parse cmthresh entry. %s", buff2);
              BSETCODE(code, buffer);
              XSRETURN_UNDEF;
            }
          }
          else {
            sprintf(buffer,
                    "Couldn't parse cmthresh entry for host %s; host not found",
                    thresh_host);
            BSETCODE(-1, buffer);
            XSRETURN_UNDEF;
          }
        }
      }
      if (global_cmThreshCount) {
        temp_host = CMnameList;
        for (i = 0; i < numCM; i++) {
          temp_host->numThresh += global_cmThreshCount;
          temp_host = temp_host->next;
        }
      }
      temp_host = CMnameList;
      for (i = 0; i < numCM; i++) {
        if (temp_host->numThresh) {
          numBytes = temp_host->numThresh * sizeof(struct Threshold);
          temp_host->thresh = (struct Threshold *)malloc(numBytes);
          if (temp_host->thresh == (struct Threshold *) NULL) {
            sprintf(buffer, "Memory Allocation error 2.5");
            BSETCODE(25, buffer);
            XSRETURN_UNDEF;
          }
          memset(temp_host->thresh, 0, numBytes);
        }
        temp_host = temp_host->next;
      }
      num = av_len(cmthresh_array);
      for (i=0; i<=num; i++) {
        thresh_host = 0;
        thresh_handler = "";
        thresh_entry = (HV*) SvRV(*av_fetch(cmthresh_array, i, 0));
        hv_iterinit(thresh_entry);
        while((value = hv_iternextsv(thresh_entry, &key, &keylen))) {
          if(strcmp(key, "host") == 0) {
            thresh_host = (char *)SvPV(value, PL_na);
            he = GetHostByName(thresh_host);
            if(he == (struct hostent *) NULL) {
              sprintf(buffer,
                      "Couldn't parse cmthresh flag; unable to resolve hostname %s\n",
                      thresh_host);
              BSETCODE(-1, buffer);
              XSRETURN_UNDEF;
            }
            thresh_host = he->h_name;
          }
          else if(strcmp(key, "handler")==0) {
            thresh_handler = (char *) SvPV(value, PL_na);
          }
          else {
            thresh_name = key;
            thresh_value = (char *) SvPV(value, PL_na);
          }
        }
        if(thresh_host) global_cmThreshCount = 0;
        else global_cmThreshCount = 1;
        code = my_store_threshold(2, thresh_name, thresh_value, thresh_handler,
                           &global_cmThreshCount, CMnameList, thresh_host,
                           numCM, buff2);
        if(code) {
          sprintf(buffer, "Unable to store threshold %s. %s", thresh_name, buff2);
          BSETCODE(code, buffer);
          XSRETURN_UNDEF;
        }
      }
    }

    /* process configuration file */
    if(config_filename) {
      code = my_process_config_file(config_filename, &numFS, &numCM, &lastHostType,
                                 &last_hostEntry, &fs_showDefault, &cm_showDefault,
                                 fs_showFlags, cm_showFlags, &FSnameList, &CMnameList);
      if(code == -1)
        XSRETURN_UNDEF;
    }

  /* from afsmon_execute() */

    /* process file server entries */
    if (numFS) {
    /* Allocate an array of sockets for each fileserver we monitor */

      FSsktbytes = numFS * sizeof(struct sockaddr_in);
      FSSktArray = (struct sockaddr_in *) malloc(FSsktbytes);
      if (FSSktArray == (struct sockaddr_in *) NULL) {
        sprintf(buffer,"cannot malloc %d sockaddr_ins for fileservers", numFS);
        BSETCODE(-1, buffer);
        XSRETURN_UNDEF;
      }

      memset(FSSktArray, 0, FSsktbytes);

      /* Fill in the socket information for each fileserve  */

      curr_skt = FSSktArray;
      curr_FS = FSnameList;  /* FS name list header */
      while (curr_FS) {
        strncpy(fullhostname,curr_FS->hostName,sizeof(fullhostname));
        he = GetHostByName(fullhostname);
        if (he == (struct hostent *) NULL) {
          sprintf(buffer,"Cannot get host info for %s", fullhostname);
          BSETCODE(-1, buffer);
          XSRETURN_UNDEF;
        }
        strncpy(curr_FS->hostName,he->h_name,HOST_NAME_LEN); /* complete name*/
        memcpy(&(curr_skt->sin_addr.s_addr), he->h_addr, 4);
#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
            curr_skt->sin_family = AF_INET;             /*Internet family */
#else
            curr_skt->sin_family = htons(AF_INET);      /*Internet family */
#endif
        curr_skt->sin_port   = htons(7000);       /*FileServer port*/
#ifdef STRUCT_SOCKADDR_HAS_SA_LEN
        curr_skt->sin_len = sizeof(struct sockaddr_in);
#endif
        /* get the next dude */
        curr_skt++;
        curr_FS = curr_FS->next;
      }

      /* initialize collection IDs. We need only one entry since we collect
         all the information from xstat */

      numCollIDs = 1;
      collIDP = (afs_int32 *) malloc (sizeof (afs_int32));
      if (collIDP == (afs_int32 *) NULL) {
        sprintf(buffer,"failed to allocate a measely afs_int32 word. Argh!");
        BSETCODE(-1, buffer);
        XSRETURN_UNDEF;
      }
      *collIDP = 2;     /* USE A macro for this */

      code = my_xstat_fs_Init(my_afsmon_FS_Handler, numFS, FSSktArray, numCollIDs,
                              collIDP, buff2, output_filename, detailed, FILESERV,
                              FSnameList, fs_showFlags, fs_showDefault);

      if (code) {
        sprintf(buffer,"my_xstat_fs_Init() returned error. %s", buff2);
        BSETCODE(125, buffer);
        XSRETURN_UNDEF;
      }
    }  /* end of process fileserver entries */

    /* process cache manager entries */
    if (numCM) {
    /* Allocate an array of sockets for each fileserver we monitor */

      CMsktbytes = numCM * sizeof(struct sockaddr_in);
      CMSktArray = (struct sockaddr_in *) malloc(CMsktbytes);
      if (CMSktArray == (struct sockaddr_in *) NULL) {
        sprintf(buffer,"cannot malloc %d sockaddr_ins for CM entries", numCM);
        BSETCODE(-1, buffer);
        XSRETURN_UNDEF;
      }

      memset(CMSktArray, 0, CMsktbytes);

      /* Fill in the socket information for each CM  */

      curr_skt = CMSktArray;
      curr_CM = CMnameList;  /* CM name list header */
      while (curr_CM) {
        strncpy(fullhostname,curr_CM->hostName,sizeof(fullhostname));
        he = GetHostByName(fullhostname);
        if (he == (struct hostent *) NULL) {
          sprintf(buffer,"Cannot get host info for %s", fullhostname);
          BSETCODE(-1, buffer);
          XSRETURN_UNDEF;
        }
        strncpy(curr_CM->hostName,he->h_name,HOST_NAME_LEN); /* complete name*/
        memcpy(&(curr_skt->sin_addr.s_addr), he->h_addr, 4);
        curr_skt->sin_family = htons(AF_INET);    /*Internet family*/
        curr_skt->sin_port   = htons(7001);  /*Cache Manager port */
#ifdef STRUCT_SOCKADDR_HAS_SA_LEN
        curr_skt->sin_len = sizeof(struct sockaddr_in);
#endif

        /* get the next dude */
        curr_skt++;
        curr_CM = curr_CM->next;
      }

      /* initialize collection IDs. We need only one entry since we collect
         all the information from xstat */

      numCollIDs = 1;
      collIDP = (afs_int32 *) malloc (sizeof (afs_int32));
      if (collIDP == (afs_int32 *) NULL) {
        sprintf(buffer,"failed to allocate a measely afs_int32 word. Argh!");
        BSETCODE(-1, buffer);
        XSRETURN_UNDEF;
      }
      *collIDP = 2;     /* USE A macro for this */

      code = my_xstat_cm_Init(my_afsmon_CM_Handler, numCM, CMSktArray, numCollIDs,
                              collIDP, buff2, output_filename, detailed, CACHEMAN,
                              CMnameList, cm_showFlags, cm_showDefault);

      if (code) {
        sprintf(buffer,"my_xstat_cm_Init() returned error. %s", buff2);
        BSETCODE(130, buffer);
        XSRETURN_UNDEF;
      }

    }  /* end of process fileserver entries */

  /* end from afsmon_execute() */

    SETCODE(0);

    EXTEND(SP, 2);
    PUSHs(sv_2mortal(newRV_inc((SV*)FILESERV)));
    PUSHs(sv_2mortal(newRV_inc((SV*)CACHEMAN)));
  }


void
afs_do_rxdebug(args)
    HV* args = (HV*) SvRV($arg);
  PREINIT:
  PPCODE:
  {
    int size;
    I32 keylen;
    char *key;
    HE* entry;
    SV* value;
    HV* RETVAL = newHV(); /* return value */
    HV* TSTATS;
    HV* RXSTATS;
    AV* CONNECTIONS;
    HV* TCONN;
    AV* CALLSTATE;
    AV* CALLMODE;
    AV* CALLFLAGS;
    AV* CALLOTHER;
    AV* CALLNUMBER;
    AV* PEERS;
    HV* TPEER;
    HV* BYTESSENT;
    HV* BYTESRECEIVED;
    HV* TIMEOUT;
    int index;

    register int i;
    int s;
    int j;
    struct sockaddr_in taddr;
    afs_int32 host;
    struct in_addr hostAddr;
    short port;
    struct hostent *th;
    register afs_int32 code;
    int nodally=0;
    int allconns=0;
    int rxstats=0;
    int onlyClient=0;
    int onlyServer=0;
    afs_int32 onlyHost = -1;
    short onlyPort = -1;
    int onlyAuth = 999;
    int flag;
    int dallyCounter;
    int withSecStats;
    int withAllConn;
    int withRxStats;
    int withWaiters;
    int withIdleThreads;
    int withPeers;
    struct rx_debugStats tstats;
    char *portName = (char *) NULL;
    char *hostName = (char *) NULL;
    struct rx_debugConn tconn;
    short noConns=0;
    short showPeers=0;
    short showLong=0;
    int version_flag=0;
    afs_int32 length=64;
    char version[64];
    char buffer[240]; /* for error messages */

    afs_uint32 supportedDebugValues = 0;
    afs_uint32 supportedStatValues = 0;
    afs_uint32 supportedConnValues = 0;
    afs_uint32 supportedPeerValues = 0;
    afs_int32 nextconn = 0;
    afs_int32 nextpeer = 0;

  size = hv_iterinit(args);
  /* fprintf(STDERR, "Parsing args now: %d\n", size); */
  while (size--) {
    char *flag;
    entry = hv_iternext(args);
    key = hv_iterkey(entry, &keylen);
    value = hv_iterval(args, entry);
    flag = key;
    /* fprintf(STDERR, "size = %d, format: got flag %s\n", size, key); */

    switch (*flag) {
    case 'a':
        if (memcmp( flag, "allconnections", 14) == 0 ) {
            allconns = (int) SvIV(value);
        }
        break;

    case 'l':
        if (memcmp( flag, "long", 4) == 0 ) {
            showLong = (int) SvIV(value);
        }
        break;

    case 'n':
        if (memcmp( flag, "nodally", 7) == 0 ) {
            nodally = (int) SvIV(value);
        } else if (memcmp( flag, "noconns", 7) == 0 ) {
            noConns = (int) SvIV(value);
        }
        break;

    case 'o':
        if (memcmp( flag, "onlyserver", 10) == 0 ) {
            onlyServer = (int) SvIV(value);
        } else if (memcmp( flag, "onlyclient", 10) == 0 ) {
            onlyClient = (int) SvIV(value);
        } else if (memcmp( flag, "onlyhost", 8) == 0 ) {
            char *name = (char *) SvPV(value, PL_na);
        struct hostent *th;
        th = hostutil_GetHostByName(name);
        if (!th) {
            sprintf(buffer, "rxdebug: host %s not found in host table", name);
            BSETCODE(-1, buffer);
            XSRETURN_UNDEF;
        }
        memcpy(&onlyHost, th->h_addr, sizeof(afs_int32));

        } else if (memcmp( flag, "onlyauth", 8) == 0 ) {
            char *name = (char *) SvPV(value, PL_na);
            if (strcmp (name, "clear") == 0) onlyAuth = 0;
            else if (strcmp (name, "auth") == 0) onlyAuth = 1;
            else if (strcmp (name, "crypt") == 0) onlyAuth = 2;

src/Monitor.xs  view on Meta::CPAN

        }
        break;

    case 's':
        if (memcmp( flag, "servers", 7) == 0 ) {
            hostName = (char *) SvPV(value, PL_na);
        }
        break;

    case 'v':
        if (memcmp( flag, "version", 7) == 0 ) {
            version_flag = (int) SvIV(value);
        }
        break;

    default:
        break;
    } /* switch */
  } /* while */
  /*  fprintf(STDERR, "Done parsing args\n\n"); */

    /* lookup host */
    if (hostName) {
      th = hostutil_GetHostByName(hostName);
      if (!th) {
        sprintf(buffer, "rxdebug: host %s not found in host table", hostName);
        VSETCODE(-1, buffer);
        XSRETURN_UNDEF;
      }
      memcpy(&host, th->h_addr, sizeof(afs_int32));
    }
    else host = htonl(0x7f000001);    /* IP localhost */

    if (!portName)
      port = htons(7000);        /* default is fileserver */
    else {
      if ((port = rxdebug_PortNumber(portName)) == -1)
        port = rxdebug_PortName(portName);
      if (port == -1) {
        sprintf(buffer, "rxdebug: can't resolve port name %s", portName);
        VSETCODE(-1, buffer);
        XSRETURN_UNDEF;
      }
    }

    dallyCounter = 0;
    hostAddr.s_addr = host;
    /* add address and port to RETVAL hash */
    hv_store(RETVAL, "address", 7, newSVpv(inet_ntoa(hostAddr), 0), 0);
    hv_store(RETVAL, "port", 4, newSViv(ntohs(port)), 0);
    s = socket(AF_INET, SOCK_DGRAM, 0);
    taddr.sin_family = AF_INET;
    taddr.sin_port = 0;
    taddr.sin_addr.s_addr = 0;
#ifdef STRUCT_SOCKADDR_HAS_SA_LEN
    taddr.sin_len = sizeof(struct sockaddr_in);
#endif
    code = bind(s, (struct sockaddr *) &taddr, sizeof(struct sockaddr_in));
    FSSETCODE(code);
    if (code) {
      perror("bind");
      XSRETURN_UNDEF;
    }

    if (version_flag) /* add version to RETVAL and finish */
    {
       code = rx_GetServerVersion(s, host, port, length, version);
       if (code < 0)
       {
          sprintf(buffer, "get version call failed with code %d, errno %d",code,errno);
          BSETCODE(code, buffer);
          XSRETURN_UNDEF;
       }
       hv_store(RETVAL, "version", 7, newSVpv(version, 0), 0);
       goto done;
    }

    code = rx_GetServerDebug(s, host, port, &tstats, &supportedDebugValues);

    if (code < 0) {
      sprintf(buffer, "getstats call failed with code %d", code);
      BSETCODE(code, buffer);
      XSRETURN_UNDEF;
    }

    withSecStats = (supportedDebugValues & RX_SERVER_DEBUG_SEC_STATS);
    withAllConn = (supportedDebugValues & RX_SERVER_DEBUG_ALL_CONN);
    withRxStats = (supportedDebugValues & RX_SERVER_DEBUG_RX_STATS);
    withWaiters = (supportedDebugValues & RX_SERVER_DEBUG_WAITER_CNT);
    withIdleThreads = (supportedDebugValues & RX_SERVER_DEBUG_IDLE_THREADS);
    withPeers = (supportedDebugValues & RX_SERVER_DEBUG_ALL_PEER);

    TSTATS = newHV();
    hv_store(TSTATS, "nFreePackets", 12, newSViv(tstats.nFreePackets), 0);
    hv_store(TSTATS, "packetReclaims", 14, newSViv(tstats.packetReclaims), 0);
    hv_store(TSTATS, "callsExecuted", 13, newSViv(tstats.callsExecuted), 0);
    hv_store(TSTATS, "usedFDs", 7, newSViv(tstats.usedFDs), 0);
    hv_store(TSTATS, "waitingForPackets", 17, newSViv(tstats.waitingForPackets), 0);
    hv_store(TSTATS, "version", 7, newSViv(tstats.version), 0);
    if (withWaiters)
       hv_store(TSTATS, "nWaiting", 8, newSViv(tstats.nWaiting), 0);
    if ( withIdleThreads )
       hv_store(TSTATS, "idleThreads", 11, newSViv(tstats.idleThreads), 0);
    hv_store(RETVAL, "tstats", 6, newRV_inc((SV*)(TSTATS)), 0);

    /* get rxstats if requested, and supported by the server */
    /* hash containing stats added at key 'rxstats' in RETVAL */
    if (rxstats)
    {
      if (!withRxStats)
      {
        noRxStats:
        withRxStats = 0;
        warn("WARNING: Server doesn't support retrieval of Rx statistics\n");
      }
      else {
        struct rx_statistics rxstats;

        /* should gracefully handle the case where rx_statistics grows */
        code = rx_GetServerStats(s, host, port, &rxstats, &supportedStatValues);
        if (code < 0) {
          sprintf(buffer, "rxstats call failed with code %d", code);
          VSETCODE(code, buffer);
          XSRETURN_UNDEF;
        }
        if (code != sizeof(rxstats)) {
          if ((((struct rx_debugIn *)(&rxstats))->type == RX_DEBUGI_BADTYPE))
            goto noRxStats;
          warn("WARNING: returned Rx statistics of unexpected size (got %d)\n", code);
          /* handle other versions?... */

src/Monitor.xs  view on Meta::CPAN

    if (!noConns) {
      if (allconns) {
        if (!withAllConn) {
          warn("WARNING: Server doesn't support retrieval of all connections,\n");
          warn("         getting only interesting instead.\n");
          }
      }

      CONNECTIONS = newAV();
      index = 0;
      for ( i = 0; ; i++) {
        code = rx_GetServerConnections(s, host, port, &nextconn, allconns,
                      supportedDebugValues, &tconn,
                      &supportedConnValues);
        if (code < 0) {
          warn("getconn call failed with code %d\n", code);
          break;
        }
        if (tconn.cid == 0xffffffff) {
          break;
        }

        /* see if we're in nodally mode and all calls are dallying */
        if (nodally) {
          flag = 0;
          for (j = 0; j < RX_MAXCALLS; j++) {
             if (tconn.callState[j] != RX_STATE_NOTINIT &&
                 tconn.callState[j] != RX_STATE_DALLY) {
               flag = 1;
               break;
             }
          }
          if (flag == 0) {
            /* this call looks too ordinary, bump skipped count and go
             * around again */
            dallyCounter++;
            continue;
          }
        }
        if ((onlyHost != -1) && (onlyHost != tconn.host)) continue;
        if ((onlyPort != -1) && (onlyPort != tconn.port)) continue;
        if (onlyServer && (tconn.type != RX_SERVER_CONNECTION)) continue;
        if (onlyClient && (tconn.type != RX_CLIENT_CONNECTION)) continue;
        if (onlyAuth != 999) {
          if (onlyAuth == -1) {
            if (tconn.securityIndex != 0) continue;
          }
          else {
            if (tconn.securityIndex != 2) continue;
            if (withSecStats && (tconn.secStats.type == 3) &&
             (tconn.secStats.level != onlyAuth)) continue;
          }
        }
        TCONN = newHV();
        hostAddr.s_addr = tconn.host;
        hv_store(TCONN, "host", 4, newSVpv(inet_ntoa(hostAddr), 0), 0);
        hv_store(TCONN, "port", 4, newSViv(ntohs(tconn.port)), 0);

        hv_store(TCONN, "cid", 3, newSViv(tconn.cid), 0);
        hv_store(TCONN, "epoch", 5, newSViv(tconn.epoch), 0);
        hv_store(TCONN, "error", 5, newSViv(tconn.error), 0);
        hv_store(TCONN, "serial", 6, newSViv(tconn.serial), 0);
        hv_store(TCONN, "natMTU", 6, newSViv(tconn.natMTU), 0);

        hv_store(TCONN, "flags", 5, newSViv(tconn.flags), 0);

        hv_store(TCONN, "securityIndex", 13, newSViv(tconn.securityIndex), 0);

        hv_store(TCONN, "type", 4, newSViv(tconn.type), 0);

        if (withSecStats) {
          HV* SECSTATS = newHV();
          hv_store(SECSTATS, "type", 4,
                   newSViv(tconn.secStats.type), 0);
          hv_store(SECSTATS, "level", 5,
                   newSViv(tconn.secStats.level), 0);
          hv_store(SECSTATS, "flags", 5,
                   newSViv(tconn.secStats.flags), 0);
          hv_store(SECSTATS, "expires", 7,
                   newSViv(tconn.secStats.expires), 0);
          hv_store(SECSTATS, "packetsReceived", 15,
                   newSViv(tconn.secStats.packetsReceived), 0);
          hv_store(SECSTATS, "packetsSent", 11,
                   newSViv(tconn.secStats.packetsSent), 0);
          hv_store(SECSTATS, "bytesReceived", 13,
                   newSViv(tconn.secStats.bytesReceived), 0);
          hv_store(SECSTATS, "bytesSent", 9,
                   newSViv(tconn.secStats.bytesSent), 0);
          hv_store(TCONN, "secStats", 8, newRV_inc((SV*)(SECSTATS)), 0);
        }

        CALLSTATE = newAV();
        av_fill(CALLSTATE, RX_MAXCALLS-1);
        CALLMODE = newAV();
        av_fill(CALLMODE, RX_MAXCALLS-1);
        CALLFLAGS = newAV();
        av_fill(CALLFLAGS, RX_MAXCALLS-1);
        CALLOTHER = newAV();
        av_fill(CALLOTHER, RX_MAXCALLS-1);
        CALLNUMBER = newAV();
        av_fill(CALLNUMBER, RX_MAXCALLS-1);

        for (j = 0; j < RX_MAXCALLS; j++) {
          av_store(CALLSTATE, j, newSViv(tconn.callState[j]));
          av_store(CALLMODE, j, newSViv(tconn.callMode[j]));
          av_store(CALLFLAGS, j, newSViv(tconn.callFlags[j]));
          av_store(CALLOTHER, j, newSViv(tconn.callOther[j]));
          av_store(CALLNUMBER, j, newSViv(tconn.callNumber[j]));
        }

        hv_store(TCONN, "callState", 9, newRV_inc((SV*)(CALLSTATE)), 0);
        hv_store(TCONN, "callMode", 8, newRV_inc((SV*)(CALLMODE)), 0);
        hv_store(TCONN, "callFlags", 9, newRV_inc((SV*)(CALLFLAGS)), 0);
        hv_store(TCONN, "callOther", 9, newRV_inc((SV*)(CALLOTHER)), 0);
        hv_store(TCONN, "callNumber", 10, newRV_inc((SV*)(CALLNUMBER)), 0);

        av_store(CONNECTIONS, index, newRV_inc((SV*)(TCONN)));
        index++;
      } /* end of for loop */
      if (nodally) hv_store(RETVAL, "dallyCounter", 12, newSViv(dallyCounter), 0);
      hv_store(RETVAL, "connections", 11, newRV_inc((SV*)(CONNECTIONS)), 0);

src/Monitor.xs  view on Meta::CPAN

        hv_store(TPEER, "ifMTU", 5, newSViv(tpeer.ifMTU), 0);
        hv_store(TPEER, "natMTU", 6, newSViv(tpeer.natMTU), 0);
        hv_store(TPEER, "maxMTU", 6, newSViv(tpeer.maxMTU), 0);
        hv_store(TPEER, "nSent", 5, newSViv(tpeer.nSent), 0);
        hv_store(TPEER, "reSends", 7, newSViv(tpeer.reSends), 0);

        BYTESSENT = newHV();
        hv_store(BYTESSENT, "high", 4, newSViv(tpeer.bytesSent.high), 0);
        hv_store(BYTESSENT, "low", 3, newSViv(tpeer.bytesSent.low), 0);
        hv_store(TPEER, "bytesSent", 9, newRV_inc((SV*)(BYTESSENT)), 0);

        BYTESRECEIVED = newHV();
        hv_store(BYTESRECEIVED, "high", 4, newSViv(tpeer.bytesReceived.high), 0);
        hv_store(BYTESRECEIVED, "low", 3, newSViv(tpeer.bytesReceived.low), 0);
        hv_store(TPEER, "bytesReceived", 13, newRV_inc((SV*)(BYTESRECEIVED)), 0);

        hv_store(TPEER, "rtt", 3, newSViv(tpeer.rtt), 0);
        hv_store(TPEER, "rtt_dev", 7, newSViv(tpeer.rtt_dev), 0);

        TIMEOUT = newHV();
        hv_store(TIMEOUT, "sec", 3, newSViv(tpeer.timeout.sec), 0);
        hv_store(TIMEOUT, "usec", 4, newSViv(tpeer.timeout.usec), 0);
        hv_store(TPEER, "timeout", 7, newRV_inc((SV*)(TIMEOUT)), 0);

        if (showLong) {
          hv_store(TPEER, "inPacketSkew", 12,
                   newSViv(tpeer.inPacketSkew), 0);
          hv_store(TPEER, "outPacketSkew", 13,
                   newSViv(tpeer.outPacketSkew), 0);
          hv_store(TPEER, "cwind", 5,
                   newSViv(tpeer.cwind), 0);
          hv_store(TPEER, "MTU", 3,
                   newSViv(tpeer.MTU), 0);
          hv_store(TPEER, "nDgramPackets", 13,
                   newSViv(tpeer.nDgramPackets), 0);
          hv_store(TPEER, "ifDgramPackets", 14,
                   newSViv(tpeer.ifDgramPackets), 0);
          hv_store(TPEER, "maxDgramPackets", 15,
                   newSViv(tpeer.maxDgramPackets), 0);
        }

        av_store(PEERS, index, newRV_inc((SV*)(TPEER)));
        index++;
      }

      hv_store(RETVAL, "peers", 5, newRV_inc((SV*)(PEERS)), 0);
    }

    done:
    /* return RETVAL */
    ST(0) = sv_2mortal(newRV_inc((SV*)RETVAL));
    SETCODE(0);
    XSRETURN(1);
}





void
afs_error_message(code)
        int32   code
    PPCODE:
    {
        ST(0) = sv_newmortal();
        sv_setpv(ST(0), (char *) error_message(code));
        XSRETURN(1);
    }



  /* this function is generated automatically by constant_gen */
  /* You didn't think I would type in this crap did you? */
  /* thats what perl is for :-) */

void
constant(name, arg=0)
	char *	name
        int     arg
   PPCODE:
   {
  ST(0) = sv_newmortal();

  errno = EINVAL;

  switch (name[0]) {
  case 'A':
	switch (name[1]) {
	case 'F':
		switch (name[2]) {
		case 'S':
		if (strEQ(name,"AFSCB_MAX_XSTAT_LONGS"))
                    sv_setiv(ST(0),AFSCB_MAX_XSTAT_LONGS);
		else if (strEQ(name,"AFSCB_XSTATSCOLL_CALL_INFO"))
                    sv_setiv(ST(0),AFSCB_XSTATSCOLL_CALL_INFO);
		else if (strEQ(name,"AFSCB_XSTATSCOLL_FULL_PERF_INFO"))
                    sv_setiv(ST(0),AFSCB_XSTATSCOLL_FULL_PERF_INFO);
		else if (strEQ(name,"AFSCB_XSTATSCOLL_PERF_INFO"))
                    sv_setiv(ST(0),AFSCB_XSTATSCOLL_PERF_INFO);
		else if (strEQ(name,"AFSCB_XSTAT_VERSION"))
                    sv_setiv(ST(0),AFSCB_XSTAT_VERSION);
		else if (strEQ(name,"AFSCONF_VOLUMEPORT"))
                    sv_setiv(ST(0),AFSCONF_VOLUMEPORT);
		else if (strEQ(name,"AFS_MAX_XSTAT_LONGS"))
                    sv_setiv(ST(0),AFS_MAX_XSTAT_LONGS);
		else if (strEQ(name,"AFS_STATS_NUM_CM_RPC_OPS"))
                    sv_setiv(ST(0),AFS_STATS_NUM_CM_RPC_OPS);
		else if (strEQ(name,"AFS_STATS_NUM_FS_RPC_OPS"))
                    sv_setiv(ST(0),AFS_STATS_NUM_FS_RPC_OPS);
		else if (strEQ(name,"AFS_STATS_NUM_FS_XFER_OPS"))
                    sv_setiv(ST(0),AFS_STATS_NUM_FS_XFER_OPS);
		else if (strEQ(name,"AFS_XSTATSCOLL_CALL_INFO"))
                    sv_setiv(ST(0),AFS_XSTATSCOLL_CALL_INFO);
#ifndef NOAFS_XSTATSCOLL_CBSTATS
		else if (strEQ(name,"AFS_XSTATSCOLL_CBSTATS"))
                    sv_setiv(ST(0),AFS_XSTATSCOLL_CBSTATS);
#endif
		else if (strEQ(name,"AFS_XSTATSCOLL_FULL_PERF_INFO"))
                    sv_setiv(ST(0),AFS_XSTATSCOLL_FULL_PERF_INFO);
		else if (strEQ(name,"AFS_XSTATSCOLL_PERF_INFO"))
                    sv_setiv(ST(0),AFS_XSTATSCOLL_PERF_INFO);
		else if (strEQ(name,"AFS_XSTAT_VERSION"))
                    sv_setiv(ST(0),AFS_XSTAT_VERSION);
		else {
		     ST(0) = ST(1) = &PL_sv_undef;
		     return;
		}
		break;
		case '_':
		if (strEQ(name,"AF_INET")) sv_setiv(ST(0),AF_INET);
		else {
		     ST(0) = ST(1) = &PL_sv_undef;
		     return;
		}
		break;
  		default:
  			ST(0) = ST(1) = &PL_sv_undef;
			return;
  		}
  		break;
  	default:
  		ST(0) = ST(1) = &PL_sv_undef;
		return;
  	}

src/Monitor.xs  view on Meta::CPAN

		break;
  		default:
  			ST(0) = ST(1) = &PL_sv_undef;
			return;
  		}
  		break;
  	default:
  		ST(0) = ST(1) = &PL_sv_undef;
		return;
  	}
  	break;
  case 'W':
	switch (name[1]) {
	case 'R':
		switch (name[2]) {
		case 'I':
		if (strEQ(name,"WRITE_LOCK"))
                    sv_setiv(ST(0),WRITE_LOCK);
		else {
		     ST(0) = ST(1) = &PL_sv_undef;
		     return;
		}
		break;
  		default:
  			ST(0) = ST(1) = &PL_sv_undef;
			return;
  		}
  		break;
  	default:
  		ST(0) = ST(1) = &PL_sv_undef;
		return;
  	}
  	break;
  case 'X':
	switch (name[1]) {
	case 'S':
		switch (name[2]) {
		case 'T':
		if (strEQ(name,"XSTAT_FS_CBPORT"))
                    sv_setiv(ST(0),XSTAT_FS_CBPORT);
		else {
		     ST(0) = ST(1) = &PL_sv_undef;
		     return;
		}
		break;
  		default:
  			ST(0) = ST(1) = &PL_sv_undef;
			return;
  		}
  		break;
  	default:
  		ST(0) = ST(1) = &PL_sv_undef;
		return;
  	}
  	break;
  default:
  	ST(0) = ST(1) = &PL_sv_undef;
	return;
  }

  errno = 0;
  XSRETURN(1);
  return;
 }



( run in 0.701 second using v1.01-cache-2.11-cpan-39bf76dae61 )