2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 /* viced.c - File Server main loop */
14 /* Function - This routine has the initialization code for */
17 /* ********************************************************************** */
19 #include <afsconfig.h>
20 #include <afs/param.h>
28 #include <sys/types.h>
29 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
35 #include <WINNT/afsevent.h>
38 #include <netinet/in.h>
40 #include <unistd.h> /* sysconf() */
52 #endif /* ITIMER_REAL */
53 #include <sys/resource.h>
54 #endif /* AFS_NT40_ENV */
59 #ifdef AFS_PTHREAD_ENV
61 #else /* AFS_PTHREAD_ENV */
62 #include <afs/assert.h>
63 #endif /* AFS_PTHREAD_ENV */
66 #include <afs/ptclient.h>
67 #include <afs/afsint.h>
68 #include <afs/vldbint.h>
69 #include <afs/errors.h>
70 #include <afs/ihandle.h>
71 #include <afs/vnode.h>
72 #include <afs/volume.h>
74 #include <afs/cellconfig.h>
76 #include <afs/prs_fs.h>
80 #include <afs/afs_args.h>
81 #include <afs/vlserver.h>
82 #include <afs/afsutil.h>
83 #include <afs/fileutil.h>
85 #include <afs/netutils.h>
89 #ifdef AFS_PTHREAD_ENV
92 #if defined(AFS_SGI_ENV)
93 #include "sys/schedctl.h"
96 #include <rx/rx_globals.h>
99 #define afs_stat stat64
100 #define afs_fstat fstat64
101 #define afs_open open64
102 #define afs_fopen fopen64
103 #else /* !O_LARGEFILE */
104 #define afs_stat stat
105 #define afs_fstat fstat
106 #define afs_open open
107 #define afs_fopen fopen
108 #endif /* !O_LARGEFILE */
110 extern int BreakVolumeCallBacks(), InitCallBack();
111 extern int BreakVolumeCallBacks(), InitCallBack(), BreakLaterCallBacks();
112 extern int BreakVolumeCallBacksLater();
113 extern int LogLevel, etext;
114 extern afs_int32 BlocksSpare, PctSpare;
117 static void ClearXStatValues(), NewParms(), PrintCounters();
118 static void ResetCheckDescriptors(void), ResetCheckSignal(void);
119 static void CheckSignal(void);
120 extern int GetKeysFromToken();
121 extern int RXAFS_ExecuteRequest();
122 extern int RXSTATS_ExecuteRequest();
123 afs_int32 Do_VLRegisterRPC();
125 int eventlog = 0, rxlog = 0;
127 FILE *console = NULL;
129 #ifdef AFS_PTHREAD_ENV
130 pthread_mutex_t fsync_glock_mutex;
131 pthread_cond_t fsync_cond;
134 #endif /* AFS_PTHREAD_ENV */
137 #define AFS_QUIETFS_ENV 1
138 #define NT_OPEN_MAX 1024 /* This is an arbitrary no. we came up with for
139 * now. We hope this will be replaced by a more
140 * intelligent estimate later. */
143 int SystemId; /* ViceID of "Administrators" */
144 int SystemAnyUser; /* Viceid of "System:AnyUser" */
145 prlist SystemAnyUserCPS; /* CPS for "system:AnyUser */
146 int AnonymousID = 0; /* ViceId of "Anonymous" */
147 prlist AnonCPS; /* CPS for "Anonymous" */
149 struct afsconf_dir *confDir; /* Configuration dir object */
151 int restartMode = RESTART_ORDINARY;
153 int Testing = 0; /* for ListViceInodes */
156 * Home for the performance statistics.
158 struct afs_PerfStats afs_perfstats;
161 extern int Statistics;
169 int rxJumbograms = 1; /* default is to send and receive jumbograms. */
170 afs_int32 implicitAdminRights = PRSFS_LOOKUP; /* The ADMINISTER right is
172 afs_int32 readonlyServer = 0;
175 int stackSize = 24000;
176 int fiveminutes = 300; /* 5 minutes. Change this for debugging only */
177 int CurrentConnections = 0;
178 int hostaclRefresh = 7200; /* refresh host clients' acls every 2 hrs */
179 #if defined(AFS_SGI_ENV)
184 int rxpackets = 150; /* 100 */
185 int nSmallVns = 400; /* 200 */
186 int large = 400; /* 200 */
187 int volcache = 400; /* 400 */
188 int numberofcbs = 60000; /* 60000 */
189 int lwps = 9; /* 6 */
190 int buffs = 90; /* 70 */
191 int novbc = 0; /* Enable Volume Break calls */
192 int busy_threshold = 600;
193 int abort_threshold = 10;
194 int udpBufSize = 0; /* UDP buffer size for receive */
195 int sendBufSize = 16384; /* send buffer size */
200 * FileServer's name and IP address, both network byte order and
203 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
205 char FS_HostName[128] = "localhost";
206 afs_uint32 FS_HostAddr_NBO;
207 afs_uint32 FS_HostAddr_HBO;
208 afs_uint32 FS_HostAddrs[ADDRSPERSITE], FS_HostAddr_cnt = 0, FS_registered = 0;
209 /* All addresses in FS_HostAddrs are in NBO */
212 static void FlagMsg();
215 * Home for the performance statistics.
223 struct afs_stat status;
224 register int tsize = getdtablesize();
226 for (i = 0; i < tsize; i++) {
227 if (afs_fstat(i, &status) != -1) {
228 printf("%d: dev %x, inode %u, length %u, type/mode %x\n", i,
229 status.st_dev, status.st_ino, status.st_size,
234 ResetCheckDescriptors();
236 } /*CheckDescriptors */
239 #ifdef AFS_PTHREAD_ENV
241 CheckSignal_Signal(x)
253 CheckDescriptors_Signal(x)
257 #else /* AFS_PTHREAD_ENV */
259 CheckSignal_Signal(x)
261 IOMGR_SoftSig(CheckSignal, 0);
267 IOMGR_SoftSig(ShutDown, 0);
271 CheckDescriptors_Signal(x)
273 IOMGR_SoftSig(CheckDescriptors, 0);
275 #endif /* AFS_PTHREAD_ENV */
277 /* check whether caller is authorized to manage RX statistics */
279 fs_rxstat_userok(struct rx_call *call)
281 return afsconf_SuperUser(confDir, call, NULL);
285 ResetCheckSignal(void)
289 #if defined(AFS_HPUX_ENV)
292 #if defined(AFS_NT40_ENV)
299 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
300 softsig_signal(signo, CheckSignal_Signal);
302 signal(signo, CheckSignal_Signal);
307 ResetCheckDescriptors(void)
310 #if defined(AFS_PTHREAD_ENV)
311 softsig_signal(SIGTERM, CheckDescriptors_Signal);
313 (void)signal(SIGTERM, CheckDescriptors_Signal);
318 #if defined(AFS_PTHREAD_ENV)
322 return pthread_getspecific(rx_thread_id_key);
326 /* proc called by rxkad module to get a key */
328 get_key(char *arock, register afs_int32 akvno, char *akey)
331 static struct afsconf_key tkey;
332 register afs_int32 code;
335 ViceLog(0, ("conf dir not open\n"));
338 code = afsconf_GetKey(confDir, akvno, tkey.key);
341 memcpy(akey, tkey.key, sizeof(tkey.key));
348 viced_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
353 #ifndef AFS_LINUX20_ENV
354 old = (void (*)())signal(SIGSYS, SIG_IGN);
356 rcode = syscall(AFS_SYSCALL, 28 /* AFSCALL_CALL */ , a3, a4, a5);
357 #ifndef AFS_LINUX20_ENV
365 #if !defined(AFS_NT40_ENV)
366 #include "AFS_component_version_number.c"
367 #endif /* !AFS_NT40_ENV */
369 #define MAXADMINNAME 64
370 char adminName[MAXADMINNAME];
376 struct afs_stat status;
378 if ((afs_stat("/AdminName", &status)) || /* if file does not exist */
379 (status.st_size <= 0) || /* or it is too short */
380 (status.st_size >= (MAXADMINNAME)) || /* or it is too long */
381 !(fd = afs_open("/AdminName", O_RDONLY, 0))) { /* or the open fails */
382 strcpy(adminName, "System:Administrators"); /* use the default name */
384 (void)read(fd, adminName, status.st_size); /* use name from the file */
387 close(fd); /* close fd if it was opened */
389 } /*CheckAdminName */
395 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
396 /* set our 'thread-id' so that the host hold table works */
397 MUTEX_ENTER(&rx_stats_mutex); /* protects rxi_pthread_hinum */
399 pthread_setspecific(rx_thread_id_key, (void *)rxi_pthread_hinum);
400 MUTEX_EXIT(&rx_stats_mutex);
402 ("Set thread id %d for '%s'\n",
403 pthread_getspecific(rx_thread_id_key), s));
407 /* This LWP does things roughly every 5 minutes */
414 ViceLog(1, ("Starting five minute check process\n"));
415 setThreadId("FiveMinuteCheckLWP");
417 #ifdef AFS_PTHREAD_ENV
419 #else /* AFS_PTHREAD_ENV */
420 IOMGR_Sleep(fiveminutes);
421 #endif /* AFS_PTHREAD_ENV */
423 /* close the log so it can be removed */
424 ReOpenLog(AFSDIR_SERVER_FILELOG_FILEPATH); /* don't trunc, just append */
425 ViceLog(2, ("Cleaning up timed out callbacks\n"));
426 if (CleanupTimedOutCallBacks())
427 ViceLog(5, ("Timed out callbacks deleted\n"));
428 ViceLog(2, ("Set disk usage statistics\n"));
430 if (FS_registered == 1)
432 /* Force wakeup in case we missed something; pthreads does timedwait */
433 #ifndef AFS_PTHREAD_ENV
434 LWP_NoYieldSignal(fsync_wait);
436 if (printBanner && (++msg & 1)) { /* Every 10 minutes */
437 time_t now = FT_ApproxTime();
438 if (console != NULL) {
439 #ifndef AFS_QUIETFS_ENV
440 fprintf(console, "File server is running at %s\r",
441 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
442 #endif /* AFS_QUIETFS_ENV */
444 ("File server is running at %s\n",
445 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
449 } /*FiveMinuteCheckLWP */
452 /* This LWP does host checks every 5 minutes: it should not be used for
453 * other 5 minute activities because it may be delayed by timeouts when
454 * it probes the workstations
459 ViceLog(1, ("Starting Host check process\n"));
460 setThreadId("HostCheckLWP");
462 #ifdef AFS_PTHREAD_ENV
464 #else /* AFS_PTHREAD_ENV */
465 IOMGR_Sleep(fiveminutes);
466 #endif /* AFS_PTHREAD_ENV */
467 ViceLog(2, ("Checking for dead venii & clients\n"));
472 /* This LWP does fsync checks every 5 minutes: it should not be used for
473 * other 5 minute activities because it may be delayed by timeouts when
474 * it probes the workstations
480 #ifdef AFS_PTHREAD_ENV
481 struct timespec fsync_next;
483 ViceLog(1, ("Starting fsync check process\n"));
485 setThreadId("FsyncCheckLWP");
487 #ifdef AFS_PTHREAD_ENV
488 assert(pthread_cond_init(&fsync_cond, NULL) == 0);
489 assert(pthread_mutex_init(&fsync_glock_mutex, NULL) == 0);
494 #ifdef AFS_PTHREAD_ENV
495 /* rounding is fine */
496 fsync_next.tv_nsec = 0;
497 fsync_next.tv_sec = time(0) + fiveminutes;
500 pthread_cond_timedwait(&fsync_cond, &fsync_glock_mutex,
502 if (code != 0 && code != ETIMEDOUT)
503 ViceLog(0, ("pthread_cond_timedwait returned %d\n", code));
504 #else /* AFS_PTHREAD_ENV */
505 if ((code = LWP_WaitProcess(fsync_wait)) != LWP_SUCCESS)
506 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
507 #endif /* AFS_PTHREAD_ENV */
509 ViceLog(2, ("Checking for fsync events\n"));
511 code = BreakLaterCallBacks();
516 /*------------------------------------------------------------------------
517 * PRIVATE ClearXStatValues
520 * Initialize all of the values collected via the xstat
530 * Must be called during File Server initialization.
534 *------------------------------------------------------------------------*/
538 { /*ClearXStatValues */
540 struct fs_stats_opTimingData *opTimeP; /*Ptr to timing struct */
541 struct fs_stats_xferData *opXferP; /*Ptr to xfer struct */
542 int i; /*Loop counter */
545 * Zero all xstat-related structures.
547 memset((char *)(&afs_perfstats), 0, sizeof(struct afs_PerfStats));
548 #if FS_STATS_DETAILED
549 memset((char *)(&afs_FullPerfStats), 0,
550 sizeof(struct fs_stats_FullPerfStats));
553 * That's not enough. We have to set reasonable minima for
554 * time and xfer values in the detailed stats.
556 opTimeP = &(afs_FullPerfStats.det.rpcOpTimes[0]);
557 for (i = 0; i < FS_STATS_NUM_RPC_OPS; i++, opTimeP++)
558 opTimeP->minTime.tv_sec = 999999;
560 opXferP = &(afs_FullPerfStats.det.xferOpTimes[0]);
561 for (i = 0; i < FS_STATS_NUM_XFER_OPS; i++, opXferP++) {
562 opXferP->minTime.tv_sec = 999999;
563 opXferP->minBytes = 999999999;
567 * There's more. We have to set our unique system identifier, as
568 * declared in param.h. If such a thing is not defined, we bitch
569 * and declare ourselves to be an unknown system type.
572 afs_perfstats.sysname_ID = SYS_NAME_ID;
575 ViceLog(0, ("Sys name ID constant not defined in param.h!!\n"));
576 ViceLog(0, ("[Choosing ``undefined'' sys name ID.\n"));
578 afs_perfstats.sysname_ID = SYS_NAME_ID_UNDEFINED;
579 #endif /* SYS_NAME_ID */
582 } /*ClearXStatValues */
588 int dirbuff, dircall, dirio;
590 int workstations, activeworkstations, delworkstations;
594 TM_GetTimeOfDay(&tpl, 0);
597 ("Vice was last started at %s\n",
598 afs_ctime(&StartTime, tbuffer, sizeof(tbuffer))));
602 DStat(&dirbuff, &dircall, &dirio);
604 ("With %d directory buffers; %d reads resulted in %d read I/Os\n",
605 dirbuff, dircall, dirio));
606 rx_PrintStats(stderr);
608 PrintCallBackStats();
610 processSize = -1; /* TODO: */
612 processSize = (int)((long)sbrk(0) >> 10);
615 ("There are %d connections, process size %d\n",
616 CurrentConnections, processSize));
617 h_GetWorkStats(&workstations, &activeworkstations, &delworkstations,
618 tpl.tv_sec - 15 * 60);
620 ("There are %d workstations, %d are active (req in < 15 mins), %d marked \"down\"\n",
621 workstations, activeworkstations, delworkstations));
631 if (FS_registered > 0) {
633 * We have proper ip addresses; tell the vlserver what we got; the following
634 * routine will do the proper reporting for us
647 ShutDownAndCore(int dopanic)
649 time_t now = time(0);
653 ("Shutting down file server at %s",
654 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
656 ViceLog(0, ("ABNORMAL SHUTDOWN, see core file.\n"));
657 #ifndef AFS_QUIETFS_ENV
658 if (console != NULL) {
659 fprintf(console, "File server restart/shutdown received at %s\r",
660 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
667 /* do not allows new reqests to be served from now on, all new requests
668 * are returned with an error code of RX_RESTARTING ( transient failure ) */
669 rx_SetRxTranquil(); /* dhruba */
673 rx_PrintStats(debugFile);
676 if (console != NULL) {
679 #ifndef AFS_QUIETFS_ENV
680 fprintf(console, "File server has terminated abnormally at %s\r",
681 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
684 ("File server has terminated abnormally at %s\n",
685 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
687 #ifndef AFS_QUIETFS_ENV
688 fprintf(console, "File server has terminated normally at %s\r",
689 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
692 ("File server has terminated normally at %s\n",
693 afs_ctime(&now, tbuffer, sizeof(tbuffer))));
703 { /* backward compatibility */
704 ShutDownAndCore(DONTPANIC);
713 /* default supports help flag */
715 strcpy(buffer, "Usage: fileserver ");
716 strcpy(buffer, "[-auditlog <log path>] ");
717 strcat(buffer, "[-d <debug level>] ");
718 strcat(buffer, "[-p <number of processes>] ");
719 strcat(buffer, "[-spare <number of spare blocks>] ");
720 strcat(buffer, "[-pctspare <percentage spare>] ");
721 strcat(buffer, "[-b <buffers>] ");
722 strcat(buffer, "[-l <large vnodes>] ");
723 strcat(buffer, "[-s <small vnodes>] ");
724 strcat(buffer, "[-vc <volume cachesize>] ");
725 strcat(buffer, "[-w <call back wait interval>] ");
726 strcat(buffer, "[-cb <number of call backs>] ");
727 strcat(buffer, "[-banner (print banner every 10 minutes)] ");
728 strcat(buffer, "[-novbc (whole volume cbs disabled)] ");
729 strcat(buffer, "[-implicit <admin mode bits: rlidwka>] ");
730 strcat(buffer, "[-readonly (read-only file server)] ");
732 "[-hr <number of hours between refreshing the host cps>] ");
733 strcat(buffer, "[-busyat <redirect clients when queue > n>] ");
734 strcat(buffer, "[-nobusy <no VBUSY before a volume is attached>] ");
735 strcat(buffer, "[-rxpck <number of rx extra packets>] ");
736 strcat(buffer, "[-rxdbg (enable rx debugging)] ");
737 strcat(buffer, "[-rxdbge (enable rxevent debugging)] ");
739 strcat(buffer, "[-vattachpar <number of volume attach threads>] ");
742 strcat(buffer, "[-m <min percentage spare in partition>] ");
744 #if defined(AFS_SGI_ENV)
745 strcat(buffer, "[-lock (keep fileserver from swapping)] ");
747 strcat(buffer, "[-L (large server conf)] ");
748 strcat(buffer, "[-S (small server conf)] ");
749 strcat(buffer, "[-k <stack size>] ");
750 strcat(buffer, "[-realm <Kerberos realm name>] ");
751 strcat(buffer, "[-udpsize <size of socket buffer in bytes>] ");
752 strcat(buffer, "[-sendsize <size of send buffer in bytes>] ");
753 /* strcat(buffer, "[-enable_peer_stats] "); */
754 /* strcat(buffer, "[-enable_process_stats] "); */
755 strcat(buffer, "[-help]\n");
757 ViceLog(0, ("%s", buffer));
760 printf("%s", buffer);
767 ParseRights(char *arights)
773 if (!arights || !strcmp(arights, "")) {
774 printf("Missing list of mode bits on -implicit option\n");
777 if (!strcmp(arights, "none"))
779 else if (!strcmp(arights, "read"))
780 mode = PRSFS_READ | PRSFS_LOOKUP;
781 else if (!strcmp(arights, "write"))
783 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
784 PRSFS_WRITE | PRSFS_LOCK;
785 else if (!strcmp(arights, "all"))
787 PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
788 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
790 len = strlen(arights);
791 for (i = 0; i < len; i++) {
796 mode |= PRSFS_LOOKUP;
798 mode |= PRSFS_INSERT;
800 mode |= PRSFS_DELETE;
806 mode |= PRSFS_ADMINISTER;
824 printf("Illegal -implicit rights character '%c'.\n", tc);
833 * Limit MAX_FILESERVER_THREAD by the system limit on the number of
834 * pthreads (sysconf(_SC_THREAD_THREADS_MAX)), if applicable and
837 * AIX: sysconf() limit is real
838 * HP-UX: sysconf() limit is real
839 * IRIX: sysconf() limit is apparently NOT real -- too small
840 * DUX: sysconf() limit is apparently NOT real -- too big
841 * Linux: sysconf() limit is apparently NOT real -- too big
842 * Solaris: no sysconf() limit
845 max_fileserver_thread(void)
847 #if defined(AFS_PTHREAD_ENV)
848 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
851 ans = sysconf(_SC_THREAD_THREADS_MAX);
852 if (0 < ans && ans < MAX_FILESERVER_THREAD)
855 #endif /* defined(AFS_PTHREAD_ENV) */
856 return MAX_FILESERVER_THREAD;
860 ParseArgs(int argc, char *argv[])
862 int SawL = 0, SawS = 0, SawVC = 0;
863 int Sawrxpck = 0, Sawsmall = 0, Sawlarge = 0, Sawcbs = 0, Sawlwps =
867 int bufSize = 0; /* temp variable to read in udp socket buf size */
869 for (i = 1; i < argc; i++) {
870 if (!strcmp(argv[i], "-d")) {
871 if ((i + 1) >= argc) {
872 fprintf(stderr, "missing argument for -d\n");
875 debuglevel = atoi(argv[++i]);
876 LogLevel = debuglevel;
877 } else if (!strcmp(argv[i], "-banner")) {
879 } else if (!strcmp(argv[i], "-implicit")) {
880 if ((i + 1) >= argc) {
881 fprintf(stderr, "missing argument for -implicit\n");
884 implicitAdminRights = ParseRights(argv[++i]);
885 if (implicitAdminRights < 0)
886 return implicitAdminRights;
887 } else if (!strcmp(argv[i], "-readonly")) {
889 } else if (!strcmp(argv[i], "-L")) {
891 } else if (!strcmp(argv[i], "-S")) {
893 } else if (!strcmp(argv[i], "-p")) {
895 max_fileserver_thread() - FILESERVER_HELPER_THREADS;
897 if ((i + 1) >= argc) {
898 fprintf(stderr, "missing argument for -p\n");
901 lwps = atoi(argv[++i]);
906 } else if (!strcmp(argv[i], "-b")) {
908 if ((i + 1) >= argc) {
909 fprintf(stderr, "missing argument for -b\n");
912 buffs = atoi(argv[++i]);
913 } else if (!strcmp(argv[i], "-l")) {
915 if ((i + 1) >= argc) {
916 fprintf(stderr, "missing argument for -l\n");
919 large = atoi(argv[++i]);
920 } else if (!strcmp(argv[i], "-vc")) {
922 if ((i + 1) >= argc) {
923 fprintf(stderr, "missing argument for -vc\n");
926 volcache = atoi(argv[++i]);
927 } else if (!strcmp(argv[i], "-novbc")) {
929 } else if (!strcmp(argv[i], "-rxpck")) {
931 if ((i + 1) >= argc) {
932 fprintf(stderr, "missing argument for -rxpck\n");
935 rxpackets = atoi(argv[++i]);
936 #ifdef AFS_PTHREAD_ENV
937 } else if (!strcmp(argv[i], "-vattachpar")) {
938 if ((i + 1) >= argc) {
939 fprintf(stderr, "missing argument for -vattachpar\n");
942 vol_attach_threads = atoi(argv[++i]);
943 #endif /* AFS_PTHREAD_ENV */
944 } else if (!strcmp(argv[i], "-s")) {
946 if ((i + 1) >= argc) {
947 fprintf(stderr, "missing argument for -s\n");
950 nSmallVns = atoi(argv[++i]);
951 } else if (!strcmp(argv[i], "-abortthreshold")) {
952 if ((i + 1) >= argc) {
953 fprintf(stderr, "missing argument for -abortthreshold\n");
956 abort_threshold = atoi(argv[++i]);
957 } else if (!strcmp(argv[i], "-k")) {
958 if ((i + 1) >= argc) {
959 fprintf(stderr, "missing argument for -k\n");
962 stack = atoi(argv[++i]);
964 #if defined(AFS_SGI_ENV)
965 else if (!strcmp(argv[i], "-lock")) {
969 else if (!strcmp(argv[i], "-spare")) {
970 if ((i + 1) >= argc) {
971 fprintf(stderr, "missing argument for -spare\n");
974 BlocksSpare = atoi(argv[++i]);
976 } else if (!strcmp(argv[i], "-pctspare")) {
977 if ((i + 1) >= argc) {
978 fprintf(stderr, "missing argument for -pctspare\n");
981 PctSpare = atoi(argv[++i]);
982 BlocksSpare = 0; /* has non-zero default */
984 } else if (!strcmp(argv[i], "-w")) {
985 if ((i + 1) >= argc) {
986 fprintf(stderr, "missing argument for -w\n");
989 fiveminutes = atoi(argv[++i]);
990 } else if (!strcmp(argv[i], "-hr")) {
992 if ((i + 1) >= argc) {
993 fprintf(stderr, "missing argument for -hr\n");
996 hr = atoi(argv[++i]);
997 if ((hr < 1) || (hr > 36)) {
999 ("host acl refresh interval of %d hours is invalid; hours must be between 1 and 36\n\n",
1003 hostaclRefresh = hr * 60 * 60;
1004 } else if (!strcmp(argv[i], "-rxdbg"))
1006 else if (!strcmp(argv[i], "-rxdbge"))
1008 else if (!strcmp(argv[i], "-cb")) {
1010 if ((i + 1) >= argc) {
1011 fprintf(stderr, "missing argument for -cb\n");
1014 numberofcbs = atoi(argv[++i]);
1015 if ((numberofcbs < 10000) || (numberofcbs > 2147483647)) {
1017 ("number of cbs %d invalid; must be between 10000 and 2147483647\n",
1021 } else if (!strcmp(argv[i], "-busyat")) {
1023 if ((i + 1) >= argc) {
1024 fprintf(stderr, "missing argument for -busyat\n");
1027 busy_threshold = atoi(argv[++i]);
1028 if (busy_threshold < 10) {
1030 ("Busy threshold %d is too low, will compute default.\n",
1034 } else if (!strcmp(argv[i], "-nobusy"))
1036 #ifdef AFS_AIX32_ENV
1037 else if (!strcmp(argv[i], "-m")) {
1038 extern int aixlow_water;
1039 if ((i + 1) >= argc) {
1040 fprintf(stderr, "missing argument for -m\n");
1043 aixlow_water = atoi(argv[++i]);
1044 if ((aixlow_water < 0) || (aixlow_water > 30)) {
1045 printf("space reserved %d% invalid; must be between 0-30%\n",
1051 else if (!strcmp(argv[i], "-nojumbo")) {
1053 } else if (!strcmp(argv[i], "-realm")) {
1054 extern char local_realm[AFS_REALM_SZ];
1055 if ((i + 1) >= argc) {
1056 fprintf(stderr, "missing argument for -realm\n");
1059 if (strlen(argv[++i]) >= AFS_REALM_SZ) {
1061 ("-realm argument must contain fewer than %d characters.\n",
1065 strncpy(local_realm, argv[i], AFS_REALM_SZ);
1066 } else if (!strcmp(argv[i], "-udpsize")) {
1067 if ((i + 1) >= argc) {
1068 printf("You have to specify -udpsize <integer value>\n");
1071 bufSize = atoi(argv[++i]);
1072 if (bufSize < rx_GetMinUdpBufSize())
1074 ("Warning:udpsize %d is less than minimum %d; ignoring\n",
1075 bufSize, rx_GetMinUdpBufSize());
1077 udpBufSize = bufSize;
1078 } else if (!strcmp(argv[i], "-sendsize")) {
1079 if ((i + 1) >= argc) {
1080 printf("You have to specify -sendsize <integer value>\n");
1083 bufSize = atoi(argv[++i]);
1084 if (bufSize < 16384)
1086 ("Warning:sendsize %d is less than minimum %d; ignoring\n",
1089 sendBufSize = bufSize;
1090 } else if (!strcmp(argv[i], "-enable_peer_stats")) {
1091 rx_enablePeerRPCStats();
1092 } else if (!strcmp(argv[i], "-enable_process_stats")) {
1093 rx_enableProcessRPCStats();
1095 else if (strcmp(argv[i], "-auditlog") == 0) {
1098 char oldName[MAXPATHLEN];
1099 char *fileName = argv[++i];
1101 #ifndef AFS_NT40_ENV
1102 struct stat statbuf;
1104 if ((lstat(fileName, &statbuf) == 0)
1105 && (S_ISFIFO(statbuf.st_mode))) {
1106 flags = O_WRONLY | O_NONBLOCK;
1110 strcpy(oldName, fileName);
1111 strcat(oldName, ".old");
1112 renamefile(fileName, oldName);
1113 flags = O_WRONLY | O_TRUNC | O_CREAT;
1115 tempfd = open(fileName, flags, 0666);
1117 auditout = fdopen(tempfd, "a");
1119 osi_audit_file(auditout);
1121 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
1123 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
1125 #ifndef AFS_NT40_ENV
1126 else if (strcmp(argv[i], "-syslog") == 0) {
1127 /* set syslog logging flag */
1128 serverLogSyslog = 1;
1129 } else if (strncmp(argv[i], "-syslog=", 8) == 0) {
1130 serverLogSyslog = 1;
1131 serverLogSyslogFacility = atoi(argv[i] + 8);
1134 else if (strcmp(argv[i], "-mrafslogs") == 0) {
1135 /* set syslog logging flag */
1143 printf("Only one of -L, or -S must be specified\n");
1154 numberofcbs = 20000;
1170 numberofcbs = 64000;
1179 busy_threshold = 3 * rxpackets / 2;
1189 NewParms(int initializing)
1191 static struct afs_stat sbuf;
1194 char *argv[MAXPARMS];
1197 if (!(afs_stat("/vice/file/parms", &sbuf))) {
1198 parms = (char *)malloc(sbuf.st_size);
1201 fd = afs_open("parms", O_RDONLY, 0666);
1203 ViceLog(0, ("Open for parms failed with errno = %d\n", errno));
1207 i = read(fd, parms, sbuf.st_size);
1209 if (i != sbuf.st_size) {
1211 ViceLog(0, ("Read on parms failed with errno = %d\n", errno));
1214 ("Read on parms failed; expected %d bytes but read %d\n",
1221 for (i = 0; i < MAXPARMS; argv[i++] = 0);
1223 for (argc = i = 0; i < sbuf.st_size; i++) {
1224 if ((*(parms + i) != ' ') && (*(parms + i) != '\n')) {
1225 if (argv[argc] == 0)
1226 argv[argc] = (parms + i);
1228 *(parms + i) = '\0';
1229 if (argv[argc] != 0) {
1230 if (++argc == MAXPARMS)
1233 while ((*(parms + i + 1) == ' ')
1234 || (*(parms + i + 1) == '\n'))
1238 if (ParseArgs(argc, argv) == 0) {
1239 ViceLog(0, ("Change parameters to:"));
1241 ViceLog(0, ("Invalid parameter in:"));
1243 for (i = 0; i < argc; i++) {
1244 ViceLog(0, (" %s", argv[i]));
1248 } else if (!initializing)
1250 ("Received request to change parms but no parms file exists\n"));
1255 /* Miscellaneous routines */
1259 ViceLog(0, ("%s\n", msg));
1271 * If this fails, it's because something major is wrong, and is not
1272 * likely to be time dependent.
1274 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
1277 ("Couldn't initialize protection library; code=%d.\n", code));
1280 SystemId = SYSADMINID;
1281 SystemAnyUser = ANYUSERID;
1282 SystemAnyUserCPS.prlist_len = 0;
1283 SystemAnyUserCPS.prlist_val = NULL;
1284 AnonCPS.prlist_len = 0;
1285 AnonCPS.prlist_val = NULL;
1287 code = pr_GetCPS(SystemAnyUser, &SystemAnyUserCPS);
1290 ("Couldn't get CPS for AnyUser, will try again in 30 seconds; code=%d.\n",
1294 code = pr_GetCPS(ANONYMOUSID, &AnonCPS);
1297 ("Couldn't get Anonymous CPS, exiting; code=%d.\n",
1301 AnonymousID = ANONYMOUSID;
1304 #ifdef AFS_PTHREAD_ENV
1306 #else /* AFS_PTHREAD_ENV */
1308 #endif /* AFS_PTHREAD_ENV */
1312 struct rx_connection *serverconns[MAXSERVERS];
1313 struct ubik_client *cstruct;
1316 vl_Initialize(char *confDir)
1318 afs_int32 code, scIndex = 0, i;
1319 struct afsconf_dir *tdir;
1320 struct rx_securityClass *sc;
1321 struct afsconf_cell info;
1323 tdir = afsconf_Open(confDir);
1326 ("Could not open configuration directory (%s).\n", confDir));
1329 code = afsconf_ClientAuth(tdir, &sc, &scIndex);
1331 ViceLog(0, ("Could not get security object for localAuth\n"));
1334 code = afsconf_GetCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info);
1335 if (info.numServers > MAXSERVERS) {
1337 ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
1338 info.numServers, MAXSERVERS));
1341 for (i = 0; i < info.numServers; i++)
1343 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
1344 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
1346 code = ubik_ClientInit(serverconns, &cstruct);
1348 ViceLog(0, ("vl_Initialize: ubik client init failed.\n"));
1354 #define SYSIDMAGIC 0x88aabbcc
1355 #define SYSIDVERSION 1
1360 afs_int32 fd, nentries, i;
1361 struct versionStamp vsn;
1362 struct afs_stat status;
1365 if ((afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status))
1366 || (status.st_size <= 0)) {
1367 ViceLog(0, ("%s: doesn't exist\n", AFSDIR_SERVER_SYSID_FILEPATH));
1370 if (!(fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_RDONLY, 0))) {
1372 ("%s: can't open (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1376 if ((i = read(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1378 ("%s: Read failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1382 if (vsn.magic != SYSIDMAGIC) {
1384 ("%s: wrong magic %x (we support %x)\n",
1385 AFSDIR_SERVER_SYSID_FILEPATH, vsn.magic, SYSIDMAGIC));
1388 if (vsn.version != SYSIDVERSION) {
1390 ("%s: wrong version %d (we support %d)\n",
1391 AFSDIR_SERVER_SYSID_FILEPATH, vsn.version, SYSIDVERSION));
1395 read(fd, (char *)&uuid,
1396 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1398 ("%s: read of uuid failed (%d)\n",
1399 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1402 afs_ntohuuid(&uuid);
1405 read(fd, (char *)&nentries,
1406 sizeof(afs_int32))) != sizeof(afs_int32)) {
1408 ("%s: Read of entries failed (%d)\n",
1409 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1412 if (nentries <= 0 || nentries > ADDRSPERSITE) {
1414 ("%s: invalid num of interfaces: %d\n",
1415 AFSDIR_SERVER_SYSID_FILEPATH, nentries));
1418 FS_HostAddr_cnt = nentries;
1419 for (i = 0; i < nentries; i++) {
1420 if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1421 sizeof(afs_int32)) {
1423 ("%s: Read of addresses failed (%d)\n",
1424 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1425 FS_HostAddr_cnt = 0; /* reset it */
1437 struct versionStamp vsn;
1438 struct afs_stat status;
1441 if (!afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status)) {
1443 * File exists; keep the old one around
1445 renamefile(AFSDIR_SERVER_SYSID_FILEPATH,
1446 AFSDIR_SERVER_OLDSYSID_FILEPATH);
1448 fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_WRONLY | O_TRUNC | O_CREAT,
1452 ("%s: can't create (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1456 vsn.magic = SYSIDMAGIC;
1458 if ((i = write(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1460 ("%s: write failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1465 afs_htonuuid(&uuid);
1467 write(fd, (char *)&uuid,
1468 sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1470 ("%s: write of uuid failed (%d)\n",
1471 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1475 write(fd, (char *)&FS_HostAddr_cnt,
1476 sizeof(afs_int32))) != sizeof(afs_int32)) {
1478 ("%s: write of # of entries failed (%d)\n",
1479 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1482 for (i = 0; i < FS_HostAddr_cnt; i++) {
1483 if (write(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1484 sizeof(afs_int32)) {
1486 ("%s: write of addresses failed (%d)\n",
1487 AFSDIR_SERVER_SYSID_FILEPATH, errno));
1497 * This routine sets up the buffers for the VL_RegisterAddrs RPC. All addresses
1498 * in FS_HostAddrs[] are in NBO, while the RPC treats them as a "blob" of data
1499 * and so we need to convert each of them into HBO which is what the extra
1500 * array called FS_HostAddrs_HBO is used here.
1507 extern int VL_RegisterAddrs();
1508 afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
1511 for (i = 0; i < FS_HostAddr_cnt; i++)
1512 FS_HostAddrs_HBO[i] = ntohl(FS_HostAddrs[i]);
1513 addrs.bulkaddrs_len = FS_HostAddr_cnt;
1514 addrs.bulkaddrs_val = (afs_uint32 *) FS_HostAddrs_HBO;
1515 code = ubik_Call(VL_RegisterAddrs, cstruct, 0, &FS_HostUUID, 0, &addrs);
1517 if (code == VL_MULTIPADDR) {
1519 ("VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n"));
1521 ("VL_RegisterAddrs rpc failed; See VLLog for details\n"));
1523 } else if (code == RXGEN_OPCODE) {
1525 ("vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"));
1526 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1529 ("VL_RegisterAddrs rpc failed; will retry periodically (code=%d, err=%d)\n",
1533 FS_registered = 2; /* So we don't have to retry in the gc daemon */
1544 extern int rxi_numNetAddrs;
1545 extern afs_uint32 rxi_NetAddrs[];
1548 * If this fails, it's because something major is wrong, and is not
1549 * likely to be time dependent.
1551 code = vl_Initialize(AFSDIR_SERVER_ETC_DIRPATH);
1554 ("Couldn't initialize protection library; code=%d.\n", code));
1558 /* Read or create the sysid file and register the fileserver's
1559 * IP addresses with the vlserver.
1561 code = ReadSysIdFile();
1563 /* Need to create the file */
1564 ViceLog(0, ("Creating new SysID file\n"));
1565 if ((code = afs_uuid_create(&FS_HostUUID))) {
1566 ViceLog(0, ("Failed to create new uuid: %d\n", code));
1570 /* A good sysid file exists; inform the vlserver. If any conflicts,
1571 * we always use the latest interface available as the real truth.
1573 #ifndef AFS_NT40_ENV
1574 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
1576 * Find addresses we are supposed to register as per the netrestrict
1577 * and netinfo files (/usr/afs/local/NetInfo and
1578 * /usr/afs/local/NetRestict)
1581 afs_int32 code = parseNetFiles(FS_HostAddrs, NULL, NULL,
1582 ADDRSPERSITE, reason,
1583 AFSDIR_SERVER_NETINFO_FILEPATH,
1584 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1586 ViceLog(0, ("Can't register any valid addresses: %s\n", reason));
1589 FS_HostAddr_cnt = (afs_uint32) code;
1593 FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE);
1597 code = Do_VLRegisterRPC();
1602 main(int argc, char *argv[])
1606 struct rx_securityClass *sc[4];
1607 struct rx_service *tservice;
1608 #ifdef AFS_PTHREAD_ENV
1609 pthread_t serverPid;
1610 pthread_attr_t tattr;
1611 #else /* AFS_PTHREAD_ENV */
1612 PROCESS parentPid, serverPid;
1613 #endif /* AFS_PTHREAD_ENV */
1615 int minVnodesRequired; /* min size of vnode cache */
1616 #ifndef AFS_NT40_ENV
1617 struct rlimit rlim; /* max number of open file descriptors */
1622 #ifdef AFS_AIX32_ENV
1623 struct sigaction nsa;
1625 sigemptyset(&nsa.sa_mask);
1626 nsa.sa_handler = SIG_DFL;
1627 nsa.sa_flags = SA_FULLDUMP;
1628 sigaction(SIGABRT, &nsa, NULL);
1629 sigaction(SIGSEGV, &nsa, NULL);
1632 /* Initialize dirpaths */
1633 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1635 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1637 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
1641 #ifndef AFS_QUIETFS_ENV
1642 console = afs_fopen("/dev/console", "w");
1645 if (ParseArgs(argc, argv)) {
1649 #ifdef AFS_PTHREAD_ENV
1650 assert(pthread_mutex_init(&fileproc_glock_mutex, NULL) == 0);
1651 #endif /* AFS_PTHREAD_ENV */
1653 #ifdef AFS_SGI_VNODE_GLUE
1654 if (afs_init_kernel_config(-1) < 0) {
1656 ("Can't determine NUMA configuration, not starting fileserver.\n");
1660 confDir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1662 fprintf(stderr, "Unable to open config directory %s\n",
1663 AFSDIR_SERVER_ETC_DIRPATH);
1669 /* Open FileLog on stdout, stderr, fd 1 and fd2 (for perror), sigh. */
1670 #ifndef AFS_NT40_ENV
1671 serverLogSyslogTag = "fileserver";
1673 OpenLog(AFSDIR_SERVER_FILELOG_FILEPATH);
1676 if (SawSpare && SawPctSpare) {
1677 ViceLog(0, ("Both -spare and -pctspare specified, exiting.\n"));
1680 #ifdef AFS_SGI_XFS_IOPS_ENV
1681 ViceLog(0, ("XFS/EFS File server starting\n"));
1683 ViceLog(0, ("File server starting\n"));
1686 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1687 /* initialize the pthread soft signal handler thread */
1691 /* install signal handlers for controlling the fileserver process */
1692 ResetCheckSignal(); /* set CheckSignal_Signal() sig handler */
1693 ResetCheckDescriptors(); /* set CheckDescriptors_Signal() sig handler */
1695 #if defined(AFS_SGI_ENV)
1696 /* give this guy a non-degrading priority so help busy servers */
1697 schedctl(NDPRI, 0, NDPNORMMAX);
1701 #ifndef AFS_NT40_ENV
1702 nice(-5); /* TODO: */
1705 assert(DInit(buffs) == 0);
1708 if (afs_winsockInit() < 0) {
1709 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
1710 ViceLog(0, ("File server failed to intialize winsock.\n"));
1716 /* if we support more than 16 threads, then we better have the ability
1717 ** to keep open a large number of files simultaneously
1719 #if defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV)
1720 curLimit = OPEN_MAX; /* for pre AIX 4.2 systems */
1721 #elif defined(AFS_NT40_ENV)
1722 curLimit = NT_OPEN_MAX; /* open file descriptor limit on NT */
1725 curLimit = 0; /* the number of open file descriptors */
1726 code = getrlimit(RLIMIT_NOFILE, &rlim);
1728 curLimit = rlim.rlim_cur;
1729 rlim.rlim_cur = rlim.rlim_max;
1730 code = setrlimit(RLIMIT_NOFILE, &rlim);
1732 curLimit = rlim.rlim_max;
1735 ViceLog(0, ("Failed to increase open file limit, using default\n"));
1737 #endif /* defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV) */
1739 curLimit -= 32; /* leave a slack of 32 file descriptors */
1740 if (lwps > curLimit) {
1744 lwps = 16; /* default to a maximum of 16 threads */
1746 ("The system supports a max of %d open files and we are starting %d threads\n",
1749 #ifndef AFS_PTHREAD_ENV
1750 assert(LWP_InitializeProcessSupport(LWP_MAX_PRIORITY - 2, &parentPid) ==
1752 #endif /* !AFS_PTHREAD_ENV */
1754 /* Initialize volume support */
1756 V_BreakVolumeCallbacks = BreakVolumeCallBacksLater;
1759 #ifdef AFS_PTHREAD_ENV
1760 SetLogThreadNumProgram( threadNum );
1763 /* initialize libacl routines */
1764 acl_Initialize(ACL_VERSION);
1766 /* initialize RX support */
1767 #ifndef AFS_NT40_ENV
1768 rxi_syscallp = viced_syscall;
1770 rx_extraPackets = rxpackets;
1771 rx_extraQuota = 4; /* for outgoing prserver calls from R threads */
1772 rx_SetBusyThreshold(busy_threshold, VBUSY);
1773 rx_SetCallAbortThreshold(abort_threshold);
1774 rx_SetConnAbortThreshold(abort_threshold);
1775 stackSize = lwps * 4000;
1776 if (stackSize < 32000)
1778 else if (stackSize > 44000)
1780 #if defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV)
1781 rx_SetStackSize(1, stackSize);
1784 rx_SetUdpBufSize(udpBufSize); /* set the UDP buffer size for receive */
1785 if (rx_Init((int)htons(7000)) < 0) {
1786 ViceLog(0, ("Cannot initialize RX\n"));
1789 if (!rxJumbograms) {
1790 /* Don't send and don't allow 3.4 clients to send jumbograms. */
1794 rx_SetRxDeadTime(30);
1795 sc[0] = rxnull_NewServerSecurityObject();
1796 sc[1] = 0; /* rxvab_NewServerSecurityObject(key1, 0) */
1797 sc[2] = rxkad_NewServerSecurityObject(rxkad_clear, NULL, get_key, NULL);
1798 sc[3] = rxkad_NewServerSecurityObject(rxkad_crypt, NULL, get_key, NULL);
1799 tservice = rx_NewService( /* port */ 0, /* service id */ 1, /*service name */
1801 /* security classes */ sc,
1802 /* numb sec classes */
1803 4, RXAFS_ExecuteRequest);
1806 ("Failed to initialize RX, probably two servers running.\n"));
1809 rx_SetDestroyConnProc(tservice, (void (*)())h_FreeConnection);
1810 rx_SetMinProcs(tservice, 3);
1811 rx_SetMaxProcs(tservice, lwps);
1812 rx_SetCheckReach(tservice, 1);
1815 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", sc, 4,
1816 RXSTATS_ExecuteRequest);
1818 ViceLog(0, ("Failed to initialize rpc stat service.\n"));
1821 rx_SetMinProcs(tservice, 2);
1822 rx_SetMaxProcs(tservice, 4);
1825 * Enable RX hot threads, which allows the listener thread to trade
1826 * places with an idle thread and moves the context switch from listener
1827 * to worker out of the critical path.
1829 rx_EnableHotThread();
1831 /* Some rx debugging */
1832 if (rxlog || eventlog) {
1833 debugFile = afs_fopen("rx_dbg", "w");
1835 rx_debugFile = debugFile;
1837 rxevent_debugFile = debugFile;
1840 init_sys_error_to_et(); /* Set up error table translation */
1841 h_InitHostPackage(); /* set up local cellname and realmname */
1842 InitCallBack(numberofcbs);
1847 ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
1853 ViceLog(0, ("Fatal error in protection initialization, exiting!!\n"));
1857 /* allow super users to manage RX statistics */
1858 rx_SetRxStatUserOk(fs_rxstat_userok);
1860 rx_StartServer(0); /* now start handling requests */
1862 /* we ensure that there is enough space in the vnode buffer to satisfy
1863 ** requests from all concurrent threads.
1864 ** the maximum number of vnodes used by a single thread at any one time
1865 ** is three ( "link" uses three vnodes simultaneously, one vLarge and
1866 ** two vSmall for linking files and two vLarge and one vSmall for linking
1869 minVnodesRequired = 2 * lwps + 1;
1870 if (minVnodesRequired > nSmallVns) {
1871 nSmallVns = minVnodesRequired;
1873 ("Overriding -s command line parameter with %d\n",
1876 if (minVnodesRequired > large) {
1877 large = minVnodesRequired;
1878 ViceLog(0, ("Overriding -l command line parameter with %d\n", large));
1881 /* We now do this after getting the listener up and running, so that client
1882 * connections don't timeout (maybe) if a file server is restarted, since it
1883 * will be available "real soon now". Worry about whether we can satisfy the
1884 * calls in the volume package itself.
1886 if (VInitVolumePackage(fileServer, large, nSmallVns, 0, volcache)) {
1888 ("Shutting down: errors encountered initializing volume package\n"));
1894 * We are done calling fopen/fdopen. It is safe to use a large
1895 * of the file descriptor cache.
1899 #ifdef AFS_PTHREAD_ENV
1900 ViceLog(5, ("Starting pthreads\n"));
1901 assert(pthread_attr_init(&tattr) == 0);
1902 assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
1904 assert(pthread_create
1905 (&serverPid, &tattr, (void *)FiveMinuteCheckLWP,
1906 &fiveminutes) == 0);
1907 assert(pthread_create
1908 (&serverPid, &tattr, (void *)HostCheckLWP, &fiveminutes) == 0);
1909 assert(pthread_create
1910 (&serverPid, &tattr, (void *)FsyncCheckLWP, &fiveminutes) == 0);
1911 #else /* AFS_PTHREAD_ENV */
1912 ViceLog(5, ("Starting LWP\n"));
1913 assert(LWP_CreateProcess
1914 (FiveMinuteCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
1915 (void *)&fiveminutes, "FiveMinuteChecks",
1916 &serverPid) == LWP_SUCCESS);
1918 assert(LWP_CreateProcess
1919 (HostCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
1920 (void *)&fiveminutes, "HostCheck", &serverPid) == LWP_SUCCESS);
1921 assert(LWP_CreateProcess
1922 (FsyncCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
1923 (void *)&fiveminutes, "FsyncCheck", &serverPid) == LWP_SUCCESS);
1924 #endif /* AFS_PTHREAD_ENV */
1926 TM_GetTimeOfDay(&tp, 0);
1928 #ifndef AFS_QUIETFS_ENV
1929 if (console != NULL) {
1930 time_t t = tp.tv_sec;
1931 fprintf(console, "File server has started at %s\r",
1932 afs_ctime(&t, tbuffer, sizeof(tbuffer)));
1937 * Figure out the FileServer's name and primary address.
1939 ViceLog(0, ("Getting FileServer name...\n"));
1940 code = gethostname(FS_HostName, 64);
1942 ViceLog(0, ("gethostname() failed\n"));
1944 ViceLog(0, ("FileServer host name is '%s'\n", FS_HostName));
1946 ViceLog(0, ("Getting FileServer address...\n"));
1947 he = gethostbyname(FS_HostName);
1949 ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
1952 memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
1953 (void)afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
1954 FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
1956 ("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
1957 FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
1960 /* Install handler to catch the shutdown signal;
1961 * bosserver assumes SIGQUIT shutdown
1963 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1964 softsig_signal(SIGQUIT, ShutDown_Signal);
1966 (void)signal(SIGQUIT, ShutDown_Signal);
1971 ("File Server started %s",
1972 afs_ctime(&t, tbuffer, sizeof(tbuffer))));
1973 #if FS_STATS_DETAILED
1974 afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec;
1976 #ifdef AFS_PTHREAD_ENV
1978 sleep(1000); /* long time */
1980 #else /* AFS_PTHREAD_ENV */
1981 assert(LWP_WaitProcess(&parentPid) == LWP_SUCCESS);
1982 #endif /* AFS_PTHREAD_ENV */