AFS-Monitor

 view release on metacpan or  search on metacpan

src/Monitor.xs  view on Meta::CPAN

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;
   int num_unused;

   hv_store(RXSTATS, "packetRequests", 14, newSViv(rxstats->packetRequests),

src/Monitor.xs  view on Meta::CPAN

   hv_store(RXSTATS, "spuriousPacketsRead", 19,
            newSViv(rxstats->spuriousPacketsRead), 0);
   hv_store(RXSTATS, "ignorePacketDally", 17,
            newSViv(rxstats->ignorePacketDally), 0);

   hv_store(RXSTATS, "pingPacketsSent", 15, newSViv(rxstats->pingPacketsSent),
            0);
   hv_store(RXSTATS, "abortPacketsSent", 16,
            newSViv(rxstats->abortPacketsSent), 0);
   hv_store(RXSTATS, "busyPacketsSent", 15, newSViv(rxstats->busyPacketsSent),
            0);

   hv_store(RXSTATS, "ackPacketsSent", 14, newSViv(rxstats->ackPacketsSent),
            0);
   hv_store(RXSTATS, "dataPacketsSent", 15, newSViv(rxstats->dataPacketsSent),
            0);
   hv_store(RXSTATS, "dataPacketsReSent", 17,
            newSViv(rxstats->dataPacketsReSent), 0);
   hv_store(RXSTATS, "dataPacketsPushed", 17,
            newSViv(rxstats->dataPacketsPushed), 0);
   hv_store(RXSTATS, "ignoreAckedPacket", 17,
            newSViv(rxstats->ignoreAckedPacket), 0);

   hv_store(RXSTATS, "netSendFailures", 15, newSViv(rxstats->netSendFailures),
            0);
   hv_store(RXSTATS, "fatalErrors", 11, newSViv(rxstats->fatalErrors), 0);

   hv_store(RXSTATS, "nServerConns", 12, newSViv(rxstats->nServerConns), 0);
   hv_store(RXSTATS, "nClientConns", 12, newSViv(rxstats->nClientConns), 0);
   hv_store(RXSTATS, "nPeerStructs", 12, newSViv(rxstats->nPeerStructs), 0);
   hv_store(RXSTATS, "nCallStructs", 12, newSViv(rxstats->nCallStructs), 0);
   hv_store(RXSTATS, "nFreeCallStructs", 16,
            newSViv(rxstats->nFreeCallStructs), 0);

   hv_store(RXSTATS, "nRttSamples", 11, newSViv(rxstats->nRttSamples), 0);

   TOTALRTT = newHV();
   hv_store(TOTALRTT, "sec", 3, newSViv(rxstats->totalRtt.sec), 0);
   hv_store(TOTALRTT, "usec", 4, newSViv(rxstats->totalRtt.usec), 0);
   hv_store(RXSTATS, "totalRtt", 8, newRV_inc((SV *) (TOTALRTT)), 0);
   MINRTT = newHV();
   hv_store(MINRTT, "sec", 3, newSViv(rxstats->minRtt.sec), 0);
   hv_store(MINRTT, "usec", 4, newSViv(rxstats->minRtt.usec), 0);
   hv_store(RXSTATS, "minRtt", 6, newRV_inc((SV *) (MINRTT)), 0);
   MAXRTT = newHV();
   hv_store(MAXRTT, "sec", 3, newSViv(rxstats->maxRtt.sec), 0);
   hv_store(MAXRTT, "usec", 4, newSViv(rxstats->maxRtt.usec), 0);
   hv_store(RXSTATS, "maxRtt", 6, newRV_inc((SV *) (MAXRTT)), 0);

#if !defined(AFS_PTHREAD_ENV) && !defined(AFS_USE_GETTIMEOFDAY)
   hv_store(RXSTATS, "clock_nUpdates", 14, newSViv(clock_nUpdates), 0);
#endif
}

/* end of rxdebug helper functions */





/* start of afsmonitor helper functions */

/*
 * 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 $");
 */

