afsd-allow-maxmtu-override-20090530
[openafs.git] / src / afsd / afsd.c
index 17b3e32..85718d3 100644 (file)
   *    -confdir    The configuration directory .
   *    -nosettime  Don't keep checking the time to avoid drift (default).
   *     -settime    Keep checking the time to avoid drift.
+  *    -rxmaxmtu   Set the max mtu to help with VPN issues.
   *    -verbose     Be chatty.
+  *    -disable-dynamic-vcaches     Disable the use of -stat value as the starting size of
+  *                          the size of the vcache/stat cache pool, 
+  *                          but increase that pool dynamically as needed.
   *    -debug     Print out additional debugging info.
   *    -kerndev    [OBSOLETE] The kernel device for AFS.
   *    -dontfork   [OBSOLETE] Don't fork off as a new process.
@@ -190,7 +194,6 @@ static io_connect_t root_port;
 static IONotificationPortRef notify;
 static io_object_t iterator;
 static CFRunLoopSourceRef source;
-static DNSSDState dnsstate;
 
 static int event_pid;
 
@@ -304,7 +307,9 @@ static int vCacheSize = 200;        /* # of volume cache entries */
 static int rootVolSet = 0;     /*True if root volume name explicitly set */
 int addrNum;                   /*Cell server address index being printed */
 static int cacheFlags = 0;     /*Flags to cache manager */
+#ifdef AFS_AIX32_ENV
 static int nBiods = 5;         /* AIX3.1 only */
+#endif
 static int preallocs = 400;    /* Def # of allocated memory blocks */
 static int enable_peer_stats = 0;      /* enable rx stats */
 static int enable_process_stats = 0;   /* enable rx stats */
@@ -319,9 +324,11 @@ static int enable_splitcache = 0;
 #ifdef notdef
 static int inodes = 60;                /* VERY conservative, but has to be */
 #endif
+int afsd_dynamic_vcaches = 0;  /* Enable dynamic-vcache support */
 int afsd_verbose = 0;          /*Are we being chatty? */
 int afsd_debug = 0;            /*Are we printing debugging info? */
 int afsd_CloseSynch = 0;       /*Are closes synchronous or not? */
+int rxmaxmtu = 0;       /* Are we forcing a limit on the mtu? */
 
 #ifdef AFS_SGI62_ENV
 #define AFSD_INO_T ino64_t
@@ -349,15 +356,14 @@ int missing_CellInfoFile = 1;     /*Is the CELLINFOFILE missing? */
 int afsd_rmtsys = 0;           /* Default: don't support rmtsys */
 struct afs_cacheParams cparams;        /* params passed to cache manager */
 
