viced: Enforce lwps limit for -L
[openafs.git] / src / viced / viced.c
index d1fcb18..50a259a 100644 (file)
@@ -21,6 +21,8 @@
 #include <afsconfig.h>
 #include <afs/param.h>
 
+#include <afs/procmgmt.h>
+#include <roken.h>
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -198,6 +200,8 @@ int udpBufSize = 0;         /* UDP buffer size for receive */
 int sendBufSize = 16384;       /* send buffer size */
 int saneacls = 0;              /* Sane ACLs Flag */
 static int unsafe_attach = 0;   /* avoid inUse check on vol attach? */
+static int offline_timeout = -1; /* -offline-timeout option */
+static int offline_shutdown_timeout = -1; /* -offline-shutdown-timeout option */
 
 struct timeval tp;
 
@@ -966,6 +970,8 @@ FlagMsg(void)
     fputs("[-abortthreshold <abort threshold>] ", stdout);
     fputs("[-nojumbo (disable jumbogram network packets - deprecated)] ", stdout);
     fputs("[-jumbo (enable jumbogram network packets)] ", stdout);
+    fputs("[-offline-timeout <client RX timeout for offlining volumes>]", stdout);
+    fputs("[-offline-shutdown-timeout <RX timeout for offlining volumes during shutdown>]", stdout);
 /*   fputs("[-enable_peer_stats] ", stdout); */
 /*   fputs("[-enable_process_stats] ", stdout); */
     fputs("[-help]\n", stdout);
@@ -1083,6 +1089,7 @@ ParseArgs(int argc, char *argv[])
     int Sawbusy = 0;
     int i;
     int bufSize = 0;           /* temp variable to read in udp socket buf size */
+    int lwps_max;
     char *auditFileName = NULL;
 
     for (i = 1; i < argc; i++) {
@@ -1110,18 +1117,12 @@ ParseArgs(int argc, char *argv[])
        } else if (!strcmp(argv[i], "-S")) {
            SawS = 1;
        } else if (!strcmp(argv[i], "-p")) {
-           int lwps_max =
-               max_fileserver_thread() - FILESERVER_HELPER_THREADS;
            Sawlwps = 1;
             if ((i + 1) >= argc) {
                fprintf(stderr, "missing argument for -p\n");
                return -1;
            }
            lwps = atoi(argv[++i]);
-           if (lwps > lwps_max)
-               lwps = lwps_max;
-           else if (lwps < 6)
-               lwps = 6;
        } else if (!strcmp(argv[i], "-b")) {
            Sawbufs = 1;
             if ((i + 1) >= argc) {
@@ -1443,6 +1444,45 @@ ParseArgs(int argc, char *argv[])
        else if (strcmp(argv[i], "-saneacls") == 0) {
            saneacls = 1;
        }
+       else if (strcmp(argv[i], "-offline-timeout") == 0) {
+           if (i + 1 >= argc) {
+               printf("You have to specify -offline-timeout <integer>\n");
+               return -1;
+           }
+           offline_timeout = atoi(argv[++i]);
+#ifndef AFS_PTHREAD_ENV
+           if (offline_timeout != -1) {
+               printf("The only valid -offline-timeout value for the LWP "
+                      "fileserver is -1\n");
+               return -1;
+           }
+#endif /* AFS_PTHREAD_ENV */
+           if (offline_timeout < -1) {
+               printf("Invalid -offline-timeout value %s; the only valid "
+                      "negative value is -1\n", argv[i]);
+               return -1;
+           }
+       }
+       else if (strcmp(argv[i], "-offline-shutdown-timeout") == 0) {
+           if (i + 1 >= argc) {
+               printf("You have to specify -offline-shutdown-timeout "
+                      "<integer>\n");
+               return -1;
+           }
+           offline_shutdown_timeout = atoi(argv[++i]);
+#ifndef AFS_PTHREAD_ENV
+           if (offline_shutdown_timeout != -1) {
+               printf("The only valid -offline-shutdown-timeout value for the "
+                      "LWP fileserver is -1\n");
+               return -1;
+           }
+#endif /* AFS_PTHREAD_ENV */
+           if (offline_shutdown_timeout < -1) {
+               printf("Invalid -offline-timeout value %s; the only valid "
+                      "negative value is -1\n", argv[i]);
+               return -1;
+           }
+       }
        else {
            return (-1);
        }
@@ -1488,6 +1528,12 @@ ParseArgs(int argc, char *argv[])
     if (auditFileName)
        osi_audit_file(auditFileName);
 
+    lwps_max = max_fileserver_thread() - FILESERVER_HELPER_THREADS;
+    if (lwps > lwps_max)
+       lwps = lwps_max;
+    else if (lwps < 6)
+       lwps = 6;
+
     return (0);
 
 }                              /*ParseArgs */
@@ -2252,6 +2298,18 @@ main(int argc, char *argv[])
     opts.nSmallVnodes = nSmallVns;
     opts.volcache = volcache;
     opts.unsafe_attach = unsafe_attach;
+    if (offline_timeout != -1) {
+       opts.interrupt_rxcall = rx_InterruptCall;
+       opts.offline_timeout = offline_timeout;
+    }
+    if (offline_shutdown_timeout == -1) {
+       /* default to -offline-timeout, if shutdown-specific timeout is not
+        * specified */
+       opts.offline_shutdown_timeout = offline_timeout;
+    } else {
+       opts.interrupt_rxcall = rx_InterruptCall;
+       opts.offline_shutdown_timeout = offline_shutdown_timeout;
+    }
 
     if (VInitVolumePackage2(fileServer, &opts)) {
        ViceLog(0,
@@ -2321,9 +2379,6 @@ main(int argc, char *argv[])
 
     FT_GetTimeOfDay(&tp, 0);
 
-    ViceLog(0, ("File server has started at %s",
-               afs_ctime((time_t *)&(tp.tv_sec), tbuffer, sizeof(tbuffer))));
-
     /*
      * Figure out the FileServer's name and primary address.
      */