#define FS 1    /* for misc. use */
#define CM 2    /* for misc. use */
#define CFG_STR_LEN 80  /* max length of config file fields */
#define NUM_XSTAT_FS_AFS_PERFSTATS_LONGS 66 /* number of fields (longs)
                                             * in struct afs_PerfStats */
#define NUM_AFS_STATS_CMPERF_LONGS 40   /* number of longs in struct afs_stats_CMPerf
                                         * excluding up/down stats and fields we dont display */


/*
 * from src/afsmonitor/afsmonitor.h
 *
 */

#define HOST_NAME_LEN 80    /* length of server/cm names */
#define THRESH_VAR_NAME_LEN 80  /* THRESHOLD STRUCTURE DEFINITIONS */
#define THRESH_VAR_LEN 16
#define NUM_FS_STAT_ENTRIES 271 /* number of file server statistics
                                 * entries to display */
#define FS_STAT_STRING_LEN 14   /* max length of each string above */
#define NUM_CM_STAT_ENTRIES 571 /* number of cache manager statistics
                                 * entries to display */
#define CM_STAT_STRING_LEN 14   /* max length of each string above */

#define FS_NUM_DATA_CATEGORIES 9    /* # of fs categories */
#define CM_NUM_DATA_CATEGORIES 16   /* # of cm categories */


/*
 * 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 $");
 *

/*
 * We have to pass a port to Rx to start up our callback listener
 * service, but 7001 is already taken up by the Cache Manager.  So,
 * we make up our own.
 */
#define XSTAT_FS_CBPORT 7101


/*
 * 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 $");
 */

static char *fsOpNames[] = {
   "FetchData",
   "FetchACL",
   "FetchStatus",
   "StoreData",
   "StoreACL",
   "StoreStatus",
   "RemoveFile",
   "CreateFile",
   "Rename",
   "Symlink",
   "Link",
   "MakeDir",
   "RemoveDir",
   "SetLock",
   "ExtendLock",
   "ReleaseLock",
   "GetStatistics",
   "GiveUpCallbacks",
   "GetVolumeInfo",
   "GetVolumeStatus",
   "SetVolumeStatus",
   "GetRootVolume",
   "CheckToken",
   "GetTime",
   "NGetVolumeInfo",
   "BulkStatus",
   "XStatsVersion",
   "GetXStats",
   "XLookup"	/* from xstat/xstat_cm_test.c */
};


/*
 * 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 $");
 */

static char *cmOpNames[] = {
   "CallBack",
   "InitCallBackState",
   "Probe",
   "GetLock",
   "GetCE",
   "XStatsVersion",
   "GetXStats"
};


