Remove DUX/OSF code
[openafs.git] / src / afsd / afsd.c
index 9b01abe..ff08532 100644 (file)
   *    -blocks     The number of blocks available in the workstation cache.
   *    -files      The target number of files in the workstation cache (Default:
   *                1000).
-  *    -rootvol            The name of the root volume to use.
+  *    -rootvol    The name of the root volume to use.
   *    -stat       The number of stat cache entries.
-  *    -hosts      List of servers to check for volume location info FOR THE
+  *    -hosts      [OBSOLETE] List of servers to check for volume location info FOR THE
   *                HOME CELL.
   *     -memcache   Use an in-memory cache rather than disk.
-  *    -cachedir    The base directory for the workstation cache.
+  *    -cachedir   The base directory for the workstation cache.
   *    -mountdir   The directory on which the AFS is to be mounted.
-  *    -confdir    The configuration directory .
+  *    -confdir    The configuration directory.
   *    -nosettime  Don't keep checking the time to avoid drift (default).
-  *     -settime    Keep checking the time to avoid drift.
+  *     -settime    [IGNORED] Keep checking the time to avoid drift.
   *    -rxmaxmtu   Set the max mtu to help with VPN issues.
-  *    -verbose     Be chatty.
+  *    -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.
   *                support daemon
   *     -chunksize [n]   2^n is the chunksize to be used.  0 is default.
   *     -dcache    The number of data cache entries.
+  *     -volumes    The number of volume entries.
   *     -biods     Number of bkg I/O daemons (AIX3.1 only)
   *    -prealloc  Number of preallocated "small" memory blocks
