viced-set-fssync-threadid-20030304
[openafs.git] / src / viced / viced.c
index 3fc8ef0..c209c6e 100644 (file)
@@ -85,6 +85,9 @@ RCSID("$Header$");
 #endif
 #include "viced.h"
 #include "host.h"
+#ifdef AFS_PTHREAD_ENV
+#include "softsig.h"
+#endif
 #if defined(AFS_SGI_ENV)
 #include "sys/schedctl.h"
 #include "sys/lock.h"
@@ -144,6 +147,7 @@ struct afs_PerfStats afs_perfstats;
 extern int     LogLevel;
 extern int     Statistics;
 
+int     busyonrst = 1;
 int     timeout = 30;
 int    SawSpare;
 int    SawPctSpare;
@@ -173,6 +177,7 @@ int     lwps = 9;           /* 6 */
 int     buffs = 90;            /* 70 */
 int    novbc = 0;              /* Enable Volume Break calls */
 int     busy_threshold = 600;
+int    abort_threshold = 10;
 int    udpBufSize = 0;         /* UDP buffer size for receive*/
 int    sendBufSize = 16384;    /* send buffer size */
 
@@ -235,22 +240,34 @@ int fs_rxstat_userok(struct rx_call *call)
 
 static void ResetCheckSignal(void)
 {
-#ifdef AFS_HPUX_ENV
-    signal(SIGPOLL, CheckSignal_Signal);
+    int signo;
+
+#if defined(AFS_HPUX_ENV)
+    signo = SIGPOLL;
 #else
-#ifdef AFS_NT40_ENV
-    signal(SIGUSR2, CheckSignal_Signal);
+#if defined(AFS_NT40_ENV)
+    signo = SIGUSR2;
 #else
-    signal(SIGXCPU, CheckSignal_Signal);
+    signo = SIGXCPU;
 #endif
 #endif
+
+#if defined(AFS_PTHREAD_ENV)
+    softsig_signal(signo, CheckSignal_Signal);
+#else
+    signal(signo, CheckSignal_Signal);
+#endif
 }
 
 static void ResetCheckDescriptors(void)
 {
 #ifndef AFS_NT40_ENV
+#if defined(AFS_PTHREAD_ENV)
+    softsig_signal(SIGTERM, CheckDescriptors_Signal);
+#else
     signal(SIGTERM, CheckDescriptors_Signal);
 #endif
+#endif
 }
 
 
@@ -319,6 +336,18 @@ CheckAdminName()
 } /*CheckAdminName*/
 
 
