Don't cast returns from malloc()
[openafs.git] / src / fsprobe / fsprobe.c
index 863a043..6f8cdbf 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
-
+#include <roken.h>
 
-#ifdef HAVE_STRING_H
-#include <string.h>
-#else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#endif
-
-#include <fsprobe.h>           /*Interface for this module */
 #include <lwp.h>               /*Lightweight process package */
 #include <afs/cellconfig.h>
+#include <afs/afsint.h>
+#include <afs/afsutil.h>
+#include <afs/volser.h>
+#include <afs/volser_prototypes.h>
+#define FSINT_COMMON_XG
+#include <afs/afscbint.h>
 
-#define LWP_STACK_SIZE (16 * 1024)
-
-/*
- * Routines we need that don't have explicit include file definitions.
- */
-extern int RXAFSCB_ExecuteRequest();   /*AFS callback dispatcher */
-extern char *hostutil_GetNameByINet(); /*Host parsing utility */
+#include "fsprobe.h"           /*Interface for this module */
 
-/*
- * Help out the linker by explicitly importing the callback routines.
- */
-extern afs_int32 SRXAFSCB_CallBack();
-extern afs_int32 SRXAFSCB_InitCallBackState2();
-extern afs_int32 SRXAFSCB_Probe();
+#define LWP_STACK_SIZE (16 * 1024)
 
 /*
  * Exported variables.
@@ -60,7 +44,7 @@ int fsprobe_ProbeFreqInSecs;  /*Probe freq. in seconds */
  */
 static int fsprobe_initflag = 0;       /*Was init routine called? */
 static int fsprobe_debug = 0;  /*Debugging output enabled? */
-static int (*fsprobe_Handler) ();      /*Probe handler routine */
+static int (*fsprobe_Handler) (void);  /*Probe handler routine */
 static PROCESS probeLWP_ID;    /*Probe LWP process ID */
 static int fsprobe_statsBytes; /*Num bytes in stats block */
 static int fsprobe_probeOKBytes;       /*Num bytes in probeOK block */
@@ -95,7 +79,7 @@ static int fsprobe_probeOKBytes;      /*Num bytes in probeOK block */
  *------------------------------------------------------------------------*/
 
 static int