src/Monitor.xs  view on Meta::CPAN

   }

   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
    * names are listed in xx_varNames[] and section/group names in xx_categories[].
    * The section/group names in xx_categiries[] also give the starting/ending
    * indices of the variables belonging to that section/group. These indices
    * are stored in order in xx_Display_map[] and displayed to the screen in that
    * order. */

   /* To handle duplicate "show" entries we keep track of what what we have
    * already marked to show in the xx_showFlags[] */

   if (strcasecmp(arg1, "fs") == 0) {   /* its a File Server entry */
      /* mark that we have to show only what the user wants */
      *fs_showDefault = 0;

      /* if it is a section/group name, find it in the fs_categories[] array */

      found = 0;
      if (strcasestr(arg2, "_section") != (char *)NULL
          || strcasestr(arg2, "_group") != (char *)NULL) {
         idx = 0;
         while (idx < FS_NUM_DATA_CATEGORIES) {
            sscanf(fs_categories[idx], "%s %d %d", catName, &fromIdx, &toIdx);
            idx++;
            if (strcasecmp(arg2, catName) == 0) {
               found = 1;
               break;
            }
         }

         if (!found) {  /* typo in section/group name */
            sprintf(buffer, "Could not find section/group name %s", arg2);
            return (-1);
         }
      }

        /* if it is a group name, read its start/end indices and fill in the
         * fs_Display_map[]. */

      if (strcasestr(arg2, "_group") != (char *)NULL) {

         if (fromIdx < 0 || toIdx < 0 || fromIdx > NUM_FS_STAT_ENTRIES ||
             toIdx > NUM_FS_STAT_ENTRIES)
            return (-2);
         for (j = fromIdx; j <= toIdx; j++) {
            fs_showFlags[j] = 1;
         }
      }

      /* if it is a section name */
      else if (strcasestr(arg2, "_section") != (char *)NULL) {
         /* fromIdx is actually the number of groups in this section */
         numGroups = fromIdx;
         /* for each group in section */
         while (idx < FS_NUM_DATA_CATEGORIES && numGroups) {
            sscanf(fs_categories[idx], "%s %d %d", catName, &fromIdx, &toIdx);

            if (strcasestr(catName, "_group") != (char *) NULL) {
               if (fromIdx < 0 || toIdx < 0 || fromIdx > NUM_FS_STAT_ENTRIES
                   || toIdx > NUM_FS_STAT_ENTRIES)
                  return (-4);
               for (j = fromIdx; j <= toIdx; j++) {
                  fs_showFlags[j] = 1;
               }
            }
            else {
               sprintf(buffer, "Error parsing groups for %s", arg2);
               return (-6);
            }
            idx++;
            numGroups--;
         }  /* for each group in section */

      }
      else {    /* it is a variable name */

         for (i = 0; i < NUM_FS_STAT_ENTRIES; i++) {
            if (strcasecmp(arg2, fs_varNames[i]) == 0) {
               fs_showFlags[i] = 1;
               found = 1;
               break;
            }
         }
         if (!found) {  /* typo in variable name */
            sprintf(buffer, "Could not find variable name %s", arg2);
            return (-1);
         }
      } /* its a variable name */

   }

    /* it is an fs entry */
   if (strcasecmp(arg1, "cm") == 0) {   /* its a Cache Manager entry */

      /* mark that we have to show only what the user wants */
      *cm_showDefault = 0;

      /* if it is a section/group name, find it in the cm_categories[] array */

      found = 0;
      if (strcasestr(arg2, "_section") != (char *)NULL
          || strcasestr(arg2, "_group") != (char *)NULL) {
         idx = 0;
         while (idx < CM_NUM_DATA_CATEGORIES) {
            sscanf(cm_categories[idx], "%s %d %d", catName, &fromIdx, &toIdx);
            idx++;
            if (strcasecmp(arg2, catName) == 0) {
               found = 1;
               break;
            }
         }

         if (!found) {  /* typo in section/group name */
            sprintf(buffer, "Could not find section/group name %s", arg2);
            return (-1);
         }
      }

      /* if it is a group name */

      if (strcasestr(arg2, "_group") != (char *)NULL) {

         if (fromIdx < 0 || toIdx < 0 || fromIdx > NUM_CM_STAT_ENTRIES
             || toIdx > NUM_CM_STAT_ENTRIES)
            return (-10);
         for (j = fromIdx; j <= toIdx; j++) {
            cm_showFlags[j] = 1;
         }
      }

      /* if it is a section name, get the count of number of groups in it and
       * for each group fill in the start/end indices in the cm_Display_map[] */

      else if (strcasestr(arg2, "_section") != (char *)NULL) {
         /* fromIdx is actually the number of groups in thi section */
         numGroups = fromIdx;
         /* for each group in section */
         while (idx < CM_NUM_DATA_CATEGORIES && numGroups) {
            sscanf(cm_categories[idx], "%s %d %d", catName, &fromIdx, &toIdx);

            if (strcasestr(catName, "_group") != (char *) NULL) {
               if (fromIdx < 0 || toIdx < 0 || fromIdx > NUM_CM_STAT_ENTRIES
                   || toIdx > NUM_CM_STAT_ENTRIES)
                  return (-12);
               for (j = fromIdx; j <= toIdx; j++) {
                  cm_showFlags[j] = 1;
               }
            }
            else {
               sprintf(buffer, "Error parsing groups for %s", arg2);
               return (-15);
            }
            idx++;
            numGroups--;
         }  /* for each group in section */
      }
      else {    /* it is a variable name */

         for (i = 0; i < NUM_CM_STAT_ENTRIES; i++) {
            if (strcasecmp(arg2, cm_varNames[i]) == 0) {
               cm_showFlags[i] = 1;
               found = 1;
               break;
            }
         }
         if (!found) {  /* typo in section/group name */
            sprintf(buffer, "Could not find variable name %s", arg2);
            return (-1);
         }
      } /* its a variable name */

   }    /* it is a cm entry */

   return (0);

}   /* my_parse_showEntry() */