+static void setThreadId(char *s)
+{
+#ifdef AFS_PTHREAD_ENV
+    /* set our 'thread-id' so that the host hold table works */
+    MUTEX_ENTER(&rx_stats_mutex);   /* protects rxi_pthread_hinum */ 
+    ++rxi_pthread_hinum;
+    pthread_setspecific(rx_thread_id_key, (void *)rxi_pthread_hinum);
+    MUTEX_EXIT(&rx_stats_mutex);
+    ViceLog(0,("Set thread id %d for '%s'\n", pthread_getspecific(rx_thread_id_key), s));
+#endif
+}
+
 /* This LWP does things roughly every 5 minutes */
 static void FiveMinuteCheckLWP()
 {
@@ -326,6 +355,7 @@ static void FiveMinuteCheckLWP()
     char tbuffer[32];
 
     ViceLog(1, ("Starting five minute check process\n"));
+    setThreadId("FiveMinuteCheckLWP");
     while (1) {
 #ifdef AFS_PTHREAD_ENV
        sleep(fiveminutes);
@@ -367,6 +397,7 @@ static void FiveMinuteCheckLWP()
 static void HostCheckLWP()
 {
     ViceLog(1, ("Starting Host check process\n"));
+    setThreadId("HostCheckLWP");
     while(1) {
 #ifdef AFS_PTHREAD_ENV
        sleep(fiveminutes);
@@ -390,6 +421,8 @@ static FsyncCheckLWP()
 #endif
     ViceLog(1, ("Starting fsync check process\n"));
 
+    setThreadId("FsyncCheckLWP");
+
 #ifdef AFS_PTHREAD_ENV
     assert(pthread_cond_init(&fsync_cond, NULL) == 0);
     assert(pthread_mutex_init(&fsync_glock_mutex, NULL) == 0);
@@ -619,6 +652,7 @@ static void FlagMsg()
     strcat(buffer, "[-readonly (read-only file server)] ");
     strcat(buffer, "[-hr <number of hours between refreshing the host cps>] ");
     strcat(buffer, "[-busyat <redirect clients when queue > n>] ");
+    strcat(buffer, "[-nobusy <no VBUSY before a volume is attached>] ");
     strcat(buffer, "[-rxpck <number of rx extra packets>] ");
     strcat(buffer, "[-rxdbg (enable rx debugging)] ");
     strcat(buffer, "[-rxdbge (enable rxevent debugging)] ");
@@ -792,6 +826,10 @@ static int ParseArgs(int argc, char *argv[])
                nSmallVns = atoi(argv[++i]);
            }
        else    
+           if (!strcmp(argv[i], "-abortthreshold")) {
+               abort_threshold = atoi(argv[++i]);
+           }
+       else    
            if (!strcmp(argv[i], "-k"))
                stack = atoi(argv[++i]);
 #if defined(AFS_SGI_ENV)
@@ -848,7 +886,10 @@ static int ParseArgs(int argc, char *argv[])
                           busy_threshold);
                    Sawbusy = 0;
                }
-           }
+             }
+           else
+             if (!strcmp(argv[i], "-nobusy")) 
+               busyonrst=0;
 #ifdef AFS_AIX32_ENV
        else
            if (!strcmp(argv[i], "-m")) {
@@ -958,7 +999,8 @@ static int ParseArgs(int argc, char *argv[])
 static void NewParms(int initializing)
 {
     static struct stat sbuf;
-    register int i, fd;
+    register afs_offs_t i;
+    register int fd;
     char *parms;
     char *argv[MAXPARMS];
     register int argc;
@@ -1246,25 +1288,7 @@ Do_VLRegisterRPC() {
     return 0;
 }
 
-#if 0
-static int AddrsEqual(cnt, addr1, addr2) 
-    int cnt;
-    afs_int32 *addr1, *addr2; 
-{
-    register int i, j;
-
-    for (i = 0; i < cnt; i++) {
-       for (j = 0; j < cnt; j++) {
-           if (addr1[i] == addr2[j]) break;
-       }
-       if (j == cnt) return 0;
-    }
-    return 1;
-}
-#endif
-
-afs_int32 
-InitVL() {
+afs_int32 InitVL() {
     int (*old)();
     afs_int32 code;
     afs_int32 cnt, i;
@@ -1337,7 +1361,6 @@ main(int argc, char * argv[])
 #ifdef AFS_PTHREAD_ENV
     pthread_t parentPid, serverPid;
     pthread_attr_t tattr;
-    AFS_SIGSET_DECL;
 #else /* AFS_PTHREAD_ENV */
     PROCESS parentPid, serverPid;
 #endif /* AFS_PTHREAD_ENV */
@@ -1410,6 +1433,11 @@ main(int argc, char * argv[])
     ViceLog(0, ("File server starting\n"));
 #endif
 
+#if defined(AFS_PTHREAD_ENV)
+    /* initialize the pthread soft signal handler thread */
+    softsig_init();
+#endif
+
     /* install signal handlers for controlling the fileserver process */
     ResetCheckSignal();  /* set CheckSignal_Signal() sig handler */
     ResetCheckDescriptors();  /* set CheckDescriptors_Signal() sig handler */
@@ -1487,8 +1515,8 @@ main(int argc, char * argv[])
     rx_extraPackets = rxpackets;
     rx_extraQuota = 4; /* for outgoing prserver calls from R threads */
     rx_SetBusyThreshold(busy_threshold, VBUSY);
-    rx_SetCallAbortThreshold(10);
-    rx_SetConnAbortThreshold(10);
+    rx_SetCallAbortThreshold(abort_threshold);
+    rx_SetConnAbortThreshold(abort_threshold);
     stackSize = lwps * 4000;
     if (stackSize < 32000)
        stackSize = 32000;
@@ -1609,12 +1637,10 @@ main(int argc, char * argv[])
 #ifdef AFS_PTHREAD_ENV
     assert(pthread_attr_init(&tattr) == 0);
     assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
-    /* Block signals in the threads */
-    AFS_SIGSET_CLEAR();
+
     assert(pthread_create(&serverPid, &tattr, (void *)FiveMinuteCheckLWP, &fiveminutes) == 0);
     assert(pthread_create(&serverPid, &tattr, (void *)HostCheckLWP, &fiveminutes) == 0);
     assert(pthread_create(&serverPid, &tattr, (void *)FsyncCheckLWP, &fiveminutes) == 0);
-    AFS_SIGSET_RESTORE();
 #else /* AFS_PTHREAD_ENV */
     assert(LWP_CreateProcess(FiveMinuteCheckLWP, stack*1024, LWP_MAX_PRIORITY - 2,
                             (void *) &fiveminutes, "FiveMinuteChecks", &serverPid) == LWP_SUCCESS);
@@ -1658,8 +1684,14 @@ main(int argc, char * argv[])
                   FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
     }
 
-    /* Install handler to catch the shutdown signal */
-    signal(SIGQUIT, ShutDown_Signal); /* bosserver assumes SIGQUIT shutdown */
+    /* Install handler to catch the shutdown signal;
+     * bosserver assumes SIGQUIT shutdown
+     */
+#if defined(AFS_PTHREAD_ENV)
+    softsig_signal(SIGQUIT, ShutDown_Signal);
+#else
+    signal(SIGQUIT, ShutDown_Signal);
+#endif
 
     ViceLog(0,("File Server started %s",
               afs_ctime(&tp.tv_sec, tbuffer, sizeof(tbuffer))));