-fsprobe_CleanupInit()
+fsprobe_CleanupInit(void)
 {                              /*fsprobe_CleanupInit */
 
     afs_int32 code;            /*Return code from callback stubs */
@@ -148,9 +132,7 @@ fsprobe_CleanupInit()
  *------------------------------------------------------------------------*/
 
 int
-fsprobe_Cleanup(a_releaseMem)
-     int a_releaseMem;
-
+fsprobe_Cleanup(int a_releaseMem)
 {                              /*fsprobe_Cleanup */
 
     static char rn[] = "fsprobe_Cleanup";      /*Routine name */
@@ -237,18 +219,20 @@ fsprobe_Cleanup(a_releaseMem)
  * Side Effects:
  *     As advertised.
  *------------------------------------------------------------------------*/
-static void
-fsprobe_LWP()
+static void *
+fsprobe_LWP(void *unused)
 {                              /*fsprobe_LWP */
 
     static char rn[] = "fsprobe_LWP";  /*Routine name */
-    register afs_int32 code;   /*Results of calls */
+    afs_int32 code;    /*Results of calls */
     struct timeval tv;         /*Time structure */
     int conn_idx;              /*Connection index */
     struct fsprobe_ConnectionInfo *curr_conn;  /*Current connection */
     struct ProbeViceStatistics *curr_stats;    /*Current stats region */
     int *curr_probeOK;         /*Current probeOK field */
-
+    ViceStatistics64 stats64;      /*Current stats region */
+    stats64.ViceStatistics64_val = malloc(STATS64_VERSION *
+                                         sizeof(afs_uint64));
     while (1) {                        /*Service loop */
        /*
         * Iterate through the server connections, gathering data.
@@ -280,8 +264,19 @@ fsprobe_LWP()
                            "[%s] Connection valid, calling RXAFS_GetStatistics\n",
                            rn);
                *curr_probeOK =
-                   RXAFS_GetStatistics(curr_conn->rxconn, curr_stats);
-
+                   RXAFS_GetStatistics64(curr_conn->rxconn, STATS64_VERSION, &stats64);
+               if (*curr_probeOK == RXGEN_OPCODE)
+                   *curr_probeOK =
+                       RXAFS_GetStatistics(curr_conn->rxconn, (ViceStatistics *)curr_stats);
+               else if (*curr_probeOK == 0) {
+                   curr_stats->CurrentTime = RoundInt64ToInt32(stats64.ViceStatistics64_val[STATS64_CURRENTTIME]);
+                   curr_stats->BootTime = RoundInt64ToInt32(stats64.ViceStatistics64_val[STATS64_BOOTTIME]);
+                   curr_stats->StartTime = RoundInt64ToInt32(stats64.ViceStatistics64_val[STATS64_STARTTIME]);
+                   curr_stats->CurrentConnections = RoundInt64ToInt32(stats64.ViceStatistics64_val[STATS64_CURRENTCONNECTIONS]);
+                   curr_stats->TotalFetchs = RoundInt64ToInt32(stats64.ViceStatistics64_val[STATS64_TOTALFETCHES]);
+                   curr_stats->TotalStores = RoundInt64ToInt32(stats64.ViceStatistics64_val[STATS64_TOTALSTORES]);
+                   curr_stats->WorkStations = RoundInt64ToInt32(stats64.ViceStatistics64_val[STATS64_WORKSTATIONS]);
+               }
            }
 
            /*Valid Rx connection */
@@ -295,6 +290,8 @@ fsprobe_LWP()
                int i, code;
                char pname[10];
                struct diskPartition partition;
+               struct diskPartition64 *partition64p =
+                   malloc(sizeof(struct diskPartition64));
 
                if (fsprobe_debug)
                    fprintf(stderr,
@@ -305,22 +302,36 @@ fsprobe_LWP()
                        MapPartIdIntoName(curr_conn->partList.partId[i],
                                          pname);
                        code =
-                           AFSVolPartitionInfo(curr_conn->rxVolconn, pname,
-                                               &partition);
+                           AFSVolPartitionInfo64(curr_conn->rxVolconn, pname,
+                                                 partition64p);
+
+                       if (!code) {
+                           curr_stats->Disk[i].BlocksAvailable =
+                               RoundInt64ToInt31(partition64p->free);
+                           curr_stats->Disk[i].TotalBlocks =
+                               RoundInt64ToInt31(partition64p->minFree);
+                           strcpy(curr_stats->Disk[i].Name, pname);
+                       }
+                       if (code == RXGEN_OPCODE) {
+                           code =
+                               AFSVolPartitionInfo(curr_conn->rxVolconn,
+                                                   pname, &partition);
+                           if (!code) {
+                               curr_stats->Disk[i].BlocksAvailable =
+                                   partition.free;
+                               curr_stats->Disk[i].TotalBlocks =
+                                   partition.minFree;
+                               strcpy(curr_stats->Disk[i].Name, pname);
+                           }
+                       }
                        if (code) {
                            fprintf(stderr,
                                    "Could not get information on server %s partition %s\n",
                                    curr_conn->hostName, pname);
-                       } else {
-                           curr_stats->Disk[i].BlocksAvailable =
-                               partition.free;
-                           curr_stats->Disk[i].TotalBlocks =
-                               partition.minFree;
-                           strcpy(curr_stats->Disk[i].Name, pname);
                        }
                    }
-
                }
+               free(partition64p);
            }
 
 
@@ -364,19 +375,21 @@ fsprobe_LWP()
        if (code)
            fprintf(stderr, "[%s] IOMGR_Select returned code %d\n", rn, code);
     }                          /*Service loop */
+    free(stats64.ViceStatistics64_val);
 
+    return NULL;
 }                              /*fsprobe_LWP */
 
 /*list all the partitions on <aserver> */
 static int newvolserver = 0;