/*
 * 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_hostEntry(a_line, numFS, numCM, lastHostType, last_hostEntry,
                   FSnameList, CMnameList, buffer)
   char *a_line;
   int *numFS;
   int *numCM;
   int *lastHostType;
   struct afsmon_hostEntry **last_hostEntry;

src/Monitor.xs  view on Meta::CPAN

      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() */


src/Monitor.xs  view on Meta::CPAN


    /*
     * 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() */


/*
 * 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_Cleanup(a_releaseMem, xstat_fs_numServers, xstat_fs_ConnInfo,
                    buffer)
   int a_releaseMem;
   int xstat_fs_numServers;
   struct xstat_fs_ConnectionInfo *xstat_fs_ConnInfo;
   char *buffer;
{
   int code = 0;                /*Return code */
   int conn_idx = 0;            /*Current connection index */
   struct xstat_fs_ConnectionInfo *curr_conn = 0;   /*Ptr to xstat_fs connection */

   /*
    * Take care of all Rx connections first.  Check to see that the
    * server count is a legal value.
    */
   if (xstat_fs_numServers <= 0) {
      sprintf(buffer,
              "Illegal number of servers (xstat_fs_numServers = %d)",
              xstat_fs_numServers);
      code = -1;
   }
   else {
      if (xstat_fs_ConnInfo != (struct xstat_fs_ConnectionInfo *) NULL) {
         /*
          * The xstat_fs connection structure array exists.  Go through
          * it and close up any Rx connections it holds.
          */
         curr_conn = xstat_fs_ConnInfo;
         for (conn_idx = 0; conn_idx < xstat_fs_numServers; conn_idx++) {
            if (curr_conn->rxconn != (struct rx_connection *) NULL) {
               rx_DestroyConnection(curr_conn->rxconn);
               curr_conn->rxconn = (struct rx_connection *) NULL;
            }
            curr_conn++;
         }  /*for each xstat_fs connection */
      } /*xstat_fs connection structure exists */
   }    /*Legal number of servers */

   /*
    * If asked to, release the space we've allocated.

src/Monitor.xs  view on Meta::CPAN


    /*
     * 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() */


/*
 * 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_Cleanup(int a_releaseMem, int xstat_cm_numServers,
                    struct xstat_cm_ConnectionInfo *xstat_cm_ConnInfo,
                    char *buffer)
{
   int code = 0;                /*Return code */
   int conn_idx = 0;            /*Current connection index */
   struct xstat_cm_ConnectionInfo *curr_conn = 0;   /*Ptr to xstat_fs connection */

   /*
    * Take care of all Rx connections first.  Check to see that the
    * server count is a legal value.
    */
   if (xstat_cm_numServers <= 0) {
      sprintf(buffer,
              "Illegal number of servers (xstat_cm_numServers = %d)",
              xstat_cm_numServers);
      code = -1;
   }
   else {
      if (xstat_cm_ConnInfo != (struct xstat_cm_ConnectionInfo *) NULL) {
         /*
          * The xstat_fs connection structure array exists.  Go through
          * it and close up any Rx connections it holds.
          */
         curr_conn = xstat_cm_ConnInfo;
         for (conn_idx = 0; conn_idx < xstat_cm_numServers; conn_idx++) {
            if (curr_conn->rxconn != (struct rx_connection *) NULL) {
               rx_DestroyConnection(curr_conn->rxconn);
               curr_conn->rxconn = (struct rx_connection *) NULL;
            }
            curr_conn++;
         }  /*for each xstat_cm connection */
      } /*xstat_cm connection structure exists */
   }    /*Legal number of servers */

   /*
    * If asked to, release the space we've allocated.
    */

src/Monitor.xs  view on Meta::CPAN

                                              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) {



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