-static int HandleMTab();
+static int HandleMTab(void);
+int PartSizeOverflow(char *path, int cs);
 
 #ifdef AFS_DARWIN_ENV
 static void
 afsd_sleep_callback(void * refCon, io_service_t service, 
                    natural_t messageType, void * messageArgument )
 {
-    afs_int32 code;
-    
     switch (messageType) {
     case kIOMessageCanSystemSleep:
        /* Idle sleep is about to kick in; can 
@@ -397,7 +403,7 @@ static void
 afsd_update_addresses(CFRunLoopTimerRef timer, void *info)
 {
     /* parse multihomed address files */
-    afs_int32 addrbuf[MAXIPADDRS], maskbuf[MAXIPADDRS],
+    afs_uint32 addrbuf[MAXIPADDRS], maskbuf[MAXIPADDRS],
        mtubuf[MAXIPADDRS];
     char reason[1024];
     afs_int32 code;
@@ -431,7 +437,6 @@ afsd_ipaddr_callback (SCDynamicStoreRef store, CFArrayRef changed_keys, void *in
 
 static void 
 afsd_event_cleanup(int signo) {
-    DNSSDState *query = &dnsstate;
 
     CFRunLoopRemoveSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode);
     CFRelease (source);
@@ -443,7 +448,7 @@ afsd_event_cleanup(int signo) {
 }
 
 /* Adapted from "Living in a Dynamic TCP/IP Environment" technote. */
-static Boolean
+static void
 afsd_install_events(void)
 {
     SCDynamicStoreContext ctx = {0};
@@ -695,10 +700,7 @@ PartSizeOverflow(char *path, int cs)
   *---------------------------------------------------------------------------*/
 
 static int
-doGetXFileNumber(fname, filechar, maxNum)
-     char *fname;
-     char filechar;
-     int maxNum;
+doGetXFileNumber(char *fname, char filechar, int maxNum)
 {
     int computedVNumber;       /*The computed file number we return */
     int filenameLen;           /*Number of chars in filename */
@@ -736,17 +738,13 @@ doGetXFileNumber(fname, filechar, maxNum)
 }
 
 int
-GetVFileNumber(fname, maxFile)
-     char *fname;
-     int maxFile;
+GetVFileNumber(char *fname, int maxFile)
 {
     return doGetXFileNumber(fname, 'V', maxFile);
 }
 
 int
-GetDDirNumber(fname, maxDir)
-     char *fname;
-     int maxDir;
+GetDDirNumber(char *fname, int maxDir)
 {
     return doGetXFileNumber(fname, 'D', maxDir);
 }
@@ -776,9 +774,7 @@ GetDDirNumber(fname, maxDir)
   *---------------------------------------------------------------------------*/
 
 static int
-CreateCacheSubDir(basename, dirNum)
-     char *basename;
-     int dirNum;
+CreateCacheSubDir(char *basename, int dirNum)
 {
     static char rn[] = "CreateCacheSubDir";    /* Routine Name */
     char dir[1024];
@@ -805,9 +801,8 @@ CreateCacheSubDir(basename, dirNum)
 }
 
 static int
-MoveCacheFile(basename, fromDir, toDir, cacheFile, maxDir)
-     char *basename;
-     int fromDir, toDir, cacheFile, maxDir;
+MoveCacheFile(char *basename, int fromDir, int toDir, int cacheFile, 
+             int maxDir)
 {
     static char rn[] = "MoveCacheFile";
     char from[1024], to[1024];
@@ -849,9 +844,7 @@ MoveCacheFile(basename, fromDir, toDir, cacheFile, maxDir)
 }
 
 int
-CreateCacheFile(fname, statp)
-     char *fname;
-     struct stat *statp;
+CreateCacheFile(char *fname, struct stat *statp)
 {
     static char rn[] = "CreateCacheFile";      /*Routine name */
     int cfd;                   /*File descriptor to AFS cache file */
@@ -939,11 +932,10 @@ UnlinkUnwantedFile(char *rn, char *fullpn_FileToDelete, char *fileToDelete)
 
 
 static int
-doSweepAFSCache(vFilesFound, directory, dirNum, maxDir)
-     int *vFilesFound;
-     char *directory;          /* /path/to/cache/directory */
-     int dirNum;               /* current directory number */
-     int maxDir;               /* maximum directory number */
+doSweepAFSCache(int *vFilesFound, 
+               char *directory,        /* /path/to/cache/directory */
+               int dirNum,             /* current directory number */
+               int maxDir)             /* maximum directory number */
 {
     static char rn[] = "doSweepAFSCache";      /* Routine Name */
     char fullpn_FileToDelete[1024];    /*File to be deleted from cache */
@@ -993,6 +985,8 @@ doSweepAFSCache(vFilesFound, directory, dirNum, maxDir)
 #ifdef AFS_SGI62_ENV
            printf("\tinode=%" AFS_INT64_FMT ", reclen=%d, name='%s'\n", currp->d_ino,
                   currp->d_reclen, currp->d_name);
+#elif defined(AFS_DFBSD_ENV)
+           printf("\tinode=%d, name='%s'\n", currp->d_ino, currp->d_name);
 #else
            printf("\tinode=%d, reclen=%d, name='%s'\n", currp->d_ino,
                   currp->d_reclen, currp->d_name);
@@ -1343,8 +1337,7 @@ CheckCacheBaseDir(char *dir)
 }
 
 int
-SweepAFSCache(vFilesFound)
-     int *vFilesFound;
+SweepAFSCache(int *vFilesFound)
 {
     static char rn[] = "SweepAFSCache";        /*Routine name */
     int maxDir = (cacheFiles + nFilesPerDir - 1) / nFilesPerDir;
@@ -1429,7 +1422,7 @@ ConfigCell(struct afsconf_cell *aci, void *arock, struct afsconf_dir *adir)
     return 0;
 }
 
-static
+static int
 ConfigCellAlias(struct afsconf_cellalias *aca,
                void *arock, struct afsconf_dir *adir)
 {
@@ -1439,8 +1432,8 @@ ConfigCellAlias(struct afsconf_cellalias *aca,
 }
 
 #ifdef AFS_AFSDB_ENV
-static
-AfsdbLookupHandler()
+static void
+AfsdbLookupHandler(void)
 {
     afs_int32 kernelMsg[64];
     char acellName[128];
@@ -1524,6 +1517,7 @@ AfsdbLookupHandler()
 #endif
 #endif
 
+int
 mainproc(struct cmd_syndesc *as, void *arock)
 {
     static char rn[] = "afsd"; /*Name of this routine */
@@ -1535,12 +1529,10 @@ mainproc(struct cmd_syndesc *as, void *arock)
     int cacheIteration;                /*How many times through cache verification */
     int vFilesFound;           /*How many data cache files were found in sweep */
     struct afsconf_dir *cdir;  /* config dir */
-    FILE *logfd;
     char *fsTypeMsg = NULL;
 #ifdef AFS_SUN5_ENV
     struct stat st;
 #endif
-    afs_int32 vfs1_type = -1;
 #ifdef AFS_SGI65_ENV
     struct sched_param sp;
 #endif
@@ -1763,6 +1755,31 @@ mainproc(struct cmd_syndesc *as, void *arock)
            }
        }
     }
+    if (as->parms[35].items) {
+#ifdef AFS_MAXVCOUNT_ENV
+       /* -disable-dynamic-vcaches */
+       afsd_dynamic_vcaches = FALSE;
+#else
+       printf("afsd: Error toggling flag, dynamically allocated vcaches not supported on your platform\n");
+       exit(1);
+#endif
+    }
+#ifdef AFS_MAXVCOUNT_ENV
+    else {
+       /* -dynamic-vcaches */
+       afsd_dynamic_vcaches = TRUE;
+    }
+
+    if (afsd_verbose)
+    printf("afsd: %s dynamically allocated vcaches\n", ( afsd_dynamic_vcaches ? "enabling" : "disabling" ));
+#endif
+
+    /* set -rxmaxmtu */
+    if (as->parms[35].items) {
+        /* -rxmaxmtu */
+        rxmaxmtu = atoi(as->parms[35].items->data);
+    }
+
     /*
      * Pull out all the configuration info for the workstation's AFS cache and
      * the cellular community we're willing to let our users see.
@@ -1951,7 +1968,7 @@ mainproc(struct cmd_syndesc *as, void *arock)
     }
     memset(inode_for_V, '\0', (cacheFiles * sizeof(AFSD_INO_T)));
     if (afsd_debug)
-       printf("%s: %d inode_for_V entries at 0x%x, %d bytes\n", rn,
+       printf("%s: %d inode_for_V entries at 0x%x, %lu bytes\n", rn,
               cacheFiles, inode_for_V, (cacheFiles * sizeof(AFSD_INO_T)));
 #endif
 
@@ -1986,7 +2003,7 @@ mainproc(struct cmd_syndesc *as, void *arock)
     /* initialize the rx random number generator from user space */
     {
        /* parse multihomed address files */
-       afs_int32 addrbuf[MAXIPADDRS], maskbuf[MAXIPADDRS],
+       afs_uint32 addrbuf[MAXIPADDRS], maskbuf[MAXIPADDRS],
            mtubuf[MAXIPADDRS];
        char reason[1024];
        code =
@@ -2101,6 +2118,7 @@ mainproc(struct cmd_syndesc *as, void *arock)
     cparams.chunkSize = chunkSize;
     cparams.setTimeFlag = cacheSetTime;
     cparams.memCacheFlag = cacheFlags;
+    cparams.dynamic_vcaches = afsd_dynamic_vcaches;
 #ifdef notdef
     cparams.inodes = inodes;
 #endif
@@ -2182,6 +2200,14 @@ mainproc(struct cmd_syndesc *as, void *arock)
               fullpn_CellInfoFile);
     call_syscall(AFSOP_CELLINFO, fullpn_CellInfoFile);
 
+    if (rxmaxmtu) {
+    if (afsd_verbose)
+        printf("%s: Setting rxmaxmtu in kernel = %d\n", rn, rxmaxmtu);
+    code = call_syscall(AFSOP_SET_RXMAXMTU, rxmaxmtu);
+    if (code)
+        printf("%s: Error seting rxmaxmtu\n", rn);
+    }
+
     if (enable_dynroot) {
        if (afsd_verbose)
            printf("%s: Enabling dynroot support in kernel.\n", rn);
@@ -2411,7 +2437,7 @@ mainproc(struct cmd_syndesc *as, void *arock)
 #include "AFS_component_version_number.c"
 
 
-
+int
 main(int argc, char **argv)
 {
     struct cmd_syndesc *ts;
@@ -2489,7 +2515,10 @@ main(int argc, char **argv)
                "set rx_extraPackets to this value");
     cmd_AddParm(ts, "-splitcache", CMD_SINGLE, CMD_OPTIONAL,
                "Percentage RW versus RO in cache (specify as 60/40)");
-
+    cmd_AddParm(ts, "-disable-dynamic-vcaches", CMD_FLAG, CMD_OPTIONAL, 
+               "disable stat/vcache cache growing as needed");
+    cmd_AddParm(ts, "-rxmaxmtu", CMD_SINGLE, CMD_OPTIONAL, "set rx max MTU to use");
+    
     return (cmd_Dispatch(argc, argv));
 }
 
@@ -2505,7 +2534,7 @@ main(int argc, char **argv)
 #endif
 
 static int
-HandleMTab()
+HandleMTab(void)
 {
 #if (defined (AFS_SUN_ENV) || defined (AFS_HPUX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV)) && !defined(AFS_SUN58_ENV)
     FILE *tfilep;
@@ -2585,8 +2614,9 @@ HandleMTab()
 
 #if !defined(AFS_SGI_ENV) && !defined(AFS_AIX32_ENV)
 
-call_syscall(param1, param2, param3, param4, param5, param6, param7)
-     long param1, param2, param3, param4, param5, param6, param7;
+int
+call_syscall(long param1, long param2, long param3, long param4, long param5, 
+            long param6, long  param7)
 {
     int error;
 #ifdef AFS_LINUX20_ENV
@@ -2637,7 +2667,7 @@ call_syscall(param1, param2, param3, param4, param5, param6, param7)
 #endif
 
     if (afsd_debug)
-       printf("SScall(%d, %d, %d)=%d ", AFS_SYSCALL, AFSCALL_CALL, param1,
+       printf("SScall(%d, %d, %ld)=%d ", AFS_SYSCALL, AFSCALL_CALL, param1,
               error);
     return (error);
 }