-XListPartitions(aconn, ptrPartList, cntp)
-     struct rx_connection *aconn;
-     struct partList *ptrPartList;
-     afs_int32 *cntp;
+
+int
+XListPartitions(struct rx_connection *aconn, struct partList *ptrPartList,
+               afs_int32 *cntp)
 {
     struct pIDs partIds;
     struct partEntries partEnts;
-    register int i, j = 0, code;
+    int i, j = 0, code;
 
     *cntp = 0;
     if (newvolserver == 1) {
@@ -461,18 +474,13 @@ XListPartitions(aconn, ptrPartList, cntp)
  *------------------------------------------------------------------------*/
 
 int
-fsprobe_Init(a_numServers, a_socketArray, a_ProbeFreqInSecs, a_ProbeHandler,
-            a_debug)
-     int a_numServers;
-     struct sockaddr_in *a_socketArray;
-     int a_ProbeFreqInSecs;
-     int (*a_ProbeHandler) ();
-     int a_debug;
-
+fsprobe_Init(int a_numServers, struct sockaddr_in *a_socketArray,
+            int a_ProbeFreqInSecs, int (*a_ProbeHandler)(void),
+            int a_debug)
 {                              /*fsprobe_Init */
 
     static char rn[] = "fsprobe_Init"; /*Routine name */
-    register afs_int32 code;   /*Return value */
+    afs_int32 code;    /*Return value */
     static struct rx_securityClass *CBsecobj;  /*Callback security object */
     struct rx_securityClass *secobj;   /*Client security object */
     struct rx_service *rxsrv_afsserver;        /*Server for AFS */
@@ -540,7 +548,7 @@ fsprobe_Init(a_numServers, a_socketArray, a_ProbeFreqInSecs, a_ProbeHandler,
        malloc(a_numServers * sizeof(struct fsprobe_ConnectionInfo));
     if (fsprobe_ConnInfo == (struct fsprobe_ConnectionInfo *)0) {
        fprintf(stderr,
-               "[%s] Can't allocate %d connection info structs (%d bytes)\n",
+               "[%s] Can't allocate %d connection info structs (%"AFS_SIZET_FMT" bytes)\n",
                rn, a_numServers,
                (a_numServers * sizeof(struct fsprobe_ConnectionInfo)));
        return (-1);            /*No cleanup needs to be done yet */
@@ -565,7 +573,7 @@ fsprobe_Init(a_numServers, a_socketArray, a_ProbeFreqInSecs, a_ProbeHandler,
                rn, fsprobe_statsBytes);
 
     fsprobe_probeOKBytes = a_numServers * sizeof(int);
-    fsprobe_Results.probeOK = (int *)malloc(fsprobe_probeOKBytes);
+    fsprobe_Results.probeOK = malloc(fsprobe_probeOKBytes);
     if (fsprobe_Results.probeOK == (int *)0) {
        fprintf(stderr,
                "[%s] Can't allocate %d probeOK array entries (%d bytes)\n",
@@ -646,7 +654,7 @@ fsprobe_Init(a_numServers, a_socketArray, a_ProbeFreqInSecs, a_ProbeHandler,
        if (fsprobe_debug) {
            fprintf(stderr, "[%s] Copying in the following socket info:\n",
                    rn);
-           fprintf(stderr, "[%s] IP addr 0x%lx, port %d\n", rn,
+           fprintf(stderr, "[%s] IP addr 0x%x, port %d\n", rn,
                    (a_socketArray + curr_srv)->sin_addr.s_addr,
                    (a_socketArray + curr_srv)->sin_port);
        }
@@ -657,7 +665,7 @@ fsprobe_Init(a_numServers, a_socketArray, a_ProbeFreqInSecs, a_ProbeHandler,
            hostutil_GetNameByINet(curr_conn->skt.sin_addr.s_addr);
        if (hostNameFound == NULL) {
            fprintf(stderr,
-                   "[%s] Can't map Internet address %lu to a string name\n",
+                   "[%s] Can't map Internet address %u to a string name\n",
                    rn, curr_conn->skt.sin_addr.s_addr);
            curr_conn->hostName[0] = '\0';
        } else {
@@ -672,7 +680,7 @@ fsprobe_Init(a_numServers, a_socketArray, a_ProbeFreqInSecs, a_ProbeHandler,
         */
        if (fsprobe_debug)
            fprintf(stderr,
-                   "[%s] Connecting to srv idx %d, IP addr 0x%lx, port %d, service 1\n",
+                   "[%s] Connecting to srv idx %d, IP addr 0x%x, port %d, service 1\n",
                    rn, curr_srv, curr_conn->skt.sin_addr.s_addr,
                    curr_conn->skt.sin_port);
        curr_conn->rxconn = rx_NewConnection(curr_conn->skt.sin_addr.s_addr,    /*Server addr */
@@ -682,12 +690,12 @@ fsprobe_Init(a_numServers, a_socketArray, a_ProbeFreqInSecs, a_ProbeHandler,
                                             0);        /*Number of above */
        if (curr_conn->rxconn == (struct rx_connection *)0) {
            fprintf(stderr,
-                   "[%s] Can't create Rx connection to server %s (%lu)\n",
+                   "[%s] Can't create Rx connection to server %s (%u)\n",
                    rn, curr_conn->hostName, curr_conn->skt.sin_addr.s_addr);
            conn_err = 1;
        }
        if (fsprobe_debug)
-           fprintf(stderr, "[%s] New connection at 0x%lx\n", rn,
+           fprintf(stderr, "[%s] New connection at %p\n", rn,
                    curr_conn->rxconn);
 
        /*
@@ -695,7 +703,7 @@ fsprobe_Init(a_numServers, a_socketArray, a_ProbeFreqInSecs, a_ProbeHandler,
         */
        if (fsprobe_debug)
            fprintf(stderr,
-                   "[%s] Connecting to srv idx %d, IP addr 0x%lx, port %d, service 1\n",
+                   "[%s] Connecting to srv idx %d, IP addr 0x%x, port %d, service 1\n",
                    rn, curr_srv, curr_conn->skt.sin_addr.s_addr,
                    htons(7005));
        curr_conn->rxVolconn = rx_NewConnection(curr_conn->skt.sin_addr.s_addr, /*Server addr */
@@ -705,7 +713,7 @@ fsprobe_Init(a_numServers, a_socketArray, a_ProbeFreqInSecs, a_ProbeHandler,
                                                0);     /*Number of above */
        if (curr_conn->rxVolconn == (struct rx_connection *)0) {
            fprintf(stderr,
-                   "[%s] Can't create Rx connection to volume server %s (%lu)\n",
+                   "[%s] Can't create Rx connection to volume server %s (%u)\n",
                    rn, curr_conn->hostName, curr_conn->skt.sin_addr.s_addr);
            conn_err = 1;
        } else {
@@ -720,7 +728,7 @@ fsprobe_Init(a_numServers, a_socketArray, a_ProbeFreqInSecs, a_ProbeHandler,
            }
        }
        if (fsprobe_debug)
-           fprintf(stderr, "[%s] New connection at 0x%lx\n", rn,
+           fprintf(stderr, "[%s] New connection at %p\n", rn,
                    curr_conn->rxVolconn);
 
 
@@ -776,7 +784,7 @@ fsprobe_Init(a_numServers, a_socketArray, a_ProbeFreqInSecs, a_ProbeHandler,
        return (code);
     }
     if (fsprobe_debug)
-       fprintf(stderr, "[%s] Probe LWP process structure located at 0x%x\n",
+       fprintf(stderr, "[%s] Probe LWP process structure located at %p\n",
                rn, probeLWP_ID);
 
 #if 0
@@ -820,7 +828,7 @@ fsprobe_Init(a_numServers, a_socketArray, a_ProbeFreqInSecs, a_ProbeHandler,
  *------------------------------------------------------------------------*/
 
 int
-fsprobe_ForceProbeNow()
+fsprobe_ForceProbeNow(void)
 {                              /*fsprobe_ForceProbeNow */
 
     static char rn[] = "fsprobe_ForceProbeNow";        /*Routine name */