-  *    -logfile   [OBSOLETE] Place where to put the logfile (default in
+  *    -logfile    [IGNORED] Place where to put the logfile (default in
   *                <cache>/etc/AFSLog.
   *    -waitclose make close calls always synchronous (slows em down, tho)
   *    -files_per_subdir [n]   number of files per cache subdir. (def=2048)
   *    -shutdown  Shutdown afs daemons
+  *    -enable_peer_stats      Collect RPC statistics by peer.
+  *    -enable_process_stats   Collect RPC statistics for this process.
+  *    -mem_alloc_sleep [IGNORED] Sleep when allocating memory.
+  *    -afsdb      Enable AFSDB support.
+  *    -dynroot        Enable dynroot support.
+  *    -dynroot-sparse Enable dynroot support with minimal cell list.
+  *    -fakestat       Enable fake stat() for cross-cell mounts.
+  *    -fakestat-all   Enable fake stat() for all mounts.
+  *    -nomount    Do not mount /afs.
+  *    -backuptree Prefer backup volumes for mountpoints in backup volumes.
+  *    -rxbind     Bind the rx socket.
+  *    -rxpck      Value for rx_extraPackets.
+  *    -splitcache RW/RO ratio for cache.
+  *    -rxmaxfrags Max number of UDP fragments per rx packet.
+  *    -inumcalc  inode number calculation method; 0=compat, 1=MD5 digest
+  *    -volume-ttl vldb cache timeout in seconds
   *---------------------------------------------------------------------------*/
 
 #include <afsconfig.h>
@@ -261,12 +278,14 @@ static int enable_fakestat = 0;   /* enable fakestat support */
 static int enable_backuptree = 0;      /* enable backup tree support */
 static int enable_nomount = 0; /* do not mount */
 static int enable_splitcache = 0;
+static char *inumcalc = NULL;        /* inode number calculation method */
 static 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? */
 static int afsd_CloseSynch = 0;        /*Are closes synchronous or not? */
 static int rxmaxmtu = 0;       /* Are we forcing a limit on the mtu? */
 static int rxmaxfrags = 0;      /* Are we forcing a limit on frags? */
+static int volume_ttl = 0;      /* enable vldb cache timeout support */
 
 #ifdef AFS_SGI62_ENV
 #define AFSD_INO_T ino64_t
@@ -344,6 +363,8 @@ enum optionsList {
     OPT_rxmaxmtu,
     OPT_dynrootsparse,
     OPT_rxmaxfrags,
+    OPT_inumcalc,
+    OPT_volume_ttl,
 };
 
 #ifdef MACOS_EVENT_HANDLING
@@ -1112,12 +1133,6 @@ doSweepAFSCache(int *vFilesFound,
            SetNoBackupAttr(fullpn_CellInfoFile);
        } else if ((strcmp(currp->d_name, ".") == 0)
                   || (strcmp(currp->d_name, "..") == 0) ||
-#ifdef AFS_DECOSF_ENV
-                  /* these are magic AdvFS files */
-                  (strcmp(currp->d_name, ".tags") == 0)
-                  || (strcmp(currp->d_name, "quota.user") == 0)
-                  || (strcmp(currp->d_name, "quota.group") == 0) ||
-#endif
 #ifdef AFS_LINUX22_ENV
                   /* this is the ext3 journal file */
                   (strcmp(currp->d_name, ".journal") == 0) ||
@@ -1666,8 +1681,16 @@ rmtsysd_thread(void *rock)
 }
 #endif /* !UKERNEL */
 
-int
-mainproc(struct cmd_syndesc *as, void *arock)
+/**
+ * Check the command line and cacheinfo options.
+ *
+ * @param[in] as  parsed command line arguments
+ *
+ * @note Invokes the shutdown syscall and exits with 0 when
+ *       -shutdown is given.
+ */
+static int
+CheckOptions(struct cmd_syndesc *as)
 {
     afs_int32 code;            /*Result of fork() */
 #ifdef AFS_SUN5_ENV
@@ -1876,6 +1899,10 @@ mainproc(struct cmd_syndesc *as, void *arock)
     }
 
     cmd_OptionAsInt(as, OPT_rxmaxfrags, &rxmaxfrags);
+    if (cmd_OptionPresent(as, OPT_inumcalc)) {
+       cmd_OptionAsString(as, OPT_inumcalc, &inumcalc);
+    }
+    cmd_OptionAsInt(as, OPT_volume_ttl, &volume_ttl);
 
     /* parse cacheinfo file if this is a diskcache */
     if (ParseCacheInfoFile()) {
@@ -2146,7 +2173,7 @@ afsd_run(void)
        if (code > 0) {
            if (enable_rxbind)
                code = code | 0x80000000;
-               afsd_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf);
+           afsd_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf);
        } else
            printf("ADVISEADDR: Error in specifying interface addresses:%s\n",
                   reason);
@@ -2217,7 +2244,11 @@ afsd_run(void)
     cparams.setTimeFlag = 0;
     cparams.memCacheFlag = cacheFlags;
     cparams.dynamic_vcaches = afsd_dynamic_vcaches;
-    afsd_syscall(AFSOP_CACHEINIT, &cparams);
+    code = afsd_syscall(AFSOP_CACHEINIT, &cparams);
+    if (code) {
+       printf("%s: Error %d during cache init.\n", rn, code);
+        exit(1);
+    }
 
     /* do it before we init the cache inodes */
     if (enable_splitcache) {
@@ -2296,6 +2327,33 @@ afsd_run(void)
             printf("%s: Error seting rxmaxmtu\n", rn);
     }
 
+    if (inumcalc != NULL) {
+       if (strcmp(inumcalc, "compat") == 0) {
+           if (afsd_verbose) {
+               printf("%s: Setting original inode number calculation method in kernel.\n",
+                      rn);
+           }
+           code = afsd_syscall(AFSOP_SET_INUMCALC, AFS_INUMCALC_COMPAT);
+           if (code) {
+               printf("%s: Error setting inode calculation method: code=%d.\n",
+                      rn, code);
+           }
+       } else if (strcmp(inumcalc, "md5") == 0) {
+           if (afsd_verbose) {
+               printf("%s: Setting md5 digest inode number calculation in kernel.\n",
+                      rn);
+           }
+           code = afsd_syscall(AFSOP_SET_INUMCALC, AFS_INUMCALC_MD5);
+           if (code) {
+               printf("%s: Error setting inode calculation method: code=%d.\n",
+                      rn, code);
+           }
+       } else {
+           printf("%s: Unknown value for -inumcalc: %s."
+                  "Using default inode calculation method.\n", rn, inumcalc);
+       }
+    }
+
     if (enable_dynroot) {
        if (afsd_verbose)
            printf("%s: Enabling dynroot support in kernel%s.\n", rn,
@@ -2369,6 +2427,26 @@ afsd_run(void)
        afsd_syscall(AFSOP_ROOTVOLUME, rootVolume);
     }
 
+    if (volume_ttl != 0) {
+       if (afsd_verbose)
+           printf("%s: Calling AFSOP_SET_VOLUME_TTL with '%d'\n", rn, volume_ttl);
+       code = afsd_syscall(AFSOP_SET_VOLUME_TTL, volume_ttl);
+       if (code == EFAULT) {
+           if (volume_ttl < AFS_MIN_VOLUME_TTL)
+               printf("%s: Failed to set volume ttl to %d seconds; "
+                      "value is too low.\n", rn, volume_ttl);
+           else if (volume_ttl > AFS_MAX_VOLUME_TTL)
+               printf("%s: Failed to set volume ttl to %d seconds; "
+                      "value is too high.\n", rn, volume_ttl);
+           else
+               printf("%s: Failed to set volume ttl to %d seconds; "
+                      "value is out of range.\n", rn, volume_ttl);
+       } else if (code != 0) {
+           printf("%s: Failed to set volume ttl to %d seconds; "
+                  "code=%d.\n", rn, volume_ttl, code);
+       }
+    }
+
     /*
      * Pass the kernel the name of the workstation cache file holding the
      * volume information.
@@ -2431,7 +2509,7 @@ afsd_run(void)
     if (afsd_debug)
        printf("%s: Calling AFSOP_GO with cacheSetTime = %d\n", rn,
               0);
-       afsd_syscall(AFSOP_GO, 0);
+    afsd_syscall(AFSOP_GO, 0);
 
     /*
      * At this point, we have finished passing the kernel all the info
@@ -2472,7 +2550,7 @@ afsd_init(void)
 {
     struct cmd_syndesc *ts;
 
-    ts = cmd_CreateSyntax(NULL, mainproc, NULL, 0, "start AFS");
+    ts = cmd_CreateSyntax(NULL, NULL, NULL, 0, "start AFS");
 
     /* 0 - 10 */
     cmd_AddParmAtOffset(ts, OPT_blocks, "-blocks", CMD_SINGLE,
@@ -2542,7 +2620,7 @@ afsd_init(void)
                        CMD_OPTIONAL, "Do not mount AFS");
     cmd_AddParmAtOffset(ts, OPT_backuptree, "-backuptree", CMD_FLAG,
                        CMD_OPTIONAL,
-                       "Prefer backup volumes for mointpoints in backup "
+                       "Prefer backup volumes for mountpoints in backup "
                        "volumes");
     cmd_AddParmAtOffset(ts, OPT_rxbind, "-rxbind", CMD_FLAG,
                        CMD_OPTIONAL,
@@ -2566,12 +2644,31 @@ afsd_init(void)
                        CMD_OPTIONAL,
                        "Set the maximum number of UDP fragments Rx should "
                        "send/receive per Rx packet");
+    cmd_AddParmAtOffset(ts, OPT_inumcalc, "-inumcalc", CMD_SINGLE, CMD_OPTIONAL,
+                       "Set inode number calculation method");
+    cmd_AddParmAtOffset(ts, OPT_volume_ttl, "-volume-ttl", CMD_SINGLE,
+                       CMD_OPTIONAL,
+                       "Set the vldb cache timeout value in seconds.");
 }
 
+/**
+ * Parse and check the command line options.
+ *
+ * @note The -shutdown command is handled in CheckOptions().
+ */
 int
 afsd_parse(int argc, char **argv)
 {
-    return cmd_Dispatch(argc, argv);
+    struct cmd_syndesc *ts = NULL;
+    int code;
+
+    code = cmd_Parse(argc, argv, &ts);
+    if (code) {
+       return code;
+    }
+    code = CheckOptions(ts);
+    cmd_FreeOptions(&ts);
+    return code;
 }
 
 /**
@@ -2631,6 +2728,8 @@ afsd_syscall_populate(struct afsd_syscall_args *args, int syscall, va_list ap)
     case AFSOP_BUCKETPCT:
     case AFSOP_GO:
     case AFSOP_SET_RMTSYS_FLAG:
+    case AFSOP_SET_INUMCALC:
+    case AFSOP_SET_VOLUME_TTL:
        params[0] = CAST_SYSCALL_PARAM((va_arg(ap, int)));
        break;
     case AFSOP_SET_THISCELL: